--- deliantra/server/ext/chat.ext 2007/04/24 18:24:31 1.14 +++ deliantra/server/ext/chat.ext 2010/09/05 05:01:39 1.56 @@ -1,12 +1,29 @@ -#! perl -#CONVERSION: PARTIAL +#! perl # depends=irc mandatory -# implement a replacement for the built-in say/chat/shout/tell/reply commands +# implement a replacement for the built-in say/chat/shout/tell commands # adds ignore/unignore functionality use NPC_Dialogue; use POSIX (); # for strftime only +sub tell_channel($) { + my ($target) = @_; + + { + id => "tell-$target", + title => "$target", + reply => "tell $target ", + tooltip => "Private messages from/to $target", + } +} + +sub send_msg($$$$$) { + my ($pl, $channel, $msg, $flags, $sound) = @_; + $pl->play_sound (cf::sound::find $sound) if defined $sound; + $pl->send_msg ($channel, $msg, $flags); + () +} + sub clean_timeouts($) { my ($player) = @_; my $NOW = time; @@ -14,84 +31,72 @@ 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}; } } } } +# 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 { my ($pl) = @_; - clean_timeouts $pl->ob; + cf::async { + clean_timeouts $pl->ob; + }; + + $pl->send_msg ($cf::SAY_CHANNEL); + $pl->send_msg ($cf::CHAT_CHANNEL); }, ); +# TODO: remove once safe cf::register_command listen => sub { - my ($pl, $msg) = @_; - 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) { - $pl->message ("Your verbose level stayed $prev_listen.", cf::NDI_UNIQUE); - } else { - $pl->message ("Your verbose level is now " . $player->listening . ". (previously: $prev_listen)", cf::NDI_UNIQUE); - } - } else { - $pl->message ("Your verbose level is " . $player->listening . ".", cf::NDI_UNIQUE); - } }; cf::register_command cointoss => sub { - my ($pl, $msg) = @_; + my ($ob, $msg) = @_; - my $name = $pl->name; + my $pl = $ob->contr; + my $name = $ob->name; - if (int rand 2) { - 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.... Heads!", cf::NDI_GREY | cf::NDI_UNIQUE); - } - - $pl->message ("You flip a coin.... Heads!", cf::NDI_GREY | cf::NDI_UNIQUE); - } else { - 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.... Tails!", cf::NDI_GREY | cf::NDI_UNIQUE); - } - - $pl->message ("You flip a coin.... Tails!", cf::NDI_GREY | cf::NDI_UNIQUE); - } + my $coin = (cf::rndm 2) ? "Heads" : "Tails"; + + send_msg $_, $cf::SAY_CHANNEL => "$name flips a coin.... $coin!", cf::NDI_GREY, "msg_say" + for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl} cf::player::list; + + $pl->send_msg ($cf::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) = map +(cf::rndm $_), 5, 5, 5, 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 $_, $cf::SAY_CHANNEL => "$name throws his orc-knuckles and rolls $result!", cf::NDI_GREY, "msg_say" + for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl} cf::player::list; + + $pl->send_msg ($cf::SAY_CHANNEL => "You roll $result!", cf::NDI_GREY | cf::NDI_REPLY); }; my $emotes = { @@ -147,7 +152,7 @@ }, scream => { noparams => { - other => " screams at the top of his lungs!", + other => " screams at the top of G lungs!", self => "ARRRRRRRRRRGH!!!!!", }, params => { @@ -166,7 +171,7 @@ self => "You puke on .", }, self => { - other => " pukes on his clothes.", + other => " pukes on G clothes.", self => "You puke on yourself.", }, }, @@ -215,7 +220,7 @@ kiss => { noparams => { other => " makes a weird facial contortion", - self => "All the lonely people..", + self => "All the lonely people...", }, params => { target => " kisses you.", @@ -225,6 +230,34 @@ self => { }, }, + hug => { + noparams => { + other => " makes weird body movements.", + self => "All the lonely people...", + }, + params => { + target => " suddenly grabs you and gives you a bear hug.", + other => " hugs .", + self => "You hug .", + }, + self => { + other => " tries to hug G, but stumbles and now feels stupid.", + self => "You try and fail to hug yourself.", + }, + }, + smother => { + noparams => { + other => " makes weird facial contortions", + self => "All the lonely people...", + }, + params => { + target => " smothers you with kisses.", + other => " smothers with kisses.", + self => "You smother with kisses.", + }, + self => { + }, + }, wink => { noparams => { other => " winks suggestively.", @@ -236,7 +269,7 @@ self => "You wink suggestively at .", }, self => { - other => " winks at himself - something strange is going on...", + other => " winks at Gself - something strange is going on...", self => "You wink at yourself?? What are you up to?", }, }, @@ -252,7 +285,7 @@ }, cackle => { noparams => { - other => " throws back his head and cackles with insane glee!", + other => " throws back G head and cackles with insane glee!", self => "You cackle gleefully.", }, params => { @@ -271,7 +304,7 @@ self => "You sniff .", }, self => { - other => " sniffs himself.", + other => " sniffs Gself.", self => "You sniff yourself.", }, }, @@ -281,9 +314,9 @@ self => "You nod solemnly.", }, params => { - target => " nods solemnly to you.", - other => " nods solemnly to .", - self => "You nod solemnly to .", + target => " nods solemnly at you.", + other => " nods solemnly at .", + self => "You nod solemnly at .", }, self => { }, @@ -299,7 +332,7 @@ self => "You frown darkly at .", }, self => { - other => " frowns at himself.", + other => " frowns at Gself.", self => "You frown at yourself.", }, }, @@ -332,18 +365,18 @@ self => "You bleed all over your nice new armour.", }, params => { - target => " slashes his wrist and bleeds all over you.", - other => " slashes his wrist and bleeds all over .", + target => " slashes G wrist and bleeds all over you.", + other => " slashes G wrist and bleeds all over .", self => "You slash your wrist and bleed all over ", }, self => { - other => " performs some satanic ritual while wiping his blood on himself.", + other => " performs some satanic ritual while wiping G blood on Gself.", self => "Very impressive! You wipe your blood all over yourself.", }, }, twiddle => { noparams => { - other => " patiently twiddles his thumbs.", + other => " patiently twiddles G thumbs.", self => "You patiently twiddle your thumbs.", }, params => { @@ -353,7 +386,7 @@ }, spit => { noparams => { - other => " spits over his left shoulder.", + other => " spits over G left shoulder.", self => "You spit over your left shoulder.", }, params => { @@ -362,13 +395,13 @@ self => "You spit on .", }, self => { - other => " drools all over himself.", + other => " drools all over Gself.", self => "You drool all over yourself.", }, }, glare => { noparams => { - other => " glares around him.", + other => " glares around G.", self => "You glare at nothing in particular.", }, params => { @@ -377,7 +410,7 @@ self => "You glare icily at .", }, self => { - other => " glares at his feet, what is bothering him?", + other => " glares at G feet, what is bothering G?", self => "You glare icily at your feet, they are suddenly very cold.", }, }, @@ -392,13 +425,13 @@ self => "You bow before .", }, self => { - other => " folds up like a jackknife and kisses his own toes.", + other => " folds up like a jackknife and kisses G own toes.", self => "You kiss your toes.", }, }, dance => { noparams => { - other => " expresses himself through interpretive dance.", + other => " expresses Gself through interpretive dance.", self => "You dance with glee.", }, params => { @@ -407,7 +440,7 @@ self => "You grab and begin doing the Cha-Cha!", }, self => { - other => " embraces himself and begins to dance!", + other => " embraces Gself and begins to dance!", self => "You skip and dance around by yourself.", }, }, @@ -433,7 +466,7 @@ }, snap => { noparams => { - other => " snaps his fingers.", + other => " snaps G fingers.", self => "PRONTO! you snap your fingers.", }, params => { @@ -452,7 +485,7 @@ self => "You wave goodbye to .", }, self => { - other => " waves goodbye to himself.", + other => " waves goodbye to Gself.", self => "Are you going on adventures as well??", }, }, @@ -476,11 +509,11 @@ }, params => { target => " sneezes on you, you feel the snot cover you. EEEEEEW.", - other => " sneezes on and a film of snot covers him.", - self => "You sneeze at and a film of snot shoots onto him.", + other => " sneezes on and a film of snot covers G.", + self => "You sneeze at and a film of snot shoots onto G.", }, self => { - other => " sneezes, and covers himself in a slimy substance.", + other => " sneezes, and covers Gself in a slimy substance.", self => "You sneeze on yourself, what a mess!", }, }, @@ -499,7 +532,7 @@ }, shake => { noparams => { - other => " shakes his head.", + other => " shakes G head.", self => "You shake your head.", }, params => { @@ -514,7 +547,7 @@ }, lick => { noparams => { - other => " licks his mouth and smiles.", + other => " licks G mouth and smiles.", self => "You lick your mouth and smile.", }, params => { @@ -523,7 +556,7 @@ self => "You lick .", }, self => { - other => " licks himself - YUCK.", + other => " licks Gself - YUCK.", self => "You lick yourself.", }, }, @@ -539,7 +572,7 @@ }, think => { noparams => { - other => " closes his eyes and thinks really hard.", + other => " closes G eyes and thinks really hard.", self => "Anything in particular that you'd care to think about?", }, params => { @@ -613,7 +646,7 @@ self => "You cry on 's shoulder.", }, self => { - other => " sobs quietly to himself.", + other => " sobs quietly to Gself.", self => "You cry to yourself.", }, }, @@ -637,7 +670,7 @@ self => "You whistle at .", }, self => { - other => " whistles to himself in boredom.", + other => " whistles to Gself in boredom.", self => "You whistle while you work.", }, }, @@ -678,263 +711,254 @@ 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/; + + $_ = $pl->expand_cfpod ($_) + for values %emote; - 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 $_, $cf::CHAT_CHANNEL, $emote{other}, cf::NDI_GREY | cf::NDI_VERBATIM, "msg_chat" + 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 | cf::NDI_VERBATIM); } elsif ($tname) { my $target = cf::player::find $tname - or return $pl->reply (undef, "$tname is not around."); + or return send_msg $pl, tell_channel $tname, "The player called $tname is not known to this poor server.", + cf::NDI_DK_ORANGE | cf::NDI_REPLY, "msg_chat"; + + $target->ob->active + or return send_msg $pl, tell_channel $tname, "$tname is not around. H<$tname must be logged in.>", + cf::NDI_DK_ORANGE | cf::NDI_REPLY, "msg_chat"; - 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); - } + $_ = $pl->expand_cfpod ($_) + for values %emote; - $target->ob->message ($emote->{target}, cf::NDI_GREY | cf::NDI_UNIQUE); - $pl->message ($emote->{self}, cf::NDI_GREY | cf::NDI_UNIQUE); + send_msg $_, $cf::CHAT_CHANNEL, $emote{other}, cf::NDI_GREY | cf::NDI_VERBATIM, "msg_chat" + for grep { $_ != $pl && $_ != $target && $ob->on_same_map_as ($_->ob) } cf::player::list; + + send_msg $target, tell_channel $name, $emote{target}, cf::NDI_GREY | cf::NDI_VERBATIM, "msg_shout"; + $pl->send_msg (tell_channel $tname, $emote{self}, cf::NDI_GREY | cf::NDI_REPLY | cf::NDI_VERBATIM); } 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/; + + $_ = $pl->expand_cfpod ($_) + for values %emote; + + send_msg $_, $cf::CHAT_CHANNEL, $emote{other}, cf::NDI_GREY | cf::NDI_VERBATIM, "msg_chat" + 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 ($cf::CHAT_CHANNEL, $emote{self}, cf::NDI_GREY | cf::NDI_REPLY | cf::NDI_VERBATIM); } }; }; } -cf::register_command me => sub { - my ($pl, $msg) = @_; - - my $name = $pl->name; - - $_->ob->message ("* $name $msg", cf::NDI_GREY | cf::NDI_UNIQUE) - for grep $pl->on_same_map_as ($_->ob), cf::player::list; -}; - cf::register_command say => sub { - my ($pl, $msg) = @_; + my ($ob, $msg) = @_; utf8::decode $msg; - return if $pl->contr->invoke (cf::EVENT_PLAYER_SAY, $msg); + return if $ob->contr->invoke (cf::EVENT_PLAYER_SAY, $msg); if ($msg) { - my $name = $pl->name; + my $name = $ob->name; + my @plonmap = grep $ob->on_same_map_as ($_->ob), cf::player::list; + + send_msg $_, $cf::SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY, "msg_say" + for grep $_ != $ob->contr, @plonmap; + $ob->contr->send_msg ($cf::SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY | cf::NDI_REPLY); - 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; + my @npc; # 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); + # we prefer the nearest items NOT in the player, otherwise in player. + my ($map, $x, $y) = ($ob->map, $ob->x, $ob->y); - for my $npc ( - grep +($_->invoke (cf::EVENT_OBJECT_SAY, $pl->contr, $msg) && return) || NPC_Dialogue::has_dialogue $_, - map +($_, $_->inv), - grep $_, - map $map->at ($x + $_ % 5, $y + (int $_ / 5)), - 0..24 + for my $dir ( + 0, + 1, 3, 5, 7, + 2, 4, 6, 8, + 9 .. cf::SIZEOFFREE2 ) { - # if some listener teleported us somewhere else, stop right here - last unless $map->path == $pl->map->path; + @npc = grep $_->should_invoke (cf::EVENT_OBJECT_SAY) || $_->has_dialogue, + map +($_, $_->inv), + grep $_ != $ob, + $map->at ($x, $y, $dir) + and last; + } - my $dialog = new NPC_Dialogue ob => $pl, npc => $npc; - my ($reply, @kw) = $dialog->tell ($msg); + unless (@npc) { + # nothing found, try the player inventory + @npc = grep $_->should_invoke (cf::EVENT_OBJECT_SAY) || $_->has_dialogue, + $ob->inv; + } - if (defined $reply) { - if ($npc->type == cf::MAGIC_EAR) { - if (length $reply) { - $_->ob->message ($reply, cf::NDI_BROWN | cf::NDI_UNIQUE) - for grep $pl->on_same_map_as ($_->ob), cf::player::list; - } - $npc->use_trigger; - } else { - if (length $reply) { - $_->ob->message ($npc->name . " says: $reply", cf::NDI_BROWN | cf::NDI_UNIQUE) - for grep $pl->on_same_map_as ($_->ob), cf::player::list; + for my $npc (@npc) { + return if $npc->invoke (cf::EVENT_OBJECT_SAY, $ob->contr, $msg); + + # if some listener teleported us somewhere else, stop right here + last unless $map->path == $ob->map->path; + + if ($npc->has_dialogue) { + my $dialog = new NPC_Dialogue pl => $ob->contr, npc => $npc; + my ($reply, @kw) = $dialog->tell ($msg); + + if (defined $reply) { + if ($npc->type == cf::MAGIC_EAR) { + send_msg $_, $cf::SAY_CHANNEL => $reply, cf::NDI_BROWN, "msg_say" + for @plonmap; + } else { + send_msg $_, $cf::SAY_CHANNEL => $npc->name . " says: $reply", cf::NDI_BROWN, "msg_say" + for @plonmap; } } - } - if (@kw) { - $_->ob->message ("[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN | cf::NDI_UNIQUE) - for grep $pl->on_same_map_as ($_->ob), cf::player::list; + if (@kw) { + $_->send_msg ($cf::SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN) + for @plonmap; + } } } } else { - $pl->message ("What do you want to say?", cf::NDI_UNIQUE); + $ob->send_msg ($cf::SAY_CHANNEL => "What do you want to say?", cf::NDI_GREY | cf::NDI_REPLY); } }; -cf::register_command chat => sub { - my ($pl, $msg) = @_; - utf8::decode $msg; +sub _chat { + my ($ob, $msg) = @_; + + my $pl = $ob->contr; - return if $pl->contr->invoke (cf::EVENT_PLAYER_CHAT, $msg); + return if $pl->invoke (cf::EVENT_PLAYER_CHAT, $msg); if ($msg) { - my $name = $pl->name; + my $name = $ob->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); + cf::LOG cf::llevDebug, sprintf "QBERT %s\n", $msg; + send_irc ("%s", $msg); - $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) - for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; + send_msg $_, $cf::CHAT_CHANNEL => $msg, cf::NDI_BLUE | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_chat" + for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW } cf::player::list; } else { - $pl->message ("Chat what?", cf::NDI_UNIQUE); + $pl->send_msg ($cf::CHAT_CHANNEL => "Chat what?", cf::NDI_BLUE | cf::NDI_DEF | cf::NDI_REPLY); } +} + +cf::register_command chat => sub { + my ($ob, $msg) = @_; + + utf8::decode $msg; + _chat $ob, $ob->name . " chats: $msg"; +}; + +cf::register_command me => sub { + my ($ob, $msg) = @_; + + utf8::decode $msg; + _chat $ob, "* " . $ob->name . " $msg"; }; 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; - 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; + send_msg $_, $cf::CHAT_CHANNEL => "$name shouts: $msg", cf::NDI_RED | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_shout" + for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW } cf::player::list; } else { - $pl->message ("Shout what?", cf::NDI_UNIQUE); + $pl->send_msg ($cf::CHAT_CHANNEL => "Shout what?", cf::NDI_RED | cf::NDI_DEF | cf::NDI_REPLY); } }; cf::register_command tell => sub { - my ($pl, $args) = @_; + my ($ob, $args) = @_; my ($target, $msg) = split /\s+/, $args, 2; utf8::decode $msg; - return if $pl->contr->invoke (cf::EVENT_PLAYER_TELL, $target, $msg); + my $pl = $ob->contr; + my $ns = $pl->ns + or return; + my $name = $ob->name; - my $name = $pl->name; + return if $pl->invoke (cf::EVENT_PLAYER_TELL, $target, $msg); + + my $pl_channel = tell_channel $target; 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); + $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 = tell_channel $name; if ($msg) { if ($target eq $name) { - $pl->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); + $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) { - $pl->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE); + $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->contr, $msg); - utf8::encode $msg; # ->message not yet utf8-ified + return if $other->invoke (cf::EVENT_PLAYER_TOLD, $pl, $msg); cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg; - $pl->message ("You tell $target: $msg"); - $other->ob->message ("$name tells you: $msg"); - $other->ob->{ext_last_tell} = $name; - } - } else { - $pl->message ("What do you want to tell $target?", cf::NDI_UNIQUE); - } - - } else { - $pl->message ("No such player. Your message: $msg", cf::NDI_UNIQUE); - } -}; - -cf::register_command reply => sub { - my ($pl, $args) = @_; - my $name = $pl->name; - - utf8::decode $args; - - return if $pl->contr->invoke (cf::EVENT_PLAYER_TELL, $pl->{ext_last_tell}, $args); - - 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); - } elsif (my $other = cf::player::find_active $pl->{ext_last_tell}) { - - if ($args) { - $other->ob->{ext_ignore_tell}{$name} >= time - 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"); - $other->ob->message ("$name tells you: $args"); - $pl->{ext_last_tell} = $other->ob->name; - } else { - $pl->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE); + $ns->send_msg ($pl_channel => "You tell $target: $msg", cf::NDI_DK_ORANGE | cf::NDI_DEF | cf::NDI_REPLY); + send_msg $other, $other_channel => "$name tells you: $msg", cf::NDI_DK_ORANGE | cf::NDI_DEF, "msg_tell"; } } else { - $pl->message ("What do you want to tell ".$other->ob->name."?", cf::NDI_UNIQUE); + $ns->send_msg ($pl_channel => "What do you want to tell $target?", cf::NDI_DK_ORANGE | cf::NDI_DEF | cf::NDI_REPLY); } } else { - $pl->message ("Can't reply, player left. Your message: $args".$pl->{ext_last_tell}, cf::NDI_UNIQUE); + $ns->send_msg ($pl_channel => "No such player. Your message: $msg", cf::NDI_DK_ORANGE | cf::NDI_DEF | cf::NDI_REPLY); } }; @@ -942,82 +966,85 @@ my ($pl, $args) = @_; my ($target, $type, $timeout) = split /\s+/, $args; - if ($args eq "list") { - clean_timeouts $pl; - - 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); - } else { - $pl->message ("Not ignoring anyone", cf::NDI_UNIQUE); - } - - } elsif ($target && $type) { - - $timeout ne "" or $timeout = 24; - my $absolute_timeout = time + $timeout * 3600; - - if (cf::player::exists $target) { - if ($type eq "tell") { - $pl->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_UNIQUE); - $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->{ext_ignore_shout}{$target} = $absolute_timeout; - } elsif ($type eq "all") { - $pl->message ("Now ignoring everything from $target for $timeout hours.", cf::NDI_UNIQUE); - $pl->{ext_ignore_tell}{$target} = $absolute_timeout; - $pl->{ext_ignore_shout}{$target} = $absolute_timeout; + cf::async { + if ($args eq "list") { + clean_timeouts $pl; + + 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_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 ("You need to specify tell, shout or all.", cf::NDI_UNIQUE); + $pl->message ("Not ignoring anyone", cf::NDI_REPLY); } + + } elsif ($target && $type) { + $timeout ne "" or $timeout = 24; + my $absolute_timeout = time + $timeout * 3600; + + if (cf::player::exists $target) { + if ($type eq "tell") { + $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_REPLY); + $pl->{ext_ignore_shout}{$target} = $absolute_timeout; + } elsif ($type eq "all") { + $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_REPLY); + } + } else { + $pl->message ("No such player: $target", cf::NDI_REPLY); + } + } else { - $pl->message ("No such player: $target", cf::NDI_UNIQUE); + $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_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); - } + }; }; cf::register_command unignore => sub { my ($pl, $args) = @_; my ($target, $type) = split /\s+/, $args; - 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); - } else { - $pl->message ("Not ignoring anyone", cf::NDI_UNIQUE); - } - } else { - if (cf::player::exists $target) { - if ($type eq "tell") { - $pl->message ("Not ignoring private messages from $target anymore.", cf::NDI_UNIQUE); - delete $pl->{ext_ignore_tell} {$target}; - } elsif ($type eq "shout") { - $pl->message ("Not ignoring shouts from $target anymore.", cf::NDI_UNIQUE); - delete $pl->{ext_ignore_shout}{$target}; - } elsif ($type eq "all") { - $pl->message ("Not ignoring anything from $target anymore.", cf::NDI_UNIQUE); - delete $pl->{ext_ignore_tell} {$target}; - delete $pl->{ext_ignore_shout}{$target}; + cf::async { + if ($args eq "") { + if ($pl->{ext_ignore_tell}) { + $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 ("You need to specify tell, shout or all.", cf::NDI_UNIQUE); + $pl->message ("Not ignoring anyone", cf::NDI_REPLY); } } else { - $pl->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE); + if (cf::player::exists $target) { + if ($type eq "tell") { + $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_REPLY); + delete $pl->{ext_ignore_shout}{$target}; + } elsif ($type eq "all") { + $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_REPLY); + } + } else { + $pl->message ("No such player or ambiguous name: $target", cf::NDI_REPLY); + } } - } + }; };