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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines