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.44 by root, Fri Sep 19 01:39:45 2008 UTC vs.
Revision 1.56 by root, Sun Sep 5 05:01:39 2010 UTC

54cf::player->attach ( 54cf::player->attach (
55 prio => -1000, 55 prio => -1000,
56 on_login => sub { 56 on_login => sub {
57 my ($pl) = @_; 57 my ($pl) = @_;
58 58
59 cf::async {
59 clean_timeouts $pl->ob; 60 clean_timeouts $pl->ob;
61 };
60 62
61 $pl->send_msg ($cf::SAY_CHANNEL); 63 $pl->send_msg ($cf::SAY_CHANNEL);
62 $pl->send_msg ($cf::CHAT_CHANNEL); 64 $pl->send_msg ($cf::CHAT_CHANNEL);
63 }, 65 },
64); 66);
71 my ($ob, $msg) = @_; 73 my ($ob, $msg) = @_;
72 74
73 my $pl = $ob->contr; 75 my $pl = $ob->contr;
74 my $name = $ob->name; 76 my $name = $ob->name;
75 77
76 my $coin = int rand 2 ? "Heads" : "Tails"; 78 my $coin = (cf::rndm 2) ? "Heads" : "Tails";
77 79
78 send_msg $_, $cf::SAY_CHANNEL => "$name flips a coin.... $coin!", cf::NDI_GREY, "msg_say" 80 send_msg $_, $cf::SAY_CHANNEL => "$name flips a coin.... $coin!", cf::NDI_GREY, "msg_say"
79 for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl} cf::player::list; 81 for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl} cf::player::list;
80 82
81 $pl->send_msg ($cf::SAY_CHANNEL => "You flip a coin.... $coin!", cf::NDI_GREY | cf::NDI_REPLY); 83 $pl->send_msg ($cf::SAY_CHANNEL => "You flip a coin.... $coin!", cf::NDI_GREY | cf::NDI_REPLY);
86 88
87 my $pl = $ob->contr; 89 my $pl = $ob->contr;
88 my $name = $ob->name; 90 my $name = $ob->name;
89 91
90 my @orcknuckle = ("beholder", "ghost", "knight", "princess", "dragon", "orc"); 92 my @orcknuckle = ("beholder", "ghost", "knight", "princess", "dragon", "orc");
91 my ($i, $j, $k, $l) = (rand 5, rand 5, rand 5, rand 6); 93 my ($i, $j, $k, $l) = map +(cf::rndm $_), 5, 5, 5, 6;
92 my $result = "$orcknuckle[$i], $orcknuckle[$j], $orcknuckle[$k], $orcknuckle[$l]"; 94 my $result = "$orcknuckle[$i], $orcknuckle[$j], $orcknuckle[$k], $orcknuckle[$l]";
93 95
94 send_msg $_, $cf::SAY_CHANNEL => "$name throws his orc-knuckles and rolls $result!", cf::NDI_GREY, "msg_say" 96 send_msg $_, $cf::SAY_CHANNEL => "$name throws his orc-knuckles and rolls $result!", cf::NDI_GREY, "msg_say"
95 for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl} cf::player::list; 97 for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl} cf::player::list;
96 98
216 }, 218 },
217 }, 219 },
218 kiss => { 220 kiss => {
219 noparams => { 221 noparams => {
220 other => "<self> makes a weird facial contortion", 222 other => "<self> makes a weird facial contortion",
221 self => "All the lonely people..", 223 self => "All the lonely people...",
222 }, 224 },
223 params => { 225 params => {
224 target => "<self> kisses you.", 226 target => "<self> kisses you.",
225 other => "<self> kisses <other>.", 227 other => "<self> kisses <other>.",
226 self => "You kiss <other>.", 228 self => "You kiss <other>.",
227 }, 229 },
228 self => { 230 self => {
229 }, 231 },
230 }, 232 },
233 hug => {
234 noparams => {
235 other => "<self> makes weird body movements.",
236 self => "All the lonely people...",
237 },
238 params => {
239 target => "<self> suddenly grabs you and gives you a bear hug.",
240 other => "<self> hugs <other>.",
241 self => "You hug <other>.",
242 },
243 self => {
244 other => "<self> tries to hug G<himself|herself>, but stumbles and now feels stupid.",
245 self => "You try and fail to hug yourself.",
246 },
247 },
231 smother => { 248 smother => {
232 noparams => { 249 noparams => {
233 other => "<self> makes weird facial contortions", 250 other => "<self> makes weird facial contortions",
234 self => "All the lonely people..", 251 self => "All the lonely people...",
235 }, 252 },
236 params => { 253 params => {
237 target => "<self> smothers you with kisses.", 254 target => "<self> smothers you with kisses.",
238 other => "<self> smothers <other> with kisses.", 255 other => "<self> smothers <other> with kisses.",
239 self => "You smother <other> with kisses.", 256 self => "You smother <other> with kisses.",
717 for grep { $ob->on_same_map_as ($_->ob) && $_ != $ob} cf::player::list; 734 for grep { $ob->on_same_map_as ($_->ob) && $_ != $ob} cf::player::list;
718 735
719 $pl->send_msg ($emote{self}, cf::NDI_GREY | cf::NDI_REPLY | cf::NDI_VERBATIM); 736 $pl->send_msg ($emote{self}, cf::NDI_GREY | cf::NDI_REPLY | cf::NDI_VERBATIM);
720 } elsif ($tname) { 737 } elsif ($tname) {
721 my $target = cf::player::find $tname 738 my $target = cf::player::find $tname
722 or return send_msg $pl, tell_channel $tname, "$tname is not around.", cf::NDI_DK_ORANGE | cf::NDI_REPLY, "msg_chat"; 739 or return send_msg $pl, tell_channel $tname, "The player called $tname is not known to this poor server.",
740 cf::NDI_DK_ORANGE | cf::NDI_REPLY, "msg_chat";
741
742 $target->ob->active
743 or return send_msg $pl, tell_channel $tname, "$tname is not around. H<$tname must be logged in.>",
744 cf::NDI_DK_ORANGE | cf::NDI_REPLY, "msg_chat";
723 745
724 my %emote = %{ $emotes->{$emotion}->{params} || {} }; 746 my %emote = %{ $emotes->{$emotion}->{params} || {} };
725 747
726 $emote{other} ||= "<self> is eyeing <other> quizzically."; 748 $emote{other} ||= "<self> is eyeing <other> quizzically.";
727 $emote{self} ||= "You are still nuts."; 749 $emote{self} ||= "You are still nuts.";
758 } 780 }
759 }; 781 };
760 }; 782 };
761} 783}
762 784
763cf::register_command me => sub {
764 my ($pl, $msg) = @_;
765
766 my $name = $pl->name;
767
768 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;
770};
771
772cf::register_command say => sub { 785cf::register_command say => sub {
773 my ($ob, $msg) = @_; 786 my ($ob, $msg) = @_;
774 787
775 utf8::decode $msg; 788 utf8::decode $msg;
776 789
781 my @plonmap = grep $ob->on_same_map_as ($_->ob), cf::player::list; 794 my @plonmap = grep $ob->on_same_map_as ($_->ob), cf::player::list;
782 795
783 send_msg $_, $cf::SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY, "msg_say" 796 send_msg $_, $cf::SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY, "msg_say"
784 for grep $_ != $ob->contr, @plonmap; 797 for grep $_ != $ob->contr, @plonmap;
785 $ob->contr->send_msg ($cf::SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY | cf::NDI_REPLY); 798 $ob->contr->send_msg ($cf::SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY | cf::NDI_REPLY);
799
800 my @npc;
786 801
787 # npcs, magic_ears etc. 802 # npcs, magic_ears etc.
788 # first find all objects and their first-level inventories 803 # first find all objects and their first-level inventories
789 # within a 5x5 square that have something resembling 804 # within a 5x5 square that have something resembling
790 # dialogue or support on_say. 805 # dialogue or support on_say.
806 # we prefer the nearest items NOT in the player, otherwise in player.
791 my ($map, $x, $y) = ($ob->map, $ob->x - 2, $ob->y - 2); 807 my ($map, $x, $y) = ($ob->map, $ob->x, $ob->y);
792 808
793 for my $npc ( 809 for my $dir (
794 grep +($_->invoke (cf::EVENT_OBJECT_SAY, $ob->contr, $msg) && return) || $_->has_dialogue, 810 0,
795 map +($_, $_->inv), 811 1, 3, 5, 7,
796 grep $_, 812 2, 4, 6, 8,
797 map $map->at ($x + $_ % 5, $y + (int $_ / 5)), 813 9 .. cf::SIZEOFFREE2
798 0..24
799 ) { 814 ) {
815 @npc = grep $_->should_invoke (cf::EVENT_OBJECT_SAY) || $_->has_dialogue,
816 map +($_, $_->inv),
817 grep $_ != $ob,
818 $map->at ($x, $y, $dir)
819 and last;
820 }
821
822 unless (@npc) {
823 # nothing found, try the player inventory
824 @npc = grep $_->should_invoke (cf::EVENT_OBJECT_SAY) || $_->has_dialogue,
825 $ob->inv;
826 }
827
828 for my $npc (@npc) {
829 return if $npc->invoke (cf::EVENT_OBJECT_SAY, $ob->contr, $msg);
830
800 # if some listener teleported us somewhere else, stop right here 831 # if some listener teleported us somewhere else, stop right here
801 last unless $map->path == $ob->map->path; 832 last unless $map->path == $ob->map->path;
802 833
834 if ($npc->has_dialogue) {
803 my $dialog = new NPC_Dialogue pl => $ob->contr, npc => $npc; 835 my $dialog = new NPC_Dialogue pl => $ob->contr, npc => $npc;
804 my ($reply, @kw) = $dialog->tell ($msg); 836 my ($reply, @kw) = $dialog->tell ($msg);
805 837
806 if (defined $reply) { 838 if (defined $reply) {
807 if ($npc->type == cf::MAGIC_EAR) { 839 if ($npc->type == cf::MAGIC_EAR) {
808 if (length $reply) {
809 send_msg $_, $cf::SAY_CHANNEL => $reply, cf::NDI_BROWN, "msg_say" 840 send_msg $_, $cf::SAY_CHANNEL => $reply, cf::NDI_BROWN, "msg_say"
810 for @plonmap; 841 for @plonmap;
811 }
812 $npc->use_trigger;
813 } else { 842 } else {
814 if (length $reply) {
815 send_msg $_, $cf::SAY_CHANNEL => $npc->name . " says: $reply", cf::NDI_BROWN, "msg_say" 843 send_msg $_, $cf::SAY_CHANNEL => $npc->name . " says: $reply", cf::NDI_BROWN, "msg_say"
816 for @plonmap; 844 for @plonmap;
817 } 845 }
818 } 846 }
819 }
820 847
821 if (@kw) { 848 if (@kw) {
822 $_->send_msg ($cf::SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN) 849 $_->send_msg ($cf::SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN)
823 for @plonmap; 850 for @plonmap;
851 }
824 } 852 }
825 } 853 }
826 854
827 } else { 855 } else {
828 $ob->send_msg ($cf::SAY_CHANNEL => "What do you want to say?", cf::NDI_GREY | cf::NDI_REPLY); 856 $ob->send_msg ($cf::SAY_CHANNEL => "What do you want to say?", cf::NDI_GREY | cf::NDI_REPLY);
829 } 857 }
830}; 858};
831 859
832cf::register_command chat => sub { 860
861sub _chat {
833 my ($ob, $msg) = @_; 862 my ($ob, $msg) = @_;
834
835 utf8::decode $msg;
836 863
837 my $pl = $ob->contr; 864 my $pl = $ob->contr;
838 865
839 return if $pl->invoke (cf::EVENT_PLAYER_CHAT, $msg); 866 return if $pl->invoke (cf::EVENT_PLAYER_CHAT, $msg);
840 867
841 if ($msg) { 868 if ($msg) {
842 my $name = $ob->name; 869 my $name = $ob->name;
843 my $NOW = time; 870 my $NOW = time;
844 871
845 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; 872 cf::LOG cf::llevDebug, sprintf "QBERT %s\n", $msg;
846 send_irc ("[%s] %s", $name, $msg); 873 send_irc ("%s", $msg);
847 874
848 send_msg $_, $cf::CHAT_CHANNEL => "$name chats: $msg", cf::NDI_BLUE | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_chat" 875 send_msg $_, $cf::CHAT_CHANNEL => $msg, cf::NDI_BLUE | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_chat"
849 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW } cf::player::list; 876 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW } cf::player::list;
850 877
851 } else { 878 } else {
852 $pl->send_msg ($cf::CHAT_CHANNEL => "Chat what?", cf::NDI_BLUE | cf::NDI_DEF | cf::NDI_REPLY); 879 $pl->send_msg ($cf::CHAT_CHANNEL => "Chat what?", cf::NDI_BLUE | cf::NDI_DEF | cf::NDI_REPLY);
853 } 880 }
881}
882
883cf::register_command chat => sub {
884 my ($ob, $msg) = @_;
885
886 utf8::decode $msg;
887 _chat $ob, $ob->name . " chats: $msg";
888};
889
890cf::register_command me => sub {
891 my ($ob, $msg) = @_;
892
893 utf8::decode $msg;
894 _chat $ob, "* " . $ob->name . " $msg";
854}; 895};
855 896
856cf::register_command shout => sub { 897cf::register_command shout => sub {
857 my ($ob, $msg) = @_; 898 my ($ob, $msg) = @_;
858 899
923 964
924cf::register_command ignore => sub { 965cf::register_command ignore => sub {
925 my ($pl, $args) = @_; 966 my ($pl, $args) = @_;
926 my ($target, $type, $timeout) = split /\s+/, $args; 967 my ($target, $type, $timeout) = split /\s+/, $args;
927 968
969 cf::async {
928 if ($args eq "list") { 970 if ($args eq "list") {
929 clean_timeouts $pl; 971 clean_timeouts $pl;
930 972
931 if ((my @ignored_tell = sort keys %{$pl->{ext_ignore_tell}}) 973 if ((my @ignored_tell = sort keys %{$pl->{ext_ignore_tell}})
932 + (my @ignored_shout = sort keys %{$pl->{ext_ignore_shout}})) { 974 + (my @ignored_shout = sort keys %{$pl->{ext_ignore_shout}})) {
933 $pl->message ("Currently ignoring private messages from: ", cf::NDI_REPLY); 975 $pl->message ("Currently ignoring private messages from: ", cf::NDI_REPLY);
934 $pl->message ((join ", ", @ignored_tell), cf::NDI_REPLY); 976 $pl->message ((join ", ", @ignored_tell), cf::NDI_REPLY);
935 $pl->message ("Currently ignoring shouts from: ", cf::NDI_REPLY); 977 $pl->message ("Currently ignoring shouts from: ", cf::NDI_REPLY);
936 $pl->message ((join ", ", @ignored_shout), cf::NDI_REPLY); 978 $pl->message ((join ", ", @ignored_shout), cf::NDI_REPLY);
937 $pl->message ("To stop ignoring one, use unignore.", cf::NDI_REPLY); 979 $pl->message ("To stop ignoring one, use unignore.", cf::NDI_REPLY);
980 } else {
981 $pl->message ("Not ignoring anyone", cf::NDI_REPLY);
982 }
983
984 } elsif ($target && $type) {
985 $timeout ne "" or $timeout = 24;
986 my $absolute_timeout = time + $timeout * 3600;
987
988 if (cf::player::exists $target) {
989 if ($type eq "tell") {
990 $pl->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_REPLY);
991 $pl->{ext_ignore_tell}{$target} = $absolute_timeout;
992 } elsif ($type eq "shout") {
993 $pl->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_REPLY);
994 $pl->{ext_ignore_shout}{$target} = $absolute_timeout;
995 } elsif ($type eq "all") {
996 $pl->message ("Now ignoring everything from $target for $timeout hours.", cf::NDI_REPLY);
997 $pl->{ext_ignore_tell}{$target} = $absolute_timeout;
998 $pl->{ext_ignore_shout}{$target} = $absolute_timeout;
999 } else {
1000 $pl->message ("You need to specify tell, shout or all.", cf::NDI_REPLY);
1001 }
1002 } else {
1003 $pl->message ("No such player: $target", cf::NDI_REPLY);
1004 }
1005
938 } else { 1006 } else {
939 $pl->message ("Not ignoring anyone", cf::NDI_REPLY); 1007 $pl->message ("Usage: ignore <player> <tell|shout|all> <timeout>\n"
1008 . "will ignore a player for <timeout> hours.\n"
1009 . "Usage: ignore list\n"
1010 . "will show you a list of players currently ignored.", cf::NDI_REPLY);
940 } 1011 }
941
942 } elsif ($target && $type) {
943
944 $timeout ne "" or $timeout = 24;
945 my $absolute_timeout = time + $timeout * 3600;
946
947 if (cf::player::exists $target) {
948 if ($type eq "tell") {
949 $pl->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_REPLY);
950 $pl->{ext_ignore_tell}{$target} = $absolute_timeout;
951 } elsif ($type eq "shout") {
952 $pl->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_REPLY);
953 $pl->{ext_ignore_shout}{$target} = $absolute_timeout;
954 } elsif ($type eq "all") {
955 $pl->message ("Now ignoring everything from $target for $timeout hours.", cf::NDI_REPLY);
956 $pl->{ext_ignore_tell}{$target} = $absolute_timeout;
957 $pl->{ext_ignore_shout}{$target} = $absolute_timeout;
958 } else {
959 $pl->message ("You need to specify tell, shout or all.", cf::NDI_REPLY);
960 }
961 } else {
962 $pl->message ("No such player: $target", cf::NDI_REPLY);
963 }
964
965 } else {
966 $pl->message ("Usage: ignore <player> <tell|shout|all> <timeout>\n"
967 . "will ignore a player for <timeout> hours.\n"
968 . "Usage: ignore list\n"
969 . "will show you a list of players currently ignored.", cf::NDI_REPLY);
970 } 1012 };
971}; 1013};
972 1014
973cf::register_command unignore => sub { 1015cf::register_command unignore => sub {
974 my ($pl, $args) = @_; 1016 my ($pl, $args) = @_;
975 my ($target, $type) = split /\s+/, $args; 1017 my ($target, $type) = split /\s+/, $args;
976 1018
1019 cf::async {
977 if ($args eq "") { 1020 if ($args eq "") {
978 if ($pl->{ext_ignore_tell}) { 1021 if ($pl->{ext_ignore_tell}) {
979 $pl->message ("Currently ignoring private messages from: ", cf::NDI_REPLY); 1022 $pl->message ("Currently ignoring private messages from: ", cf::NDI_REPLY);
980 $pl->message ((join ", ", sort keys %{ $pl->{ext_ignore_tell} }), cf::NDI_REPLY); 1023 $pl->message ((join ", ", sort keys %{ $pl->{ext_ignore_tell} }), cf::NDI_REPLY);
981 $pl->message ("Currently ignoring shouts from: ", cf::NDI_REPLY); 1024 $pl->message ("Currently ignoring shouts from: ", cf::NDI_REPLY);
982 $pl->message ((join ", ", sort keys %{ $pl->{ext_ignore_shout} }), cf::NDI_REPLY); 1025 $pl->message ((join ", ", sort keys %{ $pl->{ext_ignore_shout} }), cf::NDI_REPLY);
983 } else {
984 $pl->message ("Not ignoring anyone", cf::NDI_REPLY);
985 }
986 } else {
987 if (cf::player::exists $target) {
988 if ($type eq "tell") {
989 $pl->message ("Not ignoring private messages from $target anymore.", cf::NDI_REPLY);
990 delete $pl->{ext_ignore_tell} {$target};
991 } elsif ($type eq "shout") {
992 $pl->message ("Not ignoring shouts from $target anymore.", cf::NDI_REPLY);
993 delete $pl->{ext_ignore_shout}{$target};
994 } elsif ($type eq "all") {
995 $pl->message ("Not ignoring anything from $target anymore.", cf::NDI_REPLY);
996 delete $pl->{ext_ignore_tell} {$target};
997 delete $pl->{ext_ignore_shout}{$target};
998 } else { 1026 } else {
999 $pl->message ("You need to specify tell, shout or all.", cf::NDI_REPLY); 1027 $pl->message ("Not ignoring anyone", cf::NDI_REPLY);
1000 } 1028 }
1001 } else { 1029 } else {
1030 if (cf::player::exists $target) {
1031 if ($type eq "tell") {
1032 $pl->message ("Not ignoring private messages from $target anymore.", cf::NDI_REPLY);
1033 delete $pl->{ext_ignore_tell} {$target};
1034 } elsif ($type eq "shout") {
1035 $pl->message ("Not ignoring shouts from $target anymore.", cf::NDI_REPLY);
1036 delete $pl->{ext_ignore_shout}{$target};
1037 } elsif ($type eq "all") {
1038 $pl->message ("Not ignoring anything from $target anymore.", cf::NDI_REPLY);
1039 delete $pl->{ext_ignore_tell} {$target};
1040 delete $pl->{ext_ignore_shout}{$target};
1041 } else {
1042 $pl->message ("You need to specify tell, shout or all.", cf::NDI_REPLY);
1043 }
1044 } else {
1002 $pl->message ("No such player or ambiguous name: $target", cf::NDI_REPLY); 1045 $pl->message ("No such player or ambiguous name: $target", cf::NDI_REPLY);
1046 }
1003 } 1047 }
1004 } 1048 };
1005}; 1049};
1006 1050

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines