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 | |
… | |
… | |
36 | cf::register_command listen => sub { |
46 | cf::register_command listen => sub { |
37 | my ($pl, $msg) = @_; |
47 | my ($pl, $msg) = @_; |
38 | my $player = cf::player::find_active $pl->name; |
48 | my $player = cf::player::find_active $pl->name; |
39 | |
49 | |
40 | if ($msg ne "") { |
50 | if ($msg ne "") { |
|
|
51 | $msg = 10 if $msg > 10; |
|
|
52 | |
41 | my $prev_listen = $player->listening; |
53 | my $prev_listen = $player->listening; |
42 | $player->listening ($msg); |
54 | $player->listening ($msg); |
43 | if ($prev_listen == $player->listening) { |
55 | if ($prev_listen == $player->listening) { |
44 | $pl->message ("Your verbose level stayed $prev_listen.", cf::NDI_UNIQUE); |
56 | $pl->message ("Your verbose level stayed $prev_listen.", cf::NDI_UNIQUE); |
45 | } else { |
57 | } else { |
… | |
… | |
72 | |
84 | |
73 | $pl->message ("You flip a coin.... Tails!", cf::NDI_GREY | cf::NDI_UNIQUE); |
85 | $pl->message ("You flip a coin.... Tails!", cf::NDI_GREY | cf::NDI_UNIQUE); |
74 | } |
86 | } |
75 | }; |
87 | }; |
76 | |
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); |
|
|
105 | }; |
|
|
106 | |
77 | my $emotes = { |
107 | my $emotes = { |
78 | growl => { |
108 | growl => { |
79 | noparams => { |
109 | noparams => { |
80 | other => "<self> growls.", |
110 | other => "<self> growls.", |
81 | self => "Grrrrrrrrr....", |
111 | self => "Grrrrrrrrr....", |
… | |
… | |
209 | noparams => { |
239 | noparams => { |
210 | other => "<self> winks suggestively.", |
240 | other => "<self> winks suggestively.", |
211 | self => "Have you got something in your eye?", |
241 | self => "Have you got something in your eye?", |
212 | }, |
242 | }, |
213 | params => { |
243 | params => { |
|
|
244 | target => "<self> winks at you.", |
214 | target => "<self> winks at <other>.", |
245 | other => "<self> winks at <other>.", |
215 | self => "You wink suggestively at <other>.", |
246 | self => "You wink suggestively at <other>.", |
216 | }, |
247 | }, |
217 | self => { |
248 | self => { |
218 | other => "<self> winks at himself - something strange is going on...", |
249 | other => "<self> winks at himself - something strange is going on...", |
219 | self => "You wink at yourself?? What are you up to?", |
250 | self => "You wink at yourself?? What are you up to?", |
… | |
… | |
309 | noparams => { |
340 | noparams => { |
310 | 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?", |
311 | self => "You bleed all over your nice new armour.", |
342 | self => "You bleed all over your nice new armour.", |
312 | }, |
343 | }, |
313 | params => { |
344 | params => { |
|
|
345 | target => "<self> slashes his wrist and bleeds all over you.", |
314 | target => "<self> slashes his wrist and bleeds all over <other>.", |
346 | other => "<self> slashes his wrist and bleeds all over <other>.", |
315 | self => "You slash your wrist and bleed all over <other>", |
347 | self => "You slash your wrist and bleed all over <other>", |
316 | }, |
348 | }, |
317 | self => { |
349 | self => { |
318 | 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.", |
319 | self => "Very impressive! You wipe your blood all over yourself.", |
351 | self => "Very impressive! You wipe your blood all over yourself.", |
… | |
… | |
742 | return if $pl->contr->invoke (cf::EVENT_PLAYER_SAY, $msg); |
774 | return if $pl->contr->invoke (cf::EVENT_PLAYER_SAY, $msg); |
743 | |
775 | |
744 | if ($msg) { |
776 | if ($msg) { |
745 | my $name = $pl->name; |
777 | my $name = $pl->name; |
746 | |
778 | |
747 | utf8::encode $msg; # ->message not yet utf8-ified |
|
|
748 | $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE) |
779 | $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE) |
749 | for grep $pl->on_same_map_as ($_->ob), cf::player::list; |
780 | for grep $pl->on_same_map_as ($_->ob), cf::player::list; |
750 | utf8::decode $msg; |
|
|
751 | |
781 | |
752 | # npcs, magic_ears etc. |
782 | # npcs, magic_ears etc. |
753 | # first find all objects and theirt-level inventories |
783 | # first find all objects and their first-level inventories |
754 | # within a 5x5 square # that have something resembling |
784 | # within a 5x5 square that have something resembling |
755 | # dialogue or support on_say. |
785 | # dialogue or support on_say. |
756 | 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); |
757 | |
787 | |
758 | for my $npc ( |
788 | for my $npc ( |
759 | 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 $_, |
… | |
… | |
763 | 0..24 |
793 | 0..24 |
764 | ) { |
794 | ) { |
765 | # if some listener teleported us somewhere else, stop right here |
795 | # if some listener teleported us somewhere else, stop right here |
766 | last unless $map->path == $pl->map->path; |
796 | last unless $map->path == $pl->map->path; |
767 | |
797 | |
768 | my $dialog = new NPC_Dialogue ob => $pl, npc => $npc; |
798 | my $dialog = new NPC_Dialogue pl => $pl->contr, npc => $npc; |
769 | my ($reply, @kw) = $dialog->tell ($msg); |
799 | my ($reply, @kw) = $dialog->tell ($msg); |
770 | |
800 | |
771 | if (defined $reply) { |
801 | if (defined $reply) { |
772 | if ($npc->type == cf::MAGIC_EAR) { |
802 | if ($npc->type == cf::MAGIC_EAR) { |
773 | if (length $reply) { |
803 | if (length $reply) { |
… | |
… | |
803 | |
833 | |
804 | if ($msg) { |
834 | if ($msg) { |
805 | my $name = $pl->name; |
835 | my $name = $pl->name; |
806 | my $NOW = time; |
836 | my $NOW = time; |
807 | |
837 | |
808 | utf8::encode $msg; # ->message not yet utf8-ified |
|
|
809 | cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; |
838 | cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; |
810 | ext::schmorp_irc::do_notice (sprintf "[%s] %s", $name, $msg); |
839 | send_irc ("[%s] %s", $name, $msg); |
811 | |
840 | |
812 | $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) |
841 | $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) |
813 | 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; |
814 | |
843 | |
815 | } else { |
844 | } else { |
… | |
… | |
827 | if ($msg) { |
856 | if ($msg) { |
828 | my $NOW = time; |
857 | my $NOW = time; |
829 | my $name = $pl->name; |
858 | my $name = $pl->name; |
830 | |
859 | |
831 | cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; |
860 | cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; |
832 | ext::schmorp_irc::do_notice (sprintf "\007\0034{%s} %s\n", $name, $msg); |
861 | send_irc ("\007\0034{%s} %s\n", $name, $msg); |
833 | |
862 | |
834 | utf8::encode $msg; # ->message not yet utf8-ified |
|
|
835 | $_->ob->message ("$name shouts: $msg", cf::NDI_RED) |
863 | $_->ob->message ("$name shouts: $msg", cf::NDI_RED) |
836 | 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; |
837 | |
865 | |
838 | } else { |
866 | } else { |
839 | $pl->message ("Shout what?", cf::NDI_UNIQUE); |
867 | $pl->message ("Shout what?", cf::NDI_UNIQUE); |
… | |
… | |
851 | my $name = $pl->name; |
879 | my $name = $pl->name; |
852 | |
880 | |
853 | if ($target =~ /irc\//) { |
881 | if ($target =~ /irc\//) { |
854 | my (undef, $nick) = split /\//, $target, 2; |
882 | my (undef, $nick) = split /\//, $target, 2; |
855 | $pl->message ("You tell $target: $args"); |
883 | $pl->message ("You tell $target: $args"); |
856 | ext::schmorp_irc::do_notice (sprintf "(%s) %s: %s\n", $name, $nick, $msg); |
884 | send_irc ("(%s) %s: %s\n", $name, $nick, $msg); |
857 | } elsif (my $other = cf::player::find_active $target) { |
885 | } elsif (my $other = cf::player::find_active $target) { |
858 | |
886 | |
859 | if ($msg) { |
887 | if ($msg) { |
860 | if ($target eq $name) { |
888 | if ($target eq $name) { |
861 | $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); |
862 | } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { |
890 | } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { |
863 | $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); |
864 | } else { |
892 | } else { |
865 | utf8::encode $msg; # ->message not yet utf8-ified |
893 | return if $other->invoke (cf::EVENT_PLAYER_TOLD, $pl->contr, $msg); |
866 | 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; |
867 | |
895 | |
868 | $pl->message ("You tell $target: $msg"); |
896 | $pl->message ("You tell $target: $msg"); |
869 | $other->ob->message ("$name tells you: $msg"); |
897 | $other->ob->message ("$name tells you: $msg"); |
870 | $other->ob->{ext_last_tell} = $name; |
898 | $other->ob->{ext_last_tell} = $name; |
… | |
… | |
887 | 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); |
888 | |
916 | |
889 | if ($pl->{ext_last_tell} =~ /irc\//) { |
917 | if ($pl->{ext_last_tell} =~ /irc\//) { |
890 | my (undef, $nick) = split /\//, $pl->{ext_last_tell}, 2; |
918 | my (undef, $nick) = split /\//, $pl->{ext_last_tell}, 2; |
891 | $pl->message ("You tell " . $pl->{ext_last_tell} . ": $args"); |
919 | $pl->message ("You tell " . $pl->{ext_last_tell} . ": $args"); |
892 | ext::schmorp_irc::do_notice (sprintf "(%s) %s: %s\n", $name, $nick, $args); |
920 | send_irc ("(%s) %s: %s\n", $name, $nick, $args); |
893 | } elsif (my $other = cf::player::find_active $pl->{ext_last_tell}) { |
921 | } elsif (my $other = cf::player::find_active $pl->{ext_last_tell}) { |
894 | |
922 | |
895 | if ($args) { |
923 | if ($args) { |
896 | $other->ob->{ext_ignore_tell}{$name} >= time |
924 | $other->ob->{ext_ignore_tell}{$name} >= time |
897 | or delete $other->ob->{ext_ignore_tell}{$name}; |
925 | or delete $other->ob->{ext_ignore_tell}{$name}; |
898 | |
926 | |
899 | if ($other->ob->{ext_ignore_tell}{$name} < time) { |
927 | if ($other->ob->{ext_ignore_tell}{$name} < time) { |
900 | utf8::encode $args; # ->message not yet utf8-ified |
|
|
901 | 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; |
902 | |
929 | |
903 | $pl->message ("You tell " . $other->ob->name . ": $args"); |
930 | $pl->message ("You tell " . $other->ob->name . ": $args"); |
904 | $other->ob->message ("$name tells you: $args"); |
931 | $other->ob->message ("$name tells you: $args"); |
905 | $pl->{ext_last_tell} = $other->ob->name; |
932 | $pl->{ext_last_tell} = $other->ob->name; |
… | |
… | |
996 | $pl->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE); |
1023 | $pl->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE); |
997 | } |
1024 | } |
998 | } |
1025 | } |
999 | }; |
1026 | }; |
1000 | |
1027 | |
1001 | cf::register_command seen => sub { |
|
|
1002 | my ($pl, $args) = @_; |
|
|
1003 | |
|
|
1004 | if (my ($login) = $args =~ /(\S+)/) { |
|
|
1005 | if ($login eq $pl->name) { |
|
|
1006 | $pl->message ("Very funny, $login. Ha. Ha.", cf::NDI_UNIQUE); |
|
|
1007 | } elsif (cf::player::find_active $login) { |
|
|
1008 | $pl->message ("$login is right here on this server!", cf::NDI_UNIQUE); |
|
|
1009 | } elsif (cf::player::exists $login |
|
|
1010 | and stat sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($login) x 2) { |
|
|
1011 | my $time = (stat _)[9]; |
|
|
1012 | |
|
|
1013 | $pl->message ("$login was last seen here " |
|
|
1014 | . (POSIX::strftime "%Y-%m-%d %H:%M:%S +0000", gmtime $time) |
|
|
1015 | . " which was " . (int +(time - $time) / 3600) . " hours ago.", cf::NDI_UNIQUE); |
|
|
1016 | } else { |
|
|
1017 | $pl->message ("No player named $login is known to me.", cf::NDI_UNIQUE); |
|
|
1018 | } |
|
|
1019 | } else { |
|
|
1020 | $pl->message ("Usage: seen <player>", cf::NDI_UNIQUE); |
|
|
1021 | } |
|
|
1022 | }; |
|
|
1023 | |
|
|