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.11 by pippijn, Sun May 7 10:54:06 2006 UTC vs.
Revision 1.12 by root, Sun May 7 11:23:43 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 5
6sub valid_user($) {
7 -f sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($_[0]) x 2;
8}
9
6sub clean_timeouts { 10sub clean_timeouts($) {
7 my ($player) = @_; 11 my ($player) = @_;
8 my $NOW = time; 12 my $NOW = time;
9 13
10 for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) { 14 for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) {
11 delete $hash->{$_} for grep $hash->{$_} < $NOW, keys %$hash; 15 while (my ($k, $v) = each %$hash) {
16 if ($v < $NOW) {
17 $player->message ("Your ignore on $k has expired.", cf::NDI_GREEN);
18 delete $hash->{$k};
19 } elsif (!valid_user $k) {
20 $player->message ("Your ignore on $k is no longer valid (no such user).", cf::NDI_GREEN);
21 delete $hash->{$k};
22 }
23 }
12 } 24 }
13} 25}
14 26
15sub on_logout { 27sub on_logout {
16 my ($pl, $host) = @_; 28 my ($pl, $host) = @_;
54 my ($target, $msg) = split /\s+/, $args, 2; 66 my ($target, $msg) = split /\s+/, $args, 2;
55 67
56 my $name = $who->name; 68 my $name = $who->name;
57 69
58 if (my $other = cf::player::find $target) { 70 if (my $other = cf::player::find $target) {
71
59 if ($msg) { 72 if ($msg) {
60 73 if ($target eq $name) {
74 $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE);
61 if ($target ne $name and $other->ob->{ext_ignore_tell}{$name} < time) { 75 } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) {
76 $who->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE);
77 } else {
62 $who->message ("You tell $target: $msg"); 78 $who->message ("You tell $target: $msg");
63 $other->ob->message ("$name tells you: $msg"); 79 $other->ob->message ("$name tells you: $msg");
64 $other->ob->{ext_last_tell} = $name; 80 $other->ob->{ext_last_tell} = $name;
65 } elsif ($target eq $name) {
66 $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE);
67 } else {
68 $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE);
69 } 81 }
70
71 } else { 82 } else {
72 $who->message ("What do you want to tell $target?", cf::NDI_UNIQUE); 83 $who->message ("What do you want to tell $target?", cf::NDI_UNIQUE);
73 } 84 }
85
74 } else { 86 } else {
75 $who->message ("No such player or ambiguous name. Your message: $msg", cf::NDI_UNIQUE); 87 $who->message ("No such player. Your message: $msg", cf::NDI_UNIQUE);
76 } 88 }
77}; 89};
78 90
79cf::register_command reply => 0, sub { 91cf::register_command reply => 0, sub {
80 my ($who, $args) = @_; 92 my ($who, $args) = @_;
121 } 133 }
122 134
123 } elsif ($target && $type) { 135 } elsif ($target && $type) {
124 136
125 $timeout ne "" or $timeout = 24; 137 $timeout ne "" or $timeout = 24;
126
127 my $absolute_timeout = time + $timeout * 3600; 138 my $absolute_timeout = time + $timeout * 3600;
128 139
129 if (my $other = cf::player::find $target) { 140 if (valid_user $target) {
130 if ($type eq "tell") { 141 if ($type eq "tell") {
131 $who->message ("Now ignoring private messages from " . $other->ob->name . " for $timeout hours.", cf::NDI_UNIQUE); 142 $who->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_UNIQUE);
132 $who->{ext_ignore_tell}{$other->ob->name} = $absolute_timeout; 143 $who->{ext_ignore_tell}{$target} = $absolute_timeout;
133 } elsif ($type eq "shout") { 144 } elsif ($type eq "shout") {
134 $who->message ("Now ignoring shouts from " . $other->ob->name . " for $timeout hours.", cf::NDI_UNIQUE); 145 $who->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_UNIQUE);
135 $who->{ext_ignore_shout}{$other->ob->name} = $absolute_timeout; 146 $who->{ext_ignore_shout}{$target} = $absolute_timeout;
136 } elsif ($type eq "all") { 147 } elsif ($type eq "all") {
137 $who->message ("Now ignoring everything from " . $other->ob->name . " for $timeout hours.", cf::NDI_UNIQUE); 148 $who->message ("Now ignoring everything from $target for $timeout hours.", cf::NDI_UNIQUE);
138 $who->{ext_ignore_tell}{$other->ob->name} = $absolute_timeout; 149 $who->{ext_ignore_tell}{$target} = $absolute_timeout;
139 $who->{ext_ignore_shout}{$other->ob->name} = $absolute_timeout; 150 $who->{ext_ignore_shout}{$target} = $absolute_timeout;
140 } else { 151 } else {
141 $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE); 152 $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE);
142 } 153 }
143 } else { 154 } else {
144 $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE); 155 $who->message ("No such player: $target", cf::NDI_UNIQUE);
145 } 156 }
146 157
147 } else { 158 } else {
148 $who->message ("Usage:", cf::NDI_UNIQUE);
149 $who->message ("ignore <player> <tell | shout | all> <timeout>", cf::NDI_UNIQUE); 159 $who->message ("Usage: ignore <player> <tell | shout | all> <timeout>\n"
150 $who->message ("will ignore a player for <timeout> hours.", cf::NDI_UNIQUE); 160 . "will ignore a player for <timeout> hours.\n"
151 $who->message ("ignore list", cf::NDI_UNIQUE); 161 . "Usage: ignore list\n"
152 $who->message ("will show you a list of players currently ignored.", cf::NDI_UNIQUE); 162 . "will show you a list of players currently ignored.", cf::NDI_UNIQUE);
153 } 163 }
154}; 164};
155 165
156cf::register_command unignore => 0, sub { 166cf::register_command unignore => 0, sub {
157 my ($who, $args) = @_; 167 my ($who, $args) = @_;
158 my ($target, $type) = split /\s+/, $args; 168 my ($target, $type) = split /\s+/, $args;
159 169
160 if ($args eq "") { 170 if ($args eq "") {
161 if ($who->{ ext_ignore_tell }) { 171 if ($who->{ext_ignore_tell}) {
162 $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE); 172 $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE);
163 $who->message ((join ", ", sort keys %{ $who->{ext_ignore_tell} }), cf::NDI_UNIQUE); 173 $who->message ((join ", ", sort keys %{ $who->{ext_ignore_tell} }), cf::NDI_UNIQUE);
164 $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE); 174 $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE);
165 $who->message ((join ", ", sort keys %{ $who->{ext_ignore_shout} }), cf::NDI_UNIQUE); 175 $who->message ((join ", ", sort keys %{ $who->{ext_ignore_shout} }), cf::NDI_UNIQUE);
166 } else { 176 } else {
167 $who->message ("Not ignoring anyone", cf::NDI_UNIQUE); 177 $who->message ("Not ignoring anyone", cf::NDI_UNIQUE);
168 } 178 }
169 } else { 179 } else {
170 180
171 if (my $other = cf::player::find $target) { 181 if (valid_user $target) {
172 if ($type eq "tell") { 182 if ($type eq "tell") {
173 $who->message ("Not ignoring private messages from " . $other->ob->name . " anymore.", cf::NDI_UNIQUE); 183 $who->message ("Not ignoring private messages from $target anymore.", cf::NDI_UNIQUE);
174 delete $who->{ext_ignore_tell}{$other->ob->name}; 184 delete $who->{ext_ignore_tell} {$target};
175 } elsif ($type eq "shout") { 185 } elsif ($type eq "shout") {
176 $who->message ("Not ignoring shouts from " . $other->ob->name." anymore . ", cf::NDI_UNIQUE); 186 $who->message ("Not ignoring shouts from $target anymore.", cf::NDI_UNIQUE);
177 delete $who->{ext_ignore_shout}{$other->ob->name}; 187 delete $who->{ext_ignore_shout}{$target};
178 } elsif ($type eq "all") { 188 } elsif ($type eq "all") {
179 $who->message ("Not ignoring anything from " . $other->ob->name." anymore . ", cf::NDI_UNIQUE); 189 $who->message ("Not ignoring anything from $target anymore.", cf::NDI_UNIQUE);
180 delete $who->{ext_ignore_tell} {$other->ob->name}; 190 delete $who->{ext_ignore_tell} {$target};
181 delete $who->{ext_ignore_shout}{$other->ob->name}; 191 delete $who->{ext_ignore_shout}{$target};
182 } else { 192 } else {
183 $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE); 193 $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE);
184 } 194 }
185 } else { 195 } else {
186 $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE); 196 $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines