Skip to content

Commit

Permalink
[Admin] Makes the lag switch subsystem work (#22958)
Browse files Browse the repository at this point in the history
* Lag

* Moves the subsystem file

* Fixes that one line
  • Loading branch information
Oblisk234 authored Jan 14, 2025
1 parent cf228af commit cd1aca6
Show file tree
Hide file tree
Showing 10 changed files with 214 additions and 7 deletions.
3 changes: 3 additions & 0 deletions code/__HELPERS/icons.dm
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,10 @@ GLOBAL_DATUM_INIT(dummySave, /savefile, new("tmp/dummySave.sav")) //Cache of ico

var/key
var/icon/I = thing
var/mob/target_mob = target

if(SSlag_switch.measures[DISABLE_USR_ICON2HTML] && !HAS_TRAIT(target_mob, TRAIT_BYPASS_MEASURES))
return
if (!target)
return
if (target == world)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ SUBSYSTEM_DEF(lag_switch)
for(var/mob/user as anything in GLOB.player_list)
if(user.stat == DEAD && !user.client?.holder)
GLOB.keyloop_list -= user
deadchat_broadcast(span_big("To increase performance Observer freelook is now disabled. Please use Orbit, Teleport, and Jump to look around."), message_type = DEADCHAT_ANNOUNCEMENT)
deadchat_broadcast(span_big("To increase performance, Observer freelook is now disabled. Please use Orbit, Teleport, and Jump to look around."), message_type = DEADCHAT_ANNOUNCEMENT)
else
GLOB.keyloop_list |= GLOB.player_list
deadchat_broadcast("Observer freelook has been re-enabled. Enjoy your wooshing.", message_type = DEADCHAT_ANNOUNCEMENT)
Expand All @@ -102,15 +102,32 @@ SUBSYSTEM_DEF(lag_switch)
continue
if(!ghost.client.holder && ghost.client.view_size.getView() != ghost.client.view_size.default)
ghost.client.view_size.resetToDefault()
deadchat_broadcast(span_big("To increase performance, Observer custom view range/T-ray views are now disabled."), message_type = DEADCHAT_ANNOUNCEMENT)
else
deadchat_broadcast("Observer custom view range/T-ray views are now re-enabled. Enjoy your wooshing.", message_type = DEADCHAT_ANNOUNCEMENT)
if(DISABLE_RUNECHAT)
if(state)
to_chat(world, span_boldannounce("Runechat has been disabled for performance concerns."))
else
to_chat(world, span_boldannounce("Runechat has been re-enabled."))
if(DISABLE_USR_ICON2HTML)
if(state)
to_chat(world, span_boldannounce("Icon2html has been disabled for performance concerns."))
else
to_chat(world, span_boldannounce("Icon2html has been re-enabled."))
if(DISABLE_NON_OBSJOBS)
var/datum/admins/holder = new(usr)
holder.toggleenter() //This does the same thing, no need for duplicate proc
world.update_status()
/* Commented out since we don't have an implementation of this and I haven't figured out an alternative yet
if(SLOWMODE_SAY)
if(state)
to_chat(world, span_boldannounce("Slowmode for IC/dead chat has been enabled with [slowmode_cooldown/10] seconds between messages."))
else
for(var/client/C as anything in GLOB.clients)
COOLDOWN_RESET(C, say_slowmode)
to_chat(world, span_boldannounce("Slowmode for IC/dead chat has been disabled by an admin."))
if(DISABLE_NON_OBSJOBS)
world.update_status()
*/
if(DISABLE_PARALLAX)
if (state)
to_chat(world, span_boldannounce("Parallax has been disabled for performance concerns."))
Expand Down
3 changes: 2 additions & 1 deletion code/datums/chatmessage.dm
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
stack_trace("/datum/chatmessage created with [isnull(owner) ? "null" : "invalid"] mob owner")
qdel(src)
return
INVOKE_ASYNC(src, PROC_REF(generate_image), text, target, owner, language, extra_classes, lifespan)
if(!SSlag_switch.measures[DISABLE_RUNECHAT] && !HAS_TRAIT(owner, TRAIT_BYPASS_MEASURES))
INVOKE_ASYNC(src, PROC_REF(generate_image), text, target, owner, language, extra_classes, lifespan)

/datum/chatmessage/Destroy()
if (owned_by)
Expand Down
3 changes: 3 additions & 0 deletions code/datums/elements/footstep.dm
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@
///Prepares a footstep for living mobs. Determines if it should get played. Returns the turf it should get played on. Note that it is always a /turf/open
/datum/element/footstep/proc/prepare_step(mob/living/source)
var/turf/open/turf = get_turf(source)
if(SSlag_switch.measures[DISABLE_FOOTSTEPS] && !HAS_TRAIT(source, TRAIT_BYPASS_MEASURES))
return

if(!istype(turf))
return

Expand Down
3 changes: 2 additions & 1 deletion code/modules/admin/admin_verbs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ GLOBAL_PROTECT(admin_verbs_server)
/client/proc/mentor_memo, // YOGS - something stupid about "Mentor memos"
/client/proc/release_queue, // Yogs -- Adds some queue-manipulation verbs
/client/proc/toggle_cdn,
/client/proc/set_next_minetype
/client/proc/set_next_minetype,
/client/proc/lag_switch_panel
)
GLOBAL_LIST_INIT(admin_verbs_debug, world.AVerbsDebug())
GLOBAL_PROTECT(admin_verbs_debug)
Expand Down
69 changes: 69 additions & 0 deletions code/modules/admin/verbs/lag_switch.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/client/proc/lag_switch_panel()
set name = "Lag Switch Panel"
set category = "Server"
if(!check_rights(R_SERVER))
return
var/datum/lag_switch_menu/tgui = new(usr)
tgui.ui_interact(usr)

/datum/lag_switch_menu
var/client/holder

/datum/lag_switch_menu/New(user)
if(istype(user, /client))
var/client/user_client = user
holder = user_client
else
var/mob/user_mob = user
holder = user_mob.client

/datum/lag_switch_menu/ui_interact(mob/user, datum/tgui/ui)
ui = SStgui.try_update_ui(user, src, ui)
if(!ui)
ui = new(user, src, "LagSwitchPanel")
ui.open()
ui.set_autoupdate(TRUE)

/datum/lag_switch_menu/ui_state(mob/user)
return GLOB.admin_state

/datum/lag_switch_menu/ui_close()
qdel(src)

/datum/lag_switch_menu/ui_data(mob/user)
var/list/data = list()
data["dead_keyloop"] = SSlag_switch.measures[DISABLE_DEAD_KEYLOOP]
data["ghost_zoom_tray"] = SSlag_switch.measures[DISABLE_GHOST_ZOOM_TRAY]
data["runechat"] = SSlag_switch.measures[DISABLE_RUNECHAT]
data["icon2html"] = SSlag_switch.measures[DISABLE_USR_ICON2HTML]
data["observerjobs"] = SSlag_switch.measures[DISABLE_NON_OBSJOBS]
data["slowmodesay"] = SSlag_switch.measures[SLOWMODE_SAY]
data["parallax"] = SSlag_switch.measures[DISABLE_PARALLAX]
data["footsteps"] = SSlag_switch.measures[DISABLE_FOOTSTEPS]
return data

/datum/lag_switch_menu/ui_act(action, list/params)
. = ..()
if(.)
return
switch(action)
if("toggle_keyloop")
SSlag_switch.measures[DISABLE_DEAD_KEYLOOP] ? SSlag_switch.set_measure(DISABLE_DEAD_KEYLOOP, 0) : SSlag_switch.set_measure(DISABLE_DEAD_KEYLOOP, 1)
if("toggle_zoomtray")
SSlag_switch.measures[DISABLE_GHOST_ZOOM_TRAY] ? SSlag_switch.set_measure(DISABLE_GHOST_ZOOM_TRAY, 0) : SSlag_switch.set_measure(DISABLE_GHOST_ZOOM_TRAY, 1)
if("toggle_runechat")
SSlag_switch.measures[DISABLE_RUNECHAT] ? SSlag_switch.set_measure(DISABLE_RUNECHAT, 0) : SSlag_switch.set_measure(DISABLE_RUNECHAT, 1)
if("toggle_icon2html")
SSlag_switch.measures[DISABLE_USR_ICON2HTML] ? SSlag_switch.set_measure(DISABLE_USR_ICON2HTML, 0) : SSlag_switch.set_measure(DISABLE_USR_ICON2HTML, 1)
if("toggle_observerjobs")
SSlag_switch.measures[DISABLE_NON_OBSJOBS] ? SSlag_switch.set_measure(DISABLE_NON_OBSJOBS, 0) : SSlag_switch.set_measure(DISABLE_NON_OBSJOBS, 1)
if("toggle_slowmodesay")
SSlag_switch.measures[SLOWMODE_SAY] ? SSlag_switch.set_measure(SLOWMODE_SAY, 0) : SSlag_switch.set_measure(SLOWMODE_SAY, 1)
if("toggle_parallax")
SSlag_switch.measures[DISABLE_PARALLAX] ? SSlag_switch.set_measure(DISABLE_PARALLAX, 0) : SSlag_switch.set_measure(DISABLE_PARALLAX, 1)
if("toggle_footsteps")
SSlag_switch.measures[DISABLE_FOOTSTEPS] ? SSlag_switch.set_measure(DISABLE_FOOTSTEPS, 0) : SSlag_switch.set_measure(DISABLE_FOOTSTEPS, 1)
if("enable_all")
SSlag_switch.set_all_measures(1)
if("disable_all")
SSlag_switch.set_all_measures(0)
8 changes: 7 additions & 1 deletion code/modules/mob/dead/observer/observer.dm
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,11 @@ This is the proc mobs get to turn into a ghost. Forked from ghostize due to comp
set name = "View Range"
set desc = "Change your view range."

if(SSlag_switch.measures[DISABLE_GHOST_ZOOM_TRAY] && !is_admin(usr))
to_chat(usr, span_warning("Observer view range is disabled due to performance concerns."))
return
//yogs start -- Divert this verb to the admin variant if this guy has it
if(check_rights(R_ADMIN,FALSE) && hascall(usr.client,"toggle_view_range"))
if(is_admin(usr) && hascall(usr.client,"toggle_view_range"))
call(usr.client,"toggle_view_range")()
return
//yogs end
Expand Down Expand Up @@ -993,6 +996,9 @@ This is the proc mobs get to turn into a ghost. Forked from ghostize due to comp
set category = "Ghost"
set name = "T-ray view"
set desc = "Toggles a view of sub-floor objects"
if(SSlag_switch.measures[DISABLE_GHOST_ZOOM_TRAY] && !is_admin(usr))
to_chat(usr, span_warning("Observer T-ray view is disabled due to performance concerns."))
return

var/static/t_ray_view = FALSE
t_ray_view = !t_ray_view
Expand Down
2 changes: 2 additions & 0 deletions code/modules/mob/mob_movement.dm
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@
return FALSE //This is sota the goto stop mobs from moving var
if(mob.control_object)
return Move_object(direct)
if(mob.stat == DEAD && (SSlag_switch.measures[DISABLE_DEAD_KEYLOOP] && !is_admin(mob)))
return FALSE
if(!isliving(mob))
return mob.Move(n, direct)
if(mob.stat == DEAD)
Expand Down
104 changes: 104 additions & 0 deletions tgui/packages/tgui/interfaces/LagSwitchPanel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { useBackend } from "../backend";
import { Button, Flex, Section } from "../components";
import { Window } from "../layouts";

type Data = {
dead_keyloop: boolean;
ghost_zoom_tray: boolean;
runechat: boolean;
icon2html: boolean;
observerjobs: boolean;
slowmodesay: boolean;
parallax: boolean;
footsteps: boolean;
}

/* Credit to Xoxeyos who ported a port of the Ghost Pool Protection interface (PR #11139), which this follows the same design for the most part. */
export const LagSwitchPanel = (props, context) => {
const { act, data } = useBackend<Data>(context);
const { dead_keyloop, ghost_zoom_tray, runechat, icon2html, observerjobs, slowmodesay, parallax, footsteps } = data;
return (
<Window title="Lag Switch Panel" width={400} height={270}>
<Window.Content>
<Flex>
<Flex.Item grow={1}>
<Section title="Options"
buttons={
<>
<Button
color="good"
icon="plus-circle"
content="Enable Everything"
onClick={() => act("enable_all")} />
<Button
color="bad"
icon="minus-circle"
content="Disable Everything"
onClick={() => act("disable_all")} />
</>
}>
<Button
fluid
textAlign="center"
color={dead_keyloop ? "good" : "bad"}
icon="ghost"
content="Disable ghost freelook (Staff exempted)"
onClick={() => act("toggle_keyloop")} />
<Button
fluid
textAlign="center"
color={ghost_zoom_tray ? "good" : "bad"}
icon="magnifying-glass"
content="Disable ghost view/T-ray (Staff exempted)"
onClick={() => act("toggle_zoomtray")} />
<Button
fluid
textAlign="center"
color={runechat ? "good" : "bad"}
icon="comment"
content="Disable runechat"
onClick={() => act("toggle_runechat")} />
<Button
fluid
textAlign="center"
color={icon2html ? "good" : "bad"}
icon="image"
content="Disable icon2html"
onClick={() => act("toggle_icon2html")} />
<Button
fluid
textAlign="center"
color={observerjobs ? "good" : "bad"}
icon="hammer"
content="Prevent new player joining"
onClick={() => act("toggle_observerjobs")} />
{/* Commented out since we don't have an implementation of this and I haven't figured out an alternative yet
<Button
fluid
textAlign="center"
color={slowmodesay ? "good" : "bad"}
icon="stopwatch"
content="Enable IC/dsay slowmode"
onClick={() => act("toggle_slowmodesay")} />
*/}
<Button
fluid
textAlign="center"
color={parallax ? "good" : "bad"}
icon="map"
content="Disable parallax"
onClick={() => act("toggle_parallax")} />
<Button
fluid
textAlign="center"
color={footsteps ? "good" : "bad"}
icon="shoe-prints"
content="Disable footsteps"
onClick={() => act("toggle_footsteps")} />
</Section>
</Flex.Item>
</Flex>
</Window.Content>
</Window>
);
};
3 changes: 2 additions & 1 deletion yogstation.dme
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,6 @@
#include "code\controllers\controller.dm"
#include "code\controllers\failsafe.dm"
#include "code\controllers\globals.dm"
#include "code\controllers\lag_switch.dm"
#include "code\controllers\master.dm"
#include "code\controllers\subsystem.dm"
#include "code\controllers\configuration\config_entry.dm"
Expand Down Expand Up @@ -447,6 +446,7 @@
#include "code\controllers\subsystem\input.dm"
#include "code\controllers\subsystem\ipintel.dm"
#include "code\controllers\subsystem\job.dm"
#include "code\controllers\subsystem\lag_switch.dm"
#include "code\controllers\subsystem\language.dm"
#include "code\controllers\subsystem\lighting.dm"
#include "code\controllers\subsystem\machines.dm"
Expand Down Expand Up @@ -1716,6 +1716,7 @@
#include "code\modules\admin\verbs\ghost_pool_protection.dm"
#include "code\modules\admin\verbs\hiddenprints.dm"
#include "code\modules\admin\verbs\individual_logging.dm"
#include "code\modules\admin\verbs\lag_switch.dm"
#include "code\modules\admin\verbs\machine_upgrade.dm"
#include "code\modules\admin\verbs\manipulate_organs.dm"
#include "code\modules\admin\verbs\map_template_loadverb.dm"
Expand Down

0 comments on commit cd1aca6

Please sign in to comment.