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.39 by root, Fri Apr 11 01:15:49 2008 UTC vs.
Revision 1.40 by root, Thu May 1 06:33:19 2008 UTC

3# implement a replacement for the built-in say/chat/shout/tell 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 => {
737 $emote{other} ||= "You look away from <self>."; 723 $emote{other} ||= "You look away from <self>.";
738 $emote{self} ||= "My god! Is that LEGAL?"; 724 $emote{self} ||= "My god! Is that LEGAL?";
739 725
740 $emote{other} =~ s/<self>/$name/; 726 $emote{other} =~ s/<self>/$name/;
741 727
742 send_msg $_, $CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat" 728 send_msg $_, $cf::CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat"
743 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;
744 730
745 $pl->send_msg ($emote{self}, cf::NDI_GREY | cf::NDI_REPLY); 731 $pl->send_msg ($emote{self}, cf::NDI_GREY | cf::NDI_REPLY);
746 } elsif ($tname) { 732 } elsif ($tname) {
747 my $target = cf::player::find $tname 733 my $target = cf::player::find $tname
756 $emote{self} =~ s/<other>/$tname/; 742 $emote{self} =~ s/<other>/$tname/;
757 $emote{target} =~ s/<self>/$name/; 743 $emote{target} =~ s/<self>/$name/;
758 $emote{other} =~ s/<other>/$tname/; 744 $emote{other} =~ s/<other>/$tname/;
759 $emote{other} =~ s/<self>/$name/; 745 $emote{other} =~ s/<self>/$name/;
760 746
761 send_msg $_, $CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat" 747 send_msg $_, $cf::CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat"
762 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;
763 749
764 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";
765 $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);
766 } else { 752 } else {
769 $emote{other} ||= "<self> dances with glee."; 755 $emote{other} ||= "<self> dances with glee.";
770 $emote{self} ||= "You are a nut."; 756 $emote{self} ||= "You are a nut.";
771 757
772 $emote{other} =~ s/<self>/$name/; 758 $emote{other} =~ s/<self>/$name/;
773 759
774 send_msg $_, $CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat" 760 send_msg $_, $cf::CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat"
775 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;
776 762
777 $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);
778 } 764 }
779 }; 765 };
780 }; 766 };
781} 767}
782 768
783cf::register_command me => sub { 769cf::register_command me => sub {
784 my ($pl, $msg) = @_; 770 my ($pl, $msg) = @_;
785 771
786 my $name = $pl->name; 772 my $name = $pl->name;
787 773
788 send_msg $_, $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"
789 for grep $pl->on_same_map_as ($_->ob), cf::player::list; 775 for grep $pl->on_same_map_as ($_->ob), cf::player::list;
790}; 776};
791 777
792cf::register_command say => sub { 778cf::register_command say => sub {
793 my ($ob, $msg) = @_; 779 my ($ob, $msg) = @_;
798 784
799 if ($msg) { 785 if ($msg) {
800 my $name = $ob->name; 786 my $name = $ob->name;
801 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;
802 788
803 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"
804 for grep $_ != $ob->contr, @plonmap; 790 for grep $_ != $ob->contr, @plonmap;
805 $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);
806 792
807 # npcs, magic_ears etc. 793 # npcs, magic_ears etc.
808 # first find all objects and their first-level inventories 794 # first find all objects and their first-level inventories
809 # within a 5x5 square that have something resembling 795 # within a 5x5 square that have something resembling
810 # dialogue or support on_say. 796 # dialogue or support on_say.
824 my ($reply, @kw) = $dialog->tell ($msg); 810 my ($reply, @kw) = $dialog->tell ($msg);
825 811
826 if (defined $reply) { 812 if (defined $reply) {
827 if ($npc->type == cf::MAGIC_EAR) { 813 if ($npc->type == cf::MAGIC_EAR) {
828 if (length $reply) { 814 if (length $reply) {
829 send_msg $_, $SAY_CHANNEL => $reply, cf::NDI_BROWN, "msg_say" 815 send_msg $_, $cf::SAY_CHANNEL => $reply, cf::NDI_BROWN, "msg_say"
830 for @plonmap; 816 for @plonmap;
831 } 817 }
832 $npc->use_trigger; 818 $npc->use_trigger;
833 } else { 819 } else {
834 if (length $reply) { 820 if (length $reply) {
835 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"
836 for @plonmap; 822 for @plonmap;
837 } 823 }
838 } 824 }
839 } 825 }
840 826
841 if (@kw) { 827 if (@kw) {
842 $_->send_msg ($SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN) 828 $_->send_msg ($cf::SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN)
843 for @plonmap; 829 for @plonmap;
844 } 830 }
845 } 831 }
846 832
847 } else { 833 } else {
848 $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);
849 } 835 }
850}; 836};
851 837
852cf::register_command chat => sub { 838cf::register_command chat => sub {
853 my ($ob, $msg) = @_; 839 my ($ob, $msg) = @_;
863 my $NOW = time; 849 my $NOW = time;
864 850
865 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; 851 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg;
866 send_irc ("[%s] %s", $name, $msg); 852 send_irc ("[%s] %s", $name, $msg);
867 853
868 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"
869 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;
870 856
871 } else { 857 } else {
872 $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);
873 } 859 }
874}; 860};
875 861
876cf::register_command shout => sub { 862cf::register_command shout => sub {
877 my ($ob, $msg) = @_; 863 my ($ob, $msg) = @_;
887 my $name = $ob->name; 873 my $name = $ob->name;
888 874
889 cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; 875 cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg;
890 send_irc ("\007\0034{%s} %s\n", $name, $msg); 876 send_irc ("\007\0034{%s} %s\n", $name, $msg);
891 877
892 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"
893 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;
894 880
895 } else { 881 } else {
896 $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);
897 } 883 }
898}; 884};
899 885
900cf::register_command tell => sub { 886cf::register_command tell => sub {
901 my ($ob, $args) = @_; 887 my ($ob, $args) = @_;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines