forked from fuzzball-muck/fuzzball-muf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
con-multiguest.muf
204 lines (178 loc) · 5.26 KB
/
con-multiguest.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
@program con-multiguest
1 9999 d
1 i
(IMPORTANT NOTE: Guests must be able to use @name and @password.)
(This program will force them to rename and repasswd themselves, so players..)
(...logging in won't be able to rename or repassword the chars, themselves.)
$def GuestName "Guest" (Name of the main Guest char)
$def GuestPassWD "guest" (Normal Guest Passwrod)
(Important Note 2: There must be one fewer guest characters, including..)
("Guest" itself, than the defined NumGuests. This lets the guests have...)
(...their names shuffled around. There MUST be one guest named Guest.)
(ie: if NumGuests is 4, then Guest, Guest1, Guest2, and Guest3 should exist)
$def NumGuests 9 (Max guests allowed connected + 1)
$def Wizard #1 (Change this to a wizard's dbref. Preferably not #1)
(This next $def has the password creation scheme for the guests.)
(You'll want to change this to be something unique.)
(Don't make this just return "guest" or else the guests will be...)
(...able to rename and repassword themselves.)
$def PassWdMake (i -- s) 3 + 9 * intostr "TimE" swap strcat "tWINe" strcat
(takes guest# and returns that guests passwd)
: get-guest-num-passwd (i -- s)
dup not if pop GuestPassWD exit then
PassWdMake
;
(takes guest# and returns that guests name)
: get-guest-num-name (i -- s)
dup if intostr else pop "" then
GuestName swap strcat
;
(takes guest# and returns that guests dbref)
: get-guest-num-dbref (i -- d)
me @ 1 addpennies
get-guest-num-name .pmatch
;
(Finds first existing awake guest char)
: get-next-free-guest-num ( -- i)
1 begin
dup NumGuests <= while
dup get-guest-num-dbref
dup ok? if
awake? not if break then
else pop
then
1 +
repeat
dup NumGuests > if pop 0 exit then
;
(Finds the guest that was renamed to Guest)
: get-unclaimed-guest-num ( -- i)
1 begin
dup NumGuests <= while
dup get-guest-num-dbref
ok? not if break then
1 +
repeat
;
(Renames a guest from one guest number to another)
: rename-guest (orignum newnum -- )
"@name me=" swap get-guest-num-name strcat
" " strcat over get-guest-num-passwd strcat
swap get-guest-num-dbref swap force
;
(Repasswords a guest from one guest number to another)
: repassword-guest (i i -- )
"@password " rot
get-guest-num-passwd strcat
"=" strcat over
get-guest-num-passwd strcat
swap get-guest-num-dbref swap force
;
(Does a rename and a repassword of the guest.)
(These should be done together)
: redo-guest (i i -- )
over over rename-guest
repassword-guest
;
(Boot all connections of this [me @] guest)
: bootme ( -- )
me @ descriptors
begin
dup while 1 - swap
preempt
descrcon conboot
background
repeat pop
;
(Boots all but oldest connection to this [me @] guest)
(This is used to prevent more than one guest logging in simultaneously)
: boot-extras ( -- )
me @ descriptors
begin
dup 1 > while 1 - swap
preempt descrcon
"## I'm sorry, but you connected at the same time as someone else."
over swap connotify
dup "## Please log in as guest again." connotify
conboot background
repeat pop pop
;
(This shuffles the guests around, so Guest can be renamed to the lowest...)
(... numbered guest not currently logged in.)
: shuffle-guests ( -- )
get-next-free-guest-num
get-unclaimed-guest-num
over over < if
redo-guest
else
pop pop
then
;
(rename this Guest to the available guest number.)
(Also, inform the player who they are logged in as.)
: setup-me-guest ( -- )
get-unclaimed-guest-num
0 over redo-guest
get-guest-num-name
"You are now connected to "
swap strcat me @ swap notify
;
(Rename the next unused guest to Guest, so the next person can log in)
: prepare-next-guest ( -- )
get-next-free-guest-num
dup 0 redo-guest
;
(shuffles the guests around when Guest logs in.)
: guest-login (run this when the guest logs in)
pop
me @ name tolower GuestName tolower dup strlen strncmp if
"Sorry, but you can't use this program."
me @ swap notify pop exit
then
get-next-free-guest-num
not if
"Too many guest players connected. Please try again, later."
me @ swap notify bootme exit
then
boot-extras
shuffle-guests
setup-me-guest
prepare-next-guest
;
(When this program is run from an action, make sure...)
(...that the guests passwords are all correct.)
: init-repass-guests ( -- )
0 begin
dup NumGuests <= while
"@newpassword " over get-guest-num-name strcat
"=" strcat over get-guest-num-passwd strcat
Wizard swap force
1 +
repeat
pop
;
: main
command @ "Queued Event*" smatch
if guest-login else init-repass-guests then
;
.
c
q
@register con-multiguest=con/multiguest
@set con-multiguest=w
@action mgs=me
@link mgs=con-multiguest
mgs
@recycle mgs
@prog con-callmultiguest
1 9999 d
1 i
( Have all the guest chars call this program from a _connect propqueue )
(This calls the !Link_OK multi-guest program, to keep the password...)
(...creation subroutines secret)
: go "$con/multiguest" match call ;
.
c
q
@set con-callmultiguest=L
@set con-callmultiguest=S