ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/login.ext
(Generate patch)

Comparing deliantra/server/ext/login.ext (file contents):
Revision 1.42 by root, Wed Apr 18 17:32:06 2007 UTC vs.
Revision 1.58 by root, Sun Jul 1 03:16:56 2007 UTC

1#! perl # MANDATORY 1#! perl # mandatory
2 2
3# login handling 3# login handling
4 4
5use Fcntl; 5use Fcntl;
6use Coro::AIO; 6use Coro::AIO;
7use List::Util qw(min max); 7use List::Util qw(min max);
8
9our %EXT_SETUP;
8 10
9# paranoia function to overwrite a string-in-place 11# paranoia function to overwrite a string-in-place
10sub nuke_str { 12sub nuke_str {
11 substr $_[0], 0, (length $_[0]), "x" x length $_[0] 13 substr $_[0], 0, (length $_[0]), "x" x length $_[0]
12} 14}
51 ); 53 );
52 54
53 1 55 1
54} 56}
55 57
56sub check_clean_save { 58sub enter_map {
57 my ($pl) = @_; 59 my ($pl) = @_;
58 60
61 my ($map, $x, $y)
62 = $pl->ob->{_link_pos}
63 ? @{delete $pl->ob->{_link_pos}}
64 : ($pl->maplevel, $pl->ob->x, $pl->ob->y);
65
66 $pl->ob->enter_link;
67
59 if (my $time = delete $pl->{unclean_save}) { 68 if (my $time = delete $pl->{unclean_save}) {
69 if (my $m = cf::map::find $map) {
70 if ($time < $m->{instantiate_time}) {
71 # the map was reset in the meantime
72 my $age = $cf::RUNTIME - $time;
73 warn $pl->ob->name, " map reset after logout, logout age $age\n";#d#
74
75 # for now, just go back to savebed
76 ($map, $x, $y) = $pl->savebed;
77
60 $pl->ns->send_drawinfo ( 78 $pl->ns->send_drawinfo (
79 "You didn't use a bed to reality to leave this realm, leaving your body in great danger. "
80 . "Fortunately, some friendly dwellers found you, checked your passport, and brought you to safety. "
81 . "Better use a savebed next time, much worse things could have happened...",
82 cf::NDI_RED
83 );
84 } else {
85 $pl->ns->send_drawinfo (
61 "You didn't use a savebed to leave this realm. This is very dangerous, " 86 "You didn't use a bed to reality to leave this realm. This is very dangerous, "
62 . "as lots of things could happen when you leave by other means, such as cave-ins, " 87 . "as lots of things could happen when you leave by other means, such as cave-ins, "
63 . "or monsters suddenly snapping your body. Better use a savebed next time.", 88 . "or monsters suddenly snapping your body. Better use a savebed next time.",
64 cf::NDI_RED 89 cf::NDI_RED
90 );
91 }
65 ); 92 }
66 #d#TODO
67 } 93 }
94
95 $pl->ob->goto ($map, $x, $y);
68} 96}
69 97
70# delete a player directory, be non-blocking AND synchronous... 98# delete a player directory, be non-blocking AND synchronous...
71# (thats hard, so we crap out and fork). 99# (thats hard, so we crap out and fork).
72sub nuke_playerdir { 100sub nuke_playerdir {
99 # The client then must sort this out 127 # The client then must sort this out
100 128
101 my %setup = split / +/, $args; 129 my %setup = split / +/, $args;
102 while (my ($k, $v) = each %setup) { 130 while (my ($k, $v) = each %setup) {
103 if ($k eq "sound") { 131 if ($k eq "sound") {
104 $ns->sound ($v); 132 $ns->sound ($v);
105 133
106 } elsif ($k eq "exp64") { 134 } elsif ($k eq "exp64") {
107 $setup{$k} = 1; 135 $setup{$k} = 1;
108 136
109 } elsif ($k eq "spellmon") { 137 } elsif ($k eq "spellmon") {
110 $ns->monitor_spells ($v); 138 $ns->monitor_spells ($v);
111 139
112 } elsif ($k eq "darkness") { 140 } elsif ($k eq "darkness") {
113 $ns->darkness ($v); 141 $ns->darkness ($v);
114 142
115 } elsif ($k eq "map1cmd") { 143 } elsif ($k eq "map1cmd") {
116 $ns->mapmode (cf::Map1Cmd) if $v > 0; 144 $ns->mapmode (cf::Map1Cmd) if $v > 0;
117 145
118 } elsif ($k eq "map1acmd") { 146 } elsif ($k eq "map1acmd") {
119 $ns->mapmode (cf::Map1aCmd) if $v > 0; 147 $ns->mapmode (cf::Map1aCmd) if $v > 0;
120 148
121 } elsif ($k eq "map2cmd") { 149 } elsif ($k eq "map2cmd") {
122 # gcfclient bug, map1acmd is sent too late 150 # gcfclient bug, map1acmd is sent too late
123 $ns->mapmode (cf::Map1aCmd); 151 $ns->mapmode (cf::Map1aCmd);
124 $setup{$k} = "FALSE"; 152 $setup{$k} = "FALSE";
125 153
126 } elsif ($k eq "newmapcmd") { 154 } elsif ($k eq "newmapcmd") {
127 $ns->newmapcmd ($v); 155 $ns->newmapcmd ($v);
128 156
129 } elsif ($k eq "mapinfocmd") { 157 } elsif ($k eq "mapinfocmd") {
130 $ns->mapinfocmd ($v); 158 $ns->mapinfocmd ($v);
131 159
132 } elsif ($k eq "extcmd") { 160 } elsif ($k eq "extcmd") {
133 $ns->extcmd ($v > 0); 161 $ns->extcmd ($v > 0);
134 send_capabilities $ns; 162 send_capabilities $ns;
135 163
136 } elsif ($k eq "extmap") { 164 } elsif ($k eq "extmap") {
137 $ns->extmap ($v); 165 $ns->extmap ($v);
138 166
139 } elsif ($k eq "facecache") { 167 } elsif ($k eq "facecache") {
140 if (!$v) { 168 if (!$v) {
141 $v = 1; 169 $v = 1;
142 $setup{$k} = $v; 170 $setup{$k} = $v;
143 $ns->send_drawinfo ("(trying to forcefully enable facecaching)", cf::NDI_RED); 171 $ns->send_drawinfo ("(trying to forcefully enable facecaching)", cf::NDI_RED);
144 } 172 }
145 173
146 $ns->facecache ($v); 174 $ns->facecache ($v);
147 175
148 } elsif ($k eq "faceset") { 176 } elsif ($k eq "faceset") {
149 $ns->faceset (0); 177 $ns->faceset (0);
150 $setup{$k} = 0; 178 $setup{$k} = 0;
151 # $ns->image2 (1) 179 # $ns->image2 (1)
152 180
153 } elsif ($k eq "tileset") { 181 } elsif ($k eq "tileset") {
154 $setup{$k} = $ns->faceset ($v & 1); 182 $setup{$k} = $ns->faceset ($v & 1);
155 183
156 } elsif ($k eq "itemcmd") { 184 } elsif ($k eq "itemcmd") {
157 # Version of the item protocol command to use. Currently, 185 # Version of the item protocol command to use. Currently,
158 # only supported versions are 1 and 2. Using a numeric 186 # only supported versions are 1 and 2. Using a numeric
159 # value will make it very easy to extend this in the future. 187 # value will make it very easy to extend this in the future.
160 $ns->itemcmd ($v) if $v >= 1 && $v <= 2; 188 $ns->itemcmd ($v) if $v >= 1 && $v <= 2;
161 189
162 $setup{$k} = $ns->itemcmd; 190 $setup{$k} = $ns->itemcmd;
163 191
164 } elsif ($k eq "mapsize") { 192 } elsif ($k eq "mapsize") {
165 my ($x, $y) = split /x/, $v; 193 my ($x, $y) = split /x/, $v;
166 194
167 $ns->mapx ($x = max 9, min cf::MAP_CLIENT_X, ($x - 1) | 1); 195 $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); 196 $ns->mapy ($y = max 9, min cf::MAP_CLIENT_Y, ($y - 1) | 1);
169 197
170 $setup{$k} = "${x}x${y}"; 198 $setup{$k} = "${x}x${y}";
171 199
172 } elsif ($k eq "extendedMapInfos") { 200 } elsif ($k eq "extendedMapInfos") {
173 $ns->ext_mapinfos ($v); 201 $ns->ext_mapinfos ($v);
174 202
175 } elsif ($k eq "extendedTextInfos") { 203 } elsif ($k eq "extendedTextInfos") {
176 $ns->has_readable_type ($v); 204 $ns->has_readable_type ($v);
177 205
178 } elsif ($k eq "smoothing") { # cfplus-style smoothing 206 } elsif ($k eq "smoothing") { # cfplus-style smoothing
179 $ns->smoothing ($v); 207 $ns->smoothing ($v);
180 208
181 } elsif ($k eq "fxix") { 209 } elsif ($k eq "fxix") {
210 $v = 2 if $v > 2;
182 $ns->fxix ($v); 211 $ns->fxix ($v);
212 $setup{$k} = $v;
213
214 } elsif ($k eq "msg") {
215 $v = 2 if $v > 2;
216 $ns->can_msg ($v >= 2);
217 $setup{$k} = $v;
218
219 } elsif ($k eq "xwidget") {
220 # eXperimental server-side widgets
221 $ns->{can_widget} = 1;
222
223 } elsif ($k eq "excmd") {
224 # we support it
183 225
184 } else { 226 } else {
185 # other commands: 227 # other commands:
186 # sexp: no idea, probably for oudated servers 228 # sexp: no idea, probably for oudated servers
187 # tick: more stupidity, server should sned a tick per tick 229 # tick: more stupidity, server should send a tick per tick
188 230
189 $setup{$k} = "FALSE"; 231 $setup{$k} = "FALSE";
190 } 232 }
191 } 233 }
192 234
193 $ns->send_packet (join " ", setup => %setup); 235 $ns->send_packet (join " ", setup => %setup);
194 236
326 if ($cf::CFG{ext_login_nocheck} or $hash eq crypt $pass, $hash) { 368 if ($cf::CFG{ext_login_nocheck} or $hash eq crypt $pass, $hash) {
327 nuke_str $pass; 369 nuke_str $pass;
328 # password matches, wonderful 370 # password matches, wonderful
329 my $pl = cf::player::find $user or next; 371 my $pl = cf::player::find $user or next;
330 $pl->connect ($ns); 372 $pl->connect ($ns);
331 check_clean_save $pl; 373 enter_map $pl;
332 last; 374 last;
333 } elsif (can_cleanup $pl, $mtime) { 375 } elsif (can_cleanup $pl, $mtime) {
334 Coro::Timer::sleep 1; 376 Coro::Timer::sleep 1;
335 377
336 $ns->send_drawinfo ( 378 $ns->send_drawinfo (
399 441
400 my $pl = cf::player::new $user; 442 my $pl = cf::player::new $user;
401 $pl->password (crypt $pass, join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]); 443 $pl->password (crypt $pass, join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]);
402 nuke_str $pass; 444 nuke_str $pass;
403 $pl->connect ($ns); 445 $pl->connect ($ns);
404
405 my $ob = $pl->ob; 446 my $ob = $pl->ob;
447
448 $ob->goto ($pl->maplevel, $ob->x, $ob->y);
406 449
407 while () { 450 while () {
408 $ob->update_stats; 451 $ob->update_stats;
409 $pl->save_stats; 452 $pl->save_stats;
410 453
425 } 468 }
426 469
427 $ob->set_animation (2); 470 $ob->set_animation (2);
428 $ob->add_statbonus; 471 $ob->add_statbonus;
429 472
430 $ns->send_drawinfo ($ob->msg, cf::NDI_BLUE); 473 while () {
431 $ns->send_packet (sprintf "query %d %s", cf::CS_QUERY_SINGLECHAR, 474 $ns->send_msg (-1, "chargen-race-title", ucfirst $pl->title);
475 my $msg = $ob->msg;
476 $msg =~ s/(?<=\S)\n(?=\S)/ /g;
477 $ns->send_msg (cf::NDI_BLUE, "chargen-race-description", $msg);
478
479 my $res = query $ns, cf::CS_QUERY_SINGLECHAR,
432 "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n"); 480 "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n";
433 481
434 $ns->state (cf::ST_CHANGE_CLASS); 482 last if $res =~ /[dD]/;
483
484 $pl->chargen_race_next;
485 }
486
487 $pl->chargen_race_done;
488
489 while () {
490 my $res = query $ns, cf::CS_QUERY_SINGLECHAR,
491 "Now choose a gender.\nPress 'f' to become female, and 'm' to become male.\n";
492
493 if ($res =~ /^[fF]/) {
494 $pl->gender (1);
495 last;
496 } elsif ($res =~ /^[mM]/) {
497 $pl->gender (0);
498 last;
499 }
500 }
501
502 $ob->reply (undef, "Welcome to Crossfire!");
503
435 delete $pl->{deny_save};#d# too early 504 delete $pl->{deny_save};
436 505
437 last; 506 last;
438 } 507 }
439 }); 508 });
440} 509}
546 eval { 615 eval {
547 if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { 616 if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) {
548 cf::wait_for_tick_begin; 617 cf::wait_for_tick_begin;
549 $pl->save; 618 $pl->save;
550 619
551 unless ($pl->active) { 620 unless ($pl->active || $pl->ns) {
552 # check refcounts, this is tricky and needs to be adjusted to fit server internals 621 # check refcounts, this is tricky and needs to be adjusted to fit server internals
553 my $ob = $pl->ob; 622 my $ob = $pl->ob;
554 Scalar::Util::weaken $pl; 623
555 Scalar::Util::weaken $ob;
556 my $a_ = $pl->refcnt;#d#
557 my $b_ = $ob->refcnt;#d#
558 my $pl_ref = $pl->refcnt_cnt; 624 my $pl_ref = $pl->refcnt_cnt;
559 my $ob_ref = $ob->refcnt_cnt; 625 my $ob_ref = $ob->refcnt_cnt;
560 626
561 ## pl_ref == one from object + one from cf::PLAYER 627 ## pl_ref == $pl + ob->contr + %cf::PLAYER
562 ## ob_ref == one from simply being an object 628 ## ob_ref == $ob + pl->observe + simply being an object
563 if ($pl_ref == 2 && $ob_ref == 1) { 629 if ($pl_ref == 3 && $ob_ref == 3) {
564 warn "player-scheduler destroy ", $ob->name;#d# 630 warn "player-scheduler destroy ", $ob->name;#d#
565 631
566 # remove from sight and get fresh "copies" 632 # remove from sight and get fresh "copies"
567 $pl = delete $cf::PLAYER{$ob->name}; 633 $pl = delete $cf::PLAYER{$ob->name};
568 $ob = $pl->ob; 634 $ob = $pl->ob;
569 635
570 $ob->destroy;
571 $pl->destroy; 636 $pl->destroy; # destroys $ob
572 } else { 637 } else {
638 my $a_ = $pl->refcnt;#d#
639 my $b_ = $ob->refcnt;#d#
640
573 warn "player-scheduler refcnt ", $ob->name, " $pl_ref,$a_ $ob_ref,$b_\n";#d# 641 warn "player-scheduler refcnt ", $ob->name, " pl $pl_ref ob $ob_ref (C pl $a_ ob $b_)\n";#d#
574 } 642 }
575 } 643 }
576 } 644 }
577 }; 645 };
578 warn $@ if $@; 646 warn $@ if $@;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines