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.35 by root, Sat Oct 20 05:16:44 2007 UTC vs.
Revision 1.41 by root, Mon Jul 14 23:57:45 2008 UTC

1#! perl # depends=irc mandatory 1#! perl # depends=irc mandatory
2 2
3# 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
4# adds ignore/unignore functionality 4# adds ignore/unignore functionality
5 5
6use NPC_Dialogue; 6use NPC_Dialogue;
7use POSIX (); # for strftime only 7use POSIX (); # for strftime only
8
9our $SAY_CHANNEL = {
10 id => "say",
11 title => "Map",
12 reply => "say ",
13 tooltip => "Things said to and replied from npcs near you and other players on the same map only.",
14};
15
16our $CHAT_CHANNEL = {
17 id => "chat",
18 title => "Chat",
19 reply => "chat ",
20 tooltip => "Player chat and shouts, global to the server.",
21};
22 8
23sub tell_channel($) { 9sub tell_channel($) {
24 my ($target) = @_; 10 my ($target) = @_;
25 11
26 { 12 {
70 on_login => sub { 56 on_login => sub {
71 my ($pl) = @_; 57 my ($pl) = @_;
72 58
73 clean_timeouts $pl->ob; 59 clean_timeouts $pl->ob;
74 60
75 $pl->send_msg ($SAY_CHANNEL); 61 $pl->send_msg ($cf::SAY_CHANNEL);
76 $pl->send_msg ($CHAT_CHANNEL); 62 $pl->send_msg ($cf::CHAT_CHANNEL);
77 }, 63 },
78); 64);
79 65
80cf::register_command listen => sub { 66cf::register_command listen => sub {
81 my ($pl, $msg) = @_; 67 my ($pl, $msg) = @_;
102 my $pl = $ob->contr; 88 my $pl = $ob->contr;
103 my $name = $ob->name; 89 my $name = $ob->name;
104 90
105 my $coin = int rand 2 ? "Heads" : "Tails"; 91 my $coin = int rand 2 ? "Heads" : "Tails";
106 92
107 send_msg $_, $SAY_CHANNEL => "$name flips a coin.... $coin!", cf::NDI_GREY, "msg_say" 93 send_msg $_, $cf::SAY_CHANNEL => "$name flips a coin.... $coin!", cf::NDI_GREY, "msg_say"
108 for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl} cf::player::list; 94 for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl} cf::player::list;
109 95
110 $pl->send_msg ($SAY_CHANNEL => "You flip a coin.... $coin!", cf::NDI_GREY | cf::NDI_REPLY); 96 $pl->send_msg ($cf::SAY_CHANNEL => "You flip a coin.... $coin!", cf::NDI_GREY | cf::NDI_REPLY);
111}; 97};
112 98
113cf::register_command orcknuckle => sub { 99cf::register_command orcknuckle => sub {
114 my ($ob, $msg) = @_; 100 my ($ob, $msg) = @_;
115 101
118 104
119 my @orcknuckle = ("beholder", "ghost", "knight", "princess", "dragon", "orc"); 105 my @orcknuckle = ("beholder", "ghost", "knight", "princess", "dragon", "orc");
120 my ($i, $j, $k, $l) = (rand 5, rand 5, rand 5, rand 6); 106 my ($i, $j, $k, $l) = (rand 5, rand 5, rand 5, rand 6);
121 my $result = "$orcknuckle[$i], $orcknuckle[$j], $orcknuckle[$k], $orcknuckle[$l]"; 107 my $result = "$orcknuckle[$i], $orcknuckle[$j], $orcknuckle[$k], $orcknuckle[$l]";
122 108
123 send_msg $_, $SAY_CHANNEL => "$name throws his orc-knuckles and rolls $result!", cf::NDI_GREY, "msg_say" 109 send_msg $_, $cf::SAY_CHANNEL => "$name throws his orc-knuckles and rolls $result!", cf::NDI_GREY, "msg_say"
124 for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl} cf::player::list; 110 for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl} cf::player::list;
125 111
126 $pl->send_msg ($SAY_CHANNEL => "You roll $result!", cf::NDI_GREY | cf::NDI_REPLY); 112 $pl->send_msg ($cf::SAY_CHANNEL => "You roll $result!", cf::NDI_GREY | cf::NDI_REPLY);
127}; 113};
128 114
129my $emotes = { 115my $emotes = {
130 growl => { 116 growl => {
131 noparams => { 117 noparams => {
251 }, 237 },
252 params => { 238 params => {
253 target => "<self> kisses you.", 239 target => "<self> kisses you.",
254 other => "<self> kisses <other>.", 240 other => "<self> kisses <other>.",
255 self => "You kiss <other>.", 241 self => "You kiss <other>.",
242 },
243 self => {
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.",
256 }, 255 },
257 self => { 256 self => {
258 }, 257 },
259 }, 258 },
260 wink => { 259 wink => {
724 $emote{other} ||= "You look away from <self>."; 723 $emote{other} ||= "You look away from <self>.";
725 $emote{self} ||= "My god! Is that LEGAL?"; 724 $emote{self} ||= "My god! Is that LEGAL?";
726 725
727 $emote{other} =~ s/<self>/$name/; 726 $emote{other} =~ s/<self>/$name/;
728 727
729 send_msg $_, $CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat" 728 send_msg $_, $cf::CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat"
730 for grep { $ob->on_same_map_as ($_->ob) && $_ != $ob} cf::player::list; 729 for grep { $ob->on_same_map_as ($_->ob) && $_ != $ob} cf::player::list;
731 730
732 $pl->send_msg ($emote{self}, cf::NDI_GREY | cf::NDI_REPLY); 731 $pl->send_msg ($emote{self}, cf::NDI_GREY | cf::NDI_REPLY);
733 } elsif ($tname) { 732 } elsif ($tname) {
734 my $target = cf::player::find $tname 733 my $target = cf::player::find $tname
736 735
737 my %emote = %{ $emotes->{$emotion}->{params} || {} }; 736 my %emote = %{ $emotes->{$emotion}->{params} || {} };
738 737
739 $emote{other} ||= "<self> is eyeing <other> quizzically."; 738 $emote{other} ||= "<self> is eyeing <other> quizzically.";
740 $emote{self} ||= "You are still nuts."; 739 $emote{self} ||= "You are still nuts.";
741 $emote{target} ||= "You get the distinct feeling that <other> is nuts."; 740 $emote{target} ||= "You get the distinct feeling that <self> is nuts.";
742 741
743 $emote{self} =~ s/<other>/$tname/; 742 $emote{self} =~ s/<other>/$tname/;
744 $emote{target} =~ s/<self>/$name/; 743 $emote{target} =~ s/<self>/$name/;
745 $emote{other} =~ s/<other>/$tname/; 744 $emote{other} =~ s/<other>/$tname/;
746 $emote{other} =~ s/<self>/$name/; 745 $emote{other} =~ s/<self>/$name/;
747 746
748 send_msg $_, $CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat" 747 send_msg $_, $cf::CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat"
749 for grep { $_ != $pl && $_ != $target && $ob->on_same_map_as ($_->ob) } cf::player::list; 748 for grep { $_ != $pl && $_ != $target && $ob->on_same_map_as ($_->ob) } cf::player::list;
750 749
751 send_msg $target, tell_channel $name, $emote{target}, cf::NDI_GREY, "msg_shout"; 750 send_msg $target, tell_channel $name, $emote{target}, cf::NDI_GREY, "msg_shout";
752 $pl->send_msg (tell_channel $tname, $emote{self}, cf::NDI_GREY | cf::NDI_REPLY); 751 $pl->send_msg (tell_channel $tname, $emote{self}, cf::NDI_GREY | cf::NDI_REPLY);
753 } else { 752 } else {
756 $emote{other} ||= "<self> dances with glee."; 755 $emote{other} ||= "<self> dances with glee.";
757 $emote{self} ||= "You are a nut."; 756 $emote{self} ||= "You are a nut.";
758 757
759 $emote{other} =~ s/<self>/$name/; 758 $emote{other} =~ s/<self>/$name/;
760 759
761 send_msg $_, $CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat" 760 send_msg $_, $cf::CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat"
762 for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl } cf::player::list; 761 for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl } cf::player::list;
763 762
764 $pl->send_msg ($CHAT_CHANNEL, $emote{self}, cf::NDI_GREY | cf::NDI_REPLY); 763 $pl->send_msg ($cf::CHAT_CHANNEL, $emote{self}, cf::NDI_GREY | cf::NDI_REPLY);
765 } 764 }
766 }; 765 };
767 }; 766 };
768} 767}
769 768
770cf::register_command me => sub { 769cf::register_command me => sub {
771 my ($pl, $msg) = @_; 770 my ($pl, $msg) = @_;
772 771
773 my $name = $pl->name; 772 my $name = $pl->name;
774 773
775 send_msg $pl, $SAY_CHANNEL => "* $name $msg", cf::NDI_GREY | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_say" 774 send_msg $_, $cf::SAY_CHANNEL => "* $name $msg", cf::NDI_GREY | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_say"
776 for grep $pl->on_same_map_as ($_->ob), cf::player::list; 775 for grep $pl->on_same_map_as ($_->ob), cf::player::list;
777}; 776};
778 777
779cf::register_command say => sub { 778cf::register_command say => sub {
780 my ($ob, $msg) = @_; 779 my ($ob, $msg) = @_;
785 784
786 if ($msg) { 785 if ($msg) {
787 my $name = $ob->name; 786 my $name = $ob->name;
788 my @plonmap = grep $ob->on_same_map_as ($_->ob), cf::player::list; 787 my @plonmap = grep $ob->on_same_map_as ($_->ob), cf::player::list;
789 788
790 send_msg $_, $SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY, "msg_say" 789 send_msg $_, $cf::SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY, "msg_say"
791 for grep $_ != $ob->contr, @plonmap; 790 for grep $_ != $ob->contr, @plonmap;
792 $ob->contr->send_msg ($SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY | cf::NDI_REPLY); 791 $ob->contr->send_msg ($cf::SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY | cf::NDI_REPLY);
793 792
794 # npcs, magic_ears etc. 793 # npcs, magic_ears etc.
795 # first find all objects and their first-level inventories 794 # first find all objects and their first-level inventories
796 # within a 5x5 square that have something resembling 795 # within a 5x5 square that have something resembling
797 # dialogue or support on_say. 796 # dialogue or support on_say.
798 my ($map, $x, $y) = ($ob->map, $ob->x - 2, $ob->y - 2); 797 my ($map, $x, $y) = ($ob->map, $ob->x - 2, $ob->y - 2);
799 798
800 for my $npc ( 799 for my $npc (
801 grep +($_->invoke (cf::EVENT_OBJECT_SAY, $ob->contr, $msg) && return) || NPC_Dialogue::has_dialogue $_, 800 grep +($_->invoke (cf::EVENT_OBJECT_SAY, $ob->contr, $msg) && return) || $_->has_dialogue,
802 map +($_, $_->inv), 801 map +($_, $_->inv),
803 grep $_, 802 grep $_,
804 map $map->at ($x + $_ % 5, $y + (int $_ / 5)), 803 map $map->at ($x + $_ % 5, $y + (int $_ / 5)),
805 0..24 804 0..24
806 ) { 805 ) {
811 my ($reply, @kw) = $dialog->tell ($msg); 810 my ($reply, @kw) = $dialog->tell ($msg);
812 811
813 if (defined $reply) { 812 if (defined $reply) {
814 if ($npc->type == cf::MAGIC_EAR) { 813 if ($npc->type == cf::MAGIC_EAR) {
815 if (length $reply) { 814 if (length $reply) {
816 send_msg $_, $SAY_CHANNEL => $reply, cf::NDI_BROWN, "msg_say" 815 send_msg $_, $cf::SAY_CHANNEL => $reply, cf::NDI_BROWN, "msg_say"
817 for @plonmap; 816 for @plonmap;
818 } 817 }
819 $npc->use_trigger; 818 $npc->use_trigger;
820 } else { 819 } else {
821 if (length $reply) { 820 if (length $reply) {
822 send_msg $_, $SAY_CHANNEL => $npc->name . " says: $reply", cf::NDI_BROWN, "msg_say" 821 send_msg $_, $cf::SAY_CHANNEL => $npc->name . " says: $reply", cf::NDI_BROWN, "msg_say"
823 for @plonmap; 822 for @plonmap;
824 } 823 }
825 } 824 }
826 } 825 }
827 826
828 if (@kw) { 827 if (@kw) {
829 $_->send_msg ($SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN) 828 $_->send_msg ($cf::SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN)
830 for @plonmap; 829 for @plonmap;
831 } 830 }
832 } 831 }
833 832
834 } else { 833 } else {
835 $ob->send_msg ($SAY_CHANNEL => "What do you want to say?", cf::NDI_GREY | cf::NDI_REPLY); 834 $ob->send_msg ($cf::SAY_CHANNEL => "What do you want to say?", cf::NDI_GREY | cf::NDI_REPLY);
836 } 835 }
837}; 836};
838 837
839cf::register_command chat => sub { 838cf::register_command chat => sub {
840 my ($ob, $msg) = @_; 839 my ($ob, $msg) = @_;
850 my $NOW = time; 849 my $NOW = time;
851 850
852 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; 851 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg;
853 send_irc ("[%s] %s", $name, $msg); 852 send_irc ("[%s] %s", $name, $msg);
854 853
855 send_msg $_, $CHAT_CHANNEL => "$name chats: $msg", cf::NDI_BLUE | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_chat" 854 send_msg $_, $cf::CHAT_CHANNEL => "$name chats: $msg", cf::NDI_BLUE | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_chat"
856 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;
857 856
858 } else { 857 } else {
859 $pl->send_msg ($CHAT_CHANNEL => "Chat what?", cf::NDI_BLUE | cf::NDI_DEF | cf::NDI_REPLY); 858 $pl->send_msg ($cf::CHAT_CHANNEL => "Chat what?", cf::NDI_BLUE | cf::NDI_DEF | cf::NDI_REPLY);
860 } 859 }
861}; 860};
862 861
863cf::register_command shout => sub { 862cf::register_command shout => sub {
864 my ($ob, $msg) = @_; 863 my ($ob, $msg) = @_;
874 my $name = $ob->name; 873 my $name = $ob->name;
875 874
876 cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; 875 cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg;
877 send_irc ("\007\0034{%s} %s\n", $name, $msg); 876 send_irc ("\007\0034{%s} %s\n", $name, $msg);
878 877
879 send_msg $_, $CHAT_CHANNEL => "$name shouts: $msg", cf::NDI_RED | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_shout" 878 send_msg $_, $cf::CHAT_CHANNEL => "$name shouts: $msg", cf::NDI_RED | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_shout"
880 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;
881 880
882 } else { 881 } else {
883 $pl->send_msg ($CHAT_CHANNEL => "Shout what?", cf::NDI_RED | cf::NDI_DEF | cf::NDI_REPLY); 882 $pl->send_msg ($cf::CHAT_CHANNEL => "Shout what?", cf::NDI_RED | cf::NDI_DEF | cf::NDI_REPLY);
884 } 883 }
885}; 884};
886 885
887cf::register_command tell => sub { 886cf::register_command tell => sub {
888 my ($ob, $args) = @_; 887 my ($ob, $args) = @_;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines