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.61 by root, Tue Jul 10 06:12:13 2007 UTC vs.
Revision 1.77 by root, Fri Dec 28 19:44:34 2007 UTC

2 2
3# login handling 3# login handling
4 4
5use Fcntl; 5use Fcntl;
6use Coro::AIO; 6use Coro::AIO;
7
8our $MAX_DISCONNECT_TIME = $cf::CFG{max_disconnect_time} || 3600;
7 9
8# paranoia function to overwrite a string-in-place 10# paranoia function to overwrite a string-in-place
9sub nuke_str { 11sub nuke_str {
10 substr $_[0], 0, (length $_[0]), "x" x length $_[0] 12 substr $_[0], 0, (length $_[0]), "x" x length $_[0]
11} 13}
50 ); 52 );
51 53
52 1 54 1
53} 55}
54 56
57sub safe_spot($$$) {
58 my ($m, $x, $y) = @_;
59
60 scalar grep $_->type == cf::SAVEBED, $m->at ($x, $y)
61}
62
55sub enter_map { 63sub enter_map {
56 my ($pl) = @_; 64 my ($pl) = @_;
57 65
66 my $ob = $pl->ob;
67
58 my ($map, $x, $y) 68 my ($map, $x, $y)
59 = $pl->ob->{_link_pos} 69 = $ob->{_link_pos}
60 ? @{delete $pl->ob->{_link_pos}} 70 ? @{delete $ob->{_link_pos}}
61 : ($pl->maplevel, $pl->ob->x, $pl->ob->y); 71 : ($pl->maplevel, $ob->x, $ob->y);
62 72
63 $pl->ob->enter_link; 73 $ob->enter_link;
64 74
75 my $m = cf::map::find $map;
65 if (my $time = delete $pl->{unclean_save}) { 76 my $time = delete $pl->{unclean_save};
66 if (my $m = cf::map::find $map) { 77
78 if ($time && $m && !safe_spot $m, $x, $y) {
67 if ($time < $m->{instantiate_time}) { 79 if ($time < $m->{instantiate_time}) {
68 # the map was reset in the meantime 80 # the map was reset in the meantime
69 my $age = $cf::RUNTIME - $time; 81 my $age = $cf::RUNTIME - $time;
82
70 warn $pl->ob->name, " map reset after logout, logout age $age\n";#d# 83 warn $ob->name, " map reset after logout, logout age $age (>= $MAX_DISCONNECT_TIME)\n";#d#
71 84
72 # for now, just go back to savebed
73 ($map, $x, $y) = $pl->savebed; 85 ($map, $x, $y) = $pl->savebed;
74 86
75 $pl->ns->send_drawinfo ( 87 if ($age >= $MAX_DISCONNECT_TIME) {
88 $ob->message (
89 "You didn't use a bed to reality to leave this realm, leaving your body in great danger. "
90 . "Unfortunately, nobody was near to help you when the monsters arrived to eat you. "
91 . "Maybe you can find comfort in the thought that your body was quite satisfying in taste... "
92 . "H<You disconnected too long without having used a savebed.>",
93 cf::NDI_RED
94 );
95 # kill them.
96 # reminds me of the famous badness 10000 syndrome...
97 $ob->stats->hp (-10000); #] if they survive this they deserved to live
98 $pl->killer ("a cave-in");
99 } else {
100 $ob->message (
76 "You didn't use a bed to reality to leave this realm, leaving your body in great danger. " 101 "You didn't use a bed to reality to leave this realm, leaving your body in great danger. "
77 . "Fortunately, some friendly dwellers found you, checked your passport, and brought you to safety. " 102 . "Fortunately, some friendly dwellers found you, checked your passport, and brought you to safety. "
78 . "Better use a savebed next time, much worse things could have happened...", 103 . "Better use a savebed next time, much worse things could have happened... "
104 . "H<You disconnected without having used a savebed. When you do that for too long, you might die.>",
79 cf::NDI_RED 105 cf::NDI_RED
80 ); 106 );
107 }
81 } else { 108 } else {
82 $pl->ns->send_drawinfo ( 109 $ob->message (
83 "You didn't use a bed to reality to leave this realm. This is very dangerous, " 110 "You didn't use a bed to reality to leave this realm. This is very dangerous, "
84 . "as lots of things could happen when you leave by other means, such as cave-ins, " 111 . "as lots of things could happen when you leave by other means, such as cave-ins, "
85 . "or monsters suddenly snapping your body. Better use a savebed next time.", 112 . "or monsters suddenly snapping your body. Better use a savebed next time. "
113 . "H<Always apply a bed of reality to disconnect from the server.>",
86 cf::NDI_RED 114 cf::NDI_RED
87 ); 115 );
88 }
89 } 116 }
90 } 117 }
91 118
92 $pl->ob->goto ($map, $x, $y); 119 $ob->goto ($map, $x, $y);
93} 120}
94 121
95# delete a player directory, be non-blocking AND synchronous... 122# delete a player directory, be non-blocking AND synchronous...
96# (thats hard, so we crap out and fork). 123# (thats hard, so we crap out and fork).
97sub nuke_playerdir { 124sub nuke_playerdir {
98 my ($user) = @_; 125 my ($user) = @_;
99 126
100 aio_stat "$PLAYERDIR/$user"; 127 my $temp = "$PLAYERDIR/~$Coro::current~deleting~";
101 system "cd \Q$PLAYERDIR\E " 128
102 . "&& mv \Q$user\E ~\Q$Coro::current\E~deleting~ 2>/dev/null " 129 cf::fork_call {
103 . "&& (rm -rf ~\Q$Coro::current\E~deleting~ &)"; 130 rename "$PLAYERDIR/$user", $temp;
131 system "rm", "-rf", $temp;
132 };
104} 133}
105 134
106cf::client->attach (on_addme => sub { 135cf::client->attach (on_addme => sub {
107 my ($ns) = @_; 136 my ($ns) = @_;
108 137
121*** 150***
122*** CFPlus: all known versions automatically enable the facecache. 151*** CFPlus: all known versions automatically enable the facecache.
123*** cfclient: use the -cache commandline option. 152*** cfclient: use the -cache commandline option.
124*** cfclient: map will not redraw automatically (bug). 153*** cfclient: map will not redraw automatically (bug).
125*** gcfclient: use -cache commandline option, or enable 154*** gcfclient: use -cache commandline option, or enable
126*** gcfclient: Client=>Configure=>Map & Image=>Cache Images. 155*** gcfclient: Client => Configure => Map & Image => Cache Images.
127*** jcrossclient: your client is broken, use CFPlus or gcfclient. 156*** jcrossclient: your client is broken, use CFPlus or gcfclient.
128*** 157***
129*** 158***
130EOF 159EOF
131 if ($ns->version =~ /jcrossclient/) { 160 if ($ns->version =~ /jcrossclient/) {
152 } 181 }
153 182
154 $ns->pl and return $ns->destroy; 183 $ns->pl and return $ns->destroy;
155 184
156 $ns->async (sub { 185 $ns->async (sub {
186 $Coro::current->{desc} = "addme init";
187
157 my ($user, $pass); 188 my ($user, $pass);
158 189
159 $ns->send_packet ("addme_success"); 190 $ns->send_packet ("addme_success");
160 191
161 for (;;) { 192 for (;;) {
189 Coro::Timer::sleep 0.4; 220 Coro::Timer::sleep 0.4;
190 } 221 }
191 222
192 check_playing $ns, $user and next; 223 check_playing $ns, $user and next;
193 224
225 $Coro::current->{desc} = "addme($user) pass";
226
194 $ns->send_drawinfo ( 227 $ns->send_drawinfo (
195 "Welcome $user, please enter your password now. " 228 "Welcome $user, please enter your password now. "
196 . "New users should now choose a password. " 229 . "New users should now choose a password. "
197 . "Anything your client lets you enter is fine.", 230 . "Anything your client lets you enter is fine.",
198 cf::NDI_BLUE 231 cf::NDI_BLUE
220 next; 253 next;
221 } 254 }
222 local $cf::LOGIN_LOCK{$user} = 1; 255 local $cf::LOGIN_LOCK{$user} = 1;
223 256
224 check_playing $ns, $user and next; 257 check_playing $ns, $user and next;
258
259 $Coro::current->{desc} = "addme($user) check";
225 260
226 # try to read the user file and check the password 261 # try to read the user file and check the password
227 if (my $pl = cf::player::find $user) { 262 if (my $pl = cf::player::find $user) {
228 aio_stat $pl->path and next; 263 aio_stat $pl->path and next;
229 my $mtime = (stat _)[9]; 264 my $mtime = (stat _)[9];
283 next; 318 next;
284 } 319 }
285 } 320 }
286 321
287 # the rest of this function is character creation 322 # the rest of this function is character creation
323 $Coro::current->{desc} = "addme($user) chargen";
288 324
289 # just to make sure nothing is left over 325 # just to make sure nothing is left over
290 nuke_playerdir $user; 326 nuke_playerdir $user;
291 327
292 my $pass2 = query $ns, cf::CS_QUERY_HIDEINPUT, "Please type your password again."; 328 my $pass2 = query $ns, cf::CS_QUERY_HIDEINPUT, "Please type your password again.";
336 372
337 $ob->set_animation (2); 373 $ob->set_animation (2);
338 $ob->add_statbonus; 374 $ob->add_statbonus;
339 375
340 while () { 376 while () {
341 $ns->send_msg (-1, "chargen-race-title", ucfirst $pl->title); 377 $ns->send_msg ("chargen-race-title", ucfirst $pl->title, -1);
342 my $msg = $ob->msg; 378 my $msg = $ob->msg;
343 $msg =~ s/(?<=\S)\n(?=\S)/ /g; 379 $msg =~ s/(?<=\S)\n(?=\S)/ /g;
344 $ns->send_msg (cf::NDI_BLUE, "chargen-race-description", $msg); 380 $ns->send_msg ("chargen-race-description", $msg, cf::NDI_BLUE);
345 381
346 my $res = query $ns, cf::CS_QUERY_SINGLECHAR, 382 my $res = query $ns, cf::CS_QUERY_SINGLECHAR,
347 "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n"; 383 "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n";
348 384
349 last if $res =~ /[dD]/; 385 last if $res =~ /[dD]/;
366 last; 402 last;
367 } 403 }
368 Coro::Timer::sleep 0.2; 404 Coro::Timer::sleep 0.2;
369 } 405 }
370 406
371 $ob->reply (undef, "Welcome to Crossfire!"); 407 $ob->reply (undef, "Welcome to Deliantra!");
372 408
373 delete $pl->{deny_save}; 409 delete $pl->{deny_save};
374 410
375 last; 411 last;
376 } 412 }
456 }, 492 },
457); 493);
458 494
459############################################################################# 495#############################################################################
460 496
461our $SCHEDULE_INTERVAL = 10; # time the player scheduler sleeps between runs 497our $SCHEDULE_INTERVAL = $cf::CFG{player_schedule_interval} || 10; # time the player scheduler sleeps between runs
462our $SAVE_TIMEOUT = 20; # save players every n seconds 498our $SAVE_TIMEOUT = $cf::CFG{player_save_interval} || 20; # save players every n seconds
463 499
464our $SCHEDULER = cf::async_ext { 500our $SCHEDULER = cf::async_ext {
465 my $schedule_interval = Coro::Event->timer (after => 1, interval => $SCHEDULE_INTERVAL); 501 $Coro::current->{desc} = "player scheduler";
502
466 while () { 503 while () {
467 $schedule_interval->next; 504 Coro::EV::timer_once $SCHEDULE_INTERVAL;
468 505
469 # this weird form of iteration over values is used because 506 # this weird form of iteration over values is used because
470 # the hash changes underneath us frequently, and for 507 # the hash changes underneath us frequently, and for
471 # keeps a direct reference to the value without (in 5.8 perls) 508 # keeps a direct reference to the value without (in 5.8 perls)
472 # keeping a reference, so this is prone to crashes or worse. 509 # keeping a reference, so this is prone to crashes or worse.
476 or next; 513 or next;
477 $pl->valid or next; 514 $pl->valid or next;
478 515
479 eval { 516 eval {
480 if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { 517 if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) {
481 cf::wait_for_tick_begin;
482 $pl->save; 518 $pl->save;
483 519
484 unless ($pl->active || $pl->ns) { 520 unless ($pl->active || $pl->ns) {
485 # check refcounts, this is tricky and needs to be adjusted to fit server internals 521 # check refcounts, this is tricky and needs to be adjusted to fit server internals
486 my $ob = $pl->ob; 522 my $ob = $pl->ob;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines