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.14 by root, Tue Apr 24 18:24:31 2007 UTC vs.
Revision 1.34 by root, Sat Oct 20 05:07:19 2007 UTC

1#! perl 1#! perl # depends=irc mandatory
2#CONVERSION: PARTIAL
3 2
4# implement a replacement for the built-in say/chat/shout/tell/reply commands 3# implement a replacement for the built-in say/chat/shout/tell/reply commands
5# adds ignore/unignore functionality 4# adds ignore/unignore functionality
6 5
7use NPC_Dialogue; 6use NPC_Dialogue;
8use POSIX (); # for strftime only 7use POSIX (); # for strftime only
8
9our $SAY_CHANNEL = {
10 id => "say",
11 title => "Map",
12 reply => "say ",
13 tooltip => "Things said to and replied from npcs near you and other players on the same map only.",
14};
15
16our $CHAT_CHANNEL = {
17 id => "chat",
18 title => "Chat",
19 reply => "chat ",
20 tooltip => "Player chat and shouts, global to the server.",
21};
22
23sub tell_channel($) {
24 my ($target) = @_;
25
26 {
27 id => "tell-$target",
28 title => "$target",
29 reply => "tell $target ",
30 tooltip => "Private messages from/to $target",
31 }
32}
33
34sub send_msg($$$$$) {
35 my ($pl, $channel, $msg, $flags, $sound) = @_;
36 $pl->play_sound (cf::sound::find $sound) if defined $sound;
37 $pl->send_msg ($channel, $msg, $flags);
38 ()
39}
9 40
10sub clean_timeouts($) { 41sub clean_timeouts($) {
11 my ($player) = @_; 42 my ($player) = @_;
12 my $NOW = time; 43 my $NOW = time;
13 44
14 for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) { 45 for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) {
15 while (my ($k, $v) = each %$hash) { 46 while (my ($k, $v) = each %$hash) {
16 if ($v < $NOW) { 47 if ($v < $NOW) {
17 $player->message ("Your ignore on $k has expired.", cf::NDI_GREEN | cf::NDI_UNIQUE); 48 $player->message ("Your ignore on $k has expired.", cf::NDI_GREEN);
18 delete $hash->{$k}; 49 delete $hash->{$k};
19 } elsif (!cf::player::exists $k) { 50 } 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); 51 $player->message ("Your ignore on $k is no longer valid (no such user).", cf::NDI_GREEN);
21 delete $hash->{$k}; 52 delete $hash->{$k};
22 } 53 }
23 } 54 }
24 } 55 }
25} 56}
26 57
58# send_irc ($format, @args, $msg)
59# make sure the last argument is the message!
60sub send_irc {
61 my ($format, @args) = @_;
62 my $msg = pop @args;
63 for (split /\n/, $msg) {
64 ext::irc::do_notice (sprintf $format, @args, $_)
65 }
66}
67
27cf::player->attach ( 68cf::player->attach (
28 prio => -1000, 69 prio => -1000,
29 on_login => sub { 70 on_login => sub {
30 my ($pl) = @_; 71 my ($pl) = @_;
31 72
32 clean_timeouts $pl->ob; 73 clean_timeouts $pl->ob;
74
75 $pl->send_msg ($SAY_CHANNEL);
76 $pl->send_msg ($CHAT_CHANNEL);
33 }, 77 },
34); 78);
35 79
36cf::register_command listen => sub { 80cf::register_command listen => sub {
37 my ($pl, $msg) = @_; 81 my ($pl, $msg) = @_;
41 $msg = 10 if $msg > 10; 85 $msg = 10 if $msg > 10;
42 86
43 my $prev_listen = $player->listening; 87 my $prev_listen = $player->listening;
44 $player->listening ($msg); 88 $player->listening ($msg);
45 if ($prev_listen == $player->listening) { 89 if ($prev_listen == $player->listening) {
46 $pl->message ("Your verbose level stayed $prev_listen.", cf::NDI_UNIQUE); 90 $pl->message ("Your verbose level stays at $prev_listen.", cf::NDI_REPLY);
47 } else { 91 } else {
48 $pl->message ("Your verbose level is now " . $player->listening . ". (previously: $prev_listen)", cf::NDI_UNIQUE); 92 $pl->message ("Your verbose level is now " . $player->listening . ". (previously: $prev_listen)", cf::NDI_REPLY);
49 } 93 }
50 } else { 94 } else {
51 $pl->message ("Your verbose level is " . $player->listening . ".", cf::NDI_UNIQUE); 95 $pl->message ("Your verbose level is " . $player->listening . ".", cf::NDI_REPLY);
52 } 96 }
53}; 97};
54 98
55cf::register_command cointoss => sub { 99cf::register_command cointoss => sub {
56 my ($pl, $msg) = @_; 100 my ($ob, $msg) = @_;
57 101
102 my $pl = $ob->contr;
58 my $name = $pl->name; 103 my $name = $ob->name;
59 104
60 if (int rand 2) { 105 my $coin = int rand 2 ? "Heads" : "Tails";
106
107 send_msg $_, $SAY_CHANNEL => "$name flips a coin.... $coin!", cf::NDI_GREY, "msg_say"
61 for my $other ( grep { $pl->on_same_map_as ($_->ob) } cf::player::list ) { 108 for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl} cf::player::list;
62 next
63 if $other->ob == $pl;
64 $other->ob->message ("$name flips a coin.... Heads!", cf::NDI_GREY | cf::NDI_UNIQUE);
65 }
66
67 $pl->message ("You flip a coin.... Heads!", cf::NDI_GREY | cf::NDI_UNIQUE);
68 } else {
69 for my $other ( grep { $pl->on_same_map_as ($_->ob) } cf::player::list ) {
70 next
71 if $other->ob == $pl;
72 $other->ob->message ("$name flips a coin.... Tails!", cf::NDI_GREY | cf::NDI_UNIQUE);
73 }
74
75 $pl->message ("You flip a coin.... Tails!", cf::NDI_GREY | cf::NDI_UNIQUE);
76 } 109
110 $pl->send_msg ($SAY_CHANNEL => "You flip a coin.... $coin!", cf::NDI_GREY | cf::NDI_REPLY);
77}; 111};
78 112
79cf::register_command orcknuckle => sub { 113cf::register_command orcknuckle => sub {
80 my ($pl, $msg) = @_; 114 my ($ob, $msg) = @_;
115
116 my $pl = $ob->contr;
117 my $name = $ob->name;
118
81 my @orcknuckle = ("none", "beholder", "ghost", "knight", "princess", "dragon", "orc"); 119 my @orcknuckle = ("beholder", "ghost", "knight", "princess", "dragon", "orc");
82 120 my ($i, $j, $k, $l) = (rand 5, rand 5, rand 5, rand 6);
83 my $name = $pl->name;
84
85 my ($i, $j, $k, $l) = ((int rand 5) + 1, (int rand 5) + 1, (int rand 5) + 1, (int rand 6) + 1);
86 my $result = "$orcknuckle[$i], $orcknuckle[$j], $orcknuckle[$k], $orcknuckle[$l]"; 121 my $result = "$orcknuckle[$i], $orcknuckle[$j], $orcknuckle[$k], $orcknuckle[$l]";
87 122
123 send_msg $_, $SAY_CHANNEL => "$name throws his orc-knuckles and rolls $result!", cf::NDI_GREY, "msg_say"
88 for my $other ( grep { $pl->on_same_map_as ($_->ob) } cf::player::list ) { 124 for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl} cf::player::list;
89 next
90 if $other->ob == $pl;
91 $other->ob->message ("$name rolls $result!", cf::NDI_GREY | cf::NDI_UNIQUE);
92 } 125
93
94 $pl->message ("You roll $result!", cf::NDI_GREY | cf::NDI_UNIQUE); 126 $pl->send_msg ($SAY_CHANNEL => "You roll $result!", cf::NDI_GREY | cf::NDI_REPLY);
95}; 127};
96 128
97my $emotes = { 129my $emotes = {
98 growl => { 130 growl => {
99 noparams => { 131 noparams => {
676 }, 708 },
677}; 709};
678 710
679for my $emotion (keys %$emotes) { 711for my $emotion (keys %$emotes) {
680 cf::register_command $emotion => sub { 712 cf::register_command $emotion => sub {
681 my ($pl, $tname) = @_; 713 my ($ob, $tname) = @_;
714
715 my $pl = $ob->contr;
682 716
683 cf::async { 717 cf::async {
684 my $name = $pl->name; 718 my $name = $ob->name;
719 $Coro::current->{desc} = "emote handler for $name";
685 720
686 if ($tname eq $name) { 721 if ($tname eq $name) {
687 my $emote = $emotes->{$emotion}->{self}; 722 my %emote = %{ $emotes->{$emotion}->{self} || {} };
688 723
689 $emote->{other} = "You look away from <self>." 724 $emote{other} ||= "You look away from <self>.";
690 if !$emote->{other};
691 $emote->{self} = "My god! Is that LEGAL?" 725 $emote{self} ||= "My god! Is that LEGAL?";
692 if !$emote->{self};
693 726
694 $emote->{other} =~ s/<self>/$name/; 727 $emote{other} =~ s/<self>/$name/;
695 728
729 send_msg $_, $CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat"
696 for my $other ( grep { $pl->on_same_map_as ($_->ob) } cf::player::list ) { 730 for grep { $ob->on_same_map_as ($_->ob) && $_ != $ob} cf::player::list;
697 next
698 if $other->ob == $pl;
699 $other->ob->message ($emote->{other}, cf::NDI_GREY | cf::NDI_UNIQUE);
700 }
701 731
702 $pl->message ($emote->{self}, cf::NDI_GREY | cf::NDI_UNIQUE); 732 $pl->send_msg ($emote{self}, cf::NDI_GREY | cf::NDI_REPLY);
703 } elsif ($tname) { 733 } elsif ($tname) {
704 my $target = cf::player::find $tname 734 my $target = cf::player::find $tname
705 or return $pl->reply (undef, "$tname is not around."); 735 or return send_msg $pl, tell_channel $tname, "$tname is not around.", cf::NDI_DK_ORANGE | cf::NDI_REPLY, "msg_chat";
706 736
707 my $emote = $emotes->{$emotion}->{params}; 737 my %emote = %{ $emotes->{$emotion}->{params} || {} };
708 738
709 $emote->{other} = "<self> is eyeing <other> quizzically." 739 $emote{other} ||= "<self> is eyeing <other> quizzically.";
710 if !$emote->{other};
711 $emote->{self} = "You are still nuts." 740 $emote{self} ||= "You are still nuts.";
712 if !$emote->{self};
713 $emote->{target} = "You get the distinct feeling that <other> is nuts." 741 $emote{target} ||= "You get the distinct feeling that <other> is nuts.";
714 if !$emote->{target};
715 742
716 $emote->{self} =~ s/<other>/$tname/; 743 $emote{self} =~ s/<other>/$tname/;
717 $emote->{target} =~ s/<self>/$name/; 744 $emote{target} =~ s/<self>/$name/;
718 $emote->{other} =~ s/<other>/$tname/; 745 $emote{other} =~ s/<other>/$tname/;
719 $emote->{other} =~ s/<self>/$name/; 746 $emote{other} =~ s/<self>/$name/;
720 747
721 for my $other ( grep { $pl->on_same_map_as ($_->ob) } cf::player::list ) { 748 send_msg $_, $CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat"
722 next 749 for grep { $_ != $pl && $_ != $target && $ob->on_same_map_as ($_->ob) } cf::player::list;
723 if $other->ob == $pl or $other == $target;
724 $other->ob->message ($emote->{other}, cf::NDI_GREY | cf::NDI_UNIQUE);
725 }
726 750
727 $target->ob->message ($emote->{target}, cf::NDI_GREY | cf::NDI_UNIQUE); 751 send_msg $target, tell_channel $name, $emote{target}, cf::NDI_GREY, "msg_shout";
728 $pl->message ($emote->{self}, cf::NDI_GREY | cf::NDI_UNIQUE); 752 $pl->send_msg (tell_channel $tname, $emote{self}, cf::NDI_GREY | cf::NDI_REPLY);
729 } else { 753 } else {
730 my $emote = $emotes->{$emotion}->{noparams}; 754 my %emote = %{ $emotes->{$emotion}->{noparams} || {} };
731 $emote->{other} =~ s/<self>/$name/;
732 755
733 $emote->{other} = "<self> dances with glee." 756 $emote{other} ||= "<self> dances with glee.";
734 if !$emote->{other};
735 $emote->{self} = "You are a nut." 757 $emote{self} ||= "You are a nut.";
736 if !$emote->{self};
737 758
759 $emote{other} =~ s/<self>/$name/;
760
761 send_msg $_, $CHAT_CHANNEL, $emote{other}, cf::NDI_GREY, "msg_chat"
738 for my $other ( grep { $pl->on_same_map_as ($_->ob) } cf::player::list ) { 762 for grep { $ob->on_same_map_as ($_->ob) && $_ != $pl } cf::player::list;
739 next
740 if $other->ob == $pl;
741 $other->ob->message ($emote->{other}, cf::NDI_GREY | cf::NDI_UNIQUE);
742 }
743 763
744 $pl->message ($emote->{self}, cf::NDI_GREY | cf::NDI_UNIQUE); 764 $pl->send_msg ($CHAT_CHANNEL, $emote{self}, cf::NDI_GREY | cf::NDI_REPLY);
745 } 765 }
746 }; 766 };
747 }; 767 };
748} 768}
749 769
750cf::register_command me => sub { 770cf::register_command me => sub {
751 my ($pl, $msg) = @_; 771 my ($pl, $msg) = @_;
752 772
753 my $name = $pl->name; 773 my $name = $pl->name;
754 774
755 $_->ob->message ("* $name $msg", cf::NDI_GREY | cf::NDI_UNIQUE) 775 send_msg $pl, $SAY_CHANNEL => "* $name $msg", cf::NDI_GREY | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_say"
756 for grep $pl->on_same_map_as ($_->ob), cf::player::list; 776 for grep $pl->on_same_map_as ($_->ob), cf::player::list;
757}; 777};
758 778
759cf::register_command say => sub { 779cf::register_command say => sub {
760 my ($pl, $msg) = @_; 780 my ($ob, $msg) = @_;
761 781
762 utf8::decode $msg; 782 utf8::decode $msg;
763 783
764 return if $pl->contr->invoke (cf::EVENT_PLAYER_SAY, $msg); 784 return if $ob->contr->invoke (cf::EVENT_PLAYER_SAY, $msg);
765 785
766 if ($msg) { 786 if ($msg) {
767 my $name = $pl->name; 787 my $name = $ob->name;
768
769 utf8::encode $msg; # ->message not yet utf8-ified
770 $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE)
771 for grep $pl->on_same_map_as ($_->ob), cf::player::list; 788 my @plonmap = grep $ob->on_same_map_as ($_->ob), cf::player::list;
772 utf8::decode $msg; 789
790 send_msg $_, $SAY_CHANNEL => "$name says: $msg", cf::NDI_GREY | ($_ == $ob->contr ? cf::NDI_REPLY : 0), "msg_say"
791 for @plonmap;
773 792
774 # npcs, magic_ears etc. 793 # npcs, magic_ears etc.
775 # first find all objects and theirt-level inventories 794 # first find all objects and their first-level inventories
776 # within a 5x5 square # that have something resembling 795 # within a 5x5 square that have something resembling
777 # dialogue or support on_say. 796 # dialogue or support on_say.
778 my ($map, $x, $y) = ($pl->map, $pl->x - 2, $pl->y - 2); 797 my ($map, $x, $y) = ($ob->map, $ob->x - 2, $ob->y - 2);
779 798
780 for my $npc ( 799 for my $npc (
781 grep +($_->invoke (cf::EVENT_OBJECT_SAY, $pl->contr, $msg) && return) || NPC_Dialogue::has_dialogue $_, 800 grep +($_->invoke (cf::EVENT_OBJECT_SAY, $ob->contr, $msg) && return) || NPC_Dialogue::has_dialogue $_,
782 map +($_, $_->inv), 801 map +($_, $_->inv),
783 grep $_, 802 grep $_,
784 map $map->at ($x + $_ % 5, $y + (int $_ / 5)), 803 map $map->at ($x + $_ % 5, $y + (int $_ / 5)),
785 0..24 804 0..24
786 ) { 805 ) {
787 # if some listener teleported us somewhere else, stop right here 806 # if some listener teleported us somewhere else, stop right here
788 last unless $map->path == $pl->map->path; 807 last unless $map->path == $ob->map->path;
789 808
790 my $dialog = new NPC_Dialogue ob => $pl, npc => $npc; 809 my $dialog = new NPC_Dialogue pl => $ob->contr, npc => $npc;
791 my ($reply, @kw) = $dialog->tell ($msg); 810 my ($reply, @kw) = $dialog->tell ($msg);
792 811
793 if (defined $reply) { 812 if (defined $reply) {
794 if ($npc->type == cf::MAGIC_EAR) { 813 if ($npc->type == cf::MAGIC_EAR) {
795 if (length $reply) { 814 if (length $reply) {
796 $_->ob->message ($reply, cf::NDI_BROWN | cf::NDI_UNIQUE) 815 send_msg $_, $SAY_CHANNEL => $reply, cf::NDI_BROWN, "msg_say"
797 for grep $pl->on_same_map_as ($_->ob), cf::player::list; 816 for @plonmap;
798 } 817 }
799 $npc->use_trigger; 818 $npc->use_trigger;
800 } else { 819 } else {
801 if (length $reply) { 820 if (length $reply) {
802 $_->ob->message ($npc->name . " says: $reply", cf::NDI_BROWN | cf::NDI_UNIQUE) 821 send_msg $_, $SAY_CHANNEL => $npc->name . " says: $reply", cf::NDI_BROWN, "msg_say"
803 for grep $pl->on_same_map_as ($_->ob), cf::player::list; 822 for @plonmap;
804 } 823 }
805 } 824 }
806 } 825 }
807 826
808 if (@kw) { 827 if (@kw) {
809 $_->ob->message ("[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN | cf::NDI_UNIQUE) 828 $_->send_msg ($SAY_CHANNEL => "[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN)
810 for grep $pl->on_same_map_as ($_->ob), cf::player::list; 829 for @plonmap;
811 } 830 }
812 } 831 }
813 832
814 } else { 833 } else {
815 $pl->message ("What do you want to say?", cf::NDI_UNIQUE); 834 $ob->send_msg ($SAY_CHANNEL => "What do you want to say?", cf::NDI_GREY | cf::NDI_REPLY);
816 } 835 }
817}; 836};
818 837
819cf::register_command chat => sub { 838cf::register_command chat => sub {
820 my ($pl, $msg) = @_; 839 my ($ob, $msg) = @_;
821 840
822 utf8::decode $msg; 841 utf8::decode $msg;
823 842
843 my $pl = $ob->contr;
844
824 return if $pl->contr->invoke (cf::EVENT_PLAYER_CHAT, $msg); 845 return if $pl->invoke (cf::EVENT_PLAYER_CHAT, $msg);
825 846
826 if ($msg) { 847 if ($msg) {
827 my $name = $pl->name; 848 my $name = $ob->name;
828 my $NOW = time; 849 my $NOW = time;
829 850
830 utf8::encode $msg; # ->message not yet utf8-ified
831 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; 851 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg;
832 ext::schmorp_irc::do_notice (sprintf "[%s] %s", $name, $msg); 852 send_irc ("[%s] %s", $name, $msg);
833 853
834 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) 854 send_msg $_, $CHAT_CHANNEL => "$name chats: $msg", cf::NDI_BLUE | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_chat"
835 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; 855 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list;
836 856
837 } else { 857 } else {
838 $pl->message ("Chat what?", cf::NDI_UNIQUE); 858 $pl->send_msg ($CHAT_CHANNEL => "Chat what?", cf::NDI_BLUE | cf::NDI_DEF | cf::NDI_REPLY);
839 } 859 }
840}; 860};
841 861
842cf::register_command shout => sub { 862cf::register_command shout => sub {
843 my ($pl, $msg) = @_; 863 my ($ob, $msg) = @_;
844 864
845 utf8::decode $msg; 865 utf8::decode $msg;
846 866
867 my $pl = $ob->contr;
868
847 return if $pl->contr->invoke (cf::EVENT_PLAYER_SHOUT, $msg); 869 return if $pl->invoke (cf::EVENT_PLAYER_SHOUT, $msg);
848 870
849 if ($msg) { 871 if ($msg) {
850 my $NOW = time; 872 my $NOW = time;
851 my $name = $pl->name; 873 my $name = $ob->name;
852 874
853 cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; 875 cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg;
854 ext::schmorp_irc::do_notice (sprintf "\007\0034{%s} %s\n", $name, $msg); 876 send_irc ("\007\0034{%s} %s\n", $name, $msg);
855 877
856 utf8::encode $msg; # ->message not yet utf8-ified 878 send_msg $_, $CHAT_CHANNEL => "$name shouts: $msg", cf::NDI_RED | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_shout"
857 $_->ob->message ("$name shouts: $msg", cf::NDI_RED)
858 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; 879 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list;
859 880
860 } else { 881 } else {
861 $pl->message ("Shout what?", cf::NDI_UNIQUE); 882 $pl->send_msg ($CHAT_CHANNEL => "Shout what?", cf::NDI_RED | cf::NDI_DEF | cf::NDI_REPLY);
862 } 883 }
863}; 884};
864 885
865cf::register_command tell => sub { 886cf::register_command tell => sub {
866 my ($pl, $args) = @_; 887 my ($ob, $args) = @_;
867 my ($target, $msg) = split /\s+/, $args, 2; 888 my ($target, $msg) = split /\s+/, $args, 2;
868 889
869 utf8::decode $msg; 890 utf8::decode $msg;
870 891
892 my $pl = $ob->contr;
893 my $ns = $pl->ns
894 or return;
895 my $name = $ob->name;
896
871 return if $pl->contr->invoke (cf::EVENT_PLAYER_TELL, $target, $msg); 897 return if $pl->invoke (cf::EVENT_PLAYER_TELL, $target, $msg);
872 898
873 my $name = $pl->name; 899 my $pl_channel = tell_channel $target;
874 900
875 if ($target =~ /irc\//) { 901 if ($target =~ /irc\//) {
876 my (undef, $nick) = split /\//, $target, 2; 902 my (undef, $nick) = split /\//, $target, 2;
877 $pl->message ("You tell $target: $args"); 903 $ns->send_msg ($pl_channel => "You tell $target: $args", cf::NDI_DK_ORANGE | cf::NDI_DEF | cf::NDI_REPLY);
878 ext::schmorp_irc::do_notice (sprintf "(%s) %s: %s\n", $name, $nick, $msg); 904 send_irc ("(%s) %s: %s\n", $name, $nick, $msg);
905
879 } elsif (my $other = cf::player::find_active $target) { 906 } elsif (my $other = cf::player::find_active $target) {
907 my $other_channel = tell_channel $name;
880 908
881 if ($msg) { 909 if ($msg) {
882 if ($target eq $name) { 910 if ($target eq $name) {
883 $pl->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); 911 $ns->send_msg ($pl_channel => "You are talking to yourself, you freak!", cf::NDI_DK_ORANGE | cf::NDI_DEF | cf::NDI_REPLY);
884 } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { 912 } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) {
885 $pl->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE); 913 $ns->send_msg ($pl_channel => "$target ignores what you say. Give up on it.", cf::NDI_DK_ORANGE | cf::NDI_DEF | cf::NDI_REPLY);
886 } else { 914 } else {
887 return if $other->invoke (cf::EVENT_PLAYER_TOLD, $pl->contr, $msg); 915 return if $other->invoke (cf::EVENT_PLAYER_TOLD, $pl, $msg);
888 utf8::encode $msg; # ->message not yet utf8-ified
889 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg; 916 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg;
890 917
891 $pl->message ("You tell $target: $msg"); 918 $ns->send_msg ($pl_channel => "You tell $target: $msg", cf::NDI_DK_ORANGE | cf::NDI_DEF | cf::NDI_REPLY);
892 $other->ob->message ("$name tells you: $msg"); 919 send_msg $other, $other_channel => "$name tells you: $msg", cf::NDI_DK_ORANGE | cf::NDI_DEF, "msg_tell";
893 $other->ob->{ext_last_tell} = $name;
894 } 920 }
895 } else { 921 } else {
896 $pl->message ("What do you want to tell $target?", cf::NDI_UNIQUE); 922 $ns->send_msg ($pl_channel => "What do you want to tell $target?", cf::NDI_DK_ORANGE | cf::NDI_DEF | cf::NDI_REPLY);
897 } 923 }
898 924
899 } else { 925 } else {
900 $pl->message ("No such player. Your message: $msg", cf::NDI_UNIQUE); 926 $ns->send_msg ($pl_channel => "No such player. Your message: $msg", cf::NDI_DK_ORANGE | cf::NDI_DEF | cf::NDI_REPLY);
901 }
902};
903
904cf::register_command reply => sub {
905 my ($pl, $args) = @_;
906 my $name = $pl->name;
907
908 utf8::decode $args;
909
910 return if $pl->contr->invoke (cf::EVENT_PLAYER_TELL, $pl->{ext_last_tell}, $args);
911
912 if ($pl->{ext_last_tell} =~ /irc\//) {
913 my (undef, $nick) = split /\//, $pl->{ext_last_tell}, 2;
914 $pl->message ("You tell " . $pl->{ext_last_tell} . ": $args");
915 ext::schmorp_irc::do_notice (sprintf "(%s) %s: %s\n", $name, $nick, $args);
916 } elsif (my $other = cf::player::find_active $pl->{ext_last_tell}) {
917
918 if ($args) {
919 $other->ob->{ext_ignore_tell}{$name} >= time
920 or delete $other->ob->{ext_ignore_tell}{$name};
921
922 if ($other->ob->{ext_ignore_tell}{$name} < time) {
923 utf8::encode $args; # ->message not yet utf8-ified
924 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $other->ob->name, $args;
925
926 $pl->message ("You tell " . $other->ob->name . ": $args");
927 $other->ob->message ("$name tells you: $args");
928 $pl->{ext_last_tell} = $other->ob->name;
929 } else {
930 $pl->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE);
931 }
932 } else {
933 $pl->message ("What do you want to tell ".$other->ob->name."?", cf::NDI_UNIQUE);
934 }
935
936 } else {
937 $pl->message ("Can't reply, player left. Your message: $args".$pl->{ext_last_tell}, cf::NDI_UNIQUE);
938 } 927 }
939}; 928};
940 929
941cf::register_command ignore => sub { 930cf::register_command ignore => sub {
942 my ($pl, $args) = @_; 931 my ($pl, $args) = @_;
945 if ($args eq "list") { 934 if ($args eq "list") {
946 clean_timeouts $pl; 935 clean_timeouts $pl;
947 936
948 if ((my @ignored_tell = sort keys %{$pl->{ext_ignore_tell}}) 937 if ((my @ignored_tell = sort keys %{$pl->{ext_ignore_tell}})
949 + (my @ignored_shout = sort keys %{$pl->{ext_ignore_shout}})) { 938 + (my @ignored_shout = sort keys %{$pl->{ext_ignore_shout}})) {
950 $pl->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE); 939 $pl->message ("Currently ignoring private messages from: ", cf::NDI_REPLY);
951 $pl->message ((join ", ", @ignored_tell), cf::NDI_UNIQUE); 940 $pl->message ((join ", ", @ignored_tell), cf::NDI_REPLY);
952 $pl->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE); 941 $pl->message ("Currently ignoring shouts from: ", cf::NDI_REPLY);
953 $pl->message ((join ", ", @ignored_shout), cf::NDI_UNIQUE); 942 $pl->message ((join ", ", @ignored_shout), cf::NDI_REPLY);
954 $pl->message ("To stop ignoring one, use unignore.", cf::NDI_UNIQUE); 943 $pl->message ("To stop ignoring one, use unignore.", cf::NDI_REPLY);
955 } else { 944 } else {
956 $pl->message ("Not ignoring anyone", cf::NDI_UNIQUE); 945 $pl->message ("Not ignoring anyone", cf::NDI_REPLY);
957 } 946 }
958 947
959 } elsif ($target && $type) { 948 } elsif ($target && $type) {
960 949
961 $timeout ne "" or $timeout = 24; 950 $timeout ne "" or $timeout = 24;
962 my $absolute_timeout = time + $timeout * 3600; 951 my $absolute_timeout = time + $timeout * 3600;
963 952
964 if (cf::player::exists $target) { 953 if (cf::player::exists $target) {
965 if ($type eq "tell") { 954 if ($type eq "tell") {
966 $pl->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_UNIQUE); 955 $pl->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_REPLY);
967 $pl->{ext_ignore_tell}{$target} = $absolute_timeout; 956 $pl->{ext_ignore_tell}{$target} = $absolute_timeout;
968 } elsif ($type eq "shout") { 957 } elsif ($type eq "shout") {
969 $pl->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_UNIQUE); 958 $pl->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_REPLY);
970 $pl->{ext_ignore_shout}{$target} = $absolute_timeout; 959 $pl->{ext_ignore_shout}{$target} = $absolute_timeout;
971 } elsif ($type eq "all") { 960 } elsif ($type eq "all") {
972 $pl->message ("Now ignoring everything from $target for $timeout hours.", cf::NDI_UNIQUE); 961 $pl->message ("Now ignoring everything from $target for $timeout hours.", cf::NDI_REPLY);
973 $pl->{ext_ignore_tell}{$target} = $absolute_timeout; 962 $pl->{ext_ignore_tell}{$target} = $absolute_timeout;
974 $pl->{ext_ignore_shout}{$target} = $absolute_timeout; 963 $pl->{ext_ignore_shout}{$target} = $absolute_timeout;
975 } else { 964 } else {
976 $pl->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE); 965 $pl->message ("You need to specify tell, shout or all.", cf::NDI_REPLY);
977 } 966 }
978 } else { 967 } else {
979 $pl->message ("No such player: $target", cf::NDI_UNIQUE); 968 $pl->message ("No such player: $target", cf::NDI_REPLY);
980 } 969 }
981 970
982 } else { 971 } else {
983 $pl->message ("Usage: ignore <player> <tell|shout|all> <timeout>\n" 972 $pl->message ("Usage: ignore <player> <tell|shout|all> <timeout>\n"
984 . "will ignore a player for <timeout> hours.\n" 973 . "will ignore a player for <timeout> hours.\n"
985 . "Usage: ignore list\n" 974 . "Usage: ignore list\n"
986 . "will show you a list of players currently ignored.", cf::NDI_UNIQUE); 975 . "will show you a list of players currently ignored.", cf::NDI_REPLY);
987 } 976 }
988}; 977};
989 978
990cf::register_command unignore => sub { 979cf::register_command unignore => sub {
991 my ($pl, $args) = @_; 980 my ($pl, $args) = @_;
992 my ($target, $type) = split /\s+/, $args; 981 my ($target, $type) = split /\s+/, $args;
993 982
994 if ($args eq "") { 983 if ($args eq "") {
995 if ($pl->{ext_ignore_tell}) { 984 if ($pl->{ext_ignore_tell}) {
996 $pl->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE); 985 $pl->message ("Currently ignoring private messages from: ", cf::NDI_REPLY);
997 $pl->message ((join ", ", sort keys %{ $pl->{ext_ignore_tell} }), cf::NDI_UNIQUE); 986 $pl->message ((join ", ", sort keys %{ $pl->{ext_ignore_tell} }), cf::NDI_REPLY);
998 $pl->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE); 987 $pl->message ("Currently ignoring shouts from: ", cf::NDI_REPLY);
999 $pl->message ((join ", ", sort keys %{ $pl->{ext_ignore_shout} }), cf::NDI_UNIQUE); 988 $pl->message ((join ", ", sort keys %{ $pl->{ext_ignore_shout} }), cf::NDI_REPLY);
1000 } else { 989 } else {
1001 $pl->message ("Not ignoring anyone", cf::NDI_UNIQUE); 990 $pl->message ("Not ignoring anyone", cf::NDI_REPLY);
1002 } 991 }
1003 } else { 992 } else {
1004 if (cf::player::exists $target) { 993 if (cf::player::exists $target) {
1005 if ($type eq "tell") { 994 if ($type eq "tell") {
1006 $pl->message ("Not ignoring private messages from $target anymore.", cf::NDI_UNIQUE); 995 $pl->message ("Not ignoring private messages from $target anymore.", cf::NDI_REPLY);
1007 delete $pl->{ext_ignore_tell} {$target}; 996 delete $pl->{ext_ignore_tell} {$target};
1008 } elsif ($type eq "shout") { 997 } elsif ($type eq "shout") {
1009 $pl->message ("Not ignoring shouts from $target anymore.", cf::NDI_UNIQUE); 998 $pl->message ("Not ignoring shouts from $target anymore.", cf::NDI_REPLY);
1010 delete $pl->{ext_ignore_shout}{$target}; 999 delete $pl->{ext_ignore_shout}{$target};
1011 } elsif ($type eq "all") { 1000 } elsif ($type eq "all") {
1012 $pl->message ("Not ignoring anything from $target anymore.", cf::NDI_UNIQUE); 1001 $pl->message ("Not ignoring anything from $target anymore.", cf::NDI_REPLY);
1013 delete $pl->{ext_ignore_tell} {$target}; 1002 delete $pl->{ext_ignore_tell} {$target};
1014 delete $pl->{ext_ignore_shout}{$target}; 1003 delete $pl->{ext_ignore_shout}{$target};
1015 } else { 1004 } else {
1016 $pl->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE); 1005 $pl->message ("You need to specify tell, shout or all.", cf::NDI_REPLY);
1017 } 1006 }
1018 } else { 1007 } else {
1019 $pl->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE); 1008 $pl->message ("No such player or ambiguous name: $target", cf::NDI_REPLY);
1020 } 1009 }
1021 } 1010 }
1022}; 1011};
1023 1012

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines