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.77 by root, Fri Dec 28 19:44:34 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
64 ? @{delete $ob->{_link_pos}} 70 ? @{delete $ob->{_link_pos}}
65 : ($pl->maplevel, $ob->x, $ob->y); 71 : ($pl->maplevel, $ob->x, $ob->y);
66 72
67 $ob->enter_link; 73 $ob->enter_link;
68 74
75 my $m = cf::map::find $map;
69 if (my $time = delete $pl->{unclean_save}) { 76 my $time = delete $pl->{unclean_save};
70 if (my $m = cf::map::find $map) { 77
78 if ($time && $m && !safe_spot $m, $x, $y) {
71 if ($time < $m->{instantiate_time}) { 79 if ($time < $m->{instantiate_time}) {
72 # the map was reset in the meantime 80 # the map was reset in the meantime
73 my $age = $cf::RUNTIME - $time; 81 my $age = $cf::RUNTIME - $time;
74 82
75 warn $ob->name, " map reset after logout, logout age $age (>= $MAX_DISCONNECT_TIME)\n";#d# 83 warn $ob->name, " map reset after logout, logout age $age (>= $MAX_DISCONNECT_TIME)\n";#d#
76 84
77 # for now, just go back to savebed
78 ($map, $x, $y) = $pl->savebed; 85 ($map, $x, $y) = $pl->savebed;
79 86
80 if ($age >= $MAX_DISCONNECT_TIME) { 87 if ($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
91 } else { 98 $pl->killer ("a cave-in");
92 $ob->message (
93 "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. "
95 . "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.>",
97 cf::NDI_RED
98 );
99 }
100 } else { 99 } else {
101 $ob->message ( 100 $ob->message (
102 "You didn't use a bed to reality to leave this realm. This is very dangerous, " 101 "You didn't use a bed to reality to leave this realm, leaving your body in great danger. "
103 . "as lots of things could happen when you leave by other means, such as cave-ins, " 102 . "Fortunately, some friendly dwellers found you, checked your passport, and brought you to safety. "
104 . "or monsters suddenly snapping your body. Better use a savebed next time. " 103 . "Better use a savebed next time, much worse things could have happened... "
105 . "H<Always apply a bed of reality to disconnect from the server.>", 104 . "H<You disconnected without having used a savebed. When you do that for too long, you might die.>",
106 cf::NDI_RED 105 cf::NDI_RED
107 ); 106 );
108 } 107 }
108 } else {
109 $ob->message (
110 "You didn't use a bed to reality to leave this realm. This is very dangerous, "
111 . "as lots of things could happen when you leave by other means, such as cave-ins, "
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.>",
114 cf::NDI_RED
115 );
109 } 116 }
110 } 117 }
111 118
112 $ob->goto ($map, $x, $y); 119 $ob->goto ($map, $x, $y);
113} 120}
115# delete a player directory, be non-blocking AND synchronous... 122# delete a player directory, be non-blocking AND synchronous...
116# (thats hard, so we crap out and fork). 123# (thats hard, so we crap out and fork).
117sub nuke_playerdir { 124sub nuke_playerdir {
118 my ($user) = @_; 125 my ($user) = @_;
119 126
120 aio_stat "$PLAYERDIR/$user"; 127 my $temp = "$PLAYERDIR/~$Coro::current~deleting~";
121 system "cd \Q$PLAYERDIR\E " 128
122 . "&& mv \Q$user\E ~\Q$Coro::current\E~deleting~ 2>/dev/null " 129 cf::fork_call {
123 . "&& (rm -rf ~\Q$Coro::current\E~deleting~ &)"; 130 rename "$PLAYERDIR/$user", $temp;
131 system "rm", "-rf", $temp;
132 };
124} 133}
125 134
126cf::client->attach (on_addme => sub { 135cf::client->attach (on_addme => sub {
127 my ($ns) = @_; 136 my ($ns) = @_;
128 137
141*** 150***
142*** CFPlus: all known versions automatically enable the facecache. 151*** CFPlus: all known versions automatically enable the facecache.
143*** cfclient: use the -cache commandline option. 152*** cfclient: use the -cache commandline option.
144*** cfclient: map will not redraw automatically (bug). 153*** cfclient: map will not redraw automatically (bug).
145*** gcfclient: use -cache commandline option, or enable 154*** gcfclient: use -cache commandline option, or enable
146*** gcfclient: Client=>Configure=>Map & Image=>Cache Images. 155*** gcfclient: Client => Configure => Map & Image => Cache Images.
147*** jcrossclient: your client is broken, use CFPlus or gcfclient. 156*** jcrossclient: your client is broken, use CFPlus or gcfclient.
148*** 157***
149*** 158***
150EOF 159EOF
151 if ($ns->version =~ /jcrossclient/) { 160 if ($ns->version =~ /jcrossclient/) {
172 } 181 }
173 182
174 $ns->pl and return $ns->destroy; 183 $ns->pl and return $ns->destroy;
175 184
176 $ns->async (sub { 185 $ns->async (sub {
186 $Coro::current->{desc} = "addme init";
187
177 my ($user, $pass); 188 my ($user, $pass);
178 189
179 $ns->send_packet ("addme_success"); 190 $ns->send_packet ("addme_success");
180 191
181 for (;;) { 192 for (;;) {
209 Coro::Timer::sleep 0.4; 220 Coro::Timer::sleep 0.4;
210 } 221 }
211 222
212 check_playing $ns, $user and next; 223 check_playing $ns, $user and next;
213 224
225 $Coro::current->{desc} = "addme($user) pass";
226
214 $ns->send_drawinfo ( 227 $ns->send_drawinfo (
215 "Welcome $user, please enter your password now. " 228 "Welcome $user, please enter your password now. "
216 . "New users should now choose a password. " 229 . "New users should now choose a password. "
217 . "Anything your client lets you enter is fine.", 230 . "Anything your client lets you enter is fine.",
218 cf::NDI_BLUE 231 cf::NDI_BLUE
240 next; 253 next;
241 } 254 }
242 local $cf::LOGIN_LOCK{$user} = 1; 255 local $cf::LOGIN_LOCK{$user} = 1;
243 256
244 check_playing $ns, $user and next; 257 check_playing $ns, $user and next;
258
259 $Coro::current->{desc} = "addme($user) check";
245 260
246 # try to read the user file and check the password 261 # try to read the user file and check the password
247 if (my $pl = cf::player::find $user) { 262 if (my $pl = cf::player::find $user) {
248 aio_stat $pl->path and next; 263 aio_stat $pl->path and next;
249 my $mtime = (stat _)[9]; 264 my $mtime = (stat _)[9];
303 next; 318 next;
304 } 319 }
305 } 320 }
306 321
307 # the rest of this function is character creation 322 # the rest of this function is character creation
323 $Coro::current->{desc} = "addme($user) chargen";
308 324
309 # just to make sure nothing is left over 325 # just to make sure nothing is left over
310 nuke_playerdir $user; 326 nuke_playerdir $user;
311 327
312 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.";
356 372
357 $ob->set_animation (2); 373 $ob->set_animation (2);
358 $ob->add_statbonus; 374 $ob->add_statbonus;
359 375
360 while () { 376 while () {
361 $ns->send_msg (-1, "chargen-race-title", ucfirst $pl->title); 377 $ns->send_msg ("chargen-race-title", ucfirst $pl->title, -1);
362 my $msg = $ob->msg; 378 my $msg = $ob->msg;
363 $msg =~ s/(?<=\S)\n(?=\S)/ /g; 379 $msg =~ s/(?<=\S)\n(?=\S)/ /g;
364 $ns->send_msg (cf::NDI_BLUE, "chargen-race-description", $msg); 380 $ns->send_msg ("chargen-race-description", $msg, cf::NDI_BLUE);
365 381
366 my $res = query $ns, cf::CS_QUERY_SINGLECHAR, 382 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"; 383 "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n";
368 384
369 last if $res =~ /[dD]/; 385 last if $res =~ /[dD]/;
386 last; 402 last;
387 } 403 }
388 Coro::Timer::sleep 0.2; 404 Coro::Timer::sleep 0.2;
389 } 405 }
390 406
391 $ob->reply (undef, "Welcome to Crossfire!"); 407 $ob->reply (undef, "Welcome to Deliantra!");
392 408
393 delete $pl->{deny_save}; 409 delete $pl->{deny_save};
394 410
395 last; 411 last;
396 } 412 }
476 }, 492 },
477); 493);
478 494
479############################################################################# 495#############################################################################
480 496
481our $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
482our $SAVE_TIMEOUT = 20; # save players every n seconds 498our $SAVE_TIMEOUT = $cf::CFG{player_save_interval} || 20; # save players every n seconds
483 499
484our $SCHEDULER = cf::async_ext { 500our $SCHEDULER = cf::async_ext {
485 my $schedule_interval = Coro::Event->timer (after => 1, interval => $SCHEDULE_INTERVAL); 501 $Coro::current->{desc} = "player scheduler";
502
486 while () { 503 while () {
487 $schedule_interval->next; 504 Coro::EV::timer_once $SCHEDULE_INTERVAL;
488 505
489 # this weird form of iteration over values is used because 506 # this weird form of iteration over values is used because
490 # the hash changes underneath us frequently, and for 507 # the hash changes underneath us frequently, and for
491 # 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)
492 # keeping a reference, so this is prone to crashes or worse. 509 # keeping a reference, so this is prone to crashes or worse.
496 or next; 513 or next;
497 $pl->valid or next; 514 $pl->valid or next;
498 515
499 eval { 516 eval {
500 if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { 517 if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) {
501 cf::wait_for_tick_begin;
502 $pl->save; 518 $pl->save;
503 519
504 unless ($pl->active || $pl->ns) { 520 unless ($pl->active || $pl->ns) {
505 # 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
506 my $ob = $pl->ob; 522 my $ob = $pl->ob;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines