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

View File

@@ -1,3 +1,13 @@
21 April 2017, by Jordie0608
Modified table 'player', adding the column 'accountjoindate', removing the column 'id' and making the column 'ckey' the primary key.
ALTER TABLE `feedback`.`player` DROP COLUMN `id`, ADD COLUMN `accountjoindate` DATE NULL AFTER `lastadminrank`, DROP PRIMARY KEY, ADD PRIMARY KEY (`ckey`), DROP INDEX `ckey`;
Remember to add a prefix to the table name if you use them.
----------------------------------------------------
10 March 2017, by Jordie0608 10 March 2017, by Jordie0608
Modified table 'death', adding the columns 'toxloss', 'cloneloss', and 'staminaloss' and table 'legacy_population', adding the columns 'server_ip' and 'server_port'. Modified table 'death', adding the columns 'toxloss', 'cloneloss', and 'staminaloss' and table 'legacy_population', adding the columns 'server_ip' and 'server_port'.

View File

@@ -261,15 +261,14 @@ DROP TABLE IF EXISTS `player`;
/*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */; /*!40101 SET character_set_client = utf8 */;
CREATE TABLE `player` ( CREATE TABLE `player` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`ckey` varchar(32) NOT NULL, `ckey` varchar(32) NOT NULL,
`firstseen` datetime NOT NULL, `firstseen` datetime NOT NULL,
`lastseen` datetime NOT NULL, `lastseen` datetime NOT NULL,
`ip` int(10) unsigned NOT NULL, `ip` int(10) unsigned NOT NULL,
`computerid` varchar(32) NOT NULL, `computerid` varchar(32) NOT NULL,
`lastadminrank` varchar(32) NOT NULL DEFAULT 'Player', `lastadminrank` varchar(32) NOT NULL DEFAULT 'Player',
PRIMARY KEY (`id`), `accountjoindate` DATE DEFAULT NULL,
UNIQUE KEY `ckey` (`ckey`), PRIMARY KEY (`ckey`),
KEY `idx_player_cid_ckey` (`computerid`,`ckey`), KEY `idx_player_cid_ckey` (`computerid`,`ckey`),
KEY `idx_player_ip_ckey` (`ip`,`ckey`) KEY `idx_player_ip_ckey` (`ip`,`ckey`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1; ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

View File

@@ -261,15 +261,14 @@ DROP TABLE IF EXISTS `SS13_player`;
/*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */; /*!40101 SET character_set_client = utf8 */;
CREATE TABLE `SS13_player` ( CREATE TABLE `SS13_player` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`ckey` varchar(32) NOT NULL, `ckey` varchar(32) NOT NULL,
`firstseen` datetime NOT NULL, `firstseen` datetime NOT NULL,
`lastseen` datetime NOT NULL, `lastseen` datetime NOT NULL,
`ip` int(10) unsigned NOT NULL, `ip` int(10) unsigned NOT NULL,
`computerid` varchar(32) NOT NULL, `computerid` varchar(32) NOT NULL,
`lastadminrank` varchar(32) NOT NULL DEFAULT 'Player', `lastadminrank` varchar(32) NOT NULL DEFAULT 'Player',
PRIMARY KEY (`id`), `accountjoindate` DATE DEFAULT NULL,
UNIQUE KEY `ckey` (`ckey`), PRIMARY KEY (`ckey`),
KEY `idx_player_cid_ckey` (`computerid`,`ckey`), KEY `idx_player_cid_ckey` (`computerid`,`ckey`),
KEY `idx_player_ip_ckey` (`ip`,`ckey`) KEY `idx_player_ip_ckey` (`ip`,`ckey`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1; ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

View File

@@ -1,37 +0,0 @@
#define YOUNG 4
/client/proc/join_date_check(y,m,d)
var/datum/DBQuery/query_datediff = SSdbcore.NewQuery("SELECT DATEDIFF(Now(),'[y]-[m]-[d]')")
if(!query_datediff.Execute())
return FALSE
if(query_datediff.NextRow())
var/diff = text2num(query_datediff.item[1])
if(config.use_account_age_for_jobs)
player_age = max(0,diff) //So job code soesn't freak out if they are time traveling.
if(diff < YOUNG)
var/msg = "(IP: [address], ID: [computer_id]) is a new BYOND account made on [y]-[m]-[d]."
if(diff < 0)
msg += " They are also apparently from the future."
message_admins("[key_name_admin(src)] [msg]")
return TRUE
#undef YOUNG
/client/proc/findJoinDate()
var/http[] = world.Export("http://byond.com/members/[src.ckey]?format=text")
if(!http)
log_world("Failed to connect to byond age check for [src.ckey]")
return FALSE
var/F = file2text(http["CONTENT"])
if(F)
var/regex/R = regex("joined = \"(\\d{4})-(\\d{2})-(\\d{2})\"")
if(!R.Find(F))
CRASH("Age check regex failed")
var/y = R.group[1]
var/m = R.group[2]
var/d = R.group[3]
return join_date_check(y,m,d)

View File

@@ -129,6 +129,7 @@
var/forbid_peaceborg = 0 var/forbid_peaceborg = 0
var/panic_bunker = 0 // prevents new people it hasn't seen before from connecting var/panic_bunker = 0 // prevents new people it hasn't seen before from connecting
var/notify_new_player_age = 0 // how long do we notify admins of a new player var/notify_new_player_age = 0 // how long do we notify admins of a new player
var/notify_new_player_account_age = 0 // how long do we notify admins of a new byond account
var/irc_first_connection_alert = 0 // do we notify the irc channel when somebody is connecting for the first time? var/irc_first_connection_alert = 0 // do we notify the irc channel when somebody is connecting for the first time?
var/traitor_scaling_coeff = 6 //how much does the amount of players get divided by to determine traitors var/traitor_scaling_coeff = 6 //how much does the amount of players get divided by to determine traitors
@@ -476,6 +477,8 @@
panic_bunker = 1 panic_bunker = 1
if("notify_new_player_age") if("notify_new_player_age")
notify_new_player_age = text2num(value) notify_new_player_age = text2num(value)
if("notify_new_player_account_age")
notify_new_player_account_age = text2num(value)
if("irc_first_connection_alert") if("irc_first_connection_alert")
irc_first_connection_alert = 1 irc_first_connection_alert = 1
if("check_randomizer") if("check_randomizer")

View File

@@ -39,9 +39,11 @@
//////////////////////////////////// ////////////////////////////////////
//things that require the database// //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/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_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/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 preload_rsc = PRELOAD_RSC

View File

@@ -410,70 +410,84 @@ GLOBAL_LIST(external_rsc_urls)
/client/Destroy() /client/Destroy()
return QDEL_HINT_HARDDEL_NOW return QDEL_HINT_HARDDEL_NOW
/client/proc/set_client_age_from_db() /client/proc/set_client_age_from_db(connectiontopic)
if (IsGuestKey(src.key)) if (IsGuestKey(src.key))
return return
if(!SSdbcore.Connect()) if(!SSdbcore.Connect())
return return
var/sql_ckey = sanitizeSQL(src.ckey) var/sql_ckey = sanitizeSQL(src.ckey)
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]'")
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]'") query_get_related_ip.Execute()
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()
related_accounts_ip = "" related_accounts_ip = ""
while(query_get_ip.NextRow()) while(query_get_related_ip.NextRow())
related_accounts_ip += "[query_get_ip.item[1]], " 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]'")
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_related_cid.Execute())
if(!query_get_cid.Execute())
return return
related_accounts_cid = "" related_accounts_cid = ""
while (query_get_cid.NextRow()) while (query_get_related_cid.NextRow())
related_accounts_cid += "[query_get_cid.item[1]], " related_accounts_cid += "[query_get_related_cid.item[1]], "
var/admin_rank = "Player" var/admin_rank = "Player"
if (src.holder && src.holder.rank) if (src.holder && src.holder.rank)
admin_rank = src.holder.rank.name admin_rank = src.holder.rank.name
else else
if (check_randomizer(connectiontopic)) if (check_randomizer(connectiontopic))
return return
var/sql_ip = sanitizeSQL(address)
var/sql_ip = sanitizeSQL(src.address) var/sql_computerid = sanitizeSQL(computer_id)
var/sql_computerid = sanitizeSQL(src.computer_id)
var/sql_admin_rank = sanitizeSQL(admin_rank) var/sql_admin_rank = sanitizeSQL(admin_rank)
var/new_player
var/datum/DBQuery/query_client_in_db = SSdbcore.NewQuery("SELECT 1 FROM [format_table_name("player")] WHERE ckey = '[sql_ckey]'")
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_client_in_db.Execute())
return
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()) if(!query_log_player.Execute())
return return
if(!account_join_date)
//Logging player access 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]')") 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() 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) /client/proc/check_randomizer(topic)
. = FALSE . = FALSE
if (connection != "seeker") if (connection != "seeker")

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

View File

@@ -263,6 +263,10 @@ EXTREME_POPCAP_MESSAGE The server is currently serving a high number of users, f
## Requres database ## Requres database
NOTIFY_NEW_PLAYER_AGE 0 NOTIFY_NEW_PLAYER_AGE 0
## Notify admins when a player connects if their byond account was created in the last X days
## Requires database
NOTIFY_NEW_PLAYER_ACCOUNT_AGE 1
## Notify the irc channel when a new player makes their first connection ## Notify the irc channel when a new player makes their first connection
## Requres database ## Requres database
#IRC_FIRST_CONNECTION_ALERT #IRC_FIRST_CONNECTION_ALERT

View File

@@ -75,7 +75,6 @@
#include "code\__HELPERS\_logging.dm" #include "code\__HELPERS\_logging.dm"
#include "code\__HELPERS\_string_lists.dm" #include "code\__HELPERS\_string_lists.dm"
#include "code\__HELPERS\AStar.dm" #include "code\__HELPERS\AStar.dm"
#include "code\__HELPERS\bandetect.dm"
#include "code\__HELPERS\cmp.dm" #include "code\__HELPERS\cmp.dm"
#include "code\__HELPERS\files.dm" #include "code\__HELPERS\files.dm"
#include "code\__HELPERS\flags.dm" #include "code\__HELPERS\flags.dm"