1 |
#!/opt/bin/perl |
2 |
|
3 |
use common::sense; |
4 |
use AnyEvent::MP; |
5 |
|
6 |
initialise_node; |
7 |
|
8 |
my %clients; |
9 |
|
10 |
sub msg { |
11 |
print "relaying: $_[0]\n"; |
12 |
snd $_, $_[0] |
13 |
for values %clients; |
14 |
} |
15 |
|
16 |
sub client_connect { |
17 |
my ($client, $name) = @_; |
18 |
|
19 |
mon $client; |
20 |
mon $client, sub { |
21 |
delete $clients{$client}; |
22 |
msg "$name (quits, @_)"; |
23 |
}; |
24 |
|
25 |
$clients{$client} = $client; |
26 |
|
27 |
msg "$name (joins)"; |
28 |
|
29 |
rcv $SELF, sub { msg "$name: $_[0]" }; |
30 |
} |
31 |
|
32 |
warn "server ready.\n"; |
33 |
|
34 |
AE::cv->recv; |