From 20112b58f781900901d30e47f76b7d4e4fff74f6 Mon Sep 17 00:00:00 2001 From: "baloh.matevz" Date: Thu, 26 Jul 2012 23:07:15 +0000 Subject: [PATCH] - Added a proc which logs some information about a client when they connect. The information gathered is: - id (given by database) - ckey - firstseen (date and time) - lastseen (date and time) - last ip - last conputer id git-svn-id: http://tgstation13.googlecode.com/svn/trunk@4187 316c924e-a436-60f5-8080-3fe189b3f50e --- code/modules/client/client procs.dm | 48 +++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/code/modules/client/client procs.dm b/code/modules/client/client procs.dm index 68f830749f..09ae471cef 100644 --- a/code/modules/client/client procs.dm +++ b/code/modules/client/client procs.dm @@ -95,6 +95,7 @@ host = key world.update_status() + log_client_to_db() ..() //calls mob.Login() @@ -118,3 +119,50 @@ del(holder) client_list -= src return ..() + + + +/client/proc/log_client_to_db() + var/user = sqlfdbklogin + var/pass = sqlfdbkpass + var/db = sqlfdbkdb + var/address = sqladdress + var/port = sqlport + + var/DBConnection/dbcon = new() + + dbcon.Connect("dbi:mysql:[db]:[address]:[port]","[user]","[pass]") + if(!dbcon.IsConnected()) + return + + var/sql_ckey = sql_sanitize_text(src.ckey) + + var/DBQuery/query = dbcon.NewQuery("SELECT id FROM erro_player WHERE ckey = '[sql_ckey]'") + query.Execute() + var/sql_id = 0 + while(query.NextRow()) + sql_id = query.item[1] + break + + //Just the standard check to see if it's actually a number + if(sql_id) + if(istext(sql_id)) + sql_id = text2num(sql_id) + if(!isnum(sql_id)) + return + + var/sql_ip = sql_sanitize_text(src.address) + var/sql_computerid = sql_sanitize_text(src.computer_id) + + if(sql_id) + //Player already identified previously, we need to just update the 'lastseen', 'ip' and 'computer_id' variables + + var/DBQuery/query_update = dbcon.NewQuery("UPDATE erro_player SET lastseen = Now(), ip = '[sql_ip]', computerid = '[sql_computerid]' WHERE id = [sql_id]") + query_update.Execute() + else + //New player!! Need to insert all the stuff + + var/DBQuery/query_insert = dbcon.NewQuery("INSERT INTO erro_player (id, ckey, firstseen, lastseen, ip, computerid) VALUES (null, '[sql_ckey]', Now(), Now(), '[sql_ip]', '[sql_computerid]')") + query_insert.Execute() + + dbcon.Disconnect() \ No newline at end of file