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.5 by root, Sun May 7 08:10:23 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
11sub clean_timeouts($) {
12 my ($player) = @_;
13 my $NOW = time;
14
15 for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) {
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 }
25 }
26}
27
28sub on_logout {
29 my ($pl, $host) = @_;
30
31 clean_timeouts $pl->ob;
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#};
62
6cf::register_command chat => 0, sub 63cf::register_command chat => 0, sub {
7{
8 my ($who, $msg) = @_; 64 my ($who, $msg) = @_;
9 65
10 if ($msg) { 66 if ($msg) {
11 my $name = $who->name; 67 my $name = $who->name;
68 my $NOW = time;
69
70 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg;
12 71
13 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) 72 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE)
14 for grep !$player->ob->{ext_ignore_shout}, cf::player::list; 73 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list;
15 74
16 } else { 75 } else {
17 $who->message ("Chat what?", cf::NDI_UNIQUE); 76 $who->message ("Chat what?", cf::NDI_UNIQUE);
18 } 77 }
19}; 78};
20 79
21cf::register_command shout => 0, sub 80cf::register_command shout => 0, sub {
22{
23 my ($who, $msg) = @_; 81 my ($who, $msg) = @_;
24 82
25 if ($msg) { 83 if ($msg) {
84 my $NOW = time;
26 my $name = $who->name; 85 my $name = $who->name;
27 86
87 cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg;
88
28 $_->ob->message ("$name shouts: $msg", cf::NDI_RED) 89 $_->ob->message ("$name shouts: $msg", cf::NDI_RED)
29 for grep !$player->ob->{ext_ignore_shout}, cf::player::list; 90 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list;
30 91
31 } else { 92 } else {
32 $who->message ("Shout what?", cf::NDI_UNIQUE); 93 $who->message ("Shout what?", cf::NDI_UNIQUE);
33 } 94 }
34 95
40 101
41 my $name = $who->name; 102 my $name = $who->name;
42 103
43 if (my $other = cf::player::find $target) { 104 if (my $other = cf::player::find $target) {
44 105
45 $other->ob->{ext_ignore_tell}{$name} >= time 106 if ($msg) {
46 or delete $other->ob->{ext_ignore_tell}{$name};
47
48 if ($target ne $name and !$other->ob->{ext_ignore_tell}{$name}) {
49 $who->message ("You tell $target: $msg");
50 $other->ob->message ("$name tells you: $msg");
51 $other->ob->{ext_last_tell} = $name;
52 } elsif ($target eq $name) { 107 if ($target eq $name) {
53 $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);
54 } else { 111 } else {
55 $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;
56 } 117 }
57
58 } else { 118 } else {
119 $who->message ("What do you want to tell $target?", cf::NDI_UNIQUE);
120 }
121
122 } else {
59 $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);
60 } 124 }
61}; 125};
62 126
63cf::register_command reply => 0, sub { 127cf::register_command reply => 0, sub {
64 my ($who, $args) = @_; 128 my ($who, $args) = @_;
65 my $name = $who->name; 129 my $name = $who->name;
66 130
67 if (my $other = cf::player::find $who->{ext_last_tell}) { 131 if (my $other = cf::player::find $who->{ext_last_tell}) {
132 if ($args) {
68 133
69 $other->ob->{ext_ignore_tell}{$name} >= time 134 $other->ob->{ext_ignore_tell}{$name} >= time
70 or delete $other->ob->{ext_ignore_tell}{$name}; 135 or delete $other->ob->{ext_ignore_tell}{$name};
71 136
72 if (!$other->ob->{ext_ignore_tell}{$name}) { 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
73 $who->message ("You tell " . $other->ob->name . ": $args"); 140 $who->message ("You tell " . $other->ob->name . ": $args");
74 $other->ob->message ("$name tells you: $args"); 141 $other->ob->message ("$name tells you: $args");
75 $who->{ext_last_tell} = $other->ob->name; 142 $who->{ext_last_tell} = $other->ob->name;
76 } else { 143 } else {
77 $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);
78 } 148 }
79 149
80 } else { 150 } else {
81 $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);
82 } 152 }
85cf::register_command ignore => 0, sub { 155cf::register_command ignore => 0, sub {
86 my ($who, $args) = @_; 156 my ($who, $args) = @_;
87 my ($target, $type, $timeout) = split /\s+/, $args; 157 my ($target, $type, $timeout) = split /\s+/, $args;
88 158
89 if ($args eq "list") { 159 if ($args eq "list") {
160 clean_timeouts $who;
161
90 if ((my @ignored_tell = sort keys %{$who->{ext_ignore_tell}}) 162 if ((my @ignored_tell = sort keys %{$who->{ext_ignore_tell}})
91 + (my @ignored_shout = sort keys %{$who->{ext_ignore_shout}})) { 163 + (my @ignored_shout = sort keys %{$who->{ext_ignore_shout}})) {
92 $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE); 164 $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE);
93 $who->message ((join ", ", @ignored_tell), cf::NDI_UNIQUE); 165 $who->message ((join ", ", @ignored_tell), cf::NDI_UNIQUE);
94 $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE); 166 $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE);
99 } 171 }
100 172
101 } elsif ($target && $type) { 173 } elsif ($target && $type) {
102 174
103 $timeout ne "" or $timeout = 24; 175 $timeout ne "" or $timeout = 24;
104
105 my $absolute_timeout = time + $timeout * 3600; 176 my $absolute_timeout = time + $timeout * 3600;
106 177
107 if (my $other = cf::player::find $target) { 178 if (valid_user $target) {
108 if ($type eq "tell") { 179 if ($type eq "tell") {
109 $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);
110 $who->{ext_ignore_tell}{$other->ob->name} = $absolute_timeout; 181 $who->{ext_ignore_tell}{$target} = $absolute_timeout;
111 } elsif ($type eq "shout") { 182 } elsif ($type eq "shout") {
112 $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);
113 $who->{ext_ignore_shout}{$other->ob->name} = $absolute_timeout; 184 $who->{ext_ignore_shout}{$target} = $absolute_timeout;
114 } elsif ($type eq "all") { 185 } elsif ($type eq "all") {
115 $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);
116 $who->{ext_ignore_tell}{$other->ob->name} = $absolute_timeout; 187 $who->{ext_ignore_tell}{$target} = $absolute_timeout;
117 $who->{ext_ignore_shout}{$other->ob->name} = $absolute_timeout; 188 $who->{ext_ignore_shout}{$target} = $absolute_timeout;
118 } else { 189 } else {
119 $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);
120 } 191 }
121 } else { 192 } else {
122 $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE); 193 $who->message ("No such player: $target", cf::NDI_UNIQUE);
123 } 194 }
124 195
125 } else { 196 } else {
126 $who->message ("Usage:", cf::NDI_UNIQUE);
127 $who->message ("ignore <player> <tell | shout | all> <timeout>", cf::NDI_UNIQUE); 197 $who->message ("Usage: ignore <player> <tell | shout | all> <timeout>\n"
128 $who->message ("will ignore a player for <timeout> hours.", cf::NDI_UNIQUE); 198 . "will ignore a player for <timeout> hours.\n"
129 $who->message ("ignore list", cf::NDI_UNIQUE); 199 . "Usage: ignore list\n"
130 $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);
131 } 201 }
132}; 202};
133 203
134cf::register_command unignore => 0, sub { 204cf::register_command unignore => 0, sub {
135 my ($who, $args) = @_; 205 my ($who, $args) = @_;
136 my ($target, $type) = split /\s+/, $args; 206 my ($target, $type) = split /\s+/, $args;
137 207
138 if ($args eq "") { 208 if ($args eq "") {
139 if ($who->{ ext_ignore_tell }) { 209 if ($who->{ext_ignore_tell}) {
140 $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE); 210 $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE);
141 $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);
142 $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE); 212 $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE);
143 $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);
144 } else { 214 } else {
145 $who->message ("Not ignoring anyone", cf::NDI_UNIQUE); 215 $who->message ("Not ignoring anyone", cf::NDI_UNIQUE);
146 } 216 }
147 } else { 217 } else {
148 218
149 if (my $other = cf::player::find $target) { 219 if (valid_user $target) {
150 if ($type eq "tell") { 220 if ($type eq "tell") {
151 $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);
152 delete $who->{ext_ignore_tell}{$other->ob->name}; 222 delete $who->{ext_ignore_tell} {$target};
153 } elsif ($type eq "shout") { 223 } elsif ($type eq "shout") {
154 $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);
155 delete $who->{ext_ignore_shout}{$other->ob->name}; 225 delete $who->{ext_ignore_shout}{$target};
156 } elsif ($type eq "all") { 226 } elsif ($type eq "all") {
157 $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);
158 delete $who->{ext_ignore_tell} {$other->ob->name}; 228 delete $who->{ext_ignore_tell} {$target};
159 delete $who->{ext_ignore_shout}{$other->ob->name}; 229 delete $who->{ext_ignore_shout}{$target};
160 } else { 230 } else {
161 $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);
162 } 232 }
163 } else { 233 } else {
164 $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