1 | #! perl # mandatory |
1 | #! perl # mandatory depends=highscore |
2 | |
2 | |
3 | # login handling |
3 | # login handling |
4 | |
4 | |
5 | use Fcntl; |
5 | use Fcntl; |
6 | use Coro::AIO; |
6 | use Coro::AIO; |
|
|
7 | use Deliantra::Util (); |
7 | |
8 | |
8 | our $MAX_DISCONNECT_TIME = $cf::CFG{max_disconnect_time} || 3600; |
9 | CONF MAX_DISCONNECT_TIME = 3600; |
9 | |
|
|
10 | # paranoia function to overwrite a string-in-place |
|
|
11 | sub nuke_str { |
|
|
12 | substr $_[0], 0, (length $_[0]), "x" x length $_[0] |
|
|
13 | } |
|
|
14 | |
10 | |
15 | sub query { |
11 | sub query { |
16 | my ($ns, $flags, $text) = @_; |
12 | my ($ns, $flags, $text) = @_; |
17 | |
13 | |
18 | my $current = $Coro::current; |
14 | $ns->query ($flags, $text, Coro::rouse_cb); |
19 | $ns->query ($flags, $text, sub { $current->ready; $current = $_[0] }); |
15 | Coro::rouse_wait |
20 | Coro::schedule while ref $current; |
|
|
21 | |
|
|
22 | $current |
|
|
23 | } |
16 | } |
24 | |
17 | |
25 | sub can_cleanup { |
18 | sub can_cleanup { |
26 | my ($pl, $mtime) = @_; |
19 | my ($pl, $mtime) = @_; |
27 | |
20 | |
… | |
… | |
62 | my $m = $ob->map |
55 | my $m = $ob->map |
63 | or return; |
56 | or return; |
64 | my $x = $ob->x; |
57 | my $x = $ob->x; |
65 | my $y = $ob->y; |
58 | my $y = $ob->y; |
66 | |
59 | |
67 | # return 0;#d# |
60 | # never happens normally, but helps when shell users make mistakes |
68 | # warn join ":", $m->at ($x, $y);#d# |
61 | $m->linkable |
69 | # warn "FOO$m { ".scalar ($m->at ($x, $y))." }\n"; |
62 | or return 1; |
70 | # return 0; |
|
|
71 | |
63 | |
72 | scalar grep $_->type == cf::SAVEBED, $m->at ($x, $y) |
64 | scalar grep $_->type == cf::SAVEBED, $m->at ($x, $y) |
73 | } |
65 | } |
74 | |
66 | |
75 | sub enter_map { |
67 | sub enter_map { |
… | |
… | |
90 | if ($time && $m) { |
82 | if ($time && $m) { |
91 | if ($time < $m->{instantiate_time}) { |
83 | if ($time < $m->{instantiate_time}) { |
92 | # the map was reset in the meantime |
84 | # the map was reset in the meantime |
93 | my $age = $cf::RUNTIME - $time; |
85 | my $age = $cf::RUNTIME - $time; |
94 | |
86 | |
95 | warn $ob->name, " map reset after logout, logout age $age (>= $MAX_DISCONNECT_TIME)\n";#d# |
87 | cf::info $ob->name, " map reset after logout, logout age $age (>= $MAX_DISCONNECT_TIME)\n";#d# |
96 | |
|
|
97 | ($map, $x, $y) = $pl->savebed; |
|
|
98 | |
88 | |
99 | if ($age >= $MAX_DISCONNECT_TIME) { |
89 | if ($age >= $MAX_DISCONNECT_TIME) { |
100 | $ob->message ( |
90 | $ob->message ( |
101 | "You didn't use a bed to reality to leave this realm, leaving your body in great danger. " |
91 | "You didn't use a bed to reality to leave this realm, leaving your body in great danger. " |
102 | . "Unfortunately, nobody was near to help you when the monsters arrived to eat you. " |
92 | . "Unfortunately, nobody was near to help you when the monsters arrived to eat you. " |
… | |
… | |
105 | cf::NDI_RED |
95 | cf::NDI_RED |
106 | ); |
96 | ); |
107 | # kill them. |
97 | # kill them. |
108 | # reminds me of the famous badness 10000 syndrome... |
98 | # reminds me of the famous badness 10000 syndrome... |
109 | $ob->stats->hp (-10000); #] if they survive this they deserved to live |
99 | $ob->stats->hp (-10000); #] if they survive this they deserved to live |
110 | $pl->killer ("a cave-in"); |
100 | my $killer = cf::arch::get "killer_login"; $pl->killer ($killer); $killer->destroy; |
111 | } else { |
101 | } else { |
|
|
102 | ($map, $x, $y) = $pl->savebed; |
|
|
103 | |
112 | $ob->message ( |
104 | $ob->message ( |
113 | "You didn't use a bed to reality to leave this realm, leaving your body in great danger. " |
105 | "You didn't use a bed to reality to leave this realm, leaving your body in great danger. " |
114 | . "Fortunately, some friendly dwellers found you, checked your passport, and brought you to safety. " |
106 | . "Fortunately, some friendly dwellers found you, checked your passport, and brought you to safety. " |
115 | . "Better use a savebed next time, much worse things could have happened... " |
107 | . "Better use a savebed next time, much worse things could have happened... " |
116 | . "H<You disconnected without having used a savebed. When you do that for too long, you might die.>", |
108 | . "H<You disconnected without having used a savebed. When you do that for too long, you might die.>", |
… | |
… | |
129 | } |
121 | } |
130 | |
122 | |
131 | $ob->goto ($map, $x, $y); |
123 | $ob->goto ($map, $x, $y); |
132 | } |
124 | } |
133 | |
125 | |
134 | # delete a player directory, be non-blocking AND synchronous... |
126 | sub encode_password($) { |
135 | # (thats hard, so we crap out and fork). |
127 | "!" . unpack "H*", $_[0] |
|
|
128 | } |
|
|
129 | |
|
|
130 | sub compare_password($$) { |
|
|
131 | my ($pass, $token) = @_; |
|
|
132 | |
|
|
133 | if ($token =~ /!!(.*)/) { |
|
|
134 | return +(substr $pass, 0, 8) eq pack "H*", $1; |
|
|
135 | } elsif ($token =~ /!(.*)/) { |
|
|
136 | return $pass eq pack "H*", $1; |
|
|
137 | } else { |
|
|
138 | return $token eq crypt $pass, $token; |
|
|
139 | } |
|
|
140 | } |
|
|
141 | |
|
|
142 | # delete a player directory |
136 | sub nuke_playerdir { |
143 | sub nuke_playerdir { |
137 | my ($user) = @_; |
144 | my ($user) = @_; |
138 | |
145 | |
|
|
146 | my $lock = cf::lock_acquire "ext::login::nuke_playerdir"; |
|
|
147 | |
139 | my $temp = "$PLAYERDIR/~$Coro::current~deleting~"; |
148 | my $temp = "$PLAYERDIR/~$Coro::current~deleting~"; |
140 | |
|
|
141 | cf::fork_call { |
|
|
142 | rename "$PLAYERDIR/$user", $temp; |
149 | aio_rename "$PLAYERDIR/$user", $temp; |
143 | system "rm", "-rf", $temp; |
150 | IO::AIO::aio_rmtree $temp; |
|
|
151 | } |
|
|
152 | |
|
|
153 | sub login_done { |
|
|
154 | my ($pl) = @_; |
|
|
155 | |
|
|
156 | if (0 < Coro::AIO::aio_load "$cf::CONFDIR/motd", my $motd) { |
|
|
157 | $pl->ns->send_msg ("c/motd" => $motd, cf::NDI_CLEAR); |
144 | }; |
158 | } |
|
|
159 | } |
|
|
160 | |
|
|
161 | sub chargen { |
|
|
162 | my ($ns, $user, $pass) = @_; |
|
|
163 | |
|
|
164 | # the rest of this function is character creation |
|
|
165 | $Coro::current->{desc} = "addme($user) chargen"; |
|
|
166 | |
|
|
167 | # just to make sure nothing is left over |
|
|
168 | # normally, nothing is there. |
|
|
169 | nuke_playerdir $user; |
|
|
170 | |
|
|
171 | my $pl = cf::player::new $user; |
|
|
172 | $pl->password (encode_password $pass); |
|
|
173 | $pl->connect ($ns); |
|
|
174 | my $ob = $pl->ob; |
|
|
175 | |
|
|
176 | $ob->goto ($pl->maplevel, $ob->x, $ob->y); |
|
|
177 | |
|
|
178 | while () { |
|
|
179 | $ob->update_stats; |
|
|
180 | $pl->save_stats; |
|
|
181 | |
|
|
182 | my $res = query $ns, cf::CS_QUERY_SINGLECHAR, |
|
|
183 | "[y] to roll new stats [n] to use stats\n[1-7] [1-7] to swap stats.\nRoll again (y/n/1-7)?"; |
|
|
184 | |
|
|
185 | if ($res =~ /^[Nn]/) { |
|
|
186 | last; |
|
|
187 | } elsif ($res > 0 && $res <= 7) { |
|
|
188 | my $swap = query $ns, cf::CS_QUERY_SINGLECHAR, "Swap stat with (will not roll new stats) [1-7]?"; |
|
|
189 | |
|
|
190 | if ($swap > 0 && $swap <= 7) { |
|
|
191 | $ob->swap_stats ($res - 1, $swap - 1); |
|
|
192 | } |
|
|
193 | } else { |
|
|
194 | $ob->roll_stats; |
|
|
195 | } |
|
|
196 | |
|
|
197 | Coro::Timer::sleep 0.05; |
|
|
198 | } |
|
|
199 | |
|
|
200 | $ob->set_animation (2); |
|
|
201 | $ob->add_statbonus; |
|
|
202 | |
|
|
203 | while () { |
|
|
204 | $ns->send_msg ("chargen-race-title", ucfirst $pl->title, -1); |
|
|
205 | my $msg = $ob->msg; |
|
|
206 | $msg =~ s/(?<=\S)\n(?=\S)/ /g; |
|
|
207 | $ns->send_msg ("chargen-race-description", $msg, cf::NDI_BLUE); |
|
|
208 | |
|
|
209 | my $res = query $ns, cf::CS_QUERY_SINGLECHAR, |
|
|
210 | "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n"; |
|
|
211 | |
|
|
212 | last if $res =~ /[dD]/; |
|
|
213 | |
|
|
214 | $pl->chargen_race_next; |
|
|
215 | Coro::Timer::sleep 0.05; |
|
|
216 | } |
|
|
217 | |
|
|
218 | # create the playerdir, if necessary, as chargen_race_done did it before |
|
|
219 | # presumably because of unique maps |
|
|
220 | aio_mkdir playerdir $pl, 0770; |
|
|
221 | $pl->chargen_race_done; |
|
|
222 | |
|
|
223 | while () { |
|
|
224 | my $res = query $ns, cf::CS_QUERY_SINGLECHAR, |
|
|
225 | "Now choose a gender.\nPress 'f' to become female, and 'm' to become male.\n"; |
|
|
226 | |
|
|
227 | if ($res =~ /^[fF]/) { |
|
|
228 | $pl->gender (1); |
|
|
229 | last; |
|
|
230 | } elsif ($res =~ /^[mM]/) { |
|
|
231 | $pl->gender (0); |
|
|
232 | last; |
|
|
233 | } |
|
|
234 | Coro::Timer::sleep 0.05; |
|
|
235 | } |
|
|
236 | |
|
|
237 | $ob->reply (undef, "Welcome to Deliantra!"); |
|
|
238 | |
|
|
239 | # XXX: Workaround for delayed client ext protocol handshake |
|
|
240 | $pl->esrv_new_player; |
|
|
241 | |
|
|
242 | delete $pl->{deny_save}; |
145 | } |
243 | } |
146 | |
244 | |
147 | cf::client->attach (on_addme => sub { |
245 | cf::client->attach (on_addme => sub { |
148 | my ($ns) = @_; |
246 | my ($ns) = @_; |
149 | |
|
|
150 | if (!$ns->facecache) |
|
|
151 | { |
|
|
152 | $ns->send_drawinfo (<<EOF, cf::NDI_RED); |
|
|
153 | |
|
|
154 | |
|
|
155 | *** |
|
|
156 | *** WARNING: |
|
|
157 | *** Your client does not support face/image caching, |
|
|
158 | *** or it has been disabled. Face caching is mandatory |
|
|
159 | *** so please enable it or use a newer client. |
|
|
160 | *** |
|
|
161 | *** Look at your client preferences: |
|
|
162 | *** |
|
|
163 | *** deliantra: all known versions automatically enable the facecache. |
|
|
164 | *** cfclient: use the -cache commandline option. |
|
|
165 | *** cfclient: map will not redraw automatically (bug). |
|
|
166 | *** gcfclient: use -cache commandline option, or enable |
|
|
167 | *** gcfclient: Client => Configure => Map & Image => Cache Images. |
|
|
168 | *** jcrossclient: your client is broken, use deliantra or gcfclient. |
|
|
169 | *** |
|
|
170 | *** |
|
|
171 | EOF |
|
|
172 | if ($ns->version =~ /jcrossclient/) { |
|
|
173 | # let them, for now |
|
|
174 | } else { |
|
|
175 | $ns->flush; |
|
|
176 | return $ns->destroy; |
|
|
177 | } |
|
|
178 | |
|
|
179 | # $ns->facecache = true; |
|
|
180 | } |
|
|
181 | |
|
|
182 | if ($ns->mapmode < cf::Map1aCmd) { |
|
|
183 | $ns->send_drawinfo (<<EOF, cf::NDI_RED); |
|
|
184 | |
|
|
185 | |
|
|
186 | *** |
|
|
187 | *** WARNING: |
|
|
188 | *** Your client is too old. Please upgrade to a newer version. |
|
|
189 | EOF |
|
|
190 | |
|
|
191 | $ns->flush; |
|
|
192 | return $ns->destroy; |
|
|
193 | } |
|
|
194 | |
247 | |
195 | $ns->pl and return $ns->destroy; |
248 | $ns->pl and return $ns->destroy; |
196 | |
249 | |
197 | $ns->async (sub { |
250 | $ns->async (sub { |
198 | $Coro::current->{desc} = "addme init"; |
251 | $Coro::current->{desc} = "addme init"; |
… | |
… | |
209 | cf::NDI_BLUE |
262 | cf::NDI_BLUE |
210 | ); |
263 | ); |
211 | |
264 | |
212 | # read username |
265 | # read username |
213 | while () { |
266 | while () { |
214 | $user = query $ns, 0, "What is your name?\n:"; |
267 | $user = query $ns, 0, "What is your name? (login names are case-sensitive)\n:"; |
215 | |
268 | |
216 | if ($cf::LOGIN_LOCK{$user}) { |
269 | if ($cf::LOGIN_LOCK{$user}) { |
217 | $ns->send_drawinfo ( |
270 | $ns->send_drawinfo ( |
218 | "That username is currently used in another login session. " |
271 | "That username is currently used in another login session. " |
219 | . "Chose another, or wait till the other session has ended.", |
272 | . "Chose another, or wait till the other session has ended.", |
220 | cf::NDI_RED |
273 | cf::NDI_RED |
221 | ); |
274 | ); |
222 | } elsif ($user =~ /^[a-zA-Z0-9][a-zA-Z0-9\-_]{2,17}\z/) { |
275 | } elsif ($user =~ /^[a-zA-Z0-9][a-zA-Z0-9\-_]{2,19}\z/) { |
223 | last; |
276 | last; |
224 | } else { |
277 | } else { |
225 | $ns->send_drawinfo ( |
278 | $ns->send_drawinfo ( |
226 | "Your username contains illegal characters " |
279 | "Your username contains illegal characters " |
227 | . "(only a-z, A-Z and 0-9 are allowed), " |
280 | . "(only a-z, A-Z and 0-9 are allowed), " |
228 | . "or is not between 3 and 18 characters in length.", |
281 | . "or is not between 3 and 20 characters in length.", |
229 | cf::NDI_RED |
282 | cf::NDI_RED |
230 | ); |
283 | ); |
231 | } |
284 | } |
232 | Coro::Timer::sleep 0.4; |
285 | Coro::Timer::sleep 0.4; |
233 | } |
286 | } |
… | |
… | |
272 | |
325 | |
273 | # try to read the user file and check the password |
326 | # try to read the user file and check the password |
274 | if (my $pl = cf::player::find $user) { |
327 | if (my $pl = cf::player::find $user) { |
275 | aio_stat $pl->path and next; |
328 | aio_stat $pl->path and next; |
276 | my $mtime = (stat _)[9]; |
329 | my $mtime = (stat _)[9]; |
277 | my $hash = $pl->password; |
330 | my $token = $pl->password; |
278 | |
331 | |
279 | if ($cf::CFG{ext_login_nocheck} or $hash eq crypt $pass, $hash) { |
332 | if ($cf::CFG{ext_login_nocheck} or compare_password $pass, $token) { |
280 | nuke_str $pass; |
333 | # player exists and passwords match - we can proceed |
|
|
334 | |
281 | # password matches, wonderful |
335 | # password matches, wonderful |
282 | my $pl = cf::player::find $user or next; |
336 | my $pl = cf::player::find $user or next; |
283 | $pl->connect ($ns); |
337 | $pl->connect ($ns); |
284 | enter_map $pl; |
338 | enter_map $pl; |
|
|
339 | login_done $pl; |
285 | last; |
340 | return; |
286 | } elsif (can_cleanup $pl, $mtime) { |
341 | } elsif (can_cleanup $pl, $mtime) { |
287 | Coro::Timer::sleep 1; |
342 | Coro::Timer::sleep 1; |
288 | |
343 | |
289 | $ns->send_drawinfo ( |
344 | $ns->send_drawinfo ( |
290 | "Player exists, but password does not match. If this is your account, " |
345 | "Player exists, but password does not match. If this is your account, " |
291 | . "please try again. If not, you can now decide to take over this account " |
346 | . "please try again. If not, you can now decide to take over this account " |
292 | . "because it has not been in-use for some time.", |
347 | . "because it has not been in-use for some time.", |
293 | cf::NDI_RED |
348 | cf::NDI_RED |
294 | ); |
349 | ); |
295 | |
350 | |
296 | #TODO: nuke_str |
|
|
297 | (query $ns, cf::CS_QUERY_SINGLECHAR, "Delete existing account and create a new one (Y/N)?") =~ /^[yY]/ |
351 | (query $ns, cf::CS_QUERY_SINGLECHAR, "Delete existing account and create a new one (Y/N)?") =~ /^[yY]/ |
298 | or next; |
352 | or next; |
299 | |
353 | |
300 | # check if the file hasn't changed |
354 | # check if the file hasn't changed |
301 | aio_stat cf::player::path $user and next; |
355 | aio_stat cf::player::path $user and next; |
… | |
… | |
303 | |
357 | |
304 | $pl->quit_character; |
358 | $pl->quit_character; |
305 | |
359 | |
306 | # fall through to creation |
360 | # fall through to creation |
307 | } else { |
361 | } else { |
308 | nuke_str $pass; |
|
|
309 | |
|
|
310 | Coro::Timer::sleep 1; |
362 | Coro::Timer::sleep 1; |
311 | |
363 | |
312 | $ns->send_drawinfo ( |
364 | $ns->send_drawinfo ( |
313 | "Wrong username or password. Please try again " |
365 | "Wrong username or password. Please try again " |
314 | . "(check for Numlock and other semi-obvious error sources).", |
366 | . "(check for Numlock and other semi-obvious error sources).", |
… | |
… | |
316 | ); |
368 | ); |
317 | next; |
369 | next; |
318 | } |
370 | } |
319 | } else { |
371 | } else { |
320 | # unable to load the playerfile: |
372 | # unable to load the playerfile: |
321 | # check wether the player dir exists, which means the file is corrupted or |
373 | # check whether the player dir exists, which means the file is corrupted or |
322 | # something very similar. |
374 | # something very similar. |
323 | if (!aio_stat cf::player::playerdir $user) { |
375 | if (!aio_stat cf::player::playerdir $user) { |
324 | $ns->send_drawinfo ( |
376 | $ns->send_drawinfo ( |
325 | "Unable to retrieve this player. It might be a locked or broken account. " |
377 | "Unable to retrieve this player. It might be a locked or broken account. " |
326 | . "If this is your account, ask a dungeon master for assistance. " |
378 | . "If this is your account, ask a dungeon master for assistance. " |
… | |
… | |
329 | ); |
381 | ); |
330 | next; |
382 | next; |
331 | } |
383 | } |
332 | } |
384 | } |
333 | |
385 | |
334 | # the rest of this function is character creation |
|
|
335 | $Coro::current->{desc} = "addme($user) chargen"; |
|
|
336 | |
|
|
337 | # just to make sure nothing is left over |
|
|
338 | nuke_playerdir $user; |
|
|
339 | |
|
|
340 | my $pass2 = query $ns, cf::CS_QUERY_HIDEINPUT, "Please type your password again."; |
386 | my $pass2 = query $ns, cf::CS_QUERY_HIDEINPUT, "Please type your password again."; |
341 | |
387 | |
342 | if ($pass2 ne $pass) { |
388 | if ($pass2 ne $pass) { |
343 | nuke_str $pass; |
|
|
344 | nuke_str $pass2; |
|
|
345 | $ns->send_drawinfo ( |
389 | $ns->send_drawinfo ( |
346 | "The passwords do not match, please try again.", |
390 | "The passwords do not match, please try again.", |
347 | cf::NDI_RED |
391 | cf::NDI_RED |
348 | ); |
392 | ); |
349 | Coro::Timer::sleep 0.5; |
393 | Coro::Timer::sleep 0.5; |
350 | next; |
394 | next; |
351 | } |
395 | } |
352 | |
396 | |
353 | nuke_str $pass2; |
|
|
354 | |
|
|
355 | my $pl = cf::player::new $user; |
|
|
356 | $pl->password (crypt $pass, join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]); |
|
|
357 | nuke_str $pass; |
|
|
358 | $pl->connect ($ns); |
|
|
359 | my $ob = $pl->ob; |
|
|
360 | |
|
|
361 | $ob->goto ($pl->maplevel, $ob->x, $ob->y); |
|
|
362 | |
|
|
363 | while () { |
|
|
364 | $ob->update_stats; |
|
|
365 | $pl->save_stats; |
|
|
366 | |
|
|
367 | my $res = query $ns, cf::CS_QUERY_SINGLECHAR, |
|
|
368 | "[y] to roll new stats [n] to use stats\n[1-7] [1-7] to swap stats.\nRoll again (y/n/1-7)?"; |
|
|
369 | |
|
|
370 | if ($res =~ /^[Nn]/) { |
|
|
371 | last; |
|
|
372 | } elsif ($res > 0 && $res <= 7) { |
|
|
373 | my $swap = query $ns, cf::CS_QUERY_SINGLECHAR, "Swap stat with (will not roll new stats) [1-7]?"; |
|
|
374 | |
|
|
375 | if ($swap > 0 && $swap <= 7) { |
|
|
376 | $ob->swap_stats ($res - 1, $swap - 1); |
|
|
377 | } |
|
|
378 | } else { |
|
|
379 | $ob->roll_stats; |
|
|
380 | } |
|
|
381 | |
|
|
382 | Coro::Timer::sleep 0.2; |
|
|
383 | } |
|
|
384 | |
|
|
385 | $ob->set_animation (2); |
|
|
386 | $ob->add_statbonus; |
|
|
387 | |
|
|
388 | while () { |
|
|
389 | $ns->send_msg ("chargen-race-title", ucfirst $pl->title, -1); |
|
|
390 | my $msg = $ob->msg; |
|
|
391 | $msg =~ s/(?<=\S)\n(?=\S)/ /g; |
|
|
392 | $ns->send_msg ("chargen-race-description", $msg, cf::NDI_BLUE); |
|
|
393 | |
|
|
394 | my $res = query $ns, cf::CS_QUERY_SINGLECHAR, |
|
|
395 | "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n"; |
|
|
396 | |
|
|
397 | last if $res =~ /[dD]/; |
|
|
398 | |
|
|
399 | $pl->chargen_race_next; |
|
|
400 | Coro::Timer::sleep 0.2; |
|
|
401 | } |
|
|
402 | |
|
|
403 | $pl->chargen_race_done; |
|
|
404 | |
|
|
405 | while () { |
|
|
406 | my $res = query $ns, cf::CS_QUERY_SINGLECHAR, |
|
|
407 | "Now choose a gender.\nPress 'f' to become female, and 'm' to become male.\n"; |
|
|
408 | |
|
|
409 | if ($res =~ /^[fF]/) { |
|
|
410 | $pl->gender (1); |
|
|
411 | last; |
|
|
412 | } elsif ($res =~ /^[mM]/) { |
|
|
413 | $pl->gender (0); |
|
|
414 | last; |
|
|
415 | } |
|
|
416 | Coro::Timer::sleep 0.2; |
|
|
417 | } |
|
|
418 | |
|
|
419 | $ob->reply (undef, "Welcome to Deliantra!"); |
|
|
420 | |
|
|
421 | delete $pl->{deny_save}; |
|
|
422 | |
|
|
423 | last; |
397 | last; |
424 | } |
398 | } |
|
|
399 | |
|
|
400 | # lock again, too layz to make this nicer |
|
|
401 | local $cf::LOGIN_LOCK{$user} = 1; |
|
|
402 | |
|
|
403 | chargen $ns, $user, $pass; |
|
|
404 | login_done $ns->pl; |
425 | }); |
405 | }); |
426 | }); |
406 | }); |
427 | |
407 | |
|
|
408 | cf::client->attach ( |
|
|
409 | on_version => sub { |
|
|
410 | my ($ns, $arg) = @_; |
|
|
411 | |
|
|
412 | $ns->ext_msg (nonces => map { join "", map { chr rand 256 } 0..63 } 1..2); |
|
|
413 | |
|
|
414 | fatal ($ns,"oops");#d# |
|
|
415 | }, |
|
|
416 | ); |
|
|
417 | |
|
|
418 | #cf::register_async_exticmd create_login => sub { |
|
|
419 | # my ($ns, $reply, $user, $pass) = @_; |
|
|
420 | # |
|
|
421 | # $ns->pl and return $ns->destroy; |
|
|
422 | #}; |
|
|
423 | |
|
|
424 | cf::register_async_exticmd login => sub { |
|
|
425 | my ($ns, $reply, $user, $hash) = @_; |
|
|
426 | |
|
|
427 | $ns->pl and return $ns->destroy; |
|
|
428 | }; |
|
|
429 | |
|
|
430 | cf::register_command password => sub { |
|
|
431 | my ($pl, $arg) = @_; |
|
|
432 | |
|
|
433 | unless ($pl->flag (cf::FLAG_WIZ)) { |
|
|
434 | $pl->message ( |
|
|
435 | "The password can currently only changed by a DM.", |
|
|
436 | cf::NDI_UNIQUE | cf::NDI_REPLY); |
|
|
437 | return; |
|
|
438 | } |
|
|
439 | |
|
|
440 | my (@args) = split /\s+/, $arg; |
|
|
441 | my ($player, $new_pw) = @args; |
|
|
442 | |
|
|
443 | if ($pl->flag (cf::FLAG_WIZ) && $player eq '') { |
|
|
444 | $pl->message ( |
|
|
445 | "Usage: password <player> [<new password>]", |
|
|
446 | cf::NDI_UNIQUE | cf::NDI_REPLY); |
|
|
447 | return; |
|
|
448 | } |
|
|
449 | |
|
|
450 | if ($new_pw eq '') { |
|
|
451 | $new_pw = |
|
|
452 | join '', |
|
|
453 | map { ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[(cf::rndm 64)] } |
|
|
454 | 1..9; |
|
|
455 | } |
|
|
456 | |
|
|
457 | cf::async { |
|
|
458 | my $plc = cf::player::find $player; |
|
|
459 | if ($plc) { |
|
|
460 | $plc->password (encode_password $new_pw); |
|
|
461 | $pl->message ( |
|
|
462 | "Ok, changed password of '$player' to '$new_pw'!", |
|
|
463 | cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); |
|
|
464 | } else { |
|
|
465 | $pl->message ( |
|
|
466 | "Fail! Couldn't set password for '$player', " |
|
|
467 | . "he doesn't seem to exist!", |
|
|
468 | cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); |
|
|
469 | } |
|
|
470 | }; |
|
|
471 | }; |
|
|
472 | |
428 | cf::register_command quit => sub { |
473 | cf::register_command quit => sub { |
429 | my ($ob, $arg) = @_; |
474 | my ($ob, $arg) = @_; |
430 | |
475 | |
431 | $ob->reply (undef, |
476 | $ob->send_msg (undef, |
432 | "Quitting will delete your character PERMANENTLY: It will be gone forever and any progress will be lost. " |
477 | "Quitting will delete your character PERMANENTLY: It will be gone forever and any progress will be lost. " |
433 | . "If you are sure you want to do this, then use the quit_character command instead of quit.", |
478 | . "If you are sure you want to do this, then use the quit_character command instead of quit.", |
434 | cf::NDI_UNIQUE | cf::NDI_RED); |
479 | cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); |
435 | }; |
480 | }; |
436 | |
481 | |
437 | cf::register_command quit_character => sub { |
482 | cf::register_command quit_character => sub { |
438 | my ($ob, $arg) = @_; |
483 | my ($ob, $arg) = @_; |
439 | |
484 | |
440 | my $pl = $ob->contr; |
485 | my $pl = $ob->contr; |
441 | |
486 | |
442 | $pl->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to PERMANENTLY delete your character and all associated data (y/n)?", sub { |
487 | $pl->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to PERMANENTLY delete your character and all associated data (y/n)?", sub { |
443 | if ($_[0] !~ /^[yY]/) { |
488 | if ($_[0] !~ /^[yY]/) { |
444 | $ob->reply (undef, |
489 | $ob->send_msg (undef, "Ok, not not quitting then.", cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); |
445 | "Ok, not not quitting then.", |
|
|
446 | cf::NDI_UNIQUE | cf::NDI_RED); |
|
|
447 | } else { |
490 | } else { |
448 | $ob->reply (undef, |
491 | $ob->send_msg (undef, "Ok, quitting, hope to see you again.", cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); |
449 | "Ok, quitting, hope to see you again.", |
492 | cf::async { |
450 | cf::NDI_UNIQUE | cf::NDI_RED); |
|
|
451 | $pl->ns->flush; |
|
|
452 | cf::async { $pl->quit_character }; |
493 | $pl->quit_character; |
|
|
494 | }; |
453 | } |
495 | } |
454 | }); |
496 | }); |
455 | }; |
497 | }; |
456 | |
498 | |
457 | cf::object->attach ( |
499 | cf::object->attach ( |
… | |
… | |
463 | |
505 | |
464 | my $pl = $ob->contr; |
506 | my $pl = $ob->contr; |
465 | |
507 | |
466 | # update respawn position |
508 | # update respawn position |
467 | $pl->savebed ($bed->map->path, $bed->x, $bed->y); |
509 | $pl->savebed ($bed->map->path, $bed->x, $bed->y); |
468 | cf::async { $pl->save }; |
|
|
469 | |
510 | |
470 | $pl->killer ("left"); |
511 | cf::async { |
471 | $ob->check_score; |
512 | my $killer = cf::arch::get "killer_logout"; $pl->killer ($killer); $killer->destroy; |
|
|
513 | ext::highscore::check $ob; |
472 | |
514 | |
473 | $ob->reply (undef, "In the future, you will wake up here when you die."); |
515 | $pl->save; |
474 | |
516 | |
|
|
517 | $ob->send_msg ($cf::SAY_CHANNEL => "In the future, you will wake up here when you die.", cf::NDI_DEF | cf::NDI_REPLY); |
|
|
518 | |
|
|
519 | my $ns = $pl->ns |
|
|
520 | or return; |
|
|
521 | |
475 | $pl->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to continue playing (y/n)?", sub { |
522 | $ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to continue playing (y/n)?", sub { |
476 | if ($_[0] !~ /^[yY]/) { |
523 | if ($_[0] !~ /^[yY]/) { |
477 | $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1); |
524 | $pl->invoke (cf::EVENT_PLAYER_LOGOUT, 1); |
478 | $pl->deactivate; |
525 | $pl->deactivate; |
479 | $pl->ns->destroy; |
526 | $pl->ns->destroy; |
480 | } else { |
527 | } |
481 | cf::async { $pl->save }; |
|
|
482 | } |
528 | }); |
483 | }); |
529 | }; |
484 | }, |
530 | }, |
485 | ); |
531 | ); |
486 | |
532 | |
487 | cf::player->attach ( |
533 | cf::player->attach ( |
488 | on_login => sub { |
534 | on_login => sub { |
… | |
… | |
497 | |
543 | |
498 | if ($cleanly) { |
544 | if ($cleanly) { |
499 | $_->ob->message ("$name left the game.", cf::NDI_DK_ORANGE | cf::NDI_UNIQUE) for cf::player::list; |
545 | $_->ob->message ("$name left the game.", cf::NDI_DK_ORANGE | cf::NDI_UNIQUE) for cf::player::list; |
500 | } else { |
546 | } else { |
501 | $_->ob->message ("$name uncerimoniously disconnected.", cf::NDI_DK_ORANGE | cf::NDI_UNIQUE) for cf::player::list; |
547 | $_->ob->message ("$name uncerimoniously disconnected.", cf::NDI_DK_ORANGE | cf::NDI_UNIQUE) for cf::player::list; |
502 | warn "unclean\n" unless safe_spot $pl;#d# |
|
|
503 | $pl->{unclean_save} = $cf::RUNTIME |
548 | $pl->{unclean_save} = $cf::RUNTIME |
504 | unless safe_spot $pl; |
549 | unless safe_spot $pl; |
505 | } |
550 | } |
506 | }, |
551 | }, |
507 | ); |
552 | ); |
508 | |
553 | |
509 | ############################################################################# |
|
|
510 | |
|
|
511 | our $SCHEDULE_INTERVAL = $cf::CFG{player_schedule_interval} || 10; # time the player scheduler sleeps between runs |
|
|
512 | our $SAVE_TIMEOUT = $cf::CFG{player_save_interval} || 20; # save players every n seconds |
|
|
513 | |
|
|
514 | our $SCHEDULER = cf::async_ext { |
|
|
515 | $Coro::current->{desc} = "player scheduler"; |
|
|
516 | |
|
|
517 | while () { |
|
|
518 | Coro::EV::timer_once $SCHEDULE_INTERVAL; |
|
|
519 | |
|
|
520 | # this weird form of iteration over values is used because |
|
|
521 | # the hash changes underneath us frequently, and for |
|
|
522 | # keeps a direct reference to the value without (in 5.8 perls) |
|
|
523 | # keeping a reference, so this is prone to crashes or worse. |
|
|
524 | my @players = keys %cf::PLAYER; |
|
|
525 | for (@players) { |
|
|
526 | my $pl = $cf::PLAYER{$_} |
|
|
527 | or next; |
|
|
528 | $pl->valid or next; |
|
|
529 | |
|
|
530 | eval { |
|
|
531 | if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { |
|
|
532 | $pl->save; |
|
|
533 | |
|
|
534 | unless ($pl->active || $pl->ns) { |
|
|
535 | # check refcounts, this is tricky and needs to be adjusted to fit server internals |
|
|
536 | my $ob = $pl->ob; |
|
|
537 | |
|
|
538 | my $pl_ref = $pl->refcnt_cnt; |
|
|
539 | my $ob_ref = $ob->refcnt_cnt; |
|
|
540 | |
|
|
541 | ## pl_ref == $pl + ob->contr + %cf::PLAYER |
|
|
542 | ## ob_ref == $ob + pl->observe + simply being an object |
|
|
543 | if ($pl_ref == 3 && $ob_ref == 3) { |
|
|
544 | warn "player-scheduler destroy ", $ob->name;#d# |
|
|
545 | |
|
|
546 | # remove from sight and get fresh "copies" |
|
|
547 | $pl = delete $cf::PLAYER{$ob->name}; |
|
|
548 | $ob = $pl->ob; |
|
|
549 | |
|
|
550 | $pl->destroy; # destroys $ob |
|
|
551 | } else { |
|
|
552 | my $a_ = $pl->refcnt;#d# |
|
|
553 | my $b_ = $ob->refcnt;#d# |
|
|
554 | |
|
|
555 | warn "player-scheduler refcnt ", $ob->name, " pl $pl_ref ob $ob_ref (C pl $a_ ob $b_)\n";#d# |
|
|
556 | } |
|
|
557 | } |
|
|
558 | } |
|
|
559 | }; |
|
|
560 | warn $@ if $@; |
|
|
561 | Coro::cede; |
|
|
562 | }; |
|
|
563 | } |
|
|
564 | }; |
|
|
565 | |
|
|
566 | $SCHEDULER->prio (1); |
|
|
567 | |
|
|