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