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.78 by root, Mon Jan 7 01:55:19 2008 UTC

52 ); 52 );
53 53
54 1 54 1
55} 55}
56 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
57sub enter_map { 68sub enter_map {
58 my ($pl) = @_; 69 my ($pl) = @_;
59 70
60 my $ob = $pl->ob; 71 my $ob = $pl->ob;
61 72
64 ? @{delete $ob->{_link_pos}} 75 ? @{delete $ob->{_link_pos}}
65 : ($pl->maplevel, $ob->x, $ob->y); 76 : ($pl->maplevel, $ob->x, $ob->y);
66 77
67 $ob->enter_link; 78 $ob->enter_link;
68 79
80 my $m = cf::map::find $map;
69 if (my $time = delete $pl->{unclean_save}) { 81 my $time = delete $pl->{unclean_save};
70 if (my $m = cf::map::find $map) { 82
83 if ($time && $m && !safe_spot $m, $x, $y) {
71 if ($time < $m->{instantiate_time}) { 84 if ($time < $m->{instantiate_time}) {
72 # the map was reset in the meantime 85 # the map was reset in the meantime
73 my $age = $cf::RUNTIME - $time; 86 my $age = $cf::RUNTIME - $time;
74 87
75 warn $ob->name, " map reset after logout, logout age $age (>= $MAX_DISCONNECT_TIME)\n";#d# 88 warn $ob->name, " map reset after logout, logout age $age (>= $MAX_DISCONNECT_TIME)\n";#d#
76 89
77 # for now, just go back to savebed
78 ($map, $x, $y) = $pl->savebed; 90 ($map, $x, $y) = $pl->savebed;
79 91
80 if ($age >= $MAX_DISCONNECT_TIME) { 92 if ($age >= $MAX_DISCONNECT_TIME) {
81 $ob->message ( 93 $ob->message (
82 "You didn't use a bed to reality to leave this realm, leaving your body in great danger. " 94 "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. " 95 . "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... " 96 . "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.>", 97 . "H<You disconnected too long without having used a savebed.>",
86 cf::NDI_RED 98 cf::NDI_RED
87 ); 99 );
88 # kill them. 100 # kill them.
89 # reminds me of the famous badness 10000 syndrome... 101 # reminds me of the famous badness 10000 syndrome...
90 $ob->stats->hp (-10000); #] if they survive this they deserved to live 102 $ob->stats->hp (-10000); #] if they survive this they deserved to live
91 $pl->killer ("a cave-in"); 103 $pl->killer ("a cave-in");
92 } else {
93 $ob->message (
94 "You didn't use a bed to reality to leave this realm, leaving your body in great danger. "
95 . "Fortunately, some friendly dwellers found you, checked your passport, and brought you to safety. "
96 . "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.>",
98 cf::NDI_RED
99 );
100 }
101 } else { 104 } else {
102 $ob->message ( 105 $ob->message (
103 "You didn't use a bed to reality to leave this realm. This is very dangerous, " 106 "You didn't use a bed to reality to leave this realm, leaving your body in great danger. "
104 . "as lots of things could happen when you leave by other means, such as cave-ins, " 107 . "Fortunately, some friendly dwellers found you, checked your passport, and brought you to safety. "
105 . "or monsters suddenly snapping your body. Better use a savebed next time. " 108 . "Better use a savebed next time, much worse things could have happened... "
106 . "H<Always apply a bed of reality to disconnect from the server.>", 109 . "H<You disconnected without having used a savebed. When you do that for too long, you might die.>",
107 cf::NDI_RED 110 cf::NDI_RED
108 ); 111 );
109 } 112 }
113 } else {
114 $ob->message (
115 "You didn't use a bed to reality to leave this realm. This is very dangerous, "
116 . "as lots of things could happen when you leave by other means, such as cave-ins, "
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.>",
119 cf::NDI_RED
120 );
110 } 121 }
111 } 122 }
112 123
113 $ob->goto ($map, $x, $y); 124 $ob->goto ($map, $x, $y);
114} 125}
116# delete a player directory, be non-blocking AND synchronous... 127# delete a player directory, be non-blocking AND synchronous...
117# (thats hard, so we crap out and fork). 128# (thats hard, so we crap out and fork).
118sub nuke_playerdir { 129sub nuke_playerdir {
119 my ($user) = @_; 130 my ($user) = @_;
120 131
121 aio_stat "$PLAYERDIR/$user"; 132 my $temp = "$PLAYERDIR/~$Coro::current~deleting~";
122 system "cd \Q$PLAYERDIR\E " 133
123 . "&& mv \Q$user\E ~\Q$Coro::current\E~deleting~ 2>/dev/null " 134 cf::fork_call {
124 . "&& (rm -rf ~\Q$Coro::current\E~deleting~ &)"; 135 rename "$PLAYERDIR/$user", $temp;
136 system "rm", "-rf", $temp;
137 };
125} 138}
126 139
127cf::client->attach (on_addme => sub { 140cf::client->attach (on_addme => sub {
128 my ($ns) = @_; 141 my ($ns) = @_;
129 142
142*** 155***
143*** CFPlus: all known versions automatically enable the facecache. 156*** CFPlus: all known versions automatically enable the facecache.
144*** cfclient: use the -cache commandline option. 157*** cfclient: use the -cache commandline option.
145*** cfclient: map will not redraw automatically (bug). 158*** cfclient: map will not redraw automatically (bug).
146*** gcfclient: use -cache commandline option, or enable 159*** gcfclient: use -cache commandline option, or enable
147*** gcfclient: Client=>Configure=>Map & Image=>Cache Images. 160*** gcfclient: Client => Configure => Map & Image => Cache Images.
148*** jcrossclient: your client is broken, use CFPlus or gcfclient. 161*** jcrossclient: your client is broken, use CFPlus or gcfclient.
149*** 162***
150*** 163***
151EOF 164EOF
152 if ($ns->version =~ /jcrossclient/) { 165 if ($ns->version =~ /jcrossclient/) {
173 } 186 }
174 187
175 $ns->pl and return $ns->destroy; 188 $ns->pl and return $ns->destroy;
176 189
177 $ns->async (sub { 190 $ns->async (sub {
191 $Coro::current->{desc} = "addme init";
192
178 my ($user, $pass); 193 my ($user, $pass);
179 194
180 $ns->send_packet ("addme_success"); 195 $ns->send_packet ("addme_success");
181 196
182 for (;;) { 197 for (;;) {
210 Coro::Timer::sleep 0.4; 225 Coro::Timer::sleep 0.4;
211 } 226 }
212 227
213 check_playing $ns, $user and next; 228 check_playing $ns, $user and next;
214 229
230 $Coro::current->{desc} = "addme($user) pass";
231
215 $ns->send_drawinfo ( 232 $ns->send_drawinfo (
216 "Welcome $user, please enter your password now. " 233 "Welcome $user, please enter your password now. "
217 . "New users should now choose a password. " 234 . "New users should now choose a password. "
218 . "Anything your client lets you enter is fine.", 235 . "Anything your client lets you enter is fine.",
219 cf::NDI_BLUE 236 cf::NDI_BLUE
241 next; 258 next;
242 } 259 }
243 local $cf::LOGIN_LOCK{$user} = 1; 260 local $cf::LOGIN_LOCK{$user} = 1;
244 261
245 check_playing $ns, $user and next; 262 check_playing $ns, $user and next;
263
264 $Coro::current->{desc} = "addme($user) check";
246 265
247 # try to read the user file and check the password 266 # try to read the user file and check the password
248 if (my $pl = cf::player::find $user) { 267 if (my $pl = cf::player::find $user) {
249 aio_stat $pl->path and next; 268 aio_stat $pl->path and next;
250 my $mtime = (stat _)[9]; 269 my $mtime = (stat _)[9];
304 next; 323 next;
305 } 324 }
306 } 325 }
307 326
308 # the rest of this function is character creation 327 # the rest of this function is character creation
328 $Coro::current->{desc} = "addme($user) chargen";
309 329
310 # just to make sure nothing is left over 330 # just to make sure nothing is left over
311 nuke_playerdir $user; 331 nuke_playerdir $user;
312 332
313 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.";
387 last; 407 last;
388 } 408 }
389 Coro::Timer::sleep 0.2; 409 Coro::Timer::sleep 0.2;
390 } 410 }
391 411
392 $ob->reply (undef, "Welcome to Crossfire!"); 412 $ob->reply (undef, "Welcome to Deliantra!");
393 413
394 delete $pl->{deny_save}; 414 delete $pl->{deny_save};
395 415
396 last; 416 last;
397 } 417 }
477 }, 497 },
478); 498);
479 499
480############################################################################# 500#############################################################################
481 501
482our $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
483our $SAVE_TIMEOUT = 20; # save players every n seconds 503our $SAVE_TIMEOUT = $cf::CFG{player_save_interval} || 20; # save players every n seconds
484 504
485our $SCHEDULER = cf::async_ext { 505our $SCHEDULER = cf::async_ext {
486 my $schedule_interval = Coro::Event->timer (after => 1, interval => $SCHEDULE_INTERVAL); 506 $Coro::current->{desc} = "player scheduler";
507
487 while () { 508 while () {
488 $schedule_interval->next; 509 Coro::EV::timer_once $SCHEDULE_INTERVAL;
489 510
490 # this weird form of iteration over values is used because 511 # this weird form of iteration over values is used because
491 # the hash changes underneath us frequently, and for 512 # the hash changes underneath us frequently, and for
492 # 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)
493 # keeping a reference, so this is prone to crashes or worse. 514 # keeping a reference, so this is prone to crashes or worse.
497 or next; 518 or next;
498 $pl->valid or next; 519 $pl->valid or next;
499 520
500 eval { 521 eval {
501 if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { 522 if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) {
502 cf::wait_for_tick_begin;
503 $pl->save; 523 $pl->save;
504 524
505 unless ($pl->active || $pl->ns) { 525 unless ($pl->active || $pl->ns) {
506 # 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
507 my $ob = $pl->ob; 527 my $ob = $pl->ob;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines