… | |
… | |
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 | |
… | |
… | |
101 | # The client then must sort this out |
99 | # The client then must sort this out |
102 | |
100 | |
103 | my %setup = split / +/, $args; |
101 | my %setup = split / +/, $args; |
104 | while (my ($k, $v) = each %setup) { |
102 | while (my ($k, $v) = each %setup) { |
105 | if ($k eq "sound") { |
103 | if ($k eq "sound") { |
106 | $ns->sound ($v); |
104 | $ns->sound ($v); |
107 | |
105 | |
108 | } elsif ($k eq "exp64") { |
106 | } elsif ($k eq "exp64") { |
109 | $setup{$k} = 1; |
107 | $setup{$k} = 1; |
110 | |
108 | |
111 | } elsif ($k eq "spellmon") { |
109 | } elsif ($k eq "spellmon") { |
112 | $ns->monitor_spells ($v); |
110 | $ns->monitor_spells ($v); |
113 | |
111 | |
114 | } elsif ($k eq "darkness") { |
112 | } elsif ($k eq "darkness") { |
115 | $ns->darkness ($v); |
113 | $ns->darkness ($v); |
116 | |
114 | |
117 | } elsif ($k eq "map1cmd") { |
115 | } elsif ($k eq "map1cmd") { |
118 | $ns->mapmode (cf::Map1Cmd) if $v > 0; |
116 | $ns->mapmode (cf::Map1Cmd) if $v > 0; |
119 | |
117 | |
120 | } elsif ($k eq "map1acmd") { |
118 | } elsif ($k eq "map1acmd") { |
121 | $ns->mapmode (cf::Map1aCmd) if $v > 0; |
119 | $ns->mapmode (cf::Map1aCmd) if $v > 0; |
122 | |
120 | |
123 | } elsif ($k eq "map2cmd") { |
121 | } elsif ($k eq "map2cmd") { |
124 | # gcfclient bug, map1acmd is sent too late |
122 | # gcfclient bug, map1acmd is sent too late |
125 | $ns->mapmode (cf::Map1aCmd); |
123 | $ns->mapmode (cf::Map1aCmd); |
126 | $setup{$k} = "FALSE"; |
124 | $setup{$k} = "FALSE"; |
127 | |
125 | |
128 | } elsif ($k eq "newmapcmd") { |
126 | } elsif ($k eq "newmapcmd") { |
129 | $ns->newmapcmd ($v); |
127 | $ns->newmapcmd ($v); |
130 | |
128 | |
131 | } elsif ($k eq "mapinfocmd") { |
129 | } elsif ($k eq "mapinfocmd") { |
132 | $ns->mapinfocmd ($v); |
130 | $ns->mapinfocmd ($v); |
133 | |
131 | |
134 | } elsif ($k eq "extcmd") { |
132 | } elsif ($k eq "extcmd") { |
135 | $ns->extcmd ($v > 0); |
133 | $ns->extcmd ($v > 0); |
136 | send_capabilities $ns; |
134 | send_capabilities $ns; |
137 | |
135 | |
138 | } elsif ($k eq "extmap") { |
136 | } elsif ($k eq "extmap") { |
139 | $ns->extmap ($v); |
137 | $ns->extmap ($v); |
140 | |
138 | |
141 | } 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 | |
142 | $ns->facecache ($v); |
146 | $ns->facecache ($v); |
143 | |
147 | |
144 | } elsif ($k eq "faceset") { |
148 | } elsif ($k eq "faceset") { |
145 | $ns->faceset (0); |
149 | $ns->faceset (0); |
146 | $setup{$k} = 0; |
150 | $setup{$k} = 0; |
147 | # $ns->image2 (1) |
151 | # $ns->image2 (1) |
148 | |
152 | |
149 | } elsif ($k eq "tileset") { |
153 | } elsif ($k eq "tileset") { |
150 | $setup{$k} = $ns->faceset ($v & 1); |
154 | $setup{$k} = $ns->faceset ($v & 1); |
151 | |
155 | |
152 | } elsif ($k eq "itemcmd") { |
156 | } elsif ($k eq "itemcmd") { |
153 | # Version of the item protocol command to use. Currently, |
157 | # Version of the item protocol command to use. Currently, |
154 | # only supported versions are 1 and 2. Using a numeric |
158 | # only supported versions are 1 and 2. Using a numeric |
155 | # 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. |
156 | $ns->itemcmd ($v) if $v >= 1 && $v <= 2; |
160 | $ns->itemcmd ($v) if $v >= 1 && $v <= 2; |
157 | |
161 | |
158 | $setup{$k} = $ns->itemcmd; |
162 | $setup{$k} = $ns->itemcmd; |
159 | |
163 | |
160 | } elsif ($k eq "mapsize") { |
164 | } elsif ($k eq "mapsize") { |
161 | my ($x, $y) = split /x/, $v; |
165 | my ($x, $y) = split /x/, $v; |
162 | |
166 | |
163 | $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); |
164 | $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); |
165 | |
169 | |
166 | $setup{$k} = "${x}x${y}"; |
170 | $setup{$k} = "${x}x${y}"; |
167 | |
171 | |
168 | } elsif ($k eq "extendedMapInfos") { |
172 | } elsif ($k eq "extendedMapInfos") { |
169 | $ns->ext_mapinfos ($v); |
173 | $ns->ext_mapinfos ($v); |
170 | |
174 | |
171 | } elsif ($k eq "extendedTextInfos") { |
175 | } elsif ($k eq "extendedTextInfos") { |
172 | $ns->has_readable_type ($v); |
176 | $ns->has_readable_type ($v); |
|
|
177 | |
|
|
178 | } elsif ($k eq "smoothing") { # cfplus-style smoothing |
|
|
179 | $ns->smoothing ($v); |
173 | |
180 | |
174 | } elsif ($k eq "fxix") { |
181 | } elsif ($k eq "fxix") { |
175 | $ns->fxix ($v); |
182 | $ns->fxix ($v); |
|
|
183 | |
|
|
184 | } elsif ($k eq "msg") { |
|
|
185 | $ns->{setup}{msg} = $v; |
176 | |
186 | |
177 | } else { |
187 | } else { |
178 | # other commands: |
188 | # other commands: |
179 | # sexp: no idea, probably for oudated servers |
189 | # sexp: no idea, probably for oudated servers |
180 | # tick: more stupidity, server should sned a tick per tick |
190 | # tick: more stupidity, server should sned a tick per tick |
181 | |
191 | |
182 | $setup{$k} = "FALSE"; |
192 | $setup{$k} = "FALSE"; |
183 | } |
193 | } |
184 | } |
194 | } |
185 | |
195 | |
186 | $ns->send_packet (join " ", setup => %setup); |
196 | $ns->send_packet (join " ", setup => %setup); |
187 | |
197 | |
… | |
… | |
354 | . "(check for Numlock and other semi-obvious error sources).", |
364 | . "(check for Numlock and other semi-obvious error sources).", |
355 | cf::NDI_RED |
365 | cf::NDI_RED |
356 | ); |
366 | ); |
357 | next; |
367 | next; |
358 | } |
368 | } |
|
|
369 | } else { |
|
|
370 | # unable to load the playerfile: |
|
|
371 | # check wether the player dir exists, which means the file is corrupted or |
|
|
372 | # something very similar. |
|
|
373 | if (!aio_stat cf::player::playerdir $user) { |
|
|
374 | $ns->send_drawinfo ( |
|
|
375 | "Unable to retrieve this player. It might be a locked or broken account. " |
|
|
376 | . "If this is your account, ask a dungeon master for assistance. " |
|
|
377 | . "Otherwise choose a different login name.", |
|
|
378 | cf::NDI_RED |
|
|
379 | ); |
|
|
380 | next; |
|
|
381 | } |
359 | } |
382 | } |
360 | |
383 | |
361 | # the rest of this function is character creation |
384 | # the rest of this function is character creation |
362 | |
385 | |
363 | # just to make sure nothing is left over |
386 | # just to make sure nothing is left over |
… | |
… | |
523 | or next; |
546 | or next; |
524 | $pl->valid or next; |
547 | $pl->valid or next; |
525 | |
548 | |
526 | eval { |
549 | eval { |
527 | if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { |
550 | if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { |
528 | $cf::WAIT_FOR_TICK_ONE->wait; |
551 | cf::wait_for_tick_begin; |
529 | $pl->save; |
552 | $pl->save; |
530 | |
553 | |
531 | unless ($pl->active) { |
554 | unless ($pl->active) { |
532 | # check refcounts, this is tricky and needs to be adjusted to fit server internals |
555 | # check refcounts, this is tricky and needs to be adjusted to fit server internals |
533 | my $ob = $pl->ob; |
556 | my $ob = $pl->ob; |