--- deliantra/server/ext/login.ext 2007/06/25 05:43:45 1.57 +++ deliantra/server/ext/login.ext 2007/07/20 16:11:10 1.67 @@ -4,9 +4,8 @@ use Fcntl; use Coro::AIO; -use List::Util qw(min max); -our %EXT_SETUP; +our $MAX_DISCONNECT_TIME = $cf::CFG{max_disconnect_time} || 3600; # paranoia function to overwrite a string-in-place sub nuke_str { @@ -43,8 +42,8 @@ $ns->send_drawinfo ( "That player is already logged in on this server. " . "If you want to create a new player, choose another name. " - . "If you are already a registered player, make sure nobody " - . "else is using your account at this time. If you lost your conenction " + . "If you have already a registered, make sure nobody " + . "else is using your account at this time. If you lost your connection " . "then the server will likely timeout within a minute. If you still " . "cannot log-in after a minute, you are still logged in. Make sure " . "you do not have another client running. If you use windows, reboot, " @@ -58,41 +57,60 @@ sub enter_map { my ($pl) = @_; + my $ob = $pl->ob; + my ($map, $x, $y) - = $pl->ob->{_link_pos} - ? @{delete $pl->ob->{_link_pos}} - : ($pl->maplevel, $pl->ob->x, $pl->ob->y); + = $ob->{_link_pos} + ? @{delete $ob->{_link_pos}} + : ($pl->maplevel, $ob->x, $ob->y); - $pl->ob->enter_link; + $ob->enter_link; if (my $time = delete $pl->{unclean_save}) { if (my $m = cf::map::find $map) { if ($time < $m->{instantiate_time}) { # the map was reset in the meantime my $age = $cf::RUNTIME - $time; - warn $pl->ob->name, " map reset after logout, logout age $age\n";#d# + + warn $ob->name, " map reset after logout, logout age $age (>= $MAX_DISCONNECT_TIME)\n";#d# # for now, just go back to savebed ($map, $x, $y) = $pl->savebed; - $pl->ns->send_drawinfo ( - "You didn't use a bed to reality to leave this realm, leaving your body in great danger. " - . "Fortunately, some friendly dwellers found you, checked your passport, and brought you to safety. " - . "Better use a savebed next time, much worse things could have happened...", - cf::NDI_RED - ); + if ($age >= $MAX_DISCONNECT_TIME) { + $ob->message ( + "You didn't use a bed to reality to leave this realm, leaving your body in great danger. " + . "Unfortunately, nobody was near to help you when the monsters arrived to eat you. " + . "Maybe you can find comfort in the thought that your body was quite satisfying in taste... " + . "H", + cf::NDI_RED + ); + # kill them. + # reminds me of the famous badness 10000 syndrome... + $ob->stats->hp (-10000); #] if they survive this they deserved to live + $pl->killer ("a cave-in"); + } else { + $ob->message ( + "You didn't use a bed to reality to leave this realm, leaving your body in great danger. " + . "Fortunately, some friendly dwellers found you, checked your passport, and brought you to safety. " + . "Better use a savebed next time, much worse things could have happened... " + . "H", + cf::NDI_RED + ); + } } else { - $pl->ns->send_drawinfo ( + $ob->message ( "You didn't use a bed to reality to leave this realm. This is very dangerous, " . "as lots of things could happen when you leave by other means, such as cave-ins, " - . "or monsters suddenly snapping your body. Better use a savebed next time.", + . "or monsters suddenly snapping your body. Better use a savebed next time. " + . "H", cf::NDI_RED ); } } } - $pl->ob->goto ($map, $x, $y); + $ob->goto ($map, $x, $y); } # delete a player directory, be non-blocking AND synchronous... @@ -106,144 +124,12 @@ . "&& (rm -rf ~\Q$Coro::current\E~deleting~ &)"; } -sub send_capabilities { - my ($ns) = @_; - - return unless $ns->extcmd; - - $ns->ext_event (capabilities => - # id, name, flags (1 == 2d), edge length - tileset => [[1, "default 64x64 faceset", 1, 64], [0, "default 32x32 faceset", 1, 32]], - ); -} - -sub setup { - my ($ns, $args) = @_; - - # run through the cmds of setup - # syntax is setup ... - # - # we send the status of the cmd back, or a FALSE is the cmd is the server unknown - # The client then must sort this out - - my %setup = split / +/, $args; - while (my ($k, $v) = each %setup) { - if ($k eq "sound") { - $ns->sound ($v); - - } elsif ($k eq "exp64") { - $setup{$k} = 1; - - } elsif ($k eq "spellmon") { - $ns->monitor_spells ($v); - - } elsif ($k eq "darkness") { - $ns->darkness ($v); - - } elsif ($k eq "map1cmd") { - $ns->mapmode (cf::Map1Cmd) if $v > 0; - - } elsif ($k eq "map1acmd") { - $ns->mapmode (cf::Map1aCmd) if $v > 0; - - } elsif ($k eq "map2cmd") { - # gcfclient bug, map1acmd is sent too late - $ns->mapmode (cf::Map1aCmd); - $setup{$k} = "FALSE"; - - } elsif ($k eq "newmapcmd") { - $ns->newmapcmd ($v); - - } elsif ($k eq "mapinfocmd") { - $ns->mapinfocmd ($v); - - } elsif ($k eq "extcmd") { - $ns->extcmd ($v > 0); - send_capabilities $ns; - - } elsif ($k eq "extmap") { - $ns->extmap ($v); - - } elsif ($k eq "facecache") { - if (!$v) { - $v = 1; - $setup{$k} = $v; - $ns->send_drawinfo ("(trying to forcefully enable facecaching)", cf::NDI_RED); - } - - $ns->facecache ($v); - - } elsif ($k eq "faceset") { - $ns->faceset (0); - $setup{$k} = 0; - # $ns->image2 (1) - - } elsif ($k eq "tileset") { - $setup{$k} = $ns->faceset ($v & 1); - - } elsif ($k eq "itemcmd") { - # Version of the item protocol command to use. Currently, - # only supported versions are 1 and 2. Using a numeric - # value will make it very easy to extend this in the future. - $ns->itemcmd ($v) if $v >= 1 && $v <= 2; - - $setup{$k} = $ns->itemcmd; - - } elsif ($k eq "mapsize") { - my ($x, $y) = split /x/, $v; - - $ns->mapx ($x = max 9, min cf::MAP_CLIENT_X, ($x - 1) | 1); - $ns->mapy ($y = max 9, min cf::MAP_CLIENT_Y, ($y - 1) | 1); - - $setup{$k} = "${x}x${y}"; - - } elsif ($k eq "extendedMapInfos") { - $ns->ext_mapinfos ($v); - - } elsif ($k eq "extendedTextInfos") { - $ns->has_readable_type ($v); - - } elsif ($k eq "smoothing") { # cfplus-style smoothing - $ns->smoothing ($v); - - } elsif ($k eq "fxix") { - $ns->fxix ($v); - - } elsif ($k eq "msg") { - $ns->can_msg ($v >= 2); - $setup{$k} = $ns->can_msg; - - } elsif ($k eq "xwidget") { - # eXperimental server-side widgets - $ns->{can_widget} = 1; - - } elsif ($k eq "excmd") { - # we support it - - } else { - # other commands: - # sexp: no idea, probably for oudated servers - # tick: more stupidity, server should send a tick per tick - - $setup{$k} = "FALSE"; - } - } - - $ns->send_packet (join " ", setup => %setup); - - cf::datalog setup => - request => $args, - reply => \%setup, - client => $ns->version, - ; -} - -sub addme { +cf::client->attach (on_addme => sub { my ($ns) = @_; - if (!$ns->facecache) - { - $ns->send_drawinfo (<facecache) + { + $ns->send_drawinfo (<roll_stats; } + + Coro::Timer::sleep 0.2; } $ob->set_animation (2); $ob->add_statbonus; while () { - $ns->send_msg (-1, "chargen-race-title", ucfirst $pl->title); + $ns->send_msg ("chargen-race-title", ucfirst $pl->title, -1); my $msg = $ob->msg; $msg =~ s/(?<=\S)\n(?=\S)/ /g; - $ns->send_msg (cf::NDI_BLUE, "chargen-race-description", $msg); + $ns->send_msg ("chargen-race-description", $msg, cf::NDI_BLUE); my $res = query $ns, cf::CS_QUERY_SINGLECHAR, "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n"; @@ -479,6 +370,7 @@ last if $res =~ /[dD]/; $pl->chargen_race_next; + Coro::Timer::sleep 0.2; } $pl->chargen_race_done; @@ -494,6 +386,7 @@ $pl->gender (0); last; } + Coro::Timer::sleep 0.2; } $ob->reply (undef, "Welcome to Crossfire!"); @@ -503,7 +396,7 @@ last; } }); -} +}); cf::register_command quit => sub { my ($ob, $arg) = @_; @@ -584,11 +477,6 @@ }, ); -cf::client->attach ( - on_addme => \&addme, - on_setup => \&setup, -); - ############################################################################# our $SCHEDULE_INTERVAL = 10; # time the player scheduler sleeps between runs