@@ -852,39 +852,53 @@ 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
+ int remaining ;
872
+ char temp [sizeof ( s )];
873
+ qboolean have_password = COM_CheckStringEmpty ( sv_password .string );
871
874
872
875
SV_GetPlayerCount ( & count , & bots );
873
876
874
877
// 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 );
878
+ Info_SetValueForKey ( s , "p" , va ( "%i" , PROTOCOL_VERSION ), sizeof ( s ));
879
+ Info_SetValueForKey ( s , "map" , sv .name , sizeof ( s ));
880
+ Info_SetValueForKey ( s , "dm" , svgame .globals -> deathmatch ? "1" : "0" , sizeof ( s ));
881
+ Info_SetValueForKey ( s , "team" , svgame .globals -> teamplay ? "1" : "0" , sizeof ( s ));
882
+ Info_SetValueForKey ( s , "coop" , svgame .globals -> coop ? "1" : "0" , sizeof ( s ));
883
+ Info_SetValueForKey ( s , "numcl" , va ( "%i" , count ), sizeof ( s ));
884
+ Info_SetValueForKey ( s , "maxcl" , va ( "%i" , svs .maxclients ), sizeof ( s ));
885
+ Info_SetValueForKey ( s , "gamedir" , GI -> gamefolder , sizeof ( s ));
886
+ Info_SetValueForKey ( s , "password" , have_password ? "1" : "0" , sizeof ( s ));
887
+
888
+ // write host last so we can try to cut off too long hostnames
889
+ // TODO: value size limit for infostrings
890
+ remaining = sizeof ( s ) - Q_strlen ( s ) - sizeof ( "\\host\\" ) - 1 ;
891
+ if ( remaining < 0 )
892
+ {
893
+ // should never happen?
894
+ Con_Printf ( S_ERROR "SV_Info: infostring overflow!\n" );
895
+ return ;
896
+ }
897
+ Q_strncpy ( temp , hostname .string , remaining );
898
+ Info_SetValueForKey ( s , "host" , temp , sizeof ( s ));
885
899
}
886
900
887
- Netchan_OutOfBandPrint ( NS_SERVER , from , "info\n%s" , string );
901
+ Netchan_OutOfBandPrint ( NS_SERVER , from , "info\n%s" , s );
888
902
}
889
903
890
904
/*
0 commit comments