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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines