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 | |
… | |
… | |
36 | cf::register_command listen => sub { |
36 | cf::register_command listen => sub { |
37 | my ($pl, $msg) = @_; |
37 | my ($pl, $msg) = @_; |
38 | my $player = cf::player::find_active $pl->name; |
38 | my $player = cf::player::find_active $pl->name; |
39 | |
39 | |
40 | if ($msg ne "") { |
40 | if ($msg ne "") { |
|
|
41 | $msg = 10 if $msg > 10; |
|
|
42 | |
41 | my $prev_listen = $player->listening; |
43 | my $prev_listen = $player->listening; |
42 | $player->listening ($msg); |
44 | $player->listening ($msg); |
43 | if ($prev_listen == $player->listening) { |
45 | if ($prev_listen == $player->listening) { |
44 | $pl->message ("Your verbose level stayed $prev_listen.", cf::NDI_UNIQUE); |
46 | $pl->message ("Your verbose level stayed $prev_listen.", cf::NDI_UNIQUE); |
45 | } else { |
47 | } else { |
… | |
… | |
762 | return if $pl->contr->invoke (cf::EVENT_PLAYER_SAY, $msg); |
764 | return if $pl->contr->invoke (cf::EVENT_PLAYER_SAY, $msg); |
763 | |
765 | |
764 | if ($msg) { |
766 | if ($msg) { |
765 | my $name = $pl->name; |
767 | my $name = $pl->name; |
766 | |
768 | |
767 | utf8::encode $msg; # ->message not yet utf8-ified |
|
|
768 | $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE) |
769 | $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE) |
769 | for grep $pl->on_same_map_as ($_->ob), cf::player::list; |
770 | for grep $pl->on_same_map_as ($_->ob), cf::player::list; |
770 | utf8::decode $msg; |
|
|
771 | |
771 | |
772 | # npcs, magic_ears etc. |
772 | # npcs, magic_ears etc. |
773 | # first find all objects and theirt-level inventories |
773 | # first find all objects and their first-level inventories |
774 | # within a 5x5 square # that have something resembling |
774 | # within a 5x5 square that have something resembling |
775 | # dialogue or support on_say. |
775 | # dialogue or support on_say. |
776 | my ($map, $x, $y) = ($pl->map, $pl->x - 2, $pl->y - 2); |
776 | my ($map, $x, $y) = ($pl->map, $pl->x - 2, $pl->y - 2); |
777 | |
777 | |
778 | for my $npc ( |
778 | for my $npc ( |
779 | grep +($_->invoke (cf::EVENT_OBJECT_SAY, $pl->contr, $msg) && return) || NPC_Dialogue::has_dialogue $_, |
779 | grep +($_->invoke (cf::EVENT_OBJECT_SAY, $pl->contr, $msg) && return) || NPC_Dialogue::has_dialogue $_, |
… | |
… | |
783 | 0..24 |
783 | 0..24 |
784 | ) { |
784 | ) { |
785 | # if some listener teleported us somewhere else, stop right here |
785 | # if some listener teleported us somewhere else, stop right here |
786 | last unless $map->path == $pl->map->path; |
786 | last unless $map->path == $pl->map->path; |
787 | |
787 | |
788 | my $dialog = new NPC_Dialogue ob => $pl, npc => $npc; |
788 | my $dialog = new NPC_Dialogue pl => $pl->contr, npc => $npc; |
789 | my ($reply, @kw) = $dialog->tell ($msg); |
789 | my ($reply, @kw) = $dialog->tell ($msg); |
790 | |
790 | |
791 | if (defined $reply) { |
791 | if (defined $reply) { |
792 | if ($npc->type == cf::MAGIC_EAR) { |
792 | if ($npc->type == cf::MAGIC_EAR) { |
793 | if (length $reply) { |
793 | if (length $reply) { |
… | |
… | |
823 | |
823 | |
824 | if ($msg) { |
824 | if ($msg) { |
825 | my $name = $pl->name; |
825 | my $name = $pl->name; |
826 | my $NOW = time; |
826 | my $NOW = time; |
827 | |
827 | |
828 | utf8::encode $msg; # ->message not yet utf8-ified |
|
|
829 | cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; |
828 | cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; |
830 | ext::schmorp_irc::do_notice (sprintf "[%s] %s", $name, $msg); |
829 | ext::irc::do_notice (sprintf "[%s] %s", $name, $msg); |
831 | |
830 | |
832 | $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) |
831 | $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) |
833 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; |
832 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; |
834 | |
833 | |
835 | } else { |
834 | } else { |
… | |
… | |
847 | if ($msg) { |
846 | if ($msg) { |
848 | my $NOW = time; |
847 | my $NOW = time; |
849 | my $name = $pl->name; |
848 | my $name = $pl->name; |
850 | |
849 | |
851 | cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; |
850 | cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; |
852 | ext::schmorp_irc::do_notice (sprintf "\007\0034{%s} %s\n", $name, $msg); |
851 | ext::irc::do_notice (sprintf "\007\0034{%s} %s\n", $name, $msg); |
853 | |
852 | |
854 | utf8::encode $msg; # ->message not yet utf8-ified |
|
|
855 | $_->ob->message ("$name shouts: $msg", cf::NDI_RED) |
853 | $_->ob->message ("$name shouts: $msg", cf::NDI_RED) |
856 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; |
854 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; |
857 | |
855 | |
858 | } else { |
856 | } else { |
859 | $pl->message ("Shout what?", cf::NDI_UNIQUE); |
857 | $pl->message ("Shout what?", cf::NDI_UNIQUE); |
… | |
… | |
871 | my $name = $pl->name; |
869 | my $name = $pl->name; |
872 | |
870 | |
873 | if ($target =~ /irc\//) { |
871 | if ($target =~ /irc\//) { |
874 | my (undef, $nick) = split /\//, $target, 2; |
872 | my (undef, $nick) = split /\//, $target, 2; |
875 | $pl->message ("You tell $target: $args"); |
873 | $pl->message ("You tell $target: $args"); |
876 | ext::schmorp_irc::do_notice (sprintf "(%s) %s: %s\n", $name, $nick, $msg); |
874 | ext::irc::do_notice (sprintf "(%s) %s: %s\n", $name, $nick, $msg); |
877 | } elsif (my $other = cf::player::find_active $target) { |
875 | } elsif (my $other = cf::player::find_active $target) { |
878 | |
876 | |
879 | if ($msg) { |
877 | if ($msg) { |
880 | if ($target eq $name) { |
878 | if ($target eq $name) { |
881 | $pl->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); |
879 | $pl->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); |
882 | } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { |
880 | } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { |
883 | $pl->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE); |
881 | $pl->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE); |
884 | } else { |
882 | } else { |
885 | return if $other->invoke (cf::EVENT_PLAYER_TOLD, $pl->contr, $msg); |
883 | return if $other->invoke (cf::EVENT_PLAYER_TOLD, $pl->contr, $msg); |
886 | utf8::encode $msg; # ->message not yet utf8-ified |
|
|
887 | cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg; |
884 | cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg; |
888 | |
885 | |
889 | $pl->message ("You tell $target: $msg"); |
886 | $pl->message ("You tell $target: $msg"); |
890 | $other->ob->message ("$name tells you: $msg"); |
887 | $other->ob->message ("$name tells you: $msg"); |
891 | $other->ob->{ext_last_tell} = $name; |
888 | $other->ob->{ext_last_tell} = $name; |
… | |
… | |
908 | return if $pl->contr->invoke (cf::EVENT_PLAYER_TELL, $pl->{ext_last_tell}, $args); |
905 | return if $pl->contr->invoke (cf::EVENT_PLAYER_TELL, $pl->{ext_last_tell}, $args); |
909 | |
906 | |
910 | if ($pl->{ext_last_tell} =~ /irc\//) { |
907 | if ($pl->{ext_last_tell} =~ /irc\//) { |
911 | my (undef, $nick) = split /\//, $pl->{ext_last_tell}, 2; |
908 | my (undef, $nick) = split /\//, $pl->{ext_last_tell}, 2; |
912 | $pl->message ("You tell " . $pl->{ext_last_tell} . ": $args"); |
909 | $pl->message ("You tell " . $pl->{ext_last_tell} . ": $args"); |
913 | ext::schmorp_irc::do_notice (sprintf "(%s) %s: %s\n", $name, $nick, $args); |
910 | ext::irc::do_notice (sprintf "(%s) %s: %s\n", $name, $nick, $args); |
914 | } elsif (my $other = cf::player::find_active $pl->{ext_last_tell}) { |
911 | } elsif (my $other = cf::player::find_active $pl->{ext_last_tell}) { |
915 | |
912 | |
916 | if ($args) { |
913 | if ($args) { |
917 | $other->ob->{ext_ignore_tell}{$name} >= time |
914 | $other->ob->{ext_ignore_tell}{$name} >= time |
918 | or delete $other->ob->{ext_ignore_tell}{$name}; |
915 | or delete $other->ob->{ext_ignore_tell}{$name}; |
919 | |
916 | |
920 | if ($other->ob->{ext_ignore_tell}{$name} < time) { |
917 | if ($other->ob->{ext_ignore_tell}{$name} < time) { |
921 | utf8::encode $args; # ->message not yet utf8-ified |
|
|
922 | cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $other->ob->name, $args; |
918 | cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $other->ob->name, $args; |
923 | |
919 | |
924 | $pl->message ("You tell " . $other->ob->name . ": $args"); |
920 | $pl->message ("You tell " . $other->ob->name . ": $args"); |
925 | $other->ob->message ("$name tells you: $args"); |
921 | $other->ob->message ("$name tells you: $args"); |
926 | $pl->{ext_last_tell} = $other->ob->name; |
922 | $pl->{ext_last_tell} = $other->ob->name; |
… | |
… | |
1017 | $pl->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE); |
1013 | $pl->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE); |
1018 | } |
1014 | } |
1019 | } |
1015 | } |
1020 | }; |
1016 | }; |
1021 | |
1017 | |
1022 | cf::register_command seen => sub { |
|
|
1023 | my ($pl, $args) = @_; |
|
|
1024 | |
|
|
1025 | if (my ($login) = $args =~ /(\S+)/) { |
|
|
1026 | if ($login eq $pl->name) { |
|
|
1027 | $pl->message ("Very funny, $login. Ha. Ha.", cf::NDI_UNIQUE); |
|
|
1028 | } elsif (cf::player::find_active $login) { |
|
|
1029 | $pl->message ("$login is right here on this server!", cf::NDI_UNIQUE); |
|
|
1030 | } elsif (cf::player::exists $login |
|
|
1031 | and stat sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($login) x 2) { |
|
|
1032 | my $time = (stat _)[9]; |
|
|
1033 | |
|
|
1034 | $pl->message ("$login was last seen here " |
|
|
1035 | . (POSIX::strftime "%Y-%m-%d %H:%M:%S +0000", gmtime $time) |
|
|
1036 | . " which was " . (int +(time - $time) / 3600) . " hours ago.", cf::NDI_UNIQUE); |
|
|
1037 | } else { |
|
|
1038 | $pl->message ("No player named $login is known to me.", cf::NDI_UNIQUE); |
|
|
1039 | } |
|
|
1040 | } else { |
|
|
1041 | $pl->message ("Usage: seen <player>", cf::NDI_UNIQUE); |
|
|
1042 | } |
|
|
1043 | }; |
|
|
1044 | |
|
|