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 { |
… | |
… | |
227 | noparams => { |
239 | noparams => { |
228 | other => "<self> winks suggestively.", |
240 | other => "<self> winks suggestively.", |
229 | self => "Have you got something in your eye?", |
241 | self => "Have you got something in your eye?", |
230 | }, |
242 | }, |
231 | params => { |
243 | params => { |
|
|
244 | target => "<self> winks at you.", |
232 | target => "<self> winks at <other>.", |
245 | other => "<self> winks at <other>.", |
233 | self => "You wink suggestively at <other>.", |
246 | self => "You wink suggestively at <other>.", |
234 | }, |
247 | }, |
235 | self => { |
248 | self => { |
236 | other => "<self> winks at himself - something strange is going on...", |
249 | other => "<self> winks at himself - something strange is going on...", |
237 | self => "You wink at yourself?? What are you up to?", |
250 | self => "You wink at yourself?? What are you up to?", |
… | |
… | |
327 | noparams => { |
340 | noparams => { |
328 | 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?", |
329 | self => "You bleed all over your nice new armour.", |
342 | self => "You bleed all over your nice new armour.", |
330 | }, |
343 | }, |
331 | params => { |
344 | params => { |
|
|
345 | target => "<self> slashes his wrist and bleeds all over you.", |
332 | target => "<self> slashes his wrist and bleeds all over <other>.", |
346 | other => "<self> slashes his wrist and bleeds all over <other>.", |
333 | self => "You slash your wrist and bleed all over <other>", |
347 | self => "You slash your wrist and bleed all over <other>", |
334 | }, |
348 | }, |
335 | self => { |
349 | self => { |
336 | 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.", |
337 | self => "Very impressive! You wipe your blood all over yourself.", |
351 | self => "Very impressive! You wipe your blood all over yourself.", |
… | |
… | |
760 | return if $pl->contr->invoke (cf::EVENT_PLAYER_SAY, $msg); |
774 | return if $pl->contr->invoke (cf::EVENT_PLAYER_SAY, $msg); |
761 | |
775 | |
762 | if ($msg) { |
776 | if ($msg) { |
763 | my $name = $pl->name; |
777 | my $name = $pl->name; |
764 | |
778 | |
765 | utf8::encode $msg; # ->message not yet utf8-ified |
|
|
766 | $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE) |
779 | $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE) |
767 | for grep $pl->on_same_map_as ($_->ob), cf::player::list; |
780 | for grep $pl->on_same_map_as ($_->ob), cf::player::list; |
768 | utf8::decode $msg; |
|
|
769 | |
781 | |
770 | # npcs, magic_ears etc. |
782 | # npcs, magic_ears etc. |
771 | # first find all objects and theirt-level inventories |
783 | # first find all objects and their first-level inventories |
772 | # within a 5x5 square # that have something resembling |
784 | # within a 5x5 square that have something resembling |
773 | # dialogue or support on_say. |
785 | # dialogue or support on_say. |
774 | 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); |
775 | |
787 | |
776 | for my $npc ( |
788 | for my $npc ( |
777 | 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 $_, |
… | |
… | |
781 | 0..24 |
793 | 0..24 |
782 | ) { |
794 | ) { |
783 | # if some listener teleported us somewhere else, stop right here |
795 | # if some listener teleported us somewhere else, stop right here |
784 | last unless $map->path == $pl->map->path; |
796 | last unless $map->path == $pl->map->path; |
785 | |
797 | |
786 | my $dialog = new NPC_Dialogue ob => $pl, npc => $npc; |
798 | my $dialog = new NPC_Dialogue pl => $pl->contr, npc => $npc; |
787 | my ($reply, @kw) = $dialog->tell ($msg); |
799 | my ($reply, @kw) = $dialog->tell ($msg); |
788 | |
800 | |
789 | if (defined $reply) { |
801 | if (defined $reply) { |
790 | if ($npc->type == cf::MAGIC_EAR) { |
802 | if ($npc->type == cf::MAGIC_EAR) { |
791 | if (length $reply) { |
803 | if (length $reply) { |
… | |
… | |
821 | |
833 | |
822 | if ($msg) { |
834 | if ($msg) { |
823 | my $name = $pl->name; |
835 | my $name = $pl->name; |
824 | my $NOW = time; |
836 | my $NOW = time; |
825 | |
837 | |
826 | utf8::encode $msg; # ->message not yet utf8-ified |
|
|
827 | cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; |
838 | cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; |
828 | ext::schmorp_irc::do_notice (sprintf "[%s] %s", $name, $msg); |
839 | send_irc ("[%s] %s", $name, $msg); |
829 | |
840 | |
830 | $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) |
841 | $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) |
831 | 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; |
832 | |
843 | |
833 | } else { |
844 | } else { |
… | |
… | |
845 | if ($msg) { |
856 | if ($msg) { |
846 | my $NOW = time; |
857 | my $NOW = time; |
847 | my $name = $pl->name; |
858 | my $name = $pl->name; |
848 | |
859 | |
849 | cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; |
860 | cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; |
850 | ext::schmorp_irc::do_notice (sprintf "\007\0034{%s} %s\n", $name, $msg); |
861 | send_irc ("\007\0034{%s} %s\n", $name, $msg); |
851 | |
862 | |
852 | utf8::encode $msg; # ->message not yet utf8-ified |
|
|
853 | $_->ob->message ("$name shouts: $msg", cf::NDI_RED) |
863 | $_->ob->message ("$name shouts: $msg", cf::NDI_RED) |
854 | 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; |
855 | |
865 | |
856 | } else { |
866 | } else { |
857 | $pl->message ("Shout what?", cf::NDI_UNIQUE); |
867 | $pl->message ("Shout what?", cf::NDI_UNIQUE); |
… | |
… | |
869 | my $name = $pl->name; |
879 | my $name = $pl->name; |
870 | |
880 | |
871 | if ($target =~ /irc\//) { |
881 | if ($target =~ /irc\//) { |
872 | my (undef, $nick) = split /\//, $target, 2; |
882 | my (undef, $nick) = split /\//, $target, 2; |
873 | $pl->message ("You tell $target: $args"); |
883 | $pl->message ("You tell $target: $args"); |
874 | ext::schmorp_irc::do_notice (sprintf "(%s) %s: %s\n", $name, $nick, $msg); |
884 | send_irc ("(%s) %s: %s\n", $name, $nick, $msg); |
875 | } elsif (my $other = cf::player::find_active $target) { |
885 | } elsif (my $other = cf::player::find_active $target) { |
876 | |
886 | |
877 | if ($msg) { |
887 | if ($msg) { |
878 | if ($target eq $name) { |
888 | if ($target eq $name) { |
879 | $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); |
880 | } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { |
890 | } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { |
881 | $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); |
882 | } else { |
892 | } else { |
883 | utf8::encode $msg; # ->message not yet utf8-ified |
893 | return if $other->invoke (cf::EVENT_PLAYER_TOLD, $pl->contr, $msg); |
884 | 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; |
885 | |
895 | |
886 | $pl->message ("You tell $target: $msg"); |
896 | $pl->message ("You tell $target: $msg"); |
887 | $other->ob->message ("$name tells you: $msg"); |
897 | $other->ob->message ("$name tells you: $msg"); |
888 | $other->ob->{ext_last_tell} = $name; |
898 | $other->ob->{ext_last_tell} = $name; |
… | |
… | |
905 | 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); |
906 | |
916 | |
907 | if ($pl->{ext_last_tell} =~ /irc\//) { |
917 | if ($pl->{ext_last_tell} =~ /irc\//) { |
908 | my (undef, $nick) = split /\//, $pl->{ext_last_tell}, 2; |
918 | my (undef, $nick) = split /\//, $pl->{ext_last_tell}, 2; |
909 | $pl->message ("You tell " . $pl->{ext_last_tell} . ": $args"); |
919 | $pl->message ("You tell " . $pl->{ext_last_tell} . ": $args"); |
910 | ext::schmorp_irc::do_notice (sprintf "(%s) %s: %s\n", $name, $nick, $args); |
920 | send_irc ("(%s) %s: %s\n", $name, $nick, $args); |
911 | } elsif (my $other = cf::player::find_active $pl->{ext_last_tell}) { |
921 | } elsif (my $other = cf::player::find_active $pl->{ext_last_tell}) { |
912 | |
922 | |
913 | if ($args) { |
923 | if ($args) { |
914 | $other->ob->{ext_ignore_tell}{$name} >= time |
924 | $other->ob->{ext_ignore_tell}{$name} >= time |
915 | or delete $other->ob->{ext_ignore_tell}{$name}; |
925 | or delete $other->ob->{ext_ignore_tell}{$name}; |
916 | |
926 | |
917 | if ($other->ob->{ext_ignore_tell}{$name} < time) { |
927 | if ($other->ob->{ext_ignore_tell}{$name} < time) { |
918 | utf8::encode $args; # ->message not yet utf8-ified |
|
|
919 | 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; |
920 | |
929 | |
921 | $pl->message ("You tell " . $other->ob->name . ": $args"); |
930 | $pl->message ("You tell " . $other->ob->name . ": $args"); |
922 | $other->ob->message ("$name tells you: $args"); |
931 | $other->ob->message ("$name tells you: $args"); |
923 | $pl->{ext_last_tell} = $other->ob->name; |
932 | $pl->{ext_last_tell} = $other->ob->name; |
… | |
… | |
1014 | $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); |
1015 | } |
1024 | } |
1016 | } |
1025 | } |
1017 | }; |
1026 | }; |
1018 | |
1027 | |
1019 | cf::register_command seen => sub { |
|
|
1020 | my ($pl, $args) = @_; |
|
|
1021 | |
|
|
1022 | if (my ($login) = $args =~ /(\S+)/) { |
|
|
1023 | if ($login eq $pl->name) { |
|
|
1024 | $pl->message ("Very funny, $login. Ha. Ha.", cf::NDI_UNIQUE); |
|
|
1025 | } elsif (cf::player::find_active $login) { |
|
|
1026 | $pl->message ("$login is right here on this server!", cf::NDI_UNIQUE); |
|
|
1027 | } elsif (cf::player::exists $login |
|
|
1028 | and stat sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($login) x 2) { |
|
|
1029 | my $time = (stat _)[9]; |
|
|
1030 | |
|
|
1031 | $pl->message ("$login was last seen here " |
|
|
1032 | . (POSIX::strftime "%Y-%m-%d %H:%M:%S +0000", gmtime $time) |
|
|
1033 | . " which was " . (int +(time - $time) / 3600) . " hours ago.", cf::NDI_UNIQUE); |
|
|
1034 | } else { |
|
|
1035 | $pl->message ("No player named $login is known to me.", cf::NDI_UNIQUE); |
|
|
1036 | } |
|
|
1037 | } else { |
|
|
1038 | $pl->message ("Usage: seen <player>", cf::NDI_UNIQUE); |
|
|
1039 | } |
|
|
1040 | }; |
|
|
1041 | |
|
|