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.52 by root, Wed Apr 21 03:34:26 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);
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.",
758 } 775 }
759 }; 776 };
760 }; 777 };
761} 778}
762 779
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 { 780cf::register_command say => sub {
773 my ($ob, $msg) = @_; 781 my ($ob, $msg) = @_;
774 782
775 utf8::decode $msg; 783 utf8::decode $msg;
776 784
781 my @plonmap = grep $ob->on_same_map_as ($_->ob), cf::player::list; 789 my @plonmap = grep $ob->on_same_map_as ($_->ob), cf::player::list;
782 790
783 send_msg $_, $cf::SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY, "msg_say" 791 send_msg $_, $cf::SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY, "msg_say"
784 for grep $_ != $ob->contr, @plonmap; 792 for grep $_ != $ob->contr, @plonmap;
785 $ob->contr->send_msg ($cf::SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY | cf::NDI_REPLY); 793 $ob->contr->send_msg ($cf::SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY | cf::NDI_REPLY);
794
795 my @npc;
786 796
787 # npcs, magic_ears etc. 797 # npcs, magic_ears etc.
788 # first find all objects and their first-level inventories 798 # first find all objects and their first-level inventories
789 # within a 5x5 square that have something resembling 799 # within a 5x5 square that have something resembling
790 # dialogue or support on_say. 800 # dialogue or support on_say.
801 # 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); 802 my ($map, $x, $y) = ($ob->map, $ob->x, $ob->y);
792 803
793 for my $npc ( 804 for my $dir (0 .. cf::SIZEOFFREE2) {
794 grep +($_->invoke (cf::EVENT_OBJECT_SAY, $ob->contr, $msg) && return) || $_->has_dialogue, 805 @npc = grep $_->should_invoke (cf::EVENT_OBJECT_SAY) || $_->has_dialogue,
795 map +($_, $_->inv), 806 map +($_, $_->inv),
796 grep $_, 807 grep $_ != $ob,
797 map $map->at ($x + $_ % 5, $y + (int $_ / 5)), 808 $map->at ($x, $y, $dir)
798 0..24 809 and last;
799 ) { 810 }
811
812 unless (@npc) {
813 # nothing found, try the player inventory
814 @npc = grep $_->should_invoke (cf::EVENT_OBJECT_SAY) || $_->has_dialogue,
815 $ob->inv;
816 }
817
818 for my $npc (@npc) {
819 return if $npc->invoke (cf::EVENT_OBJECT_SAY);
820
800 # if some listener teleported us somewhere else, stop right here 821 # if some listener teleported us somewhere else, stop right here
801 last unless $map->path == $ob->map->path; 822 last unless $map->path == $ob->map->path;
802 823
824 if ($npc->has_dialogue) {
803 my $dialog = new NPC_Dialogue pl => $ob->contr, npc => $npc; 825 my $dialog = new NPC_Dialogue pl => $ob->contr, npc => $npc;
804 my ($reply, @kw) = $dialog->tell ($msg); 826 my ($reply, @kw) = $dialog->tell ($msg);
805 827
806 if (defined $reply) { 828 if (defined $reply) {
807 if ($npc->type == cf::MAGIC_EAR) { 829 if ($npc->type == cf::MAGIC_EAR) {
808 if (length $reply) {
809 send_msg $_, $cf::SAY_CHANNEL => $reply, cf::NDI_BROWN, "msg_say" 830 send_msg $_, $cf::SAY_CHANNEL => $reply, cf::NDI_BROWN, "msg_say"
810 for @plonmap; 831 for @plonmap;
811 }
812 $npc->use_trigger;
813 } else { 832 } else {
814 if (length $reply) {
815 send_msg $_, $cf::SAY_CHANNEL => $npc->name . " says: $reply", cf::NDI_BROWN, "msg_say" 833 send_msg $_, $cf::SAY_CHANNEL => $npc->name . " says: $reply", cf::NDI_BROWN, "msg_say"
816 for @plonmap; 834 for @plonmap;
817 } 835 }
818 } 836 }
819 }
820 837
821 if (@kw) { 838 if (@kw) {
822 $_->send_msg ($cf::SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN) 839 $_->send_msg ($cf::SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN)
823 for @plonmap; 840 for @plonmap;
841 }
824 } 842 }
825 } 843 }
826 844
827 } else { 845 } else {
828 $ob->send_msg ($cf::SAY_CHANNEL => "What do you want to say?", cf::NDI_GREY | cf::NDI_REPLY); 846 $ob->send_msg ($cf::SAY_CHANNEL => "What do you want to say?", cf::NDI_GREY | cf::NDI_REPLY);
829 } 847 }
830}; 848};
831 849
832cf::register_command chat => sub { 850
851sub _chat {
833 my ($ob, $msg) = @_; 852 my ($ob, $msg) = @_;
834
835 utf8::decode $msg;
836 853
837 my $pl = $ob->contr; 854 my $pl = $ob->contr;
838 855
839 return if $pl->invoke (cf::EVENT_PLAYER_CHAT, $msg); 856 return if $pl->invoke (cf::EVENT_PLAYER_CHAT, $msg);
840 857
841 if ($msg) { 858 if ($msg) {
842 my $name = $ob->name; 859 my $name = $ob->name;
843 my $NOW = time; 860 my $NOW = time;
844 861
845 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; 862 cf::LOG cf::llevDebug, sprintf "QBERT %s\n", $msg;
846 send_irc ("[%s] %s", $name, $msg); 863 send_irc ("%s", $msg);
847 864
848 send_msg $_, $cf::CHAT_CHANNEL => "$name chats: $msg", cf::NDI_BLUE | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_chat" 865 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; 866 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW } cf::player::list;
850 867
851 } else { 868 } else {
852 $pl->send_msg ($cf::CHAT_CHANNEL => "Chat what?", cf::NDI_BLUE | cf::NDI_DEF | cf::NDI_REPLY); 869 $pl->send_msg ($cf::CHAT_CHANNEL => "Chat what?", cf::NDI_BLUE | cf::NDI_DEF | cf::NDI_REPLY);
853 } 870 }
871}
872
873cf::register_command chat => sub {
874 my ($ob, $msg) = @_;
875
876 utf8::decode $msg;
877 _chat $ob, $ob->name . " chats: $msg";
878};
879
880cf::register_command me => sub {
881 my ($ob, $msg) = @_;
882
883 utf8::decode $msg;
884 _chat $ob, "* " . $ob->name . " $msg";
854}; 885};
855 886
856cf::register_command shout => sub { 887cf::register_command shout => sub {
857 my ($ob, $msg) = @_; 888 my ($ob, $msg) = @_;
858 889
923 954
924cf::register_command ignore => sub { 955cf::register_command ignore => sub {
925 my ($pl, $args) = @_; 956 my ($pl, $args) = @_;
926 my ($target, $type, $timeout) = split /\s+/, $args; 957 my ($target, $type, $timeout) = split /\s+/, $args;
927 958
959 cf::async {
928 if ($args eq "list") { 960 if ($args eq "list") {
929 clean_timeouts $pl; 961 clean_timeouts $pl;
930 962
931 if ((my @ignored_tell = sort keys %{$pl->{ext_ignore_tell}}) 963 if ((my @ignored_tell = sort keys %{$pl->{ext_ignore_tell}})
932 + (my @ignored_shout = sort keys %{$pl->{ext_ignore_shout}})) { 964 + (my @ignored_shout = sort keys %{$pl->{ext_ignore_shout}})) {
933 $pl->message ("Currently ignoring private messages from: ", cf::NDI_REPLY); 965 $pl->message ("Currently ignoring private messages from: ", cf::NDI_REPLY);
934 $pl->message ((join ", ", @ignored_tell), cf::NDI_REPLY); 966 $pl->message ((join ", ", @ignored_tell), cf::NDI_REPLY);
935 $pl->message ("Currently ignoring shouts from: ", cf::NDI_REPLY); 967 $pl->message ("Currently ignoring shouts from: ", cf::NDI_REPLY);
936 $pl->message ((join ", ", @ignored_shout), cf::NDI_REPLY); 968 $pl->message ((join ", ", @ignored_shout), cf::NDI_REPLY);
937 $pl->message ("To stop ignoring one, use unignore.", cf::NDI_REPLY); 969 $pl->message ("To stop ignoring one, use unignore.", cf::NDI_REPLY);
970 } else {
971 $pl->message ("Not ignoring anyone", cf::NDI_REPLY);
972 }
973
974 } elsif ($target && $type) {
975 $timeout ne "" or $timeout = 24;
976 my $absolute_timeout = time + $timeout * 3600;
977
978 if (cf::player::exists $target) {
979 if ($type eq "tell") {
980 $pl->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_REPLY);
981 $pl->{ext_ignore_tell}{$target} = $absolute_timeout;
982 } elsif ($type eq "shout") {
983 $pl->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_REPLY);
984 $pl->{ext_ignore_shout}{$target} = $absolute_timeout;
985 } elsif ($type eq "all") {
986 $pl->message ("Now ignoring everything from $target for $timeout hours.", cf::NDI_REPLY);
987 $pl->{ext_ignore_tell}{$target} = $absolute_timeout;
988 $pl->{ext_ignore_shout}{$target} = $absolute_timeout;
989 } else {
990 $pl->message ("You need to specify tell, shout or all.", cf::NDI_REPLY);
991 }
992 } else {
993 $pl->message ("No such player: $target", cf::NDI_REPLY);
994 }
995
938 } else { 996 } else {
939 $pl->message ("Not ignoring anyone", cf::NDI_REPLY); 997 $pl->message ("Usage: ignore <player> <tell|shout|all> <timeout>\n"
998 . "will ignore a player for <timeout> hours.\n"
999 . "Usage: ignore list\n"
1000 . "will show you a list of players currently ignored.", cf::NDI_REPLY);
940 } 1001 }
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 } 1002 };
971}; 1003};
972 1004
973cf::register_command unignore => sub { 1005cf::register_command unignore => sub {
974 my ($pl, $args) = @_; 1006 my ($pl, $args) = @_;
975 my ($target, $type) = split /\s+/, $args; 1007 my ($target, $type) = split /\s+/, $args;
976 1008
1009 cf::async {
977 if ($args eq "") { 1010 if ($args eq "") {
978 if ($pl->{ext_ignore_tell}) { 1011 if ($pl->{ext_ignore_tell}) {
979 $pl->message ("Currently ignoring private messages from: ", cf::NDI_REPLY); 1012 $pl->message ("Currently ignoring private messages from: ", cf::NDI_REPLY);
980 $pl->message ((join ", ", sort keys %{ $pl->{ext_ignore_tell} }), cf::NDI_REPLY); 1013 $pl->message ((join ", ", sort keys %{ $pl->{ext_ignore_tell} }), cf::NDI_REPLY);
981 $pl->message ("Currently ignoring shouts from: ", cf::NDI_REPLY); 1014 $pl->message ("Currently ignoring shouts from: ", cf::NDI_REPLY);
982 $pl->message ((join ", ", sort keys %{ $pl->{ext_ignore_shout} }), cf::NDI_REPLY); 1015 $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 { 1016 } else {
999 $pl->message ("You need to specify tell, shout or all.", cf::NDI_REPLY); 1017 $pl->message ("Not ignoring anyone", cf::NDI_REPLY);
1000 } 1018 }
1001 } else { 1019 } else {
1020 if (cf::player::exists $target) {
1021 if ($type eq "tell") {
1022 $pl->message ("Not ignoring private messages from $target anymore.", cf::NDI_REPLY);
1023 delete $pl->{ext_ignore_tell} {$target};
1024 } elsif ($type eq "shout") {
1025 $pl->message ("Not ignoring shouts from $target anymore.", cf::NDI_REPLY);
1026 delete $pl->{ext_ignore_shout}{$target};
1027 } elsif ($type eq "all") {
1028 $pl->message ("Not ignoring anything from $target anymore.", cf::NDI_REPLY);
1029 delete $pl->{ext_ignore_tell} {$target};
1030 delete $pl->{ext_ignore_shout}{$target};
1031 } else {
1032 $pl->message ("You need to specify tell, shout or all.", cf::NDI_REPLY);
1033 }
1034 } else {
1002 $pl->message ("No such player or ambiguous name: $target", cf::NDI_REPLY); 1035 $pl->message ("No such player or ambiguous name: $target", cf::NDI_REPLY);
1036 }
1003 } 1037 }
1004 } 1038 };
1005}; 1039};
1006 1040

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines