… | |
… | |
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 | |
… | |
… | |
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~ &)"; |
81 | } |
79 | } |
82 | |
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 | |
83 | sub setup { |
92 | sub setup { |
84 | my ($ns, $args) = @_; |
93 | my ($ns, $args) = @_; |
85 | |
94 | |
86 | # run through the cmds of setup |
95 | # run through the cmds of setup |
87 | # syntax is setup <cmdname1> <parameter> <cmdname2> <parameter> ... |
96 | # syntax is setup <cmdname1> <parameter> <cmdname2> <parameter> ... |
… | |
… | |
89 | # we send the status of the cmd back, or a FALSE is the cmd is the server unknown |
98 | # we send the status of the cmd back, or a FALSE is the cmd is the server unknown |
90 | # The client then must sort this out |
99 | # The client then must sort this out |
91 | |
100 | |
92 | my %setup = split / +/, $args; |
101 | my %setup = split / +/, $args; |
93 | while (my ($k, $v) = each %setup) { |
102 | while (my ($k, $v) = each %setup) { |
94 | |
|
|
95 | if ($k eq "sound") { |
103 | if ($k eq "sound") { |
96 | $ns->sound ($v); |
104 | $ns->sound ($v); |
97 | |
105 | |
98 | } elsif ($k eq "exp64") { |
106 | } elsif ($k eq "exp64") { |
99 | $setup{$k} = 1; |
107 | $setup{$k} = 1; |
100 | |
108 | |
101 | } elsif ($k eq "spellmon") { |
109 | } elsif ($k eq "spellmon") { |
102 | $ns->monitor_spells ($v); |
110 | $ns->monitor_spells ($v); |
103 | |
111 | |
104 | } elsif ($k eq "darkness") { |
112 | } elsif ($k eq "darkness") { |
105 | $ns->darkness ($v); |
113 | $ns->darkness ($v); |
106 | |
114 | |
107 | } elsif ($k eq "map1cmd") { |
115 | } elsif ($k eq "map1cmd") { |
108 | $ns->mapmode (cf::Map1Cmd) if $v > 0; |
116 | $ns->mapmode (cf::Map1Cmd) if $v > 0; |
109 | |
117 | |
110 | } elsif ($k eq "map1acmd") { |
118 | } elsif ($k eq "map1acmd") { |
111 | $ns->mapmode (cf::Map1aCmd) if $v > 0; |
119 | $ns->mapmode (cf::Map1aCmd) if $v > 0; |
112 | |
120 | |
113 | } elsif ($k eq "map2cmd") { |
121 | } elsif ($k eq "map2cmd") { |
114 | # gcfclient bug, map1acmd is sent too late |
122 | # gcfclient bug, map1acmd is sent too late |
115 | $ns->mapmode (cf::Map1aCmd); |
123 | $ns->mapmode (cf::Map1aCmd); |
116 | $setup{$k} = "FALSE"; |
124 | $setup{$k} = "FALSE"; |
117 | |
125 | |
118 | } elsif ($k eq "newmapcmd") { |
126 | } elsif ($k eq "newmapcmd") { |
119 | $ns->newmapcmd ($v); |
127 | $ns->newmapcmd ($v); |
120 | |
128 | |
121 | } elsif ($k eq "mapinfocmd") { |
129 | } elsif ($k eq "mapinfocmd") { |
122 | $ns->mapinfocmd ($v); |
130 | $ns->mapinfocmd ($v); |
123 | |
131 | |
124 | } elsif ($k eq "extcmd") { |
132 | } elsif ($k eq "extcmd") { |
125 | $ns->extcmd ($v > 0); |
133 | $ns->extcmd ($v > 0); |
|
|
134 | send_capabilities $ns; |
126 | |
135 | |
127 | } elsif ($k eq "extmap") { |
136 | } elsif ($k eq "extmap") { |
128 | $ns->extmap ($v); |
137 | $ns->extmap ($v); |
129 | |
138 | |
130 | } elsif ($k eq "facecache") { |
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 | |
131 | $ns->facecache ($v); |
146 | $ns->facecache ($v); |
132 | |
147 | |
133 | } elsif ($k eq "faceset") { |
148 | } elsif ($k eq "faceset") { |
134 | $ns->faceset (0); |
149 | $ns->faceset (0); |
135 | $setup{$k} = 0; |
150 | $setup{$k} = 0; |
136 | # $ns->image2 (1) |
151 | # $ns->image2 (1) |
|
|
152 | |
|
|
153 | } elsif ($k eq "tileset") { |
|
|
154 | $setup{$k} = $ns->faceset ($v & 1); |
137 | |
155 | |
138 | } elsif ($k eq "itemcmd") { |
156 | } elsif ($k eq "itemcmd") { |
139 | # Version of the item protocol command to use. Currently, |
157 | # Version of the item protocol command to use. Currently, |
140 | # only supported versions are 1 and 2. Using a numeric |
158 | # only supported versions are 1 and 2. Using a numeric |
141 | # value will make it very easy to extend this in the future. |
159 | # value will make it very easy to extend this in the future. |
142 | $ns->itemcmd ($v) if $v >= 1 && $v <= 2; |
160 | $ns->itemcmd ($v) if $v >= 1 && $v <= 2; |
143 | |
161 | |
144 | $setup{$k} = $ns->itemcmd; |
162 | $setup{$k} = $ns->itemcmd; |
145 | |
163 | |
146 | } elsif ($k eq "mapsize") { |
164 | } elsif ($k eq "mapsize") { |
147 | my ($x, $y) = split /x/, $v; |
165 | my ($x, $y) = split /x/, $v; |
148 | |
166 | |
149 | $ns->mapx ($x = max 9, min cf::MAP_CLIENT_X, $x); |
167 | $ns->mapx ($x = max 9, min cf::MAP_CLIENT_X, ($x - 1) | 1); |
150 | $ns->mapy ($y = max 9, min cf::MAP_CLIENT_Y, $y); |
168 | $ns->mapy ($y = max 9, min cf::MAP_CLIENT_Y, ($y - 1) | 1); |
151 | |
169 | |
152 | $setup{$k} = "${x}x${y}"; |
170 | $setup{$k} = "${x}x${y}"; |
153 | |
171 | |
154 | } elsif ($k eq "extendedMapInfos") { |
172 | } elsif ($k eq "extendedMapInfos") { |
155 | $ns->ext_mapinfos ($v); |
173 | $ns->ext_mapinfos ($v); |
156 | |
174 | |
157 | } elsif ($k eq "extendedTextInfos") { |
175 | } elsif ($k eq "extendedTextInfos") { |
158 | $ns->has_readable_type ($v); |
176 | $ns->has_readable_type ($v); |
|
|
177 | |
|
|
178 | } elsif ($k eq "smoothing") { # cfplus-style smoothing |
|
|
179 | $ns->smoothing ($v); |
159 | |
180 | |
160 | } elsif ($k eq "fxix") { |
181 | } elsif ($k eq "fxix") { |
161 | $ns->fxix ($v); |
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 |
162 | |
189 | |
163 | } else { |
190 | } else { |
164 | # other commands: |
191 | # other commands: |
165 | # sexp: no idea, probably for oudated servers |
192 | # sexp: no idea, probably for oudated servers |
166 | # tick: more stupidity, server should sned a tick per tick |
193 | # tick: more stupidity, server should send a tick per tick |
167 | |
194 | |
168 | $setup{$k} = "FALSE"; |
195 | $setup{$k} = "FALSE"; |
169 | } |
196 | } |
170 | } |
197 | } |
171 | |
198 | |
172 | $ns->send_packet (join " ", setup => %setup); |
199 | $ns->send_packet (join " ", setup => %setup); |
173 | |
200 | |
… | |
… | |
340 | . "(check for Numlock and other semi-obvious error sources).", |
367 | . "(check for Numlock and other semi-obvious error sources).", |
341 | cf::NDI_RED |
368 | cf::NDI_RED |
342 | ); |
369 | ); |
343 | next; |
370 | next; |
344 | } |
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 | } |
345 | } |
385 | } |
346 | |
386 | |
347 | # the rest of this function is character creation |
387 | # the rest of this function is character creation |
348 | |
388 | |
349 | # just to make sure nothing is left over |
389 | # just to make sure nothing is left over |
… | |
… | |
391 | } |
431 | } |
392 | |
432 | |
393 | $ob->set_animation (2); |
433 | $ob->set_animation (2); |
394 | $ob->add_statbonus; |
434 | $ob->add_statbonus; |
395 | |
435 | |
396 | $ns->send_drawinfo ($ob->msg, cf::NDI_BLUE); |
436 | while () { |
397 | $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, |
398 | "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"; |
399 | |
444 | |
400 | $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 | |
401 | delete $pl->{deny_save};#d# too early |
452 | delete $pl->{deny_save}; |
402 | |
453 | |
403 | last; |
454 | last; |
404 | } |
455 | } |
405 | }); |
456 | }); |
406 | } |
457 | } |
… | |
… | |
509 | or next; |
560 | or next; |
510 | $pl->valid or next; |
561 | $pl->valid or next; |
511 | |
562 | |
512 | eval { |
563 | eval { |
513 | if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { |
564 | if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { |
514 | $cf::WAIT_FOR_TICK_ONE->wait; |
565 | cf::wait_for_tick_begin; |
515 | $pl->save; |
566 | $pl->save; |
516 | |
567 | |
517 | unless ($pl->active) { |
568 | unless ($pl->active) { |
518 | # 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 |
519 | my $ob = $pl->ob; |
570 | my $ob = $pl->ob; |