Anonymous | Login | Signup for a new account | 2025-07-27 21:21 UTC | ![]() |
My View | View Issues | Change Log | Roadmap | Zandronum Issue Support Ranking | Rules | My Account |
View Issue Details [ Jump to Notes ] | [ Issue History ] [ Print ] | ||||||||
ID | Project | Category | View Status | Date Submitted | Last Update | ||||
0001820 | Zandronum | [All Projects] Suggestion | public | 2014-06-08 00:14 | 2020-05-05 21:45 | ||||
Reporter | Edward-san | ||||||||
Assigned To | |||||||||
Priority | normal | Severity | tweak | Reproducibility | always | ||||
Status | closed | Resolution | invalid | ||||||
Platform | OS | OS Version | |||||||
Product Version | 1.2 | ||||||||
Target Version | Fixed in Version | ||||||||
Summary | 0001820: [refactoring] Replace std:: classes with internal zdoom classes | ||||||||
Description | Nothing much to say, except for the fact that with these changes, some overheads from implementation-dependent part of std are gone for good. I hope this brings a lot of improvements in code size and in compile-time and runtime speed. I tested some of the changes, like the upnpnat and the outbound traffic measurements and found no problems so far. Also note that some changes are in win32 folder and are not accessible to me by compiling or anything, so tell me what should be changed. This patch is for the 'stable' branch, though I know it may not be committed there. In order to apply to 2.0, the 4th hunk of p_mobj.cpp part should be removed, because the changes involved two separated versions of AActor::SetState, which were merged in 2.0. | ||||||||
Additional Information | Essentially: std::string is replaced by FString; all the containers, like lists,vectors and sets, are replaced by TArray; std::map is replaced by TMap, with the side effect that the ordering of the keys is changed (TMap is a hash map, while std::map is an ordered map), so 'dumptrafficmeasure' ccmd may report the actors list in a different order; std::pair is only used with two strings, so I replaced it with a simple newly-created StringPair; removed some standard headers as consequence of these above. | ||||||||
Attached Files | ![]() diff -r 7d70511f0aa5 src/botcommands.cpp --- a/src/botcommands.cpp Sat Jun 07 20:38:33 2014 +0300 +++ b/src/botcommands.cpp Sun Jun 08 01:35:37 2014 +0200 @@ -75,6 +75,8 @@ #include "sv_main.h" #include "team.h" +#include <algorithm> + //***************************************************************************** // PROTOTYPES diff -r 7d70511f0aa5 src/callvote.cpp --- a/src/callvote.cpp Sat Jun 07 20:38:33 2014 +0300 +++ b/src/callvote.cpp Sun Jun 08 01:35:37 2014 +0200 @@ -65,7 +65,6 @@ #include "sv_main.h" #include "v_video.h" #include "maprotation.h" -#include <list> //***************************************************************************** // VARIABLES @@ -82,7 +81,7 @@ static ULONG g_ulPlayersWhoVotedYes[(MAXPLAYERS / 2) + 1]; static ULONG g_ulPlayersWhoVotedNo[(MAXPLAYERS / 2) + 1]; static NETADDRESS_s g_KickVoteVictimAddress; -static std::list<VOTE_s> g_PreviousVotes; +static TArray<VOTE_s> g_PreviousVotes; //***************************************************************************** // PROTOTYPES @@ -146,7 +145,7 @@ { if ( --g_ulVoteCompletedTicks == 0 ) { - g_PreviousVotes.back( ).bPassed = g_bVotePassed; + g_PreviousVotes[g_PreviousVotes.Size()-1].bPassed = g_bVotePassed; // If the vote passed, execute the command string. if (( g_bVotePassed ) && ( !g_bVoteCancelled ) && @@ -216,7 +215,7 @@ if ( VoteRecord.ulVoteType == VOTECMD_KICK ) VoteRecord.KickAddress = g_KickVoteVictimAddress; - g_PreviousVotes.push_back( VoteRecord ); + g_PreviousVotes.Push( VoteRecord ); } // Display the message in the console. @@ -367,7 +366,7 @@ if ( ulPlayer == g_ulVoteCaller && ( NETWORK_GetState( ) == NETSTATE_SERVER )) { // [BB] If a player canceled his own vote, don't prevent others from making this type of vote again. - g_PreviousVotes.back( ).ulVoteType = NUM_VOTECMDS; + g_PreviousVotes[g_PreviousVotes.Size()-1].ulVoteType = NUM_VOTECMDS; SERVER_Printf( PRINT_HIGH, "Vote caller cancelled the vote.\n" ); g_bVoteCancelled = true; @@ -653,46 +652,47 @@ time( &tNow ); // Remove old votes that no longer affect flooding. - while ( g_PreviousVotes.size( ) > 0 && (( tNow - g_PreviousVotes.front( ).tTimeCalled ) > VOTE_LONGEST_INTERVAL * MINUTE )) - g_PreviousVotes.pop_front( ); + while ( g_PreviousVotes.Size( ) > 0 && (( tNow - g_PreviousVotes[0].tTimeCalled ) > VOTE_LONGEST_INTERVAL * MINUTE )) + g_PreviousVotes.Delete(0); // [BB] If the server doesn't want to limit the number of votes, there is no check anything. if ( sv_limitnumvotes == false ) return true; // Run through the vote cache (backwards, from recent to old) and search for grounds on which to reject the vote. - for( std::list<VOTE_s>::reverse_iterator i = g_PreviousVotes.rbegin(); i != g_PreviousVotes.rend(); ++i ) + for( LONG i = (LONG)g_PreviousVotes.Size(); i >= 0; --i ) { + VOTE_s j = g_PreviousVotes[i]; // One *type* of vote per voter per ## minutes (excluding kick votes if they passed). - if ( !( i->ulVoteType == VOTECMD_KICK && i->bPassed ) && NETWORK_CompareAddress( i->Address, Address, true ) && ( ulVoteType == i->ulVoteType ) && (( tNow - i->tTimeCalled ) < VOTER_VOTETYPE_INTERVAL * MINUTE )) + if ( !( j.ulVoteType == VOTECMD_KICK && j.bPassed ) && NETWORK_CompareAddress( j.Address, Address, true ) && ( ulVoteType == j.ulVoteType ) && (( tNow - j.tTimeCalled ) < VOTER_VOTETYPE_INTERVAL * MINUTE )) { - int iMinutesLeft = static_cast<int>( 1 + ( i->tTimeCalled + VOTER_VOTETYPE_INTERVAL * MINUTE - tNow ) / MINUTE ); + int iMinutesLeft = static_cast<int>( 1 + ( j.tTimeCalled + VOTER_VOTETYPE_INTERVAL * MINUTE - tNow ) / MINUTE ); SERVER_PrintfPlayer( PRINT_HIGH, ulPlayer, "You must wait %d minute%s to call another %s vote.\n", iMinutesLeft, ( iMinutesLeft == 1 ? "" : "s" ), Command.GetChars() ); return false; } // One vote per voter per ## minutes. - if ( NETWORK_CompareAddress( i->Address, Address, true ) && (( tNow - i->tTimeCalled ) < VOTER_NEWVOTE_INTERVAL * MINUTE )) + if ( NETWORK_CompareAddress( j.Address, Address, true ) && (( tNow - j.tTimeCalled ) < VOTER_NEWVOTE_INTERVAL * MINUTE )) { - int iMinutesLeft = static_cast<int>( 1 + ( i->tTimeCalled + VOTER_NEWVOTE_INTERVAL * MINUTE - tNow ) / MINUTE ); + int iMinutesLeft = static_cast<int>( 1 + ( j.tTimeCalled + VOTER_NEWVOTE_INTERVAL * MINUTE - tNow ) / MINUTE ); SERVER_PrintfPlayer( PRINT_HIGH, ulPlayer, "You must wait %d minute%s to call another vote.\n", iMinutesLeft, ( iMinutesLeft == 1 ? "" : "s" )); return false; } // Specific votes ("map map30") that fail can't be re-proposed for ## minutes. - if (( ulVoteType == i->ulVoteType ) && ( !i->bPassed ) && (( tNow - i->tTimeCalled ) < VOTE_LITERALREVOTE_INTERVAL * MINUTE )) + if (( ulVoteType == j.ulVoteType ) && ( !j.bPassed ) && (( tNow - j.tTimeCalled ) < VOTE_LITERALREVOTE_INTERVAL * MINUTE )) { - int iMinutesLeft = static_cast<int>( 1 + ( i->tTimeCalled + VOTE_LITERALREVOTE_INTERVAL * MINUTE - tNow ) / MINUTE ); + int iMinutesLeft = static_cast<int>( 1 + ( j.tTimeCalled + VOTE_LITERALREVOTE_INTERVAL * MINUTE - tNow ) / MINUTE ); // Kickvotes (can't give the IP to clients!). - if (( i->ulVoteType == VOTECMD_KICK ) && ( !i->bPassed ) && NETWORK_CompareAddress( i->KickAddress, g_KickVoteVictimAddress, true )) + if (( j.ulVoteType == VOTECMD_KICK ) && ( !j.bPassed ) && NETWORK_CompareAddress( j.KickAddress, g_KickVoteVictimAddress, true )) { SERVER_PrintfPlayer( PRINT_HIGH, ulPlayer, "That specific player was recently on voted to be kicked, but the vote failed. You must wait %d minute%s to call it again.\n", iMinutesLeft, ( iMinutesLeft == 1 ? "" : "s" )); return false; } // Other votes. - if (( i->ulVoteType != VOTECMD_KICK ) && ( stricmp( i->fsParameter.GetChars(), Parameters.GetChars() ) == 0 )) + if (( j.ulVoteType != VOTECMD_KICK ) && ( stricmp( j.fsParameter.GetChars(), Parameters.GetChars() ) == 0 )) { SERVER_PrintfPlayer( PRINT_HIGH, ulPlayer, "That specific vote (\"%s %s\") was recently called, and failed. You must wait %d minute%s to call it again.\n", Command.GetChars(), Parameters.GetChars(), iMinutesLeft, ( iMinutesLeft == 1 ? "" : "s" )); return false; diff -r 7d70511f0aa5 src/cl_demo.cpp --- a/src/cl_demo.cpp Sat Jun 07 20:38:33 2014 +0300 +++ b/src/cl_demo.cpp Sun Jun 08 01:35:37 2014 +0200 @@ -170,13 +170,12 @@ // [Dusk] Write the amount of WADs and their names, incl. IWAD NETWORK_WriteByte( &g_ByteStream, CLD_DEMOWADS ); - std::list<std::pair<FString, FString> >* pwads = NETWORK_GetPWADList( ); - std::list<std::pair<FString, FString> >::iterator it; - ULONG ulWADCount = 1 + pwads->size( ); // 1 for IWAD + TArray<StringPair> *pwads = NETWORK_GetPWADList( ); + ULONG ulWADCount = 1 + pwads->Size( ); // 1 for IWAD NETWORK_WriteShort( &g_ByteStream, ulWADCount ); NETWORK_WriteString( &g_ByteStream, NETWORK_GetIWAD ( ) ); - for ( it = pwads->begin( ); it != pwads->end( ); ++it ) - NETWORK_WriteString( &g_ByteStream, it->first.GetChars( ) ); + for ( ULONG i = 0; i < pwads->Size(); ++i ) + NETWORK_WriteString( &g_ByteStream, (*pwads)[i].First.GetChars( ) ); // [Dusk] Write the network authentication string, we need it to // ensure we have the right WADs loaded. diff -r 7d70511f0aa5 src/cl_main.cpp --- a/src/cl_main.cpp Sat Jun 07 20:38:33 2014 +0300 +++ b/src/cl_main.cpp Sun Jun 08 01:35:37 2014 +0200 @@ -1464,24 +1464,25 @@ case NETWORK_ERRORCODE_AUTHENTICATIONFAILED: case NETWORK_ERRORCODE_PROTECTED_LUMP_AUTHENTICATIONFAILED: { - std::list<std::pair<FString, FString> > serverPWADs; + TArray<StringPair> serverPWADs; const int numServerPWADs = NETWORK_ReadByte( pByteStream ); for ( int i = 0; i < numServerPWADs; ++i ) { - std::pair<FString, FString> pwad; - pwad.first = NETWORK_ReadString( pByteStream ); - pwad.second = NETWORK_ReadString( pByteStream ); - serverPWADs.push_back ( pwad ); + StringPair pwad; + pwad.First = NETWORK_ReadString( pByteStream ); + pwad.Second = NETWORK_ReadString( pByteStream ); + serverPWADs.Push ( pwad ); } sprintf( szErrorString, "%s authentication failed.\nPlease make sure you are using the exact same WAD(s) as the server, and try again.", ( ulErrorCode == NETWORK_ERRORCODE_PROTECTED_LUMP_AUTHENTICATIONFAILED ) ? "Protected lump" : "Level" ); Printf ( "The server reports %d pwad(s):\n", numServerPWADs ); - for( std::list<std::pair<FString, FString> >::iterator i = serverPWADs.begin( ); i != serverPWADs.end( ); ++i ) - Printf( "PWAD: %s - %s\n", i->first.GetChars(), i->second.GetChars() ); - Printf ( "You have loaded %d pwad(s):\n", static_cast<int>( NETWORK_GetPWADList( )->size() )); - for( std::list<std::pair<FString, FString> >::iterator i = NETWORK_GetPWADList( )->begin( ); i != NETWORK_GetPWADList( )->end( ); ++i ) - Printf( "PWAD: %s - %s\n", i->first.GetChars(), i->second.GetChars() ); + for( ULONG i = 0; i < serverPWADs.Size(); ++i ) + Printf( "PWAD: %s - %s\n", serverPWADs[i].First.GetChars(), serverPWADs[i].Second.GetChars() ); + Printf ( "You have loaded %d pwad(s):\n", static_cast<int>( NETWORK_GetPWADList( )->Size() )); + TArray<StringPair> *clientPWADs = NETWORK_GetPWADList( ); + for( ULONG i = 0; i < clientPWADs->Size(); ++i ) + Printf( "PWAD: %s - %s\n", (*clientPWADs)[i].First.GetChars(), (*clientPWADs)[i].Second.GetChars() ); break; } diff -r 7d70511f0aa5 src/invasion.cpp --- a/src/invasion.cpp Sat Jun 07 20:38:33 2014 +0300 +++ b/src/invasion.cpp Sun Jun 08 01:35:37 2014 +0200 @@ -94,7 +94,7 @@ static INVASIONSTATE_e g_InvasionState; static ULONG g_ulNumBossMonsters = 0; static bool g_bIncreaseNumMonstersOnSpawn = true; -static std::vector<AActor*> g_MonsterCorpsesFromPreviousWave; +static TArray<AActor*> g_MonsterCorpsesFromPreviousWave; //***************************************************************************** // STRUCTURES @@ -800,7 +800,7 @@ if (( NETWORK_GetState( ) != NETSTATE_CLIENT ) && ( CLIENTDEMO_IsPlaying( ) == false )) { - g_MonsterCorpsesFromPreviousWave.clear(); + g_MonsterCorpsesFromPreviousWave.Clear(); } while (( pActor = ActorIterator.Next( ))) @@ -855,7 +855,7 @@ ( NETWORK_GetState( ) != NETSTATE_CLIENT ) && ( CLIENTDEMO_IsPlaying( ) == false )) { - g_MonsterCorpsesFromPreviousWave.push_back( pActor ); + g_MonsterCorpsesFromPreviousWave.Push( pActor ); continue; } } @@ -1390,12 +1390,11 @@ // [BB] Remove one monster corpse from the previous wave. void INVASION_RemoveMonsterCorpse( ) { + AActor *pCorpse; if (( NETWORK_GetState( ) != NETSTATE_CLIENT ) && ( CLIENTDEMO_IsPlaying( ) == false ) && - ( g_MonsterCorpsesFromPreviousWave.size() > 0 )) + ( g_MonsterCorpsesFromPreviousWave.Pop(pCorpse) == true )) { - AActor *pCorpse = g_MonsterCorpsesFromPreviousWave.back(); - g_MonsterCorpsesFromPreviousWave.pop_back(); // [BB] Check if the actor is still in its death state. // This won't be the case for example if it has been // raises by an Archvile in the mean time. @@ -1419,7 +1418,7 @@ { if ( NETWORK_GetState( ) != NETSTATE_CLIENT ) { - for( unsigned int i = 0; i < g_MonsterCorpsesFromPreviousWave.size(); i++ ) + for( unsigned int i = 0; i < g_MonsterCorpsesFromPreviousWave.Size(); ++i ) { if ( g_MonsterCorpsesFromPreviousWave[i] == pActor ) { diff -r 7d70511f0aa5 src/maprotation.cpp --- a/src/maprotation.cpp Sat Jun 07 20:38:33 2014 +0300 +++ b/src/maprotation.cpp Sun Jun 08 01:35:37 2014 +0200 @@ -48,7 +48,7 @@ //----------------------------------------------------------------------------- #include <string.h> -#include <vector> + #include "c_cvars.h" #include "c_dispatch.h" #include "g_level.h" @@ -59,7 +59,7 @@ //***************************************************************************** // VARIABLES -std::vector<MAPROTATIONENTRY_t> g_MapRotationEntries; +TArray<MAPROTATIONENTRY_t> g_MapRotationEntries; static ULONG g_ulCurMapInList; static ULONG g_ulNextMapInList; @@ -69,7 +69,7 @@ void MAPROTATION_Construct( void ) { - g_MapRotationEntries.clear( ); + g_MapRotationEntries.Clear( ); g_ulCurMapInList = g_ulNextMapInList = 0; } @@ -77,18 +77,18 @@ // ULONG MAPROTATION_GetNumEntries( void ) { - return g_MapRotationEntries.size( ); + return g_MapRotationEntries.Size( ); } //***************************************************************************** // static void MAPROTATION_CalcNextMap( void ) { - if ( g_MapRotationEntries.empty( )) + if ( g_MapRotationEntries.Size( ) == 0) return; // [BB] The random selection is only necessary if there is more than one map. - if ( sv_randommaprotation && ( g_MapRotationEntries.size( ) > 1 ) ) + if ( sv_randommaprotation && ( g_MapRotationEntries.Size( ) > 1 ) ) { // Mark the current map in the list as being used. g_MapRotationEntries[g_ulCurMapInList].bUsed = true; @@ -96,7 +96,7 @@ // If all the maps have been played, make them all available again. { bool bAllMapsPlayed = true; - for ( ULONG ulIdx = 0; ulIdx < g_MapRotationEntries.size( ); ulIdx++ ) + for ( ULONG ulIdx = 0; ulIdx < g_MapRotationEntries.Size( ); ulIdx++ ) { if ( !g_MapRotationEntries[ulIdx].bUsed ) { @@ -107,7 +107,7 @@ if ( bAllMapsPlayed ) { - for ( ULONG ulIdx = 0; ulIdx < g_MapRotationEntries.size( ); ulIdx++ ) + for ( ULONG ulIdx = 0; ulIdx < g_MapRotationEntries.Size( ); ulIdx++ ) g_MapRotationEntries[ulIdx].bUsed = false; } } @@ -115,7 +115,7 @@ // Select a new map. do { - g_ulNextMapInList = M_Random.Random( ) % g_MapRotationEntries.size( ); + g_ulNextMapInList = M_Random.Random( ) % g_MapRotationEntries.Size( ); } while (( g_MapRotationEntries[g_ulNextMapInList].bUsed == true ) || ( g_ulNextMapInList == g_ulCurMapInList )); @@ -139,7 +139,7 @@ level_info_t *MAPROTATION_GetNextMap( void ) { // [BB] If we don't want to use the rotation, there is no scheduled next map. - if (( sv_maprotation == false ) || ( g_MapRotationEntries.empty( ))) + if (( sv_maprotation == false ) || ( g_MapRotationEntries.Size( ) == 0)) return NULL; // [BB] See if we need to calculate the next map. @@ -153,7 +153,7 @@ // level_info_t *MAPROTATION_GetMap( ULONG ulIdx ) { - if ( ulIdx >= g_MapRotationEntries.size( )) + if ( ulIdx >= g_MapRotationEntries.Size( )) return ( NULL ); return ( g_MapRotationEntries[ulIdx].pMap ); @@ -163,7 +163,7 @@ // void MAPROTATION_SetPositionToMap( const char *pszMapName ) { - for ( ULONG ulIdx = 0; ulIdx < g_MapRotationEntries.size( ); ulIdx++ ) + for ( ULONG ulIdx = 0; ulIdx < g_MapRotationEntries.Size( ); ulIdx++ ) { if ( stricmp( g_MapRotationEntries[ulIdx].pMap->mapname, pszMapName ) == 0 ) { @@ -178,7 +178,7 @@ // bool MAPROTATION_IsMapInRotation( const char *pszMapName ) { - for ( ULONG ulIdx = 0; ulIdx < g_MapRotationEntries.size( ); ulIdx++ ) + for ( ULONG ulIdx = 0; ulIdx < g_MapRotationEntries.Size( ); ulIdx++ ) { if ( stricmp( g_MapRotationEntries[ulIdx].pMap->mapname, pszMapName ) == 0 ) return true; @@ -204,22 +204,16 @@ // [Dusk] iPosition of 0 implies the end of the maplist. if (iPosition == 0) { - // Add it to the queue. - g_MapRotationEntries.push_back( newEntry ); - - // [Dusk] note down the position for output - iPosition = g_MapRotationEntries.end() - g_MapRotationEntries.begin(); + // Add it to the queue and note down the position for output + iPosition = (int)g_MapRotationEntries.Push( newEntry )+1; } else { // [Dusk] insert the map into a certain position - std::vector<MAPROTATIONENTRY_t>::iterator itPosition = g_MapRotationEntries.begin() + iPosition - 1; - - // sanity check. - if (itPosition < g_MapRotationEntries.begin () || itPosition > g_MapRotationEntries.end ()) { + if (iPosition < 1 || iPosition-1 > (int)g_MapRotationEntries.Size()) { Printf ("Bad index specified!\n"); return; } - g_MapRotationEntries.insert( itPosition, 1, newEntry ); + g_MapRotationEntries.Insert( iPosition-1, newEntry ); } MAPROTATION_SetPositionToMap( level.mapname ); @@ -240,14 +234,13 @@ } // search the map in the map rotation and throw it to trash - level_info_t entry; - std::vector<MAPROTATIONENTRY_t>::iterator iterator; + level_info_t *entry; bool gotcha = false; - for (iterator = g_MapRotationEntries.begin (); iterator < g_MapRotationEntries.end (); iterator++) + for ( ULONG ulIdx = 0; ulIdx < g_MapRotationEntries.Size( ); ulIdx++ ) { - entry = *iterator->pMap; - if (!stricmp(entry.mapname, pszMapName)) { - g_MapRotationEntries.erase (iterator); + entry = g_MapRotationEntries[ulIdx].pMap; + if (!stricmp(entry->mapname, pszMapName)) { + g_MapRotationEntries.Delete(ulIdx); gotcha = true; break; } @@ -285,12 +278,12 @@ // CCMD( maplist ) { - if ( g_MapRotationEntries.size( ) == 0 ) + if ( g_MapRotationEntries.Size( ) == 0 ) Printf( "The map rotation list is empty.\n" ); else { Printf( "Map rotation list: \n" ); - for ( ULONG ulIdx = 0; ulIdx < g_MapRotationEntries.size( ); ulIdx++ ) + for ( ULONG ulIdx = 0; ulIdx < g_MapRotationEntries.Size( ); ulIdx++ ) Printf( "%lu. %s - %s\n", ulIdx + 1, g_MapRotationEntries[ulIdx].pMap->mapname, g_MapRotationEntries[ulIdx].pMap->LookupLevelName( ).GetChars( )); } } @@ -328,14 +321,14 @@ } unsigned int idx = static_cast<unsigned int> ( ( atoi(argv[1]) - 1 ) ); - if ( idx >= g_MapRotationEntries.size() ) + if ( idx >= g_MapRotationEntries.Size() ) { Printf ("No such map!\n"); return; } Printf ("%s (%s) has been removed from map rotation list.\n", g_MapRotationEntries[idx].pMap->mapname, g_MapRotationEntries[idx].pMap->LookupLevelName().GetChars()); - g_MapRotationEntries.erase (g_MapRotationEntries.begin()+idx); + g_MapRotationEntries.Delete (idx); } //***************************************************************************** diff -r 7d70511f0aa5 src/medal.cpp --- a/src/medal.cpp Sat Jun 07 20:38:33 2014 +0300 +++ b/src/medal.cpp Sun Jun 08 01:35:37 2014 +0200 @@ -654,7 +654,7 @@ } // [CK] Update the names as well - std::string medalStatusString = ""; + FString medalStatusString = ""; bool isConsolePlayer = (pPlayer - &players[consoleplayer] == 0); // The player has not earned any medals, so nothing was drawn. @@ -671,9 +671,9 @@ if ( bScale ) { screen->DrawText( SmallFont, CR_WHITE, - (LONG)(( ValWidth.Int / 2 ) - ( SmallFont->StringWidth( medalStatusString.c_str() ) / 2 )), + (LONG)(( ValWidth.Int / 2 ) - ( SmallFont->StringWidth( medalStatusString.GetChars() ) / 2 )), 26, - medalStatusString.c_str(), + medalStatusString.GetChars(), DTA_VirtualWidth, ValWidth.Int, DTA_VirtualHeight, ValHeight.Int, TAG_DONE ); @@ -681,9 +681,9 @@ else { screen->DrawText( SmallFont, CR_WHITE, - ( SCREENWIDTH / 2 ) - ( SmallFont->StringWidth( medalStatusString.c_str() ) / 2 ), + ( SCREENWIDTH / 2 ) - ( SmallFont->StringWidth( medalStatusString.GetChars() ) / 2 ), 26, - medalStatusString.c_str(), + medalStatusString.GetChars(), TAG_DONE ); } } @@ -700,9 +700,9 @@ if ( bScale ) { screen->DrawText( SmallFont, CR_WHITE, - (LONG)(( ValWidth.Int / 2 ) - ( SmallFont->StringWidth( medalStatusString.c_str() ) / 2 )), + (LONG)(( ValWidth.Int / 2 ) - ( SmallFont->StringWidth( medalStatusString.GetChars() ) / 2 )), 26, - medalStatusString.c_str(), + medalStatusString.GetChars(), DTA_VirtualWidth, ValWidth.Int, DTA_VirtualHeight, ValHeight.Int, TAG_DONE ); @@ -710,9 +710,9 @@ else { screen->DrawText( SmallFont, CR_WHITE, - ( SCREENWIDTH / 2 ) - ( SmallFont->StringWidth( medalStatusString.c_str() ) / 2 ), + ( SCREENWIDTH / 2 ) - ( SmallFont->StringWidth( medalStatusString.GetChars() ) / 2 ), 26, - medalStatusString.c_str(), + medalStatusString.GetChars(), TAG_DONE ); } } diff -r 7d70511f0aa5 src/network.cpp --- a/src/network.cpp Sat Jun 07 20:38:33 2014 +0300 +++ b/src/network.cpp Sun Jun 08 01:35:37 2014 +0200 @@ -66,7 +66,6 @@ #include <ctype.h> #include <math.h> -#include <list> #include "../GeoIP/GeoIP.h" #include "c_dispatch.h" @@ -104,7 +103,7 @@ //***************************************************************************** // VARIABLES -static std::list<std::pair<FString, FString> > g_PWADs; +static TArray<StringPair> g_PWADs; static FString g_IWAD; // [RC/BB] Which IWAD are we using? FString g_lumpsAuthenticationChecksum; @@ -282,31 +281,31 @@ SERVERCONSOLE_UpdateIP( g_LocalAddress ); // [BB] Initialize the checksum of the non-map lumps that need to be authenticated when connecting a new player. - std::vector<std::string> lumpsToAuthenticate; - std::vector<LumpAuthenticationMode> lumpsToAuthenticateMode; + TArray<FString> lumpsToAuthenticate; + TArray<LumpAuthenticationMode> lumpsToAuthenticateMode; - lumpsToAuthenticate.push_back( "COLORMAP" ); - lumpsToAuthenticateMode.push_back( LAST_LUMP ); - lumpsToAuthenticate.push_back( "PLAYPAL" ); - lumpsToAuthenticateMode.push_back( LAST_LUMP ); - lumpsToAuthenticate.push_back( "HTICDEFS" ); - lumpsToAuthenticateMode.push_back( ALL_LUMPS ); - lumpsToAuthenticate.push_back( "HEXNDEFS" ); - lumpsToAuthenticateMode.push_back( ALL_LUMPS ); - lumpsToAuthenticate.push_back( "STRFDEFS" ); - lumpsToAuthenticateMode.push_back( ALL_LUMPS ); - lumpsToAuthenticate.push_back( "DOOMDEFS" ); - lumpsToAuthenticateMode.push_back( ALL_LUMPS ); - lumpsToAuthenticate.push_back( "GLDEFS" ); - lumpsToAuthenticateMode.push_back( ALL_LUMPS ); - lumpsToAuthenticate.push_back( "DECORATE" ); - lumpsToAuthenticateMode.push_back( ALL_LUMPS ); - lumpsToAuthenticate.push_back( "LOADACS" ); - lumpsToAuthenticateMode.push_back( ALL_LUMPS ); - lumpsToAuthenticate.push_back( "DEHACKED" ); - lumpsToAuthenticateMode.push_back( ALL_LUMPS ); - lumpsToAuthenticate.push_back( "GAMEMODE" ); - lumpsToAuthenticateMode.push_back( ALL_LUMPS ); + lumpsToAuthenticate.Push( "COLORMAP" ); + lumpsToAuthenticateMode.Push( LAST_LUMP ); + lumpsToAuthenticate.Push( "PLAYPAL" ); + lumpsToAuthenticateMode.Push( LAST_LUMP ); + lumpsToAuthenticate.Push( "HTICDEFS" ); + lumpsToAuthenticateMode.Push( ALL_LUMPS ); + lumpsToAuthenticate.Push( "HEXNDEFS" ); + lumpsToAuthenticateMode.Push( ALL_LUMPS ); + lumpsToAuthenticate.Push( "STRFDEFS" ); + lumpsToAuthenticateMode.Push( ALL_LUMPS ); + lumpsToAuthenticate.Push( "DOOMDEFS" ); + lumpsToAuthenticateMode.Push( ALL_LUMPS ); + lumpsToAuthenticate.Push( "GLDEFS" ); + lumpsToAuthenticateMode.Push( ALL_LUMPS ); + lumpsToAuthenticate.Push( "DECORATE" ); + lumpsToAuthenticateMode.Push( ALL_LUMPS ); + lumpsToAuthenticate.Push( "LOADACS" ); + lumpsToAuthenticateMode.Push( ALL_LUMPS ); + lumpsToAuthenticate.Push( "DEHACKED" ); + lumpsToAuthenticateMode.Push( ALL_LUMPS ); + lumpsToAuthenticate.Push( "GAMEMODE" ); + lumpsToAuthenticateMode.Push( ALL_LUMPS ); FString checksum, longChecksum; bool noProtectedLumpsAutoloaded = true; @@ -336,21 +335,21 @@ longChecksum += checksum; } - for ( unsigned int i = 0; i < lumpsToAuthenticate.size(); i++ ) + for ( unsigned int i = 0; i < lumpsToAuthenticate.Size(); i++ ) { switch ( lumpsToAuthenticateMode[i] ){ case LAST_LUMP: int lump; - lump = Wads.CheckNumForName(lumpsToAuthenticate[i].c_str()); + lump = Wads.CheckNumForName(lumpsToAuthenticate[i].GetChars()); // [BB] Possibly we find the COLORMAP lump only in the colormaps name space. - if ( ( lump == -1 ) && ( lumpsToAuthenticate[i].compare ( "COLORMAP" ) == 0 ) ) + if ( ( lump == -1 ) && ( lumpsToAuthenticate[i].Compare ( "COLORMAP" ) == 0 ) ) lump = Wads.CheckNumForName("COLORMAP", ns_colormaps); if ( lump == -1 ) { - Printf ( PRINT_BOLD, "Warning: Can't find lump %s for authentication!\n", lumpsToAuthenticate[i].c_str() ); + Printf ( PRINT_BOLD, "Warning: Can't find lump %s for authentication!\n", lumpsToAuthenticate[i].GetChars() ); continue; } - if ( !network_GenerateLumpMD5HashAndWarnIfNeeded( lump, lumpsToAuthenticate[i].c_str(), checksum ) ) + if ( !network_GenerateLumpMD5HashAndWarnIfNeeded( lump, lumpsToAuthenticate[i].GetChars(), checksum ) ) noProtectedLumpsAutoloaded = false; // [BB] To make Doom and Freedoom network compatible, substitue the Freedoom PLAYPAL/COLORMAP hash @@ -361,9 +360,9 @@ // bb535e66cae508e3833a5d2de974267b Freedoom COLORMAP hash // 4804c7f34b5285c334a7913dd98fae16 Freedoom 0.8-beta1 PLAYPAL hash // 061a4c0f80aa8029f2c1bc12dc2e261e Freedoom 0.8-beta1 COLORMAP hash - if ( ( stricmp ( lumpsToAuthenticate[i].c_str(), "PLAYPAL" ) == 0 ) && ( ( stricmp ( checksum.GetChars(), "2e01ae6258f2a0fdad32125537efe1af" ) == 0 ) || ( stricmp ( checksum.GetChars(), "4804c7f34b5285c334a7913dd98fae16" ) == 0 ) ) ) + if ( ( stricmp ( lumpsToAuthenticate[i].GetChars(), "PLAYPAL" ) == 0 ) && ( ( stricmp ( checksum.GetChars(), "2e01ae6258f2a0fdad32125537efe1af" ) == 0 ) || ( stricmp ( checksum.GetChars(), "4804c7f34b5285c334a7913dd98fae16" ) == 0 ) ) ) checksum = "4804c7f34b5285c334a7913dd98fae16"; - else if ( ( stricmp ( lumpsToAuthenticate[i].c_str(), "COLORMAP" ) == 0 ) && ( ( stricmp ( checksum.GetChars(), "bb535e66cae508e3833a5d2de974267b" ) == 0 ) || ( stricmp ( checksum.GetChars(), "100c2c81afe87bb6dd1dbcadee9a7e58" ) == 0 ) ) ) + else if ( ( stricmp ( lumpsToAuthenticate[i].GetChars(), "COLORMAP" ) == 0 ) && ( ( stricmp ( checksum.GetChars(), "bb535e66cae508e3833a5d2de974267b" ) == 0 ) || ( stricmp ( checksum.GetChars(), "100c2c81afe87bb6dd1dbcadee9a7e58" ) == 0 ) ) ) checksum = "061a4c0f80aa8029f2c1bc12dc2e261e"; longChecksum += checksum; @@ -373,14 +372,14 @@ int workingLump, lastLump; lastLump = 0; - while ((workingLump = Wads.FindLump(lumpsToAuthenticate[i].c_str(), &lastLump)) != -1) + while ((workingLump = Wads.FindLump(lumpsToAuthenticate[i].GetChars(), &lastLump)) != -1) { - if ( !network_GenerateLumpMD5HashAndWarnIfNeeded( workingLump, lumpsToAuthenticate[i].c_str(), checksum ) ) + if ( !network_GenerateLumpMD5HashAndWarnIfNeeded( workingLump, lumpsToAuthenticate[i].GetChars(), checksum ) ) noProtectedLumpsAutoloaded = false; // [BB] To make Doom and Freedoom network compatible, we need to ignore its DEHACKED lump. // Since this lump only changes some strings, this should cause no problems. - if ( ( stricmp ( lumpsToAuthenticate[i].c_str(), "DEHACKED" ) == 0 ) + if ( ( stricmp ( lumpsToAuthenticate[i].GetChars(), "DEHACKED" ) == 0 ) && ( ( stricmp ( checksum.GetChars(), "3c48ccc87e71d791ee3df64668b3fb42" ) == 0 ) // Freedoom 0.8-beta1 || ( stricmp ( checksum.GetChars(), "9de9ddd0bc435cb8572db76a13d3140f" ) == 0 ) ) ) // Freedoom 0.8 continue; @@ -893,7 +892,7 @@ //***************************************************************************** // -std::list<std::pair<FString, FString> > *NETWORK_GetPWADList( void ) +TArray<StringPair> *NETWORK_GetPWADList( void ) { return &g_PWADs; } @@ -1186,7 +1185,7 @@ // [RC] static void network_InitPWADList( void ) { - g_PWADs.clear( ); + g_PWADs.Clear( ); // Find the IWAD index. ULONG ulNumPWADs = 0, ulRealIWADIdx; @@ -1219,7 +1218,7 @@ } char MD5Sum[33]; MD5SumOfFile ( Wads.GetWadFullName( ulIdx ), MD5Sum ); - g_PWADs.push_back( std::pair<FString, FString> ( Wads.GetWadName( ulIdx ), MD5Sum ) ); + g_PWADs.Push( StringPair ( Wads.GetWadName( ulIdx ), MD5Sum ) ); } } diff -r 7d70511f0aa5 src/network.h --- a/src/network.h Sat Jun 07 20:38:33 2014 +0300 +++ b/src/network.h Sun Jun 08 01:35:37 2014 +0200 @@ -60,6 +60,16 @@ //***************************************************************************** // DEFINES +// [EP] StringPair class in place of standard pair of two FStrings +struct StringPair +{ + FString First; + FString Second; + StringPair() {} + StringPair(const FString &f, const FString &s) + : First(f), Second(s) {} +}; + // Movement stuff. enum { @@ -350,7 +360,7 @@ FString NETWORK_GetCountryCodeFromAddress( NETADDRESS_s Address ); USHORT NETWORK_GetLocalPort( void ); -std::list<std::pair<FString, FString> > *NETWORK_GetPWADList( void ); // [RC] +TArray<StringPair> *NETWORK_GetPWADList( void ); // [RC] const char *NETWORK_GetIWAD( void ); void NETWORK_AddLumpForAuthentication( const LONG LumpNumber ); void NETWORK_GenerateMapLumpMD5Hash( MapData *Map, const LONG LumpNumber, FString &MD5Hash ); @@ -407,7 +417,9 @@ { T *pT; - std::vector<bool> idUsed ( 8192 ); + TArray<bool> idUsed; + for ( int i = 0; i < 8192; ++i ) + idUsed.Push(false); TThinkerIterator<T> Iterator; @@ -417,7 +429,7 @@ idUsed[pT->GetID( )] = true; } - for ( unsigned int i = 0; i < idUsed.size(); i++ ) + for ( unsigned int i = 0; i < idUsed.Size(); i++ ) { if ( idUsed[i] == false ) return i; diff -r 7d70511f0aa5 src/network/nettraffic.cpp --- a/src/network/nettraffic.cpp Sat Jun 07 20:38:33 2014 +0300 +++ b/src/network/nettraffic.cpp Sun Jun 08 01:35:37 2014 +0200 @@ -49,21 +49,11 @@ #include "network.h" #include "c_dispatch.h" -#include <map> - //***************************************************************************** // VARIABLES -struct ltstr -{ - bool operator()(const char* s1, const char* s2) const - { - return strcmp(s1, s2) < 0; - } -}; - -std::map<const char*, int, ltstr> g_actorTrafficMap; -std::map<int, int> g_ACSScriptTrafficMap; +TMap<FName, int> g_actorTrafficMap; +TMap<int, int> g_ACSScriptTrafficMap; CVAR( Bool, sv_measureoutboundtraffic, false, 0 ) @@ -77,7 +67,11 @@ if ( ( NETWORK_GetState( ) != NETSTATE_SERVER ) || ( sv_measureoutboundtraffic == false ) ) return; - g_actorTrafficMap [ pActor->GetClass()->TypeName.GetChars() ] += BytesUsed; + const FName curName = pActor->GetClass()->TypeName.GetChars(); + if ( g_actorTrafficMap.CheckKey( curName ) == false ) + g_actorTrafficMap.Insert( curName, BytesUsed ); + else + g_actorTrafficMap [ curName ] += BytesUsed; } //***************************************************************************** @@ -90,15 +84,18 @@ if ( ( NETWORK_GetState( ) != NETSTATE_SERVER ) || ( sv_measureoutboundtraffic == false ) ) return; - g_ACSScriptTrafficMap [ ScriptNum ] += BytesUsed; + if ( g_ACSScriptTrafficMap.CheckKey( ScriptNum ) == false ) + g_ACSScriptTrafficMap.Insert( ScriptNum, BytesUsed ); + else + g_ACSScriptTrafficMap [ ScriptNum ] += BytesUsed; } //***************************************************************************** // void NETTRAFFIC_Reset ( ) { - g_actorTrafficMap.clear(); - g_ACSScriptTrafficMap.clear(); + g_actorTrafficMap.Clear(); + g_ACSScriptTrafficMap.Clear(); } //***************************************************************************** @@ -109,13 +106,20 @@ return; Printf ( "Network traffic (in bytes) caused by actor code pointers:\n" ); - - for ( std::map<const char*, int, ltstr>::const_iterator it = g_actorTrafficMap.begin(); it != g_actorTrafficMap.end(); ++it ) - Printf ( "%s %d\n", (*it).first, (*it).second ); + const TMap<FName, int>::Pair *g_actorTrafficMapPair; + TMap<FName, int>::ConstIterator it1(g_actorTrafficMap); + while (it1.NextPair (g_actorTrafficMapPair)) + { + Printf ( "%s %d\n", g_actorTrafficMapPair->Key.GetChars(), g_actorTrafficMapPair->Value ); + } Printf ( "\nNetwork traffic (in bytes) caused by ACS scripts:\n" ); - for ( std::map<int, int>::const_iterator it = g_ACSScriptTrafficMap.begin(); it != g_ACSScriptTrafficMap.end(); ++it ) - Printf ( "Script %d: %d\n", (*it).first, (*it).second ); + const TMap<int, int>::Pair *g_ACSScriptTrafficPair; + TMap<int, int>::ConstIterator it2(g_ACSScriptTrafficMap); + while (it2.NextPair (g_ACSScriptTrafficPair)) + { + Printf ( "Script %d: %d\n", g_ACSScriptTrafficPair->Key, g_ACSScriptTrafficPair->Value ); + } } //***************************************************************************** diff -r 7d70511f0aa5 src/networkheaders.h --- a/src/networkheaders.h Sat Jun 07 20:38:33 2014 +0300 +++ b/src/networkheaders.h Sun Jun 08 01:35:37 2014 +0200 @@ -89,14 +89,6 @@ #define Sleep(x) usleep (x * 1000) #endif -#include <stdlib.h> -#include <string.h> -#include <stdio.h> -#include <iostream> - -#include <ctype.h> -#include <math.h> - // [BB] This is necessary under Linux, otherwise things like DWORD aren't defined. #ifndef __WIN32__ #include "../src/doomtype.h" diff -r 7d70511f0aa5 src/networkshared.cpp --- a/src/networkshared.cpp Sat Jun 07 20:38:33 2014 +0300 +++ b/src/networkshared.cpp Sun Jun 08 01:35:37 2014 +0200 @@ -49,9 +49,7 @@ #include "networkheaders.h" #include "networkshared.h" -#include <sstream> #include <errno.h> -#include <iostream> #include <algorithm> #include "i_system.h" @@ -563,9 +561,9 @@ //***************************************************************************** // -std::string GenerateCouldNotOpenFileErrorString( const char *pszFunctionHeader, const char *pszFileName, LONG lErrorCode ) +FString GenerateCouldNotOpenFileErrorString( const char *pszFunctionHeader, const char *pszFileName, LONG lErrorCode ) { - std::stringstream errorMessage; + FString errorMessage; errorMessage << pszFunctionHeader << ": Couldn't open file: " << pszFileName << "!\nREASON: "; switch ( lErrorCode ) { @@ -629,7 +627,7 @@ errorMessage << "UNKNOWN\n"; break; } - return errorMessage.str(); + return errorMessage; } //-------------------------------------------------------------------------------------------------------------------------------------------------- @@ -640,11 +638,11 @@ // IPFileParser //============================================================================= -bool IPFileParser::parseIPList( const char* FileName, std::vector<IPADDRESSBAN_s> &IPArray ) +bool IPFileParser::parseIPList( const char* FileName, TArray<IPADDRESSBAN_s> &IPArray ) { FILE *pFile; - IPArray.clear(); + IPArray.Clear(); char curChar = 0; _numberOfEntries = 0; @@ -657,13 +655,13 @@ ULONG oldNumberOfEntries = _numberOfEntries; bool parsingDone = !parseNextLine( pFile, IP, _numberOfEntries ); - if ( _errorMessage[0] != '\0' ) + if ( _errorMessage.IsNotEmpty() ) { fclose( pFile ); return false; } else if ( oldNumberOfEntries < _numberOfEntries ) - IPArray.push_back( IP ); + IPArray.Push( IP ); if ( parsingDone == true ) break; @@ -671,7 +669,7 @@ } else { - sprintf( _errorMessage, "%s", GenerateCouldNotOpenFileErrorString( "IPFileParser::parseIPList", FileName, errno ).c_str() ); + _errorMessage << GenerateCouldNotOpenFileErrorString( "IPFileParser::parseIPList", FileName, errno ); return false; } @@ -737,7 +735,7 @@ { if ( BanIdx == _listLength ) { - sprintf( _errorMessage, "parseNextLine: WARNING! Maximum number of IPs (%d) exceeded!\n", _listLength ); + _errorMessage.Format( "parseNextLine: WARNING! Maximum number of IPs (%d) exceeded!\n", _listLength ); return ( false ); } @@ -764,7 +762,7 @@ { if ( BanIdx == _listLength ) { - sprintf( _errorMessage, "parseNextLine: WARNING! Maximum number of IPs (%d) exceeded!\n", _listLength ); + _errorMessage.Format( "parseNextLine: WARNING! Maximum number of IPs (%d) exceeded!\n", _listLength ); return ( false ); } @@ -880,7 +878,7 @@ { destination.clear( ); - for ( ULONG ulIdx = 0; ulIdx < _ipVector.size( ); ulIdx++ ) + for ( ULONG ulIdx = 0; ulIdx < _ipVector.Size( ); ulIdx++ ) destination.push_back( _ipVector[ulIdx] ); destination.sort( ); @@ -911,7 +909,7 @@ time_t tNow; time ( &tNow ); - for ( ULONG ulIdx = 0; ulIdx < _ipVector.size(); ) + for ( ULONG ulIdx = 0; ulIdx < _ipVector.Size(); ) { // If this entry isn't infinite, and expires in the past (or now), remove it. if (( _ipVector[ulIdx].tExpirationDate != 0 ) && ( _ipVector[ulIdx].tExpirationDate - tNow <= 0)) @@ -949,7 +947,7 @@ // ULONG IPList::getFirstMatchingEntryIndex( const IPStringArray &szAddress ) const { - for ( ULONG ulIdx = 0; ulIdx < _ipVector.size(); ulIdx++ ) + for ( ULONG ulIdx = 0; ulIdx < _ipVector.Size(); ulIdx++ ) { if ((( _ipVector[ulIdx].szIP[0][0] == '*' ) || ( stricmp( szAddress[0], _ipVector[ulIdx].szIP[0] ) == 0 )) && (( _ipVector[ulIdx].szIP[1][0] == '*' ) || ( stricmp( szAddress[1], _ipVector[ulIdx].szIP[1] ) == 0 )) && @@ -992,7 +990,7 @@ // ULONG IPList::doesEntryExist( const char *pszIP0, const char *pszIP1, const char *pszIP2, const char *pszIP3 ) const { - for ( ULONG ulIdx = 0; ulIdx < _ipVector.size( ); ulIdx++ ) + for ( ULONG ulIdx = 0; ulIdx < _ipVector.Size( ); ulIdx++ ) { if (( stricmp( pszIP0, _ipVector[ulIdx].szIP[0] ) == 0 ) && ( stricmp( pszIP1, _ipVector[ulIdx].szIP[1] ) == 0 ) && @@ -1003,14 +1001,14 @@ } } - return ( static_cast<ULONG>(_ipVector.size()) ); + return ( static_cast<ULONG>(_ipVector.Size()) ); } //***************************************************************************** // IPADDRESSBAN_s IPList::getEntry( const ULONG ulIdx ) const { - if ( ulIdx >= _ipVector.size() ) + if ( ulIdx >= _ipVector.Size() ) { IPADDRESSBAN_s ZeroBan; @@ -1048,7 +1046,7 @@ { // [BB] Take IP ranges into account. ULONG ulIdx = getFirstMatchingEntryIndex( Address ); - return ( ulIdx < _ipVector.size( )) ? _ipVector[ulIdx].szComment : NULL; + return ( ulIdx < _ipVector.Size( )) ? _ipVector[ulIdx].szComment : NULL; } //***************************************************************************** @@ -1057,16 +1055,16 @@ { // [BB] Take IP ranges into account. ULONG ulIdx = getFirstMatchingEntryIndex( Address ); - return ( ulIdx < _ipVector.size( )) ? _ipVector[ulIdx].tExpirationDate : 0; + return ( ulIdx < _ipVector.Size( )) ? _ipVector[ulIdx].tExpirationDate : 0; } //***************************************************************************** // -std::string IPList::getEntryAsString( const ULONG ulIdx, bool bIncludeComment, bool bIncludeExpiration, bool bInludeNewline ) const +FString IPList::getEntryAsString( const ULONG ulIdx, bool bIncludeComment, bool bIncludeExpiration, bool bInludeNewline ) const { - std::stringstream entryStream; + FString entryStream; - if ( ulIdx < _ipVector.size() ) + if ( ulIdx < _ipVector.Size() ) { // Address. entryStream << _ipVector[ulIdx].szIP[0] << "." @@ -1091,21 +1089,20 @@ // Newline. if ( bInludeNewline ) - entryStream << std::endl; + entryStream << "\n"; } - return entryStream.str(); + return entryStream; } //***************************************************************************** // -void IPList::addEntry( const char *pszIP0, const char *pszIP1, const char *pszIP2, const char *pszIP3, const char *pszPlayerName, const char *pszCommentUncleaned, std::string &Message, time_t tExpiration ) +void IPList::addEntry( const char *pszIP0, const char *pszIP1, const char *pszIP2, const char *pszIP3, const char *pszPlayerName, const char *pszCommentUncleaned, FString &Message, time_t tExpiration ) { FILE *pFile; char szOutString[512]; char szDate[32]; ULONG ulIdx; - std::stringstream messageStream; // [BB] Before we can check whether the ban already exists, we need to build the full, cleaned comment string. @@ -1145,21 +1142,20 @@ // Address is already in the list. ulIdx = doesEntryExist( pszIP0, pszIP1, pszIP2, pszIP3 ); - if ( ulIdx != _ipVector.size() ) + if ( ulIdx != _ipVector.Size() ) { - messageStream << pszIP0 << "." << pszIP1 << "." << pszIP2 << "." << pszIP3 << " already exists in list"; + Message << pszIP0 << "." << pszIP1 << "." << pszIP2 << "." << pszIP3 << " already exists in list"; if ( ( getEntry ( ulIdx ).tExpirationDate != tExpiration ) || ( stricmp ( getEntry ( ulIdx ).szComment, szOutString ) ) ) { - messageStream << ". Just updating the expiration date and reason.\n"; + Message << ". Just updating the expiration date and reason.\n"; _ipVector[ulIdx].tExpirationDate = tExpiration; strncpy( _ipVector[ulIdx].szComment, szOutString, 127 ); _ipVector[ulIdx].szComment[127] = 0; rewriteListToFile(); } else - messageStream << " with same expiration and reason.\n"; + Message << " with same expiration and reason.\n"; - Message = messageStream.str(); return; } @@ -1172,10 +1168,10 @@ strncpy( newIPEntry.szComment, szOutString, 127 ); newIPEntry.szComment[127] = 0; newIPEntry.tExpirationDate = tExpiration; - _ipVector.push_back( newIPEntry ); + _ipVector.Push( newIPEntry ); // Finally, append the IP to the file. - if ( (pFile = fopen( _filename.c_str(), "a" )) ) + if ( (pFile = fopen( _filename.GetChars(), "a" )) ) { sprintf( szOutString, "\n%s.%s.%s.%s", pszIP0, pszIP1, pszIP2, pszIP3 ); @@ -1196,17 +1192,15 @@ fputs( szOutString, pFile ); fclose( pFile ); - messageStream << pszIP0 << "." << pszIP1 << "." << pszIP2 << "." << pszIP3 << " added to list."; + Message << pszIP0 << "." << pszIP1 << "." << pszIP2 << "." << pszIP3 << " added to list."; if ( tExpiration ) - messageStream << " It expires on " << szDate << "."; + Message << " It expires on " << szDate << "."; - messageStream << "\n"; - - Message = messageStream.str(); + Message << "\n"; } else { - Message = GenerateCouldNotOpenFileErrorString( "IPList::addEntry", _filename.c_str(), errno ); + Message = GenerateCouldNotOpenFileErrorString( "IPList::addEntry", _filename.GetChars(), errno ); } if ( pszComment ) @@ -1215,7 +1209,7 @@ //***************************************************************************** // -void IPList::addEntry( const char *pszIPAddress, const char *pszPlayerName, const char *pszComment, std::string &Message, time_t tExpiration ) +void IPList::addEntry( const char *pszIPAddress, const char *pszPlayerName, const char *pszComment, FString &Message, time_t tExpiration ) { NETADDRESS_s BanAddress; char szStringBan[4][4]; @@ -1244,41 +1238,35 @@ // [RC] Removes the entry at the given index. void IPList::removeEntry( ULONG ulEntryIdx ) { - for ( ULONG ulIdx = ulEntryIdx; ulIdx < _ipVector.size() - 1; ulIdx++ ) - _ipVector[ulIdx] = _ipVector[ulIdx+1]; - - _ipVector.pop_back(); + _ipVector.Delete(ulEntryIdx); rewriteListToFile (); } //***************************************************************************** // // Removes the entry with the given IP. Writes a success/failure message to Message. -void IPList::removeEntry( const char *pszIP0, const char *pszIP1, const char *pszIP2, const char *pszIP3, std::string &Message ) +void IPList::removeEntry( const char *pszIP0, const char *pszIP1, const char *pszIP2, const char *pszIP3, FString &Message ) { ULONG entryIdx = doesEntryExist( pszIP0, pszIP1, pszIP2, pszIP3 ); - std::stringstream messageStream; - messageStream << pszIP0 << "." << pszIP1 << "." << pszIP2 << "." << pszIP3; + Message << pszIP0 << "." << pszIP1 << "." << pszIP2 << "." << pszIP3; - if ( entryIdx < _ipVector.size() ) + if ( entryIdx < _ipVector.Size() ) { removeEntry( entryIdx ); - messageStream << " removed from list.\n"; - Message = messageStream.str(); + Message << " removed from list.\n"; } else { - messageStream << " not found in list.\n"; - Message = messageStream.str(); + Message << " not found in list.\n"; } } //***************************************************************************** // // Removes the entry with the given address. Writes a success/failure message to Message. -void IPList::removeEntry( const char *pszIPAddress, std::string &Message ) +void IPList::removeEntry( const char *pszIPAddress, FString &Message ) { char szStringBan[4][4]; @@ -1297,19 +1285,19 @@ bool IPList::rewriteListToFile () { FILE *pFile; - std::string outString; + FString outString; - if (( pFile = fopen( _filename.c_str( ), "w" ))) + if (( pFile = fopen( _filename.GetChars(), "w" ))) { for ( ULONG ulIdx = 0; ulIdx < size(); ulIdx++ ) - fputs( getEntryAsString( ulIdx ).c_str( ), pFile ); + fputs( getEntryAsString( ulIdx ).GetChars(), pFile ); fclose( pFile ); return true; } else { - _error = GenerateCouldNotOpenFileErrorString( "IPList::rewriteListToFile", _filename.c_str(), errno ); + _error = GenerateCouldNotOpenFileErrorString( "IPList::rewriteListToFile", _filename.GetChars(), errno ); return false; } } @@ -1336,7 +1324,7 @@ // void IPList::sort() { - std::sort( _ipVector.begin(), _ipVector.end(), ASCENDINGIPSORT_S() ); + std::sort( &_ipVector[0], &_ipVector[_ipVector.Size()], ASCENDINGIPSORT_S() ); } //============================================================================= @@ -1400,7 +1388,7 @@ // //============================================================================= -void QueryIPQueue::addAddress( const NETADDRESS_s AddressFrom, const LONG lCurrentTime, std::ostream *errorOut ) +void QueryIPQueue::addAddress( const NETADDRESS_s AddressFrom, const LONG lCurrentTime, FString *errorOut ) { // Add and advance the tail. _IPQueue[_iQueueTail].Address = AddressFrom; diff -r 7d70511f0aa5 src/networkshared.h --- a/src/networkshared.h Sat Jun 07 20:38:33 2014 +0300 +++ b/src/networkshared.h Sun Jun 08 01:35:37 2014 +0200 @@ -51,15 +51,7 @@ #define __NETWORKSHARED_H__ #include "platform.h" -#include <stdlib.h> -#include <string.h> -#include <stdio.h> -#include <iostream> -#include <vector> -#include <list> #include <time.h> -#include <ctype.h> -#include <math.h> //-------------------------------------------------------------------------------------------------------------------------------------------------- //-- DEFINES --------------------------------------------------------------------------------------------------------------------------------------- @@ -284,7 +276,7 @@ bool NETWORK_StringToIP( const char *pszAddress, char *pszIP0, char *pszIP1, char *pszIP2, char *pszIP3 ); void NETWORK_AddressToIPStringArray( const NETADDRESS_s &Address, IPStringArray &szAddress ); const char *NETWORK_GetHostByIPAddress( NETADDRESS_s Address ); -std::string GenerateCouldNotOpenFileErrorString( const char *pszFunctionHeader, const char *pszFileName, LONG lErrorCode ); +FString GenerateCouldNotOpenFileErrorString( const char *pszFunctionHeader, const char *pszFileName, LONG lErrorCode ); //-------------------------------------------------------------------------------------------------------------------------------------------------- //-- CLASSES --------------------------------------------------------------------------------------------------------------------------------------- @@ -303,18 +295,17 @@ { const unsigned int _listLength; ULONG _numberOfEntries; - char _errorMessage[1024]; + FString _errorMessage; //************************************************************************* public: IPFileParser( const int IPListLength ) : _listLength( IPListLength ) { - _errorMessage[0] = '\0'; } const char* getErrorMessage( ) { - return _errorMessage; + return _errorMessage.GetChars(); } ULONG getNumberOfEntries ( ) @@ -322,7 +313,7 @@ return _numberOfEntries; } - bool parseIPList( const char* FileName, std::vector<IPADDRESSBAN_s> &IPArray ); + bool parseIPList( const char* FileName, TArray<IPADDRESSBAN_s> &IPArray ); //************************************************************************* private: @@ -344,9 +335,9 @@ class IPList { - std::vector<IPADDRESSBAN_s> _ipVector; - std::string _filename; - std::string _error; + TArray<IPADDRESSBAN_s> _ipVector; + FString _filename; + FString _error; //************************************************************************* public: @@ -357,25 +348,25 @@ bool isIPInList( const NETADDRESS_s &Address ) const; ULONG doesEntryExist( const char *pszIP0, const char *pszIP1, const char *pszIP2, const char *pszIP3 ) const; IPADDRESSBAN_s getEntry( const ULONG ulIdx ) const; - std::string getEntryAsString( const ULONG ulIdx, bool bIncludeComment = true, bool bIncludeExpiration = true, bool bInludeNewline = true ) const; + FString getEntryAsString( const ULONG ulIdx, bool bIncludeComment = true, bool bIncludeExpiration = true, bool bInludeNewline = true ) const; ULONG getEntryIndex( const NETADDRESS_s &Address ) const; // [RC] const char *getEntryComment( const NETADDRESS_s &Address ) const; // [RC] time_t getEntryExpiration( const NETADDRESS_s &Address ) const; // [RC] - void addEntry( const char *pszIP0, const char *pszIP1, const char *pszIP2, const char *pszIP3, const char *pszPlayerName, const char *pszComment, std::string &Message, time_t tExpiration ); - void addEntry( const char *pszIPAddress, const char *pszPlayerName, const char *pszComment, std::string &Message, time_t tExpiration ); - void removeEntry( const char *pszIP0, const char *pszIP1, const char *pszIP2, const char *pszIP3, std::string &Message ); - void removeEntry( const char *pszIPAddress, std::string &Message ); + void addEntry( const char *pszIP0, const char *pszIP1, const char *pszIP2, const char *pszIP3, const char *pszPlayerName, const char *pszComment, FString &Message, time_t tExpiration ); + void addEntry( const char *pszIPAddress, const char *pszPlayerName, const char *pszComment, FString &Message, time_t tExpiration ); + void removeEntry( const char *pszIP0, const char *pszIP1, const char *pszIP2, const char *pszIP3, FString &Message ); + void removeEntry( const char *pszIPAddress, FString &Message ); void removeEntry( ULONG ulEntryIdx ); // [RC] void copy( IPList &destination ); // [RC] void sort(); // [RC] void removeExpiredEntries( void ); // [RC] - unsigned int size() const { return static_cast<unsigned int>( _ipVector.size( )); } - void clear() { _ipVector.clear(); } - void push_back ( IPADDRESSBAN_s &IP ) { _ipVector.push_back(IP); } - const char* getErrorMessage() const { return _error.c_str(); } + unsigned int size() const { return static_cast<unsigned int>( _ipVector.Size( )); } + void clear() { _ipVector.Clear(); } + void push_back ( IPADDRESSBAN_s &IP ) { _ipVector.Push(IP); } + const char* getErrorMessage() const { return _error.GetChars(); } - std::vector<IPADDRESSBAN_s>& getVector() { return _ipVector; } + TArray<IPADDRESSBAN_s>& getVector() { return _ipVector; } //************************************************************************* private: @@ -425,7 +416,7 @@ void adjustHead( const LONG CurrentTime ); bool addressInQueue( const NETADDRESS_s AddressFrom ) const; - void addAddress( const NETADDRESS_s AddressFrom, const LONG lCurrentTime, std::ostream *errorOut = NULL ); + void addAddress( const NETADDRESS_s AddressFrom, const LONG lCurrentTime, FString *errorOut = NULL ); bool isFull( ) const; }; diff -r 7d70511f0aa5 src/p_mobj.cpp --- a/src/p_mobj.cpp Sat Jun 07 20:38:33 2014 +0300 +++ b/src/p_mobj.cpp Sun Jun 08 01:35:37 2014 +0200 @@ -77,7 +77,6 @@ #include "survival.h" #include "network/nettraffic.h" #include "unlagged.h" -#include <set> // MACROS ------------------------------------------------------------------ @@ -510,7 +509,17 @@ } // [BB] To print the client side infinite loop workaround warning only once per actor type. -static std::set<unsigned short> clientInfiniteLoopWarningPrintedActors; +static TArray<unsigned short> clientInfiniteLoopWarningPrintedActors; + +static ULONG findActorNetworkIndexInArray(AActor *mo) +{ + ULONG i; + for ( i = 0; i < clientInfiniteLoopWarningPrintedActors.Size(); ++i) { + if ( clientInfiniteLoopWarningPrintedActors[i] == mo->GetClass()->getActorNetworkIndex() ) + break; + } + return i; +} //========================================================================== // @@ -603,10 +612,10 @@ // [BB] Workaround to break client side infinite loops in DECORATE definitions. if ( NETWORK_InClientMode() && ( numActions++ > 10000 ) ) { - if ( clientInfiniteLoopWarningPrintedActors.find ( this->GetClass( )->getActorNetworkIndex() ) == clientInfiniteLoopWarningPrintedActors.end() ) + if ( findActorNetworkIndexInArray(this) == clientInfiniteLoopWarningPrintedActors.Size() ) { Printf ( "Warning: Breaking infinite loop in actor %s.\nCurrent offset from spawn state is %ld\n", this->GetClass()->TypeName.GetChars(), static_cast<LONG>(this->state - this->SpawnState) ); - clientInfiniteLoopWarningPrintedActors.insert ( this->GetClass( )->getActorNetworkIndex() ); + clientInfiniteLoopWarningPrintedActors.Push ( this->GetClass( )->getActorNetworkIndex() ); } break; } @@ -677,10 +686,10 @@ // [BB] Workaround to break client side infinite loops in DECORATE definitions. if ( NETWORK_InClientMode() && ( numStates++ > 10000 ) ) { - if ( clientInfiniteLoopWarningPrintedActors.find ( this->GetClass( )->getActorNetworkIndex() ) == clientInfiniteLoopWarningPrintedActors.end() ) + if ( findActorNetworkIndexInArray(this) == clientInfiniteLoopWarningPrintedActors.Size() ) { Printf ( "Warning: Breaking infinite loop in actor %s.\nCurrent offset from spawn state is %ld\n", this->GetClass()->TypeName.GetChars(), static_cast<LONG>(this->state - this->SpawnState) ); - clientInfiniteLoopWarningPrintedActors.insert ( this->GetClass( )->getActorNetworkIndex() ); + clientInfiniteLoopWarningPrintedActors.Push ( this->GetClass( )->getActorNetworkIndex() ); } break; } @@ -811,25 +820,25 @@ if( pCurrentActorState != NULL ) { FState *pTempState = pState; - std::vector<FState*> checkedFrames; + TArray<FState*> checkedFrames; while ( pTempState != NULL ) { if ( pCurrentActorState == pTempState ) { if ( pOffset != NULL ) - *pOffset = checkedFrames.size(); + *pOffset = checkedFrames.Size(); return true; } bool breakLoop = false; // [BB] Check if we already encountered pTempState. - for ( unsigned int i = 0; i < checkedFrames.size(); i++ ) + for ( unsigned int i = 0; i < checkedFrames.Size(); i++ ) { if ( pTempState == checkedFrames[i] ) breakLoop = true; } // [BB] Save the frame pointer, necessary to check if we encounter this frame again. - checkedFrames.push_back( pTempState ); + checkedFrames.Push( pTempState ); pTempState = pTempState->GetNextState( ); @@ -6910,4 +6919,4 @@ } } } -#endif \ No newline at end of file +#endif diff -r 7d70511f0aa5 src/platform.cpp --- a/src/platform.cpp Sat Jun 07 20:38:33 2014 +0300 +++ b/src/platform.cpp Sun Jun 08 01:35:37 2014 +0200 @@ -69,7 +69,6 @@ #ifdef NO_SERVER_GUI -#include <iostream> #include "networkheaders.h" #include "networkshared.h" #include "v_text.h" @@ -93,7 +92,7 @@ void SERVERCONSOLE_Print( char *pszString ) { V_StripColors( pszString ); - std::cout << pszString; + printf("%s", pszString); } #endif //NO_SERVER_GUI // ------------------- GL related stuff ------------------- diff -r 7d70511f0aa5 src/scoreboard.cpp --- a/src/scoreboard.cpp Sat Jun 07 20:38:33 2014 +0300 +++ b/src/scoreboard.cpp Sun Jun 08 01:35:37 2014 +0200 @@ -2556,13 +2556,13 @@ //***************************************************************************** // [RC] Helper method for SCOREBOARD_BuildLimitStrings. Creates a "x things remaining" message. // -void scoreboard_AddSingleLimit( std::list<FString> &lines, bool condition, int remaining, const char *pszUnitName ) +void scoreboard_AddSingleLimit( TArray<FString> &lines, bool condition, int remaining, const char *pszUnitName ) { if ( condition && remaining > 0 ) { char szString[128]; sprintf( szString, "%d %s%s remain%s", static_cast<int> (remaining), pszUnitName, ( remaining == 1 ) ? "" : "s", ( remaining == 1 ) ? "s" : "" ); - lines.push_back( szString ); + lines.Push( szString ); } } @@ -2570,7 +2570,7 @@ // // [RC] Builds the series of "x frags left / 3rd match between the two / 15:10 remain" strings. Used here and in serverconsole.cpp // -void SCOREBOARD_BuildLimitStrings( std::list<FString> &lines, bool bAcceptColors ) +void SCOREBOARD_BuildLimitStrings( TArray<FString> &lines, bool bAcceptColors ) { char szString[128]; @@ -2613,7 +2613,7 @@ V_ColorizeString( szString ); if ( !bAcceptColors ) V_StripColors( szString ); - lines.push_back( szString ); + lines.Push( szString ); } } @@ -2644,7 +2644,7 @@ sprintf( szString, "%s ends in %02d:%02d:%02d", szRound, static_cast<unsigned int> (ulHours), static_cast<unsigned int> (ulMinutes), static_cast<unsigned int> (ulSeconds) ); else sprintf( szString, "%s ends in %02d:%02d", szRound, static_cast<unsigned int> (ulMinutes), static_cast<unsigned int> (ulSeconds) ); - lines.push_back( szString ); + lines.Push( szString ); } // Render the number of monsters left in coop. @@ -2654,13 +2654,13 @@ sprintf( szString, "%d%% remaining", static_cast<int> (remaining) ); else sprintf( szString, "%d monster%s remaining", static_cast<int> (remaining), remaining == 1 ? "" : "s" ); - lines.push_back( szString ); + lines.Push( szString ); // [WS] Show the damage factor. if ( sv_coop_damagefactor != 1.0f ) { sprintf( szString, "damage factor %.2f", static_cast<float> (sv_coop_damagefactor) ); - lines.push_back( szString ); + lines.Push( szString ); } } } @@ -2670,19 +2670,20 @@ static void scoreboard_DrawLimits( void ) { // Generate the strings. - std::list<FString> lines; + TArray<FString> lines; SCOREBOARD_BuildLimitStrings( lines, true ); // Now, draw them. - for ( std::list<FString>::iterator i = lines.begin(); i != lines.end(); ++i ) + for ( ULONG i = 0; i < lines.Size(); ++i ) { if ( g_bScale ) { - screen->DrawText( SmallFont, CR_GREY, (LONG)(( g_ValWidth.Int / 2 ) - ( SmallFont->StringWidth( *i ) / 2 )), - g_ulCurYPos, *i, DTA_VirtualWidth, g_ValWidth.Int, DTA_VirtualHeight, g_ValHeight.Int, TAG_DONE ); + screen->DrawText( SmallFont, CR_GREY, (LONG)(( g_ValWidth.Int / 2 ) - ( SmallFont->StringWidth( lines[i] ) / 2 )), + g_ulCurYPos, lines[i], DTA_VirtualWidth, g_ValWidth.Int, DTA_VirtualHeight, g_ValHeight.Int, TAG_DONE ); } else - screen->DrawText( SmallFont, CR_GREY, ( SCREENWIDTH / 2 ) - ( SmallFont->StringWidth( *i ) / 2 ), g_ulCurYPos, *i, TAG_DONE ); + screen->DrawText( SmallFont, CR_GREY, ( SCREENWIDTH / 2 ) - ( SmallFont->StringWidth( lines[i] ) / 2 ), + g_ulCurYPos, lines[i], TAG_DONE ); g_ulCurYPos += 10; } diff -r 7d70511f0aa5 src/scoreboard.h --- a/src/scoreboard.h Sat Jun 07 20:38:33 2014 +0300 +++ b/src/scoreboard.h Sun Jun 08 01:35:37 2014 +0200 @@ -105,7 +105,7 @@ void SCOREBOARD_RenderStats_TeamScores( void ); void SCOREBOARD_RenderStats_RankSpread( void ); void SCOREBOARD_RenderInvasionStats( void ); -void SCOREBOARD_BuildLimitStrings( std::list<FString> &lines, bool bAcceptColors ); +void SCOREBOARD_BuildLimitStrings( TArray<FString> &lines, bool bAcceptColors ); void SCOREBOARD_RenderInVote( void ); void SCOREBOARD_RenderInVoteClassic( void ); void SCOREBOARD_RenderDuelCountdown( ULONG ulTimeLeft ); diff -r 7d70511f0aa5 src/sv_ban.cpp --- a/src/sv_ban.cpp Sat Jun 07 20:38:33 2014 +0300 +++ b/src/sv_ban.cpp Sun Jun 08 01:35:37 2014 +0200 @@ -187,7 +187,7 @@ Printf( "Banlist cleared.\n" ); } else - Printf( "%s", GenerateCouldNotOpenFileErrorString( "SERVERBAN_ClearBans", sv_banfile.GetGenericRep( CVAR_String ).String, errno ).c_str() ); + Printf( "%s", GenerateCouldNotOpenFileErrorString( "SERVERBAN_ClearBans", sv_banfile.GetGenericRep( CVAR_String ).String, errno ).GetChars() ); } //***************************************************************************** @@ -201,7 +201,7 @@ for ( LONG i = 0, lNumEntries = NETWORK_ReadLong( pByteStream ); i < lNumEntries; i++ ) { const char *pszBan = NETWORK_ReadString( pByteStream ); - std::string Message; + FString Message; g_MasterServerBans.addEntry( pszBan, "", "", Message, 0 ); } @@ -210,7 +210,7 @@ for ( LONG i = 0, lNumEntries = NETWORK_ReadLong( pByteStream ); i < lNumEntries; i++ ) { const char *pszBan = NETWORK_ReadString( pByteStream ); - std::string Message; + FString Message; g_MasterServerBanExemptions.addEntry( pszBan, "", "", Message, 0 ); } @@ -252,7 +252,7 @@ case MSB_BANEXEMPTION: { const char *pszBan = NETWORK_ReadString( pByteStream ); - std::string Message; + FString Message; if ( lCommand == MSB_BAN ) g_MasterServerBans.addEntry( pszBan, "", "", Message, 0 ); @@ -408,9 +408,9 @@ V_RemoveColorCodes( szPlayerName ); // Add the ban and kick the player. - std::string message; + FString message; g_ServerBans.addEntry( NETWORK_AddressToString( SERVER_GetClient( ulPlayer )->Address ), szPlayerName, pszBanReason, message, tExpiration ); - Printf( "addban: %s", message.c_str() ); + Printf( "addban: %s", message.GetChars() ); SERVER_KickPlayer( ulPlayer, pszBanReason ? pszBanReason : "" ); // [RC] serverban_KickBannedPlayers would cover this, but we want the messages to be distinct so there's no confusion. // Kick any other players using the newly-banned address. @@ -615,9 +615,9 @@ return; } - std::string message; + FString message; g_ServerBans.addEntry( argv[1], NULL, (argv.argc( ) >= 4) ? argv[3] : NULL, message, tExpiration ); - Printf( "addban: %s", message.c_str() ); + Printf( "addban: %s", message.GetChars() ); // Kick any players using the newly-banned address. serverban_KickBannedPlayers( ); @@ -633,9 +633,9 @@ return; } - std::string message; + FString message; g_ServerBans.removeEntry( argv[1], message ); - Printf( "delban: %s", message.c_str() ); + Printf( "delban: %s", message.GetChars() ); } //***************************************************************************** @@ -648,9 +648,9 @@ return; } - std::string message; + FString message; g_ServerBanExemptions.addEntry( argv[1], NULL, (argv.argc( ) >= 3) ? argv[2] : NULL, message, 0 ); - Printf( "addbanexemption: %s", message.c_str() ); + Printf( "addbanexemption: %s", message.GetChars() ); } //***************************************************************************** @@ -663,9 +663,9 @@ return; } - std::string message; + FString message; g_ServerBanExemptions.removeEntry( argv[1], message ); - Printf( "delbanexemption: %s", message.c_str() ); + Printf( "delbanexemption: %s", message.GetChars() ); } //***************************************************************************** @@ -673,7 +673,7 @@ CCMD( viewbanlist ) { for ( ULONG ulIdx = 0; ulIdx < g_ServerBans.size(); ulIdx++ ) - Printf( "%s", g_ServerBans.getEntryAsString(ulIdx).c_str( )); + Printf( "%s", g_ServerBans.getEntryAsString(ulIdx).GetChars()); } //***************************************************************************** @@ -681,7 +681,7 @@ CCMD( viewbanexemptionlist ) { for ( ULONG ulIdx = 0; ulIdx < g_ServerBanExemptions.size(); ulIdx++ ) - Printf( "%s", g_ServerBanExemptions.getEntryAsString(ulIdx).c_str( )); + Printf( "%s", g_ServerBanExemptions.getEntryAsString(ulIdx).GetChars()); } //***************************************************************************** @@ -689,7 +689,7 @@ CCMD( viewmasterbanlist ) { for ( ULONG ulIdx = 0; ulIdx < g_MasterServerBans.size(); ulIdx++ ) - Printf( "%s", g_MasterServerBans.getEntryAsString(ulIdx).c_str( )); + Printf( "%s", g_MasterServerBans.getEntryAsString(ulIdx).GetChars()); } //***************************************************************************** @@ -697,7 +697,7 @@ CCMD( viewmasterexemptionbanlist ) { for ( ULONG ulIdx = 0; ulIdx < g_MasterServerBanExemptions.size(); ulIdx++ ) - Printf( "%s", g_MasterServerBanExemptions.getEntryAsString(ulIdx).c_str( )); + Printf( "%s", g_MasterServerBanExemptions.getEntryAsString(ulIdx).GetChars()); } //***************************************************************************** diff -r 7d70511f0aa5 src/sv_main.cpp --- a/src/sv_main.cpp Sat Jun 07 20:38:33 2014 +0300 +++ b/src/sv_main.cpp Sun Jun 08 01:35:37 2014 +0200 @@ -227,7 +227,7 @@ static TArray<EDITEDTRANSLATION_s> g_EditedTranslationList; // [BB] List of all sector links created by calls to Sector_SetLink. -static TArray<SECTORLINK_s> g_SectorLinkList; +static TArray<SECTORLINK_s> g_SectorLinkList; // [RC] File to log packets to. #ifdef CREATE_PACKET_LOG @@ -1973,7 +1973,7 @@ g_aClients[lClient].bSuspicious = false; g_aClients[lClient].ulNumConsistencyWarnings = 0; g_aClients[lClient].szSkin[0] = 0; - g_aClients[lClient].IgnoredAddresses.clear(); + g_aClients[lClient].IgnoredAddresses.Clear(); // [BB] Inform the client that he is connected and needs to authenticate the map. SERVER_RequestClientToAuthenticate( lClient ); @@ -2238,15 +2238,17 @@ break; case NETWORK_ERRORCODE_AUTHENTICATIONFAILED: case NETWORK_ERRORCODE_PROTECTED_LUMP_AUTHENTICATIONFAILED: - - NETWORK_WriteByte( &g_aClients[ulClient].PacketBuffer.ByteStream, NETWORK_GetPWADList( )->size( )); - for( std::list<std::pair<FString, FString> >::iterator i = NETWORK_GetPWADList( )->begin( ); i != NETWORK_GetPWADList( )->end(); ++i ) { - NETWORK_WriteString( &g_aClients[ulClient].PacketBuffer.ByteStream, i->first.GetChars( )); - NETWORK_WriteString( &g_aClients[ulClient].PacketBuffer.ByteStream, i->second.GetChars( )); + TArray<StringPair> *pwadList = NETWORK_GetPWADList(); + NETWORK_WriteByte( &g_aClients[ulClient].PacketBuffer.ByteStream, pwadList->Size( )); + for( ULONG i = 0; i < pwadList->Size(); ++i ) + { + NETWORK_WriteString( &g_aClients[ulClient].PacketBuffer.ByteStream, (*pwadList)[i].First.GetChars( )); + NETWORK_WriteString( &g_aClients[ulClient].PacketBuffer.ByteStream, (*pwadList)[i].Second.GetChars( )); } Printf( "%s authentication failed.\n", ( ulErrorCode == NETWORK_ERRORCODE_PROTECTED_LUMP_AUTHENTICATIONFAILED ) ? "Protected lump" : "Level" ); + } break; case NETWORK_ERRORCODE_FAILEDTOSENDUSERINFO: @@ -3545,22 +3547,23 @@ // LONG SERVER_GetPlayerIgnoreTic( ULONG ulPlayer, NETADDRESS_s Address ) { + TArray<STORED_QUERY_IP_s> ignoredAddresses = SERVER_GetClient( ulPlayer )->IgnoredAddresses; // Remove all expired entries first. ([RC] We could combine the loops, but not all of the old entries would be removed.) - for ( std::list<STORED_QUERY_IP_s>::iterator i = SERVER_GetClient( ulPlayer )->IgnoredAddresses.begin(); i != SERVER_GetClient( ulPlayer )->IgnoredAddresses.end( ); ) - { - if (( i->lNextAllowedGametic != -1 ) && ( i->lNextAllowedGametic <= gametic )) - i = SERVER_GetClient( ulPlayer )->IgnoredAddresses.erase( i ); // Returns a new iterator. + for ( ULONG i = 0; i < ignoredAddresses.Size(); ) + { + if (( ignoredAddresses[i].lNextAllowedGametic != -1 ) && ( ignoredAddresses[i].lNextAllowedGametic <= gametic )) + ignoredAddresses.Delete(i); else ++i; } // Search for entries with this address. - for ( std::list<STORED_QUERY_IP_s>::iterator i = SERVER_GetClient( ulPlayer )->IgnoredAddresses.begin(); i != SERVER_GetClient( ulPlayer )->IgnoredAddresses.end(); ++i ) - { - if ( NETWORK_CompareAddress( i->Address, Address, true )) + for ( ULONG i = 0; i < ignoredAddresses.Size(); ++i ) + { + if ( NETWORK_CompareAddress( ignoredAddresses[i].Address, Address, true )) { - if ( i->lNextAllowedGametic != -1 ) - return i->lNextAllowedGametic - gametic; + if ( ignoredAddresses[i].lNextAllowedGametic != -1 ) + return ignoredAddresses[i].lNextAllowedGametic - gametic; else return -1; } @@ -4425,10 +4428,11 @@ // First, remove any entries using this IP. NETADDRESS_s AddressToIgnore = SERVER_GetClient( ulTargetIdx )->Address; - for ( std::list<STORED_QUERY_IP_s>::iterator i = SERVER_GetClient( g_lCurrentClient )->IgnoredAddresses.begin(); i != SERVER_GetClient( g_lCurrentClient )->IgnoredAddresses.end( ); ) - { - if ( NETWORK_CompareAddress( i->Address, AddressToIgnore, true )) - i = SERVER_GetClient( g_lCurrentClient )->IgnoredAddresses.erase( i ); // Returns a new iterator. + TArray<STORED_QUERY_IP_s> ignoredAddresses = SERVER_GetClient( g_lCurrentClient )->IgnoredAddresses; + for ( ULONG i = 0; i < ignoredAddresses.Size(); ) + { + if ( NETWORK_CompareAddress( ignoredAddresses[i].Address, AddressToIgnore, true )) + ignoredAddresses.Delete(i); // Returns a new iterator. else ++i; } @@ -4440,7 +4444,7 @@ Entry.Address = AddressToIgnore; Entry.lNextAllowedGametic = ( lTicks == -1 ) ? lTicks : ( gametic + lTicks ); - SERVER_GetClient( g_lCurrentClient )->IgnoredAddresses.push_back( Entry ); + SERVER_GetClient( g_lCurrentClient )->IgnoredAddresses.Push( Entry ); } return false; @@ -6391,7 +6395,7 @@ itoa( Address.abIP[1], szAddress[1], 10 ); itoa( Address.abIP[2], szAddress[2], 10 ); itoa( Address.abIP[3], szAddress[3], 10 ); - std::string reason; + FString reason; reason = "Hacker"; g_HackerIPList.addEntry( szAddress[0], szAddress[1], szAddress[2], szAddress[3], "", pszReason, reason); } diff -r 7d70511f0aa5 src/sv_main.h --- a/src/sv_main.h Sat Jun 07 20:38:33 2014 +0300 +++ b/src/sv_main.h Sun Jun 08 01:35:37 2014 +0200 @@ -56,7 +56,6 @@ #include "i_net.h" #include "networkshared.h" #include "s_sndseq.h" -#include <list> //***************************************************************************** // DEFINES @@ -295,7 +294,7 @@ char szSkin[MAX_SKIN_NAME+1]; // [RC] List of IP addresses that this client is ignoring. - std::list<STORED_QUERY_IP_s> IgnoredAddresses; + TArray<STORED_QUERY_IP_s> IgnoredAddresses; // [K6] Last tic we got some action from the client. Used to determine his presence. LONG lLastActionTic; diff -r 7d70511f0aa5 src/sv_master.cpp --- a/src/sv_master.cpp Sat Jun 07 20:38:33 2014 +0300 +++ b/src/sv_master.cpp Sun Jun 08 01:35:37 2014 +0200 @@ -402,9 +402,10 @@ // Send out the PWAD information. if ( ulBits & SQF_PWADS ) { - NETWORK_WriteByte( &g_MasterServerBuffer.ByteStream, NETWORK_GetPWADList( )->size( )); - for( std::list<std::pair<FString, FString> >::iterator i = NETWORK_GetPWADList( )->begin( ); i != NETWORK_GetPWADList( )->end(); ++i ) - NETWORK_WriteString( &g_MasterServerBuffer.ByteStream, i->first.GetChars( )); + TArray<StringPair> *pwadList = NETWORK_GetPWADList( ); + NETWORK_WriteByte( &g_MasterServerBuffer.ByteStream, pwadList->Size()); + for( ULONG i = 0; i < pwadList->Size(); ++i ) + NETWORK_WriteString( &g_MasterServerBuffer.ByteStream, (*pwadList)[i].First.GetChars()); } if ( ulBits & SQF_GAMETYPE ) @@ -683,7 +684,8 @@ CCMD( wads ) { Printf( "IWAD: %s\n", NETWORK_GetIWAD( ) ); - Printf( "Num PWADs: %d\n", static_cast<unsigned int> (NETWORK_GetPWADList( )->size( ))); - for( std::list<std::pair<FString, FString> >::iterator i = NETWORK_GetPWADList( )->begin( ); i != NETWORK_GetPWADList( )->end( ); ++i ) - Printf( "PWAD: %s - %s\n", i->first.GetChars(), i->second.GetChars() ); + TArray<StringPair> *pwadList = NETWORK_GetPWADList( ); + Printf( "Num PWADs: %d\n", static_cast<unsigned int> (pwadList->Size( ))); + for( ULONG i = 0; i < pwadList->Size(); ++i ) + Printf( "PWAD: %s - %s\n", (*pwadList)[i].First.GetChars(), (*pwadList)[i].Second.GetChars() ); } diff -r 7d70511f0aa5 src/sv_rcon.cpp --- a/src/sv_rcon.cpp Sat Jun 07 20:38:33 2014 +0300 +++ b/src/sv_rcon.cpp Sun Jun 08 01:35:37 2014 +0200 @@ -50,7 +50,6 @@ #include "sv_rcon.h" // [BB] Do not include these system headers earlier to prevent header inclusion conflicts. -#include <list> #include <time.h> #include "sv_ban.h" #include "c_console.h" @@ -76,7 +75,7 @@ static TArray<RCONCLIENT_s> g_AuthedClients; // The last 32 lines that were printed in the console; sent to clients when they connect. (The server doesn't use the c_console buffer.) -static std::list<FString> g_RecentConsoleLines; +static TArray<FString> g_RecentConsoleLines; // IPs that we're ignoring (bad passwords, old protocol versions) to prevent flooding. static QueryIPQueue g_BadRequestFloodQueue( BAD_QUERY_IGNORE_TIME ); @@ -221,8 +220,8 @@ // Add this to the cache of recent messages. //========================================== - if ( g_RecentConsoleLines.size() >= 32 ) - g_RecentConsoleLines.pop_front(); + if ( g_RecentConsoleLines.Size() >= 32 ) + g_RecentConsoleLines.Delete(0); FString fsLogged = pszString; time_t tNow = time(0); @@ -233,7 +232,7 @@ else fsLogged.Format( "[%02d:%02d:%02d pm] %s", ( pTimeInfo->tm_hour == 12 ) ? 12 : pTimeInfo->tm_hour % 12, pTimeInfo->tm_min, pTimeInfo->tm_sec, pszString ); - g_RecentConsoleLines.push_back( fsLogged ); + g_RecentConsoleLines.Push( fsLogged ); } //========================================================================== @@ -412,9 +411,9 @@ server_WriteUpdateInfo( &g_MessageBuffer.ByteStream, i ); // Send the console history. - NETWORK_WriteByte( &g_MessageBuffer.ByteStream, g_RecentConsoleLines.size() ); - for( std::list<FString>::iterator i = g_RecentConsoleLines.begin(); i != g_RecentConsoleLines.end(); ++i ) - NETWORK_WriteString( &g_MessageBuffer.ByteStream, *i ); + NETWORK_WriteByte( &g_MessageBuffer.ByteStream, g_RecentConsoleLines.Size() ); + for( ULONG i = 0; i < g_RecentConsoleLines.Size(); ++i ) + NETWORK_WriteString( &g_MessageBuffer.ByteStream, g_RecentConsoleLines[i] ); NETWORK_LaunchPacket( &g_MessageBuffer, g_Candidates[iCandidateIndex].Address ); SERVER_RCON_UpdateInfo( SVRCU_ADMINCOUNT ); diff -r 7d70511f0aa5 src/win32/serverconsole/serverconsole.cpp --- a/src/win32/serverconsole/serverconsole.cpp Sat Jun 07 20:38:33 2014 +0300 +++ b/src/win32/serverconsole/serverconsole.cpp Sun Jun 08 01:35:37 2014 +0200 @@ -111,7 +111,7 @@ static NETADDRESS_s g_LocalAddress; // [RC] Commands that the server admin sent recently. -static std::vector<FString> g_RecentConsoleMessages; +static TArray<FString> g_RecentConsoleMessages; //-------------------------------------------------------------------------------------------------------------------------------------------------- //-- GLOBAL VARIABLES ------------------------------------------------------------------------------------------------------------------------------ @@ -346,13 +346,13 @@ pszEntry = szBuffer; // Add the command to history. - if ( g_RecentConsoleMessages.size() > 19 ) - g_RecentConsoleMessages.erase( g_RecentConsoleMessages.begin() ); - g_RecentConsoleMessages.push_back( pszEntry ); + if ( g_RecentConsoleMessages.Size() > 19 ) + g_RecentConsoleMessages.Delete(0); + g_RecentConsoleMessages.Push( pszEntry ); SERVER_AddCommand( pszEntry ); SetDlgItemText( hDlg, IDC_INPUTBOX, "" ); - EnableWindow( GetDlgItem( hDlg, IDC_HISTORY ), !g_RecentConsoleMessages.empty() ); + EnableWindow( GetDlgItem( hDlg, IDC_HISTORY ), g_RecentConsoleMessages.Size() != 0 ); } break; case IDC_HISTORY: @@ -362,7 +362,7 @@ //========================== int iSelection = -1; - if ( !g_RecentConsoleMessages.empty() ) + if ( g_RecentConsoleMessages.Size() != 0 ) { HMENU hMenu = CreatePopupMenu(); POINT pt; @@ -371,9 +371,9 @@ AppendMenu( hMenu, MF_STRING | MF_DISABLED, 0, "Recent entries..." ); AppendMenu( hMenu, MF_SEPARATOR, 0, 0 ); - for( std::vector<FString>::reverse_iterator i = g_RecentConsoleMessages.rbegin(); i != g_RecentConsoleMessages.rend(); ++i ) + for( LONG i = g_RecentConsoleMessages.Size()-1; i >= 0; --i ) { - FString entry = *i; + FString entry = g_RecentConsoleMessages[i]; if ( entry.Len() > 35 ) entry = entry.Left( 32 ) + "..."; AppendMenu( hMenu, MF_STRING, iIndex++, entry ); @@ -390,9 +390,9 @@ // Fill in the box with the command. //=================================== - if ( iSelection >= IDC_HISTORY_MENU && iSelection < IDC_HISTORY_MENU + g_RecentConsoleMessages.size() ) + if ( iSelection >= IDC_HISTORY_MENU && iSelection < IDC_HISTORY_MENU + g_RecentConsoleMessages.Size() ) { - FString entry = g_RecentConsoleMessages[ g_RecentConsoleMessages.size() - ( iSelection - IDC_HISTORY_MENU ) - 1]; + FString entry = g_RecentConsoleMessages[ g_RecentConsoleMessages.Size() - ( iSelection - IDC_HISTORY_MENU ) - 1]; SetDlgItemText( hDlg, IDC_INPUTBOX, entry ); SetFocus( GetDlgItem( hDlg, IDC_INPUTBOX )); @@ -473,11 +473,12 @@ if ( g_bServerLoaded ) { // [BB] Load all wads the server loaded and connect to it. - FString arguments = NETWORK_GetPWADList( )->size() ? "-file " : ""; - for( std::list<std::pair<FString, FString> >::iterator i = NETWORK_GetPWADList( )->begin( ); i != NETWORK_GetPWADList( )->end( ); ++i ) + TArray<StringPair> *pwadList = NETWORK_GetPWADList( ); + FString arguments = pwadList->Size() > 0 ? "-file " : ""; + for( ULONG i = 0; i < pwadList->Size(); ++i ) { // [BB] Load the wads using their full path, they don't need to be in our search path. - const int wadnum = Wads.CheckIfWadLoaded ( i->first ); + const int wadnum = Wads.CheckIfWadLoaded ( (*pwadList)[i].First ); const char *wadFullName = ( wadnum != -1 ) ? Wads.GetWadFullName ( wadnum ) : NULL; if ( wadFullName ) arguments.AppendFormat( "\"%s\" ", wadFullName ); @@ -1488,7 +1489,7 @@ *pszComment = 0; } - std::string Message; + FString Message; SERVERBAN_GetBanList( )->addEntry( szIP, "", szComment, Message, tExpiration ); } } @@ -1631,7 +1632,7 @@ //***************************************************************************** // -void SCOREBOARD_BuildLimitStrings( std::list<FString> &lines, bool bAcceptColors ); +void SCOREBOARD_BuildLimitStrings( TArray<FString> &lines, bool bAcceptColors ); void SERVERCONSOLE_UpdateScoreboard( void ) { int labels[4] = { IDC_SCOREBOARD1, IDC_SCOREBOARD2, IDC_SCOREBOARD3, IDC_SCOREBOARD4, }; @@ -1641,15 +1642,15 @@ SetDlgItemText( g_hDlg, labels[i], "" ); // Build the strings. - std::list<FString> ScoreboardNotices; + TArray<FString> ScoreboardNotices; SCOREBOARD_BuildLimitStrings( ScoreboardNotices, false ); // Put the strings on the labels. int index = 0; - for ( std::list<FString>::iterator i = ScoreboardNotices.begin(); i != ScoreboardNotices.end(); ++i ) + for ( ULONG i = 0; i < ScoreboardNotices.Size(); ++i ) { if ( index < 4 ) - SetDlgItemText( g_hDlg, labels[index++], *i ); + SetDlgItemText( g_hDlg, labels[index++], ScoreboardNotices[i] ); } // If we just have one label, center it. diff -r 7d70511f0aa5 src/win32/serverconsole/serverconsole_settings.cpp --- a/src/win32/serverconsole/serverconsole_settings.cpp Sat Jun 07 20:38:33 2014 +0300 +++ b/src/win32/serverconsole/serverconsole_settings.cpp Sun Jun 08 01:35:37 2014 +0200 @@ -598,16 +598,17 @@ int iNumChars = 0; sprintf( szString, "PWADs:" ); - for( std::list<std::pair<FString, FString> >::iterator i = NETWORK_GetPWADList( )->begin( ); i != NETWORK_GetPWADList( )->end(); ++i ) + TArray<StringPair> *pwadList = NETWORK_GetPWADList( ); + for( ULONG i = 0; i < pwadList->Size(); ++i ) { - iNumChars += i->first.Len( ); + iNumChars += (*pwadList)[i].First.Len( ); if ( iNumChars > 50 - 3 ) // Determined by width of label { sprintf( szString + strlen ( szString ), "..." ); break; } else - sprintf( szString + strlen ( szString ), " %s", i->first.GetChars( )); + sprintf( szString + strlen ( szString ), " %s", (*pwadList)[i].First.GetChars( )); } g_ulNumPWADs = NETWORK_GetPWADList( )->size( ); @@ -946,4 +947,4 @@ return FALSE; } -#endif \ No newline at end of file +#endif diff -r 7d70511f0aa5 upnpnat/upnpnat.cpp --- a/upnpnat/upnpnat.cpp Sat Jun 07 20:38:33 2014 +0300 +++ b/upnpnat/upnpnat.cpp Sun Jun 08 01:35:37 2014 +0200 @@ -11,9 +11,7 @@ #define closesocket close #define ioctlsocket ioctl #endif -#include <iostream> -#include <string> -#include <cstring> +#include <string.h> #include <stdio.h> #ifndef WIN32 #include <unistd.h> @@ -24,50 +22,52 @@ #define MAX_BUFF_SIZE 102400 -static bool parseUrl(const char* url,std::string& host,unsigned short* port,std::string& path) +#define NPOS (long)-1 + +static bool parseUrl(const char* url,FString& host,unsigned short* port,FString& path) { - std::string str_url=url; + FString str_url=url; - std::string::size_type pos1,pos2,pos3; - pos1=str_url.find("://"); - if(pos1==std::string::npos) + long pos1,pos2,pos3; + pos1=str_url.IndexOf("://"); + if(pos1==NPOS) { return false; } pos1=pos1+3; - pos2=str_url.find(":",pos1); - if(pos2==std::string::npos) + pos2=str_url.IndexOf(":",pos1); + if(pos2==NPOS) { *port=80; - pos3=str_url.find("/",pos1); - if(pos3==std::string::npos) + pos3=str_url.IndexOf("/",pos1); + if(pos3==NPOS) { return false; } - host=str_url.substr(pos1,pos3-pos1); + host=str_url.Mid(pos1,pos3-pos1); } else { - host=str_url.substr(pos1,pos2-pos1); - pos3=str_url.find("/",pos1); - if(pos3==std::string::npos) + host=str_url.Mid(pos1,pos2-pos1); + pos3=str_url.IndexOf("/",pos1); + if(pos3==NPOS) { return false; } - std::string str_port=str_url.substr(pos2+1,pos3-pos2-1); - *port=(unsigned short)atoi(str_port.c_str()); + FString str_port=str_url.Mid(pos2+1,pos3-pos2-1); + *port=(unsigned short)atoi(str_port.GetChars()); } - if(pos3+1>=str_url.size()) + if(pos3+1>=(long)str_url.Len()) { path="/"; } else { - path=str_url.substr(pos3,str_url.size()); + path=str_url.Mid(pos3,(long)str_url.Len()); } return true; @@ -201,8 +201,8 @@ { udp_socket_fd=socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP); int i,ret; - std::string send_buff=SEARCH_REQUEST_STRING; - std::string recv_buff; + FString send_buff=SEARCH_REQUEST_STRING; + FString recv_buff; char buff[MAX_BUFF_SIZE+1]; //buff should be enough big struct sockaddr_in r_address; @@ -213,7 +213,7 @@ int enable = 1; ret=setsockopt(udp_socket_fd, SOL_SOCKET, SO_BROADCAST, (const char *)&enable, sizeof(enable)); - ret=sendto(udp_socket_fd,send_buff.c_str(),send_buff.size(),0,(struct sockaddr*)&r_address,sizeof(struct sockaddr_in)); + ret=sendto(udp_socket_fd,send_buff.GetChars(),send_buff.Len(),0,(struct sockaddr*)&r_address,sizeof(struct sockaddr_in)); for(i=1;i<=time_out;i++) { @@ -228,18 +228,18 @@ } recv_buff=buff; - ret=recv_buff.find(HTTP_OK); - if(ret==(int)std::string::npos) + ret=recv_buff.IndexOf(HTTP_OK); + if(ret==(int)NPOS) continue; //invalid response - std::string::size_type begin=recv_buff.find("http://"); - if(begin==std::string::npos) + long begin=recv_buff.IndexOf("http://"); + if(begin==NPOS) continue; //invalid response - std::string::size_type end=recv_buff.find("\r",begin); - if(end==std::string::npos) + long end=recv_buff.IndexOf("\r",begin); + if(end==NPOS) continue; //invalid response - describe_url=describe_url.assign(recv_buff,begin,end-begin); + describe_url=recv_buff.Mid(begin,end-begin); if(!get_description()){ _sleep(1000); @@ -264,9 +264,9 @@ bool UPNPNAT::get_description() { - std::string host,path; + FString host,path; unsigned short int port; - int ret=parseUrl(describe_url.c_str(),host,&port,path); + int ret=parseUrl(describe_url.GetChars(),host,&port,path); if(!ret) { status=NAT_ERROR; @@ -275,21 +275,21 @@ } //connect - ret=tcp_connect(host.c_str(),port); + ret=tcp_connect(host.GetChars(),port); if(!ret){ return false; } char request[200]; - sprintf (request,"GET %s HTTP/1.1\r\nHost: %s:%d\r\n\r\n",path.c_str(),host.c_str(),port); - std::string http_request=request; + sprintf (request,"GET %s HTTP/1.1\r\nHost: %s:%d\r\n\r\n",path.GetChars(),host.GetChars(),port); + FString http_request=request; //send request - ret=send(tcp_socket_fd,http_request.c_str(),http_request.size(),0); + ret=send(tcp_socket_fd,http_request.GetChars(),http_request.Len(),0); //get description xml file char buff[MAX_BUFF_SIZE+1]; memset(buff, 0, sizeof(buff)); - std::string response; + FString response; while ( (ret=recv(tcp_socket_fd,buff,MAX_BUFF_SIZE,0) >0)) { response+=buff; @@ -303,7 +303,7 @@ bool UPNPNAT::parser_description() { - XMLNode node=XMLNode::parseString(description_info.c_str(),"root"); + XMLNode node=XMLNode::parseString(description_info.GetChars(),"root"); if(node.isEmpty()) { status=NAT_ERROR; @@ -314,14 +314,14 @@ XMLNode baseURL_node=node.getChildNode("URLBase",0); if(!baseURL_node.getText()) { - std::string::size_type index=describe_url.find("/",7); - if(index==std::string::npos ) + long index=describe_url.IndexOf("/",7); + if(index==NPOS ) { status=NAT_ERROR; last_error="Fail to get base_URL from XMLNode \"URLBase\" or describe_url.\n"; return false; } - base_url=base_url.assign(describe_url,0,index); + base_url=describe_url.Mid(0, index); } else base_url=baseURL_node.getText(); @@ -440,9 +440,9 @@ control_url=controlURL_node.getText(); //make the complete control_url; - if(control_url.find("http://")==std::string::npos&&control_url.find("HTTP://")==std::string::npos) + if(control_url.IndexOf("http://")==NPOS&&control_url.IndexOf("HTTP://")==NPOS) control_url=base_url+control_url; - if(service_describe_url.find("http://")==std::string::npos&&service_describe_url.find("HTTP://")==std::string::npos) + if(service_describe_url.IndexOf("http://")==NPOS&&service_describe_url.IndexOf("HTTP://")==NPOS) service_describe_url=base_url+service_describe_url; closesocket(tcp_socket_fd); @@ -455,9 +455,9 @@ { int ret; - std::string host,path; + FString host,path; unsigned short int port; - ret=parseUrl(control_url.c_str(),host,&port,path); + ret=parseUrl(control_url.GetChars(),host,&port,path); if(!ret) { status=NAT_ERROR; @@ -466,28 +466,28 @@ } //connect - ret=tcp_connect(host.c_str(),port); + ret=tcp_connect(host.GetChars(),port); if(!ret) return false; char buff[MAX_BUFF_SIZE+1]; sprintf(buff,ADD_PORT_MAPPING_PARAMS,_port_ex,_protocal,_port_in,_destination_ip,_description); - std::string action_params=buff; + FString action_params=buff; - sprintf(buff,SOAP_ACTION,ACTION_ADD,service_type.c_str(),action_params.c_str(),ACTION_ADD); - std::string soap_message=buff; + sprintf(buff,SOAP_ACTION,ACTION_ADD,service_type.GetChars(),action_params.GetChars(),ACTION_ADD); + FString soap_message=buff; - const char *pathString = ( ( path.c_str()[0] == '/' ) && ( path.c_str()[1] == '/' ) ) ? ( path.c_str() + 1 ) : path.c_str(); - sprintf(buff,HTTP_HEADER_ACTION,pathString,host.c_str(),port,static_cast<unsigned int>(soap_message.size()),service_type.c_str(),ACTION_ADD); - std::string action_message=buff; + const char *pathString = ( ( path.GetChars()[0] == '/' ) && ( path.GetChars()[1] == '/' ) ) ? ( path.GetChars() + 1 ) : path.GetChars(); + sprintf(buff,HTTP_HEADER_ACTION,pathString,host.GetChars(),port,static_cast<unsigned int>(soap_message.Len()),service_type.GetChars(),ACTION_ADD); + FString action_message=buff; - std::string http_request=action_message+soap_message; + FString http_request=action_message+soap_message; //send request - ret=send(tcp_socket_fd,http_request.c_str(),http_request.size(),0); + ret=send(tcp_socket_fd,http_request.GetChars(),http_request.Len(),0); //wait for response - std::string response; + FString response; memset(buff, 0, sizeof(buff)); while ((ret=recv(tcp_socket_fd,buff,MAX_BUFF_SIZE,0) >0)) { @@ -495,7 +495,7 @@ memset(buff, 0, sizeof(buff)); } - if(response.find(HTTP_OK)==std::string::npos) + if(response.IndexOf(HTTP_OK)==NPOS) { status=NAT_ERROR; char temp[100]; diff -r 7d70511f0aa5 upnpnat/upnpnat.h --- a/upnpnat/upnpnat.h Sat Jun 07 20:38:33 2014 +0300 +++ b/upnpnat/upnpnat.h Sun Jun 08 01:35:37 2014 +0200 @@ -1,8 +1,7 @@ #ifndef UPNPNAT_H #define UPNPNAT_H -#include <string> -#include <vector> +#include <zstring.h> // [Dusk] GCC complains about this #pragma #ifdef _MSC_VER @@ -28,7 +27,7 @@ ***/ bool add_port_mapping(const char * _description, const char * _destination_ip, unsigned short int _port_ex, unsigned short int _destination_port, const char * _protocal);//add port mapping - const char * get_last_error(){ return last_error.c_str();}//get last error + const char * get_last_error(){ return last_error.GetChars();}//get last error private: bool get_description(); // bool parser_description(); // @@ -51,14 +50,14 @@ NAT_STAT status; int time_out; int interval; - std::string service_type; - std::string describe_url; - std::string control_url; - std::string base_url; - std::string service_describe_url; - std::string description_info; - std::string last_error; - std::string mapping_info; + FString service_type; + FString describe_url; + FString control_url; + FString base_url; + FString service_describe_url; + FString description_info; + FString last_error; + FString mapping_info; }; #endif | ||||||||
![]() |
|
Watermelon (developer) 2014-06-08 00:47 edited on: 2014-06-08 00:48 |
As for a big discussion on this, hopefully the following questions can be answered: 1) Is it worth forever locking the std libraries out? There are a ton of useful features that I've grown accustom to over the years of using the std library. One I really liked that they added was std::regex. If we ever upgrade to C++ 11 compatibility, we'd never get to use this because we have deviated from using any std libraries. 2) The overhead, is it worth it? Since you did all the changes, can you see how much size gain we get? Is it only 10-20 kb? or is it much more? 3) Someone needs to document the equivalents of what is in ZDoom, such as (some of these we already know, like FString): String HashMap Sets Queue/Deque Priority Queue Stack Tree Iterators (for the above) I'm also worried they won't have some of the useful std lib features. While I can always code them in and add them to ZDoom... I'd have to wait for a backport to get it since it'd be way out of order. ---------------------------------------------------------- I'm not against switching to all ZDoom containers. If they are easy to work with and allow me to do what I normally can do, I personally wouldn't care at all. It looks like you did a lot of work there, so I don't want to sound like I'm against it. Just playing the Devil's advocate ;) I would definitely love the documentation (just a short one somewhere) so that I don't have to waste time trying to find out what each one does...etc. |
Torr Samaho (administrator) 2014-06-08 07:51 |
Quote from Edward-san Do you have any evidence that this is actually the case? So far I don't see any real benefit in getting rid of the std classes. In some cases I even intentionally did not use the ZDoom classes. For instance, I did not use FString anywhere in networkshared.h and networkshared.cpp so that this code can be used outside of ZDoom code, e.g. in the master server. |
Edward-san (developer) 2014-06-15 11:10 |
Okay, I reverted the changes on networkshared.*, but I have some concerns about some things: 1) the usage of std::ostream in the function QueryIPQueue::addAddress . Why don't you use "FILE *" and the "fprintf" function? (the string you print has no format, so there's no overhead from runtime checking, to begin with!); 2) std::stringstream inside some functions, when you can use safely just std::string operator+ and operator+= (all the arguments passed to '<<' are compatible with the std::string operators). 3) I can remove some useless includes (considering also point 1 and 2):
Obviously, 1) implies that masterserver should be changed by using "stderr" instead of "&std::cerr". I'll make a patch with these changes. |
Torr Samaho (administrator) 2014-06-15 17:43 |
Quote from Edward-sanWhy should I? We are not restricted to C code, so I can nicely use the STL. As I said above, I don't see any real benefit in getting rid of the STL. Quote from Edward-san Why? The code is a perfectly valid use of std::stringstream. I would even dare to say that it's more efficient than using the std::string operator+ since each call of the latter creates an extra string copy. |
Edward-san (developer) 2014-06-15 19:16 edited on: 2014-06-15 19:19 |
Quote from Torr_Samaho If there's enough reserved memory for all the strings to append to the std::string object, why should it? |
Torr Samaho (administrator) 2014-06-15 19:24 |
By design operator+ has to return a temporary copy of the combined string. That copy then is later stored into whatever you use operator= on. You don't have the problem with operator+=, but there you need multiple lines to add multiple strings. Anyway, even if using a string is as good as a stringstream here (the compiler optimizations can possibly eliminate the temporary copy), I still see absolutely no reason not to use the stringstream. |
Edward-san (developer) 2020-05-05 21:45 |
Actually, after a long time I realized that this idea is not good. If the internal code must be separated from the game code, this would hinder the process. Closing this. |
This issue is already marked as resolved. If you feel that is not the case, please reopen it and explain why. |
|
Supporters: | No one explicitly supports this issue yet. |
Opponents: | No one explicitly opposes this issue yet. |
![]() |
|||
Date Modified | Username | Field | Change |
2014-06-08 00:14 | Edward-san | New Issue | |
2014-06-08 00:14 | Edward-san | Status | new => assigned |
2014-06-08 00:14 | Edward-san | Assigned To | => Edward-san |
2014-06-08 00:14 | Edward-san | File Added: huge_std_convert.diff | |
2014-06-08 00:14 | Edward-san | Status | assigned => feedback |
2014-06-08 00:21 | Dusk | Status | feedback => needs review |
2014-06-08 00:47 | Watermelon | Note Added: 0008896 | |
2014-06-08 00:48 | Watermelon | Note Edited: 0008896 | View Revisions |
2014-06-08 00:48 | Watermelon | Note Edited: 0008896 | View Revisions |
2014-06-08 07:51 | Torr Samaho | Note Added: 0008903 | |
2014-06-08 07:52 | Torr Samaho | Status | needs review => feedback |
2014-06-15 11:10 | Edward-san | Note Added: 0009369 | |
2014-06-15 11:10 | Edward-san | Status | feedback => assigned |
2014-06-15 17:43 | Torr Samaho | Note Added: 0009471 | |
2014-06-15 19:16 | Edward-san | Note Added: 0009478 | |
2014-06-15 19:19 | Edward-san | Note Edited: 0009478 | View Revisions |
2014-06-15 19:24 | Torr Samaho | Note Added: 0009479 | |
2020-05-05 21:45 | Edward-san | Note Added: 0021311 | |
2020-05-05 21:45 | Edward-san | Status | assigned => closed |
2020-05-05 21:45 | Edward-san | Assigned To | Edward-san => |
2020-05-05 21:45 | Edward-san | Resolution | open => invalid |
Copyright © 2012-2025, Torr Samaho & Zandronum Team.
Doom and Doom II are the property of id Software.
Copyright © 2000 - 2025 MantisBT Team |