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.42 by root, Fri Aug 29 02:07:09 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
66# TODO: remove once safe
80cf::register_command listen => sub { 67cf::register_command listen => sub {
81 my ($pl, $msg) = @_;
82 my $player = cf::player::find_active $pl->name;
83
84 if ($msg ne "") {
85 $msg = 10 if $msg > 10;
86
87 my $prev_listen = $player->listening;
88 $player->listening ($msg);
89 if ($prev_listen == $player->listening) {
90 $pl->message ("Your verbose level stays at $prev_listen.", cf::NDI_REPLY);
91 } else {
92 $pl->message ("Your verbose level is now " . $player->listening . ". (previously: $prev_listen)", cf::NDI_REPLY);
93 }
94 } else {
95 $pl->message ("Your verbose level is " . $player->listening . ".", cf::NDI_REPLY);
96 }
97}; 68};
98 69
99cf::register_command cointoss => sub { 70cf::register_command cointoss => sub {
100 my ($ob, $msg) = @_; 71 my ($ob, $msg) = @_;
101 72
102 my $pl = $ob->contr; 73 my $pl = $ob->contr;
103 my $name = $ob->name; 74 my $name = $ob->name;
104 75
105 my $coin = int rand 2 ? "Heads" : "Tails"; 76 my $coin = int rand 2 ? "Heads" : "Tails";
106 77
107 send_msg $_, $SAY_CHANNEL => "$name flips a coin.... $coin!", cf::NDI_GREY, "msg_say" 78 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; 79 for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl} cf::player::list;
109 80
110 $pl->send_msg ($SAY_CHANNEL => "You flip a coin.... $coin!", cf::NDI_GREY | cf::NDI_REPLY); 81 $pl->send_msg ($cf::SAY_CHANNEL => "You flip a coin.... $coin!", cf::NDI_GREY | cf::NDI_REPLY);
111}; 82};
112 83
113cf::register_command orcknuckle => sub { 84cf::register_command orcknuckle => sub {
114 my ($ob, $msg) = @_; 85 my ($ob, $msg) = @_;
115 86
118 89
119 my @orcknuckle = ("beholder", "ghost", "knight", "princess", "dragon", "orc"); 90 my @orcknuckle = ("beholder", "ghost", "knight", "princess", "dragon", "orc");
120 my ($i, $j, $k, $l) = (rand 5, rand 5, rand 5, rand 6); 91 my ($i, $j, $k, $l) = (rand 5, rand 5, rand 5, rand 6);
121 my $result = "$orcknuckle[$i], $orcknuckle[$j], $orcknuckle[$k], $orcknuckle[$l]"; 92 my $result = "$orcknuckle[$i], $orcknuckle[$j], $orcknuckle[$k], $orcknuckle[$l]";
122 93
123 send_msg $_, $SAY_CHANNEL => "$name throws his orc-knuckles and rolls $result!", cf::NDI_GREY, "msg_say" 94 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; 95 for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl} cf::player::list;
125 96
126 $pl->send_msg ($SAY_CHANNEL => "You roll $result!", cf::NDI_GREY | cf::NDI_REPLY); 97 $pl->send_msg ($cf::SAY_CHANNEL => "You roll $result!", cf::NDI_GREY | cf::NDI_REPLY);
127}; 98};
128 99
129my $emotes = { 100my $emotes = {
130 growl => { 101 growl => {
131 noparams => { 102 noparams => {
251 }, 222 },
252 params => { 223 params => {
253 target => "<self> kisses you.", 224 target => "<self> kisses you.",
254 other => "<self> kisses <other>.", 225 other => "<self> kisses <other>.",
255 self => "You kiss <other>.", 226 self => "You kiss <other>.",
227 },
228 self => {
229 },
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.",
256 }, 240 },
257 self => { 241 self => {
258 }, 242 },
259 }, 243 },
260 wink => { 244 wink => {
724 $emote{other} ||= "You look away from <self>."; 708 $emote{other} ||= "You look away from <self>.";
725 $emote{self} ||= "My god! Is that LEGAL?"; 709 $emote{self} ||= "My god! Is that LEGAL?";
726 710
727 $emote{other} =~ s/<self>/$name/; 711 $emote{other} =~ s/<self>/$name/;
728 712
729 send_msg $_, $CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat" 713 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; 714 for grep { $ob->on_same_map_as ($_->ob) && $_ != $ob} cf::player::list;
731 715
732 $pl->send_msg ($emote{self}, cf::NDI_GREY | cf::NDI_REPLY); 716 $pl->send_msg ($emote{self}, cf::NDI_GREY | cf::NDI_REPLY);
733 } elsif ($tname) { 717 } elsif ($tname) {
734 my $target = cf::player::find $tname 718 my $target = cf::player::find $tname
736 720
737 my %emote = %{ $emotes->{$emotion}->{params} || {} }; 721 my %emote = %{ $emotes->{$emotion}->{params} || {} };
738 722
739 $emote{other} ||= "<self> is eyeing <other> quizzically."; 723 $emote{other} ||= "<self> is eyeing <other> quizzically.";
740 $emote{self} ||= "You are still nuts."; 724 $emote{self} ||= "You are still nuts.";
741 $emote{target} ||= "You get the distinct feeling that <other> is nuts."; 725 $emote{target} ||= "You get the distinct feeling that <self> is nuts.";
742 726
743 $emote{self} =~ s/<other>/$tname/; 727 $emote{self} =~ s/<other>/$tname/;
744 $emote{target} =~ s/<self>/$name/; 728 $emote{target} =~ s/<self>/$name/;
745 $emote{other} =~ s/<other>/$tname/; 729 $emote{other} =~ s/<other>/$tname/;
746 $emote{other} =~ s/<self>/$name/; 730 $emote{other} =~ s/<self>/$name/;
747 731
748 send_msg $_, $CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat" 732 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; 733 for grep { $_ != $pl && $_ != $target && $ob->on_same_map_as ($_->ob) } cf::player::list;
750 734
751 send_msg $target, tell_channel $name, $emote{target}, cf::NDI_GREY, "msg_shout"; 735 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); 736 $pl->send_msg (tell_channel $tname, $emote{self}, cf::NDI_GREY | cf::NDI_REPLY);
753 } else { 737 } else {
756 $emote{other} ||= "<self> dances with glee."; 740 $emote{other} ||= "<self> dances with glee.";
757 $emote{self} ||= "You are a nut."; 741 $emote{self} ||= "You are a nut.";
758 742
759 $emote{other} =~ s/<self>/$name/; 743 $emote{other} =~ s/<self>/$name/;
760 744
761 send_msg $_, $CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat" 745 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; 746 for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl } cf::player::list;
763 747
764 $pl->send_msg ($CHAT_CHANNEL, $emote{self}, cf::NDI_GREY | cf::NDI_REPLY); 748 $pl->send_msg ($cf::CHAT_CHANNEL, $emote{self}, cf::NDI_GREY | cf::NDI_REPLY);
765 } 749 }
766 }; 750 };
767 }; 751 };
768} 752}
769 753
770cf::register_command me => sub { 754cf::register_command me => sub {
771 my ($pl, $msg) = @_; 755 my ($pl, $msg) = @_;
772 756
773 my $name = $pl->name; 757 my $name = $pl->name;
774 758
775 send_msg $pl, $SAY_CHANNEL => "* $name $msg", cf::NDI_GREY | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_say" 759 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; 760 for grep $pl->on_same_map_as ($_->ob), cf::player::list;
777}; 761};
778 762
779cf::register_command say => sub { 763cf::register_command say => sub {
780 my ($ob, $msg) = @_; 764 my ($ob, $msg) = @_;
785 769
786 if ($msg) { 770 if ($msg) {
787 my $name = $ob->name; 771 my $name = $ob->name;
788 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;
789 773
790 send_msg $_, $SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY, "msg_say" 774 send_msg $_, $cf::SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY, "msg_say"
791 for grep $_ != $ob->contr, @plonmap; 775 for grep $_ != $ob->contr, @plonmap;
792 $ob->contr->send_msg ($SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY | cf::NDI_REPLY); 776 $ob->contr->send_msg ($cf::SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY | cf::NDI_REPLY);
793 777
794 # npcs, magic_ears etc. 778 # npcs, magic_ears etc.
795 # first find all objects and their first-level inventories 779 # first find all objects and their first-level inventories
796 # within a 5x5 square that have something resembling 780 # within a 5x5 square that have something resembling
797 # dialogue or support on_say. 781 # dialogue or support on_say.
798 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);
799 783
800 for my $npc ( 784 for my $npc (
801 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,
802 map +($_, $_->inv), 786 map +($_, $_->inv),
803 grep $_, 787 grep $_,
804 map $map->at ($x + $_ % 5, $y + (int $_ / 5)), 788 map $map->at ($x + $_ % 5, $y + (int $_ / 5)),
805 0..24 789 0..24
806 ) { 790 ) {
811 my ($reply, @kw) = $dialog->tell ($msg); 795 my ($reply, @kw) = $dialog->tell ($msg);
812 796
813 if (defined $reply) { 797 if (defined $reply) {
814 if ($npc->type == cf::MAGIC_EAR) { 798 if ($npc->type == cf::MAGIC_EAR) {
815 if (length $reply) { 799 if (length $reply) {
816 send_msg $_, $SAY_CHANNEL => $reply, cf::NDI_BROWN, "msg_say" 800 send_msg $_, $cf::SAY_CHANNEL => $reply, cf::NDI_BROWN, "msg_say"
817 for @plonmap; 801 for @plonmap;
818 } 802 }
819 $npc->use_trigger; 803 $npc->use_trigger;
820 } else { 804 } else {
821 if (length $reply) { 805 if (length $reply) {
822 send_msg $_, $SAY_CHANNEL => $npc->name . " says: $reply", cf::NDI_BROWN, "msg_say" 806 send_msg $_, $cf::SAY_CHANNEL => $npc->name . " says: $reply", cf::NDI_BROWN, "msg_say"
823 for @plonmap; 807 for @plonmap;
824 } 808 }
825 } 809 }
826 } 810 }
827 811
828 if (@kw) { 812 if (@kw) {
829 $_->send_msg ($SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN) 813 $_->send_msg ($cf::SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN)
830 for @plonmap; 814 for @plonmap;
831 } 815 }
832 } 816 }
833 817
834 } else { 818 } else {
835 $ob->send_msg ($SAY_CHANNEL => "What do you want to say?", cf::NDI_GREY | cf::NDI_REPLY); 819 $ob->send_msg ($cf::SAY_CHANNEL => "What do you want to say?", cf::NDI_GREY | cf::NDI_REPLY);
836 } 820 }
837}; 821};
838 822
839cf::register_command chat => sub { 823cf::register_command chat => sub {
840 my ($ob, $msg) = @_; 824 my ($ob, $msg) = @_;
850 my $NOW = time; 834 my $NOW = time;
851 835
852 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; 836 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg;
853 send_irc ("[%s] %s", $name, $msg); 837 send_irc ("[%s] %s", $name, $msg);
854 838
855 send_msg $_, $CHAT_CHANNEL => "$name chats: $msg", cf::NDI_BLUE | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_chat" 839 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; 840 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list;
857 841
858 } else { 842 } else {
859 $pl->send_msg ($CHAT_CHANNEL => "Chat what?", cf::NDI_BLUE | cf::NDI_DEF | cf::NDI_REPLY); 843 $pl->send_msg ($cf::CHAT_CHANNEL => "Chat what?", cf::NDI_BLUE | cf::NDI_DEF | cf::NDI_REPLY);
860 } 844 }
861}; 845};
862 846
863cf::register_command shout => sub { 847cf::register_command shout => sub {
864 my ($ob, $msg) = @_; 848 my ($ob, $msg) = @_;
874 my $name = $ob->name; 858 my $name = $ob->name;
875 859
876 cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; 860 cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg;
877 send_irc ("\007\0034{%s} %s\n", $name, $msg); 861 send_irc ("\007\0034{%s} %s\n", $name, $msg);
878 862
879 send_msg $_, $CHAT_CHANNEL => "$name shouts: $msg", cf::NDI_RED | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_shout" 863 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; 864 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list;
881 865
882 } else { 866 } else {
883 $pl->send_msg ($CHAT_CHANNEL => "Shout what?", cf::NDI_RED | cf::NDI_DEF | cf::NDI_REPLY); 867 $pl->send_msg ($cf::CHAT_CHANNEL => "Shout what?", cf::NDI_RED | cf::NDI_DEF | cf::NDI_REPLY);
884 } 868 }
885}; 869};
886 870
887cf::register_command tell => sub { 871cf::register_command tell => sub {
888 my ($ob, $args) = @_; 872 my ($ob, $args) = @_;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines