diff options
author | Andrey Nazarov <skuller@skuller.net> | 2008-08-28 17:35:47 +0000 |
---|---|---|
committer | Andrey Nazarov <skuller@skuller.net> | 2008-08-28 17:35:47 +0000 |
commit | 8d466c8c99a82c9fa87d2c8a932413da1ac89e04 (patch) | |
tree | 9954623456ae4dc245daa98f57f913f9892a742b /source/sv_http.c | |
parent | 651dbdd53d61b75108ffdc95f3efdb285adc7170 (diff) |
Removed unimplemented `sv_mvd_wait' cvar.
Bind server TCP socket with SO_REUSEADDR option, close it properly on shutdown.
Implemented server console logging over HTTP, accessible at `/console' URI.
Added `sv_console_auth' cvar controlling access to server console.
Never allow server realtime go back.
Spectator chat on GTV is no longer audible.
Moved POV name on the very top of the screen.
Diffstat (limited to 'source/sv_http.c')
-rw-r--r-- | source/sv_http.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/source/sv_http.c b/source/sv_http.c index 0c2c5cf..37b0458 100644 --- a/source/sv_http.c +++ b/source/sv_http.c @@ -239,6 +239,75 @@ static void uri_mvdstream( const char *uri ) { } } +void SV_ConsoleOutput( const char *msg ) { + tcpClient_t *client; + char text[MAXPRINTMSG]; + char *p, *maxp; + size_t len; + int c; + + if( !svs.initialized ) { + return; + } + if( LIST_EMPTY( &svs.console_list ) ) { + return; + } + + p = text; + maxp = text + sizeof( text ) - 1; + while( *msg ) { + if( Q_IsColorString( msg ) ) { + msg += 2; + continue; + } + + if( p == maxp ) { + break; + } + + c = *msg++; + c &= 127; + + *p++ = c; + } + *p = 0; + + len = p - text; + + LIST_FOR_EACH( tcpClient_t, client, &svs.console_list, mvdEntry ) { + if( FIFO_Write( &client->stream.send, text, len ) != len ) { + SV_HttpDrop( client, "overflowed" ); + } + } +} + +static void uri_console( const char *uri ) { + char *auth = sv_console_auth->string; + char *cred = http_client->credentials; + + if( !auth[0] || !cred || strcmp( cred, auth ) ) { + strcpy( http_header, + "WWW-Authenticate: Basic realm=\"console\"\r\n" ); + SV_HttpReject( "401 Not Authorized", + "You are not authorized to access " + "console stream on this server." ); + return; + } + + if( http_client->method == HTTP_METHOD_HEAD ) { + SV_HttpPrintf( "HTTP/1.0 200 OK\r\n\r\n" ); + SV_HttpDrop( http_client, "200 OK " ); + return; + } + + SV_HttpPrintf( + "HTTP/1.0 200 OK\r\n" + "Content-Type: text/plain\r\n" + "\r\n" ); + List_Append( &svs.console_list, &http_client->mvdEntry ); + http_client->state = cs_spawned; +} + #if 0 static void uri_root( const char *uri ) { SV_HttpPrintf( "HTTP/1.0 200 OK\r\n" ); @@ -270,6 +339,7 @@ static const uriEntry_t rootURIs[] = { { "", uri_status }, { "status", uri_status }, { "mvdstream", uri_mvdstream }, + { "console", uri_console }, { NULL } }; @@ -716,6 +786,10 @@ void SV_HttpRun( void ) { // run network stream ret = NET_Run( &client->stream ); if( ret == NET_AGAIN ) { + // don't timeout + if( client->state >= cs_connected && !FIFO_Usage( &client->stream.send ) ) { + client->lastmessage = svs.realtime; + } continue; } if( ret != NET_OK ) { |