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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines