Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UUID generation / Discord verification #2163

Merged
merged 12 commits into from
Jul 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion SQL/beestation_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,14 @@ CREATE TABLE IF NOT EXISTS `SS13_player` (
`lastseen_round_id` int(11) unsigned NOT NULL,
`ip` int(10) unsigned NOT NULL,
`computerid` varchar(32) NOT NULL,
`uuid` varchar(64) DEFAULT NULL,
`lastadminrank` varchar(32) NOT NULL DEFAULT 'Player',
`accountjoindate` date DEFAULT NULL,
`flags` smallint(5) unsigned NOT NULL DEFAULT '0',
`antag_tokens` tinyint(4) unsigned DEFAULT '0',
`metacoins` int(10) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`ckey`),
UNIQUE KEY (`uuid`),
KEY `idx_player_cid_ckey` (`computerid`,`ckey`),
KEY `idx_player_ip_ckey` (`ip`,`ckey`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
Expand Down Expand Up @@ -479,7 +481,7 @@ CREATE TABLE IF NOT EXISTS `SS13_schema_revision` (
`date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`major`,`minor`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
INSERT INTO `SS13_schema_revision` (`major`, `minor`) VALUES (5, 6);
INSERT INTO `SS13_schema_revision` (`major`, `minor`) VALUES (5, 7);



Expand Down
15 changes: 12 additions & 3 deletions SQL/database_changelog.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
Any time you make a change to the schema files, remember to increment the database schema version. Generally increment the minor number, major should be reserved for significant changes to the schema. Both values go up to 255.

The latest database version is 5.6; The query to update the schema revision table is:
The latest database version is 5.7; The query to update the schema revision table is:

INSERT INTO `schema_revision` (`major`, `minor`) VALUES (5, 6);
INSERT INTO `schema_revision` (`major`, `minor`) VALUES (5, 7);
or
INSERT INTO `SS13_schema_revision` (`major`, `minor`) VALUES (5, 6);
INSERT INTO `SS13_schema_revision` (`major`, `minor`) VALUES (5, 7);

In any query remember to add a prefix to the table names if you use one.

-----------------------------------------------------

Version 5.7 20 July 2020, by ike709
Adds a new `uuid` column in the `player` table that allows for discord verification.

ALTER TABLE SS13_player
ADD COLUMN `uuid` VARCHAR(64) DEFAULT NULL AFTER `computerid`,
ADD CONSTRAINT `UUID` UNIQUE KEY (`uuid`)

----------------------------------------------------

Version 5.6, 13 June 2020, by Jordie0608
Expand Down
2 changes: 1 addition & 1 deletion code/__DEFINES/subsystems.dm
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
* make sure you add an update to the schema_version stable in the db changelog
*/
#define DB_MINOR_VERSION 6
#define DB_MINOR_VERSION 7


//! ## Timing subsystem
Expand Down
6 changes: 3 additions & 3 deletions code/datums/browser.dm
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
stylesheets["spritesheet_[sheet.name].css"] = "data/spritesheets/[sheet.name]"
else
var/asset_name = "[name].css"

stylesheets[asset_name] = file

if (!SSassets.cache[asset_name])
Expand Down Expand Up @@ -439,8 +439,8 @@
// to pass a "close=1" parameter to the atom's Topic() proc for special handling.
// Otherwise, the user mob's machine var will be reset directly.
//
/proc/onclose(mob/user, windowid, atom/ref=null)
if(!user.client)
/proc/onclose(user, windowid, atom/ref=null)
if(isnull(user))
return
var/param = "null"
if(ref)
Expand Down
27 changes: 27 additions & 0 deletions code/datums/world_topic.dm
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,30 @@
.["shuttle_timer"] = SSshuttle.emergency.timeLeft()
// Shuttle timer, in seconds

/datum/world_topic/identify_uuid
keyword = "identify_uuid"
require_comms_key = TRUE
log = FALSE

/datum/world_topic/identify_uuid/Run(list/input, addr)
var/uuid = input["uuid"]
. = list()

if(!SSdbcore.Connect())
return null

var/datum/DBQuery/query_ckey_lookup = SSdbcore.NewQuery(
"SELECT ckey FROM [format_table_name("player")] WHERE uuid = :uuid",
list("uuid" = uuid)
)
if(!query_ckey_lookup.Execute())
qdel(query_ckey_lookup)
return null

.["identified_ckey"] = null
if(query_ckey_lookup.NextRow())
.["identified_ckey"] = query_ckey_lookup.item[1]
qdel(query_ckey_lookup)
return .


80 changes: 80 additions & 0 deletions code/modules/client/client_procs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,9 @@ GLOBAL_LIST_EMPTY(external_rsc_urls)
check_ip_intel()
validate_key_in_db()

fetch_uuid()
verbs += /client/proc/show_account_identifier

send_resources()

generate_clickcatcher()
Expand Down Expand Up @@ -471,6 +474,53 @@ GLOBAL_LIST_EMPTY(external_rsc_urls)
src << link("[redirect_address]")
qdel(src)

/client/proc/generate_uuid()
if(IsAdminAdvancedProcCall())
log_admin("Attempted admin generate_uuid() proc call blocked.")
message_admins("Attempted admin generate_uuid() proc call blocked.")
return FALSE

var/fiftyfifty = prob(50) ? FEMALE : MALE
var/hashtext = "[ckey][rand(0,9999)][world.realtime][rand(0,9999)][random_unique_name(fiftyfifty)][rand(0,9999)][address][rand(0,9999)][computer_id][rand(0,9999)][GLOB.round_id]"
var/uuid = "[rustg_hash_string(RUSTG_HASH_SHA256, hashtext)]"

if(!SSdbcore.Connect())
return FALSE

var/datum/DBQuery/query_update_uuid = SSdbcore.NewQuery(
"UPDATE [format_table_name("player")] SET uuid = :uuid WHERE ckey = :ckey",
list("uuid" = uuid, "ckey" = ckey)
)
query_update_uuid.Execute()
qdel(query_update_uuid)

return uuid

/client/proc/fetch_uuid()
if(IsAdminAdvancedProcCall())
log_admin("Attempted admin fetch_uuid() proc call blocked.")
message_admins("Attempted admin fetch_uuid() proc call blocked.")
return FALSE

if(!SSdbcore.Connect())
return FALSE

var/datum/DBQuery/query_get_uuid = SSdbcore.NewQuery(
"SELECT uuid FROM [format_table_name("player")] WHERE ckey = :ckey",
list("ckey" = ckey)
)
if(!query_get_uuid.Execute())
qdel(query_get_uuid)
return FALSE
var/uuid = null
if(query_get_uuid.NextRow())
uuid = query_get_uuid.item[1]
qdel(query_get_uuid)
if(uuid == null)
return generate_uuid()
else
return uuid

//////////////
//DISCONNECT//
//////////////
Expand Down Expand Up @@ -973,3 +1023,33 @@ GLOBAL_LIST_EMPTY(external_rsc_urls)
screen -= S
qdel(S)
char_render_holders = null

/client/proc/show_account_identifier()
set name = "Show Account Identifier"
set category = "OOC"
set desc ="Get your ID for account verification."

verbs -= /client/proc/show_account_identifier
addtimer(CALLBACK(src, .proc/restore_account_identifier), 20) //Don't DoS DB queries, asshole

var/confirm = alert("Do NOT share the verification ID in the following popup. Understand?", "Important Warning", "Yes", "Cancel")
if(confirm == "Cancel")
return
if(confirm == "Yes")
var/uuid = fetch_uuid()
if(!uuid)
alert("Failed to fetch your verification ID. Try again later. If problems persist, tell an admin.", "Account Verification", "Okay")
log_sql("Failed to fetch UUID for [key_name(src)]")
else
var/dat
dat += "<h3>Account Identifier</h3>"
dat += "<br>"
dat += "<h3>Do NOT share this id:</h3>"
dat += "<br>"
dat += "[uuid]"

src << browse(dat, "window=accountidentifier;size=600x320")
onclose(src, "accountidentifier")

/client/proc/restore_account_identifier()
verbs += /client/proc/show_account_identifier