Revision: | 1.9 |
Committed: | Sat Sep 5 21:16:59 2009 UTC (14 years, 9 months ago) by root |
Branch: | MAIN |
CVS Tags: | rel-1_30, rel-1_1, rel-1_2, rel-1_28, rel-1_29, rel-1_24, rel-1_26, rel-1_27, rel-1_21, rel-1_22, rel-1_23 |
Changes since 1.8: | +1 -1 lines |
Log Message: | *** empty log message *** |
# | User | Rev | Content |
---|---|---|---|
1 | root | 1.2 | #!/opt/bin/perl |
2 | |||
3 | root | 1.7 | # Usage: ./chat_server |
4 | # implement a chat server using "traditional message passing" | ||
5 | |||
6 | root | 1.4 | use common::sense; |
7 | elmex | 1.1 | use AnyEvent::MP; |
8 | root | 1.6 | use AnyEvent::MP::Global; |
9 | elmex | 1.1 | |
10 | root | 1.8 | configure; |
11 | elmex | 1.3 | |
12 | root | 1.4 | my %clients; |
13 | root | 1.2 | |
14 | root | 1.4 | sub msg { |
15 | print "relaying: $_[0]\n"; | ||
16 | snd $_, $_[0] | ||
17 | for values %clients; | ||
18 | } | ||
19 | |||
20 | root | 1.7 | our $server = port; |
21 | |||
22 | rcv $server, join => sub { | ||
23 | my ($client, $nick) = @_; | ||
24 | |||
25 | $clients{$client} = $client; | ||
26 | root | 1.4 | |
27 | mon $client, sub { | ||
28 | delete $clients{$client}; | ||
29 | root | 1.7 | msg "$nick (quits, @_)"; |
30 | root | 1.4 | }; |
31 | root | 1.7 | msg "$nick (joins)"; |
32 | }; | ||
33 | elmex | 1.1 | |
34 | root | 1.7 | rcv $server, privmsg => sub { |
35 | my ($nick, $msg) = @_; | ||
36 | msg "$nick: $msg"; | ||
37 | }; | ||
38 | elmex | 1.3 | |
39 | root | 1.9 | grp_reg eg_chat_server => $server; |
40 | elmex | 1.1 | |
41 | root | 1.4 | warn "server ready.\n"; |
42 | elmex | 1.1 | |
43 | root | 1.4 | AE::cv->recv; |