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.8 by root, Sun May 7 09:18:37 2006 UTC vs.
Revision 1.19 by root, Fri Jun 9 04:18:02 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 say/chat/shout/tell/reply commands
4# adds ignore/unignore functionality 4# adds ignore/unignore functionality
5 5
6sub valid_user($) {
7 cf::player::find $_[0]
8 or -f sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($_[0]) x 2;
9}
10
6sub clean_timeouts { 11sub clean_timeouts($) {
7 my ($player) = @_; 12 my ($player) = @_;
8 my $NOW = time; 13 my $NOW = time;
9 14
10 for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) { 15 for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) {
11 delete $hash->{$_} for grep $hash->{$_} < $NOW, keys %$hash; 16 while (my ($k, $v) = each %$hash) {
17 if ($v < $NOW) {
18 $player->message ("Your ignore on $k has expired.", cf::NDI_GREEN);
19 delete $hash->{$k};
20 } elsif (!valid_user $k) {
21 $player->message ("Your ignore on $k is no longer valid (no such user).", cf::NDI_GREEN);
22 delete $hash->{$k};
23 }
24 }
12 } 25 }
13} 26}
14 27
15sub on_logout { 28sub on_logout {
16 my ($pl, $host) = @_; 29 my ($pl, $host) = @_;
17 30
18 clean_timeouts $pl->ob; 31 clean_timeouts $pl->ob;
19} 32}
33
34cf::register_command listen => 0, sub {
35 my ($who, $msg) = @_;
36 my $player = cf::player::find $who->name;
37
38 if ($msg ne "") {
39 my $prev_listen = $player->listening;
40 $player->listening ($msg);
41 if ($prev_listen == $player->listening) {
42 $who->message ("Your verbose level stayed ".$prev_listen.".", cf::NDI_UNIQUE);
43 } else {
44 $who->message ("Your verbose level is now ".$player->listening.". (previously: ".$prev_listen.")", cf::NDI_UNIQUE);
45 }
46 } else {
47 $who->message ("Your verbose level is ".$player->listening.".", cf::NDI_UNIQUE);
48 }
49};
50
51#cf::register_command say => 0, sub {
52# my ($who, $msg) = @_;
53#
54# if ($msg) {
55# my $name = $who->name;
56# $_->ob->message ("$name says: $msg", cf::NDI_WHITE)
57# for grep $who->on_same_map_as ($_->ob), cf::player::list;
58# } else {
59# $who->message ("What do you want to say?", cf::NDI_UNIQUE);
60# }
61#};
20 62
21cf::register_command chat => 0, sub { 63cf::register_command chat => 0, sub {
22 my ($who, $msg) = @_; 64 my ($who, $msg) = @_;
23 65
24 if ($msg) { 66 if ($msg) {
25 my $name = $who->name; 67 my $name = $who->name;
26 my $NOW = time; 68 my $NOW = time;
27 69
70 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg;
71
28 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) 72 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE)
29 for grep $_->ob->{ext_ignore_shout}{$name} < $NOW, cf::player::list; 73 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list;
30 74
31 } else { 75 } else {
32 $who->message ("Chat what?", cf::NDI_UNIQUE); 76 $who->message ("Chat what?", cf::NDI_UNIQUE);
33 } 77 }
34}; 78};
38 82
39 if ($msg) { 83 if ($msg) {
40 my $NOW = time; 84 my $NOW = time;
41 my $name = $who->name; 85 my $name = $who->name;
42 86
87 cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg;
88
43 $_->ob->message ("$name shouts: $msg", cf::NDI_RED) 89 $_->ob->message ("$name shouts: $msg", cf::NDI_RED)
44 for grep $_->ob->{ext_ignore_shout}{$name} < $NOW, cf::player::list; 90 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list;
45 91
46 } else { 92 } else {
47 $who->message ("Shout what?", cf::NDI_UNIQUE); 93 $who->message ("Shout what?", cf::NDI_UNIQUE);
48 } 94 }
49 95
55 101
56 my $name = $who->name; 102 my $name = $who->name;
57 103
58 if (my $other = cf::player::find $target) { 104 if (my $other = cf::player::find $target) {
59 105
60 if ($target ne $name and $other->ob->{ext_ignore_tell}{$name} < time) { 106 if ($msg) {
61 $who->message ("You tell $target: $msg");
62 $other->ob->message ("$name tells you: $msg");
63 $other->ob->{ext_last_tell} = $name;
64 } elsif ($target eq $name) { 107 if ($target eq $name) {
65 $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); 108 $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE);
109 } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) {
110 $who->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE);
66 } else { 111 } else {
67 $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE); 112 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg;
113
114 $who->message ("You tell $target: $msg");
115 $other->ob->message ("$name tells you: $msg");
116 $other->ob->{ext_last_tell} = $name;
68 } 117 }
69
70 } else { 118 } else {
119 $who->message ("What do you want to tell $target?", cf::NDI_UNIQUE);
120 }
121
122 } else {
71 $who->message ("No such player or ambiguous name. Your message: $msg", cf::NDI_UNIQUE); 123 $who->message ("No such player. Your message: $msg", cf::NDI_UNIQUE);
72 } 124 }
73}; 125};
74 126
75cf::register_command reply => 0, sub { 127cf::register_command reply => 0, sub {
76 my ($who, $args) = @_; 128 my ($who, $args) = @_;
77 my $name = $who->name; 129 my $name = $who->name;
78 130
79 if (my $other = cf::player::find $who->{ext_last_tell}) { 131 if (my $other = cf::player::find $who->{ext_last_tell}) {
132 if ($args) {
80 133
81 $other->ob->{ext_ignore_tell}{$name} >= time 134 $other->ob->{ext_ignore_tell}{$name} >= time
82 or delete $other->ob->{ext_ignore_tell}{$name}; 135 or delete $other->ob->{ext_ignore_tell}{$name};
83 136
84 if ($other->ob->{ext_ignore_tell}{$name} < time) { 137 if ($other->ob->{ext_ignore_tell}{$name} < time) {
138 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $other->ob->name, $args;
139
85 $who->message ("You tell " . $other->ob->name . ": $args"); 140 $who->message ("You tell " . $other->ob->name . ": $args");
86 $other->ob->message ("$name tells you: $args"); 141 $other->ob->message ("$name tells you: $args");
87 $who->{ext_last_tell} = $other->ob->name; 142 $who->{ext_last_tell} = $other->ob->name;
88 } else { 143 } else {
89 $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE); 144 $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE);
145 }
146 } else {
147 $who->message ("What do you want to tell ".$other->ob->name."?", cf::NDI_UNIQUE);
90 } 148 }
91 149
92 } else { 150 } else {
93 $who->message ("Can't reply, player left. Your message: $args", cf::NDI_UNIQUE); 151 $who->message ("Can't reply, player left. Your message: $args", cf::NDI_UNIQUE);
94 } 152 }
113 } 171 }
114 172
115 } elsif ($target && $type) { 173 } elsif ($target && $type) {
116 174
117 $timeout ne "" or $timeout = 24; 175 $timeout ne "" or $timeout = 24;
118
119 my $absolute_timeout = time + $timeout * 3600; 176 my $absolute_timeout = time + $timeout * 3600;
120 177
121 if (my $other = cf::player::find $target) { 178 if (valid_user $target) {
122 if ($type eq "tell") { 179 if ($type eq "tell") {
123 $who->message ("Now ignoring private messages from " . $other->ob->name . " for $timeout hours.", cf::NDI_UNIQUE); 180 $who->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_UNIQUE);
124 $who->{ext_ignore_tell}{$other->ob->name} = $absolute_timeout; 181 $who->{ext_ignore_tell}{$target} = $absolute_timeout;
125 } elsif ($type eq "shout") { 182 } elsif ($type eq "shout") {
126 $who->message ("Now ignoring shouts from " . $other->ob->name . " for $timeout hours.", cf::NDI_UNIQUE); 183 $who->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_UNIQUE);
127 $who->{ext_ignore_shout}{$other->ob->name} = $absolute_timeout; 184 $who->{ext_ignore_shout}{$target} = $absolute_timeout;
128 } elsif ($type eq "all") { 185 } elsif ($type eq "all") {
129 $who->message ("Now ignoring everything from " . $other->ob->name . " for $timeout hours.", cf::NDI_UNIQUE); 186 $who->message ("Now ignoring everything from $target for $timeout hours.", cf::NDI_UNIQUE);
130 $who->{ext_ignore_tell}{$other->ob->name} = $absolute_timeout; 187 $who->{ext_ignore_tell}{$target} = $absolute_timeout;
131 $who->{ext_ignore_shout}{$other->ob->name} = $absolute_timeout; 188 $who->{ext_ignore_shout}{$target} = $absolute_timeout;
132 } else { 189 } else {
133 $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE); 190 $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE);
134 } 191 }
135 } else { 192 } else {
136 $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE); 193 $who->message ("No such player: $target", cf::NDI_UNIQUE);
137 } 194 }
138 195
139 } else { 196 } else {
140 $who->message ("Usage:", cf::NDI_UNIQUE);
141 $who->message ("ignore <player> <tell | shout | all> <timeout>", cf::NDI_UNIQUE); 197 $who->message ("Usage: ignore <player> <tell | shout | all> <timeout>\n"
142 $who->message ("will ignore a player for <timeout> hours.", cf::NDI_UNIQUE); 198 . "will ignore a player for <timeout> hours.\n"
143 $who->message ("ignore list", cf::NDI_UNIQUE); 199 . "Usage: ignore list\n"
144 $who->message ("will show you a list of players currently ignored.", cf::NDI_UNIQUE); 200 . "will show you a list of players currently ignored.", cf::NDI_UNIQUE);
145 } 201 }
146}; 202};
147 203
148cf::register_command unignore => 0, sub { 204cf::register_command unignore => 0, sub {
149 my ($who, $args) = @_; 205 my ($who, $args) = @_;
150 my ($target, $type) = split /\s+/, $args; 206 my ($target, $type) = split /\s+/, $args;
151 207
152 if ($args eq "") { 208 if ($args eq "") {
153 if ($who->{ ext_ignore_tell }) { 209 if ($who->{ext_ignore_tell}) {
154 $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE); 210 $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE);
155 $who->message ((join ", ", sort keys %{ $who->{ext_ignore_tell} }), cf::NDI_UNIQUE); 211 $who->message ((join ", ", sort keys %{ $who->{ext_ignore_tell} }), cf::NDI_UNIQUE);
156 $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE); 212 $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE);
157 $who->message ((join ", ", sort keys %{ $who->{ext_ignore_shout} }), cf::NDI_UNIQUE); 213 $who->message ((join ", ", sort keys %{ $who->{ext_ignore_shout} }), cf::NDI_UNIQUE);
158 } else { 214 } else {
159 $who->message ("Not ignoring anyone", cf::NDI_UNIQUE); 215 $who->message ("Not ignoring anyone", cf::NDI_UNIQUE);
160 } 216 }
161 } else { 217 } else {
162 218
163 if (my $other = cf::player::find $target) { 219 if (valid_user $target) {
164 if ($type eq "tell") { 220 if ($type eq "tell") {
165 $who->message ("Not ignoring private messages from " . $other->ob->name . " anymore.", cf::NDI_UNIQUE); 221 $who->message ("Not ignoring private messages from $target anymore.", cf::NDI_UNIQUE);
166 delete $who->{ext_ignore_tell}{$other->ob->name}; 222 delete $who->{ext_ignore_tell} {$target};
167 } elsif ($type eq "shout") { 223 } elsif ($type eq "shout") {
168 $who->message ("Not ignoring shouts from " . $other->ob->name." anymore . ", cf::NDI_UNIQUE); 224 $who->message ("Not ignoring shouts from $target anymore.", cf::NDI_UNIQUE);
169 delete $who->{ext_ignore_shout}{$other->ob->name}; 225 delete $who->{ext_ignore_shout}{$target};
170 } elsif ($type eq "all") { 226 } elsif ($type eq "all") {
171 $who->message ("Not ignoring anything from " . $other->ob->name." anymore . ", cf::NDI_UNIQUE); 227 $who->message ("Not ignoring anything from $target anymore.", cf::NDI_UNIQUE);
172 delete $who->{ext_ignore_tell} {$other->ob->name}; 228 delete $who->{ext_ignore_tell} {$target};
173 delete $who->{ext_ignore_shout}{$other->ob->name}; 229 delete $who->{ext_ignore_shout}{$target};
174 } else { 230 } else {
175 $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE); 231 $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE);
176 } 232 }
177 } else { 233 } else {
178 $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE); 234 $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines