ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/chat.ext
Revision: 1.19
Committed: Fri Jun 9 04:18:02 2006 UTC (17 years, 11 months ago) by root
Branch: MAIN
Changes since 1.18: +8 -0 lines
Log Message:
re-enable qbert logging my hacking it directly into chat.ext

File Contents

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