From b4b21842dbe49628ca4f2e81d65f3ab807a3f8e2 Mon Sep 17 00:00:00 2001 From: Shadowlight213 Date: Tue, 12 Jul 2016 15:40:18 -0800 Subject: [PATCH] Sending adminpms from IRC. (#19097) * Sending adminpms from IRC. * added limit of 2 messages sent to irc per irc message recieved. --- code/modules/admin/verbs/adminpm.dm | 188 ++++++++++++++++++-------- code/modules/client/client_defines.dm | 1 + code/world.dm | 8 ++ 3 files changed, 144 insertions(+), 53 deletions(-) diff --git a/code/modules/admin/verbs/adminpm.dm b/code/modules/admin/verbs/adminpm.dm index af50934e94b..1c705724097 100644 --- a/code/modules/admin/verbs/adminpm.dm +++ b/code/modules/admin/verbs/adminpm.dm @@ -1,3 +1,6 @@ +#define IRCREPLYCOUNT 2 + + //allows right clicking mobs to send an admin PM to their client, forwards the selected mob's client to cmd_admin_pm /client/proc/cmd_admin_pm_context(mob/M in mob_list) set category = null @@ -63,90 +66,169 @@ return var/client/C + var/irc = 0 if(istext(whom)) if(cmptext(copytext(whom,1,2),"@")) whom = findStealthKey(whom) - C = directory[whom] + if(whom == "IRCKEY") + irc = 1 + else + C = directory[whom] else if(istype(whom,/client)) C = whom - if(!C) - if(holder) - src << "Error: Admin-PM: Client not found." - else - adminhelp(msg) //admin we are replying to left. adminhelp instead - return - - //get message text, limit it's length.and clean/escape html - if(!msg) - msg = input(src,"Message:", "Private message to [key_name(C, 0, 0)]") as text|null + if(irc) + if(!ircreplyamount) //to prevent people from spamming irc + return + if(!msg) + msg = input(src,"Message:", "Private message to Administrator") as text|null if(!msg) return + if(holder) + src << "Error: Use the admin IRC channel, nerd." + return + + + else if(!C) if(holder) src << "Error: Admin-PM: Client not found." else - adminhelp(msg) //admin we are replying to has vanished, adminhelp instead + adminhelp(msg) //admin we are replying to left. adminhelp instead return + //get message text, limit it's length.and clean/escape html + if(!msg) + msg = input(src,"Message:", "Private message to [key_name(C, 0, 0)]") as text|null + + if(!msg) + return + if(!C) + if(holder) + src << "Error: Admin-PM: Client not found." + else + adminhelp(msg) //admin we are replying to has vanished, adminhelp instead + return + if (src.handle_spam_prevention(msg,MUTE_ADMINHELP)) return //clean the message if it's not sent by a high-rank admin - if(!check_rights(R_SERVER|R_DEBUG,0)) + if(!check_rights(R_SERVER|R_DEBUG,0)||irc)//no sending html to the poor bots msg = sanitize(copytext(msg,1,MAX_MESSAGE_LEN)) if(!msg) return var/rawmsg = msg + if(holder) msg = emoji_parse(msg) var/keywordparsedmsg = keywords_lookup(msg) - if(C.holder) - if(holder) //both are admins - C << "Admin PM from-[key_name(src, C, 1)]: [keywordparsedmsg]" - src << "Admin PM to-[key_name(C, src, 1)]: [keywordparsedmsg]" - - else //recipient is an admin but sender is not - C << "Reply PM from-[key_name(src, C, 1)]: [keywordparsedmsg]" - src << "PM to-Admins: [msg]" - - //play the recieving admin the adminhelp sound (if they have them enabled) - if(C.prefs.toggles & SOUND_ADMINHELP) - C << 'sound/effects/adminhelp.ogg' - + if(irc) + src << "PM to-Admins: [rawmsg]" + ircreplyamount-- + send2irc("Reply: [ckey]",rawmsg) else - if(holder) //sender is an admin but recipient is not. Do BIG RED TEXT - C << "-- Administrator private message --" - C << "Admin PM from-[key_name(src, C, 0)]: [msg]" - C << "Click on the administrator's name to reply." - src << "Admin PM to-[key_name(C, src, 1)]: [msg]" + if(C.holder) + if(holder) //both are admins + C << "Admin PM from-[key_name(src, C, 1)]: [keywordparsedmsg]" + src << "Admin PM to-[key_name(C, src, 1)]: [keywordparsedmsg]" - //always play non-admin recipients the adminhelp sound - C << 'sound/effects/adminhelp.ogg' + else //recipient is an admin but sender is not + C << "Reply PM from-[key_name(src, C, 1)]: [keywordparsedmsg]" + src << "PM to-Admins: [msg]" - //AdminPM popup for ApocStation and anybody else who wants to use it. Set it with POPUP_ADMIN_PM in config.txt ~Carn - if(config.popup_admin_pm) - spawn() //so we don't hold the caller proc up - var/sender = src - var/sendername = key - var/reply = input(C, msg,"Admin PM from-[sendername]", "") as text|null //show message and await a reply - if(C && reply) - if(sender) - C.cmd_admin_pm(sender,reply) //sender is still about, let's reply to them - else - adminhelp(reply) //sender has left, adminhelp instead - return + //play the recieving admin the adminhelp sound (if they have them enabled) + if(C.prefs.toggles & SOUND_ADMINHELP) + C << 'sound/effects/adminhelp.ogg' - else //neither are admins - src << "Error: Admin-PM: Non-admin to non-admin PM communication is forbidden." - return + else + if(holder) //sender is an admin but recipient is not. Do BIG RED TEXT + C << "-- Administrator private message --" + C << "Admin PM from-[key_name(src, C, 0)]: [msg]" + C << "Click on the administrator's name to reply." + src << "Admin PM to-[key_name(C, src, 1)]: [msg]" - log_admin("PM: [key_name(src)]->[key_name(C)]: [rawmsg]") + //always play non-admin recipients the adminhelp sound + C << 'sound/effects/adminhelp.ogg' - //we don't use message_admins here because the sender/receiver might get it too - for(var/client/X in admins) - if(X.key!=key && X.key!=C.key) //check client/X is an admin and isn't the sender or recipient - X << "PM: [key_name(src, X, 0)]->[key_name(C, X, 0)]: \blue [keywordparsedmsg]" //inform X + //AdminPM popup for ApocStation and anybody else who wants to use it. Set it with POPUP_ADMIN_PM in config.txt ~Carn + if(config.popup_admin_pm) + spawn() //so we don't hold the caller proc up + var/sender = src + var/sendername = key + var/reply = input(C, msg,"Admin PM from-[sendername]", "") as text|null //show message and await a reply + if(C && reply) + if(sender) + C.cmd_admin_pm(sender,reply) //sender is still about, let's reply to them + else + adminhelp(reply) //sender has left, adminhelp instead + return + + else //neither are admins + src << "Error: Admin-PM: Non-admin to non-admin PM communication is forbidden." + return + + if(irc) + log_admin("PM: [key_name(src)]->IRC: [rawmsg]") + for(var/client/X in admins) + X << "PM: [key_name(src, X, 0)]->IRC: \blue [keywordparsedmsg]" //inform X + else + log_admin("PM: [key_name(src)]->[key_name(C)]: [rawmsg]") + //we don't use message_admins here because the sender/receiver might get it too + for(var/client/X in admins) + if(X.key!=key && X.key!=C.key) //check client/X is an admin and isn't the sender or recipient + X << "PM: [key_name(src, X, 0)]->[key_name(C, X, 0)]: \blue [keywordparsedmsg]" //inform X + + + + +/proc/IrcPm(target,msg,sender) + + var/client/C = directory[target] + + var/static/stealthkey + + if(!C) + return "No client" + + if(!stealthkey) + stealthkey = GenIrcStealthKey() + + msg = sanitize(copytext(msg,1,MAX_MESSAGE_LEN)) + if(!msg) + return "No message" + + message_admins("IRC message from [sender] to [key_name_admin(C)] : [msg]") + log_admin("IRC PM: [sender] -> [key_name(C)] : [msg]") + msg = emoji_parse(msg) + + C << "-- Administrator private message --" + C << "Admin PM from-Administrator: [msg]" + C << "Click on the administrator's name to reply." + + //always play non-admin recipients the adminhelp sound + C << 'sound/effects/adminhelp.ogg' + + C.ircreplyamount = IRCREPLYCOUNT + + return "Message Successful" + + + +/proc/GenIrcStealthKey() + var/num = (rand(0,1000)) + var/i = 0 + while(i == 0) + i = 1 + for(var/P in stealthminID) + if(num == stealthminID[P]) + num++ + i = 0 + var/stealth = "@[num2text(num)]" + stealthminID["IRCKEY"] = stealth + return stealth + +#undef IRCREPLYCOUNT \ No newline at end of file diff --git a/code/modules/client/client_defines.dm b/code/modules/client/client_defines.dm index 7443a4a17ed..c31d2afb9af 100644 --- a/code/modules/client/client_defines.dm +++ b/code/modules/client/client_defines.dm @@ -10,6 +10,7 @@ var/jobbancache = null //Used to cache this client's jobbans to save on DB queries var/last_message = "" //Contains the last message sent by this client - used to protect against copy-paste spamming. var/last_message_count = 0 //contins a number of how many times a message identical to last_message was sent. + var/ircreplyamount = 0 ///////// //OTHER// diff --git a/code/world.dm b/code/world.dm index 2b70a86cea8..83454220e28 100644 --- a/code/world.dm +++ b/code/world.dm @@ -163,6 +163,14 @@ var/last_irc_status = 0 for(var/obj/machinery/computer/communications/CM in machines) CM.overrideCooldown() + else if("adminmsg" in input) + if(!key_valid) + return "Bad Key" + else + return IrcPm(input["adminmsg"],input["msg"],input["sender"]) + + + /world/Reboot(var/reason, var/feedback_c, var/feedback_r, var/time) if (reason == 1) //special reboot, do none of the normal stuff if (usr)