ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/chat.ext
(Generate patch)

Comparing deliantra/server/ext/chat.ext (file contents):
Revision 1.22 by root, Sun Jul 22 14:17:57 2007 UTC vs.
Revision 1.41 by root, Mon Jul 14 23:57:45 2008 UTC

1#! perl # depends=irc 1#! perl # depends=irc mandatory
2#CONVERSION: PARTIAL
3 2
4# implement a replacement for the built-in say/chat/shout/tell/reply commands 3# implement a replacement for the built-in say/chat/shout/tell commands
5# adds ignore/unignore functionality 4# adds ignore/unignore functionality
6 5
7use NPC_Dialogue; 6use NPC_Dialogue;
8use POSIX (); # for strftime only 7use POSIX (); # for strftime only
9 8
10our $SAY_CHANNEL = { 9sub tell_channel($) {
11 id => "say", 10 my ($target) = @_;
12 title => "Map",
13 reply => "say ",
14 tooltip => "Things said to and replied from npcs near you and other players on the same map only.",
15};
16 11
17our $CHAT_CHANNEL = { 12 {
18 id => "chat", 13 id => "tell-$target",
19 title => "Chat", 14 title => "$target",
20 reply => "chat ", 15 reply => "tell $target ",
21 tooltip => "Player chat and shouts, global to the server.", 16 tooltip => "Private messages from/to $target",
22}; 17 }
18}
19
20sub send_msg($$$$$) {
21 my ($pl, $channel, $msg, $flags, $sound) = @_;
22 $pl->play_sound (cf::sound::find $sound) if defined $sound;
23 $pl->send_msg ($channel, $msg, $flags);
24 ()
25}
23 26
24sub clean_timeouts($) { 27sub clean_timeouts($) {
25 my ($player) = @_; 28 my ($player) = @_;
26 my $NOW = time; 29 my $NOW = time;
27 30
28 for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) { 31 for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) {
29 while (my ($k, $v) = each %$hash) { 32 while (my ($k, $v) = each %$hash) {
30 if ($v < $NOW) { 33 if ($v < $NOW) {
31 $player->message ("Your ignore on $k has expired.", cf::NDI_GREEN | cf::NDI_UNIQUE); 34 $player->message ("Your ignore on $k has expired.", cf::NDI_GREEN);
32 delete $hash->{$k}; 35 delete $hash->{$k};
33 } elsif (!cf::player::exists $k) { 36 } elsif (!cf::player::exists $k) {
34 $player->message ("Your ignore on $k is no longer valid (no such user).", cf::NDI_GREEN | cf::NDI_UNIQUE); 37 $player->message ("Your ignore on $k is no longer valid (no such user).", cf::NDI_GREEN);
35 delete $hash->{$k}; 38 delete $hash->{$k};
36 } 39 }
37 } 40 }
38 } 41 }
39} 42}
52 prio => -1000, 55 prio => -1000,
53 on_login => sub { 56 on_login => sub {
54 my ($pl) = @_; 57 my ($pl) = @_;
55 58
56 clean_timeouts $pl->ob; 59 clean_timeouts $pl->ob;
60
57 $pl->ns->send_msg ($SAY_CHANNEL); 61 $pl->send_msg ($cf::SAY_CHANNEL);
58 $pl->ns->send_msg ($CHAT_CHANNEL); 62 $pl->send_msg ($cf::CHAT_CHANNEL);
59 }, 63 },
60); 64);
61 65
62cf::register_command listen => sub { 66cf::register_command listen => sub {
63 my ($pl, $msg) = @_; 67 my ($pl, $msg) = @_;
67 $msg = 10 if $msg > 10; 71 $msg = 10 if $msg > 10;
68 72
69 my $prev_listen = $player->listening; 73 my $prev_listen = $player->listening;
70 $player->listening ($msg); 74 $player->listening ($msg);
71 if ($prev_listen == $player->listening) { 75 if ($prev_listen == $player->listening) {
72 $pl->message ("Your verbose level stays at $prev_listen.", cf::NDI_UNIQUE); 76 $pl->message ("Your verbose level stays at $prev_listen.", cf::NDI_REPLY);
73 } else { 77 } else {
74 $pl->message ("Your verbose level is now " . $player->listening . ". (previously: $prev_listen)", cf::NDI_UNIQUE); 78 $pl->message ("Your verbose level is now " . $player->listening . ". (previously: $prev_listen)", cf::NDI_REPLY);
75 } 79 }
76 } else { 80 } else {
77 $pl->message ("Your verbose level is " . $player->listening . ".", cf::NDI_UNIQUE); 81 $pl->message ("Your verbose level is " . $player->listening . ".", cf::NDI_REPLY);
78 } 82 }
79}; 83};
80 84
81cf::register_command cointoss => sub { 85cf::register_command cointoss => sub {
82 my ($pl, $msg) = @_; 86 my ($ob, $msg) = @_;
83 87
88 my $pl = $ob->contr;
84 my $name = $pl->name; 89 my $name = $ob->name;
90
85 my $coin = int rand 2 ? "Heads" : "Tails"; 91 my $coin = int rand 2 ? "Heads" : "Tails";
86 92
93 send_msg $_, $cf::SAY_CHANNEL => "$name flips a coin.... $coin!", cf::NDI_GREY, "msg_say"
87 for my $other ( grep { $pl->on_same_map_as ($_->ob) } cf::player::list ) { 94 for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl} cf::player::list;
88 next
89 if $other->ob == $pl;
90 $other->ob->message ("$name flips a coin.... $coin!", cf::NDI_GREY | cf::NDI_UNIQUE);
91 }
92 95
93 $pl->message ("You flip a coin.... $coin!", cf::NDI_GREY | cf::NDI_UNIQUE); 96 $pl->send_msg ($cf::SAY_CHANNEL => "You flip a coin.... $coin!", cf::NDI_GREY | cf::NDI_REPLY);
94}; 97};
95 98
96cf::register_command orcknuckle => sub { 99cf::register_command orcknuckle => sub {
97 my ($pl, $msg) = @_; 100 my ($ob, $msg) = @_;
101
102 my $pl = $ob->contr;
103 my $name = $ob->name;
104
98 my @orcknuckle = ("none", "beholder", "ghost", "knight", "princess", "dragon", "orc"); 105 my @orcknuckle = ("beholder", "ghost", "knight", "princess", "dragon", "orc");
99 106 my ($i, $j, $k, $l) = (rand 5, rand 5, rand 5, rand 6);
100 my $name = $pl->name;
101
102 my ($i, $j, $k, $l) = ((int rand 5) + 1, (int rand 5) + 1, (int rand 5) + 1, (int rand 6) + 1);
103 my $result = "$orcknuckle[$i], $orcknuckle[$j], $orcknuckle[$k], $orcknuckle[$l]"; 107 my $result = "$orcknuckle[$i], $orcknuckle[$j], $orcknuckle[$k], $orcknuckle[$l]";
104 108
109 send_msg $_, $cf::SAY_CHANNEL => "$name throws his orc-knuckles and rolls $result!", cf::NDI_GREY, "msg_say"
105 for my $other ( grep { $pl->on_same_map_as ($_->ob) } cf::player::list ) { 110 for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl} cf::player::list;
106 next
107 if $other->ob == $pl;
108 $other->ob->message ("$name rolls $result!", cf::NDI_GREY | cf::NDI_UNIQUE);
109 } 111
110
111 $pl->message ("You roll $result!", cf::NDI_GREY | cf::NDI_UNIQUE); 112 $pl->send_msg ($cf::SAY_CHANNEL => "You roll $result!", cf::NDI_GREY | cf::NDI_REPLY);
112}; 113};
113 114
114my $emotes = { 115my $emotes = {
115 growl => { 116 growl => {
116 noparams => { 117 noparams => {
240 self => "You kiss <other>.", 241 self => "You kiss <other>.",
241 }, 242 },
242 self => { 243 self => {
243 }, 244 },
244 }, 245 },
246 smother => {
247 noparams => {
248 other => "<self> makes weird facial contortions",
249 self => "All the lonely people..",
250 },
251 params => {
252 target => "<self> smothers you with kisses.",
253 other => "<self> smothers <other> with kisses.",
254 self => "You smother <other> with kisses.",
255 },
256 self => {
257 },
258 },
245 wink => { 259 wink => {
246 noparams => { 260 noparams => {
247 other => "<self> winks suggestively.", 261 other => "<self> winks suggestively.",
248 self => "Have you got something in your eye?", 262 self => "Have you got something in your eye?",
249 }, 263 },
693 }, 707 },
694}; 708};
695 709
696for my $emotion (keys %$emotes) { 710for my $emotion (keys %$emotes) {
697 cf::register_command $emotion => sub { 711 cf::register_command $emotion => sub {
698 my ($pl, $tname) = @_; 712 my ($ob, $tname) = @_;
713
714 my $pl = $ob->contr;
699 715
700 cf::async { 716 cf::async {
701 my $name = $pl->name; 717 my $name = $ob->name;
718 $Coro::current->{desc} = "emote handler for $name";
702 719
703 if ($tname eq $name) { 720 if ($tname eq $name) {
704 my $emote = $emotes->{$emotion}->{self}; 721 my %emote = %{ $emotes->{$emotion}->{self} || {} };
705 722
706 $emote->{other} = "You look away from <self>." 723 $emote{other} ||= "You look away from <self>.";
707 if !$emote->{other};
708 $emote->{self} = "My god! Is that LEGAL?" 724 $emote{self} ||= "My god! Is that LEGAL?";
709 if !$emote->{self};
710 725
711 $emote->{other} =~ s/<self>/$name/; 726 $emote{other} =~ s/<self>/$name/;
712 727
728 send_msg $_, $cf::CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat"
713 for my $other ( grep { $pl->on_same_map_as ($_->ob) } cf::player::list ) { 729 for grep { $ob->on_same_map_as ($_->ob) && $_ != $ob} cf::player::list;
714 next
715 if $other->ob == $pl;
716 $other->ob->message ($emote->{other}, cf::NDI_GREY | cf::NDI_UNIQUE);
717 }
718 730
719 $pl->message ($emote->{self}, cf::NDI_GREY | cf::NDI_UNIQUE); 731 $pl->send_msg ($emote{self}, cf::NDI_GREY | cf::NDI_REPLY);
720 } elsif ($tname) { 732 } elsif ($tname) {
721 my $target = cf::player::find $tname 733 my $target = cf::player::find $tname
722 or return $pl->reply (undef, "$tname is not around."); 734 or return send_msg $pl, tell_channel $tname, "$tname is not around.", cf::NDI_DK_ORANGE | cf::NDI_REPLY, "msg_chat";
723 735
724 my $emote = $emotes->{$emotion}->{params}; 736 my %emote = %{ $emotes->{$emotion}->{params} || {} };
725 737
726 $emote->{other} = "<self> is eyeing <other> quizzically." 738 $emote{other} ||= "<self> is eyeing <other> quizzically.";
727 if !$emote->{other};
728 $emote->{self} = "You are still nuts." 739 $emote{self} ||= "You are still nuts.";
729 if !$emote->{self};
730 $emote->{target} = "You get the distinct feeling that <other> is nuts." 740 $emote{target} ||= "You get the distinct feeling that <self> is nuts.";
731 if !$emote->{target};
732 741
733 $emote->{self} =~ s/<other>/$tname/; 742 $emote{self} =~ s/<other>/$tname/;
734 $emote->{target} =~ s/<self>/$name/; 743 $emote{target} =~ s/<self>/$name/;
735 $emote->{other} =~ s/<other>/$tname/; 744 $emote{other} =~ s/<other>/$tname/;
736 $emote->{other} =~ s/<self>/$name/; 745 $emote{other} =~ s/<self>/$name/;
737 746
738 for my $other ( grep { $pl->on_same_map_as ($_->ob) } cf::player::list ) { 747 send_msg $_, $cf::CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat"
739 next 748 for grep { $_ != $pl && $_ != $target && $ob->on_same_map_as ($_->ob) } cf::player::list;
740 if $other->ob == $pl or $other == $target;
741 $other->ob->message ($emote->{other}, cf::NDI_GREY | cf::NDI_UNIQUE);
742 }
743 749
744 $target->ob->message ($emote->{target}, cf::NDI_GREY | cf::NDI_UNIQUE); 750 send_msg $target, tell_channel $name, $emote{target}, cf::NDI_GREY, "msg_shout";
745 $pl->message ($emote->{self}, cf::NDI_GREY | cf::NDI_UNIQUE); 751 $pl->send_msg (tell_channel $tname, $emote{self}, cf::NDI_GREY | cf::NDI_REPLY);
746 } else { 752 } else {
747 my $emote = $emotes->{$emotion}->{noparams}; 753 my %emote = %{ $emotes->{$emotion}->{noparams} || {} };
748 $emote->{other} =~ s/<self>/$name/;
749 754
750 $emote->{other} = "<self> dances with glee." 755 $emote{other} ||= "<self> dances with glee.";
751 if !$emote->{other};
752 $emote->{self} = "You are a nut." 756 $emote{self} ||= "You are a nut.";
753 if !$emote->{self};
754 757
758 $emote{other} =~ s/<self>/$name/;
759
760 send_msg $_, $cf::CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat"
755 for my $other ( grep { $pl->on_same_map_as ($_->ob) } cf::player::list ) { 761 for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl } cf::player::list;
756 next
757 if $other->ob == $pl;
758 $other->ob->message ($emote->{other}, cf::NDI_GREY | cf::NDI_UNIQUE);
759 }
760 762
761 $pl->message ($emote->{self}, cf::NDI_GREY | cf::NDI_UNIQUE); 763 $pl->send_msg ($cf::CHAT_CHANNEL, $emote{self}, cf::NDI_GREY | cf::NDI_REPLY);
762 } 764 }
763 }; 765 };
764 }; 766 };
765} 767}
766 768
767cf::register_command me => sub { 769cf::register_command me => sub {
768 my ($pl, $msg) = @_; 770 my ($pl, $msg) = @_;
769 771
770 my $name = $pl->name; 772 my $name = $pl->name;
771 773
772 $_->ns->send_msg ($SAY_CHANNEL => "* $name $msg", cf::NDI_GREY, $_ == $pl ? (reply => 1) : ()) 774 send_msg $_, $cf::SAY_CHANNEL => "* $name $msg", cf::NDI_GREY | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_say"
773 for grep $pl->on_same_map_as ($_->ob), cf::player::list; 775 for grep $pl->on_same_map_as ($_->ob), cf::player::list;
774}; 776};
775 777
776cf::register_command say => sub { 778cf::register_command say => sub {
777 my ($pl, $msg) = @_; 779 my ($ob, $msg) = @_;
778 780
779 utf8::decode $msg; 781 utf8::decode $msg;
780 782
781 return if $pl->contr->invoke (cf::EVENT_PLAYER_SAY, $msg); 783 return if $ob->contr->invoke (cf::EVENT_PLAYER_SAY, $msg);
782 784
783 if ($msg) { 785 if ($msg) {
784 my $name = $pl->name; 786 my $name = $ob->name;
785 my @plonmap = grep $pl->on_same_map_as ($_->ob), cf::player::list; 787 my @plonmap = grep $ob->on_same_map_as ($_->ob), cf::player::list;
786 788
787 $_->ns->send_msg ($SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY, $_ == $pl ? (reply => 1) : ()) 789 send_msg $_, $cf::SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY, "msg_say"
788 for @plonmap; 790 for grep $_ != $ob->contr, @plonmap;
791 $ob->contr->send_msg ($cf::SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY | cf::NDI_REPLY);
789 792
790 # npcs, magic_ears etc. 793 # npcs, magic_ears etc.
791 # first find all objects and their first-level inventories 794 # first find all objects and their first-level inventories
792 # within a 5x5 square that have something resembling 795 # within a 5x5 square that have something resembling
793 # dialogue or support on_say. 796 # dialogue or support on_say.
794 my ($map, $x, $y) = ($pl->map, $pl->x - 2, $pl->y - 2); 797 my ($map, $x, $y) = ($ob->map, $ob->x - 2, $ob->y - 2);
795 798
796 for my $npc ( 799 for my $npc (
797 grep +($_->invoke (cf::EVENT_OBJECT_SAY, $pl->contr, $msg) && return) || NPC_Dialogue::has_dialogue $_, 800 grep +($_->invoke (cf::EVENT_OBJECT_SAY, $ob->contr, $msg) && return) || $_->has_dialogue,
798 map +($_, $_->inv), 801 map +($_, $_->inv),
799 grep $_, 802 grep $_,
800 map $map->at ($x + $_ % 5, $y + (int $_ / 5)), 803 map $map->at ($x + $_ % 5, $y + (int $_ / 5)),
801 0..24 804 0..24
802 ) { 805 ) {
803 # if some listener teleported us somewhere else, stop right here 806 # if some listener teleported us somewhere else, stop right here
804 last unless $map->path == $pl->map->path; 807 last unless $map->path == $ob->map->path;
805 808
806 my $dialog = new NPC_Dialogue pl => $pl->contr, npc => $npc; 809 my $dialog = new NPC_Dialogue pl => $ob->contr, npc => $npc;
807 my ($reply, @kw) = $dialog->tell ($msg); 810 my ($reply, @kw) = $dialog->tell ($msg);
808 811
809 if (defined $reply) { 812 if (defined $reply) {
810 if ($npc->type == cf::MAGIC_EAR) { 813 if ($npc->type == cf::MAGIC_EAR) {
811 if (length $reply) { 814 if (length $reply) {
812 $_->contr->send_msg ($SAY_CHANNEL => $reply, cf::NDI_BROWN) 815 send_msg $_, $cf::SAY_CHANNEL => $reply, cf::NDI_BROWN, "msg_say"
813 for @plonmap; 816 for @plonmap;
814 } 817 }
815 $npc->use_trigger; 818 $npc->use_trigger;
816 } else { 819 } else {
817 if (length $reply) { 820 if (length $reply) {
818 $_->contr->send_msg ($SAY_CHANNEL => $npc->name . " says: $reply", cf::NDI_BROWN) 821 send_msg $_, $cf::SAY_CHANNEL => $npc->name . " says: $reply", cf::NDI_BROWN, "msg_say"
819 for @plonmap; 822 for @plonmap;
820 } 823 }
821 } 824 }
822 } 825 }
823 826
824 if (@kw) { 827 if (@kw) {
825 $_->contr->send_msg ($SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN) 828 $_->send_msg ($cf::SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN)
826 for @plonmap; 829 for @plonmap;
827 } 830 }
828 } 831 }
829 832
830 } else { 833 } else {
831 $pl->contr->send_msg ($SAY_CHANNEL => "What do you want to say?", 0, reply => 1); 834 $ob->send_msg ($cf::SAY_CHANNEL => "What do you want to say?", cf::NDI_GREY | cf::NDI_REPLY);
832 } 835 }
833}; 836};
834 837
835cf::register_command chat => sub { 838cf::register_command chat => sub {
836 my ($pl, $msg) = @_; 839 my ($ob, $msg) = @_;
837 840
838 utf8::decode $msg; 841 utf8::decode $msg;
839 842
843 my $pl = $ob->contr;
844
840 return if $pl->contr->invoke (cf::EVENT_PLAYER_CHAT, $msg); 845 return if $pl->invoke (cf::EVENT_PLAYER_CHAT, $msg);
841 846
842 if ($msg) { 847 if ($msg) {
843 my $name = $pl->name; 848 my $name = $ob->name;
844 my $NOW = time; 849 my $NOW = time;
845 850
846 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; 851 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg;
847 send_irc ("[%s] %s", $name, $msg); 852 send_irc ("[%s] %s", $name, $msg);
848 853
849 $_->ns->send_msg ($CHAT_CHANNEL => "$name chats: $msg", cf::NDI_BLUE, $_ == $pl ? (reply => 1) : ()) 854 send_msg $_, $cf::CHAT_CHANNEL => "$name chats: $msg", cf::NDI_BLUE | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_chat"
850 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; 855 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list;
851 856
852 } else { 857 } else {
853 $pl->ns->send_msg ($CHAT_CHANNEL => "Chat what?"); 858 $pl->send_msg ($cf::CHAT_CHANNEL => "Chat what?", cf::NDI_BLUE | cf::NDI_DEF | cf::NDI_REPLY);
854 } 859 }
855}; 860};
856 861
857cf::register_command shout => sub { 862cf::register_command shout => sub {
858 my ($pl, $msg) = @_; 863 my ($ob, $msg) = @_;
859 864
860 utf8::decode $msg; 865 utf8::decode $msg;
861 866
867 my $pl = $ob->contr;
868
862 return if $pl->contr->invoke (cf::EVENT_PLAYER_SHOUT, $msg); 869 return if $pl->invoke (cf::EVENT_PLAYER_SHOUT, $msg);
863 870
864 if ($msg) { 871 if ($msg) {
865 my $NOW = time; 872 my $NOW = time;
866 my $name = $pl->name; 873 my $name = $ob->name;
867 874
868 cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; 875 cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg;
869 send_irc ("\007\0034{%s} %s\n", $name, $msg); 876 send_irc ("\007\0034{%s} %s\n", $name, $msg);
870 877
871 $_->ns->send_msg ($CHAT_CHANNEL => "$name shouts: $msg", cf::NDI_BLUE, $_ == $pl ? (reply => 1) : ()) 878 send_msg $_, $cf::CHAT_CHANNEL => "$name shouts: $msg", cf::NDI_RED | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_shout"
872 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; 879 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list;
873 880
874 } else { 881 } else {
875 $pl->ns->send_msg ($CHAT_CHANNEL => "Shout what?"); 882 $pl->send_msg ($cf::CHAT_CHANNEL => "Shout what?", cf::NDI_RED | cf::NDI_DEF | cf::NDI_REPLY);
876 } 883 }
877}; 884};
878 885
879cf::register_command tell => sub { 886cf::register_command tell => sub {
880 my ($ob, $args) = @_; 887 my ($ob, $args) = @_;
887 or return; 894 or return;
888 my $name = $ob->name; 895 my $name = $ob->name;
889 896
890 return if $pl->invoke (cf::EVENT_PLAYER_TELL, $target, $msg); 897 return if $pl->invoke (cf::EVENT_PLAYER_TELL, $target, $msg);
891 898
892 my $pl_channel = { 899 my $pl_channel = tell_channel $target;
893 id => "tell-$target",
894 title => "$target",
895 reply => "tell $target ",
896 tooltip => "Private messages from/to $target",
897 };
898 900
899 if ($target =~ /irc\//) { 901 if ($target =~ /irc\//) {
900 my (undef, $nick) = split /\//, $target, 2; 902 my (undef, $nick) = split /\//, $target, 2;
901 $ns->send_msg ($pl_channel => "You tell $target: $args", reply => 1); 903 $ns->send_msg ($pl_channel => "You tell $target: $args", cf::NDI_DK_ORANGE | cf::NDI_DEF | cf::NDI_REPLY);
902 send_irc ("(%s) %s: %s\n", $name, $nick, $msg); 904 send_irc ("(%s) %s: %s\n", $name, $nick, $msg);
905
903 } elsif (my $other = cf::player::find_active $target) { 906 } elsif (my $other = cf::player::find_active $target) {
904 my $other_channel = { 907 my $other_channel = tell_channel $name;
905 id => "tell-$name",
906 title => "$name",
907 reply => "tell $name ",
908 tooltip => "Private messages from/to $name",
909 };
910 908
911 if ($msg) { 909 if ($msg) {
912 if ($target eq $name) { 910 if ($target eq $name) {
913 $ns->send_msg ($pl_channel => "You are talking to yourself, you freak!", reply => 1); 911 $ns->send_msg ($pl_channel => "You are talking to yourself, you freak!", cf::NDI_DK_ORANGE | cf::NDI_DEF | cf::NDI_REPLY);
914 } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { 912 } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) {
915 $ns->send_msg ($pl_channel => "$target ignores what you say. Give up on it.", reply => 1); 913 $ns->send_msg ($pl_channel => "$target ignores what you say. Give up on it.", cf::NDI_DK_ORANGE | cf::NDI_DEF | cf::NDI_REPLY);
916 } else { 914 } else {
917 return if $other->invoke (cf::EVENT_PLAYER_TOLD, $pl->contr, $msg); 915 return if $other->invoke (cf::EVENT_PLAYER_TOLD, $pl, $msg);
918 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg; 916 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg;
919 917
920 $ns->send_msg ($pl_channel => "You tell $target: $msg", reply => 1); 918 $ns->send_msg ($pl_channel => "You tell $target: $msg", cf::NDI_DK_ORANGE | cf::NDI_DEF | cf::NDI_REPLY);
921 $other->ns->send_msg ($other_channel => "$name tells you: $msg"); 919 send_msg $other, $other_channel => "$name tells you: $msg", cf::NDI_DK_ORANGE | cf::NDI_DEF, "msg_tell";
922 } 920 }
923 } else { 921 } else {
924 $ns->send_msg ($pl_channel => "What do you want to tell $target?"); 922 $ns->send_msg ($pl_channel => "What do you want to tell $target?", cf::NDI_DK_ORANGE | cf::NDI_DEF | cf::NDI_REPLY);
925 } 923 }
926 924
927 } else { 925 } else {
928 $ns->send_msg ($pl_channel => "No such player. Your message: $msg"); 926 $ns->send_msg ($pl_channel => "No such player. Your message: $msg", cf::NDI_DK_ORANGE | cf::NDI_DEF | cf::NDI_REPLY);
929 } 927 }
930}; 928};
931 929
932cf::register_command ignore => sub { 930cf::register_command ignore => sub {
933 my ($pl, $args) = @_; 931 my ($pl, $args) = @_;
936 if ($args eq "list") { 934 if ($args eq "list") {
937 clean_timeouts $pl; 935 clean_timeouts $pl;
938 936
939 if ((my @ignored_tell = sort keys %{$pl->{ext_ignore_tell}}) 937 if ((my @ignored_tell = sort keys %{$pl->{ext_ignore_tell}})
940 + (my @ignored_shout = sort keys %{$pl->{ext_ignore_shout}})) { 938 + (my @ignored_shout = sort keys %{$pl->{ext_ignore_shout}})) {
941 $pl->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE); 939 $pl->message ("Currently ignoring private messages from: ", cf::NDI_REPLY);
942 $pl->message ((join ", ", @ignored_tell), cf::NDI_UNIQUE); 940 $pl->message ((join ", ", @ignored_tell), cf::NDI_REPLY);
943 $pl->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE); 941 $pl->message ("Currently ignoring shouts from: ", cf::NDI_REPLY);
944 $pl->message ((join ", ", @ignored_shout), cf::NDI_UNIQUE); 942 $pl->message ((join ", ", @ignored_shout), cf::NDI_REPLY);
945 $pl->message ("To stop ignoring one, use unignore.", cf::NDI_UNIQUE); 943 $pl->message ("To stop ignoring one, use unignore.", cf::NDI_REPLY);
946 } else { 944 } else {
947 $pl->message ("Not ignoring anyone", cf::NDI_UNIQUE); 945 $pl->message ("Not ignoring anyone", cf::NDI_REPLY);
948 } 946 }
949 947
950 } elsif ($target && $type) { 948 } elsif ($target && $type) {
951 949
952 $timeout ne "" or $timeout = 24; 950 $timeout ne "" or $timeout = 24;
953 my $absolute_timeout = time + $timeout * 3600; 951 my $absolute_timeout = time + $timeout * 3600;
954 952
955 if (cf::player::exists $target) { 953 if (cf::player::exists $target) {
956 if ($type eq "tell") { 954 if ($type eq "tell") {
957 $pl->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_UNIQUE); 955 $pl->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_REPLY);
958 $pl->{ext_ignore_tell}{$target} = $absolute_timeout; 956 $pl->{ext_ignore_tell}{$target} = $absolute_timeout;
959 } elsif ($type eq "shout") { 957 } elsif ($type eq "shout") {
960 $pl->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_UNIQUE); 958 $pl->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_REPLY);
961 $pl->{ext_ignore_shout}{$target} = $absolute_timeout; 959 $pl->{ext_ignore_shout}{$target} = $absolute_timeout;
962 } elsif ($type eq "all") { 960 } elsif ($type eq "all") {
963 $pl->message ("Now ignoring everything from $target for $timeout hours.", cf::NDI_UNIQUE); 961 $pl->message ("Now ignoring everything from $target for $timeout hours.", cf::NDI_REPLY);
964 $pl->{ext_ignore_tell}{$target} = $absolute_timeout; 962 $pl->{ext_ignore_tell}{$target} = $absolute_timeout;
965 $pl->{ext_ignore_shout}{$target} = $absolute_timeout; 963 $pl->{ext_ignore_shout}{$target} = $absolute_timeout;
966 } else { 964 } else {
967 $pl->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE); 965 $pl->message ("You need to specify tell, shout or all.", cf::NDI_REPLY);
968 } 966 }
969 } else { 967 } else {
970 $pl->message ("No such player: $target", cf::NDI_UNIQUE); 968 $pl->message ("No such player: $target", cf::NDI_REPLY);
971 } 969 }
972 970
973 } else { 971 } else {
974 $pl->message ("Usage: ignore <player> <tell|shout|all> <timeout>\n" 972 $pl->message ("Usage: ignore <player> <tell|shout|all> <timeout>\n"
975 . "will ignore a player for <timeout> hours.\n" 973 . "will ignore a player for <timeout> hours.\n"
976 . "Usage: ignore list\n" 974 . "Usage: ignore list\n"
977 . "will show you a list of players currently ignored.", cf::NDI_UNIQUE); 975 . "will show you a list of players currently ignored.", cf::NDI_REPLY);
978 } 976 }
979}; 977};
980 978
981cf::register_command unignore => sub { 979cf::register_command unignore => sub {
982 my ($pl, $args) = @_; 980 my ($pl, $args) = @_;
983 my ($target, $type) = split /\s+/, $args; 981 my ($target, $type) = split /\s+/, $args;
984 982
985 if ($args eq "") { 983 if ($args eq "") {
986 if ($pl->{ext_ignore_tell}) { 984 if ($pl->{ext_ignore_tell}) {
987 $pl->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE); 985 $pl->message ("Currently ignoring private messages from: ", cf::NDI_REPLY);
988 $pl->message ((join ", ", sort keys %{ $pl->{ext_ignore_tell} }), cf::NDI_UNIQUE); 986 $pl->message ((join ", ", sort keys %{ $pl->{ext_ignore_tell} }), cf::NDI_REPLY);
989 $pl->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE); 987 $pl->message ("Currently ignoring shouts from: ", cf::NDI_REPLY);
990 $pl->message ((join ", ", sort keys %{ $pl->{ext_ignore_shout} }), cf::NDI_UNIQUE); 988 $pl->message ((join ", ", sort keys %{ $pl->{ext_ignore_shout} }), cf::NDI_REPLY);
991 } else { 989 } else {
992 $pl->message ("Not ignoring anyone", cf::NDI_UNIQUE); 990 $pl->message ("Not ignoring anyone", cf::NDI_REPLY);
993 } 991 }
994 } else { 992 } else {
995 if (cf::player::exists $target) { 993 if (cf::player::exists $target) {
996 if ($type eq "tell") { 994 if ($type eq "tell") {
997 $pl->message ("Not ignoring private messages from $target anymore.", cf::NDI_UNIQUE); 995 $pl->message ("Not ignoring private messages from $target anymore.", cf::NDI_REPLY);
998 delete $pl->{ext_ignore_tell} {$target}; 996 delete $pl->{ext_ignore_tell} {$target};
999 } elsif ($type eq "shout") { 997 } elsif ($type eq "shout") {
1000 $pl->message ("Not ignoring shouts from $target anymore.", cf::NDI_UNIQUE); 998 $pl->message ("Not ignoring shouts from $target anymore.", cf::NDI_REPLY);
1001 delete $pl->{ext_ignore_shout}{$target}; 999 delete $pl->{ext_ignore_shout}{$target};
1002 } elsif ($type eq "all") { 1000 } elsif ($type eq "all") {
1003 $pl->message ("Not ignoring anything from $target anymore.", cf::NDI_UNIQUE); 1001 $pl->message ("Not ignoring anything from $target anymore.", cf::NDI_REPLY);
1004 delete $pl->{ext_ignore_tell} {$target}; 1002 delete $pl->{ext_ignore_tell} {$target};
1005 delete $pl->{ext_ignore_shout}{$target}; 1003 delete $pl->{ext_ignore_shout}{$target};
1006 } else { 1004 } else {
1007 $pl->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE); 1005 $pl->message ("You need to specify tell, shout or all.", cf::NDI_REPLY);
1008 } 1006 }
1009 } else { 1007 } else {
1010 $pl->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE); 1008 $pl->message ("No such player or ambiguous name: $target", cf::NDI_REPLY);
1011 } 1009 }
1012 } 1010 }
1013}; 1011};
1014 1012

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines