From 5ac23f6a2da6dcd28238d9ae24fe8349fe0981fb Mon Sep 17 00:00:00 2001 From: MrStonedOne Date: Wed, 25 Feb 2015 23:27:03 -0800 Subject: [PATCH] Panic bunker + new player notification configs Panic bunker! Uses the power of the database to reject new ckeys that have never connected to the server(s) before. Admins are exempt, even while deadmin'ed, but they are also unlikely to be new ckeys except in rare cases that involve vv fuckary. New player notification is now configurable. Adds a optional default disabled irc notification of a players first time connecting. --- code/controllers/configuration.dm | 9 +++++++++ code/modules/admin/admin_verbs.dm | 6 ++++-- code/modules/admin/verbs/panicbunker.dm | 16 +++++++++++++++ code/modules/client/client procs.dm | 27 +++++++++++++++++++++---- config/config.txt | 14 ++++++++++++- tgstation.dme | 1 + 6 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 code/modules/admin/verbs/panicbunker.dm diff --git a/code/controllers/configuration.dm b/code/controllers/configuration.dm index 7e9ea75db89..89333ee5fa2 100644 --- a/code/controllers/configuration.dm +++ b/code/controllers/configuration.dm @@ -85,6 +85,9 @@ var/humans_need_surnames = 0 var/allow_random_events = 0 // enables random events mid-round when set to 1 var/allow_ai = 0 // allow ai job + 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/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/changeling_scaling_coeff = 6 //how much does the amount of players get divided by to determine changelings @@ -316,6 +319,12 @@ config.hard_popcap_message = value if("extreme_popcap_message") config.extreme_popcap_message = value + if("panic_bunker") + config.panic_bunker = 1 + if("notify_new_player_age") + config.notify_new_player_age = text2num(value) + if("irc_first_connection_alert") + config.irc_first_connection_alert = 1 else diary << "Unknown setting in configuration: '[name]'" diff --git a/code/modules/admin/admin_verbs.dm b/code/modules/admin/admin_verbs.dm index 0434213187c..f35c93a3e89 100644 --- a/code/modules/admin/admin_verbs.dm +++ b/code/modules/admin/admin_verbs.dm @@ -100,7 +100,8 @@ var/list/admin_verbs_server = list( /datum/admins/proc/toggleAI, /client/proc/cmd_admin_delete, /*delete an instance/object/mob/etc*/ /client/proc/cmd_debug_del_all, - /client/proc/toggle_random_events + /client/proc/toggle_random_events, + /client/proc/panicbunker ) var/list/admin_verbs_debug = list( /client/proc/restart_controller, @@ -190,7 +191,8 @@ var/list/admin_verbs_hideable = list( /proc/possess, /proc/release, /client/proc/reload_admins, - /client/proc/reset_all_tcs + /client/proc/reset_all_tcs, + /client/proc/panicbunker ) /client/proc/add_admin_verbs() diff --git a/code/modules/admin/verbs/panicbunker.dm b/code/modules/admin/verbs/panicbunker.dm new file mode 100644 index 00000000000..e9b12dc5ba2 --- /dev/null +++ b/code/modules/admin/verbs/panicbunker.dm @@ -0,0 +1,16 @@ +/client/proc/panicbunker() + set category = "Server" + set name = "Toggle Panic Bunker" + if (!config.sql_enabled) + usr << "The Database is not enabled!" + return + + if (!dbcon || !dbcon.IsConnected()) + usr << "The Database is not connected!" + return + + config.panic_bunker = (!config.panic_bunker) + log_admin("[key_name(usr)] has toggled the Panic Bunker, it is now [(config.panic_bunker?"on":"off")]") + message_admins("[key_name_admin(usr)] has toggled the Panic Bunker, it is now [(config.panic_bunker?"on":"off")]") + feedback_add_details("admin_verb","PANIC") //If you are copy-pasting this, ensure the 2nd parameter is unique to the new proc! + diff --git a/code/modules/client/client procs.dm b/code/modules/client/client procs.dm index 32ae0986467..51ca6ecf703 100644 --- a/code/modules/client/client procs.dm +++ b/code/modules/client/client procs.dm @@ -136,6 +136,24 @@ var/next_external_rsc = 0 add_verbs_from_config() set_client_age_from_db() + if (isnum(player_age) && player_age == -1) //first connection + if (config.panic_bunker && !holder && !(ckey in deadmins)) + src << "Sorry but the server is currently not accepting connections from never before seen players." + del(src) + return 0 + + if (config.notify_new_player_age >= 0) + message_admins("New user: [key_name_admin(src)] is connecting here for the first time.") + + if (config.irc_first_connection_alert) + send2irc("New user", "[key_name(src)] is connecting for the first time!") + + player_age = 0 // set it from -1 to 0 so the job selection code doesn't have a panic attack + + else if (isnum(player_age) && player_age < config.notify_new_player_age) + message_admins("New user: [key_name_admin(src)] just connected with an age of [player_age] day[(player_age==1?"":"s")]") + + if (!ticker || ticker.current_state == GAME_STATE_PREGAME) spawn (rand(10,150)) if (src) @@ -172,14 +190,15 @@ var/next_external_rsc = 0 var/sql_ckey = sanitizeSQL(src.ckey) var/DBQuery/query = dbcon.NewQuery("SELECT id, datediff(Now(),firstseen) as age FROM [format_table_name("player")] WHERE ckey = '[sql_ckey]'") - query.Execute() + if (!query.Execute()) + return while (query.NextRow()) player_age = text2num(query.item[2]) return - //player not found. - player_age = 0 - message_admins("[key_name_admin(src)] is connecting here for the first time.") + + //no match mark it as a first connection for use in client/New() + player_age = -1 /client/proc/sync_client_with_db() diff --git a/config/config.txt b/config/config.txt index 412245906b1..e28c4ff6b2f 100644 --- a/config/config.txt +++ b/config/config.txt @@ -175,4 +175,16 @@ HARD_MESSAGE The server is currently serving a high number of users, You cannot #EXTREME_POPCAP 200 ## Message for extreme cap -EXTREME_MESSAGE The server is currently serving a high number of users, find alternative servers. \ No newline at end of file +EXTREME_MESSAGE The server is currently serving a high number of users, find alternative servers. + +## Notify admins when a new player connects for the first x days a player's been around. (0 for first connection only, -1 for never) +## Requres database +NOTIFY_NEW_PLAYER_AGE 0 + +## Notify the irc channel when a new player makes their first connection +## Requres database +#IRC_FIRST_CONNECTION_ALERT + +## Deny all new connections by ckeys we haven't seen before (exempts admins and only denies the connection if the database is enabled and connected) +## Requires database +#PANIC_BUNKER \ No newline at end of file diff --git a/tgstation.dme b/tgstation.dme index 6bce7153849..08724346457 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -798,6 +798,7 @@ #include "code\modules\admin\verbs\modifyvariables.dm" #include "code\modules\admin\verbs\one_click_antag.dm" #include "code\modules\admin\verbs\onlyone.dm" +#include "code\modules\admin\verbs\panicbunker.dm" #include "code\modules\admin\verbs\playsound.dm" #include "code\modules\admin\verbs\possess.dm" #include "code\modules\admin\verbs\pray.dm"