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.32 by root, Sun Sep 2 08:43:46 2007 UTC vs.
Revision 1.40 by root, Thu May 1 06:33:19 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 => {
707 713
708 my $pl = $ob->contr; 714 my $pl = $ob->contr;
709 715
710 cf::async { 716 cf::async {
711 my $name = $ob->name; 717 my $name = $ob->name;
718 $Coro::current->{desc} = "emote handler for $name";
712 719
713 if ($tname eq $name) { 720 if ($tname eq $name) {
714 my %emote = %{ $emotes->{$emotion}->{self} || {} }; 721 my %emote = %{ $emotes->{$emotion}->{self} || {} };
715 722
716 $emote{other} ||= "You look away from <self>."; 723 $emote{other} ||= "You look away from <self>.";
717 $emote{self} ||= "My god! Is that LEGAL?"; 724 $emote{self} ||= "My god! Is that LEGAL?";
718 725
719 $emote{other} =~ s/<self>/$name/; 726 $emote{other} =~ s/<self>/$name/;
720 727
721 $_->send_msg ($CHAT_CHANNEL, $emote{other}, cf::NDI_GREY) 728 send_msg $_, $cf::CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat"
722 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;
723 730
724 $pl->send_msg ($emote{self}, cf::NDI_GREY | cf::NDI_REPLY); 731 $pl->send_msg ($emote{self}, cf::NDI_GREY | cf::NDI_REPLY);
725 } elsif ($tname) { 732 } elsif ($tname) {
726 my $target = cf::player::find $tname 733 my $target = cf::player::find $tname
727 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";
728 735
729 my %emote = %{ $emotes->{$emotion}->{params} || {} }; 736 my %emote = %{ $emotes->{$emotion}->{params} || {} };
730 737
731 $emote{other} ||= "<self> is eyeing <other> quizzically."; 738 $emote{other} ||= "<self> is eyeing <other> quizzically.";
732 $emote{self} ||= "You are still nuts."; 739 $emote{self} ||= "You are still nuts.";
733 $emote{target} ||= "You get the distinct feeling that <other> is nuts."; 740 $emote{target} ||= "You get the distinct feeling that <self> is nuts.";
734 741
735 $emote{self} =~ s/<other>/$tname/; 742 $emote{self} =~ s/<other>/$tname/;
736 $emote{target} =~ s/<self>/$name/; 743 $emote{target} =~ s/<self>/$name/;
737 $emote{other} =~ s/<other>/$tname/; 744 $emote{other} =~ s/<other>/$tname/;
738 $emote{other} =~ s/<self>/$name/; 745 $emote{other} =~ s/<self>/$name/;
739 746
740 $_->send_msg ($CHAT_CHANNEL, $emote{other}, cf::NDI_GREY) 747 send_msg $_, $cf::CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat"
741 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;
742 749
743 $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";
744 $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);
745 } else { 752 } else {
746 my %emote = %{ $emotes->{$emotion}->{noparams} || {} }; 753 my %emote = %{ $emotes->{$emotion}->{noparams} || {} };
747 754
748 $emote{other} ||= "<self> dances with glee."; 755 $emote{other} ||= "<self> dances with glee.";
749 $emote{self} ||= "You are a nut."; 756 $emote{self} ||= "You are a nut.";
750 757
751 $emote{other} =~ s/<self>/$name/; 758 $emote{other} =~ s/<self>/$name/;
752 759
753 $_->send_msg ($CHAT_CHANNEL, $emote{other}, cf::NDI_GREY) 760 send_msg $_, $cf::CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat"
754 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;
755 762
756 $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);
757 } 764 }
758 }; 765 };
759 }; 766 };
760} 767}
761 768
762cf::register_command me => sub { 769cf::register_command me => sub {
763 my ($pl, $msg) = @_; 770 my ($pl, $msg) = @_;
764 771
765 my $name = $pl->name; 772 my $name = $pl->name;
766 773
767 $_->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"
768 for grep $pl->on_same_map_as ($_->ob), cf::player::list; 775 for grep $pl->on_same_map_as ($_->ob), cf::player::list;
769}; 776};
770 777
771cf::register_command say => sub { 778cf::register_command say => sub {
772 my ($ob, $msg) = @_; 779 my ($ob, $msg) = @_;
777 784
778 if ($msg) { 785 if ($msg) {
779 my $name = $ob->name; 786 my $name = $ob->name;
780 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;
781 788
789 send_msg $_, $cf::SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY, "msg_say"
790 for grep $_ != $ob->contr, @plonmap;
782 $_->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);
783 for @plonmap;
784 792
785 # npcs, magic_ears etc. 793 # npcs, magic_ears etc.
786 # first find all objects and their first-level inventories 794 # first find all objects and their first-level inventories
787 # within a 5x5 square that have something resembling 795 # within a 5x5 square that have something resembling
788 # dialogue or support on_say. 796 # dialogue or support on_say.
802 my ($reply, @kw) = $dialog->tell ($msg); 810 my ($reply, @kw) = $dialog->tell ($msg);
803 811
804 if (defined $reply) { 812 if (defined $reply) {
805 if ($npc->type == cf::MAGIC_EAR) { 813 if ($npc->type == cf::MAGIC_EAR) {
806 if (length $reply) { 814 if (length $reply) {
807 $_->send_msg ($SAY_CHANNEL => $reply, cf::NDI_BROWN) 815 send_msg $_, $cf::SAY_CHANNEL => $reply, cf::NDI_BROWN, "msg_say"
808 for @plonmap; 816 for @plonmap;
809 } 817 }
810 $npc->use_trigger; 818 $npc->use_trigger;
811 } else { 819 } else {
812 if (length $reply) { 820 if (length $reply) {
813 $_->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"
814 for @plonmap; 822 for @plonmap;
815 } 823 }
816 } 824 }
817 } 825 }
818 826
819 if (@kw) { 827 if (@kw) {
820 $_->send_msg ($SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN) 828 $_->send_msg ($cf::SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN)
821 for @plonmap; 829 for @plonmap;
822 } 830 }
823 } 831 }
824 832
825 } else { 833 } else {
826 $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);
827 } 835 }
828}; 836};
829 837
830cf::register_command chat => sub { 838cf::register_command chat => sub {
831 my ($ob, $msg) = @_; 839 my ($ob, $msg) = @_;
841 my $NOW = time; 849 my $NOW = time;
842 850
843 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; 851 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg;
844 send_irc ("[%s] %s", $name, $msg); 852 send_irc ("[%s] %s", $name, $msg);
845 853
846 $_->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"
847 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;
848 856
849 } else { 857 } else {
850 $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);
851 } 859 }
852}; 860};
853 861
854cf::register_command shout => sub { 862cf::register_command shout => sub {
855 my ($ob, $msg) = @_; 863 my ($ob, $msg) = @_;
865 my $name = $ob->name; 873 my $name = $ob->name;
866 874
867 cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; 875 cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg;
868 send_irc ("\007\0034{%s} %s\n", $name, $msg); 876 send_irc ("\007\0034{%s} %s\n", $name, $msg);
869 877
870 $_->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"
871 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;
872 880
873 } else { 881 } else {
874 $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);
875 } 883 }
876}; 884};
877 885
878cf::register_command tell => sub { 886cf::register_command tell => sub {
879 my ($ob, $args) = @_; 887 my ($ob, $args) = @_;
906 } else { 914 } else {
907 return if $other->invoke (cf::EVENT_PLAYER_TOLD, $pl, $msg); 915 return if $other->invoke (cf::EVENT_PLAYER_TOLD, $pl, $msg);
908 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;
909 917
910 $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);
911 $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";
912 } 920 }
913 } else { 921 } else {
914 $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);
915 } 923 }
916 924

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines