--- deliantra/server/ext/chat.ext 2007/07/23 21:17:14 1.25 +++ deliantra/server/ext/chat.ext 2007/09/19 21:56:30 1.33 @@ -1,5 +1,4 @@ -#! perl # depends=irc -#CONVERSION: PARTIAL +#! perl # depends=irc mandatory # implement a replacement for the built-in say/chat/shout/tell/reply commands # adds ignore/unignore functionality @@ -21,6 +20,17 @@ tooltip => "Player chat and shouts, global to the server.", }; +sub tell_channel($) { + my ($target) = @_; + + { + id => "tell-$target", + title => "$target", + reply => "tell $target ", + tooltip => "Private messages from/to $target", + } +} + sub clean_timeouts($) { my ($player) = @_; my $NOW = time; @@ -28,10 +38,10 @@ for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) { while (my ($k, $v) = each %$hash) { if ($v < $NOW) { - $player->message ("Your ignore on $k has expired.", cf::NDI_GREEN | cf::NDI_UNIQUE); + $player->message ("Your ignore on $k has expired.", cf::NDI_GREEN); delete $hash->{$k}; } elsif (!cf::player::exists $k) { - $player->message ("Your ignore on $k is no longer valid (no such user).", cf::NDI_GREEN | cf::NDI_UNIQUE); + $player->message ("Your ignore on $k is no longer valid (no such user).", cf::NDI_GREEN); delete $hash->{$k}; } } @@ -54,8 +64,9 @@ my ($pl) = @_; clean_timeouts $pl->ob; - $pl->ns->send_msg ($SAY_CHANNEL); - $pl->ns->send_msg ($CHAT_CHANNEL); + + $pl->send_msg ($SAY_CHANNEL); + $pl->send_msg ($CHAT_CHANNEL); }, ); @@ -69,46 +80,43 @@ my $prev_listen = $player->listening; $player->listening ($msg); if ($prev_listen == $player->listening) { - $pl->message ("Your verbose level stays at $prev_listen.", cf::NDI_UNIQUE); + $pl->message ("Your verbose level stays at $prev_listen.", cf::NDI_REPLY); } else { - $pl->message ("Your verbose level is now " . $player->listening . ". (previously: $prev_listen)", cf::NDI_UNIQUE); + $pl->message ("Your verbose level is now " . $player->listening . ". (previously: $prev_listen)", cf::NDI_REPLY); } } else { - $pl->message ("Your verbose level is " . $player->listening . ".", cf::NDI_UNIQUE); + $pl->message ("Your verbose level is " . $player->listening . ".", cf::NDI_REPLY); } }; cf::register_command cointoss => sub { - my ($pl, $msg) = @_; + my ($ob, $msg) = @_; + + my $pl = $ob->contr; + my $name = $ob->name; - my $name = $pl->name; my $coin = int rand 2 ? "Heads" : "Tails"; - for my $other ( grep { $pl->on_same_map_as ($_->ob) } cf::player::list ) { - next - if $other->ob == $pl; - $other->ob->message ("$name flips a coin.... $coin!", cf::NDI_GREY | cf::NDI_UNIQUE); - } + $_->send_msg ($SAY_CHANNEL => "$name flips a coin.... $coin!", cf::NDI_GREY) + for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl} cf::player::list; - $pl->message ("You flip a coin.... $coin!", cf::NDI_GREY | cf::NDI_UNIQUE); + $pl->send_msg ($SAY_CHANNEL => "You flip a coin.... $coin!", cf::NDI_GREY | cf::NDI_REPLY); }; cf::register_command orcknuckle => sub { - my ($pl, $msg) = @_; - my @orcknuckle = ("none", "beholder", "ghost", "knight", "princess", "dragon", "orc"); + my ($ob, $msg) = @_; - my $name = $pl->name; + my $pl = $ob->contr; + my $name = $ob->name; - my ($i, $j, $k, $l) = ((int rand 5) + 1, (int rand 5) + 1, (int rand 5) + 1, (int rand 6) + 1); + my @orcknuckle = ("beholder", "ghost", "knight", "princess", "dragon", "orc"); + my ($i, $j, $k, $l) = (rand 5, rand 5, rand 5, rand 6); my $result = "$orcknuckle[$i], $orcknuckle[$j], $orcknuckle[$k], $orcknuckle[$l]"; - for my $other ( grep { $pl->on_same_map_as ($_->ob) } cf::player::list ) { - next - if $other->ob == $pl; - $other->ob->message ("$name rolls $result!", cf::NDI_GREY | cf::NDI_UNIQUE); - } - - $pl->message ("You roll $result!", cf::NDI_GREY | cf::NDI_UNIQUE); + $_->send_msg ($SAY_CHANNEL => "$name throws his orc-knuckles and rolls $result!", cf::NDI_GREY) + for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl} cf::player::list; + + $pl->send_msg ($SAY_CHANNEL => "You roll $result!", cf::NDI_GREY | cf::NDI_REPLY); }; my $emotes = { @@ -695,70 +703,58 @@ for my $emotion (keys %$emotes) { cf::register_command $emotion => sub { - my ($pl, $tname) = @_; + my ($ob, $tname) = @_; + + my $pl = $ob->contr; cf::async { - my $name = $pl->name; + my $name = $ob->name; + $Coro::current->{desc} = "emote handler for $name"; if ($tname eq $name) { - my $emote = $emotes->{$emotion}->{self}; + my %emote = %{ $emotes->{$emotion}->{self} || {} }; - $emote->{other} = "You look away from ." - if !$emote->{other}; - $emote->{self} = "My god! Is that LEGAL?" - if !$emote->{self}; + $emote{other} ||= "You look away from ."; + $emote{self} ||= "My god! Is that LEGAL?"; - $emote->{other} =~ s//$name/; + $emote{other} =~ s//$name/; - for my $other ( grep { $pl->on_same_map_as ($_->ob) } cf::player::list ) { - next - if $other->ob == $pl; - $other->ob->message ($emote->{other}, cf::NDI_GREY | cf::NDI_UNIQUE); - } + $_->send_msg ($CHAT_CHANNEL, $emote{other}, cf::NDI_GREY) + for grep { $ob->on_same_map_as ($_->ob) && $_ != $ob} cf::player::list; - $pl->message ($emote->{self}, cf::NDI_GREY | cf::NDI_UNIQUE); + $pl->send_msg ($emote{self}, cf::NDI_GREY | cf::NDI_REPLY); } elsif ($tname) { my $target = cf::player::find $tname - or return $pl->reply (undef, "$tname is not around."); + or return $pl->send_msg (tell_channel $tname, "$tname is not around.", cf::NDI_DK_ORANGE | cf::NDI_REPLY); - my $emote = $emotes->{$emotion}->{params}; + my %emote = %{ $emotes->{$emotion}->{params} || {} }; - $emote->{other} = " is eyeing quizzically." - if !$emote->{other}; - $emote->{self} = "You are still nuts." - if !$emote->{self}; - $emote->{target} = "You get the distinct feeling that is nuts." - if !$emote->{target}; - - $emote->{self} =~ s//$tname/; - $emote->{target} =~ s//$name/; - $emote->{other} =~ s//$tname/; - $emote->{other} =~ s//$name/; + $emote{other} ||= " is eyeing quizzically."; + $emote{self} ||= "You are still nuts."; + $emote{target} ||= "You get the distinct feeling that is nuts."; + + $emote{self} =~ s//$tname/; + $emote{target} =~ s//$name/; + $emote{other} =~ s//$tname/; + $emote{other} =~ s//$name/; - for my $other ( grep { $pl->on_same_map_as ($_->ob) } cf::player::list ) { - next - if $other->ob == $pl or $other == $target; - $other->ob->message ($emote->{other}, cf::NDI_GREY | cf::NDI_UNIQUE); - } + $_->send_msg ($CHAT_CHANNEL, $emote{other}, cf::NDI_GREY) + for grep { $_ != $pl && $_ != $target && $ob->on_same_map_as ($_->ob) } cf::player::list; - $target->ob->message ($emote->{target}, cf::NDI_GREY | cf::NDI_UNIQUE); - $pl->message ($emote->{self}, cf::NDI_GREY | cf::NDI_UNIQUE); + $target->send_msg (tell_channel $name, $emote{target}, cf::NDI_GREY); + $pl->send_msg (tell_channel $tname, $emote{self}, cf::NDI_GREY | cf::NDI_REPLY); } else { - my $emote = $emotes->{$emotion}->{noparams}; - $emote->{other} =~ s//$name/; + my %emote = %{ $emotes->{$emotion}->{noparams} || {} }; - $emote->{other} = " dances with glee." - if !$emote->{other}; - $emote->{self} = "You are a nut." - if !$emote->{self}; + $emote{other} ||= " dances with glee."; + $emote{self} ||= "You are a nut."; - for my $other ( grep { $pl->on_same_map_as ($_->ob) } cf::player::list ) { - next - if $other->ob == $pl; - $other->ob->message ($emote->{other}, cf::NDI_GREY | cf::NDI_UNIQUE); - } + $emote{other} =~ s//$name/; + + $_->send_msg ($CHAT_CHANNEL, $emote{other}, cf::NDI_GREY) + for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl } cf::player::list; - $pl->message ($emote->{self}, cf::NDI_GREY | cf::NDI_UNIQUE); + $pl->send_msg ($CHAT_CHANNEL, $emote{self}, cf::NDI_GREY | cf::NDI_REPLY); } }; }; @@ -769,7 +765,7 @@ my $name = $pl->name; - $_->ns->send_msg ($SAY_CHANNEL => "* $name $msg", cf::NDI_GREY, $_ == $pl ? (reply => 1) : ()) + $_->send_msg ($SAY_CHANNEL => "* $name $msg", cf::NDI_GREY | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0)) for grep $pl->on_same_map_as ($_->ob), cf::player::list; }; @@ -784,7 +780,7 @@ my $name = $ob->name; my @plonmap = grep $ob->on_same_map_as ($_->ob), cf::player::list; - $_->ns->send_msg ($SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY, $_ == $ob ? (reply => 1) : ()) + $_->send_msg ($SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY | ($_ == $ob->contr ? cf::NDI_REPLY : 0)) for @plonmap; # npcs, magic_ears etc. @@ -809,70 +805,74 @@ if (defined $reply) { if ($npc->type == cf::MAGIC_EAR) { if (length $reply) { - $_->ns->send_msg ($SAY_CHANNEL => $reply, cf::NDI_BROWN) + $_->send_msg ($SAY_CHANNEL => $reply, cf::NDI_BROWN) for @plonmap; } $npc->use_trigger; } else { if (length $reply) { - $_->ns->send_msg ($SAY_CHANNEL => $npc->name . " says: $reply", cf::NDI_BROWN) + $_->send_msg ($SAY_CHANNEL => $npc->name . " says: $reply", cf::NDI_BROWN) for @plonmap; } } } if (@kw) { - $_->ns->send_msg ($SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN) + $_->send_msg ($SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN) for @plonmap; } } } else { - $ob->contr->send_msg ($SAY_CHANNEL => "What do you want to say?", 0, reply => 1); + $ob->send_msg ($SAY_CHANNEL => "What do you want to say?", cf::NDI_GREY | cf::NDI_REPLY); } }; cf::register_command chat => sub { - my ($pl, $msg) = @_; + my ($ob, $msg) = @_; utf8::decode $msg; - return if $pl->contr->invoke (cf::EVENT_PLAYER_CHAT, $msg); + my $pl = $ob->contr; + + return if $pl->invoke (cf::EVENT_PLAYER_CHAT, $msg); if ($msg) { - my $name = $pl->name; + my $name = $ob->name; my $NOW = time; cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; send_irc ("[%s] %s", $name, $msg); - $_->ns->send_msg ($CHAT_CHANNEL => "$name chats: $msg", cf::NDI_BLUE, $_ == $pl ? (reply => 1) : ()) + $_->send_msg ($CHAT_CHANNEL => "$name chats: $msg", cf::NDI_BLUE | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0)) for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; } else { - $pl->ns->send_msg ($CHAT_CHANNEL => "Chat what?"); + $pl->send_msg ($CHAT_CHANNEL => "Chat what?", cf::NDI_BLUE | cf::NDI_DEF | cf::NDI_REPLY); } }; cf::register_command shout => sub { - my ($pl, $msg) = @_; + my ($ob, $msg) = @_; utf8::decode $msg; - return if $pl->contr->invoke (cf::EVENT_PLAYER_SHOUT, $msg); + my $pl = $ob->contr; + + return if $pl->invoke (cf::EVENT_PLAYER_SHOUT, $msg); if ($msg) { my $NOW = time; - my $name = $pl->name; + my $name = $ob->name; cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; send_irc ("\007\0034{%s} %s\n", $name, $msg); - $_->ns->send_msg ($CHAT_CHANNEL => "$name shouts: $msg", cf::NDI_RED, $_ == $pl ? (reply => 1) : ()) + $_->send_msg ($CHAT_CHANNEL => "$name shouts: $msg", cf::NDI_RED | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0)) for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; } else { - $pl->ns->send_msg ($CHAT_CHANNEL => "Shout what?"); + $pl->send_msg ($CHAT_CHANNEL => "Shout what?", cf::NDI_RED | cf::NDI_DEF | cf::NDI_REPLY); } }; @@ -889,43 +889,34 @@ return if $pl->invoke (cf::EVENT_PLAYER_TELL, $target, $msg); - my $pl_channel = { - id => "tell-$target", - title => "$target", - reply => "tell $target ", - tooltip => "Private messages from/to $target", - }; + my $pl_channel = tell_channel $target; if ($target =~ /irc\//) { my (undef, $nick) = split /\//, $target, 2; - $ns->send_msg ($pl_channel => "You tell $target: $args", reply => 1); + $ns->send_msg ($pl_channel => "You tell $target: $args", cf::NDI_DK_ORANGE | cf::NDI_DEF | cf::NDI_REPLY); send_irc ("(%s) %s: %s\n", $name, $nick, $msg); + } elsif (my $other = cf::player::find_active $target) { - my $other_channel = { - id => "tell-$name", - title => "$name", - reply => "tell $name ", - tooltip => "Private messages from/to $name", - }; + my $other_channel = tell_channel $name; if ($msg) { if ($target eq $name) { - $ns->send_msg ($pl_channel => "You are talking to yourself, you freak!", reply => 1); + $ns->send_msg ($pl_channel => "You are talking to yourself, you freak!", cf::NDI_DK_ORANGE | cf::NDI_DEF | cf::NDI_REPLY); } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { - $ns->send_msg ($pl_channel => "$target ignores what you say. Give up on it.", reply => 1); + $ns->send_msg ($pl_channel => "$target ignores what you say. Give up on it.", cf::NDI_DK_ORANGE | cf::NDI_DEF | cf::NDI_REPLY); } else { return if $other->invoke (cf::EVENT_PLAYER_TOLD, $pl, $msg); cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg; - $ns->send_msg ($pl_channel => "You tell $target: $msg", reply => 1); - $other->ns->send_msg ($other_channel => "$name tells you: $msg"); + $ns->send_msg ($pl_channel => "You tell $target: $msg", cf::NDI_DK_ORANGE | cf::NDI_DEF | cf::NDI_REPLY); + $other->send_msg ($other_channel => "$name tells you: $msg", cf::NDI_DK_ORANGE | cf::NDI_DEF); } } else { - $ns->send_msg ($pl_channel => "What do you want to tell $target?"); + $ns->send_msg ($pl_channel => "What do you want to tell $target?", cf::NDI_DK_ORANGE | cf::NDI_DEF | cf::NDI_REPLY); } } else { - $ns->send_msg ($pl_channel => "No such player. Your message: $msg"); + $ns->send_msg ($pl_channel => "No such player. Your message: $msg", cf::NDI_DK_ORANGE | cf::NDI_DEF | cf::NDI_REPLY); } }; @@ -938,13 +929,13 @@ if ((my @ignored_tell = sort keys %{$pl->{ext_ignore_tell}}) + (my @ignored_shout = sort keys %{$pl->{ext_ignore_shout}})) { - $pl->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE); - $pl->message ((join ", ", @ignored_tell), cf::NDI_UNIQUE); - $pl->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE); - $pl->message ((join ", ", @ignored_shout), cf::NDI_UNIQUE); - $pl->message ("To stop ignoring one, use unignore.", cf::NDI_UNIQUE); + $pl->message ("Currently ignoring private messages from: ", cf::NDI_REPLY); + $pl->message ((join ", ", @ignored_tell), cf::NDI_REPLY); + $pl->message ("Currently ignoring shouts from: ", cf::NDI_REPLY); + $pl->message ((join ", ", @ignored_shout), cf::NDI_REPLY); + $pl->message ("To stop ignoring one, use unignore.", cf::NDI_REPLY); } else { - $pl->message ("Not ignoring anyone", cf::NDI_UNIQUE); + $pl->message ("Not ignoring anyone", cf::NDI_REPLY); } } elsif ($target && $type) { @@ -954,27 +945,27 @@ if (cf::player::exists $target) { if ($type eq "tell") { - $pl->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_UNIQUE); + $pl->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_REPLY); $pl->{ext_ignore_tell}{$target} = $absolute_timeout; } elsif ($type eq "shout") { - $pl->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_UNIQUE); + $pl->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_REPLY); $pl->{ext_ignore_shout}{$target} = $absolute_timeout; } elsif ($type eq "all") { - $pl->message ("Now ignoring everything from $target for $timeout hours.", cf::NDI_UNIQUE); + $pl->message ("Now ignoring everything from $target for $timeout hours.", cf::NDI_REPLY); $pl->{ext_ignore_tell}{$target} = $absolute_timeout; $pl->{ext_ignore_shout}{$target} = $absolute_timeout; } else { - $pl->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE); + $pl->message ("You need to specify tell, shout or all.", cf::NDI_REPLY); } } else { - $pl->message ("No such player: $target", cf::NDI_UNIQUE); + $pl->message ("No such player: $target", cf::NDI_REPLY); } } else { $pl->message ("Usage: ignore \n" . "will ignore a player for hours.\n" . "Usage: ignore list\n" - . "will show you a list of players currently ignored.", cf::NDI_UNIQUE); + . "will show you a list of players currently ignored.", cf::NDI_REPLY); } }; @@ -984,30 +975,30 @@ if ($args eq "") { if ($pl->{ext_ignore_tell}) { - $pl->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE); - $pl->message ((join ", ", sort keys %{ $pl->{ext_ignore_tell} }), cf::NDI_UNIQUE); - $pl->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE); - $pl->message ((join ", ", sort keys %{ $pl->{ext_ignore_shout} }), cf::NDI_UNIQUE); + $pl->message ("Currently ignoring private messages from: ", cf::NDI_REPLY); + $pl->message ((join ", ", sort keys %{ $pl->{ext_ignore_tell} }), cf::NDI_REPLY); + $pl->message ("Currently ignoring shouts from: ", cf::NDI_REPLY); + $pl->message ((join ", ", sort keys %{ $pl->{ext_ignore_shout} }), cf::NDI_REPLY); } else { - $pl->message ("Not ignoring anyone", cf::NDI_UNIQUE); + $pl->message ("Not ignoring anyone", cf::NDI_REPLY); } } else { if (cf::player::exists $target) { if ($type eq "tell") { - $pl->message ("Not ignoring private messages from $target anymore.", cf::NDI_UNIQUE); + $pl->message ("Not ignoring private messages from $target anymore.", cf::NDI_REPLY); delete $pl->{ext_ignore_tell} {$target}; } elsif ($type eq "shout") { - $pl->message ("Not ignoring shouts from $target anymore.", cf::NDI_UNIQUE); + $pl->message ("Not ignoring shouts from $target anymore.", cf::NDI_REPLY); delete $pl->{ext_ignore_shout}{$target}; } elsif ($type eq "all") { - $pl->message ("Not ignoring anything from $target anymore.", cf::NDI_UNIQUE); + $pl->message ("Not ignoring anything from $target anymore.", cf::NDI_REPLY); delete $pl->{ext_ignore_tell} {$target}; delete $pl->{ext_ignore_shout}{$target}; } else { - $pl->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE); + $pl->message ("You need to specify tell, shout or all.", cf::NDI_REPLY); } } else { - $pl->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE); + $pl->message ("No such player or ambiguous name: $target", cf::NDI_REPLY); } } };