… | |
… | |
4 | |
4 | |
5 | use Fcntl; |
5 | use Fcntl; |
6 | use Coro::AIO; |
6 | use Coro::AIO; |
7 | use List::Util qw(min max); |
7 | use List::Util qw(min max); |
8 | |
8 | |
9 | my $PLAYERDIR = sprintf "%s/%s", cf::localdir, cf::playerdir; |
|
|
10 | |
|
|
11 | # paranoia function to overwrite a string-in-place |
9 | # paranoia function to overwrite a string-in-place |
12 | sub nuke_str { |
10 | sub nuke_str { |
13 | substr $_[0], 0, (length $_[0]), "x" x length $_[0] |
11 | substr $_[0], 0, (length $_[0]), "x" x length $_[0] |
14 | } |
12 | } |
15 | |
13 | |
16 | sub query { |
14 | sub query { |
17 | my ($ns, $flags, $text) = @_; |
15 | my ($ns, $flags, $text) = @_; |
18 | |
16 | |
19 | my $current = $Coro::current; |
17 | my $current = $Coro::current; |
20 | $ns->query ($flags, $text, sub { $current->ready; $current = $_[0]; }); |
18 | $ns->query ($flags, $text, sub { $current->ready; $current = $_[0] }); |
21 | Coro::schedule while ref $current; |
19 | Coro::schedule while ref $current; |
22 | |
20 | |
23 | $current |
21 | $current |
24 | } |
22 | } |
25 | |
23 | |
… | |
… | |
76 | |
74 | |
77 | aio_stat "$PLAYERDIR/$user"; |
75 | aio_stat "$PLAYERDIR/$user"; |
78 | system "cd \Q$PLAYERDIR\E " |
76 | system "cd \Q$PLAYERDIR\E " |
79 | . "&& mv \Q$user\E ~\Q$Coro::current\E~deleting~ 2>/dev/null " |
77 | . "&& mv \Q$user\E ~\Q$Coro::current\E~deleting~ 2>/dev/null " |
80 | . "&& (rm -rf ~\Q$Coro::current\E~deleting~ &)"; |
78 | . "&& (rm -rf ~\Q$Coro::current\E~deleting~ &)"; |
|
|
79 | } |
|
|
80 | |
|
|
81 | sub send_capabilities { |
|
|
82 | my ($ns) = @_; |
|
|
83 | |
|
|
84 | return unless $ns->extcmd; |
|
|
85 | |
|
|
86 | $ns->ext_event (capabilities => |
|
|
87 | # id, name, flags (1 == 2d), edge length |
|
|
88 | tileset => [[1, "default 64x64 faceset", 1, 64], [0, "default 32x32 faceset", 1, 32]], |
|
|
89 | ); |
|
|
90 | } |
|
|
91 | |
|
|
92 | sub setup { |
|
|
93 | my ($ns, $args) = @_; |
|
|
94 | |
|
|
95 | # run through the cmds of setup |
|
|
96 | # syntax is setup <cmdname1> <parameter> <cmdname2> <parameter> ... |
|
|
97 | # |
|
|
98 | # we send the status of the cmd back, or a FALSE is the cmd is the server unknown |
|
|
99 | # The client then must sort this out |
|
|
100 | |
|
|
101 | my %setup = split / +/, $args; |
|
|
102 | while (my ($k, $v) = each %setup) { |
|
|
103 | if ($k eq "sound") { |
|
|
104 | $ns->sound ($v); |
|
|
105 | |
|
|
106 | } elsif ($k eq "exp64") { |
|
|
107 | $setup{$k} = 1; |
|
|
108 | |
|
|
109 | } elsif ($k eq "spellmon") { |
|
|
110 | $ns->monitor_spells ($v); |
|
|
111 | |
|
|
112 | } elsif ($k eq "darkness") { |
|
|
113 | $ns->darkness ($v); |
|
|
114 | |
|
|
115 | } elsif ($k eq "map1cmd") { |
|
|
116 | $ns->mapmode (cf::Map1Cmd) if $v > 0; |
|
|
117 | |
|
|
118 | } elsif ($k eq "map1acmd") { |
|
|
119 | $ns->mapmode (cf::Map1aCmd) if $v > 0; |
|
|
120 | |
|
|
121 | } elsif ($k eq "map2cmd") { |
|
|
122 | # gcfclient bug, map1acmd is sent too late |
|
|
123 | $ns->mapmode (cf::Map1aCmd); |
|
|
124 | $setup{$k} = "FALSE"; |
|
|
125 | |
|
|
126 | } elsif ($k eq "newmapcmd") { |
|
|
127 | $ns->newmapcmd ($v); |
|
|
128 | |
|
|
129 | } elsif ($k eq "mapinfocmd") { |
|
|
130 | $ns->mapinfocmd ($v); |
|
|
131 | |
|
|
132 | } elsif ($k eq "extcmd") { |
|
|
133 | $ns->extcmd ($v > 0); |
|
|
134 | send_capabilities $ns; |
|
|
135 | |
|
|
136 | } elsif ($k eq "extmap") { |
|
|
137 | $ns->extmap ($v); |
|
|
138 | |
|
|
139 | } elsif ($k eq "facecache") { |
|
|
140 | if (!$v) { |
|
|
141 | $v = 1; |
|
|
142 | $setup{$k} = $v; |
|
|
143 | $ns->send_drawinfo ("(trying to forcefully enable facecaching)", cf::NDI_RED); |
|
|
144 | } |
|
|
145 | |
|
|
146 | $ns->facecache ($v); |
|
|
147 | |
|
|
148 | } elsif ($k eq "faceset") { |
|
|
149 | $ns->faceset (0); |
|
|
150 | $setup{$k} = 0; |
|
|
151 | # $ns->image2 (1) |
|
|
152 | |
|
|
153 | } elsif ($k eq "tileset") { |
|
|
154 | $setup{$k} = $ns->faceset ($v & 1); |
|
|
155 | |
|
|
156 | } elsif ($k eq "itemcmd") { |
|
|
157 | # Version of the item protocol command to use. Currently, |
|
|
158 | # only supported versions are 1 and 2. Using a numeric |
|
|
159 | # value will make it very easy to extend this in the future. |
|
|
160 | $ns->itemcmd ($v) if $v >= 1 && $v <= 2; |
|
|
161 | |
|
|
162 | $setup{$k} = $ns->itemcmd; |
|
|
163 | |
|
|
164 | } elsif ($k eq "mapsize") { |
|
|
165 | my ($x, $y) = split /x/, $v; |
|
|
166 | |
|
|
167 | $ns->mapx ($x = max 9, min cf::MAP_CLIENT_X, ($x - 1) | 1); |
|
|
168 | $ns->mapy ($y = max 9, min cf::MAP_CLIENT_Y, ($y - 1) | 1); |
|
|
169 | |
|
|
170 | $setup{$k} = "${x}x${y}"; |
|
|
171 | |
|
|
172 | } elsif ($k eq "extendedMapInfos") { |
|
|
173 | $ns->ext_mapinfos ($v); |
|
|
174 | |
|
|
175 | } elsif ($k eq "extendedTextInfos") { |
|
|
176 | $ns->has_readable_type ($v); |
|
|
177 | |
|
|
178 | } elsif ($k eq "smoothing") { # cfplus-style smoothing |
|
|
179 | $ns->smoothing ($v); |
|
|
180 | |
|
|
181 | } elsif ($k eq "fxix") { |
|
|
182 | $ns->fxix ($v); |
|
|
183 | |
|
|
184 | } elsif ($k eq "msg") { |
|
|
185 | $ns->can_msg ($v); |
|
|
186 | |
|
|
187 | } elsif ($k eq "excmd") { |
|
|
188 | # we support it |
|
|
189 | |
|
|
190 | } else { |
|
|
191 | # other commands: |
|
|
192 | # sexp: no idea, probably for oudated servers |
|
|
193 | # tick: more stupidity, server should send a tick per tick |
|
|
194 | |
|
|
195 | $setup{$k} = "FALSE"; |
|
|
196 | } |
|
|
197 | } |
|
|
198 | |
|
|
199 | $ns->send_packet (join " ", setup => %setup); |
|
|
200 | |
|
|
201 | cf::datalog setup => |
|
|
202 | request => $args, |
|
|
203 | reply => \%setup, |
|
|
204 | client => $ns->version, |
|
|
205 | ; |
81 | } |
206 | } |
82 | |
207 | |
83 | sub addme { |
208 | sub addme { |
84 | my ($ns) = @_; |
209 | my ($ns) = @_; |
85 | |
210 | |
… | |
… | |
111 | $ns->flush; |
236 | $ns->flush; |
112 | return $ns->destroy; |
237 | return $ns->destroy; |
113 | } |
238 | } |
114 | |
239 | |
115 | # $ns->facecache = true; |
240 | # $ns->facecache = true; |
116 | } |
241 | } |
|
|
242 | |
|
|
243 | if ($ns->mapmode < cf::Map1aCmd) { |
|
|
244 | $ns->send_drawinfo (<<EOF, cf::NDI_RED); |
|
|
245 | |
|
|
246 | |
|
|
247 | *** |
|
|
248 | *** WARNING: |
|
|
249 | *** Your client is too old. Please upgrade to a newer version. |
|
|
250 | EOF |
|
|
251 | |
|
|
252 | $ns->flush; |
|
|
253 | return $ns->destroy; |
|
|
254 | } |
117 | |
255 | |
118 | $ns->pl and return $ns->destroy; |
256 | $ns->pl and return $ns->destroy; |
119 | |
257 | |
120 | $ns->async (sub { |
258 | $ns->async (sub { |
121 | my ($user, $pass); |
259 | my ($user, $pass); |
… | |
… | |
229 | . "(check for Numlock and other semi-obvious error sources).", |
367 | . "(check for Numlock and other semi-obvious error sources).", |
230 | cf::NDI_RED |
368 | cf::NDI_RED |
231 | ); |
369 | ); |
232 | next; |
370 | next; |
233 | } |
371 | } |
|
|
372 | } else { |
|
|
373 | # unable to load the playerfile: |
|
|
374 | # check wether the player dir exists, which means the file is corrupted or |
|
|
375 | # something very similar. |
|
|
376 | if (!aio_stat cf::player::playerdir $user) { |
|
|
377 | $ns->send_drawinfo ( |
|
|
378 | "Unable to retrieve this player. It might be a locked or broken account. " |
|
|
379 | . "If this is your account, ask a dungeon master for assistance. " |
|
|
380 | . "Otherwise choose a different login name.", |
|
|
381 | cf::NDI_RED |
|
|
382 | ); |
|
|
383 | next; |
|
|
384 | } |
234 | } |
385 | } |
235 | |
386 | |
236 | # the rest of this function is character creation |
387 | # the rest of this function is character creation |
237 | |
388 | |
238 | # just to make sure nothing is left over |
389 | # just to make sure nothing is left over |
… | |
… | |
280 | } |
431 | } |
281 | |
432 | |
282 | $ob->set_animation (2); |
433 | $ob->set_animation (2); |
283 | $ob->add_statbonus; |
434 | $ob->add_statbonus; |
284 | |
435 | |
285 | $ns->send_drawinfo ($ob->msg, cf::NDI_BLUE); |
436 | while () { |
286 | $ns->send_packet (sprintf "query %d %s", cf::CS_QUERY_SINGLECHAR, |
437 | $ns->send_msg (-1, "chargen-race-title", ucfirst $pl->title); |
|
|
438 | my $msg = $ob->msg; |
|
|
439 | $msg =~ s/(?<=\S)\n(?=\S)/ /g; |
|
|
440 | $ns->send_msg (cf::NDI_BLUE, "chargen-race-description", $msg); |
|
|
441 | |
|
|
442 | my $res = query $ns, cf::CS_QUERY_SINGLECHAR, |
287 | "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n"); |
443 | "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n"; |
288 | |
444 | |
289 | $ns->state (cf::ST_CHANGE_CLASS); |
445 | last if $res =~ /[dD]/; |
|
|
446 | |
|
|
447 | $pl->chargen_race_next; |
|
|
448 | } |
|
|
449 | |
|
|
450 | $pl->chargen_race_done; |
|
|
451 | |
290 | delete $pl->{deny_save};#d# too early |
452 | delete $pl->{deny_save}; |
291 | |
453 | |
292 | last; |
454 | last; |
293 | } |
455 | } |
294 | }); |
456 | }); |
295 | } |
457 | } |
… | |
… | |
371 | $pl->{unclean_save} = $cf::RUNTIME; |
533 | $pl->{unclean_save} = $cf::RUNTIME; |
372 | } |
534 | } |
373 | }, |
535 | }, |
374 | ); |
536 | ); |
375 | |
537 | |
376 | sub setup { |
|
|
377 | my ($ns, $args) = @_; |
|
|
378 | |
|
|
379 | # run through the cmds of setup |
|
|
380 | # syntax is setup <cmdname1> <parameter> <cmdname2> <parameter> ... |
|
|
381 | # |
|
|
382 | # we send the status of the cmd back, or a FALSE is the cmd is the server unknown |
|
|
383 | # The client then must sort this out |
|
|
384 | |
|
|
385 | my %setup = split / +/, $args; |
|
|
386 | while (my ($k, $v) = each %setup) { |
|
|
387 | |
|
|
388 | if ($k eq "sound") { |
|
|
389 | $ns->sound ($v); |
|
|
390 | |
|
|
391 | } elsif ($k eq "exp64") { |
|
|
392 | $setup{$k} = 1; |
|
|
393 | |
|
|
394 | } elsif ($k eq "spellmon") { |
|
|
395 | $ns->monitor_spells ($v); |
|
|
396 | |
|
|
397 | } elsif ($k eq "darkness") { |
|
|
398 | $ns->darkness ($v); |
|
|
399 | |
|
|
400 | } elsif ($k eq "map1cmd") { |
|
|
401 | $ns->mapmode (cf::Map1Cmd) if $v > 0; |
|
|
402 | |
|
|
403 | } elsif ($k eq "map1acmd") { |
|
|
404 | $ns->mapmode (cf::Map1aCmd) if $v > 0; |
|
|
405 | |
|
|
406 | } elsif ($k eq "newmapcmd") { |
|
|
407 | $ns->newmapcmd ($v); |
|
|
408 | |
|
|
409 | } elsif ($k eq "mapinfocmd") { |
|
|
410 | $ns->mapinfocmd ($v); |
|
|
411 | |
|
|
412 | } elsif ($k eq "extcmd") { |
|
|
413 | $ns->extcmd ($v > 0); |
|
|
414 | |
|
|
415 | } elsif ($k eq "extmap") { |
|
|
416 | $ns->extmap ($v); |
|
|
417 | |
|
|
418 | } elsif ($k eq "facecache") { |
|
|
419 | $ns->facecache ($v); |
|
|
420 | |
|
|
421 | } elsif ($k eq "faceset") { |
|
|
422 | $ns->faceset (0); |
|
|
423 | $setup{$k} = 0; |
|
|
424 | # $ns->image2 (1) |
|
|
425 | |
|
|
426 | } elsif ($k eq "itemcmd") { |
|
|
427 | # Version of the item protocol command to use. Currently, |
|
|
428 | # only supported versions are 1 and 2. Using a numeric |
|
|
429 | # value will make it very easy to extend this in the future. |
|
|
430 | $ns->itemcmd ($v) if $v >= 1 && $v <= 2; |
|
|
431 | |
|
|
432 | $setup{$k} = $ns->itemcmd; |
|
|
433 | |
|
|
434 | } elsif ($k eq "mapsize") { |
|
|
435 | my ($x, $y) = split /x/, $v; |
|
|
436 | |
|
|
437 | $ns->mapx ($x = max 9, min cf::MAP_CLIENT_X, $x); |
|
|
438 | $ns->mapy ($y = max 9, min cf::MAP_CLIENT_Y, $y); |
|
|
439 | |
|
|
440 | $setup{$k} = "${x}x${y}"; |
|
|
441 | |
|
|
442 | } elsif ($k eq "extendedMapInfos") { |
|
|
443 | $ns->ext_mapinfos ($v); |
|
|
444 | |
|
|
445 | } elsif ($k eq "extendedTextInfos") { |
|
|
446 | $ns->has_readable_type ($v); |
|
|
447 | |
|
|
448 | } else { |
|
|
449 | # other commands: |
|
|
450 | # sexp: no idea, probably for oudated servers |
|
|
451 | # tick: more stupidity, server should sned a tick per tick |
|
|
452 | |
|
|
453 | $setup{$k} = "FALSE"; |
|
|
454 | } |
|
|
455 | } |
|
|
456 | |
|
|
457 | $ns->send_packet (join " ", setup => %setup); |
|
|
458 | |
|
|
459 | cf::datalog setup => |
|
|
460 | request => $args, |
|
|
461 | reply => \%setup, |
|
|
462 | client => $ns->version, |
|
|
463 | ; |
|
|
464 | } |
|
|
465 | |
|
|
466 | cf::client->attach ( |
538 | cf::client->attach ( |
467 | on_addme => \&addme, |
539 | on_addme => \&addme, |
468 | on_setup => \&setup, |
540 | on_setup => \&setup, |
469 | ); |
541 | ); |
470 | |
542 | |
… | |
… | |
488 | or next; |
560 | or next; |
489 | $pl->valid or next; |
561 | $pl->valid or next; |
490 | |
562 | |
491 | eval { |
563 | eval { |
492 | if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { |
564 | if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { |
493 | $cf::WAIT_FOR_TICK_ONE->wait; |
565 | cf::wait_for_tick_begin; |
494 | $pl->save; |
566 | $pl->save; |
495 | |
567 | |
496 | unless ($pl->active) { |
568 | unless ($pl->active) { |
497 | # check refcounts, this is tricky and needs to be adjusted to fit server internals |
569 | # check refcounts, this is tricky and needs to be adjusted to fit server internals |
498 | my $ob = $pl->ob; |
570 | my $ob = $pl->ob; |