diff options
author | Andrey Nazarov <skuller@skuller.net> | 2008-01-04 18:19:19 +0000 |
---|---|---|
committer | Andrey Nazarov <skuller@skuller.net> | 2008-01-04 18:19:19 +0000 |
commit | 348024fbd44d37f073e7b2d4a19a7b555c3dd684 (patch) | |
tree | 18e475eec42589304ebc4cf863242c1751bb4ddb | |
parent | 87573a3f6ae7400f597b74318bdaf161edfa225c (diff) |
Added `sv_mvd_encoding' variable, defaults to gzip content encoding.
Allow unicast configstrings in CS_GENERAL range only.
When parsing mvd_configstring, reset corresponding unicast configstrings.
Removed `Status page of' prefix.
Highlight MVD stream links only when `sv_mvd_enable' is non-zero.
-rw-r--r-- | source/mvd_client.c | 66 | ||||
-rw-r--r-- | source/mvd_parse.c | 40 | ||||
-rw-r--r-- | source/sv_http.c | 6 | ||||
-rw-r--r-- | source/sv_local.h | 1 | ||||
-rw-r--r-- | source/sv_mvd.c | 63 |
5 files changed, 117 insertions, 59 deletions
diff --git a/source/mvd_client.c b/source/mvd_client.c index f167160..40a1d31 100644 --- a/source/mvd_client.c +++ b/source/mvd_client.c @@ -303,7 +303,7 @@ void MVD_SendGamestate( tcpClient_t *client ) { void MVD_GetStatus( void ) { char buffer[MAX_STRING_CHARS]; mvd_t *mvd; - int count; + int count, len; SV_HttpPrintf( "HTTP/1.0 200 OK\r\n" ); @@ -318,17 +318,21 @@ void MVD_GetStatus( void ) { "\r\n" ); count = SV_CountClients(); - Q_EscapeMarkup( buffer, sv_hostname->string, sizeof( buffer ) ); - SV_HttpHeader( va( "%s - %d/%d", buffer, count, sv_maxclients->integer ) ); - SV_HttpPrintf( "<h1>Status page of %s</h1>" - "<p>This server has ", buffer ); + len = Q_EscapeMarkup( buffer, sv_hostname->string, sizeof( buffer ) ); + Com_sprintf( buffer + len, sizeof( buffer ) - len, " - %d/%d", + count, sv_maxclients->integer - sv_reserved_slots->integer ); + + SV_HttpHeader( buffer ); + + buffer[len] = 0; + SV_HttpPrintf( "<h1>%s</h1><p>This server has ", buffer ); count = List_Count( &mvd_ready ); if( count ) { - SV_HttpPrintf( "%d MVD stream%s available. ", + SV_HttpPrintf( "%d channel%s available. ", count, count == 1 ? "" : "s" ); } else { - SV_HttpPrintf( "no MVD streams available. " ); + SV_HttpPrintf( "no channels available. " ); } count = List_Count( &mvd_waitingRoom.udpClients ); @@ -345,23 +349,32 @@ void MVD_GetStatus( void ) { "<th>ID</th><th>Name</th><th>Map</th><th>Clients</th></tr>" ); LIST_FOR_EACH( mvd_t, mvd, &mvd_ready, ready ) { - SV_HttpPrintf( - "<tr><td><a href=\"http://%s/mvdstream/%d\">%d</a></td>", - http_host, mvd->id, mvd->id ); + SV_HttpPrintf( "<tr><td>" ); + if( sv_mvd_enable->integer ) { + SV_HttpPrintf( "<a href=\"http://%s/mvdstream/%d\">%d</a>", + http_host, mvd->id, mvd->id ); + } else { + SV_HttpPrintf( "%d", mvd->id ); + } + SV_HttpPrintf( "</td><td>" ); Q_EscapeMarkup( buffer, mvd->name, sizeof( buffer ) ); - SV_HttpPrintf( - "<td><a href=\"http://%s/mvdstream/%d\">%s</a></td>", - http_host, mvd->id, buffer ); + if( sv_mvd_enable->integer ) { + SV_HttpPrintf( "<a href=\"http://%s/mvdstream/%d\">%s</a>", + http_host, mvd->id, buffer ); + } else { + SV_HttpPrintf( "%s", buffer ); + } Q_EscapeMarkup( buffer, mvd->mapname, sizeof( buffer ) ); count = List_Count( &mvd->udpClients ); - SV_HttpPrintf( "<td>%s</td><td>%d</td></tr>", buffer, count ); + SV_HttpPrintf( "</td><td>%s</td><td>%d</td></tr>", buffer, count ); } - SV_HttpPrintf( "</table><br>" ); + SV_HttpPrintf( "</table>" ); } - SV_HttpPrintf( "<a href=\"quake2://%s\">Join this server</a>", http_host ); + SV_HttpPrintf( + "<p><a href=\"quake2://%s\">Join this server</a></p>", http_host ); SV_HttpFooter(); @@ -406,17 +419,14 @@ static mvd_t *MVD_SetStream( const char *uri ) { void MVD_GetStream( const char *uri ) { mvd_t *mvd; - uint32 magic; mvd = MVD_SetStream( uri ); if( !mvd ) { return; } - SV_HttpPrintf( "HTTP/1.0 200 OK\r\n" ); - if( http_client->method == HTTP_METHOD_HEAD ) { - SV_HttpPrintf( "\r\n" ); + SV_HttpPrintf( "HTTP/1.0 200 OK\r\n\r\n" ); SV_HttpDrop( http_client, "200 OK " ); return; } @@ -424,25 +434,11 @@ void MVD_GetStream( const char *uri ) { List_Append( &mvd->tcpClients, &http_client->mvdEntry ); http_client->mvd = mvd; - SV_HttpPrintf( -#if USE_ZLIB - "Content-Encoding: deflate\r\n" -#endif - "Content-Type: application/octet-stream\r\n" - "Content-Disposition: attachment; filename=\"stream.mvd2\"\r\n" - "\r\n" ); - -#if USE_ZLIB - deflateInit( &http_client->z, Z_DEFAULT_COMPRESSION ); -#endif - - magic = MVD_MAGIC; - SV_HttpWrite( http_client, &magic, 4 ); + SV_MvdInitStream(); MVD_SendGamestate( http_client ); } - void MVD_ChangeLevel( mvd_t *mvd ) { udpClient_t *u; diff --git a/source/mvd_parse.c b/source/mvd_parse.c index b0c3f95..819211e 100644 --- a/source/mvd_parse.c +++ b/source/mvd_parse.c @@ -353,8 +353,12 @@ static void MVD_UnicastString( mvd_t *mvd, qboolean reliable, mvd_player_t *play if( index < 0 || index >= MAX_CONFIGSTRINGS ) { MVD_Destroyf( mvd, "%s: bad index: %d", __func__, index ); } + if( index < CS_GENERAL ) { + Com_DPrintf( "%s: common configstring: %d\n", __func__, index ); + return; + } if( length >= MAX_QPATH ) { - Com_WPrintf( "%s: oversize configstring: %d\n", __func__, index ); + Com_DPrintf( "%s: oversize configstring: %d\n", __func__, index ); return; } @@ -440,7 +444,7 @@ static void MVD_ParseUnicast( mvd_t *mvd, mvd_ops_t op, int extrabits ) { mvd_player_t *player; byte *data; qboolean reliable; - int c; + int cmd; length = MSG_ReadByte(); length |= extrabits << 8; @@ -460,8 +464,11 @@ static void MVD_ParseUnicast( mvd_t *mvd, mvd_ops_t op, int extrabits ) { reliable = op == mvd_unicast_r ? qtrue : qfalse; while( msg_read.readcount < last ) { - c = MSG_ReadByte(); - switch( c ) { + cmd = MSG_ReadByte(); + if( mvd_shownet->integer > 1 ) { + MSG_ShowSVC( cmd ); + } + switch( cmd ) { case svc_layout: MVD_UnicastLayout( mvd, reliable, player ); break; @@ -475,6 +482,9 @@ static void MVD_ParseUnicast( mvd_t *mvd, mvd_ops_t op, int extrabits ) { MVD_UnicastStuff( mvd, reliable, player ); break; default: + if( mvd_shownet->integer > 1 ) { + Com_Printf( "%d:SKIPPING UNICAST\n", msg_read.readcount - 1 ); + } // send remaining data and return data = msg_read.data + msg_read.readcount - 1; length = last - msg_read.readcount + 1; @@ -484,6 +494,10 @@ static void MVD_ParseUnicast( mvd_t *mvd, mvd_ops_t op, int extrabits ) { } } + if( mvd_shownet->integer > 1 ) { + Com_Printf( "%d:END OF UNICAST\n", msg_read.readcount - 1 ); + } + if( msg_read.readcount > last ) { MVD_Destroyf( mvd, "%s: read past end of unicast", __func__ ); } @@ -617,6 +631,8 @@ static void MVD_ParseConfigstring( mvd_t *mvd ) { char *string, *p; udpClient_t *client; mvd_player_t *player; + mvd_cs_t *cs, **pcs; + int i; index = MSG_ReadShort(); @@ -635,12 +651,28 @@ static void MVD_ParseConfigstring( mvd_t *mvd ) { } if( index >= CS_PLAYERSKINS && index < CS_PLAYERSKINS + mvd->maxclients ) { + // update player name player = &mvd->players[ index - CS_PLAYERSKINS ]; Q_strncpyz( player->name, string, sizeof( player->name ) ); p = strchr( player->name, '\\' ); if( p ) { *p = 0; } + } else if( index >= CS_GENERAL ) { + // reset unicast versions of this string + for( i = 0; i < mvd->maxclients; i++ ) { + player = &mvd->players[i]; + pcs = &player->configstrings; + for( cs = player->configstrings; cs; cs = cs->next ) { + if( cs->index == index ) { + Com_DPrintf( "%s: reset %d on %d\n", __func__, index, i ); + *pcs = cs->next; + Z_Free( cs ); + break; + } + pcs = &cs->next; + } + } } memcpy( mvd->configstrings[index], string, length + 1 ); diff --git a/source/sv_http.c b/source/sv_http.c index f09d3f9..6df031e 100644 --- a/source/sv_http.c +++ b/source/sv_http.c @@ -123,7 +123,7 @@ static void SV_GetStatus( void ) { SV_HttpHeader( buffer ); buffer[len] = 0; - SV_HttpPrintf( "<h1>Status page of %s</h1>", buffer ); + SV_HttpPrintf( "<h1>%s</h1>", buffer ); time( &clock ); @@ -343,11 +343,11 @@ void SV_HttpWrite( tcpClient_t *client, void *data, int length ) { } return; } -#else +#endif + if( !FIFO_TryWrite( fifo, data, length ) ) { SV_HttpDrop( client, "overflowed" ); } -#endif } void SV_HttpFinish( tcpClient_t *client ) { diff --git a/source/sv_local.h b/source/sv_local.h index 0994397..ad92847 100644 --- a/source/sv_local.h +++ b/source/sv_local.h @@ -481,6 +481,7 @@ void SV_MvdConfigstring( int index, const char *string ); void SV_MvdRecStop( void ); qboolean SV_MvdPlayerIsActive( edict_t *ent ); void SV_MvdClientNew( tcpClient_t *client ); +void SV_MvdInitStream( void ); void SV_MvdGetStream( const char *uri ); void SV_MvdRemoveDummy( void ); void SV_MvdSpawnDummy( void ); diff --git a/source/sv_mvd.c b/source/sv_mvd.c index 9aaebbe..0a04971 100644 --- a/source/sv_mvd.c +++ b/source/sv_mvd.c @@ -34,6 +34,9 @@ cvar_t *sv_mvd_max_size; cvar_t *sv_mvd_max_duration; cvar_t *sv_mvd_begincmd; cvar_t *sv_mvd_scorecmd; +#if USE_ZLIB +cvar_t *sv_mvd_encoding; +#endif static cmdbuf_t dummy_buffer; static char dummy_buffer_text[MAX_STRING_CHARS]; @@ -681,10 +684,47 @@ void SV_MvdClientNew( tcpClient_t *client ) { SZ_Clear( &msg_write ); } - -void SV_MvdGetStream( const char *uri ) { +void SV_MvdInitStream( void ) { uint32 magic; +#if USE_ZLIB + int bits; +#endif + + SV_HttpPrintf( "HTTP/1.0 200 OK\r\n" ); + +#if USE_ZLIB + switch( sv_mvd_encoding->integer ) { + case 1: + SV_HttpPrintf( "Content-Encoding: gzip\r\n" ); + bits = 31; + break; + case 2: + SV_HttpPrintf( "Content-Encoding: deflate\r\n" ); + bits = 15; + break; + default: + bits = 0; + break; + } +#endif + + SV_HttpPrintf( + "Content-Type: application/octet-stream\r\n" + "Content-Disposition: attachment; filename=\"stream.mvd2\"\r\n" + "\r\n" ); +#if USE_ZLIB + if( bits ) { + deflateInit2( &http_client->z, Z_DEFAULT_COMPRESSION, + Z_DEFLATED, bits, 8, Z_DEFAULT_STRATEGY ); + } +#endif + + magic = MVD_MAGIC; + SV_HttpWrite( http_client, &magic, 4 ); +} + +void SV_MvdGetStream( const char *uri ) { if( http_client->method == HTTP_METHOD_HEAD ) { SV_HttpPrintf( "HTTP/1.0 200 OK\r\n\r\n" ); SV_HttpDrop( http_client, "200 OK " ); @@ -699,21 +739,7 @@ void SV_MvdGetStream( const char *uri ) { List_Append( &svs.mvd.clients, &http_client->mvdEntry ); - SV_HttpPrintf( - "HTTP/1.0 200 OK\r\n" -#ifdef USE_ZLIB - "Content-Encoding: deflate\r\n" -#endif - "Content-Type: application/octet-stream\r\n" - "Content-Disposition: attachment; filename=\"stream.mvd2\"\r\n" - "\r\n" ); - -#if USE_ZLIB - deflateInit( &http_client->z, Z_DEFAULT_COMPRESSION ); -#endif - - magic = MVD_MAGIC; - SV_HttpWrite( http_client, &magic, 4 ); + SV_MvdInitStream(); SV_MvdClientNew( http_client ); } @@ -915,6 +941,9 @@ void SV_MvdRegister( void ) { "wait 50; putaway; wait 10; help;", 0 ); sv_mvd_scorecmd = Cvar_Get( "sv_mvd_scorecmd", "putaway; wait 10; help;", 0 ); +#if USE_ZLIB + sv_mvd_encoding = Cvar_Get( "sv_mvd_encoding", "1", 0 ); +#endif dummy_buffer.text = dummy_buffer_text; dummy_buffer.maxsize = sizeof( dummy_buffer_text ); |