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.95 by root, Wed Dec 17 16:43:38 2008 UTC vs.
Revision 1.110 by root, Sat May 8 10:49:44 2010 UTC

1#! perl # mandatory 1#! perl # mandatory depends=highscore
2 2
3# login handling 3# login handling
4 4
5use Fcntl; 5use Fcntl;
6use Coro::AIO; 6use Coro::AIO;
70} 70}
71 71
72sub enter_map { 72sub enter_map {
73 my ($pl) = @_; 73 my ($pl) = @_;
74 74
75 warn $pl->ob->name, ": enter map 1\n";#d#
76 my $ob = $pl->ob; 75 my $ob = $pl->ob;
77 76
78 my ($map, $x, $y) 77 my ($map, $x, $y)
79 = $ob->{_link_pos} 78 = $ob->{_link_pos}
80 ? @{delete $ob->{_link_pos}} 79 ? @{delete $ob->{_link_pos}}
81 : ($pl->maplevel, $ob->x, $ob->y); 80 : ($pl->maplevel, $ob->x, $ob->y);
82 81
83 warn $pl->ob->name, ": enter map 2\n";#d#
84 $ob->enter_link; 82 $ob->enter_link;
85 warn $pl->ob->name, ": enter map 3\n";#d#
86 83
87 my $m = cf::map::find $map; 84 my $m = cf::map::find $map;
88 my $time = delete $pl->{unclean_save}; 85 my $time = delete $pl->{unclean_save};
89 warn $pl->ob->name, ": enter map 4\n";#d#
90 86
91 if ($time && $m) { 87 if ($time && $m) {
92 if ($time < $m->{instantiate_time}) { 88 if ($time < $m->{instantiate_time}) {
93 # the map was reset in the meantime 89 # the map was reset in the meantime
94 my $age = $cf::RUNTIME - $time; 90 my $age = $cf::RUNTIME - $time;
95 91
96 warn $ob->name, " map reset after logout, logout age $age (>= $MAX_DISCONNECT_TIME)\n";#d# 92 cf::info $ob->name, " map reset after logout, logout age $age (>= $MAX_DISCONNECT_TIME)\n";#d#
97 93
98 if ($age >= $MAX_DISCONNECT_TIME) { 94 if ($age >= $MAX_DISCONNECT_TIME) {
99 $ob->message ( 95 $ob->message (
100 "You didn't use a bed to reality to leave this realm, leaving your body in great danger. " 96 "You didn't use a bed to reality to leave this realm, leaving your body in great danger. "
101 . "Unfortunately, nobody was near to help you when the monsters arrived to eat you. " 97 . "Unfortunately, nobody was near to help you when the monsters arrived to eat you. "
127 cf::NDI_RED 123 cf::NDI_RED
128 ); 124 );
129 } 125 }
130 } 126 }
131 127
132 warn $pl->ob->name, ": enter map 5\n";#d#
133 #$ob->goto ($map, $x, $y); 128 $ob->goto ($map, $x, $y);
134 $ob->goto ($map, $x, $y, sub { 129}
135 warn $pl->ob->name, ": enter map check\n";#d# 130
136 $_[0] 131sub encode_password($) {
137 }, sub { 132# crypt $_[0],
138 warn $pl->ob->name, ": enter map done\n";#d# 133# join '',
134# ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[(cf::rndm 64), (cf::rndm 64)]
135 "!" . unpack "H*", $_[0]
136}
137
138sub compare_password($$) {
139 my ($pass, $token) = @_;
140
141 if ($token =~ /\!(.*)/) {
142 return $pass eq pack "H*", $1;
143 } else {
144 return $token eq crypt $pass, $token;
139 }); 145 }
140 warn $pl->ob->name, ": enter map 6\n";#d#
141
142} 146}
143 147
144# delete a player directory, be non-blocking AND synchronous... 148# delete a player directory, be non-blocking AND synchronous...
145# (thats hard, so we crap out and fork). 149# (that's hard, so we crap out and fork).
146sub nuke_playerdir { 150sub nuke_playerdir {
147 my ($user) = @_; 151 my ($user) = @_;
148 152
149 my $temp = "$PLAYERDIR/~$Coro::current~deleting~"; 153 my $temp = "$PLAYERDIR/~$Coro::current~deleting~";
150 154
154 }; 158 };
155} 159}
156 160
157cf::client->attach (on_addme => sub { 161cf::client->attach (on_addme => sub {
158 my ($ns) = @_; 162 my ($ns) = @_;
159
160 if (!$ns->facecache)
161 {
162 $ns->send_drawinfo (<<EOF, cf::NDI_RED);
163
164
165***
166*** WARNING:
167*** Your client does not support face/image caching,
168*** or it has been disabled. Face caching is mandatory
169*** so please enable it or use a newer client.
170***
171*** Look at your client preferences:
172***
173*** deliantra: all known versions automatically enable the facecache.
174*** cfclient: use the -cache commandline option.
175*** cfclient: map will not redraw automatically (bug).
176*** gcfclient: use -cache commandline option, or enable
177*** gcfclient: Client => Configure => Map & Image => Cache Images.
178*** jcrossclient: your client is broken, use deliantra or gcfclient.
179***
180***
181EOF
182 if ($ns->version =~ /jcrossclient/) {
183 # let them, for now
184 } else {
185 $ns->flush;
186 return $ns->destroy;
187 }
188
189 # $ns->facecache = true;
190 }
191
192 if ($ns->mapmode < cf::Map1aCmd) {
193 $ns->send_drawinfo (<<EOF, cf::NDI_RED);
194
195
196***
197*** WARNING:
198*** Your client is too old. Please upgrade to a newer version.
199EOF
200
201 $ns->flush;
202 return $ns->destroy;
203 }
204 163
205 $ns->pl and return $ns->destroy; 164 $ns->pl and return $ns->destroy;
206 165
207 $ns->async (sub { 166 $ns->async (sub {
208 $Coro::current->{desc} = "addme init"; 167 $Coro::current->{desc} = "addme init";
282 241
283 # try to read the user file and check the password 242 # try to read the user file and check the password
284 if (my $pl = cf::player::find $user) { 243 if (my $pl = cf::player::find $user) {
285 aio_stat $pl->path and next; 244 aio_stat $pl->path and next;
286 my $mtime = (stat _)[9]; 245 my $mtime = (stat _)[9];
287 my $hash = $pl->password; 246 my $token = $pl->password;
288 247
289 if ($cf::CFG{ext_login_nocheck} or $hash eq crypt $pass, $hash) { 248 if ($cf::CFG{ext_login_nocheck} or compare_password $pass, $token) {
249 $pl->password (encode_password $pass); # make sure we store the new encoding #d#
290 nuke_str $pass; 250 nuke_str $pass;
291 # password matches, wonderful 251 # password matches, wonderful
292 my $pl = cf::player::find $user or next; 252 my $pl = cf::player::find $user or next;
293 $pl->connect ($ns); 253 $pl->connect ($ns);
294 $pl->ob->flag (cf::FLAG_DEBUG, 1);#d# temp
295 enter_map $pl; 254 enter_map $pl;
296 last; 255 last;
297 } elsif (can_cleanup $pl, $mtime) { 256 } elsif (can_cleanup $pl, $mtime) {
298 Coro::Timer::sleep 1; 257 Coro::Timer::sleep 1;
299 258
362 } 321 }
363 322
364 nuke_str $pass2; 323 nuke_str $pass2;
365 324
366 my $pl = cf::player::new $user; 325 my $pl = cf::player::new $user;
367 $pl->password (crypt $pass, join '', ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[rand 64, rand 64]); 326 $pl->password (encode_password $pass);
368 nuke_str $pass; 327 nuke_str $pass;
369 $pl->connect ($ns); 328 $pl->connect ($ns);
370 my $ob = $pl->ob; 329 my $ob = $pl->ob;
371 330
372 $ob->goto ($pl->maplevel, $ob->x, $ob->y); 331 $ob->goto ($pl->maplevel, $ob->x, $ob->y);
406 "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n"; 365 "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n";
407 366
408 last if $res =~ /[dD]/; 367 last if $res =~ /[dD]/;
409 368
410 $pl->chargen_race_next; 369 $pl->chargen_race_next;
411 Coro::Timer::sleep 0.2; 370 Coro::Timer::sleep 0.05;
412 } 371 }
413 372
414 # create the playerdir, if necessary, as chargen_race_done did it before 373 # create the playerdir, if necessary, as chargen_race_done did it before
415 # presumably because of unique maps 374 # presumably because of unique maps
416 aio_mkdir playerdir $pl, 0770; 375 aio_mkdir playerdir $pl, 0770;
425 last; 384 last;
426 } elsif ($res =~ /^[mM]/) { 385 } elsif ($res =~ /^[mM]/) {
427 $pl->gender (0); 386 $pl->gender (0);
428 last; 387 last;
429 } 388 }
430 Coro::Timer::sleep 0.2; 389 Coro::Timer::sleep 0.05;
431 } 390 }
432 391
433 $ob->reply (undef, "Welcome to Deliantra!"); 392 $ob->reply (undef, "Welcome to Deliantra!");
434 393
435 # XXX: Workaround for delayed client ext protocol handshake 394 # XXX: Workaround for delayed client ext protocol handshake
437 396
438 delete $pl->{deny_save}; 397 delete $pl->{deny_save};
439 398
440 last; 399 last;
441 } 400 }
401
402 if (0 < Coro::AIO::aio_load "$cf::CONFDIR/motd", my $motd) {
403 $ns->send_msg ("c/motd" => $motd, cf::NDI_CLEAR);
404 }
442 }); 405 });
443}); 406});
407
408cf::register_command password => sub {
409 my ($pl, $arg) = @_;
410
411 my (@args) = split /\s+/, $arg;
412
413 my ($new_pw, $player);
414
415 if ($pl->flag (cf::FLAG_WIZ)) {
416 ($player, $new_pw) = @args;
417 } else {
418 $new_pw = $args[0];
419 }
420
421 if ($pl->flag (cf::FLAG_WIZ) && $player eq '') {
422 $pl->message (
423 "Usage: password <player> [<new password>]",
424 cf::NDI_UNIQUE | cf::NDI_REPLY);
425 return;
426 } elsif (!$pl->flag (cf::FLAG_WIZ) && $new_pw eq '') {
427 $pl->message (
428 "Usage: password <new password>",
429 cf::NDI_UNIQUE | cf::NDI_REPLY);
430 return;
431 }
432
433 if ($player ne '' && $pl->flag (cf::FLAG_WIZ)) {
434 unless ($new_pw ne '') {
435 $new_pw =
436 join '',
437 map { ('.', '/', 0..9, 'A'..'Z', 'a'..'z')[(cf::rndm 64)] }
438 1..9;
439 }
440
441 cf::async {
442 my $plc = cf::player::find $player;
443 if ($plc) {
444 $plc->password (encode_password $new_pw);
445 $pl->message (
446 "Ok, changed password of '$player' to '$new_pw'!",
447 cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY);
448 } else {
449 $pl->message (
450 "Fail! Couldn't set password for '$player', "
451 . "he doesn't seem to exist!",
452 cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY);
453 }
454 };
455 } else {
456 my $change = delete $pl->{password_change};
457
458 if ($change && (time - $change->[0]) < 60) {
459 $pl->message (
460 "Ok, changed your password!",
461 cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY);
462 $pl->contr->password (encode_password $new_pw);
463
464 } else {
465 $pl->message (
466 "Ok, please confirm your new password by sending "
467 . "the command again within one minute!",
468 cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY);
469 $pl->{password_change} = [time, $new_pw];
470 }
471 }
472};
444 473
445cf::register_command quit => sub { 474cf::register_command quit => sub {
446 my ($ob, $arg) = @_; 475 my ($ob, $arg) = @_;
447 476
448 $ob->send_msg (undef, 477 $ob->send_msg (undef,
460 if ($_[0] !~ /^[yY]/) { 489 if ($_[0] !~ /^[yY]/) {
461 $ob->send_msg (undef, "Ok, not not quitting then.", cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); 490 $ob->send_msg (undef, "Ok, not not quitting then.", cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY);
462 } else { 491 } else {
463 $ob->send_msg (undef, "Ok, quitting, hope to see you again.", cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY); 492 $ob->send_msg (undef, "Ok, quitting, hope to see you again.", cf::NDI_UNIQUE | cf::NDI_RED | cf::NDI_REPLY);
464 $pl->ns->flush; 493 $pl->ns->flush;
494 cf::async {
495 ext::highscore::check $pl->ob;
465 cf::async { $pl->quit_character }; 496 $pl->quit_character;
497 };
466 } 498 }
467 }); 499 });
468}; 500};
469 501
470cf::object->attach ( 502cf::object->attach (
479 # update respawn position 511 # update respawn position
480 $pl->savebed ($bed->map->path, $bed->x, $bed->y); 512 $pl->savebed ($bed->map->path, $bed->x, $bed->y);
481 cf::async { $pl->save }; 513 cf::async { $pl->save };
482 514
483 my $killer = cf::arch::get "killer_logout"; $pl->killer ($killer); $killer->destroy; 515 my $killer = cf::arch::get "killer_logout"; $pl->killer ($killer); $killer->destroy;
484 $ob->check_score; 516 ext::highscore::check $ob;
485 517
486 $ob->send_msg ($cf::SAY_CHANNEL => "In the future, you will wake up here when you die.", cf::NDI_DEF | cf::NDI_REPLY); 518 $ob->send_msg ($cf::SAY_CHANNEL => "In the future, you will wake up here when you die.", cf::NDI_DEF | cf::NDI_REPLY);
487 519
488 $pl->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to continue playing (y/n)?", sub { 520 $pl->ns->query (cf::CS_QUERY_SINGLECHAR, "Do you want to continue playing (y/n)?", sub {
489 if ($_[0] !~ /^[yY]/) { 521 if ($_[0] !~ /^[yY]/) {
516 unless safe_spot $pl; 548 unless safe_spot $pl;
517 } 549 }
518 }, 550 },
519); 551);
520 552
521

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines