From 5906ae7556f603374f894e11b0ca1cbfb2f9e4a5 Mon Sep 17 00:00:00 2001 From: GinjaNinja32 Date: Thu, 25 Jun 2015 22:52:36 +0100 Subject: [PATCH] Adds 'age' command to world.Topic, for the IRC bot. Also runs all keys through ckey() before using them, to avoid easily-fixed errors --- code/modules/client/client procs.dm | 19 +++++++++++++++++++ code/world.dm | 23 +++++++++++++++++++++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/code/modules/client/client procs.dm b/code/modules/client/client procs.dm index d68356792c..51a5333fdc 100644 --- a/code/modules/client/client procs.dm +++ b/code/modules/client/client procs.dm @@ -177,6 +177,25 @@ return ..() +// here because it's similar to below + +// Returns null if no DB connection can be established, or -1 if the requested key was not found in the database + +/proc/get_player_age(key) + establish_db_connection() + if(!dbcon.IsConnected()) + return null + + var/sql_ckey = sql_sanitize_text(ckey(key)) + + var/DBQuery/query = dbcon.NewQuery("SELECT datediff(Now(),firstseen) as age FROM erro_player WHERE ckey = '[sql_ckey]'") + query.Execute() + + if(query.NextRow()) + return text2num(query.item[1]) + else + return -1 + /client/proc/log_client_to_db() diff --git a/code/world.dm b/code/world.dm index 2fd24cf9f5..f67d6711ac 100644 --- a/code/world.dm +++ b/code/world.dm @@ -156,9 +156,10 @@ var/world_topic_spam_protect_time = world.timeofday return "Bad Key" var/client/C + var/req_ckey = ckey(input["adminmsg"]) for(var/client/K in clients) - if(K.ckey == input["adminmsg"]) + if(K.ckey == req_ckey) C = K break if(!C) @@ -199,10 +200,28 @@ var/world_topic_spam_protect_time = world.timeofday world_topic_spam_protect_ip = addr return "Bad Key" - return show_player_info_irc(input["notes"]) + return show_player_info_irc(ckey(input["notes"])) + else if(copytext(T,1,4) == "age") + var/input[] = params2list(T) + if(input["key"] != config.comms_password) + if(world_topic_spam_protect_ip == addr && abs(world_topic_spam_protect_time - world.time) < 50) + spawn(50) + world_topic_spam_protect_time = world.time + return "Bad Key (Throttled)" + world_topic_spam_protect_time = world.time + world_topic_spam_protect_ip = addr + return "Bad Key" + var/age = get_player_age(input["age"]) + if(isnum(age)) + if(age >= 0) + return "[age]" + else + return "Ckey not found" + else + return "Database connection failed or not set up" /world/Reboot(var/reason)