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.39 by root, Mon Apr 16 06:23:41 2007 UTC vs.
Revision 1.51 by root, Sun Jun 10 03:15:17 2007 UTC

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
9my $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
12sub nuke_str { 10sub nuke_str {
13 substr $_[0], 0, (length $_[0]), "x" x length $_[0] 11 substr $_[0], 0, (length $_[0]), "x" x length $_[0]
14} 12}
53 ); 51 );
54 52
55 1 53 1
56} 54}
57 55
58sub check_clean_save { 56sub enter_map {
59 my ($pl) = @_; 57 my ($pl) = @_;
60 58
59 my ($map, $x, $y)
60 = $pl->ob->{_link_pos}
61 ? @{delete $pl->ob->{_link_pos}}
62 : ($pl->maplevel, $pl->ob->x, $pl->ob->y);
63
64 $pl->ob->enter_link;
65
61 if (my $time = delete $pl->{unclean_save}) { 66 if (my $time = delete $pl->{unclean_save}) {
67 if (my $m = cf::map::find $map) {
68 if ($time < $m->{instantiate_time}) {
69 # the map was reset in the meantime
70 my $age = $cf::RUNTIME - $time;
71 warn $pl->ob->name, " map reset after logout, logout age $age\n";#d#
72
73 # for now, just go back to savebed
74 ($map, $x, $y) = $pl->savebed;
75
62 $pl->ns->send_drawinfo ( 76 $pl->ns->send_drawinfo (
77 "You didn't use a bed to reality to leave this realm, leaving your body in great danger. "
78 . "Fortunately, some friendly dwellers found you, checked your passport, and brought you to safety. "
79 . "Better use a savebed next time, much worse things could have happened...",
80 cf::NDI_RED
81 );
82 } else {
83 $pl->ns->send_drawinfo (
63 "You didn't use a savebed to leave this realm. This is very dangerous, " 84 "You didn't use a bed to reality to leave this realm. This is very dangerous, "
64 . "as lots of things could happen when you leave by other means, such as cave-ins, " 85 . "as lots of things could happen when you leave by other means, such as cave-ins, "
65 . "or monsters suddenly snapping your body. Better use a savebed next time.", 86 . "or monsters suddenly snapping your body. Better use a savebed next time.",
66 cf::NDI_RED 87 cf::NDI_RED
88 );
89 }
67 ); 90 }
68 #d#TODO
69 } 91 }
92
93 $pl->ob->goto ($map, $x, $y);
70} 94}
71 95
72# delete a player directory, be non-blocking AND synchronous... 96# delete a player directory, be non-blocking AND synchronous...
73# (thats hard, so we crap out and fork). 97# (thats hard, so we crap out and fork).
74sub nuke_playerdir { 98sub nuke_playerdir {
101 # The client then must sort this out 125 # The client then must sort this out
102 126
103 my %setup = split / +/, $args; 127 my %setup = split / +/, $args;
104 while (my ($k, $v) = each %setup) { 128 while (my ($k, $v) = each %setup) {
105 if ($k eq "sound") { 129 if ($k eq "sound") {
106 $ns->sound ($v); 130 $ns->sound ($v);
107 131
108 } elsif ($k eq "exp64") { 132 } elsif ($k eq "exp64") {
109 $setup{$k} = 1; 133 $setup{$k} = 1;
110 134
111 } elsif ($k eq "spellmon") { 135 } elsif ($k eq "spellmon") {
112 $ns->monitor_spells ($v); 136 $ns->monitor_spells ($v);
113 137
114 } elsif ($k eq "darkness") { 138 } elsif ($k eq "darkness") {
115 $ns->darkness ($v); 139 $ns->darkness ($v);
116 140
117 } elsif ($k eq "map1cmd") { 141 } elsif ($k eq "map1cmd") {
118 $ns->mapmode (cf::Map1Cmd) if $v > 0; 142 $ns->mapmode (cf::Map1Cmd) if $v > 0;
119 143
120 } elsif ($k eq "map1acmd") { 144 } elsif ($k eq "map1acmd") {
121 $ns->mapmode (cf::Map1aCmd) if $v > 0; 145 $ns->mapmode (cf::Map1aCmd) if $v > 0;
122 146
123 } elsif ($k eq "map2cmd") { 147 } elsif ($k eq "map2cmd") {
124 # gcfclient bug, map1acmd is sent too late 148 # gcfclient bug, map1acmd is sent too late
125 $ns->mapmode (cf::Map1aCmd); 149 $ns->mapmode (cf::Map1aCmd);
126 $setup{$k} = "FALSE"; 150 $setup{$k} = "FALSE";
127 151
128 } elsif ($k eq "newmapcmd") { 152 } elsif ($k eq "newmapcmd") {
129 $ns->newmapcmd ($v); 153 $ns->newmapcmd ($v);
130 154
131 } elsif ($k eq "mapinfocmd") { 155 } elsif ($k eq "mapinfocmd") {
132 $ns->mapinfocmd ($v); 156 $ns->mapinfocmd ($v);
133 157
134 } elsif ($k eq "extcmd") { 158 } elsif ($k eq "extcmd") {
135 $ns->extcmd ($v > 0); 159 $ns->extcmd ($v > 0);
136 send_capabilities $ns; 160 send_capabilities $ns;
137 161
138 } elsif ($k eq "extmap") { 162 } elsif ($k eq "extmap") {
139 $ns->extmap ($v); 163 $ns->extmap ($v);
140 164
141 } elsif ($k eq "facecache") { 165 } elsif ($k eq "facecache") {
166 if (!$v) {
167 $v = 1;
168 $setup{$k} = $v;
169 $ns->send_drawinfo ("(trying to forcefully enable facecaching)", cf::NDI_RED);
170 }
171
142 $ns->facecache ($v); 172 $ns->facecache ($v);
143 173
144 } elsif ($k eq "faceset") { 174 } elsif ($k eq "faceset") {
145 $ns->faceset (0); 175 $ns->faceset (0);
146 $setup{$k} = 0; 176 $setup{$k} = 0;
147 # $ns->image2 (1) 177 # $ns->image2 (1)
148 178
149 } elsif ($k eq "tileset") { 179 } elsif ($k eq "tileset") {
150 $setup{$k} = $ns->faceset ($v & 1); 180 $setup{$k} = $ns->faceset ($v & 1);
151 181
152 } elsif ($k eq "itemcmd") { 182 } elsif ($k eq "itemcmd") {
153 # Version of the item protocol command to use. Currently, 183 # Version of the item protocol command to use. Currently,
154 # only supported versions are 1 and 2. Using a numeric 184 # only supported versions are 1 and 2. Using a numeric
155 # value will make it very easy to extend this in the future. 185 # value will make it very easy to extend this in the future.
156 $ns->itemcmd ($v) if $v >= 1 && $v <= 2; 186 $ns->itemcmd ($v) if $v >= 1 && $v <= 2;
157 187
158 $setup{$k} = $ns->itemcmd; 188 $setup{$k} = $ns->itemcmd;
159 189
160 } elsif ($k eq "mapsize") { 190 } elsif ($k eq "mapsize") {
161 my ($x, $y) = split /x/, $v; 191 my ($x, $y) = split /x/, $v;
162 192
163 $ns->mapx ($x = max 9, min cf::MAP_CLIENT_X, ($x - 1) | 1); 193 $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 - 1) | 1); 194 $ns->mapy ($y = max 9, min cf::MAP_CLIENT_Y, ($y - 1) | 1);
165 195
166 $setup{$k} = "${x}x${y}"; 196 $setup{$k} = "${x}x${y}";
167 197
168 } elsif ($k eq "extendedMapInfos") { 198 } elsif ($k eq "extendedMapInfos") {
169 $ns->ext_mapinfos ($v); 199 $ns->ext_mapinfos ($v);
170 200
171 } elsif ($k eq "extendedTextInfos") { 201 } elsif ($k eq "extendedTextInfos") {
172 $ns->has_readable_type ($v); 202 $ns->has_readable_type ($v);
173 203
174 } elsif ($k eq "smoothing") { # cfplus-style smoothing 204 } elsif ($k eq "smoothing") { # cfplus-style smoothing
175 $ns->smoothing ($v); 205 $ns->smoothing ($v);
176 206
177 } elsif ($k eq "fxix") { 207 } elsif ($k eq "fxix") {
178 $ns->fxix ($v); 208 $ns->fxix ($v);
209
210 } elsif ($k eq "msg") {
211 $ns->can_msg ($v);
212
213 } elsif ($k eq "excmd") {
214 # we support it
179 215
180 } else { 216 } else {
181 # other commands: 217 # other commands:
182 # sexp: no idea, probably for oudated servers 218 # sexp: no idea, probably for oudated servers
183 # tick: more stupidity, server should sned a tick per tick 219 # tick: more stupidity, server should send a tick per tick
184 220
185 $setup{$k} = "FALSE"; 221 $setup{$k} = "FALSE";
186 } 222 }
187 } 223 }
188 224
189 $ns->send_packet (join " ", setup => %setup); 225 $ns->send_packet (join " ", setup => %setup);
190 226
322 if ($cf::CFG{ext_login_nocheck} or $hash eq crypt $pass, $hash) { 358 if ($cf::CFG{ext_login_nocheck} or $hash eq crypt $pass, $hash) {
323 nuke_str $pass; 359 nuke_str $pass;
324 # password matches, wonderful 360 # password matches, wonderful
325 my $pl = cf::player::find $user or next; 361 my $pl = cf::player::find $user or next;
326 $pl->connect ($ns); 362 $pl->connect ($ns);
327 check_clean_save $pl; 363 enter_map $pl;
328 last; 364 last;
329 } elsif (can_cleanup $pl, $mtime) { 365 } elsif (can_cleanup $pl, $mtime) {
330 Coro::Timer::sleep 1; 366 Coro::Timer::sleep 1;
331 367
332 $ns->send_drawinfo ( 368 $ns->send_drawinfo (
395 431
396 my $pl = cf::player::new $user; 432 my $pl = cf::player::new $user;
397 $pl->password (crypt $pass, join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]); 433 $pl->password (crypt $pass, join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]);
398 nuke_str $pass; 434 nuke_str $pass;
399 $pl->connect ($ns); 435 $pl->connect ($ns);
400
401 my $ob = $pl->ob; 436 my $ob = $pl->ob;
437
438 $ob->goto ($pl->maplevel, $ob->x, $ob->y);
402 439
403 while () { 440 while () {
404 $ob->update_stats; 441 $ob->update_stats;
405 $pl->save_stats; 442 $pl->save_stats;
406 443
421 } 458 }
422 459
423 $ob->set_animation (2); 460 $ob->set_animation (2);
424 $ob->add_statbonus; 461 $ob->add_statbonus;
425 462
426 $ns->send_drawinfo ($ob->msg, cf::NDI_BLUE); 463 while () {
427 $ns->send_packet (sprintf "query %d %s", cf::CS_QUERY_SINGLECHAR, 464 $ns->send_msg (-1, "chargen-race-title", ucfirst $pl->title);
465 my $msg = $ob->msg;
466 $msg =~ s/(?<=\S)\n(?=\S)/ /g;
467 $ns->send_msg (cf::NDI_BLUE, "chargen-race-description", $msg);
468
469 my $res = query $ns, cf::CS_QUERY_SINGLECHAR,
428 "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n"); 470 "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n";
429 471
430 $ns->state (cf::ST_CHANGE_CLASS); 472 last if $res =~ /[dD]/;
473
474 $pl->chargen_race_next;
475 }
476
477 $pl->chargen_race_done;
478
431 delete $pl->{deny_save};#d# too early 479 delete $pl->{deny_save};
432 480
433 last; 481 last;
434 } 482 }
435 }); 483 });
436} 484}
542 eval { 590 eval {
543 if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { 591 if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) {
544 cf::wait_for_tick_begin; 592 cf::wait_for_tick_begin;
545 $pl->save; 593 $pl->save;
546 594
547 unless ($pl->active) { 595 unless ($pl->active || $pl->ns) {
548 # check refcounts, this is tricky and needs to be adjusted to fit server internals 596 # check refcounts, this is tricky and needs to be adjusted to fit server internals
549 my $ob = $pl->ob; 597 my $ob = $pl->ob;
550 Scalar::Util::weaken $pl; 598
551 Scalar::Util::weaken $ob;
552 my $a_ = $pl->refcnt;#d#
553 my $b_ = $ob->refcnt;#d#
554 my $pl_ref = $pl->refcnt_cnt; 599 my $pl_ref = $pl->refcnt_cnt;
555 my $ob_ref = $ob->refcnt_cnt; 600 my $ob_ref = $ob->refcnt_cnt;
556 601
557 ## pl_ref == one from object + one from cf::PLAYER 602 ## pl_ref == $pl + ob->contr + %cf::PLAYER
558 ## ob_ref == one from simply being an object 603 ## ob_ref == $ob + pl->observe + simply being an object
559 if ($pl_ref == 2 && $ob_ref == 1) { 604 if ($pl_ref == 3 && $ob_ref == 3) {
560 warn "player-scheduler destroy ", $ob->name;#d# 605 warn "player-scheduler destroy ", $ob->name;#d#
561 606
562 # remove from sight and get fresh "copies" 607 # remove from sight and get fresh "copies"
563 $pl = delete $cf::PLAYER{$ob->name}; 608 $pl = delete $cf::PLAYER{$ob->name};
564 $ob = $pl->ob; 609 $ob = $pl->ob;
565 610
566 $ob->destroy; 611 $ob->destroy;
567 $pl->destroy; 612 $pl->destroy;
568 } else { 613 } else {
614 my $a_ = $pl->refcnt;#d#
615 my $b_ = $ob->refcnt;#d#
616
569 warn "player-scheduler refcnt ", $ob->name, " $pl_ref,$a_ $ob_ref,$b_\n";#d# 617 warn "player-scheduler refcnt ", $ob->name, " pp$pl_ref,pc$a_ op$ob_ref,oc$b_\n";#d#
570 } 618 }
571 } 619 }
572 } 620 }
573 }; 621 };
574 warn $@ if $@; 622 warn $@ if $@;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines