diff --git a/code/__DEFINES/subsystems.dm b/code/__DEFINES/subsystems.dm index 3313754324..9b49ec2e9d 100644 --- a/code/__DEFINES/subsystems.dm +++ b/code/__DEFINES/subsystems.dm @@ -82,6 +82,7 @@ // Subsystem fire priority, from lowest to highest priority // If the subsystem isn't listed here it's either DEFAULT or PROCESS (if it's a processing subsystem child) +#define FIRE_PRIORITY_PING 10 #define FIRE_PRIORITY_IDLE_NPC 10 #define FIRE_PRIORITY_SERVER_MAINT 10 #define FIRE_PRIORITY_RESEARCH 10 diff --git a/code/controllers/subsystem/ping.dm b/code/controllers/subsystem/ping.dm new file mode 100644 index 0000000000..2cf88bc7ad --- /dev/null +++ b/code/controllers/subsystem/ping.dm @@ -0,0 +1,32 @@ +SUBSYSTEM_DEF(ping) + name = "Ping" + priority = FIRE_PRIORITY_PING + wait = 3 SECONDS + flags = SS_NO_INIT + + var/list/currentrun = list() + +/datum/controller/subsystem/ping/stat_entry() + ..("P:[GLOB.clients.len]") + + +/datum/controller/subsystem/ping/fire(resumed = 0) + if (!resumed) + src.currentrun = GLOB.clients.Copy() + + //cache for sanic speed (lists are references anyways) + var/list/currentrun = src.currentrun + + while (currentrun.len) + var/client/C = currentrun[currentrun.len] + currentrun.len-- + + if (!C || !C.chatOutput || !C.chatOutput.loaded) + if (MC_TICK_CHECK) + return + continue + + // softPang isn't handled anywhere but it'll always reset the opts.lastPang. + C.chatOutput.ehjax_send(data = C.is_afk(29) ? "softPang" : "pang") + if (MC_TICK_CHECK) + return diff --git a/code/modules/goonchat/browserOutput.dm b/code/modules/goonchat/browserOutput.dm index 7fe939ea29..be06f99d61 100644 --- a/code/modules/goonchat/browserOutput.dm +++ b/code/modules/goonchat/browserOutput.dm @@ -105,19 +105,10 @@ GLOBAL_DATUM_INIT(iconCache, /savefile, new("data/iconCache.sav")) //Cache of ic //do not convert to to_chat() SEND_TEXT(owner, "Failed to load fancy chat, reverting to old chat. Certain features won't work.") - pingLoop() - /datum/chatOutput/proc/showChat() winset(owner, "output", "is-visible=false") winset(owner, "browseroutput", "is-disabled=false;is-visible=true") -/datum/chatOutput/proc/pingLoop() - set waitfor = FALSE - - while (owner) - ehjax_send(data = owner.is_afk(29) ? "softPang" : "pang") // SoftPang isn't handled anywhere but it'll always reset the opts.lastPang. - sleep(30) - /datum/chatOutput/proc/ehjax_send(client/C = owner, window = "browseroutput", data) if(islist(data)) data = json_encode(data) diff --git a/tgstation.dme b/tgstation.dme index 2f9498c45b..1267dcd53e 100755 --- a/tgstation.dme +++ b/tgstation.dme @@ -233,6 +233,7 @@ #include "code\controllers\subsystem\parallax.dm" #include "code\controllers\subsystem\pathfinder.dm" #include "code\controllers\subsystem\persistence.dm" +#include "code\controllers\subsystem\ping.dm" #include "code\controllers\subsystem\radiation.dm" #include "code\controllers\subsystem\radio.dm" #include "code\controllers\subsystem\religion.dm"