--- deliantra/server/ext/chat.ext 2008/09/19 01:39:45 1.44 +++ deliantra/server/ext/chat.ext 2009/01/25 23:56:13 1.47 @@ -56,7 +56,9 @@ on_login => sub { my ($pl) = @_; - clean_timeouts $pl->ob; + cf::async { + clean_timeouts $pl->ob; + }; $pl->send_msg ($cf::SAY_CHANNEL); $pl->send_msg ($cf::CHAT_CHANNEL); @@ -760,15 +762,6 @@ }; } -cf::register_command me => sub { - my ($pl, $msg) = @_; - - my $name = $pl->name; - - send_msg $_, $cf::SAY_CHANNEL => "* $name $msg", cf::NDI_GREY | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_say" - for grep $pl->on_same_map_as ($_->ob), cf::player::list; -}; - cf::register_command say => sub { my ($ob, $msg) = @_; @@ -805,16 +798,11 @@ if (defined $reply) { if ($npc->type == cf::MAGIC_EAR) { - if (length $reply) { - send_msg $_, $cf::SAY_CHANNEL => $reply, cf::NDI_BROWN, "msg_say" - for @plonmap; - } - $npc->use_trigger; + send_msg $_, $cf::SAY_CHANNEL => $reply, cf::NDI_BROWN, "msg_say" + for @plonmap; } else { - if (length $reply) { - send_msg $_, $cf::SAY_CHANNEL => $npc->name . " says: $reply", cf::NDI_BROWN, "msg_say" - for @plonmap; - } + send_msg $_, $cf::SAY_CHANNEL => $npc->name . " says: $reply", cf::NDI_BROWN, "msg_say" + for @plonmap; } } @@ -829,10 +817,9 @@ } }; -cf::register_command chat => sub { - my ($ob, $msg) = @_; - utf8::decode $msg; +sub _chat { + my ($ob, $msg) = @_; my $pl = $ob->contr; @@ -842,15 +829,29 @@ my $name = $ob->name; my $NOW = time; - cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; - send_irc ("[%s] %s", $name, $msg); + cf::LOG cf::llevDebug, sprintf "QBERT %s\n", $name, $msg; + send_irc ($msg); - send_msg $_, $cf::CHAT_CHANNEL => "$name chats: $msg", cf::NDI_BLUE | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_chat" + send_msg $_, $cf::CHAT_CHANNEL => $msg, cf::NDI_BLUE | cf::NDI_DEF | ($_ == $pl ? cf::NDI_REPLY : 0), "msg_chat" for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW } cf::player::list; } else { $pl->send_msg ($cf::CHAT_CHANNEL => "Chat what?", cf::NDI_BLUE | cf::NDI_DEF | cf::NDI_REPLY); } +} + +cf::register_command chat => sub { + my ($ob, $msg) = @_; + + utf8::decode $msg; + _chat $ob, $ob->name . " chats: $msg"; +}; + +cf::register_command me => sub { + my ($ob, $msg) = @_; + + utf8::decode $msg; + _chat $ob, "* " . $ob->name . " $msg"; }; cf::register_command shout => sub { @@ -925,82 +926,85 @@ my ($pl, $args) = @_; my ($target, $type, $timeout) = split /\s+/, $args; - if ($args eq "list") { - clean_timeouts $pl; - - if ((my @ignored_tell = sort keys %{$pl->{ext_ignore_tell}}) - + (my @ignored_shout = sort keys %{$pl->{ext_ignore_shout}})) { - $pl->message ("Currently ignoring private messages from: ", cf::NDI_REPLY); - $pl->message ((join ", ", @ignored_tell), cf::NDI_REPLY); - $pl->message ("Currently ignoring shouts from: ", cf::NDI_REPLY); - $pl->message ((join ", ", @ignored_shout), cf::NDI_REPLY); - $pl->message ("To stop ignoring one, use unignore.", cf::NDI_REPLY); - } else { - $pl->message ("Not ignoring anyone", cf::NDI_REPLY); - } - - } elsif ($target && $type) { - - $timeout ne "" or $timeout = 24; - my $absolute_timeout = time + $timeout * 3600; - - if (cf::player::exists $target) { - if ($type eq "tell") { - $pl->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_REPLY); - $pl->{ext_ignore_tell}{$target} = $absolute_timeout; - } elsif ($type eq "shout") { - $pl->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_REPLY); - $pl->{ext_ignore_shout}{$target} = $absolute_timeout; - } elsif ($type eq "all") { - $pl->message ("Now ignoring everything from $target for $timeout hours.", cf::NDI_REPLY); - $pl->{ext_ignore_tell}{$target} = $absolute_timeout; - $pl->{ext_ignore_shout}{$target} = $absolute_timeout; + cf::async { + if ($args eq "list") { + clean_timeouts $pl; + + if ((my @ignored_tell = sort keys %{$pl->{ext_ignore_tell}}) + + (my @ignored_shout = sort keys %{$pl->{ext_ignore_shout}})) { + $pl->message ("Currently ignoring private messages from: ", cf::NDI_REPLY); + $pl->message ((join ", ", @ignored_tell), cf::NDI_REPLY); + $pl->message ("Currently ignoring shouts from: ", cf::NDI_REPLY); + $pl->message ((join ", ", @ignored_shout), cf::NDI_REPLY); + $pl->message ("To stop ignoring one, use unignore.", cf::NDI_REPLY); } else { - $pl->message ("You need to specify tell, shout or all.", cf::NDI_REPLY); + $pl->message ("Not ignoring anyone", cf::NDI_REPLY); } + + } elsif ($target && $type) { + $timeout ne "" or $timeout = 24; + my $absolute_timeout = time + $timeout * 3600; + + if (cf::player::exists $target) { + if ($type eq "tell") { + $pl->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_REPLY); + $pl->{ext_ignore_tell}{$target} = $absolute_timeout; + } elsif ($type eq "shout") { + $pl->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_REPLY); + $pl->{ext_ignore_shout}{$target} = $absolute_timeout; + } elsif ($type eq "all") { + $pl->message ("Now ignoring everything from $target for $timeout hours.", cf::NDI_REPLY); + $pl->{ext_ignore_tell}{$target} = $absolute_timeout; + $pl->{ext_ignore_shout}{$target} = $absolute_timeout; + } else { + $pl->message ("You need to specify tell, shout or all.", cf::NDI_REPLY); + } + } else { + $pl->message ("No such player: $target", cf::NDI_REPLY); + } + } else { - $pl->message ("No such player: $target", cf::NDI_REPLY); + $pl->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_REPLY); } - - } else { - $pl->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_REPLY); - } + }; }; cf::register_command unignore => sub { my ($pl, $args) = @_; my ($target, $type) = split /\s+/, $args; - if ($args eq "") { - if ($pl->{ext_ignore_tell}) { - $pl->message ("Currently ignoring private messages from: ", cf::NDI_REPLY); - $pl->message ((join ", ", sort keys %{ $pl->{ext_ignore_tell} }), cf::NDI_REPLY); - $pl->message ("Currently ignoring shouts from: ", cf::NDI_REPLY); - $pl->message ((join ", ", sort keys %{ $pl->{ext_ignore_shout} }), cf::NDI_REPLY); - } else { - $pl->message ("Not ignoring anyone", cf::NDI_REPLY); - } - } else { - if (cf::player::exists $target) { - if ($type eq "tell") { - $pl->message ("Not ignoring private messages from $target anymore.", cf::NDI_REPLY); - delete $pl->{ext_ignore_tell} {$target}; - } elsif ($type eq "shout") { - $pl->message ("Not ignoring shouts from $target anymore.", cf::NDI_REPLY); - delete $pl->{ext_ignore_shout}{$target}; - } elsif ($type eq "all") { - $pl->message ("Not ignoring anything from $target anymore.", cf::NDI_REPLY); - delete $pl->{ext_ignore_tell} {$target}; - delete $pl->{ext_ignore_shout}{$target}; + cf::async { + if ($args eq "") { + if ($pl->{ext_ignore_tell}) { + $pl->message ("Currently ignoring private messages from: ", cf::NDI_REPLY); + $pl->message ((join ", ", sort keys %{ $pl->{ext_ignore_tell} }), cf::NDI_REPLY); + $pl->message ("Currently ignoring shouts from: ", cf::NDI_REPLY); + $pl->message ((join ", ", sort keys %{ $pl->{ext_ignore_shout} }), cf::NDI_REPLY); } else { - $pl->message ("You need to specify tell, shout or all.", cf::NDI_REPLY); + $pl->message ("Not ignoring anyone", cf::NDI_REPLY); } } else { - $pl->message ("No such player or ambiguous name: $target", cf::NDI_REPLY); + if (cf::player::exists $target) { + if ($type eq "tell") { + $pl->message ("Not ignoring private messages from $target anymore.", cf::NDI_REPLY); + delete $pl->{ext_ignore_tell} {$target}; + } elsif ($type eq "shout") { + $pl->message ("Not ignoring shouts from $target anymore.", cf::NDI_REPLY); + delete $pl->{ext_ignore_shout}{$target}; + } elsif ($type eq "all") { + $pl->message ("Not ignoring anything from $target anymore.", cf::NDI_REPLY); + delete $pl->{ext_ignore_tell} {$target}; + delete $pl->{ext_ignore_shout}{$target}; + } else { + $pl->message ("You need to specify tell, shout or all.", cf::NDI_REPLY); + } + } else { + $pl->message ("No such player or ambiguous name: $target", cf::NDI_REPLY); + } } - } + }; };