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.60 by root, Thu Jul 5 20:52:22 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
71 my $ob = $pl->ob;
72
58 my ($map, $x, $y) 73 my ($map, $x, $y)
59 = $pl->ob->{_link_pos} 74 = $ob->{_link_pos}
60 ? @{delete $pl->ob->{_link_pos}} 75 ? @{delete $ob->{_link_pos}}
61 : ($pl->maplevel, $pl->ob->x, $pl->ob->y); 76 : ($pl->maplevel, $ob->x, $ob->y);
62 77
63 $pl->ob->enter_link; 78 $ob->enter_link;
64 79
80 my $m = cf::map::find $map;
65 if (my $time = delete $pl->{unclean_save}) { 81 my $time = delete $pl->{unclean_save};
66 if (my $m = cf::map::find $map) { 82
83 if ($time && $m && !safe_spot $m, $x, $y) {
67 if ($time < $m->{instantiate_time}) { 84 if ($time < $m->{instantiate_time}) {
68 # the map was reset in the meantime 85 # the map was reset in the meantime
69 my $age = $cf::RUNTIME - $time; 86 my $age = $cf::RUNTIME - $time;
87
70 warn $pl->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#
71 89
72 # for now, just go back to savebed
73 ($map, $x, $y) = $pl->savebed; 90 ($map, $x, $y) = $pl->savebed;
74 91
75 $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 (
76 "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. "
77 . "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. "
78 . "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.>",
79 cf::NDI_RED 110 cf::NDI_RED
80 ); 111 );
112 }
81 } else { 113 } else {
82 $pl->ns->send_drawinfo ( 114 $ob->message (
83 "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, "
84 . "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, "
85 . "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.>",
86 cf::NDI_RED 119 cf::NDI_RED
87 ); 120 );
88 }
89 } 121 }
90 } 122 }
91 123
92 $pl->ob->goto ($map, $x, $y); 124 $ob->goto ($map, $x, $y);
93} 125}
94 126
95# delete a player directory, be non-blocking AND synchronous... 127# delete a player directory, be non-blocking AND synchronous...
96# (thats hard, so we crap out and fork). 128# (thats hard, so we crap out and fork).
97sub nuke_playerdir { 129sub nuke_playerdir {
98 my ($user) = @_; 130 my ($user) = @_;
99 131
100 aio_stat "$PLAYERDIR/$user"; 132 my $temp = "$PLAYERDIR/~$Coro::current~deleting~";
101 system "cd \Q$PLAYERDIR\E " 133
102 . "&& mv \Q$user\E ~\Q$Coro::current\E~deleting~ 2>/dev/null " 134 cf::fork_call {
103 . "&& (rm -rf ~\Q$Coro::current\E~deleting~ &)"; 135 rename "$PLAYERDIR/$user", $temp;
136 system "rm", "-rf", $temp;
137 };
104} 138}
105 139
106cf::client->attach (on_addme => sub { 140cf::client->attach (on_addme => sub {
107 my ($ns) = @_; 141 my ($ns) = @_;
108 142
121*** 155***
122*** CFPlus: all known versions automatically enable the facecache. 156*** CFPlus: all known versions automatically enable the facecache.
123*** cfclient: use the -cache commandline option. 157*** cfclient: use the -cache commandline option.
124*** cfclient: map will not redraw automatically (bug). 158*** cfclient: map will not redraw automatically (bug).
125*** gcfclient: use -cache commandline option, or enable 159*** gcfclient: use -cache commandline option, or enable
126*** gcfclient: Client=>Configure=>Map & Image=>Cache Images. 160*** gcfclient: Client => Configure => Map & Image => Cache Images.
127*** jcrossclient: your client is broken, use CFPlus or gcfclient. 161*** jcrossclient: your client is broken, use CFPlus or gcfclient.
128*** 162***
129*** 163***
130EOF 164EOF
131 if ($ns->version =~ /jcrossclient/) { 165 if ($ns->version =~ /jcrossclient/) {
152 } 186 }
153 187
154 $ns->pl and return $ns->destroy; 188 $ns->pl and return $ns->destroy;
155 189
156 $ns->async (sub { 190 $ns->async (sub {
191 $Coro::current->{desc} = "addme init";
192
157 my ($user, $pass); 193 my ($user, $pass);
158 194
159 $ns->send_packet ("addme_success"); 195 $ns->send_packet ("addme_success");
160 196
161 for (;;) { 197 for (;;) {
184 . "(only a-z, A-Z and 0-9 are allowed), " 220 . "(only a-z, A-Z and 0-9 are allowed), "
185 . "or is not between 3 and 18 characters in length.", 221 . "or is not between 3 and 18 characters in length.",
186 cf::NDI_RED 222 cf::NDI_RED
187 ); 223 );
188 } 224 }
225 Coro::Timer::sleep 0.4;
189 } 226 }
190 227
191 check_playing $ns, $user and next; 228 check_playing $ns, $user and next;
229
230 $Coro::current->{desc} = "addme($user) pass";
192 231
193 $ns->send_drawinfo ( 232 $ns->send_drawinfo (
194 "Welcome $user, please enter your password now. " 233 "Welcome $user, please enter your password now. "
195 . "New users should now choose a password. " 234 . "New users should now choose a password. "
196 . "Anything your client lets you enter is fine.", 235 . "Anything your client lets you enter is fine.",
204 $ns->send_drawinfo ( 243 $ns->send_drawinfo (
205 "Try to use at least three characters as your password please, " 244 "Try to use at least three characters as your password please, "
206 . "that cannot be too much to ask for :)", 245 . "that cannot be too much to ask for :)",
207 cf::NDI_RED 246 cf::NDI_RED
208 ); 247 );
248 Coro::Timer::sleep 0.4;
209 } 249 }
210 250
211 # lock this username for the remainder of this login session 251 # lock this username for the remainder of this login session
212 if ($cf::LOGIN_LOCK{$user}) { 252 if ($cf::LOGIN_LOCK{$user}) {
213 $ns->send_drawinfo ( 253 $ns->send_drawinfo (
218 next; 258 next;
219 } 259 }
220 local $cf::LOGIN_LOCK{$user} = 1; 260 local $cf::LOGIN_LOCK{$user} = 1;
221 261
222 check_playing $ns, $user and next; 262 check_playing $ns, $user and next;
263
264 $Coro::current->{desc} = "addme($user) check";
223 265
224 # try to read the user file and check the password 266 # try to read the user file and check the password
225 if (my $pl = cf::player::find $user) { 267 if (my $pl = cf::player::find $user) {
226 aio_stat $pl->path and next; 268 aio_stat $pl->path and next;
227 my $mtime = (stat _)[9]; 269 my $mtime = (stat _)[9];
281 next; 323 next;
282 } 324 }
283 } 325 }
284 326
285 # the rest of this function is character creation 327 # the rest of this function is character creation
328 $Coro::current->{desc} = "addme($user) chargen";
286 329
287 # just to make sure nothing is left over 330 # just to make sure nothing is left over
288 nuke_playerdir $user; 331 nuke_playerdir $user;
289 332
290 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.";
294 nuke_str $pass2; 337 nuke_str $pass2;
295 $ns->send_drawinfo ( 338 $ns->send_drawinfo (
296 "The passwords do not match, please try again.", 339 "The passwords do not match, please try again.",
297 cf::NDI_RED 340 cf::NDI_RED
298 ); 341 );
342 Coro::Timer::sleep 0.5;
299 next; 343 next;
300 } 344 }
301 345
302 nuke_str $pass2; 346 nuke_str $pass2;
303 347
325 $ob->swap_stats ($res - 1, $swap - 1); 369 $ob->swap_stats ($res - 1, $swap - 1);
326 } 370 }
327 } else { 371 } else {
328 $ob->roll_stats; 372 $ob->roll_stats;
329 } 373 }
374
375 Coro::Timer::sleep 0.2;
330 } 376 }
331 377
332 $ob->set_animation (2); 378 $ob->set_animation (2);
333 $ob->add_statbonus; 379 $ob->add_statbonus;
334 380
335 while () { 381 while () {
336 $ns->send_msg (-1, "chargen-race-title", ucfirst $pl->title); 382 $ns->send_msg ("chargen-race-title", ucfirst $pl->title, -1);
337 my $msg = $ob->msg; 383 my $msg = $ob->msg;
338 $msg =~ s/(?<=\S)\n(?=\S)/ /g; 384 $msg =~ s/(?<=\S)\n(?=\S)/ /g;
339 $ns->send_msg (cf::NDI_BLUE, "chargen-race-description", $msg); 385 $ns->send_msg ("chargen-race-description", $msg, cf::NDI_BLUE);
340 386
341 my $res = query $ns, cf::CS_QUERY_SINGLECHAR, 387 my $res = query $ns, cf::CS_QUERY_SINGLECHAR,
342 "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";
343 389
344 last if $res =~ /[dD]/; 390 last if $res =~ /[dD]/;
345 391
346 $pl->chargen_race_next; 392 $pl->chargen_race_next;
393 Coro::Timer::sleep 0.2;
347 } 394 }
348 395
349 $pl->chargen_race_done; 396 $pl->chargen_race_done;
350 397
351 while () { 398 while () {
357 last; 404 last;
358 } elsif ($res =~ /^[mM]/) { 405 } elsif ($res =~ /^[mM]/) {
359 $pl->gender (0); 406 $pl->gender (0);
360 last; 407 last;
361 } 408 }
409 Coro::Timer::sleep 0.2;
362 } 410 }
363 411
364 $ob->reply (undef, "Welcome to Crossfire!"); 412 $ob->reply (undef, "Welcome to Deliantra!");
365 413
366 delete $pl->{deny_save}; 414 delete $pl->{deny_save};
367 415
368 last; 416 last;
369 } 417 }
449 }, 497 },
450); 498);
451 499
452############################################################################# 500#############################################################################
453 501
454our $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
455our $SAVE_TIMEOUT = 20; # save players every n seconds 503our $SAVE_TIMEOUT = $cf::CFG{player_save_interval} || 20; # save players every n seconds
456 504
457our $SCHEDULER = cf::async_ext { 505our $SCHEDULER = cf::async_ext {
458 my $schedule_interval = Coro::Event->timer (after => 1, interval => $SCHEDULE_INTERVAL); 506 $Coro::current->{desc} = "player scheduler";
507
459 while () { 508 while () {
460 $schedule_interval->next; 509 Coro::EV::timer_once $SCHEDULE_INTERVAL;
461 510
462 # this weird form of iteration over values is used because 511 # this weird form of iteration over values is used because
463 # the hash changes underneath us frequently, and for 512 # the hash changes underneath us frequently, and for
464 # 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)
465 # keeping a reference, so this is prone to crashes or worse. 514 # keeping a reference, so this is prone to crashes or worse.
469 or next; 518 or next;
470 $pl->valid or next; 519 $pl->valid or next;
471 520
472 eval { 521 eval {
473 if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { 522 if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) {
474 cf::wait_for_tick_begin;
475 $pl->save; 523 $pl->save;
476 524
477 unless ($pl->active || $pl->ns) { 525 unless ($pl->active || $pl->ns) {
478 # 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
479 my $ob = $pl->ob; 527 my $ob = $pl->ob;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines