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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines