1 |
root |
1.8 |
=head1 NAME |
2 |
|
|
|
3 |
|
|
Net::Knuddels - www.knuddels.de protocol implementation. |
4 |
|
|
|
5 |
|
|
=head1 SYNOPSIS |
6 |
|
|
|
7 |
|
|
use Net::Knuddels; |
8 |
|
|
|
9 |
|
|
=head1 DESCRIPTION |
10 |
|
|
|
11 |
|
|
RTSL. |
12 |
|
|
|
13 |
|
|
=cut |
14 |
|
|
|
15 |
root |
1.1 |
package Net::Knuddels; |
16 |
|
|
|
17 |
root |
1.3 |
use Net::Knuddels::Dictionary; |
18 |
|
|
|
19 |
root |
1.2 |
use strict; |
20 |
|
|
use utf8; |
21 |
|
|
|
22 |
root |
1.4 |
use Carp; |
23 |
|
|
use Math::BigInt; |
24 |
|
|
|
25 |
root |
1.14 |
sub _to32($) { |
26 |
|
|
unpack "l", pack "L", (new Math::BigInt $_[0]) & 0xffffffff |
27 |
|
|
} |
28 |
|
|
|
29 |
root |
1.4 |
sub hash_pw($$) { |
30 |
|
|
my ($challenge, $pw) = @_; |
31 |
|
|
|
32 |
|
|
my $l1 = length $pw; |
33 |
|
|
my $l2 = length $challenge; |
34 |
|
|
|
35 |
|
|
my $k = chr ($l1 ^ ($l2 << 4)); |
36 |
|
|
|
37 |
|
|
my $l = $l1 < $l2 ? $l2 : $l1; |
38 |
|
|
|
39 |
|
|
my $xor = substr +($pw x 100) ^ ($challenge x 100) ^ ($k x 100), 0, $l; |
40 |
|
|
|
41 |
|
|
my ($i, $j); |
42 |
|
|
|
43 |
|
|
--$l; |
44 |
|
|
|
45 |
|
|
if ($l <= 17) { |
46 |
|
|
for (0 .. $l) { |
47 |
root |
1.14 |
$i = _to32 $i * 3 + ord substr $xor, $l - $_; |
48 |
|
|
$j = _to32 $j * 5 + ord substr $xor, $_; |
49 |
root |
1.4 |
} |
50 |
|
|
} else { |
51 |
|
|
for ($_ = $l; $_ >= 0; $_ -= int $_/19) { |
52 |
root |
1.14 |
$i = _to32 $i * 5 + ord substr $xor, $_; |
53 |
|
|
$j = _to32 $j * 3 + ord substr $xor, $l - $_; |
54 |
root |
1.4 |
} |
55 |
|
|
} |
56 |
|
|
|
57 |
|
|
$i ^= $j; |
58 |
root |
1.14 |
_to32 (($i & 0xffffff) ^ ($i >> 24)) |
59 |
root |
1.4 |
} |
60 |
|
|
|
61 |
root |
1.10 |
my $RE_dec = join "|", keys %$Net::Knuddels::Dictionary; |
62 |
|
|
|
63 |
|
|
sub decode { |
64 |
|
|
my $bin = unpack "b*", $_[0]; |
65 |
|
|
my $res = ""; |
66 |
|
|
|
67 |
|
|
while ($bin =~ /\G($RE_dec)/cog) { |
68 |
|
|
my $frag = $Net::Knuddels::Dictionary->{$1}; |
69 |
root |
1.14 |
$frag = chr unpack "v", pack "b*", $bin =~ /\G(.{16})/cg && $1 if $frag eq "\\\\\\"; |
70 |
root |
1.10 |
$res .= $frag; |
71 |
|
|
} |
72 |
|
|
$bin =~ /\G(.*[^0].*)$/ and die "Net::Knuddels::Receiver: undecodable message tail '$1'"; |
73 |
|
|
|
74 |
|
|
$res |
75 |
|
|
} |
76 |
|
|
|
77 |
root |
1.9 |
my %encode = reverse %$Net::Knuddels::Dictionary; |
78 |
|
|
|
79 |
root |
1.10 |
my $RE_enc = join "|", map quotemeta, sort { (length $b) <=> (length $a) } keys %encode; |
80 |
root |
1.9 |
|
81 |
root |
1.10 |
sub encode($) { |
82 |
root |
1.9 |
my ($msg) = @_; |
83 |
|
|
|
84 |
|
|
my $data = ""; |
85 |
|
|
|
86 |
|
|
while () { |
87 |
|
|
$data .= $encode{$1} while $msg =~ /\G($RE_enc)/cog; |
88 |
|
|
|
89 |
|
|
$msg =~ /\G./csog |
90 |
|
|
or last; |
91 |
|
|
|
92 |
|
|
$data .= $encode{"\\\\\\"} . unpack "b*", pack "v", ord $1; |
93 |
|
|
} |
94 |
|
|
|
95 |
|
|
pack "b*", $data |
96 |
|
|
} |
97 |
|
|
|
98 |
root |
1.5 |
=head2 CLASS Net::Knuddels::Protocol |
99 |
|
|
|
100 |
|
|
You B<must> call the C<destroy> method of this class when you no longer |
101 |
|
|
use it, as circular references will keep the object alive otherwise. |
102 |
|
|
|
103 |
root |
1.6 |
=over 4 |
104 |
|
|
|
105 |
root |
1.8 |
=cut |
106 |
|
|
|
107 |
|
|
package Net::Knuddels::Protocol; |
108 |
|
|
|
109 |
root |
1.6 |
=item new |
110 |
|
|
|
111 |
|
|
Create a new C<Net::Knuddels::Protocol> object. |
112 |
|
|
|
113 |
root |
1.5 |
=cut |
114 |
root |
1.2 |
|
115 |
|
|
sub new { |
116 |
|
|
my $class = shift; |
117 |
|
|
|
118 |
root |
1.4 |
my %data; |
119 |
|
|
|
120 |
|
|
my $self = bless { |
121 |
|
|
@_ |
122 |
|
|
}, $class; |
123 |
|
|
|
124 |
|
|
$self; |
125 |
root |
1.2 |
} |
126 |
|
|
|
127 |
root |
1.6 |
=item $protocol->feed_data ($octets) |
128 |
|
|
|
129 |
|
|
Feed raw protocol data into the decoder. |
130 |
|
|
|
131 |
|
|
=cut |
132 |
|
|
|
133 |
root |
1.2 |
sub feed_data($$) { |
134 |
|
|
my ($self, $data) = @_; |
135 |
|
|
|
136 |
|
|
# split data stream into packets |
137 |
|
|
|
138 |
|
|
$data = "$self->{rbuf}$data"; |
139 |
|
|
|
140 |
|
|
while () { |
141 |
|
|
1 <= length $data or last; |
142 |
|
|
my $len = ord substr $data, 0, 1; |
143 |
|
|
|
144 |
|
|
my $skip; |
145 |
|
|
if ($len & 0x80) { |
146 |
|
|
my $tail = (($len >> 5) & 3) - 1; |
147 |
|
|
$len = ($len & 0x1f) + 1; |
148 |
|
|
|
149 |
|
|
$tail < length $data or last; |
150 |
|
|
$len += (ord substr $data, $_ + 1, 1) << ($_ * 8 + 5) |
151 |
|
|
for 0 .. $tail; |
152 |
|
|
|
153 |
|
|
$skip = 2 + $tail; |
154 |
|
|
} else { |
155 |
|
|
$skip = 1; |
156 |
|
|
$len++; |
157 |
|
|
} |
158 |
|
|
|
159 |
|
|
$len + $skip <= length $data or last; |
160 |
|
|
substr $data, 0, $skip, ""; |
161 |
|
|
my $msg = substr $data, 0, $len, ""; |
162 |
|
|
|
163 |
|
|
$self->feed_msg ($msg); |
164 |
|
|
} |
165 |
|
|
|
166 |
|
|
$self->{rbuf} = $data; |
167 |
|
|
} |
168 |
|
|
|
169 |
|
|
sub feed_msg($$) { |
170 |
|
|
my ($self, $msg) = @_; |
171 |
root |
1.1 |
|
172 |
root |
1.10 |
$self->feed_event (split /\0/, Net::Knuddels::decode $msg); |
173 |
root |
1.1 |
} |
174 |
|
|
|
175 |
root |
1.2 |
sub feed_event($@) { |
176 |
root |
1.14 |
my ($self, @cmd) = @_; |
177 |
root |
1.1 |
|
178 |
root |
1.14 |
my $ev = $self->{cb}{ALL}; |
179 |
|
|
$_->(@cmd) for values %$ev; |
180 |
|
|
|
181 |
|
|
unless ($self->{cb}{$cmd[0]}) { |
182 |
|
|
my $ev = $self->{cb}{UNHANDLED}; |
183 |
|
|
$_->(@cmd) for values %$ev; |
184 |
root |
1.1 |
} |
185 |
root |
1.14 |
|
186 |
|
|
my $ev = $self->{cb}{shift @cmd}; |
187 |
|
|
$_->(@cmd) for values %$ev; |
188 |
root |
1.2 |
} |
189 |
root |
1.1 |
|
190 |
root |
1.11 |
=item $msg = $protocol->encode_msg (@strings) |
191 |
|
|
|
192 |
|
|
Join the strings with C<\0>, encode the result into a protocol packet and |
193 |
|
|
return it. |
194 |
|
|
|
195 |
|
|
=cut |
196 |
|
|
|
197 |
|
|
sub encode_msg($@) { |
198 |
|
|
my ($self, @args) = @_; |
199 |
|
|
my $msg = Net::Knuddels::encode join "\0", @args; |
200 |
root |
1.12 |
my $len = (length $msg) - 1; |
201 |
|
|
|
202 |
|
|
if ($len < 0x80) { |
203 |
|
|
(chr $len) . $msg |
204 |
|
|
} else { |
205 |
|
|
(chr 0x80 | 0x40 | ($len & 0x1f)) |
206 |
|
|
. (chr +($len >> 5) % 0xff) |
207 |
|
|
. (chr +($len >> 13) % 0xff) |
208 |
|
|
. $msg |
209 |
|
|
} |
210 |
root |
1.11 |
} |
211 |
|
|
|
212 |
root |
1.6 |
=item $protocol->register ($type => $callback) |
213 |
|
|
|
214 |
|
|
Register a callback for events of type C<$type>, which is either the name |
215 |
|
|
of a low-level event sent by the server (such as "k" for dialog box) or |
216 |
root |
1.16 |
the name of a generated event, such as C<login>. |
217 |
root |
1.6 |
|
218 |
|
|
=cut |
219 |
|
|
|
220 |
root |
1.2 |
sub register { |
221 |
|
|
my ($self, $type, $cb) = @_; |
222 |
root |
1.1 |
|
223 |
root |
1.2 |
$self->{cb}{$type}{$cb} = $cb; |
224 |
root |
1.1 |
} |
225 |
|
|
|
226 |
root |
1.8 |
=item $protocol->destroy |
227 |
|
|
|
228 |
root |
1.9 |
I<MUST> be called to destroy the object, otherwise it will leak (no automatic cleanup). |
229 |
root |
1.8 |
|
230 |
|
|
=cut |
231 |
|
|
|
232 |
root |
1.5 |
sub destroy { |
233 |
|
|
my ($self) = @_; |
234 |
|
|
|
235 |
|
|
delete $self->{cb}; |
236 |
|
|
} |
237 |
|
|
|
238 |
root |
1.6 |
=back |
239 |
|
|
|
240 |
root |
1.8 |
=head2 CLASS Net::Knuddels::Client |
241 |
|
|
|
242 |
root |
1.9 |
Implement a Knuddels client connection. |
243 |
|
|
|
244 |
root |
1.8 |
=over 4 |
245 |
|
|
|
246 |
|
|
=cut |
247 |
|
|
|
248 |
|
|
package Net::Knuddels::Client; |
249 |
|
|
|
250 |
root |
1.16 |
sub handle_room { |
251 |
|
|
my ($self, $room) = @_; |
252 |
|
|
|
253 |
|
|
if ($room eq "-") { |
254 |
|
|
if (defined $self->{only_room}) { |
255 |
|
|
return $self->{only_room}; |
256 |
|
|
} else { |
257 |
|
|
warn "Couldn't assign '-' room to a room!"; |
258 |
|
|
return '-'; |
259 |
|
|
} |
260 |
|
|
} else { |
261 |
|
|
return $room; |
262 |
|
|
} |
263 |
|
|
} |
264 |
|
|
|
265 |
elmex |
1.20 |
sub update_user_stats { |
266 |
|
|
my ($user) = @_; |
267 |
root |
1.16 |
|
268 |
|
|
if ($user->{name} =~ s/\cJ(\d+)$//) { |
269 |
|
|
$user->{age} = $1 |
270 |
|
|
} |
271 |
|
|
|
272 |
|
|
if ($user->{picture} =~ m/\bmale/) { |
273 |
|
|
$user->{gender} = 'm'; |
274 |
elmex |
1.20 |
|
275 |
root |
1.16 |
} elsif ($user->{picture} =~ m/female/) { |
276 |
|
|
$user->{gender} = 'f'; |
277 |
|
|
} |
278 |
root |
1.19 |
|
279 |
root |
1.16 |
return $user; |
280 |
|
|
} |
281 |
|
|
|
282 |
elmex |
1.18 |
sub clean_windef { |
283 |
|
|
my ($self, $windef) = @_; |
284 |
|
|
|
285 |
|
|
my $wd = {}; |
286 |
|
|
|
287 |
|
|
if ($windef =~ s/^(.*?)\365//) { |
288 |
|
|
$wd->{title} = $1; |
289 |
|
|
} |
290 |
|
|
|
291 |
|
|
while ($windef =~ s/^([^\343])//) { |
292 |
|
|
if ($1 eq 's') { |
293 |
|
|
if ($windef =~ s/^(.*?)\365(.*?)\365//) { |
294 |
|
|
$wd->{cmd} = $1; |
295 |
|
|
$wd->{nickname} = $2; |
296 |
|
|
} |
297 |
|
|
} elsif ($1 eq 'w' or $1 eq 'p') { |
298 |
|
|
$windef =~ s/^..//; |
299 |
|
|
} elsif ($1 eq 'h' or $1 eq 'f') { |
300 |
|
|
$windef =~ s/^.//; |
301 |
|
|
} elsif ($1 eq 'r') { |
302 |
|
|
# ... resizeable |
303 |
|
|
} |
304 |
|
|
} |
305 |
|
|
|
306 |
|
|
return $wd; |
307 |
|
|
} |
308 |
|
|
|
309 |
root |
1.9 |
=item new Net::Knuddels::Client [IO::Socket::new arguments] |
310 |
|
|
|
311 |
|
|
Create a new client connection. |
312 |
|
|
|
313 |
|
|
=cut |
314 |
|
|
|
315 |
|
|
use IO::Socket::INET; |
316 |
|
|
|
317 |
|
|
sub new { |
318 |
|
|
my ($class, @arg) = @_; |
319 |
|
|
|
320 |
|
|
my $fh = new IO::Socket::INET @arg |
321 |
|
|
or Carp::croak "Net::Knuddels::Client::new: $!"; |
322 |
|
|
|
323 |
|
|
my $self = bless { |
324 |
|
|
fh => $fh, |
325 |
|
|
proto => (new Net::Knuddels::Protocol), |
326 |
|
|
}, $class; |
327 |
|
|
|
328 |
|
|
syswrite $fh, "\0"; |
329 |
|
|
|
330 |
root |
1.16 |
$self->register ("(" => sub { |
331 |
|
|
$self->{login_challenge} = $_[0]; |
332 |
|
|
$self->{login_room} = $_[1]; |
333 |
|
|
$self->{proto}->feed_event ("login"); |
334 |
|
|
}); |
335 |
elmex |
1.21 |
$self->register (t => sub { |
336 |
|
|
my $src = $_[0]; |
337 |
|
|
if ($src eq '-') { |
338 |
|
|
$_[2] = $self->{knuddels_nick} . " " . $_[2]; |
339 |
|
|
} else { |
340 |
|
|
$_[2] = $src . " " . $_[2]; |
341 |
|
|
} |
342 |
|
|
$self->{proto}->feed_event (action_room => $self->handle_room ($_[1]), $_[2]); |
343 |
|
|
}); |
344 |
root |
1.16 |
$self->register (r => sub { |
345 |
elmex |
1.21 |
my $src = $_[0]; |
346 |
|
|
$src = $self->{knuddels_nick} if $src eq "-"; |
347 |
|
|
$self->{proto}->feed_event (msg_priv => $self->handle_room ($_[2]), $src, $_[1], $_[3]); |
348 |
root |
1.16 |
}); |
349 |
|
|
$self->register (e => sub { |
350 |
|
|
$self->{proto}->feed_event (msg_room => $self->handle_room ($_[1]), $_[0], $_[2]); |
351 |
|
|
}); |
352 |
|
|
$self->register (l => sub { |
353 |
|
|
my $room = $self->handle_room ($_[0]); |
354 |
|
|
return if $room eq "-"; # things that shouln't happen |
355 |
|
|
|
356 |
|
|
my $user = { |
357 |
|
|
name => $_[1], |
358 |
|
|
flag => $_[2], |
359 |
|
|
color => $_[3], |
360 |
|
|
picture => $_[4] |
361 |
|
|
}; |
362 |
|
|
|
363 |
elmex |
1.20 |
update_user_stats ($user); |
364 |
root |
1.16 |
|
365 |
|
|
my $rl = $self->{user_lists}->{lc $room}->{lc $user->{name}} = $user; |
366 |
|
|
|
367 |
|
|
$self->{proto}->feed_event (join_room => $room, $user); |
368 |
|
|
}); |
369 |
|
|
$self->register (w => sub { |
370 |
|
|
my $room = $self->handle_room ($_[1]); |
371 |
|
|
return if $room eq "-"; # things that shouln't happen |
372 |
|
|
|
373 |
|
|
my $username = $_[0]; |
374 |
|
|
|
375 |
|
|
my $u = delete $self->{user_lists}->{lc $room}->{lc $username}; |
376 |
|
|
|
377 |
|
|
if (not defined $u) { |
378 |
|
|
warn "User $username wasn't in room $room, trying to fix... but be careful!!!\n"; |
379 |
|
|
$u = { name => $username }; |
380 |
|
|
} |
381 |
|
|
|
382 |
|
|
$self->{proto}->feed_event (part_room => $room, $u); |
383 |
|
|
}); |
384 |
|
|
$self->register (a => sub { |
385 |
|
|
# the only_room stuff is from java-code, which has naughy semantics |
386 |
|
|
if (not defined $self->{only_room}) { |
387 |
|
|
$self->{only_room} = $_[0]; |
388 |
|
|
} else { |
389 |
|
|
$self->{only_room} = "-"; |
390 |
|
|
} |
391 |
|
|
|
392 |
|
|
$self->{my_nick} = $_[1]; # i'm really _not_ shure about this |
393 |
|
|
|
394 |
|
|
my $ri = $self->{room}->{lc $_[0]} = { |
395 |
|
|
picture => $_[7], |
396 |
|
|
}; |
397 |
|
|
|
398 |
|
|
$self->{proto}->feed_event (room_info => $_[0], $ri); |
399 |
|
|
}); |
400 |
|
|
$self->register (u => sub { |
401 |
|
|
my $room = shift; |
402 |
|
|
my $rl = $self->{user_lists}->{lc $room} = {}; |
403 |
|
|
my $cur_u = {}; |
404 |
|
|
|
405 |
|
|
while (@_) { |
406 |
|
|
$cur_u->{name} = shift; |
407 |
|
|
$cur_u->{flag} = shift; |
408 |
|
|
$cur_u->{color} = shift; |
409 |
|
|
|
410 |
|
|
my $i = 0; |
411 |
|
|
|
412 |
|
|
while ((my $nxt = shift) ne "-") { |
413 |
|
|
if ($i == 0) { |
414 |
|
|
$cur_u->{picture} = $nxt; |
415 |
|
|
} |
416 |
|
|
$i++; |
417 |
|
|
} |
418 |
|
|
|
419 |
elmex |
1.20 |
update_user_stats ($cur_u); |
420 |
root |
1.16 |
$rl->{lc $cur_u->{name}} = $cur_u; |
421 |
|
|
$cur_u = {}; |
422 |
|
|
} |
423 |
|
|
$self->{proto}->feed_event (user_list => $room, $rl); |
424 |
|
|
}); |
425 |
|
|
|
426 |
root |
1.9 |
$self |
427 |
|
|
} |
428 |
|
|
|
429 |
|
|
=item $client->fh |
430 |
|
|
|
431 |
|
|
Return the fh used for communications. You are responsible for calling C<< |
432 |
root |
1.13 |
$client->ready >> whenever the fh becomes ready for reading. |
433 |
root |
1.9 |
|
434 |
|
|
=cut |
435 |
|
|
|
436 |
|
|
sub fh { |
437 |
|
|
$_[0]->{fh} |
438 |
|
|
} |
439 |
|
|
|
440 |
root |
1.13 |
=item $client->ready |
441 |
|
|
|
442 |
|
|
To be called then the filehandle is ready for reading. Returns false if |
443 |
|
|
the server closed the connection, true otherwise. |
444 |
|
|
|
445 |
|
|
=cut |
446 |
|
|
|
447 |
|
|
sub ready { |
448 |
|
|
my ($self) = @_; |
449 |
|
|
|
450 |
|
|
sysread $self->{fh}, my $buf, 8192 |
451 |
|
|
or return; |
452 |
|
|
|
453 |
|
|
$self->{proto}->feed_data ($buf); |
454 |
|
|
|
455 |
|
|
1; |
456 |
|
|
} |
457 |
|
|
|
458 |
root |
1.9 |
=item $client->command ($type => @args) |
459 |
|
|
|
460 |
|
|
Send a message of type C<$type> and the given arguments to the server. |
461 |
|
|
|
462 |
|
|
=cut |
463 |
|
|
|
464 |
|
|
sub command { |
465 |
|
|
my ($self, $type, @args) = @_; |
466 |
|
|
|
467 |
root |
1.14 |
#use Dumpvalue; Dumpvalue->new (compactDump => 1, veryCompact => 1, quoteHighBit => 1, tick => '"')->dumpValue ([$type, @args]); |
468 |
root |
1.13 |
|
469 |
|
|
syswrite $self->{fh}, $self->{proto}->encode_msg ($type, @args); |
470 |
root |
1.9 |
} |
471 |
|
|
|
472 |
|
|
=item $client->login ($url, $unknown) |
473 |
|
|
|
474 |
|
|
Send a 't' message. The default for C<$url> is |
475 |
|
|
C<http://www.knuddels.de/applet.html?v=86a&c=0> and C<$unknown> is C<6>. |
476 |
|
|
|
477 |
|
|
=cut |
478 |
|
|
|
479 |
|
|
sub login { |
480 |
root |
1.13 |
my ($self, $url, $unknown) = @_; |
481 |
|
|
|
482 |
|
|
$self->command ("t", "V8.6a", $url || "http://www.knuddels.de/applet.html?v=86a&c=0", $unknown || 3); |
483 |
|
|
} |
484 |
|
|
|
485 |
|
|
=item $client->set_nick ($room, $nick, $password) |
486 |
|
|
|
487 |
|
|
Registers the nick with the given password. |
488 |
|
|
|
489 |
|
|
=cut |
490 |
|
|
|
491 |
|
|
sub set_nick { |
492 |
|
|
my ($self, $room, $nick, $password) = @_; |
493 |
|
|
|
494 |
root |
1.16 |
exists $self->{login_challenge} or Carp::croak "set_nick can only be called after a login event"; |
495 |
root |
1.13 |
|
496 |
elmex |
1.21 |
$self->{knuddels_nick} = $nick; |
497 |
root |
1.16 |
$self->command ("n", $room, $nick, Net::Knuddels::hash_pw $self->{login_challenge}, $password); |
498 |
root |
1.9 |
} |
499 |
|
|
|
500 |
elmex |
1.21 |
=item $client->send_room_msg ($nick, $room, $message) |
501 |
|
|
|
502 |
|
|
Sends a private C<$message> to C<$nick> over C<$room>. |
503 |
|
|
|
504 |
|
|
=cut |
505 |
|
|
sub send_room_msg { |
506 |
|
|
my ($self, $room, $message) = @_; |
507 |
|
|
|
508 |
|
|
print "SEND ROOM: $room : $message\n"; |
509 |
|
|
$self->command ("e", $room, $message); |
510 |
|
|
} |
511 |
|
|
|
512 |
|
|
|
513 |
|
|
=item $client->send_priv_msg ($nick, $room, $message) |
514 |
|
|
|
515 |
|
|
Sends a private C<$message> to C<$nick> over C<$room>. |
516 |
|
|
|
517 |
|
|
=cut |
518 |
|
|
sub send_priv_msg { |
519 |
|
|
my ($self, $nick, $room, $message) = @_; |
520 |
|
|
|
521 |
|
|
print "SEND ROOM: $room : /p $nick:$message\n"; |
522 |
|
|
$self->command ("e", $room, "/p $nick:$message"); |
523 |
|
|
} |
524 |
|
|
|
525 |
root |
1.9 |
=item $client->register ($type => $cb) |
526 |
|
|
|
527 |
root |
1.16 |
See L<Net::Knuddels::Protocol::register>. The following extra events will |
528 |
|
|
be generated by this class: |
529 |
root |
1.9 |
|
530 |
root |
1.16 |
login |
531 |
|
|
set_nick can only be called _after_ a login event has occured. |
532 |
|
|
|
533 |
|
|
msg_room => $room, $user, $msg |
534 |
|
|
produced when a public message is uttered :) |
535 |
|
|
|
536 |
|
|
msg_room => $room, $src, $dst, $msg |
537 |
|
|
personal message from $src to $dst |
538 |
|
|
|
539 |
|
|
user_list => $room, $list |
540 |
|
|
the userlist of a channel named $room, a elmement of the list (a user) |
541 |
|
|
looks like: |
542 |
|
|
{ |
543 |
|
|
name => <name>, |
544 |
|
|
flag => <some flag i don't know what it means>, |
545 |
|
|
color => like /\d+.\d+.\d+/, |
546 |
|
|
age => /\d+/, |
547 |
|
|
gender => /(f|m)/, |
548 |
|
|
picture => <the picture file to put behind the nick> |
549 |
|
|
} |
550 |
|
|
|
551 |
|
|
room_info => $room, $room_info |
552 |
|
|
some information about the $room: |
553 |
|
|
$room_info = |
554 |
|
|
{ |
555 |
|
|
picture => <some picturefile> |
556 |
|
|
} |
557 |
|
|
|
558 |
|
|
join_room => $room, $user |
559 |
|
|
join message of $user joined the room $room |
560 |
|
|
$user contains the user structure (see user_list). |
561 |
|
|
|
562 |
|
|
part_room => $room, $user |
563 |
|
|
part message of $user who left the room $room |
564 |
|
|
$user contains the user structure (see user_list). |
565 |
root |
1.9 |
=cut |
566 |
|
|
|
567 |
|
|
sub register { |
568 |
|
|
my ($self, $type, $cb) = @_; |
569 |
|
|
|
570 |
root |
1.13 |
$self->{proto}->register ($type, $cb); |
571 |
root |
1.9 |
} |
572 |
|
|
|
573 |
root |
1.8 |
=back |
574 |
|
|
|
575 |
|
|
=head1 AUTHOR |
576 |
|
|
|
577 |
|
|
Marc Lehmann <pcg@goof.com> |
578 |
|
|
http://home.schmorp.de/ |
579 |
|
|
|
580 |
root |
1.6 |
=cut |
581 |
|
|
|
582 |
root |
1.2 |
1; |
583 |
|
|
|