SShttp + SSdiscord | ASYNCHRONOUS STUFF IN BYOND! (#14762)

* SShttp + SSdiscord | ASYNCHRONOUS STUFF IN BYOND!

* Cleanup

* HTTP Callback example

* Fixes rust instability

* More refactors

* This works

* The sanitizer (Now worth £3000)

* New configs + other stuff

* Lets give this a shot

* Farie changes

* Mentor support

* Farie fixes
This commit is contained in:
AffectedArc07
2020-11-07 11:57:47 -05:00
committed by GitHub
parent dbe4e00f43
commit 56752b0e78
29 changed files with 652 additions and 213 deletions
+5 -5
View File
@@ -12,7 +12,7 @@
var/bantype_pass = 0
var/bantype_str
var/maxadminbancheck //Used to limit the number of active bans of a certein type that each admin can give. Used to protect against abuse or mutiny.
var/announceinirc //When set, it announces the ban in irc. Intended to be a way to raise an alarm, so to speak.
var/announce_in_discord = FALSE //When set, it announces the ban in irc. Intended to be a way to raise an alarm, so to speak.
var/blockselfban //Used to prevent the banning of yourself.
var/kickbannedckey //Defines whether this proc should kick the banned person, if they are connected (if banned_mob is defined).
//some ban types kick players after this proc passes (tempban, permaban), but some are specific to db_ban, so
@@ -46,14 +46,14 @@
duration = -1
bantype_pass = 1
maxadminbancheck = 1
announceinirc = 1
announce_in_discord = TRUE
blockselfban = 1
kickbannedckey = 1
if(BANTYPE_ADMIN_TEMP)
bantype_str = "ADMIN_TEMPBAN"
bantype_pass = 1
maxadminbancheck = 1
announceinirc = 1
announce_in_discord = TRUE
blockselfban = 1
kickbannedckey = 1
@@ -141,8 +141,8 @@
to_chat(usr, "<span class='notice'>Ban saved to database.</span>")
message_admins("[key_name_admin(usr)] has added a [bantype_str] for [ckey] [(job)?"([job])":""] [(duration > 0)?"([duration] minutes)":""] with the reason: \"[reason]\" to the ban database.",1)
if(announceinirc)
send2irc("BAN ALERT","[a_ckey] applied a [bantype_str] on [ckey]")
if(announce_in_discord)
SSdiscord.send2discord_simple(DISCORD_WEBHOOK_ADMIN, "**BAN ALERT** [a_ckey] applied a [bantype_str] on [ckey]")
if(kickbannedckey)
if(banned_mob && banned_mob.client && banned_mob.client.ckey == banckey)
+1
View File
@@ -82,6 +82,7 @@
if(!SSipintel.enabled)
return
// Do not refactor this to use SShttp, because that requires the subsystem to be firing for requests to be made, and this will be triggered before the MC has finished loading
var/list/http[] = world.Export("http://[config.ipintel_domain]/check.php?ip=[ip]&contact=[config.ipintel_email]&format=json&flags=b")
if(http)
+23 -55
View File
@@ -34,62 +34,30 @@ GLOBAL_LIST_INIT(adminhelp_ignored_words, list("unknown","the","a","an","of","mo
else
SStickets.newHelpRequest(src, msg)
//See how many staff are on
var/admin_number_afk = 0
var/list/mentorholders = list()
var/list/modholders = list()
var/list/adminholders = list()
for(var/client/X in GLOB.admins)
if(check_rights(R_ADMIN, 0, X.mob))
if(X.is_afk())
admin_number_afk++
adminholders += X
continue
if(check_rights(R_MOD, 0, X.mob))
modholders += X
continue
if(check_rights(R_MENTOR, 0, X.mob))
mentorholders += X
continue
//show it to the person adminhelping too
to_chat(src, "<span class='boldnotice'>[selected_type]</b>: [msg]</span>")
var/admin_number_present = adminholders.len - admin_number_afk
log_admin("[selected_type]: [key_name(src)]: [msg] - heard by [admin_number_present] non-AFK admins.")
if(admin_number_present <= 0)
if(!admin_number_afk)
send2adminirc("[selected_type] from [key_name(src)]: [msg] - !!No admins online!!")
else
send2adminirc("[selected_type] from [key_name(src)]: [msg] - !!All admins AFK ([admin_number_afk])!!")
else
send2adminirc("[selected_type] from [key_name(src)]: [msg]")
feedback_add_details("admin_verb","AH") //If you are copy-pasting this, ensure the 2nd parameter is unique to the new proc!
return
/proc/send2irc_adminless_only(source, msg, requiredflags = R_BAN)
var/admin_number_total = 0 //Total number of admins
var/admin_number_afk = 0 //Holds the number of admins who are afk
var/admin_number_ignored = 0 //Holds the number of admins without +BAN (so admins who are not really admins)
var/admin_number_decrease = 0 //Holds the number of admins with are afk, ignored or both
for(var/client/X in GLOB.admins)
admin_number_total++
var/invalid = 0
if(requiredflags != 0 && !check_rights_for(X, requiredflags))
admin_number_ignored++
invalid = 1
if(X.is_afk())
admin_number_afk++
invalid = 1
if(X.holder.fakekey)
admin_number_ignored++
invalid = 1
if(invalid)
admin_number_decrease++
var/admin_number_present = admin_number_total - admin_number_decrease //Number of admins who are neither afk nor invalid
if(admin_number_present <= 0)
if(!admin_number_afk && !admin_number_ignored)
send2irc(source, "[msg] - No admins online")
else
send2irc(source, "[msg] - All admins AFK ([admin_number_afk]/[admin_number_total]) or skipped ([admin_number_ignored]/[admin_number_total])")
return admin_number_present
switch(selected_type)
if("Adminhelp")
//See how many staff are on
var/list/admincount = staff_countup(R_BAN)
var/active_admins = admincount[1]
log_admin("[selected_type]: [key_name(src)]: [msg] - heard by [active_admins] non-AFK admins.")
SSdiscord.send2discord_simple_noadmins("[selected_type] from [key_name(src)]: [msg]", check_send_always = TRUE)
if("Mentorhelp")
var/alerttext
var/list/mentorcount = staff_countup(R_MENTOR)
var/active_mentors = mentorcount[1]
var/inactive_mentors = mentorcount[3]
if(active_mentors <= 0)
if(inactive_mentors > 0)
alerttext = " | **ALL MENTORS AFK**"
else
alerttext = " | **NO MENTORS ONLINE**"
log_admin("[selected_type]: [key_name(src)]: [msg] - heard by [active_mentors] non-AFK mentors.")
SSdiscord.send2discord_simple(DISCORD_WEBHOOK_MENTOR, "[key_name(src)]: [msg][alerttext]")
+16 -10
View File
@@ -211,34 +211,40 @@
i.addResponse(src, msg)
return
/client/proc/cmd_admin_irc_pm()
/client/proc/cmd_admin_discord_pm()
if(prefs.muted & MUTE_ADMINHELP)
to_chat(src, "<span class='danger'>Error: Private-Message: You are unable to use PM-s (muted).</span>")
to_chat(src, "<span class='danger'>Error: Private-Message: You are unable to use PMs (muted).</span>")
return
var/msg = clean_input("Message:", "Private message to admins on IRC / 400 character limit", , src)
if(last_discord_pm_time > world.time)
to_chat(usr, "<span class='warning'>Please wait [(last_discord_pm_time - world.time)/10] seconds, or for a reply, before sending another PM to Discord.</span>")
return
// We only allow PMs once every 10 seconds, othewrise the channel can get spammed very quickly
last_discord_pm_time = world.time + 10 SECONDS
var/msg = clean_input("Message:", "Private message to admins on Discord / 400 character limit", , src)
if(!msg)
return
sanitize(msg)
if(length(msg) > 400) // TODO: if message length is over 400, divide it up into seperate messages, the message length restriction is based on IRC limitations. Probably easier to do this on the bots ends.
if(length(msg) > 400) // Dont want them super spamming
to_chat(src, "<span class='warning'>Your message was not sent because it was more then 400 characters find your message below for ease of copy/pasting</span>")
to_chat(src, "<span class='notice'>[msg]</span>")
return
send2adminirc("PlayerPM from [key_name(src)]: [html_decode(msg)]")
SSdiscord.send2discord_simple(DISCORD_WEBHOOK_ADMIN, "PM from [key_name(src)]: [html_decode(msg)]")
to_chat(src, "<span class='pmsend'>IRC PM to-<b>IRC-Admins</b>: [msg]</span>")
to_chat(src, "<span class='pmsend'>PM to-<b>Discord Admins</b>: [msg]</span>")
log_admin("PM: [key_name(src)]->IRC: [msg]")
log_admin("PM: [key_name(src)]->Discord: [msg]")
for(var/client/X in GLOB.admins)
if(X == src)
continue
if(check_rights(R_ADMIN|R_MOD|R_MENTOR, 0, X.mob))
to_chat(X, "<B><span class='pmsend'>PM: [key_name(src, TRUE, 0)]-&gt;IRC-Admins:</B> <span class='notice'>[msg]</span></span>")
if(check_rights(R_ADMIN, 0, X.mob))
to_chat(X, "<span class='pmsend'><b>PM: [key_name_admin(src)]-&gt;Discord Admins:</b> <span class='notice'>[msg]</span></span>")
/client/verb/open_pms_ui()
set name = "My PMs"
+8 -3
View File
@@ -43,9 +43,6 @@
// comment out the line below when debugging locally to enable the options & messages menu
//control_freak = 1
var/received_irc_pm = -99999
var/irc_admin //IRC admin that spoke with them last.
var/mute_irc = 0
var/ssd_warning_acknowledged = FALSE
////////////////////////////////////
@@ -99,3 +96,11 @@
var/byondacc_date
/// Days since the client's BYOND account was created
var/byondacc_age = 0
// Do not attempt to merge these vars together. They are for different things
/// Last world.time that a PM was send to discord by a player
var/last_discord_pm_time = 0
/// Last world/time that a PM was sent to the player by an admin
var/received_discord_pm = -99999 // Yes this super low number is intentional
+10 -9
View File
@@ -113,14 +113,14 @@
cmd_admin_pm(ckey_txt, null, href_list["type"])
return
if(href_list["irc_msg"])
if(!holder && received_irc_pm < world.time - 6000) //Worse they can do is spam IRC for 10 minutes
to_chat(usr, "<span class='warning'>You are no longer able to use this, it's been more then 10 minutes since an admin on IRC has responded to you</span>")
if(href_list["discord_msg"])
if(!holder && received_discord_pm < world.time - 6000) // Worse they can do is spam discord for 10 minutes
to_chat(usr, "<span class='warning'>You are no longer able to use this, it's been more then 10 minutes since an admin on Discord has responded to you</span>")
return
if(mute_irc)
to_chat(usr, "<span class='warning'You cannot use this as your client has been muted from sending messages to the admins on IRC</span>")
if(prefs.muted & MUTE_ADMINHELP)
to_chat(usr, "<span class='warning'>You cannot use this as your client has been muted from sending messages to the admins on Discord</span>")
return
cmd_admin_irc_pm()
cmd_admin_discord_pm()
return
@@ -561,7 +561,7 @@
var/watchreason = check_watchlist(ckey)
if(watchreason)
message_admins("<font color='red'><B>Notice: </B></font><font color='blue'>[key_name_admin(src)] is on the watchlist and has just connected - Reason: [watchreason]</font>")
send2irc(config.admin_notify_irc, "Watchlist - [key_name(src)] is on the watchlist and has just connected - Reason: [watchreason]")
SSdiscord.send2discord_simple_noadmins("**\[Watchlist]** [key_name(src)] is on the watchlist and has just connected - Reason: [watchreason]")
//Just the standard check to see if it's actually a number
@@ -760,7 +760,7 @@
if(!cidcheck_failedckeys[ckey])
message_admins("<span class='adminnotice'>[key_name(src)] has been detected as using a CID randomizer. Connection rejected.</span>")
send2irc(config.cidrandomizer_irc, "[key_name(src)] has been detected as using a CID randomizer. Connection rejected.")
SSdiscord.send2discord_simple_noadmins("[key_name(src)] has been detected as using a CID randomizer. Connection rejected.")
cidcheck_failedckeys[ckey] = TRUE
note_randomizer_user()
@@ -773,7 +773,7 @@
if(cidcheck_failedckeys[ckey])
// Atonement
message_admins("<span class='adminnotice'>[key_name_admin(src)] has been allowed to connect after showing they removed their cid randomizer</span>")
send2irc(config.cidrandomizer_irc, "[key_name(src)] has been allowed to connect after showing they removed their cid randomizer.")
SSdiscord.send2discord_simple_noadmins("[key_name(src)] has been allowed to connect after showing they removed their cid randomizer.")
cidcheck_failedckeys -= ckey
if (cidcheck_spoofckeys[ckey])
message_admins("<span class='adminnotice'>[key_name_admin(src)] has been allowed to connect after appearing to have attempted to spoof a cid randomizer check because it <i>appears</i> they aren't spoofing one this time</span>")
@@ -988,6 +988,7 @@
* Returns the data in a parsed, associative list
*/
/client/proc/retrieve_byondacc_data()
// Do not refactor this to use SShttp, because that requires the subsystem to be firing for requests to be made, and this will be triggered before the MC has finished loading
var/list/http[] = world.Export("http://www.byond.com/members/[ckey]?format=text")
if(http)
var/status = text2num(http["STATUS"])
-21
View File
@@ -1,21 +0,0 @@
/proc/send2irc(var/channel, var/msg, var/lesser_sanitize = FALSE)
if(config.use_irc_bot && config.irc_bot_host.len)
for(var/IP in config.irc_bot_host)
spawn(0)
if(lesser_sanitize == 7355608) // Super random number because this could be bad if done accidentally
// Runs sanitization but allows <> and // (Needed for discord)
ext_python("ircbot_message.py", "[config.comms_password] [IP] [channel] [not_as_paranoid_sanitize(msg)]")
else
// I have no means of trusting you, cmd
ext_python("ircbot_message.py", "[config.comms_password] [IP] [channel] [paranoid_sanitize(msg)]")
return
/proc/send2mainirc(var/msg, var/lesser_sanitize = FALSE)
if(config.main_irc)
send2irc(config.main_irc, msg, lesser_sanitize)
return
/proc/send2adminirc(var/msg)
if(config.admin_irc)
send2irc(config.admin_irc, msg)
return
-9
View File
@@ -1,9 +0,0 @@
/proc/ext_python(var/script, var/args, var/scriptsprefix = 1)
if(scriptsprefix) script = "scripts/" + script
if(world.system_type == MS_WINDOWS)
script = replacetext(script, "/", "\\")
var/command = GLOB.python_path + " " + script + " " + args
shell("[command]")
return
+1 -1
View File
@@ -15,7 +15,7 @@
message_admins("Admin logout: [key_name_admin(src)]")
var/list/admincounter = staff_countup(R_BAN)
if(admincounter[1] == 0) // No active admins
send2irc(config.admin_notify_irc, "[key_name(src)] logged out - No active admins, [admincounter[2]] non-admin staff, [admincounter[3]] inactive staff.")
SSdiscord.send2discord_simple(DISCORD_WEBHOOK_ADMIN, "[key_name(src)] logged out - No active admins, [admincounter[2]] non-admin staff, [admincounter[3]] inactive staff.")
..()
update_morgue()
@@ -121,13 +121,12 @@
aw_emerg = status_adminwarn_check(SUPERMATTER_EMERGENCY, aw_emerg, "CRIT: Supermatter integrity is below 50%!<A HREF='?_src_=holder;adminplayerobservecoodjump=1;X=[x];Y=[y];Z=[z]'>(JMP)</a>.", FALSE)
aw_delam = status_adminwarn_check(SUPERMATTER_DELAMINATING, aw_delam, "CRIT: Supermatter is delaminating!<A HREF='?_src_=holder;adminplayerobservecoodjump=1;X=[x];Y=[y];Z=[z]'>(JMP)</a>.", TRUE)
/obj/machinery/power/supermatter_shard/proc/status_adminwarn_check(var/min_status, var/current_state, var/message, var/send_to_irc = FALSE)
/obj/machinery/power/supermatter_shard/proc/status_adminwarn_check(min_status, current_state, message)
var/status = get_status()
if(status >= min_status)
if(!current_state)
log_and_message_admins(message)
if(send_to_irc)
send2adminirc(message)
SSdiscord.send2discord_simple_noadmins(message)
return TRUE
else
return FALSE
+1 -1
View File
@@ -231,7 +231,7 @@
return
mode = SHUTTLE_DOCKED
timer = world.time
send2irc("Server", "The Emergency Shuttle has docked with the station.")
SSdiscord.send2discord_simple(DISCORD_WEBHOOK_PRIMARY, "The Emergency Shuttle has docked with the station.")
emergency_shuttle_docked.Announce("The Emergency Shuttle has docked with the station. You have [timeLeft(600)] minutes to board the Emergency Shuttle.")
/*