--- deliantra/server/ext/tcp_http.ext 2012/11/06 01:25:48 1.1 +++ deliantra/server/ext/tcp_http.ext 2012/11/06 23:55:54 1.5 @@ -1,8 +1,6 @@ #! perl # optional depends=tcp -# http server on base port - -use Coro::AnyEvent; +# http server sub send { my $self = $_[0]; @@ -60,9 +58,9 @@ cf::debug "HTTP GET: $self->{id} $uri"; - if ($uri =~ m%^/(M?)([0-9a-f]+)$%) { # faces - my $want_meta = $1; - my $idx = $cf::FACEHASH{pack "H*", $2}; + if ($uri =~ m%^/([0-9a-f]+)(M?)$%) { # faces + my $want_meta = $2; + my $idx = $cf::FACEHASH{pack "H*", $1}; $idx or do { $self->respond ("404 illegal face name"), next }; @@ -89,29 +87,32 @@ } } elsif ($uri eq "/debug") { # for debugging - my $body = ""; + my @body = ""; for my $type (6, 5, 4, 3, 2, 1, 0) { - $body .= "

$type

"; + push @body, "

$type

"; for (1 .. cf::face::faces_size - 1) { next if $type != cf::face::get_type $_; my $name = cf::face::get_name $_; my $id = unpack "H*", cf::face::get_chksum $_, 1; - $body .= "$_ $name ($id)"; - $body .= " (meta)" if $type & 1; - $body .= "
"; + push @body, "$_ $name ($id)"; + push @body, " (meta)" if $type & 1; + push @body, "
"; } } - $body .= ""; + push @body, ""; - $self->respond ("200 OK", $body, "Content-Type: text/html\015\012"); + $self->respond ("200 OK", (join "", @body), "content-type: text/html\015\012"); } elsif ($uri eq "/ws" && defined &ext::ws::server) { &ext::ws::server ($self->{id}, $self->{fh}, "$req\015\012\015\012$self->{rbuf}"); %$self = (); + } elsif ($uri eq "/") { + $self->respond ("302 hack", "", "location: http://cvs.schmorp.de/deliantra/html5client/client.html\015\012"); + } else { $self->respond ("404 not found"); } @@ -120,7 +121,7 @@ our $DETECTOR = ext::tcp::register http => 64, sub { # regex avoids conflict with websockets, which use /ws - m{^(?:(?i)GET|HEAD|OPTIONS) \ (?: [^/] | /[^w] | /w[^s] /ws[^\ ] ) }x + m{^(?i:GET|HEAD|OPTIONS) \ (?! (?i:http://[^/]+)? /ws \ ) }x }, sub { my $self = bless { id => $_[0],