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.33 by root, Wed Sep 19 21:56:30 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 {
27 id => "tell-$target", 13 id => "tell-$target",
28 title => "$target", 14 title => "$target",
29 reply => "tell $target ", 15 reply => "tell $target ",
30 tooltip => "Private messages from/to $target", 16 tooltip => "Private messages from/to $target",
31 } 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 ()
32} 25}
33 26
34sub clean_timeouts($) { 27sub clean_timeouts($) {
35 my ($player) = @_; 28 my ($player) = @_;
36 my $NOW = time; 29 my $NOW = time;
63 on_login => sub { 56 on_login => sub {
64 my ($pl) = @_; 57 my ($pl) = @_;
65 58
66 clean_timeouts $pl->ob; 59 clean_timeouts $pl->ob;
67 60
68 $pl->send_msg ($SAY_CHANNEL); 61 $pl->send_msg ($cf::SAY_CHANNEL);
69 $pl->send_msg ($CHAT_CHANNEL); 62 $pl->send_msg ($cf::CHAT_CHANNEL);
70 }, 63 },
71); 64);
72 65
73cf::register_command listen => sub { 66cf::register_command listen => sub {
74 my ($pl, $msg) = @_; 67 my ($pl, $msg) = @_;
95 my $pl = $ob->contr; 88 my $pl = $ob->contr;
96 my $name = $ob->name; 89 my $name = $ob->name;
97 90
98 my $coin = int rand 2 ? "Heads" : "Tails"; 91 my $coin = int rand 2 ? "Heads" : "Tails";
99 92
100 $_->send_msg ($SAY_CHANNEL => "$name flips a coin.... $coin!", cf::NDI_GREY) 93 send_msg $_, $cf::SAY_CHANNEL => "$name flips a coin.... $coin!", cf::NDI_GREY, "msg_say"
101 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;
102 95
103 $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);
104}; 97};
105 98
106cf::register_command orcknuckle => sub { 99cf::register_command orcknuckle => sub {
107 my ($ob, $msg) = @_; 100 my ($ob, $msg) = @_;
108 101
111 104
112 my @orcknuckle = ("beholder", "ghost", "knight", "princess", "dragon", "orc"); 105 my @orcknuckle = ("beholder", "ghost", "knight", "princess", "dragon", "orc");
113 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);
114 my $result = "$orcknuckle[$i], $orcknuckle[$j], $orcknuckle[$k], $orcknuckle[$l]"; 107 my $result = "$orcknuckle[$i], $orcknuckle[$j], $orcknuckle[$k], $orcknuckle[$l]";
115 108
116 $_->send_msg ($SAY_CHANNEL => "$name throws his orc-knuckles and rolls $result!", cf::NDI_GREY) 109 send_msg $_, $cf::SAY_CHANNEL => "$name throws his orc-knuckles and rolls $result!", cf::NDI_GREY, "msg_say"
117 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;
118 111
119 $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);
120}; 113};
121 114
122my $emotes = { 115my $emotes = {
123 growl => { 116 growl => {
124 noparams => { 117 noparams => {
244 }, 237 },
245 params => { 238 params => {
246 target => "<self> kisses you.", 239 target => "<self> kisses you.",
247 other => "<self> kisses <other>.", 240 other => "<self> kisses <other>.",
248 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.",
249 }, 255 },
250 self => { 256 self => {
251 }, 257 },
252 }, 258 },
253 wink => { 259 wink => {
717 $emote{other} ||= "You look away from <self>."; 723 $emote{other} ||= "You look away from <self>.";
718 $emote{self} ||= "My god! Is that LEGAL?"; 724 $emote{self} ||= "My god! Is that LEGAL?";
719 725
720 $emote{other} =~ s/<self>/$name/; 726 $emote{other} =~ s/<self>/$name/;
721 727
722 $_->send_msg ($CHAT_CHANNEL, $emote{other}, cf::NDI_GREY) 728 send_msg $_, $cf::CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat"
723 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;
724 730
725 $pl->send_msg ($emote{self}, cf::NDI_GREY | cf::NDI_REPLY); 731 $pl->send_msg ($emote{self}, cf::NDI_GREY | cf::NDI_REPLY);
726 } elsif ($tname) { 732 } elsif ($tname) {
727 my $target = cf::player::find $tname 733 my $target = cf::player::find $tname
728 or return $pl->send_msg (tell_channel $tname, "$tname is not around.", cf::NDI_DK_ORANGE | cf::NDI_REPLY); 734 or return send_msg $pl, tell_channel $tname, "$tname is not around.", cf::NDI_DK_ORANGE | cf::NDI_REPLY, "msg_chat";
729 735
730 my %emote = %{ $emotes->{$emotion}->{params} || {} }; 736 my %emote = %{ $emotes->{$emotion}->{params} || {} };
731 737
732 $emote{other} ||= "<self> is eyeing <other> quizzically."; 738 $emote{other} ||= "<self> is eyeing <other> quizzically.";
733 $emote{self} ||= "You are still nuts."; 739 $emote{self} ||= "You are still nuts.";
734 $emote{target} ||= "You get the distinct feeling that <other> is nuts."; 740 $emote{target} ||= "You get the distinct feeling that <self> is nuts.";
735 741
736 $emote{self} =~ s/<other>/$tname/; 742 $emote{self} =~ s/<other>/$tname/;
737 $emote{target} =~ s/<self>/$name/; 743 $emote{target} =~ s/<self>/$name/;
738 $emote{other} =~ s/<other>/$tname/; 744 $emote{other} =~ s/<other>/$tname/;
739 $emote{other} =~ s/<self>/$name/; 745 $emote{other} =~ s/<self>/$name/;
740 746
741 $_->send_msg ($CHAT_CHANNEL, $emote{other}, cf::NDI_GREY) 747 send_msg $_, $cf::CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat"
742 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;
743 749
744 $target->send_msg (tell_channel $name, $emote{target}, cf::NDI_GREY); 750 send_msg $target, tell_channel $name, $emote{target}, cf::NDI_GREY, "msg_shout";
745 $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);
746 } else { 752 } else {
747 my %emote = %{ $emotes->{$emotion}->{noparams} || {} }; 753 my %emote = %{ $emotes->{$emotion}->{noparams} || {} };
748 754
749 $emote{other} ||= "<self> dances with glee."; 755 $emote{other} ||= "<self> dances with glee.";
750 $emote{self} ||= "You are a nut."; 756 $emote{self} ||= "You are a nut.";
751 757
752 $emote{other} =~ s/<self>/$name/; 758 $emote{other} =~ s/<self>/$name/;
753 759
754 $_->send_msg ($CHAT_CHANNEL, $emote{other}, cf::NDI_GREY) 760 send_msg $_, $cf::CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat"
755 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;
756 762
757 $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);
758 } 764 }
759 }; 765 };
760 }; 766 };
761} 767}
762 768
763cf::register_command me => sub { 769cf::register_command me => sub {
764 my ($pl, $msg) = @_; 770 my ($pl, $msg) = @_;
765 771
766 my $name = $pl->name; 772 my $name = $pl->name;
767 773
768 $_->send_msg ($SAY_CHANNEL => "* $name $msg", cf::NDI_GREY | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0)) 774 send_msg $_, $cf::SAY_CHANNEL => "* $name $msg", cf::NDI_GREY | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_say"
769 for grep $pl->on_same_map_as ($_->ob), cf::player::list; 775 for grep $pl->on_same_map_as ($_->ob), cf::player::list;
770}; 776};
771 777
772cf::register_command say => sub { 778cf::register_command say => sub {
773 my ($ob, $msg) = @_; 779 my ($ob, $msg) = @_;
778 784
779 if ($msg) { 785 if ($msg) {
780 my $name = $ob->name; 786 my $name = $ob->name;
781 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;
782 788
789 send_msg $_, $cf::SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY, "msg_say"
790 for grep $_ != $ob->contr, @plonmap;
783 $_->send_msg ($SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY | ($_ == $ob->contr ? cf::NDI_REPLY : 0)) 791 $ob->contr->send_msg ($cf::SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY | cf::NDI_REPLY);
784 for @plonmap;
785 792
786 # npcs, magic_ears etc. 793 # npcs, magic_ears etc.
787 # first find all objects and their first-level inventories 794 # first find all objects and their first-level inventories
788 # within a 5x5 square that have something resembling 795 # within a 5x5 square that have something resembling
789 # dialogue or support on_say. 796 # dialogue or support on_say.
790 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);
791 798
792 for my $npc ( 799 for my $npc (
793 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,
794 map +($_, $_->inv), 801 map +($_, $_->inv),
795 grep $_, 802 grep $_,
796 map $map->at ($x + $_ % 5, $y + (int $_ / 5)), 803 map $map->at ($x + $_ % 5, $y + (int $_ / 5)),
797 0..24 804 0..24
798 ) { 805 ) {
803 my ($reply, @kw) = $dialog->tell ($msg); 810 my ($reply, @kw) = $dialog->tell ($msg);
804 811
805 if (defined $reply) { 812 if (defined $reply) {
806 if ($npc->type == cf::MAGIC_EAR) { 813 if ($npc->type == cf::MAGIC_EAR) {
807 if (length $reply) { 814 if (length $reply) {
808 $_->send_msg ($SAY_CHANNEL => $reply, cf::NDI_BROWN) 815 send_msg $_, $cf::SAY_CHANNEL => $reply, cf::NDI_BROWN, "msg_say"
809 for @plonmap; 816 for @plonmap;
810 } 817 }
811 $npc->use_trigger; 818 $npc->use_trigger;
812 } else { 819 } else {
813 if (length $reply) { 820 if (length $reply) {
814 $_->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"
815 for @plonmap; 822 for @plonmap;
816 } 823 }
817 } 824 }
818 } 825 }
819 826
820 if (@kw) { 827 if (@kw) {
821 $_->send_msg ($SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN) 828 $_->send_msg ($cf::SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN)
822 for @plonmap; 829 for @plonmap;
823 } 830 }
824 } 831 }
825 832
826 } else { 833 } else {
827 $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);
828 } 835 }
829}; 836};
830 837
831cf::register_command chat => sub { 838cf::register_command chat => sub {
832 my ($ob, $msg) = @_; 839 my ($ob, $msg) = @_;
842 my $NOW = time; 849 my $NOW = time;
843 850
844 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; 851 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg;
845 send_irc ("[%s] %s", $name, $msg); 852 send_irc ("[%s] %s", $name, $msg);
846 853
847 $_->send_msg ($CHAT_CHANNEL => "$name chats: $msg", cf::NDI_BLUE | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0)) 854 send_msg $_, $cf::CHAT_CHANNEL => "$name chats: $msg", cf::NDI_BLUE | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_chat"
848 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;
849 856
850 } else { 857 } else {
851 $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);
852 } 859 }
853}; 860};
854 861
855cf::register_command shout => sub { 862cf::register_command shout => sub {
856 my ($ob, $msg) = @_; 863 my ($ob, $msg) = @_;
866 my $name = $ob->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 $_->send_msg ($CHAT_CHANNEL => "$name shouts: $msg", cf::NDI_RED | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0)) 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->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);
876 } 883 }
877}; 884};
878 885
879cf::register_command tell => sub { 886cf::register_command tell => sub {
880 my ($ob, $args) = @_; 887 my ($ob, $args) = @_;
907 } else { 914 } else {
908 return if $other->invoke (cf::EVENT_PLAYER_TOLD, $pl, $msg); 915 return if $other->invoke (cf::EVENT_PLAYER_TOLD, $pl, $msg);
909 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;
910 917
911 $ns->send_msg ($pl_channel => "You tell $target: $msg", cf::NDI_DK_ORANGE | cf::NDI_DEF | cf::NDI_REPLY); 918 $ns->send_msg ($pl_channel => "You tell $target: $msg", cf::NDI_DK_ORANGE | cf::NDI_DEF | cf::NDI_REPLY);
912 $other->send_msg ($other_channel => "$name tells you: $msg", cf::NDI_DK_ORANGE | cf::NDI_DEF); 919 send_msg $other, $other_channel => "$name tells you: $msg", cf::NDI_DK_ORANGE | cf::NDI_DEF, "msg_tell";
913 } 920 }
914 } else { 921 } else {
915 $ns->send_msg ($pl_channel => "What do you want to tell $target?", cf::NDI_DK_ORANGE | cf::NDI_DEF | cf::NDI_REPLY); 922 $ns->send_msg ($pl_channel => "What do you want to tell $target?", cf::NDI_DK_ORANGE | cf::NDI_DEF | cf::NDI_REPLY);
916 } 923 }
917 924

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines