ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cf.schmorp.de/server/ext/login.ext
(Generate patch)

Comparing cf.schmorp.de/server/ext/login.ext (file contents):
Revision 1.64 by root, Sat Jul 14 19:27:59 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 } else { 103 $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 { 104 } else {
101 $ob->message ( 105 $ob->message (
102 "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. "
103 . "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. "
104 . "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... "
105 . "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.>",
106 cf::NDI_RED 110 cf::NDI_RED
107 ); 111 );
108 } 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 );
109 } 121 }
110 } 122 }
111 123
112 $ob->goto ($map, $x, $y); 124 $ob->goto ($map, $x, $y);
113} 125}
115# delete a player directory, be non-blocking AND synchronous... 127# delete a player directory, be non-blocking AND synchronous...
116# (thats hard, so we crap out and fork). 128# (thats hard, so we crap out and fork).
117sub nuke_playerdir { 129sub nuke_playerdir {
118 my ($user) = @_; 130 my ($user) = @_;
119 131
120 aio_stat "$PLAYERDIR/$user"; 132 my $temp = "$PLAYERDIR/~$Coro::current~deleting~";
121 system "cd \Q$PLAYERDIR\E " 133
122 . "&& mv \Q$user\E ~\Q$Coro::current\E~deleting~ 2>/dev/null " 134 cf::fork_call {
123 . "&& (rm -rf ~\Q$Coro::current\E~deleting~ &)"; 135 rename "$PLAYERDIR/$user", $temp;
136 system "rm", "-rf", $temp;
137 };
124} 138}
125 139
126cf::client->attach (on_addme => sub { 140cf::client->attach (on_addme => sub {
127 my ($ns) = @_; 141 my ($ns) = @_;
128 142
141*** 155***
142*** CFPlus: all known versions automatically enable the facecache. 156*** CFPlus: all known versions automatically enable the facecache.
143*** cfclient: use the -cache commandline option. 157*** cfclient: use the -cache commandline option.
144*** cfclient: map will not redraw automatically (bug). 158*** cfclient: map will not redraw automatically (bug).
145*** gcfclient: use -cache commandline option, or enable 159*** gcfclient: use -cache commandline option, or enable
146*** gcfclient: Client=>Configure=>Map & Image=>Cache Images. 160*** gcfclient: Client => Configure => Map & Image => Cache Images.
147*** jcrossclient: your client is broken, use CFPlus or gcfclient. 161*** jcrossclient: your client is broken, use CFPlus or gcfclient.
148*** 162***
149*** 163***
150EOF 164EOF
151 if ($ns->version =~ /jcrossclient/) { 165 if ($ns->version =~ /jcrossclient/) {
172 } 186 }
173 187
174 $ns->pl and return $ns->destroy; 188 $ns->pl and return $ns->destroy;
175 189
176 $ns->async (sub { 190 $ns->async (sub {
191 $Coro::current->{desc} = "addme init";
192
177 my ($user, $pass); 193 my ($user, $pass);
178 194
179 $ns->send_packet ("addme_success"); 195 $ns->send_packet ("addme_success");
180 196
181 for (;;) { 197 for (;;) {
209 Coro::Timer::sleep 0.4; 225 Coro::Timer::sleep 0.4;
210 } 226 }
211 227
212 check_playing $ns, $user and next; 228 check_playing $ns, $user and next;
213 229
230 $Coro::current->{desc} = "addme($user) pass";
231
214 $ns->send_drawinfo ( 232 $ns->send_drawinfo (
215 "Welcome $user, please enter your password now. " 233 "Welcome $user, please enter your password now. "
216 . "New users should now choose a password. " 234 . "New users should now choose a password. "
217 . "Anything your client lets you enter is fine.", 235 . "Anything your client lets you enter is fine.",
218 cf::NDI_BLUE 236 cf::NDI_BLUE
240 next; 258 next;
241 } 259 }
242 local $cf::LOGIN_LOCK{$user} = 1; 260 local $cf::LOGIN_LOCK{$user} = 1;
243 261
244 check_playing $ns, $user and next; 262 check_playing $ns, $user and next;
263
264 $Coro::current->{desc} = "addme($user) check";
245 265
246 # try to read the user file and check the password 266 # try to read the user file and check the password
247 if (my $pl = cf::player::find $user) { 267 if (my $pl = cf::player::find $user) {
248 aio_stat $pl->path and next; 268 aio_stat $pl->path and next;
249 my $mtime = (stat _)[9]; 269 my $mtime = (stat _)[9];
303 next; 323 next;
304 } 324 }
305 } 325 }
306 326
307 # the rest of this function is character creation 327 # the rest of this function is character creation
328 $Coro::current->{desc} = "addme($user) chargen";
308 329
309 # just to make sure nothing is left over 330 # just to make sure nothing is left over
310 nuke_playerdir $user; 331 nuke_playerdir $user;
311 332
312 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.";
356 377
357 $ob->set_animation (2); 378 $ob->set_animation (2);
358 $ob->add_statbonus; 379 $ob->add_statbonus;
359 380
360 while () { 381 while () {
361 $ns->send_msg (-1, "chargen-race-title", ucfirst $pl->title); 382 $ns->send_msg ("chargen-race-title", ucfirst $pl->title, -1);
362 my $msg = $ob->msg; 383 my $msg = $ob->msg;
363 $msg =~ s/(?<=\S)\n(?=\S)/ /g; 384 $msg =~ s/(?<=\S)\n(?=\S)/ /g;
364 $ns->send_msg (cf::NDI_BLUE, "chargen-race-description", $msg); 385 $ns->send_msg ("chargen-race-description", $msg, cf::NDI_BLUE);
365 386
366 my $res = query $ns, cf::CS_QUERY_SINGLECHAR, 387 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"; 388 "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n";
368 389
369 last if $res =~ /[dD]/; 390 last if $res =~ /[dD]/;
386 last; 407 last;
387 } 408 }
388 Coro::Timer::sleep 0.2; 409 Coro::Timer::sleep 0.2;
389 } 410 }
390 411
391 $ob->reply (undef, "Welcome to Crossfire!"); 412 $ob->reply (undef, "Welcome to Deliantra!");
392 413
393 delete $pl->{deny_save}; 414 delete $pl->{deny_save};
394 415
395 last; 416 last;
396 } 417 }
476 }, 497 },
477); 498);
478 499
479############################################################################# 500#############################################################################
480 501
481our $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
482our $SAVE_TIMEOUT = 20; # save players every n seconds 503our $SAVE_TIMEOUT = $cf::CFG{player_save_interval} || 20; # save players every n seconds
483 504
484our $SCHEDULER = cf::async_ext { 505our $SCHEDULER = cf::async_ext {
485 my $schedule_interval = Coro::Event->timer (after => 1, interval => $SCHEDULE_INTERVAL); 506 $Coro::current->{desc} = "player scheduler";
507
486 while () { 508 while () {
487 $schedule_interval->next; 509 Coro::EV::timer_once $SCHEDULE_INTERVAL;
488 510
489 # this weird form of iteration over values is used because 511 # this weird form of iteration over values is used because
490 # the hash changes underneath us frequently, and for 512 # the hash changes underneath us frequently, and for
491 # 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)
492 # keeping a reference, so this is prone to crashes or worse. 514 # keeping a reference, so this is prone to crashes or worse.
496 or next; 518 or next;
497 $pl->valid or next; 519 $pl->valid or next;
498 520
499 eval { 521 eval {
500 if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) { 522 if ($pl->{last_save} + $SAVE_TIMEOUT <= $cf::RUNTIME) {
501 cf::wait_for_tick_begin;
502 $pl->save; 523 $pl->save;
503 524
504 unless ($pl->active || $pl->ns) { 525 unless ($pl->active || $pl->ns) {
505 # 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
506 my $ob = $pl->ob; 527 my $ob = $pl->ob;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines