ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/chat.ext
(Generate patch)

Comparing deliantra/maps/perl/chat.ext (file contents):
Revision 1.7 by root, Sun May 7 08:26:47 2006 UTC vs.
Revision 1.8 by root, Sun May 7 09:18:37 2006 UTC

1#! perl 1#! perl
2 2
3# implement a replacement for the built-in chat/shout/tell/reply commands 3# implement a replacement for the built-in chat/shout/tell/reply commands
4# adds ignore/unignore functionality 4# adds ignore/unignore functionality
5
6sub clean_timeouts {
7 my ($player) = @_;
8 my $NOW = time;
9
10 for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) {
11 delete $hash->{$_} for grep $hash->{$_} < $NOW, keys %$hash;
12 }
13}
14
15sub on_logout {
16 my ($pl, $host) = @_;
17
18 clean_timeouts $pl->ob;
19}
5 20
6cf::register_command chat => 0, sub { 21cf::register_command chat => 0, sub {
7 my ($who, $msg) = @_; 22 my ($who, $msg) = @_;
8 23
9 if ($msg) { 24 if ($msg) {
10 my $name = $who->name; 25 my $name = $who->name;
26 my $NOW = time;
11 27
12 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) 28 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE)
13 for grep !$_->ob->{ext_ignore_shout}, cf::player::list; 29 for grep $_->ob->{ext_ignore_shout}{$name} < $NOW, cf::player::list;
14 30
15 } else { 31 } else {
16 $who->message ("Chat what?", cf::NDI_UNIQUE); 32 $who->message ("Chat what?", cf::NDI_UNIQUE);
17 } 33 }
18}; 34};
19 35
20cf::register_command shout => 0, sub { 36cf::register_command shout => 0, sub {
21 my ($who, $msg) = @_; 37 my ($who, $msg) = @_;
22 38
23 if ($msg) { 39 if ($msg) {
40 my $NOW = time;
24 my $name = $who->name; 41 my $name = $who->name;
25 42
26 $_->ob->message ("$name shouts: $msg", cf::NDI_RED) 43 $_->ob->message ("$name shouts: $msg", cf::NDI_RED)
27 for grep !$_->ob->{ext_ignore_shout}, cf::player::list; 44 for grep $_->ob->{ext_ignore_shout}{$name} < $NOW, cf::player::list;
28 45
29 } else { 46 } else {
30 $who->message ("Shout what?", cf::NDI_UNIQUE); 47 $who->message ("Shout what?", cf::NDI_UNIQUE);
31 } 48 }
32 49
38 55
39 my $name = $who->name; 56 my $name = $who->name;
40 57
41 if (my $other = cf::player::find $target) { 58 if (my $other = cf::player::find $target) {
42 59
43 $other->ob->{ext_ignore_tell}{$name} >= time
44 or delete $other->ob->{ext_ignore_tell}{$name};
45
46 if ($target ne $name and !$other->ob->{ext_ignore_tell}{$name}) { 60 if ($target ne $name and $other->ob->{ext_ignore_tell}{$name} < time) {
47 $who->message ("You tell $target: $msg"); 61 $who->message ("You tell $target: $msg");
48 $other->ob->message ("$name tells you: $msg"); 62 $other->ob->message ("$name tells you: $msg");
49 $other->ob->{ext_last_tell} = $name; 63 $other->ob->{ext_last_tell} = $name;
50 } elsif ($target eq $name) { 64 } elsif ($target eq $name) {
51 $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); 65 $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE);
65 if (my $other = cf::player::find $who->{ext_last_tell}) { 79 if (my $other = cf::player::find $who->{ext_last_tell}) {
66 80
67 $other->ob->{ext_ignore_tell}{$name} >= time 81 $other->ob->{ext_ignore_tell}{$name} >= time
68 or delete $other->ob->{ext_ignore_tell}{$name}; 82 or delete $other->ob->{ext_ignore_tell}{$name};
69 83
70 if (!$other->ob->{ext_ignore_tell}{$name}) { 84 if ($other->ob->{ext_ignore_tell}{$name} < time) {
71 $who->message ("You tell " . $other->ob->name . ": $args"); 85 $who->message ("You tell " . $other->ob->name . ": $args");
72 $other->ob->message ("$name tells you: $args"); 86 $other->ob->message ("$name tells you: $args");
73 $who->{ext_last_tell} = $other->ob->name; 87 $who->{ext_last_tell} = $other->ob->name;
74 } else { 88 } else {
75 $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE); 89 $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE);
83cf::register_command ignore => 0, sub { 97cf::register_command ignore => 0, sub {
84 my ($who, $args) = @_; 98 my ($who, $args) = @_;
85 my ($target, $type, $timeout) = split /\s+/, $args; 99 my ($target, $type, $timeout) = split /\s+/, $args;
86 100
87 if ($args eq "list") { 101 if ($args eq "list") {
102 clean_timeouts $who;
103
88 if ((my @ignored_tell = sort keys %{$who->{ext_ignore_tell}}) 104 if ((my @ignored_tell = sort keys %{$who->{ext_ignore_tell}})
89 + (my @ignored_shout = sort keys %{$who->{ext_ignore_shout}})) { 105 + (my @ignored_shout = sort keys %{$who->{ext_ignore_shout}})) {
90 $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE); 106 $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE);
91 $who->message ((join ", ", @ignored_tell), cf::NDI_UNIQUE); 107 $who->message ((join ", ", @ignored_tell), cf::NDI_UNIQUE);
92 $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE); 108 $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines