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.70 by root, Sun Sep 2 12:37:10 2007 UTC vs.
Revision 1.90 by root, Tue Sep 16 16:03:02 2008 UTC

52 ); 52 );
53 53
54 1 54 1
55} 55}
56 56
57sub safe_spot($) {
58 my ($pl) = @_;
59
60 my $ob = $pl->ob;
61
62 my $m = $ob->map
63 or return;
64 my $x = $ob->x;
65 my $y = $ob->y;
66
67# return 0;#d#
68# warn join ":", $m->at ($x, $y);#d#
69# warn "FOO$m { ".scalar ($m->at ($x, $y))." }\n";
70# return 0;
71
72 scalar grep $_->type == cf::SAVEBED, $m->at ($x, $y)
73}
74
57sub enter_map { 75sub enter_map {
58 my ($pl) = @_; 76 my ($pl) = @_;
59 77
78 warn $pl->ob->name, ": enter map 1\n";#d#
60 my $ob = $pl->ob; 79 my $ob = $pl->ob;
61 80
62 my ($map, $x, $y) 81 my ($map, $x, $y)
63 = $ob->{_link_pos} 82 = $ob->{_link_pos}
64 ? @{delete $ob->{_link_pos}} 83 ? @{delete $ob->{_link_pos}}
65 : ($pl->maplevel, $ob->x, $ob->y); 84 : ($pl->maplevel, $ob->x, $ob->y);
66 85
86 warn $pl->ob->name, ": enter map 2\n";#d#
67 $ob->enter_link; 87 $ob->enter_link;
88 warn $pl->ob->name, ": enter map 3\n";#d#
68 89
90 my $m = cf::map::find $map;
69 if (my $time = delete $pl->{unclean_save}) { 91 my $time = delete $pl->{unclean_save};
70 if (my $m = cf::map::find $map) { 92 warn $pl->ob->name, ": enter map 4\n";#d#
93
94 if ($time && $m) {
71 if ($time < $m->{instantiate_time}) { 95 if ($time < $m->{instantiate_time}) {
72 # the map was reset in the meantime 96 # the map was reset in the meantime
73 my $age = $cf::RUNTIME - $time; 97 my $age = $cf::RUNTIME - $time;
74 98
75 warn $ob->name, " map reset after logout, logout age $age (>= $MAX_DISCONNECT_TIME)\n";#d# 99 warn $ob->name, " map reset after logout, logout age $age (>= $MAX_DISCONNECT_TIME)\n";#d#
76 100
77 # for now, just go back to savebed
78 ($map, $x, $y) = $pl->savebed;
79
80 if ($age >= $MAX_DISCONNECT_TIME) { 101 if ($age >= $MAX_DISCONNECT_TIME) {
81 $ob->message (
82 "You didn't use a bed to reality to leave this realm, leaving your body in great danger. "
83 . "Unfortunately, nobody was near to help you when the monsters arrived to eat you. "
84 . "Maybe you can find comfort in the thought that your body was quite satisfying in taste... "
85 . "H<You disconnected too long without having used a savebed.>",
86 cf::NDI_RED
87 );
88 # kill them.
89 # reminds me of the famous badness 10000 syndrome...
90 $ob->stats->hp (-10000); #] if they survive this they deserved to live
91 $pl->killer ("a cave-in");
92 } else {
93 $ob->message (
94 "You didn't use a bed to reality to leave this realm, leaving your body in great danger. "
95 . "Fortunately, some friendly dwellers found you, checked your passport, and brought you to safety. "
96 . "Better use a savebed next time, much worse things could have happened... "
97 . "H<You disconnected without having used a savebed. When you do that for too long, you might die.>",
98 cf::NDI_RED
99 );
100 }
101 } else {
102 $ob->message ( 102 $ob->message (
103 "You didn't use a bed to reality to leave this realm. This is very dangerous, " 103 "You didn't use a bed to reality to leave this realm, leaving your body in great danger. "
104 . "as lots of things could happen when you leave by other means, such as cave-ins, " 104 . "Unfortunately, nobody was near to help you when the monsters arrived to eat you. "
105 . "or monsters suddenly snapping your body. Better use a savebed next time. " 105 . "Maybe you can find comfort in the thought that your body was quite satisfying in taste... "
106 . "H<Always apply a bed of reality to disconnect from the server.>", 106 . "H<You disconnected too long without having used a savebed.>",
107 cf::NDI_RED 107 cf::NDI_RED
108 ); 108 );
109 # kill them.
110 # reminds me of the famous badness 10000 syndrome...
111 $ob->stats->hp (-10000); #] if they survive this they deserved to live
112 my $killer = cf::arch::get "killer_login"; $pl->killer ($killer); $killer->destroy;
113 } else {
114 ($map, $x, $y) = $pl->savebed;
115
116 $ob->message (
117 "You didn't use a bed to reality to leave this realm, leaving your body in great danger. "
118 . "Fortunately, some friendly dwellers found you, checked your passport, and brought you to safety. "
119 . "Better use a savebed next time, much worse things could have happened... "
120 . "H<You disconnected without having used a savebed. When you do that for too long, you might die.>",
121 cf::NDI_RED
122 );
123 }
124 } else {
125 $ob->message (
126 "You didn't use a bed to reality to leave this realm. This is very dangerous, "
127 . "as lots of things could happen when you leave by other means, such as cave-ins, "
128 . "or monsters suddenly snapping your body. Better use a savebed next time. "
129 . "H<Always apply a bed of reality to disconnect from the server.>",
130 cf::NDI_RED
109 } 131 );
110 } 132 }
111 } 133 }
112 134
135 warn $pl->ob->name, ": enter map 5\n";#d#
113 $ob->goto ($map, $x, $y); 136 #$ob->goto ($map, $x, $y);
137 $ob->goto ($map, $x, $y, sub {
138 warn $pl->ob->name, ": enter map check\n";#d#
139 $_[0]
140 }, sub {
141 warn $pl->ob->name, ": enter map done\n";#d#
142 });
143 warn $pl->ob->name, ": enter map 6\n";#d#
144
114} 145}
115 146
116# delete a player directory, be non-blocking AND synchronous... 147# delete a player directory, be non-blocking AND synchronous...
117# (thats hard, so we crap out and fork). 148# (thats hard, so we crap out and fork).
118sub nuke_playerdir { 149sub nuke_playerdir {
119 my ($user) = @_; 150 my ($user) = @_;
120 151
121 aio_rename "$PLAYERDIR/$user", "$PLAYERDIR/~$Coro::current~deleting~";
122 system "rm -rf \Q$PLAYERDIR/~$Coro::current~deleting~\E &"; 152 my $temp = "$PLAYERDIR/~$Coro::current~deleting~";
153
154 cf::fork_call {
155 rename "$PLAYERDIR/$user", $temp;
156 system "rm", "-rf", $temp;
157 };
123} 158}
124 159
125cf::client->attach (on_addme => sub { 160cf::client->attach (on_addme => sub {
126 my ($ns) = @_; 161 my ($ns) = @_;
127 162
136*** or it has been disabled. Face caching is mandatory 171*** or it has been disabled. Face caching is mandatory
137*** so please enable it or use a newer client. 172*** so please enable it or use a newer client.
138*** 173***
139*** Look at your client preferences: 174*** Look at your client preferences:
140*** 175***
141*** CFPlus: all known versions automatically enable the facecache. 176*** deliantra: all known versions automatically enable the facecache.
142*** cfclient: use the -cache commandline option. 177*** cfclient: use the -cache commandline option.
143*** cfclient: map will not redraw automatically (bug). 178*** cfclient: map will not redraw automatically (bug).
144*** gcfclient: use -cache commandline option, or enable 179*** gcfclient: use -cache commandline option, or enable
145*** gcfclient: Client => Configure => Map & Image => Cache Images. 180*** gcfclient: Client => Configure => Map & Image => Cache Images.
146*** jcrossclient: your client is broken, use CFPlus or gcfclient. 181*** jcrossclient: your client is broken, use deliantra or gcfclient.
147*** 182***
148*** 183***
149EOF 184EOF
150 if ($ns->version =~ /jcrossclient/) { 185 if ($ns->version =~ /jcrossclient/) {
151 # let them, for now 186 # let them, for now
171 } 206 }
172 207
173 $ns->pl and return $ns->destroy; 208 $ns->pl and return $ns->destroy;
174 209
175 $ns->async (sub { 210 $ns->async (sub {
211 $Coro::current->{desc} = "addme init";
212
176 my ($user, $pass); 213 my ($user, $pass);
177 214
178 $ns->send_packet ("addme_success"); 215 $ns->send_packet ("addme_success");
179 216
180 for (;;) { 217 for (;;) {
185 cf::NDI_BLUE 222 cf::NDI_BLUE
186 ); 223 );
187 224
188 # read username 225 # read username
189 while () { 226 while () {
190 $user = query $ns, 0, "What is your name?\n:"; 227 $user = query $ns, 0, "What is your name? (login names are case-sensitive)\n:";
191 228
192 if ($cf::LOGIN_LOCK{$user}) { 229 if ($cf::LOGIN_LOCK{$user}) {
193 $ns->send_drawinfo ( 230 $ns->send_drawinfo (
194 "That username is currently used in another login session. " 231 "That username is currently used in another login session. "
195 . "Chose another, or wait till the other session has ended.", 232 . "Chose another, or wait till the other session has ended.",
208 Coro::Timer::sleep 0.4; 245 Coro::Timer::sleep 0.4;
209 } 246 }
210 247
211 check_playing $ns, $user and next; 248 check_playing $ns, $user and next;
212 249
250 $Coro::current->{desc} = "addme($user) pass";
251
213 $ns->send_drawinfo ( 252 $ns->send_drawinfo (
214 "Welcome $user, please enter your password now. " 253 "Welcome $user, please enter your password now. "
215 . "New users should now choose a password. " 254 . "New users should now choose a password. "
216 . "Anything your client lets you enter is fine.", 255 . "Anything your client lets you enter is fine.",
217 cf::NDI_BLUE 256 cf::NDI_BLUE
240 } 279 }
241 local $cf::LOGIN_LOCK{$user} = 1; 280 local $cf::LOGIN_LOCK{$user} = 1;
242 281
243 check_playing $ns, $user and next; 282 check_playing $ns, $user and next;
244 283
284 $Coro::current->{desc} = "addme($user) check";
285
245 # try to read the user file and check the password 286 # try to read the user file and check the password
246 if (my $pl = cf::player::find $user) { 287 if (my $pl = cf::player::find $user) {
247 aio_stat $pl->path and next; 288 aio_stat $pl->path and next;
248 my $mtime = (stat _)[9]; 289 my $mtime = (stat _)[9];
249 my $hash = $pl->password; 290 my $hash = $pl->password;
251 if ($cf::CFG{ext_login_nocheck} or $hash eq crypt $pass, $hash) { 292 if ($cf::CFG{ext_login_nocheck} or $hash eq crypt $pass, $hash) {
252 nuke_str $pass; 293 nuke_str $pass;
253 # password matches, wonderful 294 # password matches, wonderful
254 my $pl = cf::player::find $user or next; 295 my $pl = cf::player::find $user or next;
255 $pl->connect ($ns); 296 $pl->connect ($ns);
297 $pl->ob->flag (cf::FLAG_DEBUG, 1);#d# temp
256 enter_map $pl; 298 enter_map $pl;
257 last; 299 last;
258 } elsif (can_cleanup $pl, $mtime) { 300 } elsif (can_cleanup $pl, $mtime) {
259 Coro::Timer::sleep 1; 301 Coro::Timer::sleep 1;
260 302
302 next; 344 next;
303 } 345 }
304 } 346 }
305 347
306 # the rest of this function is character creation 348 # the rest of this function is character creation
349 $Coro::current->{desc} = "addme($user) chargen";
307 350
308 # just to make sure nothing is left over 351 # just to make sure nothing is left over
309 nuke_playerdir $user; 352 nuke_playerdir $user;
310 353
311 my $pass2 = query $ns, cf::CS_QUERY_HIDEINPUT, "Please type your password again."; 354 my $pass2 = query $ns, cf::CS_QUERY_HIDEINPUT, "Please type your password again.";
348 } 391 }
349 } else { 392 } else {
350 $ob->roll_stats; 393 $ob->roll_stats;
351 } 394 }
352 395
353 Coro::Timer::sleep 0.2; 396 Coro::Timer::sleep 0.05;
354 } 397 }
355 398
356 $ob->set_animation (2); 399 $ob->set_animation (2);
357 $ob->add_statbonus; 400 $ob->add_statbonus;
358 401
369 412
370 $pl->chargen_race_next; 413 $pl->chargen_race_next;
371 Coro::Timer::sleep 0.2; 414 Coro::Timer::sleep 0.2;
372 } 415 }
373 416
417 # create the playerdir, if necessary, as chargen_race_done did it before
418 # presumably because of unique maps
419 aio_mkdir playerdir $pl, 0770;
374 $pl->chargen_race_done; 420 $pl->chargen_race_done;
375 421
376 while () { 422 while () {
377 my $res = query $ns, cf::CS_QUERY_SINGLECHAR, 423 my $res = query $ns, cf::CS_QUERY_SINGLECHAR,
378 "Now choose a gender.\nPress 'f' to become female, and 'm' to become male.\n"; 424 "Now choose a gender.\nPress 'f' to become female, and 'm' to become male.\n";
385 last; 431 last;
386 } 432 }
387 Coro::Timer::sleep 0.2; 433 Coro::Timer::sleep 0.2;
388 } 434 }
389 435
390 $ob->reply (undef, "Welcome to Crossfire!"); 436 $ob->reply (undef, "Welcome to Deliantra!");
391 437
392 delete $pl->{deny_save}; 438 delete $pl->{deny_save};
393 439
394 last; 440 last;
395 } 441 }
436 482
437 # update respawn position 483 # update respawn position
438 $pl->savebed ($bed->map->path, $bed->x, $bed->y); 484 $pl->savebed ($bed->map->path, $bed->x, $bed->y);
439 cf::async { $pl->save }; 485 cf::async { $pl->save };
440 486
441 $pl->killer ("left"); 487 my $killer = cf::arch::get "killer_logout"; $pl->killer ($killer); $killer->destroy;
442 $ob->check_score; 488 $ob->check_score;
443 489
444 $ob->reply (undef, "In the future, you will wake up here when you die."); 490 $ob->reply (undef, "In the future, you will wake up here when you die.");
445 491
446 $pl->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to continue playing (y/n)?", sub { 492 $pl->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to continue playing (y/n)?", sub {
468 514
469 if ($cleanly) { 515 if ($cleanly) {
470 $_->ob->message ("$name left the game.", cf::NDI_DK_ORANGE | cf::NDI_UNIQUE) for cf::player::list; 516 $_->ob->message ("$name left the game.", cf::NDI_DK_ORANGE | cf::NDI_UNIQUE) for cf::player::list;
471 } else { 517 } else {
472 $_->ob->message ("$name uncerimoniously disconnected.", cf::NDI_DK_ORANGE | cf::NDI_UNIQUE) for cf::player::list; 518 $_->ob->message ("$name uncerimoniously disconnected.", cf::NDI_DK_ORANGE | cf::NDI_UNIQUE) for cf::player::list;
473 $pl->{unclean_save} = $cf::RUNTIME; 519 $pl->{unclean_save} = $cf::RUNTIME
520 unless safe_spot $pl;
474 } 521 }
475 }, 522 },
476); 523);
477 524
478############################################################################# 525#############################################################################
479 526
480our $SCHEDULE_INTERVAL = $cf::CFG{player_schedule_interval} || 10; # time the player scheduler sleeps between runs 527our $SCHEDULE_INTERVAL = $cf::CFG{player_schedule_interval} || 10; # time the player scheduler sleeps between runs
481our $SAVE_TIMEOUT = $cf::CFG{player_save_interval} || 20; # save players every n seconds 528our $SAVE_TIMEOUT = $cf::CFG{player_save_interval} || 20; # save players every n seconds
482 529
483our $SCHEDULER = cf::async_ext { 530our $SCHEDULER = cf::async_ext {
484 my $schedule_interval = Coro::Event->timer (after => 1); 531 $Coro::current->{desc} = "player scheduler";
532
485 while () { 533 while () {
486 $schedule_interval->interval ($SCHEDULE_INTERVAL); 534 Coro::EV::timer_once $SCHEDULE_INTERVAL;
487 $schedule_interval->next;
488 535
489 # this weird form of iteration over values is used because 536 # this weird form of iteration over values is used because
490 # the hash changes underneath us frequently, and for 537 # the hash changes underneath us frequently, and for
491 # keeps a direct reference to the value without (in 5.8 perls) 538 # keeps a direct reference to the value without (in 5.8 perls)
492 # keeping a reference, so this is prone to crashes or worse. 539 # keeping a reference, so this is prone to crashes or worse.
519 $pl->destroy; # destroys $ob 566 $pl->destroy; # destroys $ob
520 } else { 567 } else {
521 my $a_ = $pl->refcnt;#d# 568 my $a_ = $pl->refcnt;#d#
522 my $b_ = $ob->refcnt;#d# 569 my $b_ = $ob->refcnt;#d#
523 570
524 warn "player-scheduler refcnt ", $ob->name, " pl $pl_ref ob $ob_ref (C pl $a_ ob $b_)\n";#d# 571 warn "player-scheduler refcnt ", $ob->name, " pl $pl_ref/3 ob $ob_ref/3 (C pl $a_/1 ob $b_/2)\n";#d#
525 } 572 }
526 } 573 }
527 } 574 }
528 }; 575 };
529 warn $@ if $@; 576 warn $@ if $@;
530 Coro::cede; 577 cf::cede_to_tick;
531 }; 578 };
532 } 579 }
533}; 580};
534 581
535$SCHEDULER->prio (1); 582$SCHEDULER->prio (1);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines