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.15 by root, Fri Apr 27 00:49:58 2007 UTC vs.
Revision 1.20 by elmex, Thu Jun 28 08:34:42 2007 UTC

1#! perl 1#! perl # depends=irc
2#CONVERSION: PARTIAL 2#CONVERSION: PARTIAL
3 3
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
19 } elsif (!cf::player::exists $k) { 19 } elsif (!cf::player::exists $k) {
20 $player->message ("Your ignore on $k is no longer valid (no such user).", cf::NDI_GREEN | cf::NDI_UNIQUE); 20 $player->message ("Your ignore on $k is no longer valid (no such user).", cf::NDI_GREEN | cf::NDI_UNIQUE);
21 delete $hash->{$k}; 21 delete $hash->{$k};
22 } 22 }
23 } 23 }
24 }
25}
26
27# send_irc ($format, @args, $msg)
28# make sure the last argument is the message!
29sub send_irc {
30 my ($format, @args) = @_;
31 my $msg = pop @args;
32 for (split /\n/, $msg) {
33 ext::irc::do_notice (sprintf $format, @args, $_)
24 } 34 }
25} 35}
26 36
27cf::player->attach ( 37cf::player->attach (
28 prio => -1000, 38 prio => -1000,
764 return if $pl->contr->invoke (cf::EVENT_PLAYER_SAY, $msg); 774 return if $pl->contr->invoke (cf::EVENT_PLAYER_SAY, $msg);
765 775
766 if ($msg) { 776 if ($msg) {
767 my $name = $pl->name; 777 my $name = $pl->name;
768 778
769 utf8::encode $msg; # ->message not yet utf8-ified
770 $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE) 779 $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE)
771 for grep $pl->on_same_map_as ($_->ob), cf::player::list; 780 for grep $pl->on_same_map_as ($_->ob), cf::player::list;
772 utf8::decode $msg;
773 781
774 # npcs, magic_ears etc. 782 # npcs, magic_ears etc.
775 # first find all objects and theirt-level inventories 783 # first find all objects and their first-level inventories
776 # within a 5x5 square # that have something resembling 784 # within a 5x5 square that have something resembling
777 # dialogue or support on_say. 785 # dialogue or support on_say.
778 my ($map, $x, $y) = ($pl->map, $pl->x - 2, $pl->y - 2); 786 my ($map, $x, $y) = ($pl->map, $pl->x - 2, $pl->y - 2);
779 787
780 for my $npc ( 788 for my $npc (
781 grep +($_->invoke (cf::EVENT_OBJECT_SAY, $pl->contr, $msg) && return) || NPC_Dialogue::has_dialogue $_, 789 grep +($_->invoke (cf::EVENT_OBJECT_SAY, $pl->contr, $msg) && return) || NPC_Dialogue::has_dialogue $_,
785 0..24 793 0..24
786 ) { 794 ) {
787 # if some listener teleported us somewhere else, stop right here 795 # if some listener teleported us somewhere else, stop right here
788 last unless $map->path == $pl->map->path; 796 last unless $map->path == $pl->map->path;
789 797
790 my $dialog = new NPC_Dialogue ob => $pl, npc => $npc; 798 my $dialog = new NPC_Dialogue pl => $pl->contr, npc => $npc;
791 my ($reply, @kw) = $dialog->tell ($msg); 799 my ($reply, @kw) = $dialog->tell ($msg);
792 800
793 if (defined $reply) { 801 if (defined $reply) {
794 if ($npc->type == cf::MAGIC_EAR) { 802 if ($npc->type == cf::MAGIC_EAR) {
795 if (length $reply) { 803 if (length $reply) {
826 if ($msg) { 834 if ($msg) {
827 my $name = $pl->name; 835 my $name = $pl->name;
828 my $NOW = time; 836 my $NOW = time;
829 837
830 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; 838 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg;
831 ext::schmorp_irc::do_notice (sprintf "[%s] %s", $name, $msg); 839 send_irc ("[%s] %s", $name, $msg);
832 840
833 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) 841 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE)
834 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; 842 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list;
835 843
836 } else { 844 } else {
848 if ($msg) { 856 if ($msg) {
849 my $NOW = time; 857 my $NOW = time;
850 my $name = $pl->name; 858 my $name = $pl->name;
851 859
852 cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; 860 cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg;
853 ext::schmorp_irc::do_notice (sprintf "\007\0034{%s} %s\n", $name, $msg); 861 send_irc ("\007\0034{%s} %s\n", $name, $msg);
854 862
855 utf8::encode $msg; # ->message not yet utf8-ified
856 $_->ob->message ("$name shouts: $msg", cf::NDI_RED) 863 $_->ob->message ("$name shouts: $msg", cf::NDI_RED)
857 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;
858 865
859 } else { 866 } else {
860 $pl->message ("Shout what?", cf::NDI_UNIQUE); 867 $pl->message ("Shout what?", cf::NDI_UNIQUE);
872 my $name = $pl->name; 879 my $name = $pl->name;
873 880
874 if ($target =~ /irc\//) { 881 if ($target =~ /irc\//) {
875 my (undef, $nick) = split /\//, $target, 2; 882 my (undef, $nick) = split /\//, $target, 2;
876 $pl->message ("You tell $target: $args"); 883 $pl->message ("You tell $target: $args");
877 ext::schmorp_irc::do_notice (sprintf "(%s) %s: %s\n", $name, $nick, $msg); 884 send_irc ("(%s) %s: %s\n", $name, $nick, $msg);
878 } elsif (my $other = cf::player::find_active $target) { 885 } elsif (my $other = cf::player::find_active $target) {
879 886
880 if ($msg) { 887 if ($msg) {
881 if ($target eq $name) { 888 if ($target eq $name) {
882 $pl->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); 889 $pl->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE);
883 } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { 890 } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) {
884 $pl->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE); 891 $pl->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE);
885 } else { 892 } else {
886 return if $other->invoke (cf::EVENT_PLAYER_TOLD, $pl->contr, $msg); 893 return if $other->invoke (cf::EVENT_PLAYER_TOLD, $pl->contr, $msg);
887 utf8::encode $msg; # ->message not yet utf8-ified
888 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg; 894 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg;
889 895
890 $pl->message ("You tell $target: $msg"); 896 $pl->message ("You tell $target: $msg");
891 $other->ob->message ("$name tells you: $msg"); 897 $other->ob->message ("$name tells you: $msg");
892 $other->ob->{ext_last_tell} = $name; 898 $other->ob->{ext_last_tell} = $name;
909 return if $pl->contr->invoke (cf::EVENT_PLAYER_TELL, $pl->{ext_last_tell}, $args); 915 return if $pl->contr->invoke (cf::EVENT_PLAYER_TELL, $pl->{ext_last_tell}, $args);
910 916
911 if ($pl->{ext_last_tell} =~ /irc\//) { 917 if ($pl->{ext_last_tell} =~ /irc\//) {
912 my (undef, $nick) = split /\//, $pl->{ext_last_tell}, 2; 918 my (undef, $nick) = split /\//, $pl->{ext_last_tell}, 2;
913 $pl->message ("You tell " . $pl->{ext_last_tell} . ": $args"); 919 $pl->message ("You tell " . $pl->{ext_last_tell} . ": $args");
914 ext::schmorp_irc::do_notice (sprintf "(%s) %s: %s\n", $name, $nick, $args); 920 send_irc ("(%s) %s: %s\n", $name, $nick, $args);
915 } elsif (my $other = cf::player::find_active $pl->{ext_last_tell}) { 921 } elsif (my $other = cf::player::find_active $pl->{ext_last_tell}) {
916 922
917 if ($args) { 923 if ($args) {
918 $other->ob->{ext_ignore_tell}{$name} >= time 924 $other->ob->{ext_ignore_tell}{$name} >= time
919 or delete $other->ob->{ext_ignore_tell}{$name}; 925 or delete $other->ob->{ext_ignore_tell}{$name};
920 926
921 if ($other->ob->{ext_ignore_tell}{$name} < time) { 927 if ($other->ob->{ext_ignore_tell}{$name} < time) {
922 utf8::encode $args; # ->message not yet utf8-ified
923 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $other->ob->name, $args; 928 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $other->ob->name, $args;
924 929
925 $pl->message ("You tell " . $other->ob->name . ": $args"); 930 $pl->message ("You tell " . $other->ob->name . ": $args");
926 $other->ob->message ("$name tells you: $args"); 931 $other->ob->message ("$name tells you: $args");
927 $pl->{ext_last_tell} = $other->ob->name; 932 $pl->{ext_last_tell} = $other->ob->name;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines