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.47 by root, Sun Jan 25 23:56:13 2009 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);
757 $pl->send_msg ($cf::CHAT_CHANNEL, $emote{self}, cf::NDI_GREY | cf::NDI_REPLY | cf::NDI_VERBATIM); 759 $pl->send_msg ($cf::CHAT_CHANNEL, $emote{self}, cf::NDI_GREY | cf::NDI_REPLY | cf::NDI_VERBATIM);
758 } 760 }
759 }; 761 };
760 }; 762 };
761} 763}
762
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 764
772cf::register_command say => sub { 765cf::register_command say => sub {
773 my ($ob, $msg) = @_; 766 my ($ob, $msg) = @_;
774 767
775 utf8::decode $msg; 768 utf8::decode $msg;
803 my $dialog = new NPC_Dialogue pl => $ob->contr, npc => $npc; 796 my $dialog = new NPC_Dialogue pl => $ob->contr, npc => $npc;
804 my ($reply, @kw) = $dialog->tell ($msg); 797 my ($reply, @kw) = $dialog->tell ($msg);
805 798
806 if (defined $reply) { 799 if (defined $reply) {
807 if ($npc->type == cf::MAGIC_EAR) { 800 if ($npc->type == cf::MAGIC_EAR) {
808 if (length $reply) {
809 send_msg $_, $cf::SAY_CHANNEL => $reply, cf::NDI_BROWN, "msg_say" 801 send_msg $_, $cf::SAY_CHANNEL => $reply, cf::NDI_BROWN, "msg_say"
810 for @plonmap; 802 for @plonmap;
811 }
812 $npc->use_trigger;
813 } else { 803 } else {
814 if (length $reply) {
815 send_msg $_, $cf::SAY_CHANNEL => $npc->name . " says: $reply", cf::NDI_BROWN, "msg_say" 804 send_msg $_, $cf::SAY_CHANNEL => $npc->name . " says: $reply", cf::NDI_BROWN, "msg_say"
816 for @plonmap; 805 for @plonmap;
817 }
818 } 806 }
819 } 807 }
820 808
821 if (@kw) { 809 if (@kw) {
822 $_->send_msg ($cf::SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN) 810 $_->send_msg ($cf::SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN)
827 } else { 815 } else {
828 $ob->send_msg ($cf::SAY_CHANNEL => "What do you want to say?", cf::NDI_GREY | cf::NDI_REPLY); 816 $ob->send_msg ($cf::SAY_CHANNEL => "What do you want to say?", cf::NDI_GREY | cf::NDI_REPLY);
829 } 817 }
830}; 818};
831 819
832cf::register_command chat => sub { 820
821sub _chat {
833 my ($ob, $msg) = @_; 822 my ($ob, $msg) = @_;
834
835 utf8::decode $msg;
836 823
837 my $pl = $ob->contr; 824 my $pl = $ob->contr;
838 825
839 return if $pl->invoke (cf::EVENT_PLAYER_CHAT, $msg); 826 return if $pl->invoke (cf::EVENT_PLAYER_CHAT, $msg);
840 827
841 if ($msg) { 828 if ($msg) {
842 my $name = $ob->name; 829 my $name = $ob->name;
843 my $NOW = time; 830 my $NOW = time;
844 831
845 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; 832 cf::LOG cf::llevDebug, sprintf "QBERT %s\n", $name, $msg;
846 send_irc ("[%s] %s", $name, $msg); 833 send_irc ($msg);
847 834
848 send_msg $_, $cf::CHAT_CHANNEL => "$name chats: $msg", cf::NDI_BLUE | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_chat" 835 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; 836 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW } cf::player::list;
850 837
851 } else { 838 } else {
852 $pl->send_msg ($cf::CHAT_CHANNEL => "Chat what?", cf::NDI_BLUE | cf::NDI_DEF | cf::NDI_REPLY); 839 $pl->send_msg ($cf::CHAT_CHANNEL => "Chat what?", cf::NDI_BLUE | cf::NDI_DEF | cf::NDI_REPLY);
853 } 840 }
841}
842
843cf::register_command chat => sub {
844 my ($ob, $msg) = @_;
845
846 utf8::decode $msg;
847 _chat $ob, $ob->name . " chats: $msg";
848};
849
850cf::register_command me => sub {
851 my ($ob, $msg) = @_;
852
853 utf8::decode $msg;
854 _chat $ob, "* " . $ob->name . " $msg";
854}; 855};
855 856
856cf::register_command shout => sub { 857cf::register_command shout => sub {
857 my ($ob, $msg) = @_; 858 my ($ob, $msg) = @_;
858 859
923 924
924cf::register_command ignore => sub { 925cf::register_command ignore => sub {
925 my ($pl, $args) = @_; 926 my ($pl, $args) = @_;
926 my ($target, $type, $timeout) = split /\s+/, $args; 927 my ($target, $type, $timeout) = split /\s+/, $args;
927 928
929 cf::async {
928 if ($args eq "list") { 930 if ($args eq "list") {
929 clean_timeouts $pl; 931 clean_timeouts $pl;
930 932
931 if ((my @ignored_tell = sort keys %{$pl->{ext_ignore_tell}}) 933 if ((my @ignored_tell = sort keys %{$pl->{ext_ignore_tell}})
932 + (my @ignored_shout = sort keys %{$pl->{ext_ignore_shout}})) { 934 + (my @ignored_shout = sort keys %{$pl->{ext_ignore_shout}})) {
933 $pl->message ("Currently ignoring private messages from: ", cf::NDI_REPLY); 935 $pl->message ("Currently ignoring private messages from: ", cf::NDI_REPLY);
934 $pl->message ((join ", ", @ignored_tell), cf::NDI_REPLY); 936 $pl->message ((join ", ", @ignored_tell), cf::NDI_REPLY);
935 $pl->message ("Currently ignoring shouts from: ", cf::NDI_REPLY); 937 $pl->message ("Currently ignoring shouts from: ", cf::NDI_REPLY);
936 $pl->message ((join ", ", @ignored_shout), cf::NDI_REPLY); 938 $pl->message ((join ", ", @ignored_shout), cf::NDI_REPLY);
937 $pl->message ("To stop ignoring one, use unignore.", cf::NDI_REPLY); 939 $pl->message ("To stop ignoring one, use unignore.", cf::NDI_REPLY);
940 } else {
941 $pl->message ("Not ignoring anyone", cf::NDI_REPLY);
942 }
943
944 } elsif ($target && $type) {
945 $timeout ne "" or $timeout = 24;
946 my $absolute_timeout = time + $timeout * 3600;
947
948 if (cf::player::exists $target) {
949 if ($type eq "tell") {
950 $pl->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_REPLY);
951 $pl->{ext_ignore_tell}{$target} = $absolute_timeout;
952 } elsif ($type eq "shout") {
953 $pl->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_REPLY);
954 $pl->{ext_ignore_shout}{$target} = $absolute_timeout;
955 } elsif ($type eq "all") {
956 $pl->message ("Now ignoring everything from $target for $timeout hours.", cf::NDI_REPLY);
957 $pl->{ext_ignore_tell}{$target} = $absolute_timeout;
958 $pl->{ext_ignore_shout}{$target} = $absolute_timeout;
959 } else {
960 $pl->message ("You need to specify tell, shout or all.", cf::NDI_REPLY);
961 }
962 } else {
963 $pl->message ("No such player: $target", cf::NDI_REPLY);
964 }
965
938 } else { 966 } else {
939 $pl->message ("Not ignoring anyone", cf::NDI_REPLY); 967 $pl->message ("Usage: ignore <player> <tell|shout|all> <timeout>\n"
968 . "will ignore a player for <timeout> hours.\n"
969 . "Usage: ignore list\n"
970 . "will show you a list of players currently ignored.", cf::NDI_REPLY);
940 } 971 }
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 } 972 };
971}; 973};
972 974
973cf::register_command unignore => sub { 975cf::register_command unignore => sub {
974 my ($pl, $args) = @_; 976 my ($pl, $args) = @_;
975 my ($target, $type) = split /\s+/, $args; 977 my ($target, $type) = split /\s+/, $args;
976 978
979 cf::async {
977 if ($args eq "") { 980 if ($args eq "") {
978 if ($pl->{ext_ignore_tell}) { 981 if ($pl->{ext_ignore_tell}) {
979 $pl->message ("Currently ignoring private messages from: ", cf::NDI_REPLY); 982 $pl->message ("Currently ignoring private messages from: ", cf::NDI_REPLY);
980 $pl->message ((join ", ", sort keys %{ $pl->{ext_ignore_tell} }), cf::NDI_REPLY); 983 $pl->message ((join ", ", sort keys %{ $pl->{ext_ignore_tell} }), cf::NDI_REPLY);
981 $pl->message ("Currently ignoring shouts from: ", cf::NDI_REPLY); 984 $pl->message ("Currently ignoring shouts from: ", cf::NDI_REPLY);
982 $pl->message ((join ", ", sort keys %{ $pl->{ext_ignore_shout} }), cf::NDI_REPLY); 985 $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 { 986 } else {
999 $pl->message ("You need to specify tell, shout or all.", cf::NDI_REPLY); 987 $pl->message ("Not ignoring anyone", cf::NDI_REPLY);
1000 } 988 }
1001 } else { 989 } else {
990 if (cf::player::exists $target) {
991 if ($type eq "tell") {
992 $pl->message ("Not ignoring private messages from $target anymore.", cf::NDI_REPLY);
993 delete $pl->{ext_ignore_tell} {$target};
994 } elsif ($type eq "shout") {
995 $pl->message ("Not ignoring shouts from $target anymore.", cf::NDI_REPLY);
996 delete $pl->{ext_ignore_shout}{$target};
997 } elsif ($type eq "all") {
998 $pl->message ("Not ignoring anything from $target anymore.", cf::NDI_REPLY);
999 delete $pl->{ext_ignore_tell} {$target};
1000 delete $pl->{ext_ignore_shout}{$target};
1001 } else {
1002 $pl->message ("You need to specify tell, shout or all.", cf::NDI_REPLY);
1003 }
1004 } else {
1002 $pl->message ("No such player or ambiguous name: $target", cf::NDI_REPLY); 1005 $pl->message ("No such player or ambiguous name: $target", cf::NDI_REPLY);
1006 }
1003 } 1007 }
1004 } 1008 };
1005}; 1009};
1006 1010

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines