forked from fuzzball-muck/fuzzball-muf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd-@bringitdown.muf
98 lines (85 loc) · 2.27 KB
/
cmd-@bringitdown.muf
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
@prog cmd-@bringitdown
1 99999 d
1 i
$def WARNTIMES 15 10 5 1
: wall[ str:mesg -- ]
#-1 descr_array
foreach swap pop
mesg @ descrnotify
repeat
;
: warn[ str:mesg str:whendown -- ]
{
" "
{ "## WARNING: " __muckname " will be shutting down " whendown @ }join
mesg @ if
"## " mesg @ strcat
then
"## All building will be saved to disk, and we should be"
"## back up within a couple minutes after the shutdown."
"## If you have any questions, please page a wizard for help."
" "
}list "\r" array_join wall
;
: main[ str:args -- ]
me @ "wizard" flag?
$ifdef __muckname=FurryMUCK
me @ #1026 dbcmp or
$endif
not if
"Permission denied." .tell
pop exit
then
args @ tolower
"#help" 5 strncmp not if
"@bringitdown <message> to shut down the MUCK in 15 mins, warning the users." .tell
"@bringitdown #restart <message> to restart in 15 mins, warning the users." .tell
exit
then
"!@shutdown" var! thecmd
args @ tolower
"#restart" 8 strncmp not if
args @ 8 strcut swap pop striplead args !
"!@restart" thecmd !
else
args @ "#" 1 strncmp not if
"Unrecognized #-option " swap strcat .tell
exit
then
then
{ WARNTIMES }list SORTTYPE_DESCENDING array_sort var! sortedtimes
sortedtimes @ dup array_count -- [] if
0 sortedtimes @ array_appenditem sortedtimes !
then
sortedtimes @ 0 [] var! maxtime
{ }dict var! warnsystimes
sortedtimes @
foreach var! t pop
totaltime @ t @ 60 * -
systime +
warnsystimes @ t @ ->[] warnsystimes !
repeat
sortedtimes @
foreach var! t pop
warnsystimes @ t @ [] var! nexttime
nexttime @ systime > if nexttime @ systime - sleep then
"NOW." var! whenstr
t @ 0 > if
t @ 1 = if "in %i minute." else "in %i minutes." then
t @ swap fmtstring whenstr !
then
args @ whenstr @ warn
repeat
10 sleep
#1 "@set me=!q" force
#1 thecmd @ force
;
.
c
q
@register #me cmd-@bringitdown=tmp/prog1
@set $tmp/prog1=W
@set $tmp/prog1=3
@chown $tmp/prog1=#1
@action @bringitdown=#0=tmp/exit1
@link $tmp/exit1=$tmp/prog1