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 | |
… | |
… | |
22 | } |
22 | } |
23 | } |
23 | } |
24 | } |
24 | } |
25 | } |
25 | } |
26 | |
26 | |
|
|
27 | # send_irc ($format, @args, $msg) |
|
|
28 | # make sure the last argument is the message! |
|
|
29 | sub send_irc { |
|
|
30 | my ($format, @args) = @_; |
|
|
31 | my $msg = pop @args; |
|
|
32 | for (split /\n/, $msg) { |
|
|
33 | ext::irc::do_notice (sprintf $format, @args, $_) |
|
|
34 | } |
|
|
35 | } |
|
|
36 | |
27 | cf::player->attach ( |
37 | cf::player->attach ( |
28 | prio => -1000, |
38 | prio => -1000, |
29 | on_login => sub { |
39 | on_login => sub { |
30 | my ($pl) = @_; |
40 | my ($pl) = @_; |
31 | |
41 | |
32 | clean_timeouts $pl->ob; |
42 | clean_timeouts $pl->ob; |
33 | }, |
43 | }, |
34 | |
|
|
35 | 1 |
|
|
36 | ); |
44 | ); |
37 | |
45 | |
38 | cf::register_command listen => sub { |
46 | cf::register_command listen => sub { |
39 | my ($who, $msg) = @_; |
47 | my ($pl, $msg) = @_; |
40 | my $player = cf::player::find_active $who->name; |
48 | my $player = cf::player::find_active $pl->name; |
41 | |
49 | |
42 | if ($msg ne "") { |
50 | if ($msg ne "") { |
|
|
51 | $msg = 10 if $msg > 10; |
|
|
52 | |
43 | my $prev_listen = $player->listening; |
53 | my $prev_listen = $player->listening; |
44 | $player->listening ($msg); |
54 | $player->listening ($msg); |
45 | if ($prev_listen == $player->listening) { |
55 | if ($prev_listen == $player->listening) { |
46 | $who->message ("Your verbose level stayed $prev_listen.", cf::NDI_UNIQUE); |
56 | $pl->message ("Your verbose level stayed $prev_listen.", cf::NDI_UNIQUE); |
47 | } else { |
57 | } else { |
48 | $who->message ("Your verbose level is now " . $player->listening . ". (previously: $prev_listen)", cf::NDI_UNIQUE); |
58 | $pl->message ("Your verbose level is now " . $player->listening . ". (previously: $prev_listen)", cf::NDI_UNIQUE); |
49 | } |
59 | } |
50 | } else { |
60 | } else { |
51 | $who->message ("Your verbose level is " . $player->listening . ".", cf::NDI_UNIQUE); |
61 | $pl->message ("Your verbose level is " . $player->listening . ".", cf::NDI_UNIQUE); |
52 | } |
|
|
53 | |
|
|
54 | 1 |
62 | } |
|
|
63 | }; |
|
|
64 | |
|
|
65 | cf::register_command cointoss => sub { |
|
|
66 | my ($pl, $msg) = @_; |
|
|
67 | |
|
|
68 | my $name = $pl->name; |
|
|
69 | |
|
|
70 | if (int rand 2) { |
|
|
71 | for my $other ( grep { $pl->on_same_map_as ($_->ob) } cf::player::list ) { |
|
|
72 | next |
|
|
73 | if $other->ob == $pl; |
|
|
74 | $other->ob->message ("$name flips a coin.... Heads!", cf::NDI_GREY | cf::NDI_UNIQUE); |
|
|
75 | } |
|
|
76 | |
|
|
77 | $pl->message ("You flip a coin.... Heads!", cf::NDI_GREY | cf::NDI_UNIQUE); |
|
|
78 | } else { |
|
|
79 | for my $other ( grep { $pl->on_same_map_as ($_->ob) } cf::player::list ) { |
|
|
80 | next |
|
|
81 | if $other->ob == $pl; |
|
|
82 | $other->ob->message ("$name flips a coin.... Tails!", cf::NDI_GREY | cf::NDI_UNIQUE); |
|
|
83 | } |
|
|
84 | |
|
|
85 | $pl->message ("You flip a coin.... Tails!", cf::NDI_GREY | cf::NDI_UNIQUE); |
|
|
86 | } |
|
|
87 | }; |
|
|
88 | |
|
|
89 | cf::register_command orcknuckle => sub { |
|
|
90 | my ($pl, $msg) = @_; |
|
|
91 | my @orcknuckle = ("none", "beholder", "ghost", "knight", "princess", "dragon", "orc"); |
|
|
92 | |
|
|
93 | my $name = $pl->name; |
|
|
94 | |
|
|
95 | my ($i, $j, $k, $l) = ((int rand 5) + 1, (int rand 5) + 1, (int rand 5) + 1, (int rand 6) + 1); |
|
|
96 | my $result = "$orcknuckle[$i], $orcknuckle[$j], $orcknuckle[$k], $orcknuckle[$l]"; |
|
|
97 | |
|
|
98 | for my $other ( grep { $pl->on_same_map_as ($_->ob) } cf::player::list ) { |
|
|
99 | next |
|
|
100 | if $other->ob == $pl; |
|
|
101 | $other->ob->message ("$name rolls $result!", cf::NDI_GREY | cf::NDI_UNIQUE); |
|
|
102 | } |
|
|
103 | |
|
|
104 | $pl->message ("You roll $result!", cf::NDI_GREY | cf::NDI_UNIQUE); |
55 | }; |
105 | }; |
56 | |
106 | |
57 | my $emotes = { |
107 | my $emotes = { |
58 | growl => { |
108 | growl => { |
59 | noparams => { |
109 | noparams => { |
… | |
… | |
189 | noparams => { |
239 | noparams => { |
190 | other => "<self> winks suggestively.", |
240 | other => "<self> winks suggestively.", |
191 | self => "Have you got something in your eye?", |
241 | self => "Have you got something in your eye?", |
192 | }, |
242 | }, |
193 | params => { |
243 | params => { |
|
|
244 | target => "<self> winks at you.", |
194 | target => "<self> winks at <other>.", |
245 | other => "<self> winks at <other>.", |
195 | self => "You wink suggestively at <other>.", |
246 | self => "You wink suggestively at <other>.", |
196 | }, |
247 | }, |
197 | self => { |
248 | self => { |
198 | other => "<self> winks at himself - something strange is going on...", |
249 | other => "<self> winks at himself - something strange is going on...", |
199 | self => "You wink at yourself?? What are you up to?", |
250 | self => "You wink at yourself?? What are you up to?", |
… | |
… | |
289 | noparams => { |
340 | noparams => { |
290 | other => "<self> is bleeding all over the carpet - got a spare tourniquet?", |
341 | other => "<self> is bleeding all over the carpet - got a spare tourniquet?", |
291 | self => "You bleed all over your nice new armour.", |
342 | self => "You bleed all over your nice new armour.", |
292 | }, |
343 | }, |
293 | params => { |
344 | params => { |
|
|
345 | target => "<self> slashes his wrist and bleeds all over you.", |
294 | target => "<self> slashes his wrist and bleeds all over <other>.", |
346 | other => "<self> slashes his wrist and bleeds all over <other>.", |
295 | self => "You slash your wrist and bleed all over <other>", |
347 | self => "You slash your wrist and bleed all over <other>", |
296 | }, |
348 | }, |
297 | self => { |
349 | self => { |
298 | other => "<self> performs some satanic ritual while wiping his blood on himself.", |
350 | other => "<self> performs some satanic ritual while wiping his blood on himself.", |
299 | self => "Very impressive! You wipe your blood all over yourself.", |
351 | self => "Very impressive! You wipe your blood all over yourself.", |
… | |
… | |
634 | }, |
686 | }, |
635 | }; |
687 | }; |
636 | |
688 | |
637 | for my $emotion (keys %$emotes) { |
689 | for my $emotion (keys %$emotes) { |
638 | cf::register_command $emotion => sub { |
690 | cf::register_command $emotion => sub { |
639 | my ($ob, $tname) = @_; |
691 | my ($pl, $tname) = @_; |
640 | |
692 | |
641 | cf::async { |
693 | cf::async { |
642 | my $name = $ob->name; |
694 | my $name = $pl->name; |
643 | |
695 | |
644 | if ($tname eq $name) { |
696 | if ($tname eq $name) { |
645 | my $emote = $emotes->{$emotion}->{self}; |
697 | my $emote = $emotes->{$emotion}->{self}; |
646 | |
698 | |
647 | $emote->{other} = "You look away from <self>." |
699 | $emote->{other} = "You look away from <self>." |
… | |
… | |
649 | $emote->{self} = "My god! Is that LEGAL?" |
701 | $emote->{self} = "My god! Is that LEGAL?" |
650 | if !$emote->{self}; |
702 | if !$emote->{self}; |
651 | |
703 | |
652 | $emote->{other} =~ s/<self>/$name/; |
704 | $emote->{other} =~ s/<self>/$name/; |
653 | |
705 | |
654 | for my $other ( grep { $ob->on_same_map_as ($_->ob) } cf::player::list ) { |
706 | for my $other ( grep { $pl->on_same_map_as ($_->ob) } cf::player::list ) { |
655 | next |
707 | next |
656 | if $other->ob == $ob; |
708 | if $other->ob == $pl; |
657 | $other->ob->message ($emote->{other}, cf::NDI_GREY | cf::NDI_UNIQUE); |
709 | $other->ob->message ($emote->{other}, cf::NDI_GREY | cf::NDI_UNIQUE); |
658 | } |
710 | } |
659 | |
711 | |
660 | $ob->message ($emote->{self}, cf::NDI_GREY | cf::NDI_UNIQUE); |
712 | $pl->message ($emote->{self}, cf::NDI_GREY | cf::NDI_UNIQUE); |
661 | } elsif ($tname) { |
713 | } elsif ($tname) { |
662 | my $target = cf::player::find $tname |
714 | my $target = cf::player::find $tname |
663 | or return $ob->reply (undef, "$tname is not around."); |
715 | or return $pl->reply (undef, "$tname is not around."); |
664 | |
716 | |
665 | my $emote = $emotes->{$emotion}->{params}; |
717 | my $emote = $emotes->{$emotion}->{params}; |
666 | |
718 | |
667 | $emote->{other} = "<self> is eyeing <other> quizzically." |
719 | $emote->{other} = "<self> is eyeing <other> quizzically." |
668 | if !$emote->{other}; |
720 | if !$emote->{other}; |
… | |
… | |
674 | $emote->{self} =~ s/<other>/$tname/; |
726 | $emote->{self} =~ s/<other>/$tname/; |
675 | $emote->{target} =~ s/<self>/$name/; |
727 | $emote->{target} =~ s/<self>/$name/; |
676 | $emote->{other} =~ s/<other>/$tname/; |
728 | $emote->{other} =~ s/<other>/$tname/; |
677 | $emote->{other} =~ s/<self>/$name/; |
729 | $emote->{other} =~ s/<self>/$name/; |
678 | |
730 | |
679 | for my $other ( grep { $ob->on_same_map_as ($_->ob) } cf::player::list ) { |
731 | for my $other ( grep { $pl->on_same_map_as ($_->ob) } cf::player::list ) { |
680 | next |
732 | next |
681 | if $other->ob == $ob or $other == $target; |
733 | if $other->ob == $pl or $other == $target; |
682 | $other->ob->message ($emote->{other}, cf::NDI_GREY | cf::NDI_UNIQUE); |
734 | $other->ob->message ($emote->{other}, cf::NDI_GREY | cf::NDI_UNIQUE); |
683 | } |
735 | } |
684 | |
736 | |
685 | $target->ob->message ($emote->{target}, cf::NDI_GREY | cf::NDI_UNIQUE); |
737 | $target->ob->message ($emote->{target}, cf::NDI_GREY | cf::NDI_UNIQUE); |
686 | $ob->message ($emote->{self}, cf::NDI_GREY | cf::NDI_UNIQUE); |
738 | $pl->message ($emote->{self}, cf::NDI_GREY | cf::NDI_UNIQUE); |
687 | } else { |
739 | } else { |
688 | my $emote = $emotes->{$emotion}->{noparams}; |
740 | my $emote = $emotes->{$emotion}->{noparams}; |
689 | $emote->{other} =~ s/<self>/$name/; |
741 | $emote->{other} =~ s/<self>/$name/; |
690 | |
742 | |
691 | $emote->{other} = "<self> dances with glee." |
743 | $emote->{other} = "<self> dances with glee." |
692 | if !$emote->{other}; |
744 | if !$emote->{other}; |
693 | $emote->{self} = "You are a nut." |
745 | $emote->{self} = "You are a nut." |
694 | if !$emote->{self}; |
746 | if !$emote->{self}; |
695 | |
747 | |
696 | for my $other ( grep { $ob->on_same_map_as ($_->ob) } cf::player::list ) { |
748 | for my $other ( grep { $pl->on_same_map_as ($_->ob) } cf::player::list ) { |
697 | next |
749 | next |
698 | if $other->ob == $ob; |
750 | if $other->ob == $pl; |
699 | $other->ob->message ($emote->{other}, cf::NDI_GREY | cf::NDI_UNIQUE); |
751 | $other->ob->message ($emote->{other}, cf::NDI_GREY | cf::NDI_UNIQUE); |
700 | } |
752 | } |
701 | |
753 | |
702 | $ob->message ($emote->{self}, cf::NDI_GREY | cf::NDI_UNIQUE); |
754 | $pl->message ($emote->{self}, cf::NDI_GREY | cf::NDI_UNIQUE); |
703 | } |
755 | } |
704 | }; |
756 | }; |
705 | }; |
757 | }; |
706 | } |
758 | } |
707 | |
759 | |
|
|
760 | cf::register_command me => sub { |
|
|
761 | my ($pl, $msg) = @_; |
|
|
762 | |
|
|
763 | my $name = $pl->name; |
|
|
764 | |
|
|
765 | $_->ob->message ("* $name $msg", cf::NDI_GREY | cf::NDI_UNIQUE) |
|
|
766 | for grep $pl->on_same_map_as ($_->ob), cf::player::list; |
|
|
767 | }; |
|
|
768 | |
708 | cf::register_command say => sub { |
769 | cf::register_command say => sub { |
709 | my ($who, $msg) = @_; |
770 | my ($pl, $msg) = @_; |
710 | |
771 | |
711 | utf8::decode $msg; |
772 | utf8::decode $msg; |
712 | |
773 | |
713 | return if $who->contr->invoke (cf::EVENT_PLAYER_SAY, $msg); |
774 | return if $pl->contr->invoke (cf::EVENT_PLAYER_SAY, $msg); |
714 | |
775 | |
715 | if ($msg) { |
776 | if ($msg) { |
716 | my $name = $who->name; |
777 | my $name = $pl->name; |
717 | |
778 | |
718 | utf8::encode $msg; # ->message not yet utf8-ified |
|
|
719 | $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE) |
779 | $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE) |
720 | for grep $who->on_same_map_as ($_->ob), cf::player::list; |
780 | for grep $pl->on_same_map_as ($_->ob), cf::player::list; |
721 | utf8::decode $msg; |
|
|
722 | |
781 | |
723 | # npcs, magic_ears etc. |
782 | # npcs, magic_ears etc. |
724 | # first find all objects and theirt-level inventories |
783 | # first find all objects and their first-level inventories |
725 | # within a 5x5 square # that have something resembling |
784 | # within a 5x5 square that have something resembling |
726 | # dialogue or support on_say. |
785 | # dialogue or support on_say. |
727 | my ($map, $x, $y) = ($who->map, $who->x - 2, $who->y - 2); |
786 | my ($map, $x, $y) = ($pl->map, $pl->x - 2, $pl->y - 2); |
728 | |
787 | |
729 | for my $npc ( |
788 | for my $npc ( |
730 | grep +($_->invoke (cf::EVENT_OBJECT_SAY, $who->contr, $msg) && return) || NPC_Dialogue::has_dialogue $_, |
789 | grep +($_->invoke (cf::EVENT_OBJECT_SAY, $pl->contr, $msg) && return) || NPC_Dialogue::has_dialogue $_, |
731 | map +($_, $_->inv), |
790 | map +($_, $_->inv), |
732 | grep $_, |
791 | grep $_, |
733 | map $map->at ($x + $_ % 5, $y + (int $_ / 5)), |
792 | map $map->at ($x + $_ % 5, $y + (int $_ / 5)), |
734 | 0..24 |
793 | 0..24 |
735 | ) { |
794 | ) { |
736 | # if some listener teleported us somewhere else, stop right here |
795 | # if some listener teleported us somewhere else, stop right here |
737 | last unless $map->path == $who->map->path; |
796 | last unless $map->path == $pl->map->path; |
738 | |
797 | |
739 | my $dialog = new NPC_Dialogue ob => $who, npc => $npc; |
798 | my $dialog = new NPC_Dialogue pl => $pl->contr, npc => $npc; |
740 | my ($reply, @kw) = $dialog->tell ($msg); |
799 | my ($reply, @kw) = $dialog->tell ($msg); |
741 | |
800 | |
742 | if (defined $reply) { |
801 | if (defined $reply) { |
743 | if ($npc->type == cf::MAGIC_EAR) { |
802 | if ($npc->type == cf::MAGIC_EAR) { |
744 | if (length $reply) { |
803 | if (length $reply) { |
745 | $_->ob->message ($reply, cf::NDI_BROWN | cf::NDI_UNIQUE) |
804 | $_->ob->message ($reply, cf::NDI_BROWN | cf::NDI_UNIQUE) |
746 | for grep $who->on_same_map_as ($_->ob), cf::player::list; |
805 | for grep $pl->on_same_map_as ($_->ob), cf::player::list; |
747 | } |
806 | } |
748 | $npc->use_trigger; |
807 | $npc->use_trigger; |
749 | } else { |
808 | } else { |
750 | if (length $reply) { |
809 | if (length $reply) { |
751 | $_->ob->message ($npc->name . " says: $reply", cf::NDI_BROWN | cf::NDI_UNIQUE) |
810 | $_->ob->message ($npc->name . " says: $reply", cf::NDI_BROWN | cf::NDI_UNIQUE) |
752 | for grep $who->on_same_map_as ($_->ob), cf::player::list; |
811 | for grep $pl->on_same_map_as ($_->ob), cf::player::list; |
753 | } |
812 | } |
754 | } |
813 | } |
755 | } |
814 | } |
756 | |
815 | |
757 | if (@kw) { |
816 | if (@kw) { |
758 | $_->ob->message ("[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN | cf::NDI_UNIQUE) |
817 | $_->ob->message ("[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN | cf::NDI_UNIQUE) |
759 | for grep $who->on_same_map_as ($_->ob), cf::player::list; |
818 | for grep $pl->on_same_map_as ($_->ob), cf::player::list; |
760 | } |
819 | } |
761 | } |
820 | } |
762 | |
821 | |
763 | } else { |
822 | } else { |
764 | $who->message ("What do you want to say?", cf::NDI_UNIQUE); |
823 | $pl->message ("What do you want to say?", cf::NDI_UNIQUE); |
765 | } |
|
|
766 | |
|
|
767 | 1 |
824 | } |
768 | }; |
825 | }; |
769 | |
826 | |
770 | cf::register_command chat => sub { |
827 | cf::register_command chat => sub { |
771 | my ($who, $msg) = @_; |
828 | my ($pl, $msg) = @_; |
772 | |
829 | |
773 | utf8::decode $msg; |
830 | utf8::decode $msg; |
774 | |
831 | |
775 | return if $who->contr->invoke (cf::EVENT_PLAYER_CHAT, $msg); |
832 | return if $pl->contr->invoke (cf::EVENT_PLAYER_CHAT, $msg); |
776 | |
833 | |
777 | if ($msg) { |
834 | if ($msg) { |
778 | my $name = $who->name; |
835 | my $name = $pl->name; |
779 | my $NOW = time; |
836 | my $NOW = time; |
780 | |
837 | |
781 | utf8::encode $msg; # ->message not yet utf8-ified |
|
|
782 | cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; |
838 | cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; |
783 | ext::schmorp_irc::do_notice (sprintf "[%s] %s", $name, $msg); |
839 | send_irc ("[%s] %s", $name, $msg); |
784 | |
840 | |
785 | $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) |
841 | $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) |
786 | 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; |
787 | |
843 | |
788 | } else { |
844 | } else { |
789 | $who->message ("Chat what?", cf::NDI_UNIQUE); |
845 | $pl->message ("Chat what?", cf::NDI_UNIQUE); |
790 | } |
|
|
791 | |
|
|
792 | 1 |
846 | } |
793 | }; |
847 | }; |
794 | |
848 | |
795 | cf::register_command shout => sub { |
849 | cf::register_command shout => sub { |
796 | my ($who, $msg) = @_; |
850 | my ($pl, $msg) = @_; |
797 | |
851 | |
798 | utf8::decode $msg; |
852 | utf8::decode $msg; |
799 | |
853 | |
800 | return if $who->contr->invoke (cf::EVENT_PLAYER_SHOUT, $msg); |
854 | return if $pl->contr->invoke (cf::EVENT_PLAYER_SHOUT, $msg); |
801 | |
855 | |
802 | if ($msg) { |
856 | if ($msg) { |
803 | my $NOW = time; |
857 | my $NOW = time; |
804 | my $name = $who->name; |
858 | my $name = $pl->name; |
805 | |
859 | |
806 | cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; |
860 | cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; |
807 | ext::schmorp_irc::do_notice (sprintf "\007\0034{%s} %s\n", $name, $msg); |
861 | send_irc ("\007\0034{%s} %s\n", $name, $msg); |
808 | |
862 | |
809 | utf8::encode $msg; # ->message not yet utf8-ified |
|
|
810 | $_->ob->message ("$name shouts: $msg", cf::NDI_RED) |
863 | $_->ob->message ("$name shouts: $msg", cf::NDI_RED) |
811 | 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; |
812 | |
865 | |
813 | } else { |
866 | } else { |
814 | $who->message ("Shout what?", cf::NDI_UNIQUE); |
867 | $pl->message ("Shout what?", cf::NDI_UNIQUE); |
815 | } |
|
|
816 | |
|
|
817 | 1 |
868 | } |
818 | }; |
869 | }; |
819 | |
870 | |
820 | cf::register_command tell => sub { |
871 | cf::register_command tell => sub { |
821 | my ($who, $args) = @_; |
872 | my ($pl, $args) = @_; |
822 | my ($target, $msg) = split /\s+/, $args, 2; |
873 | my ($target, $msg) = split /\s+/, $args, 2; |
823 | |
874 | |
824 | utf8::decode $msg; |
875 | utf8::decode $msg; |
825 | |
876 | |
826 | return if $who->contr->invoke (cf::EVENT_PLAYER_TELL, $target, $msg); |
877 | return if $pl->contr->invoke (cf::EVENT_PLAYER_TELL, $target, $msg); |
827 | |
878 | |
828 | my $name = $who->name; |
879 | my $name = $pl->name; |
829 | |
880 | |
830 | if ($target =~ /irc\//) { |
881 | if ($target =~ /irc\//) { |
831 | my (undef, $nick) = split /\//, $target, 2; |
882 | my (undef, $nick) = split /\//, $target, 2; |
832 | $who->message ("You tell $target: $args"); |
883 | $pl->message ("You tell $target: $args"); |
833 | ext::schmorp_irc::do_notice (sprintf "(%s) %s: %s\n", $name, $nick, $msg); |
884 | send_irc ("(%s) %s: %s\n", $name, $nick, $msg); |
834 | } elsif (my $other = cf::player::find_active $target) { |
885 | } elsif (my $other = cf::player::find_active $target) { |
835 | |
886 | |
836 | if ($msg) { |
887 | if ($msg) { |
837 | if ($target eq $name) { |
888 | if ($target eq $name) { |
838 | $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); |
889 | $pl->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); |
839 | } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { |
890 | } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { |
840 | $who->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); |
841 | } else { |
892 | } else { |
842 | utf8::encode $msg; # ->message not yet utf8-ified |
893 | return if $other->invoke (cf::EVENT_PLAYER_TOLD, $pl->contr, $msg); |
843 | 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; |
844 | |
895 | |
845 | $who->message ("You tell $target: $msg"); |
896 | $pl->message ("You tell $target: $msg"); |
846 | $other->ob->message ("$name tells you: $msg"); |
897 | $other->ob->message ("$name tells you: $msg"); |
847 | $other->ob->{ext_last_tell} = $name; |
898 | $other->ob->{ext_last_tell} = $name; |
848 | } |
899 | } |
849 | } else { |
900 | } else { |
850 | $who->message ("What do you want to tell $target?", cf::NDI_UNIQUE); |
901 | $pl->message ("What do you want to tell $target?", cf::NDI_UNIQUE); |
851 | } |
902 | } |
852 | |
903 | |
853 | } else { |
904 | } else { |
854 | $who->message ("No such player. Your message: $msg", cf::NDI_UNIQUE); |
905 | $pl->message ("No such player. Your message: $msg", cf::NDI_UNIQUE); |
855 | } |
|
|
856 | |
|
|
857 | 1 |
906 | } |
858 | }; |
907 | }; |
859 | |
908 | |
860 | cf::register_command reply => sub { |
909 | cf::register_command reply => sub { |
861 | my ($who, $args) = @_; |
910 | my ($pl, $args) = @_; |
862 | my $name = $who->name; |
911 | my $name = $pl->name; |
863 | |
912 | |
864 | utf8::decode $args; |
913 | utf8::decode $args; |
865 | |
914 | |
866 | return if $who->contr->invoke (cf::EVENT_PLAYER_TELL, $who->{ext_last_tell}, $args); |
915 | return if $pl->contr->invoke (cf::EVENT_PLAYER_TELL, $pl->{ext_last_tell}, $args); |
867 | |
916 | |
868 | if ($who->{ext_last_tell} =~ /irc\//) { |
917 | if ($pl->{ext_last_tell} =~ /irc\//) { |
869 | my (undef, $nick) = split /\//, $who->{ext_last_tell}, 2; |
918 | my (undef, $nick) = split /\//, $pl->{ext_last_tell}, 2; |
870 | $who->message ("You tell " . $who->{ext_last_tell} . ": $args"); |
919 | $pl->message ("You tell " . $pl->{ext_last_tell} . ": $args"); |
871 | ext::schmorp_irc::do_notice (sprintf "(%s) %s: %s\n", $name, $nick, $args); |
920 | send_irc ("(%s) %s: %s\n", $name, $nick, $args); |
872 | } elsif (my $other = cf::player::find_active $who->{ext_last_tell}) { |
921 | } elsif (my $other = cf::player::find_active $pl->{ext_last_tell}) { |
873 | |
922 | |
874 | if ($args) { |
923 | if ($args) { |
875 | $other->ob->{ext_ignore_tell}{$name} >= time |
924 | $other->ob->{ext_ignore_tell}{$name} >= time |
876 | or delete $other->ob->{ext_ignore_tell}{$name}; |
925 | or delete $other->ob->{ext_ignore_tell}{$name}; |
877 | |
926 | |
878 | if ($other->ob->{ext_ignore_tell}{$name} < time) { |
927 | if ($other->ob->{ext_ignore_tell}{$name} < time) { |
879 | utf8::encode $args; # ->message not yet utf8-ified |
|
|
880 | 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; |
881 | |
929 | |
882 | $who->message ("You tell " . $other->ob->name . ": $args"); |
930 | $pl->message ("You tell " . $other->ob->name . ": $args"); |
883 | $other->ob->message ("$name tells you: $args"); |
931 | $other->ob->message ("$name tells you: $args"); |
884 | $who->{ext_last_tell} = $other->ob->name; |
932 | $pl->{ext_last_tell} = $other->ob->name; |
885 | } else { |
933 | } else { |
886 | $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE); |
934 | $pl->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE); |
887 | } |
935 | } |
888 | } else { |
936 | } else { |
889 | $who->message ("What do you want to tell ".$other->ob->name."?", cf::NDI_UNIQUE); |
937 | $pl->message ("What do you want to tell ".$other->ob->name."?", cf::NDI_UNIQUE); |
890 | } |
938 | } |
891 | |
939 | |
892 | } else { |
940 | } else { |
893 | $who->message ("Can't reply, player left. Your message: $args".$who->{ext_last_tell}, cf::NDI_UNIQUE); |
941 | $pl->message ("Can't reply, player left. Your message: $args".$pl->{ext_last_tell}, cf::NDI_UNIQUE); |
894 | } |
|
|
895 | |
|
|
896 | 1 |
942 | } |
897 | }; |
943 | }; |
898 | |
944 | |
899 | cf::register_command ignore => sub { |
945 | cf::register_command ignore => sub { |
900 | my ($who, $args) = @_; |
946 | my ($pl, $args) = @_; |
901 | my ($target, $type, $timeout) = split /\s+/, $args; |
947 | my ($target, $type, $timeout) = split /\s+/, $args; |
902 | |
948 | |
903 | if ($args eq "list") { |
949 | if ($args eq "list") { |
904 | clean_timeouts $who; |
950 | clean_timeouts $pl; |
905 | |
951 | |
906 | if ((my @ignored_tell = sort keys %{$who->{ext_ignore_tell}}) |
952 | if ((my @ignored_tell = sort keys %{$pl->{ext_ignore_tell}}) |
907 | + (my @ignored_shout = sort keys %{$who->{ext_ignore_shout}})) { |
953 | + (my @ignored_shout = sort keys %{$pl->{ext_ignore_shout}})) { |
908 | $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE); |
954 | $pl->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE); |
909 | $who->message ((join ", ", @ignored_tell), cf::NDI_UNIQUE); |
955 | $pl->message ((join ", ", @ignored_tell), cf::NDI_UNIQUE); |
910 | $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE); |
956 | $pl->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE); |
911 | $who->message ((join ", ", @ignored_shout), cf::NDI_UNIQUE); |
957 | $pl->message ((join ", ", @ignored_shout), cf::NDI_UNIQUE); |
912 | $who->message ("To stop ignoring one, use unignore.", cf::NDI_UNIQUE); |
958 | $pl->message ("To stop ignoring one, use unignore.", cf::NDI_UNIQUE); |
913 | } else { |
959 | } else { |
914 | $who->message ("Not ignoring anyone", cf::NDI_UNIQUE); |
960 | $pl->message ("Not ignoring anyone", cf::NDI_UNIQUE); |
915 | } |
961 | } |
916 | |
962 | |
917 | } elsif ($target && $type) { |
963 | } elsif ($target && $type) { |
918 | |
964 | |
919 | $timeout ne "" or $timeout = 24; |
965 | $timeout ne "" or $timeout = 24; |
920 | my $absolute_timeout = time + $timeout * 3600; |
966 | my $absolute_timeout = time + $timeout * 3600; |
921 | |
967 | |
922 | if (cf::player::exists $target) { |
968 | if (cf::player::exists $target) { |
923 | if ($type eq "tell") { |
969 | if ($type eq "tell") { |
924 | $who->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_UNIQUE); |
970 | $pl->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_UNIQUE); |
925 | $who->{ext_ignore_tell}{$target} = $absolute_timeout; |
971 | $pl->{ext_ignore_tell}{$target} = $absolute_timeout; |
926 | } elsif ($type eq "shout") { |
972 | } elsif ($type eq "shout") { |
927 | $who->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_UNIQUE); |
973 | $pl->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_UNIQUE); |
928 | $who->{ext_ignore_shout}{$target} = $absolute_timeout; |
974 | $pl->{ext_ignore_shout}{$target} = $absolute_timeout; |
929 | } elsif ($type eq "all") { |
975 | } elsif ($type eq "all") { |
930 | $who->message ("Now ignoring everything from $target for $timeout hours.", cf::NDI_UNIQUE); |
976 | $pl->message ("Now ignoring everything from $target for $timeout hours.", cf::NDI_UNIQUE); |
931 | $who->{ext_ignore_tell}{$target} = $absolute_timeout; |
977 | $pl->{ext_ignore_tell}{$target} = $absolute_timeout; |
932 | $who->{ext_ignore_shout}{$target} = $absolute_timeout; |
978 | $pl->{ext_ignore_shout}{$target} = $absolute_timeout; |
933 | } else { |
979 | } else { |
934 | $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE); |
980 | $pl->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE); |
935 | } |
981 | } |
936 | } else { |
982 | } else { |
937 | $who->message ("No such player: $target", cf::NDI_UNIQUE); |
983 | $pl->message ("No such player: $target", cf::NDI_UNIQUE); |
938 | } |
984 | } |
939 | |
985 | |
940 | } else { |
986 | } else { |
941 | $who->message ("Usage: ignore <player> <tell|shout|all> <timeout>\n" |
987 | $pl->message ("Usage: ignore <player> <tell|shout|all> <timeout>\n" |
942 | . "will ignore a player for <timeout> hours.\n" |
988 | . "will ignore a player for <timeout> hours.\n" |
943 | . "Usage: ignore list\n" |
989 | . "Usage: ignore list\n" |
944 | . "will show you a list of players currently ignored.", cf::NDI_UNIQUE); |
990 | . "will show you a list of players currently ignored.", cf::NDI_UNIQUE); |
945 | } |
991 | } |
946 | |
|
|
947 | 1 |
|
|
948 | }; |
992 | }; |
949 | |
993 | |
950 | cf::register_command unignore => sub { |
994 | cf::register_command unignore => sub { |
951 | my ($who, $args) = @_; |
995 | my ($pl, $args) = @_; |
952 | my ($target, $type) = split /\s+/, $args; |
996 | my ($target, $type) = split /\s+/, $args; |
953 | |
997 | |
954 | if ($args eq "") { |
998 | if ($args eq "") { |
955 | if ($who->{ext_ignore_tell}) { |
999 | if ($pl->{ext_ignore_tell}) { |
956 | $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE); |
1000 | $pl->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE); |
957 | $who->message ((join ", ", sort keys %{ $who->{ext_ignore_tell} }), cf::NDI_UNIQUE); |
1001 | $pl->message ((join ", ", sort keys %{ $pl->{ext_ignore_tell} }), cf::NDI_UNIQUE); |
958 | $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE); |
1002 | $pl->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE); |
959 | $who->message ((join ", ", sort keys %{ $who->{ext_ignore_shout} }), cf::NDI_UNIQUE); |
1003 | $pl->message ((join ", ", sort keys %{ $pl->{ext_ignore_shout} }), cf::NDI_UNIQUE); |
960 | } else { |
1004 | } else { |
961 | $who->message ("Not ignoring anyone", cf::NDI_UNIQUE); |
1005 | $pl->message ("Not ignoring anyone", cf::NDI_UNIQUE); |
962 | } |
1006 | } |
963 | } else { |
1007 | } else { |
964 | if (cf::player::exists $target) { |
1008 | if (cf::player::exists $target) { |
965 | if ($type eq "tell") { |
1009 | if ($type eq "tell") { |
966 | $who->message ("Not ignoring private messages from $target anymore.", cf::NDI_UNIQUE); |
1010 | $pl->message ("Not ignoring private messages from $target anymore.", cf::NDI_UNIQUE); |
967 | delete $who->{ext_ignore_tell} {$target}; |
1011 | delete $pl->{ext_ignore_tell} {$target}; |
968 | } elsif ($type eq "shout") { |
1012 | } elsif ($type eq "shout") { |
969 | $who->message ("Not ignoring shouts from $target anymore.", cf::NDI_UNIQUE); |
1013 | $pl->message ("Not ignoring shouts from $target anymore.", cf::NDI_UNIQUE); |
970 | delete $who->{ext_ignore_shout}{$target}; |
1014 | delete $pl->{ext_ignore_shout}{$target}; |
971 | } elsif ($type eq "all") { |
1015 | } elsif ($type eq "all") { |
972 | $who->message ("Not ignoring anything from $target anymore.", cf::NDI_UNIQUE); |
1016 | $pl->message ("Not ignoring anything from $target anymore.", cf::NDI_UNIQUE); |
973 | delete $who->{ext_ignore_tell} {$target}; |
1017 | delete $pl->{ext_ignore_tell} {$target}; |
974 | delete $who->{ext_ignore_shout}{$target}; |
1018 | delete $pl->{ext_ignore_shout}{$target}; |
975 | } else { |
1019 | } else { |
976 | $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE); |
1020 | $pl->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE); |
977 | } |
1021 | } |
978 | } else { |
1022 | } else { |
979 | $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE); |
1023 | $pl->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE); |
980 | } |
1024 | } |
981 | } |
1025 | } |
982 | |
|
|
983 | 1 |
|
|
984 | }; |
1026 | }; |
985 | |
1027 | |
986 | cf::register_command seen => sub { |
|
|
987 | my ($who, $args) = @_; |
|
|
988 | |
|
|
989 | if (my ($login) = $args =~ /(\S+)/) { |
|
|
990 | if ($login eq $who->name) { |
|
|
991 | $who->message ("Very funny, $login. Ha. Ha.", cf::NDI_UNIQUE); |
|
|
992 | } elsif (cf::player::find_active $login) { |
|
|
993 | $who->message ("$login is right here on this server!", cf::NDI_UNIQUE); |
|
|
994 | } elsif (cf::player::exists $login |
|
|
995 | and stat sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($login) x 2) { |
|
|
996 | my $time = (stat _)[9]; |
|
|
997 | |
|
|
998 | $who->message ("$login was last seen here " |
|
|
999 | . (POSIX::strftime "%Y-%m-%d %H:%M:%S +0000", gmtime $time) |
|
|
1000 | . " which was " . (int +(time - $time) / 3600) . " hours ago.", cf::NDI_UNIQUE); |
|
|
1001 | } else { |
|
|
1002 | $who->message ("No player named $login is known to me.", cf::NDI_UNIQUE); |
|
|
1003 | } |
|
|
1004 | } else { |
|
|
1005 | $who->message ("Usage: seen <player>", cf::NDI_UNIQUE); |
|
|
1006 | } |
|
|
1007 | |
|
|
1008 | 1 |
|
|
1009 | }; |
|
|
1010 | |
|
|