#! perl # implement a replacement for the built-in say/chat/shout/tell/reply commands # adds ignore/unignore functionality sub valid_user($) { cf::player::find $_[0] or -f sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($_[0]) x 2; } sub clean_timeouts($) { my ($player) = @_; my $NOW = time; for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) { while (my ($k, $v) = each %$hash) { if ($v < $NOW) { $player->message ("Your ignore on $k has expired.", cf::NDI_GREEN); delete $hash->{$k}; } elsif (!valid_user $k) { $player->message ("Your ignore on $k is no longer valid (no such user).", cf::NDI_GREEN); delete $hash->{$k}; } } } } sub on_logout { my ($pl, $host) = @_; clean_timeouts $pl->ob; } cf::register_command listen => 0, sub { my ($who, $msg) = @_; my $player = cf::player::find $who->name; if ($msg ne "") { my $prev_listen = $player->listening; $player->listening ($msg); if ($prev_listen == $player->listening) { $who->message ("Your verbose level stayed ".$prev_listen.".", cf::NDI_UNIQUE); } else { $who->message ("Your verbose level is now ".$player->listening.". (previously: ".$prev_listen.")", cf::NDI_UNIQUE); } } else { $who->message ("Your verbose level is ".$player->listening.".", cf::NDI_UNIQUE); } }; #cf::register_command say => 0, sub { # my ($who, $msg) = @_; # # if ($msg) { # my $name = $who->name; # $_->ob->message ("$name says: $msg", cf::NDI_WHITE) # for grep $who->on_same_map_as ($_->ob), cf::player::list; # } else { # $who->message ("What do you want to say?", cf::NDI_UNIQUE); # } #}; cf::register_command chat => 0, sub { my ($who, $msg) = @_; if ($msg) { my $name = $who->name; my $NOW = time; cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; } else { $who->message ("Chat what?", cf::NDI_UNIQUE); } }; cf::register_command shout => 0, sub { my ($who, $msg) = @_; if ($msg) { my $NOW = time; my $name = $who->name; cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; $_->ob->message ("$name shouts: $msg", cf::NDI_RED) for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; } else { $who->message ("Shout what?", cf::NDI_UNIQUE); } }; cf::register_command tell => 0, sub { my ($who, $args) = @_; my ($target, $msg) = split /\s+/, $args, 2; my $name = $who->name; if (my $other = cf::player::find $target) { if ($msg) { if ($target eq $name) { $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { $who->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE); } else { cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg; $who->message ("You tell $target: $msg"); $other->ob->message ("$name tells you: $msg"); $other->ob->{ext_last_tell} = $name; } } else { $who->message ("What do you want to tell $target?", cf::NDI_UNIQUE); } } else { $who->message ("No such player. Your message: $msg", cf::NDI_UNIQUE); } }; cf::register_command reply => 0, sub { my ($who, $args) = @_; my $name = $who->name; if (my $other = cf::player::find $who->{ext_last_tell}) { if ($args) { $other->ob->{ext_ignore_tell}{$name} >= time or delete $other->ob->{ext_ignore_tell}{$name}; if ($other->ob->{ext_ignore_tell}{$name} < time) { cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $other->ob->name, $args; $who->message ("You tell " . $other->ob->name . ": $args"); $other->ob->message ("$name tells you: $args"); $who->{ext_last_tell} = $other->ob->name; } else { $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE); } } else { $who->message ("What do you want to tell ".$other->ob->name."?", cf::NDI_UNIQUE); } } else { $who->message ("Can't reply, player left. Your message: $args", cf::NDI_UNIQUE); } }; cf::register_command ignore => 0, sub { my ($who, $args) = @_; my ($target, $type, $timeout) = split /\s+/, $args; if ($args eq "list") { clean_timeouts $who; if ((my @ignored_tell = sort keys %{$who->{ext_ignore_tell}}) + (my @ignored_shout = sort keys %{$who->{ext_ignore_shout}})) { $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE); $who->message ((join ", ", @ignored_tell), cf::NDI_UNIQUE); $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE); $who->message ((join ", ", @ignored_shout), cf::NDI_UNIQUE); $who->message ("To stop ignoring one, use unignore.", cf::NDI_UNIQUE); } else { $who->message ("Not ignoring anyone", cf::NDI_UNIQUE); } } elsif ($target && $type) { $timeout ne "" or $timeout = 24; my $absolute_timeout = time + $timeout * 3600; if (valid_user $target) { if ($type eq "tell") { $who->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_UNIQUE); $who->{ext_ignore_tell}{$target} = $absolute_timeout; } elsif ($type eq "shout") { $who->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_UNIQUE); $who->{ext_ignore_shout}{$target} = $absolute_timeout; } elsif ($type eq "all") { $who->message ("Now ignoring everything from $target for $timeout hours.", cf::NDI_UNIQUE); $who->{ext_ignore_tell}{$target} = $absolute_timeout; $who->{ext_ignore_shout}{$target} = $absolute_timeout; } else { $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE); } } else { $who->message ("No such player: $target", cf::NDI_UNIQUE); } } else { $who->message ("Usage: ignore \n" . "will ignore a player for hours.\n" . "Usage: ignore list\n" . "will show you a list of players currently ignored.", cf::NDI_UNIQUE); } }; cf::register_command unignore => 0, sub { my ($who, $args) = @_; my ($target, $type) = split /\s+/, $args; if ($args eq "") { if ($who->{ext_ignore_tell}) { $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE); $who->message ((join ", ", sort keys %{ $who->{ext_ignore_tell} }), cf::NDI_UNIQUE); $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE); $who->message ((join ", ", sort keys %{ $who->{ext_ignore_shout} }), cf::NDI_UNIQUE); } else { $who->message ("Not ignoring anyone", cf::NDI_UNIQUE); } } else { if (valid_user $target) { if ($type eq "tell") { $who->message ("Not ignoring private messages from $target anymore.", cf::NDI_UNIQUE); delete $who->{ext_ignore_tell} {$target}; } elsif ($type eq "shout") { $who->message ("Not ignoring shouts from $target anymore.", cf::NDI_UNIQUE); delete $who->{ext_ignore_shout}{$target}; } elsif ($type eq "all") { $who->message ("Not ignoring anything from $target anymore.", cf::NDI_UNIQUE); delete $who->{ext_ignore_tell} {$target}; delete $who->{ext_ignore_shout}{$target}; } else { $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE); } } else { $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE); } } };