@@ -852,39 +852,52 @@ The second parameter should be the current protocol version number.
852
852
*/
853
853
void SV_Info ( netadr_t from , int protocolVersion )
854
854
{
855
- char string [ MAX_INFO_STRING ];
855
+ char s [ 512 ];
856
856
857
857
// ignore in single player
858
858
if ( svs .maxclients == 1 || !svs .initialized )
859
859
return ;
860
860
861
- string [0 ] = '\0' ;
861
+ s [0 ] = '\0' ;
862
862
863
863
if ( protocolVersion != PROTOCOL_VERSION )
864
864
{
865
- Q_snprintf ( string , sizeof ( string ), "%s: wrong version\n" , hostname .string );
865
+ Q_snprintf ( s , sizeof ( s ), "%s: wrong version\n" , hostname .string );
866
866
}
867
867
else
868
868
{
869
- int i , count , bots ;
870
- qboolean havePassword = COM_CheckStringEmpty ( sv_password .string );
869
+ int count ;
870
+ int bots ;
871
+ char temp [sizeof ( s )];
872
+ qboolean have_password = COM_CheckStringEmpty ( sv_password .string );
871
873
872
874
SV_GetPlayerCount ( & count , & bots );
873
875
874
876
// a1ba: send protocol version to distinguish old engine and new
875
- Info_SetValueForKey ( string , "p" , va ( "%i" , PROTOCOL_VERSION ), MAX_INFO_STRING );
876
- Info_SetValueForKey ( string , "host" , hostname .string , MAX_INFO_STRING );
877
- Info_SetValueForKey ( string , "map" , sv .name , MAX_INFO_STRING );
878
- Info_SetValueForKey ( string , "dm" , va ( "%i" , (int )svgame .globals -> deathmatch ), MAX_INFO_STRING );
879
- Info_SetValueForKey ( string , "team" , va ( "%i" , (int )svgame .globals -> teamplay ), MAX_INFO_STRING );
880
- Info_SetValueForKey ( string , "coop" , va ( "%i" , (int )svgame .globals -> coop ), MAX_INFO_STRING );
881
- Info_SetValueForKey ( string , "numcl" , va ( "%i" , count ), MAX_INFO_STRING );
882
- Info_SetValueForKey ( string , "maxcl" , va ( "%i" , svs .maxclients ), MAX_INFO_STRING );
883
- Info_SetValueForKey ( string , "gamedir" , GI -> gamefolder , MAX_INFO_STRING );
884
- Info_SetValueForKey ( string , "password" , havePassword ? "1" : "0" , MAX_INFO_STRING );
877
+ Info_SetValueForKey ( s , "p" , va ( "%i" , PROTOCOL_VERSION ), sizeof ( s ));
878
+ Info_SetValueForKey ( s , "map" , sv .name , sizeof ( s ));
879
+ Info_SetValueForKey ( s , "dm" , svgame .globals -> deathmatch ? "1" : "0" , sizeof ( s ));
880
+ Info_SetValueForKey ( s , "team" , svgame .globals -> teamplay ? "1" : "0" , sizeof ( s ));
881
+ Info_SetValueForKey ( s , "coop" , svgame .globals -> coop ? "1" : "0" , sizeof ( s ));
882
+ Info_SetValueForKey ( s , "numcl" , va ( "%i" , count ), sizeof ( s ));
883
+ Info_SetValueForKey ( s , "maxcl" , va ( "%i" , svs .maxclients ), sizeof ( s ));
884
+ Info_SetValueForKey ( s , "gamedir" , GI -> gamefolder , sizeof ( s ));
885
+ Info_SetValueForKey ( s , "password" , have_password ? "1" : "0" , sizeof ( s ));
886
+
887
+ // write host last so we can try to cut off too long hostnames
888
+ // TODO: value size limit for infostrings
889
+ remaining = sizeof ( s ) - Q_strlen ( s ) - sizeof ( "\\host\\" ) - 1 ;
890
+ if ( remaining < 0 )
891
+ {
892
+ // should never happen?
893
+ Con_Printf ( S_ERROR "SV_Info: infostring overflow!\n" );
894
+ return ;
895
+ }
896
+ Q_strncpy ( temp , hostname .string , remaining );
897
+ Info_SetValueForKey ( s , "host" , temp , sizeof ( s ));
885
898
}
886
899
887
- Netchan_OutOfBandPrint ( NS_SERVER , from , "info\n%s" , string );
900
+ Netchan_OutOfBandPrint ( NS_SERVER , from , "info\n%s" , s );
888
901
}
889
902
890
903
/*
0 commit comments