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.21 by root, Fri Jul 20 16:11:10 2007 UTC vs.
Revision 1.28 by root, Tue Jul 24 22:49:40 2007 UTC

4# implement a replacement for the built-in say/chat/shout/tell/reply commands 4# implement a replacement for the built-in say/chat/shout/tell/reply commands
5# adds ignore/unignore functionality 5# adds ignore/unignore functionality
6 6
7use NPC_Dialogue; 7use NPC_Dialogue;
8use POSIX (); # for strftime only 8use POSIX (); # for strftime only
9
10our $SAY_CHANNEL = {
11 id => "say",
12 title => "Map",
13 reply => "say ",
14 tooltip => "Things said to and replied from npcs near you and other players on the same map only.",
15};
16
17our $CHAT_CHANNEL = {
18 id => "chat",
19 title => "Chat",
20 reply => "chat ",
21 tooltip => "Player chat and shouts, global to the server.",
22};
9 23
10sub clean_timeouts($) { 24sub clean_timeouts($) {
11 my ($player) = @_; 25 my ($player) = @_;
12 my $NOW = time; 26 my $NOW = time;
13 27
38 prio => -1000, 52 prio => -1000,
39 on_login => sub { 53 on_login => sub {
40 my ($pl) = @_; 54 my ($pl) = @_;
41 55
42 clean_timeouts $pl->ob; 56 clean_timeouts $pl->ob;
57 $pl->ns->send_msg ($SAY_CHANNEL);
58 $pl->ns->send_msg ($CHAT_CHANNEL);
43 }, 59 },
44); 60);
45 61
46cf::register_command listen => sub { 62cf::register_command listen => sub {
47 my ($pl, $msg) = @_; 63 my ($pl, $msg) = @_;
746 } 762 }
747 }; 763 };
748 }; 764 };
749} 765}
750 766
751our $SAY_CHANNEL = {
752 id => "say",
753 title => "Map",
754 reply => "say ",
755 tooltip => "Things said to and replied from npcs near you and other players on the same map only.",
756};
757
758cf::register_command me => sub { 767cf::register_command me => sub {
759 my ($pl, $msg) = @_; 768 my ($pl, $msg) = @_;
760 769
761 my $name = $pl->name; 770 my $name = $pl->name;
762 771
763 $_->ns->send_msg ($SAY_CHANNEL => "* $name $msg", cf::NDI_GREY, $_ == $pl ? (reply => 1) : ()) 772 $_->ns->send_msg ($SAY_CHANNEL => "* $name $msg", cf::NDI_GREY, $_ == $pl ? (reply => 1) : ())
764 for grep $pl->on_same_map_as ($_->ob), cf::player::list; 773 for grep $pl->on_same_map_as ($_->ob), cf::player::list;
765}; 774};
766 775
767cf::register_command say => sub { 776cf::register_command say => sub {
768 my ($pl, $msg) = @_; 777 my ($ob, $msg) = @_;
769 778
770 utf8::decode $msg; 779 utf8::decode $msg;
771 780
772 return if $pl->contr->invoke (cf::EVENT_PLAYER_SAY, $msg); 781 return if $ob->contr->invoke (cf::EVENT_PLAYER_SAY, $msg);
773 782
774 if ($msg) { 783 if ($msg) {
775 my $name = $pl->name; 784 my $name = $ob->name;
776 my @plonmap = grep $pl->on_same_map_as ($_->ob), cf::player::list; 785 my @plonmap = grep $ob->on_same_map_as ($_->ob), cf::player::list;
777 786
778 $_->ns->send_msg ($SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY, $_ == $pl ? (reply => 1) : ()) 787 $_->ns->send_msg ($SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY, $_ == $ob ? (reply => 1) : ())
779 for @plonmap; 788 for @plonmap;
780 789
781 # npcs, magic_ears etc. 790 # npcs, magic_ears etc.
782 # first find all objects and their first-level inventories 791 # first find all objects and their first-level inventories
783 # within a 5x5 square that have something resembling 792 # within a 5x5 square that have something resembling
784 # dialogue or support on_say. 793 # dialogue or support on_say.
785 my ($map, $x, $y) = ($pl->map, $pl->x - 2, $pl->y - 2); 794 my ($map, $x, $y) = ($ob->map, $ob->x - 2, $ob->y - 2);
786 795
787 for my $npc ( 796 for my $npc (
788 grep +($_->invoke (cf::EVENT_OBJECT_SAY, $pl->contr, $msg) && return) || NPC_Dialogue::has_dialogue $_, 797 grep +($_->invoke (cf::EVENT_OBJECT_SAY, $ob->contr, $msg) && return) || NPC_Dialogue::has_dialogue $_,
789 map +($_, $_->inv), 798 map +($_, $_->inv),
790 grep $_, 799 grep $_,
791 map $map->at ($x + $_ % 5, $y + (int $_ / 5)), 800 map $map->at ($x + $_ % 5, $y + (int $_ / 5)),
792 0..24 801 0..24
793 ) { 802 ) {
794 # if some listener teleported us somewhere else, stop right here 803 # if some listener teleported us somewhere else, stop right here
795 last unless $map->path == $pl->map->path; 804 last unless $map->path == $ob->map->path;
796 805
797 my $dialog = new NPC_Dialogue pl => $pl->contr, npc => $npc; 806 my $dialog = new NPC_Dialogue pl => $ob->contr, npc => $npc;
798 my ($reply, @kw) = $dialog->tell ($msg); 807 my ($reply, @kw) = $dialog->tell ($msg);
799 808
800 if (defined $reply) { 809 if (defined $reply) {
801 if ($npc->type == cf::MAGIC_EAR) { 810 if ($npc->type == cf::MAGIC_EAR) {
802 if (length $reply) { 811 if (length $reply) {
803 $_->contr->send_msg ($SAY_CHANNEL => $reply, cf::NDI_BROWN) 812 $_->ns->send_msg ($SAY_CHANNEL => $reply, cf::NDI_BROWN)
804 for @plonmap; 813 for @plonmap;
805 } 814 }
806 $npc->use_trigger; 815 $npc->use_trigger;
807 } else { 816 } else {
808 if (length $reply) { 817 if (length $reply) {
809 $_->contr->send_msg ($SAY_CHANNEL => $npc->name . " says: $reply", cf::NDI_BROWN) 818 $_->ns->send_msg ($SAY_CHANNEL => $npc->name . " says: $reply", cf::NDI_BROWN)
810 for @plonmap; 819 for @plonmap;
811 } 820 }
812 } 821 }
813 } 822 }
814 823
815 if (@kw) { 824 if (@kw) {
816 $_->contr->send_msg ($SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN) 825 $_->ns->send_msg ($SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN)
817 for @plonmap; 826 for @plonmap;
818 } 827 }
819 } 828 }
820 829
821 } else { 830 } else {
822 $pl->contr->send_msg ($SAY_CHANNEL => "What do you want to say?", 0, reply => 1); 831 $ob->contr->ns->send_msg ($SAY_CHANNEL => "What do you want to say?", 0, reply => 1);
823 } 832 }
824}; 833};
825 834
826our $CHAT_CHANNEL = {
827 id => "chat",
828 title => "Chat",
829 reply => "chat ",
830 tooltip => "Player chat and shouts, global to the server.",
831};
832
833cf::register_command chat => sub { 835cf::register_command chat => sub {
834 my ($pl, $msg) = @_; 836 my ($ob, $msg) = @_;
835 837
836 utf8::decode $msg; 838 utf8::decode $msg;
837 839
840 my $pl = $ob->contr;
841
838 return if $pl->contr->invoke (cf::EVENT_PLAYER_CHAT, $msg); 842 return if $pl->invoke (cf::EVENT_PLAYER_CHAT, $msg);
839 843
840 if ($msg) { 844 if ($msg) {
841 my $name = $pl->name; 845 my $name = $ob->name;
842 my $NOW = time; 846 my $NOW = time;
843 847
844 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; 848 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg;
845 send_irc ("[%s] %s", $name, $msg); 849 send_irc ("[%s] %s", $name, $msg);
846 850
851 $pl->ns->send_msg ($CHAT_CHANNEL => "Chat what?"); 855 $pl->ns->send_msg ($CHAT_CHANNEL => "Chat what?");
852 } 856 }
853}; 857};
854 858
855cf::register_command shout => sub { 859cf::register_command shout => sub {
856 my ($pl, $msg) = @_; 860 my ($ob, $msg) = @_;
857 861
858 utf8::decode $msg; 862 utf8::decode $msg;
859 863
864 my $pl = $ob->contr;
865
860 return if $pl->contr->invoke (cf::EVENT_PLAYER_SHOUT, $msg); 866 return if $pl->invoke (cf::EVENT_PLAYER_SHOUT, $msg);
861 867
862 if ($msg) { 868 if ($msg) {
863 my $NOW = time; 869 my $NOW = time;
864 my $name = $pl->name; 870 my $name = $ob->name;
865 871
866 cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; 872 cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg;
867 send_irc ("\007\0034{%s} %s\n", $name, $msg); 873 send_irc ("\007\0034{%s} %s\n", $name, $msg);
868 874
869 $_->ns->send_msg ($CHAT_CHANNEL => "$name shouts: $msg", cf::NDI_BLUE, $_ == $pl ? (reply => 1) : ()) 875 $_->ns->send_msg ($CHAT_CHANNEL => "$name shouts: $msg", cf::NDI_RED, $_ == $pl ? (reply => 1) : ())
870 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; 876 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list;
871 877
872 } else { 878 } else {
873 $pl->ns->send_msg ($CHAT_CHANNEL => "Shout what?"); 879 $pl->ns->send_msg ($CHAT_CHANNEL => "Shout what?");
874 } 880 }
910 if ($target eq $name) { 916 if ($target eq $name) {
911 $ns->send_msg ($pl_channel => "You are talking to yourself, you freak!", reply => 1); 917 $ns->send_msg ($pl_channel => "You are talking to yourself, you freak!", reply => 1);
912 } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { 918 } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) {
913 $ns->send_msg ($pl_channel => "$target ignores what you say. Give up on it.", reply => 1); 919 $ns->send_msg ($pl_channel => "$target ignores what you say. Give up on it.", reply => 1);
914 } else { 920 } else {
915 return if $other->invoke (cf::EVENT_PLAYER_TOLD, $pl->contr, $msg); 921 return if $other->invoke (cf::EVENT_PLAYER_TOLD, $pl, $msg);
916 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg; 922 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg;
917 923
918 $ns->send_msg ($pl_channel => "You tell $target: $msg", reply => 1); 924 $ns->send_msg ($pl_channel => "You tell $target: $msg", reply => 1);
919 $other->ns->send_msg ($other_channel => "$name tells you: $msg"); 925 $other->ns->send_msg ($other_channel => "$name tells you: $msg");
920 } 926 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines