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.29 by root, Sat Jul 28 12:02:58 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;
62 prio => -1000, 55 prio => -1000,
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;
60
67 $pl->ns->send_msg ($SAY_CHANNEL); 61 $pl->send_msg ($cf::SAY_CHANNEL);
68 $pl->ns->send_msg ($CHAT_CHANNEL); 62 $pl->send_msg ($cf::CHAT_CHANNEL);
69 }, 63 },
70); 64);
71 65
72cf::register_command listen => sub { 66cf::register_command listen => sub {
73 my ($pl, $msg) = @_; 67 my ($pl, $msg) = @_;
94 my $pl = $ob->contr; 88 my $pl = $ob->contr;
95 my $name = $ob->name; 89 my $name = $ob->name;
96 90
97 my $coin = int rand 2 ? "Heads" : "Tails"; 91 my $coin = int rand 2 ? "Heads" : "Tails";
98 92
99 $_->ns->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"
100 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;
101 95
102 $pl->ns->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);
103}; 97};
104 98
105cf::register_command orcknuckle => sub { 99cf::register_command orcknuckle => sub {
106 my ($ob, $msg) = @_; 100 my ($ob, $msg) = @_;
107 101
110 104
111 my @orcknuckle = ("beholder", "ghost", "knight", "princess", "dragon", "orc"); 105 my @orcknuckle = ("beholder", "ghost", "knight", "princess", "dragon", "orc");
112 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);
113 my $result = "$orcknuckle[$i], $orcknuckle[$j], $orcknuckle[$k], $orcknuckle[$l]"; 107 my $result = "$orcknuckle[$i], $orcknuckle[$j], $orcknuckle[$k], $orcknuckle[$l]";
114 108
115 $_->ns->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"
116 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;
117 111
118 $pl->ns->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);
119}; 113};
120 114
121my $emotes = { 115my $emotes = {
122 growl => { 116 growl => {
123 noparams => { 117 noparams => {
243 }, 237 },
244 params => { 238 params => {
245 target => "<self> kisses you.", 239 target => "<self> kisses you.",
246 other => "<self> kisses <other>.", 240 other => "<self> kisses <other>.",
247 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.",
248 }, 255 },
249 self => { 256 self => {
250 }, 257 },
251 }, 258 },
252 wink => { 259 wink => {
706 713
707 my $pl = $ob->contr; 714 my $pl = $ob->contr;
708 715
709 cf::async { 716 cf::async {
710 my $name = $ob->name; 717 my $name = $ob->name;
718 $Coro::current->{desc} = "emote handler for $name";
711 719
712 if ($tname eq $name) { 720 if ($tname eq $name) {
713 my %emote = %{ $emotes->{$emotion}->{self} || {} }; 721 my %emote = %{ $emotes->{$emotion}->{self} || {} };
714 722
715 $emote{other} ||= "You look away from <self>."; 723 $emote{other} ||= "You look away from <self>.";
716 $emote{self} ||= "My god! Is that LEGAL?"; 724 $emote{self} ||= "My god! Is that LEGAL?";
717 725
718 $emote{other} =~ s/<self>/$name/; 726 $emote{other} =~ s/<self>/$name/;
719 727
720 $_->ns->send_msg ($CHAT_CHANNEL, $emote{other}, cf::NDI_GREY) 728 send_msg $_, $cf::CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat"
721 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;
722 730
723 $pl->ns->send_msg ($emote{self}, cf::NDI_GREY | cf::NDI_REPLY); 731 $pl->send_msg ($emote{self}, cf::NDI_GREY | cf::NDI_REPLY);
724 } elsif ($tname) { 732 } elsif ($tname) {
725 my $target = cf::player::find $tname 733 my $target = cf::player::find $tname
726 or return $pl->ns->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";
727 735
728 my %emote = %{ $emotes->{$emotion}->{params} || {} }; 736 my %emote = %{ $emotes->{$emotion}->{params} || {} };
729 737
730 $emote{other} ||= "<self> is eyeing <other> quizzically."; 738 $emote{other} ||= "<self> is eyeing <other> quizzically.";
731 $emote{self} ||= "You are still nuts."; 739 $emote{self} ||= "You are still nuts.";
732 $emote{target} ||= "You get the distinct feeling that <other> is nuts."; 740 $emote{target} ||= "You get the distinct feeling that <self> is nuts.";
733 741
734 $emote{self} =~ s/<other>/$tname/; 742 $emote{self} =~ s/<other>/$tname/;
735 $emote{target} =~ s/<self>/$name/; 743 $emote{target} =~ s/<self>/$name/;
736 $emote{other} =~ s/<other>/$tname/; 744 $emote{other} =~ s/<other>/$tname/;
737 $emote{other} =~ s/<self>/$name/; 745 $emote{other} =~ s/<self>/$name/;
738 746
739 $_->ns->send_msg ($CHAT_CHANNEL, $emote{other}, cf::NDI_GREY) 747 send_msg $_, $cf::CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat"
740 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;
741 749
742 $target->ns->send_msg (tell_channel $name, $emote{target}, cf::NDI_GREY); 750 send_msg $target, tell_channel $name, $emote{target}, cf::NDI_GREY, "msg_shout";
743 $pl->ns->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);
744 } else { 752 } else {
745 my %emote = %{ $emotes->{$emotion}->{noparams} || {} }; 753 my %emote = %{ $emotes->{$emotion}->{noparams} || {} };
746 754
747 $emote{other} ||= "<self> dances with glee."; 755 $emote{other} ||= "<self> dances with glee.";
748 $emote{self} ||= "You are a nut."; 756 $emote{self} ||= "You are a nut.";
749 757
750 $emote{other} =~ s/<self>/$name/; 758 $emote{other} =~ s/<self>/$name/;
751 759
752 $_->ns->send_msg ($CHAT_CHANNEL, $emote{other}, cf::NDI_GREY) 760 send_msg $_, $cf::CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat"
753 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;
754 762
755 $pl->ns->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);
756 } 764 }
757 }; 765 };
758 }; 766 };
759} 767}
760 768
761cf::register_command me => sub { 769cf::register_command me => sub {
762 my ($pl, $msg) = @_; 770 my ($pl, $msg) = @_;
763 771
764 my $name = $pl->name; 772 my $name = $pl->name;
765 773
766 $_->ns->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"
767 for grep $pl->on_same_map_as ($_->ob), cf::player::list; 775 for grep $pl->on_same_map_as ($_->ob), cf::player::list;
768}; 776};
769 777
770cf::register_command say => sub { 778cf::register_command say => sub {
771 my ($ob, $msg) = @_; 779 my ($ob, $msg) = @_;
776 784
777 if ($msg) { 785 if ($msg) {
778 my $name = $ob->name; 786 my $name = $ob->name;
779 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;
780 788
789 send_msg $_, $cf::SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY, "msg_say"
790 for grep $_ != $ob->contr, @plonmap;
781 $_->ns->send_msg ($SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY | ($_ == $ob ? cf::NDI_REPLY : 0)) 791 $ob->contr->send_msg ($cf::SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY | cf::NDI_REPLY);
782 for @plonmap;
783 792
784 # npcs, magic_ears etc. 793 # npcs, magic_ears etc.
785 # first find all objects and their first-level inventories 794 # first find all objects and their first-level inventories
786 # within a 5x5 square that have something resembling 795 # within a 5x5 square that have something resembling
787 # dialogue or support on_say. 796 # dialogue or support on_say.
788 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);
789 798
790 for my $npc ( 799 for my $npc (
791 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,
792 map +($_, $_->inv), 801 map +($_, $_->inv),
793 grep $_, 802 grep $_,
794 map $map->at ($x + $_ % 5, $y + (int $_ / 5)), 803 map $map->at ($x + $_ % 5, $y + (int $_ / 5)),
795 0..24 804 0..24
796 ) { 805 ) {
801 my ($reply, @kw) = $dialog->tell ($msg); 810 my ($reply, @kw) = $dialog->tell ($msg);
802 811
803 if (defined $reply) { 812 if (defined $reply) {
804 if ($npc->type == cf::MAGIC_EAR) { 813 if ($npc->type == cf::MAGIC_EAR) {
805 if (length $reply) { 814 if (length $reply) {
806 $_->ns->send_msg ($SAY_CHANNEL => $reply, cf::NDI_BROWN) 815 send_msg $_, $cf::SAY_CHANNEL => $reply, cf::NDI_BROWN, "msg_say"
807 for @plonmap; 816 for @plonmap;
808 } 817 }
809 $npc->use_trigger; 818 $npc->use_trigger;
810 } else { 819 } else {
811 if (length $reply) { 820 if (length $reply) {
812 $_->ns->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"
813 for @plonmap; 822 for @plonmap;
814 } 823 }
815 } 824 }
816 } 825 }
817 826
818 if (@kw) { 827 if (@kw) {
819 $_->ns->send_msg ($SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN) 828 $_->send_msg ($cf::SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN)
820 for @plonmap; 829 for @plonmap;
821 } 830 }
822 } 831 }
823 832
824 } else { 833 } else {
825 $ob->contr->ns->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);
826 } 835 }
827}; 836};
828 837
829cf::register_command chat => sub { 838cf::register_command chat => sub {
830 my ($ob, $msg) = @_; 839 my ($ob, $msg) = @_;
840 my $NOW = time; 849 my $NOW = time;
841 850
842 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; 851 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg;
843 send_irc ("[%s] %s", $name, $msg); 852 send_irc ("[%s] %s", $name, $msg);
844 853
845 $_->ns->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"
846 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;
847 856
848 } else { 857 } else {
849 $pl->ns->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);
850 } 859 }
851}; 860};
852 861
853cf::register_command shout => sub { 862cf::register_command shout => sub {
854 my ($ob, $msg) = @_; 863 my ($ob, $msg) = @_;
864 my $name = $ob->name; 873 my $name = $ob->name;
865 874
866 cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; 875 cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg;
867 send_irc ("\007\0034{%s} %s\n", $name, $msg); 876 send_irc ("\007\0034{%s} %s\n", $name, $msg);
868 877
869 $_->ns->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"
870 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;
871 880
872 } else { 881 } else {
873 $pl->ns->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);
874 } 883 }
875}; 884};
876 885
877cf::register_command tell => sub { 886cf::register_command tell => sub {
878 my ($ob, $args) = @_; 887 my ($ob, $args) = @_;
905 } else { 914 } else {
906 return if $other->invoke (cf::EVENT_PLAYER_TOLD, $pl, $msg); 915 return if $other->invoke (cf::EVENT_PLAYER_TOLD, $pl, $msg);
907 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;
908 917
909 $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);
910 $other->ns->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";
911 } 920 }
912 } else { 921 } else {
913 $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);
914 } 923 }
915 924

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines