… | |
… | |
3 | # login handling |
3 | # login handling |
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 | |
|
|
9 | my $PLAYERDIR = sprintf "%s/%s", cf::localdir, cf::playerdir; |
|
|
10 | |
8 | |
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 | } |
… | |
… | |
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") { |
142 | if (!$v) { |
140 | if (!$v) { |
143 | $v = 1; |
141 | $v = 1; |
144 | $setup{$k} = $v; |
142 | $setup{$k} = $v; |
145 | $ns->send_drawinfo ("(trying to forcefully enable facecaching)", cf::NDI_RED); |
143 | $ns->send_drawinfo ("(trying to forcefully enable facecaching)", cf::NDI_RED); |
146 | } |
144 | } |
147 | |
145 | |
148 | $ns->facecache ($v); |
146 | $ns->facecache ($v); |
149 | |
147 | |
150 | } elsif ($k eq "faceset") { |
148 | } elsif ($k eq "faceset") { |
151 | $ns->faceset (0); |
149 | $ns->faceset (0); |
152 | $setup{$k} = 0; |
150 | $setup{$k} = 0; |
153 | # $ns->image2 (1) |
151 | # $ns->image2 (1) |
154 | |
152 | |
155 | } elsif ($k eq "tileset") { |
153 | } elsif ($k eq "tileset") { |
156 | $setup{$k} = $ns->faceset ($v & 1); |
154 | $setup{$k} = $ns->faceset ($v & 1); |
157 | |
155 | |
158 | } elsif ($k eq "itemcmd") { |
156 | } elsif ($k eq "itemcmd") { |
159 | # Version of the item protocol command to use. Currently, |
157 | # Version of the item protocol command to use. Currently, |
160 | # only supported versions are 1 and 2. Using a numeric |
158 | # only supported versions are 1 and 2. Using a numeric |
161 | # 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. |
162 | $ns->itemcmd ($v) if $v >= 1 && $v <= 2; |
160 | $ns->itemcmd ($v) if $v >= 1 && $v <= 2; |
163 | |
161 | |
164 | $setup{$k} = $ns->itemcmd; |
162 | $setup{$k} = $ns->itemcmd; |
165 | |
163 | |
166 | } elsif ($k eq "mapsize") { |
164 | } elsif ($k eq "mapsize") { |
167 | my ($x, $y) = split /x/, $v; |
165 | my ($x, $y) = split /x/, $v; |
168 | |
166 | |
169 | $ns->mapx ($x = max 9, min cf::MAP_CLIENT_X, ($x - 1) | 1); |
167 | $ns->mapx ($x = max 9, min cf::MAP_CLIENT_X, ($x - 1) | 1); |
170 | $ns->mapy ($y = max 9, min cf::MAP_CLIENT_Y, ($y - 1) | 1); |
168 | $ns->mapy ($y = max 9, min cf::MAP_CLIENT_Y, ($y - 1) | 1); |
171 | |
169 | |
172 | $setup{$k} = "${x}x${y}"; |
170 | $setup{$k} = "${x}x${y}"; |
173 | |
171 | |
174 | } elsif ($k eq "extendedMapInfos") { |
172 | } elsif ($k eq "extendedMapInfos") { |
175 | $ns->ext_mapinfos ($v); |
173 | $ns->ext_mapinfos ($v); |
176 | |
174 | |
177 | } elsif ($k eq "extendedTextInfos") { |
175 | } elsif ($k eq "extendedTextInfos") { |
178 | $ns->has_readable_type ($v); |
176 | $ns->has_readable_type ($v); |
179 | |
177 | |
180 | } elsif ($k eq "smoothing") { # cfplus-style smoothing |
178 | } elsif ($k eq "smoothing") { # cfplus-style smoothing |
181 | $ns->smoothing ($v); |
179 | $ns->smoothing ($v); |
182 | |
180 | |
183 | } elsif ($k eq "fxix") { |
181 | } elsif ($k eq "fxix") { |
184 | $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 |
185 | |
189 | |
186 | } else { |
190 | } else { |
187 | # other commands: |
191 | # other commands: |
188 | # sexp: no idea, probably for oudated servers |
192 | # sexp: no idea, probably for oudated servers |
189 | # tick: more stupidity, server should sned a tick per tick |
193 | # tick: more stupidity, server should send a tick per tick |
190 | |
194 | |
191 | $setup{$k} = "FALSE"; |
195 | $setup{$k} = "FALSE"; |
192 | } |
196 | } |
193 | } |
197 | } |
194 | |
198 | |
195 | $ns->send_packet (join " ", setup => %setup); |
199 | $ns->send_packet (join " ", setup => %setup); |
196 | |
200 | |
… | |
… | |
427 | } |
431 | } |
428 | |
432 | |
429 | $ob->set_animation (2); |
433 | $ob->set_animation (2); |
430 | $ob->add_statbonus; |
434 | $ob->add_statbonus; |
431 | |
435 | |
432 | $ns->send_drawinfo ($ob->msg, cf::NDI_BLUE); |
436 | while () { |
433 | $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, |
434 | "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"; |
435 | |
444 | |
436 | $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 | |
437 | delete $pl->{deny_save};#d# too early |
452 | delete $pl->{deny_save}; |
438 | |
453 | |
439 | last; |
454 | last; |
440 | } |
455 | } |
441 | }); |
456 | }); |
442 | } |
457 | } |
… | |
… | |
570 | $ob = $pl->ob; |
585 | $ob = $pl->ob; |
571 | |
586 | |
572 | $ob->destroy; |
587 | $ob->destroy; |
573 | $pl->destroy; |
588 | $pl->destroy; |
574 | } else { |
589 | } else { |
575 | warn "player-scheduler refcnt ", $ob->name, " $pl_ref,$a_ $ob_ref,$b_\n";#d# |
590 | warn "player-scheduler refcnt ", $ob->name, " pp$pl_ref,pc$a_ op$ob_ref,oc$b_\n";#d# |
576 | } |
591 | } |
577 | } |
592 | } |
578 | } |
593 | } |
579 | }; |
594 | }; |
580 | warn $@ if $@; |
595 | warn $@ if $@; |