From 5957b4f9bca5fe110815cf96fbf46b886b871795 Mon Sep 17 00:00:00 2001 From: charles <128108973+OldFoolAgain@users.noreply.github.com> Date: Wed, 30 Aug 2023 11:00:11 -0400 Subject: [PATCH 1/3] strutil replacement --- make/VS2017/uox3.vcxproj | 3 +- make/VS2017/uox3.vcxproj.filters | 7 +- make/VS2022/uox3.vcxproj | 5 +- make/VS2022/uox3.vcxproj.filters | 9 +- make/XCode/uox3.xcodeproj/project.pbxproj | 26 +- make/cmake/CMakeLists.txt | 2 + source/CGump.cpp | 10 +- source/CJSMapping.cpp | 36 +- source/CPacketReceive.cpp | 27 +- source/CPacketSend.cpp | 113 ++-- source/CResponse.cpp | 76 +-- source/Dictionary.cpp | 11 +- source/JSEncapsulate.cpp | 8 +- source/SEFunctions.cpp | 50 +- source/StringUtility.cpp | 198 +------ source/StringUtility.hpp | 90 ---- source/UOXJSMethods.cpp | 131 ++--- source/UOXJSPropertyFuncs.cpp | 126 ++--- source/ai.cpp | 3 +- source/archive.cpp | 7 +- source/boats.cpp | 13 +- source/books.cpp | 28 +- source/cAccountClass.cpp | 142 ++--- source/cBaseObject.cpp | 132 ++--- source/cChar.cpp | 251 ++++----- source/cConsole.cpp | 60 +-- source/cGuild.cpp | 62 +-- source/cHTMLSystem.cpp | 58 ++- source/cItem.cpp | 228 +++++---- source/cMultiObj.cpp | 46 +- source/cPlayerAction.cpp | 49 +- source/cRaces.cpp | 33 +- source/cScript.cpp | 18 +- source/cServerData.cpp | 106 ++-- source/cServerDefinitions.cpp | 19 +- source/cSocket.cpp | 36 +- source/cSpawnRegion.cpp | 32 +- source/cWeather.cpp | 16 +- source/cmdtable.cpp | 73 +-- source/commands.cpp | 15 +- source/effect.cpp | 46 +- source/fileio.cpp | 101 ++-- source/funcdecl.h | 3 +- source/gumps.cpp | 338 ++++++------ source/house.cpp | 43 +- source/items.cpp | 211 ++++---- source/jail.cpp | 9 +- source/magic.cpp | 54 +- source/mapstuff.cpp | 23 +- source/movement.cpp | 52 +- source/msgboard.cpp | 45 +- source/network.cpp | 37 +- source/npcs.cpp | 169 +++--- source/pcmanage.cpp | 30 +- source/regions.cpp | 38 +- source/scriptc.cpp | 13 +- source/skills.cpp | 69 +-- source/sound.cpp | 5 +- source/speech.cpp | 21 +- source/ssection.cpp | 27 +- source/targeting.cpp | 37 +- source/townregion.cpp | 200 ++++---- source/typedefs.h | 4 +- source/uox3.cpp | 27 +- source/utility/strutil.hpp | 598 ++++++++++++++++++++++ source/wholist.cpp | 50 +- source/worldmain.cpp | 4 +- 67 files changed, 2516 insertions(+), 2093 deletions(-) create mode 100644 source/utility/strutil.hpp diff --git a/make/VS2017/uox3.vcxproj b/make/VS2017/uox3.vcxproj index b712ba8ea..eee0072e3 100644 --- a/make/VS2017/uox3.vcxproj +++ b/make/VS2017/uox3.vcxproj @@ -1442,6 +1442,7 @@ + @@ -1468,4 +1469,4 @@ - \ No newline at end of file + diff --git a/make/VS2017/uox3.vcxproj.filters b/make/VS2017/uox3.vcxproj.filters index b5955147c..866ab0671 100644 --- a/make/VS2017/uox3.vcxproj.filters +++ b/make/VS2017/uox3.vcxproj.filters @@ -555,7 +555,10 @@ Header Files\Utility - + + Header Files\Utility + + Header Files\UOData @@ -581,4 +584,4 @@ Resource Files - \ No newline at end of file + diff --git a/make/VS2022/uox3.vcxproj b/make/VS2022/uox3.vcxproj index 1978d7850..e3ca192b0 100644 --- a/make/VS2022/uox3.vcxproj +++ b/make/VS2022/uox3.vcxproj @@ -278,7 +278,8 @@ - + + @@ -303,4 +304,4 @@ - \ No newline at end of file + diff --git a/make/VS2022/uox3.vcxproj.filters b/make/VS2022/uox3.vcxproj.filters index e23a44689..e30f8963b 100644 --- a/make/VS2022/uox3.vcxproj.filters +++ b/make/VS2022/uox3.vcxproj.filters @@ -1,4 +1,4 @@ - + @@ -555,7 +555,10 @@ Header Files\Utility - + + Header Files\Utility + + Header Files\UOData @@ -581,4 +584,4 @@ Resource Files - \ No newline at end of file + diff --git a/make/XCode/uox3.xcodeproj/project.pbxproj b/make/XCode/uox3.xcodeproj/project.pbxproj index 56b55edc8..c9ad8b840 100644 --- a/make/XCode/uox3.xcodeproj/project.pbxproj +++ b/make/XCode/uox3.xcodeproj/project.pbxproj @@ -128,6 +128,7 @@ 56C9E3DB2A9C9035004D9F38 /* uox3.vcxproj */ = {isa = PBXFileReference; lastKnownFileType = text.xml; name = uox3.vcxproj; path = ../VS2017/uox3.vcxproj; sourceTree = ""; }; 56C9E3DC2A9C9035004D9F38 /* uox3.vcxproj.filters */ = {isa = PBXFileReference; lastKnownFileType = text.xml; name = uox3.vcxproj.filters; path = ../VS2017/uox3.vcxproj.filters; sourceTree = ""; }; 56C9E3DD2A9C9035004D9F38 /* uox3.sln */ = {isa = PBXFileReference; lastKnownFileType = text; name = uox3.sln; path = ../VS2017/uox3.sln; sourceTree = ""; }; + 56D6EEC32A9F7707005355FA /* strutil.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = strutil.hpp; sourceTree = ""; }; 648153C929466EF400784170 /* libjscript.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = libjscript.a; sourceTree = BUILT_PRODUCTS_DIR; }; 64A9006A293E3DA3009B54DA /* uox3 */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = uox3; sourceTree = BUILT_PRODUCTS_DIR; }; 64A90075293E3DD4009B54DA /* ai.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ai.cpp; sourceTree = ""; }; @@ -342,6 +343,14 @@ name = vs2017; sourceTree = ""; }; + 56D6EEC22A9F76DD005355FA /* utility */ = { + isa = PBXGroup; + children = ( + 56D6EEC32A9F7707005355FA /* strutil.hpp */, + ); + path = utility; + sourceTree = ""; + }; 64A90061293E3DA3009B54DA = { isa = PBXGroup; children = ( @@ -363,13 +372,14 @@ 64A90074293E3DD4009B54DA /* source */ = { isa = PBXGroup; children = ( + 56D6EEC22A9F76DD005355FA /* utility */, 64E2F795293FCE7500546A08 /* Script */, 64E2F790293FCE3800546A08 /* Base Objects */, 64E2F791293FCE4800546A08 /* Subsystem */, 64E2F792293FCE5900546A08 /* Other */, 64E2F793293FCE6200546A08 /* JS Engine */, 64E2F794293FCE6C00546A08 /* Network */, - 64E2F797293FCE8C00546A08 /* Utility */, + 64E2F797293FCE8C00546A08 /* OldUtility */, 64E2F796293FCE8400546A08 /* UOData */, 64A90089293E3DD4009B54DA /* Changelog.txt */, 64A90103293E3DD4009B54DA /* uox3.cpp */, @@ -586,7 +596,7 @@ name = UOData; sourceTree = ""; }; - 64E2F797293FCE8C00546A08 /* Utility */ = { + 64E2F797293FCE8C00546A08 /* OldUtility */ = { isa = PBXGroup; children = ( 64A900BD293E3DD4009B54DA /* EventTimer.cpp */, @@ -596,7 +606,7 @@ 64A900FB293E3DD4009B54DA /* TimeUtility.cpp */, 64A900FC293E3DD4009B54DA /* TimeUtility.hpp */, ); - name = Utility; + name = OldUtility; sourceTree = ""; }; /* End PBXGroup section */ @@ -891,7 +901,10 @@ ../../source, ../../spidermonkey, ); - WARNING_CFLAGS = "-Wno-shift-negative-value"; + WARNING_CFLAGS = ( + "-Wno-shift-negative-value", + "-Wno-format-security", + ); }; name = Debug; }; @@ -911,7 +924,10 @@ ../../source, ../../spidermonkey, ); - WARNING_CFLAGS = "-Wno-shift-negative-value"; + WARNING_CFLAGS = ( + "-Wno-shift-negative-value", + "-Wno-format-security", + ); }; name = Release; }; diff --git a/make/cmake/CMakeLists.txt b/make/cmake/CMakeLists.txt index 34ae0cbc1..bb4aa0d29 100644 --- a/make/cmake/CMakeLists.txt +++ b/make/cmake/CMakeLists.txt @@ -166,6 +166,7 @@ add_executable(uox3 ../../source/TimeUtility.hpp ../../source/EventTimer.cpp ../../source/EventTimer.hpp + ../../source/utility/strutil.hpp # UOData group ../../source/mapclasses.h ../../source/mapstuff.cpp @@ -211,6 +212,7 @@ else() -funsigned-char -Wno-shift-negative-value -Wno-deprecated-declarations + -Wno-format-security ) if (APPLE) # We always use the system zlib , as it is most likely better optimized diff --git a/source/CGump.cpp b/source/CGump.cpp index 65c323966..99844741b 100644 --- a/source/CGump.cpp +++ b/source/CGump.cpp @@ -112,7 +112,7 @@ void CGump::SetSerial( UI32 newSerial ) //o------------------------------------------------------------------------------------------------o void CGump::AddBackground( UI16 x, UI16 y, UI16 gumpId, UI16 width, UI16 height ) { - TagList.push_back( oldstrutil::format( "resizepic %u %u %u %u %u", x, y, gumpId, width, height )); + TagList.push_back( util::format( "resizepic %u %u %u %u %u", x, y, gumpId, width, height )); } //o------------------------------------------------------------------------------------------------o @@ -122,7 +122,7 @@ void CGump::AddBackground( UI16 x, UI16 y, UI16 gumpId, UI16 width, UI16 height //o------------------------------------------------------------------------------------------------o void CGump::AddGump( UI16 x, UI16 y, UI16 gumpId ) { - TagList.push_back( oldstrutil::format( "gumppic %u %u %u", x, y, gumpId )); + TagList.push_back( util::format( "gumppic %u %u %u", x, y, gumpId )); } //o------------------------------------------------------------------------------------------------o @@ -132,7 +132,7 @@ void CGump::AddGump( UI16 x, UI16 y, UI16 gumpId ) //o------------------------------------------------------------------------------------------------o void CGump::AddButton( UI16 x, UI16 y, UI16 imageUp, UI16 imageDown, UI16 behaviour, UI16 page, UI32 uniqueId ) { - TagList.push_back( oldstrutil::format( "button %u %u %u %u %u %u %u", x, y, imageUp, imageDown, behaviour, page, uniqueId )); + TagList.push_back( util::format( "button %u %u %u %u %u %u %u", x, y, imageUp, imageDown, behaviour, page, uniqueId )); } //o------------------------------------------------------------------------------------------------o @@ -145,7 +145,7 @@ void CGump::AddText( UI16 x, UI16 y, UI16 hue, std::string text ) UI32 textId = static_cast( TextList.size() ); TextList.push_back( text ); - TagList.push_back( oldstrutil::format( "text %u %u %u %u", x, y, hue, textId )); + TagList.push_back( util::format( "text %u %u %u %u", x, y, hue, textId )); } //o------------------------------------------------------------------------------------------------o @@ -155,7 +155,7 @@ void CGump::AddText( UI16 x, UI16 y, UI16 hue, std::string text ) //o------------------------------------------------------------------------------------------------o UI16 CGump::StartPage( void ) { - TagList.push_back( oldstrutil::format( "page %u", PageCount )); + TagList.push_back( util::format( "page %u", PageCount )); ++PageCount; return PageCount - 1; diff --git a/source/CJSMapping.cpp b/source/CJSMapping.cpp index 6bb4a63eb..4109ee9c4 100644 --- a/source/CJSMapping.cpp +++ b/source/CJSMapping.cpp @@ -4,6 +4,8 @@ #include "scriptc.h" #include "ssection.h" #include "StringUtility.hpp" +#include "utility/strutil.hpp" + #include using namespace std::string_literals; @@ -100,7 +102,7 @@ void CJSMapping::Reload( UI16 scriptId ) { if( scriptId != 0xFFFF ) { - Console.Print( oldstrutil::format( "CMD: Attempting Reload of JavaScript (ScriptId %u)\n", scriptId )); + Console.Print( util::format( "CMD: Attempting Reload of JavaScript (ScriptId %u)\n", scriptId )); for( size_t i = SCPT_NORMAL; i < SCPT_COUNT; ++i ) { if( mapSection[i]->IsInMap( scriptId )) @@ -109,11 +111,11 @@ void CJSMapping::Reload( UI16 scriptId ) return; } } - Console.Warning( oldstrutil::format( "Unable to locate specified JavaScript in the map (ScriptId %u)", scriptId )); + Console.Warning( util::format( "Unable to locate specified JavaScript in the map (ScriptId %u)", scriptId )); } else { - Console.Print( oldstrutil::format( "CMD: Loading JSE Scripts... \n" )); + Console.Print( util::format( "CMD: Loading JSE Scripts... \n" )); Cleanup(); ResetDefaults(); envokeById->Parse(); @@ -129,7 +131,7 @@ void CJSMapping::Reload( UI16 scriptId ) //o------------------------------------------------------------------------------------------------o void CJSMapping::Reload( SCRIPTTYPE sectionId ) { - Console.Print( oldstrutil::format( "CMD: Attempting Reload of JavaScript (SectionId %u)\n", static_cast( sectionId ))); + Console.Print( util::format( "CMD: Attempting Reload of JavaScript (SectionId %u)\n", static_cast( sectionId ))); if( mapSection[sectionId] != nullptr ) { delete mapSection[sectionId]; @@ -153,7 +155,7 @@ void CJSMapping::Parse( SCRIPTTYPE toParse ) std::string scpFileName = cwmWorldState->ServerData()->Directory( CSDDP_SCRIPTS ) + "jse_fileassociations.scp"; if( !FileExists( scpFileName )) { - Console.Error( oldstrutil::format( "Failed to open %s", scpFileName.c_str() )); + Console.Error( util::format( "Failed to open %s", scpFileName.c_str() )); return; } @@ -345,7 +347,7 @@ auto CJSMappingSection::Parse( Script *fileAssocData ) -> void if( !FileExists( fullPath )) { - Console.Error( oldstrutil::format( "SE mapping of %i to %s failed, file does not exist!", scriptId, data.c_str() )); + Console.Error( util::format( "SE mapping of %i to %s failed, file does not exist!", scriptId, data.c_str() )); } else { @@ -361,22 +363,22 @@ auto CJSMappingSection::Parse( Script *fileAssocData ) -> void } catch( std::runtime_error &e ) { - Console.Error( oldstrutil::format( "Compiling %s caused a construction failure (Details: %s)", fullPath.c_str(), e.what() )); + Console.Error( util::format( "Compiling %s caused a construction failure (Details: %s)", fullPath.c_str(), e.what() )); } } } Console.Print( " o Loaded " ); Console.TurnYellow(); - Console.Print( oldstrutil::format( "%4u ", i )); + Console.Print( util::format( "%4u ", i )); Console.TurnNormal(); Console.Print( "scripts from section " ); Console.TurnYellow(); - Console.Print( oldstrutil::format( "%s\n", ScriptNames[scriptType].c_str() )); + Console.Print( util::format( "%s\n", ScriptNames[scriptType].c_str() )); Console.TurnNormal(); } else { - Console.Warning( oldstrutil::format( "No JS file mappings found in section %s", ScriptNames[scriptType].c_str() )); + Console.Warning( util::format( "No JS file mappings found in section %s", ScriptNames[scriptType].c_str() )); } } @@ -391,7 +393,7 @@ auto CJSMappingSection::Reload( UI16 toLoad ) -> void auto scpFileName = cwmWorldState->ServerData()->Directory( CSDDP_SCRIPTS ) + "jse_fileassociations.scp"s; if( !FileExists( scpFileName )) { - Console.Error( oldstrutil::format( "Failed to open %s", scpFileName.c_str() )); + Console.Error( util::format( "Failed to open %s", scpFileName.c_str() )); return; } @@ -420,7 +422,7 @@ auto CJSMappingSection::Reload( UI16 toLoad ) -> void if( !FileExists( fullPath )) { - Console.Error( oldstrutil::format( "SE mapping of %i to %s failed, file does not exist!", scriptId, data.c_str() )); + Console.Error( util::format( "SE mapping of %i to %s failed, file does not exist!", scriptId, data.c_str() )); } else { @@ -447,22 +449,22 @@ auto CJSMappingSection::Reload( UI16 toLoad ) -> void { scriptIdMap[scriptId] = toAdd; scriptJSMap[toAdd->Object()] = scriptId; - Console.Print( oldstrutil::format( "Reload of JavaScript (ScriptId %u) Successful\n", toLoad )); + Console.Print( util::format( "Reload of JavaScript (ScriptId %u) Successful\n", toLoad )); } } catch( std::runtime_error &e ) { - Console.Error( oldstrutil::format( "Compiling %s caused a construction failure (Details: %s)", fullPath.c_str(), e.what() )); + Console.Error( util::format( "Compiling %s caused a construction failure (Details: %s)", fullPath.c_str(), e.what() )); } } return; } } - Console.Warning( oldstrutil::format( "Unable to locate the specified JavaScript in the file (ScriptId %u)", toLoad )); + Console.Warning( util::format( "Unable to locate the specified JavaScript in the file (ScriptId %u)", toLoad )); } else { - Console.Warning( oldstrutil::format( "No JS file mappings found in section %s", ScriptNames[scriptType].c_str() )); + Console.Warning( util::format( "No JS file mappings found in section %s", ScriptNames[scriptType].c_str() )); } } } @@ -660,7 +662,7 @@ auto CEnvoke::Parse() -> void } else { - Console.Error( oldstrutil::format( "(ENVOKE) Item %s refers to scriptId %u which does not exist.", tag.c_str(), scriptId )); + Console.Error( util::format( "(ENVOKE) Item %s refers to scriptId %u which does not exist.", tag.c_str(), scriptId )); } } } diff --git a/source/CPacketReceive.cpp b/source/CPacketReceive.cpp index 945511bd1..cb5b9c1a1 100644 --- a/source/CPacketReceive.cpp +++ b/source/CPacketReceive.cpp @@ -17,6 +17,7 @@ #include "cGuild.h" #include "CResponse.h" #include "StringUtility.hpp" +#include "utility/strutil.hpp" #include "cRaces.h" #include #include "IP4Address.hpp" @@ -347,7 +348,7 @@ bool CPIFirstLogin::Handle( void ) if( tSock->AcctNo() != AB_INVALID_ID ) { actbTemp->dwLastIP = CalcSerial( tSock->ClientIP4(), tSock->ClientIP3(), tSock->ClientIP2(), tSock->ClientIP1() ); - auto temp = oldstrutil::format( "Client [%i.%i.%i.%i] connected using Account '%s'.", tSock->ClientIP4(), tSock->ClientIP3(), tSock->ClientIP2(), tSock->ClientIP1(), username.c_str() ); + auto temp = util::format( "Client [%i.%i.%i.%i] connected using Account '%s'.", tSock->ClientIP4(), tSock->ClientIP3(), tSock->ClientIP2(), tSock->ClientIP1(), username.c_str() ); Console.Log( temp , "server.log" ); messageLoop << temp; @@ -718,9 +719,9 @@ void CPINewClientVersion::Receive( void ) clientPrototype = tSock->GetDWord( 17 ); tSock->ClientVersion( majorVersion, minorVersion, clientRevision, clientPrototype ); - std::string verString = oldstrutil::number( majorVersion ) + std::string( "." ) + - oldstrutil::number( minorVersion ) + std::string( ". ") + oldstrutil::number( clientRevision ) + - std::string( "." ) + oldstrutil::number( clientPrototype ); + std::string verString = util::ntos( majorVersion ) + std::string( "." ) + + util::ntos( minorVersion ) + std::string( ". ") + util::ntos( clientRevision ) + + std::string( "." ) + util::ntos( clientPrototype ); Console << verString << myendl; // Set client-version based on information received so far. We need this to be able to send the correct info during login @@ -1329,7 +1330,7 @@ auto CPITips::Handle() -> bool for( tag = tips->First(); !tips->AtEnd(); tag = tips->Next() ) { - if( !tag.empty() && oldstrutil::upper( tag ) == "TIP" ) + if( !tag.empty() && util::upper( tag ) == "TIP" ) { --x; } @@ -1344,7 +1345,7 @@ auto CPITips::Handle() -> bool } data = tips->GrabData(); - sect = "TIP " + oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )); + sect = "TIP " + util::trim( util::strip( data, "//" )); tips = FileLookup->FindEntry( sect, misc_def ); if( tips ) { @@ -2467,7 +2468,7 @@ bool CPITalkRequest::HandleCommon( void ) tempPage->Reason( Text() ); tempPage->WhoPaging( ourChar->GetSerial() ); - auto temp = oldstrutil::format( "GM Page from %s [%x %x %x %x]: %s", ourChar->GetName().c_str(), a1, a2, a3, a4, tempPage->Reason().c_str() ); + auto temp = util::format( "GM Page from %s [%x %x %x %x]: %s", ourChar->GetName().c_str(), a1, a2, a3, a4, tempPage->Reason().c_str() ); bool x = false; { for( auto &tmpSock : Network->connClients ) @@ -2506,7 +2507,7 @@ bool CPITalkRequest::HandleCommon( void ) tempPageCns = CounselorQueue->Current(); tempPageCns->Reason( Text() ); tempPageCns->WhoPaging( ourChar->GetSerial() ); - auto temp = oldstrutil::format( "Counselor Page from %s [%x %x %x %x]: %s", ourChar->GetName().c_str(), a1, a2, a3, a4, tempPageCns->Reason().c_str() ); + auto temp = util::format( "Counselor Page from %s [%x %x %x %x]: %s", ourChar->GetName().c_str(), a1, a2, a3, a4, tempPageCns->Reason().c_str() ); bool x = false; { for( auto &tmpSock : Network->connClients ) @@ -3025,7 +3026,7 @@ void CPICreateCharacter::Create3DCharacter( void ) { if( ValidateObject( tSock->CurrcharObj() )) { - Console.Error( oldstrutil::format( "CreateCharacter packet 0x8D detected for socket with pre-existing character (%i) attached. Disconnecting socket as safeguard against corruption!", tSock->CurrcharObj()->GetSerial() )); + Console.Error( util::format( "CreateCharacter packet 0x8D detected for socket with pre-existing character (%i) attached. Disconnecting socket as safeguard against corruption!", tSock->CurrcharObj()->GetSerial() )); Network->Disconnect( tSock ); return; } @@ -3124,7 +3125,7 @@ void CPICreateCharacter::Create2DCharacter( void ) { if( ValidateObject( tSock->CurrcharObj() )) { - Console.Error( oldstrutil::format( "CreateCharacter packet 0x00 or 0xF8 detected for socket with pre-existing character (%i) attached. Disconnecting socket as safeguard against corruption!", tSock->CurrcharObj()->GetSerial() )); + Console.Error( util::format( "CreateCharacter packet 0x00 or 0xF8 detected for socket with pre-existing character (%i) attached. Disconnecting socket as safeguard against corruption!", tSock->CurrcharObj()->GetSerial() )); Network->Disconnect( tSock ); return; } @@ -3975,7 +3976,7 @@ void CPISubcommands::Receive( void ) case 0x0C: { subPacket = new CPIClosedStatusGump( tSock ); } break; // Closed Status Gump case 0x0F: skipOver = true; break; // Unknown, Sent once at Login case 0x24: skipOver = true; break; - default: Console.Print( oldstrutil::format( "Packet 0xBF: Unhandled Subcommand: 0x%X\n", subCmd )); skipOver = true; break; + default: Console.Print( util::format( "Packet 0xBF: Unhandled Subcommand: 0x%X\n", subCmd )); skipOver = true; break; case 0x06: { subPacket = new CPIPartyCommand( tSock ); } break; case 0x07: { subPacket = new CPITrackingArrow( tSock ); } break; // Click on Quest/Tracking Arrow case 0x0B: { subPacket = new CPIClientLanguage( tSock ); } break; // Client language. 3 bytes. "ENU" for english @@ -4705,7 +4706,7 @@ bool CPIPopupMenuSelect::Handle( void ) } else { - Console.Warning( oldstrutil::format( "Character 0x%X has no backpack!", targChar->GetSerial() )); + Console.Warning( util::format( "Character 0x%X has no backpack!", targChar->GetSerial() )); } } } @@ -5087,7 +5088,7 @@ bool CPIPopupMenuSelect::Handle( void ) } break; default: - Console.Print( oldstrutil::format( "Popup Menu Selection Called, Player: 0x%X Selection: 0x%X\n", tSock->GetDWord( 5 ), tSock->GetWord( 9 ))); + Console.Print( util::format( "Popup Menu Selection Called, Player: 0x%X Selection: 0x%X\n", tSock->GetDWord( 5 ), tSock->GetWord( 9 ))); break; } diff --git a/source/CPacketSend.cpp b/source/CPacketSend.cpp index 5756b38da..388a79eb1 100644 --- a/source/CPacketSend.cpp +++ b/source/CPacketSend.cpp @@ -18,6 +18,7 @@ #include #include #include "osunique.hpp" +#include "utility/strutil.hpp" #if defined(_WIN32) #include #endif @@ -1945,7 +1946,7 @@ void CPOpenGump::Question( std::string toAdd ) #if defined( UOX_DEBUG_MODE ) if( toAdd.length() >= 255 ) { - Console.Error( oldstrutil::format( "CPOpenGump::Question toAdd.length() is too long (%i)", toAdd.length() )); + Console.Error( util::format( "CPOpenGump::Question toAdd.length() is too long (%i)", toAdd.length() )); } #endif pStream.WriteByte( 9, static_cast( toAdd.length() + 1 )); @@ -1958,7 +1959,7 @@ void CPOpenGump::AddResponse( UI16 modelNum, UI16 colour, std::string responseTe #if defined( UOX_DEBUG_MODE ) if( responseText.length() >= 255 ) { - Console.Error( oldstrutil::format( "CPOpenGump::AddResponse responseText is too long (%i)", responseText.length() )); + Console.Error( util::format( "CPOpenGump::AddResponse responseText is too long (%i)", responseText.length() )); } #endif UI16 toAdd = static_cast( 5 + responseText.length() ); @@ -4740,10 +4741,10 @@ void CPOpenBuyWindow::AddItem( CItem *toAdd, CTownRegion *tReg, UI16 &baseOffset itemname.reserve( MAX_NAME ); UI08 sLen = 0; std::string temp = toAdd->GetName(); - temp = oldstrutil::simplify(temp); + temp = util::simplify(temp); if( temp.substr( 0, 1 ) == "#" ) { - itemname = oldstrutil::number( 1020000 + toAdd->GetId() ); + itemname = util::ntos( 1020000 + toAdd->GetId() ); sLen = static_cast( itemname.size() + 1 ); } else @@ -7184,24 +7185,24 @@ void CPToolTip::CopyItemData( CItem& cItem, size_t &totalStringLen, bool addAmou GetTileName( cItem, temp ); if( cItem.GetAmount() > 1 && addAmount ) { - tempEntry.ourText = oldstrutil::format( " \t%s : %i\t ", temp.c_str(), cItem.GetAmount() ); + tempEntry.ourText = util::format( " \t%s : %i\t ", temp.c_str(), cItem.GetAmount() ); } else { - tempEntry.ourText = oldstrutil::format( " \t%s\t ", temp.c_str() ); + tempEntry.ourText = util::format( " \t%s\t ", temp.c_str() ); } } else { if( cItem.GetAmount() > 1 && !cItem.IsCorpse() && addAmount && cItem.GetType() != IT_SPAWNCONT && cItem.GetType() != IT_LOCKEDSPAWNCONT && cItem.GetType() != IT_UNLOCKABLESPAWNCONT ) { - tempEntry.ourText = oldstrutil::format( " \t%s : %i\t ", cItemName.c_str(), cItem.GetAmount() ); + tempEntry.ourText = util::format( " \t%s : %i\t ", cItemName.c_str(), cItem.GetAmount() ); } else { if( cwmWorldState->ServerData()->RankSystemStatus() && cItem.GetRank() == 10 ) { - tempEntry.ourText = oldstrutil::format(" \t%s %s\t ", cItemName.c_str(), Dictionary->GetEntry( 9140, tSock->Language() ).c_str() ); // %s of exceptional quality + tempEntry.ourText = util::format(" \t%s %s\t ", cItemName.c_str(), Dictionary->GetEntry( 9140, tSock->Language() ).c_str() ); // %s of exceptional quality } else { @@ -7229,11 +7230,11 @@ void CPToolTip::CopyItemData( CItem& cItem, size_t &totalStringLen, bool addAmou } } - tempEntry.ourText = oldstrutil::format( " \t%s\t ", iFlagColor.c_str(), cItemName.c_str() ); + tempEntry.ourText = util::format( " \t%s\t ", iFlagColor.c_str(), cItemName.c_str() ); } else { - tempEntry.ourText = oldstrutil::format( " \t%s\t ", cItemName.c_str() ); + tempEntry.ourText = util::format( " \t%s\t ", cItemName.c_str() ); } } } @@ -7250,8 +7251,8 @@ void CPToolTip::CopyItemData( CItem& cItem, size_t &totalStringLen, bool addAmou if( ValidateObject( cItemCreator )) { tempEntry.stringNum = 1042971; // ~1_NOTHING~ - tempEntry.ourText = oldstrutil::format( "%s by %s", cwmWorldState->skill[cItem.GetMadeWith()-1].madeWord.c_str(), cItemCreator->GetName().c_str() ); // tailored/tinkered/forged by %s - //tempEntry.ourText = oldstrutil::format( "%s %s", Dictionary->GetEntry( 9141, tSock->Language() ).c_str(), cItemCreator->GetName().c_str() ); // Crafted by %s + tempEntry.ourText = util::format( "%s by %s", cwmWorldState->skill[cItem.GetMadeWith()-1].madeWord.c_str(), cItemCreator->GetName().c_str() ); // tailored/tinkered/forged by %s + //tempEntry.ourText = util::format( "%s %s", Dictionary->GetEntry( 9141, tSock->Language() ).c_str(), cItemCreator->GetName().c_str() ); // Crafted by %s FinalizeData( tempEntry, totalStringLen ); } } @@ -7277,20 +7278,20 @@ void CPToolTip::CopyItemData( CItem& cItem, size_t &totalStringLen, bool addAmou if( !itemTownRegion->IsGuarded() && !itemTownRegion->IsSafeZone() ) { tempEntry.stringNum = 1042971; // ~1_NOTHING~ - tempEntry.ourText = oldstrutil::format( "%s", Dictionary->GetEntry( 9051, tSock->Language() ).c_str() ); // [Guarded] + tempEntry.ourText = util::format( "%s", Dictionary->GetEntry( 9051, tSock->Language() ).c_str() ); // [Guarded] FinalizeData( tempEntry, totalStringLen ); } } if( cItem.IsNewbie() ) { tempEntry.stringNum = 1042971; // ~1_NOTHING~ - tempEntry.ourText = oldstrutil::format( "%s", Dictionary->GetEntry( 9055, tSock->Language() ).c_str() ); // [Blessed] + tempEntry.ourText = util::format( "%s", Dictionary->GetEntry( 9055, tSock->Language() ).c_str() ); // [Blessed] FinalizeData( tempEntry, totalStringLen ); } if( cItem.GetType() == IT_LOCKEDDOOR ) { tempEntry.stringNum = 1042971; // ~1_NOTHING~ - tempEntry.ourText = oldstrutil::format( "%s", Dictionary->GetEntry( 9050, tSock->Language() ).c_str() ); // [Locked] + tempEntry.ourText = util::format( "%s", Dictionary->GetEntry( 9050, tSock->Language() ).c_str() ); // [Locked] FinalizeData( tempEntry, totalStringLen ); } @@ -7355,28 +7356,28 @@ void CPToolTip::CopyItemData( CItem& cItem, size_t &totalStringLen, bool addAmou if( cItem.GetType() == IT_LOCKEDCONTAINER ) { tempEntry.stringNum = 1042971; // ~1_NOTHING~ - tempEntry.ourText = oldstrutil::format( "%s", Dictionary->GetEntry( 9050 ).c_str(), tSock->Language() ); // [Locked] + tempEntry.ourText = util::format( "%s", Dictionary->GetEntry( 9050 ).c_str(), tSock->Language() ); // [Locked] FinalizeData( tempEntry, totalStringLen ); } tempEntry.stringNum = 1050044; // ~1_COUNT~ items, ~2_WEIGHT~ stones - //tempEntry.ourText = oldstrutil::format( "%u\t%i", cItem.GetContainsList()->Num(), ( cItem.GetWeight() / 100 )); - tempEntry.ourText = oldstrutil::format( "%u\t%i", GetTotalItemCount( &cItem ), ( cItem.GetWeight() / 100 )); + //tempEntry.ourText = util::format( "%u\t%i", cItem.GetContainsList()->Num(), ( cItem.GetWeight() / 100 )); + tempEntry.ourText = util::format( "%u\t%i", GetTotalItemCount( &cItem ), ( cItem.GetWeight() / 100 )); FinalizeData( tempEntry, totalStringLen ); if(( cItem.GetWeightMax() / 100 ) >= 1 ) { tempEntry.stringNum = 1072226; // Capacity: ~1_COUNT~ items, ~2_WEIGHT~ stones - tempEntry.ourText = oldstrutil::format( "%u\t%i", cItem.GetMaxItems(), ( cItem.GetWeightMax() / 100 )); + tempEntry.ourText = util::format( "%u\t%i", cItem.GetMaxItems(), ( cItem.GetWeightMax() / 100 )); //tempEntry.stringNum = 1060658; - //tempEntry.ourText = oldstrutil::format( "Capacity\t%i Stones", ( cItem.GetWeightMax() / 100 )); + //tempEntry.ourText = util::format( "Capacity\t%i Stones", ( cItem.GetWeightMax() / 100 )); FinalizeData( tempEntry, totalStringLen ); } } else if( cItem.GetType() == IT_LOCKEDSPAWNCONT ) { tempEntry.stringNum = 1050045; // ~1_PREFIX~~2_NAME~~3_SUFFIX~ - tempEntry.ourText = oldstrutil::format( " \t%s\t ", Dictionary->GetEntry( 9050 ).c_str(), tSock->Language() ); // [Locked] + tempEntry.ourText = util::format( " \t%s\t ", Dictionary->GetEntry( 9050 ).c_str(), tSock->Language() ); // [Locked] FinalizeData( tempEntry, totalStringLen ); } else if( cItem.GetType() == IT_HOUSESIGN ) @@ -7395,7 +7396,7 @@ void CPToolTip::CopyItemData( CItem& cItem, size_t &totalStringLen, bool addAmou else if( !cItem.IsCorpse() && cItem.GetType() != IT_POTION && cItem.GetSectionId() != "potionkeg" && cItem.GetName2() != "#" && cItem.GetName2() != "" ) { tempEntry.stringNum = 1050045; // ~1_PREFIX~~2_NAME~~3_SUFFIX~ - tempEntry.ourText = oldstrutil::format( " \t%s\t ", Dictionary->GetEntry( 9402 ).c_str(), tSock->Language() ); // [Unidentified] + tempEntry.ourText = util::format( " \t%s\t ", Dictionary->GetEntry( 9402 ).c_str(), tSock->Language() ); // [Unidentified] FinalizeData( tempEntry, totalStringLen ); } else if( cItem.GetType() == IT_RECALLRUNE && cItem.GetTempVar( CITV_MOREX ) != 0 && cItem.GetTempVar( CITV_MOREY ) != 0 ) @@ -7443,18 +7444,18 @@ void CPToolTip::CopyItemData( CItem& cItem, size_t &totalStringLen, bool addAmou if( cItem.GetType() == IT_ITEMSPAWNER || cItem.GetType() == IT_NPCSPAWNER ) { - tempEntry.ourText = oldstrutil::number(( cItem.GetWeight() / 100 )); + tempEntry.ourText = util::ntos(( cItem.GetWeight() / 100 )); } else { CItem *cItemCont = static_cast( cItem.GetCont() ); if( ValidateObject( cItemCont ) && cItemCont->GetLayer() == IL_SELLCONTAINER ) { - tempEntry.ourText = oldstrutil::number(( cItem.GetWeight() / 100 )); + tempEntry.ourText = util::ntos(( cItem.GetWeight() / 100 )); } else { - tempEntry.ourText = oldstrutil::number(( cItem.GetWeight() / 100 ) * cItem.GetAmount() ); + tempEntry.ourText = util::ntos(( cItem.GetWeight() / 100 ) * cItem.GetAmount() ); } } FinalizeData( tempEntry, totalStringLen ); @@ -7462,7 +7463,7 @@ void CPToolTip::CopyItemData( CItem& cItem, size_t &totalStringLen, bool addAmou if( cItem.GetType() == IT_MAGICWAND && cItem.GetTempVar( CITV_MOREZ )) { tempEntry.stringNum = 1060584; // uses remaining: ~1_val~ - tempEntry.ourText = oldstrutil::number( cItem.GetTempVar( CITV_MOREZ )); + tempEntry.ourText = util::ntos( cItem.GetTempVar( CITV_MOREZ )); FinalizeData( tempEntry, totalStringLen ); } @@ -7478,68 +7479,68 @@ void CPToolTip::CopyItemData( CItem& cItem, size_t &totalStringLen, bool addAmou if( cItem.GetWeatherDamage( PHYSICAL )) { tempEntry.stringNum = 1060403; // physical damage ~1_val~% - tempEntry.ourText = oldstrutil::number( 100 ); + tempEntry.ourText = util::ntos( 100 ); FinalizeData( tempEntry, totalStringLen ); } else if( cItem.GetWeatherDamage( LIGHT )) { tempEntry.stringNum = 1042971; // ~1_NOTHING~ - tempEntry.ourText = oldstrutil::format( "light damage: 100%" ); + tempEntry.ourText = util::format( "light damage: 100%" ); FinalizeData( tempEntry, totalStringLen ); } else if( cItem.GetWeatherDamage( RAIN )) { tempEntry.stringNum = 1042971; // ~1_NOTHING~ - tempEntry.ourText = oldstrutil::format( "rain damage: 100%" ); + tempEntry.ourText = util::format( "rain damage: 100%" ); FinalizeData( tempEntry, totalStringLen ); } else if( cItem.GetWeatherDamage( COLD )) { tempEntry.stringNum = 1060403; // cold damage ~1_val~% - tempEntry.ourText = oldstrutil::number( 100 ); + tempEntry.ourText = util::ntos( 100 ); FinalizeData( tempEntry, totalStringLen ); } else if( cItem.GetWeatherDamage( HEAT )) { tempEntry.stringNum = 1042971; // ~1_NOTHING~ - tempEntry.ourText = oldstrutil::format( "fire damage: 100%" ); + tempEntry.ourText = util::format( "fire damage: 100%" ); FinalizeData( tempEntry, totalStringLen ); } else if( cItem.GetWeatherDamage( LIGHTNING )) { tempEntry.stringNum = 1060407; // energy damage ~1_val~% - tempEntry.ourText = oldstrutil::number( 100 ); + tempEntry.ourText = util::ntos( 100 ); FinalizeData( tempEntry, totalStringLen ); } else if( cItem.GetWeatherDamage( POISON )) { tempEntry.stringNum = 1060406; // energy damage ~1_val~% - tempEntry.ourText = oldstrutil::number( 100 ); + tempEntry.ourText = util::ntos( 100 ); FinalizeData( tempEntry, totalStringLen ); } else if( cItem.GetWeatherDamage( SNOW )) { tempEntry.stringNum = 1042971; // ~1_NOTHING~ - tempEntry.ourText = oldstrutil::format( "snow damage: 100%" ); + tempEntry.ourText = util::format( "snow damage: 100%" ); FinalizeData( tempEntry, totalStringLen ); } else if( cItem.GetWeatherDamage( STORM )) { tempEntry.stringNum = 1042971; // ~1_NOTHING~ - tempEntry.ourText = oldstrutil::format( "storm damage: 100%" ); + tempEntry.ourText = util::format( "storm damage: 100%" ); FinalizeData( tempEntry, totalStringLen ); } } tempEntry.stringNum = 1061168; // weapon damage ~1_val~ - ~2_val~ - tempEntry.ourText = oldstrutil::format( "%i\t%i", cItem.GetLoDamage(), cItem.GetHiDamage() ); + tempEntry.ourText = util::format( "%i\t%i", cItem.GetLoDamage(), cItem.GetHiDamage() ); FinalizeData( tempEntry, totalStringLen ); } if( cItem.GetSpeed() > 0 ) { tempEntry.stringNum = 1061167; // weapon speed ~1_val~ - tempEntry.ourText = oldstrutil::number( cItem.GetSpeed() ); + tempEntry.ourText = util::ntos( cItem.GetSpeed() ); FinalizeData( tempEntry, totalStringLen ); } @@ -7584,35 +7585,35 @@ void CPToolTip::CopyItemData( CItem& cItem, size_t &totalStringLen, bool addAmou if( cItem.GetResist( PHYSICAL ) > 0 ) { tempEntry.stringNum = 1060448; // physical resist ~1_val~% - tempEntry.ourText = oldstrutil::number( cItem.GetResist( PHYSICAL )); + tempEntry.ourText = util::ntos( cItem.GetResist( PHYSICAL )); FinalizeData( tempEntry, totalStringLen ); } if( cItem.GetResist( HEAT ) > 0 ) { tempEntry.stringNum = 1060447; // fire resist ~1_val~% - tempEntry.ourText = oldstrutil::number( cItem.GetResist( HEAT )); + tempEntry.ourText = util::ntos( cItem.GetResist( HEAT )); FinalizeData( tempEntry, totalStringLen ); } if( cItem.GetResist( COLD ) > 0 ) { tempEntry.stringNum = 1060445; // cold resist ~1_val~% - tempEntry.ourText = oldstrutil::number( cItem.GetResist( COLD )); + tempEntry.ourText = util::ntos( cItem.GetResist( COLD )); FinalizeData( tempEntry, totalStringLen ); } if( cItem.GetResist( POISON ) > 0 ) { tempEntry.stringNum = 1060449; // poison resist ~1_val~% - tempEntry.ourText = oldstrutil::number( cItem.GetResist( POISON )); + tempEntry.ourText = util::ntos( cItem.GetResist( POISON )); FinalizeData( tempEntry, totalStringLen ); } if( cItem.GetResist( LIGHTNING ) > 0 ) { tempEntry.stringNum = 1060446; // energy/electrical resist ~1_val~% - tempEntry.ourText = oldstrutil::number( cItem.GetResist( LIGHTNING )); + tempEntry.ourText = util::ntos( cItem.GetResist( LIGHTNING )); FinalizeData( tempEntry, totalStringLen ); } } @@ -7621,7 +7622,7 @@ void CPToolTip::CopyItemData( CItem& cItem, size_t &totalStringLen, bool addAmou if( cItem.GetResist( PHYSICAL ) > 0 ) { tempEntry.stringNum = 1042971; // ~1_NOTHING~ - tempEntry.ourText = oldstrutil::format( "Armor Rating: %s", oldstrutil::number( cItem.GetResist( PHYSICAL )).c_str() ); + tempEntry.ourText = util::format( "Armor Rating: %s", util::ntos( cItem.GetResist( PHYSICAL )).c_str() ); FinalizeData( tempEntry, totalStringLen ); } } @@ -7629,33 +7630,33 @@ void CPToolTip::CopyItemData( CItem& cItem, size_t &totalStringLen, bool addAmou if( cItem.GetMaxHP() > 1 ) { tempEntry.stringNum = 1060639; // durability ~1_val~ / ~2_val~ - tempEntry.ourText = oldstrutil::format( "%i\t%i", cItem.GetHP(), cItem.GetMaxHP() ); + tempEntry.ourText = util::format( "%i\t%i", cItem.GetHP(), cItem.GetMaxHP() ); FinalizeData( tempEntry, totalStringLen ); } if( cItem.GetStrength2() > 0 ) { tempEntry.stringNum = 1060485; // strength bonus ~1_val~ - tempEntry.ourText = oldstrutil::number( cItem.GetStrength2() ); + tempEntry.ourText = util::ntos( cItem.GetStrength2() ); FinalizeData( tempEntry, totalStringLen ); } if( cItem.GetDexterity2() > 0 ) { tempEntry.stringNum = 1060409; // dexterity bonus ~1_val~ - tempEntry.ourText = oldstrutil::number( cItem.GetDexterity2() ); + tempEntry.ourText = util::ntos( cItem.GetDexterity2() ); FinalizeData( tempEntry, totalStringLen ); } if( cItem.GetIntelligence2() > 0 ) { tempEntry.stringNum = 1060432; // intelligence bonus ~1_val~ - tempEntry.ourText = oldstrutil::number( cItem.GetIntelligence2() ); + tempEntry.ourText = util::ntos( cItem.GetIntelligence2() ); FinalizeData( tempEntry, totalStringLen ); } if( cItem.GetStrength() > 1 ) { tempEntry.stringNum = 1061170; // strength requirement ~1_val~ - tempEntry.ourText = oldstrutil::number( cItem.GetStrength() ); + tempEntry.ourText = util::ntos( cItem.GetStrength() ); FinalizeData( tempEntry, totalStringLen ); } } @@ -7681,7 +7682,7 @@ void CPToolTip::CopyItemData( CItem& cItem, size_t &totalStringLen, bool addAmou { // First the price tempEntry.stringNum = 1043304; // Price: ~1_COST~ - tempEntry.ourText = oldstrutil::number( cItem.GetVendorPrice() ); + tempEntry.ourText = util::ntos( cItem.GetVendorPrice() ); FinalizeData( tempEntry, totalStringLen ); } else @@ -7719,7 +7720,7 @@ void CPToolTip::CopyCharData( CChar& mChar, size_t &totalStringLen ) if( cwmWorldState->creatures[mChar.GetId()].IsHuman() && !mChar.IsIncognito() && !mChar.IsDisguised() ) { GetFameTitle( &mChar, fameTitle ); - fameTitle = oldstrutil::trim( fameTitle ); + fameTitle = util::trim( fameTitle ); } } @@ -7727,7 +7728,7 @@ void CPToolTip::CopyCharData( CChar& mChar, size_t &totalStringLen ) tempEntry.stringNum = 1050045; // ~1_PREFIX~~2_NAME~~3_SUFFIX~ std::string mCharName = GetNpcDictName( &mChar, tSock, NRS_TOOLTIP ); std::string convertedString = oldstrutil::stringToWstringToString( mCharName ); - tempEntry.ourText = oldstrutil::format( "%s \t%s\t ", fameTitle.c_str(), convertedString.c_str() ); + tempEntry.ourText = util::format( "%s \t%s\t ", fameTitle.c_str(), convertedString.c_str() ); FinalizeData( tempEntry, totalStringLen ); @@ -7743,11 +7744,11 @@ void CPToolTip::CopyCharData( CChar& mChar, size_t &totalStringLen ) auto guildTitle = mChar.GetGuildTitle(); if( guildTitle != "" ) { - tempEntry.ourText = oldstrutil::format( "%s, %s", guildTitle.c_str(), myGuild->Name().c_str() ); + tempEntry.ourText = util::format( "%s, %s", guildTitle.c_str(), myGuild->Name().c_str() ); } else { - tempEntry.ourText = oldstrutil::format( "%s", myGuild->Name().c_str() ); + tempEntry.ourText = util::format( "%s", myGuild->Name().c_str() ); } FinalizeData( tempEntry, totalStringLen ); } @@ -7761,7 +7762,7 @@ void CPToolTip::CopyCharData( CChar& mChar, size_t &totalStringLen ) { tempEntry.stringNum = 1042971; // ~1_NOTHING~ auto raceName = Races->Name( mChar.GetRace() ); - tempEntry.ourText = oldstrutil::format( "%s", ( "("s + raceName + ")"s ).c_str() ); + tempEntry.ourText = util::format( "%s", ( "("s + raceName + ")"s ).c_str() ); FinalizeData( tempEntry, totalStringLen ); } } @@ -7773,7 +7774,7 @@ void CPToolTip::CopyCharData( CChar& mChar, size_t &totalStringLen ) if( !charTownRegion->IsGuarded() && !charTownRegion->IsSafeZone() ) { tempEntry.stringNum = 1042971; // ~1_NOTHING~ - tempEntry.ourText = oldstrutil::format( "%s", Dictionary->GetEntry( 9051, tSock->Language() ).c_str() ); // [Guarded] + tempEntry.ourText = util::format( "%s", Dictionary->GetEntry( 9051, tSock->Language() ).c_str() ); // [Guarded] FinalizeData( tempEntry, totalStringLen ); } } @@ -7785,7 +7786,7 @@ void CPToolTip::CopyCharData( CChar& mChar, size_t &totalStringLen ) std::string mCharTitle = GetNpcDictTitle( &mChar, tSock ); convertedString = oldstrutil::stringToWstringToString( mCharTitle ); - tempEntry.ourText = oldstrutil::format( "%s", convertedString.c_str() ); + tempEntry.ourText = util::format( "%s", convertedString.c_str() ); FinalizeData( tempEntry, totalStringLen ); } diff --git a/source/CResponse.cpp b/source/CResponse.cpp index e1486a83e..df37e513a 100644 --- a/source/CResponse.cpp +++ b/source/CResponse.cpp @@ -37,6 +37,8 @@ #include "cGuild.h" #include "skills.h" #include "StringUtility.hpp" +#include "utility/strutil.hpp" + #include #include @@ -206,51 +208,51 @@ bool WhichResponse( CSocket *mSock, CChar *mChar, std::string text, CChar *tChar case TW_QUESTDEST: tResp = new CEscortResponse( true ); break; case TW_TRAIN: tResp = new CTrainingResponse( trigWord, tChar ); break; case TW_FOLLOW: [[fallthrough]]; - case TW_FOLLOW2: tResp = new CPetMultiResponse( oldstrutil::upper( text ), false, TARGET_FOLLOW, 1310, false, true ); break; + case TW_FOLLOW2: tResp = new CPetMultiResponse( util::upper( text ), false, TARGET_FOLLOW, 1310, false, true ); break; case TW_COME: [[fallthrough]]; - case TW_FOLLOWME: tResp = new CPetComeResponse( false, oldstrutil::upper( text )); break; + case TW_FOLLOWME: tResp = new CPetComeResponse( false, util::upper( text )); break; case TW_ALLFOLLOWME: [[fallthrough]]; - case TW_ALLCOME: tResp = new CPetComeResponse( true, oldstrutil::upper( text )); break; - case TW_ALLFOLLOW: tResp = new CPetMultiResponse( oldstrutil::upper( text ), false, TARGET_FOLLOW, 1310, true, true ); break; + case TW_ALLCOME: tResp = new CPetComeResponse( true, util::upper( text )); break; + case TW_ALLFOLLOW: tResp = new CPetMultiResponse( util::upper( text ), false, TARGET_FOLLOW, 1310, true, true ); break; case TW_KILL: [[fallthrough]]; - case TW_ATTACK: tResp = new CPetAttackResponse( false, oldstrutil::upper( text )); break; + case TW_ATTACK: tResp = new CPetAttackResponse( false, util::upper( text )); break; case TW_ALLKILL: [[fallthrough]]; case TW_ALLATTACK: /*{ - tResp = new CPetAttackResponse( true, oldstrutil::upper( text )); + tResp = new CPetAttackResponse( true, util::upper( text )); tResp->Handle( mSock, mChar ); delete tResp; tResp = nullptr; goto endResponseCheck; }*/ - tResp = new CPetAttackResponse( true, oldstrutil::upper( text )); + tResp = new CPetAttackResponse( true, util::upper( text )); break; case TW_FETCH: case TW_GET: - case TW_BRING: tResp = new CPetMultiResponse( oldstrutil::upper( text ), false, TARGET_GUARD, 1316, false, true ); break; - case TW_FRIEND: tResp = new CPetMultiResponse( oldstrutil::upper( text ), true, TARGET_FRIEND, 1620, false, true ); break; - case TW_GUARD: tResp = new CPetMultiResponse( oldstrutil::upper( text ), false, TARGET_GUARD, 1104, false, true ); break; + case TW_BRING: tResp = new CPetMultiResponse( util::upper( text ), false, TARGET_GUARD, 1316, false, true ); break; + case TW_FRIEND: tResp = new CPetMultiResponse( util::upper( text ), true, TARGET_FRIEND, 1620, false, true ); break; + case TW_GUARD: tResp = new CPetMultiResponse( util::upper( text ), false, TARGET_GUARD, 1104, false, true ); break; case TW_ALLGUARD: [[fallthrough]]; - case TW_ALLGUARDME: tResp = new CPetGuardResponse( true, oldstrutil::upper( text )); break; + case TW_ALLGUARDME: tResp = new CPetGuardResponse( true, util::upper( text )); break; case TW_STOP: [[fallthrough]]; - case TW_STAY: tResp = new CPetStayResponse( false, oldstrutil::upper( text )); break; + case TW_STAY: tResp = new CPetStayResponse( false, util::upper( text )); break; case TW_ALLSTOP: [[fallthrough]]; - case TW_ALLSTAY: tResp = new CPetStayResponse( true, oldstrutil::upper( text )); break; - case TW_TRANSFER: tResp = new CPetMultiResponse( oldstrutil::upper( text ), true, TARGET_TRANSFER, 1323, false, false ); break; - case TW_RELEASE: tResp = new CPetReleaseResponse( oldstrutil::upper( text )); break; - case TW_VENDORBUY: tResp = new CVendorBuyResponse( true, oldstrutil::upper( text )); break; - case TW_BUY: tResp = new CVendorBuyResponse( false, oldstrutil::upper( text )); break; - case TW_VENDORSELL: tResp = new CVendorSellResponse( true, oldstrutil::upper( text )); break; - case TW_SELL: tResp = new CVendorSellResponse( false, oldstrutil::upper( text )); break; - case TW_VENDORVIEW: tResp = new CVendorViewResponse( true, oldstrutil::upper( text )); break; - case TW_VIEW: tResp = new CVendorViewResponse( false, oldstrutil::upper( text )); break; - case TW_VENDORGOLD: tResp = new CVendorGoldResponse( true, oldstrutil::upper( text )); break; + case TW_ALLSTAY: tResp = new CPetStayResponse( true, util::upper( text )); break; + case TW_TRANSFER: tResp = new CPetMultiResponse( util::upper( text ), true, TARGET_TRANSFER, 1323, false, false ); break; + case TW_RELEASE: tResp = new CPetReleaseResponse( util::upper( text )); break; + case TW_VENDORBUY: tResp = new CVendorBuyResponse( true, util::upper( text )); break; + case TW_BUY: tResp = new CVendorBuyResponse( false, util::upper( text )); break; + case TW_VENDORSELL: tResp = new CVendorSellResponse( true, util::upper( text )); break; + case TW_SELL: tResp = new CVendorSellResponse( false, util::upper( text )); break; + case TW_VENDORVIEW: tResp = new CVendorViewResponse( true, util::upper( text )); break; + case TW_VIEW: tResp = new CVendorViewResponse( false, util::upper( text )); break; + case TW_VENDORGOLD: tResp = new CVendorGoldResponse( true, util::upper( text )); break; case TW_COLLECT: [[fallthrough]]; - case TW_GOLD: tResp = new CVendorGoldResponse( false, oldstrutil::upper( text )); break; - case TW_VENDORSTATUS: tResp = new CVendorStatusResponse( true, oldstrutil::upper( text )); break; - case TW_STATUS: tResp = new CVendorStatusResponse( false, oldstrutil::upper( text )); break; - case TW_VENDORDISMISS: tResp = new CVendorDismissResponse( true, oldstrutil::upper( text )); break; - case TW_DISMISS: tResp = new CVendorDismissResponse( false, oldstrutil::upper( text )); break; + case TW_GOLD: tResp = new CVendorGoldResponse( false, util::upper( text )); break; + case TW_VENDORSTATUS: tResp = new CVendorStatusResponse( true, util::upper( text )); break; + case TW_STATUS: tResp = new CVendorStatusResponse( false, util::upper( text )); break; + case TW_VENDORDISMISS: tResp = new CVendorDismissResponse( true, util::upper( text )); break; + case TW_DISMISS: tResp = new CVendorDismissResponse( false, util::upper( text )); break; case TW_HOUSEBAN: tResp = new CHouseMultiResponse( TARGET_HOUSEBAN, 585 ); break; case TW_HOUSEEJECT: tResp = new CHouseMultiResponse( TARGET_HOUSEEJECT, 587 ); break; case TW_HOUSELOCKDOWN: tResp = new CHouseMultiResponse( TARGET_HOUSELOCKDOWN, 589 ); break; @@ -324,7 +326,7 @@ bool WhichResponse( CSocket *mSock, CChar *mChar, std::string text, CChar *tChar break; } #if defined( UOX_DEBUG_MODE ) - Console.Print( oldstrutil::format( "Unhandled trigger [%s] sent by the client 0x%X\n", text.c_str(), trigWord )); + Console.Print( util::format( "Unhandled trigger [%s] sent by the client 0x%X\n", text.c_str(), trigWord )); #endif break; } @@ -600,7 +602,7 @@ void CTrainingResponse::Handle( CSocket *mSock, CChar *mChar ) { if( nearbyNpc->GetBaseSkill( j ) > 10 ) { - temp2 = oldstrutil::lower( cwmWorldState->skill[j].name ); + temp2 = util::lower( cwmWorldState->skill[j].name ); if( !skillsToTrainIn ) { temp2[0] = std::toupper( temp2[0] ); // If it's the first skill, capitalize it, and add a space in front. @@ -644,7 +646,7 @@ void CTrainingResponse::Handle( CSocket *mSock, CChar *mChar ) } if( nearbyNpc->GetBaseSkill( static_cast( skill )) > 10 ) { - temp = oldstrutil::format( maxsize, Dictionary->GetEntry( 1304 ), oldstrutil::lower( cwmWorldState->skill[skill].name ).c_str() ); // Thou wishest to learn of %s? + temp = oldstrutil::format( maxsize, Dictionary->GetEntry( 1304 ), util::lower( cwmWorldState->skill[skill].name ).c_str() ); // Thou wishest to learn of %s? if( mChar->GetBaseSkill( static_cast( skill )) >= 250 ) { temp += Dictionary->GetEntry( 1305 ); // I can teach thee no more than thou already knowest! @@ -750,7 +752,7 @@ bool CPetMultiResponse::Handle( CSocket *mSock, CChar *mChar, CChar *petNpc ) npcName = Dictionary->GetEntry( 3000 + petNpc->GetId() ); } - if( FindString( ourText, oldstrutil::upper( npcName ))) + if( FindString( ourText, util::upper( npcName ))) { if( Npcs->CanControlPet( mChar, petNpc, isRestricted, checkDifficulty )) { @@ -779,7 +781,7 @@ CPetReleaseResponse::CPetReleaseResponse( const std::string &text ) : CBasePetRe bool CPetReleaseResponse::Handle( CSocket *mSock, CChar *mChar, CChar *petNpc ) { std::string npcName = GetNpcDictName( petNpc, mSock, NRS_SYSTEM ); - if( FindString( ourText, oldstrutil::upper( npcName ))) + if( FindString( ourText, util::upper( npcName ))) { if( Npcs->CanControlPet( mChar, petNpc, true, false )) { @@ -811,7 +813,7 @@ CPetGuardResponse::CPetGuardResponse( bool allVal, const std::string &text ) : C bool CPetGuardResponse::Handle( CSocket *mSock, CChar *mChar, CChar *petNpc ) { std::string npcName = GetNpcDictName( petNpc, mSock, NRS_SYSTEM ); - if( saidAll || FindString( ourText, oldstrutil::upper( npcName ))) + if( saidAll || FindString( ourText, util::upper( npcName ))) { if( Npcs->CanControlPet( mChar, petNpc, false, true )) { @@ -840,7 +842,7 @@ CPetAttackResponse::CPetAttackResponse( bool allVal, const std::string &text ) : bool CPetAttackResponse::Handle( CSocket *mSock, CChar *mChar, CChar *petNpc ) { std::string npcName = GetNpcDictName( petNpc, mSock, NRS_SYSTEM ); - if( saidAll || FindString( ourText, oldstrutil::upper( npcName ))) + if( saidAll || FindString( ourText, util::upper( npcName ))) { if( Npcs->CanControlPet( mChar, petNpc, false, true )) { @@ -869,7 +871,7 @@ CPetComeResponse::CPetComeResponse( bool allVal, const std::string &text ) : CPe bool CPetComeResponse::Handle( CSocket *mSock, CChar *mChar, CChar *petNpc ) { std::string npcName = GetNpcDictName( petNpc, mSock, NRS_SYSTEM ); - if( saidAll || FindString( ourText, oldstrutil::upper( npcName ))) + if( saidAll || FindString( ourText, util::upper( npcName ))) { if( Npcs->CanControlPet( mChar, petNpc, false, true )) { @@ -895,7 +897,7 @@ CPetStayResponse::CPetStayResponse( bool allVal, const std::string &text ) : CPe bool CPetStayResponse::Handle( CSocket *mSock, CChar *mChar, CChar *petNpc ) { std::string npcName = GetNpcDictName( petNpc, mSock, NRS_SYSTEM ); - if( saidAll || FindString( ourText, oldstrutil::upper( npcName ))) + if( saidAll || FindString( ourText, util::upper( npcName ))) { if( Npcs->CanControlPet( mChar, petNpc, false, true )) { @@ -940,7 +942,7 @@ void CBaseVendorResponse::Handle( CSocket *mSock, CChar *mChar ) continue; std::string npcName = GetNpcDictName( nearbyNpc, mSock, NRS_SYSTEM ); - if( saidVendor || FindString( ourText, oldstrutil::upper( npcName ))) + if( saidVendor || FindString( ourText, util::upper( npcName ))) { if( !Handle( mSock, mChar, nearbyNpc )) break; diff --git a/source/Dictionary.cpp b/source/Dictionary.cpp index 5b05310b8..ae4d19772 100644 --- a/source/Dictionary.cpp +++ b/source/Dictionary.cpp @@ -8,6 +8,7 @@ #include "scriptc.h" #include "ssection.h" #include "StringUtility.hpp" +#include "utility/strutil.hpp" #include #include @@ -169,8 +170,8 @@ auto CDictionary::ParseFile( const std::string &dictionaryfile ) -> bool { input_buffer[input.gcount()] = 0; auto line = std::string( input_buffer ); - line = oldstrutil::removeTrailing( line, "//" ); - line = oldstrutil::trim( line ); + line = util::strip( line, "//" ); + line = util::trim( line ); if( !line.empty() ) { switch( static_cast( state )) @@ -180,8 +181,8 @@ auto CDictionary::ParseFile( const std::string &dictionaryfile ) -> bool if(( line[0] == '[' ) && ( *( line.rbegin() ) == ']' )) { // it is a section header! - line = oldstrutil::upper( oldstrutil::simplify( line.substr( 1, line.size() - 2 ))); - auto [key, value] = oldstrutil::split( line, " " ); + line = util::upper( util::simplify( line.substr( 1, line.size() - 2 ))); + auto [key, value] = util::split( line, " " ); if(( key == "DICTIONARY" ) && ( value == "CLIENTMSG" )) { // This is a good section start! @@ -204,7 +205,7 @@ auto CDictionary::ParseFile( const std::string &dictionaryfile ) -> bool { if( line != "}" ) { - auto [key, value] = oldstrutil::split( line, "=" ); + auto [key, value] = util::split( line, "=" ); try { auto number = std::stoi( key, nullptr, 0 ); diff --git a/source/JSEncapsulate.cpp b/source/JSEncapsulate.cpp index 1bf09313c..c0749a327 100644 --- a/source/JSEncapsulate.cpp +++ b/source/JSEncapsulate.cpp @@ -1,6 +1,8 @@ #include "JSEncapsulate.h" #include #include "StringUtility.hpp" +#include "utility/strutil.hpp" + #include "jsobj.h" #include "jsutil.h" @@ -240,7 +242,7 @@ void JSEncapsulate::Parse( JSEncapsObjectType typeConvert ) case JSOT_BOOL: boolVal = ( JSVAL_TO_BOOLEAN(( *vp )) == JS_TRUE ); break; case JSOT_STRING: svalue = JS_GetStringBytes( JS_ValueToString( cx, *vp )); - boolVal = ( oldstrutil::upper( svalue ) == "TRUE" ); + boolVal = ( util::upper( svalue ) == "TRUE" ); break; default: case JSOT_COUNT: @@ -252,11 +254,11 @@ void JSEncapsulate::Parse( JSEncapsObjectType typeConvert ) { case JSOT_INT: ivalue = JSVAL_TO_INT(( *vp )); - stringVal = oldstrutil::number( ivalue ); + stringVal = util::ntos( ivalue ); break; case JSOT_DOUBLE: JS_ValueToNumber( cx, ( *vp ), &fvalue ); - stringVal = oldstrutil::number( fvalue ); + stringVal = std::to_string( fvalue ); break; case JSOT_BOOL: bvalue = ( JSVAL_TO_BOOLEAN(( *vp )) == JS_TRUE ); diff --git a/source/SEFunctions.cpp b/source/SEFunctions.cpp index 384d1632f..0d308f725 100644 --- a/source/SEFunctions.cpp +++ b/source/SEFunctions.cpp @@ -35,7 +35,7 @@ #include "PartySystem.h" #include "cSpawnRegion.h" #include "CPacketSend.h" - +#include "utility/strutil.hpp" void LoadTeleportLocations( void ); @@ -71,7 +71,7 @@ ObjectType FindObjTypeFromString( std::string strToFind ) { InitStringToObjType(); } - std::map::const_iterator toFind = stringToObjType.find( oldstrutil::upper( strToFind )); + std::map::const_iterator toFind = stringToObjType.find( util::upper( strToFind )); if( toFind != stringToObjType.end() ) { return toFind->second; @@ -173,7 +173,7 @@ JSBool SE_BroadcastMessage( JSContext *cx, [[maybe_unused]] JSObject *obj, uintN std::string trgMessage = JS_GetStringBytes( JS_ValueToString( cx, argv[0] )); if( trgMessage.empty() || trgMessage.length() == 0 ) { - ScriptError( cx, oldstrutil::format( "BroadcastMessage: Invalid string (%s)", trgMessage.c_str() ).c_str() ); + ScriptError( cx, util::format( "BroadcastMessage: Invalid string (%s)", trgMessage.c_str() ).c_str() ); return JS_FALSE; } SysBroadcast( trgMessage ); @@ -196,7 +196,7 @@ JSBool SE_CalcItemFromSer( JSContext *cx, [[maybe_unused]] JSObject *obj, uintN if( argc == 1 ) { std::string str = JS_GetStringBytes( JS_ValueToString( cx, argv[0] )); - targSerial = oldstrutil::value( str ); + targSerial = util::ston( str ); } else { @@ -491,7 +491,7 @@ JSBool SE_MakeItem( JSContext *cx, [[maybe_unused]] JSObject *obj, uintN argc, j CreateEntry_st *toFind = Skills->FindItem( itemMenu ); if( toFind == nullptr ) { - ScriptError( cx, oldstrutil::format( "MakeItem: Invalid make item (%i)", itemMenu ).c_str() ); + ScriptError( cx, util::format( "MakeItem: Invalid make item (%i)", itemMenu ).c_str() ); return JS_FALSE; } UI16 resourceColour = 0; @@ -690,7 +690,7 @@ JSBool SE_RegisterSkill( JSContext *cx, [[maybe_unused]] JSObject *obj, uintN ar Console.MoveTo( 15 ); Console.Print( "Registering skill number " ); Console.TurnYellow(); - Console.Print( oldstrutil::format( "%i", skillNumber )); + Console.Print( util::format( "%i", skillNumber )); if( !isEnabled ) { Console.TurnRed(); @@ -737,7 +737,7 @@ JSBool SE_RegisterPacket( JSContext *cx, [[maybe_unused]] JSObject *obj, uintN a if( scriptId != 0xFFFF ) { #if defined( UOX_DEBUG_MODE ) - Console.Print( oldstrutil::format( "Registering packet number 0x%X, subcommand 0x%x\n", packet, subCmd )); + Console.Print( util::format( "Registering packet number 0x%X, subcommand 0x%x\n", packet, subCmd )); #endif Network->RegisterPacket( packet, subCmd, scriptId ); } @@ -2267,7 +2267,7 @@ JSBool SE_NumToString( JSContext *cx, [[maybe_unused]] JSObject *obj, uintN argc } SI32 num = JSVAL_TO_INT( argv[0] ); - auto str = oldstrutil::number( num ); + auto str = util::ntos( num ); *rval = STRING_TO_JSVAL( JS_NewStringCopyZ( cx, str.c_str() )); return JS_TRUE; } @@ -2287,7 +2287,7 @@ JSBool SE_NumToHexString( JSContext *cx, [[maybe_unused]] JSObject *obj, uintN a } SI32 num = JSVAL_TO_INT( argv[0] ); - auto str = oldstrutil::number( num, 16 ); + auto str = util::ntos( num, 16 ); *rval = STRING_TO_JSVAL( JS_NewStringCopyZ( cx, str.c_str() )); return JS_TRUE; @@ -2385,7 +2385,7 @@ JSBool SE_AreaCharacterFunction( JSContext *cx, [[maybe_unused]] JSObject *obj, } catch( const std::out_of_range &e ) { - ScriptError( cx, oldstrutil::format( "Critical error encountered in AreaObjFunc!", e.what() ).c_str() ); + ScriptError( cx, util::format( "Critical error encountered in AreaObjFunc!", e.what() ).c_str() ); } *rval = INT_TO_JSVAL( retCounter ); @@ -2816,7 +2816,7 @@ JSBool SE_WorldBrightLevel( [[maybe_unused]] JSContext *cx, [[maybe_unused]] JSO { if( argc > 1 ) { - ScriptError( cx, oldstrutil::format( "WorldBrightLevel: Unknown Count of Arguments: %d", argc ).c_str() ); + ScriptError( cx, util::format( "WorldBrightLevel: Unknown Count of Arguments: %d", argc ).c_str() ); return JS_FALSE; } else if( argc == 1 ) @@ -2838,7 +2838,7 @@ JSBool SE_WorldDarkLevel( [[maybe_unused]] JSContext *cx, [[maybe_unused]] JSObj { if( argc > 1 ) { - ScriptError( cx, oldstrutil::format( "WorldDarkLevel: Unknown Count of Arguments: %d", argc ).c_str() ); + ScriptError( cx, util::format( "WorldDarkLevel: Unknown Count of Arguments: %d", argc ).c_str() ); return JS_FALSE; } else if( argc == 1 ) @@ -2860,7 +2860,7 @@ JSBool SE_WorldDungeonLevel( [[maybe_unused]] JSContext *cx, [[maybe_unused]] JS { if( argc > 1 ) { - ScriptError( cx, oldstrutil::format( "WorldDungeonLevel: Unknown Count of Arguments: %d", argc ).c_str() ); + ScriptError( cx, util::format( "WorldDungeonLevel: Unknown Count of Arguments: %d", argc ).c_str() ); return JS_FALSE; } else if( argc == 1 ) @@ -2881,7 +2881,7 @@ JSBool SE_GetSpawnRegionFacetStatus( [[maybe_unused]] JSContext *cx, [[maybe_unu { if( argc > 1 ) { - ScriptError( cx, oldstrutil::format( "GetSpawnRegionFacetStatus: Unknown Count of Arguments: %d", argc ).c_str() ); + ScriptError( cx, util::format( "GetSpawnRegionFacetStatus: Unknown Count of Arguments: %d", argc ).c_str() ); return JS_FALSE; } else if( argc == 1 ) @@ -2909,7 +2909,7 @@ JSBool SE_SetSpawnRegionFacetStatus( [[maybe_unused]] JSContext *cx, [[maybe_unu { if( argc > 2 ) { - ScriptError( cx, oldstrutil::format( "SetSpawnRegionFacetStatus: Unknown Count of Arguments: %d", argc ).c_str() ); + ScriptError( cx, util::format( "SetSpawnRegionFacetStatus: Unknown Count of Arguments: %d", argc ).c_str() ); return JS_FALSE; } else if( argc == 1 ) @@ -2975,7 +2975,7 @@ JSBool SE_ReloadJSFile( JSContext *cx, [[maybe_unused]] JSObject *obj, uintN arg UI16 scriptId = static_cast( JSVAL_TO_INT( argv[0] )); if( scriptId == JSMapping->GetScriptId( JS_GetGlobalObject( cx ))) { - ScriptError( cx, oldstrutil::format( "ReloadJSFile: JS Script attempted to reload itself, crash avoided (ScriptID %u)", scriptId ).c_str() ); + ScriptError( cx, util::format( "ReloadJSFile: JS Script attempted to reload itself, crash avoided (ScriptID %u)", scriptId ).c_str() ); return JS_FALSE; } @@ -2994,12 +2994,12 @@ JSBool SE_ResourceArea( JSContext *cx, [[maybe_unused]] JSObject *obj, uintN arg { if( argc != 0 ) { - ScriptError( cx, oldstrutil::format( "ResourceArea: Invalid Count of Arguments: %d", argc ).c_str() ); + ScriptError( cx, util::format( "ResourceArea: Invalid Count of Arguments: %d", argc ).c_str() ); return JS_FALSE; } auto resType = std::string( JS_GetStringBytes( JS_ValueToString( cx, argv[0] ))); - resType = oldstrutil::upper( oldstrutil::trim( oldstrutil::removeTrailing( resType, "//" ))); + resType = util::upper( util::trim( util::strip( resType, "//" ))); *rval = INT_TO_JSVAL( cwmWorldState->ServerData()->ResourceAreaSize() ); @@ -3016,11 +3016,11 @@ JSBool SE_ResourceAmount( JSContext *cx, [[maybe_unused]] JSObject *obj, uintN a { if( argc > 2 || argc == 0 ) { - ScriptError( cx, oldstrutil::format( "ResourceAmount: Invalid Count of Arguments: %d", argc ).c_str() ); + ScriptError( cx, util::format( "ResourceAmount: Invalid Count of Arguments: %d", argc ).c_str() ); return JS_FALSE; } auto resType = std::string( JS_GetStringBytes( JS_ValueToString( cx, argv[0] ))); - resType = oldstrutil::upper( oldstrutil::trim( oldstrutil::removeTrailing( resType, "//" ))); + resType = util::upper( util::trim( util::strip( resType, "//" ))); if( argc == 2 ) { @@ -3065,12 +3065,12 @@ JSBool SE_ResourceTime( JSContext *cx, [[maybe_unused]] JSObject *obj, uintN arg { if( argc > 2 || argc == 0 ) { - ScriptError( cx, oldstrutil::format( "ResourceTime: Invalid Count of Arguments: %d", argc ).c_str() ); + ScriptError( cx, util::format( "ResourceTime: Invalid Count of Arguments: %d", argc ).c_str() ); return JS_FALSE; } auto resType = std::string( JS_GetStringBytes( JS_ValueToString( cx, argv[0] ))); - resType = oldstrutil::upper( oldstrutil::trim( oldstrutil::removeTrailing( resType, "//" ))); + resType = util::upper( util::trim( util::strip( resType, "//" ))); if( argc == 2 ) { UI16 newVal = static_cast( JSVAL_TO_INT( argv[1] )); @@ -3408,7 +3408,7 @@ JSBool SE_Moon( [[maybe_unused]] JSContext *cx, [[maybe_unused]] JSObject *obj, { if( argc > 2 || argc == 0 ) { - ScriptError( cx, oldstrutil::format( "Moon: Invalid Count of Arguments: %d", argc ).c_str() ); + ScriptError( cx, util::format( "Moon: Invalid Count of Arguments: %d", argc ).c_str() ); return JS_FALSE; } @@ -3862,7 +3862,7 @@ JSBool SE_EraStringToNum( JSContext *cx, [[maybe_unused]] JSObject *obj, uintN a return JS_FALSE; } - std::string eraString = oldstrutil::upper( JS_GetStringBytes( JS_ValueToString( cx, argv[0] ))); + std::string eraString = util::upper( JS_GetStringBytes( JS_ValueToString( cx, argv[0] ))); if( !eraString.empty() ) { UI08 eraNum = static_cast( cwmWorldState->ServerData()->EraStringToEnum( eraString, false, false )); @@ -3900,7 +3900,7 @@ JSBool SE_GetServerSetting( JSContext *cx, [[maybe_unused]] JSObject *obj, uintN } JSString *tString; - std::string settingName = oldstrutil::upper( JS_GetStringBytes( JS_ValueToString( cx, argv[0] ))); + std::string settingName = util::upper( JS_GetStringBytes( JS_ValueToString( cx, argv[0] ))); if( !settingName.empty() ) { auto settingId = cwmWorldState->ServerData()->LookupINIValue( settingName ); diff --git a/source/StringUtility.cpp b/source/StringUtility.cpp index 6adb6c46c..135d9ccf2 100644 --- a/source/StringUtility.cpp +++ b/source/StringUtility.cpp @@ -14,152 +14,13 @@ #include #include #include +#include "utility/strutil.hpp" using namespace std::string_literals; namespace oldstrutil { - //===================================================================== - // Lowercase the string - std::string lower( const std::string &value ) - { - auto rValue = value; - std::transform( rValue.begin(), rValue.end(), rValue.begin(), - []( unsigned char c ){ return std::tolower( c ); } ); - return rValue; - } - //===================================================================== - // Uppercase the string - std::string upper( const std::string &value ) - { - auto rValue = value; - std::transform( rValue.begin(), rValue.end(), rValue.begin(), - []( unsigned char c ){ return std::toupper( c ); } ); - return rValue; - } - //===================================================================== - // Remove leading whitespace - std::string ltrim( const std::string &value ) - { - auto count = 0; - for( auto it = value.begin(); it != value.end(); it++ ) - { - if( !isspace( *it )) - { - return value.substr( count ); - } - else - { - count++; - } - } - - return std::string(); - } - - //===================================================================== - // Remove trailing whitespace - std::string rtrim( const std::string &value ) - { - auto count = 0; - for( auto it = value.rbegin(); it != value.rend(); it++ ) - { - if( !isspace( *it )) - { - return value.substr( 0, value.size() - count ); - } - else - { - count++; - } - } - - return std::string(); - } - - //===================================================================== - // Remove leading/trailing whitespace - std::string trim( const std::string &value ) - { - return rtrim( ltrim( value )); - } - - //===================================================================== - // Remove leading/trailing whitepace, and reduce all other whitespace to one " " - std::string simplify( const std::string &value ) - { - auto tvalue = trim( value ); - auto rValue = ""s; - auto toggle = false; - for( auto &c : tvalue ) - { - if( isspace( c )) - { - if( !toggle ) - { - rValue = rValue + c; - toggle = true; - } - } - else - { - toggle = false; - rValue = rValue + c; - } - } - return rValue; - } - - //===================================================================== - // Removing everything after a delimiter. Normally "//" for comments - std::string removeTrailing( const std::string& value, const std::string& delim ) - { - auto loc = value.find( delim ); - if( loc == std::string::npos ) - { - return value; - } - return value.substr( 0, loc ); - } - - //===================================================================== - // Return the values between two delimitors. - std::string contents( const std::string &value, const std::string& startdelim, const std::string &enddelim, std::string::size_type location ) - { - auto loc = value.find_first_of( startdelim, location ); - if( loc == std::string::npos ) - { - return std::string(); - } - auto start_search = loc + startdelim.size(); - if( start_search >= value.size() ) - { - return std::string(); - } - auto end = value.find_first_of( enddelim, start_search ); - if( end == std::string::npos ) - { - return std::string(); - } - return value.substr( start_search, end - start_search ); - } - - //===================================================================== - // Split a string based on a separator - std::tuple split( const std::string &value, const std::string &sep ) - { - auto loc = value.find( sep ); - auto next = loc + sep.size(); - if(( loc == std::string::npos ) || ( next >= value.size() )) - { - return std::make_tuple( trim( value ), ""s ); - } - else - { - return std::make_tuple( trim( value.substr( 0, loc )), trim( value.substr( next ))); - } - } //+++++++++++++++++++++++++++++++++++++ std::string format( std::size_t maxsize, const std::string fmtstring, ... ) @@ -192,13 +53,6 @@ namespace oldstrutil return temp; } - //+++++++++++++++++++++++++++++++++++++ - std::string format( const std::string fmtstring, ... ) - { - std::va_list argptr; - va_start( argptr, fmtstring ); - return oldstrutil::format( fmtstring, argptr ); - } //++++++++++++++++++++++++++++++++++++++ std::string format( const std::string fmtstring, va_list& list ) @@ -277,7 +131,7 @@ namespace oldstrutil { return sec[sectionindex]; } - throw std::runtime_error( oldstrutil::format( "Section index %ul exceeded size %ul from sections %s", sectionindex, sec.size(), value.c_str() )); + throw std::runtime_error( util::format( "Section index %ul exceeded size %ul from sections %s", sectionindex, sec.size(), value.c_str() )); } //+++++++++++++++++++++++++++++++++++++++++ @@ -361,7 +215,7 @@ namespace oldstrutil { std::string value = "\\"; std::string::size_type index = 0; - auto data = trim( base ); + auto data = util::trim( base ); while(( index = data.find( value, index )) != std::string::npos ) { data = data.replace( index, 1, "/" ); @@ -387,52 +241,6 @@ namespace oldstrutil return data; } - std::string number( char n, int base ) - { - std::stringstream conversion; - auto value = static_cast( n ); - - switch( base ) - { - case 10: - conversion << std::dec << value; - break; - case 16: - conversion << std::hex << value << std::dec; - break; - case 8: - conversion << std::oct << value << std::dec; - break; - default: - conversion << std::dec << value; - break; - } - - return conversion.str(); - } - std::string number( unsigned char n, int base ) - { - std::stringstream conversion; - auto value = static_cast( n ); - - switch( base ) - { - case 10: - conversion << std::dec << value; - break; - case 16: - conversion << std::hex << value << std::dec; - break; - case 8: - conversion << std::oct << value << std::dec; - break; - default: - conversion << std::dec << value; - break; - } - - return conversion.str(); - } #if defined( _MSC_VER ) #pragma warning(push) diff --git a/source/StringUtility.hpp b/source/StringUtility.hpp index 2be725277..bedec005e 100644 --- a/source/StringUtility.hpp +++ b/source/StringUtility.hpp @@ -17,34 +17,9 @@ namespace oldstrutil { - // Uppercase the string - std::string lower( const std::string &value ); - // Lowercase the string - std::string upper( const std::string &value ); - - // Remove leading whitespace - std::string ltrim( const std::string &value ); - // Remove trailing whitespace - std::string rtrim( const std::string &value ); - // Remove leading/trailing whitespace - std::string trim( const std::string &value ); - // Remove leading/trailing whitepace, and reduce all other whitespace to one " " - std::string simplify( const std::string &value ); - - // Removing everything after a delimiter. Normally "//" for comments - std::string removeTrailing( const std::string& value, const std::string& delim = "//" ); - - // Return the values between two delimitors. - std::string contents( const std::string &value, const std::string& startdelim, const std::string &enddelim, std::string::size_type location = 0 ); - - // Split a string based on a separator - std::tuple split( const std::string &value, const std::string &sep ); - - std::string format( std::size_t maxsize, const std::string fmtstring, ... ); std::string format( std::size_t maxsize, const std::string fmtstring, va_list &list ); - std::string format( const std::string fmtstring, ... ); std::string format( const std::string fmtstring, va_list &list ); std::string formatMessage( const std::string& uformat, const std::string& data ); @@ -77,9 +52,6 @@ namespace oldstrutil std::string extractSection( const std::string& value, const std::string& sep, std::string::size_type start, std::string::size_type stop = std::string::npos ); //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ - // Convert a number to a string - std::string number( char n, int base = 10 ); - std::string number( unsigned char n, int base = 10 ); // Convert a string to wstring (for UTF8 characters) std::wstring stringToWstring( const std::string& t_str ); @@ -93,69 +65,7 @@ namespace oldstrutil // Tackles converting text loaded from dictionary into japanese std::wstring FromUTF8( const char* str ); - template - std::string number( T n, int base = 10 ) - { - std::stringstream conversion; - if( std::is_integral::value ) - { - switch( base ) - { - case 10: - conversion << std::dec << n; - break; - case 16: - conversion << std::hex << n << std::dec; - break; - case 8: - conversion << std::oct << n << std::dec; - break; - default: - conversion << std::dec << n; - break; - } - } - else if( std::is_floating_point::value ) - { - conversion << n; - } - - return conversion.str(); - } - //++++++++++++++++++++++++++++++++++++++++++++++ - // Convert a string to a value (integer, number) - // - template - T value( const std::string& input, int base = 0 ) - { - if( std::is_floating_point::value ) - { - double value = 0.0; - try - { - value = std::stod( input ); - } - catch(...) - { - // ok, it couldn't convert it, leave it a 0.0 - } - return static_cast( value ); - } - else - { - long long value = 0.0; - try - { - value = std::stoll( input, 0, base ); - } - catch(...) - { - // ok, it couldn't convert, keave it a 0 - } - return static_cast( value ); - } - } } diff --git a/source/UOXJSMethods.cpp b/source/UOXJSMethods.cpp index a7dc81496..15c6a779b 100644 --- a/source/UOXJSMethods.cpp +++ b/source/UOXJSMethods.cpp @@ -48,6 +48,7 @@ #include "combat.h" #include "PartySystem.h" #include "osunique.hpp" +#include "utility/strutil.hpp" void BuildAddMenuGump( CSocket *s, UI16 m ); // Menus for item creation void SpawnGate( CChar *caster, SI16 srcX, SI16 srcY, SI08 srcZ, UI08 srcWorld, SI16 trgX, SI16 trgY, SI08 trgZ, UI08 trgWorld, UI16 trgInstanceId = 0 ); @@ -278,7 +279,7 @@ JSBool CPacket_WriteLong( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, size_t position = static_cast( JSVAL_TO_INT( argv[0] )); //UI32 toWrite = static_cast( JSVAL_TO_INT( argv[1] )); char * toWriteChar = JS_GetStringBytes( JS_ValueToString( cx, argv[1] )); - UI32 toWrite = oldstrutil::value( toWriteChar ); + UI32 toWrite = util::ston( toWriteChar ); myPacket->GetPacketStream().WriteLong( position, toWrite ); @@ -596,7 +597,7 @@ JSBool CGump_AddCheckbox( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, return JS_FALSE; } - gList->one->push_back( oldstrutil::format( "checkbox %i %i %i %i %i %i", tL, tR, gImage, gImageChk, initState, relay )); + gList->one->push_back( util::format( "checkbox %i %i %i %i %i %i", tL, tR, gImage, gImageChk, initState, relay )); return JS_TRUE; } @@ -741,7 +742,7 @@ JSBool CGump_MasterGump( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, } // Also send mastergump command with new gumpId - gList->one->push_back( oldstrutil::format( "mastergump %i %i %i %i %i", masterGumpId )); + gList->one->push_back( util::format( "mastergump %i %i %i %i %i", masterGumpId )); return JS_TRUE; } @@ -773,7 +774,7 @@ JSBool CGump_AddBackground( JSContext *cx, JSObject *obj, uintN argc, jsval *arg return JS_FALSE; } - gList->one->push_back( oldstrutil::format( "resizepic %i %i %i %i %i", tL, tR, gImage, bL, bR )); + gList->one->push_back( util::format( "resizepic %i %i %i %i %i", tL, tR, gImage, bL, bR )); return JS_TRUE; } @@ -806,7 +807,7 @@ JSBool CGump_AddButton( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, [ return JS_FALSE; } - gList->one->push_back( oldstrutil::format( "button %i %i %i %i %i %i %i", tL, tR, gImage, gImage2, x1, x2, x3 )); + gList->one->push_back( util::format( "button %i %i %i %i %i %i %i", tL, tR, gImage, gImage2, x1, x2, x3 )); return JS_TRUE; } @@ -845,7 +846,7 @@ JSBool CGump_AddButtonTileArt( JSContext *cx, JSObject *obj, uintN argc, jsval * return JS_FALSE; } - gList->one->push_back( oldstrutil::format( "buttontileart %i %i %i %i %i %i %i %i %i %i %i", tL, tR, tileIdNorm, tileIdPush, buttonType, pageNum, buttonId, tileId, hue, tileX, tileY )); + gList->one->push_back( util::format( "buttontileart %i %i %i %i %i %i %i %i %i %i %i", tL, tR, tileIdNorm, tileIdPush, buttonType, pageNum, buttonId, tileId, hue, tileX, tileY )); return JS_TRUE; } @@ -876,7 +877,7 @@ JSBool CGump_AddPageButton( JSContext *cx, JSObject *obj, uintN argc, jsval *arg return JS_FALSE; } - gList->one->push_back( oldstrutil::format( "button %i %i %i %i 0 %i", tL, tR, gImage, gImage2, pageNum )); + gList->one->push_back( util::format( "button %i %i %i %i 0 %i", tL, tR, gImage, gImage2, pageNum )); return JS_TRUE; } @@ -908,7 +909,7 @@ JSBool CGump_AddCheckerTrans( JSContext *cx, JSObject *obj, uintN argc, jsval *a return JS_FALSE; } - gList->one->push_back( oldstrutil::format( "checkertrans %i %i %i %i", x, y, width, height )); + gList->one->push_back( util::format( "checkertrans %i %i %i %i", x, y, width, height )); return JS_TRUE; } @@ -952,7 +953,7 @@ JSBool CGump_AddCroppedText( JSContext *cx, JSObject *obj, uintN argc, jsval *ar UI32 textId = gList->textId; ++gList->textId; - gList->one->push_back( oldstrutil::format( "croppedtext %i %i %i %i %i %u", TextX, TextY, TextWidth, TextHeight, TextHue, textId )); + gList->one->push_back( util::format( "croppedtext %i %i %i %i %i %u", TextX, TextY, TextWidth, TextHeight, TextHue, textId )); gList->two->push_back( TextString ); return JS_TRUE; @@ -980,7 +981,7 @@ JSBool CGump_AddGroup( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, [[ return JS_FALSE; } - gList->one->push_back( oldstrutil::format( "group %d", JSVAL_TO_INT( argv[0] ))); + gList->one->push_back( util::format( "group %d", JSVAL_TO_INT( argv[0] ))); return JS_TRUE; } @@ -1006,7 +1007,7 @@ JSBool CGump_EndGroup( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, [[ return JS_FALSE; } - gList->one->push_back( oldstrutil::format( "endgroup", JSVAL_TO_INT( argv[0] ))); + gList->one->push_back( util::format( "endgroup", JSVAL_TO_INT( argv[0] ))); return JS_TRUE; } @@ -1043,11 +1044,11 @@ JSBool CGump_AddGump( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, [[m if( rgbColor == 0 ) { - gList->one->push_back( oldstrutil::format( "gumppic %i %i %i", tL, tR, gImage )); + gList->one->push_back( util::format( "gumppic %i %i %i", tL, tR, gImage )); } else { - gList->one->push_back( oldstrutil::format( "gumppic %i %i %i hue=%i", tL, tR, gImage, rgbColor )); + gList->one->push_back( util::format( "gumppic %i %i %i hue=%i", tL, tR, gImage, rgbColor )); } return JS_TRUE; @@ -1079,7 +1080,7 @@ JSBool CGump_AddGumpColor( JSContext *cx, JSObject *obj, uintN argc, jsval *argv return JS_FALSE; } - gList->one->push_back( oldstrutil::format( "gumppic %i %i %i hue=%i", tL, tR, gImage, rgbColour )); + gList->one->push_back( util::format( "gumppic %i %i %i hue=%i", tL, tR, gImage, rgbColour )); return JS_TRUE; } @@ -1182,7 +1183,7 @@ JSBool CGump_AddHTMLGump( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, SI32 iBrd = ( hasBorder ? 1 : 0 ); SI32 iScrl = ( hasScrollbar ? 1 : 0 ); - gList->one->push_back( oldstrutil::format( "htmlgump %i %i %i %i %u %i %i", x, y, width, height, textId, iBrd, iScrl )); + gList->one->push_back( util::format( "htmlgump %i %i %i %i %u %i %i", x, y, width, height, textId, iBrd, iScrl )); gList->two->push_back( TextString ); return JS_TRUE; @@ -1209,7 +1210,7 @@ JSBool CGump_AddPage( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, [[m return JS_FALSE; } - gList->one->push_back( oldstrutil::format( "page %d", JSVAL_TO_INT( argv[0] ))); + gList->one->push_back( util::format( "page %d", JSVAL_TO_INT( argv[0] ))); return JS_TRUE; } @@ -1239,7 +1240,7 @@ JSBool CGump_AddPicture( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, return JS_FALSE; } - gList->one->push_back( oldstrutil::format( "tilepic %i %i %i", tL, tR, gImage )); + gList->one->push_back( util::format( "tilepic %i %i %i", tL, tR, gImage )); return JS_TRUE; } @@ -1270,7 +1271,7 @@ JSBool CGump_AddPictureColor( JSContext *cx, JSObject *obj, uintN argc, jsval *a return JS_FALSE; } - gList->one->push_back( oldstrutil::format( "tilepichue %i %i %i %i", tL, tR, gImage, rgbColour )); + gList->one->push_back( util::format( "tilepichue %i %i %i %i", tL, tR, gImage, rgbColour )); return JS_TRUE; } @@ -1305,7 +1306,7 @@ JSBool CGump_AddPicInPic( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, return JS_FALSE; } - gList->one->push_back( oldstrutil::format( "picinpic %i %i %i %i %i %i %i", x, y, gImage, spriteX, spriteY, width, height )); + gList->one->push_back( util::format( "picinpic %i %i %i %i %i %i %i", x, y, gImage, spriteX, spriteY, width, height )); return JS_TRUE; } @@ -1346,7 +1347,7 @@ JSBool CGump_AddItemProperty( JSContext *cx, JSObject *obj, uintN argc, jsval *a return JS_FALSE; } - gList->one->push_back( oldstrutil::format( "itemproperty %i", trgSer )); + gList->one->push_back( util::format( "itemproperty %i", trgSer )); return JS_TRUE; } @@ -1399,7 +1400,7 @@ JSBool CGump_AddRadio( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, [[ return JS_FALSE; } - gList->one->push_back( oldstrutil::format( "radio %i %i %i %i %i %i", tL, tR, gImage, gImageChk, initialState, relay )); + gList->one->push_back( util::format( "radio %i %i %i %i %i %i", tL, tR, gImage, gImageChk, initialState, relay )); return JS_TRUE; } @@ -1442,7 +1443,7 @@ JSBool CGump_AddText( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, [[m textId = gList->textId; ++gList->textId; - gList->one->push_back( oldstrutil::format( "text %i %i %i %u", TextX, TextY, TextHue, textId )); + gList->one->push_back( util::format( "text %i %i %i %u", TextX, TextY, TextHue, textId )); gList->two->push_back( TextString ); return JS_TRUE; @@ -1484,7 +1485,7 @@ JSBool CGump_AddTextEntry( JSContext *cx, JSObject *obj, uintN argc, jsval *argv return JS_FALSE; } - gList->one->push_back( oldstrutil::format( "textentry %i %i %i %i %i %i %i", tL, tR, width, height, hue, relay, initialTextIndex )); + gList->one->push_back( util::format( "textentry %i %i %i %i %i %i %i", tL, tR, width, height, hue, relay, initialTextIndex )); gList->two->push_back( test ); return JS_TRUE; @@ -1527,7 +1528,7 @@ JSBool CGump_AddTextEntryLimited( JSContext *cx, JSObject *obj, uintN argc, jsva return JS_FALSE; } - gList->one->push_back( oldstrutil::format( "textentrylimited %i %i %i %i %i %i %i %i", tL, tR, width, height, hue, relay, initialTextIndex, textEntrySize )); + gList->one->push_back( util::format( "textentrylimited %i %i %i %i %i %i %i %i", tL, tR, width, height, hue, relay, initialTextIndex, textEntrySize )); gList->two->push_back( test ); return JS_TRUE; @@ -1561,7 +1562,7 @@ JSBool CGump_AddTiledGump( JSContext *cx, JSObject *obj, uintN argc, jsval *argv return JS_FALSE; } - gList->one->push_back( oldstrutil::format( "gumppictiled %i %i %i %i %i", x, y, width, height, gumpId )); + gList->one->push_back( util::format( "gumppictiled %i %i %i %i %i", x, y, width, height, gumpId )); return JS_TRUE; } @@ -1599,7 +1600,7 @@ JSBool CGump_AddXMFHTMLGump( JSContext *cx, JSObject *obj, uintN argc, jsval *ar SI32 iBrd = ( hasBorder ? 1 : 0 ); SI32 iScrl = ( hasScrollbar ? 1 : 0 ); - gList->one->push_back( oldstrutil::format( "xmfhtmlgump %i %i %i %i %i %i %i", x, y, width, height, number, iBrd, iScrl )); + gList->one->push_back( util::format( "xmfhtmlgump %i %i %i %i %i %i %i", x, y, width, height, number, iBrd, iScrl )); return JS_TRUE; } @@ -1638,7 +1639,7 @@ JSBool CGump_AddXMFHTMLGumpColor( JSContext *cx, JSObject *obj, uintN argc, jsva SI32 iBrd = ( hasBorder ? 1 : 0 ); SI32 iScrl = ( hasScrollbar ? 1 : 0 ); - gList->one->push_back( oldstrutil::format( "xmfhtmlgumpcolor %i %i %i %i %i %i %i %i", x, y, width, height, number, iBrd, iScrl, rgbColour )); + gList->one->push_back( util::format( "xmfhtmlgumpcolor %i %i %i %i %i %i %i %i", x, y, width, height, number, iBrd, iScrl, rgbColour )); return JS_TRUE; } @@ -1680,7 +1681,7 @@ JSBool CGump_AddXMFHTMLTok( JSContext *cx, JSObject *obj, uintN argc, jsval *arg SI32 iBrd = ( hasBorder ? 1 : 0 ); SI32 iScrl = ( hasScrollbar ? 1 : 0 ); - gList->one->push_back( oldstrutil::format( "xmfhtmltok %i %i %i %i %i %i %i %i @%s\t%s\t%s@", x, y, width, height, iBrd, iScrl, rgbColour, number, TextString1, TextString2, TextString3 )); + gList->one->push_back( util::format( "xmfhtmltok %i %i %i %i %i %i %i %i @%s\t%s\t%s@", x, y, width, height, iBrd, iScrl, rgbColour, number, TextString1, TextString2, TextString3 )); return JS_TRUE; } @@ -1885,7 +1886,7 @@ JSBool CBase_TextMessage( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, if( retVal == JS_FALSE ) { // Dummy function not found, let shard admin know! - Console.Warning( oldstrutil::format( "Script context lost after using Char/Item JS Method .TextMessage(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); + Console.Warning( util::format( "Script context lost after using Char/Item JS Method .TextMessage(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); } } @@ -2136,7 +2137,7 @@ JSBool CBase_Delete( JSContext *cx, JSObject *obj, [[maybe_unused]] uintN argc, if( retVal == JS_FALSE ) { // Dummy function not found, let shard admin know! - Console.Warning( oldstrutil::format( "Script context lost after using Char/Item JS Method .Delete(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); + Console.Warning( util::format( "Script context lost after using Char/Item JS Method .Delete(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); } } @@ -2494,7 +2495,7 @@ JSBool CSocket_Disconnect( JSContext *cx, JSObject *obj, uintN argc, [[maybe_unu if( retVal == JS_FALSE ) { // Dummy function not found, let shard admin know! - Console.Warning( oldstrutil::format( "Script context lost after using Socket JS Method .Disconnect(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); + Console.Warning( util::format( "Script context lost after using Socket JS Method .Disconnect(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); } } return JS_TRUE; @@ -2704,7 +2705,7 @@ JSBool CBase_Teleport( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, [[ if( retVal == JS_FALSE ) { // Dummy function not found, let shard admin know! - Console.Warning( oldstrutil::format( "Script context lost after using Char/Item JS Method .Teleport(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); + Console.Warning( util::format( "Script context lost after using Char/Item JS Method .Teleport(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); } } @@ -2914,7 +2915,7 @@ JSBool CMisc_SellTo( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsva if( retVal == JS_FALSE ) { // Dummy function not found, let shard admin know! - Console.Warning( oldstrutil::format( "Script context lost after using Char/Socket JS Method .SellTo(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); + Console.Warning( util::format( "Script context lost after using Char/Socket JS Method .SellTo(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); } } @@ -2998,7 +2999,7 @@ JSBool CMisc_BuyFrom( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, [[m if( retVal == JS_FALSE ) { // Dummy function not found, let shard admin know! - Console.Warning( oldstrutil::format( "Script context lost after using Char/Socket JS Method .BuyFrom(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); + Console.Warning( util::format( "Script context lost after using Char/Socket JS Method .BuyFrom(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); } } @@ -3127,7 +3128,7 @@ JSBool CMisc_RemoveSpell( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, if( retVal == JS_FALSE ) { // Dummy function not found, let shard admin know! - Console.Warning( oldstrutil::format( "Script context lost after using Char/Item JS Method .RemoveSpell(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); + Console.Warning( util::format( "Script context lost after using Char/Item JS Method .RemoveSpell(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); } } @@ -3658,7 +3659,7 @@ JSBool CChar_OpenBank( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, [[ if( retVal == JS_FALSE ) { // Dummy function not found, let shard admin know! - Console.Warning( oldstrutil::format( "Script context lost after using Char JS Method .OpenBank(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); + Console.Warning( util::format( "Script context lost after using Char JS Method .OpenBank(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); } } @@ -3703,7 +3704,7 @@ JSBool CSocket_OpenContainer( JSContext *cx, JSObject *obj, uintN argc, jsval *a if( retVal == JS_FALSE ) { // Dummy function not found, let shard admin know! - Console.Warning( oldstrutil::format( "Script context lost after using Socket JS Method .OpenContainer(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); + Console.Warning( util::format( "Script context lost after using Socket JS Method .OpenContainer(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); } } } @@ -3751,7 +3752,7 @@ JSBool CChar_OpenLayer( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, [ if( retVal == JS_FALSE ) { // Dummy function not found, let shard admin know! - Console.Warning( oldstrutil::format( "Script context lost after using Char JS Method .OpenLayer(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); + Console.Warning( util::format( "Script context lost after using Char JS Method .OpenLayer(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); } } } @@ -3843,7 +3844,7 @@ JSBool CChar_TurnToward( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, if( retVal == JS_FALSE ) { // Dummy function not found, let shard admin know! - Console.Warning( oldstrutil::format( "Script context lost after using Character JS Method .TurnToward(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); + Console.Warning( util::format( "Script context lost after using Character JS Method .TurnToward(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); } } @@ -4934,7 +4935,7 @@ JSBool CItem_SetCont( JSContext *cx, JSObject *obj, [[maybe_unused]] uintN argc, if( retVal == JS_FALSE ) { // Dummy function not found, let shard admin know! - Console.Warning( oldstrutil::format( "Script context lost after using Item JS Method .SetCont(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); + Console.Warning( util::format( "Script context lost after using Item JS Method .SetCont(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); } } @@ -5661,7 +5662,7 @@ JSBool CItem_PlaceInPack( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, if( retVal == JS_FALSE ) { // Dummy function not found, let shard admin know! - Console.Warning( oldstrutil::format( "Script context lost after using Item JS Method .PlaceInPack(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); + Console.Warning( util::format( "Script context lost after using Item JS Method .PlaceInPack(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); } } @@ -6149,7 +6150,7 @@ JSBool CChar_YellMessage( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, if( retVal == JS_FALSE ) { // Dummy function not found, let shard admin know! - Console.Warning( oldstrutil::format( "Script context lost after using Char JS Method .YellMessage(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); + Console.Warning( util::format( "Script context lost after using Char JS Method .YellMessage(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); } } @@ -6211,7 +6212,7 @@ JSBool CChar_WhisperMessage( JSContext *cx, JSObject *obj, uintN argc, jsval *ar if( retVal == JS_FALSE ) { // Dummy function not found, let shard admin know! - Console.Warning( oldstrutil::format( "Script context lost after using Char JS Method .WhisperMessage(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); + Console.Warning( util::format( "Script context lost after using Char JS Method .WhisperMessage(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); } } @@ -6485,7 +6486,7 @@ JSBool CChar_AddSpell( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, [[ if( retVal == JS_FALSE ) { // Dummy function not found, let shard admin know! - Console.Warning( oldstrutil::format( "Script context lost after using Char JS Method .AddSpell(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); + Console.Warning( util::format( "Script context lost after using Char JS Method .AddSpell(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); } } } @@ -6579,7 +6580,7 @@ JSBool CBase_Refresh( JSContext *cx, JSObject *obj, uintN argc, [[maybe_unused]] if( retVal == JS_FALSE ) { // Dummy function not found, let shard admin know! - Console.Warning( oldstrutil::format( "Script context lost after using Char/Item JS Method .Refresh(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); + Console.Warning( util::format( "Script context lost after using Char/Item JS Method .Refresh(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); } } @@ -6847,7 +6848,7 @@ JSBool CFile_Open( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, [[mayb useScriptDataDir = ( JSVAL_TO_BOOLEAN( argv[3] ) == JS_TRUE ); } - if( oldstrutil::lower( mode ).find_first_of( "rwa", 0, 3 ) == std::string::npos ) + if( util::lower( mode ).find_first_of( "rwa", 0, 3 ) == std::string::npos ) { ScriptError( cx, "Open: Invalid mode must be \"read\", \"write\", or \"append\"!" ); return JS_FALSE; @@ -6891,7 +6892,7 @@ JSBool CFile_Open( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, [[mayb filePath.append( fileName ); FILE* stream; - mFile->mWrap = mfopen( &stream, filePath.c_str(), oldstrutil::lower( mode ).substr( 0, 1 ).c_str() ); + mFile->mWrap = mfopen( &stream, filePath.c_str(), util::lower( mode ).substr( 0, 1 ).c_str() ); return JS_TRUE; } @@ -7343,7 +7344,7 @@ JSBool CChar_WalkTo( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, [[ma cMove->FlushPath(); #if defined( UOX_DEBUG_MODE ) - Console.Print( oldstrutil::format( "WalkTo: Moving character 0x%X to (%i,%i) with a maximum of %i steps\n", cMove->GetSerial(), gx, gy, maxSteps )); + Console.Print( util::format( "WalkTo: Moving character 0x%X to (%i,%i) with a maximum of %i steps\n", cMove->GetSerial(), gx, gy, maxSteps )); #endif if( cMove->GetNpcWander() != WT_PATHFIND ) { @@ -7368,7 +7369,7 @@ JSBool CChar_WalkTo( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, [[ma if( retVal == JS_FALSE ) { // Dummy function not found, let shard admin know! - Console.Warning( oldstrutil::format( "Script context lost after using Char JS Method .WalkTo(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); + Console.Warning( util::format( "Script context lost after using Char JS Method .WalkTo(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); } } return JS_TRUE; @@ -7456,7 +7457,7 @@ JSBool CChar_RunTo( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, [[may cMove->FlushPath(); #if defined( UOX_DEBUG_MODE ) - Console.Print( oldstrutil::format( "RunTo: Moving character %i to (%i,%i) with a maximum of %i steps", cMove->GetSerial(), gx, gy, maxSteps )); + Console.Print( util::format( "RunTo: Moving character %i to (%i,%i) with a maximum of %i steps", cMove->GetSerial(), gx, gy, maxSteps )); #endif if( cMove->GetNpcWander() != WT_PATHFIND ) { @@ -7482,7 +7483,7 @@ JSBool CChar_RunTo( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, [[may if( retVal == JS_FALSE ) { // Dummy function not found, let shard admin know! - Console.Warning( oldstrutil::format( "Script context lost after using Char JS Method .RunTo(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); + Console.Warning( util::format( "Script context lost after using Char JS Method .RunTo(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); } } @@ -7671,7 +7672,7 @@ JSBool CItem_Glow( JSContext *cx, JSObject *obj, [[maybe_unused]] uintN argc, js if( retVal == JS_FALSE ) { // Dummy function not found, let shard admin know! - Console.Warning( oldstrutil::format( "Script context lost after using Item JS Method .Glow(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); + Console.Warning( util::format( "Script context lost after using Item JS Method .Glow(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); } } @@ -7735,7 +7736,7 @@ JSBool CItem_UnGlow( JSContext *cx, JSObject *obj, [[maybe_unused]] uintN argc, if( retVal == JS_FALSE ) { // Dummy function not found, let shard admin know! - Console.Warning( oldstrutil::format( "Script context lost after using Item JS Method .UnGlow(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); + Console.Warning( util::format( "Script context lost after using Item JS Method .UnGlow(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); } } @@ -7884,7 +7885,7 @@ JSBool CChar_Recall( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, [[ma if( retVal == JS_FALSE ) { // Dummy function not found, let shard admin know! - Console.Warning( oldstrutil::format( "Script context lost after using Character JS Method .Recall(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); + Console.Warning( util::format( "Script context lost after using Character JS Method .Recall(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); } } @@ -7929,7 +7930,7 @@ JSBool CChar_Mark( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, [[mayb if( mChar->GetRegion()->GetName()[0] != 0 ) { - mItem->SetName( oldstrutil::format( Dictionary->GetEntry( 684 ), mChar->GetRegion()->GetName().c_str() )); + mItem->SetName( util::format( Dictionary->GetEntry( 684 ), mChar->GetRegion()->GetName().c_str() )); } else { @@ -8060,7 +8061,7 @@ JSBool CChar_Kill( JSContext *cx, JSObject *obj, uintN argc, [[maybe_unused]] js if( retVal == JS_FALSE ) { // Dummy function not found, let shard admin know! - Console.Warning( oldstrutil::format( "Script context lost after using Character JS Method .Kill(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); + Console.Warning( util::format( "Script context lost after using Character JS Method .Kill(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); } } @@ -8101,7 +8102,7 @@ JSBool CChar_Resurrect( JSContext *cx, JSObject *obj, uintN argc, [[maybe_unused if( retVal == JS_FALSE ) { // Dummy function not found, let shard admin know! - Console.Warning( oldstrutil::format( "Script context lost after using Character JS Method .Resurrect(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); + Console.Warning( util::format( "Script context lost after using Character JS Method .Resurrect(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); } } @@ -8712,7 +8713,7 @@ JSBool CConsole_Reload( JSContext *cx, [[maybe_unused]] JSObject *obj, uintN arg ScriptError( cx, "Reload: Section to reload must be between 0 and 8" ); return JS_FALSE; } - messageLoop.NewMessage( MSG_RELOAD, oldstrutil::number( mArg ).c_str() ); + messageLoop.NewMessage( MSG_RELOAD, util::ntos( mArg ).c_str() ); return JS_TRUE; } @@ -8947,7 +8948,7 @@ JSBool CItem_Carve( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, [[may if( retVal == JS_FALSE ) { // Dummy function not found, let shard admin know! - Console.Warning( oldstrutil::format( "Script context lost after using Item JS Method .Carve(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); + Console.Warning( util::format( "Script context lost after using Item JS Method .Carve(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); } } @@ -9868,7 +9869,7 @@ JSBool CChar_Damage( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, [[ma if( retVal == JS_FALSE ) { // Dummy function not found, let shard admin know! - Console.Warning( oldstrutil::format( "Script context lost after using Character JS Method .Damage(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); + Console.Warning( util::format( "Script context lost after using Character JS Method .Damage(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); } } @@ -9917,7 +9918,7 @@ JSBool CChar_InitiateCombat( JSContext *cx, JSObject *obj, uintN argc, jsval *ar if( retVal == JS_FALSE ) { // Dummy function not found, let shard admin know! - Console.Warning( oldstrutil::format( "Script context lost after using Character JS Method .InitiateCombat(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); + Console.Warning( util::format( "Script context lost after using Character JS Method .InitiateCombat(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); } } @@ -9959,7 +9960,7 @@ JSBool CChar_InvalidateAttacker( JSContext *cx, JSObject *obj, uintN argc, [[may if( retVal == JS_FALSE ) { // Dummy function not found, let shard admin know! - Console.Warning( oldstrutil::format( "Script context lost after using Character JS Method .InvalidateAttacker(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); + Console.Warning( util::format( "Script context lost after using Character JS Method .InvalidateAttacker(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); } } @@ -10390,7 +10391,7 @@ JSBool CChar_Heal( JSContext *cx, JSObject *obj, uintN argc, jsval *argv, [[mayb if( retVal == JS_FALSE ) { // Dummy function not found, let shard admin know! - Console.Warning( oldstrutil::format( "Script context lost after using Character JS Method .Heal(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); + Console.Warning( util::format( "Script context lost after using Character JS Method .Heal(). Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", origScriptID )); } } @@ -10726,7 +10727,7 @@ JSBool CBase_AddScriptTrigger( JSContext *cx, JSObject *obj, uintN argc, jsval * cScript *toExecute = JSMapping->GetScript( scriptId ); if( toExecute == nullptr ) { - ScriptError( cx, oldstrutil::format( "Unable to assign script trigger - script ID (%i) not found in jse_fileassociations.scp!", scriptId ).c_str() ); + ScriptError( cx, util::format( "Unable to assign script trigger - script ID (%i) not found in jse_fileassociations.scp!", scriptId ).c_str() ); return JS_FALSE; } else @@ -10845,7 +10846,7 @@ JSBool CRegion_AddScriptTrigger( JSContext *cx, JSObject *obj, uintN argc, jsval cScript *toExecute = JSMapping->GetScript( scriptId ); if( toExecute == nullptr ) { - ScriptError( cx, oldstrutil::format( "Unable to assign script trigger - script ID (%i) not found in jse_fileassociations.scp!", scriptId ).c_str() ); + ScriptError( cx, util::format( "Unable to assign script trigger - script ID (%i) not found in jse_fileassociations.scp!", scriptId ).c_str() ); return JS_FALSE; } else diff --git a/source/UOXJSPropertyFuncs.cpp b/source/UOXJSPropertyFuncs.cpp index 69c7d05ff..b7c82ebb5 100644 --- a/source/UOXJSPropertyFuncs.cpp +++ b/source/UOXJSPropertyFuncs.cpp @@ -36,6 +36,8 @@ #include "PartySystem.h" +#include "utility/strutil.hpp" + void MakeShop( CChar *c ); void ScriptError( JSContext *cx, const char *txt, ... ); @@ -56,7 +58,7 @@ JSBool CSpellsProps_getProperty( JSContext *cx, JSObject *obj, jsval id, jsval * if( spellId >= Magic->spells.size() ) { - ScriptError( cx, oldstrutil::format( "Spells: Invalid Spell ID (%i) provided", spellId ).c_str() ); + ScriptError( cx, util::format( "Spells: Invalid Spell ID (%i) provided", spellId ).c_str() ); *vp = JSVAL_NULL; return JS_FALSE; } @@ -64,7 +66,7 @@ JSBool CSpellsProps_getProperty( JSContext *cx, JSObject *obj, jsval id, jsval * CSpellInfo *mySpell = &Magic->spells[spellId]; if( mySpell == nullptr ) { - ScriptError( cx, oldstrutil::format( "Spells: Invalid Spell with spellId %i", spellId ).c_str() ); + ScriptError( cx, util::format( "Spells: Invalid Spell with spellId %i", spellId ).c_str() ); *vp = JSVAL_NULL; return JS_FALSE; } @@ -170,7 +172,7 @@ JSBool CGlobalSkillsProps_getProperty( JSContext *cx, JSObject *obj, jsval id, j if( skillId > THROWING ) { - ScriptError( cx, oldstrutil::format( "Invalid Skill ID, must be between 0 and 57" ).c_str() ); + ScriptError( cx, util::format( "Invalid Skill ID, must be between 0 and 57" ).c_str() ); *vp = JSVAL_NULL; return JS_FALSE; } @@ -178,7 +180,7 @@ JSBool CGlobalSkillsProps_getProperty( JSContext *cx, JSObject *obj, jsval id, j CWorldMain::Skill_st *mySkill = &cwmWorldState->skill[skillId]; if( mySkill == nullptr ) { - ScriptError( cx, oldstrutil::format( "Invalid Skill" ).c_str() ); + ScriptError( cx, util::format( "Invalid Skill" ).c_str() ); *vp = JSVAL_NULL; return JS_FALSE; } @@ -285,7 +287,7 @@ JSBool CCreateEntriesProps_getProperty( JSContext *cx, JSObject *obj, jsval id, CreateEntry_st *myCreateEntry = Skills->FindItem( createEntryId ); if( myCreateEntry == nullptr ) { - ScriptError( cx, oldstrutil::format( "Invalid create entry ID (%i)", createEntryId ).c_str() ); + ScriptError( cx, util::format( "Invalid create entry ID (%i)", createEntryId ).c_str() ); *vp = JSVAL_NULL; return JS_FALSE; } @@ -1099,7 +1101,7 @@ JSBool CItemProps_setProperty( JSContext *cx, JSObject *obj, jsval id, jsval *vp cScript *toExecute = JSMapping->GetScript( scriptId ); if( toExecute == nullptr ) { - ScriptError( cx, oldstrutil::format( "Unable to assign script trigger - script ID (%i) not found in jse_fileassociations.scp!", scriptId ).c_str() ); + ScriptError( cx, util::format( "Unable to assign script trigger - script ID (%i) not found in jse_fileassociations.scp!", scriptId ).c_str() ); } else { @@ -1116,7 +1118,7 @@ JSBool CItemProps_setProperty( JSContext *cx, JSObject *obj, jsval id, jsval *vp cScript *toExecute = JSMapping->GetScript( scriptId ); if( toExecute == nullptr ) { - ScriptError( cx, oldstrutil::format( "Unable to assign script trigger - script ID (%i) not found in jse_fileassociations.scp!", scriptId ).c_str() ); + ScriptError( cx, util::format( "Unable to assign script trigger - script ID (%i) not found in jse_fileassociations.scp!", scriptId ).c_str() ); } else { @@ -1162,14 +1164,14 @@ JSBool CItemProps_setProperty( JSContext *cx, JSObject *obj, jsval id, jsval *vp case CIP_MORE: { auto sEncaps = encaps.toString(); - sEncaps = oldstrutil::trim( oldstrutil::removeTrailing( sEncaps, "//" )); + sEncaps = util::trim( util::strip( sEncaps, "//" )); auto encapsSections = oldstrutil::sections( sEncaps, " " ); if( encapsSections.size() >= 4 ) { - gPriv->SetTempVar( CITV_MORE, 1, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( encapsSections[0], "//" )), nullptr, 0 ))); - gPriv->SetTempVar( CITV_MORE, 2, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( encapsSections[1], "//" )), nullptr, 0 ))); - gPriv->SetTempVar( CITV_MORE, 3, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( encapsSections[2], "//" )), nullptr, 0 ))); - gPriv->SetTempVar( CITV_MORE, 4, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( encapsSections[3], "//" )), nullptr, 0 ))); + gPriv->SetTempVar( CITV_MORE, 1, static_cast( std::stoul( util::trim( util::strip( encapsSections[0], "//" )), nullptr, 0 ))); + gPriv->SetTempVar( CITV_MORE, 2, static_cast( std::stoul( util::trim( util::strip( encapsSections[1], "//" )), nullptr, 0 ))); + gPriv->SetTempVar( CITV_MORE, 3, static_cast( std::stoul( util::trim( util::strip( encapsSections[2], "//" )), nullptr, 0 ))); + gPriv->SetTempVar( CITV_MORE, 4, static_cast( std::stoul( util::trim( util::strip( encapsSections[3], "//" )), nullptr, 0 ))); } else { @@ -1180,14 +1182,14 @@ JSBool CItemProps_setProperty( JSContext *cx, JSObject *obj, jsval id, jsval *vp case CIP_MORE0: { auto sEncaps = encaps.toString(); - sEncaps = oldstrutil::trim( oldstrutil::removeTrailing( sEncaps, "//" )); + sEncaps = util::trim( util::strip( sEncaps, "//" )); auto encapsSections = oldstrutil::sections( sEncaps, " " ); if( encapsSections.size() >= 4 ) { - gPriv->SetTempVar( CITV_MORE0, 1, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( encapsSections[0], "//" )), nullptr, 0 ))); - gPriv->SetTempVar( CITV_MORE0, 2, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( encapsSections[1], "//" )), nullptr, 0 ))); - gPriv->SetTempVar( CITV_MORE0, 3, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( encapsSections[2], "//" )), nullptr, 0 ))); - gPriv->SetTempVar( CITV_MORE0, 4, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( encapsSections[3], "//" )), nullptr, 0 ))); + gPriv->SetTempVar( CITV_MORE0, 1, static_cast( std::stoul( util::trim( util::strip( encapsSections[0], "//" )), nullptr, 0 ))); + gPriv->SetTempVar( CITV_MORE0, 2, static_cast( std::stoul( util::trim( util::strip( encapsSections[1], "//" )), nullptr, 0 ))); + gPriv->SetTempVar( CITV_MORE0, 3, static_cast( std::stoul( util::trim( util::strip( encapsSections[2], "//" )), nullptr, 0 ))); + gPriv->SetTempVar( CITV_MORE0, 4, static_cast( std::stoul( util::trim( util::strip( encapsSections[3], "//" )), nullptr, 0 ))); } else { @@ -1198,14 +1200,14 @@ JSBool CItemProps_setProperty( JSContext *cx, JSObject *obj, jsval id, jsval *vp case CIP_MORE1: { auto sEncaps = encaps.toString(); - sEncaps = oldstrutil::trim( oldstrutil::removeTrailing( sEncaps, "//" )); + sEncaps = util::trim( util::strip( sEncaps, "//" )); auto encapsSections = oldstrutil::sections( sEncaps, " " ); if( encapsSections.size() >= 4 ) { - gPriv->SetTempVar( CITV_MORE1, 1, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( encapsSections[0], "//" )), nullptr, 0 ))); - gPriv->SetTempVar( CITV_MORE1, 2, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( encapsSections[1], "//" )), nullptr, 0 ))); - gPriv->SetTempVar( CITV_MORE1, 3, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( encapsSections[2], "//" )), nullptr, 0 ))); - gPriv->SetTempVar( CITV_MORE1, 4, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( encapsSections[3], "//" )), nullptr, 0 ))); + gPriv->SetTempVar( CITV_MORE1, 1, static_cast( std::stoul( util::trim( util::strip( encapsSections[0], "//" )), nullptr, 0 ))); + gPriv->SetTempVar( CITV_MORE1, 2, static_cast( std::stoul( util::trim( util::strip( encapsSections[1], "//" )), nullptr, 0 ))); + gPriv->SetTempVar( CITV_MORE1, 3, static_cast( std::stoul( util::trim( util::strip( encapsSections[2], "//" )), nullptr, 0 ))); + gPriv->SetTempVar( CITV_MORE1, 4, static_cast( std::stoul( util::trim( util::strip( encapsSections[3], "//" )), nullptr, 0 ))); } else { @@ -1216,14 +1218,14 @@ JSBool CItemProps_setProperty( JSContext *cx, JSObject *obj, jsval id, jsval *vp case CIP_MORE2: { auto sEncaps = encaps.toString(); - sEncaps = oldstrutil::trim( oldstrutil::removeTrailing( sEncaps, "//" )); + sEncaps = util::trim( util::strip( sEncaps, "//" )); auto encapsSections = oldstrutil::sections( sEncaps, " " ); if( encapsSections.size() >= 4 ) { - gPriv->SetTempVar( CITV_MORE2, 1, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( encapsSections[0], "//" )), nullptr, 0 ))); - gPriv->SetTempVar( CITV_MORE2, 2, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( encapsSections[1], "//" )), nullptr, 0 ))); - gPriv->SetTempVar( CITV_MORE2, 3, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( encapsSections[2], "//" )), nullptr, 0 ))); - gPriv->SetTempVar( CITV_MORE2, 4, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( encapsSections[3], "//" )), nullptr, 0 ))); + gPriv->SetTempVar( CITV_MORE2, 1, static_cast( std::stoul( util::trim( util::strip( encapsSections[0], "//" )), nullptr, 0 ))); + gPriv->SetTempVar( CITV_MORE2, 2, static_cast( std::stoul( util::trim( util::strip( encapsSections[1], "//" )), nullptr, 0 ))); + gPriv->SetTempVar( CITV_MORE2, 3, static_cast( std::stoul( util::trim( util::strip( encapsSections[2], "//" )), nullptr, 0 ))); + gPriv->SetTempVar( CITV_MORE2, 4, static_cast( std::stoul( util::trim( util::strip( encapsSections[3], "//" )), nullptr, 0 ))); } else { @@ -1234,14 +1236,14 @@ JSBool CItemProps_setProperty( JSContext *cx, JSObject *obj, jsval id, jsval *vp case CIP_MOREX: { auto sEncaps = encaps.toString(); - sEncaps = oldstrutil::trim( oldstrutil::removeTrailing( sEncaps, "//")); + sEncaps = util::trim( util::strip( sEncaps, "//")); auto encapsSections = oldstrutil::sections( sEncaps, " " ); if( encapsSections.size() >= 4 ) { - gPriv->SetTempVar( CITV_MOREX, 1, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( encapsSections[0], "//" )), nullptr, 0 ))); - gPriv->SetTempVar( CITV_MOREX, 2, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( encapsSections[1], "//" )), nullptr, 0 ))); - gPriv->SetTempVar( CITV_MOREX, 3, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( encapsSections[2], "//" )), nullptr, 0 ))); - gPriv->SetTempVar( CITV_MOREX, 4, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( encapsSections[3], "//" )), nullptr, 0 ))); + gPriv->SetTempVar( CITV_MOREX, 1, static_cast( std::stoul( util::trim( util::strip( encapsSections[0], "//" )), nullptr, 0 ))); + gPriv->SetTempVar( CITV_MOREX, 2, static_cast( std::stoul( util::trim( util::strip( encapsSections[1], "//" )), nullptr, 0 ))); + gPriv->SetTempVar( CITV_MOREX, 3, static_cast( std::stoul( util::trim( util::strip( encapsSections[2], "//" )), nullptr, 0 ))); + gPriv->SetTempVar( CITV_MOREX, 4, static_cast( std::stoul( util::trim( util::strip( encapsSections[3], "//" )), nullptr, 0 ))); } else { @@ -1252,14 +1254,14 @@ JSBool CItemProps_setProperty( JSContext *cx, JSObject *obj, jsval id, jsval *vp case CIP_MOREY: { auto sEncaps = encaps.toString(); - sEncaps = oldstrutil::trim( oldstrutil::removeTrailing( sEncaps, "//")); + sEncaps = util::trim( util::strip( sEncaps, "//")); auto encapsSections = oldstrutil::sections( sEncaps, " " ); if( encapsSections.size() >= 4 ) { - gPriv->SetTempVar( CITV_MOREY, 1, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( encapsSections[0], "//" )), nullptr, 0 ))); - gPriv->SetTempVar( CITV_MOREY, 2, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( encapsSections[1], "//" )), nullptr, 0 ))); - gPriv->SetTempVar( CITV_MOREY, 3, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( encapsSections[2], "//" )), nullptr, 0 ))); - gPriv->SetTempVar( CITV_MOREY, 4, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( encapsSections[3], "//" )), nullptr, 0 ))); + gPriv->SetTempVar( CITV_MOREY, 1, static_cast( std::stoul( util::trim( util::strip( encapsSections[0], "//" )), nullptr, 0 ))); + gPriv->SetTempVar( CITV_MOREY, 2, static_cast( std::stoul( util::trim( util::strip( encapsSections[1], "//" )), nullptr, 0 ))); + gPriv->SetTempVar( CITV_MOREY, 3, static_cast( std::stoul( util::trim( util::strip( encapsSections[2], "//" )), nullptr, 0 ))); + gPriv->SetTempVar( CITV_MOREY, 4, static_cast( std::stoul( util::trim( util::strip( encapsSections[3], "//" )), nullptr, 0 ))); } else { @@ -1270,14 +1272,14 @@ JSBool CItemProps_setProperty( JSContext *cx, JSObject *obj, jsval id, jsval *vp case CIP_MOREZ: { auto sEncaps = encaps.toString(); - sEncaps = oldstrutil::trim( oldstrutil::removeTrailing( sEncaps, "//" )); + sEncaps = util::trim( util::strip( sEncaps, "//" )); auto encapsSections = oldstrutil::sections( sEncaps, " " ); if( encapsSections.size() >= 4 ) { - gPriv->SetTempVar( CITV_MOREZ, 1, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( encapsSections[0], "//" )), nullptr, 0 ))); - gPriv->SetTempVar( CITV_MOREZ, 2, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( encapsSections[1], "//" )), nullptr, 0 ))); - gPriv->SetTempVar( CITV_MOREZ, 3, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( encapsSections[2], "//" )), nullptr, 0 ))); - gPriv->SetTempVar( CITV_MOREZ, 4, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( encapsSections[3], "//" )), nullptr, 0 ))); + gPriv->SetTempVar( CITV_MOREZ, 1, static_cast( std::stoul( util::trim( util::strip( encapsSections[0], "//" )), nullptr, 0 ))); + gPriv->SetTempVar( CITV_MOREZ, 2, static_cast( std::stoul( util::trim( util::strip( encapsSections[1], "//" )), nullptr, 0 ))); + gPriv->SetTempVar( CITV_MOREZ, 3, static_cast( std::stoul( util::trim( util::strip( encapsSections[2], "//" )), nullptr, 0 ))); + gPriv->SetTempVar( CITV_MOREZ, 4, static_cast( std::stoul( util::trim( util::strip( encapsSections[3], "//" )), nullptr, 0 ))); } else { @@ -1511,7 +1513,7 @@ JSBool CItemProps_setProperty( JSContext *cx, JSObject *obj, jsval id, jsval *vp if( retVal == JS_FALSE ) { // Dummy function not found, let shard admin know! - Console.Warning( oldstrutil::format( "Script context lost after setting Item property %u. Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", JSVAL_TO_INT( id ), origScriptID )); + Console.Warning( util::format( "Script context lost after setting Item property %u. Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", JSVAL_TO_INT( id ), origScriptID )); } } @@ -2126,7 +2128,7 @@ JSBool CCharacterProps_getProperty( JSContext *cx, JSObject *obj, jsval id, jsva if( retVal == JS_FALSE ) { // Dummy function not found, let shard admin know! - Console.Warning( oldstrutil::format( "Script context lost after setting Item property %u. Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", JSVAL_TO_INT( id ), origScriptID )); + Console.Warning( util::format( "Script context lost after setting Item property %u. Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", JSVAL_TO_INT( id ), origScriptID )); } } @@ -2188,7 +2190,7 @@ JSBool CCharacterProps_setProperty( JSContext *cx, JSObject *obj, jsval id, jsva cScript *toExecute = JSMapping->GetScript( scriptId ); if( toExecute == nullptr ) { - ScriptError( cx, oldstrutil::format( "Unable to assign script trigger - script ID (%i) not found in jse_fileassociations.scp!", scriptId ).c_str() ); + ScriptError( cx, util::format( "Unable to assign script trigger - script ID (%i) not found in jse_fileassociations.scp!", scriptId ).c_str() ); } else { @@ -2205,7 +2207,7 @@ JSBool CCharacterProps_setProperty( JSContext *cx, JSObject *obj, jsval id, jsva cScript *toExecute = JSMapping->GetScript( scriptId ); if( toExecute == nullptr ) { - ScriptError( cx, oldstrutil::format( "Unable to assign script trigger - script ID (%i) not found in jse_fileassociations.scp!", scriptId ).c_str() ); + ScriptError( cx, util::format( "Unable to assign script trigger - script ID (%i) not found in jse_fileassociations.scp!", scriptId ).c_str() ); } else { @@ -2607,7 +2609,7 @@ JSBool CCharacterProps_setProperty( JSContext *cx, JSObject *obj, jsval id, jsva if( retVal == JS_FALSE ) { // Dummy function not found, let shard admin know! - Console.Warning( oldstrutil::format( "Script context lost after setting Character property %u. Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", JSVAL_TO_INT( id ), origScriptID )); + Console.Warning( util::format( "Script context lost after setting Character property %u. Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", JSVAL_TO_INT( id ), origScriptID )); } } @@ -2750,7 +2752,7 @@ JSBool CRegionProps_setProperty( JSContext *cx, JSObject *obj, jsval id, jsval * cScript *toExecute = JSMapping->GetScript( scriptId ); if( toExecute == nullptr ) { - ScriptError( cx, oldstrutil::format( "Unable to assign script trigger - script ID (%i) not found in jse_fileassociations.scp!", scriptId ).c_str() ); + ScriptError( cx, util::format( "Unable to assign script trigger - script ID (%i) not found in jse_fileassociations.scp!", scriptId ).c_str() ); } else { @@ -2767,7 +2769,7 @@ JSBool CRegionProps_setProperty( JSContext *cx, JSObject *obj, jsval id, jsval * cScript *toExecute = JSMapping->GetScript( scriptId ); if( toExecute == nullptr ) { - ScriptError( cx, oldstrutil::format( "Unable to assign script trigger - script ID (%i) not found in jse_fileassociations.scp!", scriptId ).c_str() ); + ScriptError( cx, util::format( "Unable to assign script trigger - script ID (%i) not found in jse_fileassociations.scp!", scriptId ).c_str() ); } else { @@ -2803,7 +2805,7 @@ JSBool CRegionProps_setProperty( JSContext *cx, JSObject *obj, jsval id, jsval * if( retVal == JS_FALSE ) { // Dummy function not found, let shard admin know! - Console.Warning( oldstrutil::format( "Script context lost after setting Region property %u. Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", JSVAL_TO_INT( id ), origScriptID )); + Console.Warning( util::format( "Script context lost after setting Region property %u. Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", JSVAL_TO_INT( id ), origScriptID )); } } @@ -2942,7 +2944,7 @@ JSBool CSpawnRegionProps_setProperty( JSContext *cx, JSObject *obj, jsval id, js if( retVal == JS_FALSE ) { // Dummy function not found, let shard admin know! - Console.Warning( oldstrutil::format( "Script context lost after setting SpawnRegion property %u. Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", JSVAL_TO_INT( id ), origScriptID )); + Console.Warning( util::format( "Script context lost after setting SpawnRegion property %u. Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", JSVAL_TO_INT( id ), origScriptID )); } } @@ -3082,7 +3084,7 @@ JSBool CGuildProps_setProperty( JSContext *cx, JSObject *obj, jsval id, jsval *v if( retVal == JS_FALSE ) { // Dummy function not found, let shard admin know! - Console.Warning( oldstrutil::format( "Script context lost after setting Guild property %u. Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", JSVAL_TO_INT( id ), origScriptID )); + Console.Warning( util::format( "Script context lost after setting Guild property %u. Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", JSVAL_TO_INT( id ), origScriptID )); } } @@ -3177,7 +3179,7 @@ JSBool CRaceProps_setProperty( JSContext *cx, JSObject *obj, jsval id, jsval *vp JSBool retVal = origScript->CallParticularEvent( "_restorecontext_", &id, 0, vp ); if( retVal == JS_FALSE ) { - Console.Warning( oldstrutil::format( "Script context lost after setting Race property %u. Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", JSVAL_TO_INT( id ), origScriptID )); + Console.Warning( util::format( "Script context lost after setting Race property %u. Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", JSVAL_TO_INT( id ), origScriptID )); } } @@ -3281,7 +3283,7 @@ JSBool CSocketProps_setProperty( JSContext *cx, JSObject *obj, jsval id, jsval * if( retVal == JS_FALSE ) { // Dummy function not found, let shard admin know! - Console.Warning( oldstrutil::format( "Script context lost after setting Socket property %u. Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", JSVAL_TO_INT( id ), origScriptID )); + Console.Warning( util::format( "Script context lost after setting Socket property %u. Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", JSVAL_TO_INT( id ), origScriptID )); } } @@ -3586,7 +3588,7 @@ JSBool CSkillsProps_setProperty( JSContext *cx, JSObject *obj, jsval id, jsval * if( retVal == JS_FALSE ) { // Dummy function not found, let shard admin know! - Console.Warning( oldstrutil::format( "Script context lost after setting Skill property %u. Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", JSVAL_TO_INT( id ), origScriptID )); + Console.Warning( util::format( "Script context lost after setting Skill property %u. Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", JSVAL_TO_INT( id ), origScriptID )); } } @@ -3830,10 +3832,10 @@ JSBool CAccountProps_getProperty( JSContext *cx, JSObject *obj, jsval id, jsval } case CACCOUNT_LASTIP: { - std::string ipString = oldstrutil::number( static_cast(( myAccount->dwLastIP & 0xFF000000 ) >> 24 )) - + "." + oldstrutil::number( static_cast(( myAccount->dwLastIP & 0x00FF0000 ) >> 16 )) - + "." + oldstrutil::number( static_cast(( myAccount->dwLastIP & 0x0000FF00 ) >> 8 )) - + "." + oldstrutil::number( static_cast(( myAccount->dwLastIP & 0x000000FF ) % 256 )); + std::string ipString = util::ntos( static_cast(( myAccount->dwLastIP & 0xFF000000 ) >> 24 )) + + "." + util::ntos( static_cast(( myAccount->dwLastIP & 0x00FF0000 ) >> 16 )) + + "." + util::ntos( static_cast(( myAccount->dwLastIP & 0x0000FF00 ) >> 8 )) + + "." + util::ntos( static_cast(( myAccount->dwLastIP & 0x000000FF ) % 256 )); tString = JS_NewStringCopyZ( cx, ipString.c_str() ); *vp = STRING_TO_JSVAL( tString ); break; @@ -3952,7 +3954,7 @@ JSBool CAccountProps_setProperty( JSContext *cx, JSObject *obj, jsval id, jsval if( retVal == JS_FALSE ) { // Dummy function not found, let shard admin know! - Console.Warning( oldstrutil::format( "Script context lost after setting Account property %u. Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", JSVAL_TO_INT( id ), origScriptID )); + Console.Warning( util::format( "Script context lost after setting Account property %u. Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", JSVAL_TO_INT( id ), origScriptID )); } } @@ -4070,7 +4072,7 @@ JSBool CResourceProps_setProperty( JSContext *cx, JSObject *obj, jsval id, jsval if( retVal == JS_FALSE ) { // Dummy function not found, let shard admin know! - Console.Warning( oldstrutil::format( "Script context lost after setting Resource property %u. Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", JSVAL_TO_INT( id ), origScriptID )); + Console.Warning( util::format( "Script context lost after setting Resource property %u. Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", JSVAL_TO_INT( id ), origScriptID )); } } @@ -4151,7 +4153,7 @@ JSBool CPartyProps_setProperty( JSContext *cx, JSObject *obj, jsval id, jsval *v if( retVal == JS_FALSE ) { // Dummy function not found, let shard admin know! - Console.Warning( oldstrutil::format( "Script context lost after setting Party property %u. Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", JSVAL_TO_INT( id ), origScriptID )); + Console.Warning( util::format( "Script context lost after setting Party property %u. Add 'function _restorecontext_() {}' to original script (%u) as safeguard!", JSVAL_TO_INT( id ), origScriptID )); } } diff --git a/source/ai.cpp b/source/ai.cpp index ab72060ac..3eac41630 100644 --- a/source/ai.cpp +++ b/source/ai.cpp @@ -22,6 +22,7 @@ #include "cScript.h" #include "Dictionary.h" #include "StringUtility.hpp" +#include "utility/strutil.hpp" #undef DBGFILE #define DBGFILE "ai.cpp" @@ -671,7 +672,7 @@ void CheckAI( CChar& mChar ) default: { std::string mCharName = GetNpcDictName( &mChar, nullptr, NRS_SYSTEM ); - Console.Error( oldstrutil::format( " CheckAI() Error npc %s(0x%X) has invalid AI type %i", mCharName.c_str(), mChar.GetSerial(), mChar.GetNpcAiType() )); //Morrolan + Console.Error( util::format( " CheckAI() Error npc %s(0x%X) has invalid AI type %i", mCharName.c_str(), mChar.GetSerial(), mChar.GetNpcAiType() )); //Morrolan return; } } diff --git a/source/archive.cpp b/source/archive.cpp index e09d732fa..b89a65b5a 100644 --- a/source/archive.cpp +++ b/source/archive.cpp @@ -5,6 +5,7 @@ #include #include #include "osunique.hpp" +#include "utility/strutil.hpp" //o------------------------------------------------------------------------------------------------o //| Function - BackupFile() @@ -33,7 +34,7 @@ void FileArchive( void ) auto mytime = std::chrono::system_clock::to_time_t( std::chrono::system_clock::now() ); struct tm ttemp; char tbuffer[100]; - auto timenow = oldstrutil::simplify( asciitime( tbuffer, 100, *lcltime( mytime, ttemp ))); + auto timenow = util::simplify( asciitime( tbuffer, 100, *lcltime( mytime, ttemp ))); timenow = std::regex_replace( timenow, std::regex( "[\\s:]" ), std::string( "-" )); std::string backupRoot = cwmWorldState->ServerData()->Directory( CSDDP_BACKUP ); @@ -52,13 +53,13 @@ void FileArchive( void ) const SI16 AreaX = UpperX / 8; // we're storing 8x8 grid arrays together const SI16 AreaY = UpperY / 8; - auto backupPath = oldstrutil::format( "%s%s/", cwmWorldState->ServerData()->Directory( CSDDP_SHARED ).c_str(), timenow.c_str() ); + auto backupPath = util::format( "%s%s/", cwmWorldState->ServerData()->Directory( CSDDP_SHARED ).c_str(), timenow.c_str() ); for( SI16 counter1 = 0; counter1 < AreaX; ++counter1 ) // move left->right { for( SI16 counter2 = 0; counter2 < AreaY; ++counter2 ) // move up->down { - auto filename1 = oldstrutil::format( "%i.%i.wsc", counter1, counter2 ); + auto filename1 = util::format( "%i.%i.wsc", counter1, counter2 ); BackupFile( filename1, backupRoot ); } } diff --git a/source/boats.cpp b/source/boats.cpp index 8829b2249..50e84a524 100644 --- a/source/boats.cpp +++ b/source/boats.cpp @@ -7,6 +7,7 @@ #include "cEffects.h" #include "Dictionary.h" #include "StringUtility.hpp" +#include "utility/strutil.hpp" #define XP 0 @@ -206,7 +207,7 @@ void OpenPlank( CItem *p ) case 0xD5: p->SetId( 0xB1, 2 ); break; case 0xD4: p->SetId( 0xB2, 2 ); break; case 0x89: p->SetId( 0x8A, 2 ); break; - default: Console.Warning( oldstrutil::format( "Invalid plank ID called! Plank 0x%X '%s' [%u]", p->GetSerial(), p->GetName().c_str(), p->GetId() )); + default: Console.Warning( util::format( "Invalid plank ID called! Plank 0x%X '%s' [%u]", p->GetSerial(), p->GetName().c_str(), p->GetId() )); break; } } @@ -891,7 +892,7 @@ void TurnBoat( CBoatObj *b, bool rightTurn, bool disableChecks ) tiller->IncLocation( iLargeShipOffsets[dir][TILLER][XP], iLargeShipOffsets[dir][TILLER][YP] ); hold->IncLocation( iLargeShipOffsets[dir][HOLD][XP], iLargeShipOffsets[dir][HOLD][YP] ); break; - default: Console.Error( oldstrutil::format( "TurnBoat() more1 error! more1 = %c not found!", b->GetTempVar( CITV_MOREZ, 1 ))); + default: Console.Error( util::format( "TurnBoat() more1 error! more1 = %c not found!", b->GetTempVar( CITV_MOREZ, 1 ))); } for( auto &tSock :nearbyChars ) @@ -1001,15 +1002,15 @@ void CBoatResponse::Handle( CSocket *mSock, CChar *mChar ) } // Check if player provided anything after the actual set name command - std::string cmdString = oldstrutil::upper( Dictionary->GetEntry( 1425, mLang )); // SET NAME - if( oldstrutil::upper( ourText ).size() == cmdString.size() ) + std::string cmdString = util::upper( Dictionary->GetEntry( 1425, mLang )); // SET NAME + if( util::upper( ourText ).size() == cmdString.size() ) { tiller->TextMessage( mSock, 12 ); // Can ya say that again with an actual name, sir? return; } // Check if we can find the dictionary-based command string in the player's speech - std::string upperOurText = oldstrutil::upper( ourText ); + std::string upperOurText = util::upper( ourText ); size_t cmdStringPos = upperOurText.find( cmdString ); if( cmdStringPos == std::string::npos ) { @@ -1026,7 +1027,7 @@ void CBoatResponse::Handle( CSocket *mSock, CChar *mChar ) } // Trim spaces from start and end of player provided name, and see if there's actually a name there and not just empty spaces! - ourText = oldstrutil::trim( ourText ); + ourText = util::trim( ourText ); if( ourText.size() == 0 ) { boat->SetName( Dictionary->GetEntry( 2035, mLang )); // a ship diff --git a/source/books.cpp b/source/books.cpp index 6dc86b92f..ccd911a1f 100644 --- a/source/books.cpp +++ b/source/books.cpp @@ -27,6 +27,8 @@ #include "ssection.h" #include "CPacketSend.h" #include "StringUtility.hpp" +#include "utility/strutil.hpp" + #include "osunique.hpp" using namespace std::string_literals; @@ -48,7 +50,7 @@ bool CPINewBookHeader::Handle( void ) if( !ValidateObject( mBook )) return true; - const std::string fileName = cwmWorldState->ServerData()->Directory( CSDDP_BOOKS ) + oldstrutil::number( bookSer, 16 ) + std::string( ".bok" ); + const std::string fileName = cwmWorldState->ServerData()->Directory( CSDDP_BOOKS ) + util::ntos( bookSer, 16 ) + std::string( ".bok" ); if( !FileExists( fileName )) { @@ -81,18 +83,18 @@ bool CPINewBookHeader::Handle( void ) if( file.fail() ) { - Console.Error( oldstrutil::format( "Couldn't write to book file %s", fileName.c_str() )); + Console.Error( util::format( "Couldn't write to book file %s", fileName.c_str() )); } } else { - Console.Error( oldstrutil::format( "Failed to seek to book file %s", fileName.c_str() )); + Console.Error( util::format( "Failed to seek to book file %s", fileName.c_str() )); } file.close(); } else { - Console.Error( oldstrutil::format( "Couldn't write to book file %s for book 0x%X", fileName.c_str(), bookSer) ); + Console.Error( util::format( "Couldn't write to book file %s for book 0x%X", fileName.c_str(), bookSer) ); } } return true; @@ -108,7 +110,7 @@ auto CBooks::OpenPreDefBook( CSocket *mSock, CItem *i ) -> void { if( mSock ) { - auto temp = "BOOK "s + oldstrutil::number( i->GetTempVar( CITV_MORE )); + auto temp = "BOOK "s + util::ntos( i->GetTempVar( CITV_MORE )); auto book = FileLookup->FindEntry( temp, misc_def ); if( book ) { @@ -121,7 +123,7 @@ auto CBooks::OpenPreDefBook( CSocket *mSock, CItem *i ) -> void for( const auto &sec : book->collection() ) { auto tag = sec->tag; - auto UTag = oldstrutil::upper( tag ); + auto UTag = util::upper( tag ); auto data = sec->data; if( UTag == "PAGES" ) { @@ -169,7 +171,7 @@ void CBooks::OpenBook( CSocket *mSock, CItem *mBook, bool isWriteable ) UI16 numPages = 0; std::string bookTitle, bookAuthor; - const std::string fileName = cwmWorldState->ServerData()->Directory( CSDDP_BOOKS ) + oldstrutil::number( mBook->GetSerial(), 16 ) + std::string( ".bok" ); + const std::string fileName = cwmWorldState->ServerData()->Directory( CSDDP_BOOKS ) + util::ntos( mBook->GetSerial(), 16 ) + std::string( ".bok" ); std::ifstream file( fileName.c_str(), std::ios::in | std::ios::binary ); @@ -217,7 +219,7 @@ void CBooks::OpenBook( CSocket *mSock, CItem *mBook, bool isWriteable ) } else { - Console.Error( oldstrutil::format( "Failed to seek to book file %s", fileName.c_str() )); + Console.Error( util::format( "Failed to seek to book file %s", fileName.c_str() )); } file.close(); @@ -280,7 +282,7 @@ auto CBooks::ReadPreDefBook( CSocket *mSock, CItem *i, UI16 p ) -> void { if( mSock ) { - auto temp = "BOOK "s + oldstrutil::number( i->GetTempVar( CITV_MORE )); + auto temp = "BOOK "s + util::ntos( i->GetTempVar( CITV_MORE )); CScriptSection *book = FileLookup->FindEntry( temp, misc_def ); if( book ) { @@ -340,7 +342,7 @@ bool CPIBookPage::Handle( void ) return true; } - const std::string fileName = cwmWorldState->ServerData()->Directory( CSDDP_BOOKS ) + oldstrutil::number( mBook->GetSerial(), 16 ) + std::string( ".bok" ); + const std::string fileName = cwmWorldState->ServerData()->Directory( CSDDP_BOOKS ) + util::ntos( mBook->GetSerial(), 16 ) + std::string( ".bok" ); UI16 totalLines = tSock->GetWord( 11 ); // Cap amount of lines sent in one go at 8 per page @@ -389,13 +391,13 @@ bool CPIBookPage::Handle( void ) } else { - Console.Error( oldstrutil::format( "Failed to seek to book file %s", fileName.c_str() )); + Console.Error( util::format( "Failed to seek to book file %s", fileName.c_str() )); } file.close(); } else { - Console.Error( oldstrutil::format( "Couldn't write to book file %s", fileName.c_str() )); + Console.Error( util::format( "Couldn't write to book file %s", fileName.c_str() )); } } return true; @@ -409,7 +411,7 @@ bool CPIBookPage::Handle( void ) //o------------------------------------------------------------------------------------------------o void CBooks::DeleteBook( CItem *id ) { - std::string fileName = cwmWorldState->ServerData()->Directory( CSDDP_BOOKS ) + oldstrutil::number( id->GetSerial(), 16 ) + std::string( ".bok" ); + std::string fileName = cwmWorldState->ServerData()->Directory( CSDDP_BOOKS ) + util::ntos( id->GetSerial(), 16 ) + std::string( ".bok" ); [[maybe_unused]] int removeResult = remove( fileName.c_str() ); } diff --git a/source/cAccountClass.cpp b/source/cAccountClass.cpp index 10d0c3882..7da152025 100644 --- a/source/cAccountClass.cpp +++ b/source/cAccountClass.cpp @@ -14,6 +14,8 @@ #include #include #include "StringUtility.hpp" +#include "utility/strutil.hpp" + #include "osunique.hpp" #if PLATFORM != WINDOWS #include @@ -128,27 +130,27 @@ UI16 cAccountClass::CreateAccountSystem( void ) UI08 nLockCount = 0x00; bool bSkipUAD = false; actb.reset(); - sLine = oldstrutil::trim( oldstrutil::removeTrailing( sLine, "//" )); + sLine = util::trim( util::strip( sLine, "//" )); while( !fs2.eof() && !fs2.fail() ) { if( sLine.empty() || sLine.length() == 0 ) // Either nothing on the line, or there was a comment we've ignored { std::getline( fs2, sLine ); - sLine = oldstrutil::trim( oldstrutil::removeTrailing( sLine, "//" )); + sLine = util::trim( util::strip( sLine, "//" )); continue; } // Check to see if there is an EOF for those that are like legacy FREAKS!!! Freaks I say!! if( "EOF" == sLine ) { std::getline( fs2, sLine ); - sLine = oldstrutil::trim( oldstrutil::removeTrailing( sLine, "//" )); + sLine = util::trim( util::strip( sLine, "//" )); continue; } // Keep track of the section account lines. There is nothing to process till at least one of these has been read if( sLine.substr( 0, 15 ) == "SECTION ACCOUNT" ) { // Ok the section block was found, Tokenize the string to get the account # - auto accountIdFromFile = oldstrutil::value( oldstrutil::extractSection( sLine, " ", 2, 2 )); + auto accountIdFromFile = util::ston( oldstrutil::extractSection( sLine, " ", 2, 2 )); if( accountIdFromFile == 0 && wAccountCount > 0 ) { actb.wAccountIndex = wAccountCount; @@ -169,7 +171,7 @@ UI16 cAccountClass::CreateAccountSystem( void ) bBraces[2] = true; // Get the next line and continue std::getline( fs2, sLine ); - sLine = oldstrutil::trim( oldstrutil::removeTrailing( sLine, "//" )); + sLine = util::trim( util::strip( sLine, "//" )); continue; } // Fail safe. If bBraces[2] isn't set there is no need to even run this code @@ -177,7 +179,7 @@ UI16 cAccountClass::CreateAccountSystem( void ) { // Make sure the get the next line to process. std::getline( fs2, sLine ); - sLine = oldstrutil::trim( oldstrutil::removeTrailing( sLine, "//" )); + sLine = util::trim( util::strip( sLine, "//" )); continue; } // If we get here then were reading a block now. Check for the openning brace. @@ -185,7 +187,7 @@ UI16 cAccountClass::CreateAccountSystem( void ) { bBraces[0] = true; std::getline( fs2, sLine ); - sLine = oldstrutil::trim( oldstrutil::removeTrailing( sLine, "//" )); + sLine = util::trim( util::strip( sLine, "//" )); continue; } if((( sLine[0] == '{') && bBraces[0] ) || (( sLine[0] == '{' ) && bBraces[1] )) @@ -206,33 +208,33 @@ UI16 cAccountClass::CreateAccountSystem( void ) bBraces[0] = false; nLockCount = 0; std::getline( fs2, sLine ); - sLine = oldstrutil::trim( oldstrutil::removeTrailing( sLine, "//" )); + sLine = util::trim( util::strip( sLine, "//" )); continue; } // Set up the tokenizing auto ssecs = oldstrutil::sections( sLine, " " ); - auto l = oldstrutil::trim( oldstrutil::removeTrailing( ssecs[0], "//" )); + auto l = util::trim( util::strip( ssecs[0], "//" )); std::string r = ""; if( ssecs.size() > 1 ) { - r = oldstrutil::trim( oldstrutil::removeTrailing( ssecs[1], "//" )); + r = util::trim( util::strip( ssecs[1], "//" )); } // Parse and store based on tag if( "NAME" == l ) { if( !r.empty() && r.length() != 0 ) { - actb.sUsername = r; //oldstrutil::lower( r ); + actb.sUsername = r; //util::lower( r ); if( ssecs.size() > 2 ) { - actb.sUsername += ssecs[2]; // oldstrutil::lower( ssecs[2] ); + actb.sUsername += ssecs[2]; // util::lower( ssecs[2] ); } // Next thing were going to do is make sure there isn't a duplicate username. while( IsUser( actb.sUsername )) { // This username is already on the list, keep adding a random value to the end of the username until we find a free one - actb.sUsername += oldstrutil::number( RandomNum( 10000, 20000 )); + actb.sUsername += util::ntos( RandomNum( 10000, 20000 )); } } else @@ -240,7 +242,7 @@ UI16 cAccountClass::CreateAccountSystem( void ) actb.sUsername = "ERROR"; } std::getline( fs2, sLine ); - sLine = oldstrutil::trim( oldstrutil::removeTrailing( sLine, "//" )); + sLine = util::trim( util::strip( sLine, "//" )); continue; } else if( l == "PASS" ) @@ -254,21 +256,21 @@ UI16 cAccountClass::CreateAccountSystem( void ) if( fs1.is_open() ) { std::getline( fs1, sLine2 ); - sLine2 = oldstrutil::trim( oldstrutil::removeTrailing( sLine2, "//" )); + sLine2 = util::trim( util::strip( sLine2, "//" )); bBraces2[2] = true; while( !fs1.eof() && bBraces2[2] && !fs1.fail() ) { if( sLine2.empty() && sLine2.length() != 0 ) { std::getline( fs1, sLine2 ); - sLine2 = oldstrutil::trim( oldstrutil::removeTrailing( sLine2, "//" )); + sLine2 = util::trim( util::strip( sLine2, "//" )); continue; } // Keep track of the section account lines. There is nothing to process till at least one of these has been read if( sLine2.substr( 0, 14 ) == "SECTION ACCESS" ) { // Ok the section block was found, Tokenize the string to get the account # - wAccessId = oldstrutil::value( oldstrutil::extractSection( sLine2, " ", 2 )); + wAccessId = util::ston( oldstrutil::extractSection( sLine2, " ", 2 )); // Ok, we have parsed out the account ID, Set bBraces[2] to true to allow block reading bBraces2[0] = false; bBraces2[1] = false; @@ -310,8 +312,8 @@ UI16 cAccountClass::CreateAccountSystem( void ) break; } auto ssecs = oldstrutil::sections( sLine2, " " ); - auto l2 = oldstrutil::trim( oldstrutil::removeTrailing( ssecs[0], "//" )); - auto r2 = oldstrutil::trim( oldstrutil::removeTrailing( ssecs[1], "//" )); + auto l2 = util::trim( util::strip( ssecs[0], "//" )); + auto r2 = util::trim( util::strip( ssecs[1], "//" )); // Parse and store based on tag if( "PATH" == l2 ) { @@ -410,7 +412,7 @@ UI16 cAccountClass::CreateAccountSystem( void ) auto psecs = oldstrutil::sections( r, "." ); if( !r.empty() && r.length() != 0 && psecs.size() == 4 ) { - actb.dwLastIP = CalcSerial( oldstrutil::value( psecs[0] ), oldstrutil::value( psecs[1] ), oldstrutil::value( psecs[2] ), oldstrutil::value( psecs[3] )); + actb.dwLastIP = CalcSerial( util::ston( psecs[0] ), util::ston( psecs[1] ), util::ston( psecs[2] ), util::ston( psecs[3] )); } else { @@ -425,7 +427,7 @@ UI16 cAccountClass::CreateAccountSystem( void ) // Ok strip the name and store it. We need to make it all the same case for comparisons if( !r.empty() && r.length() != 0 ) { - actb.sContact = oldstrutil::lower( r ); + actb.sContact = util::lower( r ); } else { @@ -512,10 +514,10 @@ UI16 cAccountClass::CreateAccountSystem( void ) } else { - r = oldstrutil::trim(r); + r = util::trim(r); if( !r.empty() ) { - auto temp = oldstrutil::value(r); // int64_t used for promotion from 32-bit int + auto temp = util::ston(r); // int64_t used for promotion from 32-bit int if( (temp > 0) && (temp < static_cast(INVALIDSERIAL)) ) { actb.dwCharacters[charNum-1] = static_cast(std::stoul( r, nullptr, 0 )); @@ -566,7 +568,7 @@ UI16 cAccountClass::CreateAccountSystem( void ) auto create_status = std::filesystem::create_directory( std::filesystem::path( sNewPath )); if( !create_status ) { - Console.Error( oldstrutil::format( "CreateAccountSystem(): Couldn't create directory %s", sNewPath.c_str() )); + Console.Error( util::format( "CreateAccountSystem(): Couldn't create directory %s", sNewPath.c_str() )); m_mapUsernameIdMap.clear(); m_mapUsernameMap.clear(); return 0L; @@ -652,7 +654,7 @@ UI16 cAccountClass::CreateAccountSystem( void ) while( nResp == -1 ) { // Loop through 255 numbers, these will be added to the end of the bu in case a bu exists. - szltoa2 = oldstrutil::format( "%d", kk++ ); + szltoa2 = util::format( "%d", kk++ ); sNewPath += szltoa2; nResp= rename( sAccountsAdm.c_str(), sNewPath.c_str() ); sNewPath = sBUPath; @@ -738,7 +740,7 @@ UI16 cAccountClass::AddAccount( std::string sUsername, std::string sPassword, co if( sUsername.length() < 4 || sPassword.length() < 5 ) { // Username and password must be 4 and 5 characters or more in length, respectively - Console.Log( oldstrutil::format( "ERROR: Unable to create account for username '%s' with password of '%s'. Username/Password to short", sUsername.c_str(), sPassword.c_str() ), "accounts.log" ); + Console.Log( util::format( "ERROR: Unable to create account for username '%s' with password of '%s'. Username/Password to short", sUsername.c_str(), sPassword.c_str() ), "accounts.log" ); return 0x0000; } // Next thing were going to do is make sure there isn't a duplicate username. @@ -774,7 +776,7 @@ UI16 cAccountClass::AddAccount( std::string sUsername, std::string sPassword, co std::string sTempPath( m_sAccountsDirectory ); if( sTempPath[sTempPath.length() - 1] == '\\' || sTempPath[sTempPath.length() - 1] == '/' ) { - auto szTempBuff = sUsername; // oldstrutil::lower( sUsername ); + auto szTempBuff = sUsername; // util::lower( sUsername ); sTempPath += szTempBuff; sTempPath += "/"; sTempPath = oldstrutil::replaceSlash( sTempPath ); @@ -782,7 +784,7 @@ UI16 cAccountClass::AddAccount( std::string sUsername, std::string sPassword, co } else { - auto szTempBuff = sUsername; //oldstrutil::lower( sUsername ); + auto szTempBuff = sUsername; //util::lower( sUsername ); sTempPath += "/"; sTempPath += szTempBuff; sTempPath += "/"; @@ -795,7 +797,7 @@ UI16 cAccountClass::AddAccount( std::string sUsername, std::string sPassword, co auto create_status = std::filesystem::create_directory( std::filesystem::path( actbTemp.sPath )); if( !create_status ) { - Console.Error( oldstrutil::format( "AddAccount(): Couldn't create directory %s", actbTemp.sPath.c_str() )); + Console.Error( util::format( "AddAccount(): Couldn't create directory %s", actbTemp.sPath.c_str() )); return 0x0000; } @@ -966,7 +968,7 @@ UI16 cAccountClass::Load( void ) // We need to read from the stream once before entering the loop std::getline( fsAccountsADM, sLine ); - sLine = oldstrutil::trim( oldstrutil::removeTrailing( sLine, "//" )); + sLine = util::trim( util::strip( sLine, "//" )); // Ok start the loop and process bool bBraces[3] = { false, false, false }; [[maybe_unused]] bool bBraces2[3] = { false, false, false }; @@ -983,7 +985,7 @@ UI16 cAccountClass::Load( void ) if( sLine[0] == '\\' || sLine[0] == ';' || sLine[0] == '/' || sLine[0] == '\'' || sLine[0] == 0x13|| sLine[0] == 0x00 ) { std::getline( fsAccountsADM, sLine ); - sLine = oldstrutil::trim( oldstrutil::removeTrailing( sLine, "//" )); + sLine = util::trim( util::strip( sLine, "//" )); continue; } // Keep track of the section account lines. There is nothing to process till at least one of these has been read @@ -991,7 +993,7 @@ UI16 cAccountClass::Load( void ) { // Increment the account acount ++wAccountCount; - actb.wAccountIndex = wAccountId = oldstrutil::value( oldstrutil::extractSection( sLine, " ", 2 )); + actb.wAccountIndex = wAccountId = util::ston( oldstrutil::extractSection( sLine, " ", 2 )); // Scan for hiegest account. Needed for additional accounts. if( actb.wAccountIndex>m_wHighestAccount ) @@ -1004,7 +1006,7 @@ UI16 cAccountClass::Load( void ) bBraces[2] = true; // Get the next line and continue std::getline( fsAccountsADM, sLine ); - sLine = oldstrutil::trim( oldstrutil::removeTrailing( sLine, "//" )); + sLine = util::trim( util::strip( sLine, "//" )); continue; } // Fail safe. If bBraces[2] isn't set there is no need to even run this code @@ -1012,7 +1014,7 @@ UI16 cAccountClass::Load( void ) { // Make sure the get the next line to process. std::getline( fsAccountsADM, sLine ); - sLine = oldstrutil::trim( oldstrutil::removeTrailing( sLine, "//" )); + sLine = util::trim( util::strip( sLine, "//" )); continue; } // If we get here then were reading a block now. Check for the openning brace. @@ -1020,7 +1022,7 @@ UI16 cAccountClass::Load( void ) { bBraces[0]=true; std::getline( fsAccountsADM, sLine ); - sLine = oldstrutil::trim( oldstrutil::removeTrailing( sLine, "//" )); + sLine = util::trim( util::strip( sLine, "//" )); continue; } if((( sLine[0] == '{' ) && bBraces[0] ) || (( sLine[0] == '{' ) && bBraces[1] )) @@ -1084,7 +1086,7 @@ UI16 cAccountClass::Load( void ) bBraces[1] = false; bBraces[2] = false; std::getline( fsAccountsADM, sLine ); - sLine = oldstrutil::trim( oldstrutil::removeTrailing( sLine, "//" )); + sLine = util::trim( util::strip( sLine, "//" )); for( UI08 kk = 0; kk < CHARACTERCOUNT; ++kk ) { dwChars[kk] = INVALIDSERIAL; @@ -1092,15 +1094,15 @@ UI16 cAccountClass::Load( void ) continue; } auto ssecs = oldstrutil::sections( sLine, " " ); - auto l = oldstrutil::trim( oldstrutil::removeTrailing( ssecs[0], "//" )); - auto r = oldstrutil::trim( oldstrutil::removeTrailing( ssecs[1], "//" )); + auto l = util::trim( util::strip( ssecs[0], "//" )); + auto r = util::trim( util::strip( ssecs[1], "//" )); // Parse and store based on tag if( l == "NAME" ) { // Ok strip the name and store it. We need to make it all the same case for comparisons if( !r.empty() && r.length() != 0 ) { - actb.sUsername = r; //oldstrutil::lower( r ); + actb.sUsername = r; //util::lower( r ); } else { @@ -1108,7 +1110,7 @@ UI16 cAccountClass::Load( void ) } std::getline( fsAccountsADM, sLine ); - sLine = oldstrutil::trim( oldstrutil::removeTrailing( sLine, "//" )); + sLine = util::trim( util::strip( sLine, "//" )); continue; } else if( l == "PASS" ) @@ -1128,7 +1130,7 @@ UI16 cAccountClass::Load( void ) bBraces2[1] = false; bBraces2[2] = false; std::getline( fsAccountsADM, sLine ); - sLine = oldstrutil::trim( oldstrutil::removeTrailing( sLine, "//" )); + sLine = util::trim( util::strip( sLine, "//" )); continue; } else if( l == "FLAGS" ) @@ -1147,7 +1149,7 @@ UI16 cAccountClass::Load( void ) } std::getline( fsAccountsADM, sLine ); - sLine = oldstrutil::trim( oldstrutil::removeTrailing( sLine, "//" )); + sLine = util::trim( util::strip( sLine, "//" )); continue; } else if( l == "PATH" ) @@ -1163,7 +1165,7 @@ UI16 cAccountClass::Load( void ) } std::getline( fsAccountsADM, sLine ); - sLine = oldstrutil::trim( oldstrutil::removeTrailing( sLine, "//" )); + sLine = util::trim( util::strip( sLine, "//" )); continue; } else if( l == "TIMEBAN" ) @@ -1178,7 +1180,7 @@ UI16 cAccountClass::Load( void ) } std::getline( fsAccountsADM, sLine ); - sLine = oldstrutil::trim( oldstrutil::removeTrailing( sLine, "//" )); + sLine = util::trim( util::strip( sLine, "//" )); continue; } else if( l == "FIRSTLOGIN" ) @@ -1193,7 +1195,7 @@ UI16 cAccountClass::Load( void ) } std::getline( fsAccountsADM, sLine ); - sLine = oldstrutil::trim( oldstrutil::removeTrailing( sLine, "//" )); + sLine = util::trim( util::strip( sLine, "//" )); continue; } else if( l == "TOTALPLAYTIME" ) @@ -1208,7 +1210,7 @@ UI16 cAccountClass::Load( void ) } std::getline( fsAccountsADM, sLine ); - sLine = oldstrutil::trim( oldstrutil::removeTrailing( sLine, "//" )); + sLine = util::trim( util::strip( sLine, "//" )); continue; } else if( l == "CONTACT" ) @@ -1216,7 +1218,7 @@ UI16 cAccountClass::Load( void ) // Ok strip the name and store it. We need to make it all the same case for comparisons if( !r.empty() && r.length() != 0 ) { - actb.sContact = oldstrutil::lower( r ); + actb.sContact = util::lower( r ); } else { @@ -1224,7 +1226,7 @@ UI16 cAccountClass::Load( void ) } std::getline( fsAccountsADM, sLine ); - sLine = oldstrutil::trim( oldstrutil::removeTrailing( sLine, "//" )); + sLine = util::trim( util::strip( sLine, "//" )); continue; } else if( l == "LASTIP" ) @@ -1232,8 +1234,8 @@ UI16 cAccountClass::Load( void ) auto psecs = oldstrutil::sections( r, "." ); if( !r.empty() && r.length() != 0 && psecs.size() == 4 ) { - actb.dwLastIP = CalcSerial( oldstrutil::value( psecs[0] ), oldstrutil::value( psecs[1] ), - oldstrutil::value( psecs[2] ), oldstrutil::value( psecs[3] )); + actb.dwLastIP = CalcSerial( util::ston( psecs[0] ), util::ston( psecs[1] ), + util::ston( psecs[2] ), util::ston( psecs[3] )); } else { @@ -1241,7 +1243,7 @@ UI16 cAccountClass::Load( void ) } std::getline( fsAccountsADM, sLine ); - sLine = oldstrutil::trim( oldstrutil::removeTrailing( sLine, "//" )); + sLine = util::trim( util::strip( sLine, "//" )); continue; } else if( l.substr( 0, 10 ) == "CHARACTER-" ) // It's a character @@ -1266,11 +1268,11 @@ UI16 cAccountClass::Load( void ) } } std::getline( fsAccountsADM, sLine ); - sLine = oldstrutil::trim( oldstrutil::removeTrailing( sLine, "//" )); + sLine = util::trim( util::strip( sLine, "//" )); continue; } std::getline( fsAccountsADM, sLine ); - sLine = oldstrutil::trim( oldstrutil::removeTrailing( sLine, "//" )); + sLine = util::trim( util::strip( sLine, "//" )); actb.reset(); } // We need to see if there are any new accounts to come. @@ -1843,7 +1845,7 @@ UI16 cAccountClass::Save( [[maybe_unused]] bool bForceLoad ) if( actbId.sUsername != actbName.sUsername || actbId.sPassword != actbName.sPassword ) { // there was an error between blocks - Console.Error( oldstrutil::format( "Save(): Mismatch %s - %s (Duplicate username in accounts file?)", actbId.sUsername.c_str(), actbName.sUsername.c_str() )); + Console.Error( util::format( "Save(): Mismatch %s - %s (Duplicate username in accounts file?)", actbId.sUsername.c_str(), actbName.sUsername.c_str() )); fsAccountsAdm.close(); return 0xFFFF; } @@ -1859,7 +1861,7 @@ UI16 cAccountClass::Save( [[maybe_unused]] bool bForceLoad ) std::string sTempPath( m_sAccountsDirectory ); if( sTempPath[sTempPath.length() - 1] == '\\' || sTempPath[sTempPath.length() - 1] == '/' ) { - auto szTempBuff = actbId.sUsername; // oldstrutil::lower( actbId.sUsername ); + auto szTempBuff = actbId.sUsername; // util::lower( actbId.sUsername ); sTempPath += szTempBuff; sTempPath += "/"; sTempPath = oldstrutil::replaceSlash( sTempPath ); @@ -1867,7 +1869,7 @@ UI16 cAccountClass::Save( [[maybe_unused]] bool bForceLoad ) } else { - auto szTempBuff = actbId.sUsername; // oldstrutil::lower( actbId.sUsername ); + auto szTempBuff = actbId.sUsername; // util::lower( actbId.sUsername ); sTempPath += "/"; sTempPath += szTempBuff; sTempPath += "/"; @@ -1882,7 +1884,7 @@ UI16 cAccountClass::Save( [[maybe_unused]] bool bForceLoad ) auto create_status = std::filesystem::create_directory( std::filesystem::path( actbId.sPath )); if( !create_status ) { - Console.Error( oldstrutil::format( "Save(): Couldn't create directory %s", actbId.sPath.c_str() )); + Console.Error( util::format( "Save(): Couldn't create directory %s", actbId.sPath.c_str() )); fsAccountsAdm << "// !!! Couldn't save .uad file !!!" << std::endl; continue; @@ -1909,7 +1911,7 @@ UI16 cAccountClass::Save( [[maybe_unused]] bool bForceLoad ) if( !fsAccountsUad.is_open() ) { // Ok we were unable to open the file so this user will not be added. - Console.Error( oldstrutil::format( "Save(): Couldn't open file %s", sUsernameUadPath.c_str() )); + Console.Error( util::format( "Save(): Couldn't open file %s", sUsernameUadPath.c_str() )); fsAccountsAdm << "// !!! Couldn't save .uad file !!!" << std::endl; continue; } @@ -1964,7 +1966,7 @@ UI16 cAccountClass::ImportAccounts( void ) } // Now that we have a file, we want to read it, and add these accounts to the system std::getline( fsInputAccountsTest, sLine ); - sLine = oldstrutil::trim( oldstrutil::removeTrailing( sLine, "//" )); + sLine = util::trim( util::strip( sLine, "//" )); UI16 wAccountCount = 0x0000; UI16 wCurrentFlags = 0x0004; while( !fsInputAccountsTest.eof() && !fsInputAccountsTest.fail() ) @@ -1973,22 +1975,22 @@ UI16 cAccountClass::ImportAccounts( void ) if( sLine.empty() || sLine.length() == 0 ) { std::getline( fsInputAccountsTest, sLine ); - sLine = oldstrutil::trim( oldstrutil::removeTrailing( sLine, "//" )); + sLine = util::trim( util::strip( sLine, "//" )); continue; } auto esecs = oldstrutil::sections( sLine, "=" ); - auto l = oldstrutil::trim( oldstrutil::removeTrailing( esecs[0], "//" )); - auto r = oldstrutil::trim( oldstrutil::removeTrailing( esecs[1], "//" )); + auto l = util::trim( util::strip( esecs[0], "//" )); + auto r = util::trim( util::strip( esecs[1], "//" )); if( l == "USER" ) { // OK we have an account to import, start parsing it. std::string user, pass; auto csecs = oldstrutil::sections( r, "," ); - user = oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )); + user = util::trim( util::strip( csecs[0], "//" )); if( csecs.size() > 1 ) { - pass = oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )); + pass = util::trim( util::strip( csecs[1], "//" )); } if( user.empty() || user.length() == 0 || pass.empty() || pass.length() == 0 ) @@ -1996,14 +1998,14 @@ UI16 cAccountClass::ImportAccounts( void ) // error there are no NULLS allowed for usernames, passwords. So we move to the next. // NOTE! This record will be dropped onces parsing is completed as file is deleted. std::getline( fsInputAccountsTest, sLine ); - sLine = oldstrutil::trim( oldstrutil::removeTrailing( sLine, "//" )); + sLine = util::trim( util::strip( sLine, "//" )); continue; } std::string flags; if( csecs.size() > 2 ) { - flags = oldstrutil::trim( oldstrutil::removeTrailing( csecs[2], "//" )); + flags = util::trim( util::strip( csecs[2], "//" )); } // Set flags to a default value. and in this case I believe that its 0x00000004 @@ -2019,7 +2021,7 @@ UI16 cAccountClass::ImportAccounts( void ) std::string email; if( csecs.size() > 3 ) { - email = oldstrutil::trim( oldstrutil::removeTrailing( csecs[3], "//" )); + email = util::trim( util::strip( csecs[3], "//" )); } if( email.empty() || email.length() == 0 ) @@ -2038,7 +2040,7 @@ UI16 cAccountClass::ImportAccounts( void ) { // The bad accounts file wasn't writable or something so were going to skip it std::getline( fsInputAccountsTest, sLine ); - sLine = oldstrutil::trim( oldstrutil::removeTrailing( sLine, "//" )); + sLine = util::trim( util::strip( sLine, "//" )); continue; } // Write the failed line to the file @@ -2047,14 +2049,14 @@ UI16 cAccountClass::ImportAccounts( void ) // OK there was a problem entering this accounts into the system. Possibly a duplicate? or Other issues Console << "NOTICE: New account was not processed. Please see failed_accounts.log for details." << myendl; std::getline( fsInputAccountsTest, sLine ); - sLine = oldstrutil::trim( oldstrutil::removeTrailing( sLine, "//" )); + sLine = util::trim( util::strip( sLine, "//" )); continue; } wAccountCount++; } // Need to make sure we get the next line std::getline( fsInputAccountsTest, sLine ); - sLine = oldstrutil::trim( oldstrutil::removeTrailing( sLine, "//" )); + sLine = util::trim( util::strip( sLine, "//" )); } // Make sure to close the file fsInputAccountsTest.close(); diff --git a/source/cBaseObject.cpp b/source/cBaseObject.cpp index 7f62821e4..30c8119a2 100644 --- a/source/cBaseObject.cpp +++ b/source/cBaseObject.cpp @@ -27,8 +27,12 @@ #include "ObjectFactory.h" #include "weight.h" #include "Dictionary.h" + +#include "utility/strutil.hpp" + #include + const UI32 BIT_FREE = 0; const UI32 BIT_DELETED = 1; const UI32 BIT_POSTLOADED = 2; @@ -1172,7 +1176,7 @@ void CBaseObject::RemoveFromMulti( bool fireTrigger ) } else { - Console.Error( oldstrutil::format( "Object of type %i with serial 0x%X has a bad multi setting of %i", GetObjType(), serial, multis->GetSerial() )); + Console.Error( util::format( "Object of type %i with serial 0x%X has a bad multi setting of %i", GetObjType(), serial, multis->GetSerial() )); } } } @@ -1234,7 +1238,7 @@ void CBaseObject::AddToMulti( bool fireTrigger ) } else { - Console.Error( oldstrutil::format( "Object of type %i with serial 0x%X has a bad multi setting of %X", GetObjType(), serial, multis->GetSerial() )); + Console.Error( util::format( "Object of type %i with serial 0x%X has a bad multi setting of %X", GetObjType(), serial, multis->GetSerial() )); } } } @@ -1691,10 +1695,10 @@ bool CBaseObject::Load( std::istream &inStream ) ReadWorldTagData( inStream, tag, data ); if( tag != "o---o" ) { - UTag = oldstrutil::upper( tag ); + UTag = util::upper( tag ); if( !HandleLine( UTag, data )) { - Console.Warning( oldstrutil::format( "Unknown world file tag %s with contents of %s", tag.c_str(), data.c_str() )); + Console.Warning( util::format( "Unknown world file tag %s with contents of %s", tag.c_str(), data.c_str() )); } } } @@ -1720,8 +1724,8 @@ bool CBaseObject::HandleLine( std::string &UTag, std::string &data ) if( UTag == "ATT" ) { // For backwards compatibility with older UOX3 versions - loDamage = static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )); - hiDamage = static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )); + loDamage = static_cast( std::stoi( util::trim( util::strip( data, "//" )), nullptr, 0 )); + hiDamage = static_cast( std::stoi( util::trim( util::strip( data, "//" )), nullptr, 0 )); } else { @@ -1760,19 +1764,19 @@ bool CBaseObject::HandleLine( std::string &UTag, std::string &data ) { if( csecs.size() >= 2 ) { - loDamage = static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )) , nullptr, 0 )); - hiDamage = static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 )); + loDamage = static_cast( std::stoi( util::trim( util::strip( csecs[0], "//" )) , nullptr, 0 )); + hiDamage = static_cast( std::stoi( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 )); } else { // If there's only one value, set both to the same - loDamage = static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )); + loDamage = static_cast( std::stoi( util::trim( util::strip( data, "//" )), nullptr, 0 )); hiDamage = loDamage; } } else if( UTag == "DAMAGEABLE" ) { - SetDamageable( oldstrutil::value( data ) == 1 ); + SetDamageable( util::ston( data ) == 1 ); } else if( UTag == "DIRECTION" || UTag == "DIR" ) { @@ -1783,17 +1787,17 @@ bool CBaseObject::HandleLine( std::string &UTag, std::string &data ) { if( csecs.size() >= 2 ) { - dexterity = static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 )); - dx2 = static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 )); + dexterity = static_cast( std::stoi( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 )); + dx2 = static_cast( std::stoi( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 )); } else { - dexterity = static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )); + dexterity = static_cast( std::stoi( util::trim( util::strip( data, "//" )), nullptr, 0 )); } } else if( UTag == "DEXTERITY2" ) { - dx2 = static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )); + dx2 = static_cast( std::stoi( util::trim( util::strip( data, "//" )), nullptr, 0 )); } else if( UTag == "DEFENSE" ) { @@ -1804,7 +1808,7 @@ bool CBaseObject::HandleLine( std::string &UTag, std::string &data ) { if( !val.empty() ) { - auto temp = oldstrutil::upper( oldstrutil::trim( oldstrutil::removeTrailing( val, "//" ))); + auto temp = util::upper( util::trim( util::strip( val, "//" ))); if( temp == "[END]" ) { break; @@ -1817,12 +1821,12 @@ bool CBaseObject::HandleLine( std::string &UTag, std::string &data ) } else { - SetResist( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )), PHYSICAL ); + SetResist( static_cast( std::stoi( util::trim( util::strip( data, "//" )), nullptr, 0 )), PHYSICAL ); } } else if( UTag == "DISABLED" ) { - SetDisabled( oldstrutil::value( data ) == 1 ); + SetDisabled( util::ston( data ) == 1 ); } else { @@ -1832,7 +1836,7 @@ bool CBaseObject::HandleLine( std::string &UTag, std::string &data ) case 'F': if( UTag == "FAME" ) { - SetFame( oldstrutil::value( data )); + SetFame( util::ston( data )); } else { @@ -1842,11 +1846,11 @@ bool CBaseObject::HandleLine( std::string &UTag, std::string &data ) case 'H': if( UTag == "HITPOINTS" ) { - hitpoints = oldstrutil::value( data ); + hitpoints = util::ston( data ); } else if( UTag == "HIDAMAGE" ) { - hiDamage = oldstrutil::value( data ); + hiDamage = util::ston( data ); } else { @@ -1856,23 +1860,23 @@ bool CBaseObject::HandleLine( std::string &UTag, std::string &data ) case 'I': if( UTag == "ID" ) { - id = oldstrutil::value( data ); + id = util::ston( data ); } else if( UTag == "INTELLIGENCE" ) { if( data.find( "," ) != std::string::npos ) { - intelligence = static_cast( std::stoi (oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 )); - in2 = static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 )); + intelligence = static_cast( std::stoi (util::trim( util::strip( csecs[0], "//" )), nullptr, 0 )); + in2 = static_cast( std::stoi( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 )); } else { - intelligence = oldstrutil::value( data ); + intelligence = util::ston( data ); } } else if( UTag == "INTELLIGENCE2" ) { - in2 = oldstrutil::value( data ); + in2 = util::ston( data ); } else { @@ -1882,11 +1886,11 @@ bool CBaseObject::HandleLine( std::string &UTag, std::string &data ) case 'K': if( UTag == "KARMA" ) { - SetKarma( oldstrutil::value( data )); + SetKarma( util::ston( data )); } else if( UTag == "KILLS" ) { - SetKills( oldstrutil::value( data )); + SetKills( util::ston( data )); } else { @@ -1896,15 +1900,15 @@ bool CBaseObject::HandleLine( std::string &UTag, std::string &data ) case 'L': if( UTag == "LOCATION" ) { - x = static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 )); - y = static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 )); - z = static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[2], "//" )), nullptr, 0 )); - worldNumber = static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[3], "//" )), nullptr, 0 )); + x = static_cast( std::stoi( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 )); + y = static_cast( std::stoi( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 )); + z = static_cast( std::stoi( util::trim( util::strip( csecs[2], "//" )), nullptr, 0 )); + worldNumber = static_cast( std::stoi( util::trim( util::strip( csecs[3], "//" )), nullptr, 0 )); // Backwards compatibility with pre-instanceId worldfiles if( csecs.size() >= 5 ) { - instanceId = static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[4], "//" )), nullptr, 0 )); + instanceId = static_cast( std::stoi( util::trim( util::strip( csecs[4], "//" )), nullptr, 0 )); } else { @@ -1913,7 +1917,7 @@ bool CBaseObject::HandleLine( std::string &UTag, std::string &data ) } else if( UTag == "LODAMAGE" ) { - loDamage = oldstrutil::value( data ); + loDamage = util::ston( data ); } else { @@ -1923,11 +1927,11 @@ bool CBaseObject::HandleLine( std::string &UTag, std::string &data ) case 'M': if( UTag == "MANA" ) { - mana = oldstrutil::value( data ); + mana = util::ston( data ); } else if( UTag == "MULTIID" ) { - tempMulti = (oldstrutil::value( data )); + tempMulti = (util::ston( data )); multis = nullptr; } else @@ -1952,7 +1956,7 @@ bool CBaseObject::HandleLine( std::string &UTag, std::string &data ) } else if( UTag == "OWNERID" ) { - owner = oldstrutil::value( data ); + owner = util::ston( data ); } else { @@ -1962,7 +1966,7 @@ bool CBaseObject::HandleLine( std::string &UTag, std::string &data ) case 'P': if( UTag == "POISONED" ) { - poisoned = oldstrutil::value( data ); + poisoned = util::ston( data ); } else { @@ -1972,15 +1976,15 @@ bool CBaseObject::HandleLine( std::string &UTag, std::string &data ) case 'R': if( UTag == "RACE" ) { - race = oldstrutil::value( data ); + race = util::ston( data ); } else if( UTag == "REPUTATION" ) { if( csecs.size() == 3 ) { - SetFame( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 ))); - SetKarma( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 ))); - SetKills( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[2], "//" )), nullptr, 0 ))); + SetFame( static_cast( std::stoi( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 ))); + SetKarma( static_cast( std::stoi( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 ))); + SetKills( static_cast( std::stoi( util::trim( util::strip( csecs[2], "//" )), nullptr, 0 ))); } } else @@ -1996,46 +2000,46 @@ bool CBaseObject::HandleLine( std::string &UTag, std::string &data ) } else if( UTag == "STAMINA" ) { - stamina = oldstrutil::value( data ); + stamina = util::ston( data ); } else if( UTag == "SPAWNERID" ) { - spawnSerial = oldstrutil::value( data ); + spawnSerial = util::ston( data ); } else if( UTag == "SERIAL" ) { - serial = oldstrutil::value( data ); + serial = util::ston( data ); } else if( UTag == "STRENGTH" ) { if( csecs.size() >= 2 ) { - strength = static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 )); - st2 = static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 )); + strength = static_cast( std::stoi( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 )); + st2 = static_cast( std::stoi( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 )); } else { - strength = oldstrutil::value( data ); + strength = util::ston( data ); } } else if( UTag == "STRENGTH2" ) { - st2 = oldstrutil::value( data ); + st2 = util::ston( data ); } else if( UTag == "SCPTRIG" ) { - //scriptTrig = oldstrutil::value(data); - UI16 scriptId = oldstrutil::value( data ); + //scriptTrig = util::ston(data); + UI16 scriptId = util::ston( data ); if( scriptId != 0 && scriptId != 65535 ) { cScript *toExecute = JSMapping->GetScript( scriptId ); if( toExecute == nullptr ) { - Console.Warning( oldstrutil::format( "SCPTRIG tag found with invalid script ID (%s) while loading world data!", data.c_str() )); + Console.Warning( util::format( "SCPTRIG tag found with invalid script ID (%s) while loading world data!", data.c_str() )); } else { - this->AddScriptTrigger( oldstrutil::value( data )); + this->AddScriptTrigger( util::ston( data )); } } } @@ -2057,7 +2061,7 @@ bool CBaseObject::HandleLine( std::string &UTag, std::string &data ) { TAGMAPOBJECT tagvalObject; tagvalObject.m_ObjectType = TAGMAP_TYPE_INT; - tagvalObject.m_IntValue = std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ); + tagvalObject.m_IntValue = std::stoi( util::trim( util::strip( data, "//" )), nullptr, 0 ); tagvalObject.m_Destroy = false; tagvalObject.m_StringValue = ""; SetTag( staticTagName, tagvalObject ); @@ -2081,7 +2085,7 @@ bool CBaseObject::HandleLine( std::string &UTag, std::string &data ) case 'V': if( UTag == "VISIBLE" ) { - visible = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )))); + visible = static_cast( std::stoul( util::trim( util::strip( data, "//" )))); } else { @@ -2091,15 +2095,15 @@ bool CBaseObject::HandleLine( std::string &UTag, std::string &data ) case 'W': if( UTag == "WEIGHT" ) { - SetWeight( oldstrutil::value( data )); + SetWeight( util::ston( data )); } else if( UTag == "WIPE" ) { - SetWipeable( oldstrutil::value( data ) == 1 ); + SetWipeable( util::ston( data ) == 1 ); } else if( UTag == "WORLDNUMBER" ) { - worldNumber = oldstrutil::value( data ); + worldNumber = util::ston( data ); } else { @@ -2111,7 +2115,7 @@ bool CBaseObject::HandleLine( std::string &UTag, std::string &data ) { if( csecs.size() >= 1 ) { - x = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 )); + x = static_cast( std::stoul( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 )); } else { @@ -2119,7 +2123,7 @@ bool CBaseObject::HandleLine( std::string &UTag, std::string &data ) } if( csecs.size() >= 2 ) { - y = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 )); + y = static_cast( std::stoul( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 )); } else { @@ -2127,7 +2131,7 @@ bool CBaseObject::HandleLine( std::string &UTag, std::string &data ) } if( csecs.size() >= 3 ) { - z = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[2], "//" )), nullptr, 0 )); + z = static_cast( std::stoul( util::trim( util::strip( csecs[2], "//" )), nullptr, 0 )); } else { @@ -2136,7 +2140,7 @@ bool CBaseObject::HandleLine( std::string &UTag, std::string &data ) } else if( UTag == "X" ) // For backwards compatibility with older UOX3 versions { - x = oldstrutil::value( data ); + x = util::ston( data ); } else { @@ -2146,7 +2150,7 @@ bool CBaseObject::HandleLine( std::string &UTag, std::string &data ) case 'Y': if( UTag == "Y" ) // For backwards compatibility with older UOX3 versions { - y = oldstrutil::value( data ); + y = util::ston( data ); } else { @@ -2156,7 +2160,7 @@ bool CBaseObject::HandleLine( std::string &UTag, std::string &data ) case 'Z': if( UTag == "Z" ) // For backwards compatibility with older UOX3 versions { - z = oldstrutil::value( data ); + z = util::ston( data ); } else { @@ -2493,7 +2497,7 @@ void CBaseObject::Dirty( [[maybe_unused]] UpdateTypes updateType ) { if( IsDeleted() ) { - Console.Error( oldstrutil::format( "Attempt was made to add deleted item (name: %s, id: %i, serial: %i) to refreshQueue!", GetName().c_str(), GetId(), GetSerial() )); + Console.Error( util::format( "Attempt was made to add deleted item (name: %s, id: %i, serial: %i) to refreshQueue!", GetName().c_str(), GetId(), GetSerial() )); } else if( IsPostLoaded() ) { diff --git a/source/cChar.cpp b/source/cChar.cpp index 3cf42c9c2..a82a27618 100644 --- a/source/cChar.cpp +++ b/source/cChar.cpp @@ -56,6 +56,7 @@ #include "CJSEngine.h" #include "combat.h" #include "StringUtility.hpp" +#include "utility/strutil.hpp" #include "cEffects.h" #include @@ -2902,7 +2903,7 @@ bool CChar::WearItem( CItem *toWear ) { #if defined( UOX_DEBUG_MODE ) std::string charName = GetNpcDictName( this, nullptr, NRS_SYSTEM ); - Console.Warning( oldstrutil::format( "Failed to equip item %s(0x%X) to layer 0x%X on character %s(0x%X, from section [%s]) - another item (%s) is already equipped in that layer!", toWear->GetName().c_str(), toWear->GetSerial(), tLayer, charName.c_str(), serial, GetSectionId().c_str(), GetItemAtLayer( tLayer )->GetName().c_str() )); + Console.Warning( util::format( "Failed to equip item %s(0x%X) to layer 0x%X on character %s(0x%X, from section [%s]) - another item (%s) is already equipped in that layer!", toWear->GetName().c_str(), toWear->GetSerial(), tLayer, charName.c_str(), serial, GetSectionId().c_str(), GetItemAtLayer( tLayer )->GetName().c_str() )); #endif rValue = false; } @@ -4222,7 +4223,7 @@ bool CChar::HandleLine( std::string &UTag, std::string &data ) case 'A': if( UTag == "ACCOUNT" ) { - SetAccountNum( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetAccountNum( static_cast( std::stoi( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "ATROPHY" ) @@ -4230,7 +4231,7 @@ bool CChar::HandleLine( std::string &UTag, std::string &data ) int count = 0; for( auto &value : csecs ) { - value = oldstrutil::upper( oldstrutil::trim( oldstrutil::removeTrailing( value,"//" ))); + value = util::upper( util::trim( util::strip( value,"//" ))); if( value == "[END]" ) { break; @@ -4246,34 +4247,34 @@ bool CChar::HandleLine( std::string &UTag, std::string &data ) } else if( UTag == "ADVANCEOBJECT" ) { - SetAdvObj( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetAdvObj( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "ADVRACEOBJECT" ) { - SetRaceGate( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetRaceGate( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "ALLMOVE" ) { - SetAllMove( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )) == 1 ); + SetAllMove( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 )) == 1 ); rValue = true; } else if( UTag == "AWAKE" ) { - SetAwake( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )) == 1 ); + SetAwake( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 )) == 1 ); rValue = true; } break; case 'B': if( UTag == "BEARDSTYLE" ) { - SetBeardStyle( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetBeardStyle( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "BEARDCOLOUR" ) { - SetBeardColour( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetBeardColour( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "BASESKILLS" ) @@ -4298,121 +4299,121 @@ bool CChar::HandleLine( std::string &UTag, std::string &data ) } else if( UTag == "BEARD" ) { - SetBeardStyle( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 ))); - SetBeardColour( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 ))); + SetBeardStyle( static_cast( std::stoul( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 ))); + SetBeardColour( static_cast( std::stoul( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "BRKPEACECHANCEGAIN" ) { - SetBrkPeaceChanceGain( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetBrkPeaceChanceGain( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "BRKPEACECHANCE" ) { - SetBrkPeaceChance( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetBrkPeaceChance( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } break; case 'C': if( UTag == "COMMANDLEVEL" ) { - SetCommandLevel( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetCommandLevel( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "CANRUN" ) { - SetRun( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )) == 1 ); + SetRun( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 )) == 1 ); rValue = true; } else if( UTag == "CANATTACK" ) { - SetCanAttack( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )) == 1 ); + SetCanAttack( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 )) == 1 ); rValue = true; } else if( UTag == "CANTRAIN" ) { - SetCanTrain( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )) == 1 ); + SetCanTrain( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 )) == 1 ); rValue = true; } else if( UTag == "CANBEHIRED" ) { - SetCanHire( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )) == 1 ); + SetCanHire( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 )) == 1 ); rValue = true; } else if( UTag == "CONTROLSLOTS" ) { - SetControlSlots( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetControlSlots( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "CONTROLSLOTSUSED" ) { - SetControlSlotsUsed( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetControlSlotsUsed( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "CREATEDON" ) { - SetCreatedOn( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetCreatedOn( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } break; case 'D': if( UTag == "DEATHS" ) { - SetDeaths( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetDeaths( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "DEAD" ) { - SetDead(( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )) == 1 )); + SetDead(( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 )) == 1 )); rValue = true; } break; case 'E': if( UTag == "EMOTION" ) { - SetEmoteColour( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetEmoteColour( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } break; case 'F': if( UTag == "FIXEDLIGHT" ) { - SetFixedLight( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetFixedLight( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "FX1" ) { - SetFx( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )), 0 ); + SetFx( static_cast( std::stoi( util::trim( util::strip( data, "//" )), nullptr, 0 )), 0 ); rValue = true; } else if( UTag == "FX2" ) { - SetFx( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )), 1 ); + SetFx( static_cast( std::stoi( util::trim( util::strip( data, "//" )), nullptr, 0 )), 1 ); rValue = true; } else if( UTag == "FY1" ) { - SetFy( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )), 0 ); + SetFy( static_cast( std::stoi( util::trim( util::strip( data, "//" )), nullptr, 0 )), 0 ); rValue = true; } else if( UTag == "FY2" ) { - SetFy( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )), 1 ); + SetFy( static_cast( std::stoi( util::trim( util::strip( data, "//" )), nullptr, 0 )), 1 ); rValue = true; } else if( UTag == "FZ1" ) { - SetFz( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetFz( static_cast( std::stoi( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "FLEEAT" ) { - SetFleeAt( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetFleeAt( static_cast( std::stoi( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "FONTTYPE" ) { - SetFontType( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetFontType( static_cast( std::stoi( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "FOODLIST" ) @@ -4422,19 +4423,19 @@ bool CChar::HandleLine( std::string &UTag, std::string &data ) } else if( UTag == "FLEEINGSPEED" ) { - SetFleeingSpeed( static_cast( std::stof( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" ))))); + SetFleeingSpeed( static_cast( std::stof( util::trim( util::strip( data, "//" ))))); rValue = true; } else if( UTag == "FLEEINGSPEEDMOUNTED" ) { - SetMountedFleeingSpeed( static_cast( std::stof( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" ))))); + SetMountedFleeingSpeed( static_cast( std::stof( util::trim( util::strip( data, "//" ))))); rValue = true; } break; case 'G': if( UTag == "GUILDFEALTY" ) { - SetGuildFealty( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetGuildFealty( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "GUILDTITLE" ) @@ -4444,57 +4445,57 @@ bool CChar::HandleLine( std::string &UTag, std::string &data ) } else if( UTag == "GUILDNUMBER" ) { - SetGuildNumber( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetGuildNumber( static_cast( std::stoi( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "GUILDTOGGLE" ) { - SetGuildToggle( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )) == 1 ); + SetGuildToggle( static_cast( std::stoi( util::trim( util::strip( data, "//" )), nullptr, 0 )) == 1 ); rValue = true; } break; case 'H': if( UTag == "HUNGER" ) { - SetHunger( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetHunger( static_cast( std::stoi( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "HOLDG" ) { - SetHoldG( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetHoldG( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "HAIRSTYLE" ) { - SetHairStyle( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetHairStyle( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "HAIRCOLOUR" ) { - SetHairColour( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetHairColour( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "HAIR" ) { - SetHairStyle( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 ))); - SetHairColour( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 ))); + SetHairStyle( static_cast( std::stoul( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 ))); + SetHairColour( static_cast( std::stoul( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 ))); rValue = true; } break; case 'I': if( UTag == "ISNPC" ) { - SetNpc(( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )) == 1 )); + SetNpc(( static_cast( std::stoi( util::trim( util::strip( data, "//" )), nullptr, 0 )) == 1 )); rValue = true; } else if( UTag == "ISSHOP" ) { - SetShop(( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )) == 1 )); + SetShop(( static_cast( std::stoi( util::trim( util::strip( data, "//" )), nullptr, 0 )) == 1 )); rValue = true; } else if( UTag == "ISWARRING" ) { - SetWar(( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )) == 1 )); + SetWar(( static_cast( std::stoi( util::trim( util::strip( data, "//" )), nullptr, 0 )) == 1 )); rValue = true; } break; @@ -4506,85 +4507,85 @@ bool CChar::HandleLine( std::string &UTag, std::string &data ) } else if( UTag == "LASTONSECS" ) { - SetLastOnSecs( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetLastOnSecs( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "LOYALTY" ) { - SetLoyalty( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetLoyalty( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } break; case 'M': if( UTag == "MAYLEVITATE" ) { - SetLevitate(( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )) == 1 )); + SetLevitate(( static_cast( std::stoi( util::trim( util::strip( data, "//" )), nullptr, 0 )) == 1 )); rValue = true; } else if( UTag == "MURDERTIMER" ) { - SetTimer( tCHAR_MURDERRATE, BuildTimeValue( static_cast( std::stof( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )))))); + SetTimer( tCHAR_MURDERRATE, BuildTimeValue( static_cast( std::stof( util::trim( util::strip( data, "//" )))))); rValue = true; } else if( UTag == "MAXHP" ) { - SetFixedMaxHP( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetFixedMaxHP( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "MAXMANA" ) { - SetFixedMaxMana( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetFixedMaxMana( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "MAXLOYALTY" ) { - SetMaxLoyalty( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetMaxLoyalty( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "MAXSTAM" ) { - SetFixedMaxStam( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetFixedMaxStam( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "MOUNTED" ) { - SetMounted( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )) == 1 ); + SetMounted( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 )) == 1 ); rValue = true; } break; case 'N': if( UTag == "NPCAITYPE" ) { - SetNPCAiType( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetNPCAiType( static_cast( std::stoi( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "NPCWANDER" ) { if( csecs.size() >= 2 ) { - SetNpcWander( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 ))); - SetOldNpcWander( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 ))); + SetNpcWander( static_cast( std::stoi( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 ))); + SetOldNpcWander( static_cast( std::stoi( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 ))); } else { - SetNpcWander( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetNpcWander( static_cast( std::stoi( util::trim( util::strip( data, "//" )), nullptr, 0 ))); } rValue = true; } else if( UTag == "NPCFLAG" ) { - SetNPCFlag( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetNPCFlag( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); UpdateFlag( this ); rValue = true; } else if( UTag == "NPCGUILD" ) { - SetNPCGuild( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetNPCGuild( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "NPCGUILDJOINED" ) { - SetNPCGuildJoined( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetNPCGuildJoined( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } break; @@ -4596,40 +4597,40 @@ bool CChar::HandleLine( std::string &UTag, std::string &data ) } else if( UTag == "ORIGINALBODYID" ) { - SetOrgId( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetOrgId( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "ORIGINALSKINID" ) { - SetOrgSkin( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetOrgSkin( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "ORIGINALID" ) { - SetOrgId( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 ))); - SetOrgSkin( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 ))); + SetOrgId( static_cast( std::stoul( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 ))); + SetOrgSkin( static_cast( std::stoul( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "ORNERINESS" ) { - SetOrneriness( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetOrneriness( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } break; case 'P': if( UTag == "PRIVILEGES" ) { - SetPriv( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetPriv( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "PACKITEM" ) { - tempContainerSerial = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )); + tempContainerSerial = static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 )); rValue = true; } else if( UTag == "PETOWNER" ) { - CChar *cList = CalcCharObjFromSer( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + CChar *cList = CalcCharObjFromSer( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); if( ValidateObject( cList )) { AddPetOwnerToList( cList ); @@ -4638,67 +4639,67 @@ bool CChar::HandleLine( std::string &UTag, std::string &data ) } else if( UTag == "POISON" ) { - SetPoisoned( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetPoisoned( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "POISONSTRENGTH" ) { - SetPoisonStrength( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetPoisonStrength( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "PEACEING" ) { - SetPeaceing( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetPeaceing( static_cast( std::stoi( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "PROVOING" ) { - SetProvoing( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetProvoing( static_cast( std::stoi( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "PEACETIMER" ) { - SetTimer( tCHAR_PEACETIMER, BuildTimeValue( static_cast( std::stof( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )))))); + SetTimer( tCHAR_PEACETIMER, BuildTimeValue( static_cast( std::stof( util::trim( util::strip( data, "//" )))))); rValue = true; } else if( UTag == "PLAYTIME" ) { - SetPlayTime( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetPlayTime( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } break; case 'Q': if( UTag == "QUESTTYPE" ) { - SetQuestType( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetQuestType( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "QUESTDESTINATIONREGION" ) { - SetQuestDestRegion( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetQuestDestRegion( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "QUESTORIGINALREGION" ) { - SetQuestOrigRegion( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetQuestOrigRegion( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "QUESTREGIONS" ) { - SetQuestOrigRegion( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 ))); - SetQuestDestRegion( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 ))); + SetQuestOrigRegion( static_cast( std::stoul( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 ))); + SetQuestDestRegion( static_cast( std::stoul( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 ))); rValue = true; } break; case 'R': if( UTag == "ROBESERIAL" ) { - SetRobe( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetRobe( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "RESERVED" ) { - SetCell( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetCell( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "RUNNING" ) @@ -4707,22 +4708,22 @@ bool CChar::HandleLine( std::string &UTag, std::string &data ) } else if( UTag == "REGION" ) { - SetRegion(static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetRegion(static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "REATTACKAT" ) { - SetReattackAt( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetReattackAt( static_cast( std::stoi( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "RUNNINGSPEED" ) { - SetRunningSpeed( static_cast( std::stof( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" ))))); + SetRunningSpeed( static_cast( std::stof( util::trim( util::strip( data, "//" ))))); rValue = true; } else if( UTag == "RUNNINGSPEEDMOUNTED" ) { - SetMountedRunningSpeed( static_cast( std::stof( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" ))))); + SetMountedRunningSpeed( static_cast( std::stof( util::trim( util::strip( data, "//" ))))); rValue = true; } break; @@ -4731,56 +4732,56 @@ bool CChar::HandleLine( std::string &UTag, std::string &data ) { if( csecs.size() >= 2 ) { - SetSplit( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 ))); - SetSplitChance( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 ))); + SetSplit( static_cast( std::stoul( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 ))); + SetSplitChance( static_cast( std::stoul( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 ))); } else { - SetSplit( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetSplit( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); } rValue = true; } else if( UTag == "SPLITCHANCE" ) { - SetSplitChance( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetSplitChance( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "SUMMONTIMER" ) { - SetTimer( tNPC_SUMMONTIME, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetTimer( tNPC_SUMMONTIME, static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "SAY" ) { - SetSayColour( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetSayColour( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "STEALTH" ) { - SetStealth( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetStealth( static_cast( std::stoi( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "SPATTACK" ) { if( csecs.size() >=2 ) { - SetSpAttack( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 ))); - SetSpDelay( static_cast (std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 ))); + SetSpAttack( static_cast( std::stoul( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 ))); + SetSpDelay( static_cast (std::stoul( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 ))); } else { - SetSpAttack( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetSpAttack( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); } rValue = true; } else if( UTag == "SPECIALATTACKDELAY" ) { - SetSpDelay( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetSpDelay( static_cast( std::stoi( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "SQUELCHED" ) { - SetSquelched( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetSquelched( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "SKILLLOCKS" ) @@ -4807,103 +4808,103 @@ bool CChar::HandleLine( std::string &UTag, std::string &data ) } else if( UTag == "SPEECH" ) { - SetSayColour( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 ))); - SetEmoteColour( static_cast( std::stoul (oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 ))); + SetSayColour( static_cast( std::stoul( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 ))); + SetEmoteColour( static_cast( std::stoul (util::trim( util::strip( csecs[1], "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "STABLED" ) { - SetStabled( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )) == 1 ); + SetStabled( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 )) == 1 ); rValue = true; } break; case 'T': if( UTag == "TAMING" ) { - SetTaming( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetTaming( static_cast( std::stoi( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "TAMEDHUNGERRATE" ) { - SetTamedHungerRate( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetTamedHungerRate( static_cast( std::stoi( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "TAMEDHUNGERWILDCHANCE" ) { - SetTamedHungerWildChance( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetTamedHungerWildChance( static_cast( std::stoi( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "TAMEDTHIRSTRATE" ) { - SetTamedThirstRate( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetTamedThirstRate( static_cast( std::stoi( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "TAMEDTHIRSTWILDCHANCE" ) { - SetTamedThirstWildChance( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetTamedThirstWildChance( static_cast( std::stoi( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "TOWN" ) { - SetTown( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetTown( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "TOWNVOTE" ) { - SetTownVote( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetTownVote( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "TOWNPRIVILEGES" ) { - SetTownpriv( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetTownpriv( static_cast( std::stoi( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "TOWNTITLE" ) { - SetTownTitle( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )) == 1 ); + SetTownTitle( static_cast( std::stoi( util::trim( util::strip( data, "//" )), nullptr, 0 )) == 1 ); rValue = true; } else if( UTag == "THIRST" ) { - SetThirst( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetThirst( static_cast( std::stoi( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } break; case 'W': if( UTag == "WANDERAREA" ) { - SetFx( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 )), 0 ); - SetFy( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 )), 0 ); - SetFx( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[2], "//" )), nullptr, 0 )), 1 ); - SetFy( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[3], "//" )), nullptr, 0 )), 1 ); - SetFz( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[4], "//" )), nullptr, 0 ))); + SetFx( static_cast( std::stoi( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 )), 0 ); + SetFy( static_cast( std::stoi( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 )), 0 ); + SetFx( static_cast( std::stoi( util::trim( util::strip( csecs[2], "//" )), nullptr, 0 )), 1 ); + SetFy( static_cast( std::stoi( util::trim( util::strip( csecs[3], "//" )), nullptr, 0 )), 1 ); + SetFz( static_cast( std::stoi( util::trim( util::strip( csecs[4], "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "WILLHUNGER" ) { - SetHungerStatus( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )) == 1 ); + SetHungerStatus( static_cast( std::stoi( util::trim( util::strip( data, "//" )), nullptr, 0 )) == 1 ); rValue = true; } else if( UTag == "WILLTHIRST" ) { - SetThirstStatus( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )) == 1 ); + SetThirstStatus( static_cast( std::stoi( util::trim( util::strip( data, "//" )), nullptr, 0 )) == 1 ); rValue = true; } else if( UTag == "WALKINGSPEED" ) { - SetWalkingSpeed( static_cast( std::stof( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" ))))); + SetWalkingSpeed( static_cast( std::stof( util::trim( util::strip( data, "//" ))))); rValue = true; } else if( UTag == "WALKINGSPEEDMOUNTED" ) { - SetMountedWalkingSpeed( static_cast( std::stof( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" ))))); + SetMountedWalkingSpeed( static_cast( std::stof( util::trim( util::strip( data, "//" ))))); rValue = true; } break; case 'X': if( UTag == "XNPCWANDER" ) { - SetOldNpcWander( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetOldNpcWander( static_cast( std::stoi( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } break; @@ -4945,7 +4946,7 @@ bool CChar::LoadRemnants( void ) if( acct == AB_INVALID_ID ) { std::string charName = GetNpcDictName( this, nullptr, NRS_SYSTEM ); - Console.Warning( oldstrutil::format( "NPC: %s with serial 0x%X with bugged body found, deleting", charName.c_str(), GetSerial() )); + Console.Warning( util::format( "NPC: %s with serial 0x%X with bugged body found, deleting", charName.c_str(), GetSerial() )); rValue = false; } else @@ -4969,7 +4970,7 @@ bool CChar::LoadRemnants( void ) if( IsNpc() ) { std::string charName = GetNpcDictName( this, nullptr, NRS_SYSTEM ); - Console.Warning( oldstrutil::format( "NPC: %s with serial 0x%X found outside valid world locations, deleting", charName.c_str(), GetSerial() )); + Console.Warning( util::format( "NPC: %s with serial 0x%X found outside valid world locations, deleting", charName.c_str(), GetSerial() )); rValue = false; } else @@ -8983,7 +8984,7 @@ void CChar::Die( CChar *attacker, bool doRepsys ) } if(( !attacker->IsNpc() ) && (!IsNpc() )) { - Console.Log( oldstrutil::format( Dictionary->GetEntry( 1617 ), GetName().c_str(), attacker->GetName().c_str() ), "PvP.log" ); + Console.Log( util::format( Dictionary->GetEntry( 1617 ), GetName().c_str(), attacker->GetName().c_str() ), "PvP.log" ); } Combat->Kill( attacker, this ); diff --git a/source/cConsole.cpp b/source/cConsole.cpp index 5374b14b7..9cdef5a2a 100644 --- a/source/cConsole.cpp +++ b/source/cConsole.cpp @@ -30,6 +30,8 @@ #include "cGuild.h" #include "cScript.h" #include "StringUtility.hpp" +#include "utility/strutil.hpp" + #include #include #include @@ -455,7 +457,7 @@ auto CConsole::Log( const std::string& msg, const std::string& filename ) -> voi toWrite.close(); if( LogEcho() ) { - Print( oldstrutil::format( "%s%s\n", timeStr, msg.c_str() )); + Print( util::format( "%s%s\n", timeStr, msg.c_str() )); } } } @@ -996,7 +998,7 @@ auto CConsole::Process(std::int32_t c) -> void { // All commands that execute are of the form: command_commandname (to avoid possible clashes) #if defined( UOX_DEBUG_MODE ) - Print( oldstrutil::format( "Executing JS keystroke %c %s\n", c, toFind->second.cmdName.c_str() )); + Print( util::format( "Executing JS keystroke %c %s\n", c, toFind->second.cmdName.c_str() )); #endif jsval eventRetVal; [[maybe_unused]] JSBool retVal = toExecute->CallParticularEvent( toFind->second.cmdName.c_str(), nullptr, 0, &eventRetVal ); @@ -1059,7 +1061,7 @@ auto CConsole::Process(std::int32_t c) -> void indexcount = 0; kill = true; std::cout << std::endl; - temp = oldstrutil::format( "CMD: System broadcast sent message \"%s\"", outputline.c_str() ); + temp = util::format( "CMD: System broadcast sent message \"%s\"", outputline.c_str() ); outputline = ""; messageLoop << temp; break; @@ -1090,7 +1092,7 @@ auto CConsole::Process(std::int32_t c) -> void { localMap.insert( std::make_pair( CJ->first, 0 )); szBuffer = ""; - szBuffer = oldstrutil::format( "AddMenuGroup %u:", CJ->first ); + szBuffer = util::format( "AddMenuGroup %u:", CJ->first ); messageLoop << szBuffer; std::pair< ADDMENUMAP_CITERATOR, ADDMENUMAP_CITERATOR > pairRange = g_mmapAddMenuMap.equal_range( CJ->first ); SI32 count = 0; @@ -1099,7 +1101,7 @@ auto CConsole::Process(std::int32_t c) -> void count++; } szBuffer = ""; - szBuffer = oldstrutil::format( " Found %i Auto-AddMenu Item(s).", count ); + szBuffer = util::format( " Found %i Auto-AddMenu Item(s).", count ); messageLoop << szBuffer; } } @@ -1206,15 +1208,15 @@ auto CConsole::Process(std::int32_t c) -> void LogEcho( true ); Log( "--- Starting Performance Dump ---", "performance.log"); Log( "\tPerformance Dump:", "performance.log"); - Log( oldstrutil::format( "\tNetwork code: %.2fmsec [%i samples]", static_cast( static_cast( cwmWorldState->ServerProfile()->NetworkTime() ) / static_cast( networkTimeCount )), networkTimeCount ), "performance.log" ); - Log( oldstrutil::format( "\tTimer code: %.2fmsec [%i samples]", static_cast( static_cast( cwmWorldState->ServerProfile()->TimerTime() ) / static_cast( timerTimeCount )), timerTimeCount ), "performance.log" ); - Log( oldstrutil::format( "\tAuto code: %.2fmsec [%i samples]", static_cast( static_cast( cwmWorldState->ServerProfile()->AutoTime() ) / static_cast( autoTimeCount )), autoTimeCount ), "performance.log" ); - Log( oldstrutil::format( "\tLoop Time: %.2fmsec [%i samples]", static_cast( static_cast( cwmWorldState->ServerProfile()->LoopTime() ) / static_cast( loopTimeCount )), loopTimeCount ), "performance.log" ); - - Log( oldstrutil::format( "\tCharacters: %i/%i - Items: %i/%i (Dynamic)", ObjectFactory::GetSingleton().CountOfObjects( OT_CHAR ), ObjectFactory::GetSingleton().SizeOfObjects( OT_CHAR ), ObjectFactory::GetSingleton().CountOfObjects( OT_ITEM ), ObjectFactory::GetSingleton().SizeOfObjects( OT_ITEM )), "performance.log" ); - Log( oldstrutil::format( "\tSimulation Cycles: %f per sec", (1000.0*(1.0/static_cast( static_cast( cwmWorldState->ServerProfile()->LoopTime() ) / static_cast( loopTimeCount ))))), "performance.log" ); - Log( oldstrutil::format( "\tBytes sent: %i", cwmWorldState->ServerProfile()->GlobalSent() ), "performance.log" ); - Log( oldstrutil::format( "\tBytes Received: %i", cwmWorldState->ServerProfile()->GlobalReceived() ), "performance.log" ); + Log( util::format( "\tNetwork code: %.2fmsec [%i samples]", static_cast( static_cast( cwmWorldState->ServerProfile()->NetworkTime() ) / static_cast( networkTimeCount )), networkTimeCount ), "performance.log" ); + Log( util::format( "\tTimer code: %.2fmsec [%i samples]", static_cast( static_cast( cwmWorldState->ServerProfile()->TimerTime() ) / static_cast( timerTimeCount )), timerTimeCount ), "performance.log" ); + Log( util::format( "\tAuto code: %.2fmsec [%i samples]", static_cast( static_cast( cwmWorldState->ServerProfile()->AutoTime() ) / static_cast( autoTimeCount )), autoTimeCount ), "performance.log" ); + Log( util::format( "\tLoop Time: %.2fmsec [%i samples]", static_cast( static_cast( cwmWorldState->ServerProfile()->LoopTime() ) / static_cast( loopTimeCount )), loopTimeCount ), "performance.log" ); + + Log( util::format( "\tCharacters: %i/%i - Items: %i/%i (Dynamic)", ObjectFactory::GetSingleton().CountOfObjects( OT_CHAR ), ObjectFactory::GetSingleton().SizeOfObjects( OT_CHAR ), ObjectFactory::GetSingleton().CountOfObjects( OT_ITEM ), ObjectFactory::GetSingleton().SizeOfObjects( OT_ITEM )), "performance.log" ); + Log( util::format( "\tSimulation Cycles: %f per sec", (1000.0*(1.0/static_cast( static_cast( cwmWorldState->ServerProfile()->LoopTime() ) / static_cast( loopTimeCount ))))), "performance.log" ); + Log( util::format( "\tBytes sent: %i", cwmWorldState->ServerProfile()->GlobalSent() ), "performance.log" ); + Log( util::format( "\tBytes Received: %i", cwmWorldState->ServerProfile()->GlobalReceived() ), "performance.log" ); Log( "--- Performance Dump Complete ---", "performance.log"); LogEcho( false ); break; @@ -1229,12 +1231,12 @@ auto CConsole::Process(std::int32_t c) -> void ++j; CChar *mChar = iSock->CurrcharObj(); - temp = oldstrutil::format( " %i) %s [%x %x %x %x]", j - 1, mChar->GetName().c_str(), mChar->GetSerial( 1 ), mChar->GetSerial( 2 ), mChar->GetSerial( 3 ), mChar->GetSerial( 4 )); + temp = util::format( " %i) %s [%x %x %x %x]", j - 1, mChar->GetName().c_str(), mChar->GetSerial( 1 ), mChar->GetSerial( 2 ), mChar->GetSerial( 3 ), mChar->GetSerial( 4 )); messageLoop << temp; } } - temp = oldstrutil::format( " Total users online: %i", j ); + temp = util::format( " Total users online: %i", j ); messageLoop << temp; break; } @@ -1246,23 +1248,23 @@ auto CConsole::Process(std::int32_t c) -> void UI32 m, n; m = static_cast( ObjectFactory::GetSingleton().SizeOfObjects( OT_CHAR )); total += tmp = m + m * sizeof( CTEffect ) + m * sizeof( SI08 ) + m * sizeof( intptr_t ) * 5; - temp = oldstrutil::format( " Characters: %u bytes [%u chars ( %u allocated )]", tmp, ObjectFactory::GetSingleton().CountOfObjects( OT_CHAR ), m ); + temp = util::format( " Characters: %u bytes [%u chars ( %u allocated )]", tmp, ObjectFactory::GetSingleton().CountOfObjects( OT_CHAR ), m ); messageLoop << temp; n = static_cast( ObjectFactory::GetSingleton().SizeOfObjects( OT_ITEM )); total += tmp = n + n * sizeof( intptr_t ) * 4; - temp = oldstrutil::format( " Items: %u bytes [%u items ( %u allocated )]", tmp, ObjectFactory::GetSingleton().CountOfObjects( OT_ITEM ), n ); + temp = util::format( " Items: %u bytes [%u items ( %u allocated )]", tmp, ObjectFactory::GetSingleton().CountOfObjects( OT_ITEM ), n ); messageLoop << temp; - temp = oldstrutil::format( " You save I: %lu & C: %lu bytes!", m * sizeof(CItem) - ObjectFactory::GetSingleton().CountOfObjects( OT_ITEM ), m * sizeof( CChar ) - ObjectFactory::GetSingleton().CountOfObjects( OT_CHAR )); + temp = util::format( " You save I: %lu & C: %lu bytes!", m * sizeof(CItem) - ObjectFactory::GetSingleton().CountOfObjects( OT_ITEM ), m * sizeof( CChar ) - ObjectFactory::GetSingleton().CountOfObjects( OT_CHAR )); total += tmp = 69 * sizeof( CSpellInfo ); - temp = oldstrutil::format( temp, " Spells: %i bytes", tmp ); + temp = util::format( temp, " Spells: %i bytes", tmp ); messageLoop << " Sizes:"; - temp = oldstrutil::format(" CItem : %lu bytes", sizeof( CItem )); + temp = util::format(" CItem : %lu bytes", sizeof( CItem )); messageLoop << temp; - temp = oldstrutil::format( " CChar : %lu bytes", sizeof( CChar )); + temp = util::format( " CChar : %lu bytes", sizeof( CChar )); messageLoop << temp; - temp = oldstrutil::format( " TEffect: %lu bytes %lui total)", sizeof( CTEffect ), sizeof( CTEffect ) * cwmWorldState->tempEffects.Num() ); + temp = util::format( " TEffect: %lu bytes %lui total)", sizeof( CTEffect ), sizeof( CTEffect ) * cwmWorldState->tempEffects.Num() ); messageLoop << temp; - temp = oldstrutil::format( " Approximate Total: %i bytes", total ); + temp = util::format( " Approximate Total: %i bytes", total ); messageLoop << temp; break; case '?': @@ -1332,7 +1334,7 @@ auto CConsole::Process(std::int32_t c) -> void FileLookup->DisplayPriorityMap(); break; default: - temp = oldstrutil::format( "Key \'%c\' [%i] does not perform a function", static_cast( c ), c ); + temp = util::format( "Key \'%c\' [%i] does not perform a function", static_cast( c ), c ); messageLoop << temp; break; } @@ -1398,7 +1400,7 @@ auto CConsole::DisplaySettings() -> void auto CConsole::RegisterKey( SI32 key, std::string cmdName, UI16 scriptId ) -> void { #if defined( UOX_DEBUG_MODE ) - messageLoop << oldstrutil::format( " Registering key \"%c\"", key ); + messageLoop << util::format( " Registering key \"%c\"", key ); #endif JSKeyHandler[key] = JSConsoleEntry_st( scriptId, cmdName ); } @@ -1425,9 +1427,9 @@ auto CConsole::SetKeyStatus( SI32 key, bool isEnabled ) -> void auto CConsole::RegisterFunc( const std::string &cmdFunc, const std::string &cmdName, UI16 scriptId ) -> void { #if defined( UOX_DEBUG_MODE ) - Print( oldstrutil::format( " Registering console func \"%s\"\n", cmdFunc.c_str() )); + Print( util::format( " Registering console func \"%s\"\n", cmdFunc.c_str() )); #endif - JSConsoleFunctions[oldstrutil::upper( cmdFunc )] = JSConsoleEntry_st( scriptId, cmdName ); + JSConsoleFunctions[util::upper( cmdFunc )] = JSConsoleEntry_st( scriptId, cmdName ); } //o------------------------------------------------------------------------------------------------o @@ -1437,7 +1439,7 @@ auto CConsole::RegisterFunc( const std::string &cmdFunc, const std::string &cmdN //o------------------------------------------------------------------------------------------------o auto CConsole::SetFuncStatus( const std::string &cmdFunc, bool isEnabled ) -> void { - auto upper = oldstrutil::upper( cmdFunc ); + auto upper = util::upper( cmdFunc ); auto toFind = JSConsoleFunctions.find( upper ); if( toFind != JSConsoleFunctions.end() ) { diff --git a/source/cGuild.cpp b/source/cGuild.cpp index b3576f235..a0fea7b41 100644 --- a/source/cGuild.cpp +++ b/source/cGuild.cpp @@ -8,6 +8,8 @@ #include "Dictionary.h" #include "CJSEngine.h" #include "StringUtility.hpp" +#include "utility/strutil.hpp" + #include "osunique.hpp" #ifndef va_start #include @@ -691,7 +693,7 @@ void CGuild::Load( CScriptSection *toRead ) if( tag.empty() ) continue; - UTag = oldstrutil::upper( tag ); + UTag = util::upper( tag ); switch(( UTag.data()[0] )) { case '{': @@ -1083,9 +1085,9 @@ void CGuildCollection::Menu( CSocket *s, SI16 menu, GUILDID trgGuild, SERIAL plI toSend.UserId( INVALIDSERIAL ); toSend.addCommand( "page 0" ); - toSend.addCommand( oldstrutil::format( "resizepic 0 0 %u 600 400", cwmWorldState->ServerData()->BackgroundPic() )); - toSend.addCommand( oldstrutil::format( "button 560 10 %u %i 1 0 1", cwmWorldState->ServerData()->ButtonCancel(), cwmWorldState->ServerData()->ButtonCancel() + 1 )); //OKAY - toSend.addCommand( oldstrutil::format( "text 120 10 %u 0", cwmWorldState->ServerData()->TitleColour() )); + toSend.addCommand( util::format( "resizepic 0 0 %u 600 400", cwmWorldState->ServerData()->BackgroundPic() )); + toSend.addCommand( util::format( "button 560 10 %u %i 1 0 1", cwmWorldState->ServerData()->ButtonCancel(), cwmWorldState->ServerData()->ButtonCancel() + 1 )); //OKAY + toSend.addCommand( util::format( "text 120 10 %u 0", cwmWorldState->ServerData()->TitleColour() )); toSend.addCommand( "page 1" ); SERIAL gMaster = gList[trgGuild]->Master(); @@ -1147,25 +1149,25 @@ void CGuildCollection::Menu( CSocket *s, SI16 menu, GUILDID trgGuild, SERIAL plI toSend.addText( Dictionary->GetEntry( 103, sLang )); toSend.addText( Dictionary->GetEntry( 104, sLang )); toSend.addText( Dictionary->GetEntry( 105, sLang )); - toSend.addText( oldstrutil::format( Dictionary->GetEntry( 106, sLang ), guildFealty.c_str() )); - toSend.addText( oldstrutil::format( Dictionary->GetEntry( 107, sLang ), toggle.c_str() )); + toSend.addText( util::format( Dictionary->GetEntry( 106, sLang ), guildFealty.c_str() )); + toSend.addText( util::format( Dictionary->GetEntry( 107, sLang ), toggle.c_str() )); toSend.addText( Dictionary->GetEntry( 108, sLang )); toSend.addText( Dictionary->GetEntry( 109, sLang )); - toSend.addText( oldstrutil::format( Dictionary->GetEntry( 110, sLang ), gName.c_str() )); - toSend.addText( oldstrutil::format( Dictionary->GetEntry( 111, sLang ), gName.c_str() )); + toSend.addText( util::format( Dictionary->GetEntry( 110, sLang ), gName.c_str() )); + toSend.addText( util::format( Dictionary->GetEntry( 111, sLang ), gName.c_str() )); toSend.addText( Dictionary->GetEntry( 112, sLang )); if( mChar->GetSerial() == gMaster || mChar->IsGM() ) // Guildmaster Access? { ++numButtons; - toSend.addText( oldstrutil::format( Dictionary->GetEntry( 113, sLang ), gMstr->GetGuildTitle().c_str() )); + toSend.addText( util::format( Dictionary->GetEntry( 113, sLang ), gMstr->GetGuildTitle().c_str() )); } break; case BasePage + 2: numButtons = 16; // Guildmaster menu toSend.addText( Dictionary->GetEntry( 114, sLang )); toSend.addText( Dictionary->GetEntry( 115, sLang )); toSend.addText( Dictionary->GetEntry( 116, sLang )); - toSend.addText(oldstrutil::format( Dictionary->GetEntry( 117, sLang ), guildt.c_str() )); + toSend.addText(util::format( Dictionary->GetEntry( 117, sLang ), guildt.c_str() )); for( tCounter = 118; tCounter <= 130; ++tCounter ) { toSend.addText( Dictionary->GetEntry( tCounter, sLang )); @@ -1187,7 +1189,7 @@ void CGuildCollection::Menu( CSocket *s, SI16 menu, GUILDID trgGuild, SERIAL plI case BasePage + 5: numButtons = 3; // View charter toSend.addText( Dictionary->GetEntry( 140, sLang )); toSend.addText( gList[trgGuild]->Charter() ); - toSend.addText( oldstrutil::format( Dictionary->GetEntry( 142, sLang ), gList[trgGuild]->Webpage().c_str() )); + toSend.addText( util::format( Dictionary->GetEntry( 142, sLang ), gList[trgGuild]->Webpage().c_str() )); toSend.addText( Dictionary->GetEntry( 130, sLang )); break; case BasePage + 6: // List of recruits @@ -1317,15 +1319,15 @@ void CGuildCollection::Menu( CSocket *s, SI16 menu, GUILDID trgGuild, SERIAL plI toSend.addText( temp ); // To display: Name, str, dex, int, # kills, # deaths, status (criminal, murderer, innocent), top x skills toSend.addText( "Strength" ); - toSend.addText( oldstrutil::format( "%i", kChar->GetStrength() )); + toSend.addText( util::format( "%i", kChar->GetStrength() )); toSend.addText( "Dexterity" ); - toSend.addText( oldstrutil::format( "%i", kChar->GetDexterity() )); + toSend.addText( util::format( "%i", kChar->GetDexterity() )); toSend.addText( "Intelligence" ); - toSend.addText( oldstrutil::format( "%i", kChar->GetIntelligence() )); + toSend.addText( util::format( "%i", kChar->GetIntelligence() )); toSend.addText( "Kills" ); - toSend.addText( oldstrutil::format( "%i", kChar->GetKills() )); + toSend.addText( util::format( "%i", kChar->GetKills() )); toSend.addText( "Deaths" ); - toSend.addText( oldstrutil::format( "%u", kChar->GetDeaths() )); + toSend.addText( util::format( "%u", kChar->GetDeaths() )); numText = 10; numColumns = 2; numButtons = 1; @@ -1373,8 +1375,8 @@ void CGuildCollection::Menu( CSocket *s, SI16 menu, GUILDID trgGuild, SERIAL plI for( UI16 iCtr = 0; iCtr < numButtons; ++iCtr ) { - toSend.addCommand( oldstrutil::format( "button 20 %i %i %i 1 0 %i", 30 + 20 * iCtr, cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1, iCtr + 2 )); - toSend.addCommand( oldstrutil::format( "text 50 %i %i %i", 30 + 20 * iCtr, cwmWorldState->ServerData()->LeftTextColour(), iCtr + 1 )); + toSend.addCommand( util::format( "button 20 %i %i %i 1 0 %i", 30 + 20 * iCtr, cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1, iCtr + 2 )); + toSend.addCommand( util::format( "text 50 %i %i %i", 30 + 20 * iCtr, cwmWorldState->ServerData()->LeftTextColour(), iCtr + 1 )); } if( numText != 0 ) { @@ -1382,11 +1384,11 @@ void CGuildCollection::Menu( CSocket *s, SI16 menu, GUILDID trgGuild, SERIAL plI { if( numColumns == 1 ) { - toSend.addCommand( oldstrutil::format( "text 50 %i %i %i", 30 + 20 * ( iCtr + numButtons ), cwmWorldState->ServerData()->LeftTextColour(), iCtr + numButtons + 1 )); + toSend.addCommand( util::format( "text 50 %i %i %i", 30 + 20 * ( iCtr + numButtons ), cwmWorldState->ServerData()->LeftTextColour(), iCtr + numButtons + 1 )); } else { - toSend.addCommand( oldstrutil::format( "text %i %i %i %i", 50 + ( iCtr % numColumns ) * 100, 30 + 20 * (( iCtr / 2 ) + numButtons ), cwmWorldState->ServerData()->LeftTextColour(), iCtr + numButtons + 1 )); + toSend.addCommand( util::format( "text %i %i %i %i", 50 + ( iCtr % numColumns ) * 100, 30 + 20 * (( iCtr / 2 ) + numButtons ), cwmWorldState->ServerData()->LeftTextColour(), iCtr + numButtons + 1 )); } } } @@ -1481,7 +1483,7 @@ void CGuildCollection::TransportGuildStone( CSocket *s, GUILDID guildId ) gTransportStone->SetNewbie( true ); gTransportStone->SetWeight( 1, true ); gTransportStone->SetType( IT_GUILDSTONE ); - gTransportStone->SetName( oldstrutil::format( Dictionary->GetEntry( 101 ), gList[guildId]->Name().c_str() )); + gTransportStone->SetName( util::format( Dictionary->GetEntry( 101 ), gList[guildId]->Name().c_str() )); CItem *gStone = CalcItemObjFromSer( gList[guildId]->Stone() ); gStone->Delete(); @@ -1890,7 +1892,7 @@ void CGuildCollection::PlaceStone( CSocket *s, CItem *deed ) if( nGuild == nullptr ) { s->ObjMessage( 174, deed ); // Critical error adding guildstone, please contact a GM! - Console.Error( oldstrutil::format( "Critical error adding guildstone, memory allocation failed. Attempted by player 0x%X", mChar->GetSerial() )); + Console.Error( util::format( "Critical error adding guildstone, memory allocation failed. Attempted by player 0x%X", mChar->GetSerial() )); return; } mChar->SetGuildNumber( gNum ); @@ -1900,7 +1902,7 @@ void CGuildCollection::PlaceStone( CSocket *s, CItem *deed ) if( !ValidateObject( stone )) { s->ObjMessage( 176, deed ); // Critical error, unable to spawn guildstone, please contact a GM! - Console.Error( oldstrutil::format( "Critical error spawning guildstone, no stone made. Attempted by player 0x%X", mChar->GetSerial() )); + Console.Error( util::format( "Critical error spawning guildstone, no stone made. Attempted by player 0x%X", mChar->GetSerial() )); return; } stone->SetName( Dictionary->GetEntry( 175 )); // Guildstone for an unnamed guild @@ -1937,17 +1939,17 @@ void CGuildCollection::PlaceStone( CSocket *s, CItem *deed ) if( nGuild == nullptr ) { s->ObjMessage( 174, deed ); // Critical error adding guildstone, please contact a GM! - Console.Error( oldstrutil::format( "Critical error adding guildstone, memory allocation failed. Attempted by player 0x%X", mChar->GetSerial() )); + Console.Error( util::format( "Critical error adding guildstone, memory allocation failed. Attempted by player 0x%X", mChar->GetSerial() )); return; } CItem *stone = Items->CreateItem( nullptr, mChar, 0x0ED5, 1, 0, OT_ITEM ); if( !ValidateObject( stone )) { s->ObjMessage( 176, deed ); // Critical error, unable to spawn guildstone, please contact a GM! - Console.Error( oldstrutil::format( "Critical error spawning guildstone, no stone made. Attempted by player 0x%X", mChar->GetSerial() )); + Console.Error( util::format( "Critical error spawning guildstone, no stone made. Attempted by player 0x%X", mChar->GetSerial() )); return; } - stone->SetName( oldstrutil::format( Dictionary->GetEntry( 101 ), nGuild->Name().c_str() )); + stone->SetName( util::format( Dictionary->GetEntry( 101 ), nGuild->Name().c_str() )); stone->SetLocation( mChar ); stone->SetType( IT_GUILDSTONE ); stone->SetTempVar( CITV_MORE, gNum ); @@ -2020,22 +2022,22 @@ void CGuildCollection::DisplayTitle( CSocket *s, CChar *src ) const auto guildtype= GTypeNames[mGuild->Type()]; if( !src->GetGuildTitle().empty() ) { - title = oldstrutil::format( "[%s, %s] [%s]", src->GetGuildTitle().c_str(), abbreviation.c_str(), guildtype.c_str() ); + title = util::format( "[%s, %s] [%s]", src->GetGuildTitle().c_str(), abbreviation.c_str(), guildtype.c_str() ); } else { - title = oldstrutil::format( "[%s] [%s]", abbreviation.c_str(), guildtype.c_str() ); + title = util::format( "[%s] [%s]", abbreviation.c_str(), guildtype.c_str() ); } } else { if( !src->GetGuildTitle().empty() ) { - title = oldstrutil::format( "[%s, %s]", src->GetGuildTitle().c_str(), abbreviation.c_str() ); + title = util::format( "[%s, %s]", src->GetGuildTitle().c_str(), abbreviation.c_str() ); } else { - title = oldstrutil::format( "[%s]", abbreviation.c_str() ); + title = util::format( "[%s]", abbreviation.c_str() ); } } s->ObjMessage( title, src ); diff --git a/source/cHTMLSystem.cpp b/source/cHTMLSystem.cpp index 730c682a8..8a221c3de 100644 --- a/source/cHTMLSystem.cpp +++ b/source/cHTMLSystem.cpp @@ -13,6 +13,8 @@ #include "CPacketSend.h" #include "ObjectFactory.h" #include "osunique.hpp" +#include "utility/strutil.hpp" + cHTMLTemplates *HTMLTemplates; cHTMLTemplate::cHTMLTemplate() : updateTimer( 60 ), loaded( false ), type( ETT_INVALIDTEMPLATE ), scheduledUpdate( 0 ) @@ -42,17 +44,17 @@ std::string GetUptime( void ) { builtString += std::string( "0" ); } - builtString += oldstrutil::number( ho ) + ":"; + builtString += util::ntos( ho ) + ":"; if( mi < 10 ) { builtString += std::string( "0" ); } - builtString += oldstrutil::number( mi ) + std::string(":"); + builtString += util::ntos( mi ) + std::string(":"); if( se < 10 ) { builtString += std::string( "0" ); } - builtString += oldstrutil::number( se ); + builtString += util::ntos( se ); return builtString; } @@ -98,7 +100,7 @@ void cHTMLTemplate::Process( void ) // Replacing Placeholders // Account-Count - std::string AccountCount = oldstrutil::number(( Accounts->size() )); + std::string AccountCount = util::ntos(( Accounts->size() )); size_t Pos = ParsedContent.find( "%accounts" ); while( Pos != std::string::npos ) { @@ -121,7 +123,7 @@ void cHTMLTemplate::Process( void ) Pos = ParsedContent.find( "%version" ); } // Character Count - std::string CharacterCount = oldstrutil::number( ObjectFactory::GetSingleton().CountOfObjects( OT_CHAR )); + std::string CharacterCount = util::ntos( ObjectFactory::GetSingleton().CountOfObjects( OT_CHAR )); Pos = ParsedContent.find( "%charcount" ); while( Pos != std::string::npos ) { @@ -130,7 +132,7 @@ void cHTMLTemplate::Process( void ) } // Item Count - std::string ItemCount = oldstrutil::number( ObjectFactory::GetSingleton().CountOfObjects( OT_ITEM )); + std::string ItemCount = util::ntos( ObjectFactory::GetSingleton().CountOfObjects( OT_ITEM )); Pos = ParsedContent.find( "%itemcount" ); while( Pos != std::string::npos ) { @@ -166,7 +168,7 @@ void cHTMLTemplate::Process( void ) } // GMs - std::string GMCount = oldstrutil::number( gm ); + std::string GMCount = util::ntos( gm ); Pos = ParsedContent.find( "%online_gms" ); while( Pos != std::string::npos ) { @@ -175,7 +177,7 @@ void cHTMLTemplate::Process( void ) } // Counselor - std::string CounsiCount = oldstrutil::number( cns ); + std::string CounsiCount = util::ntos( cns ); Pos = ParsedContent.find( "%online_couns" ); while( Pos != std::string::npos ) { @@ -184,7 +186,7 @@ void cHTMLTemplate::Process( void ) } // Player - std::string PlayerCount = oldstrutil::number( ccount ); + std::string PlayerCount = util::ntos( ccount ); Pos = ParsedContent.find( "%online_player" ); while( Pos != std::string::npos ) { @@ -193,7 +195,7 @@ void cHTMLTemplate::Process( void ) } // Total - std::string AllCount = oldstrutil::number(( ccount + gm + cns )); + std::string AllCount = util::ntos(( ccount + gm + cns )); Pos = ParsedContent.find( "%online_all" ); while( Pos != std::string::npos ) { @@ -225,7 +227,7 @@ void cHTMLTemplate::Process( void ) time( &currTime ); struct tm dtime; currTime = mktime( mgmtime( &dtime, &currTime )); - std::string timestamp = oldstrutil::number( currTime ); + std::string timestamp = util::ntos( currTime ); Pos = ParsedContent.find( "%tstamp" ); while( Pos != std::string::npos ) { @@ -256,7 +258,7 @@ void cHTMLTemplate::Process( void ) Pos = ParsedContent.find( "%serverport" ); while( Pos != std::string::npos ) { - ( cwmWorldState->GetKeepRun() ) ? ParsedContent.replace( Pos, 11, oldstrutil::number( serverPort )) : ParsedContent.replace( Pos, 11, "127.0.0.1" ); + ( cwmWorldState->GetKeepRun() ) ? ParsedContent.replace( Pos, 11, util::ntos( serverPort )) : ParsedContent.replace( Pos, 11, "127.0.0.1" ); Pos = ParsedContent.find( "%serverport" ); } @@ -325,7 +327,7 @@ void cHTMLTemplate::Process( void ) { CSocket *mySock = tChar->GetSocket(); - auto ClientIP = oldstrutil::format( "%i.%i.%i.%i", mySock->ClientIP4(), mySock->ClientIP3(), mySock->ClientIP3(), mySock->ClientIP1() ); + auto ClientIP = util::format( "%i.%i.%i.%i", mySock->ClientIP4(), mySock->ClientIP3(), mySock->ClientIP3(), mySock->ClientIP1() ); ( cwmWorldState->GetKeepRun() ) ? parsedInline.replace( sPos, 9, ClientIP ):parsedInline.replace( sPos, 9, "" ); sPos = parsedInline.find( "%playerip" ); } @@ -346,7 +348,7 @@ void cHTMLTemplate::Process( void ) sPos = parsedInline.find( "%playerx" ); while( sPos != std::string::npos ) { - std::string myX = oldstrutil::number( tChar->GetX() ); + std::string myX = util::ntos( tChar->GetX() ); ( cwmWorldState->GetKeepRun() ) ? parsedInline.replace( sPos, 8, myX ) : parsedInline.replace( sPos, 8, "" ); sPos = parsedInline.find( "%playerx" ); } @@ -355,7 +357,7 @@ void cHTMLTemplate::Process( void ) sPos = parsedInline.find( "%playery" ); while( sPos != std::string::npos ) { - std::string myY = oldstrutil::number( tChar->GetY() ); + std::string myY = util::ntos( tChar->GetY() ); ( cwmWorldState->GetKeepRun() ) ? parsedInline.replace( sPos, 8, myY ) : parsedInline.replace( sPos, 8, "" ); sPos = parsedInline.find( "%playery" ); } @@ -364,7 +366,7 @@ void cHTMLTemplate::Process( void ) sPos = parsedInline.find( "%playerz" ); while( sPos != std::string::npos ) { - std::string myZ = oldstrutil::number( tChar->GetZ() ); + std::string myZ = util::ntos( tChar->GetZ() ); ( cwmWorldState->GetKeepRun() ) ? parsedInline.replace( sPos, 8, myZ ) : parsedInline.replace( sPos, 8, "" ); sPos = parsedInline.find( "%playerz" ); } @@ -408,7 +410,7 @@ void cHTMLTemplate::Process( void ) } // GuildCount - std::string GuildCount = oldstrutil::number( static_cast( GuildSys->NumGuilds() )); + std::string GuildCount = util::ntos( static_cast( GuildSys->NumGuilds() )); Pos = ParsedContent.find( "%guildcount" ); while( Pos != std::string::npos ) { @@ -441,7 +443,7 @@ void cHTMLTemplate::Process( void ) size_t sPos; CGuild *myGuild = GuildSys->Guild( i ); - std::string GuildId = oldstrutil::number( i ); + std::string GuildId = util::ntos( i ); sPos = parsedInline.find( "%guildid" ); while( sPos != std::string::npos ) { @@ -461,7 +463,7 @@ void cHTMLTemplate::Process( void ) sPos = parsedInline.find( "%guildmembercount" ); while( sPos != std::string::npos ) { - ( cwmWorldState->GetKeepRun() ) ? parsedInline.replace( sPos, 17, oldstrutil::number( myGuild->NumMembers() )) : parsedInline.replace( sPos, 10, "" ); + ( cwmWorldState->GetKeepRun() ) ? parsedInline.replace( sPos, 17, util::ntos( myGuild->NumMembers() )) : parsedInline.replace( sPos, 10, "" ); sPos = parsedInline.find( "%guildmembercount" ); } @@ -478,7 +480,7 @@ void cHTMLTemplate::Process( void ) ObjectFactory::GetSingleton().IterateOver( OT_CHAR, b, nullptr, &CountNPCFunctor ); npccount = b; - std::string npcs = oldstrutil::number( npccount ); + std::string npcs = util::ntos( npccount ); Pos = ParsedContent.find( "%npcs" ); while( Pos != std::string::npos ) { @@ -563,7 +565,7 @@ void cHTMLTemplate::Process( void ) Pos = ParsedContent.find( "%updatetime" ); while( Pos != std::string::npos ) { - std::string strUpdateTimer = oldstrutil::number( updateTimer ); + std::string strUpdateTimer = util::ntos( updateTimer ); ( cwmWorldState->GetKeepRun() ) ? ParsedContent.replace( Pos, 11, strUpdateTimer ) : ParsedContent.replace( Pos, 11, "0" ); Pos = ParsedContent.find( "%updatetime" ); } @@ -580,7 +582,7 @@ void cHTMLTemplate::Process( void ) } else { - Console.Error( oldstrutil::format( " Couldn't open the template file %s for writing", outputFile.c_str() )); + Console.Error( util::format( " Couldn't open the template file %s for writing", outputFile.c_str() )); } } @@ -614,7 +616,7 @@ void cHTMLTemplate::LoadTemplate( void ) if( !InputFile1.is_open() ) { - Console.Error( oldstrutil::format( "Couldn't open HTML Template File %s", inputFile.c_str() )); + Console.Error( util::format( "Couldn't open HTML Template File %s", inputFile.c_str() )); return; } @@ -656,7 +658,7 @@ void cHTMLTemplate::Load( CScriptSection *found ) { auto tag = sec->tag; auto data = sec->data; - auto UTag = oldstrutil::upper( tag ); + auto UTag = util::upper( tag ); if( UTag == "UPDATE" ) { @@ -664,7 +666,7 @@ void cHTMLTemplate::Load( CScriptSection *found ) } else if( UTag == "TYPE" ) { - auto UData = oldstrutil::upper( data ); + auto UData = util::upper( data ); if( UData == "STATUS" ) { type = ETT_ONLINE; @@ -690,13 +692,13 @@ void cHTMLTemplate::Load( CScriptSection *found ) { auto fullPath = cwmWorldState->ServerData()->Directory( CSDDP_DEFS ) + "html/" + data; //LOOKATME - inputFile = oldstrutil::trim( fullPath ).substr( 0, MAX_PATH - 1 ); + inputFile = util::trim( fullPath ).substr( 0, MAX_PATH - 1 ); } else if( UTag == "OUTPUT" ) { auto fullPath = cwmWorldState->ServerData()->Directory( CSDDP_HTML ) + data; //LOOKATME - outputFile = oldstrutil::trim( fullPath ).substr( 0, MAX_PATH - 1 ); + outputFile = util::trim( fullPath ).substr( 0, MAX_PATH - 1 ); } else if( UTag == "NAME" ) { @@ -822,7 +824,7 @@ void cHTMLTemplates::TemplateInfoGump( CSocket *mySocket ) // ~25 pixel per entry - InfoGump.AddText( 40, static_cast( 40 + ( Entries - 1 ) * 25 ), cwmWorldState->ServerData()->LeftTextColour(), oldstrutil::format( "%s (%i)", Templates[ i ]->GetName().c_str(), i )); + InfoGump.AddText( 40, static_cast( 40 + ( Entries - 1 ) * 25 ), cwmWorldState->ServerData()->LeftTextColour(), util::format( "%s (%i)", Templates[ i ]->GetName().c_str(), i )); if( Entries == 5 ) { diff --git a/source/cItem.cpp b/source/cItem.cpp index 27f0885c5..04216f22c 100644 --- a/source/cItem.cpp +++ b/source/cItem.cpp @@ -50,6 +50,8 @@ #include "cServerDefinitions.h" #include "ssection.h" #include "StringUtility.hpp" +#include "utility/strutil.hpp" + #include "osunique.hpp" #include @@ -1777,12 +1779,12 @@ bool CItem::HandleLine( std::string &UTag, std::string &data ) { if( csecs.size() == 2 ) { - SetAmmoId( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 ))); - SetAmmoHue( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 ))); + SetAmmoId( static_cast( std::stoul( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 ))); + SetAmmoHue( static_cast( std::stoul( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 ))); } else { - SetAmmoId( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetAmmoId( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); SetAmmoHue(( 0 )); } rValue = true; @@ -1791,13 +1793,13 @@ bool CItem::HandleLine( std::string &UTag, std::string &data ) { if( csecs.size() == 2 ) { - SetAmmoFX( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 ))); - SetAmmoFXHue( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 ))); - SetAmmoFXRender( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 ))); + SetAmmoFX( static_cast( std::stoul( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 ))); + SetAmmoFXHue( static_cast( std::stoul( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 ))); + SetAmmoFXRender( static_cast( std::stoul( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 ))); } else { - SetAmmoFX( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetAmmoFX( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); SetAmmoFXHue(( 0 )); SetAmmoFXRender(( 0 )); } @@ -1805,41 +1807,41 @@ bool CItem::HandleLine( std::string &UTag, std::string &data ) } else if( UTag == "AMOUNT" ) { - amount = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )); + amount = static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 )); rValue = true; } else if( UTag == "AC" ) { - SetArmourClass( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetArmourClass( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } break; case 'B': if( UTag == "BOOLS" ) { - bools = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )); + bools = static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 )); rValue = true; } break; case 'C': if( UTag == "CONT" ) { - tempContainerSerial = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )); + tempContainerSerial = static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 )); rValue = true; } else if( UTag == "CREATOR" || UTag == "CREATER" ) { - SetCreator( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetCreator( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "CORPSE" ) { - SetCorpse( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )) == 1 ); + SetCorpse( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 )) == 1 ); rValue = true; } else if( UTag == "COLD" ) { - SetWeatherDamage( COLD, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )) == 1 ); + SetWeatherDamage( COLD, static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 )) == 1 ); rValue = true; } break; @@ -1851,19 +1853,19 @@ bool CItem::HandleLine( std::string &UTag, std::string &data ) } if( UTag == "DIR" ) { - SetDir( static_cast( std::stoi(oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetDir( static_cast( std::stoi(util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "DYEABLE" ) { - SetDye( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )) == 1 ); + SetDye( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 )) == 1 ); rValue = true; } break; case 'E': if( UTag == "ENTRYMADEFROM" ) { - EntryMadeFrom( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + EntryMadeFrom( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "EVENT" ) @@ -1875,72 +1877,72 @@ bool CItem::HandleLine( std::string &UTag, std::string &data ) case 'G': if( UTag == "GRIDLOC" ) { - SetGridLocation( static_cast( std::stoi(oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetGridLocation( static_cast( std::stoi(util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "GLOWTYPE" ) { - SetGlowEffect( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetGlowEffect( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "GLOWBC" ) { - SetGlowColour( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetGlowColour( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "GLOW" ) { - SetGlow( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetGlow( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "GOOD" ) { - SetGood( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetGood( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } break; case 'H': if( UTag == "HEAT" ) { - SetWeatherDamage( HEAT, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )) == 1 ); + SetWeatherDamage( HEAT, static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 )) == 1 ); rValue = true; } break; case 'L': if( UTag == "LAYER" ) { - layer = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )); + layer = static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 )); rValue = true; } else if( UTag == "LIGHT" ) { - SetWeatherDamage( LIGHT, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )) == 1 ); + SetWeatherDamage( LIGHT, static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 )) == 1 ); rValue = true; } else if( UTag == "LIGHTNING" ) { - SetWeatherDamage( LIGHTNING, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )) == 1 ); + SetWeatherDamage( LIGHTNING, static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 )) == 1 ); rValue = true; } break; case 'M': if( UTag == "MAXITEMS" ) { - SetMaxItems( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetMaxItems( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "MORE" ) { if( csecs.size() >= 4 ) { - SetTempVar( CITV_MORE, 1, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 ))); - SetTempVar( CITV_MORE, 2, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 ))); - SetTempVar( CITV_MORE, 3, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[2], "//" )), nullptr, 0 ))); - SetTempVar( CITV_MORE, 4, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[3], "//" )), nullptr, 0 ))); + SetTempVar( CITV_MORE, 1, static_cast( std::stoul( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 ))); + SetTempVar( CITV_MORE, 2, static_cast( std::stoul( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 ))); + SetTempVar( CITV_MORE, 3, static_cast( std::stoul( util::trim( util::strip( csecs[2], "//" )), nullptr, 0 ))); + SetTempVar( CITV_MORE, 4, static_cast( std::stoul( util::trim( util::strip( csecs[3], "//" )), nullptr, 0 ))); } else { - SetTempVar( CITV_MORE, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetTempVar( CITV_MORE, static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); } rValue = true; } @@ -1950,30 +1952,30 @@ bool CItem::HandleLine( std::string &UTag, std::string &data ) } else if( UTag == "MORE012" ) { - SetTempVar( CITV_MOREX, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 ))); - SetTempVar( CITV_MOREY, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 ))); - SetTempVar( CITV_MOREZ, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[2], "//" )), nullptr, 0 ))); + SetTempVar( CITV_MOREX, static_cast( std::stoul( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 ))); + SetTempVar( CITV_MOREY, static_cast( std::stoul( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 ))); + SetTempVar( CITV_MOREZ, static_cast( std::stoul( util::trim( util::strip( csecs[2], "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "MOREXYZ" ) { - SetTempVar( CITV_MOREX, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 ))); - SetTempVar( CITV_MOREY, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 ))); - SetTempVar( CITV_MOREZ, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[2], "//" )), nullptr, 0 ))); + SetTempVar( CITV_MOREX, static_cast( std::stoul( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 ))); + SetTempVar( CITV_MOREY, static_cast( std::stoul( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 ))); + SetTempVar( CITV_MOREZ, static_cast( std::stoul( util::trim( util::strip( csecs[2], "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "MOREX" ) { if( csecs.size() >= 4 ) { - SetTempVar( CITV_MOREX, 1, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 ))); - SetTempVar( CITV_MOREX, 2, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 ))); - SetTempVar( CITV_MOREX, 3, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[2], "//" )), nullptr, 0 ))); - SetTempVar( CITV_MOREX, 4, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[3], "//" )), nullptr, 0 ))); + SetTempVar( CITV_MOREX, 1, static_cast( std::stoul( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 ))); + SetTempVar( CITV_MOREX, 2, static_cast( std::stoul( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 ))); + SetTempVar( CITV_MOREX, 3, static_cast( std::stoul( util::trim( util::strip( csecs[2], "//" )), nullptr, 0 ))); + SetTempVar( CITV_MOREX, 4, static_cast( std::stoul( util::trim( util::strip( csecs[3], "//" )), nullptr, 0 ))); } else { - SetTempVar( CITV_MOREX, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetTempVar( CITV_MOREX, static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); } rValue = true; } @@ -1981,14 +1983,14 @@ bool CItem::HandleLine( std::string &UTag, std::string &data ) { if( csecs.size() >= 4 ) { - SetTempVar( CITV_MOREY, 1, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 ))); - SetTempVar( CITV_MOREY, 2, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 ))); - SetTempVar( CITV_MOREY, 3, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[2], "//" )), nullptr, 0 ))); - SetTempVar( CITV_MOREY, 4, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[3], "//" )), nullptr, 0 ))); + SetTempVar( CITV_MOREY, 1, static_cast( std::stoul( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 ))); + SetTempVar( CITV_MOREY, 2, static_cast( std::stoul( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 ))); + SetTempVar( CITV_MOREY, 3, static_cast( std::stoul( util::trim( util::strip( csecs[2], "//" )), nullptr, 0 ))); + SetTempVar( CITV_MOREY, 4, static_cast( std::stoul( util::trim( util::strip( csecs[3], "//" )), nullptr, 0 ))); } else { - SetTempVar( CITV_MOREY, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetTempVar( CITV_MOREY, static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); } rValue = true; } @@ -1996,14 +1998,14 @@ bool CItem::HandleLine( std::string &UTag, std::string &data ) { if( csecs.size() >= 4 ) { - SetTempVar( CITV_MOREZ, 1, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 ))); - SetTempVar( CITV_MOREZ, 2, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 ))); - SetTempVar( CITV_MOREZ, 3, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[2], "//" )), nullptr, 0 ))); - SetTempVar( CITV_MOREZ, 4, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[3], "//" )), nullptr, 0 ))); + SetTempVar( CITV_MOREZ, 1, static_cast( std::stoul( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 ))); + SetTempVar( CITV_MOREZ, 2, static_cast( std::stoul( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 ))); + SetTempVar( CITV_MOREZ, 3, static_cast( std::stoul( util::trim( util::strip( csecs[2], "//" )), nullptr, 0 ))); + SetTempVar( CITV_MOREZ, 4, static_cast( std::stoul( util::trim( util::strip( csecs[3], "//" )), nullptr, 0 ))); } else { - SetTempVar( CITV_MOREZ, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetTempVar( CITV_MOREZ, static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); } rValue = true; } @@ -2013,17 +2015,17 @@ bool CItem::HandleLine( std::string &UTag, std::string &data ) } else if( UTag == "MOVABLE" ) { - SetMovable( static_cast( std::stoi(oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetMovable( static_cast( std::stoi(util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "MAXHP" ) { - SetMaxHP( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetMaxHP( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "MAXUSES" ) { - SetMaxUses( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetMaxUses( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } break; @@ -2037,58 +2039,58 @@ bool CItem::HandleLine( std::string &UTag, std::string &data ) case 'O': if( UTag == "OFFSPELL" ) { - SetOffSpell( static_cast( std::stoi(oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetOffSpell( static_cast( std::stoi(util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } break; case 'P': if( UTag == "PRIV" ) { - SetPriv( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetPriv( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "PILEABLE" ) { - SetPileable( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )) == 1 ); + SetPileable( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 )) == 1 ); rValue = true; } break; case 'R': if( UTag == "RESTOCK" ) { - SetRestock( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetRestock( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "RACEDAMAGE" ) { - SetWeatherDamage( LIGHT, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 )) == 1 ); - SetWeatherDamage( RAIN, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 )) == 1 ); - SetWeatherDamage( HEAT, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[2], "//" )), nullptr, 0 )) == 1 ); - SetWeatherDamage( COLD, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[3], "//" )), nullptr, 0 )) == 1 ); - SetWeatherDamage( SNOW, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[4], "//" )), nullptr, 0 )) == 1 ); - SetWeatherDamage( LIGHTNING, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[5], "//" )), nullptr, 0 )) == 1 ); + SetWeatherDamage( LIGHT, static_cast( std::stoul( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 )) == 1 ); + SetWeatherDamage( RAIN, static_cast( std::stoul( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 )) == 1 ); + SetWeatherDamage( HEAT, static_cast( std::stoul( util::trim( util::strip( csecs[2], "//" )), nullptr, 0 )) == 1 ); + SetWeatherDamage( COLD, static_cast( std::stoul( util::trim( util::strip( csecs[3], "//" )), nullptr, 0 )) == 1 ); + SetWeatherDamage( SNOW, static_cast( std::stoul( util::trim( util::strip( csecs[4], "//" )), nullptr, 0 )) == 1 ); + SetWeatherDamage( LIGHTNING, static_cast( std::stoul( util::trim( util::strip( csecs[5], "//" )), nullptr, 0 )) == 1 ); rValue = true; } else if( UTag == "RANK" ) { - SetRank( static_cast( std::stoi(oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetRank( static_cast( std::stoi(util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "RAIN" ) { - SetWeatherDamage( RAIN, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )) == 1 ); + SetWeatherDamage( RAIN, static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 )) == 1 ); rValue = true; } else if( UTag == "RANGE" ) { if( csecs.size() > 1 ) { - SetBaseRange( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 ))); - SetMaxRange( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 ))); + SetBaseRange( static_cast( std::stoul( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 ))); + SetMaxRange( static_cast( std::stoul( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 ))); } else { - auto val = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )); + auto val = static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 )); SetBaseRange( val ); SetMaxRange( val / 2 ); } @@ -2102,29 +2104,29 @@ bool CItem::HandleLine( std::string &UTag, std::string &data ) case 'S': if( UTag == "SPEED" ) { - SetSpeed( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetSpeed( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "SK_MADE" ) { - SetMadeWith( static_cast( std::stoi(oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetMadeWith( static_cast( std::stoi(util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "SNOW" ) { - SetWeatherDamage( SNOW, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )) == 1 ); + SetWeatherDamage( SNOW, static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 )) == 1 ); rValue = true; } else if( UTag == "SPELLS" ) { - SetSpell( 0, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 ))); - SetSpell( 1, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 ))); - SetSpell( 2, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[2], "//" )), nullptr, 0 ))); + SetSpell( 0, static_cast( std::stoul( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 ))); + SetSpell( 1, static_cast( std::stoul( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 ))); + SetSpell( 2, static_cast( std::stoul( util::trim( util::strip( csecs[2], "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "STEALABLE" ) { - SetStealable( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetStealable( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } break; @@ -2133,11 +2135,11 @@ bool CItem::HandleLine( std::string &UTag, std::string &data ) { if( csecs.size() != 1 ) { - SetType( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 ))); + SetType( static_cast( std::stoul( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 ))); } else { - SetType( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetType( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); } rValue = true; } @@ -2149,7 +2151,7 @@ bool CItem::HandleLine( std::string &UTag, std::string &data ) case 'U': if( UTag == "USESLEFT" ) { - SetUsesLeft( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetUsesLeft( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } break; @@ -2158,18 +2160,18 @@ bool CItem::HandleLine( std::string &UTag, std::string &data ) { if( csecs.size() > 2 ) { - SetBuyValue( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 ))); - SetSellValue( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 ))); - SetVendorPrice( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[2], "//" )), nullptr, 0 ))); + SetBuyValue( static_cast( std::stoul( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 ))); + SetSellValue( static_cast( std::stoul( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 ))); + SetVendorPrice( static_cast( std::stoul( util::trim( util::strip( csecs[2], "//" )), nullptr, 0 ))); } else if( csecs.size() > 1 ) { - SetBuyValue( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 ))); - SetSellValue( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 ))); + SetBuyValue( static_cast( std::stoul( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 ))); + SetSellValue( static_cast( std::stoul( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 ))); } else { - auto val = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )); + auto val = static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 )); SetBuyValue( val ); SetSellValue( val / 2 ); } @@ -2179,7 +2181,7 @@ bool CItem::HandleLine( std::string &UTag, std::string &data ) case 'W': if( UTag == "WEIGHTMAX" ) { - SetWeightMax( static_cast( std::stoi(oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetWeightMax( static_cast( std::stoi(util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } break; @@ -2281,24 +2283,24 @@ void CItem::CheckItemIntegrity( void ) SERIAL getSerial = GetSerial(); if( getSerial == INVALIDSERIAL ) { - Console.Warning( oldstrutil::format( "Item (%s, from DFN section [%s]) has an invalid serial number, Deleting", GetName().c_str(), GetSectionId().c_str() )); + Console.Warning( util::format( "Item (%s, from DFN section [%s]) has an invalid serial number, Deleting", GetName().c_str(), GetSectionId().c_str() )); Delete(); return; } if( getSerial == GetContSerial() ) { - Console.Warning( oldstrutil::format( "Item 0x%X (%s, from DFN section [%s]) has dangerous container value, Auto-Correcting", getSerial, GetName().c_str(), GetSectionId().c_str() )); + Console.Warning( util::format( "Item 0x%X (%s, from DFN section [%s]) has dangerous container value, Auto-Correcting", getSerial, GetName().c_str(), GetSectionId().c_str() )); SetCont( nullptr ); } if( getSerial == GetOwner() ) { - Console.Warning( oldstrutil::format( "Item 0x%X (%s, from DFN section [%s]) has dangerous owner value, Auto-Correcting", getSerial, GetName().c_str(), GetSectionId().c_str() )); + Console.Warning( util::format( "Item 0x%X (%s, from DFN section [%s]) has dangerous owner value, Auto-Correcting", getSerial, GetName().c_str(), GetSectionId().c_str() )); SetOwner( nullptr ); } if( getSerial == GetSpawn() ) { - Console.Warning( oldstrutil::format( "Item 0x%X (%s, from DFN section [%s]) has dangerous spawner value, Auto-Correcting", getSerial, GetName().c_str(), GetSectionId().c_str() )); + Console.Warning( util::format( "Item 0x%X (%s, from DFN section [%s]) has dangerous spawner value, Auto-Correcting", getSerial, GetName().c_str(), GetSectionId().c_str() )); SetSpawn( INVALIDSERIAL ); } @@ -2307,12 +2309,12 @@ void CItem::CheckItemIntegrity( void ) if( GetMaxItems() == 0 ) { SetMaxItems( cwmWorldState->ServerData()->MaxPlayerPackItems() ); - Console.Warning( oldstrutil::format( "Container (%s, from DFN section [%s]) with maxItems set to 0 detected on character (%s). Resetting maxItems for container to default value.", std::to_string( GetSerial() ).c_str(), GetSectionId().c_str(), std::to_string( contObj->GetSerial() ).c_str() )); + Console.Warning( util::format( "Container (%s, from DFN section [%s]) with maxItems set to 0 detected on character (%s). Resetting maxItems for container to default value.", std::to_string( GetSerial() ).c_str(), GetSectionId().c_str(), std::to_string( contObj->GetSerial() ).c_str() )); } if( GetWeightMax() == 0 ) { SetWeightMax( cwmWorldState->ServerData()->MaxPlayerPackWeight() ); - Console.Warning( oldstrutil::format( "Container (%s, from DFN section [%s]) with weightMax set to 0 detected on character (%s). Resetting weightMax for container to default value.", std::to_string( GetSerial() ).c_str(), GetSectionId().c_str(), std::to_string( contObj->GetSerial() ).c_str() )); + Console.Warning( util::format( "Container (%s, from DFN section [%s]) with weightMax set to 0 detected on character (%s). Resetting weightMax for container to default value.", std::to_string( GetSerial() ).c_str(), GetSectionId().c_str(), std::to_string( contObj->GetSerial() ).c_str() )); } } } @@ -2598,7 +2600,7 @@ void CItem::Update( [[maybe_unused]] CSocket *mSock, [[maybe_unused]] bool drawG if( GetCont() == this ) { - Console.Warning( oldstrutil::format( "Item %s(0x%X) has a dangerous container value, auto-correcting", GetName().c_str(), GetSerial() )); + Console.Warning( util::format( "Item %s(0x%X) has a dangerous container value, auto-correcting", GetName().c_str(), GetSerial() )); SetCont( nullptr ); } @@ -2660,7 +2662,7 @@ void CItem::Update( [[maybe_unused]] CSocket *mSock, [[maybe_unused]] bool drawG return; } } - Console.Error( oldstrutil::format( " CItem::Update(0x%X): cannot determine container type!", GetSerial() )); + Console.Error( util::format( " CItem::Update(0x%X): cannot determine container type!", GetSerial() )); } //o------------------------------------------------------------------------------------------------o @@ -3351,13 +3353,13 @@ bool CSpawnItem::HandleLine( std::string &UTag, std::string &data ) case 'I': if( UTag == "INTERVAL" ) { - SetInterval( 0, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 ))); - SetInterval( 1, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 ))); + SetInterval( 0, static_cast( std::stoul( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 ))); + SetInterval( 1, static_cast( std::stoul( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 ))); rValue = true; } else if( UTag == "ISSECTIONALIST" ) { - IsSectionAList(( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )) == 1) ); + IsSectionAList(( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 )) == 1) ); rValue = true; } break; @@ -3424,7 +3426,7 @@ auto CSpawnItem::HandleItemSpawner() -> bool } else if( GetTempVar( CITV_MOREX ) != 0 ) { - Items->AddRespawnItem( this, oldstrutil::number( GetTempVar( CITV_MOREX )), false, 1 ); + Items->AddRespawnItem( this, util::ntos( GetTempVar( CITV_MOREX )), false, 1 ); } else { @@ -3447,7 +3449,7 @@ auto CSpawnItem::HandleNPCSpawner() -> bool } else if( GetTempVar( CITV_MOREX ) != 0 ) { - Npcs->CreateNPC( this, oldstrutil::number( GetTempVar( CITV_MOREX ))); + Npcs->CreateNPC( this, util::ntos( GetTempVar( CITV_MOREX ))); } else { @@ -3476,7 +3478,7 @@ auto CSpawnItem::HandleSpawnContainer() -> bool if( !listObj.empty() ) { std::string sect = "ITEMLIST " + listObj; - sect = oldstrutil::trim( oldstrutil::removeTrailing( sect, "//" )); + sect = util::trim( util::strip( sect, "//" )); // Look up the relevant ITEMLIST from DFNs CScriptSection *itemList = FileLookup->FindEntry( sect, items_def ); @@ -3491,28 +3493,28 @@ auto CSpawnItem::HandleSpawnContainer() -> bool for( size_t i = 0; i < itemListSize; i++ ) { // listObj will either contain an itemID and amount, or an itemlist/lootlist tag - auto listObj = oldstrutil::sections( oldstrutil::trim( oldstrutil::removeTrailing( itemList->MoveTo( i ), "//" )), "," ); + auto listObj = oldstrutil::sections( util::trim( util::strip( itemList->MoveTo( i ), "//" )), "," ); if( !listObj.empty() ) { UI16 amountToSpawn = 1; std::vector itemListData; - if( oldstrutil::upper( listObj[0] ) == "ITEMLIST" || oldstrutil::upper( listObj[0] ) == "LOOTLIST" ) + if( util::upper( listObj[0] ) == "ITEMLIST" || util::upper( listObj[0] ) == "LOOTLIST" ) { - bool useLootList = oldstrutil::upper( listObj[0] ) == "LOOTLIST"; + bool useLootList = util::upper( listObj[0] ) == "LOOTLIST"; // Itemlist/Lootlist - itemListData = oldstrutil::sections( oldstrutil::trim( oldstrutil::removeTrailing( itemList->GrabData(), "//" )), "," ); + itemListData = oldstrutil::sections( util::trim( util::strip( itemList->GrabData(), "//" )), "," ); listEntry = itemListData[0]; if( itemListData.size() > 1 ) { // Also grab amount - std::string amountData = oldstrutil::trim( oldstrutil::removeTrailing( itemListData[1], "//" )); + std::string amountData = util::trim( util::strip( itemListData[1], "//" )); auto tsects = oldstrutil::sections( amountData, " " ); if( tsects.size() > 1 ) // check if the second part of the tag-data contains two sections separated by a space { - auto first = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( tsects[0], "//" )), nullptr, 0 )); - auto second = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( tsects[1], "//" )), nullptr, 0 )); + auto first = static_cast( std::stoul( util::trim( util::strip( tsects[0], "//" )), nullptr, 0 )); + auto second = static_cast( std::stoul( util::trim( util::strip( tsects[1], "//" )), nullptr, 0 )); // Tag contained a minimum and maximum value for amount! Let's randomize! amountToSpawn = static_cast( RandomNum( first, second )); @@ -3543,12 +3545,12 @@ auto CSpawnItem::HandleSpawnContainer() -> bool if( listObj.size() > 1 ) { // Grab amount - std::string amountData = oldstrutil::trim( oldstrutil::removeTrailing( listObj[1], "//" )); + std::string amountData = util::trim( util::strip( listObj[1], "//" )); auto tsects = oldstrutil::sections( amountData, " " ); if( tsects.size() > 1 ) // check if the second part of the tag-data contains two sections separated by a space { - auto first = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( tsects[0], "//" )), nullptr, 0 )); - auto second = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( tsects[1], "//" )), nullptr, 0 )); + auto first = static_cast( std::stoul( util::trim( util::strip( tsects[0], "//" )), nullptr, 0 )); + auto second = static_cast( std::stoul( util::trim( util::strip( tsects[1], "//" )), nullptr, 0 )); // Tag contained a minimum and maximum value for amount! Let's randomize! amountToSpawn = static_cast( RandomNum( first, second )); @@ -3590,7 +3592,7 @@ auto CSpawnItem::HandleSpawnContainer() -> bool } else if( GetTempVar( CITV_MOREX ) != 0 ) { - Items->AddRespawnItem( this, oldstrutil::number( GetTempVar( CITV_MOREX )), true, 1 ); + Items->AddRespawnItem( this, util::ntos( GetTempVar( CITV_MOREX )), true, 1 ); } else { diff --git a/source/cMultiObj.cpp b/source/cMultiObj.cpp index 1888b25bb..fd9a046dc 100644 --- a/source/cMultiObj.cpp +++ b/source/cMultiObj.cpp @@ -24,6 +24,8 @@ #include "uox3.h" #include "mapstuff.h" #include "osunique.hpp" +#include "utility/strutil.hpp" + const UI16 DEFMULTI_MAXLOCKDOWNS = 256; const UI16 DEFMULTI_MAXSECURECONTAINERS = 4; const UI16 DEFMULTI_MAXFRIENDS = 50; @@ -1086,7 +1088,7 @@ bool CMultiObj::HandleLine( std::string &UTag, std::string &data ) case 'B': if( UTag == "BANNED" ) { - CChar *bList = CalcCharObjFromSer( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + CChar *bList = CalcCharObjFromSer( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); if( ValidateObject( bList )) { AddToBanList( bList ); @@ -1095,7 +1097,7 @@ bool CMultiObj::HandleLine( std::string &UTag, std::string &data ) } else if( UTag == "BUILDTIME" ) { - time_t buildTime = static_cast( std::stoll( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )); + time_t buildTime = static_cast( std::stoll( util::trim( util::strip( data, "//" )), nullptr, 0 )); if( buildTime > 0 ) { SetBuildTimestamp( buildTime ); @@ -1106,7 +1108,7 @@ bool CMultiObj::HandleLine( std::string &UTag, std::string &data ) case 'C': if( UTag == "COOWNER" ) // Legacy tag for loading older data { - CChar *cList = CalcCharObjFromSer( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + CChar *cList = CalcCharObjFromSer( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); if( ValidateObject( cList )) { AddAsOwner( cList ); @@ -1124,7 +1126,7 @@ bool CMultiObj::HandleLine( std::string &UTag, std::string &data ) case 'F': if( UTag == "FRIEND" ) { - CChar *cList = CalcCharObjFromSer( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + CChar *cList = CalcCharObjFromSer( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); if( ValidateObject( cList )) { AddAsFriend( cList ); @@ -1135,7 +1137,7 @@ bool CMultiObj::HandleLine( std::string &UTag, std::string &data ) case 'G': if( UTag == "GUEST" ) { - CChar *cList = CalcCharObjFromSer( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + CChar *cList = CalcCharObjFromSer( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); if( ValidateObject( cList )) { AddAsGuest( cList ); @@ -1146,14 +1148,14 @@ bool CMultiObj::HandleLine( std::string &UTag, std::string &data ) case 'I': if( UTag == "ISPUBLIC" ) { - SetPublicStatus( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )) == 1 ); + SetPublicStatus( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 )) == 1 ); rValue = true; } break; case 'L': if( UTag == "LOCKEDITEM" ) { - CItem *iList = CalcItemObjFromSer( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + CItem *iList = CalcItemObjFromSer( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); if( ValidateObject( iList )) { LockDownItem( iList ); @@ -1164,44 +1166,44 @@ bool CMultiObj::HandleLine( std::string &UTag, std::string &data ) case 'M': if( UTag == "MAXBANS" ) { - maxBans = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )); + maxBans = static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 )); rValue = true; } else if( UTag == "MAXFRIENDS" ) { - maxFriends = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )); + maxFriends = static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 )); rValue = true; } else if( UTag == "MAXGUESTS" ) { - maxGuests = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )); + maxGuests = static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 )); rValue = true; } else if( UTag == "MAXLOCKDOWNS" || UTag == "MAXLOCKEDDOWN" ) { - maxLockdowns = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )); + maxLockdowns = static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 )); rValue = true; } else if( UTag == "MAXOWNERS" ) { - maxOwners = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )); + maxOwners = static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 )); rValue = true; } else if( UTag == "MAXSECURECONTAINERS" ) { - maxSecureContainers = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )); + maxSecureContainers = static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 )); rValue = true; } else if( UTag == "MAXVENDORS" ) { - maxVendors = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )); + maxVendors = static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 )); rValue = true; } break; case 'O': if( UTag == "OWNER" ) { - CChar *cList = CalcCharObjFromSer( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + CChar *cList = CalcCharObjFromSer( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); if( ValidateObject( cList )) { AddAsOwner( cList ); @@ -1212,7 +1214,7 @@ bool CMultiObj::HandleLine( std::string &UTag, std::string &data ) case 'S': if( UTag == "SECURECONTAINER" ) { - CItem *iList = CalcItemObjFromSer( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + CItem *iList = CalcItemObjFromSer( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); if( ValidateObject( iList )) { SecureContainer( iList ); @@ -1223,7 +1225,7 @@ bool CMultiObj::HandleLine( std::string &UTag, std::string &data ) case 'T': if( UTag == "TRADETIME" ) { - time_t tradeTime = static_cast( std::stoll( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )); + time_t tradeTime = static_cast( std::stoll( util::trim( util::strip( data, "//" )), nullptr, 0 )); if( tradeTime > 0 ) { SetTradeTimestamp( tradeTime ); @@ -1234,7 +1236,7 @@ bool CMultiObj::HandleLine( std::string &UTag, std::string &data ) case 'V': if( UTag == "VENDOR" ) { - CChar *cList = CalcCharObjFromSer( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + CChar *cList = CalcCharObjFromSer( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); if( ValidateObject( cList )) { AddVendor( cList ); @@ -1544,22 +1546,22 @@ bool CBoatObj::HandleLine( std::string &UTag, std::string &data ) case 'H': if( UTag == "HOLD" ) { - SetHold( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + SetHold( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); rValue = true; } break; case 'P': if( UTag == "PLANKS" ) { - SetPlank( 0, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 ))); - SetPlank( 1, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 ))); + SetPlank( 0, static_cast( std::stoul( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 ))); + SetPlank( 1, static_cast( std::stoul( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 ))); rValue = true; } break; case 'T': if( UTag == "TILLER" ) { - SetTiller( oldstrutil::value( data )); + SetTiller( util::ston( data )); rValue = true; } break; diff --git a/source/cPlayerAction.cpp b/source/cPlayerAction.cpp index 128d71fb7..8fec6efe3 100644 --- a/source/cPlayerAction.cpp +++ b/source/cPlayerAction.cpp @@ -20,6 +20,7 @@ #include "cServerDefinitions.h" #include "cSkillClass.h" #include "Dictionary.h" +#include "utility/strutil.hpp" using namespace std::string_literals; @@ -554,7 +555,7 @@ bool CPIGetItem::Handle( void ) // Store temp tag on corpse with serial of player who looted the corpse last TAGMAPOBJECT tagObject; tagObject.m_Destroy = false; - tagObject.m_StringValue = oldstrutil::number( ourChar->GetSerial() ); + tagObject.m_StringValue = util::ntos( ourChar->GetSerial() ); tagObject.m_IntValue = 0; tagObject.m_ObjectType = TAGMAP_TYPE_INT; i->SetTempTag( "lootedBy", tagObject ); @@ -890,7 +891,7 @@ auto IsOnFoodList( const std::string& sFoodList, const UI16 sItemId ) -> bool auto tag = sec->tag; if( !tag.empty() ) { - if( oldstrutil::upper( tag ) == "FOODLIST" ) + if( util::upper( tag ) == "FOODLIST" ) { doesEat = IsOnFoodList( sec->data, sItemId ); } @@ -2368,20 +2369,20 @@ void GetFameTitle( CChar *p, std::string& fameTitle ) { if( p->GetId( 2 ) == 0x91 ) { - fameTitle = oldstrutil::format( Dictionary->GetEntry( 1177 ), Races->Name( p->GetRace() ).c_str() ) + std::string( " " ); + fameTitle = util::format( Dictionary->GetEntry( 1177 ), Races->Name( p->GetRace() ).c_str() ) + std::string( " " ); } else { - fameTitle = oldstrutil::format( Dictionary->GetEntry( 1178 ), Races->Name( p->GetRace() ).c_str() ) + std::string( " " ); + fameTitle = util::format( Dictionary->GetEntry( 1178 ), Races->Name( p->GetRace() ).c_str() ) + std::string( " " ); } } else if( p->GetId( 2 ) == 0x91 ) { - fameTitle = oldstrutil::format( Dictionary->GetEntry( 1179 ), theTitle.c_str() ) + std::string( " " ); + fameTitle = util::format( Dictionary->GetEntry( 1179 ), theTitle.c_str() ) + std::string( " " ); } else { - fameTitle = oldstrutil::format( Dictionary->GetEntry( 1180 ), theTitle.c_str() ) + std::string( " " ); + fameTitle = util::format( Dictionary->GetEntry( 1180 ), theTitle.c_str() ) + std::string( " " ); } } else @@ -2390,9 +2391,9 @@ void GetFameTitle( CChar *p, std::string& fameTitle ) { fameTitle = Dictionary->GetEntry( 1181 ) + std::string( " " ); } - else if( !( theTitle = oldstrutil::removeTrailing( theTitle, "//" )).empty() ) + else if( !( theTitle = util::strip( theTitle, "//" )).empty() ) { - fameTitle = oldstrutil::format( Dictionary->GetEntry( 1182 ), theTitle.c_str() ); + fameTitle = util::format( Dictionary->GetEntry( 1182 ), theTitle.c_str() ); } } } @@ -2483,7 +2484,7 @@ void PaperDoll( CSocket *s, CChar *pdoll ) { if( cwmWorldState->murdererTags.empty() ) { - tempstr = oldstrutil::format( Dictionary->GetEntry( 374, sLang ), pdoll->GetNameRequest( myChar, NRS_PAPERDOLL ).c_str(), pdoll->GetTitle().c_str(), skillProwessTitle.c_str() ); + tempstr = util::format( Dictionary->GetEntry( 374, sLang ), pdoll->GetNameRequest( myChar, NRS_PAPERDOLL ).c_str(), pdoll->GetTitle().c_str(), skillProwessTitle.c_str() ); } else if( pdoll->GetKills() < cwmWorldState->murdererTags[0].lowBound ) // not a real murderer { @@ -2510,7 +2511,7 @@ void PaperDoll( CSocket *s, CChar *pdoll ) } else if( pdoll->IsCriminal() ) { - tempstr = oldstrutil::format( Dictionary->GetEntry( 373, sLang ), pdoll->GetNameRequest( myChar, NRS_PAPERDOLL ).c_str(), pdoll->GetTitle().c_str(), skillProwessTitle.c_str() ); + tempstr = util::format( Dictionary->GetEntry( 373, sLang ), pdoll->GetNameRequest( myChar, NRS_PAPERDOLL ).c_str(), pdoll->GetTitle().c_str(), skillProwessTitle.c_str() ); } else { @@ -2530,7 +2531,7 @@ void PaperDoll( CSocket *s, CChar *pdoll ) { if( pdoll->GetTownPriv() == 2 ) // is Mayor { - tempstr = oldstrutil::format( Dictionary->GetEntry( 379, sLang ), pdoll->GetNameRequest( myChar, NRS_PAPERDOLL ).c_str(), cwmWorldState->townRegions[pdoll->GetTown()]->GetName().c_str(), skillProwessTitle.c_str() ); + tempstr = util::format( Dictionary->GetEntry( 379, sLang ), pdoll->GetNameRequest( myChar, NRS_PAPERDOLL ).c_str(), cwmWorldState->townRegions[pdoll->GetTown()]->GetName().c_str(), skillProwessTitle.c_str() ); } else // is Resident { @@ -3395,7 +3396,7 @@ ItemTypes FindItemTypeFromTag( const std::string &strToFind ) { InitTagToItemType(); } - std::map::const_iterator toFind = tagToItemType.find( oldstrutil::upper( strToFind )); + std::map::const_iterator toFind = tagToItemType.find( util::upper( strToFind )); if( toFind != tagToItemType.end() ) return toFind->second; @@ -3429,7 +3430,7 @@ auto InitIdToItemType() -> void { for( SI32 i = 0; i <= sectionCount; i++ ) { - idToItemType[ oldstrutil::value( oldstrutil::extractSection( data, ",", i, i ), 16 )] = iType; + idToItemType[ util::ston( oldstrutil::extractSection( data, ",", i, i ), 16 )] = iType; } } else @@ -3766,13 +3767,13 @@ const char *AppendData( CSocket *s, CItem *i, std::string ¤tName ) case IT_CONTAINER: case IT_SPAWNCONT: case IT_UNLOCKABLESPAWNCONT: - dataToAdd = std::string( " (" ) + oldstrutil::number( static_cast( i->GetContainsList()->Num() )) + std::string( " items, " ); - dataToAdd += oldstrutil::number(( i->GetWeight() / 100 )) + std::string( " stones)" ); + dataToAdd = std::string( " (" ) + util::ntos( static_cast( i->GetContainsList()->Num() )) + std::string( " items, " ); + dataToAdd += util::ntos(( i->GetWeight() / 100 )) + std::string( " stones)" ); break; case IT_LOCKEDCONTAINER: // containers case IT_LOCKEDSPAWNCONT: // spawn containers - dataToAdd = std::string( " (" ) + oldstrutil::number( static_cast( i->GetContainsList()->Num() )) + std::string( " items, " ); - dataToAdd += oldstrutil::number(( i->GetWeight() / 100 )) + std::string( " stones) " + Dictionary->GetEntry( 9050, s->Language() )); // [Locked] + dataToAdd = std::string( " (" ) + util::ntos( static_cast( i->GetContainsList()->Num() )) + std::string( " items, " ); + dataToAdd += util::ntos(( i->GetWeight() / 100 )) + std::string( " stones) " + Dictionary->GetEntry( 9050, s->Language() )); // [Locked] break; case IT_LOCKEDDOOR: dataToAdd = " " + Dictionary->GetEntry( 9050 ); // [Locked] @@ -3917,13 +3918,13 @@ bool CPISingleClick::Handle( void ) { if( i->GetId() == 0x0ED5 ) //guildstone { - realname = oldstrutil::format( Dictionary->GetEntry( 101, tSock->Language() ).c_str(), i->GetNameRequest( tSock->CurrcharObj(), NRS_SINGLECLICK ).c_str() ); + realname = util::format( Dictionary->GetEntry( 101, tSock->Language() ).c_str(), i->GetNameRequest( tSock->CurrcharObj(), NRS_SINGLECLICK ).c_str() ); } if( !i->IsPileable() || getAmount == 1 ) { if( mChar->IsGM() && !i->IsCorpse() && getAmount > 1 ) { - realname = oldstrutil::format( "%s (%u)", i->GetNameRequest( tSock->CurrcharObj(), NRS_SINGLECLICK ).c_str(), getAmount ); + realname = util::format( "%s (%u)", i->GetNameRequest( tSock->CurrcharObj(), NRS_SINGLECLICK ).c_str(), getAmount ); } else { @@ -3932,7 +3933,7 @@ bool CPISingleClick::Handle( void ) } else { - realname = oldstrutil::format( "%u %ss", getAmount, i->GetNameRequest( tSock->CurrcharObj(), NRS_SINGLECLICK ).c_str() ); + realname = util::format( "%u %ss", getAmount, i->GetNameRequest( tSock->CurrcharObj(), NRS_SINGLECLICK ).c_str() ); } } else @@ -3946,7 +3947,7 @@ bool CPISingleClick::Handle( void ) { if( i->GetName2() == "#" || i->GetName2() == "" ) { - realname += oldstrutil::format( Dictionary->GetEntry( 9404, tSock->Language() ), i->GetTempVar( CITV_MOREZ )); // with %d charges + realname += util::format( Dictionary->GetEntry( 9404, tSock->Language() ), i->GetTempVar( CITV_MOREZ )); // with %d charges } else { @@ -3964,7 +3965,7 @@ bool CPISingleClick::Handle( void ) { iCount = static_cast( i->GetContainsList()->Num() ); } - realname += oldstrutil::format( ", (%u items, %u stones)", iCount, ( i->GetWeight() / 100 )); + realname += util::format( ", (%u items, %u stones)", iCount, ( i->GetWeight() / 100 )); } // Use item's real name as starting point for final string @@ -3978,11 +3979,11 @@ bool CPISingleClick::Handle( void ) if( cwmWorldState->ServerData()->RankSystemStatus() && i->GetRank() == 10 ) { std::string creatorName = GetNpcDictName( mCreator, tSock, NRS_SINGLECLICK ); - temp2 += oldstrutil::format( " %s", Dictionary->GetEntry( 9140, tSock->Language() ).c_str() ); // of exceptional quality + temp2 += util::format( " %s", Dictionary->GetEntry( 9140, tSock->Language() ).c_str() ); // of exceptional quality if( cwmWorldState->ServerData()->DisplayMakersMark() && i->IsMarkedByMaker() ) { - temp2 += oldstrutil::format( " %s by %s", cwmWorldState->skill[i->GetMadeWith()-1].madeWord.c_str(), creatorName.c_str() ); // [crafted] by %s + temp2 += util::format( " %s by %s", cwmWorldState->skill[i->GetMadeWith()-1].madeWord.c_str(), creatorName.c_str() ); // [crafted] by %s } } } diff --git a/source/cRaces.cpp b/source/cRaces.cpp index 6c67aaa7d..506767f73 100644 --- a/source/cRaces.cpp +++ b/source/cRaces.cpp @@ -7,6 +7,7 @@ #include "CJSEngine.h" #include "power.h" #include +#include "utility/strutil.hpp" cRaces *Races = nullptr; @@ -90,7 +91,7 @@ void cRaces::Load() while( !done ) { - sect = std::string( "RACE " ) + oldstrutil::number( raceCount ); + sect = std::string( "RACE " ) + util::ntos( raceCount ); CScriptSection *tempSect = FileLookup->FindEntry( sect, race_def ); if( tempSect == nullptr ) { @@ -117,7 +118,7 @@ void cRaces::Load() } else { - if( oldstrutil::upper( tag ) != "MODCOUNT" ) + if( util::upper( tag ) != "MODCOUNT" ) { Console.Error( "MODCOUNT must come before any entries!" ); DefaultInitCombat(); @@ -1691,7 +1692,7 @@ void CRace::Load( size_t sectNum, SI32 modCount ) std::string data; std::string UTag; SI32 raceDiff = 0; - std::string sect = std::string( "RACE " ) + oldstrutil::number( sectNum ); + std::string sect = std::string( "RACE " ) + util::ntos( sectNum ); CScriptSection *RacialPart = FileLookup->FindEntry( sect, race_def ); if( RacialPart == nullptr ) return; @@ -1700,7 +1701,7 @@ void CRace::Load( size_t sectNum, SI32 modCount ) for( tag = RacialPart->First(); !RacialPart->AtEnd(); tag = RacialPart->Next() ) { - UTag = oldstrutil::upper( tag ); + UTag = util::upper( tag ); data = RacialPart->GrabData(); switch( tag[0] ) @@ -1714,14 +1715,14 @@ void CRace::Load( size_t sectNum, SI32 modCount ) std::string subTag; std::string subUTag; std::string subData; - std::string subSect = std::string( "EQUIPLIST " ) + oldstrutil::number( static_cast( std::stoul( data, nullptr, 0 ))); + std::string subSect = std::string( "EQUIPLIST " ) + util::ntos( static_cast( std::stoul( data, nullptr, 0 ))); CScriptSection *RacialEquipment = FileLookup->FindEntry( subSect, race_def ); if( RacialEquipment == nullptr ) break; for( subTag = RacialEquipment->First(); !RacialEquipment->AtEnd(); subTag = RacialEquipment->Next() ) { - subUTag = oldstrutil::upper( subTag ); + subUTag = util::upper( subTag ); subData = RacialEquipment->GrabData(); switch( subTag[0] ) { @@ -1732,7 +1733,7 @@ void CRace::Load( size_t sectNum, SI32 modCount ) auto csecs = oldstrutil::sections( subData, "," ); for( size_t i = 0; i < csecs.size() - 1; i++ ) { - UI16 temp = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[i], "//" )), nullptr, 0 )); + UI16 temp = static_cast( std::stoul( util::trim( util::strip( csecs[i], "//" )), nullptr, 0 )); //allowedEquipment.push_back( temp ); allowedEquipment.insert( temp ); } @@ -1757,14 +1758,14 @@ void CRace::Load( size_t sectNum, SI32 modCount ) std::string subTag; std::string subUTag; std::string subData; - std::string subSect = std::string( "EQUIPLIST " ) + oldstrutil::number( static_cast( std::stoul( data, nullptr, 0 ))); + std::string subSect = std::string( "EQUIPLIST " ) + util::ntos( static_cast( std::stoul( data, nullptr, 0 ))); CScriptSection *RacialEquipment = FileLookup->FindEntry( subSect, race_def ); if( RacialEquipment == nullptr ) break; for( subTag = RacialEquipment->First(); !RacialEquipment->AtEnd(); subTag = RacialEquipment->Next() ) { - subUTag = oldstrutil::upper( subTag ); + subUTag = util::upper( subTag ); subData = RacialEquipment->GrabData(); switch( subTag[0] ) { @@ -1775,7 +1776,7 @@ void CRace::Load( size_t sectNum, SI32 modCount ) auto csecs = oldstrutil::sections( subData, "," ); for( size_t i = 0; i < csecs.size() - 1; i++ ) { - UI16 temp = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[i], "//" )), nullptr, 0 )); + UI16 temp = static_cast( std::stoul( util::trim( util::strip( csecs[i], "//" )), nullptr, 0 )); //bannedEquipment.push_back( temp ); bannedEquipment.insert( temp ); } @@ -1832,7 +1833,7 @@ void CRace::Load( size_t sectNum, SI32 modCount ) case 'G': if( UTag == "GENDER" ) { - auto udata = oldstrutil::upper( data ); + auto udata = util::upper( data ); if( udata == "MALE" ) { GenderRestriction( MALE ); @@ -1888,8 +1889,8 @@ void CRace::Load( size_t sectNum, SI32 modCount ) auto csecs = oldstrutil::sections( data, "," ); if( csecs.size() > 1 ) { - SetHungerRate( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 ))); - SetHungerDamage( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 ))); + SetHungerRate( static_cast( std::stoi( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 ))); + SetHungerDamage( static_cast( std::stoi( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 ))); } else { @@ -2027,7 +2028,7 @@ void CRace::Load( size_t sectNum, SI32 modCount ) auto ssecs = oldstrutil::sections(data," "); if( ssecs.size() > 1 ) { - RaceRelation( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[1], "//" )), nullptr, 0 )), static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[0], "//" )), nullptr, 0 ))); + RaceRelation( static_cast( std::stoi( util::trim( util::strip( ssecs[1], "//" )), nullptr, 0 )), static_cast( std::stoul( util::trim( util::strip( ssecs[0], "//" )), nullptr, 0 ))); } } else if( UTag == "RACIALENEMY" ) @@ -2107,8 +2108,8 @@ void CRace::Load( size_t sectNum, SI32 modCount ) auto csecs = oldstrutil::sections( data, "," ); if( csecs.size() > 1 ) { - SetThirstRate( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 ))); - SetThirstDrain( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 ))); + SetThirstRate( static_cast( std::stoi( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 ))); + SetThirstDrain( static_cast( std::stoi( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 ))); } else { diff --git a/source/cScript.cpp b/source/cScript.cpp index 0a248184e..9058c8a68 100644 --- a/source/cScript.cpp +++ b/source/cScript.cpp @@ -11,6 +11,8 @@ #include "JSEncapsulate.h" #include "cSpawnRegion.h" #include "StringUtility.hpp" +#include "utility/strutil.hpp" + #include "osunique.hpp" //o------------------------------------------------------------------------------------------------o @@ -188,16 +190,16 @@ void UOX3ErrorReporter( JSContext *cx, const char *message, JSErrorReport *repor { UI16 scriptNum = JSMapping->GetScriptId( JS_GetGlobalObject( cx )); // If we're loading the world then do NOT print out anything! - Console.Error( oldstrutil::format( "JS script failure: Script Number (%u) Message (%s)", scriptNum, message )); + Console.Error( util::format( "JS script failure: Script Number (%u) Message (%s)", scriptNum, message )); if( report == nullptr || report->filename == nullptr ) { Console.Error( "No detailed data" ); return; } - Console.Error( oldstrutil::format( "Filename: %s\n| Line Number: %i", report->filename, report->lineno )); + Console.Error( util::format( "Filename: %s\n| Line Number: %i", report->filename, report->lineno )); if( report->linebuf != nullptr || report->tokenptr != nullptr ) { - Console.Error( oldstrutil::format( "Erroneous Line: %s\n| Token Ptr: %s", report->linebuf, report->tokenptr )); + Console.Error( util::format( "Erroneous Line: %s\n| Token Ptr: %s", report->linebuf, report->tokenptr )); } } @@ -545,7 +547,7 @@ SI08 cScript::OnSpeech( const char *speech, CChar *personTalking, CBaseObject *t JSString *strSpeech = nullptr; std::string lwrSpeech = speech; - strSpeech = JS_NewStringCopyZ( targContext, oldstrutil::lower( lwrSpeech ).c_str() ); + strSpeech = JS_NewStringCopyZ( targContext, util::lower( lwrSpeech ).c_str() ); JSObject *ptObj = JSEngine->AcquireObject( IUE_CHAR, personTalking, runTime ); JSObject *ttObj = nullptr; @@ -2436,7 +2438,7 @@ bool cScript::DoCallback( CSocket *tSock, SERIAL targeted, UI08 callNum ) JS_SetGlobalObject( targContext, targObject ); - JSBool retVal = JS_CallFunctionName( targContext, targObject, oldstrutil::format( "onCallback%i", callNum ).c_str(), 2, params, &rval ); + JSBool retVal = JS_CallFunctionName( targContext, targObject, util::format( "onCallback%i", callNum ).c_str(), 2, params, &rval ); return ( retVal == JS_TRUE ); } catch( ... ) @@ -3101,7 +3103,7 @@ SI08 cScript::OnTalk( CChar *myChar, const char *mySpeech ) JSString *strSpeech = nullptr; std::string lwrSpeech = mySpeech; - strSpeech = JS_NewStringCopyZ( targContext, oldstrutil::lower( lwrSpeech ).c_str() ); + strSpeech = JS_NewStringCopyZ( targContext, util::lower( lwrSpeech ).c_str() ); JSObject *charObj = JSEngine->AcquireObject( IUE_CHAR, myChar, runTime ); @@ -3349,7 +3351,7 @@ SI08 cScript::OnCommand( CSocket *mSock, std::string command ) jsval params[2], rval; JSObject *myObj = JSEngine->AcquireObject( IUE_SOCK, mSock, runTime ); JSString *strCmd = nullptr; - strCmd = JS_NewStringCopyZ( targContext, oldstrutil::lower( command ).c_str() ); + strCmd = JS_NewStringCopyZ( targContext, util::lower( command ).c_str() ); params[0] = OBJECT_TO_JSVAL( myObj ); params[1] = STRING_TO_JSVAL( strCmd ); JSBool retVal = JS_CallFunctionName( targContext, targObject, "onCommand", 2, params, &rval ); @@ -3407,7 +3409,7 @@ bool cScript::ScriptRegistration( std::string scriptType ) JS_GetProperty( targContext, targObject, scriptType.c_str(), &Func ); if( Func == JSVAL_VOID ) { - Console.Warning( oldstrutil::format( "Script Number (%u) does not have a %s function", JSMapping->GetScriptId( targObject ), scriptType.c_str() )); + Console.Warning( util::format( "Script Number (%u) does not have a %s function", JSMapping->GetScriptId( targObject ), scriptType.c_str() )); return false; } diff --git a/source/cServerData.cpp b/source/cServerData.cpp index d72e19472..382bf5f88 100644 --- a/source/cServerData.cpp +++ b/source/cServerData.cpp @@ -14,6 +14,8 @@ #endif #include "StringUtility.hpp" +#include "utility/strutil.hpp" +#include "utility/strutil.hpp" #include "osunique.hpp" using namespace std::string_literals; @@ -1430,11 +1432,11 @@ auto CServerData::Directory( CSDDirectoryPaths dp, std::string value ) -> void }; // First, let's normalize the path name and fix common errors // remove all trailing and leading spaces... - auto sText = oldstrutil::trim( value ); + auto sText = util::trim(value) ; if( sText.empty() ) { - Console.Error( oldstrutil::format( " %s directory is blank, set in uox.ini", verboseDirectory.c_str() )); + Console.Error( util::format( " %s directory is blank, set in uox.ini", verboseDirectory.c_str() )); Shutdown( FATAL_UOX3_DIR_NOT_FOUND ); } else @@ -1467,7 +1469,7 @@ auto CServerData::Directory( CSDDirectoryPaths dp, std::string value ) -> void if( error ) { - Console.Error( oldstrutil::format( "%s %s does not exist", verboseDirectory.c_str(), sText.c_str() )); + Console.Error( util::format( "%s %s does not exist", verboseDirectory.c_str(), sText.c_str() )); Shutdown( FATAL_UOX3_DIR_NOT_FOUND ); } else @@ -4737,7 +4739,7 @@ auto CServerData::EraEnumToString( ExpansionRuleset eraEnum, bool coreEnum ) -> } catch( const std::out_of_range &e ) { - Console.Error( oldstrutil::format( "Unknown era enum detected, exception thrown: %s", e.what() )); + Console.Error( util::format( "Unknown era enum detected, exception thrown: %s", e.what() )); } } @@ -4757,7 +4759,7 @@ auto CServerData::EraStringToEnum( const std::string &eraString, bool useDefault rValue = ER_LBR; // Default era if specified era is not found } - auto searchEra = oldstrutil::lower( eraString ); + auto searchEra = util::lower( eraString ); if( inheritCore && searchEra == "core" ) { // Inherit setting from CORESHARDERA setting @@ -5237,7 +5239,7 @@ auto CServerData::SaveIni( const std::string &filename ) -> bool } else { - Console.Error( oldstrutil::format( "Unable to open file %s for writing", filename.c_str() )); + Console.Error( util::format( "Unable to open file %s for writing", filename.c_str() )); } return rValue; } @@ -5350,7 +5352,7 @@ auto CServerData::ParseIni( const std::string& filename ) -> bool if( pos2 != std::string::npos ) { // We have the bounds - auto contents = oldstrutil::trim( input.substr( pos1 + 1, ( pos2 - pos1 ) - 1 )); + auto contents = util::trim( input.substr( pos1 + 1, ( pos2 - pos1 ) - 1 )); return contents; } } @@ -5368,7 +5370,7 @@ auto CServerData::ParseIni( const std::string& filename ) -> bool if( input.gcount() > 0 ) { input_buffer[input.gcount()] = 0; - auto line = oldstrutil::trim( oldstrutil::removeTrailing( std::string( input_buffer ), "//" )); + auto line = util::trim( util::strip( std::string( input_buffer ), "//" )); if( !line.empty() ) { switch( static_cast( state )) @@ -5397,7 +5399,7 @@ auto CServerData::ParseIni( const std::string& filename ) -> bool { if( line[0] != '}' ) { - auto [key, value] = oldstrutil::split( line, "=" ); + auto [key, value] = util::split( line, "=" ); try { if( HandleLine( key, value )) @@ -5408,8 +5410,8 @@ auto CServerData::ParseIni( const std::string& filename ) -> bool catch( const std::exception &e ) { Console.Error( "Error parsing ini file" ); - Console.Error( oldstrutil::format( "Entry was: %s = %s", key.c_str(), value.c_str() )); - Console.Error( oldstrutil::format( "Exception was: %s", e.what() )); + Console.Error( util::format( "Entry was: %s = %s", key.c_str(), value.c_str() )); + Console.Error( util::format( "Exception was: %s", e.what() )); exit( 1 ); } } @@ -5439,9 +5441,9 @@ auto CServerData::ParseIni( const std::string& filename ) -> bool if( section){ for (auto &sec : section->collection() ){ auto tag = sec->tag; - auto data = oldstrutil::simplify( sec->data ); + auto data = util::simplify( sec->data ); if( !HandleLine( tag, data )) { - Console.Warning( oldstrutil::format( "Unhandled tag '%s'", tag.c_str() )); + Console.Warning( util::format( "Unhandled tag '%s'", tag.c_str() )); } } } @@ -5451,7 +5453,7 @@ auto CServerData::ParseIni( const std::string& filename ) -> bool } else { - Console.Warning( oldstrutil::format( "%s File not found, Using default settings.", filename.c_str() )); + Console.Warning( util::format( "%s File not found, Using default settings.", filename.c_str() )); cwmWorldState->ServerData()->save(); } } @@ -6138,31 +6140,31 @@ auto CServerData::HandleLine( const std::string& tag, const std::string& value ) MapDiffsEnabled( static_cast( std::stoul( value, nullptr, 0 )) == 1 ); break; case 231: // CORESHARDERA - ExpansionCoreShardEra( EraStringToEnum( oldstrutil::trim( value ))); + ExpansionCoreShardEra( EraStringToEnum( util::trim( value ))); break; case 232: // ARMORCALCULATION - ExpansionArmorCalculation( EraStringToEnum( oldstrutil::trim( value ))); + ExpansionArmorCalculation( EraStringToEnum( util::trim( value ))); break; case 233: // STRENGTHDAMAGEBONUS - ExpansionStrengthDamageBonus( EraStringToEnum( oldstrutil::trim( value ))); + ExpansionStrengthDamageBonus( EraStringToEnum( util::trim( value ))); break; case 234: // TACTICSDAMAGEBONUS - ExpansionTacticsDamageBonus( EraStringToEnum( oldstrutil::trim( value ))); + ExpansionTacticsDamageBonus( EraStringToEnum( util::trim( value ))); break; case 235: // ANATOMYDAMAGEBONUS - ExpansionAnatomyDamageBonus( EraStringToEnum( oldstrutil::trim( value ))); + ExpansionAnatomyDamageBonus( EraStringToEnum( util::trim( value ))); break; case 236: // LUMBERJACKDAMAGEBONUS - ExpansionLumberjackDamageBonus( EraStringToEnum( oldstrutil::trim( value ))); + ExpansionLumberjackDamageBonus( EraStringToEnum( util::trim( value ))); break; case 237: // RACIALDAMAGEBONUS - ExpansionRacialDamageBonus( EraStringToEnum( oldstrutil::trim( value ))); + ExpansionRacialDamageBonus( EraStringToEnum( util::trim( value ))); break; case 238: // DAMAGEBONUSCAP - ExpansionDamageBonusCap( EraStringToEnum( oldstrutil::trim( value ))); + ExpansionDamageBonusCap( EraStringToEnum( util::trim( value ))); break; case 239: // SHIELDPARRY - ExpansionShieldParry( EraStringToEnum( oldstrutil::trim( value ))); + ExpansionShieldParry( EraStringToEnum( util::trim( value ))); break; case 240: // PARRYDAMAGECHANCE CombatParryDamageChance( static_cast( std::stoul( value, nullptr, 0 ))); @@ -6386,13 +6388,13 @@ auto CServerData::HandleLine( const std::string& tag, const std::string& value ) ShowRaceInPaperdoll(( static_cast( std::stoul( value, nullptr, 0 )) >= 1 ? true : false )); break; case 313: // WEAPONPARRY - ExpansionWeaponParry( EraStringToEnum( oldstrutil::trim( value ))); + ExpansionWeaponParry( EraStringToEnum( util::trim( value ))); break; case 314: // WRESTLINGPARRY - ExpansionWrestlingParry( EraStringToEnum( oldstrutil::trim( value ))); + ExpansionWrestlingParry( EraStringToEnum( util::trim( value ))); break; case 315: // COMBATHITCHANCE - ExpansionCombatHitChance( EraStringToEnum( oldstrutil::trim( value ))); + ExpansionCombatHitChance( EraStringToEnum( util::trim( value ))); break; case 316: // CASTSPELLSWHILEMOVING CastSpellsWhileMoving(( static_cast( std::stoul( value, nullptr, 0 )) >= 1 ? true : false )); @@ -6656,29 +6658,29 @@ auto CServerData::ServerLocation( size_t locNum ) -> __STARTLOCATIONDATA__* auto CServerData::ServerLocation( std::string toSet ) -> void { auto temp = toSet; - temp = oldstrutil::trim( oldstrutil::removeTrailing( temp, "//" )); + temp = util::trim( util::strip( temp, "//" )); auto csecs = oldstrutil::sections( temp, "," ); __STARTLOCATIONDATA__ toAdd; if( csecs.size() >= 7 ) { - toAdd.oldTown = oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )); - toAdd.oldDescription = oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )); + toAdd.oldTown = util::trim( util::strip( csecs[0], "//" )); + toAdd.oldDescription = util::trim( util::strip( csecs[1], "//" )); toAdd.newTown = toAdd.oldTown; toAdd.newDescription = toAdd.oldDescription; - toAdd.x = static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[2], "//" )), nullptr, 0 )); - toAdd.y = static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[3], "//" )), nullptr, 0 )); - toAdd.z = static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[4], "//" )), nullptr, 0 )); - toAdd.worldNum = static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[5], "//" )), nullptr, 0 )); + toAdd.x = static_cast( std::stoi( util::trim( util::strip( csecs[2], "//" )), nullptr, 0 )); + toAdd.y = static_cast( std::stoi( util::trim( util::strip( csecs[3], "//" )), nullptr, 0 )); + toAdd.z = static_cast( std::stoi( util::trim( util::strip( csecs[4], "//" )), nullptr, 0 )); + toAdd.worldNum = static_cast( std::stoi( util::trim( util::strip( csecs[5], "//" )), nullptr, 0 )); if( csecs.size() == 7 ) { - toAdd.clilocDesc = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[6], "//" )), nullptr, 0 )); + toAdd.clilocDesc = static_cast( std::stoul( util::trim( util::strip( csecs[6], "//" )), nullptr, 0 )); } else { - toAdd.instanceId = static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[6], "//" )), nullptr, 0 )); - toAdd.clilocDesc = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[7], "//" )), nullptr, 0 )); + toAdd.instanceId = static_cast( std::stoi( util::trim( util::strip( csecs[6], "//" )), nullptr, 0 )); + toAdd.clilocDesc = static_cast( std::stoul( util::trim( util::strip( csecs[7], "//" )), nullptr, 0 )); } startlocations.push_back( toAdd ); } @@ -6711,29 +6713,29 @@ auto CServerData::YoungServerLocation( size_t locNum ) -> __STARTLOCATIONDATA__* auto CServerData::YoungServerLocation( std::string toSet ) -> void { auto temp = toSet; - temp = oldstrutil::trim( oldstrutil::removeTrailing( temp, "//" )); + temp = util::trim( util::strip( temp, "//" )); auto csecs = oldstrutil::sections( temp, "," ); __STARTLOCATIONDATA__ toAdd; if( csecs.size() >= 7 ) { - toAdd.oldTown = oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )); - toAdd.oldDescription = oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )); + toAdd.oldTown = util::trim( util::strip( csecs[0], "//" )); + toAdd.oldDescription = util::trim( util::strip( csecs[1], "//" )); toAdd.newTown = toAdd.oldTown; toAdd.newDescription = toAdd.oldDescription; - toAdd.x = static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[2], "//" )), nullptr, 0 )); - toAdd.y = static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[3], "//" )), nullptr, 0 )); - toAdd.z = static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[4], "//" )), nullptr, 0 )); - toAdd.worldNum = static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[5], "//" )), nullptr, 0 )); + toAdd.x = static_cast( std::stoi( util::trim( util::strip( csecs[2], "//" )), nullptr, 0 )); + toAdd.y = static_cast( std::stoi( util::trim( util::strip( csecs[3], "//" )), nullptr, 0 )); + toAdd.z = static_cast( std::stoi( util::trim( util::strip( csecs[4], "//" )), nullptr, 0 )); + toAdd.worldNum = static_cast( std::stoi( util::trim( util::strip( csecs[5], "//" )), nullptr, 0 )); if( csecs.size() == 7 ) { - toAdd.clilocDesc = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[6], "//" )), nullptr, 0 )); + toAdd.clilocDesc = static_cast( std::stoul( util::trim( util::strip( csecs[6], "//" )), nullptr, 0 )); } else { - toAdd.instanceId = static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[6], "//" )), nullptr, 0 )); - toAdd.clilocDesc = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[7], "//" )), nullptr, 0 )); + toAdd.instanceId = static_cast( std::stoi( util::trim( util::strip( csecs[6], "//" )), nullptr, 0 )); + toAdd.clilocDesc = static_cast( std::stoul( util::trim( util::strip( csecs[7], "//" )), nullptr, 0 )); } youngStartlocations.push_back( toAdd ); } @@ -6916,7 +6918,7 @@ auto CServerData::SaveTime() -> void std::ofstream timeDestination( timeFile.c_str() ); if( !timeDestination ) { - Console.Error( oldstrutil::format( "Failed to open %s for writing", timeFile.c_str() )); + Console.Error( util::format( "Failed to open %s for writing", timeFile.c_str() )); return; } @@ -6955,10 +6957,10 @@ auto CServerData::LoadTime() -> void input.getline( line, 1023 ); line[input.gcount()] = 0; std::string sLine( line ); - sLine = oldstrutil::trim( oldstrutil::removeTrailing( sLine, "//" )); + sLine = util::trim( util::strip( sLine, "//" )); if( !sLine.empty() ) { - if( oldstrutil::upper( sLine ) == "[TIME]" ) + if( util::upper( sLine ) == "[TIME]" ) { LoadTimeTags( input ); } @@ -6977,7 +6979,7 @@ auto CServerData::LoadTimeTags( std::istream &input ) -> void ReadWorldTagData( input, tag, data ); if( tag != "o---o" ) { - UTag = oldstrutil::upper( tag ); + UTag = util::upper( tag ); if( UTag == "AMPM" ) { @@ -7004,8 +7006,8 @@ auto CServerData::LoadTimeTags( std::istream &input ) -> void auto csecs = oldstrutil::sections( data, "," ); if( csecs.size() > 1 ) { - ServerMoon( 0, static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 ))); - ServerMoon( 1, static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 ))); + ServerMoon( 0, static_cast( std::stoi( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 ))); + ServerMoon( 1, static_cast( std::stoi( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 ))); } } } diff --git a/source/cServerDefinitions.cpp b/source/cServerDefinitions.cpp index db3d29314..0ab4f3a2c 100644 --- a/source/cServerDefinitions.cpp +++ b/source/cServerDefinitions.cpp @@ -3,6 +3,7 @@ #include "ssection.h" #include "scriptc.h" #include "StringUtility.hpp" +#include "utility/strutil.hpp" #include #include @@ -155,7 +156,7 @@ auto CServerDefinitions::FindEntry( const std::string &toFind, DEFINITIONCATEGOR if( !toFind.empty() && typeToFind != NUM_DEFS ) { - auto tUFind = oldstrutil::upper( toFind ); + auto tUFind = util::upper( toFind ); VECSCRIPTLIST& toDel = ScriptListings[typeToFind]; for( VECSCRIPTLIST_CITERATOR dIter = toDel.begin(); dIter != toDel.end(); ++dIter ) @@ -255,7 +256,7 @@ auto CServerDefinitions::LoadDFNCategory( DEFINITIONCATEGORIES toLoad) -> void if( !mSort.empty() ) { std::sort( mSort.begin(), mSort.end() ); - Console.Print( oldstrutil::format( "Section %20s : %6i", dirNames[toLoad].c_str(), 0 )); + Console.Print( util::format( "Section %20s : %6i", dirNames[toLoad].c_str(), 0 )); size_t iTotal = 0; Console.TurnYellow(); @@ -265,10 +266,10 @@ auto CServerDefinitions::LoadDFNCategory( DEFINITIONCATEGORIES toLoad) -> void Console.Print( "\b\b\b\b\b\b" ); ScriptListings[toLoad].push_back( new Script(( *mIter ).filename, toLoad, false )); iTotal += ScriptListings[toLoad].back()->NumEntries(); - Console.Print( oldstrutil::format( "%6i", iTotal )); + Console.Print( util::format( "%6i", iTotal )); } - Console.Print( oldstrutil::format( "\b\b\b\b\b\b%6i", CountOfEntries( toLoad ))); + Console.Print( util::format( "\b\b\b\b\b\b%6i", CountOfEntries( toLoad ))); Console.TurnNormal(); Console.Print( " entries" ); switch( wasPriod ) @@ -385,13 +386,13 @@ auto CServerDefinitions::BuildPriorityMap( DEFINITIONCATEGORIES category, UI08& { auto tag = sec->tag; auto data = sec->data; - if( oldstrutil::upper( tag ) == "DEFAULTPRIORITY" ) + if( util::upper( tag ) == "DEFAULTPRIORITY" ) { defaultPriority = static_cast( std::stoul( data, nullptr, 0 )); } else { - std::string filenametemp = oldstrutil::lower( tag ); + std::string filenametemp = util::lower( tag ); priorityMap[filenametemp] =static_cast( std::stoi( data, nullptr, 0 )); } } @@ -411,7 +412,7 @@ auto CServerDefinitions::BuildPriorityMap( DEFINITIONCATEGORIES category, UI08& } } #if defined( UOX_DEBUG_MODE ) - // Console.Warning( oldstrutil::format( "Failed to open priority.nfo for reading in %s DFN", dirNames[category].c_str() )); + // Console.Warning( util::format( "Failed to open priority.nfo for reading in %s DFN", dirNames[category].c_str() )); #endif wasPrioritized = 2; } @@ -435,7 +436,7 @@ void CServerDefinitions::DisplayPriorityMap() auto CServerDefinitions::GetPriority( const char *file ) -> SI16 { auto retVal = defaultPriority; - auto lowername = oldstrutil::lower( file ); + auto lowername = util::lower( file ); auto p = priorityMap.find( lowername ); if( p != priorityMap.end() ) { @@ -460,7 +461,7 @@ auto CDirectoryListing::PushDir( std::string toMove ) -> bool auto rValue = true; if( !std::filesystem::exists( path )) { - Console.Error( oldstrutil::format( "DFN directory %s does not exist", toMove.c_str() )); + Console.Error( util::format( "DFN directory %s does not exist", toMove.c_str() )); Shutdown( FATAL_UOX3_DIR_NOT_FOUND ); } std::filesystem::current_path( path ); diff --git a/source/cSocket.cpp b/source/cSocket.cpp index e1b7a5522..d7e708b9d 100644 --- a/source/cSocket.cpp +++ b/source/cSocket.cpp @@ -11,6 +11,8 @@ #include "Dictionary.h" #include "CJSEngine.h" #include "StringUtility.hpp" +#include "utility/strutil.hpp" + #include "typedefs.h" #if PLATFORM != WINDOWS @@ -769,7 +771,7 @@ bool CSocket::FlushBuffer( bool doLog ) { toPrint = currCharObj->GetSerial(); } - std::string logFile = cwmWorldState->ServerData()->Directory( CSDDP_LOGS ) + oldstrutil::number( toPrint ) + std::string( ".snd" ); + std::string logFile = cwmWorldState->ServerData()->Directory( CSDDP_LOGS ) + util::ntos( toPrint ) + std::string( ".snd" ); std::ofstream logDestination; logDestination.open( logFile.c_str(), std::ios::out | std::ios::app ); if( logDestination.is_open() ) @@ -780,7 +782,7 @@ bool CSocket::FlushBuffer( bool doLog ) } else { - Console.Error( oldstrutil::format( "Failed to open socket log %s", logFile.c_str() )); + Console.Error( util::format( "Failed to open socket log %s", logFile.c_str() )); } bytesSent += outlength; } @@ -833,7 +835,7 @@ bool CSocket::FlushLargeBuffer( bool doLog ) { toPrint = currCharObj->GetSerial(); } - std::string logFile = cwmWorldState->ServerData()->Directory( CSDDP_LOGS ) + oldstrutil::number( toPrint ) + std::string( ".snd" ); + std::string logFile = cwmWorldState->ServerData()->Directory( CSDDP_LOGS ) + util::ntos( toPrint ) + std::string( ".snd" ); std::ofstream logDestination; logDestination.open( logFile.c_str(), std::ios::out | std::ios::app ); if( logDestination.is_open() ) @@ -844,7 +846,7 @@ bool CSocket::FlushLargeBuffer( bool doLog ) } else { - Console.Error( oldstrutil::format( "Failed to open socket log %s", logFile.c_str() )); + Console.Error( util::format( "Failed to open socket log %s", logFile.c_str() )); } bytesSent += outlength; } @@ -969,13 +971,13 @@ void CSocket::Send( const void *point, SI32 length ) } if( outlength > 0 ) { - Console.Print( oldstrutil::format( "Fragmented packet! [packet: %i]\n", outbuffer[0] )); + Console.Print( util::format( "Fragmented packet! [packet: %i]\n", outbuffer[0] )); } // sometimes we send enormous packets... oh what fun if( length > MAXBUFFER ) { #if defined( UOX_DEBUG_MODE ) - Console.Print( oldstrutil::format( "Large packet found [%i]\n", outbuffer[0] )); + Console.Print( util::format( "Large packet found [%i]\n", outbuffer[0] )); #endif largeBuffer.resize( length ); memcpy( &largeBuffer[0], point, length ); @@ -1030,12 +1032,12 @@ void CSocket::ReceiveLogging( CPInputBuffer *toLog ) { toPrint = currCharObj->GetSerial(); } - std::string logFile = cwmWorldState->ServerData()->Directory( CSDDP_LOGS ) + oldstrutil::number( toPrint ) + std::string( ".rcv" ); + std::string logFile = cwmWorldState->ServerData()->Directory( CSDDP_LOGS ) + util::ntos( toPrint ) + std::string( ".rcv" ); std::ofstream logDestination; logDestination.open( logFile.c_str(), std::ios::out | std::ios::app ); if( !logDestination.is_open() ) { - Console.Error( oldstrutil::format( "Failed to open socket log %s", logFile.c_str() )); + Console.Error( util::format( "Failed to open socket log %s", logFile.c_str() )); return; } if( toLog != nullptr ) @@ -1280,7 +1282,7 @@ UI32 CSocket::GetDWord( size_t offset ) UI32 retVal = 0; if( offset + 3 >= MAXBUFFER ) { - Console.Error( oldstrutil::format( "GetDWord was passed an invalid offset value 0x%X", offset )); + Console.Error( util::format( "GetDWord was passed an invalid offset value 0x%X", offset )); } else { @@ -1299,7 +1301,7 @@ UI16 CSocket::GetWord( size_t offset ) UI16 retVal = 0; if( offset+1 >= MAXBUFFER ) { - Console.Error( oldstrutil::format( "GetWord was passed an invalid offset value 0x%X", offset )); + Console.Error( util::format( "GetWord was passed an invalid offset value 0x%X", offset )); } else { @@ -1318,7 +1320,7 @@ UI08 CSocket::GetByte( size_t offset ) UI08 retVal = 0; if( offset >= MAXBUFFER ) { - Console.Error( oldstrutil::format( "GetByte was passed an invalid offset value 0x%X", offset )); + Console.Error( util::format( "GetByte was passed an invalid offset value 0x%X", offset )); } else { @@ -1579,12 +1581,12 @@ void CSocket::Send( CPUOXBuffer *toSend ) { toPrint = currCharObj->GetSerial(); } - std::string logFile = cwmWorldState->ServerData()->Directory( CSDDP_LOGS ) + oldstrutil::number( toPrint ) + std::string( ".snd" ); + std::string logFile = cwmWorldState->ServerData()->Directory( CSDDP_LOGS ) + util::ntos( toPrint ) + std::string( ".snd" ); std::ofstream logDestination; logDestination.open( logFile.c_str(), std::ios::out | std::ios::app ); if( !logDestination.is_open() ) { - Console.Error( oldstrutil::format( "Failed to open socket log %s", logFile.c_str() )); + Console.Error( util::format( "Failed to open socket log %s", logFile.c_str() )); return; } toSend->Log( logDestination ); @@ -2163,11 +2165,11 @@ void CSocket::ShowCharName( CChar *i, bool showSer ) { if( i->GetId( 2 ) == 0x91 ) { - charName = oldstrutil::format( Dictionary->GetEntry( 1740, Language() ).c_str(), charName.c_str() ); // Morrolan, added Lord/Lady to title overhead + charName = util::format( Dictionary->GetEntry( 1740, Language() ).c_str(), charName.c_str() ); // Morrolan, added Lord/Lady to title overhead } else if( i->GetId( 1 ) == 0x90 ) { - charName = oldstrutil::format( Dictionary->GetEntry( 1739, Language() ).c_str(), charName.c_str() ); + charName = util::format( Dictionary->GetEntry( 1739, Language() ).c_str(), charName.c_str() ); } } if( cwmWorldState->ServerData()->ShowRaceWithName() && i->GetRace() != 0 && i->GetRace() != 65535 ) // need to check for placeholder race ( ) @@ -2178,7 +2180,7 @@ void CSocket::ShowCharName( CChar *i, bool showSer ) } if( i->GetTownPriv() == 2 ) { - charName = oldstrutil::format( Dictionary->GetEntry( 1738, Language() ).c_str(), charName.c_str() ); + charName = util::format( Dictionary->GetEntry( 1738, Language() ).c_str(), charName.c_str() ); } if( !IsOnline(( *i ))) { @@ -2765,7 +2767,7 @@ void CSocket::OpenPack( CItem *i, bool isPlayerVendor ) contSend.Model( 0x11A ); // Square gray mailbox break; case PT_UNKNOWN: - Console.Warning( oldstrutil::format( "OpenPack() passed an invalid container type: 0x%X", i->GetSerial() )); + Console.Warning( util::format( "OpenPack() passed an invalid container type: 0x%X", i->GetSerial() )); return; } } diff --git a/source/cSpawnRegion.cpp b/source/cSpawnRegion.cpp index 0e9af162c..f90d18e62 100644 --- a/source/cSpawnRegion.cpp +++ b/source/cSpawnRegion.cpp @@ -6,6 +6,8 @@ #include "classes.h" #include "Dictionary.h" #include "StringUtility.hpp" +#include "utility/strutil.hpp" + #include #include #include @@ -505,7 +507,7 @@ void CSpawnRegion::LoadNPCList( const std::string &npcList ) { for( std::string npc = CharList->First(); !CharList->AtEnd(); npc = CharList->Next() ) { - if( oldstrutil::upper( npc ) == "NPCLIST" ) + if( util::upper( npc ) == "NPCLIST" ) { LoadNPCList( CharList->GrabData() ); } @@ -530,7 +532,7 @@ void CSpawnRegion::LoadItemList( const std::string &itemList ) { for( std::string itm = ItemList->First(); !ItemList->AtEnd(); itm = ItemList->Next() ) { - if( oldstrutil::upper( itm ) == "ITEMLIST" ) + if( util::upper( itm ) == "ITEMLIST" ) { LoadItemList( ItemList->GrabData() ); } @@ -557,7 +559,7 @@ void CSpawnRegion::Load( CScriptSection *toScan ) { if( !tag.empty() ) { - UTag = oldstrutil::upper( tag ); + UTag = util::upper( tag ); data = toScan->GrabData(); // Default to instanceId 0, in case nothing else is specified in DFN @@ -645,22 +647,22 @@ void CSpawnRegion::Load( CScriptSection *toScan ) } else if( UTag == "VALIDLANDPOS" ) { - data = oldstrutil::simplify( data ); + data = util::simplify( data ); auto csecs = oldstrutil::sections( data, "," ); if( csecs.size() == 3 ) { - validLandPos.push_back( Point3_st( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0)), static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//") ), nullptr, 0 )), static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 )))); - validLandPosCheck[ static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 )) + ( static_cast(std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 )) << 16 ) ] = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[2], "//" )), nullptr, 0 )); + validLandPos.push_back( Point3_st( static_cast( std::stoul( util::trim( util::strip( csecs[0], "//" )), nullptr, 0)), static_cast( std::stoul( util::trim( util::strip( csecs[1], "//") ), nullptr, 0 )), static_cast( std::stoul( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 )))); + validLandPosCheck[ static_cast( std::stoul( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 )) + ( static_cast(std::stoul( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 )) << 16 ) ] = static_cast( std::stoul( util::trim( util::strip( csecs[2], "//" )), nullptr, 0 )); } } else if( UTag == "VALIDWATERPOS" ) { - data = oldstrutil::simplify( data ); + data = util::simplify( data ); auto csecs = oldstrutil::sections( data, "," ); if( csecs.size() == 3 ) { - validWaterPos.push_back( Point3_st( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 )), static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 )), static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 )))); - validWaterPosCheck[ static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 )) + ( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 )) << 16 ) ] = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[2], "//" )), nullptr, 0 )); + validWaterPos.push_back( Point3_st( static_cast( std::stoul( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 )), static_cast( std::stoul( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 )), static_cast( std::stoul( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 )))); + validWaterPosCheck[ static_cast( std::stoul( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 )) + ( static_cast( std::stoul( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 )) << 16 ) ] = static_cast( std::stoul( util::trim( util::strip( csecs[2], "//" )), nullptr, 0 )); } } } @@ -741,12 +743,12 @@ auto CSpawnRegion::RegionSpawnChar() -> CChar * for( size_t i = 0; i < sNpcs.size(); i++ ) { // Split string for entry into a stringlist based on | as separator - auto csecs = oldstrutil::sections( oldstrutil::trim( oldstrutil::removeTrailing( sNpcs[i], "//" )), "|" ); + auto csecs = oldstrutil::sections( util::trim( util::strip( sNpcs[i], "//" )), "|" ); UI16 sectionWeight = 1; if( csecs.size() > 1 ) { - sectionWeight = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 )); + sectionWeight = static_cast( std::stoul( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 )); } auto npcSection = ( csecs.size() > 1 ? csecs[1] : csecs[0] ); @@ -757,8 +759,8 @@ auto CSpawnRegion::RegionSpawnChar() -> CChar * if( ourNPC.empty() ) return nullptr; - auto csecs = oldstrutil::sections( oldstrutil::trim( oldstrutil::removeTrailing( ourNPC, "//" )), "=" ); - if( oldstrutil::upper( csecs[0] ) == "NPCLIST" ) + auto csecs = oldstrutil::sections( util::trim( util::strip( ourNPC, "//" )), "=" ); + if( util::upper( csecs[0] ) == "NPCLIST" ) { // Chosen entry contained another NPCLIST! Let's dive back into it... ourNPC = Npcs->NpcListLookup( ourNPC ); @@ -778,7 +780,7 @@ auto CSpawnRegion::RegionSpawnChar() -> CChar * switch( tag ) { case DFNTAG_ID: - npcId = oldstrutil::value( cdata ); // static_cast( ndata ); + npcId = util::ston( cdata ); // static_cast( ndata ); goto foundNpcId; default: break; @@ -820,7 +822,7 @@ auto CSpawnRegion::RegionSpawnChar() -> CChar * } else { - Console.Warning( oldstrutil::format( "Unable to find valid location to spawn NPC in region %i", this->GetRegionNum() )); + Console.Warning( util::format( "Unable to find valid location to spawn NPC in region %i", this->GetRegionNum() )); } return nullptr; } diff --git a/source/cWeather.cpp b/source/cWeather.cpp index 5049a5b49..fba9002b7 100644 --- a/source/cWeather.cpp +++ b/source/cWeather.cpp @@ -11,7 +11,7 @@ #include "cScript.h" #include "CJSMapping.h" #include "combat.h" - +#include "utility/strutil.hpp" #define EFFECTIVE 2 const UI08 MAXVAL = 0; @@ -913,7 +913,7 @@ auto cWeatherAb::Load() -> bool { tag = sec->tag; data = sec->data; - UTag = oldstrutil::upper( tag ); + UTag = util::upper( tag ); switch( tag[0] ) { case 'c': @@ -979,8 +979,8 @@ auto cWeatherAb::Load() -> bool auto csecs = oldstrutil::sections( data, "," ); if( csecs.size() > 1 ) { - RainIntensityLow( static_cast( i ), static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 ))); - RainIntensityHigh( static_cast( i ), static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 ))); + RainIntensityLow( static_cast( i ), static_cast( std::stoi( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 ))); + RainIntensityHigh( static_cast( i ), static_cast( std::stoi( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 ))); } else { @@ -1004,8 +1004,8 @@ auto cWeatherAb::Load() -> bool auto csecs = oldstrutil::sections( data, "," ); if( csecs.size() > 1 ) { - SnowIntensityLow( static_cast( i ), static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 ))); - SnowIntensityHigh( static_cast( i ), static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 ))); + SnowIntensityLow( static_cast( i ), static_cast( std::stoi( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 ))); + SnowIntensityHigh( static_cast( i ), static_cast( std::stoi( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 ))); } else { @@ -1026,8 +1026,8 @@ auto cWeatherAb::Load() -> bool auto csecs = oldstrutil::sections( data, "," ); if( csecs.size() > 1 ) { - SnowIntensityLow( static_cast( i ), static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 ))); - SnowIntensityHigh( static_cast( i ), static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 ))); + SnowIntensityLow( static_cast( i ), static_cast( std::stoi( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 ))); + SnowIntensityHigh( static_cast( i ), static_cast( std::stoi( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 ))); } else { diff --git a/source/cmdtable.cpp b/source/cmdtable.cpp index 8943cde84..6f05c3e36 100644 --- a/source/cmdtable.cpp +++ b/source/cmdtable.cpp @@ -29,6 +29,7 @@ #include "ObjectFactory.h" #include "cRaces.h" #include "StringUtility.hpp" +#include "utility/strutil.hpp" #include "Dictionary.h" @@ -199,7 +200,7 @@ void Command_AddAccount( CSocket *s) if( Commands->NumArguments() > 2 ) { - newFlags = oldstrutil::value( Commands->CommandString( 4, 4 )); + newFlags = util::ston( Commands->CommandString( 4, 4 )); } if( newUsername == "" || newPassword == "" ) @@ -282,7 +283,7 @@ void Command_SetPost( CSocket *s ) return; PostTypes type = PT_LOCAL; - std::string upperCommand = oldstrutil::upper( Commands->CommandString( 2, 2 )); + std::string upperCommand = util::upper( Commands->CommandString( 2, 2 )); if( upperCommand == "GLOBAL" ) // user's next post appears in ALL bulletin boards { type = PT_GLOBAL; @@ -372,7 +373,7 @@ void Command_Tile( CSocket *s ) return; UI16 targId = 0; - if( oldstrutil::upper( Commands->CommandString( 2, 2 )) == "STATIC" ) + if( util::upper( Commands->CommandString( 2, 2 )) == "STATIC" ) { targId = static_cast( Commands->Argument( 2 )); } @@ -433,7 +434,7 @@ void Command_Tile( CSocket *s ) // tile static itemId s->ClickX( -1 ); s->ClickY( -1 ); - if( oldstrutil::upper( Commands->CommandString( 2, 2 )) != "STATIC" ) + if( util::upper( Commands->CommandString( 2, 2 )) != "STATIC" ) { s->TempInt2( static_cast( Commands->Argument( 2 ))); } @@ -640,7 +641,7 @@ void Command_Command( CSocket *s ) VALIDATESOCKET( s ); if( Commands->NumArguments() > 1 ) { - HandleGumpCommand( s, oldstrutil::upper( Commands->CommandString( 2, 2 )), oldstrutil::upper( Commands->CommandString( 3 ))); + HandleGumpCommand( s, util::upper( Commands->CommandString( 2, 2 )), util::upper( Commands->CommandString( 3 ))); } } @@ -689,7 +690,7 @@ void Command_MemStats( CSocket *s ) void Command_Restock( CSocket *s ) { VALIDATESOCKET( s ); - if( oldstrutil::upper( Commands->CommandString( 2, 2 )) == "ALL" ) + if( util::upper( Commands->CommandString( 2, 2 )) == "ALL" ) { Restock( true ); s->SysMessage( 55 ); // Restocking all shops to their maximums @@ -781,7 +782,7 @@ void Command_RegSpawn( CSocket *s ) UI32 itemsSpawned = 0; UI32 npcsSpawned = 0; - if( oldstrutil::upper( Commands->CommandString( 2, 2 )) == "ALL" ) + if( util::upper( Commands->CommandString( 2, 2 )) == "ALL" ) { std::for_each( cwmWorldState->spawnRegions.begin(), cwmWorldState->spawnRegions.end(), [&itemsSpawned, &npcsSpawned]( std::pair entry ) { @@ -845,7 +846,7 @@ void Command_CQ( CSocket *s ) VALIDATESOCKET( s ); if( Commands->NumArguments() == 2 ) { - std::string upperCommand = oldstrutil::upper( Commands->CommandString( 2, 2 )); + std::string upperCommand = util::upper( Commands->CommandString( 2, 2 )); if( upperCommand == "NEXT" ) // Go to next call in Counselor queue { NextCall( s, false ); @@ -904,7 +905,7 @@ void Command_GQ( CSocket *s ) VALIDATESOCKET( s ); if( Commands->NumArguments() == 2 ) { - std::string upperCommand = oldstrutil::upper( Commands->CommandString( 2, 2 )); + std::string upperCommand = util::upper( Commands->CommandString( 2, 2 )); if( upperCommand == "NEXT" ) // Go to next call in GM queue { NextCall( s, true ); @@ -947,12 +948,12 @@ void Command_MineCheck( void ) //o------------------------------------------------------------------------------------------------o void Command_Guards( void ) { - if( oldstrutil::upper( Commands->CommandString( 2, 2 )) == "ON" ) + if( util::upper( Commands->CommandString( 2, 2 )) == "ON" ) { cwmWorldState->ServerData()->GuardStatus( true ); SysBroadcast( Dictionary->GetEntry( 61 )); // Guards have been reactivated. } - else if( oldstrutil::upper( Commands->CommandString( 2, 2 )) == "OFF" ) + else if( util::upper( Commands->CommandString( 2, 2 )) == "OFF" ) { cwmWorldState->ServerData()->GuardStatus( false ); SysBroadcast( Dictionary->GetEntry( 62 )); // Warning: Guards have been deactivated globally. @@ -966,12 +967,12 @@ void Command_Guards( void ) //o------------------------------------------------------------------------------------------------o void Command_Announce( void ) { - if( oldstrutil::upper( Commands->CommandString( 2, 2 )) == "ON" ) + if( util::upper( Commands->CommandString( 2, 2 )) == "ON" ) { cwmWorldState->ServerData()->ServerAnnounceSaves( true ); SysBroadcast( Dictionary->GetEntry( 63 )); // WorldStat Saves will be displayed. } - else if( oldstrutil::upper( Commands->CommandString( 2, 2 )) == "OFF" ) + else if( util::upper( Commands->CommandString( 2, 2 )) == "OFF" ) { cwmWorldState->ServerData()->ServerAnnounceSaves( false ); SysBroadcast( Dictionary->GetEntry( 64 )); // WorldStat Saves will not be displayed. @@ -1064,7 +1065,7 @@ void BuildWhoGump( CSocket *s, UI08 commandLevel, std::string title ) CChar *iChar = iSock->CurrcharObj(); if( iChar->GetCommandLevel() >= commandLevel ) { - auto temp = oldstrutil::format( "%i) %s", j, iChar->GetName().c_str() ); + auto temp = util::format( "%i) %s", j, iChar->GetName().c_str() ); Who.AddData( temp, iChar->GetSerial(), 3 ); } ++j; @@ -1113,7 +1114,7 @@ void Command_ReportBug( CSocket *s ) logDestination.open( logName.c_str(), std::ios::out | std::ios::app ); if( !logDestination.is_open() ) { - Console.Error( oldstrutil::format( "Unable to open bugs log file %s!", logName.c_str() )); + Console.Error( util::format( "Unable to open bugs log file %s!", logName.c_str() )); return; } char dateTime[1024]; @@ -1208,7 +1209,7 @@ void Command_ValidCmd( CSocket *s ) void Command_HowTo( CSocket *s ) { VALIDATESOCKET( s ); - std::string commandStart = oldstrutil::upper( Commands->CommandString( 2 )); + std::string commandStart = util::upper( Commands->CommandString( 2 )); if( commandStart.empty() ) { CChar *mChar = s->CurrcharObj(); @@ -1225,11 +1226,11 @@ void Command_HowTo( CSocket *s ) toSend.UserId( INVALIDSERIAL ); toSend.GumpId( 13 ); - toSend.addCommand( oldstrutil::format( "resizepic 0 0 %u 480 320", cwmWorldState->ServerData()->BackgroundPic() )); + toSend.addCommand( util::format( "resizepic 0 0 %u 480 320", cwmWorldState->ServerData()->BackgroundPic() )); toSend.addCommand( "page 0" ); toSend.addCommand( "text 200 20 0 0" ); toSend.addText( "HOWTO" ); - toSend.addCommand( oldstrutil::format( "button 440 20 %u %i 1 0 1", cwmWorldState->ServerData()->ButtonCancel(), cwmWorldState->ServerData()->ButtonCancel() + 1 )); + toSend.addCommand( util::format( "button 440 20 %u %i 1 0 1", cwmWorldState->ServerData()->ButtonCancel(), cwmWorldState->ServerData()->ButtonCancel() + 1 )); UI08 currentLevel = mChar->GetCommandLevel(); COMMANDMAP_ITERATOR gAdd = CommandMap.begin(); @@ -1245,14 +1246,14 @@ void Command_HowTo( CSocket *s ) { position = 40; ++pagenum; - toSend.addCommand( oldstrutil::format( "page %u", pagenum )); + toSend.addCommand( util::format( "page %u", pagenum )); justDonePageAdd = true; } if( gAdd->second.cmdLevelReq <= currentLevel ) { justDonePageAdd = false; - toSend.addCommand( oldstrutil::format( "text 50 %u %u %u", position, cwmWorldState->ServerData()->LeftTextColour(), linenum )); - toSend.addCommand( oldstrutil::format("button 20 %u %u %i %u 0 %i", position, cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1, pagenum, iCmd )); + toSend.addCommand( util::format( "text 50 %u %u %u", position, cwmWorldState->ServerData()->LeftTextColour(), linenum )); + toSend.addCommand( util::format("button 20 %u %u %i %u 0 %i", position, cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1, pagenum, iCmd )); toSend.addText( gAdd->first ); ++numAdded; ++linenum; @@ -1267,14 +1268,14 @@ void Command_HowTo( CSocket *s ) { position = 40; ++pagenum; - toSend.addCommand( oldstrutil::format( "page %u", pagenum )); + toSend.addCommand( util::format( "page %u", pagenum )); justDonePageAdd = true; } if( tAdd->second.cmdLevelReq <= currentLevel ) { justDonePageAdd = false; - toSend.addCommand( oldstrutil::format( "text 50 %u %u %u", position, cwmWorldState->ServerData()->LeftTextColour(), linenum )); - toSend.addCommand( oldstrutil::format( "button 20 %u %u %i %u 0 %i", position, cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1, pagenum, iCmd )); + toSend.addCommand( util::format( "text 50 %u %u %u", position, cwmWorldState->ServerData()->LeftTextColour(), linenum )); + toSend.addCommand( util::format( "button 20 %u %u %i %u 0 %i", position, cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1, pagenum, iCmd )); toSend.addText( tAdd->first ); ++numAdded; ++linenum; @@ -1289,14 +1290,14 @@ void Command_HowTo( CSocket *s ) { position = 40; ++pagenum; - toSend.addCommand( oldstrutil::format( "page %u", pagenum )); + toSend.addCommand( util::format( "page %u", pagenum )); justDonePageAdd = true; } if( jAdd->second.cmdLevelReq <= currentLevel ) { justDonePageAdd = false; - toSend.addCommand( oldstrutil::format( "text 50 %u %u %u", position, cwmWorldState->ServerData()->LeftTextColour(), linenum )); - toSend.addCommand( oldstrutil::format( "button 20 %u %u %i %u 0 %i", position, cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1, pagenum, iCmd )); + toSend.addCommand( util::format( "text 50 %u %u %u", position, cwmWorldState->ServerData()->LeftTextColour(), linenum )); + toSend.addCommand( util::format( "button 20 %u %u %i %u 0 %i", position, cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1, pagenum, iCmd )); toSend.addText( jAdd->first ); ++numAdded; ++linenum; @@ -1308,14 +1309,14 @@ void Command_HowTo( CSocket *s ) pagenum = 1; for( SI32 i = 0; i < numAdded; i += 10 ) { - toSend.addCommand( oldstrutil::format( "page %u", pagenum )); + toSend.addCommand( util::format( "page %u", pagenum )); if( i >= 10 ) { - toSend.addCommand( oldstrutil::format( "button 30 290 %u %i 0 %i", cwmWorldState->ServerData()->ButtonLeft(), cwmWorldState->ServerData()->ButtonLeft() + 1, pagenum - 1 )); //back button + toSend.addCommand( util::format( "button 30 290 %u %i 0 %i", cwmWorldState->ServerData()->ButtonLeft(), cwmWorldState->ServerData()->ButtonLeft() + 1, pagenum - 1 )); //back button } if(( numAdded > 10 ) && (( i + 10 ) < numAdded )) { - toSend.addCommand( oldstrutil::format("button 440 290 %u %i 0 %i", cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1, pagenum + 1 )); + toSend.addCommand( util::format("button 440 290 %u %i 0 %i", cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1, pagenum + 1 )); } ++pagenum; } @@ -1511,10 +1512,10 @@ void CCommands::CommandReset() void CCommands::UnRegister( const std::string &cmdName, [[maybe_unused]] cScript *toRegister ) { #if defined( UOX_DEBUG_MODE ) - Console.Print( oldstrutil::format( " UnRegistering command %s\n", cmdName.c_str() )); + Console.Print( util::format( " UnRegistering command %s\n", cmdName.c_str() )); #endif std::string upper = cmdName; - upper = oldstrutil::upper( upper ); + upper = util::upper( upper ); JSCOMMANDMAP_ITERATOR p = JSCommandMap.find( upper ); if( p != JSCommandMap.end() ) { @@ -1523,7 +1524,7 @@ void CCommands::UnRegister( const std::string &cmdName, [[maybe_unused]] cScript #if defined( UOX_DEBUG_MODE ) else { - Console.Print( oldstrutil::format( " Command \"%s\" was not found.\n", cmdName.c_str() )); + Console.Print( util::format( " Command \"%s\" was not found.\n", cmdName.c_str() )); } #endif } @@ -1545,11 +1546,11 @@ void CCommands::Register( const std::string &cmdName, UI16 scriptId, UI08 cmdLev Console.MoveTo( 50 ); Console.Print( "@ command level " ); Console.TurnYellow(); - Console.Print( oldstrutil::format( "%i\n", cmdLevel )); + Console.Print( util::format( "%i\n", cmdLevel )); Console.TurnNormal(); #endif std::string upper = cmdName; - upper = oldstrutil::upper( upper ); + upper = util::upper( upper ); JSCommandMap[upper] = JSCommandEntry_st( cmdLevel, scriptId, isEnabled ); } @@ -1561,7 +1562,7 @@ void CCommands::Register( const std::string &cmdName, UI16 scriptId, UI08 cmdLev void CCommands::SetCommandStatus( const std::string &cmdName, bool isEnabled ) { std::string upper = cmdName; - upper = oldstrutil::upper( upper ); + upper = util::upper( upper ); JSCOMMANDMAP_ITERATOR toFind = JSCommandMap.find( upper ); if( toFind != JSCommandMap.end() ) { diff --git a/source/commands.cpp b/source/commands.cpp index 74705c05b..6d6466bbd 100644 --- a/source/commands.cpp +++ b/source/commands.cpp @@ -6,6 +6,7 @@ #include "cScript.h" #include "CPacketSend.h" #include "StringUtility.hpp" +#include "utility/strutil.hpp" CCommands *Commands = nullptr; @@ -57,7 +58,7 @@ SI32 CCommands::Argument( UI08 argNum ) } catch( const std::invalid_argument & e ) { - Console.Error( oldstrutil::format( "[%s] Unable to convert command argument ('%s') to integer.", e.what(), tempString.c_str() )); + Console.Error( util::format( "[%s] Unable to convert command argument ('%s') to integer.", e.what(), tempString.c_str() )); } } @@ -99,12 +100,12 @@ void CCommands::CommandString( std::string newValue ) //o------------------------------------------------------------------------------------------------o void CCommands::Command( CSocket *s, CChar *mChar, std::string text, bool checkSocketAccess ) { - CommandString( oldstrutil::simplify( text )); + CommandString( util::simplify( text )); if( NumArguments() < 1 ) return; // Discard the leading command prefix - std::string command = oldstrutil::upper( CommandString( 1, 1 )); + std::string command = util::upper( CommandString( 1, 1 )); JSCOMMANDMAP_ITERATOR toFind = JSCommandMap.find( command ); if( toFind != JSCommandMap.end() ) @@ -138,7 +139,7 @@ void CCommands::Command( CSocket *s, CChar *mChar, std::string text, bool checkS if( toExecute != nullptr ) { // All commands that execute are of the form: command_commandname (to avoid possible clashes) #if defined( UOX_DEBUG_MODE ) - Console.Print( oldstrutil::format( "Executing JS command %s\n", command.c_str() )); + Console.Print( util::format( "Executing JS command %s\n", command.c_str() )); #endif toExecute->executeCommand( s, "command_" + command, CommandString( 2 )); } @@ -393,7 +394,7 @@ void CCommands::Load( void ) { tag = sec->tag; data = sec->data; - UTag = oldstrutil::upper( tag ); + UTag = util::upper( tag ); if( UTag == "NICKCOLOUR" ) { ourClear->nickColour = static_cast( std::stoul( data, nullptr, 0 )); @@ -459,7 +460,7 @@ void CCommands::Log( const std::string &command, CChar *player1, CChar *player2, logDestination.open( logName.c_str(), std::ios::out | std::ios::app ); if( !logDestination.is_open() ) { - Console.Error( oldstrutil::format( "Unable to open command log file %s!", logName.c_str() )); + Console.Error( util::format( "Unable to open command log file %s!", logName.c_str() )); return; } char dateTime[1024]; @@ -492,7 +493,7 @@ CommandLevel_st *CCommands::GetClearance( std::string clearName ) for( clearIter = clearance.begin(); clearIter != clearance.end(); ++clearIter ) { clearPointer = ( *clearIter ); - if( oldstrutil::upper( clearName ) == clearPointer->name ) + if( util::upper( clearName ) == clearPointer->name ) { return clearPointer; } diff --git a/source/effect.cpp b/source/effect.cpp index 7a3e23c1c..82bd2beec 100644 --- a/source/effect.cpp +++ b/source/effect.cpp @@ -14,6 +14,8 @@ #include "CJSMapping.h" #include "townregion.h" #include "StringUtility.hpp" +#include "utility/strutil.hpp" + #include //o------------------------------------------------------------------------------------------------o @@ -523,7 +525,7 @@ void cEffects::HandleMakeItemEffect( CTEffect *tMake ) auto csecs = oldstrutil::sections( addItem, "," ); if( csecs.size() > 1 ) { - amount = oldstrutil::value( oldstrutil::extractSection( addItem, ",", 1, 1 )); + amount = util::ston( oldstrutil::extractSection( addItem, ",", 1, 1 )); addItem = oldstrutil::extractSection( addItem, ",", 0, 0 ); } @@ -546,7 +548,7 @@ void cEffects::HandleMakeItemEffect( CTEffect *tMake ) } if( targItem == nullptr ) { - Console.Error( oldstrutil::format( "CSkills::MakeItem() bad script item # %s, made by player 0x%X", addItem.c_str(), src->GetSerial() )); + Console.Error( util::format( "CSkills::MakeItem() bad script item # %s, made by player 0x%X", addItem.c_str(), src->GetSerial() )); return; } else @@ -769,7 +771,7 @@ auto cEffects::CheckTempeffects() -> void if( src->GetTimer( tCHAR_ANTISPAM ) < cwmWorldState->GetUICurrentTime() ) { src->SetTimer( tCHAR_ANTISPAM, BuildTimeValue( 1 )); - std::string mTemp = oldstrutil::number( Effect->More3() ); + std::string mTemp = util::ntos( Effect->More3() ); if( tSock ) { tSock->SysMessage( mTemp.c_str() ); @@ -1081,7 +1083,7 @@ auto cEffects::CheckTempeffects() -> void break; } default: - Console.Error( oldstrutil::format( " Fallout of switch statement without default (%i). checktempeffects()", Effect->Number() )); + Console.Error( util::format( " Fallout of switch statement without default (%i). checktempeffects()", Effect->Number() )); break; } if( validChar && equipCheckNeeded ) @@ -1683,7 +1685,7 @@ void cEffects::TempEffect( CChar *source, CChar *dest, UI08 num, UI16 more1, UI1 toAdd->ExpireTime( BuildTimeValue( static_cast( more1 ))); break; default: - Console.Error( oldstrutil::format( " Fallout of switch statement (%d) without default. uox3.cpp, tempeffect()", num )); + Console.Error( util::format( " Fallout of switch statement (%d) without default. uox3.cpp, tempeffect()", num )); delete toAdd; return; } @@ -1776,7 +1778,7 @@ void cEffects::SaveEffects( void ) effectDestination.open( filename.c_str() ); if( !effectDestination ) { - Console.Error( oldstrutil::format( "Failed to open %s for writing", filename.c_str() )); + Console.Error( util::format( "Failed to open %s for writing", filename.c_str() )); return; } @@ -1794,7 +1796,7 @@ void cEffects::SaveEffects( void ) Console.PrintDone(); SI32 e_t = GetClock(); - Console.Print( oldstrutil::format("Effects saved in %.02fsec\n", ( static_cast( e_t-s_t )) / 1000.0f )); + Console.Print( util::format("Effects saved in %.02fsec\n", ( static_cast( e_t-s_t )) / 1000.0f )); } void ReadWorldTagData( std::istream &inStream, std::string &tag, std::string &data ); @@ -1826,8 +1828,8 @@ void cEffects::LoadEffects( void ) input.getline(line, 1023); line[input.gcount()] = 0; std::string sLine( line ); - sLine = oldstrutil::trim( oldstrutil::removeTrailing( sLine, "//" )); - auto usLine = oldstrutil::upper( sLine ); + sLine = util::trim( util::strip( sLine, "//" )); + auto usLine = util::upper( sLine ); if( !sLine.empty() ) { @@ -1839,35 +1841,35 @@ void cEffects::LoadEffects( void ) ReadWorldTagData( input, tag, data ); if( tag != "o---o" ) { - UTag = oldstrutil::upper( tag ); + UTag = util::upper( tag ); switch(( UTag.data()[0] )) { case 'A': if( UTag == "ASSOCSCRIPT" ) { - toLoad->AssocScript( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + toLoad->AssocScript( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); } break; case 'D': if( UTag == "DEST" ) { - toLoad->Destination( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + toLoad->Destination( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); } if( UTag == "DISPEL" ) { - toLoad->Dispellable((( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )) == 0 ) ? false : true )); + toLoad->Dispellable((( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 )) == 0 ) ? false : true )); } break; case 'E': if( UTag == "EXPIRE" ) { - toLoad->ExpireTime( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )) + cwmWorldState->GetUICurrentTime() ); + toLoad->ExpireTime( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 )) + cwmWorldState->GetUICurrentTime() ); } break; case 'I': if( UTag == "ITEMPTR" ) { - SERIAL objSer = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )); + SERIAL objSer = static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 )); if( objSer != INVALIDSERIAL ) { if( objSer < BASEITEMSERIAL ) @@ -1888,27 +1890,27 @@ void cEffects::LoadEffects( void ) case 'M': if( UTag == "MORE1" ) { - toLoad->More1( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + toLoad->More1( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); } if( UTag == "MORE2" ) { - toLoad->More2( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + toLoad->More2( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); } if( UTag == "MORE3" ) { - toLoad->More3( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + toLoad->More3( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); } break; case 'N': if( UTag == "NUMBER" ) { - toLoad->Number( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + toLoad->Number( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); } break; case 'O': if( UTag == "OBJPTR" ) { - SERIAL objSer = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )); + SERIAL objSer = static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 )); if( objSer != INVALIDSERIAL ) { if( objSer < BASEITEMSERIAL ) @@ -1929,11 +1931,11 @@ void cEffects::LoadEffects( void ) case 'S': if( UTag == "SOURCE" ) { - toLoad->Source( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + toLoad->Source( static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); } break; default: - Console.Error( oldstrutil::format( "Unknown effects tag %s with contents of %s", tag.c_str(), data.c_str() )); + Console.Error( util::format( "Unknown effects tag %s with contents of %s", tag.c_str(), data.c_str() )); break; } } diff --git a/source/fileio.cpp b/source/fileio.cpp index 7aee52755..5905782f2 100644 --- a/source/fileio.cpp +++ b/source/fileio.cpp @@ -4,6 +4,9 @@ #include "cSpawnRegion.h" #include "scriptc.h" #include "townregion.h" + +#include "utility/strutil.hpp" + #include #include #include @@ -107,19 +110,19 @@ void LoadSkills( void ) skEntry = creatScp->EntryName(); auto ssecs = oldstrutil::sections( skEntry, " " ); - if( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[0], "// ")) == "SKILL" ) + if( util::trim( util::strip( ssecs[0], "// ")) == "SKILL" ) { if( ssecs.size() > 1 ) { - i = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[1], "//" )))); + i = static_cast( std::stoul( util::trim( util::strip( ssecs[1], "//" )))); if( i <= INTELLECT ) { cwmWorldState->skill[i].ResetDefaults(); for( tag = SkillList->First(); !SkillList->AtEnd(); tag = SkillList->Next() ) { - UTag = oldstrutil::upper( tag ); + UTag = util::upper( tag ); data = SkillList->GrabData(); - data = oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )); + data = util::trim( util::strip( data, "//" )); if( UTag == "STR" ) { cwmWorldState->skill[i].strength = static_cast( std::stoul( data, nullptr, 0 )); @@ -135,14 +138,14 @@ void LoadSkills( void ) else if( UTag == "SKILLPOINT" ) { Advance_st tempAdvance; - data = oldstrutil::simplify( data ); + data = util::simplify( data ); auto csecs = oldstrutil::sections( data, "," ); - tempAdvance.base = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 )); - tempAdvance.success = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 )); - tempAdvance.failure = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[2], "//" )), nullptr, 0 )); + tempAdvance.base = static_cast( std::stoul( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 )); + tempAdvance.success = static_cast( std::stoul( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 )); + tempAdvance.failure = static_cast( std::stoul( util::trim( util::strip( csecs[2], "//" )), nullptr, 0 )); if( csecs.size() == 4 ) { - tempAdvance.amtToGain = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[3], "//" )), nullptr, 0 )); + tempAdvance.amtToGain = static_cast( std::stoul( util::trim( util::strip( csecs[3], "//" )), nullptr, 0 )); } cwmWorldState->skill[i].advancement.push_back( tempAdvance ); } @@ -160,7 +163,7 @@ void LoadSkills( void ) } else { - Console.Warning( oldstrutil::format( "Unknown tag in skills.dfn: %s", data.c_str() )); + Console.Warning( util::format( "Unknown tag in skills.dfn: %s", data.c_str() )); } } } @@ -193,7 +196,7 @@ void LoadSpawnRegions( void ) auto ssecs = oldstrutil::sections( sectionName, " " ); if( "REGIONSPAWN" == ssecs[0] ) // Is it a region spawn entry? { - i = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[1], "//" )), nullptr, 0 )); + i = static_cast( std::stoul( util::trim( util::strip( ssecs[1], "//" )), nullptr, 0 )); if( cwmWorldState->spawnRegions.find( i ) == cwmWorldState->spawnRegions.end() ) { cwmWorldState->spawnRegions[i] = new CSpawnRegion( i ); @@ -201,7 +204,7 @@ void LoadSpawnRegions( void ) } else { - Console.Warning( oldstrutil::format( "spawn.dfn has a duplicate REGIONSPAWN entry, Entry Number: %u", i )); + Console.Warning( util::format( "spawn.dfn has a duplicate REGIONSPAWN entry, Entry Number: %u", i )); } } } @@ -239,9 +242,9 @@ void LoadRegions( void ) regEntry = regScp->EntryName(); auto ssecs = oldstrutil::sections( regEntry, " " ); - if( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[0], "//" )) == "REGION" ) + if( util::trim( util::strip( ssecs[0], "//" )) == "REGION" ) { - i = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[1], "//" )), nullptr, 0 )); + i = static_cast( std::stoul( util::trim( util::strip( ssecs[1], "//" )), nullptr, 0 )); if( cwmWorldState->townRegions.find( i ) == cwmWorldState->townRegions.end() ) { cwmWorldState->townRegions[i] = new CTownRegion( i ); @@ -253,7 +256,7 @@ void LoadRegions( void ) } else { - Console.Warning( oldstrutil::format( "regions.dfn has a duplicate REGION entry, Entry Number: %u", i )); + Console.Warning( util::format( "regions.dfn has a duplicate REGION entry, Entry Number: %u", i )); } } } @@ -281,9 +284,9 @@ void LoadRegions( void ) std::string data, UTag; for( std::string tag = InstaLog->First(); !InstaLog->AtEnd(); tag = InstaLog->Next() ) { - UTag = oldstrutil::upper( tag ); + UTag = util::upper( tag ); data = InstaLog->GrabData(); - data = oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )); + data = util::trim( util::strip( data, "//" )); if( UTag == "X1" ) { toAdd.x1 = static_cast( std::stoi( data, nullptr, 0 )); @@ -320,9 +323,9 @@ void LoadRegions( void ) SOSLocationEntry_st toAddSOS; for( std::string tag = sosAreas->First(); !sosAreas->AtEnd(); tag = sosAreas->Next() ) { - UTag = oldstrutil::upper( tag ); + UTag = util::upper( tag ); data = sosAreas->GrabData(); - data = oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )); + data = util::trim( util::strip( data, "//" )); if( UTag == "X1" ) { toAddSOS.x1 = static_cast( std::stoi( data, nullptr, 0 )); @@ -364,8 +367,8 @@ void LoadTeleportLocations( void ) if( !FileExists( filename )) { Console << myendl; - Console.Error( oldstrutil::format( " Failed to open teleport data script %s", filename.c_str() )); - Console.Error( oldstrutil::format( " Teleport Data not found" )); + Console.Error( util::format( " Failed to open teleport data script %s", filename.c_str() )); + Console.Error( util::format( " Teleport Data not found" )); cwmWorldState->SetKeepRun( false ); cwmWorldState->SetError( true ); return; @@ -387,36 +390,36 @@ void LoadTeleportLocations( void ) for( tag = teleportSect->First(); !teleportSect->AtEnd(); tag = teleportSect->Next() ) { CTeleLocationEntry toAdd; - if( oldstrutil::upper( tag ) == "ENTRY" ) + if( util::upper( tag ) == "ENTRY" ) { tempX = 0; tempY = 0; tempZ = ILLEGAL_Z; - data = oldstrutil::simplify( teleportSect->GrabData() ); + data = util::simplify( teleportSect->GrabData() ); auto csecs = oldstrutil::sections( data, "," ); SI32 sectCount = static_cast( csecs.size() ); if( sectCount >= 6 ) { - tempX = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 )); - tempY = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 )); - temp = oldstrutil::upper( oldstrutil::trim( oldstrutil::removeTrailing( csecs[2], "//" ))); + tempX = static_cast( std::stoul( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 )); + tempY = static_cast( std::stoul( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 )); + temp = util::upper( util::trim( util::strip( csecs[2], "//" ))); if( temp != "ALL" && temp != "A" ) { tempZ = static_cast( std::stoul( temp, nullptr, 0 )); } toAdd.SourceLocation( tempX, tempY, tempZ ); - tempX = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[3], "//" )), nullptr, 0 )); - tempY = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[4], "//" )), nullptr, 0 )); - tempZ = static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[5], "//" )), nullptr, 0 )); + tempX = static_cast( std::stoul( util::trim( util::strip( csecs[3], "//" )), nullptr, 0 )); + tempY = static_cast( std::stoul( util::trim( util::strip( csecs[4], "//" )), nullptr, 0 )); + tempZ = static_cast( std::stoi( util::trim( util::strip( csecs[5], "//" )), nullptr, 0 )); toAdd.TargetLocation( tempX, tempY, tempZ ); if( sectCount >= 7 ) { - toAdd.SourceWorld( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[6], "//" )), nullptr, 0 ))); + toAdd.SourceWorld( static_cast( std::stoul( util::trim( util::strip( csecs[6], "//" )), nullptr, 0 ))); if( sectCount >= 8 ) { - toAdd.TargetWorld( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[7], "//" )), nullptr, 0 ))); + toAdd.TargetWorld( static_cast( std::stoul( util::trim( util::strip( csecs[7], "//" )), nullptr, 0 ))); } } cwmWorldState->teleLocs.push_back( toAdd ); @@ -461,7 +464,7 @@ void LoadCreatures( void ) auto ssecs = oldstrutil::sections( cEntry, " " ); if( ssecs[0] == "CREATURE" ) { - i = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[1], "//" )), nullptr, 0 )); + i = static_cast( std::stoul( util::trim( util::strip( ssecs[1], "//" )), nullptr, 0 )); cwmWorldState->creatures[i].CreatureId( i ); for( tag = creatureData->First(); !creatureData->AtEnd(); tag = creatureData->Next() ) @@ -471,8 +474,8 @@ void LoadCreatures( void ) continue; } data = creatureData->GrabData(); - data = oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )); - UTag = oldstrutil::upper( tag ); + data = util::trim( util::strip( data, "//" )); + UTag = util::upper( tag ); switch(( UTag.data()[0] )) { case 'A': @@ -492,12 +495,12 @@ void LoadCreatures( void ) auto csecs = oldstrutil::sections( data, "," ); if( csecs.size() > 1 ) { - animId = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 )); - animLength = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 )); + animId = static_cast( std::stoul( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 )); + animLength = static_cast( std::stoul( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 )); } else { - animId = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 )); + animId = static_cast( std::stoul( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 )); animLength = 7; // default to 7 frames if nothing is specified } @@ -555,11 +558,11 @@ void LoadCreatures( void ) case 'M': if( UTag == "MOVEMENT" ) { - if( oldstrutil::upper( data ) == "WATER" ) + if( util::upper( data ) == "WATER" ) { cwmWorldState->creatures[i].IsWater( true ); } - else if( oldstrutil::upper( data ) == "BOTH" ) + else if( util::upper( data ) == "BOTH" ) { cwmWorldState->creatures[i].IsAmphibian( true ); } @@ -701,13 +704,13 @@ void LoadPlaces( void ) entryName = locScp->EntryName(); auto ssecs = oldstrutil::sections( entryName, " " ); - size_t entryNum = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[1], "//" )), nullptr, 0 )); + size_t entryNum = static_cast( std::stoul( util::trim( util::strip( ssecs[1], "//" )), nullptr, 0 )); - if(( oldstrutil::upper( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[0], "//" ))) == "LOCATION" ) && entryNum ) + if(( util::upper( util::trim( util::strip( ssecs[0], "//" ))) == "LOCATION" ) && entryNum ) { if( cwmWorldState->goPlaces.find( static_cast( entryNum )) != cwmWorldState->goPlaces.end() ) { - Console.Warning( oldstrutil::format( "Doubled up entry in Location.dfn (%u)", entryNum )); + Console.Warning( util::format( "Doubled up entry in Location.dfn (%u)", entryNum )); } toAdd = &cwmWorldState->goPlaces[static_cast( entryNum )]; if( toAdd != nullptr ) @@ -715,8 +718,8 @@ void LoadPlaces( void ) for( std::string tag = toScan->First(); !toScan->AtEnd(); tag = toScan->Next() ) { data = toScan->GrabData(); - data = oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )); - UTag = oldstrutil::upper( tag ); + data = util::trim( util::strip( data, "//" )); + UTag = util::upper( tag ); if( UTag == "X" ) { toAdd->x = static_cast( std::stoi( data, nullptr, 0 )); @@ -743,15 +746,15 @@ void LoadPlaces( void ) size_t sectionCount = csecs.size() + 1; if( sectionCount >= 3 ) { - toAdd->x = static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 )); - toAdd->y = static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 )); - toAdd->z = static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( csecs[2], "//" )), nullptr, 0 )); - toAdd->worldNum = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[3], "//" )), nullptr, 0 )); + toAdd->x = static_cast( std::stoi( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 )); + toAdd->y = static_cast( std::stoi( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 )); + toAdd->z = static_cast( std::stoi( util::trim( util::strip( csecs[2], "//" )), nullptr, 0 )); + toAdd->worldNum = static_cast( std::stoul( util::trim( util::strip( csecs[3], "//" )), nullptr, 0 )); } if( sectionCount == 4 ) { - toAdd->instanceId = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[4], "//" )), nullptr, 0 )); + toAdd->instanceId = static_cast( std::stoul( util::trim( util::strip( csecs[4], "//" )), nullptr, 0 )); } } } diff --git a/source/funcdecl.h b/source/funcdecl.h index 929ce8f38..15f66e15a 100644 --- a/source/funcdecl.h +++ b/source/funcdecl.h @@ -16,6 +16,7 @@ #include #include "uoxstruct.h" #include "StringUtility.hpp" +#include "utility/strutil.hpp" #include #include #include @@ -251,7 +252,7 @@ inline bool ValidateObject( const CBaseObject *toValidate ) catch( ... ) { rValue = false; - Console.Error( oldstrutil::format( "Invalid Object found: 0x%X", (UI64)toValidate )); + Console.Error( util::format( "Invalid Object found: 0x%X", (UI64)toValidate )); } return rValue; } diff --git a/source/gumps.cpp b/source/gumps.cpp index 52d58771b..dafa7063b 100644 --- a/source/gumps.cpp +++ b/source/gumps.cpp @@ -19,6 +19,8 @@ #include "PageVector.h" #include "ObjectFactory.h" #include "StringUtility.hpp" +#include "utility/strutil.hpp" + #include #include "osunique.hpp" @@ -44,7 +46,7 @@ void TextEntryGump( CSocket *s, SERIAL ser, UI08 type, UI08 index, SI16 maxlengt return; } - auto temp = oldstrutil::format( "(%i chars max)", maxlength ); + auto temp = util::format( "(%i chars max)", maxlength ); CPGumpTextEntry toSend( txt, temp ); toSend.Serial( ser ); toSend.ParentId( type ); @@ -65,31 +67,31 @@ void BuildGumpFromScripts( CSocket *s, UI16 m ) CPSendGumpMenu toSend; toSend.UserId( INVALIDSERIAL ); - std::string sect = std::string( "GUMPMENU " ) + oldstrutil::number( m ); + std::string sect = std::string( "GUMPMENU " ) + util::ntos( m ); CScriptSection *gump = FileLookup->FindEntry( sect, misc_def ); if( gump == nullptr ) return; UI08 targType = 0x12; std::string tag = gump->First(); - if( oldstrutil::upper( oldstrutil::extractSection( tag, " ", 0, 0 )) == "TYPE" ) + if( util::upper( oldstrutil::extractSection( tag, " ", 0, 0 )) == "TYPE" ) { - targType = oldstrutil::value( oldstrutil::extractSection( tag, " ", 1, 1 )); + targType = util::ston( oldstrutil::extractSection( tag, " ", 1, 1 )); tag = gump->Next(); } for(; !gump->AtEnd(); tag = gump->Next() ) { - auto temp = oldstrutil::format( "%s %s", tag.c_str(), gump->GrabData().c_str() ); + auto temp = util::format( "%s %s", tag.c_str(), gump->GrabData().c_str() ); toSend.addCommand( temp ); } - sect = std::string( "GUMPTEXT " ) + oldstrutil::number( m ); + sect = std::string( "GUMPTEXT " ) + util::ntos( m ); gump = FileLookup->FindEntry( sect, misc_def ); if( gump == nullptr ) return; for( tag = gump->First(); !gump->AtEnd(); tag = gump->Next() ) { - toSend.addText( oldstrutil::format( "%s %s", tag.c_str(), gump->GrabData().c_str() )); + toSend.addText( util::format( "%s %s", tag.c_str(), gump->GrabData().c_str() )); } toSend.GumpId( targType ); toSend.Finalize(); @@ -325,7 +327,7 @@ void HandleAccountModButton( CPIGumpMenuSelect *packet ) case 1001: password = packet->GetTextString( i ); break; case 1002: emailAddy = packet->GetTextString( i ); break; default: - Console.Warning( oldstrutil::format( "Unknown textId %i with string %s", textId, packet->GetTextString( i ).c_str() )); + Console.Warning( util::format( "Unknown textId %i with string %s", textId, packet->GetTextString( i ).c_str() )); } } @@ -335,7 +337,7 @@ void HandleAccountModButton( CPIGumpMenuSelect *packet ) s->SysMessage( 555 ); // An account by that name already exists! return; } - Console.Print( oldstrutil::format( "Attempting to add username %s with password %s at emailaddy %s", username.c_str(), password.c_str(), emailAddy.c_str() )); + Console.Print( util::format( "Attempting to add username %s with password %s at emailaddy %s", username.c_str(), password.c_str(), emailAddy.c_str() )); } //o------------------------------------------------------------------------------------------------o @@ -371,7 +373,7 @@ void BuildAddMenuGump( CSocket *s, UI16 m ) //////////////////////////////////////////////// s->TempInt( m ); // Store what menu they are in - std::string sect = std::string( "ITEMMENU " ) + oldstrutil::number( m ); + std::string sect = std::string( "ITEMMENU " ) + util::ntos( m ); CScriptSection *ItemMenu = FileLookup->FindEntry( sect, items_def ); if( ItemMenu == nullptr ) return; @@ -387,33 +389,33 @@ void BuildAddMenuGump( CSocket *s, UI16 m ) UI32 bgImage = cwmWorldState->ServerData()->BackgroundPic(); // Set and resize the gumps background image. - toSend.addCommand( oldstrutil::format( "resizepic %u %u %u %u %u", xStart, yStart, bgImage, xWidth, yWidth )); - toSend.addCommand( oldstrutil::format( "checkertrans %u %u %u %u", xStart + 5, yStart + 5, xWidth - 10, yWidth - 11 )); + toSend.addCommand( util::format( "resizepic %u %u %u %u %u", xStart, yStart, bgImage, xWidth, yWidth )); + toSend.addCommand( util::format( "checkertrans %u %u %u %u", xStart + 5, yStart + 5, xWidth - 10, yWidth - 11 )); // Grab the first tag/value pair from the gump itemmenu respectivly std::string tag = ItemMenu->First(); std::string data = ItemMenu->GrabData(); - toSend.addCommand( oldstrutil::format( "resizepic %u %u %u %u %u", 2, 4, 0xDAC, 675, 40 )); + toSend.addCommand( util::format( "resizepic %u %u %u %u %u", 2, 4, 0xDAC, 675, 40 )); // Create the text stuff for what appears to be the title of the gump. This appears to change from page to page. // Next we create and position the close window button as well set its Down, and Up states. - toSend.addCommand( oldstrutil::format( "button %u %u %u %u %u %u %u", xWidth - 32, yStart + 10, 0xA51, 0xA50, 1, 0, 1 )); + toSend.addCommand( util::format( "button %u %u %u %u %u %u %u", xWidth - 32, yStart + 10, 0xA51, 0xA50, 1, 0, 1 )); linenum = 0; - toSend.addCommand( oldstrutil::format( "text %u %u %u %u", 30, yStart + 13, 39, linenum++ )); + toSend.addCommand( util::format( "text %u %u %u %u", 30, yStart + 13, 39, linenum++ )); toSend.addText( "Players: " ); // Player count - auto szBuffer = oldstrutil::format( "%4i ", cwmWorldState->GetPlayersOnline() ); - toSend.addCommand( oldstrutil::format( "text %u %u %u %u", 80, yStart + 13, 25, linenum++ )); + auto szBuffer = util::format( "%4i ", cwmWorldState->GetPlayersOnline() ); + toSend.addCommand( util::format( "text %u %u %u %u", 80, yStart + 13, 25, linenum++ )); toSend.addText( szBuffer ); // Gm Pages - toSend.addCommand( oldstrutil::format( "text %u %u %u %u", 118, yStart + 13, 39, linenum++ )); + toSend.addCommand( util::format( "text %u %u %u %u", 118, yStart + 13, 39, linenum++ )); toSend.addText( "GM Pages: " ); szBuffer = "0"; - toSend.addCommand( oldstrutil::format( "text %u %u %u %u", 200, yStart + 13, 25, linenum++ )); + toSend.addCommand( util::format( "text %u %u %u %u", 200, yStart + 13, 25, linenum++ )); toSend.addText( szBuffer ); // Current Time/Date - toSend.addCommand( oldstrutil::format( "text %u %u %u %u", 230, yStart + 13, 39, linenum++ )); + toSend.addCommand( util::format( "text %u %u %u %u", 230, yStart + 13, 39, linenum++ )); toSend.addText( "Time: " ); // Current server time auto timet = std::chrono::system_clock::to_time_t( std::chrono::system_clock::now() ); @@ -434,30 +436,30 @@ void BuildAddMenuGump( CSocket *s, UI16 m ) } // Draw the current date to the gump char tbuffer[100]; - szBuffer = oldstrutil::format( "%s %.8s%s", tmpBuffer, asciitime( tbuffer, 100, *today ) + 11, (( isAM ) ? "Am" : "Pm" )); - toSend.addCommand( oldstrutil::format( "text %u %u %u %u", 280, yStart + 13, 25, linenum++ )); + szBuffer = util::format( "%s %.8s%s", tmpBuffer, asciitime( tbuffer, 100, *today ) + 11, (( isAM ) ? "Am" : "Pm" )); + toSend.addCommand( util::format( "text %u %u %u %u", 280, yStart + 13, 25, linenum++ )); toSend.addText( szBuffer ); // add the next gump portion. New server level services, in the form of a gump Configuration, and Accounts tabs to start. These are default tabs - toSend.addCommand( oldstrutil::format( "resizepic %u %u %u %u %u", xStart + 10, yStart + 62, 5054, 190, 340 )); + toSend.addCommand( util::format( "resizepic %u %u %u %u %u", xStart + 10, yStart + 62, 5054, 190, 340 )); UI32 tabNumber = 1; // Do the shard tab - toSend.addCommand( oldstrutil::format( "button %u %u %u %u %u %u %u", 17, yStart + 47, 0x138E, 0x138F, 0, 1, 0 )); + toSend.addCommand( util::format( "button %u %u %u %u %u %u %u", 17, yStart + 47, 0x138E, 0x138F, 0, 1, 0 )); szBuffer = "Objects"; - toSend.addCommand( oldstrutil::format( "text %u %u %u %u", 42, yStart + 46, 47, linenum++ )); + toSend.addCommand( util::format( "text %u %u %u %u", 42, yStart + 46, 47, linenum++ )); toSend.addText( szBuffer ); // Do the server tab - toSend.addCommand( oldstrutil::format( "button %u %u %u %u %u %u %u", 105, yStart + 47, 0x138E, 0x138F, 0, 30, 1 )); - toSend.addCommand( oldstrutil::format( "text %u %u %u %u", 132, yStart + 46, 47, linenum++ )); + toSend.addCommand( util::format( "button %u %u %u %u %u %u %u", 105, yStart + 47, 0x138E, 0x138F, 0, 30, 1 )); + toSend.addCommand( util::format( "text %u %u %u %u", 132, yStart + 46, 47, linenum++ )); toSend.addText( "Settings" ); // Need a seperator - toSend.addCommand( oldstrutil::format( "gumppictiled %u %u %u %u %u", xStart + 22, yWidth - 50, 165, 5, 0x2393 )); + toSend.addCommand( util::format( "gumppictiled %u %u %u %u %u", xStart + 22, yWidth - 50, 165, 5, 0x2393 )); // Ok, now the job of pulling the rest of the first itemmenu information and making tabs for them - toSend.addCommand( oldstrutil::format( "button %u %u %u %u %u %u %u", 65, yWidth-40, 0x4B9, 0x4BA, 1, 0, 50002 )); - toSend.addCommand( oldstrutil::format( "croppedtext %u %u %u %u %u %u", 85, yWidth-42, 150, 20, 94, linenum++ )); + toSend.addCommand( util::format( "button %u %u %u %u %u %u %u", 65, yWidth-40, 0x4B9, 0x4BA, 1, 0, 50002 )); + toSend.addCommand( util::format( "croppedtext %u %u %u %u %u %u", 85, yWidth-42, 150, 20, 94, linenum++ )); toSend.addText( "Home" ); // Ok here we have some conditions that we need to filter. First being the menu called. @@ -473,53 +475,53 @@ void BuildAddMenuGump( CSocket *s, UI16 m ) pagenum = 2; toSend.addCommand( "page 1" ); // Do the shard tab - toSend.addCommand( oldstrutil::format( "gumppic %u %u %u ", 17, yStart + 47, 0x138F )); + toSend.addCommand( util::format( "gumppic %u %u %u ", 17, yStart + 47, 0x138F )); szBuffer = "Objects"; - toSend.addCommand( oldstrutil::format( "text %u %u %u %u", 42, yStart + 46, 70, linenum++ )); + toSend.addCommand( util::format( "text %u %u %u %u", 42, yStart + 46, 70, linenum++ )); toSend.addText( szBuffer ); - toSend.addCommand( oldstrutil::format( "htmlgump %i %i %i %i %u %i %i", 245, 70, 220, 30, linenum++, 0, 0 )); + toSend.addCommand( util::format( "htmlgump %i %i %i %i %u %i %i", 245, 70, 220, 30, linenum++, 0, 0 )); toSend.addText( "
Ultima Offline eXperiment 3
" ); // Shard Menu Version szBuffer = "v" + CVersionClass::GetVersion() + "." + CVersionClass::GetBuild(); - toSend.addCommand( oldstrutil::format( "text %u %u %u %u", 320, 90, 27, linenum++ )); + toSend.addCommand( util::format( "text %u %u %u %u", 320, 90, 27, linenum++ )); toSend.addText( szBuffer ); // Shard Menu Description szBuffer = "Greetings! Using these menus you can"; - toSend.addCommand( oldstrutil::format( "text %u %u %u %u", 225, 120, 94, linenum++ )); + toSend.addCommand( util::format( "text %u %u %u %u", 225, 120, 94, linenum++ )); toSend.addText( szBuffer ); szBuffer = "quickly and easily add Items, Spawners,"; - toSend.addCommand( oldstrutil::format( "text %u %u %u %u", 225, 135, 94, linenum++ )); + toSend.addCommand( util::format( "text %u %u %u %u", 225, 135, 94, linenum++ )); toSend.addText( szBuffer ); szBuffer = "NPCs and more to your shard, in order"; - toSend.addCommand( oldstrutil::format( "text %u %u %u %u", 225, 150, 94, linenum++ )); + toSend.addCommand( util::format( "text %u %u %u %u", 225, 150, 94, linenum++ )); toSend.addText( szBuffer ); szBuffer = "to customize it to your needs."; - toSend.addCommand( oldstrutil::format( "text %u %u %u %u", 225, 165, 94, linenum++ )); + toSend.addCommand( util::format( "text %u %u %u %u", 225, 165, 94, linenum++ )); toSend.addText( szBuffer ); szBuffer = "Objects tab is used to find stuff to"; - toSend.addCommand( oldstrutil::format( "text %u %u %u %u", 225, 190, 94, linenum++ )); + toSend.addCommand( util::format( "text %u %u %u %u", 225, 190, 94, linenum++ )); toSend.addText( szBuffer ); szBuffer = "add. Use Settings tab to configure"; - toSend.addCommand( oldstrutil::format( "text %u %u %u %u", 225, 205, 94, linenum++ )); + toSend.addCommand( util::format( "text %u %u %u %u", 225, 205, 94, linenum++ )); toSend.addText( szBuffer ); szBuffer = "various options for this menu!"; - toSend.addCommand( oldstrutil::format( "text %u %u %u %u", 225, 220, 94, linenum++ )); + toSend.addCommand( util::format( "text %u %u %u %u", 225, 220, 94, linenum++ )); toSend.addText( szBuffer ); szBuffer = "Don't forget to check out the UOX3 Docs!"; - toSend.addCommand( oldstrutil::format( "text %u %u %u %u", 225, 260, 27, linenum++ )); + toSend.addCommand( util::format( "text %u %u %u %u", 225, 260, 27, linenum++ )); toSend.addText( szBuffer ); - toSend.addCommand( oldstrutil::format( "button %u %u %u %u %u %u %u", 295, 295, 0x5d1, 0x5d3, 1, 0, 50020 )); + toSend.addCommand( util::format( "button %u %u %u %u %u %u %u", 295, 295, 0x5d1, 0x5d3, 1, 0, 50020 )); // here we hunt tags to make sure that we get them all from the itemmenus etc. UI08 numCounter = 0; @@ -532,27 +534,27 @@ void BuildAddMenuGump( CSocket *s, UI16 m ) if( numCounter > 0 && ( !( numCounter % 12 ))) { position = 80; - toSend.addCommand( oldstrutil::format( "page %i", ++pagenum )); + toSend.addCommand( util::format( "page %i", ++pagenum )); xOffset = SXOFFSET; yOffset = SYOFFSET; } // Drop in the page number text area image - toSend.addCommand( oldstrutil::format( "gumppic %u %u %u", xStart + 300, yWidth - 28, 0x98E )); + toSend.addCommand( util::format( "gumppic %u %u %u", xStart + 300, yWidth - 28, 0x98E )); // Add the page number text to the text area for display - toSend.addCommand( oldstrutil::format( "text %u %u %u %u", xStart + 335, yWidth - 27, 39, linenum++ )); - szBuffer = oldstrutil::format( "Menu %i - Page %i", m, pagenum - 1 ); + toSend.addCommand( util::format( "text %u %u %u %u", xStart + 335, yWidth - 27, 39, linenum++ )); + szBuffer = util::format( "Menu %i - Page %i", m, pagenum - 1 ); toSend.addText( szBuffer ); // Spin the tagged items loaded in from the dfn files. - toSend.addCommand( oldstrutil::format( "button %u %u %u %u %u %u %u", 15, position, 0x4B9, 0x4BA, 1, 0, buttonnum)); - toSend.addCommand( oldstrutil::format( "croppedtext %u %u %u %u %u %u", 35, position-3, 150, 20, 50, linenum++ )); + toSend.addCommand( util::format( "button %u %u %u %u %u %u %u", 15, position, 0x4B9, 0x4BA, 1, 0, buttonnum)); + toSend.addCommand( util::format( "croppedtext %u %u %u %u %u %u", 35, position-3, 150, 20, 50, linenum++ )); toSend.addText( data ); if( tag.data()[0] != '<' && tag.data()[0] != ' ' ) // it actually has a picture, well bugger me! :> { // Draw a frame for the item to make it stand out a touch more. - toSend.addCommand( oldstrutil::format( "resizepic %u %u %u %u %u", xOffset, yOffset, 0x53, 65, 100 )); - toSend.addCommand( oldstrutil::format( "checkertrans %u %u %u %u", xOffset + 7, yOffset + 9, 52, 82 )); - toSend.addCommand( oldstrutil::format( "tilepic %u %u %i", xOffset + 5, yOffset + 10, std::stoi( tag, nullptr, 0 ))); - toSend.addCommand( oldstrutil::format( "croppedtext %u %u %u %u %u %u", xOffset, yOffset+65, 65, 20, 55, linenum++ )); + toSend.addCommand( util::format( "resizepic %u %u %u %u %u", xOffset, yOffset, 0x53, 65, 100 )); + toSend.addCommand( util::format( "checkertrans %u %u %u %u", xOffset + 7, yOffset + 9, 52, 82 )); + toSend.addCommand( util::format( "tilepic %u %u %i", xOffset + 5, yOffset + 10, std::stoi( tag, nullptr, 0 ))); + toSend.addCommand( util::format( "croppedtext %u %u %u %u %u %u", xOffset, yOffset+65, 65, 20, 55, linenum++ )); toSend.addText( data ); xOffset += XOFFSET; if( xOffset > 480 ) @@ -571,14 +573,14 @@ void BuildAddMenuGump( CSocket *s, UI16 m ) for( i = 0; i < numCounter; i += 12 ) { - toSend.addCommand( oldstrutil::format( "page %i", currentPage )); + toSend.addCommand( util::format( "page %i", currentPage )); if( i >= 10 ) { - toSend.addCommand( oldstrutil::format( "button %u %u %u %u %u %u", xStart + 240, yWidth - 25, 0x25EB, 0x25EA, 0, currentPage - 1 )); + toSend.addCommand( util::format( "button %u %u %u %u %u %u", xStart + 240, yWidth - 25, 0x25EB, 0x25EA, 0, currentPage - 1 )); } if(( numCounter > 12 ) && (( i + 12 ) < numCounter )) { - toSend.addCommand( oldstrutil::format( "button %u %u %u %u %u %u", xWidth - 60, yWidth - 25, 0x25E7, 0x25E6, 0, currentPage + 1 )); + toSend.addCommand( util::format( "button %u %u %u %u %u %u", xWidth - 60, yWidth - 25, 0x25E7, 0x25E6, 0, currentPage + 1 )); } currentPage++; } @@ -589,9 +591,9 @@ void BuildAddMenuGump( CSocket *s, UI16 m ) pagenum = 2; toSend.addCommand( "page 1" ); // Do the shard tab - toSend.addCommand( oldstrutil::format( "gumppic %u %u %u ", 17, yStart + 47, 0x138F )); + toSend.addCommand( util::format( "gumppic %u %u %u ", 17, yStart + 47, 0x138F )); szBuffer = "Shard"; - toSend.addCommand( oldstrutil::format( "text %u %u %u %u", 42, yStart + 46, 39, linenum++ )); + toSend.addCommand( util::format( "text %u %u %u %u", 42, yStart + 46, 39, linenum++ )); toSend.addText( szBuffer ); // here we hunt tags to make sure that we get them all from the itemmenus etc. UI08 numCounter = 0; @@ -600,10 +602,10 @@ void BuildAddMenuGump( CSocket *s, UI16 m ) yOffset = SYOFFSET; // Drop in the page number text area image - toSend.addCommand( oldstrutil::format( "gumppic %u %u %u", xStart + 300, yWidth - 28, 0x98E )); + toSend.addCommand( util::format( "gumppic %u %u %u", xStart + 300, yWidth - 28, 0x98E )); // Add the page number text to the text area for display - toSend.addCommand( oldstrutil::format( "text %u %u %u %u", xStart + 335, yWidth - 27, 39, linenum++ )); - szBuffer = oldstrutil::format( "Menu %i - Page %i", m, pagenum - 1 ); + toSend.addCommand( util::format( "text %u %u %u %u", xStart + 335, yWidth - 27, 39, linenum++ )); + szBuffer = util::format( "Menu %i - Page %i", m, pagenum - 1 ); toSend.addText( szBuffer ); for( tag = ItemMenu->Next(); !ItemMenu->AtEnd(); tag = ItemMenu->Next() ) @@ -613,19 +615,19 @@ void BuildAddMenuGump( CSocket *s, UI16 m ) if( numCounter > 0 && (!(numCounter % 12 ))) { position = 80; - toSend.addCommand( oldstrutil::format( "page %i", pagenum++ )); + toSend.addCommand( util::format( "page %i", pagenum++ )); xOffset=SXOFFSET; yOffset=SYOFFSET; // Drop in the page number text area image - toSend.addCommand( oldstrutil::format( "gumppic %u %u %u", xStart + 300, yWidth - 28, 0x98E )); + toSend.addCommand( util::format( "gumppic %u %u %u", xStart + 300, yWidth - 28, 0x98E )); // Add the page number text to the text area for display - toSend.addCommand( oldstrutil::format( "text %u %u %u %u", xStart + 335, yWidth - 27, 39, linenum++ )); - szBuffer = oldstrutil::format( "Menu %i - Page %i", m, pagenum - 1 ); + toSend.addCommand( util::format( "text %u %u %u %u", xStart + 335, yWidth - 27, 39, linenum++ )); + szBuffer = util::format( "Menu %i - Page %i", m, pagenum - 1 ); toSend.addText( szBuffer ); } // Drop in the page number text area image - if( oldstrutil::upper( tag ) == "INSERTADDMENUITEMS" ) + if( util::upper( tag ) == "INSERTADDMENUITEMS" ) { // Check to see if the desired menu has any items to add if( g_mmapAddMenuMap.find( m ) == g_mmapAddMenuMap.end() ) @@ -636,17 +638,17 @@ void BuildAddMenuGump( CSocket *s, UI16 m ) std::pair pairRange = g_mmapAddMenuMap.equal_range( m ); for( ADDMENUMAP_CITERATOR CI = pairRange.first; CI!=pairRange.second; CI++ ) { - toSend.addCommand( oldstrutil::format( "button %u %u %u %u %u %u %u", 15, position, 0x4B9, 0x4BA , 1, 0, buttonnum )); - toSend.addCommand( oldstrutil::format( "croppedtext %u %u %u %u %u %u", 35, position - 3, 150, 20, 40, linenum) ); + toSend.addCommand( util::format( "button %u %u %u %u %u %u %u", 15, position, 0x4B9, 0x4BA , 1, 0, buttonnum )); + toSend.addCommand( util::format( "croppedtext %u %u %u %u %u %u", 35, position - 3, 150, 20, 40, linenum) ); toSend.addText( CI->second.itemName ); // check to make sure that we have an image now, seeing as we might not have one with the new changes in 0.98.01.2+ if(CI->second.tileId != 0 ) { // Draw a frame for the item to make it stand out a touch more. - toSend.addCommand( oldstrutil::format( "resizepic %u %u %u %u %u", xOffset, yOffset, 0x53, 65, 100 )); - toSend.addCommand( oldstrutil::format( "checkertrans %u %u %u %u", xOffset + 7, yOffset + 9, 52, 82 )); - toSend.addCommand( oldstrutil::format( "tilepic %u %u %i", xOffset + 5, yOffset + 10, CI->second.tileId )); - toSend.addCommand( oldstrutil::format( "croppedtext %u %u %u %u %u %u", xOffset, yOffset + 65, 65, 20, 55, linenum++ )); + toSend.addCommand( util::format( "resizepic %u %u %u %u %u", xOffset, yOffset, 0x53, 65, 100 )); + toSend.addCommand( util::format( "checkertrans %u %u %u %u", xOffset + 7, yOffset + 9, 52, 82 )); + toSend.addCommand( util::format( "tilepic %u %u %i", xOffset + 5, yOffset + 10, CI->second.tileId )); + toSend.addCommand( util::format( "croppedtext %u %u %u %u %u %u", xOffset, yOffset + 65, 65, 20, 55, linenum++ )); toSend.addText( CI->second.itemName ); toSend.addText( CI->second.itemName.c_str() ); xOffset += XOFFSET; @@ -663,16 +665,16 @@ void BuildAddMenuGump( CSocket *s, UI16 m ) } continue; } - toSend.addCommand( oldstrutil::format( "button %u %u %u %u %u %u %u", 15, position, 0x4B9, 0x4BA, 1, 0, buttonnum )); - toSend.addCommand( oldstrutil::format( "croppedtext %u %u %u %u %u %u", 35, position - 3, 150, 20, 50, linenum++ )); + toSend.addCommand( util::format( "button %u %u %u %u %u %u %u", 15, position, 0x4B9, 0x4BA, 1, 0, buttonnum )); + toSend.addCommand( util::format( "croppedtext %u %u %u %u %u %u", 35, position - 3, 150, 20, 50, linenum++ )); toSend.addText( data ); if( tag.data()[0] != '<' && tag.data()[0] != ' ' ) // it actually has a picture, well bugger me! :> { // Draw a frame for the item to make it stand out a touch more. - toSend.addCommand( oldstrutil::format( "checkertrans %u %u %u %u", xOffset + 7, yOffset + 9, 110, 110 )); - toSend.addCommand( oldstrutil::format( "buttontileart %u %u 0x0a9f 0x0aa1 %u %u %u %u %u %u %u", xOffset, yOffset, 1, 0, buttonnum, std::stoi( tag, nullptr, 0 ), 0, 25, 25 )); - toSend.addCommand( oldstrutil::format( "tooltip 1042971 @%s@", data.c_str() )); - toSend.addCommand( oldstrutil::format( "croppedtext %u %u %u %u %u %u", xOffset + 15, yOffset + 85, 100, 20, 50, linenum++ )); + toSend.addCommand( util::format( "checkertrans %u %u %u %u", xOffset + 7, yOffset + 9, 110, 110 )); + toSend.addCommand( util::format( "buttontileart %u %u 0x0a9f 0x0aa1 %u %u %u %u %u %u %u", xOffset, yOffset, 1, 0, buttonnum, std::stoi( tag, nullptr, 0 ), 0, 25, 25 )); + toSend.addCommand( util::format( "tooltip 1042971 @%s@", data.c_str() )); + toSend.addCommand( util::format( "croppedtext %u %u %u %u %u %u", xOffset + 15, yOffset + 85, 100, 20, 50, linenum++ )); toSend.addText( data ); xOffset += XOFFSET; if( xOffset > 640 ) @@ -691,14 +693,14 @@ void BuildAddMenuGump( CSocket *s, UI16 m ) UI32 currentPage = 1; for( i = 0; i < numCounter; i += 12 ) { - toSend.addCommand( oldstrutil::format( "page %i", currentPage) ); + toSend.addCommand( util::format( "page %i", currentPage) ); if( i >= 10 ) { - toSend.addCommand( oldstrutil::format( "button %u %u %u %u %u %u", xStart + 240, yWidth - 25, 0x25EB, 0x25EA, 0, currentPage - 1 )); //back button + toSend.addCommand( util::format( "button %u %u %u %u %u %u", xStart + 240, yWidth - 25, 0x25EB, 0x25EA, 0, currentPage - 1 )); //back button } if(( numCounter > 12 ) && (( i + 12 ) < numCounter )) { - toSend.addCommand( oldstrutil::format( "button %u %u %u %u %u %u", xWidth - 60, yWidth - 25, 0x25E7, 0x25E6, 0, currentPage + 1 )); + toSend.addCommand( util::format( "button %u %u %u %u %u %u", xWidth - 60, yWidth - 25, 0x25E7, 0x25E6, 0, currentPage + 1 )); } ++currentPage; } @@ -708,55 +710,55 @@ void BuildAddMenuGump( CSocket *s, UI16 m ) // Reserved page # 800 - 899 for the server support pages toSend.addCommand( "page 30" ); // Show the selected tab image for this page. - toSend.addCommand( oldstrutil::format( "gumppic %u %u %u", 105, yStart + 47, 0x138F )); - toSend.addCommand( oldstrutil::format( "text %u %u %u %u", 132, yStart + 46, 70, linenum++ )); + toSend.addCommand( util::format( "gumppic %u %u %u", 105, yStart + 47, 0x138F )); + toSend.addCommand( util::format( "text %u %u %u %u", 132, yStart + 46, 70, linenum++ )); toSend.addText( "Settings" ); // Create the Quick Access Menu - toSend.addCommand( oldstrutil::format( "text %u %u %u %u", 57, yStart + 76, 52, linenum++ )); + toSend.addCommand( util::format( "text %u %u %u %u", 57, yStart + 76, 52, linenum++ )); toSend.addText( "Quick-Access" ); // Need a seperator - toSend.addCommand( oldstrutil::format( "gumppictiled %u %u %u %u %u", xStart + 21, yStart + 105, 165, 5, 0x2393 )); + toSend.addCommand( util::format( "gumppictiled %u %u %u %u %u", xStart + 21, yStart + 105, 165, 5, 0x2393 )); // Create the Commandlist button - toSend.addCommand( oldstrutil::format( "button %u %u %u %u %u %u %u", 45, yStart + 125, 0x2A30, 0x2A44, 1, 4, 50008 )); - toSend.addCommand( oldstrutil::format( "text %u %u %u %u", 65, yStart + 129, 52, linenum++ )); + toSend.addCommand( util::format( "button %u %u %u %u %u %u %u", 45, yStart + 125, 0x2A30, 0x2A44, 1, 4, 50008 )); + toSend.addCommand( util::format( "text %u %u %u %u", 65, yStart + 129, 52, linenum++ )); toSend.addText( "Commandlist" ); // Create the Wholist Online button - toSend.addCommand( oldstrutil::format( "button %u %u %u %u %u %u %u", 45, yStart + 155, 0x2A30, 0x2A44, 1, 4, 50009 )); - toSend.addCommand( oldstrutil::format( "text %u %u %u %u", 62, yStart + 159, 52, linenum++ )); + toSend.addCommand( util::format( "button %u %u %u %u %u %u %u", 45, yStart + 155, 0x2A30, 0x2A44, 1, 4, 50009 )); + toSend.addCommand( util::format( "text %u %u %u %u", 62, yStart + 159, 52, linenum++ )); toSend.addText( "Who is Online" ); // Create the Wholist Offline button - toSend.addCommand( oldstrutil::format( "button %u %u %u %u %u %u %u", 45, yStart + 185, 0x2A30, 0x2A44, 1, 4, 50010 )); - toSend.addCommand( oldstrutil::format( "text %u %u %u %u", 60, yStart + 189, 52, linenum++ )); + toSend.addCommand( util::format( "button %u %u %u %u %u %u %u", 45, yStart + 185, 0x2A30, 0x2A44, 1, 4, 50010 )); + toSend.addCommand( util::format( "text %u %u %u %u", 60, yStart + 189, 52, linenum++ )); toSend.addText( "Who is Offline" ); // Create the Reload DFNs button - toSend.addCommand( oldstrutil::format( "button %u %u %u %u %u %u %u", 45, yStart + 215, 0x2A30, 0x2A44, 1, 4, 50011 )); - toSend.addCommand( oldstrutil::format( "text %u %u %u %u", 60, yStart + 219, 52, linenum++ )); + toSend.addCommand( util::format( "button %u %u %u %u %u %u %u", 45, yStart + 215, 0x2A30, 0x2A44, 1, 4, 50011 )); + toSend.addCommand( util::format( "text %u %u %u %u", 60, yStart + 219, 52, linenum++ )); toSend.addText( "Reload DFNs" ); // Create the Server Shutdown button if( mChar->GetCommandLevel() >= CL_ADMIN ) { - toSend.addCommand( oldstrutil::format( "button %u %u %u %u %u %u %u", 45, yStart + 275, 0x2A58, 0x2A44, 1, 4, 50012 )); - toSend.addCommand( oldstrutil::format( "text %u %u %u %u", 73, yStart + 279, 52, linenum++ )); + toSend.addCommand( util::format( "button %u %u %u %u %u %u %u", 45, yStart + 275, 0x2A58, 0x2A44, 1, 4, 50012 )); + toSend.addCommand( util::format( "text %u %u %u %u", 73, yStart + 279, 52, linenum++ )); toSend.addText( "Shutdown" ); } // Settings Backgrounds - toSend.addCommand( oldstrutil::format( "resizepic %u %u %u %u %u", 210, 55, 5120, 250, 150 )); - toSend.addCommand( oldstrutil::format( "resizepic %u %u %u %u %u", 210, 205, 5120, 250, 150 )); + toSend.addCommand( util::format( "resizepic %u %u %u %u %u", 210, 55, 5120, 250, 150 )); + toSend.addCommand( util::format( "resizepic %u %u %u %u %u", 210, 205, 5120, 250, 150 )); // Settings Header 1 - toSend.addCommand( oldstrutil::format( "htmlgump %i %i %i %i %u %i %i", 235, 60, 200, 60, linenum++, 0, 0 )); + toSend.addCommand( util::format( "htmlgump %i %i %i %i %u %i %i", 235, 60, 200, 60, linenum++, 0, 0 )); toSend.addText( "
Menu Settings
" ); // Settings Header 2 - toSend.addCommand( oldstrutil::format( "htmlgump %i %i %i %i %u %i %i", 235, 220, 200, 60, linenum++, 0, 0 )); + toSend.addCommand( util::format( "htmlgump %i %i %i %i %u %i %i", 235, 220, 200, 60, linenum++, 0, 0 )); toSend.addText( "
Item Settings
" ); // Settings Options START @@ -764,130 +766,130 @@ void BuildAddMenuGump( CSocket *s, UI16 m ) TAGMAPOBJECT addAtLoc = mChar->GetTag( "addAtLoc" ); if( addAtLoc.m_IntValue == 1 ) { - toSend.addCommand( oldstrutil::format( "button %u %u %u %u %u %u %u", 225, 80, 0x869, 0x867, 1, 0, 50000 )); + toSend.addCommand( util::format( "button %u %u %u %u %u %u %u", 225, 80, 0x869, 0x867, 1, 0, 50000 )); } else { - toSend.addCommand( oldstrutil::format( "button %u %u %u %u %u %u %u", 225, 80, 0x867, 0x869, 1, 0, 50000 )); + toSend.addCommand( util::format( "button %u %u %u %u %u %u %u", 225, 80, 0x867, 0x869, 1, 0, 50000 )); } szBuffer = "Add item at specific location"; - toSend.addCommand( oldstrutil::format( "text %u %u %u %u", 255, 80, 94, linenum++ )); + toSend.addCommand( util::format( "text %u %u %u %u", 255, 80, 94, linenum++ )); toSend.addText( szBuffer ); szBuffer = "instead of in GM's backpack"; - toSend.addCommand( oldstrutil::format( "text %u %u %u %u", 255, 95, 94, linenum++ )); + toSend.addCommand( util::format( "text %u %u %u %u", 255, 95, 94, linenum++ )); toSend.addText( szBuffer ); // Repeat Add Object TAGMAPOBJECT repeatAdd = mChar->GetTag( "repeatAdd" ); if( repeatAdd.m_IntValue == 1 ) { - toSend.addCommand( oldstrutil::format( "button %u %u %u %u %u %u %u", 250, 120, 0x869, 0x867, 1, 0, 50001 )); + toSend.addCommand( util::format( "button %u %u %u %u %u %u %u", 250, 120, 0x869, 0x867, 1, 0, 50001 )); } else { - toSend.addCommand( oldstrutil::format( "button %u %u %u %u %u %u %u", 250, 120, 0x867, 0x869, 1, 0, 50001 )); + toSend.addCommand( util::format( "button %u %u %u %u %u %u %u", 250, 120, 0x867, 0x869, 1, 0, 50001 )); } szBuffer = "Add item repeatedly"; - toSend.addCommand( oldstrutil::format( "text %u %u %u %u", 280, 120, 94, linenum++ )); + toSend.addCommand( util::format( "text %u %u %u %u", 280, 120, 94, linenum++ )); toSend.addText( szBuffer ); szBuffer = "until cancelled"; - toSend.addCommand( oldstrutil::format( "text %u %u %u %u", 280, 135, 94, linenum++ )); + toSend.addCommand( util::format( "text %u %u %u %u", 280, 135, 94, linenum++ )); toSend.addText( szBuffer ); // Auto-reopen Menu TAGMAPOBJECT reopenMenu = mChar->GetTag( "reopenMenu" ); if( reopenMenu.m_IntValue == 1 ) { - toSend.addCommand( oldstrutil::format( "button %u %u %u %u %u %u %u", 225, 160, 0x869, 0x867, 1, 0, 50003 )); + toSend.addCommand( util::format( "button %u %u %u %u %u %u %u", 225, 160, 0x869, 0x867, 1, 0, 50003 )); } else { - toSend.addCommand( oldstrutil::format( "button %u %u %u %u %u %u %u", 225, 160, 0x867, 0x869, 1, 0, 50003 )); + toSend.addCommand( util::format( "button %u %u %u %u %u %u %u", 225, 160, 0x867, 0x869, 1, 0, 50003 )); } szBuffer = "Automatically reopen menu"; - toSend.addCommand( oldstrutil::format( "text %u %u %u %u", 255, 160, 94, linenum++ )); + toSend.addCommand( util::format( "text %u %u %u %u", 255, 160, 94, linenum++ )); toSend.addText( szBuffer ); szBuffer = "after selecting object to add"; - toSend.addCommand( oldstrutil::format( "text %u %u %u %u", 255, 175, 94, linenum++ )); + toSend.addCommand( util::format( "text %u %u %u %u", 255, 175, 94, linenum++ )); toSend.addText( szBuffer ); // Force-Decayable Off TAGMAPOBJECT forceDecayOff = mChar->GetTag( "forceDecayOff" ); if( forceDecayOff.m_IntValue == 1 ) { - toSend.addCommand( oldstrutil::format( "button %u %u %u %u %u %u %u", 240, 260, 0x16ca, 0x16cb, 1, 0, 50004 )); + toSend.addCommand( util::format( "button %u %u %u %u %u %u %u", 240, 260, 0x16ca, 0x16cb, 1, 0, 50004 )); } else { - toSend.addCommand( oldstrutil::format( "button %u %u %u %u %u %u %u", 240, 260, 0x16c6, 0x16c7, 1, 0, 50004 )); + toSend.addCommand( util::format( "button %u %u %u %u %u %u %u", 240, 260, 0x16c6, 0x16c7, 1, 0, 50004 )); } // Force-Decayable On TAGMAPOBJECT forceDecayOn = mChar->GetTag( "forceDecayOn" ); if( forceDecayOn.m_IntValue == 1 ) { - toSend.addCommand( oldstrutil::format( "button %u %u %u %u %u %u %u", 350, 260, 0x16c4, 0x16c5, 1, 0, 50005 )); + toSend.addCommand( util::format( "button %u %u %u %u %u %u %u", 350, 260, 0x16c4, 0x16c5, 1, 0, 50005 )); } else { - toSend.addCommand( oldstrutil::format( "button %u %u %u %u %u %u %u", 350, 260, 0x16c0, 0x16c1, 1, 0, 50005 )); + toSend.addCommand( util::format( "button %u %u %u %u %u %u %u", 350, 260, 0x16c0, 0x16c1, 1, 0, 50005 )); } szBuffer = "Default Decayable Status of Items"; - toSend.addCommand( oldstrutil::format( "text %u %u %u %u", 230, 240, 94, linenum++ )); + toSend.addCommand( util::format( "text %u %u %u %u", 230, 240, 94, linenum++ )); toSend.addText( szBuffer ); szBuffer = "Force OFF"; - toSend.addCommand( oldstrutil::format( "text %u %u %u %u", 275, 265, 27, linenum++ )); + toSend.addCommand( util::format( "text %u %u %u %u", 275, 265, 27, linenum++ )); toSend.addText( szBuffer ); szBuffer = "Force ON"; - toSend.addCommand( oldstrutil::format( "text %u %u %u %u", 385, 265, 72, linenum++ )); + toSend.addCommand( util::format( "text %u %u %u %u", 385, 265, 72, linenum++ )); toSend.addText( szBuffer ); // Force-Movable Off TAGMAPOBJECT forceMovableOff = mChar->GetTag( "forceMovableOff" ); if( forceMovableOff.m_IntValue == 1 ) { - toSend.addCommand( oldstrutil::format( "button %u %u %u %u %u %u %u", 240, 320, 0x16ca, 0x16cb, 1, 0, 50006 )); + toSend.addCommand( util::format( "button %u %u %u %u %u %u %u", 240, 320, 0x16ca, 0x16cb, 1, 0, 50006 )); } else { - toSend.addCommand( oldstrutil::format( "button %u %u %u %u %u %u %u", 240, 320, 0x16c6, 0x16c7, 1, 0, 50006 )); + toSend.addCommand( util::format( "button %u %u %u %u %u %u %u", 240, 320, 0x16c6, 0x16c7, 1, 0, 50006 )); } // Force-Movable On TAGMAPOBJECT forceMovableOn = mChar->GetTag( "forceMovableOn" ); if( forceMovableOn.m_IntValue == 1 ) { - toSend.addCommand( oldstrutil::format( "button %u %u %u %u %u %u %u", 350, 320, 0x16c4, 0x16c5, 1, 0, 50007 )); + toSend.addCommand( util::format( "button %u %u %u %u %u %u %u", 350, 320, 0x16c4, 0x16c5, 1, 0, 50007 )); } else { - toSend.addCommand( oldstrutil::format( "button %u %u %u %u %u %u %u", 350, 320, 0x16c0, 0x16c1, 1, 0, 50007 )); + toSend.addCommand( util::format( "button %u %u %u %u %u %u %u", 350, 320, 0x16c0, 0x16c1, 1, 0, 50007 )); } szBuffer = "Default Movable State of Items"; - toSend.addCommand( oldstrutil::format( "text %u %u %u %u", 230, 300, 94, linenum++ )); + toSend.addCommand( util::format( "text %u %u %u %u", 230, 300, 94, linenum++ )); toSend.addText( szBuffer ); szBuffer = "Force OFF"; - toSend.addCommand( oldstrutil::format( "text %u %u %u %u", 275, 325, 27, linenum++ )); + toSend.addCommand( util::format( "text %u %u %u %u", 275, 325, 27, linenum++ )); toSend.addText( szBuffer ); szBuffer = "Force ON"; - toSend.addCommand( oldstrutil::format( "text %u %u %u %u", 385, 325, 72, linenum++ )); + toSend.addCommand( util::format( "text %u %u %u %u", 385, 325, 72, linenum++ )); toSend.addText( szBuffer ); // Settings Options END // Reserved pages 900-999 for the online help system. (comming soon) toSend.addCommand( "page 31" ); // Ok display the scroll that we use to display our help information - toSend.addCommand( oldstrutil::format( "resizepic %u %u %u %u %u", xStart + 205, yStart + 62, 0x1432, 175, 200 )); + toSend.addCommand( util::format( "resizepic %u %u %u %u %u", xStart + 205, yStart + 62, 0x1432, 175, 200 )); // Write out what page were on (Mainly for debug purposes - szBuffer = oldstrutil::format( "%5u", 31 ); - toSend.addCommand( oldstrutil::format( "text %u %u %u %u", xWidth - 58, yWidth - 25, 110, linenum++ )); + szBuffer = util::format( "%5u", 31 ); + toSend.addCommand( util::format( "text %u %u %u %u", xWidth - 58, yWidth - 25, 110, linenum++ )); toSend.addText( szBuffer ); // Ok, now the job of pulling the rest of the first itemmenu information and making tabs for them szBuffer = "Page 31"; - toSend.addCommand( oldstrutil::format( "text %u %u %u %u", 30, yStart + 200, 87, linenum++ )); + toSend.addCommand( util::format( "text %u %u %u %u", 30, yStart + 200, 87, linenum++ )); toSend.addText( szBuffer ); - toSend.addCommand( oldstrutil::format( "button %u %u %u %u %u %u %u", 104, yStart + 300, 0x138E, 0x138E, 0, 1, tabNumber++ )); + toSend.addCommand( util::format( "button %u %u %u %u %u %u %u", 104, yStart + 300, 0x138E, 0x138E, 0, 1, tabNumber++ )); #if defined( UOX_DEBUG_MODE ) Console << "==============================" << myendl; @@ -930,7 +932,7 @@ bool CPIHelpRequest::Handle( void ) } } - std::string sect = std::string( "GMMENU " ) + oldstrutil::number( menuNum ); + std::string sect = std::string( "GMMENU " ) + util::ntos( menuNum ); CScriptSection *GMMenu = FileLookup->FindEntry( sect, menus_def ); if( GMMenu == nullptr ) return true; @@ -1077,8 +1079,8 @@ void HandleGumpCommand( CSocket *s, std::string cmd, std::string data ) CChar *mChar = s->CurrcharObj(); - cmd = oldstrutil::upper( cmd ); - data = oldstrutil::upper( data ); + cmd = util::upper( cmd ); + data = util::upper( data ); std::string builtString; switch( cmd.data()[0] ) @@ -1109,8 +1111,8 @@ void HandleGumpCommand( CSocket *s, std::string cmd, std::string data ) auto secs = oldstrutil::sections( data, "," ); if( secs.size() > 1 ) { - std::string tmp = oldstrutil::trim( oldstrutil::removeTrailing( secs[0], "//" )); - UI16 num = oldstrutil::value( oldstrutil::trim( oldstrutil::removeTrailing( secs[1], "//" ))); + std::string tmp = util::trim( util::strip( secs[0], "//" )); + UI16 num = util::ston( util::trim( util::strip( secs[1], "//" ))); if( addAtLoc.m_IntValue == 1 ) { @@ -1119,22 +1121,22 @@ void HandleGumpCommand( CSocket *s, std::string cmd, std::string data ) { if( itemType == OT_SPAWNER ) { - addCmd = oldstrutil::format( "raddspawner %s", tmp.c_str() ); + addCmd = util::format( "raddspawner %s", tmp.c_str() ); } else { - addCmd = oldstrutil::format( "radditem %s", tmp.c_str() ); + addCmd = util::format( "radditem %s", tmp.c_str() ); } } else { if( itemType == OT_SPAWNER ) { - addCmd = oldstrutil::format( "add spawner %s", tmp.c_str() ); + addCmd = util::format( "add spawner %s", tmp.c_str() ); } else { - addCmd = oldstrutil::format( "add item %s", tmp.c_str() ); + addCmd = util::format( "add item %s", tmp.c_str() ); } } Commands->Command( s, mChar, addCmd ); @@ -1144,11 +1146,11 @@ void HandleGumpCommand( CSocket *s, std::string cmd, std::string data ) std::string addCmd = ""; if( itemType == OT_SPAWNER ) { - addCmd = oldstrutil::format( "raddspawner %s", tmp.c_str() ); + addCmd = util::format( "raddspawner %s", tmp.c_str() ); } else { - addCmd = oldstrutil::format( "radditem %s", tmp.c_str() ); + addCmd = util::format( "radditem %s", tmp.c_str() ); } Commands->Command( s, mChar, addCmd ); } @@ -1189,22 +1191,22 @@ void HandleGumpCommand( CSocket *s, std::string cmd, std::string data ) { if( itemType == OT_SPAWNER ) { - addCmd = oldstrutil::format( "raddspawner %s", data.c_str() ); + addCmd = util::format( "raddspawner %s", data.c_str() ); } else { - addCmd = oldstrutil::format( "radditem %s", data.c_str() ); + addCmd = util::format( "radditem %s", data.c_str() ); } } else { if( itemType == OT_SPAWNER ) { - addCmd = oldstrutil::format( "add spawner %s", data.c_str() ); + addCmd = util::format( "add spawner %s", data.c_str() ); } else { - addCmd = oldstrutil::format( "add item %s", data.c_str() ); + addCmd = util::format( "add item %s", data.c_str() ); } } Commands->Command( s, mChar, addCmd ); @@ -1214,11 +1216,11 @@ void HandleGumpCommand( CSocket *s, std::string cmd, std::string data ) std::string addCmd = ""; if( itemType == OT_SPAWNER ) { - addCmd = oldstrutil::format( "raddspawner %s", data.c_str() ); + addCmd = util::format( "raddspawner %s", data.c_str() ); } else { - addCmd = oldstrutil::format( "radditem %s", data.c_str() ); + addCmd = util::format( "radditem %s", data.c_str() ); } Commands->Command( s, mChar, addCmd ); } @@ -1253,7 +1255,7 @@ void HandleGumpCommand( CSocket *s, std::string cmd, std::string data ) } if( reopenMenu.m_IntValue == 1 ) { - std::string menuString = oldstrutil::format( "itemmenu %d", s->TempInt() ); + std::string menuString = util::format( "itemmenu %d", s->TempInt() ); Commands->Command( s, mChar, menuString ); } } @@ -1273,7 +1275,7 @@ void HandleGumpCommand( CSocket *s, std::string cmd, std::string data ) if( data.empty() ) return; - CPIHelpRequest toHandle( s, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + CPIHelpRequest toHandle( s, static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); toHandle.Handle(); } else if( cmd == "GMPAGE" ) @@ -1292,7 +1294,7 @@ void HandleGumpCommand( CSocket *s, std::string cmd, std::string data ) if( data.empty() ) return; - UI16 placeNum = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )); + UI16 placeNum = static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 )); if( cwmWorldState->goPlaces.find( placeNum ) != cwmWorldState->goPlaces.end() ) { GoPlaces_st toGoTo = cwmWorldState->goPlaces[placeNum]; @@ -1337,7 +1339,7 @@ void HandleGumpCommand( CSocket *s, std::string cmd, std::string data ) if( data.empty() ) return; - BuildAddMenuGump( s, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ))); + BuildAddMenuGump( s, static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 ))); } else if( cmd == "INFORMATION" ) { @@ -1351,7 +1353,7 @@ void HandleGumpCommand( CSocket *s, std::string cmd, std::string data ) if( data.empty() ) return; - Skills->NewMakeMenu( s, std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 ), static_cast( s->AddId() )); + Skills->NewMakeMenu( s, std::stoi( util::trim( util::strip( data, "//" )), nullptr, 0 ), static_cast( s->AddId() )); } break; case 'N': @@ -1360,13 +1362,13 @@ void HandleGumpCommand( CSocket *s, std::string cmd, std::string data ) if( data.empty() ) return; - std::string menuString = oldstrutil::format( "itemmenu %d", s->TempInt() ); + std::string menuString = util::format( "itemmenu %d", s->TempInt() ); Commands->Command( s, mChar, menuString ); TAGMAPOBJECT repeatAdd = mChar->GetTag( "repeatAdd" ); if( repeatAdd.m_IntValue == 1 ) { - std::string addCmd = oldstrutil::format( "raddnpc %s", data.c_str() ); + std::string addCmd = util::format( "raddnpc %s", data.c_str() ); Commands->Command( s, mChar, addCmd ); } else @@ -1431,7 +1433,7 @@ void HandleGumpCommand( CSocket *s, std::string cmd, std::string data ) void HandleAddMenuButton( CSocket *s, UI32 button ) { SI32 addMenuLoc = s->TempInt(); - std::string sect = std::string( "ITEMMENU " ) + oldstrutil::number( addMenuLoc ); + std::string sect = std::string( "ITEMMENU " ) + util::ntos( addMenuLoc ); CChar *mChar = s->CurrcharObj(); if( button >= 50000 && button <= 50020 ) @@ -1756,7 +1758,7 @@ void HandleHowTo( CSocket *sock, SI32 cmdNumber ) } - auto filename = oldstrutil::format( "help/commands/%s.txt", cmdName.c_str() ); + auto filename = util::format( "help/commands/%s.txt", cmdName.c_str() ); std::ifstream toOpen( filename ); if( !toOpen.is_open() ) @@ -2059,7 +2061,7 @@ bool CPIGumpChoice::Handle( void ) } else if( main >= POLYMORPHMENUOFFSET ) { - sect = std::string( "POLYMORPHMENU " ) + oldstrutil::number( main ); + sect = std::string( "POLYMORPHMENU " ) + util::ntos( main ); data = GrabMenuData( sect, ( static_cast( sub ) * 2 ), tag ); if( !data.empty() ) { @@ -2085,7 +2087,7 @@ bool CPIGumpChoice::Handle( void ) { if( main == TRACKINGMENUOFFSET ) { - sect = std::string( "TRACKINGMENU " ) + oldstrutil::number( main ); + sect = std::string( "TRACKINGMENU " ) + util::ntos( main ); data = GrabMenuData( sect, ( static_cast( sub ) * 2 ), tag ); if( !data.empty() && tag != "What" ) { @@ -2104,7 +2106,7 @@ bool CPIGumpChoice::Handle( void ) } else if( main < ITEMMENUOFFSET ) // GM Menus { - sect = std::string( "GMMENU " ) + oldstrutil::number( main ); + sect = std::string( "GMMENU " ) + util::ntos( main ); data = GrabMenuData( sect, ( static_cast( sub ) * 2 ), tag ); if( !tag.empty() ) { @@ -2352,21 +2354,21 @@ void CGumpDisplay::Send( UI32 gumpNum, bool isMenu, SERIAL serial ) temp = std::to_string( value ); break; case 1: - temp = oldstrutil::format( "%x", static_cast( value )); + temp = util::format( "%x", static_cast( value )); break; case 2: ser1 = static_cast( value >> 24 ); ser2 = static_cast( value >> 16 ); ser3 = static_cast( value >> 8 ); ser4 = static_cast( value % 256 ); - temp = oldstrutil::format( "%i %i %i %i", ser1, ser2, ser3, ser4 ); + temp = util::format( "%i %i %i %i", ser1, ser2, ser3, ser4 ); break; case 3: ser1 = static_cast( value >> 24 ); ser2 = static_cast( value >> 16 ); ser3 = static_cast( value >> 8 ); ser4 = static_cast( value % 256 ); - temp = oldstrutil::format( "%x %x %x %x", ser1, ser2, ser3, ser4 ); + temp = util::format( "%x %x %x %x", ser1, ser2, ser3, ser4 ); break; case 4: if( gumpData[i]->stringValue.empty() ) @@ -2391,7 +2393,7 @@ void CGumpDisplay::Send( UI32 gumpNum, bool isMenu, SERIAL serial ) //LOOKATME position += 20; ++lineForButton; - temp3 = oldstrutil::format( "text %i %u %i %u", 30, position, cwmWorldState->ServerData()->RightTextColour(), linenum++ ); + temp3 = util::format( "text %i %u %i %u", 30, position, cwmWorldState->ServerData()->RightTextColour(), linenum++ ); one.push_back( temp3 ); auto remaining = std::min(( temp.size() - ( static_cast( tempCounter ) + 1 ) * static_cast( stringWidth ) * 2 ), static_cast( stringWidth ) * 2 ); @@ -2408,12 +2410,12 @@ void CGumpDisplay::Send( UI32 gumpNum, bool isMenu, SERIAL serial ) case 5: ser1 = static_cast( value >> 8 ); ser2 = static_cast( value % 256 ); - temp = oldstrutil::format( "0x%02x%02x", ser1, ser2 ); + temp = util::format( "0x%02x%02x", ser1, ser2 ); break; case 6: ser1 = static_cast( value >> 8 ); ser2 = static_cast( value % 256 ); - temp = oldstrutil::format( "%i %i", ser1, ser2 ); + temp = util::format( "%i %i", ser1, ser2 ); break; case 7: if( gumpData[i]->stringValue.empty() ) @@ -2461,7 +2463,7 @@ void CGumpDisplay::Send( UI32 gumpNum, bool isMenu, SERIAL serial ) else { - temp = oldstrutil::format( "%.2f", std::stof( gumpData[i]->stringValue )); + temp = util::format( "%.2f", std::stof( gumpData[i]->stringValue )); } break; default: @@ -2483,12 +2485,12 @@ void CGumpDisplay::Send( UI32 gumpNum, bool isMenu, SERIAL serial ) one.push_back( temp ); if( i >= 10 ) { - temp = oldstrutil::format( "button 10 %i %i %i 0 %u", height - 40, cwmWorldState->ServerData()->ButtonLeft(), cwmWorldState->ServerData()->ButtonLeft() + 1, pagenum - 1 ); //back button + temp = util::format( "button 10 %i %i %i 0 %u", height - 40, cwmWorldState->ServerData()->ButtonLeft(), cwmWorldState->ServerData()->ButtonLeft() + 1, pagenum - 1 ); //back button one.push_back( temp ); } if( lineForButton > numToPage && static_cast(( i + numToPage )) < lineForButton ) { - temp = oldstrutil::format( "button %i %i %i %i 0 %u", width - 40, height - 40, cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1, pagenum + 1 ); //forward button + temp = util::format( "button %i %i %i %i 0 %u", width - 40, height - 40, cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1, pagenum + 1 ); //forward button one.push_back( temp ); } ++pagenum; diff --git a/source/house.cpp b/source/house.cpp index 980f05ae5..fed5229ca 100644 --- a/source/house.cpp +++ b/source/house.cpp @@ -10,6 +10,7 @@ #include "regions.h" #include "Dictionary.h" #include "StringUtility.hpp" +#include "utility/strutil.hpp" #include "ObjectFactory.h" @@ -30,7 +31,7 @@ auto DoHouseTarget( CSocket *mSock, UI16 houseEntry ) -> void { UI16 houseId = 0; std::string tag, data; - auto sect = "HOUSE "s + oldstrutil::number( houseEntry ); + auto sect = "HOUSE "s + util::ntos( houseEntry ); auto House = FileLookup->FindEntry( sect, house_def ); if( House ) { @@ -38,15 +39,15 @@ auto DoHouseTarget( CSocket *mSock, UI16 houseEntry ) -> void { auto tag = sec->tag; auto data = sec->data; - if( oldstrutil::upper( tag ) == "ID" ) + if( util::upper( tag ) == "ID" ) { - houseId = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )), nullptr, 0 )); + houseId = static_cast( std::stoul( util::trim( util::strip( data, "//" )), nullptr, 0 )); break; } } if( !houseId ) { - Console.Error( oldstrutil::format( "Bad house script: #%u\n", houseEntry )); + Console.Error( util::format( "Bad house script: #%u\n", houseEntry )); } else { @@ -126,8 +127,8 @@ auto CreateHouseItems( CChar *mChar, std::vector houseItems, CItem { tag = sec->tag; data = sec->data; - UTag = oldstrutil::upper( tag ); - data = oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )); + UTag = util::upper( tag ); + data = util::trim( util::strip( data, "//" )); if( UTag == "ITEM" ) { hItem = Items->CreateBaseScriptItem( nullptr, data, worldNum, 1, hInstanceId ); @@ -591,7 +592,7 @@ CMultiObj * BuildHouse( CSocket *mSock, UI16 houseEntry, bool checkLocation = tr TAGMAPOBJECT customTag; std::map customTagMap; - std::string sect = "HOUSE " + oldstrutil::number( houseEntry ); + std::string sect = "HOUSE " + util::ntos( houseEntry ); CScriptSection *House = FileLookup->FindEntry( sect, house_def ); if( House == nullptr ) return nullptr; // House entry not found @@ -601,8 +602,8 @@ CMultiObj * BuildHouse( CSocket *mSock, UI16 houseEntry, bool checkLocation = tr { tag = sec->tag; data = sec->data; - UTag = oldstrutil::upper( tag ); - data = oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )); + UTag = util::upper( tag ); + data = util::trim( util::strip( data, "//" )); if( UTag == "ID" ) { @@ -727,16 +728,16 @@ CMultiObj * BuildHouse( CSocket *mSock, UI16 houseEntry, bool checkLocation = tr { if( count == 1 ) { - result = oldstrutil::trim( oldstrutil::removeTrailing( sec, "//" )); + result = util::trim( util::strip( sec, "//" )); } else { - result = result + " " + oldstrutil::trim( oldstrutil::removeTrailing( sec, "//" )); + result = result + " " + util::trim( util::strip( sec, "//" )); } } count++; } - customTagName = oldstrutil::trim( oldstrutil::removeTrailing( ssecs[0], "//" )); + customTagName = util::trim( util::strip( ssecs[0], "//" )); customTagStringValue = result; if( !customTagName.empty() && !customTagStringValue.empty() ) @@ -749,7 +750,7 @@ CMultiObj * BuildHouse( CSocket *mSock, UI16 houseEntry, bool checkLocation = tr } else { - Console.Warning( oldstrutil::format( "Invalid data found in CUSTOMSTRINGTAG tag inside House script [%s] - Supported data format: ", sect.c_str() )); + Console.Warning( util::format( "Invalid data found in CUSTOMSTRINGTAG tag inside House script [%s] - Supported data format: ", sect.c_str() )); } break; } @@ -764,35 +765,35 @@ CMultiObj * BuildHouse( CSocket *mSock, UI16 houseEntry, bool checkLocation = tr { if( count == 1 ) { - result = oldstrutil::trim( oldstrutil::removeTrailing( sec, "//" )); + result = util::trim( util::strip( sec, "//" )); } } count++; } - customTagName = oldstrutil::trim( oldstrutil::removeTrailing( ssecs[0], "//" )); + customTagName = util::trim( util::strip( ssecs[0], "//" )); customTagStringValue = result; if( !customTagName.empty() && !customTagStringValue.empty() ) { customTag.m_Destroy = false; - customTag.m_IntValue = std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( customTagStringValue, "//" )), nullptr, 0 ); + customTag.m_IntValue = std::stoi( util::trim( util::strip( customTagStringValue, "//" )), nullptr, 0 ); customTag.m_ObjectType = TAGMAP_TYPE_INT; customTag.m_StringValue = ""; customTagMap.insert( std::pair( customTagName, customTag )); if( count > 1 ) { - Console.Warning( oldstrutil::format( "Multiple values detected for CUSTOMINTTAG in House script [%s] - only first value will be used! Supported data format: ", sect.c_str() )); + Console.Warning( util::format( "Multiple values detected for CUSTOMINTTAG in House script [%s] - only first value will be used! Supported data format: ", sect.c_str() )); } } else { - Console.Warning( oldstrutil::format( "Invalid data found in CUSTOMINTTAG tag in House script [%s] - Supported data format: ", sect.c_str() )); + Console.Warning( util::format( "Invalid data found in CUSTOMINTTAG tag in House script [%s] - Supported data format: ", sect.c_str() )); } } } if( !houseId ) { - Console.Error( oldstrutil::format( "Bad house script # %u!", houseEntry )); + Console.Error( util::format( "Bad house script # %u!", houseEntry )); return nullptr; } @@ -1164,7 +1165,7 @@ bool KillKeysFunctor( CBaseObject *a, [[maybe_unused]] UI32 &b, void *extraData { std::string keyTag = "key" + std::to_string( j ) + "more"; TAGMAPOBJECT keyMore = i->GetTag( keyTag ); - if( oldstrutil::value( keyMore.m_StringValue ) == targSerial ) + if( util::ston( keyMore.m_StringValue ) == targSerial ) { // More value of key in keyring matches house serial TAGMAPOBJECT localObject; @@ -1233,7 +1234,7 @@ bool KillKeysFunctor( CBaseObject *a, [[maybe_unused]] UI32 &b, void *extraData { std::string keyTag = "key" + std::to_string( j ) + "more"; TAGMAPOBJECT keyMore = i->GetTag( keyTag ); - if( oldstrutil::value( keyMore.m_StringValue ) == targSerial ) + if( util::ston( keyMore.m_StringValue ) == targSerial ) { // More value of key in keyring matches house serial TAGMAPOBJECT localObject; diff --git a/source/items.cpp b/source/items.cpp index d301995b5..b320cdd39 100644 --- a/source/items.cpp +++ b/source/items.cpp @@ -12,6 +12,7 @@ #include "regions.h" #include "ObjectFactory.h" #include "StringUtility.hpp" +#include "utility/strutil.hpp" using namespace std::string_literals; @@ -77,24 +78,24 @@ auto ApplyItemSection( CItem *applyTo, CScriptSection *toApply, std::string sect continue; } - auto ssecs = oldstrutil::sections( oldstrutil::trim( oldstrutil::removeTrailing( cdata, "//" )), " " ); + auto ssecs = oldstrutil::sections( util::trim( util::strip( cdata, "//" )), " " ); switch( tag ) { case DFNTAG_AMMO: - applyTo->SetAmmoId( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[0], "//" )), nullptr, 0 ))); + applyTo->SetAmmoId( static_cast( std::stoul( util::trim( util::strip( ssecs[0], "//" )), nullptr, 0 ))); if( ssecs.size() > 1 ) { - applyTo->SetAmmoHue( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[1], "//" )), nullptr, 0 ))); + applyTo->SetAmmoHue( static_cast( std::stoul( util::trim( util::strip( ssecs[1], "//" )), nullptr, 0 ))); } break; case DFNTAG_AMMOFX: - applyTo->SetAmmoFX( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[0], "//" )), nullptr, 0 ))); + applyTo->SetAmmoFX( static_cast( std::stoul( util::trim( util::strip( ssecs[0], "//" )), nullptr, 0 ))); if( ssecs.size() > 1 ) { - applyTo->SetAmmoFXHue( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[1], "//" )), nullptr, 0 ))); + applyTo->SetAmmoFXHue( static_cast( std::stoul( util::trim( util::strip( ssecs[1], "//" )), nullptr, 0 ))); if( ssecs.size() > 2 ) { - applyTo->SetAmmoFXRender( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[2], "//" )), nullptr, 0 ))); + applyTo->SetAmmoFXRender( static_cast( std::stoul( util::trim( util::strip( ssecs[2], "//" )), nullptr, 0 ))); } } break; @@ -113,7 +114,7 @@ auto ApplyItemSection( CItem *applyTo, CScriptSection *toApply, std::string sect } else { - Console.Warning( oldstrutil::format( "Invalid data found in AMOUNT tag inside item script [%s]", sectionId.c_str() )); + Console.Warning( util::format( "Invalid data found in AMOUNT tag inside item script [%s]", sectionId.c_str() )); } break; case DFNTAG_DAMAGE: @@ -133,7 +134,7 @@ auto ApplyItemSection( CItem *applyTo, CScriptSection *toApply, std::string sect } else { - Console.Warning( oldstrutil::format( "Invalid data found in ATT/DAMAGE tag inside item script [%s]", sectionId.c_str() )); + Console.Warning( util::format( "Invalid data found in ATT/DAMAGE tag inside item script [%s]", sectionId.c_str() )); } break; case DFNTAG_AC: applyTo->SetArmourClass( static_cast( ndata )); break; @@ -146,19 +147,19 @@ auto ApplyItemSection( CItem *applyTo, CScriptSection *toApply, std::string sect case DFNTAG_ELEMENTRESIST: if( ssecs.size() >= 4 ) { - applyTo->SetResist( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[0], "//" )), nullptr, 0 )), HEAT ); - applyTo->SetResist( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[1], "//" )), nullptr, 0 )), COLD ); - applyTo->SetResist( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[2], "//" )), nullptr, 0 )), LIGHTNING ); - applyTo->SetResist( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[3], "//" )), nullptr, 0 )), POISON ); + applyTo->SetResist( static_cast( std::stoul( util::trim( util::strip( ssecs[0], "//" )), nullptr, 0 )), HEAT ); + applyTo->SetResist( static_cast( std::stoul( util::trim( util::strip( ssecs[1], "//" )), nullptr, 0 )), COLD ); + applyTo->SetResist( static_cast( std::stoul( util::trim( util::strip( ssecs[2], "//" )), nullptr, 0 )), LIGHTNING ); + applyTo->SetResist( static_cast( std::stoul( util::trim( util::strip( ssecs[3], "//" )), nullptr, 0 )), POISON ); } break; case DFNTAG_ERBONUS: if( ssecs.size() >= 4 ) { - applyTo->SetResist( applyTo->GetResist( HEAT ) + static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[0], "//" )), nullptr, 0 )), HEAT ); - applyTo->SetResist( applyTo->GetResist( COLD ) + static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[1], "//" )), nullptr, 0 )), COLD ); - applyTo->SetResist( applyTo->GetResist( LIGHTNING ) + static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[2], "//" )), nullptr, 0 )), LIGHTNING ); - applyTo->SetResist( applyTo->GetResist( POISON ) + static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[3], "//" )), nullptr, 0 )), POISON ); + applyTo->SetResist( applyTo->GetResist( HEAT ) + static_cast( std::stoul( util::trim( util::strip( ssecs[0], "//" )), nullptr, 0 )), HEAT ); + applyTo->SetResist( applyTo->GetResist( COLD ) + static_cast( std::stoul( util::trim( util::strip( ssecs[1], "//" )), nullptr, 0 )), COLD ); + applyTo->SetResist( applyTo->GetResist( LIGHTNING ) + static_cast( std::stoul( util::trim( util::strip( ssecs[2], "//" )), nullptr, 0 )), LIGHTNING ); + applyTo->SetResist( applyTo->GetResist( POISON ) + static_cast( std::stoul( util::trim( util::strip( ssecs[3], "//" )), nullptr, 0 )), POISON ); } break; case DFNTAG_EVENT: applyTo->SetEvent( cdata ); break; @@ -176,7 +177,7 @@ auto ApplyItemSection( CItem *applyTo, CScriptSection *toApply, std::string sect } } else - Console.Warning( oldstrutil::format( "Invalid data found in DEF tag inside item script [%s]", sectionId.c_str() )); + Console.Warning( util::format( "Invalid data found in DEF tag inside item script [%s]", sectionId.c_str() )); break; case DFNTAG_DEFBONUS: if( ndata >= 0 ) @@ -192,7 +193,7 @@ auto ApplyItemSection( CItem *applyTo, CScriptSection *toApply, std::string sect } else { - Console.Warning( oldstrutil::format( "Invalid data found in DEFBONUS tag inside item script [%s]", sectionId.c_str() )); + Console.Warning( util::format( "Invalid data found in DEFBONUS tag inside item script [%s]", sectionId.c_str() )); } break; case DFNTAG_DEX: @@ -209,11 +210,11 @@ auto ApplyItemSection( CItem *applyTo, CScriptSection *toApply, std::string sect } else { - Console.Warning( oldstrutil::format( "Invalid data found in DEX tag inside item script [%s]", sectionId.c_str() )); + Console.Warning( util::format( "Invalid data found in DEX tag inside item script [%s]", sectionId.c_str() )); } break; case DFNTAG_DEXADD: applyTo->SetDexterity2( static_cast( ndata )); break; - case DFNTAG_DIR: applyTo->SetDir( static_cast( std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( cdata, "//" )), nullptr, 0 ))); break; + case DFNTAG_DIR: applyTo->SetDir( static_cast( std::stoi( util::trim( util::strip( cdata, "//" )), nullptr, 0 ))); break; case DFNTAG_DYE: applyTo->SetDye( ndata != 0 ); break; case DFNTAG_DECAY: if( ndata == 1 ) @@ -242,17 +243,17 @@ auto ApplyItemSection( CItem *applyTo, CScriptSection *toApply, std::string sect else { UI32 rndEntry = RandomNum( 0, static_cast( ssecs.size() - 1 )); - scriptEntry = oldstrutil::trim( oldstrutil::removeTrailing( ssecs[rndEntry], "//" )); + scriptEntry = util::trim( util::strip( ssecs[rndEntry], "//" )); } auto toFind = FileLookup->FindEntry( scriptEntry, items_def ); if( toFind == nullptr ) { - Console.Warning( oldstrutil::format( "Invalid script entry (%s) called with GET tag, item serial 0x%X", scriptEntry.c_str(), applyTo->GetSerial() )); + Console.Warning( util::format( "Invalid script entry (%s) called with GET tag, item serial 0x%X", scriptEntry.c_str(), applyTo->GetSerial() )); } else if( toFind == toApply ) { - Console.Warning( oldstrutil::format( "Infinite loop avoided with GET tag inside item script [%s]", scriptEntry.c_str() )); + Console.Warning( util::format( "Infinite loop avoided with GET tag inside item script [%s]", scriptEntry.c_str() )); } else { @@ -300,17 +301,17 @@ auto ApplyItemSection( CItem *applyTo, CScriptSection *toApply, std::string sect else { UI32 rndEntry = RandomNum( 0, static_cast( ssecs.size() - 1 )); - scriptEntry = oldstrutil::trim( oldstrutil::removeTrailing( ssecs[rndEntry], "//" )); + scriptEntry = util::trim( util::strip( ssecs[rndEntry], "//" )); } CScriptSection *toFind = FileLookup->FindEntry( scriptEntry, items_def ); if( toFind == NULL ) { - Console.Warning( oldstrutil::format( "Invalid script entry (%s) called with %s tag, item serial 0x%X", scriptEntry.c_str(), tagName.c_str(), applyTo->GetSerial() )); + Console.Warning( util::format( "Invalid script entry (%s) called with %s tag, item serial 0x%X", scriptEntry.c_str(), tagName.c_str(), applyTo->GetSerial() )); } else if( toFind == toApply ) { - Console.Warning( oldstrutil::format( "Infinite loop avoided with %s tag inside item script [%s]", tagName.c_str(), scriptEntry.c_str() )); + Console.Warning( util::format( "Infinite loop avoided with %s tag inside item script [%s]", tagName.c_str(), scriptEntry.c_str() )); } else { @@ -333,7 +334,7 @@ auto ApplyItemSection( CItem *applyTo, CScriptSection *toApply, std::string sect } else { - Console.Warning( oldstrutil::format( "Invalid data found in HP tag inside item script [%s]", sectionId.c_str() )); + Console.Warning( util::format( "Invalid data found in HP tag inside item script [%s]", sectionId.c_str() )); } break; case DFNTAG_HIDAMAGE: applyTo->SetHiDamage( static_cast( ndata )); break; @@ -341,12 +342,12 @@ auto ApplyItemSection( CItem *applyTo, CScriptSection *toApply, std::string sect case DFNTAG_ID: // applyTo->SetId( static_cast( ndata )); break; if( ssecs.size() == 1 ) { - applyTo->SetId( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[0], "//" )), nullptr, 0 ))); + applyTo->SetId( static_cast( std::stoul( util::trim( util::strip( ssecs[0], "//" )), nullptr, 0 ))); } else { SI32 rndEntry = RandomNum( 0, static_cast( ssecs.size() - 1 )); - applyTo->SetId( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[rndEntry], "//" )), nullptr, 0 ))); + applyTo->SetId( static_cast( std::stoul( util::trim( util::strip( ssecs[rndEntry], "//" )), nullptr, 0 ))); } break; case DFNTAG_INTELLIGENCE: applyTo->SetIntelligence( static_cast( ndata )); break; @@ -363,92 +364,92 @@ auto ApplyItemSection( CItem *applyTo, CScriptSection *toApply, std::string sect case DFNTAG_MORE: if( ssecs.size() >= 4 ) { - applyTo->SetTempVar( CITV_MORE, 1, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[0], "//" )), nullptr, 0 ))); - applyTo->SetTempVar( CITV_MORE, 2, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[1], "//" )), nullptr, 0 ))); - applyTo->SetTempVar( CITV_MORE, 3, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[2], "//" )), nullptr, 0 ))); - applyTo->SetTempVar( CITV_MORE, 4, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[3], "//" )), nullptr, 0 ))); + applyTo->SetTempVar( CITV_MORE, 1, static_cast( std::stoul( util::trim( util::strip( ssecs[0], "//" )), nullptr, 0 ))); + applyTo->SetTempVar( CITV_MORE, 2, static_cast( std::stoul( util::trim( util::strip( ssecs[1], "//" )), nullptr, 0 ))); + applyTo->SetTempVar( CITV_MORE, 3, static_cast( std::stoul( util::trim( util::strip( ssecs[2], "//" )), nullptr, 0 ))); + applyTo->SetTempVar( CITV_MORE, 4, static_cast( std::stoul( util::trim( util::strip( ssecs[3], "//" )), nullptr, 0 ))); } else { - applyTo->SetTempVar( CITV_MORE, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[0], "//" )), nullptr, 0 ))); + applyTo->SetTempVar( CITV_MORE, static_cast( std::stoul( util::trim( util::strip( ssecs[0], "//" )), nullptr, 0 ))); } break; case DFNTAG_MORE0: if( ssecs.size() >= 4 ) { - applyTo->SetTempVar( CITV_MORE0, 1, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[0], "//" )), nullptr, 0 ))); - applyTo->SetTempVar( CITV_MORE0, 2, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[1], "//" )), nullptr, 0 ))); - applyTo->SetTempVar( CITV_MORE0, 3, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[2], "//" )), nullptr, 0 ))); - applyTo->SetTempVar( CITV_MORE0, 4, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[3], "//" )), nullptr, 0 ))); + applyTo->SetTempVar( CITV_MORE0, 1, static_cast( std::stoul( util::trim( util::strip( ssecs[0], "//" )), nullptr, 0 ))); + applyTo->SetTempVar( CITV_MORE0, 2, static_cast( std::stoul( util::trim( util::strip( ssecs[1], "//" )), nullptr, 0 ))); + applyTo->SetTempVar( CITV_MORE0, 3, static_cast( std::stoul( util::trim( util::strip( ssecs[2], "//" )), nullptr, 0 ))); + applyTo->SetTempVar( CITV_MORE0, 4, static_cast( std::stoul( util::trim( util::strip( ssecs[3], "//" )), nullptr, 0 ))); } else { - applyTo->SetTempVar( CITV_MORE0, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[0], "//" )), nullptr, 0 ))); + applyTo->SetTempVar( CITV_MORE0, static_cast( std::stoul( util::trim( util::strip( ssecs[0], "//" )), nullptr, 0 ))); } break; case DFNTAG_MORE1: if( ssecs.size() >= 4 ) { - applyTo->SetTempVar( CITV_MORE1, 1, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[0], "//" )), nullptr, 0 ))); - applyTo->SetTempVar( CITV_MORE1, 2, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[1], "//" )), nullptr, 0 ))); - applyTo->SetTempVar( CITV_MORE1, 3, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[2], "//" )), nullptr, 0 ))); - applyTo->SetTempVar( CITV_MORE1, 4, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[3], "//" )), nullptr, 0 ))); + applyTo->SetTempVar( CITV_MORE1, 1, static_cast( std::stoul( util::trim( util::strip( ssecs[0], "//" )), nullptr, 0 ))); + applyTo->SetTempVar( CITV_MORE1, 2, static_cast( std::stoul( util::trim( util::strip( ssecs[1], "//" )), nullptr, 0 ))); + applyTo->SetTempVar( CITV_MORE1, 3, static_cast( std::stoul( util::trim( util::strip( ssecs[2], "//" )), nullptr, 0 ))); + applyTo->SetTempVar( CITV_MORE1, 4, static_cast( std::stoul( util::trim( util::strip( ssecs[3], "//" )), nullptr, 0 ))); } else { - applyTo->SetTempVar( CITV_MORE1, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[0], "//" )), nullptr, 0 ))); + applyTo->SetTempVar( CITV_MORE1, static_cast( std::stoul( util::trim( util::strip( ssecs[0], "//" )), nullptr, 0 ))); } break; case DFNTAG_MORE2: if( ssecs.size() >= 4 ) { - applyTo->SetTempVar( CITV_MORE2, 1, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[0], "//" )), nullptr, 0 ))); - applyTo->SetTempVar( CITV_MORE2, 2, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[1], "//" )), nullptr, 0 ))); - applyTo->SetTempVar( CITV_MORE2, 3, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[2], "//" )), nullptr, 0 ))); - applyTo->SetTempVar( CITV_MORE2, 4, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[3], "//" )), nullptr, 0 ))); + applyTo->SetTempVar( CITV_MORE2, 1, static_cast( std::stoul( util::trim( util::strip( ssecs[0], "//" )), nullptr, 0 ))); + applyTo->SetTempVar( CITV_MORE2, 2, static_cast( std::stoul( util::trim( util::strip( ssecs[1], "//" )), nullptr, 0 ))); + applyTo->SetTempVar( CITV_MORE2, 3, static_cast( std::stoul( util::trim( util::strip( ssecs[2], "//" )), nullptr, 0 ))); + applyTo->SetTempVar( CITV_MORE2, 4, static_cast( std::stoul( util::trim( util::strip( ssecs[3], "//" )), nullptr, 0 ))); } else { - applyTo->SetTempVar( CITV_MORE2, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[0], "//" )), nullptr, 0 ))); + applyTo->SetTempVar( CITV_MORE2, static_cast( std::stoul( util::trim( util::strip( ssecs[0], "//" )), nullptr, 0 ))); } break; case DFNTAG_MOREX: if( ssecs.size() >= 4 ) { - applyTo->SetTempVar( CITV_MOREX, 1, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[0], "//" )), nullptr, 0 ))); - applyTo->SetTempVar( CITV_MOREX, 2, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[1], "//" )), nullptr, 0 ))); - applyTo->SetTempVar( CITV_MOREX, 3, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[2], "//" )), nullptr, 0 ))); - applyTo->SetTempVar( CITV_MOREX, 4, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[3], "//" )), nullptr, 0 ))); + applyTo->SetTempVar( CITV_MOREX, 1, static_cast( std::stoul( util::trim( util::strip( ssecs[0], "//" )), nullptr, 0 ))); + applyTo->SetTempVar( CITV_MOREX, 2, static_cast( std::stoul( util::trim( util::strip( ssecs[1], "//" )), nullptr, 0 ))); + applyTo->SetTempVar( CITV_MOREX, 3, static_cast( std::stoul( util::trim( util::strip( ssecs[2], "//" )), nullptr, 0 ))); + applyTo->SetTempVar( CITV_MOREX, 4, static_cast( std::stoul( util::trim( util::strip( ssecs[3], "//" )), nullptr, 0 ))); } else { - applyTo->SetTempVar( CITV_MOREX, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[0], "//" )), nullptr, 0 ))); + applyTo->SetTempVar( CITV_MOREX, static_cast( std::stoul( util::trim( util::strip( ssecs[0], "//" )), nullptr, 0 ))); } break; case DFNTAG_MOREY: if( ssecs.size() >= 4 ) { - applyTo->SetTempVar( CITV_MOREY, 1, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[0], "//" )), nullptr, 0 ))); - applyTo->SetTempVar( CITV_MOREY, 2, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[1], "//" )), nullptr, 0 ))); - applyTo->SetTempVar( CITV_MOREY, 3, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[2], "//" )), nullptr, 0 ))); - applyTo->SetTempVar( CITV_MOREY, 4, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[3], "//" )), nullptr, 0 ))); + applyTo->SetTempVar( CITV_MOREY, 1, static_cast( std::stoul( util::trim( util::strip( ssecs[0], "//" )), nullptr, 0 ))); + applyTo->SetTempVar( CITV_MOREY, 2, static_cast( std::stoul( util::trim( util::strip( ssecs[1], "//" )), nullptr, 0 ))); + applyTo->SetTempVar( CITV_MOREY, 3, static_cast( std::stoul( util::trim( util::strip( ssecs[2], "//" )), nullptr, 0 ))); + applyTo->SetTempVar( CITV_MOREY, 4, static_cast( std::stoul( util::trim( util::strip( ssecs[3], "//" )), nullptr, 0 ))); } else { - applyTo->SetTempVar( CITV_MOREY, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[0], "//" )), nullptr, 0 ))); + applyTo->SetTempVar( CITV_MOREY, static_cast( std::stoul( util::trim( util::strip( ssecs[0], "//" )), nullptr, 0 ))); } break; case DFNTAG_MOREZ: if( ssecs.size() >= 4 ) { - applyTo->SetTempVar( CITV_MOREZ, 1, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[0], "//" )), nullptr, 0 ))); - applyTo->SetTempVar( CITV_MOREZ, 2, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[1], "//" )), nullptr, 0 ))); - applyTo->SetTempVar( CITV_MOREZ, 3, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[2], "//" )), nullptr, 0 ))); - applyTo->SetTempVar( CITV_MOREZ, 4, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[3], "//" )), nullptr, 0 ))); + applyTo->SetTempVar( CITV_MOREZ, 1, static_cast( std::stoul( util::trim( util::strip( ssecs[0], "//" )), nullptr, 0 ))); + applyTo->SetTempVar( CITV_MOREZ, 2, static_cast( std::stoul( util::trim( util::strip( ssecs[1], "//" )), nullptr, 0 ))); + applyTo->SetTempVar( CITV_MOREZ, 3, static_cast( std::stoul( util::trim( util::strip( ssecs[2], "//" )), nullptr, 0 ))); + applyTo->SetTempVar( CITV_MOREZ, 4, static_cast( std::stoul( util::trim( util::strip( ssecs[3], "//" )), nullptr, 0 ))); } else { - applyTo->SetTempVar( CITV_MOREZ, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[0], "//" )), nullptr, 0 ))); + applyTo->SetTempVar( CITV_MOREZ, static_cast( std::stoul( util::trim( util::strip( ssecs[0], "//" )), nullptr, 0 ))); } break; case DFNTAG_NAME: applyTo->SetName( cdata ); break; @@ -482,7 +483,7 @@ auto ApplyItemSection( CItem *applyTo, CScriptSection *toApply, std::string sect } else { - Console.Warning( oldstrutil::format( "Invalid data found in RESISTFIRE tag inside Item script [%s]", sectionId.c_str() )); + Console.Warning( util::format( "Invalid data found in RESISTFIRE tag inside Item script [%s]", sectionId.c_str() )); } break; case DFNTAG_RESISTCOLD: @@ -499,7 +500,7 @@ auto ApplyItemSection( CItem *applyTo, CScriptSection *toApply, std::string sect } else { - Console.Warning( oldstrutil::format( "Invalid data found in RESISTCOLD tag inside Item script [%s]", sectionId.c_str() )); + Console.Warning( util::format( "Invalid data found in RESISTCOLD tag inside Item script [%s]", sectionId.c_str() )); } break; case DFNTAG_RESISTLIGHTNING: @@ -516,7 +517,7 @@ auto ApplyItemSection( CItem *applyTo, CScriptSection *toApply, std::string sect } else { - Console.Warning( oldstrutil::format( "Invalid data found in RESISTLIGHTNING tag inside Item script [%s]", sectionId.c_str() )); + Console.Warning( util::format( "Invalid data found in RESISTLIGHTNING tag inside Item script [%s]", sectionId.c_str() )); } break; case DFNTAG_RESISTPOISON: @@ -533,7 +534,7 @@ auto ApplyItemSection( CItem *applyTo, CScriptSection *toApply, std::string sect } else { - Console.Warning( oldstrutil::format( "Invalid data found in RESISTPOISON tag inside Item script [%s]", sectionId.c_str() )); + Console.Warning( util::format( "Invalid data found in RESISTPOISON tag inside Item script [%s]", sectionId.c_str() )); } break; case DFNTAG_RESTOCK: @@ -555,13 +556,13 @@ auto ApplyItemSection( CItem *applyTo, CScriptSection *toApply, std::string sect case DFNTAG_SPELLS: if( ssecs.size() == 3 ) { - applyTo->SetSpell( 0, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[0], "//" )), nullptr, 0 ))); - applyTo->SetSpell( 1, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[1], "//" )), nullptr, 0 ))); - applyTo->SetSpell( 2, static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[2], "//" )), nullptr, 0 ))); + applyTo->SetSpell( 0, static_cast( std::stoul( util::trim( util::strip( ssecs[0], "//" )), nullptr, 0 ))); + applyTo->SetSpell( 1, static_cast( std::stoul( util::trim( util::strip( ssecs[1], "//" )), nullptr, 0 ))); + applyTo->SetSpell( 2, static_cast( std::stoul( util::trim( util::strip( ssecs[2], "//" )), nullptr, 0 ))); } else { - Console.Warning( oldstrutil::format( "Invalid data found in SPELLS tag inside Item script [%s]", sectionId.c_str() )); + Console.Warning( util::format( "Invalid data found in SPELLS tag inside Item script [%s]", sectionId.c_str() )); } break; case DFNTAG_TYPE: @@ -595,7 +596,7 @@ auto ApplyItemSection( CItem *applyTo, CScriptSection *toApply, std::string sect } else { - Console.Warning( oldstrutil::format( "Invalid data found in VALUE tag inside item script [%s]", sectionId.c_str() )); + Console.Warning( util::format( "Invalid data found in VALUE tag inside item script [%s]", sectionId.c_str() )); } break; case DFNTAG_WEIGHT: @@ -617,16 +618,16 @@ auto ApplyItemSection( CItem *applyTo, CScriptSection *toApply, std::string sect { if( count == 1 ) { - result = oldstrutil::trim( oldstrutil::removeTrailing( sec, "//" )); + result = util::trim( util::strip( sec, "//" )); } else { - result = result + " " + oldstrutil::trim( oldstrutil::removeTrailing( sec, "//" )); + result = result + " " + util::trim( util::strip( sec, "//" )); } } count++; } - customTagName = oldstrutil::trim( oldstrutil::removeTrailing( ssecs[0], "//" )); + customTagName = util::trim( util::strip( ssecs[0], "//" )); customTagStringValue = result; if( !customTagName.empty() && !customTagStringValue.empty() ) @@ -639,7 +640,7 @@ auto ApplyItemSection( CItem *applyTo, CScriptSection *toApply, std::string sect } else { - Console.Warning( oldstrutil::format( "Invalid data found in CUSTOMSTRINGTAG tag inside Item script [%s] - Supported data format: ", sectionId.c_str() )); + Console.Warning( util::format( "Invalid data found in CUSTOMSTRINGTAG tag inside Item script [%s] - Supported data format: ", sectionId.c_str() )); } break; } @@ -653,12 +654,12 @@ auto ApplyItemSection( CItem *applyTo, CScriptSection *toApply, std::string sect { if( count == 1 ) { - result = oldstrutil::trim( oldstrutil::removeTrailing( sec, "//" )); + result = util::trim( util::strip( sec, "//" )); } } count++; } - customTagName = oldstrutil::trim( oldstrutil::removeTrailing( ssecs[0], "//" )); + customTagName = util::trim( util::strip( ssecs[0], "//" )); customTagStringValue = result; if( !customTagName.empty() && !customTagStringValue.empty() ) { @@ -669,12 +670,12 @@ auto ApplyItemSection( CItem *applyTo, CScriptSection *toApply, std::string sect applyTo->SetTag( customTagName, customTag ); if( count > 2 ) { - Console.Warning( oldstrutil::format( "Multiple values detected for CUSTOMINTTAG in Item script [%s] - only first value will be used! Supported data format: ", sectionId.c_str() )); + Console.Warning( util::format( "Multiple values detected for CUSTOMINTTAG in Item script [%s] - only first value will be used! Supported data format: ", sectionId.c_str() )); } } else { - Console.Warning( oldstrutil::format( "Invalid data found in CUSTOMINTTAG tag in Item script [%s] - Supported data format: ", sectionId.c_str() )); + Console.Warning( util::format( "Invalid data found in CUSTOMINTTAG tag in Item script [%s] - Supported data format: ", sectionId.c_str() )); } break; } @@ -687,16 +688,16 @@ auto ApplyItemSection( CItem *applyTo, CScriptSection *toApply, std::string sect { if( !cdata.empty() ) { - auto csecs = oldstrutil::sections( oldstrutil::trim( oldstrutil::removeTrailing( cdata, "//" )), "," ); + auto csecs = oldstrutil::sections( util::trim( util::strip( cdata, "//" )), "," ); if( csecs.size() > 1 ) { UI16 iAmount = 0; - std::string amountData = oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )); + std::string amountData = util::trim( util::strip( csecs[1], "//" )); auto tsects = oldstrutil::sections( amountData, " " ); if( tsects.size() > 1 ) // check if the second part of the tag-data contains two sections separated by a space { - auto first = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( tsects[0], "//" )), nullptr, 0 )); - auto second = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( tsects[1], "//" )), nullptr, 0 )); + auto first = static_cast( std::stoul( util::trim( util::strip( tsects[0], "//" )), nullptr, 0 )); + auto second = static_cast( std::stoul( util::trim( util::strip( tsects[1], "//" )), nullptr, 0 )); // Tag contained a minimum and maximum value for amount! Let's randomize! iAmount = static_cast( RandomNum( first, second )); @@ -705,7 +706,7 @@ auto ApplyItemSection( CItem *applyTo, CScriptSection *toApply, std::string sect { iAmount = static_cast( std::stoul( amountData, nullptr, 0 )); } - auto tdata = oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )); + auto tdata = util::trim( util::strip( csecs[0], "//" )); if( tag == DFNTAG_LOOT ) { @@ -732,7 +733,7 @@ auto ApplyItemSection( CItem *applyTo, CScriptSection *toApply, std::string sect } default: { - Console.Warning( oldstrutil::format( "Unknown items dfn tag %i %s %i %i ", tag, cdata.c_str(), ndata, odata )); + Console.Warning( util::format( "Unknown items dfn tag %i %s %i %i ", tag, cdata.c_str(), ndata, odata )); break; } } @@ -758,7 +759,7 @@ CItem * cItem::CreateItem( CSocket *mSock, CChar *mChar, const UI16 itemId, cons if( inPack && !ValidateObject( mChar->GetPackItem() )) { std::string charName = GetNpcDictName( mChar, nullptr, NRS_SYSTEM ); - Console.Warning( oldstrutil::format( "CreateItem(): Character %s(0x%X) has no pack, item creation aborted.", charName.c_str(), mChar->GetSerial() )); + Console.Warning( util::format( "CreateItem(): Character %s(0x%X) has no pack, item creation aborted.", charName.c_str(), mChar->GetSerial() )); return nullptr; } @@ -837,7 +838,7 @@ CItem * cItem::CreateScriptItem( CSocket *mSock, CChar *mChar, const std::string if( inPack && !ValidateObject( mChar->GetPackItem() )) { std::string charName = GetNpcDictName( mChar, nullptr, NRS_SYSTEM ); - Console.Warning( oldstrutil::format( "CreateScriptItem(): Character %s(0x%X) has no pack, item creation aborted.", charName.c_str(), mChar->GetSerial() )); + Console.Warning( util::format( "CreateScriptItem(): Character %s(0x%X) has no pack, item creation aborted.", charName.c_str(), mChar->GetSerial() )); return nullptr; } @@ -947,7 +948,7 @@ auto cItem::CreateRandomItem( CItem *mCont, const std::string& sItemList, const { sect = "ITEMLIST "s + sItemList; } - sect = oldstrutil::trim( oldstrutil::removeTrailing( sect, "//" )); + sect = util::trim( util::strip( sect, "//" )); // This is never "blank", since we assign "LOOTLIST" or "ITEMLIST" in the previous step!! if( sect == "blank" ) // The itemlist-entry is just a blank filler item @@ -975,11 +976,11 @@ auto cItem::CreateRandomItem( CItem *mCont, const std::string& sItemList, const for( size_t j = 0; j < itemListSize; j++ ) { // Split string for entry into a stringlist, based on | as a separator - auto csecs = oldstrutil::sections( oldstrutil::trim( oldstrutil::removeTrailing( ItemList->MoveTo( j ), "//" )), "|" ); + auto csecs = oldstrutil::sections( util::trim( util::strip( ItemList->MoveTo( j ), "//" )), "|" ); if( csecs.size() == 2 ) { // The entry has a weight assigned to it - let's add the weight to the total - sum_of_weight += static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 )); + sum_of_weight += static_cast( std::stoul( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 )); } else { @@ -999,11 +1000,11 @@ auto cItem::CreateRandomItem( CItem *mCont, const std::string& sItemList, const int weightOfChosenItem = 0; for( auto j = 0; j < static_cast( itemListSize ); j++ ) { - auto csecs = oldstrutil::sections( oldstrutil::trim( oldstrutil::removeTrailing( ItemList->MoveTo( j ), "//" )), "|" ); + auto csecs = oldstrutil::sections( util::trim( util::strip( ItemList->MoveTo( j ), "//" )), "|" ); if( csecs.size() == 2 ) { // Ok, item entry has a weight, let's compare that weight to our chosen random number - itemWeight = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 )); + itemWeight = static_cast( std::stoul( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 )); if( rndChoice < itemWeight ) { // If we find another entry with same weight as the first one found, or if none have been found yet, add to list @@ -1034,14 +1035,14 @@ auto cItem::CreateRandomItem( CItem *mCont, const std::string& sItemList, const if( itemEntryToSpawn != -1 ) { // If an entry has been selected based on weights, use that - csecs = oldstrutil::sections( oldstrutil::trim( oldstrutil::removeTrailing( ItemList->MoveTo( itemEntryToSpawn ), "//" )), "," ); + csecs = oldstrutil::sections( util::trim( util::strip( ItemList->MoveTo( itemEntryToSpawn ), "//" )), "," ); } else { // Otherwise choose a random entry - csecs = oldstrutil::sections( oldstrutil::trim( oldstrutil::removeTrailing( ItemList->MoveTo( RandomNum( static_cast( 0 ), itemListSize - 1 )), "//" )), "," ); + csecs = oldstrutil::sections( util::trim( util::strip( ItemList->MoveTo( RandomNum( static_cast( 0 ), itemListSize - 1 )), "//" )), "," ); } - auto csecs2 = oldstrutil::sections( oldstrutil::trim( csecs[0] ), "|" ); + auto csecs2 = oldstrutil::sections( util::trim( csecs[0] ), "|" ); k = csecs2.size() > 1 ? csecs2[1] : csecs2[0]; // Also fetch amount to spawn, if specified @@ -1049,12 +1050,12 @@ auto cItem::CreateRandomItem( CItem *mCont, const std::string& sItemList, const if( csecs.size() > 1 ) { // UI16 iAmount = 0; - std::string amountData = oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )); + std::string amountData = util::trim( util::strip( csecs[1], "//" )); auto tsects = oldstrutil::sections( amountData, " " ); if( tsects.size() > 1 ) // check if the second part of the tag-data contains two sections separated by a space { - auto first = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( tsects[0], "//" )), nullptr, 0 )); - auto second = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( tsects[1], "//" )), nullptr, 0 )); + auto first = static_cast( std::stoul( util::trim( util::strip( tsects[0], "//" )), nullptr, 0 )); + auto second = static_cast( std::stoul( util::trim( util::strip( tsects[1], "//" )), nullptr, 0 )); // Tag contained a minimum and maximum value for amount! Let's randomize! amountToSpawn = static_cast( RandomNum( first, second )); @@ -1067,7 +1068,7 @@ auto cItem::CreateRandomItem( CItem *mCont, const std::string& sItemList, const if( !k.empty() ) { - if( oldstrutil::upper( k ) == "ITEMLIST" || oldstrutil::upper( k ) == "LOOTLIST" ) + if( util::upper( k ) == "ITEMLIST" || util::upper( k ) == "LOOTLIST" ) { // The chosen entry contained another ITEMLIST or LOOTLIST reference! Let's dive back into it... iCreated = CreateRandomItem( mCont, ItemList->GrabData(), worldNum, instanceId, shouldSave ); @@ -1157,7 +1158,7 @@ CItem * cItem::CreateBaseItem( const UI08 worldNum, const ObjectType itemType, c //o------------------------------------------------------------------------------------------------o CItem * cItem::CreateBaseScriptItem( CItem *mCont, std::string ourItem, const UI08 worldNum, const UI16 iAmount, const UI16 instanceId, const ObjectType itemType, const UI16 iColor, bool shouldSave ) { - ourItem = oldstrutil::trim( oldstrutil::removeTrailing( ourItem, "//" )); + ourItem = util::trim( util::strip( ourItem, "//" )); if( ourItem == "blank" ) // The lootlist-entry is just a blank filler item return nullptr; @@ -1165,7 +1166,7 @@ CItem * cItem::CreateBaseScriptItem( CItem *mCont, std::string ourItem, const UI CScriptSection *itemCreate = FileLookup->FindEntry( ourItem, items_def ); if( itemCreate == nullptr ) { - Console.Error( oldstrutil::format( "CreateBaseScriptItem(): Bad script item %s (Item Not Found).", ourItem.c_str() )); + Console.Error( util::format( "CreateBaseScriptItem(): Bad script item %s (Item Not Found).", ourItem.c_str() )); return nullptr; } @@ -1248,7 +1249,7 @@ CItem * cItem::CreateBaseScriptItem( CItem *mCont, std::string ourItem, const UI //o------------------------------------------------------------------------------------------------o void cItem::GetScriptItemSettings( CItem *iCreated ) { - std::string hexId = oldstrutil::number( iCreated->GetId(), 16 ); + std::string hexId = util::ntos( iCreated->GetId(), 16 ); while( hexId.size() < 4 ) { hexId = "0" + hexId; @@ -1369,7 +1370,7 @@ auto DecayItem( CItem& toDecay, const UI32 nextDecayItems, UI32 nextDecayItemsIn if( toDecay.CanBeObjType( OT_MULTI )) { toDecay.SetDecayTime( nextDecayItems ); - Console.Warning( oldstrutil::format( "Warning: Prevented multi (serial: 0x%X) from decaying!", toDecay.GetSerial() )); + Console.Warning( util::format( "Warning: Prevented multi (serial: 0x%X) from decaying!", toDecay.GetSerial() )); } toDecay.Delete(); // This is a problem, if done in a ierator loop return true; diff --git a/source/jail.cpp b/source/jail.cpp index 93990bfe6..b41f55136 100644 --- a/source/jail.cpp +++ b/source/jail.cpp @@ -4,6 +4,7 @@ #include "ssection.h" #include "scriptc.h" #include "StringUtility.hpp" +#include "utility/strutil.hpp" #include using namespace std::string_literals; @@ -247,7 +248,7 @@ auto CJailSystem::ReadSetup() -> void auto data = sec->data; if( !tag.empty() ) { - data = oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )); + data = util::trim( util::strip( data, "//" )); switch(( tag.data()[0] )) { case 'X': toAdd.X( static_cast( std::stoi( data, nullptr, 0 ))); break; @@ -291,9 +292,9 @@ auto CJailSystem::ReadData() -> void auto tag = sec->tag; if( !tag.empty() ) { - auto UTag = oldstrutil::upper( tag ); + auto UTag = util::upper( tag ); auto data = sec->data; - data = oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )); + data = util::trim( util::strip( data, "//" )); switch(( UTag.data()[0] )) { case 'C': @@ -358,7 +359,7 @@ void CJailSystem::WriteData( void ) std::ofstream jailsDestination( jailsFile.c_str() ); if( !jailsDestination ) { - Console.Error( oldstrutil::format( "Failed to open %s for writing", jailsFile.c_str() )); + Console.Error( util::format( "Failed to open %s for writing", jailsFile.c_str() )); return; } for( size_t jCtr = 0; jCtr < jails.size(); ++jCtr ) diff --git a/source/magic.cpp b/source/magic.cpp index d39be7cbc..80190dcf3 100644 --- a/source/magic.cpp +++ b/source/magic.cpp @@ -20,6 +20,8 @@ #include "movement.h" #include "scriptc.h" #include "StringUtility.hpp" +#include "utility/strutil.hpp" + #include "ObjectFactory.h" #include #include "osunique.hpp" @@ -1060,7 +1062,7 @@ auto splRecall( CSocket *sock, CChar *caster, CItem *i, [[maybe_unused]] SI08 cu TAGMAPOBJECT runeMore = i->GetTag( "multiSerial" ); if( runeMore.m_StringValue != "" ) { - SERIAL mSerial = oldstrutil::value( runeMore.m_StringValue ); + SERIAL mSerial = util::ston( runeMore.m_StringValue ); if( mSerial != 0 && mSerial != INVALIDSERIAL ) { CMultiObj *shipMulti = CalcMultiFromSer( mSerial ); @@ -1619,7 +1621,7 @@ bool splMark( CSocket *sock, CChar *caster, CItem *i, [[maybe_unused]] SI08 curS i->SetTag( "multiSerial", tagObject ); markedInMulti = true; - std::string tempRuneName = oldstrutil::format( Dictionary->GetEntry( 684 ), multi->GetNameRequest( caster, NRS_SYSTEM ).c_str() ); // A recall rune for %s. + std::string tempRuneName = util::format( Dictionary->GetEntry( 684 ), multi->GetNameRequest( caster, NRS_SYSTEM ).c_str() ); // A recall rune for %s. if( tempRuneName.length() > 0 ) { i->SetName( tempRuneName ); @@ -1639,7 +1641,7 @@ bool splMark( CSocket *sock, CChar *caster, CItem *i, [[maybe_unused]] SI08 curS if( caster->GetRegion()->GetName()[0] != 0 ) { - tempitemname = oldstrutil::format( Dictionary->GetEntry( 684 ), caster->GetRegion()->GetName().c_str() ); // A recall rune for %s. + tempitemname = util::format( Dictionary->GetEntry( 684 ), caster->GetRegion()->GetName().c_str() ); // A recall rune for %s. } else { @@ -1933,7 +1935,7 @@ bool splGateTravel( CSocket *sock, CChar *caster, CItem *i, [[maybe_unused]] SI0 TAGMAPOBJECT runeMore = i->GetTag( "multiSerial" ); if( runeMore.m_StringValue != "" ) { - SERIAL mSerial = oldstrutil::value( runeMore.m_StringValue ); + SERIAL mSerial = util::ston( runeMore.m_StringValue ); if( mSerial != 0 && mSerial != INVALIDSERIAL ) { CMultiObj *shipMulti = CalcMultiFromSer( mSerial ); @@ -4552,7 +4554,7 @@ void CMagic::CastSpell( CSocket *s, CChar *caster ) break; } default: - Console.Error( oldstrutil::format( " Unknown Travel spell %i, magic.cpp", curSpell )); + Console.Error( util::format( " Unknown Travel spell %i, magic.cpp", curSpell )); break; } } @@ -4784,7 +4786,7 @@ void CMagic::CastSpell( CSocket *s, CChar *caster ) break; } default: - Console.Error( oldstrutil::format( " Unknown CharacterTarget spell %i, magic.cpp", curSpell )); + Console.Error( util::format( " Unknown CharacterTarget spell %i, magic.cpp", curSpell )); break; } } @@ -4922,7 +4924,7 @@ void CMagic::CastSpell( CSocket *s, CChar *caster ) (*(( MAGIC_LOCFUNC )magic_table[curSpell-1].mag_extra ))( s, caster, x, y, z, curSpell ); break; default: - Console.Error(oldstrutil::format( " Unknown LocationTarget spell %i", curSpell )); + Console.Error(util::format( " Unknown LocationTarget spell %i", curSpell )); break; } } @@ -4966,7 +4968,7 @@ void CMagic::CastSpell( CSocket *s, CChar *caster ) (*(( MAGIC_ITEMFUNC )magic_table[curSpell-1].mag_extra))( s, caster, i, curSpell ); break; default: - Console.Error( oldstrutil::format(" Unknown ItemTarget spell %i, magic.cpp", curSpell )); + Console.Error( util::format(" Unknown ItemTarget spell %i, magic.cpp", curSpell )); break; } } @@ -5004,7 +5006,7 @@ void CMagic::CastSpell( CSocket *s, CChar *caster ) (*(( MAGIC_NOFUNC )magic_table[curSpell-1].mag_extra ))( s, caster, curSpell ); break; default: - Console.Error( oldstrutil::format( " Unknown NonTarget spell %i, magic.cpp", curSpell )); + Console.Error( util::format( " Unknown NonTarget spell %i, magic.cpp", curSpell )); break; } return; @@ -5044,7 +5046,7 @@ void CMagic::LoadScript( void ) auto ssecs = oldstrutil::sections( spEntry, " " ); if( ssecs[0] == "SPELL" ) { - i = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[1], "//" )), nullptr, 0 )); + i = static_cast( std::stoul( util::trim( util::strip( ssecs[1], "//" )), nullptr, 0 )); if( i <= SPELL_MAX ) { ++spellCount; @@ -5056,8 +5058,8 @@ void CMagic::LoadScript( void ) { tag = sec->tag; data = sec->data; - UTag = oldstrutil::upper( tag ); - data = oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )); + UTag = util::upper( tag ); + data = util::trim( util::strip( data, "//" )); //Console.Log( "Tag: %s\tData: %s", "spell.log", UTag.c_str(), data.c_str() ); // Disabled for performance reasons switch(( UTag.data()[0] )) { @@ -5110,8 +5112,8 @@ void CMagic::LoadScript( void ) if( ssecs.size() > 1 ) { // This is used to load flags from old-style spells.dfn, where flags are written as FLAGS=## ## instead of FLAGS=0x#### - spells[i].Flags((( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[0], "//" )), nullptr, 16 ))) << 8 ) | - static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[1], "//" )), nullptr, 16 ))); + spells[i].Flags((( static_cast( std::stoul( util::trim( util::strip( ssecs[0], "//" )), nullptr, 16 ))) << 8 ) | + static_cast( std::stoul( util::trim( util::strip( ssecs[1], "//" )), nullptr, 16 ))); } else { @@ -5164,10 +5166,10 @@ void CMagic::LoadScript( void ) if( ssecs.size() > 1 ) { CMagicMove *mv = spells[i].MoveEffectPtr(); - mv->Effect( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[0], "//" )), nullptr, 16 )), static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[1], "//" )), nullptr, 16 ))); - mv->Speed( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[2], "//" )), nullptr, 16 ))); - mv->Loop( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[3], "//" )), nullptr, 16 ))); - mv->Explode( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[4], "//" )), nullptr, 16 ))); + mv->Effect( static_cast( std::stoul( util::trim( util::strip( ssecs[0], "//" )), nullptr, 16 )), static_cast( std::stoul( util::trim( util::strip( ssecs[1], "//" )), nullptr, 16 ))); + mv->Speed( static_cast( std::stoul( util::trim( util::strip( ssecs[2], "//" )), nullptr, 16 ))); + mv->Loop( static_cast( std::stoul( util::trim( util::strip( ssecs[3], "//" )), nullptr, 16 ))); + mv->Explode( static_cast( std::stoul( util::trim( util::strip( ssecs[4], "//" )), nullptr, 16 ))); } } break; @@ -5198,8 +5200,8 @@ void CMagic::LoadScript( void ) if( ssecs.size() > 1 ) { // This is used to load sounds from old-style spells.dfn, where soundfx are written as SOUNDFX=## ## instead of SOUNDFX=0x#### - spells[i].Effect(((static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[0], "//" )), nullptr, 16 )) << 8 ) | - static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[1], "//" )), nullptr, 16 )))); + spells[i].Effect(((static_cast( std::stoul( util::trim( util::strip( ssecs[0], "//" )), nullptr, 16 )) << 8 ) | + static_cast( std::stoul( util::trim( util::strip( ssecs[1], "//" )), nullptr, 16 )))); } else { @@ -5213,9 +5215,9 @@ void CMagic::LoadScript( void ) { CMagicStat *stat = spells[i].StaticEffectPtr(); - stat->Effect( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[0], "//" )), nullptr, 16 )), static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[1], "//" )), nullptr, 16 ))); - stat->Speed( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[2], "//" )), nullptr, 16 ))); - stat->Loop( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[3], "//" )), nullptr, 16 ))); + stat->Effect( static_cast( std::stoul( util::trim( util::strip( ssecs[0], "//" )), nullptr, 16 )), static_cast( std::stoul( util::trim( util::strip( ssecs[1], "//" )), nullptr, 16 ))); + stat->Speed( static_cast( std::stoul( util::trim( util::strip( ssecs[2], "//" )), nullptr, 16 ))); + stat->Loop( static_cast( std::stoul( util::trim( util::strip( ssecs[3], "//" )), nullptr, 16 ))); } } else if( UTag == "SCLO" ) @@ -5329,7 +5331,7 @@ void HandleCommonGump( CSocket *mSock, CScriptSection *gumpScript, UI16 gumpInde //o------------------------------------------------------------------------------------------------o void CMagic::PolymorphMenu( CSocket *s, UI16 gmindex ) { - std::string sect = "POLYMORPHMENU " + oldstrutil::number( gmindex ); + std::string sect = "POLYMORPHMENU " + util::ntos( gmindex ); CScriptSection *polyStuff = FileLookup->FindEntry( sect, menus_def ); if( polyStuff == nullptr ) return; @@ -5371,7 +5373,7 @@ void CMagic::LogSpell( std::string spell, CChar *player1, CChar *player2, const logDestination.open( logName.c_str(), std::ios::out | std::ios::app ); if( !logDestination.is_open() ) { - Console.Error(oldstrutil::format( "Unable to open spell log file %s!", logName.c_str() )); + Console.Error(util::format( "Unable to open spell log file %s!", logName.c_str() )); return; } char dateTime[1024]; @@ -5399,7 +5401,7 @@ void CMagic::LogSpell( std::string spell, CChar *player1, CChar *player2, const void CMagic::Register( cScript *toRegister, SI32 spellNumber, bool isEnabled ) { #if defined( UOX_DEBUG_MODE ) - Console.Print( oldstrutil::format( "Registering spell number %i\n", spellNumber )); + Console.Print( util::format( "Registering spell number %i\n", spellNumber )); #endif if( spellNumber < 0 || static_cast( spellNumber ) >= spells.size() ) return; diff --git a/source/mapstuff.cpp b/source/mapstuff.cpp index a328e5a84..8d3604bdc 100644 --- a/source/mapstuff.cpp +++ b/source/mapstuff.cpp @@ -4,6 +4,9 @@ #include "cServerDefinitions.h" #include "ssection.h" #include "scriptc.h" + +#include "utility/strutil.hpp" + #include #include @@ -48,8 +51,8 @@ auto CMulHandler::LoadMapsDFN( const std::string &uodir ) -> std::mapcollection() ) { - auto uTag = oldstrutil::upper( sec->tag ); - auto data = oldstrutil::trim( oldstrutil::removeTrailing( sec->data )); + auto uTag = util::upper( sec->tag ); + auto data = util::trim( util::strip( sec->data )); switch( uTag.data()[0] ) { case 'M': @@ -178,8 +181,8 @@ auto CMulHandler::LoadDFNOverrides() -> void if( toScan == nullptr ) continue; - entryNum = oldstrutil::value( oldstrutil::extractSection( entryName, " ", 1, 1 )); - auto titlePart = oldstrutil::upper( oldstrutil::extractSection( entryName, " ", 0, 0 )); + entryNum = util::ston( oldstrutil::extractSection( entryName, " ", 1, 1 )); + auto titlePart = util::upper( oldstrutil::extractSection( entryName, " ", 0, 0 )); // have we got an entry starting with TILE ? if( titlePart == "TILE" && entryNum ) { @@ -191,8 +194,8 @@ auto CMulHandler::LoadDFNOverrides() -> void { for( const auto &sec : toScan->collection() ) { - auto UTag = oldstrutil::upper( sec->tag ); - auto data = oldstrutil::trim( oldstrutil::removeTrailing( sec->data, "//" )); + auto UTag = util::upper( sec->tag ); + auto data = util::trim( util::strip( sec->data, "//" )); // CTile properties if( UTag == "WEIGHT" ) { @@ -1164,7 +1167,7 @@ auto CMulHandler::SeekTile( std::uint16_t tileNum ) -> CTile& { if( !IsValidTile( tileNum )) { - Console.Warning( oldstrutil::format( "Invalid tile access, the offending tile number is %u", tileNum )); + Console.Warning( util::format( "Invalid tile access, the offending tile number is %u", tileNum )); static CTile emptyTile; return emptyTile; } @@ -1178,7 +1181,7 @@ auto CMulHandler::SeekTile( std::uint16_t tileNum ) const -> const CTile& { if( !IsValidTile( tileNum )) { - Console.Warning( oldstrutil::format( "Invalid tile access, the offending tile number is %u", tileNum )); + Console.Warning( util::format( "Invalid tile access, the offending tile number is %u", tileNum )); static CTile emptyTile; return emptyTile; } @@ -1197,7 +1200,7 @@ auto CMulHandler::SeekLand( std::uint16_t landNum ) ->CLand& { if( landNum == INVALIDID || landNum >= tileInfo.SizeTerrain() ) { - Console.Warning( oldstrutil::format( "Invalid land access, the offending land number is %u", landNum )); + Console.Warning( util::format( "Invalid land access, the offending land number is %u", landNum )); static CLand emptyTile; return emptyTile; } @@ -1211,7 +1214,7 @@ auto CMulHandler::SeekLand( std::uint16_t landNum ) const -> const CLand& { if( landNum == INVALIDID || landNum >= tileInfo.SizeTerrain() ) { - Console.Warning( oldstrutil::format( "Invalid land access, the offending land number is %u", landNum )); + Console.Warning( util::format( "Invalid land access, the offending land number is %u", landNum )); static CLand emptyTile; return emptyTile; } diff --git a/source/movement.cpp b/source/movement.cpp index 7aa2e2716..4fa6b61b0 100644 --- a/source/movement.cpp +++ b/source/movement.cpp @@ -49,6 +49,8 @@ #include "cWeather.hpp" #include "Dictionary.h" #include "StringUtility.hpp" +#include "utility/strutil.hpp" + #include "EventTimer.hpp" #include @@ -220,7 +222,7 @@ void CMovement::Walking( CSocket *mSock, CChar *c, UI08 dir, SI16 sequence ) if( !IsValidDirection( dir )) { std::string charName = GetNpcDictName( c, nullptr, NRS_SYSTEM ); - Console.Error( oldstrutil::format( "%s (CMovement::Walking) caught bad direction = %s %d 0x%x\n", DBGFILE, charName.c_str(), dir, dir )); + Console.Error( util::format( "%s (CMovement::Walking) caught bad direction = %s %d 0x%x\n", DBGFILE, charName.c_str(), dir, dir )); // If I don't do this, the NPC will keep trying to walk on the same step, which is // where he's already at. Can cause an infinite loop. (Trust me, was one of the things // that locked up NW Alpha 2) @@ -263,9 +265,9 @@ void CMovement::Walking( CSocket *mSock, CChar *c, UI08 dir, SI16 sequence ) { #if DEBUG_WALKING std::string charName = GetNpcDictName( c, nullptr, NRS_SYSTEM ); - Console.Print( oldstrutil::format( "DEBUG: %s (CMovement::Walking) Character Walk Failed for %s\n", DBGFILE, charName )); - Console.Print( oldstrutil::format( "DEBUG: %s (CMovement::Walking) sx (%d) sy (%d) sz (%d)\n", DBGFILE, oldx, oldy, c->GetZ() )); - Console.Print( oldstrutil::format( "DEBUG: %s (CMovement::Walking) dx (%d) dy (%d) dz (%d)\n", DBGFILE, myx, myy, myz )); + Console.Print( util::format( "DEBUG: %s (CMovement::Walking) Character Walk Failed for %s\n", DBGFILE, charName )); + Console.Print( util::format( "DEBUG: %s (CMovement::Walking) sx (%d) sy (%d) sz (%d)\n", DBGFILE, oldx, oldy, c->GetZ() )); + Console.Print( util::format( "DEBUG: %s (CMovement::Walking) dx (%d) dy (%d) dz (%d)\n", DBGFILE, myx, myy, myz )); #endif if( mSock != nullptr ) { @@ -335,9 +337,9 @@ void CMovement::Walking( CSocket *mSock, CChar *c, UI08 dir, SI16 sequence ) } #if DEBUG_WALKING std::string charName = GetNpcDictName( c, nullptr, NRS_SYSTEM ); - Console.Print( oldstrutil::format( "DEBUG: %s (CMovement::Walking) Character Walk Passed for %s\n", DBGFILE, charName )); - Console.Print( oldstrutil::format( "DEBUG: %s (CMovement::Walking) sx (%d) sy (%d) sz (%d)\n", DBGFILE, oldx, oldy, c->GetZ() )); - Console.Print( oldstrutil::format( "DEBUG: %s (CMovement::Walking) dx (%d) dy (%d) dz (%d)\n", DBGFILE, myx, myy, myz )); + Console.Print( util::format( "DEBUG: %s (CMovement::Walking) Character Walk Passed for %s\n", DBGFILE, charName )); + Console.Print( util::format( "DEBUG: %s (CMovement::Walking) sx (%d) sy (%d) sz (%d)\n", DBGFILE, oldx, oldy, c->GetZ() )); + Console.Print( util::format( "DEBUG: %s (CMovement::Walking) dx (%d) dy (%d) dz (%d)\n", DBGFILE, myx, myy, myz )); #endif if( c->IsNpc() && CheckForCharacterAtXYZ( c, myx, myy, myz )) @@ -359,7 +361,7 @@ void CMovement::Walking( CSocket *mSock, CChar *c, UI08 dir, SI16 sequence ) } #if DEBUG_WALKING std::string charName = GetNpcDictName( c, nullptr, NRS_SYSTEM ); - Console.Print( oldstrutil::format( "DEBUG: Walking() - NPC (%s) failed to pathfind (%d times). Calculating new path!\n", charName.c_str(), c->GetPathFail() )); + Console.Print( util::format( "DEBUG: Walking() - NPC (%s) failed to pathfind (%d times). Calculating new path!\n", charName.c_str(), c->GetPathFail() )); #endif } return; @@ -368,10 +370,10 @@ void CMovement::Walking( CSocket *mSock, CChar *c, UI08 dir, SI16 sequence ) { #if DEBUG_WALKING std::string charName = GetNpcDictName( c, nullptr, NRS_SYSTEM ); - Console.Print( oldstrutil::format( "DEBUG: %s (CMovement::Walking) Character Walk Passed for %s\n", DBGFILE, charName )); - Console.Print( oldstrutil::format( "DEBUG: %s (CMovement::Walking) sx (%d) sy (%d) sz (%d)\n", DBGFILE, oldx, oldy, c->GetZ() )); - Console.Print( oldstrutil::format( "DEBUG: %s (CMovement::Walking) dx (%d) dy (%d) dz (%d)\n", DBGFILE, myx, myy, myz )); - Console.Print( oldstrutil::format( "DEBUG: Walking() - NPC (%s) failed to pathfind (%d times, but less than 10). Invalidating old target location!\n", charName.c_str(), c->GetPathFail() )); + Console.Print( util::format( "DEBUG: %s (CMovement::Walking) Character Walk Passed for %s\n", DBGFILE, charName )); + Console.Print( util::format( "DEBUG: %s (CMovement::Walking) sx (%d) sy (%d) sz (%d)\n", DBGFILE, oldx, oldy, c->GetZ() )); + Console.Print( util::format( "DEBUG: %s (CMovement::Walking) dx (%d) dy (%d) dz (%d)\n", DBGFILE, myx, myy, myz )); + Console.Print( util::format( "DEBUG: Walking() - NPC (%s) failed to pathfind (%d times, but less than 10). Invalidating old target location!\n", charName.c_str(), c->GetPathFail() )); #endif c->FlushPath(); @@ -395,7 +397,7 @@ void CMovement::Walking( CSocket *mSock, CChar *c, UI08 dir, SI16 sequence ) { #if DEBUG_WALKING std::string charName = GetNpcDictName( c, nullptr, NRS_SYSTEM ); - Console.Print( oldstrutil::format( "DEBUG: Walking() - NPC (%s) failed to pathfind %d times! Pausing pathfinding for some time.\n", charName.c_str(), c->GetPathFail() )); + Console.Print( util::format( "DEBUG: Walking() - NPC (%s) failed to pathfind %d times! Pausing pathfinding for some time.\n", charName.c_str(), c->GetPathFail() )); #endif c->FlushPath(); c->SetPathResult( 0 ); // partial success, but blocked by character @@ -504,7 +506,7 @@ bool CMovement::IsFrozen( CChar *c, CSocket *mSock, SI16 sequence ) } #if DEBUG_WALKING std::string charName = GetNpcDictName( c, nullptr, NRS_SYSTEM ); - Console.Print( oldstrutil::format( "DEBUG: %s (CMovement::IsFrozen) casting char %s\n", DBGFILE, charName )); + Console.Print( util::format( "DEBUG: %s (CMovement::IsFrozen) casting char %s\n", DBGFILE, charName )); #endif return true; } @@ -517,7 +519,7 @@ bool CMovement::IsFrozen( CChar *c, CSocket *mSock, SI16 sequence ) } #if DEBUG_WALKING std::string charName = GetNpcDictName( c, nullptr, NRS_SYSTEM ); - Console.Print( oldstrutil::format( "DEBUG: %s (CMovement::IsFrozen) frozen char %s\n", DBGFILE, charName )); + Console.Print( util::format( "DEBUG: %s (CMovement::IsFrozen) frozen char %s\n", DBGFILE, charName )); #endif return true; } @@ -555,7 +557,7 @@ bool CMovement::IsOverloaded( CChar *c, CSocket *mSock, SI16 sequence ) DenyMovement( mSock, c, sequence ); #if DEBUG_WALKING std::string charName = GetNpcDictName( c, nullptr, NRS_SYSTEM ); - Console.Print( oldstrutil::format( "DEBUG: %s (CMovement::Walking) overloaded char %s\n", DBGFILE, charName )); + Console.Print( util::format( "DEBUG: %s (CMovement::Walking) overloaded char %s\n", DBGFILE, charName )); #endif return true; } @@ -810,7 +812,7 @@ auto CMovement::GetBlockingDynamics( SI16 x, SI16 y, std::vector &xyblo if( !tItem->CanBeObjType( OT_MULTI )) { #if DEBUG_WALKING - Console.Print( oldstrutil::format( "DEBUG: Item X: %i\nItem Y: %i\n", tItem->GetX(), tItem->GetY() )); + Console.Print( util::format( "DEBUG: Item X: %i\nItem Y: %i\n", tItem->GetX(), tItem->GetY() )); #endif if( tItem->GetX() == x && tItem->GetY() == y ) { @@ -1696,7 +1698,7 @@ void CMovement::NpcWalk( CChar *i, UI08 j, SI08 getWander ) break; } default: - Console.Error( oldstrutil::format( "Bad NPC Wander type passed to NpcWalk: %i", getWander )); + Console.Error( util::format( "Bad NPC Wander type passed to NpcWalk: %i", getWander )); break; } // If path back can't be found, use alternative route - through the magical ether! (teleport) @@ -1766,7 +1768,7 @@ void CMovement::BoundingBoxTeleport( CChar *nChar, UI16 fx2Actual, UI16 fy2Actua { #if defined( UOX_DEBUG_MODE ) std::string charName = GetNpcDictName( nChar, nullptr, NRS_SYSTEM ); - Console.Warning( oldstrutil::format( "NPC: %s with serial 0x%X was unable to path back to bounding box, teleporting NPC back.\n", charName.c_str(), nChar->GetSerial() )); + Console.Warning( util::format( "NPC: %s with serial 0x%X was unable to path back to bounding box, teleporting NPC back.\n", charName.c_str(), nChar->GetSerial() )); #endif nChar->SetLocation( m, n, fz1, nChar->WorldNumber(), nChar->GetInstanceId() ); nChar->SetNpcWander( nChar->GetOldNpcWander() ); @@ -1778,7 +1780,7 @@ void CMovement::BoundingBoxTeleport( CChar *nChar, UI16 fx2Actual, UI16 fy2Actua // If a valid teleport-location hasn't been found at this point, despawn NPC #if defined( UOX_DEBUG_MODE ) std::string charName = GetNpcDictName( nChar, nullptr, NRS_SYSTEM ); - Console.Warning( oldstrutil::format( "NPC: %s with serial 0x%X was unable to path back to bounding box, no valid teleport location found. Deleting NPC!\n", charName.c_str(), nChar->GetSerial() )); + Console.Warning( util::format( "NPC: %s with serial 0x%X was unable to path back to bounding box, no valid teleport location found. Deleting NPC!\n", charName.c_str(), nChar->GetSerial() )); #endif nChar->Delete(); } @@ -2268,7 +2270,7 @@ void CMovement::NpcMovement( CChar& mChar ) { #if DEBUG_NPCWALK std::string charName = GetNpcDictName( mChar, nullptr, NRS_SYSTEM ); - Console.Print( oldstrutil::format( "DEBUG: ENTER (%s): %d AI %d WAR %d J\n", charName, mChar.GetNpcWander(), mChar.IsAtWar(), j )); + Console.Print( util::format( "DEBUG: ENTER (%s): %d AI %d WAR %d J\n", charName, mChar.GetNpcWander(), mChar.IsAtWar(), j )); #endif bool shouldRun = false; if( mChar.IsAtWar() && mChar.GetNpcWander() != WT_FLEE && ( mChar.GetNpcWander() != WT_SCARED || ( ValidateObject( mChar.GetTarg() ) && GetDist( &mChar, mChar.GetTarg() ) <= 1 ))) @@ -2313,7 +2315,7 @@ void CMovement::NpcMovement( CChar& mChar ) mChar.SetHP( mChar.GetMaxHP() ); mChar.SetEvadeState( true ); Combat->InvalidateAttacker( &mChar ); - //Console.Warning( oldstrutil::format( "EvadeTimer started for NPC (%s, 0x%X, at %i, %i, %i, %i). Could no longer see or reach target.\n", mChar.GetName().c_str(), mChar.GetSerial(), mChar.GetX(), mChar.GetY(), mChar.GetZ(), mChar.WorldNumber() )); + //Console.Warning( util::format( "EvadeTimer started for NPC (%s, 0x%X, at %i, %i, %i, %i). Could no longer see or reach target.\n", mChar.GetName().c_str(), mChar.GetSerial(), mChar.GetX(), mChar.GetY(), mChar.GetZ(), mChar.WorldNumber() )); std::vector scriptTriggers = mChar.GetScriptTriggers(); for( auto scriptTrig : scriptTriggers ) @@ -2440,7 +2442,7 @@ void CMovement::NpcMovement( CChar& mChar ) mChar.SetEvadeState( true ); IgnoreAndEvadeTarget( &mChar ); Combat->InvalidateAttacker( &mChar ); - //Console.Warning( oldstrutil::format( "EvadeTimer started for NPC (%s, 0x%X, at %i, %i, %i, %i).\n", mChar.GetName().c_str(), mChar.GetSerial(), mChar.GetX(), mChar.GetY(), mChar.GetZ(), mChar.WorldNumber() )); + //Console.Warning( util::format( "EvadeTimer started for NPC (%s, 0x%X, at %i, %i, %i, %i).\n", mChar.GetName().c_str(), mChar.GetSerial(), mChar.GetX(), mChar.GetY(), mChar.GetZ(), mChar.WorldNumber() )); std::vector scriptTriggers = mChar.GetScriptTriggers(); for( auto scriptTrig : scriptTriggers ) @@ -3385,7 +3387,7 @@ bool CMovement::AdvancedPathfinding( CChar *mChar, UI16 targX, UI16 targY, bool { #if defined( UOX_DEBUG_MODE ) std::string charName = GetNpcDictName( mChar, nullptr, NRS_SYSTEM ); - Console.Warning( oldstrutil::format( "AdvancedPathfinding: NPC (%s at %i %i %i %i) unable to find a path, max steps limit (%i) reached, aborting.\n", + Console.Warning( util::format( "AdvancedPathfinding: NPC (%s at %i %i %i %i) unable to find a path, max steps limit (%i) reached, aborting.\n", charName.c_str(), mChar->GetX(), mChar->GetY(), mChar->GetZ(), mChar->WorldNumber(), maxSteps )); #endif if( !cwmWorldState->creatures[mChar->GetId()].IsWater() || mChar->GetPathFail() == 20 ) @@ -3424,7 +3426,7 @@ bool CMovement::AdvancedPathfinding( CChar *mChar, UI16 targX, UI16 targY, bool else { #if defined( UOX_DEBUG_MODE ) - Console.Print( oldstrutil::format( "AdvancedPathfinding: %u loops to find path.\n", loopCtr )); + Console.Print( util::format( "AdvancedPathfinding: %u loops to find path.\n", loopCtr )); #endif if( GetDist( mChar->GetLocation(), Point3_st( targX, targY, curZ )) > 1 ) { diff --git a/source/msgboard.cpp b/source/msgboard.cpp index 7e1fb4a43..bfb10d896 100644 --- a/source/msgboard.cpp +++ b/source/msgboard.cpp @@ -32,6 +32,7 @@ #include "classes.h" #include "Dictionary.h" #include "StringUtility.hpp" +#include "utility/strutil.hpp" #include "osunique.hpp" #include @@ -55,10 +56,10 @@ std::string GetMsgBoardFile( const SERIAL msgBoardSer, const UI08 msgType ) CTownRegion *mbRegion; msgBoard = CalcItemObjFromSer( msgBoardSer ); mbRegion = CalcRegionFromXY( msgBoard->GetX(), msgBoard->GetY(), msgBoard->WorldNumber(), msgBoard->GetInstanceId() ); - fileName = std::string( "region" ) + oldstrutil::number( mbRegion->GetRegionNum() ) + std::string( ".bbf" ); + fileName = std::string( "region" ) + util::ntos( mbRegion->GetRegionNum() ) + std::string( ".bbf" ); break; case PT_LOCAL: - fileName = oldstrutil::number( msgBoardSer, 16 ) + std::string( ".bbf" ); + fileName = util::ntos( msgBoardSer, 16 ) + std::string( ".bbf" ); break; default: Console.Error( "GetMsgBoardFile() Invalid post type, aborting" ); @@ -224,7 +225,7 @@ void MsgBoardList( CSocket *mSock ) if( file.fail() ) { - Console.Warning( oldstrutil::format( "Malformed MessageBoard post, MessageID: 0x%X", msgBoardPost.serial )); + Console.Warning( util::format( "Malformed MessageBoard post, MessageID: 0x%X", msgBoardPost.serial )); file.close(); } else @@ -253,7 +254,7 @@ void MsgBoardList( CSocket *mSock ) if( !mSock->FinishedPostAck() ) { mSock->PostClear(); - Console.Error( oldstrutil::format( "Failed to list all posts for MessageBoard ID: 0x%X", mSock->GetDWord( 4 ))); + Console.Error( util::format( "Failed to list all posts for MessageBoard ID: 0x%X", mSock->GetDWord( 4 ))); } } @@ -287,7 +288,7 @@ bool GetMaxSerial( const std::string& fileName, UI08 *nextMsgId, const PostTypes if( nextMsgId[1] == 0xFF && nextMsgId[2] == 0xFF && nextMsgId[3] == 0xFF ) { - Console.Warning( oldstrutil::format( "Maximum Posts reached for board %s, no further posts can be created", fileName.c_str() )); + Console.Warning( util::format( "Maximum Posts reached for board %s, no further posts can be created", fileName.c_str() )); return false; } @@ -395,7 +396,7 @@ SERIAL MsgBoardWritePost( MsgBoardPost_st& msgBoardPost, const std::string& file lcltime( timet, timeOfPost ); lcltime( timet, timeOfPost ); - auto time = oldstrutil::format( "Day %i @ %i:%02i\0", ( timeOfPost.tm_yday + 1 ), timeOfPost.tm_hour, timeOfPost.tm_min ); + auto time = util::format( "Day %i @ %i:%02i\0", ( timeOfPost.tm_yday + 1 ), timeOfPost.tm_hour, timeOfPost.tm_min ); time.resize( time.size() + 1 ); const UI08 timeSize = static_cast( time.size() ); const UI08 posterSize = static_cast( msgBoardPost.posterLen ); @@ -639,7 +640,7 @@ void MsgBoardOpenPost( CSocket *mSock ) } else { - Console.Error( oldstrutil::format( "Failed to open MessageBoard file for reading MessageID: 0x%X", msgSerial) ); + Console.Error( util::format( "Failed to open MessageBoard file for reading MessageID: 0x%X", msgSerial) ); } if( foundEntry ) @@ -649,7 +650,7 @@ void MsgBoardOpenPost( CSocket *mSock ) } else { - Console.Warning( oldstrutil::format( "Failed to find MessageBoard file for MessageID: 0x%X", msgSerial )); + Console.Warning( util::format( "Failed to find MessageBoard file for MessageID: 0x%X", msgSerial )); } } @@ -715,7 +716,7 @@ void MsgBoardRemovePost( CSocket *mSock ) { mSock->SysMessage( 9038 ); // Failed to remove post; file size not found! Check server log for more details. } - Console.Error( oldstrutil::format( "Could not fetch file size for file %s", fileName.c_str() )); + Console.Error( util::format( "Could not fetch file size for file %s", fileName.c_str() )); return; } @@ -804,7 +805,7 @@ void MsgBoardRemovePost( CSocket *mSock ) } else { - Console.Error( oldstrutil::format( "Could not open file %s for reading", fileName.c_str() )); + Console.Error( util::format( "Could not open file %s for reading", fileName.c_str() )); } // If we found the post to remove previously, remove it at this point, since all potential replies to it have been removed already @@ -860,7 +861,7 @@ auto MsgBoardPostQuest( CChar *mNPC, const QuestTypes questType ) -> bool { MsgBoardPost_st msgBoardPost; std::string sect, tag, data; - auto fileName = "region"s + oldstrutil::number( mNPC->GetQuestOrigRegion() ) + ".bbf"s; + auto fileName = "region"s + util::ntos( mNPC->GetQuestOrigRegion() ) + ".bbf"s; CScriptSection *EscortData = nullptr, *Escort = nullptr; size_t totalEntries = 0; std::string tmpSubject = ""; @@ -888,7 +889,7 @@ auto MsgBoardPostQuest( CChar *mNPC, const QuestTypes questType ) -> bool EscortData = FileLookup->FindEntry( sect, msgboard_def ); if( EscortData == nullptr ) { - Console.Error( oldstrutil::format( "MsgBoardPostQuest() Couldn't find entry %s", sect.c_str() )); + Console.Error( util::format( "MsgBoardPostQuest() Couldn't find entry %s", sect.c_str() )); return false; } for( const auto &sec : EscortData->collection() ) @@ -906,7 +907,7 @@ auto MsgBoardPostQuest( CChar *mNPC, const QuestTypes questType ) -> bool position = fullLine.find( "%l" ); while( position != std::string::npos ) { - fullLine.replace( position, 2, oldstrutil::format( "%d %d", mNPC->GetX(), mNPC->GetY() )); + fullLine.replace( position, 2, util::format( "%d %d", mNPC->GetX(), mNPC->GetY() )); position = fullLine.find( "%l" ); } @@ -945,7 +946,7 @@ auto MsgBoardPostQuest( CChar *mNPC, const QuestTypes questType ) -> bool msgBoardPost.toggle = QT_ITEMQUEST; break; default: - Console.Error( oldstrutil::format( "MsgBoardPostQuest() Invalid questType %d", questType )); + Console.Error( util::format( "MsgBoardPostQuest() Invalid questType %d", questType )); return false; } @@ -994,7 +995,7 @@ void MsgBoardQuestEscortCreate( CChar *mNPC ) // Abort out if there are no valid escort region candidates if( regionCandidates.empty() ) { - Console.Error( oldstrutil::format( "MsgBoardQuestEscortCreate() No valid regions defined for escort quests" ) ); + Console.Error( util::format( "MsgBoardQuestEscortCreate() No valid regions defined for escort quests" ) ); mNPC->Delete(); return; } @@ -1017,7 +1018,7 @@ void MsgBoardQuestEscortCreate( CChar *mNPC ) if( !MsgBoardPostQuest( mNPC, QT_ESCORTQUEST )) { - Console.Error( oldstrutil::format( "MsgBoardQuestEscortCreate() Failed to add quest post for %s", mNPC->GetName().c_str() )); + Console.Error( util::format( "MsgBoardQuestEscortCreate() Failed to add quest post for %s", mNPC->GetName().c_str() )); mNPC->Delete(); } } @@ -1088,7 +1089,7 @@ void MsgBoardQuestEscortRemovePost( CChar *mNPC ) fileName = cwmWorldState->ServerData()->Directory( CSDDP_MSGBOARD ); } - fileName += std::string( "region" ) + oldstrutil::number( mNPC->GetQuestOrigRegion() ) + std::string( ".bbf" ); + fileName += std::string( "region" ) + util::ntos( mNPC->GetQuestOrigRegion() ) + std::string( ".bbf" ); std::size_t fileSize = 0; try { @@ -1138,7 +1139,7 @@ void MsgBoardQuestEscortRemovePost( CChar *mNPC ) } else { - Console.Error( oldstrutil::format( "Attempting to seek past end of file in %s", fileName.c_str() )); + Console.Error( util::format( "Attempting to seek past end of file in %s", fileName.c_str() )); break; } } @@ -1147,7 +1148,7 @@ void MsgBoardQuestEscortRemovePost( CChar *mNPC ) } else { - Console.Error( oldstrutil::format( "Could not open file %s for reading", fileName.c_str() )); + Console.Error( util::format( "Could not open file %s for reading", fileName.c_str() )); } } @@ -1166,11 +1167,11 @@ void MsgBoardRemoveFile( const SERIAL msgBoardSer ) fileName = cwmWorldState->ServerData()->Directory( CSDDP_MSGBOARD ); } - fileName += oldstrutil::number( msgBoardSer, 16 ) + std::string( ".bbf" ); + fileName += util::ntos( msgBoardSer, 16 ) + std::string( ".bbf" ); [[maybe_unused]] int removeResult = remove( fileName.c_str() ); - Console.Print( oldstrutil::format( "Deleted MessageBoard file for Board Serial 0x%X\n", msgBoardSer )); + Console.Print( util::format( "Deleted MessageBoard file for Board Serial 0x%X\n", msgBoardSer )); } //o------------------------------------------------------------------------------------------------o @@ -1243,7 +1244,7 @@ void MsgBoardMaintenance( void ) } else { - Console.Error( oldstrutil::format( "Failed to open MessageBoard file for reading: %s", entry.path().string().c_str() )); + Console.Error( util::format( "Failed to open MessageBoard file for reading: %s", entry.path().string().c_str() )); } } } diff --git a/source/network.cpp b/source/network.cpp index 27104f6ea..97cc8811b 100644 --- a/source/network.cpp +++ b/source/network.cpp @@ -18,6 +18,7 @@ #include "ObjectFactory.h" #include "StringUtility.hpp" +#include "utility/strutil.hpp" #include "osunique.hpp" #if PLATFORM != WINDOWS @@ -493,7 +494,7 @@ void CNetworkStuff::sockInit( void ) { Console.Error( " Unable to create socket"); #if PLATFORM == WINDOWS - Console.Error( oldstrutil::format( " Code %i", WSAGetLastError() )); + Console.Error( util::format( " Code %i", WSAGetLastError() )); #else Console << myendl; #endif @@ -516,7 +517,7 @@ void CNetworkStuff::sockInit( void ) if( bcode < 0 ) { - Console.Error( oldstrutil::format( " Unable to bind socket 1 - Error code: %i", bcode )); + Console.Error( util::format( " Unable to bind socket 1 - Error code: %i", bcode )); cwmWorldState->SetKeepRun( false ); cwmWorldState->SetError( true ); Shutdown( FATAL_UOX3_ALLOC_NETWORK ); @@ -619,14 +620,14 @@ void CNetworkStuff::CheckConn( void ) if( IsFirewallBlocked( part )) { - messageLoop << oldstrutil::format( "FIREWALL: Blocking address %i.%i.%i.%i --> Blocked!", part[0], part[1], part[2], part[3] ); + messageLoop << util::format( "FIREWALL: Blocking address %i.%i.%i.%i --> Blocked!", part[0], part[1], part[2], part[3] ); closesocket( static_cast( newClient )); delete toMake; return; } //Firewall-messages are really only needed when firewall blocks, not when it lets someone through. Leads to information overload in console. Commenting out. - messageLoop << oldstrutil::format( "Client %zu [%i.%i.%i.%i] connected [Total:%lu]", cwmWorldState->GetPlayersOnline(), part[0], part[1], part[2], part[3], cwmWorldState->GetPlayersOnline() + 1 ); + messageLoop << util::format( "Client %zu [%i.%i.%i.%i] connected [Total:%lu]", cwmWorldState->GetPlayersOnline(), part[0], part[1], part[2], part[3], cwmWorldState->GetPlayersOnline() + 1 ); loggedInClients.push_back( toMake ); toMake->ClientIP( client_addr.sin_addr.s_addr ); return; @@ -799,7 +800,7 @@ void CNetworkStuff::GetMsg( UOXSOCKET s ) total -= mi * 60; se = total; - auto uoxmonitor = oldstrutil::format( "UOX LoginServer\r\nUOX3 Server: up for %ih %im %is\r\n", ho, mi, se ); + auto uoxmonitor = util::format( "UOX LoginServer\r\nUOX3 Server: up for %ih %im %is\r\n", ho, mi, se ); mSock->Send( uoxmonitor.c_str(), static_cast( uoxmonitor.size() )); mSock->NewClient( false ); } @@ -837,7 +838,7 @@ void CNetworkStuff::GetMsg( UOXSOCKET s ) return; } #if _DEBUG_PACKET - Console.Print( oldstrutil::format( "Packet ID: 0x%x\n", packetId )); + Console.Print( util::format( "Packet ID: 0x%x\n", packetId )); #endif if( packetId != 0x73 && packetId != 0xA4 && packetId != 0x80 && packetId != 0x91 ) { @@ -1188,7 +1189,7 @@ void CNetworkStuff::GetMsg( UOXSOCKET s ) mSock->Receive( MAXBUFFER ); } - Console << oldstrutil::format( "Unknown message from client: 0x%02X - Ignored", packetId ) << myendl; + Console << util::format( "Unknown message from client: 0x%02X - Ignored", packetId ) << myendl; break; } } @@ -1257,7 +1258,7 @@ void CNetworkStuff::CheckLoginMessage( void ) } else if( blah.ErrorNumber() != -1 ) { - messageLoop << oldstrutil::format( "Socket error: %i", blah.ErrorNumber() ); + messageLoop << util::format( "Socket error: %i", blah.ErrorNumber() ); } #endif LoginDisconnect( static_cast( i )); // abnormal error @@ -1284,7 +1285,7 @@ void CNetworkStuff::CheckLoginMessage( void ) //o------------------------------------------------------------------------------------------------o void CNetworkStuff::LoginDisconnect( UOXSOCKET s ) { - messageLoop << oldstrutil::format( "LoginClient %u disconnected.", s ); + messageLoop << util::format( "LoginClient %u disconnected.", s ); loggedInClients[s]->FlushBuffer(); loggedInClients[s]->CloseSocket(); @@ -1405,18 +1406,18 @@ void CNetworkStuff::GetLoginMsg( UOXSOCKET s ) // April 5, 2004 - Hmmm there are two of these ? if( cwmWorldState->ServerData()->ServerUOGEnabled() ) { - messageLoop << oldstrutil::format( "UOG Stats Sent or Encrypted client detected. [%i.%i.%i.%i]", mSock->ClientIP4(), mSock->ClientIP3(), mSock->ClientIP2(), mSock->ClientIP1() ); + messageLoop << util::format( "UOG Stats Sent or Encrypted client detected. [%i.%i.%i.%i]", mSock->ClientIP4(), mSock->ClientIP3(), mSock->ClientIP2(), mSock->ClientIP1() ); } else { - messageLoop << oldstrutil::format( "Encrypted client detected. [%i.%i.%i.%i]", mSock->ClientIP4(), mSock->ClientIP3(), mSock->ClientIP2(), mSock->ClientIP1() ); + messageLoop << util::format( "Encrypted client detected. [%i.%i.%i.%i]", mSock->ClientIP4(), mSock->ClientIP3(), mSock->ClientIP2(), mSock->ClientIP1() ); } LoginDisconnect( s ); return; } else if( mSock->FirstPacket() && packetId == 0 ) { - messageLoop << oldstrutil::format( "Buffer is empty, no packets to read. Disconnecting client. [%i.%i.%i.%i]", mSock->ClientIP4(), mSock->ClientIP3(), mSock->ClientIP2(), mSock->ClientIP1() ); + messageLoop << util::format( "Buffer is empty, no packets to read. Disconnecting client. [%i.%i.%i.%i]", mSock->ClientIP4(), mSock->ClientIP3(), mSock->ClientIP2(), mSock->ClientIP1() ); LoginDisconnect( s ); return; } @@ -1442,14 +1443,14 @@ void CNetworkStuff::GetLoginMsg( UOXSOCKET s ) } catch( socket_error& ) { - Console.Warning( oldstrutil::format( "Bad packet request thrown! [packet ID: 0x%x]", packetId )); + Console.Warning( util::format( "Bad packet request thrown! [packet ID: 0x%x]", packetId )); mSock->FlushIncoming(); return; } if( test != nullptr ) { #ifdef _DEBUG_PACKET - Console.Log( oldstrutil::format( "Logging packet ID: 0x%X", packetId ), "loginthread.txt" ); + Console.Log( util::format( "Logging packet ID: 0x%X", packetId ), "loginthread.txt" ); #endif mSock->ReceiveLogging( test ); if( test->Handle() ) @@ -1495,7 +1496,7 @@ void CNetworkStuff::GetLoginMsg( UOXSOCKET s ) { mSock->Receive( MAXBUFFER ); } - messageLoop << oldstrutil::format( "Unknown message from client: 0x%02X - Ignored", packetId ); + messageLoop << util::format( "Unknown message from client: 0x%02X - Ignored", packetId ); break; } } @@ -1551,9 +1552,9 @@ auto CNetworkStuff::LoadFirewallEntries() -> void { auto tag = sec->tag; auto data = sec->data; - if( oldstrutil::upper( tag ) == "IP" ) + if( util::upper( tag ) == "IP" ) { - data = oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )); + data = util::trim( util::strip( data, "//" )); if( !data.empty() ) { auto psecs = oldstrutil::sections( data, "." ); @@ -1575,7 +1576,7 @@ auto CNetworkStuff::LoadFirewallEntries() -> void } else if( data != "\n" && data != "\r" ) { - Console.Error( oldstrutil::format( "Malformed IP address in banlist.ini (line: %s)", data.c_str() )); + Console.Error( util::format( "Malformed IP address in banlist.ini (line: %s)", data.c_str() )); } } } diff --git a/source/npcs.cpp b/source/npcs.cpp index 137421861..a27be036d 100644 --- a/source/npcs.cpp +++ b/source/npcs.cpp @@ -17,6 +17,7 @@ #include "Dictionary.h" #include "ObjectFactory.h" +#include "utility/strutil.hpp" using namespace std::string_literals; @@ -51,22 +52,22 @@ auto CCharStuff::AddRandomLoot( CItem *s, const std::string& lootlist, bool shou i = RandomNum( static_cast( 0 ), i - 1 ); std::string tag = lootList->MoveTo( i ); std::string tagData = lootList->GrabData(); - auto csecs = oldstrutil::sections( oldstrutil::trim( oldstrutil::removeTrailing( tagData, "//" )), "," ); - auto tcsecs = oldstrutil::sections( oldstrutil::trim( oldstrutil::removeTrailing( tag, "//" )), "," ); + auto csecs = oldstrutil::sections( util::trim( util::strip( tagData, "//" )), "," ); + auto tcsecs = oldstrutil::sections( util::trim( util::strip( tag, "//" )), "," ); if( !tag.empty() ) { UI16 iAmount = 0; - if( oldstrutil::upper( tag ) == "LOOTLIST" ) + if( util::upper( tag ) == "LOOTLIST" ) { if( csecs.size() > 1 ) // Amount specified behind lootlist entry? { - iAmount = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 )); + iAmount = static_cast( std::stoul( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 )); [[maybe_unused]] CItem *retItemNested = nullptr; for( UI16 iCount = 0; iCount < iAmount; ++iCount ) { - retItemNested = AddRandomLoot( s, oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), shouldSave ); + retItemNested = AddRandomLoot( s, util::trim( util::strip( csecs[0], "//" )), shouldSave ); } } else @@ -78,8 +79,8 @@ auto CCharStuff::AddRandomLoot( CItem *s, const std::string& lootlist, bool shou { if( tcsecs.size() > 1 ) // Amount specified behind lootlist entry? { - iAmount = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( tcsecs[1], "//" )), nullptr, 0 )); - retItem = Items->CreateBaseScriptItem( s, oldstrutil::trim( oldstrutil::removeTrailing( tcsecs[0], "//" )), s->WorldNumber(), iAmount, s->GetInstanceId(), OT_ITEM, 0xFFFF, shouldSave ); + iAmount = static_cast( std::stoul( util::trim( util::strip( tcsecs[1], "//" )), nullptr, 0 )); + retItem = Items->CreateBaseScriptItem( s, util::trim( util::strip( tcsecs[0], "//" )), s->WorldNumber(), iAmount, s->GetInstanceId(), OT_ITEM, 0xFFFF, shouldSave ); if( retItem ) { retItem->SetCont( s ); @@ -110,11 +111,11 @@ auto CCharStuff::AddRandomLoot( CItem *s, const std::string& lootlist, bool shou //o------------------------------------------------------------------------------------------------o CChar *CCharStuff::CreateBaseNPC( std::string ourNPC, bool shouldSave ) { - ourNPC = oldstrutil::trim( oldstrutil::removeTrailing( ourNPC, "//" )); + ourNPC = util::trim( util::strip( ourNPC, "//" )); CScriptSection *npcCreate = FileLookup->FindEntry( ourNPC, npc_def ); if( npcCreate == nullptr ) { - Console.Error( oldstrutil::format( "CreateBaseNPC(): Bad script npc %s (NPC Not Found).", ourNPC.c_str() )); + Console.Error( util::format( "CreateBaseNPC(): Bad script npc %s (NPC Not Found).", ourNPC.c_str() )); return nullptr; } @@ -234,7 +235,7 @@ auto CCharStuff::ChooseNpcToCreate( const std::vector std::string { auto sect = "NPCLIST "s + npclist; - sect = oldstrutil::trim( oldstrutil::removeTrailing( sect, "//" )); + sect = util::trim( util::strip( sect, "//" )); auto npcList = FileLookup->FindEntry( sect, npc_def ); if( !npcList ) @@ -249,12 +250,12 @@ auto CCharStuff::NpcListLookup( const std::string &npclist ) -> std::string for( size_t i = 0; i < npcListSize; i++ ) { // Split string for entry into a stringlist based on | as separator - auto csecs = oldstrutil::sections( oldstrutil::trim( oldstrutil::removeTrailing( npcList->MoveTo( i ), "//" )), "|" ); + auto csecs = oldstrutil::sections( util::trim( util::strip( npcList->MoveTo( i ), "//" )), "|" ); UI16 sectionWeight = 1; if( csecs.size() > 1 ) { - sectionWeight = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 )); + sectionWeight = static_cast( std::stoul( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 )); } auto npcSection = ( csecs.size() > 1 ? csecs[1] : csecs[0] ); @@ -265,8 +266,8 @@ auto CCharStuff::NpcListLookup( const std::string &npclist ) -> std::string if( chosenNpcSection.empty() ) return ""; - auto csecs = oldstrutil::sections( oldstrutil::trim( oldstrutil::removeTrailing( chosenNpcSection, "//" )), "=" ); - if( oldstrutil::upper( csecs[0] ) == "NPCLIST" ) + auto csecs = oldstrutil::sections( util::trim( util::strip( chosenNpcSection, "//" )), "=" ); + if( util::upper( csecs[0] ) == "NPCLIST" ) { // Chosen entry contained another NPCLIST! Let's dive back into it... chosenNpcSection = NpcListLookup( chosenNpcSection ); @@ -284,7 +285,7 @@ auto CCharStuff::NpcListLookup( const std::string &npclist ) -> std::string auto CCharStuff::CreateRandomNPC( const std::string &npclist ) -> CChar * { auto sect = "NPCLIST "s + npclist; - sect = oldstrutil::trim( oldstrutil::removeTrailing( sect, "//" )); + sect = util::trim( util::strip( sect, "//" )); auto npcList = FileLookup->FindEntry( sect, npc_def ); if( !npcList ) @@ -299,12 +300,12 @@ auto CCharStuff::CreateRandomNPC( const std::string &npclist ) -> CChar * for( size_t i = 0; i < npcListSize; i++ ) { // Split string for entry into a stringlist based on | as separator - auto csecs = oldstrutil::sections( oldstrutil::trim( oldstrutil::removeTrailing( npcList->MoveTo( i ), "//" )), "|" ); + auto csecs = oldstrutil::sections( util::trim( util::strip( npcList->MoveTo( i ), "//" )), "|" ); UI16 sectionWeight = 1; if( csecs.size() > 1 ) { - sectionWeight = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 )); + sectionWeight = static_cast( std::stoul( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 )); } auto npcSection = ( csecs.size() > 1 ? csecs[1] : csecs[0] ); @@ -316,8 +317,8 @@ auto CCharStuff::CreateRandomNPC( const std::string &npclist ) -> CChar * return nullptr; CChar *cCreated = nullptr; - auto csecs = oldstrutil::sections( oldstrutil::trim( oldstrutil::removeTrailing( chosenNpcSection, "//" )), "=" ); - if( oldstrutil::upper( csecs[0] ) == "NPCLIST" ) + auto csecs = oldstrutil::sections( util::trim( util::strip( chosenNpcSection, "//" )), "=" ); + if( util::upper( csecs[0] ) == "NPCLIST" ) { // Chosen entry contained another NPCLIST! Let's dive back into it... cCreated = CreateRandomNPC( npcList->GrabData() ); @@ -569,7 +570,7 @@ void CCharStuff::FindSpotForNPC( CChar *cCreated, const SI16 originX, const SI16 { #ifdef DEBUG_SPAWN - Console.Print( oldstrutil::format( "Going to spawn at (%d,%d) within %d by %d\n", originX, originY, xAway, yAway )); + Console.Print( util::format( "Going to spawn at (%d,%d) within %d by %d\n", originX, originY, xAway, yAway )); #endif if( !ValidateObject( cCreated )) @@ -632,7 +633,7 @@ auto CCharStuff::LoadShopList( const std::string& list, CChar *c ) -> void auto sellLayer = c->GetItemAtLayer( IL_SELLCONTAINER ); //Contains items the NPC will sell auto sect = "SHOPLIST "s + list; - sect = oldstrutil::trim( oldstrutil::removeTrailing( sect, "//" )); + sect = util::trim( util::strip( sect, "//" )); auto ShoppingList = FileLookup->FindEntry( sect, items_def ); if( ShoppingList == nullptr ) return; @@ -720,8 +721,8 @@ auto CCharStuff::LoadShopList( const std::string& list, CChar *c ) -> void auto ssecs = oldstrutil::sections( cdata, " " ); if( ssecs.size() > 1 ) { - retItem->SetBuyValue( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[0], "//" )), nullptr, 0 ))); - retItem->SetSellValue( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[1], "//" )), nullptr, 0 ))); + retItem->SetBuyValue( static_cast( std::stoul( util::trim( util::strip( ssecs[0], "//" )), nullptr, 0 ))); + retItem->SetSellValue( static_cast( std::stoul( util::trim( util::strip( ssecs[1], "//" )), nullptr, 0 ))); break; } } @@ -743,7 +744,7 @@ auto CCharStuff::LoadShopList( const std::string& list, CChar *c ) -> void void SetRandomName( CChar *s, const std::string& namelist ) { std::string sect = std::string( "RANDOMNAME " ) + namelist; - sect = oldstrutil::trim( oldstrutil::removeTrailing( sect, "//" )); + sect = util::trim( util::strip( sect, "//" )); std::string tempName; CScriptSection *RandomName = FileLookup->FindEntry( sect, npc_def ); @@ -771,11 +772,11 @@ void SetRandomName( CChar *s, const std::string& namelist ) UI16 AddRandomColor( const std::string& colorlist ) { std::string sect = std::string( "RANDOMCOLOR " ) + colorlist; - sect = oldstrutil::trim( oldstrutil::removeTrailing( sect, "//" )); + sect = util::trim( util::strip( sect, "//" )); CScriptSection *RandomColours = FileLookup->FindEntry( sect, colors_def ); if( RandomColours == nullptr ) { - Console.Warning( oldstrutil::format( "Error Colorlist %s Not Found", colorlist.c_str() )); + Console.Warning( util::format( "Error Colorlist %s Not Found", colorlist.c_str() )); return 0; } size_t i = RandomColours->NumEntries(); @@ -783,7 +784,7 @@ UI16 AddRandomColor( const std::string& colorlist ) { i = RandomNum( static_cast( 0 ), i - 1 ); std::string tag = RandomColours->MoveTo( static_cast( i )); - return static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( tag, "//" )), nullptr, 0 )); + return static_cast( std::stoul( util::trim( util::strip( tag, "//" )), nullptr, 0 )); } return 0; } @@ -853,7 +854,7 @@ auto CCharStuff::ApplyNpcSection( CChar *applyTo, CScriptSection *NpcCreation, s cdata = sec->cdata; ndata = sec->ndata; odata = sec->odata; - cdata = oldstrutil::trim( oldstrutil::removeTrailing( cdata, "//" )); + cdata = util::trim( util::strip( cdata, "//" )); auto ssects = oldstrutil::sections( cdata, " " ); auto csects = oldstrutil::sections( cdata, "," ); switch( tag ) @@ -880,7 +881,7 @@ auto CCharStuff::ApplyNpcSection( CChar *applyTo, CScriptSection *NpcCreation, s } else { - Console.Warning( oldstrutil::format( "Invalid data found in ATT/DAMAGE tag inside NPC script [%s]", sectionId.c_str() )); + Console.Warning( util::format( "Invalid data found in ATT/DAMAGE tag inside NPC script [%s]", sectionId.c_str() )); } break; case DFNTAG_AWAKE: @@ -978,7 +979,7 @@ auto CCharStuff::ApplyNpcSection( CChar *applyTo, CScriptSection *NpcCreation, s } else { - Console.Warning( oldstrutil::format( "Invalid data found in DEX tag inside NPC script [%s]", sectionId.c_str() )); + Console.Warning( util::format( "Invalid data found in DEX tag inside NPC script [%s]", sectionId.c_str() )); } break; case DFNTAG_DETECTINGHIDDEN: skillToSet = DETECTINGHIDDEN; break; @@ -996,7 +997,7 @@ auto CCharStuff::ApplyNpcSection( CChar *applyTo, CScriptSection *NpcCreation, s } else { - Console.Warning( oldstrutil::format( "Invalid data found in DEF tag inside NPC script [%s]", sectionId.c_str() )); + Console.Warning( util::format( "Invalid data found in DEF tag inside NPC script [%s]", sectionId.c_str() )); } break; case DFNTAG_DEFBONUS: @@ -1013,13 +1014,13 @@ auto CCharStuff::ApplyNpcSection( CChar *applyTo, CScriptSection *NpcCreation, s } else { - Console.Warning( oldstrutil::format( "Invalid data found in DEFBONUS tag inside item script [%s]", sectionId.c_str() )); + Console.Warning( util::format( "Invalid data found in DEFBONUS tag inside item script [%s]", sectionId.c_str() )); } break; case DFNTAG_DIR: if( !isGate ) { - std::string cupper = oldstrutil::upper( cdata ); + std::string cupper = util::upper( cdata ); if( cupper == "NE" ) { applyTo->SetDir( NORTHEAST ); @@ -1088,19 +1089,19 @@ auto CCharStuff::ApplyNpcSection( CChar *applyTo, CScriptSection *NpcCreation, s case DFNTAG_ELEMENTRESIST: if( ssects.size() >= 4 ) { - applyTo->SetResist(( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssects[0], "//" )), nullptr, 0 ))), HEAT ); - applyTo->SetResist(( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssects[1], "//" )), nullptr, 0 ))), COLD ); - applyTo->SetResist(( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssects[2], "//" )), nullptr, 0 ))), LIGHTNING ); - applyTo->SetResist(( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssects[3], "//" )), nullptr, 0 ))), POISON ); + applyTo->SetResist(( static_cast( std::stoul( util::trim( util::strip( ssects[0], "//" )), nullptr, 0 ))), HEAT ); + applyTo->SetResist(( static_cast( std::stoul( util::trim( util::strip( ssects[1], "//" )), nullptr, 0 ))), COLD ); + applyTo->SetResist(( static_cast( std::stoul( util::trim( util::strip( ssects[2], "//" )), nullptr, 0 ))), LIGHTNING ); + applyTo->SetResist(( static_cast( std::stoul( util::trim( util::strip( ssects[3], "//" )), nullptr, 0 ))), POISON ); } break; case DFNTAG_ERBONUS: if( ssects.size() >= 4 ) { - applyTo->SetResist( applyTo->GetResist( HEAT ) + static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssects[0], "//" )), nullptr, 0 )), HEAT ); - applyTo->SetResist( applyTo->GetResist( COLD ) + static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssects[1], "//" )), nullptr, 0 )), COLD ); - applyTo->SetResist( applyTo->GetResist( LIGHTNING ) + static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssects[2], "//" )), nullptr, 0 )), LIGHTNING ); - applyTo->SetResist( applyTo->GetResist( POISON ) + static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssects[3], "//" )), nullptr, 0 )), POISON ); + applyTo->SetResist( applyTo->GetResist( HEAT ) + static_cast( std::stoul( util::trim( util::strip( ssects[0], "//" )), nullptr, 0 )), HEAT ); + applyTo->SetResist( applyTo->GetResist( COLD ) + static_cast( std::stoul( util::trim( util::strip( ssects[1], "//" )), nullptr, 0 )), COLD ); + applyTo->SetResist( applyTo->GetResist( LIGHTNING ) + static_cast( std::stoul( util::trim( util::strip( ssects[2], "//" )), nullptr, 0 )), LIGHTNING ); + applyTo->SetResist( applyTo->GetResist( POISON ) + static_cast( std::stoul( util::trim( util::strip( ssects[3], "//" )), nullptr, 0 )), POISON ); } break; case DFNTAG_EMOTECOLOUR: @@ -1158,7 +1159,7 @@ auto CCharStuff::ApplyNpcSection( CChar *applyTo, CScriptSection *NpcCreation, s { if( !cdata.empty() ) { - std::string upperData = oldstrutil::upper( cdata ); + std::string upperData = util::upper( cdata ); if( upperData == "NEUTRAL" ) { applyTo->SetNPCFlag( fNPC_NEUTRAL ); @@ -1217,17 +1218,17 @@ auto CCharStuff::ApplyNpcSection( CChar *applyTo, CScriptSection *NpcCreation, s else { SI32 rndEntry = RandomNum( 0, static_cast( ssects.size() - 1 )); - scriptEntry = oldstrutil::trim( oldstrutil::removeTrailing( ssects[rndEntry], "//" )); + scriptEntry = util::trim( util::strip( ssects[rndEntry], "//" )); } CScriptSection *toFind = FileLookup->FindEntry( scriptEntry, npc_def ); if( toFind == nullptr ) { - Console.Warning( oldstrutil::format( "Invalid script entry ([%s]) called with GET tag, NPC serial 0x%X", scriptEntry.c_str(), applyTo->GetSerial() )); + Console.Warning( util::format( "Invalid script entry ([%s]) called with GET tag, NPC serial 0x%X", scriptEntry.c_str(), applyTo->GetSerial() )); } else if( toFind == NpcCreation ) { - Console.Warning( oldstrutil::format( "Infinite loop avoided with GET tag inside NPC script [%s]", scriptEntry.c_str() )); + Console.Warning( util::format( "Infinite loop avoided with GET tag inside NPC script [%s]", scriptEntry.c_str() )); } else { @@ -1277,17 +1278,17 @@ auto CCharStuff::ApplyNpcSection( CChar *applyTo, CScriptSection *NpcCreation, s else { SI32 rndEntry = RandomNum( 0, static_cast( ssects.size() - 1 )); - scriptEntry = oldstrutil::trim( oldstrutil::removeTrailing( ssects[rndEntry], "//" )); + scriptEntry = util::trim( util::strip( ssects[rndEntry], "//" )); } CScriptSection *toFind = FileLookup->FindEntry( scriptEntry, npc_def ); if( toFind == NULL ) { - Console.Warning( oldstrutil::format( "Invalid script entry ([%s]) called with %s tag, NPC serial 0x%X", scriptEntry.c_str(), tagName.c_str(), applyTo->GetSerial() )); + Console.Warning( util::format( "Invalid script entry ([%s]) called with %s tag, NPC serial 0x%X", scriptEntry.c_str(), tagName.c_str(), applyTo->GetSerial() )); } else if( toFind == NpcCreation ) { - Console.Warning( oldstrutil::format( "Infinite loop avoided with %s tag inside NPC script [%s]", tagName.c_str(), scriptEntry.c_str() )); + Console.Warning( util::format( "Infinite loop avoided with %s tag inside NPC script [%s]", tagName.c_str(), scriptEntry.c_str() )); } else { @@ -1320,12 +1321,12 @@ auto CCharStuff::ApplyNpcSection( CChar *applyTo, CScriptSection *NpcCreation, s } else { - Console.Warning( oldstrutil::format( "Invalid data found in GOLD tag inside NPC script [%s]", sectionId.c_str() )); + Console.Warning( util::format( "Invalid data found in GOLD tag inside NPC script [%s]", sectionId.c_str() )); } } else { - Console.Warning( oldstrutil::format( "Bad NPC Script ([%s]) with problem no backpack for gold", sectionId.c_str() )); + Console.Warning( util::format( "Bad NPC Script ([%s]) with problem no backpack for gold", sectionId.c_str() )); } } break; @@ -1360,7 +1361,7 @@ auto CCharStuff::ApplyNpcSection( CChar *applyTo, CScriptSection *NpcCreation, s } else { - Console.Warning( oldstrutil::format( "Invalid data found in HP tag inside NPC script [%s]", sectionId.c_str() )); + Console.Warning( util::format( "Invalid data found in HP tag inside NPC script [%s]", sectionId.c_str() )); } break; case DFNTAG_HPMAX: @@ -1380,7 +1381,7 @@ auto CCharStuff::ApplyNpcSection( CChar *applyTo, CScriptSection *NpcCreation, s } else { - Console.Warning( oldstrutil::format( "Invalid data found in HPMAX tag inside NPC script [%s]", sectionId.c_str() )); + Console.Warning( util::format( "Invalid data found in HPMAX tag inside NPC script [%s]", sectionId.c_str() )); } break; case DFNTAG_ID: @@ -1390,14 +1391,14 @@ auto CCharStuff::ApplyNpcSection( CChar *applyTo, CScriptSection *NpcCreation, s if( ssects.size() == 1 ) { - applyTo->SetId( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssects[0], "//" )), nullptr, 0 ))); - applyTo->SetOrgId( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssects[0], "//" )), nullptr, 0 ))); + applyTo->SetId( static_cast( std::stoul( util::trim( util::strip( ssects[0], "//" )), nullptr, 0 ))); + applyTo->SetOrgId( static_cast( std::stoul( util::trim( util::strip( ssects[0], "//" )), nullptr, 0 ))); } else { SI32 rndEntry = RandomNum( 0, static_cast( ssects.size() - 1 )); - applyTo->SetId( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssects[rndEntry], "//" )), nullptr, 0 ))); - applyTo->SetOrgId( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssects[rndEntry], "//" )), nullptr, 0 ))); + applyTo->SetId( static_cast( std::stoul( util::trim( util::strip( ssects[rndEntry], "//" )), nullptr, 0 ))); + applyTo->SetOrgId( static_cast( std::stoul( util::trim( util::strip( ssects[rndEntry], "//" )), nullptr, 0 ))); } break; case DFNTAG_IMBUING: skillToSet = IMBUING; break; @@ -1417,7 +1418,7 @@ auto CCharStuff::ApplyNpcSection( CChar *applyTo, CScriptSection *NpcCreation, s } else { - Console.Warning( oldstrutil::format( "Invalid data found in INTELLIGENCE tag inside NPC script [%s]", sectionId.c_str() )); + Console.Warning( util::format( "Invalid data found in INTELLIGENCE tag inside NPC script [%s]", sectionId.c_str() )); } break; case DFNTAG_ITEMID: skillToSet = ITEMID; break; @@ -1435,16 +1436,16 @@ auto CCharStuff::ApplyNpcSection( CChar *applyTo, CScriptSection *NpcCreation, s { if( !cdata.empty() ) { - auto csecs = oldstrutil::sections( oldstrutil::trim( oldstrutil::removeTrailing( cdata, "//" )), "," ); + auto csecs = oldstrutil::sections( util::trim( util::strip( cdata, "//" )), "," ); if( csecs.size() > 1 ) { UI16 iAmount = 0; - std::string amountData = oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )); + std::string amountData = util::trim( util::strip( csecs[1], "//" )); auto tsects = oldstrutil::sections( amountData, " " ); if( tsects.size() > 1 ) // check if the second part of the tag-data contains two sections separated by a space { - auto first = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( tsects[0], "//" )), nullptr, 0 )); - auto second = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( tsects[1], "//" )), nullptr, 0 )); + auto first = static_cast( std::stoul( util::trim( util::strip( tsects[0], "//" )), nullptr, 0 )); + auto second = static_cast( std::stoul( util::trim( util::strip( tsects[1], "//" )), nullptr, 0 )); // Tag contained a minimum and maximum value for amount! Let's randomize! iAmount = static_cast( RandomNum( first, second )); @@ -1453,7 +1454,7 @@ auto CCharStuff::ApplyNpcSection( CChar *applyTo, CScriptSection *NpcCreation, s { iAmount = static_cast( std::stoul(amountData, nullptr, 0 )); } - auto tdata = oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )); + auto tdata = util::trim( util::strip( csecs[0], "//" )); if( tag == DFNTAG_LOOT ) { @@ -1479,7 +1480,7 @@ auto CCharStuff::ApplyNpcSection( CChar *applyTo, CScriptSection *NpcCreation, s } else { - Console.Warning( oldstrutil::format( "Bad NPC Script ([%s]) with problem no backpack for loot", sectionId.c_str() )); + Console.Warning( util::format( "Bad NPC Script ([%s]) with problem no backpack for loot", sectionId.c_str() )); } } break; @@ -1506,7 +1507,7 @@ auto CCharStuff::ApplyNpcSection( CChar *applyTo, CScriptSection *NpcCreation, s } else { - Console.Warning( oldstrutil::format( "Invalid data found in MANA tag inside NPC script [%s]", sectionId.c_str() )); + Console.Warning( util::format( "Invalid data found in MANA tag inside NPC script [%s]", sectionId.c_str() )); } break; case DFNTAG_MANAMAX: @@ -1526,7 +1527,7 @@ auto CCharStuff::ApplyNpcSection( CChar *applyTo, CScriptSection *NpcCreation, s } else { - Console.Warning( oldstrutil::format( "Invalid data found in MANAMAX tag inside NPC script [%s]", sectionId.c_str() )); + Console.Warning( util::format( "Invalid data found in MANAMAX tag inside NPC script [%s]", sectionId.c_str() )); } break; case DFNTAG_MAXLOYALTY: @@ -1596,7 +1597,7 @@ auto CCharStuff::ApplyNpcSection( CChar *applyTo, CScriptSection *NpcCreation, s } else { - Console.Warning( oldstrutil::format( "Invalid data found in RESISTFIRE tag inside NPC script [%s]", sectionId.c_str() )); + Console.Warning( util::format( "Invalid data found in RESISTFIRE tag inside NPC script [%s]", sectionId.c_str() )); } break; case DFNTAG_RESISTCOLD: @@ -1613,7 +1614,7 @@ auto CCharStuff::ApplyNpcSection( CChar *applyTo, CScriptSection *NpcCreation, s } else { - Console.Warning( oldstrutil::format( "Invalid data found in RESISTCOLD tag inside NPC script [%s]", sectionId.c_str() )); + Console.Warning( util::format( "Invalid data found in RESISTCOLD tag inside NPC script [%s]", sectionId.c_str() )); } break; case DFNTAG_RESISTLIGHTNING: @@ -1630,7 +1631,7 @@ auto CCharStuff::ApplyNpcSection( CChar *applyTo, CScriptSection *NpcCreation, s } else { - Console.Warning( oldstrutil::format( "Invalid data found in RESISTLIGHTNING tag inside NPC script [%s]", sectionId.c_str() )); + Console.Warning( util::format( "Invalid data found in RESISTLIGHTNING tag inside NPC script [%s]", sectionId.c_str() )); } break; case DFNTAG_RESISTPOISON: @@ -1647,7 +1648,7 @@ auto CCharStuff::ApplyNpcSection( CChar *applyTo, CScriptSection *NpcCreation, s } else { - Console.Warning( oldstrutil::format( "Invalid data found in RESISTPOISON tag inside NPC script [%s]", sectionId.c_str() )); + Console.Warning( util::format( "Invalid data found in RESISTPOISON tag inside NPC script [%s]", sectionId.c_str() )); } break; case DFNTAG_RSHOPITEM: @@ -1672,7 +1673,7 @@ auto CCharStuff::ApplyNpcSection( CChar *applyTo, CScriptSection *NpcCreation, s } else { - Console.Warning( oldstrutil::format( "Bad NPC Script ([%s]) with no Vendor Buy Pack for item", sectionId.c_str() )); + Console.Warning( util::format( "Bad NPC Script ([%s]) with no Vendor Buy Pack for item", sectionId.c_str() )); } } break; @@ -1733,7 +1734,7 @@ auto CCharStuff::ApplyNpcSection( CChar *applyTo, CScriptSection *NpcCreation, s } else { - Console.Warning( oldstrutil::format( "Bad NPC Script ([%s]) with no Vendor SellPack for item", sectionId.c_str() )); + Console.Warning( util::format( "Bad NPC Script ([%s]) with no Vendor SellPack for item", sectionId.c_str() )); } } break; @@ -1760,7 +1761,7 @@ auto CCharStuff::ApplyNpcSection( CChar *applyTo, CScriptSection *NpcCreation, s } else { - Console.Warning(oldstrutil::format( "Bad NPC Script ([%s]) with no Vendor Bought Pack for item", sectionId.c_str() )); + Console.Warning(util::format( "Bad NPC Script ([%s]) with no Vendor Bought Pack for item", sectionId.c_str() )); } } break; @@ -1813,7 +1814,7 @@ auto CCharStuff::ApplyNpcSection( CChar *applyTo, CScriptSection *NpcCreation, s } else { - Console.Warning( oldstrutil::format( "Invalid data found in STRENGTH tag inside NPC script [%s]", sectionId.c_str() )); + Console.Warning( util::format( "Invalid data found in STRENGTH tag inside NPC script [%s]", sectionId.c_str() )); } break; case DFNTAG_SWORDSMANSHIP: skillToSet = SWORDSMANSHIP; break; @@ -1831,7 +1832,7 @@ auto CCharStuff::ApplyNpcSection( CChar *applyTo, CScriptSection *NpcCreation, s } else { - Console.Warning( oldstrutil::format( "Invalid data found in STAMINA tag inside NPC script [%s]", sectionId.c_str() )); + Console.Warning( util::format( "Invalid data found in STAMINA tag inside NPC script [%s]", sectionId.c_str() )); } break; case DFNTAG_STAMINAMAX: @@ -1851,7 +1852,7 @@ auto CCharStuff::ApplyNpcSection( CChar *applyTo, CScriptSection *NpcCreation, s } else { - Console.Warning( oldstrutil::format( "Invalid data found in STAMINA tag inside NPC script [%s]", sectionId.c_str() )); + Console.Warning( util::format( "Invalid data found in STAMINA tag inside NPC script [%s]", sectionId.c_str() )); } break; case DFNTAG_STEALTH: skillToSet = STEALTH; break; @@ -1936,16 +1937,16 @@ auto CCharStuff::ApplyNpcSection( CChar *applyTo, CScriptSection *NpcCreation, s { if( count == 1 ) { - result = oldstrutil::trim( oldstrutil::removeTrailing( sec, "//" )); + result = util::trim( util::strip( sec, "//" )); } else { - result = result + " " + oldstrutil::trim( oldstrutil::removeTrailing( sec, "//" )); + result = result + " " + util::trim( util::strip( sec, "//" )); } } count++; } - customTagName = oldstrutil::trim( oldstrutil::removeTrailing( ssects[0], "//" )); + customTagName = util::trim( util::strip( ssects[0], "//" )); customTagStringValue = result; if( !customTagName.empty() && !customTagStringValue.empty() ) @@ -1958,7 +1959,7 @@ auto CCharStuff::ApplyNpcSection( CChar *applyTo, CScriptSection *NpcCreation, s } else { - Console.Warning( oldstrutil::format( "Invalid data found in CUSTOMSTRINGTAG tag inside NPC script [%s] - Supported data format: ", sectionId.c_str() )); + Console.Warning( util::format( "Invalid data found in CUSTOMSTRINGTAG tag inside NPC script [%s] - Supported data format: ", sectionId.c_str() )); } break; } @@ -1972,12 +1973,12 @@ auto CCharStuff::ApplyNpcSection( CChar *applyTo, CScriptSection *NpcCreation, s { if( count == 1 ) { - result = oldstrutil::trim( oldstrutil::removeTrailing( sec, "//" )); + result = util::trim( util::strip( sec, "//" )); } } count++; } - customTagName = oldstrutil::trim( oldstrutil::removeTrailing( ssects[0], "//" )); + customTagName = util::trim( util::strip( ssects[0], "//" )); customTagStringValue = result; if( !customTagName.empty() && !customTagStringValue.empty() ) { @@ -1988,12 +1989,12 @@ auto CCharStuff::ApplyNpcSection( CChar *applyTo, CScriptSection *NpcCreation, s applyTo->SetTag( customTagName, customTag ); if( count > 2 ) { - Console.Warning( oldstrutil::format( "Multiple values detected for CUSTOMINTTAG in NPC script [%s] - only first value will be used! Supported data format: ", sectionId.c_str() )); + Console.Warning( util::format( "Multiple values detected for CUSTOMINTTAG in NPC script [%s] - only first value will be used! Supported data format: ", sectionId.c_str() )); } } else { - Console.Warning( oldstrutil::format( "Invalid data found in CUSTOMINTTAG tag in NPC script [%s] - Supported data format: ", sectionId.c_str() )); + Console.Warning( util::format( "Invalid data found in CUSTOMINTTAG tag in NPC script [%s] - Supported data format: ", sectionId.c_str() )); } break; } @@ -2239,7 +2240,7 @@ void MonsterGate( CChar *s, const std::string& scriptEntry ) return; auto entry = scriptEntry; - entry = oldstrutil::trim( oldstrutil::removeTrailing( entry, "//" )); + entry = util::trim( util::strip( entry, "//" )); CScriptSection *Monster = FileLookup->FindEntry( entry, npc_def ); if( Monster == nullptr ) return; diff --git a/source/pcmanage.cpp b/source/pcmanage.cpp index 7768a8976..ce10b1a0c 100644 --- a/source/pcmanage.cpp +++ b/source/pcmanage.cpp @@ -15,6 +15,8 @@ #include "cEffects.h" #include "cRaces.h" #include "StringUtility.hpp" +#include "utility/strutil.hpp" + #include "cServerData.h" #include "ObjectFactory.h" #include @@ -510,17 +512,17 @@ auto AddNewbieItem( CSocket *socket, CChar *c, const char* str, COLOUR pantsColo { auto tag = sec->tag; auto data = sec->data; - data = oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )); + data = util::trim( util::strip( data, "//" )); if( !data.empty() ) { - auto UTag = oldstrutil::upper( tag ); + auto UTag = util::upper( tag ); if( UTag == "PACKITEM" ) { auto csecs = oldstrutil::sections( data, "," ); if( csecs.size() > 1 ) { - UI16 nAmount = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 )); - n = Items->CreateScriptItem( socket, c, oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nAmount, OT_ITEM, true ); + UI16 nAmount = static_cast( std::stoul( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 )); + n = Items->CreateScriptItem( socket, c, util::trim( util::strip( csecs[0], "//" )), nAmount, OT_ITEM, true ); } else { @@ -534,8 +536,8 @@ auto AddNewbieItem( CSocket *socket, CChar *c, const char* str, COLOUR pantsColo auto csecs = oldstrutil::sections( data, "," ); if( csecs.size() > 1 ) { - itemSection = oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )); - itemHue = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 )); + itemSection = util::trim( util::strip( csecs[0], "//" )); + itemHue = static_cast( std::stoul( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 )); } else { @@ -704,7 +706,7 @@ void CPICreateCharacter::NewbieItems( CChar *mChar ) { if( vecSkills[i].value > 0 ) { - whichsect = oldstrutil::format( "BESTSKILL %i", vecSkills[i].skill ); + whichsect = util::format( "BESTSKILL %i", vecSkills[i].skill ); AddNewbieItem( tSock, mChar, whichsect.c_str(), 0, 0 ); } } @@ -1030,7 +1032,7 @@ void CPICreateCharacter::SetNewCharSkillsStats( CChar *mChar ) mChar->SetIntelligence( extStats ? 20 : 10 ); break; default: - Console.Error( oldstrutil::format( "Character created with invalid profession - no skills or stats assigned! (0x%X, %s)", mChar->GetSerial(), mChar->GetName().c_str() )); + Console.Error( util::format( "Character created with invalid profession - no skills or stats assigned! (0x%X, %s)", mChar->GetSerial(), mChar->GetName().c_str() )); break; } } @@ -1047,7 +1049,7 @@ void CPICreateCharacter::SetNewCharSkillsStats( CChar *mChar ) if( totalstats > 80 ) { // If ExtendedStartingStats() is false, allow a total of 80 starting statpoints - Console.Error( oldstrutil::format( "Character created with invalid stats (over 80 total): 0x%X, (%s)", mChar->GetSerial(), mChar->GetName().c_str() )); + Console.Error( util::format( "Character created with invalid stats (over 80 total): 0x%X, (%s)", mChar->GetSerial(), mChar->GetName().c_str() )); percheck = ( mChar->GetStrength() / static_cast( totalstats )); mChar->SetStrength( static_cast(Capped( percheck * 80, 10.0f, 60.0f ))); percheck = ( mChar->GetDexterity() / static_cast( totalstats )); @@ -1057,7 +1059,7 @@ void CPICreateCharacter::SetNewCharSkillsStats( CChar *mChar ) } else { - Console.Error( oldstrutil::format( "Character created with invalid stats (under 80 total): 0x%X, (%s)", mChar->GetSerial(), mChar->GetName().c_str() )); + Console.Error( util::format( "Character created with invalid stats (under 80 total): 0x%X, (%s)", mChar->GetSerial(), mChar->GetName().c_str() )); } } else if( totalstats != 90 && cwmWorldState->ServerData()->ExtendedStartingStats() ) @@ -1065,7 +1067,7 @@ void CPICreateCharacter::SetNewCharSkillsStats( CChar *mChar ) if( totalstats > 90 ) { // If ExtendedStartingStats() is true, allow a total of 90 starting statpoints - Console.Error( oldstrutil::format( "Character created with invalid stats (over 90 total): 0x%X, (%s)", mChar->GetSerial(), mChar->GetName().c_str() )); + Console.Error( util::format( "Character created with invalid stats (over 90 total): 0x%X, (%s)", mChar->GetSerial(), mChar->GetName().c_str() )); percheck = ( mChar->GetStrength() / static_cast( totalstats )); mChar->SetStrength( static_cast(Capped( percheck * 90, 10.0f, 60.0f ))); percheck = ( mChar->GetDexterity() / static_cast( totalstats )); @@ -1075,7 +1077,7 @@ void CPICreateCharacter::SetNewCharSkillsStats( CChar *mChar ) } else { - Console.Error( oldstrutil::format( "Character created with invalid stats (under 90 total): 0x%X, (%s)", mChar->GetSerial(), mChar->GetName().c_str() )); + Console.Error( util::format( "Character created with invalid stats (under 90 total): 0x%X, (%s)", mChar->GetSerial(), mChar->GetName().c_str() )); } } @@ -1102,7 +1104,7 @@ void CPICreateCharacter::SetNewCharSkillsStats( CChar *mChar ) totalskills += skillValue[2]; if( totalskills < 100 ) { - Console.Error( oldstrutil::format( "Character created with invalid skills (under 100 total): 0x%X, (%s)", mChar->GetSerial(), mChar->GetName().c_str() )); + Console.Error( util::format( "Character created with invalid skills (under 100 total): 0x%X, (%s)", mChar->GetSerial(), mChar->GetName().c_str() )); } } else // If ExtendedStartingSkills is enabled, allow for the fourth starting skill @@ -1123,7 +1125,7 @@ void CPICreateCharacter::SetNewCharSkillsStats( CChar *mChar ) totalskills += skillValue[3]; if( totalskills < 120 ) { - Console.Error( oldstrutil::format( "Character created with invalid skills (under 120 total): 0x%X, (%s)", mChar->GetSerial(), mChar->GetName().c_str() )); + Console.Error( util::format( "Character created with invalid skills (under 120 total): 0x%X, (%s)", mChar->GetSerial(), mChar->GetName().c_str() )); } } } diff --git a/source/regions.cpp b/source/regions.cpp index fb24f0218..7538848ad 100644 --- a/source/regions.cpp +++ b/source/regions.cpp @@ -7,6 +7,8 @@ #include "uox3.h" #include "classes.h" #include "StringUtility.hpp" +#include "utility/strutil.hpp" + #include "ObjectFactory.h" using namespace std::string_literals ; @@ -361,7 +363,7 @@ void CMapWorld::LoadResources( UI08 worldNum ) { mapResources = std::vector(mapResources.size(),MapResource_st(cwmWorldState->ServerData()->ResOre(),cwmWorldState->ServerData()->ResLogs(),cwmWorldState->ServerData()->ResFish(),BuildTimeValue( static_cast( cwmWorldState->ServerData()->ResOreTime() )), BuildTimeValue( static_cast( cwmWorldState->ServerData()->ResLogTime() )),BuildTimeValue( static_cast( cwmWorldState->ServerData()->ResFishTime() )))) ; - auto resourceFile = std::filesystem::path(cwmWorldState->ServerData()->Directory( CSDDP_SHARED ) + "resource["s + oldstrutil::number( worldNum ) + "].bin"s); + auto resourceFile = std::filesystem::path(cwmWorldState->ServerData()->Directory( CSDDP_SHARED ) + "resource["s + util::ntos( worldNum ) + "].bin"s); // The data is grouped as three shorts (for each resource), so we read in that format auto buffer = std::vector(3,0) ; @@ -439,7 +441,7 @@ bool CMapHandler::ChangeRegion( CItem *nItem, SI16 x, SI16 y, UI08 worldNum ) if( !curCell->GetRegionSerialList()->Remove( nItem->GetSerial() ) || !curCell->GetItemList()->Remove( nItem )) { #if DEBUG_REGIONS - Console.Warning( oldstrutil::format( "Item 0x%X does not exist in MapRegion, remove failed", nItem->GetSerial() )); + Console.Warning( util::format( "Item 0x%X does not exist in MapRegion, remove failed", nItem->GetSerial() )); #endif } else @@ -462,7 +464,7 @@ bool CMapHandler::ChangeRegion( CItem *nItem, SI16 x, SI16 y, UI08 worldNum ) else { #if DEBUG_REGIONS - Console.Warning( oldstrutil::format( "Item 0x%X already exists in MapRegion, add failed", nItem->GetSerial() )); + Console.Warning( util::format( "Item 0x%X already exists in MapRegion, add failed", nItem->GetSerial() )); #endif } } @@ -488,7 +490,7 @@ bool CMapHandler::ChangeRegion( CChar *nChar, SI16 x, SI16 y, UI08 worldNum ) if( !curCell->GetRegionSerialList()->Remove( nChar->GetSerial() ) || !curCell->GetCharList()->Remove( nChar )) { #if DEBUG_REGIONS - Console.Warning( oldstrutil::format( "Character 0x%X does not exist in MapRegion, remove failed", nChar->GetSerial() )); + Console.Warning( util::format( "Character 0x%X does not exist in MapRegion, remove failed", nChar->GetSerial() )); #endif } else @@ -511,7 +513,7 @@ bool CMapHandler::ChangeRegion( CChar *nChar, SI16 x, SI16 y, UI08 worldNum ) else { #if DEBUG_REGIONS - Console.Warning( oldstrutil::format( "Character 0x%X already exists in MapRegion, add failed", nChar->GetSerial() )); + Console.Warning( util::format( "Character 0x%X already exists in MapRegion, add failed", nChar->GetSerial() )); #endif } } @@ -542,7 +544,7 @@ bool CMapHandler::AddItem( CItem *nItem ) else { #if DEBUG_REGIONS - Console.Warning( oldstrutil::format( "Item 0x%X already exists in MapRegion, add failed", nItem->GetSerial() )); + Console.Warning( util::format( "Item 0x%X already exists in MapRegion, add failed", nItem->GetSerial() )); #endif } return false; @@ -571,7 +573,7 @@ bool CMapHandler::RemoveItem( CItem *nItem ) else { #if DEBUG_REGIONS - Console.Warning( oldstrutil::format( "Item 0x%X does not exist in MapRegion, remove failed", nItem->GetSerial() )); + Console.Warning( util::format( "Item 0x%X does not exist in MapRegion, remove failed", nItem->GetSerial() )); #endif return false; } @@ -602,7 +604,7 @@ bool CMapHandler::AddChar( CChar *toAdd ) else { #if DEBUG_REGIONS - Console.Warning( oldstrutil::format( "Character 0x%X already exists in MapRegion, add failed", toAdd->GetSerial() )); + Console.Warning( util::format( "Character 0x%X already exists in MapRegion, add failed", toAdd->GetSerial() )); #endif } return false; @@ -631,7 +633,7 @@ bool CMapHandler::RemoveChar( CChar *toRemove ) else { #if DEBUG_REGIONS - Console.Warning( oldstrutil::format( "Character 0x%X does not exist in MapRegion, remove failed", toRemove->GetSerial() )); + Console.Warning( util::format( "Character 0x%X does not exist in MapRegion, remove failed", toRemove->GetSerial() )); #endif return false; } @@ -798,7 +800,7 @@ void CMapHandler::Save( void ) for( SI16 counter2 = 0; counter2 < AreaY; ++counter2 ) // move up->down { const SI32 baseY = counter2 * 8; // calculate x grid offset - filename = basePath + oldstrutil::number( counter1 ) + std::string( "." ) + oldstrutil::number( counter2 ) + std::string( ".wsc" ); // let's name our file + filename = basePath + util::ntos( counter1 ) + std::string( "." ) + util::ntos( counter2 ) + std::string( ".wsc" ); // let's name our file bool changesDetected = false; for( UI08 xCnt = 0; !changesDetected && xCnt < 8; ++xCnt ) // walk through each part of the 8x8 grid, left->right @@ -828,7 +830,7 @@ void CMapHandler::Save( void ) if( !writeDestination ) { - Console.Error( oldstrutil::format( "Failed to open %s for writing", filename.c_str() )); + Console.Error( util::format( "Failed to open %s for writing", filename.c_str() )); continue; } @@ -881,7 +883,7 @@ void CMapHandler::Save( void ) } else { - Console.Error( oldstrutil::format( "Failed to open %s for writing", filename.c_str() )); + Console.Error( util::format( "Failed to open %s for writing", filename.c_str() )); return; } @@ -889,7 +891,7 @@ void CMapHandler::Save( void ) Console.PrintDone(); const UI32 e_t = GetClock(); - Console.Print( oldstrutil::format( "World saved in %.02fsec\n", ( static_cast( e_t - s_t )) / 1000.0f )); + Console.Print( util::format( "World saved in %.02fsec\n", ( static_cast( e_t - s_t )) / 1000.0f )); i = 0; for( WORLDLIST_ITERATOR wIter = mapWorlds.begin(); wIter != mapWorlds.end(); ++wIter ) @@ -935,7 +937,7 @@ void CMapHandler::Load( void ) { for( SI16 cy = 0; cy < AreaY; ++cy ) { - filename = basePath + oldstrutil::number( cx ) + std::string( "." ) + oldstrutil::number( cy ) + std::string( ".wsc" ); // let's name our file + filename = basePath + util::ntos( cx ) + std::string( "." ) + util::ntos( cy ) + std::string( ".wsc" ); // let's name our file fileSizes[cx][cy] = FileSize( filename ); runningCount += fileSizes[cx][cy]; } @@ -951,7 +953,7 @@ void CMapHandler::Load( void ) { for( SI16 counter2 = 0; counter2 < AreaY; ++counter2 ) // move up->down { - filename = basePath + oldstrutil::number( counter1 ) + std::string( "." ) + oldstrutil::number( counter2 ) + std::string( ".wsc" ); // let's name our file + filename = basePath + util::ntos( counter1 ) + std::string( "." ) + util::ntos( counter2 ) + std::string( ".wsc" ); // let's name our file readDestination.open( filename.c_str() ); // let's open it readDestination.seekg( 0, std::ios::beg ); @@ -1007,7 +1009,7 @@ void CMapHandler::Load( void ) houseDestination.close(); UI32 e_t = GetClock(); - Console.Print( oldstrutil::format( "ASCII world loaded in %.02fsec\n", ( static_cast( e_t - s_t )) / 1000.0f )); + Console.Print( util::format( "ASCII world loaded in %.02fsec\n", ( static_cast( e_t - s_t )) / 1000.0f )); UI08 i = 0; for( WORLDLIST_ITERATOR wIter = mapWorlds.begin(); wIter != mapWorlds.end(); ++wIter ) @@ -1036,12 +1038,12 @@ void CMapHandler::LoadFromDisk( std::istream& readDestination, SI32 baseValue, S readDestination.getline( line, 1023 ); line[readDestination.gcount()] = 0; std::string sLine( line ); - sLine = oldstrutil::trim( sLine ); + sLine = util::trim( sLine ); if( sLine.substr( 0, 1 ) == "[" ) // in a section { sLine = sLine.substr( 1, sLine.size() - 2 ); - sLine = oldstrutil::upper( oldstrutil::trim( sLine )); + sLine = util::upper( util::trim( sLine )); if( sLine == "CHARACTER" ) { LoadChar( readDestination ); diff --git a/source/scriptc.cpp b/source/scriptc.cpp index df8f07dba..31ac655c0 100644 --- a/source/scriptc.cpp +++ b/source/scriptc.cpp @@ -10,6 +10,7 @@ #include "ssection.h" #include "scriptc.h" #include "StringUtility.hpp" +#include "utility/strutil.hpp" #include "osunique.hpp" //o------------------------------------------------------------------------------------------------o @@ -51,7 +52,7 @@ void Script::Reload( bool disp ) input.getline( line, 2047 ); line[input.gcount()] = 0; sLine = std::string( line ); - sLine = oldstrutil::trim( oldstrutil::removeTrailing( sLine, "//" )); + sLine = util::trim( util::strip( sLine, "//" )); if( !sLine.empty() ) { // We have some real data @@ -60,14 +61,14 @@ void Script::Reload( bool disp ) { // Ok a section is starting here, get the name std::string sectionname = sLine.substr( 1, sLine.size() - 2 ); - sectionname = oldstrutil::upper( oldstrutil::simplify( sectionname )); + sectionname = util::upper( util::simplify( sectionname )); // Now why we look for a {, no idea, but we do - Because we want to make sure that were IN a block not before the block. At least this makes sure that were inside the {}'s of a block... while( !input.eof() && sLine.substr( 0, 1 ) != "{" && !input.fail() ) { input.getline( line, 2047 ); line[input.gcount()] = 0; sLine = std::string( line ); - sLine = oldstrutil::trim( oldstrutil::removeTrailing( sLine, "//" )); + sLine = util::trim( util::strip( sLine, "//" )); } // We are finally in the actual section! // We waited until now to create it, incase a total invalid file @@ -88,7 +89,7 @@ void Script::Reload( bool disp ) } if( disp ) { - Console.Print( oldstrutil::format( "Reloading %-15s: ", filename.c_str() )); + Console.Print( util::format( "Reloading %-15s: ", filename.c_str() )); } fflush( stdout ); @@ -139,7 +140,7 @@ Script::~Script() bool Script::IsInSection( const std::string& section ) { std::string temp( section ); - SSMAP::const_iterator iSearch = defEntries.find( oldstrutil::upper( temp )); + SSMAP::const_iterator iSearch = defEntries.find( util::upper( temp )); if( iSearch != defEntries.end() ) return true; @@ -173,7 +174,7 @@ CScriptSection *Script::FindEntrySubStr( const std::string& section ) { CScriptSection *rValue = nullptr; auto usection = std::string( section ); - usection = oldstrutil::upper( usection ); + usection = util::upper( usection ); for( SSMAP::const_iterator iSearch = defEntries.begin(); iSearch != defEntries.end(); ++iSearch ) { if( iSearch->first.find( usection ) != std::string::npos ) // FOUND IT! diff --git a/source/skills.cpp b/source/skills.cpp index 026f654a5..4ced80410 100644 --- a/source/skills.cpp +++ b/source/skills.cpp @@ -17,6 +17,7 @@ #include "Dictionary.h" #include "movement.h" #include "StringUtility.hpp" +#include "utility/strutil.hpp" #include "weight.h" #include @@ -424,7 +425,7 @@ void CSkills::SmeltOre( CSocket *s ) CItem *ingot = Items->CreateScriptItem( s, chr, "0x1BF2", ingotNum, OT_ITEM, true, oreType->colour ); if( ingot != nullptr ) { - ingot->SetName( oldstrutil::format( "%s Ingot", oreType->name.c_str() )); + ingot->SetName( util::format( "%s Ingot", oreType->name.c_str() )); } if( smeltItemId == 0x19B7 && itemToSmelt->GetAmount() % 2 != 0 ) @@ -968,7 +969,7 @@ void CSkills::Tracking( CSocket *s, SI32 selection ) void CSkills::CreateTrackingMenu( CSocket *s, UI16 m ) { VALIDATESOCKET( s ); - const std::string sect = std::string( "TRACKINGMENU " ) + oldstrutil::number( m ); + const std::string sect = std::string( "TRACKINGMENU " ) + util::ntos( m ); CScriptSection *TrackStuff = FileLookup->FindEntry( sect, menus_def ); if( TrackStuff == nullptr ) return; @@ -1081,7 +1082,7 @@ void HandleCommonGump( CSocket *mSock, CScriptSection *gumpScript, UI16 gumpInde void CSkills::TrackingMenu( CSocket *s, UI16 gmindex ) { VALIDATESOCKET( s ); - const std::string sect = std::string( "TRACKINGMENU " ) + oldstrutil::number( gmindex ); + const std::string sect = std::string( "TRACKINGMENU " ) + util::ntos( gmindex ); CScriptSection *TrackStuff = FileLookup->FindEntry( sect, menus_def ); if( TrackStuff == nullptr ) { @@ -1360,8 +1361,8 @@ bool CSkills::LoadMiningData( void ) { tag = sec->tag; data = sec->data; - UTag = oldstrutil::upper( tag ); - data = oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )); + UTag = util::upper( tag ); + data = util::trim( util::strip( data, "//" )); switch(( UTag.data()[0] )) // break on tag { case 'C': @@ -1529,15 +1530,15 @@ auto CSkills::LoadCreateMenus() -> void auto eName = eName1; if( "SUBMENU" == eName.substr( 0, 7 )) // is it a menu? (not really SUB, just to avoid picking up MAKEMENUs) { - eName = oldstrutil::trim( oldstrutil::removeTrailing( eName, "//" )); + eName = util::trim( util::strip( eName, "//" )); auto ssecs = oldstrutil::sections( eName, " " ); - ourEntry = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[1], "//" )), nullptr, 0 )); + ourEntry = static_cast( std::stoul( util::trim( util::strip( ssecs[1], "//" )), nullptr, 0 )); for( const auto &sec : toSearch->collection() ) { auto tag = sec->tag; auto data = sec->data; - auto UTag = oldstrutil::upper( tag ); - data = oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )); + auto UTag = util::upper( tag ); + data = util::trim( util::strip( data, "//" )); if( UTag == "MENU" ) { actualMenus[ourEntry].menuEntries.push_back( static_cast( std::stoul( data, nullptr, 0 ))); @@ -1552,7 +1553,7 @@ auto CSkills::LoadCreateMenus() -> void { auto ssecs = oldstrutil::sections( eName, " " ); - ourEntry = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[1], "//" )), nullptr, 0 )); + ourEntry = static_cast( std::stoul( util::trim( util::strip( ssecs[1], "//" )), nullptr, 0 )); CreateEntry_st tmpEntry; tmpEntry.minRank = 0; tmpEntry.maxRank = 10; @@ -1564,8 +1565,8 @@ auto CSkills::LoadCreateMenus() -> void { auto tag = sec->tag; auto data = sec->data; - auto UTag = oldstrutil::upper( tag ); - data = oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )); + auto UTag = util::upper( tag ); + data = util::trim( util::strip( data, "//" )); if( UTag == "COLOUR" ) { tmpEntry.colour = static_cast( std::stoul( data, nullptr, 0 )); @@ -1606,18 +1607,18 @@ auto CSkills::LoadCreateMenus() -> void { if( ssecs.size() == 4 ) { - tmpResource.moreVal = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[3], "//" )), nullptr, 0 )); + tmpResource.moreVal = static_cast( std::stoul( util::trim( util::strip( ssecs[3], "//" )), nullptr, 0 )); } if( ssecs.size() >= 3 ) { - tmpResource.colour = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[2], "//" )), nullptr, 0 )); + tmpResource.colour = static_cast( std::stoul( util::trim( util::strip( ssecs[2], "//" )), nullptr, 0 )); } if( ssecs.size() >= 2 ) { - tmpResource.amountNeeded = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[1], "//" )), nullptr, 0 )); + tmpResource.amountNeeded = static_cast( std::stoul( util::trim( util::strip( ssecs[1], "//" )), nullptr, 0 )); } } - auto resType = "RESOURCE "s + oldstrutil::trim( oldstrutil::removeTrailing( ssecs[0], "//" )); + auto resType = "RESOURCE "s + util::trim( util::strip( ssecs[0], "//" )); auto resList = FileLookup->FindEntry( resType, create_def ); if( resList ) { @@ -1628,7 +1629,7 @@ auto CSkills::LoadCreateMenus() -> void } else { - tmpResource.idList.push_back( static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[0], "//" )), nullptr, 0 ))); + tmpResource.idList.push_back( static_cast( std::stoul( util::trim( util::strip( ssecs[0], "//" )), nullptr, 0 ))); } tmpEntry.resourceNeeded.push_back( tmpResource ); @@ -1648,14 +1649,14 @@ auto CSkills::LoadCreateMenus() -> void if( ssecs.size() == 2 ) { tmpResource.maxSkill = 1000; - tmpResource.minSkill = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[1], "//" )), nullptr, 0 )); + tmpResource.minSkill = static_cast( std::stoul( util::trim( util::strip( ssecs[1], "//" )), nullptr, 0 )); } else { - tmpResource.minSkill = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[1], "//" )), nullptr, 0 )); - tmpResource.maxSkill = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[2], "//" )), nullptr, 0 )); + tmpResource.minSkill = static_cast( std::stoul( util::trim( util::strip( ssecs[1], "//" )), nullptr, 0 )); + tmpResource.maxSkill = static_cast( std::stoul( util::trim( util::strip( ssecs[2], "//" )), nullptr, 0 )); } - tmpResource.skillNumber = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[0], "//" )), nullptr, 0 )); + tmpResource.skillNumber = static_cast( std::stoul( util::trim( util::strip( ssecs[0], "//" )), nullptr, 0 )); } tmpEntry.skillReqs.push_back( tmpResource ); } @@ -1669,13 +1670,13 @@ auto CSkills::LoadCreateMenus() -> void else if( "MENUENTRY" == eName.substr( 0, 9 )) { auto ssecs = oldstrutil::sections( eName, " " ); - ourEntry = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[1], "//" )), nullptr, 0 )); + ourEntry = static_cast( std::stoul( util::trim( util::strip( ssecs[1], "//" )), nullptr, 0 )); for( const auto &sec : toSearch->collection() ) { auto tag = sec->tag; auto data = sec->data; - auto UTag = oldstrutil::upper( tag ); - data = oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )); + auto UTag = util::upper( tag ); + data = util::trim( util::strip( data, "//" )); if( UTag == "ID" ) { skillMenus[ourEntry].targId = static_cast( std::stoul( data, nullptr, 0 )); @@ -2020,21 +2021,21 @@ void CSkills::NewMakeMenu( CSocket *s, SI32 menu, [[maybe_unused]] UI08 skill ) CScriptSection *GumpHeader = FileLookup->FindEntry( "ADDMENU HEADER", misc_def ); if( GumpHeader == nullptr ) { - toSend.addCommand( oldstrutil::format( "resizepic 0 0 %i 400 320", background) ); + toSend.addCommand( util::format( "resizepic 0 0 %i 400 320", background) ); toSend.addCommand( "page 0" ); toSend.addCommand( "text 200 20 0 0" ); toSend.addText( "Create menu" ); ++textCounter; - toSend.addCommand( oldstrutil::format( "button 360 15 %i %i 1 0 1", btnCancel, btnCancel + 1 )); + toSend.addCommand( util::format( "button 360 15 %i %i 1 0 1", btnCancel, btnCancel + 1 )); } else { std::string tag, data, UTag; for( tag = GumpHeader->First(); !GumpHeader->AtEnd(); tag = GumpHeader->Next() ) { - UTag = oldstrutil::upper( tag ); + UTag = util::upper( tag ); data = GumpHeader->GrabData(); - data = oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )); + data = util::trim( util::strip( data, "//" )); if( UTag == "BUTTONLEFT" ) { btnLeft = static_cast( std::stoul( data, nullptr, 0 )); @@ -2119,12 +2120,12 @@ void CSkills::NewMakeMenu( CSocket *s, SI32 menu, [[maybe_unused]] UI08 skill ) } if( canMake ) { - toSend.addCommand( oldstrutil::format( "button %i %i %i %i 1 0 %i", xLoc - 40, yLoc, btnRight, btnRight + 1, ( *ourMenu.iIter ))); + toSend.addCommand( util::format( "button %i %i %i %i 1 0 %i", xLoc - 40, yLoc, btnRight, btnRight + 1, ( *ourMenu.iIter ))); if( iItem.targId ) { - toSend.addCommand( oldstrutil::format( "tilepic %i %i %i", xLoc - 20, yLoc, iItem.targId )); + toSend.addCommand( util::format( "tilepic %i %i %i", xLoc - 20, yLoc, iItem.targId )); } - toSend.addCommand( oldstrutil::format( "text %i %i 35 %i", xLoc + 20, yLoc, textCounter++ )); + toSend.addCommand( util::format( "text %i %i 35 %i", xLoc + 20, yLoc, textCounter++ )); toSend.addText( iItem.name ); yLoc += 40; ++actualItems; @@ -2144,12 +2145,12 @@ void CSkills::NewMakeMenu( CSocket *s, SI32 menu, [[maybe_unused]] UI08 skill ) if( smIter != skillMenus.end() ) { CreateMenuEntry_st iMenu = smIter->second; - toSend.addCommand(oldstrutil::format( "button %i %i %i %i 1 0 %i", xLoc - 40, yLoc, btnRight, btnRight + 1, CREATE_MENU_OFFSET + ( *ourMenu.mIter ))); + toSend.addCommand(util::format( "button %i %i %i %i 1 0 %i", xLoc - 40, yLoc, btnRight, btnRight + 1, CREATE_MENU_OFFSET + ( *ourMenu.mIter ))); if( iMenu.targId ) { - toSend.addCommand( oldstrutil::format( "tilepic %i %i %i", xLoc - 20, yLoc, iMenu.targId) ); + toSend.addCommand( util::format( "tilepic %i %i %i", xLoc - 20, yLoc, iMenu.targId) ); } - toSend.addCommand( oldstrutil::format( "text %i %i 35 %i", xLoc + 20, yLoc, textCounter++) ); + toSend.addCommand( util::format( "text %i %i 35 %i", xLoc + 20, yLoc, textCounter++) ); toSend.addText( iMenu.name ); yLoc += 40; ++actualItems; diff --git a/source/sound.cpp b/source/sound.cpp index 3d8898659..f4f7c995b 100644 --- a/source/sound.cpp +++ b/source/sound.cpp @@ -6,6 +6,7 @@ #include "cEffects.h" #include "CPacketSend.h" #include "regions.h" +#include "utility/strutil.hpp" using namespace std::string_literals; @@ -329,7 +330,7 @@ auto cEffects::DoSocketMusic( CSocket *s ) -> void } else { - sect = std::string( "MUSICLIST " ) + oldstrutil::number( musicList ); + sect = std::string( "MUSICLIST " ) + util::ntos( musicList ); } auto MusicList = FileLookup->FindEntry( sect, regions_def ); @@ -337,7 +338,7 @@ auto cEffects::DoSocketMusic( CSocket *s ) -> void { for( const auto &sec : MusicList->collection() ) { - if( oldstrutil::upper( sec->tag ) == "MUSIC" ) + if( util::upper( sec->tag ) == "MUSIC" ) { musicArray[i++] = static_cast( std::stoi( sec->data, nullptr, 0 )); } diff --git a/source/speech.cpp b/source/speech.cpp index e20ae8cbf..b2b77af71 100644 --- a/source/speech.cpp +++ b/source/speech.cpp @@ -12,6 +12,7 @@ #include "movement.h" #include "Dictionary.h" #include "StringUtility.hpp" +#include "utility/strutil.hpp" //o------------------------------------------------------------------------------------------------o //| Function - ClilocMessage() @@ -31,7 +32,7 @@ void ClilocMessage( CSocket *mSock, SpeechType speechType, UI16 hue, UI16 font, { if( *typesPtr == 'i' ) { - stringVal = oldstrutil::number( va_arg( marker, SI32 )); + stringVal = util::ntos( va_arg( marker, SI32 )); } else if( *typesPtr == 's' ) { @@ -47,7 +48,7 @@ void ClilocMessage( CSocket *mSock, SpeechType speechType, UI16 hue, UI16 font, } else { - argList += oldstrutil::format( "\t%s", stringVal.c_str() ); + argList += util::format( "\t%s", stringVal.c_str() ); } } ++typesPtr; @@ -82,7 +83,7 @@ void ClilocMessage( CSocket *mSock, CBaseObject *srcObj, SpeechType speechType, { if( *typesPtr == 'i' ) { - stringVal = oldstrutil::number( va_arg( marker, SI32 )); + stringVal = util::ntos( va_arg( marker, SI32 )); } else if( *typesPtr == 's' ) { @@ -98,7 +99,7 @@ void ClilocMessage( CSocket *mSock, CBaseObject *srcObj, SpeechType speechType, } else { - argList += oldstrutil::format( "\t%s", stringVal.c_str() ); + argList += util::format( "\t%s", stringVal.c_str() ); } } ++typesPtr; @@ -174,7 +175,7 @@ UnicodeTypes FindLanguage( CSocket *s, UI16 offset ) langCode[3] = 0; std::string ulangCode = langCode; - ulangCode = oldstrutil::upper( ulangCode ); + ulangCode = util::upper( ulangCode ); UnicodeTypes cLang = s->Language(); if( LanguageCodes[cLang] != ulangCode.c_str() ) @@ -186,7 +187,7 @@ UnicodeTypes FindLanguage( CSocket *s, UI16 offset ) } else { - Console.Error( oldstrutil::format( "Unknown language type \"%s\". PLEASE report this in the Bugs section of the forums at https://www.uox3.org!", ulangCode.c_str() )); + Console.Error( util::format( "Unknown language type \"%s\". PLEASE report this in the Bugs section of the forums at https://www.uox3.org!", ulangCode.c_str() )); } } return cLang; @@ -365,12 +366,12 @@ bool CPITalkRequest::Handle( void ) } if( cwmWorldState->ServerData()->ServerSpeechLog() && !mChar->IsNpc() ) // Logging { - auto temp = oldstrutil::format( "%s.log", mChar->GetName().c_str() ); - auto temp2 = oldstrutil::format( "%s [%x %x %x %x] [%i]: %s\n", mChar->GetName().c_str(), mChar->GetSerial( 1 ), mChar->GetSerial( 2 ), mChar->GetSerial( 3 ), mChar->GetSerial( 4 ), mChar->GetAccount().wAccountIndex, asciiText ); + auto temp = util::format( "%s.log", mChar->GetName().c_str() ); + auto temp2 = util::format( "%s [%x %x %x %x] [%i]: %s\n", mChar->GetName().c_str(), mChar->GetSerial( 1 ), mChar->GetSerial( 2 ), mChar->GetSerial( 3 ), mChar->GetSerial( 4 ), mChar->GetAccount().wAccountIndex, asciiText ); Console.Log( temp, temp2 ); } - std::string upperText = oldstrutil::upper( text ); + std::string upperText = util::upper( text ); if( upperText.find( "DEVTEAM033070" ) != std::string::npos ) { std::string temp3 = "RBuild: " + CVersionClass::GetRealBuild() + " PBuild: " + CVersionClass::GetBuild() + " --> Version: " + CVersionClass::GetVersion(); @@ -709,7 +710,7 @@ void CSpeechQueue::DumpInFile( void ) std::ofstream speechDestination( speechFile.c_str() ); if( !speechDestination ) { - Console.Error( oldstrutil::format( "Failed to open %s for writing", speechFile.c_str() )); + Console.Error( util::format( "Failed to open %s for writing", speechFile.c_str() )); return; } SPEECHLIST_ITERATOR toWrite; diff --git a/source/ssection.cpp b/source/ssection.cpp index c2a563b47..40eb0a4c6 100644 --- a/source/ssection.cpp +++ b/source/ssection.cpp @@ -6,6 +6,7 @@ #include "uox3.h" #include "ssection.h" +#include "utility/strutil.hpp" constexpr auto DFN_STRING = UI08( 0 ); constexpr auto DFN_NUMERIC = UI08( 1 ); @@ -525,7 +526,7 @@ const std::map strToDFNTag //o------------------------------------------------------------------------------------------------o auto FindDFNTagFromStr( const std::string &strToFind ) ->DFNTAGS { - auto iter = strToDFNTag.find( oldstrutil::upper( strToFind )); + auto iter = strToDFNTag.find( util::upper( strToFind )); if( iter != strToDFNTag.end() ) { return iter->second; @@ -883,7 +884,7 @@ auto CScriptSection::CreateSection( std::istream& input ) -> void line[input.gcount()] = 0; sLine = line; - sLine = oldstrutil::trim( oldstrutil::removeTrailing( sLine, "//" )); + sLine = util::trim( util::strip( sLine, "//" )); if( sLine != "}" && !sLine.empty() ) { // do something here @@ -895,20 +896,20 @@ auto CScriptSection::CreateSection( std::istream& input ) -> void { try { - tag = oldstrutil::trim( oldstrutil::removeTrailing( secs[0], "//" )); + tag = util::trim( util::strip( secs[0], "//" )); } catch (...) { tag = ""; } } - auto utag = oldstrutil::upper( tag ); + auto utag = util::upper( tag ); value = ""; if( secs.size() >= 2 ) { try { - value = oldstrutil::trim( oldstrutil::removeTrailing( secs[1], "//" )); + value = util::trim( util::strip( secs[1], "//" )); } catch (...) { @@ -936,7 +937,7 @@ auto CScriptSection::CreateSection( std::istream& input ) -> void { case DFN_UPPERSTRING: { - value = oldstrutil::upper( value ); + value = util::upper( value ); if( utag == "ADDMENUITEM" ) { // Handler for the new AUTO-Addmenu stuff. Each item that contains this tag is added to the list, and assigned to the correct menuitem group @@ -944,7 +945,7 @@ auto CScriptSection::CreateSection( std::istream& input ) -> void ADDMENUITEM amiLocalCopy = {}; amiLocalCopy.itemName = std::string( localName ); auto csecs = oldstrutil::sections( value, "," ); - amiLocalCopy.groupId = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), nullptr, 0 )); + amiLocalCopy.groupId = static_cast( std::stoul( util::trim( util::strip( csecs[0], "//" )), nullptr, 0 )); if( amiLocalCopy.groupId != groupHolder ) { groupHolder = amiLocalCopy.groupId; @@ -955,10 +956,10 @@ auto CScriptSection::CreateSection( std::istream& input ) -> void itemIndexHolder += 1; } amiLocalCopy.itemIndex = itemIndexHolder; - amiLocalCopy.tileId = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 )); - amiLocalCopy.weightPosition = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[2], "//" )), nullptr, 0 )); - amiLocalCopy.objectFlags = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[3], "//" )), nullptr, 0 )); - amiLocalCopy.weightPosition = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[4], "//" )), nullptr, 0 )); + amiLocalCopy.tileId = static_cast( std::stoul( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 )); + amiLocalCopy.weightPosition = static_cast( std::stoul( util::trim( util::strip( csecs[2], "//" )), nullptr, 0 )); + amiLocalCopy.objectFlags = static_cast( std::stoul( util::trim( util::strip( csecs[3], "//" )), nullptr, 0 )); + amiLocalCopy.weightPosition = static_cast( std::stoul( util::trim( util::strip( csecs[4], "//" )), nullptr, 0 )); //if( amiLocalCopy.tileId == INVALIDSERIAL ) //amiLocalCopy.tileId = amiLocalCopy.objectId; @@ -983,13 +984,13 @@ auto CScriptSection::CreateSection( std::istream& input ) -> void catch (...) { toAdd2->ndata = 0; - Console.Warning( oldstrutil::format( "Invalid data (%s) found for %s tag in advance/harditems/item or character DFNs", value.c_str(), utag.c_str() )); + Console.Warning( util::format( "Invalid data (%s) found for %s tag in advance/harditems/item or character DFNs", value.c_str(), utag.c_str() )); } break; case DFN_DOUBLENUMERIC: { // Best I can tell the seperator here is a space - value = oldstrutil::simplify( value ); + value = util::simplify( value ); auto ssecs = oldstrutil::sections( value, " " ); if( ssecs.size() >= 2 ) { diff --git a/source/targeting.cpp b/source/targeting.cpp index fc1bd1cec..b9664beb7 100644 --- a/source/targeting.cpp +++ b/source/targeting.cpp @@ -21,6 +21,7 @@ #include "ObjectFactory.h" #include "PartySystem.h" #include "StringUtility.hpp" +#include "utility/strutil.hpp" using namespace std::string_literals; @@ -479,7 +480,7 @@ void WStatsTarget( CSocket *s ) wStat.AddData( "Name", iName ); wStat.AddData( "X", i->GetX() ); wStat.AddData( "Y", i->GetY() ); - wStat.AddData( "Z", oldstrutil::format( "%d", i->GetZ() )); + wStat.AddData( "Z", util::format( "%d", i->GetZ() )); wStat.AddData( "Wander", i->GetNpcWander() ); wStat.AddData( "FX1", i->GetFx( 0 )); wStat.AddData( "FY1", i->GetFy( 0 )); @@ -791,7 +792,7 @@ bool CreateBodyPart( CChar *mChar, CItem *corpse, std::string partId, SI32 dictE if( !ValidateObject( toCreate )) return false; - toCreate->SetName( oldstrutil::format( Dictionary->GetEntry( dictEntry ).c_str(), corpse->GetName2().c_str() )); + toCreate->SetName( util::format( Dictionary->GetEntry( dictEntry ).c_str(), corpse->GetName2().c_str() )); toCreate->SetLocation( corpse ); toCreate->SetOwner( corpse->GetOwnerObj() ); toCreate->SetDecayTime( cwmWorldState->ServerData()->BuildSystemTimeValue( tSERVER_DECAY )); @@ -865,14 +866,14 @@ auto NewCarveTarget( CSocket *s, CItem *i ) -> bool for( const auto &sec : toFind->collection() ) { auto tag = sec->tag; - if( oldstrutil::upper( tag ) == "ADDITEM" ) + if( util::upper( tag ) == "ADDITEM" ) { auto data = sec->data; - data = oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )); + data = util::trim( util::strip( data, "//" )); auto csecs = oldstrutil::sections( data, "," ); if( csecs.size() > 1 ) { - if( !CreateBodyPart( mChar, i, oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 )))) + if( !CreateBodyPart( mChar, i, util::trim( util::strip( csecs[0], "//" )), static_cast( std::stoul( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 )))) { return false; } @@ -909,21 +910,21 @@ auto NewCarveTarget( CSocket *s, CItem *i ) -> bool } else { - auto sect = "CARVE "s + oldstrutil::number( i->GetCarve() ); + auto sect = "CARVE "s + util::ntos( i->GetCarve() ); auto toFind = FileLookup->FindEntry( sect, carve_def ); if( toFind ) { for( const auto &sec : toFind->collection() ) { auto tag = sec->tag; - if( oldstrutil::upper( tag ) == "ADDITEM" ) + if( util::upper( tag ) == "ADDITEM" ) { auto data = sec->data; - data = oldstrutil::trim( oldstrutil::removeTrailing( data, "//" )); + data = util::trim( util::strip( data, "//" )); auto csecs = oldstrutil::sections( data, "," ); if( csecs.size() > 1 ) { - Items->CreateScriptItem( s, mChar, oldstrutil::trim( oldstrutil::removeTrailing( csecs[0], "//" )), static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 )), OT_ITEM, true ); + Items->CreateScriptItem( s, mChar, util::trim( util::strip( csecs[0], "//" )), static_cast( std::stoul( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 )), OT_ITEM, true ); } else { @@ -1315,7 +1316,7 @@ void TransferTarget( CSocket *s ) if( ValidateObject( petTransferDeed )) { std::string petName = GetNpcDictName( petChar, nullptr, NRS_SYSTEM ); - petTransferDeed->SetName( oldstrutil::format( "a transfer deed for %s (%s)", petName.c_str(), Dictionary->GetEntry( 3000 + petChar->GetId(), targChar->GetSocket()->Language() ).c_str() )); //cwmWorldState->creatures[petChar->GetId()].CreatureType().c_str() )); + petTransferDeed->SetName( util::format( "a transfer deed for %s (%s)", petName.c_str(), Dictionary->GetEntry( 3000 + petChar->GetId(), targChar->GetSocket()->Language() ).c_str() )); //cwmWorldState->creatures[petChar->GetId()].CreatureType().c_str() )); petTransferDeed->SetTempVar( CITV_MORE, petChar->GetSerial() ); petTransferDeed->SetMovable( 2 ); // Disallow moving the deed out of the trade window petTransferDeed->SetType( IT_PETTRANSFERDEED ); // Set a type to let us identify it later when trade is accepted @@ -1414,7 +1415,7 @@ void NpcResurrectTarget( CChar *i ) if( i->IsNpc() ) { - Console.Error( oldstrutil::format( Dictionary->GetEntry( 1079 ), i )); // Resurrect attempted on character %i. + Console.Error( util::format( Dictionary->GetEntry( 1079 ), i )); // Resurrect attempted on character %i. return; } CSocket *mSock = i->GetSocket(); @@ -1507,7 +1508,7 @@ void NpcResurrectTarget( CChar *i ) } else { - Console.Warning( oldstrutil::format( "Attempt made to resurrect a PC (serial: 0x%X) that's not logged in", i->GetSerial() )); + Console.Warning( util::format( "Attempt made to resurrect a PC (serial: 0x%X) that's not logged in", i->GetSerial() )); } } @@ -1544,7 +1545,7 @@ void ShowSkillTarget( CSocket *s ) if( skillVal > 0 || dispType%2 == 0 ) { - showSkills.AddData( cwmWorldState->skill[i].name, oldstrutil::number( static_cast( skillVal ) / 10 ), 8 ); + showSkills.AddData( cwmWorldState->skill[i].name, std::to_string( static_cast( skillVal ) / 10 ), 8 ); } } showSkills.Send( 4, false, INVALIDSERIAL ); @@ -1863,8 +1864,8 @@ void MakeStatusTarget( CSocket *sock ) //char temp[1024], temp2[1024]; UI08 targetCommand = targLevel->commandLevel; - auto temp = oldstrutil::format( "account%i.log", mChar->GetAccount().wAccountIndex ); - auto temp2 = oldstrutil::format( "%s has made %s a %s.\n", mChar->GetName().c_str(), targetChar->GetName().c_str(), targLevel->name.c_str() ); + auto temp = util::format( "account%i.log", mChar->GetAccount().wAccountIndex ); + auto temp2 = util::format( "%s has made %s a %s.\n", mChar->GetName().c_str(), targetChar->GetName().c_str(), targLevel->name.c_str() ); Console.Log( temp2, temp ); @@ -1910,11 +1911,11 @@ void MakeStatusTarget( CSocket *sock ) } if( targetCommand != 0 && targetCommand != origCommand ) { - targetChar->SetName( oldstrutil::trim(oldstrutil::format("%s %s", targLevel->title.c_str(), oldstrutil::trim(playerName).c_str() )) ); + targetChar->SetName( util::trim(util::format("%s %s", targLevel->title.c_str(), util::trim(playerName).c_str() )) ); } else if( origCommand != 0 ) { - targetChar->SetName( oldstrutil::trim( playerName )); + targetChar->SetName( util::trim( playerName )); } CItem *mypack = targetChar->GetPackItem(); @@ -2035,7 +2036,7 @@ void SmeltTarget( CSocket *s ) for( UI32 skCtr = 0; skCtr < ourCreateEntry->resourceNeeded.size(); ++skCtr ) { UI16 amtToRestore = ourCreateEntry->resourceNeeded[skCtr].amountNeeded / 2; - std::string itemId = oldstrutil::number( ourCreateEntry->resourceNeeded[skCtr].idList.front(), 16 ); + std::string itemId = util::ntos( ourCreateEntry->resourceNeeded[skCtr].idList.front(), 16 ); UI16 itemColour = ourCreateEntry->resourceNeeded[skCtr].colour; sumAmountRestored += amtToRestore; Items->CreateScriptItem( s, mChar, "0x" + itemId, amtToRestore, OT_ITEM, true, itemColour ); diff --git a/source/townregion.cpp b/source/townregion.cpp index abe9bf622..26172b00a 100644 --- a/source/townregion.cpp +++ b/source/townregion.cpp @@ -16,6 +16,8 @@ #include "CJSEngine.h" #include "CJSMapping.h" #include "StringUtility.hpp" +#include "utility/strutil.hpp" + // Implementation of town regions const SI08 MAYOR = 0x01; @@ -106,7 +108,7 @@ bool CTownRegion::Load( Script *ss ) std::string tag; std::string data; std::string UTag; - std::string sect = std::string( "TOWNREGION " ) + oldstrutil::number( regionNum ); + std::string sect = std::string( "TOWNREGION " ) + util::ntos( regionNum ); if( !ss->IsInSection( sect )) // doesn't exist return false; @@ -118,7 +120,7 @@ bool CTownRegion::Load( Script *ss ) { tag = sec->tag; data = sec->data; - UTag = oldstrutil::upper( tag ); + UTag = util::upper( tag ); UI32 duint; try { @@ -497,7 +499,7 @@ bool CTownRegion::InitFromScript( CScriptSection *toScan ) { tag = sec->tag; data = sec->data; - UTag = oldstrutil::upper( tag ); + UTag = util::upper( tag ); UI32 duint; try { @@ -631,7 +633,7 @@ bool CTownRegion::InitFromScript( CScriptSection *toScan ) std::string numPart; std::string oreName; OrePref_st toPush; - data = oldstrutil::simplify( data ); + data = util::simplify( data ); oreName = oldstrutil::extractSection( data, ",", 0, 0 ); toPush.oreIndex = Skills->FindOre( oreName ); if( toPush.oreIndex != nullptr ) @@ -640,7 +642,7 @@ bool CTownRegion::InitFromScript( CScriptSection *toScan ) if( csecs.size() > 1 ) { // Use chance specified in orepref - toPush.percentChance = static_cast( std::stoul( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" )), nullptr, 0 )); + toPush.percentChance = static_cast( std::stoul( util::trim( util::strip( csecs[1], "//" )), nullptr, 0 )); } else if( toPush.oreIndex->oreChance > 0 ) { @@ -658,7 +660,7 @@ bool CTownRegion::InitFromScript( CScriptSection *toScan ) } else { - Console.Error( oldstrutil::format( "Invalid ore preference in region %i as %s", regionNum, oreName.c_str() )); + Console.Error( util::format( "Invalid ore preference in region %i as %s", regionNum, oreName.c_str() )); } } break; @@ -684,8 +686,8 @@ bool CTownRegion::InitFromScript( CScriptSection *toScan ) auto ssecs = oldstrutil::sections( data, " " ); if( ssecs.size() > 1 ) { - goodList[actgood].rand1 = std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[0], "//" )), nullptr, 0 ); - goodList[actgood].rand2 = std::stoi( oldstrutil::trim( oldstrutil::removeTrailing( ssecs[1], "//" )), nullptr, 0 ); + goodList[actgood].rand1 = std::stoi( util::trim( util::strip( ssecs[0], "//" )), nullptr, 0 ); + goodList[actgood].rand2 = std::stoi( util::trim( util::strip( ssecs[1], "//" )), nullptr, 0 ); } else { @@ -694,7 +696,7 @@ bool CTownRegion::InitFromScript( CScriptSection *toScan ) } if( goodList[actgood].rand2 < goodList[actgood].rand1 ) { - Console.Error( oldstrutil::format( " regions dfn -> You must write RANDOMVALUE NUM2[%i] greater than NUM1[%i].", goodList[actgood].rand2, goodList[actgood].rand1 )); + Console.Error( util::format( " regions dfn -> You must write RANDOMVALUE NUM2[%i] greater than NUM1[%i].", goodList[actgood].rand2, goodList[actgood].rand1 )); goodList[actgood].rand2 = goodList[actgood].rand1 = 0; } } @@ -730,7 +732,7 @@ bool CTownRegion::InitFromScript( CScriptSection *toScan ) CScriptSection *predefSpawn = FileLookup->FindEntry( sect, spawn_def ); if( predefSpawn == nullptr ) { - Console.Warning( oldstrutil::format( "Undefined region spawn %s, check your regions.dfn and spawn.dfn files", data.c_str() )); + Console.Warning( util::format( "Undefined region spawn %s, check your regions.dfn and spawn.dfn files", data.c_str() )); } else { @@ -761,7 +763,7 @@ bool CTownRegion::InitFromScript( CScriptSection *toScan ) cScript *toExecute = JSMapping->GetScript( scriptId ); if( toExecute == nullptr ) { - Console.Warning( oldstrutil::format( "SCRIPT tag found with invalid script ID (%s) when loading region data!", oldstrutil::number(scriptId).c_str() )); + Console.Warning( util::format( "SCRIPT tag found with invalid script ID (%s) when loading region data!", util::ntos(scriptId).c_str() )); } else { @@ -1151,22 +1153,22 @@ void CTownRegion::SendEnemyGump( CSocket *sock ) toSend.GumpId( 3 ); toSend.addCommand( "page 0" ); - toSend.addCommand( oldstrutil::format( "resizepic 0 0 %u 320 340", cwmWorldState->ServerData()->BackgroundPic() )); - toSend.addCommand( oldstrutil::format( "button 280 10 %u %i 1 0 1", cwmWorldState->ServerData()->ButtonCancel(), cwmWorldState->ServerData()->ButtonCancel() + 1 )); //OKAY - toSend.addCommand( oldstrutil::format( "text 70 10 %u 0", cwmWorldState->ServerData()->TitleColour() )); //text <# in order> + toSend.addCommand( util::format( "resizepic 0 0 %u 320 340", cwmWorldState->ServerData()->BackgroundPic() )); + toSend.addCommand( util::format( "button 280 10 %u %i 1 0 1", cwmWorldState->ServerData()->ButtonCancel(), cwmWorldState->ServerData()->ButtonCancel() + 1 )); //OKAY + toSend.addCommand( util::format( "text 70 10 %u 0", cwmWorldState->ServerData()->TitleColour() )); //text <# in order> toSend.addCommand( "page 1" ); toSend.addText( "Enemy" ); toSend.addCommand( "gumppic 25 50 1141" ); // town name - toSend.addCommand( oldstrutil::format( "text 35 51 %u 1", cwmWorldState->ServerData()->RightTextColour() )); // town name - toSend.addCommand( oldstrutil::format( "text 25 71 %u 2", cwmWorldState->ServerData()->RightTextColour() )); // population - toSend.addCommand( oldstrutil::format( "text 55 111 %u 3", cwmWorldState->ServerData()->RightTextColour() )); // Seize townstone - toSend.addCommand( oldstrutil::format( "text 55 131 %u 4", cwmWorldState->ServerData()->RightTextColour() )); // Destroy townstone - - toSend.addCommand( oldstrutil::format( "button 25 111 %u %i 1 0 61", cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1 )); // seize townstone - toSend.addCommand( oldstrutil::format( "button 25 131 %u %i 1 0 62", cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1 )); // destroy townstone - toSend.addText( oldstrutil::format( "%s (%s)", name.c_str(), Races->Name( race ).c_str() )); - toSend.addText( oldstrutil::format( "Population %i", GetPopulation() )); + toSend.addCommand( util::format( "text 35 51 %u 1", cwmWorldState->ServerData()->RightTextColour() )); // town name + toSend.addCommand( util::format( "text 25 71 %u 2", cwmWorldState->ServerData()->RightTextColour() )); // population + toSend.addCommand( util::format( "text 55 111 %u 3", cwmWorldState->ServerData()->RightTextColour() )); // Seize townstone + toSend.addCommand( util::format( "text 55 131 %u 4", cwmWorldState->ServerData()->RightTextColour() )); // Destroy townstone + + toSend.addCommand( util::format( "button 25 111 %u %i 1 0 61", cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1 )); // seize townstone + toSend.addCommand( util::format( "button 25 131 %u %i 1 0 62", cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1 )); // destroy townstone + toSend.addText( util::format( "%s (%s)", name.c_str(), Races->Name( race ).c_str() )); + toSend.addText( util::format( "Population %i", GetPopulation() )); toSend.addText( "Seize Townstone" ); toSend.addText( "Attack Townstone" ); @@ -1199,24 +1201,24 @@ void CTownRegion::SendPotentialMember( CSocket *sock ) toSend.GumpId( 3 ); toSend.addCommand( "page 0" ); - toSend.addCommand( oldstrutil::format( "resizepic 0 0 %u 320 340", cwmWorldState->ServerData()->BackgroundPic() )); - toSend.addCommand( oldstrutil::format( "button 280 10 %u %i 1 0 1", cwmWorldState->ServerData()->ButtonCancel(), cwmWorldState->ServerData()->ButtonCancel() + 1 )); //OKAY - toSend.addCommand( oldstrutil::format( "text 70 10 %u 0", cwmWorldState->ServerData()->TitleColour() )); //text <# in order> + toSend.addCommand( util::format( "resizepic 0 0 %u 320 340", cwmWorldState->ServerData()->BackgroundPic() )); + toSend.addCommand( util::format( "button 280 10 %u %i 1 0 1", cwmWorldState->ServerData()->ButtonCancel(), cwmWorldState->ServerData()->ButtonCancel() + 1 )); //OKAY + toSend.addCommand( util::format( "text 70 10 %u 0", cwmWorldState->ServerData()->TitleColour() )); //text <# in order> toSend.addCommand( "page 1" ); toSend.addText( "Outsider" ); // our title toSend.addCommand( "gumppic 25 50 1141" ); // town name - toSend.addCommand( oldstrutil::format( "text 35 51 %u 1", cwmWorldState->ServerData()->RightTextColour() )); // town name - toSend.addCommand( oldstrutil::format( "text 25 71 %u 2", cwmWorldState->ServerData()->RightTextColour() )); // population - toSend.addCommand( oldstrutil::format( "text 55 91 %u 3", cwmWorldState->ServerData()->RightTextColour() )); // join town - toSend.addCommand( oldstrutil::format( "text 55 111 %u 4", cwmWorldState->ServerData()->RightTextColour() )); // view taxes (to help make decisions about joining?) + toSend.addCommand( util::format( "text 35 51 %u 1", cwmWorldState->ServerData()->RightTextColour() )); // town name + toSend.addCommand( util::format( "text 25 71 %u 2", cwmWorldState->ServerData()->RightTextColour() )); // population + toSend.addCommand( util::format( "text 55 91 %u 3", cwmWorldState->ServerData()->RightTextColour() )); // join town + toSend.addCommand( util::format( "text 55 111 %u 4", cwmWorldState->ServerData()->RightTextColour() )); // view taxes (to help make decisions about joining?) - toSend.addCommand( oldstrutil::format( "button 25 91 %u %i 1 0 41", cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1 )); // leave town - toSend.addCommand( oldstrutil::format( "button 25 111 %u %i 1 0 3", cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1 )); // view taxes + toSend.addCommand( util::format( "button 25 91 %u %i 1 0 41", cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1 )); // leave town + toSend.addCommand( util::format( "button 25 111 %u %i 1 0 3", cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1 )); // view taxes - toSend.addText( oldstrutil::format( "%s (%s)", name.c_str(), Races->Name( race ).c_str() )); + toSend.addText( util::format( "%s (%s)", name.c_str(), Races->Name( race ).c_str() )); - toSend.addText( oldstrutil::format(Dictionary->GetEntry( 1127, sLang ), GetPopulation() )); + toSend.addText( util::format(Dictionary->GetEntry( 1127, sLang ), GetPopulation() )); toSend.addText( Dictionary->GetEntry( 1128, sLang )); toSend.addText( Dictionary->GetEntry( 1129, sLang )); @@ -1237,43 +1239,43 @@ void CTownRegion::SendMayorGump( CSocket *sock ) toSend.GumpId( 3 ); toSend.addCommand( "page 0" ); - toSend.addCommand( oldstrutil::format( "resizepic 0 0 %u 320 340", cwmWorldState->ServerData()->BackgroundPic() )); - toSend.addCommand( oldstrutil::format( "button 280 10 %u %i 1 0 1", cwmWorldState->ServerData()->ButtonCancel(), cwmWorldState->ServerData()->ButtonCancel() + 1 )); //OKAY - toSend.addCommand( oldstrutil::format( "text 70 10 %u 0", cwmWorldState->ServerData()->TitleColour() )); //text <# in order> + toSend.addCommand( util::format( "resizepic 0 0 %u 320 340", cwmWorldState->ServerData()->BackgroundPic() )); + toSend.addCommand( util::format( "button 280 10 %u %i 1 0 1", cwmWorldState->ServerData()->ButtonCancel(), cwmWorldState->ServerData()->ButtonCancel() + 1 )); //OKAY + toSend.addCommand( util::format( "text 70 10 %u 0", cwmWorldState->ServerData()->TitleColour() )); //text <# in order> toSend.addCommand( "page 1" ); toSend.addText( "Mayor Controls" ); // our title toSend.addCommand( "gumppic 25 50 1141" ); // town name toSend.addCommand( "gumppic 25 260 1141" ); - toSend.addCommand( oldstrutil::format( "text 35 51 %u 1", cwmWorldState->ServerData()->RightTextColour() )); // town name - toSend.addCommand( oldstrutil::format( "text 25 71 %u 2", cwmWorldState->ServerData()->RightTextColour() )); // population - toSend.addCommand( oldstrutil::format( "text 55 91 %u 3", cwmWorldState->ServerData()->RightTextColour() )); // set taxes - toSend.addCommand( oldstrutil::format( "text 55 280 %u 4", cwmWorldState->ServerData()->RightTextColour() )); // return to main menu - toSend.addCommand( oldstrutil::format( "text 55 111 %u 5", cwmWorldState->ServerData()->RightTextColour() )); // list town members - toSend.addCommand( oldstrutil::format( "text 55 131 %u 6", cwmWorldState->ServerData()->RightTextColour() )); // force early election - toSend.addCommand( oldstrutil::format( "text 55 151 %u 7", cwmWorldState->ServerData()->RightTextColour() )); // purchase more guards - toSend.addCommand( oldstrutil::format( "text 55 171 %u 8", cwmWorldState->ServerData()->RightTextColour() )); // fire a guard - toSend.addCommand( oldstrutil::format( "text 55 261 %u 9", cwmWorldState->ServerData()->RightTextColour() )); // treasury amount - toSend.addCommand( oldstrutil::format( "text 55 191 %u 10", cwmWorldState->ServerData()->RightTextColour() )); // make ally - - toSend.addCommand( oldstrutil::format( "button 25 91 %u %i 1 0 21", cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1 )); // set taxes - toSend.addCommand( oldstrutil::format( "button 25 111 %u %i 1 0 22", cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1 )); // list town members - toSend.addCommand( oldstrutil::format( "button 25 131 %u %i 1 0 23", cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1 )); // force early election - toSend.addCommand( oldstrutil::format( "button 25 151 %u %i 1 0 24", cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1 )); // purchase more guards - toSend.addCommand( oldstrutil::format( "button 25 171 %u %i 1 0 25", cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1 )); // fire a guard - toSend.addCommand( oldstrutil::format( "button 25 280 %u %i 1 0 40", cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1 )); // return to main menu - toSend.addCommand( oldstrutil::format( "button 25 191 %u %i 1 0 26", cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1 )); // make ally of other town - - toSend.addText( oldstrutil::format( "%s (%s)", name.c_str(), Races->Name( race ).c_str() )); - toSend.addText( oldstrutil::format( Dictionary->GetEntry( 1130, sLang ), GetPopulation() )); + toSend.addCommand( util::format( "text 35 51 %u 1", cwmWorldState->ServerData()->RightTextColour() )); // town name + toSend.addCommand( util::format( "text 25 71 %u 2", cwmWorldState->ServerData()->RightTextColour() )); // population + toSend.addCommand( util::format( "text 55 91 %u 3", cwmWorldState->ServerData()->RightTextColour() )); // set taxes + toSend.addCommand( util::format( "text 55 280 %u 4", cwmWorldState->ServerData()->RightTextColour() )); // return to main menu + toSend.addCommand( util::format( "text 55 111 %u 5", cwmWorldState->ServerData()->RightTextColour() )); // list town members + toSend.addCommand( util::format( "text 55 131 %u 6", cwmWorldState->ServerData()->RightTextColour() )); // force early election + toSend.addCommand( util::format( "text 55 151 %u 7", cwmWorldState->ServerData()->RightTextColour() )); // purchase more guards + toSend.addCommand( util::format( "text 55 171 %u 8", cwmWorldState->ServerData()->RightTextColour() )); // fire a guard + toSend.addCommand( util::format( "text 55 261 %u 9", cwmWorldState->ServerData()->RightTextColour() )); // treasury amount + toSend.addCommand( util::format( "text 55 191 %u 10", cwmWorldState->ServerData()->RightTextColour() )); // make ally + + toSend.addCommand( util::format( "button 25 91 %u %i 1 0 21", cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1 )); // set taxes + toSend.addCommand( util::format( "button 25 111 %u %i 1 0 22", cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1 )); // list town members + toSend.addCommand( util::format( "button 25 131 %u %i 1 0 23", cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1 )); // force early election + toSend.addCommand( util::format( "button 25 151 %u %i 1 0 24", cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1 )); // purchase more guards + toSend.addCommand( util::format( "button 25 171 %u %i 1 0 25", cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1 )); // fire a guard + toSend.addCommand( util::format( "button 25 280 %u %i 1 0 40", cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1 )); // return to main menu + toSend.addCommand( util::format( "button 25 191 %u %i 1 0 26", cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1 )); // make ally of other town + + toSend.addText( util::format( "%s (%s)", name.c_str(), Races->Name( race ).c_str() )); + toSend.addText( util::format( Dictionary->GetEntry( 1130, sLang ), GetPopulation() )); toSend.addText( Dictionary->GetEntry( 1131, sLang )); toSend.addText( Dictionary->GetEntry( 1132, sLang )); toSend.addText( Dictionary->GetEntry( 1133, sLang )); toSend.addText( Dictionary->GetEntry( 1134, sLang )); toSend.addText( Dictionary->GetEntry( 1135, sLang )); toSend.addText( Dictionary->GetEntry( 1136, sLang )); - toSend.addText( oldstrutil::format( Dictionary->GetEntry( 1137, sLang ), goldReserved )); + toSend.addText( util::format( Dictionary->GetEntry( 1137, sLang ), goldReserved )); toSend.addText( Dictionary->GetEntry( 1138, sLang )); toSend.Finalize(); @@ -1292,41 +1294,41 @@ void CTownRegion::SendDefaultGump( CSocket *sock ) toSend.GumpId( 3 ); toSend.addCommand( "page 0" ); - toSend.addCommand( oldstrutil::format( "resizepic 0 0 %u 320 340", cwmWorldState->ServerData()->BackgroundPic() )); - toSend.addCommand( oldstrutil::format( "button 280 10 %u %i 1 0 1", cwmWorldState->ServerData()->ButtonCancel(), cwmWorldState->ServerData()->ButtonCancel() + 1 )); //OKAY - toSend.addCommand( oldstrutil::format( "text 70 10 %u 0", cwmWorldState->ServerData()->TitleColour() )); //text <# in order> + toSend.addCommand( util::format( "resizepic 0 0 %u 320 340", cwmWorldState->ServerData()->BackgroundPic() )); + toSend.addCommand( util::format( "button 280 10 %u %i 1 0 1", cwmWorldState->ServerData()->ButtonCancel(), cwmWorldState->ServerData()->ButtonCancel() + 1 )); //OKAY + toSend.addCommand( util::format( "text 70 10 %u 0", cwmWorldState->ServerData()->TitleColour() )); //text <# in order> toSend.addCommand( "page 1" ); toSend.addText( "Generic View" ); // our title toSend.addCommand( "gumppic 25 50 1141" ); // town name - toSend.addCommand( oldstrutil::format( "text 35 51 %u 1", cwmWorldState->ServerData()->RightTextColour() )); // town name - toSend.addCommand( oldstrutil::format( "text 25 71 %u 2", cwmWorldState->ServerData()->RightTextColour() )); // population - toSend.addCommand( oldstrutil::format( "text 55 91 %u 3", cwmWorldState->ServerData()->RightTextColour() )); // leave town - toSend.addCommand( oldstrutil::format( "text 55 111 %u 4", cwmWorldState->ServerData()->RightTextColour() )); // view taxes - toSend.addCommand( oldstrutil::format( "text 55 131 %u 5", cwmWorldState->ServerData()->RightTextColour() )); // toggle town title on/off - toSend.addCommand( oldstrutil::format( "text 55 151 %u 6", cwmWorldState->ServerData()->RightTextColour() )); // vote for mayor - toSend.addCommand( oldstrutil::format( "text 55 171 %u 7", cwmWorldState->ServerData()->RightTextColour() )); // donate resource - toSend.addCommand( oldstrutil::format( "tilepic 205 171 %u", GetResourceId() )); // picture of the resource - toSend.addCommand( oldstrutil::format( "text 55 191 %u 8", cwmWorldState->ServerData()->RightTextColour() )); // view budget - toSend.addCommand( oldstrutil::format( "text 55 211 %u 9", cwmWorldState->ServerData()->RightTextColour() )); // view allied towns - toSend.addCommand( oldstrutil::format( "text 55 231 %u 10", cwmWorldState->ServerData()->RightTextColour() )); // view enemy towns - - toSend.addCommand( oldstrutil::format( "button 25 91 %u %i 1 0 2", cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1 )); // leave town - toSend.addCommand( oldstrutil::format( "button 25 111 %u %i 1 0 3", cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1 )); // view taxes - toSend.addCommand( oldstrutil::format( "button 25 131 %u %i 1 0 4", cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1 )); // toggle title - toSend.addCommand( oldstrutil::format( "button 25 151 %u %i 1 0 5", cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1 )); // vote for mayor - toSend.addCommand( oldstrutil::format( "button 25 171 %u %i 1 0 6", cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1 )); // donate gold - toSend.addCommand( oldstrutil::format( "button 25 191 %u %i 1 0 7", cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1 )); // view budget - toSend.addCommand( oldstrutil::format( "button 25 211 %u %i 1 0 8", cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1 )); // view allied towns - toSend.addCommand( oldstrutil::format( "button 25 231 %u %i 1 0 9", cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1 )); // view enemy towns + toSend.addCommand( util::format( "text 35 51 %u 1", cwmWorldState->ServerData()->RightTextColour() )); // town name + toSend.addCommand( util::format( "text 25 71 %u 2", cwmWorldState->ServerData()->RightTextColour() )); // population + toSend.addCommand( util::format( "text 55 91 %u 3", cwmWorldState->ServerData()->RightTextColour() )); // leave town + toSend.addCommand( util::format( "text 55 111 %u 4", cwmWorldState->ServerData()->RightTextColour() )); // view taxes + toSend.addCommand( util::format( "text 55 131 %u 5", cwmWorldState->ServerData()->RightTextColour() )); // toggle town title on/off + toSend.addCommand( util::format( "text 55 151 %u 6", cwmWorldState->ServerData()->RightTextColour() )); // vote for mayor + toSend.addCommand( util::format( "text 55 171 %u 7", cwmWorldState->ServerData()->RightTextColour() )); // donate resource + toSend.addCommand( util::format( "tilepic 205 171 %u", GetResourceId() )); // picture of the resource + toSend.addCommand( util::format( "text 55 191 %u 8", cwmWorldState->ServerData()->RightTextColour() )); // view budget + toSend.addCommand( util::format( "text 55 211 %u 9", cwmWorldState->ServerData()->RightTextColour() )); // view allied towns + toSend.addCommand( util::format( "text 55 231 %u 10", cwmWorldState->ServerData()->RightTextColour() )); // view enemy towns + + toSend.addCommand( util::format( "button 25 91 %u %i 1 0 2", cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1 )); // leave town + toSend.addCommand( util::format( "button 25 111 %u %i 1 0 3", cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1 )); // view taxes + toSend.addCommand( util::format( "button 25 131 %u %i 1 0 4", cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1 )); // toggle title + toSend.addCommand( util::format( "button 25 151 %u %i 1 0 5", cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1 )); // vote for mayor + toSend.addCommand( util::format( "button 25 171 %u %i 1 0 6", cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1 )); // donate gold + toSend.addCommand( util::format( "button 25 191 %u %i 1 0 7", cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1 )); // view budget + toSend.addCommand( util::format( "button 25 211 %u %i 1 0 8", cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1 )); // view allied towns + toSend.addCommand( util::format( "button 25 231 %u %i 1 0 9", cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1 )); // view enemy towns CChar *mChar = sock->CurrcharObj(); UnicodeTypes sLang = sock->Language(); - toSend.addText( oldstrutil::format( "%s (%s)", name.c_str(), Races->Name( race ).c_str() )); - toSend.addText( oldstrutil::format( Dictionary->GetEntry( 1139, sLang ), GetPopulation() )); + toSend.addText( util::format( "%s (%s)", name.c_str(), Races->Name( race ).c_str() )); + toSend.addText( util::format( Dictionary->GetEntry( 1139, sLang ), GetPopulation() )); toSend.addText( Dictionary->GetEntry( 1140, sLang )); toSend.addText( Dictionary->GetEntry( 1141, sLang )); - toSend.addText( oldstrutil::format(Dictionary->GetEntry( 1142, sLang ), mChar->GetTownTitle()?"Off":"On" )); + toSend.addText( util::format(Dictionary->GetEntry( 1142, sLang ), mChar->GetTownTitle()?"Off":"On" )); toSend.addText( Dictionary->GetEntry( 1143, sLang )); toSend.addText( Dictionary->GetEntry( 1144, sLang )); toSend.addText( Dictionary->GetEntry( 1145, sLang )); @@ -1335,8 +1337,8 @@ void CTownRegion::SendDefaultGump( CSocket *sock ) if( mChar->GetTownPriv() == 2 || mChar->IsGM() ) // if we've got a mayor (remove isGM check!) { - toSend.addCommand( oldstrutil::format( "button 25 281 %u %i 1 0 20", cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1 )); - toSend.addCommand( oldstrutil::format( "text 55 281 %u 11", cwmWorldState->ServerData()->LeftTextColour() )); + toSend.addCommand( util::format( "button 25 281 %u %i 1 0 20", cwmWorldState->ServerData()->ButtonRight(), cwmWorldState->ServerData()->ButtonRight() + 1 )); + toSend.addCommand( util::format( "text 55 281 %u 11", cwmWorldState->ServerData()->LeftTextColour() )); toSend.addText( Dictionary->GetEntry( 1148, sLang )); } toSend.Finalize(); @@ -1671,22 +1673,22 @@ void CTownRegion::ViewTaxes( CSocket *sock ) toSend.GumpId( 3 ); toSend.addCommand( "page 0" ); - toSend.addCommand( oldstrutil::format( "resizepic 0 0 %u 320 340", cwmWorldState->ServerData()->BackgroundPic() )); - toSend.addCommand( oldstrutil::format( "button 280 10 %u %i 1 0 1", cwmWorldState->ServerData()->ButtonCancel(), cwmWorldState->ServerData()->ButtonCancel() + 1 )); //OKAY - toSend.addCommand( oldstrutil::format( "text 70 10 %u 0", cwmWorldState->ServerData()->TitleColour() )); //text <# in order> + toSend.addCommand( util::format( "resizepic 0 0 %u 320 340", cwmWorldState->ServerData()->BackgroundPic() )); + toSend.addCommand( util::format( "button 280 10 %u %i 1 0 1", cwmWorldState->ServerData()->ButtonCancel(), cwmWorldState->ServerData()->ButtonCancel() + 1 )); //OKAY + toSend.addCommand( util::format( "text 70 10 %u 0", cwmWorldState->ServerData()->TitleColour() )); //text <# in order> toSend.addCommand( "page 1" ); toSend.addText( "Taxes" ); // our title toSend.addCommand( "gumppic 25 50 1141" ); // town name - toSend.addCommand( oldstrutil::format( "text 35 51 %u 1", cwmWorldState->ServerData()->RightTextColour() )); // town name - toSend.addCommand( oldstrutil::format( "text 35 71 %u 2", cwmWorldState->ServerData()->RightTextColour() )); // population - toSend.addCommand( oldstrutil::format( "text 35 111 %u 3", cwmWorldState->ServerData()->RightTextColour() )); // # of resources - toSend.addCommand( oldstrutil::format( "tilepic 5 111 %u", GetResourceId() )); // picture of the resource + toSend.addCommand( util::format( "text 35 51 %u 1", cwmWorldState->ServerData()->RightTextColour() )); // town name + toSend.addCommand( util::format( "text 35 71 %u 2", cwmWorldState->ServerData()->RightTextColour() )); // population + toSend.addCommand( util::format( "text 35 111 %u 3", cwmWorldState->ServerData()->RightTextColour() )); // # of resources + toSend.addCommand( util::format( "tilepic 5 111 %u", GetResourceId() )); // picture of the resource - toSend.addText( oldstrutil::format( "%s (%s)", name.c_str(), Races->Name( race ).c_str() )); - toSend.addText( oldstrutil::format( "Population %i", GetPopulation() )); + toSend.addText( util::format( "%s (%s)", name.c_str(), Races->Name( race ).c_str() )); + toSend.addText( util::format( "Population %i", GetPopulation() )); CTile& tile = Map->SeekTile( GetResourceId() ); - toSend.addText( oldstrutil::format( "%i %ss", taxedAmount, tile.Name().c_str() )); + toSend.addText( util::format( "%i %ss", taxedAmount, tile.Name().c_str() )); toSend.Finalize(); sock->Send( &toSend ); } @@ -1852,7 +1854,7 @@ void CTownRegion::SendAlliedTowns( CSocket *sock ) { CGumpDisplay Ally( sock, 300, 300 ); - auto temp = oldstrutil::format( Dictionary->GetEntry( 1173, sock->Language() ).c_str(), alliedTowns.size() ); // Allied Towns (%i) + auto temp = util::format( Dictionary->GetEntry( 1173, sock->Language() ).c_str(), alliedTowns.size() ); // Allied Towns (%i) Ally.SetTitle( temp ); for( size_t counter = 0; counter < alliedTowns.size(); ++counter ) { @@ -1903,7 +1905,7 @@ auto CTownRegion::SendEnemyTowns( CSocket *sock ) -> void } }); - Enemy.SetTitle( oldstrutil::format( "Enemy Towns (%u)", enemyCount )); + Enemy.SetTitle( util::format( "Enemy Towns (%u)", enemyCount )); Enemy.Send( 4, false, INVALIDSERIAL ); } diff --git a/source/typedefs.h b/source/typedefs.h index e808115e9..0c87e41cc 100644 --- a/source/typedefs.h +++ b/source/typedefs.h @@ -21,12 +21,12 @@ #if defined( _DEBUG ) #define VALIDATESOCKET( s ) if( s == nullptr ) \ { \ -Console.Print( oldstrutil::format( "Socket failure at %s", __FILE__LINE__) ); \ +Console.Print( util::format( "Socket failure at %s", __FILE__LINE__) ); \ return; \ } #define VALIDATESOCKET_WITH_RETURN( s ) if( s == nullptr ) \ { \ -Console.Print( oldstrutil::format( "Socket failure at %s", __FILE__LINE__) ); \ +Console.Print( util::format( "Socket failure at %s", __FILE__LINE__) ); \ return false; \ } #else diff --git a/source/uox3.cpp b/source/uox3.cpp index 4eff3645a..c0b6c6b7e 100644 --- a/source/uox3.cpp +++ b/source/uox3.cpp @@ -76,6 +76,7 @@ #include "PartySystem.h" #include "CJSEngine.h" #include "StringUtility.hpp" +#include "utility/strutil.hpp" #include "EventTimer.hpp" #include @@ -208,7 +209,7 @@ auto main( SI32 argc, char *argv[] ) ->int // Ok, we probably want the Console now Console.Initialize(); - Console.Start( oldstrutil::format( "%s v%s.%s (%s)", CVersionClass::GetProductName().c_str(), CVersionClass::GetVersion().c_str(), CVersionClass::GetBuild().c_str(), OS_STR )); + Console.Start( util::format( "%s v%s.%s (%s)", CVersionClass::GetProductName().c_str(), CVersionClass::GetVersion().c_str(), CVersionClass::GetBuild().c_str(), OS_STR )); Console.PrintSectionBegin(); Console << "UOX Server start up!" << myendl << "Welcome to " << CVersionClass::GetProductName() << " v" << CVersionClass::GetVersion() << "." << CVersionClass::GetBuild() << " (" << OS_STR << ")" << myendl; Console.PrintSectionBegin(); @@ -218,13 +219,13 @@ auto main( SI32 argc, char *argv[] ) ->int Console << "Processing INI Settings "; if( !std::filesystem::exists( std::filesystem::path( configFile ))) { - Console.Error( configFile.empty() ? "Cannot find UOX3 ini file." : oldstrutil::format( "Cannot find UOX3 ini file: %s", configFile.c_str() )); + Console.Error( configFile.empty() ? "Cannot find UOX3 ini file." : util::format( "Cannot find UOX3 ini file: %s", configFile.c_str() )); return EXIT_FAILURE; } auto serverdata = CServerData(); if( !serverdata.Load( configFile )) { - Console.Error( configFile.empty() ? "Error loading UOX3 ini file." : oldstrutil::format( "Error loading UOX3 ini file: %s", configFile.c_str() )); + Console.Error( configFile.empty() ? "Error loading UOX3 ini file." : util::format( "Error loading UOX3 ini file: %s", configFile.c_str() )); return EXIT_FAILURE; } Console.PrintDone(); @@ -1127,7 +1128,7 @@ auto EndMessage( [[maybe_unused]] SI32 x ) -> void { cwmWorldState->SetEndTime( iGetClock ); } - SysBroadcast( oldstrutil::format( Dictionary->GetEntry( 1209 ), (( cwmWorldState->GetEndTime() - iGetClock ) / 1000 ) / 60 )); // Server going down in %i minutes! + SysBroadcast( util::format( Dictionary->GetEntry( 1209 ), (( cwmWorldState->GetEndTime() - iGetClock ) / 1000 ) / 60 )); // Server going down in %i minutes! } //o------------------------------------------------------------------------------------------------o @@ -1379,7 +1380,7 @@ auto GenericCheck( CSocket *mSock, CChar& mChar, bool checkFieldEffects, bool do mChar.SetEvadeState( false ); #if defined( UOX_DEBUG_MODE ) && defined( DEBUG_COMBAT ) std::string mCharName = GetNpcDictName( &mChar, nullptr, NRS_SYSTEM ); - Console.Print( oldstrutil::format( "DEBUG: EvadeTimer ended for NPC (%s, 0x%X, at %i, %i, %i, %i).\n", mCharName.c_str(), mChar.GetSerial(), mChar.GetX(), mChar.GetY(), mChar.GetZ(), mChar.WorldNumber() )); + Console.Print( util::format( "DEBUG: EvadeTimer ended for NPC (%s, 0x%X, at %i, %i, %i, %i).\n", mCharName.c_str(), mChar.GetSerial(), mChar.GetX(), mChar.GetY(), mChar.GetZ(), mChar.WorldNumber() )); #endif } @@ -2998,8 +2999,8 @@ auto AdvanceObj( CChar *applyTo, UI16 advObj, bool multiUse ) -> void Effects->PlayStaticAnimation( applyTo, 0x373A, 0, 15); Effects->PlaySound( applyTo, 0x01E9 ); applyTo->SetAdvObj( advObj ); - auto sect = "ADVANCEMENT "s + oldstrutil::number( advObj ); - sect = oldstrutil::trim( oldstrutil::removeTrailing( sect, "//" )); + auto sect = "ADVANCEMENT "s + util::ntos( advObj ); + sect = util::trim( util::strip( sect, "//" )); auto Advancement = FileLookup->FindEntry( sect, advance_def ); if( Advancement == nullptr ) { @@ -3123,7 +3124,7 @@ auto AdvanceObj( CChar *applyTo, UI16 advObj, bool multiUse ) -> void { if( csecs.size() > 1 ) { - retItem = Items->CreateScriptItem( nullptr, applyTo, oldstrutil::trim( oldstrutil::removeTrailing( csecs[0],"//") ), oldstrutil::value( oldstrutil::trim( oldstrutil::removeTrailing( csecs[1], "//" ))), OT_ITEM, true ); + retItem = Items->CreateScriptItem( nullptr, applyTo, util::trim( util::strip( csecs[0],"//") ), util::ston( util::trim( util::strip( csecs[1], "//" ))), OT_ITEM, true ); } else { @@ -3526,7 +3527,7 @@ auto GetPoisonTickTime( UI08 poisonStrength )->TIMERVAL auto GetTileName( CItem& mItem, std::string& itemname ) -> size_t { std::string temp = mItem.GetName(); - temp = oldstrutil::trim( oldstrutil::removeTrailing( temp, "//" )); + temp = util::trim( util::strip( temp, "//" )); const UI16 getAmount = mItem.GetAmount(); CTile& tile = Map->SeekTile( mItem.GetId() ); if( temp.substr( 0, 1 ) == "#" ) @@ -3569,7 +3570,7 @@ auto GetTileName( CItem& mItem, std::string& itemname ) -> size_t temp = first + plural + rest; } } - itemname = oldstrutil::simplify( temp ); + itemname = util::simplify( temp ); return itemname.size() + 1; } @@ -3605,7 +3606,7 @@ auto GetNpcDictName( CChar *mChar, CSocket *tSock, UI08 requestSource ) -> std:: else if( IsNumber( dictName )) { // If name is a number, assume it's a direct dictionary entry reference, and use that - dictEntryId = static_cast( oldstrutil::value( dictName )); + dictEntryId = static_cast( util::ston( dictName )); if( tSock ) { dictName = Dictionary->GetEntry( dictEntryId, tSock->Language() ); @@ -3633,7 +3634,7 @@ auto GetNpcDictTitle( CChar *mChar, CSocket *tSock ) -> std::string if( !dictTitle.empty() && IsNumber( dictTitle )) { // If title is a number, assume it's a direct dictionary entry reference, and use that - dictEntryId = static_cast( oldstrutil::value( dictTitle )); + dictEntryId = static_cast( util::ston( dictTitle )); if( tSock ) { dictTitle = Dictionary->GetEntry( dictEntryId, tSock->Language() ); @@ -3942,7 +3943,7 @@ auto UpdateFlag( CChar *mChar ) -> void { // Default to blue, invalid owner detected mChar->SetFlagBlue(); - Console.Warning( oldstrutil::format( "Tamed Creature has an invalid owner, Serial: 0x%X", mChar->GetSerial() )); + Console.Warning( util::format( "Tamed Creature has an invalid owner, Serial: 0x%X", mChar->GetSerial() )); } } else diff --git a/source/utility/strutil.hpp b/source/utility/strutil.hpp new file mode 100644 index 000000000..5957b5fb6 --- /dev/null +++ b/source/utility/strutil.hpp @@ -0,0 +1,598 @@ +// Copyright © 2022 Charles Kerr. All rights reserved. + +#ifndef strutil_h +#define strutil_h +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +//============================================================================ + +namespace util { + + //======================================================================== + // Trim utilities + //======================================================================= + + //======================================================================= + /// Trim all whitespace from the left of the string + /// - Parameters: + /// - value: The string to be trimmed + /// - whitespace: optional value to specify the whitespace characters + /// - Returns: Returns a new string, that has been trimmed + inline auto ltrim(const std::string &value,const std::string &whitespace = " \t\v\f\n\r") ->std::string { + if (!value.empty() && !whitespace.empty()){ + auto loc = value.find_first_not_of(whitespace) ; + if (loc == std::string::npos){ + return std::string(); + } + return value.substr(loc) ; + } + return value ; + } + + //======================================================================= + /// Trim all whitespace from the right of the string + /// - Parameters: + /// - value: The string to be trimmed + /// - whitespace: optional value to specify the whitespace characters + /// - Returns: Returns a new string, that has been trimmed + inline auto rtrim(const std::string &value,const std::string &whitespace = " \t\v\f\n\r") ->std::string { + if (!value.empty() && !whitespace.empty()){ + auto loc = value.find_last_not_of(whitespace) ; + if (loc == std::string::npos){ + return std::string(); + } + return value.substr(0,loc+1) ; + } + return value ; + } + + //======================================================================= + /// Trim all whitespace from both sides of the string + /// - Parameters: + /// - value: The string to be trimmed + /// - whitespace: optional value to specify the whitespace characters + /// - Returns: Returns a new string , that has been trimmed + inline auto trim(const std::string &value,const std::string &whitespace = " \t\v\f\n\r") ->std::string { + return rtrim(ltrim(value,whitespace),whitespace); + } + + //======================================================================= + /// Simplify the string. + /// Removes all whitespace from both sides of the string, and then replaces + /// whitespace between words with a single space character + /// - Parameters: + /// - value: The string to be simplified + /// - whitespace: optional value to specify the whitespace characters + /// - Returns: Returns a new string, that has been simplified + inline auto simplify(const std::string &value,const std::string &whitespace = " \t\v\f\n\r") ->std::string { + auto rvalue = std::string() ; + auto working = trim(value,whitespace) ; + if (!working.empty()){ + auto ewhitespace = working.find_first_not_of(whitespace); + auto swhitespace = working.find_first_of(whitespace) ; + if (swhitespace != std::string::npos){ + while((swhitespace != std::string::npos) && (swhitespace < working.size())){ + if (!rvalue.empty()){ + rvalue += std::string(" "); + } + rvalue += std::string(working.begin()+ewhitespace,working.begin()+ewhitespace+(swhitespace-ewhitespace)) ; // So it has now been appended + ewhitespace = working.find_first_not_of(whitespace, swhitespace); + swhitespace = working.find_first_of(whitespace, ewhitespace); + if (swhitespace == std::string::npos){ + // No whitespace found, so we take what is ever left + if (ewhitespace != std::string::npos){ + if (!rvalue.empty()){ + rvalue += std::string(" "); + } + rvalue += std::string(working.begin()+ewhitespace,working.end()) ; + } + } + } + } + else { + // There was no whitespace, so just copy the whole thing + rvalue = std::string(working.begin(),working.end()); + } + } + return rvalue ; + } + + //========================================================= + // Case utilities + //========================================================= + + //======================================================================= + /// Upper case the string + /// - Parameters: + /// - value: The string to be uppercased + /// - Returns: Returns a new string , that has been uppercased + inline auto upper(const std::string &value) ->std::string { + auto rvalue = std::string() ; + std::transform(value.begin(), value.end(), std::back_inserter(rvalue), + [](unsigned char c) { return std::toupper(c); } + ); + return rvalue; + + } + //======================================================================= + /// lower case the string + /// - Parameters: + /// - value: The string to be trimmed + /// - Returns: Returns a new string , that has been lower cased + inline auto lower(const std::string &value) ->std::string { + auto rvalue = std::string() ; + std::transform(value.begin(), value.end(), std::back_inserter(rvalue), + [](unsigned char c) { return std::tolower(c); } + ); + return rvalue; + + } + + //========================================================= + // String manipulation + //========================================================= + + //======================================================================= + /// Strip all text after the specified separator + /// - Parameters: + /// - value: The string to be worked on + /// - sep: optional, The separator to search for for removal + /// - whitespace: optional, if present(not empty), the data is trimmed + /// - Returns: Returns a new string , that has all data after the separator removed (inclusive) + inline auto strip(const std::string &value, const std::string &sep = "//", const std::string &whitespace=" \t\v\f\n\r") -> std::string { + auto rvalue = std::string(); + auto temp = value; + if (!sep.empty()){ + auto loc = value.find(sep); + if (loc != std::string::npos) { + temp = value.substr(0, loc); + } + } + temp = rtrim(temp,whitespace); + + return std::string(temp.begin(),temp.end()); + } + + //======================================================================= + /// Split a text string into to values, based on a separator + /// The values are trimmed based on whitespace value + /// - Parameters: + /// - value: The string view to be worked on + /// - sep: The separator to search for to split the string on + /// - whitespace: optional, if present(not empty), the two values are trimmed on return + /// - Returns: Returns a pair of string views containing the two values + inline auto split(const std::string &value, const std::string &sep,const std::string &whitespace=" \t\v\f\n\r") -> std::pair { + auto vfirst = value; + auto vsecond = std::string(); + if (!sep.empty()){ + auto loc = value.find(sep); + if (loc != std::string ::npos) { + vfirst = trim(value.substr(0, loc),whitespace); + loc = loc + sep.size(); + if (loc < value.size()) { + vsecond = trim(value.substr(loc),whitespace); + } + } + } + return std::make_pair(vfirst, vsecond); + } + + //======================================================================= + /// Parse a text string into to values, based on a separator + /// The values are trimmed based on whitespace value + /// - Parameters: + /// - value: The string to be worked on + /// - sep: The separator to search for to split the string on + /// - whitespace: optional, if present(not empty), the two values are trimmed on return + /// - Returns: Returns a vector containing the values + inline auto parse(const std::string value, const std::string &sep,const std::string whitespace=" \t\v\f\n\r") -> std::vector { + auto rvalue = std::vector(); + auto current = std::string::size_type(0); + if (!sep.empty()){ + auto loc = value.find(sep, current); + while (loc != std::string::npos) { + + rvalue.push_back(trim(value.substr(current, loc - current),whitespace)); + current = loc + sep.size(); + if (current >= value.size()){ + rvalue.push_back(std::string()); + } + loc = value.find(sep, current); + } + if (current < value.size()) { + rvalue.push_back(trim(value.substr(current),whitespace)); + } + } + else { + rvalue.push_back(trim(value)); + } + return rvalue; + } + //======================================================================= + /// Acquire the contents of the string between two separators + /// The values are trimmed based on whitespace value + /// - Parameters: + /// - value: The string to be worked on + /// - sepStart: The starting separator + /// - sepEnd: The ending separator + /// - trimReturn: Bool to indicate if result should be trimmed. Defaults to true + /// - Returns: Returns a string\_view of the contents + /// - Throws: runtime error if separators are not found or the end is before the beginning + inline auto contentsOf(const std::string &data,const std::string &sepStart, const std::string &sepEnd,bool trimReturn=true) -> std::string { + auto startloc = data.find_first_of(sepStart); + auto endloc = data.find_last_of(sepEnd); + if ((startloc == std::string::npos) || (endloc == std::string::npos) || (startloc >= endloc)) { + //throw std::runtime_error(std::string("Unable to retrieve contents from: ") + std::string(data)); + // Keeping with our approach of system functions, so no exceptions, we return a blank + return std::string() ; + } + auto actualstart = startloc + sepStart.size(); + auto contents = data.substr(actualstart,endloc-actualstart); + if (trimReturn) { + contents = trim(contents) ; + } + return contents ; + } + + //========================================================== + // String formatting + //========================================================== + + //======================================================================= + /// Format a string based on a string format statement + /// + /// - Parameters: + /// - format: string of the format statment + /// - args: argument list for the values in the format statement + /// - Returns: Returns a string formatted based on the arguments/format statment + /// - Throws: If it can not allocate the memory for conversion, throws a runtime error + template + auto format(const std::string &format_str, Args... args) -> std::string { + auto rvalue = std::string(); + if (!format_str.empty()) { + // First see how much space we need? + auto size_s = std::snprintf(nullptr, 0, format_str.c_str(), args...); + if (size_s < 0) { + throw std::runtime_error("Error applying format string"); + } + if (size_s > 0) { + // Take the space we need and add 1 for the terminating \0 + size_s += 1; + auto size = static_cast(size_s); + // Lets create a buffer we need for the data + auto buf = std::make_unique(size); + size_s = + std::snprintf(buf.get(), size, format_str.c_str(), args...); + if (size_s < 0) { + throw std::runtime_error("Error applying format string"); + } + if (size_s > 0) { + rvalue = std::string(buf.get(), buf.get() + size_s); + } + } + } + return rvalue; + } + //========================================================== + // Number/string conversions + // These are equivalanet to std::stoi type functions, but allow + // one to fix width, pad, etc. + //========================================================== + //========================================================== + // The maximum characters in a string number for conversion sake + // Used by ntos method + inline constexpr auto max_characters_in_number = 50; + + //======================================================================= + /// Convert a number to a string, with options on radix,prefix,size,pad + /// - Parameters: + /// - value: The value one is trying to convert to a string + /// - radix: the radix one wants, 10,16,2,8 + /// - prefix: Should the string have the prefix (0x,0,0b) (optional, defaults to false) + /// - width: The minimum width the result should be (optional, defaults to 0) ; + /// - pad: The pad character to be used (optional, defaults to '0' + /// - Returns: Returns a string formatted based on the arguments/format statment + /// - Throws: If the conversion can not be performed, throws a runtime error. + template + typename std::enable_if_t && !std::is_same_v, std::string> + ntos(T value, int radix = 10, bool prefix = false, int size = 0, char pad = '0') { + // first, thing we need to convert the value to a string + std::array str; + + if (auto [pc, ec] = std::to_chars(str.data(), str.data() + str.size(), + value, static_cast(radix)); + ec == std::errc()) { + // How many characters did this number take + auto numchars = static_cast(std::distance(str.data(), pc)); + // what is larger, that is the size of our string + auto sizeofstring = std::max(numchars, size); + // where do we start adding the number into our string ? + auto index = sizeofstring - numchars; + if (prefix) { + // We have a prefix, so we add two characters to the beginning + sizeofstring += 2; + index += 2; + } + auto rvalue = std::string(sizeofstring, pad); + // copy the value into the string + std::copy(str.data(), pc, rvalue.begin() + index); + // do we need our prefix? + if (prefix) { + switch (static_cast(radix)) { + case 10: + // We dont add anything for decimal! + break; + case 16: + rvalue[0] = '0'; + rvalue[1] = 'x'; + break; + case 8: + rvalue[0] = '0'; + rvalue[1] = 'o'; + break; + case 2: + rvalue[0] = '0'; + rvalue[1] = 'b'; + break; + + default: + break; + } + } + return rvalue; + } + else { + // The conversion was not successful, so we return an empty string + throw std::runtime_error("Unable to convert the value: "); + //return std::string(); + } + + } + //======================================================================= + /// Convert a bool to a string, + /// - Parameters: + /// - value: The value one is trying to convert to a string + /// - Returns: Returns a string (true/false); + template + typename std::enable_if_t && std::is_same_v, std::string> + ntos(T value) { + // first, thing we need to convert the value to a string + if (value){ + + return "true"; + } + return "false" ; + } + //======================================================================= + /// Convert a string to a number, with options on radix + /// - Parameters: + /// - value: The value one is trying to convert to a string + /// - radix: the radix of the value (if no prefix) ; + /// - Returns: the requested number + /// - Throws: If unable to convert it, or has a format error, throws a runtime error. + template + typename std::enable_if_t && !std::is_same_v, T> + ston(const std::string &str_value, int radix = 10) { + auto value = T{0}; + //auto svalue = std::string(str_value); + if (!str_value.empty()) { + if (str_value.size() < 2) { + //std::from_chars(str_value.data(),str_value.data() + str_value.size(), value,radix); + std::from_chars(str_value.data(), str_value.data()+ str_value.size(), value, radix); + } + else if (std::isalpha(static_cast(static_cast(str_value[1])))) { + // This has a "radix indicator" + switch (str_value[1]) { + case 'b': + case 'B': + //std::from_chars(str_value.data() + 2,str_value.data() + str_value.size(), value,2); + std::from_chars(str_value.data() + 2, str_value.data() + str_value.size(), value,2); + break; + case 'x': + case 'X': + //std::from_chars(str_value.data() + 2,str_value.data() + str_value.size(), value,16); + std::from_chars(str_value.data() + 2, str_value.data() + str_value.size(), value,16); + break; + case 'o': + case 'O': + //std::from_chars(str_value.data() + 2,str_value.data() + str_value.size(), value,8); + std::from_chars(str_value.data() + 2, str_value.data() + str_value.size(), value,8); + break; + default: + // we dont do anything, we dont undertand so let value be 0 + break; + } + + } + else { + //auto [ptr,ec] = std::from_chars(str_value.data(),str_value.data() + str_value.size(), value,radix); + auto [ptr,ec] = std::from_chars(str_value.data(), str_value.data()+ str_value.size(), value, radix); + if (ec == std::errc::invalid_argument) { + throw std::runtime_error("Invalid argument for number conversion from string."); + } + else if (ec == std::errc::result_out_of_range) { + throw std::runtime_error("Out of range for number conversion from string."); + } + return value; + } + } + return value; + } + //======================================================================= + /// Convert a string(true/false) to a bool + /// - Parameters: + /// - value: The value one is trying to convert to a string + /// - true_value: what text would indicate true (optional, defaults to "true" ; + /// - Returns: a boolean of true if the text equals the true value (or if it converts as a number to not 0) + template + typename std::enable_if_t && std::is_same_v, T> + ston(const std::string &str_value, const std::string &true_value = "true") { + // If string empty, we return false + // we take advantege, that if in ston() we set value to 0 false, and if + // the from_chars fails, it doesn't touch value + auto numvalue = ston(str_value); + if ((str_value == true_value) || (numvalue != 0)) { + return true; + } + return false; + } + //======================================================================= + /// Convert a string to a real + /// - Parameters: + /// - value: The value one is trying to convert to a string + /// - Returns: a boolean of true if the text equals the true value (or if it converts as a number to not 0) + /// - Throws: If unable to convert it, or has a format error, throws a runtime error. + template + typename std::enable_if_t, T> + ston(const std::string &str_value) { + // If string empty, we return false + auto value = T{ 0.0 }; + if (str_value.empty()) { + return value; + } + auto [ptr, ec] = std::from_chars(str_value.data(), str_value.data() + str_value.size(), value); + if (ec == std::errc::invalid_argument) { + throw std::runtime_error("Invalid argument for number conversion from string."); + } + else if (ec == std::errc::result_out_of_range) { + throw std::runtime_error("Out of range for number conversion from string."); + } + } + + //======================================================================= + /// Dump a byte buffer in the standard value : alpha format + /// - Parameters: + /// - output: the output (ostream) + /// - buffer: a pointer to the data buffer of bytes + /// - length: the length of the buffer (bytes) + /// - radix: (16,10,8,2) the radix of the output + /// - entries per line: the number of byes printed per line (defaults to 8) + /// - Returns: Nothing + inline auto dump(std::ostream &output, const std::uint8_t *buffer, + std::size_t length, int radix = 16, + int entries_line = 8) -> void { + // number of characters for entry + auto entry_size = 3; // decimal and octal + switch (static_cast(radix)) { + case 16: + entry_size = 2; + break; + case 2: + entry_size = 8; + break; + default: + break; + } + auto num_rows = + (length / entries_line) + (((length % entries_line) == 0) ? 0 : 1); + // what is the largest number for the address ? + auto max_address_chars = + static_cast((ntos(num_rows * entries_line)).size()); + + // first write out the header + output << std::setw(max_address_chars + 2) << "" << std::setw(1); + for (auto i = 0; i < entries_line; ++i) { + output << ntos(i, 10, false, entry_size, ' ') << " "; + } + output << "\n"; + + // now we write out the values for each line + std::string text(entries_line, ' '); + + for (std::size_t i = 0; i < length; ++i) { + auto row = i / entries_line; + if (((i % static_cast(entries_line) == 0) && + (i >= static_cast(entries_line))) || + (i == 0)) { + // This is a new line! + output << ntos(row * entries_line, 10, false, + max_address_chars, ' ') + << ": "; + text = std::string(entries_line, ' '); + } + output << ntos(*(buffer+i), radix, false, entry_size) << " "; + // If it is an alpha, we want to write it + if (std::isalpha(static_cast(*(buffer + i))) != 0) { + // we want to write this to the string + text[(i % entries_line)] = static_cast(*reinterpret_cast((buffer + i))); + } else { + text[(i % entries_line)] = '.'; + } + if (i % entries_line == entries_line - 1) { + output << " " << text << "\n"; + } + } + // what if we had a partial last line, we need to figure that out + auto last_line_entry = length % entries_line; + if (last_line_entry != 0) { + // we need to put the number of leading spaces + output << std::setw(static_cast((entries_line - last_line_entry) * + (entry_size + 1))) + << "" << std::setw(1) << " " << text << "\n"; + } + } + + + //========================================================= + // Time/String conversions + //========================================================= + + //======================================================================= + /// Converts a system clock time point to a string value + /// - Parameters: + /// - t: the time point + /// - format: the format string (defaults to Thu Dec 30 14:13:28 2021) + /// - Returns: string value of the time point + inline auto sysTimeToString(const std::chrono::system_clock::time_point &t,const std::string &format = "%a %b %d %H:%M:%S %Y") -> std::string { + std::stringstream output ; + auto time = std::chrono::system_clock::to_time_t(t); + tm myvalue ; +#if defined(_MSC_VER) + auto status = ::localtime_s(&myvalue,&time) ; +#else + ::localtime_r(&time,&myvalue) ; +#endif + output << std::put_time(&myvalue, format.c_str()); + + return output.str() ; + } + + //======================================================================= + /// Converts a string value of time to a system time point + /// - Parameters: + /// - str: the string value for the time point + /// - format: the string value representing the format (Thu Dec 30 14:13:28 2021) + /// - Returns: a system time point + inline auto stringToSysTime(const std::string &str, const std::string &format = "%a %b %d %H:%M:%S %Y") -> std::chrono::system_clock::time_point { + std::stringstream timbuf(str); + tm converted; + timbuf >> std::get_time(&converted, format.c_str()); + converted.tm_isdst = -1; + auto ntime = mktime(&converted); + return std::chrono::system_clock::from_time_t(ntime); + } + + //======================================================================= + /// Returns time now in a string + /// - Parameters: + /// - format: the format string (defaults to Thu Dec 30 14:13:28 2021) + /// - Returns: string value of the time point + inline auto timeNow(const std::string &format = "%a %b %d %H:%M:%S %Y") -> std::string{ + return sysTimeToString(std::chrono::system_clock::now(),format) ; + } +} +#endif /* Header guard */ diff --git a/source/wholist.cpp b/source/wholist.cpp index f05d30cf5..1f88ab580 100644 --- a/source/wholist.cpp +++ b/source/wholist.cpp @@ -341,32 +341,32 @@ void CWhoList::Command( CSocket *toSendTo, UI08 type, UI16 buttonPressed ) UI16 butRight = cwmWorldState->ServerData()->ButtonRight(); //--static pages toSend.addCommand( "page 0" ); - toSend.addCommand( oldstrutil::format( "resizepic 0 0 %u 260 340", cwmWorldState->ServerData()->BackgroundPic() )); - toSend.addCommand( oldstrutil::format( "button 30 300 %u %i 1 0 1", cwmWorldState->ServerData()->ButtonCancel(), cwmWorldState->ServerData()->ButtonCancel() + 1 )); // OKAY - toSend.addCommand( oldstrutil::format( "text 30 40 %u 0", tColour )); // text <# in order> - toSend.addCommand( oldstrutil::format( "text 30 60 %u 1", tColour) ); + toSend.addCommand( util::format( "resizepic 0 0 %u 260 340", cwmWorldState->ServerData()->BackgroundPic() )); + toSend.addCommand( util::format( "button 30 300 %u %i 1 0 1", cwmWorldState->ServerData()->ButtonCancel(), cwmWorldState->ServerData()->ButtonCancel() + 1 )); // OKAY + toSend.addCommand( util::format( "text 30 40 %u 0", tColour )); // text <# in order> + toSend.addCommand( util::format( "text 30 60 %u 1", tColour) ); toSend.addCommand( "page 1" ); - toSend.addCommand( oldstrutil::format( "text 50 90 %u 2", lColour) ); // goto text - toSend.addCommand( oldstrutil::format( "text 50 110 %u 3", lColour) ); // gettext - toSend.addCommand( oldstrutil::format( "text 50 130 %u 4", lColour )); // Jail text - toSend.addCommand( oldstrutil::format( "text 50 150 %u 5", lColour )); // Release text - toSend.addCommand( oldstrutil::format( "text 50 170 %u 6", lColour )); // Kick user text - toSend.addCommand( oldstrutil::format( "text 50 190 %u 7", lColour )); - toSend.addCommand( oldstrutil::format( "text 50 210 %u 8", lColour )); - toSend.addCommand( oldstrutil::format( "text 50 230 %u 9", lColour) ); - toSend.addCommand( oldstrutil::format( "text 50 270 %u 10", lColour )); - toSend.addCommand( oldstrutil::format( "button 20 90 %u %i 1 0 200", butRight, butRight + 1 )); // goto button - toSend.addCommand( oldstrutil::format( "button 20 110 %u %i 1 0 201", butRight, butRight + 1 )); // get button - toSend.addCommand( oldstrutil::format( "button 20 130 %u %i 1 0 202", butRight, butRight + 1 )); // Jail button - toSend.addCommand( oldstrutil::format( "button 20 150 %u %i 1 0 203", butRight, butRight + 1 )); // Release button - toSend.addCommand( oldstrutil::format( "button 20 170 %u %i 1 0 204", butRight, butRight + 1 )); // kick button - toSend.addCommand( oldstrutil::format( "button 20 190 %u %i 1 0 205", butRight, butRight + 1 )); // Where button - toSend.addCommand( oldstrutil::format( "button 20 210 %u %i 1 0 206", butRight, butRight + 1 )); // Cstats button - toSend.addCommand( oldstrutil::format( "button 20 230 %u %i 1 0 207", butRight, butRight + 1 )); // Tweak button - - toSend.addText(oldstrutil::format( "User %u selected (account %u)", buttonPressed, targetChar->GetAccount().wAccountIndex)); - toSend.addText( oldstrutil::format( "Name: %s", targetChar->GetName().c_str() )); + toSend.addCommand( util::format( "text 50 90 %u 2", lColour) ); // goto text + toSend.addCommand( util::format( "text 50 110 %u 3", lColour) ); // gettext + toSend.addCommand( util::format( "text 50 130 %u 4", lColour )); // Jail text + toSend.addCommand( util::format( "text 50 150 %u 5", lColour )); // Release text + toSend.addCommand( util::format( "text 50 170 %u 6", lColour )); // Kick user text + toSend.addCommand( util::format( "text 50 190 %u 7", lColour )); + toSend.addCommand( util::format( "text 50 210 %u 8", lColour )); + toSend.addCommand( util::format( "text 50 230 %u 9", lColour) ); + toSend.addCommand( util::format( "text 50 270 %u 10", lColour )); + toSend.addCommand( util::format( "button 20 90 %u %i 1 0 200", butRight, butRight + 1 )); // goto button + toSend.addCommand( util::format( "button 20 110 %u %i 1 0 201", butRight, butRight + 1 )); // get button + toSend.addCommand( util::format( "button 20 130 %u %i 1 0 202", butRight, butRight + 1 )); // Jail button + toSend.addCommand( util::format( "button 20 150 %u %i 1 0 203", butRight, butRight + 1 )); // Release button + toSend.addCommand( util::format( "button 20 170 %u %i 1 0 204", butRight, butRight + 1 )); // kick button + toSend.addCommand( util::format( "button 20 190 %u %i 1 0 205", butRight, butRight + 1 )); // Where button + toSend.addCommand( util::format( "button 20 210 %u %i 1 0 206", butRight, butRight + 1 )); // Cstats button + toSend.addCommand( util::format( "button 20 230 %u %i 1 0 207", butRight, butRight + 1 )); // Tweak button + + toSend.addText(util::format( "User %u selected (account %u)", buttonPressed, targetChar->GetAccount().wAccountIndex)); + toSend.addText( util::format( "Name: %s", targetChar->GetName().c_str() )); toSend.addText( Dictionary->GetEntry( 1400, sLang )); toSend.addText( Dictionary->GetEntry( 1401, sLang )); toSend.addText( Dictionary->GetEntry( 1402, sLang )); @@ -375,7 +375,7 @@ void CWhoList::Command( CSocket *toSendTo, UI08 type, UI16 buttonPressed ) toSend.addText( Dictionary->GetEntry( 1405, sLang )); toSend.addText( Dictionary->GetEntry( 1406, sLang )); toSend.addText( Dictionary->GetEntry( 1407, sLang )); - toSend.addText( oldstrutil::format( "Serial#[%x %x %x %x]", targetChar->GetSerial( 1 ), targetChar->GetSerial( 2 ), targetChar->GetSerial( 3 ), targetChar->GetSerial( 4 ))); + toSend.addText( util::format( "Serial#[%x %x %x %x]", targetChar->GetSerial( 1 ), targetChar->GetSerial( 2 ), targetChar->GetSerial( 3 ), targetChar->GetSerial( 4 ))); toSend.Finalize(); toSendTo->Send( &toSend ); diff --git a/source/worldmain.cpp b/source/worldmain.cpp index b35fbeec1..2472fcf8f 100644 --- a/source/worldmain.cpp +++ b/source/worldmain.cpp @@ -591,7 +591,7 @@ void CWorldMain::RegionSave() std::ofstream regionsDestination( regionsFile.c_str() ); if( !regionsDestination ) { - Console.Error( oldstrutil::format( "Failed to open %s for writing", regionsFile.c_str() )); + Console.Error( util::format( "Failed to open %s for writing", regionsFile.c_str() )); return; } std::for_each( cwmWorldState->townRegions.begin(), cwmWorldState->townRegions.end(), [®ionsDestination]( const std::pair &town ) @@ -629,7 +629,7 @@ void CWorldMain::SaveStatistics( void ) std::ofstream statsDestination( statsFile.c_str() ); if( !statsDestination ) { - Console.Error( oldstrutil::format( "Failed to open %s for writing", statsFile.c_str() )); + Console.Error( util::format( "Failed to open %s for writing", statsFile.c_str() )); return; } statsDestination << "[STATISTICS]" << '\n' << "{" << '\n'; From 683fdaa91f43f40f669a16231e8c12907d31030f Mon Sep 17 00:00:00 2001 From: "cmkerr59@icloud.com" <128108973+OldFoolAgain@users.noreply.github.com> Date: Wed, 30 Aug 2023 11:06:52 -0400 Subject: [PATCH 2/3] Update mapstuff.cpp --- source/mapstuff.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/mapstuff.cpp b/source/mapstuff.cpp index 8d3604bdc..ebde2703b 100644 --- a/source/mapstuff.cpp +++ b/source/mapstuff.cpp @@ -2073,7 +2073,7 @@ auto UltimaMap::ProcessEntry( [[maybe_unused]] std::size_t entry, std::size_t in auto ptr = data.data() + ( i * 196 ); if( block < _terrain.size() ) { - LoadTerrainBlock( block, ptr ); + LoadTerrainBlock( static_cast(block), ptr ); } ++block; } From 3b4a7c14142bad570453c51cfe061bd4248867d5 Mon Sep 17 00:00:00 2001 From: "cmkerr59@icloud.com" <128108973+OldFoolAgain@users.noreply.github.com> Date: Wed, 30 Aug 2023 11:08:37 -0400 Subject: [PATCH 3/3] Update uox3.vcxproj.filters --- make/VS2022/uox3.vcxproj.filters | 61 +++++++++++--------------------- 1 file changed, 20 insertions(+), 41 deletions(-) diff --git a/make/VS2022/uox3.vcxproj.filters b/make/VS2022/uox3.vcxproj.filters index e30f8963b..38eba63d2 100644 --- a/make/VS2022/uox3.vcxproj.filters +++ b/make/VS2022/uox3.vcxproj.filters @@ -66,7 +66,7 @@ Source Files - + Source Files\Script @@ -82,8 +82,7 @@ Source Files\Script - - + Source Files\Base Objects @@ -117,8 +116,7 @@ Source Files\Base Objects - - + Source Files\Subsystem @@ -209,8 +207,7 @@ Source Files\Subsystem - - + Source Files\Other @@ -256,8 +253,7 @@ Source Files\Other - - + Source Files\JS Engine @@ -279,8 +275,7 @@ Source Files\JS Engine - - + Source Files\Network @@ -293,8 +288,7 @@ Source Files\Network - - + Source Files\Utility @@ -304,8 +298,7 @@ Source Files\Utility - - + Source Files\UOData @@ -315,14 +308,12 @@ Source Files\UOData - Header Files - - + Header Files\Script @@ -338,8 +329,7 @@ Header Files\Script - - + Header Files\Base Objects @@ -379,8 +369,7 @@ Header Files\Base Objects - - + Header Files\Subsystem @@ -411,9 +400,6 @@ Header Files\Subsystem - - Header Files\Subsystem - Header Files\Subsystem @@ -453,8 +439,7 @@ Header Files\Subsystem - - + Header Files\Other @@ -497,8 +482,7 @@ Header Files\Other - - + Header Files\JS Engine @@ -526,11 +510,10 @@ Header Files\JS Engine - + Header Files\JS Engine - - + Header Files\Network @@ -543,23 +526,20 @@ Header Files\Network - - - + Header Files\Utility Header Files\Utility - + Header Files\Utility - + Header Files\Utility - - + Header Files\UOData @@ -572,7 +552,6 @@ Header Files\UOData - @@ -584,4 +563,4 @@ Resource Files - + \ No newline at end of file