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.67 by root, Fri Jul 20 16:11:10 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.>",
96 . "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... "
97 . "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.>",
98 cf::NDI_RED 105 cf::NDI_RED
99 ); 106 );
100 } 107 }
108 } elsif (safe_spot $m, $x, $y) {
109 # do nothing, this is simply ok without a special scary message
101 } else { 110 } else {
102 $ob->message ( 111 $ob->message (
103 "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, "
104 . "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, "
105 . "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. "
116# delete a player directory, be non-blocking AND synchronous... 125# delete a player directory, be non-blocking AND synchronous...
117# (thats hard, so we crap out and fork). 126# (thats hard, so we crap out and fork).
118sub nuke_playerdir { 127sub nuke_playerdir {
119 my ($user) = @_; 128 my ($user) = @_;
120 129
121 aio_stat "$PLAYERDIR/$user"; 130 my $temp = "$PLAYERDIR/~$Coro::current~deleting~";
122 system "cd \Q$PLAYERDIR\E " 131
123 . "&& mv \Q$user\E ~\Q$Coro::current\E~deleting~ 2>/dev/null " 132 cf::fork_call {
124 . "&& (rm -rf ~\Q$Coro::current\E~deleting~ &)"; 133 rename "$PLAYERDIR/$user", $temp;
134 system "rm", "-rf", $temp;
135 };
125} 136}
126 137
127cf::client->attach (on_addme => sub { 138cf::client->attach (on_addme => sub {
128 my ($ns) = @_; 139 my ($ns) = @_;
129 140
142*** 153***
143*** CFPlus: all known versions automatically enable the facecache. 154*** CFPlus: all known versions automatically enable the facecache.
144*** cfclient: use the -cache commandline option. 155*** cfclient: use the -cache commandline option.
145*** cfclient: map will not redraw automatically (bug). 156*** cfclient: map will not redraw automatically (bug).
146*** gcfclient: use -cache commandline option, or enable 157*** gcfclient: use -cache commandline option, or enable
147*** gcfclient: Client=>Configure=>Map & Image=>Cache Images. 158*** gcfclient: Client => Configure => Map & Image => Cache Images.
148*** jcrossclient: your client is broken, use CFPlus or gcfclient. 159*** jcrossclient: your client is broken, use CFPlus or gcfclient.
149*** 160***
150*** 161***
151EOF 162EOF
152 if ($ns->version =~ /jcrossclient/) { 163 if ($ns->version =~ /jcrossclient/) {
173 } 184 }
174 185
175 $ns->pl and return $ns->destroy; 186 $ns->pl and return $ns->destroy;
176 187
177 $ns->async (sub { 188 $ns->async (sub {
189 $Coro::current->{desc} = "addme init";
190
178 my ($user, $pass); 191 my ($user, $pass);
179 192
180 $ns->send_packet ("addme_success"); 193 $ns->send_packet ("addme_success");
181 194
182 for (;;) { 195 for (;;) {
209 } 222 }
210 Coro::Timer::sleep 0.4; 223 Coro::Timer::sleep 0.4;
211 } 224 }
212 225
213 check_playing $ns, $user and next; 226 check_playing $ns, $user and next;
227
228 $Coro::current->{desc} = "addme($user) pass";
214 229
215 $ns->send_drawinfo ( 230 $ns->send_drawinfo (
216 "Welcome $user, please enter your password now. " 231 "Welcome $user, please enter your password now. "
217 . "New users should now choose a password. " 232 . "New users should now choose a password. "
218 . "Anything your client lets you enter is fine.", 233 . "Anything your client lets you enter is fine.",
242 } 257 }
243 local $cf::LOGIN_LOCK{$user} = 1; 258 local $cf::LOGIN_LOCK{$user} = 1;
244 259
245 check_playing $ns, $user and next; 260 check_playing $ns, $user and next;
246 261
262 $Coro::current->{desc} = "addme($user) check";
263
247 # try to read the user file and check the password 264 # try to read the user file and check the password
248 if (my $pl = cf::player::find $user) { 265 if (my $pl = cf::player::find $user) {
249 aio_stat $pl->path and next; 266 aio_stat $pl->path and next;
250 my $mtime = (stat _)[9]; 267 my $mtime = (stat _)[9];
251 my $hash = $pl->password; 268 my $hash = $pl->password;
304 next; 321 next;
305 } 322 }
306 } 323 }
307 324
308 # the rest of this function is character creation 325 # the rest of this function is character creation
326 $Coro::current->{desc} = "addme($user) chargen";
309 327
310 # just to make sure nothing is left over 328 # just to make sure nothing is left over
311 nuke_playerdir $user; 329 nuke_playerdir $user;
312 330
313 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.";
387 last; 405 last;
388 } 406 }
389 Coro::Timer::sleep 0.2; 407 Coro::Timer::sleep 0.2;
390 } 408 }
391 409
392 $ob->reply (undef, "Welcome to Crossfire!"); 410 $ob->reply (undef, "Welcome to Deliantra!");
393 411
394 delete $pl->{deny_save}; 412 delete $pl->{deny_save};
395 413
396 last; 414 last;
397 } 415 }
477 }, 495 },
478); 496);
479 497
480############################################################################# 498#############################################################################
481 499
482our $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
483our $SAVE_TIMEOUT = 20; # save players every n seconds 501our $SAVE_TIMEOUT = $cf::CFG{player_save_interval} || 20; # save players every n seconds
484 502
485our $SCHEDULER = cf::async_ext { 503our $SCHEDULER = cf::async_ext {
486 my $schedule_interval = Coro::Event->timer (after => 1, interval => $SCHEDULE_INTERVAL); 504 $Coro::current->{desc} = "player scheduler";
505
487 while () { 506 while () {
488 $schedule_interval->next; 507 Coro::EV::timer_once $SCHEDULE_INTERVAL;
489 508
490 # this weird form of iteration over values is used because 509 # this weird form of iteration over values is used because
491 # the hash changes underneath us frequently, and for 510 # the hash changes underneath us frequently, and for
492 # 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)
493 # keeping a reference, so this is prone to crashes or worse. 512 # keeping a reference, so this is prone to crashes or worse.
497 or next; 516 or next;
498 $pl->valid or next; 517 $pl->valid or next;
499 518
500 eval { 519 eval {
501 if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { 520 if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) {
502 cf::wait_for_tick_begin;
503 $pl->save; 521 $pl->save;
504 522
505 unless ($pl->active || $pl->ns) { 523 unless ($pl->active || $pl->ns) {
506 # 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
507 my $ob = $pl->ob; 525 my $ob = $pl->ob;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines