ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/chat.ext
Revision: 1.17
Committed: Mon May 22 08:13:37 2006 UTC (18 years ago) by pippijn
Branch: MAIN
Changes since 1.16: +1 -1 lines
Log Message:
Fixed bug where one could not do listen 0.

File Contents

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