Playar byound accunt age storid in db

This commit is contained in:
CitadelStationBot
2017-05-04 18:14:23 -05:00
parent 4ef516ca24
commit 3b84fcb9c2
10 changed files with 132 additions and 93 deletions
+6 -4
View File
@@ -39,9 +39,11 @@
////////////////////////////////////
//things that require the database//
////////////////////////////////////
var/player_age = "Requires database" //So admins know why it isn't working - Used to determine how old the account is - in days.
var/related_accounts_ip = "Requires database" //So admins know why it isn't working - Used to determine what other accounts previously logged in from this ip
var/related_accounts_cid = "Requires database" //So admins know why it isn't working - Used to determine what other accounts previously logged in from this computer id
var/player_age = -1 //Used to determine how old the account is - in days.
var/related_accounts_ip = "Requires database" //So admins know why it isn't working - Used to determine what other accounts previously logged in from this ip
var/related_accounts_cid = "Requires database" //So admins know why it isn't working - Used to determine what other accounts previously logged in from this computer id
var/account_join_date = null //Date of byond account creation in ISO 8601 format
var/account_age = -1 //Age of byond account in days
preload_rsc = PRELOAD_RSC
@@ -62,4 +64,4 @@
var/connection_timeofday //world.timeofday they connected
var/inprefs = FALSE
var/list/topiclimiter
var/list/topiclimiter
+59 -45
View File
@@ -410,70 +410,84 @@ GLOBAL_LIST(external_rsc_urls)
/client/Destroy()
return QDEL_HINT_HARDDEL_NOW
/client/proc/set_client_age_from_db()
/client/proc/set_client_age_from_db(connectiontopic)
if (IsGuestKey(src.key))
return
if(!SSdbcore.Connect())
return
var/sql_ckey = sanitizeSQL(src.ckey)
var/datum/DBQuery/query_get_client_age = SSdbcore.NewQuery("SELECT id, datediff(Now(),firstseen) as age FROM [format_table_name("player")] WHERE ckey = '[sql_ckey]'")
if(!query_get_client_age.Execute())
return
while(query_get_client_age.NextRow())
player_age = text2num(query_get_client_age.item[2])
return
//no match mark it as a first connection for use in client/New()
player_age = -1
/client/proc/sync_client_with_db(connectiontopic)
if (IsGuestKey(src.key))
return
if (!SSdbcore.Connect())
return
var/sql_ckey = sanitizeSQL(ckey)
var/datum/DBQuery/query_get_ip = SSdbcore.NewQuery("SELECT ckey FROM [format_table_name("player")] WHERE ip = INET_ATON('[address]') AND ckey != '[sql_ckey]'")
query_get_ip.Execute()
var/datum/DBQuery/query_get_related_ip = SSdbcore.NewQuery("SELECT ckey FROM [format_table_name("player")] WHERE ip = INET_ATON('[address]') AND ckey != '[sql_ckey]'")
query_get_related_ip.Execute()
related_accounts_ip = ""
while(query_get_ip.NextRow())
related_accounts_ip += "[query_get_ip.item[1]], "
var/datum/DBQuery/query_get_cid = SSdbcore.NewQuery("SELECT ckey FROM [format_table_name("player")] WHERE computerid = '[computer_id]' AND ckey != '[sql_ckey]'")
if(!query_get_cid.Execute())
while(query_get_related_ip.NextRow())
related_accounts_ip += "[query_get_related_ip.item[1]], "
var/datum/DBQuery/query_get_related_cid = SSdbcore.NewQuery("SELECT ckey FROM [format_table_name("player")] WHERE computerid = '[computer_id]' AND ckey != '[sql_ckey]'")
if(!query_get_related_cid.Execute())
return
related_accounts_cid = ""
while (query_get_cid.NextRow())
related_accounts_cid += "[query_get_cid.item[1]], "
while (query_get_related_cid.NextRow())
related_accounts_cid += "[query_get_related_cid.item[1]], "
var/admin_rank = "Player"
if (src.holder && src.holder.rank)
admin_rank = src.holder.rank.name
else
if (check_randomizer(connectiontopic))
return
var/sql_ip = sanitizeSQL(src.address)
var/sql_computerid = sanitizeSQL(src.computer_id)
var/sql_ip = sanitizeSQL(address)
var/sql_computerid = sanitizeSQL(computer_id)
var/sql_admin_rank = sanitizeSQL(admin_rank)
var/datum/DBQuery/query_log_player = SSdbcore.NewQuery("INSERT INTO [format_table_name("player")] (id, ckey, firstseen, lastseen, ip, computerid, lastadminrank) VALUES (null, '[sql_ckey]', Now(), Now(), INET_ATON('[sql_ip]'), '[sql_computerid]', '[sql_admin_rank]') ON DUPLICATE KEY UPDATE lastseen = VALUES(lastseen), ip = VALUES(ip), computerid = VALUES(computerid), lastadminrank = VALUES(lastadminrank)")
if(!query_log_player.Execute())
var/new_player
var/datum/DBQuery/query_client_in_db = SSdbcore.NewQuery("SELECT 1 FROM [format_table_name("player")] WHERE ckey = '[sql_ckey]'")
if(!query_client_in_db.Execute())
return
//Logging player access
if(!query_client_in_db.NextRow())
new_player = 1
account_join_date = sanitizeSQL(findJoinDate())
var/datum/DBQuery/query_add_player = SSdbcore.NewQuery("INSERT INTO [format_table_name("player")] VALUES ('[sql_ckey]', Now(), Now(), INET_ATON('[sql_ip]'), '[sql_computerid]', '[sql_admin_rank]', [account_join_date ? "'[account_join_date]'" : "NULL"])")
if(!query_add_player.Execute())
return
if(!account_join_date)
account_join_date = "Error"
account_age = -1
var/datum/DBQuery/query_get_client_age = SSdbcore.NewQuery("SELECT DATEDIFF(Now(),firstseen), DATEDIFF(Now(),accountjoindate) FROM [format_table_name("player")] WHERE ckey = '[sql_ckey]'")
if(!query_get_client_age.Execute())
return
if(query_get_client_age.NextRow())
player_age = text2num(query_get_client_age.item[1])
if(!account_join_date)
account_age = query_get_client_age.item[2]
if(!account_age)
account_join_date = sanitizeSQL(findJoinDate())
if(!account_join_date)
account_age = -1
else
var/datum/DBQuery/query_datediff = SSdbcore.NewQuery("SELECT DATEDIFF(Now(),accountjoindate)")
if(!query_datediff.Execute())
return
if(query_datediff.NextRow())
account_age = text2num(query_datediff.item[1])
if(!new_player)
var/datum/DBQuery/query_log_player = SSdbcore.NewQuery("UPDATE [format_table_name("player")] SET lastseen = Now(), ip = INET_ATON('[sql_ip]'), computerid = '[sql_computerid]', lastadminrank = '[sql_admin_rank]', accountjoindate = [account_join_date ? "'[account_join_date]'" : "NULL"] WHERE ckey = '[sql_ckey]'")
if(!query_log_player.Execute())
return
if(!account_join_date)
account_join_date = "Error"
var/datum/DBQuery/query_log_connection = SSdbcore.NewQuery("INSERT INTO `[format_table_name("connection_log")]` (`id`,`datetime`,`server_ip`,`server_port`,`ckey`,`ip`,`computerid`) VALUES(null,Now(),INET_ATON('[world.internet_address]'),'[world.port]','[sql_ckey]',INET_ATON('[sql_ip]'),'[sql_computerid]')")
query_log_connection.Execute()
/client/proc/findJoinDate()
var/list/http = world.Export("http://byond.com/members/[ckey]?format=text")
if(!http)
log_world("Failed to connect to byond age check for [ckey]")
return
var/F = file2text(http["CONTENT"])
if(F)
var/regex/R = regex("joined = \"(\\d{4}-\\d{2}-\\d{2})\"")
if(R.Find(F))
. = R.group[1]
else
CRASH("Age check regex failed for [src.ckey]")
/client/proc/check_randomizer(topic)
. = FALSE
if (connection != "seeker")
+46
View File
@@ -0,0 +1,46 @@
diff a/code/modules/client/client_procs.dm b/code/modules/client/client_procs.dm (rejected hunks)
@@ -266,17 +266,11 @@ GLOBAL_LIST(external_rsc_urls)
if((global.comms_key == "default_pwd" || length(global.comms_key) <= 6) && global.comms_allowed) //It's the default value or less than 6 characters long, but it somehow didn't disable comms.
to_chat(src, "<span class='danger'>The server's API key is either too short or is the default value! Consider changing it immediately!</span>")
- add_verbs_from_config()
+ add_verbs_from_config(tdata)
set_client_age_from_db()
var/cached_player_age = player_age //we have to cache this because other shit may change it and we need it's current value now down below.
if (isnum(cached_player_age) && cached_player_age == -1) //first connection
- player_age = 0
- if(!IsGuestKey(key) && SSdbcore.IsConnected())
- findJoinDate()
-
- sync_client_with_db(tdata)
-
-
+ player_age = 0
if (isnum(cached_player_age) && cached_player_age == -1) //first connection
if (config.panic_bunker && !holder && !(ckey in GLOB.deadmins))
log_access("Failed Login: [key] - New account attempting to connect during panic bunker")
@@ -295,7 +289,14 @@ GLOBAL_LIST(external_rsc_urls)
send2irc_adminless_only("New-user", "[key_name(src)] is connecting for the first time!")
else if (isnum(cached_player_age) && cached_player_age < config.notify_new_player_age)
message_admins("New user: [key_name_admin(src)] just connected with an age of [cached_player_age] day[(player_age==1?"":"s")]")
-
+ if(config.use_account_age_for_jobs && account_age >= 0)
+ player_age = account_age
+ if(account_age >= 0 && account_age < config.notify_new_player_account_age)
+ message_admins("[key_name_admin(src)] (IP: [address], ID: [computer_id]) is a new BYOND account day[(account_age==1?"":"s")] old, created on [account_join_date].")
+ if (config.irc_first_connection_alert)
+ send2irc_adminless_only("new_byond_user", "[key_name(src)] (IP: [address], ID: [computer_id]) is a new BYOND account day[(account_age==1?"":"s")] old, created on [account_join_date].")
+ else //We failed to get an age for this user, let admins know they need to keep an eye on them
+ message_admins("Failed to get BYOND account age for [key_name_admin(src)]")
get_message_output("watchlist entry", ckey)
check_ip_intel()
@@ -340,7 +341,7 @@ GLOBAL_LIST(external_rsc_urls)
adminGreet(1)
holder.owner = null
GLOB.admins -= src
-
+
GLOB.ahelp_tickets.ClientLogout(src)
GLOB.directory -= ckey
GLOB.clients -= src