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.64 by root, Sat Jul 14 19:27:59 2007 UTC vs.
Revision 1.76 by root, Fri Dec 28 19:40:22 2007 UTC

52 ); 52 );
53 53
54 1 54 1
55} 55}
56 56
57sub safe_spot($$$) {
58 my ($m, $x, $y) = @_;
59
60 scalar grep $_->type == cf::SAVEBED, $m->at ($x, $y)
61}
62
57sub enter_map { 63sub enter_map {
58 my ($pl) = @_; 64 my ($pl) = @_;
59 65
60 my $ob = $pl->ob; 66 my $ob = $pl->ob;
61 67
72 # the map was reset in the meantime 78 # the map was reset in the meantime
73 my $age = $cf::RUNTIME - $time; 79 my $age = $cf::RUNTIME - $time;
74 80
75 warn $ob->name, " map reset after logout, logout age $age (>= $MAX_DISCONNECT_TIME)\n";#d# 81 warn $ob->name, " map reset after logout, logout age $age (>= $MAX_DISCONNECT_TIME)\n";#d#
76 82
77 # for now, just go back to savebed
78 ($map, $x, $y) = $pl->savebed; 83 ($map, $x, $y) = $pl->savebed;
79 84
85 if (safe_spot $m, $x, $y) {
86 # do nothing, this is simply ok without a special scary message
80 if ($age >= $MAX_DISCONNECT_TIME) { 87 } elsif ($age >= $MAX_DISCONNECT_TIME) {
81 $ob->message ( 88 $ob->message (
82 "You didn't use a bed to reality to leave this realm, leaving your body in great danger. " 89 "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. " 90 . "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... " 91 . "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.>", 92 . "H<You disconnected too long without having used a savebed.>",
86 cf::NDI_RED 93 cf::NDI_RED
87 ); 94 );
88 # kill them. 95 # kill them.
89 # reminds me of the famous badness 10000 syndrome... 96 # reminds me of the famous badness 10000 syndrome...
90 $ob->stats->hp (-10000); #] if they survive this they deserved to live 97 $ob->stats->hp (-10000); #] if they survive this they deserved to live
98 $pl->killer ("a cave-in");
91 } else { 99 } else {
92 $ob->message ( 100 $ob->message (
93 "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. "
94 . "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. "
95 . "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... "
96 . "H<You disconnected without having used a savebed. When you do that for too long, you might die.>", 104 . "H<You disconnected without having used a savebed. When you do that for too long, you might die.>",
97 cf::NDI_RED 105 cf::NDI_RED
98 ); 106 );
99 } 107 }
108 } elsif (safe_spot $m, $x, $y) {
109 # do nothing, this is simply ok without a special scary message
100 } else { 110 } else {
101 $ob->message ( 111 $ob->message (
102 "You didn't use a bed to reality to leave this realm. This is very dangerous, " 112 "You didn't use a bed to reality to leave this realm. This is very dangerous, "
103 . "as lots of things could happen when you leave by other means, such as cave-ins, " 113 . "as lots of things could happen when you leave by other means, such as cave-ins, "
104 . "or monsters suddenly snapping your body. Better use a savebed next time. " 114 . "or monsters suddenly snapping your body. Better use a savebed next time. "
115# delete a player directory, be non-blocking AND synchronous... 125# delete a player directory, be non-blocking AND synchronous...
116# (thats hard, so we crap out and fork). 126# (thats hard, so we crap out and fork).
117sub nuke_playerdir { 127sub nuke_playerdir {
118 my ($user) = @_; 128 my ($user) = @_;
119 129
120 aio_stat "$PLAYERDIR/$user"; 130 my $temp = "$PLAYERDIR/~$Coro::current~deleting~";
121 system "cd \Q$PLAYERDIR\E " 131
122 . "&& mv \Q$user\E ~\Q$Coro::current\E~deleting~ 2>/dev/null " 132 cf::fork_call {
123 . "&& (rm -rf ~\Q$Coro::current\E~deleting~ &)"; 133 rename "$PLAYERDIR/$user", $temp;
134 system "rm", "-rf", $temp;
135 };
124} 136}
125 137
126cf::client->attach (on_addme => sub { 138cf::client->attach (on_addme => sub {
127 my ($ns) = @_; 139 my ($ns) = @_;
128 140
141*** 153***
142*** CFPlus: all known versions automatically enable the facecache. 154*** CFPlus: all known versions automatically enable the facecache.
143*** cfclient: use the -cache commandline option. 155*** cfclient: use the -cache commandline option.
144*** cfclient: map will not redraw automatically (bug). 156*** cfclient: map will not redraw automatically (bug).
145*** gcfclient: use -cache commandline option, or enable 157*** gcfclient: use -cache commandline option, or enable
146*** gcfclient: Client=>Configure=>Map & Image=>Cache Images. 158*** gcfclient: Client => Configure => Map & Image => Cache Images.
147*** jcrossclient: your client is broken, use CFPlus or gcfclient. 159*** jcrossclient: your client is broken, use CFPlus or gcfclient.
148*** 160***
149*** 161***
150EOF 162EOF
151 if ($ns->version =~ /jcrossclient/) { 163 if ($ns->version =~ /jcrossclient/) {
172 } 184 }
173 185
174 $ns->pl and return $ns->destroy; 186 $ns->pl and return $ns->destroy;
175 187
176 $ns->async (sub { 188 $ns->async (sub {
189 $Coro::current->{desc} = "addme init";
190
177 my ($user, $pass); 191 my ($user, $pass);
178 192
179 $ns->send_packet ("addme_success"); 193 $ns->send_packet ("addme_success");
180 194
181 for (;;) { 195 for (;;) {
208 } 222 }
209 Coro::Timer::sleep 0.4; 223 Coro::Timer::sleep 0.4;
210 } 224 }
211 225
212 check_playing $ns, $user and next; 226 check_playing $ns, $user and next;
227
228 $Coro::current->{desc} = "addme($user) pass";
213 229
214 $ns->send_drawinfo ( 230 $ns->send_drawinfo (
215 "Welcome $user, please enter your password now. " 231 "Welcome $user, please enter your password now. "
216 . "New users should now choose a password. " 232 . "New users should now choose a password. "
217 . "Anything your client lets you enter is fine.", 233 . "Anything your client lets you enter is fine.",
241 } 257 }
242 local $cf::LOGIN_LOCK{$user} = 1; 258 local $cf::LOGIN_LOCK{$user} = 1;
243 259
244 check_playing $ns, $user and next; 260 check_playing $ns, $user and next;
245 261
262 $Coro::current->{desc} = "addme($user) check";
263
246 # try to read the user file and check the password 264 # try to read the user file and check the password
247 if (my $pl = cf::player::find $user) { 265 if (my $pl = cf::player::find $user) {
248 aio_stat $pl->path and next; 266 aio_stat $pl->path and next;
249 my $mtime = (stat _)[9]; 267 my $mtime = (stat _)[9];
250 my $hash = $pl->password; 268 my $hash = $pl->password;
303 next; 321 next;
304 } 322 }
305 } 323 }
306 324
307 # the rest of this function is character creation 325 # the rest of this function is character creation
326 $Coro::current->{desc} = "addme($user) chargen";
308 327
309 # just to make sure nothing is left over 328 # just to make sure nothing is left over
310 nuke_playerdir $user; 329 nuke_playerdir $user;
311 330
312 my $pass2 = query $ns, cf::CS_QUERY_HIDEINPUT, "Please type your password again."; 331 my $pass2 = query $ns, cf::CS_QUERY_HIDEINPUT, "Please type your password again.";
356 375
357 $ob->set_animation (2); 376 $ob->set_animation (2);
358 $ob->add_statbonus; 377 $ob->add_statbonus;
359 378
360 while () { 379 while () {
361 $ns->send_msg (-1, "chargen-race-title", ucfirst $pl->title); 380 $ns->send_msg ("chargen-race-title", ucfirst $pl->title, -1);
362 my $msg = $ob->msg; 381 my $msg = $ob->msg;
363 $msg =~ s/(?<=\S)\n(?=\S)/ /g; 382 $msg =~ s/(?<=\S)\n(?=\S)/ /g;
364 $ns->send_msg (cf::NDI_BLUE, "chargen-race-description", $msg); 383 $ns->send_msg ("chargen-race-description", $msg, cf::NDI_BLUE);
365 384
366 my $res = query $ns, cf::CS_QUERY_SINGLECHAR, 385 my $res = query $ns, cf::CS_QUERY_SINGLECHAR,
367 "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n"; 386 "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n";
368 387
369 last if $res =~ /[dD]/; 388 last if $res =~ /[dD]/;
386 last; 405 last;
387 } 406 }
388 Coro::Timer::sleep 0.2; 407 Coro::Timer::sleep 0.2;
389 } 408 }
390 409
391 $ob->reply (undef, "Welcome to Crossfire!"); 410 $ob->reply (undef, "Welcome to Deliantra!");
392 411
393 delete $pl->{deny_save}; 412 delete $pl->{deny_save};
394 413
395 last; 414 last;
396 } 415 }
476 }, 495 },
477); 496);
478 497
479############################################################################# 498#############################################################################
480 499
481our $SCHEDULE_INTERVAL = 10; # time the player scheduler sleeps between runs 500our $SCHEDULE_INTERVAL = $cf::CFG{player_schedule_interval} || 10; # time the player scheduler sleeps between runs
482our $SAVE_TIMEOUT = 20; # save players every n seconds 501our $SAVE_TIMEOUT = $cf::CFG{player_save_interval} || 20; # save players every n seconds
483 502
484our $SCHEDULER = cf::async_ext { 503our $SCHEDULER = cf::async_ext {
485 my $schedule_interval = Coro::Event->timer (after => 1, interval => $SCHEDULE_INTERVAL); 504 $Coro::current->{desc} = "player scheduler";
505
486 while () { 506 while () {
487 $schedule_interval->next; 507 Coro::EV::timer_once $SCHEDULE_INTERVAL;
488 508
489 # this weird form of iteration over values is used because 509 # this weird form of iteration over values is used because
490 # the hash changes underneath us frequently, and for 510 # the hash changes underneath us frequently, and for
491 # keeps a direct reference to the value without (in 5.8 perls) 511 # keeps a direct reference to the value without (in 5.8 perls)
492 # keeping a reference, so this is prone to crashes or worse. 512 # keeping a reference, so this is prone to crashes or worse.
496 or next; 516 or next;
497 $pl->valid or next; 517 $pl->valid or next;
498 518
499 eval { 519 eval {
500 if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { 520 if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) {
501 cf::wait_for_tick_begin;
502 $pl->save; 521 $pl->save;
503 522
504 unless ($pl->active || $pl->ns) { 523 unless ($pl->active || $pl->ns) {
505 # check refcounts, this is tricky and needs to be adjusted to fit server internals 524 # check refcounts, this is tricky and needs to be adjusted to fit server internals
506 my $ob = $pl->ob; 525 my $ob = $pl->ob;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines