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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines