Skip to content

Commit

Permalink
Add reboot countdown to stat panel (#88438)
Browse files Browse the repository at this point in the history
Rewrite ticker `Reboot` proc slightly to use a timer and callback for
the delay before the reboot, tracks this timer in the stat panel for
players to see. Also adds a verb to cancel a pending reboot independent
of the delay round end verb.

It's nice to be able to see exactly how much time is left until the
server restarts, and it's even nicer to see that the round end has been
delayed when the "admin has delayed round end" message gets buried in a
fast moving chat.

:cl:
qol: The time until the server reboots is now visible in the status tab.
admin: Added a cancel reboot verb to the server tab.
/:cl:
  • Loading branch information
TealSeer authored and Absolucy committed Feb 11, 2025
1 parent b739536 commit f291e37
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
9 changes: 9 additions & 0 deletions code/controllers/subsystem/statpanel.dm
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ SUBSYSTEM_DEF(statpanels)
var/ETA = SSshuttle.emergency.getModeStr()
if(ETA)
global_data += "[ETA] [SSshuttle.emergency.getTimerStr()]"

if(SSticker.reboot_timer)
var/reboot_time = timeleft(SSticker.reboot_timer)
if(reboot_time)
global_data += "Reboot: [DisplayTimeText(reboot_time, 1)]"
// admin must have delayed round end
else if(SSticker.ready_for_reboot)
global_data += "Reboot: DELAYED"

src.currentrun = GLOB.clients.Copy()
mc_data = null

Expand Down
25 changes: 21 additions & 4 deletions code/controllers/subsystem/ticker.dm
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ SUBSYSTEM_DEF(ticker)
/// Why an emergency shuttle was called
var/emergency_reason

/// ID of round reboot timer, if it exists
var/reboot_timer = null

///add bitflags to this that should be rewarded monkecoins, example: DEPARTMENT_BITFLAG_SECURITY
var/list/bitflags_to_reward = list(DEPARTMENT_BITFLAG_SECURITY,)
///add jobs to this that should get rewarded monkecoins, example: JOB_SECURITY_OFFICER
Expand Down Expand Up @@ -784,11 +787,10 @@ SUBSYSTEM_DEF(ticker)

var/start_wait = world.time
UNTIL(round_end_sound_sent || (world.time - start_wait) > (delay * 2)) //don't wait forever
sleep(delay - (world.time - start_wait))
reboot_timer = addtimer(CALLBACK(src, PROC_REF(reboot_callback), reason, end_string), delay - (world.time - start_wait), TIMER_STOPPABLE)

if(delay_end && !skip_delay)
to_chat(world, span_boldannounce("Reboot was cancelled by an admin."))
return

/datum/controller/subsystem/ticker/proc/reboot_callback(reason, end_string)
if(end_string)
end_state = end_string

Expand All @@ -803,6 +805,21 @@ SUBSYSTEM_DEF(ticker)

world.Reboot()

/**
* Deletes the current reboot timer and nulls the var
*
* Arguments:
* * user - the user that cancelled the reboot, may be null
*/
/datum/controller/subsystem/ticker/proc/cancel_reboot(mob/user)
if(!reboot_timer)
to_chat(user, span_warning("There is no pending reboot!"))
return FALSE
to_chat(world, span_boldannounce("An admin has delayed the round end."))
deltimer(reboot_timer)
reboot_timer = null
return TRUE

/datum/controller/subsystem/ticker/Shutdown()
gather_newscaster() //called here so we ensure the log is created even upon admin reboot
save_admin_data()
Expand Down
10 changes: 10 additions & 0 deletions code/modules/admin/verbs/server.dm
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@
to_chat(world, "Server restart - [init_by]")
world.TgsEndProcess()

/* uncomment this when/if we port the the admin verb refactor
ADMIN_VERB(cancel_reboot, R_SERVER, "Cancel Reboot", "Cancels a pending world reboot.", ADMIN_CATEGORY_SERVER)
if(!SSticker.cancel_reboot(user))
return
log_admin("[key_name(user)] cancelled the pending world reboot.")
message_admins("[key_name_admin(user)] cancelled the pending world reboot.")
*/

/datum/admins/proc/end_round()
set category = "Server"
set name = "End Round"
Expand Down Expand Up @@ -151,6 +159,8 @@

SSticker.delay_end = TRUE
SSticker.admin_delay_notice = delay_reason
if(SSticker.reboot_timer)
SSticker.cancel_reboot(usr)

log_admin("[key_name(usr)] delayed the round end for reason: [SSticker.admin_delay_notice]")
message_admins("[key_name_admin(usr)] delayed the round end for reason: [SSticker.admin_delay_notice]")
Expand Down

0 comments on commit f291e37

Please sign in to comment.