From d1efbe63072f8ac4dc4331144dc3c2401524c127 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 26 Sep 2018 08:47:22 -0400 Subject: [PATCH] Various small cleanups --- src/common/Common.h | 46 ++++++------------- src/common/Logging/Logger.h | 6 +-- src/common/Network/Acceptor.h | 1 - src/common/Network/CommonNetwork.h | 16 +++---- src/common/Util/Util.cpp | 1 + src/common/Util/Util.h | 2 +- src/common/Util/UtilMath.h | 8 +--- src/servers/sapphire_api/main.cpp | 2 +- src/servers/sapphire_lobby/GameConnection.cpp | 22 ++++----- src/servers/sapphire_zone/Actor/PlayerSql.cpp | 2 +- .../sapphire_zone/Script/ScriptMgr.cpp | 14 +++--- src/servers/sapphire_zone/ServerZone.cpp | 6 +-- src/servers/sapphire_zone/ServerZone.h | 2 - 13 files changed, 51 insertions(+), 77 deletions(-) diff --git a/src/common/Common.h b/src/common/Common.h index 96d33e30..0847aac9 100644 --- a/src/common/Common.h +++ b/src/common/Common.h @@ -4,7 +4,6 @@ #include #include -#include #include "CommonGen.h" // +--------------------------------------------------------------------------- @@ -27,8 +26,7 @@ struct FFXIVARR_POSITION3 float z; }; -enum InventoryOperation : - uint8_t +enum InventoryOperation : uint8_t { Discard = 0x07, Move = 0x08, @@ -37,8 +35,7 @@ enum InventoryOperation : Split = 0x0A }; -enum ClientLanguage : - uint8_t +enum ClientLanguage : uint8_t { Japanese = 1, English = 2, @@ -46,8 +43,7 @@ enum ClientLanguage : French = 8 }; -enum ObjKind : - uint8_t +enum ObjKind : uint8_t { None = 0x00, Player = 0x01, @@ -66,15 +62,13 @@ enum ObjKind : CardStand = 0x0E, }; -enum Stance : - uint8_t +enum Stance : uint8_t { Passive = 0, Active = 1, }; -enum class DisplayFlags : - uint16_t +enum class DisplayFlags : uint16_t { ActiveStance = 0x001, Invisible = 0x020, @@ -84,8 +78,7 @@ enum class DisplayFlags : Visor = 0x800, }; -enum struct ActorStatus : - uint8_t +enum struct ActorStatus : uint8_t { Idle = 0x01, Dead = 0x02, @@ -99,8 +92,7 @@ enum struct ActorStatus : EmoteMode = 0x0B }; -enum GearSetSlot : - uint8_t +enum GearSetSlot : uint8_t { MainHand = 0, OffHand = 1, @@ -173,8 +165,7 @@ enum EquipSlotCategory : uint8_t BodyDisallowLegsFeet = 21, }; -enum InventoryType : - uint16_t +enum InventoryType : uint16_t { Bag0 = 0, Bag1 = 1, @@ -226,8 +217,7 @@ enum InventoryType : FreeCompanyCrystal = 22001 }; -enum ContainerType : - uint16_t +enum ContainerType : uint16_t { Unknown = 0, Bag = 1, @@ -237,8 +227,7 @@ enum ContainerType : }; -enum CurrencyType : - uint8_t +enum CurrencyType : uint8_t { Gil = 0x01, StormSeal = 0x02, @@ -256,8 +245,7 @@ enum CurrencyType : TomestoneLore = 0x0E }; -enum CrystalType : - uint8_t +enum CrystalType : uint8_t { FireShard = 0x01, IceShard = 0x02, @@ -281,8 +269,7 @@ enum CrystalType : WaterCluster = 0x12 }; -enum struct ZoneingType : - uint8_t +enum struct ZoneingType : uint8_t { None = 1, Teleport = 2, @@ -291,24 +278,21 @@ enum struct ZoneingType : FadeIn = 5, }; -enum struct ResurrectType : - uint8_t +enum struct ResurrectType : uint8_t { None = 0, RaiseSpell = 5, Return = 8 }; -enum Gender : - uint8_t +enum Gender : uint8_t { Male = 0, Female = 1, }; -enum struct GCRank : - uint8_t +enum struct GCRank : uint8_t { None = 0, PrivateThirdClass = 1, diff --git a/src/common/Logging/Logger.h b/src/common/Logging/Logger.h index f85ad5e9..28384f16 100644 --- a/src/common/Logging/Logger.h +++ b/src/common/Logging/Logger.h @@ -5,9 +5,7 @@ namespace Core { - -enum struct LoggingSeverity : - uint8_t +enum struct LoggingSeverity : uint8_t { trace = 0, debug = 1, @@ -50,4 +48,4 @@ public: } -#endif \ No newline at end of file +#endif diff --git a/src/common/Network/Acceptor.h b/src/common/Network/Acceptor.h index b70b10e6..99586d45 100644 --- a/src/common/Network/Acceptor.h +++ b/src/common/Network/Acceptor.h @@ -2,7 +2,6 @@ #define ACCEPTOR_H_ #include -#include #include #include #include "Forwards.h" diff --git a/src/common/Network/CommonNetwork.h b/src/common/Network/CommonNetwork.h index 1ce7c50b..f8be9aeb 100644 --- a/src/common/Network/CommonNetwork.h +++ b/src/common/Network/CommonNetwork.h @@ -5,8 +5,6 @@ #include #include "PacketDef/Ipcs.h" -using namespace std; - namespace Core { namespace Network { namespace Packets { @@ -70,12 +68,12 @@ struct FFXIVARR_PACKET_HEADER uint32_t unknown_24; }; -inline ostream& operator<<( ostream& os, const FFXIVARR_PACKET_HEADER& hdr ) +inline std::ostream& operator<<( std::ostream& os, const FFXIVARR_PACKET_HEADER& hdr ) { return os.write( reinterpret_cast< const char* >( &hdr ), sizeof hdr ); } -inline istream& operator>>( istream& is, FFXIVARR_PACKET_HEADER& hdr ) +inline std::istream& operator>>( std::istream& is, FFXIVARR_PACKET_HEADER& hdr ) { return is.read( reinterpret_cast< char* >( &hdr ), sizeof hdr ); } @@ -108,12 +106,12 @@ struct FFXIVARR_PACKET_SEGMENT_HEADER uint16_t padding; }; -inline ostream& operator<<( ostream& os, const FFXIVARR_PACKET_SEGMENT_HEADER& hdr ) +inline std::ostream& operator<<( std::ostream& os, const FFXIVARR_PACKET_SEGMENT_HEADER& hdr ) { return os.write( reinterpret_cast< const char* >( &hdr ), sizeof hdr ); } -inline istream& operator>>( istream& is, FFXIVARR_PACKET_SEGMENT_HEADER& hdr ) +inline std::istream& operator>>( std::istream& is, FFXIVARR_PACKET_SEGMENT_HEADER& hdr ) { return is.read( reinterpret_cast< char* >( &hdr ), sizeof hdr ); } @@ -145,7 +143,7 @@ enum FFXIVARR_SEGMENT_TYPE SEGMENTTYPE_IPC = 3, SEGMENTTYPE_KEEPALIVE = 7, //SEGMENTTYPE_RESPONSE = 8, - SEGMENTTYPE_ENCRYPTIONINIT = 9, + SEGMENTTYPE_ENCRYPTIONINIT = 9, }; /** @@ -171,12 +169,12 @@ struct FFXIVARR_IPC_HEADER uint32_t padding1; }; -inline ostream& operator<<( ostream& os, const FFXIVARR_IPC_HEADER& hdr ) +inline std::ostream& operator<<( std::ostream& os, const FFXIVARR_IPC_HEADER& hdr ) { return os.write( reinterpret_cast< const char* >( &hdr ), sizeof hdr ); } -inline istream& operator>>( istream& is, FFXIVARR_IPC_HEADER& hdr ) +inline std::istream& operator>>( std::istream& is, FFXIVARR_IPC_HEADER& hdr ) { return is.read( reinterpret_cast< char* >( &hdr ), sizeof hdr ); } diff --git a/src/common/Util/Util.cpp b/src/common/Util/Util.cpp index 56e277ba..89f0a5f8 100644 --- a/src/common/Util/Util.cpp +++ b/src/common/Util/Util.cpp @@ -1,6 +1,7 @@ #include "Util.h" #include #include +#include std::string Core::Util::binaryToHexString( uint8_t* pBinData, uint16_t size ) { diff --git a/src/common/Util/Util.h b/src/common/Util/Util.h index b03dd987..a0fbb52d 100644 --- a/src/common/Util/Util.h +++ b/src/common/Util/Util.h @@ -2,7 +2,7 @@ #define _UTIL_H #include -#include +#include namespace Core { namespace Util { diff --git a/src/common/Util/UtilMath.h b/src/common/Util/UtilMath.h index 5826b08f..fb089867 100644 --- a/src/common/Util/UtilMath.h +++ b/src/common/Util/UtilMath.h @@ -27,22 +27,18 @@ uint16_t floatToUInt16Rot( float val ); uint8_t floatToUInt8Rot( float val ); -template - < typename T > +template < typename T > T clamp( T val, T minimum, T maximum ) { if( val > maximum ) - { return maximum; - } if( val < minimum ) - { return minimum; - } return val; } + } } } diff --git a/src/servers/sapphire_api/main.cpp b/src/servers/sapphire_api/main.cpp index 59063132..609a2d84 100644 --- a/src/servers/sapphire_api/main.cpp +++ b/src/servers/sapphire_api/main.cpp @@ -6,7 +6,7 @@ #include #include #include - +#include #include #include diff --git a/src/servers/sapphire_lobby/GameConnection.cpp b/src/servers/sapphire_lobby/GameConnection.cpp index 688d0b04..000fc5c7 100644 --- a/src/servers/sapphire_lobby/GameConnection.cpp +++ b/src/servers/sapphire_lobby/GameConnection.cpp @@ -160,13 +160,13 @@ void Core::Network::GameConnection::getCharList( FFXIVARR_PACKET_RAW& packet, ui memset( &details, 0, sizeof( FFXIVIpcCharList::CharaDetails ) ); auto& charEntry = charList[ charIndex ]; - details.uniqueId = get< 1 >( charEntry ); - details.contentId = get< 2 >( charEntry ); + details.uniqueId = std::get< 1 >( charEntry ); + details.contentId = std::get< 2 >( charEntry ); details.serverId = g_serverLobby.getConfig()->getValue< uint16_t >( "Lobby.WorldID", 1 ); details.serverId1 = g_serverLobby.getConfig()->getValue< uint16_t >( "Lobby.WorldID", 1 ); details.index = charIndex; - strcpy( details.charDetailJson, get< 3 >( charEntry ).c_str() ); - strcpy( details.nameChara, get< 0 >( charEntry ).c_str() ); + strcpy( details.charDetailJson, std::get< 3 >( charEntry ).c_str() ); + strcpy( details.nameChara, std::get< 0 >( charEntry ).c_str() ); strcpy( details.nameServer, g_serverLobby.getConfig()->getValue< std::string >( "Lobby.WorldName", "Sapphire" ).c_str() ); strcpy( details.nameServer1, @@ -175,10 +175,10 @@ void Core::Network::GameConnection::getCharList( FFXIVARR_PACKET_RAW& packet, ui charListPacket->data().charaDetails[ j ] = details; g_log.debug( "[" + std::to_string( charIndex ) + "] " + std::to_string( details.index ) + " - " - + get< 0 >( charEntry ) + " - " + - std::to_string( get< 1 >( charEntry ) ) + " - " + - std::to_string( get< 2 >( charEntry ) ) + " - " + - get< 3 >( charEntry ) ); + + std::get< 0 >( charEntry ) + " - " + + std::to_string( std::get< 1 >( charEntry ) ) + " - " + + std::to_string( std::get< 2 >( charEntry ) ) + " - " + + std::get< 3 >( charEntry ) ); } charIndex++; } @@ -215,12 +215,12 @@ void Core::Network::GameConnection::enterWorld( FFXIVARR_PACKET_RAW& packet, uin auto charList = g_restConnector.getCharList( ( char* ) m_pSession->getSessionId() ); for( uint32_t i = 0; i < charList.size(); i++ ) { - uint64_t thisContentId = get< 2 >( charList[ i ] ); + uint64_t thisContentId = std::get< 2 >( charList[ i ] ); if( thisContentId == lookupId ) { - logInCharId = get< 1 >( charList[ i ] ); - logInCharName = get< 0 >( charList[ i ] ); + logInCharId = std::get< 1 >( charList[ i ] ); + logInCharName = std::get< 0 >( charList[ i ] ); break; } } diff --git a/src/servers/sapphire_zone/Actor/PlayerSql.cpp b/src/servers/sapphire_zone/Actor/PlayerSql.cpp index 5c06b8c4..5b6abae1 100644 --- a/src/servers/sapphire_zone/Actor/PlayerSql.cpp +++ b/src/servers/sapphire_zone/Actor/PlayerSql.cpp @@ -502,7 +502,7 @@ void Core::Entity::Player::updateDbSearchInfo() const pDb->execute( stmtS1 ); auto stmtS2 = pDb->getPreparedStatement( Db::CHARA_SEARCHINFO_UP_SEARCHCOMMENT ); - stmtS2->setString( 1, string( m_searchMessage ) ); + stmtS2->setString( 1, std::string( m_searchMessage ) ); stmtS2->setInt( 2, m_id ); pDb->execute( stmtS2 ); } diff --git a/src/servers/sapphire_zone/Script/ScriptMgr.cpp b/src/servers/sapphire_zone/Script/ScriptMgr.cpp index 4663ae50..7bc9b216 100644 --- a/src/servers/sapphire_zone/Script/ScriptMgr.cpp +++ b/src/servers/sapphire_zone/Script/ScriptMgr.cpp @@ -141,13 +141,13 @@ bool Core::Scripting::ScriptMgr::loadDir( const std::string& dirname, std::set< boost::filesystem::directory_iterator iter( targetDir ); boost::filesystem::directory_iterator eod; - BOOST_FOREACH( boost::filesystem::path const& i, make_pair( iter, eod ) ) - { - if( is_regular_file( i ) && boost::filesystem::extension( i.string() ) == ext ) - { - files.insert( i.string() ); - } - } + BOOST_FOREACH( boost::filesystem::path const& i, std::make_pair( iter, eod ) ) + { + if( is_regular_file( i ) && boost::filesystem::extension( i.string() ) == ext ) + { + files.insert( i.string() ); + } + } if( files.size() ) return true; diff --git a/src/servers/sapphire_zone/ServerZone.cpp b/src/servers/sapphire_zone/ServerZone.cpp index 6217e4f0..f6bd3ec6 100644 --- a/src/servers/sapphire_zone/ServerZone.cpp +++ b/src/servers/sapphire_zone/ServerZone.cpp @@ -216,7 +216,7 @@ void Core::ServerZone::mainLoop() while( isRunning() ) { - this_thread::sleep_for( chrono::milliseconds( 50 ) ); + std::this_thread::sleep_for( std::chrono::milliseconds( 50 ) ); auto currTime = Util::getTimeSeconds(); @@ -224,7 +224,7 @@ void Core::ServerZone::mainLoop() pScriptMgr->update(); - lock_guard< std::mutex > lock( m_sessionMutex ); + std::lock_guard< std::mutex > lock( m_sessionMutex ); for( auto sessionIt : m_sessionMapById ) { auto session = sessionIt.second; @@ -423,4 +423,4 @@ Core::Entity::BNpcTemplatePtr Core::ServerZone::getBNpcTemplate( uint32_t id ) } return nullptr; -} \ No newline at end of file +} diff --git a/src/servers/sapphire_zone/ServerZone.h b/src/servers/sapphire_zone/ServerZone.h index 73a6c867..d92c1a9e 100644 --- a/src/servers/sapphire_zone/ServerZone.h +++ b/src/servers/sapphire_zone/ServerZone.h @@ -9,8 +9,6 @@ #include "ForwardsZone.h" -#include "Actor/BNpcTemplate.h" - namespace Core { class ServerZone