# HG changeset patch # User Adam Kaminski # Date 1621192169 14400 # Sun May 16 15:09:29 2021 -0400 # Node ID 7a206ce67da78edeedf55036b83b03fcc9c1914b # Parent 18a10015f9f82e35cb02de77373ad81a42a9b9f8 Converted some old character arrays used to store player names into FString variables. diff -r 18a10015f9f8 -r 7a206ce67da7 src/botcommands.cpp --- a/src/botcommands.cpp Sun May 16 14:42:37 2021 -0400 +++ b/src/botcommands.cpp Sun May 16 15:09:29 2021 -0400 @@ -296,8 +296,8 @@ static bool g_bReturnBool = false; static char g_szReturnString[BOTCMD_RETURNSTRING_SIZE] = { 0 }; static char g_szLastChatString[256] = { 0 }; -static char g_szLastChatPlayer[MAXPLAYERNAME+1] = { 0 }; -static char g_szLastJoinedPlayer[MAXPLAYERNAME+1] = { 0 }; +static FString g_LastChatPlayer; +static FString g_LastJoinedPlayer; static FRandom g_RandomBotCmdSeed( "RandomBotCmdSeed" ); static FRandom g_RandomBotChatSeed( "RandomBotChatSeed" ); @@ -612,16 +612,14 @@ // void BOTCMD_SetLastChatPlayer( const char *pszString ) { - strncpy( g_szLastChatPlayer, pszString, MAXPLAYERNAME ); - g_szLastChatPlayer[MAXPLAYERNAME] = 0; + g_LastChatPlayer = pszString; } //***************************************************************************** // void BOTCMD_SetLastJoinedPlayer( const char *pszString ) { - strncpy( g_szLastJoinedPlayer, pszString, MAXPLAYERNAME ); - g_szLastJoinedPlayer[MAXPLAYERNAME] = 0; + g_LastJoinedPlayer = pszString; } //***************************************************************************** @@ -746,10 +744,10 @@ pszInString += strlen( "player_random" ); } - else if (( strnicmp( pszInString + 1, "player_lastchat", strlen( "player_lastchat" )) == 0 ) && ( g_szLastChatPlayer[0] != 0 )) + else if (( strnicmp( pszInString + 1, "player_lastchat", strlen( "player_lastchat" )) == 0 ) && ( g_LastChatPlayer.Len( ) > 0 )) { - sprintf( pszOutString, "%s", g_szLastChatPlayer ); - pszOutString += strlen( g_szLastChatPlayer ); + sprintf( pszOutString, "%s", g_LastChatPlayer.GetChars( )); + pszOutString += g_LastChatPlayer.Len( ); pszInString += strlen( "player_lastchat" ); } @@ -2270,8 +2268,8 @@ // static void botcmd_GetLastChatPlayer( CSkullBot *pBot ) { - if ( strlen( g_szLastChatPlayer ) < BOTCMD_RETURNSTRING_SIZE ) - sprintf( g_szReturnString, "%s", g_szLastChatPlayer ); + if ( g_LastChatPlayer.Len( ) < BOTCMD_RETURNSTRING_SIZE ) + sprintf( g_szReturnString, "%s", g_LastChatPlayer.GetChars( )); else g_szReturnString[0] = 0; } @@ -2518,8 +2516,8 @@ // static void botcmd_GetLastJoinedPlayer( CSkullBot *pBot ) { - if ( strlen( g_szLastJoinedPlayer ) < BOTCMD_RETURNSTRING_SIZE ) - sprintf( g_szReturnString, "%s", g_szLastJoinedPlayer ); + if ( g_LastJoinedPlayer.Len( ) < BOTCMD_RETURNSTRING_SIZE ) + sprintf( g_szReturnString, "%s", g_LastJoinedPlayer.GetChars( )); else g_szReturnString[0] = 0; } diff -r 18a10015f9f8 -r 7a206ce67da7 src/sv_main.cpp --- a/src/sv_main.cpp Sun May 16 14:42:37 2021 -0400 +++ b/src/sv_main.cpp Sun May 16 15:09:29 2021 -0400 @@ -1930,7 +1930,6 @@ { player_t *pPlayer; FString szSkin; - char szOldPlayerName[MAXPLAYERNAME+1]; ULONG ulUserInfoInstance; // [BB] We may only kick the player after completely parsing the current message, // otherwise we'll get network parsing errors. @@ -2005,10 +2004,10 @@ if ( name == NAME_Name ) { - sprintf( szOldPlayerName, "%s", pPlayer->userinfo.GetName() ); + FString oldPlayerName = pPlayer->userinfo.GetName(); if ( value.Len() > MAXPLAYERNAME ) - value.Truncate(MAXPLAYERNAME); + value.Truncate( MAXPLAYERNAME ); FString nameStringCopy = value; @@ -2053,20 +2052,17 @@ if ( g_aClients[g_lCurrentClient].State == CLS_SPAWNED ) { - char szPlayerNameNoColor[MAXPLAYERNAME+1]; - char szOldPlayerNameNoColor[MAXPLAYERNAME+1]; - - sprintf( szPlayerNameNoColor, "%s", pPlayer->userinfo.GetName() ); - sprintf( szOldPlayerNameNoColor, "%s", szOldPlayerName ); - - V_ColorizeString( szPlayerNameNoColor ); - V_ColorizeString( szOldPlayerNameNoColor ); - V_RemoveColorCodes( szPlayerNameNoColor ); - V_RemoveColorCodes( szOldPlayerNameNoColor ); - - if ( stricmp( szPlayerNameNoColor, szOldPlayerNameNoColor ) != 0 ) + FString playerNameNoColor = pPlayer->userinfo.GetName(); + FString oldPlayerNameNoColor = oldPlayerName.GetChars(); + + V_ColorizeString( playerNameNoColor ); + V_RemoveColorCodes( playerNameNoColor ); + V_ColorizeString( oldPlayerNameNoColor ); + V_RemoveColorCodes( oldPlayerNameNoColor ); + + if ( playerNameNoColor.CompareNoCase( oldPlayerNameNoColor ) != 0 ) { - SERVER_Printf( "%s is now known as %s\n", szOldPlayerName, pPlayer->userinfo.GetName() ); + SERVER_Printf( "%s is now known as %s\n", oldPlayerName.GetChars(), pPlayer->userinfo.GetName() ); // [RC] Update clients using the RCON utility. SERVER_RCON_UpdateInfo( SVRCU_PLAYERDATA ); @@ -2905,7 +2901,7 @@ Info.lPointCount = players[ulClient].lPointCount; Info.lWinCount = players[ulClient].ulWins; Info.ulTime = players[ulClient].ulTime; // [RC] Save time - sprintf( Info.szName, "%s", players[ulClient].userinfo.GetName() ); + Info.Name = players[ulClient].userinfo.GetName(); SERVER_SAVE_SaveInfo( &Info ); } @@ -2921,7 +2917,7 @@ pInfo->lFragCount = 0; pInfo->lPointCount = 0; pInfo->lWinCount = 0; - pInfo->szName[0] = 0; + pInfo->Name = ""; } } diff -r 18a10015f9f8 -r 7a206ce67da7 src/sv_save.cpp --- a/src/sv_save.cpp Sun May 16 14:42:37 2021 -0400 +++ b/src/sv_save.cpp Sun May 16 15:09:29 2021 -0400 @@ -77,17 +77,16 @@ PLAYERSAVEDINFO_t *SERVER_SAVE_GetSavedInfo( const char *pszPlayerName, NETADDRESS_s Address ) { ULONG ulIdx; - char szPlayerName[128]; + FString name = pszPlayerName; - sprintf( szPlayerName, "%s", pszPlayerName ); - V_RemoveColorCodes( szPlayerName ); + V_RemoveColorCodes( name ); for ( ulIdx = 0; ulIdx < MAXPLAYERS; ulIdx++ ) { if ( g_SavedPlayerInfo[ulIdx].bInitialized == false ) continue; - if (( stricmp( szPlayerName, g_SavedPlayerInfo[ulIdx].szName ) == 0 ) && + if (( g_SavedPlayerInfo[ulIdx].Name.CompareNoCase( name ) == 0 ) && Address.Compare( g_SavedPlayerInfo[ulIdx].Address )) { return ( &g_SavedPlayerInfo[ulIdx] ); @@ -110,7 +109,7 @@ g_SavedPlayerInfo[ulIdx].lFragCount = 0; g_SavedPlayerInfo[ulIdx].lPointCount = 0; g_SavedPlayerInfo[ulIdx].lWinCount = 0; - g_SavedPlayerInfo[ulIdx].szName[0] = 0; + g_SavedPlayerInfo[ulIdx].Name = ""; g_SavedPlayerInfo[ulIdx].ulTime = 0; } } @@ -120,17 +119,16 @@ void SERVER_SAVE_SaveInfo( PLAYERSAVEDINFO_t *pInfo ) { ULONG ulIdx; - char szPlayerName[128]; + FString name = pInfo->Name.GetChars(); - sprintf( szPlayerName, "%s", pInfo->szName ); - V_RemoveColorCodes( szPlayerName ); + V_RemoveColorCodes( name ); for ( ulIdx = 0; ulIdx < MAXPLAYERS; ulIdx++ ) { if ( g_SavedPlayerInfo[ulIdx].bInitialized ) { // If this slot matches the player we're trying to save, just update it. - if (( stricmp( szPlayerName, g_SavedPlayerInfo[ulIdx].szName ) == 0 ) && + if (( g_SavedPlayerInfo[ulIdx].Name.CompareNoCase( name ) == 0 ) && pInfo->Address.Compare( g_SavedPlayerInfo[ulIdx].Address )) { server_save_UpdateSlotWithInfo( ulIdx, pInfo ); @@ -159,7 +157,7 @@ g_SavedPlayerInfo[ulSlot].lPointCount = pInfo->lPointCount; g_SavedPlayerInfo[ulSlot].lWinCount = pInfo->lWinCount; g_SavedPlayerInfo[ulSlot].ulTime = pInfo->ulTime; - sprintf( g_SavedPlayerInfo[ulSlot].szName, "%s", pInfo->szName ); + g_SavedPlayerInfo[ulSlot].Name = pInfo->Name.GetChars(); - V_RemoveColorCodes( g_SavedPlayerInfo[ulSlot].szName ); + V_RemoveColorCodes( g_SavedPlayerInfo[ulSlot].Name ); } diff -r 18a10015f9f8 -r 7a206ce67da7 src/sv_save.h --- a/src/sv_save.h Sun May 16 14:42:37 2021 -0400 +++ b/src/sv_save.h Sun May 16 15:09:29 2021 -0400 @@ -59,7 +59,7 @@ struct PLAYERSAVEDINFO_t { // Name of the player. - char szName[MAXPLAYERNAME+1]; + FString Name; // Address of the player whose information is being saved. NETADDRESS_s Address; diff -r 18a10015f9f8 -r 7a206ce67da7 src/win32/serverconsole/serverconsole.cpp --- a/src/win32/serverconsole/serverconsole.cpp Sun May 16 14:42:37 2021 -0400 +++ b/src/win32/serverconsole/serverconsole.cpp Sun May 16 15:09:29 2021 -0400 @@ -1853,7 +1853,7 @@ void SERVERCONSOLE_ReListPlayers( void ) { LVITEM Item; - char szString[MAXPLAYERNAME+1]; + FString playerName; LONG lIndex; LONG lIdx; @@ -1876,9 +1876,9 @@ if ( playeringame[lIdx] == false ) continue; - sprintf( szString, "%s", players[lIdx].userinfo.GetName() ); - V_RemoveColorCodes( szString ); - Item.pszText = szString; + playerName = players[lIdx].userinfo.GetName(); + V_RemoveColorCodes( playerName ); + Item.pszText = const_cast( playerName.GetChars()); lIndex = SendDlgItemMessage( g_hDlg, IDC_PLAYERLIST, LVM_INSERTITEM, 0, (LPARAM)&Item ); if ( lIndex == -1 ) @@ -1896,7 +1896,7 @@ void SERVERCONSOLE_UpdatePlayerInfo( LONG lPlayer, ULONG ulUpdateFlags ) { LVITEM Item; - char szString[MAXPLAYERNAME+1]; + FString message; LONG lIndex = -1; LONG lIdx; @@ -1918,9 +1918,9 @@ if ( ulUpdateFlags & UDF_NAME ) { Item.iSubItem = COLUMN_NAME; - sprintf( szString, "%s", players[lPlayer].userinfo.GetName() ); - Item.pszText = szString; - V_RemoveColorCodes( szString ); + message = players[lPlayer].userinfo.GetName(); + V_RemoveColorCodes( message ); + Item.pszText = const_cast( message.GetChars()); SendDlgItemMessage( g_hDlg, IDC_PLAYERLIST, LVM_SETITEM, lIndex, (LPARAM)&Item ); } @@ -1929,25 +1929,25 @@ { Item.iSubItem = COLUMN_FRAGS; if ( PLAYER_IsTrueSpectator( &players[lPlayer] )) - sprintf( szString, "Spectating" ); + message = "Spectating"; else if (( GAMEMODE_GetCurrentFlags( ) & GMF_PLAYERSONTEAMS ) && ( !players[lPlayer].bOnTeam )) - sprintf( szString, "No team" ); + message = "No team"; else if ( lastmanstanding || teamlms ) { if ( players[lPlayer].health <=0 ) - sprintf( szString, "Dead" ); + message = "Dead"; else if ( lastmanstanding ) - sprintf( szString, "%ld", players[lPlayer].ulWins ); + message.Format( "%ld", players[lPlayer].ulWins ); else - sprintf( szString, "%d", players[lPlayer].fragcount ); + message.Format( "%d", players[lPlayer].fragcount ); } else if (( GAMEMODE_GetCurrentFlags( ) & GMF_PLAYERSEARNPOINTS ) || (( GAMEMODE_GetCurrentFlags( ) & GMF_PLAYERSEARNKILLS ) && ( zadmflags & ZADF_AWARD_DAMAGE_INSTEAD_KILLS ))) - sprintf( szString, "%ld", players[lPlayer].lPointCount ); + message.Format( "%ld", players[lPlayer].lPointCount ); else if ( GAMEMODE_GetCurrentFlags( ) & GMF_PLAYERSEARNFRAGS ) - sprintf( szString, "%d", players[lPlayer].fragcount ); + message.Format( "%d", players[lPlayer].fragcount ); else - sprintf( szString, "%d", players[lPlayer].killcount ); - Item.pszText = szString; + message.Format( "%d", players[lPlayer].killcount ); + Item.pszText = const_cast( message.GetChars()); SendDlgItemMessage( g_hDlg, IDC_PLAYERLIST, LVM_SETITEM, lIndex, (LPARAM)&Item ); } @@ -1955,10 +1955,10 @@ { Item.iSubItem = COLUMN_PING; if ( players[lPlayer].bIsBot ) - sprintf( szString, "Bot" ); + message = "Bot"; else - sprintf( szString, "%ld", players[lPlayer].ulPing ); - Item.pszText = szString; + message.Format( "%ld", players[lPlayer].ulPing ); + Item.pszText = const_cast( message.GetChars()); SendDlgItemMessage( g_hDlg, IDC_PLAYERLIST, LVM_SETITEM, lIndex, (LPARAM)&Item ); } @@ -1966,8 +1966,8 @@ if ( ulUpdateFlags & UDF_TIME ) { Item.iSubItem = COLUMN_TIME; - sprintf( szString, "%ld", ( players[lPlayer].ulTime / ( TICRATE * 60 ))); - Item.pszText = szString; + message.Format( "%ld", ( players[lPlayer].ulTime / ( TICRATE * 60 ))); + Item.pszText = const_cast( message.GetChars()); SendDlgItemMessage( g_hDlg, IDC_PLAYERLIST, LVM_SETITEM, lIndex, (LPARAM)&Item ); }