ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/tcp.ext
(Generate patch)

Comparing deliantra/server/ext/tcp.ext (file contents):
Revision 1.20 by root, Fri Feb 3 03:01:45 2012 UTC vs.
Revision 1.23 by root, Mon Nov 5 23:23:04 2012 UTC

7use Socket; 7use Socket;
8use AnyEvent::Socket; 8use AnyEvent::Socket;
9 9
10CONF BIND_ADDRESSES = [[undef, 13327]]; 10CONF BIND_ADDRESSES = [[undef, 13327]];
11 11
12our $MAX_DETECT = 16; # how many bytes to raed to identify the protocol
13
12our @LISTENERS; 14our @LISTENERS;
15
16sub flash_policy_server {
17 my ($fh) = @_;
18
19 # socket policy file, just write answer and hope the kernel accepts it in one go
20 syswrite $fh, <<EOF . "\x00"
21<?xml version="1.0"?>
22<!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
23<cross-domain-policy>
24 <allow-access-from domain="*" to-ports="*"/>
25</cross-domain-policy>
26EOF
27}
13 28
14for (@$BIND_ADDRESSES) { 29for (@$BIND_ADDRESSES) {
15 my ($host, $port) = @$_; 30 my ($host, $port) = @$_;
16 cf::info "listening on ", (format_hostport $host, $port), "\n"; 31 cf::info "listening on ", (format_hostport $host, $port), "\n";
17 32
20 or return; 35 or return;
21 36
22 my $lhost = AnyEvent::Socket::format_address 37 my $lhost = AnyEvent::Socket::format_address
23 +(AnyEvent::Socket::unpack_sockaddr getsockname $fh)[1]; 38 +(AnyEvent::Socket::unpack_sockaddr getsockname $fh)[1];
24 39
25 cf::info "new connection from ", (format_hostport $host, $port), "\n" 40 my $id = format_hostport $host, $port;
41
42 cf::info "$id: new connection\n"
26 if $lhost ne $host; # do not log connections from the host, e.g. for watchdogs 43 if $lhost ne $host; # do not log connections from the host, e.g. for watchdogs
27 44
45 my $buf;
46 my $w; $w = AE::io $fh, 0, sub {
47 my $len = sysread $fh, $buf, 512, length $buf;
48
49 if ($len) {
50 if ($buf =~ /^..version /s) { # deliantra protocol
51 undef $w;
52
28 cf::client::create fileno $fh, $host; 53 my $ns = cf::client::create fileno $fh, $host;
54 $ns->inbuf_append ($buf);
55
56 } elsif ($buf =~ /^GET / && defined &ext::http::server) { # http or websocket
57 undef $w;
58
59 &ext::http::server ($id, $fh, $buf);
60
61 } elsif ($buf =~ /^<policy-file-request\/>\x00/) {
62 undef $w;
63
64 flash_policy_server $fh;
65
66 } elsif (length $buf >= $MAX_DETECT) { # unable to detect protocol
67 undef $w;
68
69 cf::info "$id: protocol detection error\n";
70 }
71 } else {
72 undef $w;
73
74 cf::info "$id: read error during protocol detection\n";
75 }
76 };
29 }; 77 };
30} 78}
31 79

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines