forked from tgstation/tgstation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrestart_vote.dm
83 lines (63 loc) · 2.9 KB
/
restart_vote.dm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#define CHOICE_RESTART "Restart Round"
#define CHOICE_CONTINUE "Continue Playing"
/datum/vote/restart_vote
name = "Restart"
default_choices = list(
CHOICE_RESTART,
CHOICE_CONTINUE,
)
message = "Vote to restart the ongoing round."
/// This proc checks to see if any admins are online for the purposes of this vote to see if it can pass. Returns TRUE if there are valid admins online (Has +SERVER and is not AFK), FALSE otherwise.
/datum/vote/restart_vote/proc/admins_present()
for(var/client/online_admin as anything in GLOB.admins)
if(online_admin.is_afk() || !check_rights_for(online_admin, R_SERVER))
continue
return TRUE
return FALSE
/datum/vote/restart_vote/toggle_votable(mob/toggler)
if(!toggler)
CRASH("[type] wasn't passed a \"toggler\" mob to toggle_votable.")
if(!check_rights_for(toggler.client, R_ADMIN))
return FALSE
CONFIG_SET(flag/allow_vote_restart, !CONFIG_GET(flag/allow_vote_restart))
return TRUE
/datum/vote/restart_vote/is_config_enabled()
return CONFIG_GET(flag/allow_vote_restart)
/datum/vote/restart_vote/can_be_initiated(mob/by_who, forced)
. = ..()
if(!.)
return FALSE
if(!forced && !CONFIG_GET(flag/allow_vote_restart))
message = "Restart voting is disabled by server configuration settings."
return FALSE
// We still want players to be able to vote to restart even if valid admins are online. Let's update the message just so that the player is aware of this fact.
// We don't want to lock-out the vote though, so we'll return TRUE.
if(admins_present())
message = "Regardless of the results of this vote, the round will not automatically restart because an admin is online."
return TRUE
message = initial(message)
return TRUE
/datum/vote/restart_vote/get_vote_result(list/non_voters)
if(!CONFIG_GET(flag/default_no_vote))
// Default no votes will add non-voters to "Continue Playing"
choices[CHOICE_CONTINUE] += length(non_voters)
return ..()
/datum/vote/restart_vote/finalize_vote(winning_option)
if(winning_option == CHOICE_CONTINUE)
return
if(winning_option == CHOICE_RESTART)
if(admins_present())
to_chat(world, span_boldannounce("Notice: A restart vote will not restart the server automatically because there are active admins on."))
message_admins("A restart vote has passed, but there are active admins on with +SERVER, so it has been canceled. If you wish, you may restart the server.")
return
// If there was a previous map vote, we revert the change.
if(!isnull(SSmapping.next_map_config))
log_game("The next map has been reset due to successful restart vote.")
send_to_playing_players(span_boldannounce("The next map has been reset due to successful restart vote."))
revert_map_vote()
SSticker.force_ending = FORCE_END_ROUND
log_game("End round forced by successful restart vote.")
return
CRASH("[type] wasn't passed a valid winning choice. (Got: [winning_option || "null"])")
#undef CHOICE_RESTART
#undef CHOICE_CONTINUE