--- deliantra/server/ext/chat.ext 2007/03/02 00:29:08 1.12 +++ deliantra/server/ext/chat.ext 2007/06/28 08:34:42 1.20 @@ -1,4 +1,4 @@ -#! perl +#! perl # depends=irc #CONVERSION: PARTIAL # implement a replacement for the built-in say/chat/shout/tell/reply commands @@ -24,6 +24,16 @@ } } +# send_irc ($format, @args, $msg) +# make sure the last argument is the message! +sub send_irc { + my ($format, @args) = @_; + my $msg = pop @args; + for (split /\n/, $msg) { + ext::irc::do_notice (sprintf $format, @args, $_) + } +} + cf::player->attach ( prio => -1000, on_login => sub { @@ -38,6 +48,8 @@ my $player = cf::player::find_active $pl->name; if ($msg ne "") { + $msg = 10 if $msg > 10; + my $prev_listen = $player->listening; $player->listening ($msg); if ($prev_listen == $player->listening) { @@ -764,14 +776,12 @@ if ($msg) { my $name = $pl->name; - utf8::encode $msg; # ->message not yet utf8-ified $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE) for grep $pl->on_same_map_as ($_->ob), cf::player::list; - utf8::decode $msg; # npcs, magic_ears etc. - # first find all objects and theirt-level inventories - # within a 5x5 square # that have something resembling + # first find all objects and their first-level inventories + # within a 5x5 square that have something resembling # dialogue or support on_say. my ($map, $x, $y) = ($pl->map, $pl->x - 2, $pl->y - 2); @@ -785,7 +795,7 @@ # if some listener teleported us somewhere else, stop right here last unless $map->path == $pl->map->path; - my $dialog = new NPC_Dialogue ob => $pl, npc => $npc; + my $dialog = new NPC_Dialogue pl => $pl->contr, npc => $npc; my ($reply, @kw) = $dialog->tell ($msg); if (defined $reply) { @@ -825,9 +835,8 @@ my $name = $pl->name; my $NOW = time; - utf8::encode $msg; # ->message not yet utf8-ified cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; - ext::schmorp_irc::do_notice (sprintf "[%s] %s", $name, $msg); + send_irc ("[%s] %s", $name, $msg); $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; @@ -849,9 +858,8 @@ my $name = $pl->name; cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; - ext::schmorp_irc::do_notice (sprintf "\007\0034{%s} %s\n", $name, $msg); + send_irc ("\007\0034{%s} %s\n", $name, $msg); - utf8::encode $msg; # ->message not yet utf8-ified $_->ob->message ("$name shouts: $msg", cf::NDI_RED) for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; @@ -873,7 +881,7 @@ if ($target =~ /irc\//) { my (undef, $nick) = split /\//, $target, 2; $pl->message ("You tell $target: $args"); - ext::schmorp_irc::do_notice (sprintf "(%s) %s: %s\n", $name, $nick, $msg); + send_irc ("(%s) %s: %s\n", $name, $nick, $msg); } elsif (my $other = cf::player::find_active $target) { if ($msg) { @@ -883,7 +891,6 @@ $pl->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE); } else { return if $other->invoke (cf::EVENT_PLAYER_TOLD, $pl->contr, $msg); - utf8::encode $msg; # ->message not yet utf8-ified cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg; $pl->message ("You tell $target: $msg"); @@ -910,7 +917,7 @@ if ($pl->{ext_last_tell} =~ /irc\//) { my (undef, $nick) = split /\//, $pl->{ext_last_tell}, 2; $pl->message ("You tell " . $pl->{ext_last_tell} . ": $args"); - ext::schmorp_irc::do_notice (sprintf "(%s) %s: %s\n", $name, $nick, $args); + send_irc ("(%s) %s: %s\n", $name, $nick, $args); } elsif (my $other = cf::player::find_active $pl->{ext_last_tell}) { if ($args) { @@ -918,7 +925,6 @@ or delete $other->ob->{ext_ignore_tell}{$name}; if ($other->ob->{ext_ignore_tell}{$name} < time) { - utf8::encode $args; # ->message not yet utf8-ified cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $other->ob->name, $args; $pl->message ("You tell " . $other->ob->name . ": $args"); @@ -1019,26 +1025,3 @@ } }; -cf::register_command seen => sub { - my ($pl, $args) = @_; - - if (my ($login) = $args =~ /(\S+)/) { - if ($login eq $pl->name) { - $pl->message ("Very funny, $login. Ha. Ha.", cf::NDI_UNIQUE); - } elsif (cf::player::find_active $login) { - $pl->message ("$login is right here on this server!", cf::NDI_UNIQUE); - } elsif (cf::player::exists $login - and stat sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($login) x 2) { - my $time = (stat _)[9]; - - $pl->message ("$login was last seen here " - . (POSIX::strftime "%Y-%m-%d %H:%M:%S +0000", gmtime $time) - . " which was " . (int +(time - $time) / 3600) . " hours ago.", cf::NDI_UNIQUE); - } else { - $pl->message ("No player named $login is known to me.", cf::NDI_UNIQUE); - } - } else { - $pl->message ("Usage: seen ", cf::NDI_UNIQUE); - } -}; -