diff --git a/code/_globalvars/configuration.dm b/code/_globalvars/configuration.dm index 58c6dd7913c..6522caafe81 100644 --- a/code/_globalvars/configuration.dm +++ b/code/_globalvars/configuration.dm @@ -21,6 +21,10 @@ var/tinted_weldhelh = 1 var/Debug = 0 // global debug switch var/Debug2 = 0 +//Server API key +var/global/comms_key = "default_pwd" +var/global/comms_allowed = 0 //By default, the server does not allow messages to be sent to it, unless the key is strong enough (this is to prevent misconfigured servers from becoming vulnerable) + //This was a define, but I changed it to a variable so it can be changed in-game.(kept the all-caps definition because... code...) -Errorage var/MAX_EX_DEVESTATION_RANGE = 3 diff --git a/code/controllers/configuration.dm b/code/controllers/configuration.dm index f0f0f727089..f11d2fdebc5 100644 --- a/code/controllers/configuration.dm +++ b/code/controllers/configuration.dm @@ -101,9 +101,6 @@ var/rename_cyborg = 0 var/ooc_during_round = 0 - var/comms_key = "default_pwd" //Server API key - var/comms_allowed = 0 //By default, the server does not allow messages to be sent to it, unless the key is strong enough (this is to prevent misconfigured servers from becoming victims) - //Used for modifying movement speed for mobs. //Unversal modifiers var/run_speed = 0 @@ -269,9 +266,9 @@ if("automute_on") automute_on = 1 if("comms_key") - comms_key = value + global.comms_key = value if(value != "default_pwd" && length(value) > 6) //It's the default value or less than 6 characters long, warn badmins - comms_allowed = 1 + global.comms_allowed = 1 else diary << "Unknown setting in configuration: '[name]'" diff --git a/code/modules/client/client procs.dm b/code/modules/client/client procs.dm index d87d0e987a4..c95d27a2a7d 100644 --- a/code/modules/client/client procs.dm +++ b/code/modules/client/client procs.dm @@ -130,7 +130,7 @@ var/next_external_rsc = 0 if(holder) add_admin_verbs() admin_memo_show() - if((config.comms_key == "default_pwd" || length(config.comms_key) <= 6) && config.comms_allowed) //It's the default value or less than 6 characters long, but it somehow didn't disable comms. + 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. src << "The server's API key is either too short or is the default value! Consider changing it immediately!" log_client_to_db() diff --git a/code/world.dm b/code/world.dm index 506b0cdd7b4..34f73a49f4b 100644 --- a/code/world.dm +++ b/code/world.dm @@ -162,8 +162,8 @@ return list2params(s) else if (copytext(T,1,9) == "announce") var/input[] = params2list(T) - if(config.comms_allowed) - if(input["key"] != config.comms_key) + if(global.comms_allowed) + if(input["key"] != global.comms_key) return "Bad Key" else #define CHAT_PULLR 2048 diff --git a/tools/PR_announcer_bot/config.txt b/tools/PR_announcer_bot/config.txt index 2919a9b96a2..f5cc606b2b3 100644 --- a/tools/PR_announcer_bot/config.txt +++ b/tools/PR_announcer_bot/config.txt @@ -4,4 +4,5 @@ commskey = this_is_a_test_key //API key of the server GitHub_bot_name = testbot_github //It'll get the data from this bot IRC_bot_name = testbot_BYOND //This'll be our name IRC_server = irc.rizon.net:6670 //format - server:port -IRC_channel = #ircchannel \ No newline at end of file +IRC_channel = #ircchannel +Nickserv_auth = _NONE_ //leave _NONE_ if your bot does not require nickserv authentication \ No newline at end of file diff --git a/tools/PR_announcer_bot/sendkeys_ss13.exe b/tools/PR_announcer_bot/sendkeys_ss13.exe index 4f9332811d9..acdc57f094e 100644 Binary files a/tools/PR_announcer_bot/sendkeys_ss13.exe and b/tools/PR_announcer_bot/sendkeys_ss13.exe differ diff --git a/tools/PR_announcer_bot/sendkeys_ss13/Program.cs b/tools/PR_announcer_bot/sendkeys_ss13/Program.cs index 8d7d5856a98..440f85b691c 100644 --- a/tools/PR_announcer_bot/sendkeys_ss13/Program.cs +++ b/tools/PR_announcer_bot/sendkeys_ss13/Program.cs @@ -37,6 +37,7 @@ namespace sendkeys_ss13 public static string IRC_server = "test.net"; public static int IRC_port = 11111; public static string IRC_channel = "#channel"; + public static string NickServAuth = null; public static string[] merge_archive; public static bool mergeflag = false; @@ -57,10 +58,10 @@ namespace sendkeys_ss13 catch (Exception) { IRCReconnectAttempt++; - if (IRCReconnectAttempt <= 3) + if (IRCReconnectAttempt <= 5) { Console.WriteLine("IRC server is unavaible at the moment. Reconnect attempt {0}...", IRCReconnectAttempt); - System.Threading.Thread.Sleep(3000); //Reconnecting after 5 seconds. + System.Threading.Thread.Sleep(5000); //Reconnecting after 5 seconds. Main(args); } else @@ -71,7 +72,17 @@ namespace sendkeys_ss13 } } Console.WriteLine("Connected to IRC"); - irc.Login(IRC_bot_name, IRC_bot_name); + try + { + irc.Login(IRC_bot_name, IRC_bot_name); + } + catch (Exception) + { + irc.Login(IRC_bot_name + "_1", IRC_bot_name + "_1"); + Console.WriteLine("Bot name is already taken, trying alternate..."); + } + if (NickServAuth != null) + irc.SendMessage(SendType.Message, "NickServ", "identify " + NickServAuth); Console.WriteLine("Logged in"); irc.RfcJoin(IRC_channel); Console.WriteLine("Joining {0}", IRC_channel); @@ -83,10 +94,10 @@ namespace sendkeys_ss13 if (File.Exists("config.txt")) { StreamReader reader = new StreamReader("config.txt"); - string[] line = reader.ReadLine().Split(' '); + string[] line = ReadLine_exception(reader); if (line[2] != null) { - Match match1 = Regex.Match(line[2], @"(\d{1,3}.?){4}"); //rudimentary IP validation + Match match1 = Regex.Match(line[2], @"^(\d{1,3}.?){4}$"); //rudimentary IP validation if (match1.Success) { serverIP = line[2]; @@ -95,13 +106,12 @@ namespace sendkeys_ss13 else { Console.WriteLine("IP cannot be validated."); - return; } } - line = reader.ReadLine().Split(' '); + line = ReadLine_exception(reader); if (line[2] != null) { - Match match2 = Regex.Match(line[2], @"\d{1,5}"); //rudimentary port validation + Match match2 = Regex.Match(line[2], @"^\d{1,5}$"); //rudimentary port validation if (match2.Success && (Convert.ToInt32(line[2]) < 65535)) { serverPort = Convert.ToInt32(line[2]); @@ -110,10 +120,9 @@ namespace sendkeys_ss13 else { Console.WriteLine("Port cannot be validated."); - return; } } - line = reader.ReadLine().Split(' '); + line = ReadLine_exception(reader); if (line[2] != null) { commskey = line[2]; @@ -122,9 +131,8 @@ namespace sendkeys_ss13 else { Console.WriteLine("No Commskey!"); - return; } - line = reader.ReadLine().Split(' '); + line = ReadLine_exception(reader); if (line[2] != null) { Github_bot_name = line[2]; @@ -133,23 +141,21 @@ namespace sendkeys_ss13 else { Console.WriteLine("No botname found."); - return; } - line = reader.ReadLine().Split(' '); + line = ReadLine_exception(reader); if (line[2] != null) { IRC_bot_name = line[2]; - Console.WriteLine("Read IRC bot name: " + Github_bot_name); + Console.WriteLine("Read IRC bot name: " + IRC_bot_name); } else { Console.WriteLine("No botname found."); - return; } - line = reader.ReadLine().Split(' '); + line = ReadLine_exception(reader); if (line[2] != null) { - Match match3 = Regex.Match(line[2], @"(.+)\:(\d{1,5})"); //rudimentary port validation + Match match3 = Regex.Match(line[2], @"^(.+)\:(\d{1,5})$"); //rudimentary port validation if (match3.Success) { IRC_server = Convert.ToString(match3.Groups[1]); @@ -159,10 +165,9 @@ namespace sendkeys_ss13 else { Console.WriteLine("Server:port invalid."); - return; } } - line = reader.ReadLine().Split(' '); + line = ReadLine_exception(reader); if (line[2] != null) { IRC_channel = line[2]; @@ -171,7 +176,16 @@ namespace sendkeys_ss13 else { Console.WriteLine("No channel found."); - return; + } + line = ReadLine_exception(reader); + if (line[2] != null && line[2] != "_NONE_") + { + NickServAuth = line[2]; + Console.WriteLine("Read Nickserv auth"); + } + else + { + Console.WriteLine("No NickServ auth chosen."); } reader.Close(); } @@ -182,6 +196,21 @@ namespace sendkeys_ss13 } } + private static string[] ReadLine_exception(StreamReader reader) + { + string[] readline = null; + try + { + readline = reader.ReadLine().Split(' '); + } + catch (Exception) + { + readline[3] = "Error, couldn't read all lines of config file! Are you sure the config file has the right format?"; + return readline; + } + return readline; + } + public static void OnChannelMessage(object sender, IrcEventArgs e) { if (e.Data.Nick == Github_bot_name) @@ -260,6 +289,7 @@ namespace sendkeys_ss13 server.Connect(ip); server.Send(PACKETS); Console.WriteLine("- sent ;)"); + ServerReconnectAttempt = 0; output.Close(); Console.WriteLine(); } @@ -269,7 +299,7 @@ namespace sendkeys_ss13 if(ServerReconnectAttempt <= 5) { Console.WriteLine("Server is not available at the moment. Reconnect attempt {0}...", ServerReconnectAttempt); - System.Threading.Thread.Sleep(5000); //Reconnecting after 5 seconds. + System.Threading.Thread.Sleep(15000); //Reconnecting after 15 seconds. SendPacket(output, PACKETS); } else