From 70c581e60cbe8b942671b6f125410f8b0a9f3041 Mon Sep 17 00:00:00 2001 From: amibu Date: Mon, 25 Sep 2017 18:05:33 +0200 Subject: [PATCH 01/11] Moved byte bool code into exd parser --- src/servers/Server_Common/Exd/ExdData.cpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/servers/Server_Common/Exd/ExdData.cpp b/src/servers/Server_Common/Exd/ExdData.cpp index 0c5fd98f..edb12add 100644 --- a/src/servers/Server_Common/Exd/ExdData.cpp +++ b/src/servers/Server_Common/Exd/ExdData.cpp @@ -344,21 +344,13 @@ bool Core::Data::ExdData::loadActionInfo() uint8_t points_type = getField< uint8_t >( fields, 30 ); // 30 uint16_t points_cost = getField< uint16_t >( fields, 31 ); // 31 - uint32_t instantval = getField< bool >( fields, 35 ); // 35 + bool is_instant = getField< bool >( fields, 35 ); // 35 uint16_t cast_time = getField< uint16_t >( fields, 36 ); // 36 uint16_t recast_time = getField< uint16_t >( fields, 37 ); // 37 int8_t model = getField< int8_t >( fields, 39 ); // 39: Action model uint8_t aspect = getField< uint8_t >( fields, 40 ); // 40: Action aspect - uint8_t typeshift = 0x6; - uint8_t mask = 1 << typeshift; - instantval &= mask; - bool final = ( instantval & mask ) == mask; - bool is_instant = final; - - - info->id = id; info->name = name; info->category = category; From 50404f9b2f42d8dc071e421dc6c1e621efa858bf Mon Sep 17 00:00:00 2001 From: amibu Date: Mon, 25 Sep 2017 18:06:17 +0200 Subject: [PATCH 02/11] Add compile time to !info --- .../DebugCommand/DebugCommandHandler.cpp | 22 ++----------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/src/servers/Server_Zone/DebugCommand/DebugCommandHandler.cpp b/src/servers/Server_Zone/DebugCommand/DebugCommandHandler.cpp index 6a4f6e84..b3137453 100644 --- a/src/servers/Server_Zone/DebugCommand/DebugCommandHandler.cpp +++ b/src/servers/Server_Zone/DebugCommand/DebugCommandHandler.cpp @@ -239,25 +239,6 @@ void Core::DebugCommandHandler::set( char * data, Core::Entity::PlayerPtr pPlaye else pPlayer->setClassJob( static_cast ( id ) ); } - else if( subCommand == "no" ) - { - int32_t id; - - sscanf( params.c_str(), "%d", &id ); - - uint8_t typeshift = 0x6; - uint8_t mask = 1 << typeshift; - id &= mask; - bool final = ( id & mask ) == mask; - pPlayer->sendDebug( std::to_string(final) ); - } - else if( subCommand == "aaah" ) - { - int32_t id; - sscanf( params.c_str(), "%d", &id ); - - pPlayer->sendDebug( std::to_string( pPlayer->actionHasCastTime( id ) ) ); - } else if ( subCommand == "cfpenalty" ) { int32_t minutes; @@ -486,6 +467,7 @@ void Core::DebugCommandHandler::nudge( char * data, Entity::PlayerPtr pPlayer, b void Core::DebugCommandHandler::serverInfo( char * data, Core::Entity::PlayerPtr pPlayer, boost::shared_ptr< Core::DebugCommand > command ) { - pPlayer->sendDebug( "SapphireServer " + Version::VERSION + " - " + Version::GIT_HASH ); + pPlayer->sendDebug( "SapphireServer " + Version::VERSION + "\nRev: " + Version::GIT_HASH ); + pPlayer->sendDebug( "Compiled: " __DATE__ " " __TIME__ ); pPlayer->sendDebug( "Sessions: " + std::to_string( g_serverZone.getSessionCount() ) ); } From b8bc014a914d10d9dba0a42c21afda8edbe8ac23 Mon Sep 17 00:00:00 2001 From: amibu Date: Mon, 25 Sep 2017 18:27:08 +0200 Subject: [PATCH 03/11] updated libraries --- src/libraries | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries b/src/libraries index 4e08821a..f24f9418 160000 --- a/src/libraries +++ b/src/libraries @@ -1 +1 @@ -Subproject commit 4e08821a45adbff969f6c4863bbe156d4229ffda +Subproject commit f24f9418a993c8359be74fbaf6e13bbabe21c99b From 5ecd68e0eab61eb800d4dee1364b4ea977343b06 Mon Sep 17 00:00:00 2001 From: Biscuit Boy Date: Wed, 27 Sep 2017 04:12:08 +1000 Subject: [PATCH 04/11] Added Some TerritoryIntendedUseTypes Added Some Territory Intended Use Types TODO: Add The Rest of The Territory Types and Have Better Names For Them --- src/servers/Server_Common/Common.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/servers/Server_Common/Common.h b/src/servers/Server_Common/Common.h index 752eb711..bdaf72c1 100644 --- a/src/servers/Server_Common/Common.h +++ b/src/servers/Server_Common/Common.h @@ -383,6 +383,29 @@ namespace Core { instance, }; + enum TerritoryIntendedUseType : uint8_t //ToDo: Add The Rest of The Territory Types and Have Better Names For Them + { + Town = 0, + OpenWorld = 1, + Inn = 2, + Dungeon = 3, + JailArea = 5, + Opening = 6, + BeforeTrialDung = 7, + AllianceRaid = 8, + OpenWorldInstanceBattle = 9, + Trial = 10, + HousingArea = 13, + HousingPrivateArea = 14, + MSQPrivateArea = 15, + Raids = 16, + RaidFights = 17, + ChocoboTutorial = 21, + Wedding = 22, + BeginnerTutorial = 27, + PalaceOfTheDead = 31, + }; + enum CharaLook : uint8_t { Race = 0x00, From ac4486625150e170de1675587c7f0dafedbbf68b Mon Sep 17 00:00:00 2001 From: Biscuit Boy Date: Wed, 27 Sep 2017 04:29:48 +1000 Subject: [PATCH 05/11] Should of Fixed Build Changed Opening in TerritoryIntendedUseType to OpeningArea --- src/servers/Server_Common/Common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/servers/Server_Common/Common.h b/src/servers/Server_Common/Common.h index bdaf72c1..15b0ccc6 100644 --- a/src/servers/Server_Common/Common.h +++ b/src/servers/Server_Common/Common.h @@ -390,7 +390,7 @@ namespace Core { Inn = 2, Dungeon = 3, JailArea = 5, - Opening = 6, + OpeningArea = 6, BeforeTrialDung = 7, AllianceRaid = 8, OpenWorldInstanceBattle = 9, From 2333d51fef8cf4a305181e63c5f00b3a7a2f52e5 Mon Sep 17 00:00:00 2001 From: Biscuit Boy Date: Sun, 1 Oct 2017 04:14:54 +1000 Subject: [PATCH 06/11] Added All Coming To X Quests and Fixed Black Bars Fixed the Coming to Ul'dah and Coming to Limsa Quests, also Fixed the Openings having Black Bards and not being able to jump --- scripts/chai/opening/OpeningGridania.chai | 2 +- scripts/chai/opening/OpeningLimsa.chai | 1 - scripts/chai/opening/OpeningUldah.chai | 2 +- scripts/chai/quest/ManSea001.chai | 15 ++++++++------- scripts/chai/quest/ManWil001.chai | 23 ++++++++++++----------- 5 files changed, 22 insertions(+), 21 deletions(-) diff --git a/scripts/chai/opening/OpeningGridania.chai b/scripts/chai/opening/OpeningGridania.chai index fbaf1005..207cf8fe 100644 --- a/scripts/chai/opening/OpeningGridania.chai +++ b/scripts/chai/opening/OpeningGridania.chai @@ -34,7 +34,7 @@ class OpeningGridaniaDef def Scene00000( player ) { - player.eventPlay( this.id, 0, 0x2001, 0, 1, + player.eventPlay( this.id, 0, 0x04AC05, 0, 1, fun( player, eventId, param1, param2, param3 ) { player.setOpeningSequence( 1 ); diff --git a/scripts/chai/opening/OpeningLimsa.chai b/scripts/chai/opening/OpeningLimsa.chai index ebae5446..f7ab44c7 100644 --- a/scripts/chai/opening/OpeningLimsa.chai +++ b/scripts/chai/opening/OpeningLimsa.chai @@ -72,7 +72,6 @@ class OpeningLimsaLominsaDef player.eventPlay( this.id, 40, 1, 2, 1, fun( player, eventId, param1, param2, param3 ) { - player.eventFinish( eventId, UNLOCK ); if( player.getOpeningSequence() == 2 ) { // update the instance boundaries diff --git a/scripts/chai/opening/OpeningUldah.chai b/scripts/chai/opening/OpeningUldah.chai index 6c19e6c4..829bab1b 100644 --- a/scripts/chai/opening/OpeningUldah.chai +++ b/scripts/chai/opening/OpeningUldah.chai @@ -35,7 +35,7 @@ class OpeningUldahDef def Scene00000( player ) { - player.eventPlay( this.id, 0, 0x2001, 0, 1, + player.eventPlay( this.id, 0, 0x04AC05, 0, 1, fun( player, eventId, param1, param2, param3 ) { player.setOpeningSequence( 1 ); diff --git a/scripts/chai/quest/ManSea001.chai b/scripts/chai/quest/ManSea001.chai index c3af3b76..8c060bf2 100644 --- a/scripts/chai/quest/ManSea001.chai +++ b/scripts/chai/quest/ManSea001.chai @@ -51,11 +51,12 @@ class ManSea001Def // Available Scenes in this quest, not necessarly all are used def Scene00000( player ) { - player.eventPlay( this.id, 0, HIDE_HOTBAR, 0/*unk*/, 0/*unk*/, + player.eventPlay( this.id, 0, 0x2000, 0, 0, fun( player, eventId, param1, param2, param3 ) { if( param2 == 1 ) { + player.setOpeningSequence( 2 ); ManSea001.Scene00001( player ); } }); @@ -63,7 +64,7 @@ class ManSea001Def def Scene00001( player ) { - player.eventPlay( this.id, 1, HIDE_HOTBAR, 0/*unk*/, 0/*unk*/, + player.eventPlay( this.id, 1, 0xF8482EFB, 0, 0, fun( player, eventId, param1, param2, param3 ) { ManSea001.Scene00002( player ); @@ -81,13 +82,13 @@ class ManSea001Def def Scene00003( player ) { - player.eventPlay( this.id, 3, NONE, 0/*unk*/, 0/*unk*/, + player.eventPlay( this.id, 3, NONE, 0, 0, fun( player, eventId, param1, param2, param3 ) { player.questUpdate( ManSea001.id, 0x01 ); // add quest to player. // update the instance boundaries, call to the opening event - //player.eventPlay( ManSea001.OPENING_EVENT_HANDLER, 0x1E, HIDE_HOTBAR, 1, 0); + player.eventPlay( ManSea001.OPENING_EVENT_HANDLER, 0x1E, 0x2001, 1, 0); }); } @@ -107,7 +108,7 @@ class ManSea001Def def Scene00006( player ) { - player.eventPlay( this.id, 6, NONE, 0/*unk*/, 0/*unk*/, + player.eventPlay( this.id, 6, 0x20, 0/*unk*/, 0/*unk*/, fun( player, eventId, param1, param2, param3 ) { if( param2 == 1 ) @@ -141,7 +142,7 @@ class ManSea001Def def Scene00011( player ) { - player.eventPlay( this.id, 11, NONE, 0, 0, + player.eventPlay( this.id, 11, 0x2c02, 0, 0, fun( player, eventId, param1, param2, param3 ) { ManSea001.Scene00012( player ); @@ -150,7 +151,7 @@ class ManSea001Def def Scene00012( player ) { - player.eventPlay( this.id, 12, NONE, 0, 0, + player.eventPlay( this.id, 12, 0x20, 0, 0, fun( player, eventId, param1, param2, param3 ) { if( param2 == 1 ) diff --git a/scripts/chai/quest/ManWil001.chai b/scripts/chai/quest/ManWil001.chai index 1799e45a..da55f8c1 100644 --- a/scripts/chai/quest/ManWil001.chai +++ b/scripts/chai/quest/ManWil001.chai @@ -9,25 +9,25 @@ // Start NPC: 1003987 // End NPC: 1003988 -class ManWil001Def +class ManWil001Def { ////////////////////////////////////////////////////////////////////// // default ctor def ManWil001Def() { - // Basic quest information + // Basic quest information this.name = "Coming to Ul'dah"; this.id = 66130; // Quest vars / flags used // GetQuestUI8AL - // Steps in this quest ( 0 is before accepting, + // Steps in this quest ( 0 is before accepting, // 1 is first, 255 means ready for turning it in this.SEQ_0 = 0; this.SEQ_FINISH = 255; - // Quest rewards + // Quest rewards this.RewardExpFactor = 50; this.RewardGil = 103; @@ -49,11 +49,12 @@ class ManWil001Def // Available Scenes in this quest, not necessarly all are used def Scene00000( player ) { - player.eventPlay( this.id, 0, 0, 0, 0, + player.eventPlay( this.id, 0, 0x2000, 0, 0, fun( player, eventId, param1, param2, param3 ) { if( param2 == 1 ) // accept quest { + player.setOpeningSequence( 2 ); ManWil001.Scene00001( player ); } }); @@ -61,7 +62,7 @@ class ManWil001Def def Scene00001( player ) { - player.eventPlay( this.id, 1, 0, 0, 0, + player.eventPlay( this.id, 1, 0xF8482EFB, 0, 0, fun( player, eventId, param1, param2, param3 ) { ManWil001.Scene00002( player ); @@ -70,11 +71,11 @@ class ManWil001Def def Scene00002( player ) { - player.eventPlay( this.id, 2, 0, 0, 0, + player.eventPlay( this.id, 2, NONE, 0, 0, fun( player, eventId, param1, param2, param3 ) { - player.questUpdate( ManWil001.id, ManWil001Obj.SEQ_FINISH );// add quest to player. - player.eventPlay( ManWil001.OPENING_EVENT_HANDLER, 0x1E, 0x2001, 0, 0 ); + player.questUpdate( ManWil001.id, ManWil001.SEQ_FINISH );// add quest to player. + player.eventPlay( ManWil001.OPENING_EVENT_HANDLER, 0x1E, 0x2001, 0, 0 ); }); } @@ -85,7 +86,7 @@ class ManWil001Def def Scene00004( player ) { - player.eventPlay( this.id, 4, 0, 0, 0, + player.eventPlay( this.id, 4, 0x2c02, 0, 0, fun( player, eventId, param1, param2, param3 ) { ManWil001.Scene00005( player ); @@ -94,7 +95,7 @@ class ManWil001Def def Scene00005( player ) { - player.eventPlay( this.id, 5, 0/*flags*/, 0/*unk*/, 0/*unk*/, + player.eventPlay( this.id, 5, 0x20/*flags*/, 0/*unk*/, 0/*unk*/, fun( player, eventId, param1, param2, param3 ) { if( param2 == 1 ) // clicked finish button From 72517bffbd0e417718fb40114728931a208a8cf5 Mon Sep 17 00:00:00 2001 From: Biscuit Boy Date: Sun, 1 Oct 2017 05:04:42 +1000 Subject: [PATCH 07/11] Fixed Close to Home (Archer) Fixed the Close to Home (Archer) Quest --- scripts/chai/quest/ManFst003.chai | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/scripts/chai/quest/ManFst003.chai b/scripts/chai/quest/ManFst003.chai index 8d592cff..403d18d3 100644 --- a/scripts/chai/quest/ManFst003.chai +++ b/scripts/chai/quest/ManFst003.chai @@ -9,11 +9,11 @@ // Start NPC: 1001140 // End NPC: 1000100 -class ManFst003Def +class ManFst003Def { def ManFst003Def() { - // Basic quest information + // Basic quest information this.name = "Close to Home"; this.id = 65659; @@ -24,13 +24,13 @@ class ManFst003Def // GetQuestUI8BL // GetQuestUI8CH - // Steps in this quest ( 0 is before accepting, + // Steps in this quest ( 0 is before accepting, // 1 is first, 255 means ready for turning it in this.SEQ_0 = 0; this.SEQ_1 = 1; this.SEQ_FINISH = 255; - // Quest rewards + // Quest rewards this.RewardExpFactor = 100; this.RewardGil = 107; @@ -74,7 +74,6 @@ class ManFst003Def def checkQuestCompletion( player, varIdx ) { - print( varIdx ); if (varIdx == 3) { player.questMessage(this.id, 1, 0, 0, 0 ); @@ -118,8 +117,8 @@ class ManFst003Def player.eventPlay( this.id, 1, 0x0EFB/*flags*/, 0/*unk*/, 0/*unk*/, fun( player, eventId, param1, param2, param3 ) { - player.setQuestUI8AL( ManFst004.id, 1 ); - ManFst003.checkQuestCompletion( player, 1 ); + player.setQuestUI8AL( ManFst003.id, 1 ); + ManFst003.checkQuestCompletion( player, 0 ); }); } @@ -128,7 +127,7 @@ class ManFst003Def player.eventPlay( this.id, 2, 0, 0, 0, fun( player, eventId, param1, param2, param3 ) { - player.setQuestUI8BH( ManFst004.id, 1 ); + player.setQuestUI8BH( ManFst003.id, 1 ); ManFst003.checkQuestCompletion( player, 3 ); }); } @@ -207,8 +206,8 @@ class ManFst003Def player.eventPlay( this.id, 100, 0x0EFB, 0, 0, fun( player, eventId, param1, param2, param3 ) { - player.setQuestUI8CH( ManFst004.id, 0 ); // remove key item, since we have just traded it - player.setQuestUI8BL( ManFst004.id, 1 ); + player.setQuestUI8CH( ManFst003.id, 0 ); // remove key item, since we have just traded it + player.setQuestUI8BL( ManFst003.id, 1 ); ManFst003.checkQuestCompletion(player, 2 ); }); } @@ -237,7 +236,6 @@ class ManFst003Def }, fun( player, eventId, additional ) {}, eventId ); - player.unlock(); } else if( actor == this.ACTOR2 ) { @@ -257,4 +255,3 @@ class ManFst003Def }; GLOBAL ManFst003 = ManFst003Def(); - From 53e2a46af75e0c6ba17b66f71756e47dca0c8e05 Mon Sep 17 00:00:00 2001 From: Mordred Date: Sun, 1 Oct 2017 01:42:07 +0200 Subject: [PATCH 08/11] Fixed playerStateFlags being wrongfully offset by 1 bit --- src/servers/Server_Common/Common.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/servers/Server_Common/Common.h b/src/servers/Server_Common/Common.h index 15b0ccc6..f573dfc6 100644 --- a/src/servers/Server_Common/Common.h +++ b/src/servers/Server_Common/Common.h @@ -630,6 +630,7 @@ namespace Core { enum struct PlayerStateFlag : uint8_t { + SomeFlag, NoCombat, Combat, Casting, From 0474a6f9ce0645373735c4dbff0b6e27d1f3f094 Mon Sep 17 00:00:00 2001 From: Mordred Date: Sun, 1 Oct 2017 17:58:11 +0200 Subject: [PATCH 09/11] refactoring of server zone mainloop --- src/servers/Server_Common/Common.h | 7 ++-- src/servers/Server_Zone/ServerZone.cpp | 49 ++++++++++++++++---------- src/servers/Server_Zone/ServerZone.h | 6 ++++ 3 files changed, 41 insertions(+), 21 deletions(-) diff --git a/src/servers/Server_Common/Common.h b/src/servers/Server_Common/Common.h index f573dfc6..609496a9 100644 --- a/src/servers/Server_Common/Common.h +++ b/src/servers/Server_Common/Common.h @@ -638,9 +638,9 @@ namespace Core { StatusAffliction1, Occupied, Occupied1, - Occupied2, Occupied3, + BoundByDuty, Occupied4, DuelingArea, @@ -651,6 +651,7 @@ namespace Core { PreparingToCraft, Gathering, Fishing, + BeingRaised, BetweenAreas, Stealthed, @@ -661,9 +662,9 @@ namespace Core { BetweenAreas1, SystemError, LoggingOut, + InvalidLocation, WaitingForDuty, - BoundByDuty1, Mounting, WatchingCutscene, @@ -681,9 +682,9 @@ namespace Core { FreeTrail, BeingMoved, Mounting2, - StatusAffliction3, StatusAffliction4, + RegisteringRaceOrMatch, WaitingForRaceOrMatch, WaitingForTripleTriadMatch, diff --git a/src/servers/Server_Zone/ServerZone.cpp b/src/servers/Server_Zone/ServerZone.cpp index 16042e03..32d6b9e1 100644 --- a/src/servers/Server_Zone/ServerZone.cpp +++ b/src/servers/Server_Zone/ServerZone.cpp @@ -41,7 +41,8 @@ Core::LinkshellMgr g_linkshellMgr; Core::ServerZone::ServerZone( const std::string& configPath, uint16_t serverId ) - : m_configPath( configPath ) + : m_configPath( configPath ), + m_bRunning( true ) { m_pConfig = XMLConfigPtr( new XMLConfig ); } @@ -224,18 +225,32 @@ void Core::ServerZone::run( int32_t argc, char* argv[] ) g_zoneMgr.createZones(); std::vector< std::thread > thread_list; - thread_list.push_back( std::thread( std::bind( &Network::Hive::Run, hive.get() ) ) ); + thread_list.emplace_back( std::thread( std::bind( &Network::Hive::Run, hive.get() ) ) ); g_log.info( "Server listening on port: " + std::to_string( m_port ) ); g_log.info( "Ready for connections..." ); - while( true ) + mainLoop(); + + for( auto& thread_entry : thread_list ) { - std::this_thread::sleep_for( std::chrono::milliseconds( 50 ) ); + thread_entry.join(); + } + +} + +void Core::ServerZone::mainLoop() +{ + while( isRunning() ) + { + this_thread::sleep_for( chrono::milliseconds( 50 ) ); g_zoneMgr.updateZones(); - std::lock_guard lock( m_sessionMutex ); - for( auto sessionIt : m_sessionMap ) + + auto currTime = static_cast< uint32_t >( time( nullptr ) ); + + lock_guard< std::mutex > lock( this->m_sessionMutex ); + for( auto sessionIt : this->m_sessionMap ) { auto session = sessionIt.second; if( session && session->getPlayer() ) @@ -247,9 +262,9 @@ void Core::ServerZone::run( int32_t argc, char* argv[] ) } } - uint32_t currTime = static_cast< uint32_t >( time( nullptr ) ); - auto it = m_sessionMap.begin(); - for( ; it != m_sessionMap.end(); ) + + auto it = this->m_sessionMap.begin(); + for( ; it != this->m_sessionMap.end(); ) { uint32_t diff = currTime - it->second->getLastDataTime(); @@ -257,11 +272,11 @@ void Core::ServerZone::run( int32_t argc, char* argv[] ) if( diff > 20 ) { - g_log.info( "[" + std::to_string( it->second->getId() ) + "] Session time out" ); + g_log.info("[" + std::to_string(it->second->getId() ) + "] Session time out" ); it->second->close(); // if( it->second.unique() ) { - it = m_sessionMap.erase( it ); + it = this->m_sessionMap.erase(it ); } } else @@ -272,13 +287,6 @@ void Core::ServerZone::run( int32_t argc, char* argv[] ) } } - - // currently never reached, need a "stopServer" variable to break out of the above while loop - /*for( auto& thread_entry : thread_list ) - { - thread_entry.join(); - }*/ - } bool Core::ServerZone::createSession( uint32_t sessionId ) @@ -364,3 +372,8 @@ void Core::ServerZone::updateSession( std::string playerName ) it->second->loadPlayer(); } +bool Core::ServerZone::isRunning() const +{ + return m_bRunning; +} + diff --git a/src/servers/Server_Zone/ServerZone.h b/src/servers/Server_Zone/ServerZone.h index 2472c487..130d2f22 100644 --- a/src/servers/Server_Zone/ServerZone.h +++ b/src/servers/Server_Zone/ServerZone.h @@ -40,12 +40,18 @@ namespace Core { Entity::BattleNpcTemplatePtr getBnpcTemplate( std::string templateName ); + void mainLoop(); + + bool isRunning() const; + private: uint16_t m_port; std::string m_ip; + bool m_bRunning; + std::string m_configPath; XMLConfigPtr m_pConfig; From 69a7076e36ff78dd7245d4bd13323a007cc0624d Mon Sep 17 00:00:00 2001 From: Mordred Date: Sun, 1 Oct 2017 18:38:58 +0200 Subject: [PATCH 10/11] Some refactoring and TODO tags --- src/servers/Server_Zone/Actor/BattleNpc.cpp | 9 +-- src/servers/Server_Zone/Actor/CalcBattle.cpp | 1 - src/servers/Server_Zone/Actor/Player.cpp | 67 +++---------------- src/servers/Server_Zone/Actor/PlayerEvent.cpp | 48 +++++++++++++ 4 files changed, 62 insertions(+), 63 deletions(-) diff --git a/src/servers/Server_Zone/Actor/BattleNpc.cpp b/src/servers/Server_Zone/Actor/BattleNpc.cpp index b9891203..6ec2a5d7 100644 --- a/src/servers/Server_Zone/Actor/BattleNpc.cpp +++ b/src/servers/Server_Zone/Actor/BattleNpc.cpp @@ -54,6 +54,7 @@ Core::Entity::BattleNpc::BattleNpc( uint32_t modelId, uint32_t nameid, const Com m_type = ActorType::BattleNpc; m_mode = MODE_IDLE; + m_targetId = INVALID_GAME_OBJECT_ID; m_maxHp = 150; m_maxMp = 100; @@ -229,7 +230,7 @@ void Core::Entity::BattleNpc::setOwner( Core::Entity::PlayerPtr pPlayer ) } else { - GamePacketNew< FFXIVIpcActorOwner, ServerZoneIpcType > setOwnerPacket(getId(), INVALID_GAME_OBJECT_ID); + GamePacketNew< FFXIVIpcActorOwner, ServerZoneIpcType > setOwnerPacket(getId(), INVALID_GAME_OBJECT_ID ); setOwnerPacket.data().type = 0x01; setOwnerPacket.data().actorId = INVALID_GAME_OBJECT_ID; sendToInRangeSet( setOwnerPacket ); @@ -251,15 +252,15 @@ bool Core::Entity::BattleNpc::moveTo( Common::FFXIVARR_POSITION3& pos ) // reached destination return true; - float rot = Math::Util::calcAngFrom(getPos().x, getPos().z, pos.x, pos.z); + float rot = Math::Util::calcAngFrom( getPos().x, getPos().z, pos.x, pos.z ); float newRot = PI - rot + (PI / 2); face( pos ); float angle = Math::Util::calcAngFrom( getPos().x, getPos().z, pos.x, pos.z ) + PI; - float x = static_cast< float >( cosf(angle) * 1.1f ); + float x = static_cast< float >( cosf( angle ) * 1.1f ); float y = ( getPos().y + pos.y ) * 0.5f; // fake value while there is no collision - float z = static_cast< float >( sinf(angle) * 1.1f ); + float z = static_cast< float >( sinf( angle ) * 1.1f ); Common::FFXIVARR_POSITION3 newPos; diff --git a/src/servers/Server_Zone/Actor/CalcBattle.cpp b/src/servers/Server_Zone/Actor/CalcBattle.cpp index f33c2e5c..1ef0f325 100644 --- a/src/servers/Server_Zone/Actor/CalcBattle.cpp +++ b/src/servers/Server_Zone/Actor/CalcBattle.cpp @@ -113,7 +113,6 @@ uint32_t CalcBattle::calculateMaxMp( PlayerPtr pPlayer ) return result; } - uint32_t CalcBattle::calculateHealValue( PlayerPtr pPlayer, uint32_t potency ) { auto classInfoIt = g_exdData.m_classJobInfoMap.find( pPlayer->getClass() ); diff --git a/src/servers/Server_Zone/Actor/Player.cpp b/src/servers/Server_Zone/Actor/Player.cpp index 49bc2ad3..a0f72be5 100644 --- a/src/servers/Server_Zone/Actor/Player.cpp +++ b/src/servers/Server_Zone/Actor/Player.cpp @@ -192,7 +192,7 @@ void Core::Entity::Player::prepareZoning( uint16_t targetZone, bool fadeOut, uin preparePacket.data().targetZone = targetZone; preparePacket.data().fadeOutTime = fadeOutTime; preparePacket.data().animation = animation; - preparePacket.data().fadeOut = fadeOut == true ? 1 : 0; + preparePacket.data().fadeOut = static_cast< uint8_t >( fadeOut ? 1 : 0 ); queuePacket( preparePacket ); } @@ -398,7 +398,7 @@ void Core::Entity::Player::setZone( uint32_t zoneId ) if( isLogin() ) { GamePacketNew< FFXIVIpcCFAvailableContents, ServerZoneIpcType > contentFinderList( getId() ); - for( auto i = 0; i < 72; i++ ) + for( auto i = 0; i < sizeof( contentFinderList.data().contents ); i++ ) { // unlock all contents for now contentFinderList.data().contents[i] = 0xFF; @@ -632,7 +632,9 @@ void Core::Entity::Player::gainExp( uint32_t amount ) if( ( currentExp + amount ) >= neededExpToLevel ) { // levelup - amount = ( currentExp + amount - neededExpToLevel ) > neededExpToLevelplus1 ? neededExpToLevelplus1 - 1 : ( currentExp + amount - neededExpToLevel ); + amount = ( currentExp + amount - neededExpToLevel ) > neededExpToLevelplus1 ? + neededExpToLevelplus1 - 1 : + ( currentExp + amount - neededExpToLevel ); setExp( amount ); gainLevel(); queuePacket( ActorControlPacket143( getId(), UpdateUiExp, static_cast< uint8_t >( getClass() ), amount ) ); @@ -791,50 +793,6 @@ void Core::Entity::Player::setLevelForClass( uint8_t level, Core::Common::ClassJ setSyncFlag( PlayerSyncFlags::ExpLevel ); } -void Core::Entity::Player::eventActionStart( uint32_t eventId, - uint32_t action, - ActionCallback finishCallback, - ActionCallback interruptCallback, - uint64_t additional ) -{ - Action::ActionPtr pEventAction( new Action::EventAction( shared_from_this(), eventId, action, - finishCallback, interruptCallback, additional ) ); - - setCurrentAction( pEventAction ); - auto pEvent = getEvent( eventId ); - - if( !pEvent && getEventCount() ) - { - // We're trying to play a nested event, need to start it first. - eventStart( getId(), eventId, Event::Event::Nest, 0, 0 ); - pEvent = getEvent( eventId ); - } - else if( !pEvent ) - { - g_log.error( "Could not find event " + std::to_string( eventId ) + ", event has not been started!" ); - return; - } - - if( pEvent ) - pEvent->setPlayedScene( true ); - pEventAction->onStart(); -} - - -void Core::Entity::Player::eventItemActionStart( uint32_t eventId, - uint32_t action, - ActionCallback finishCallback, - ActionCallback interruptCallback, - uint64_t additional ) -{ - Action::ActionPtr pEventItemAction( new Action::EventItemAction( shared_from_this(), eventId, action, - finishCallback, interruptCallback, additional ) ); - - setCurrentAction( pEventItemAction ); - - pEventItemAction->onStart(); -} - void Core::Entity::Player::sendModel() { ModelEquipPacket modelEquip( getAsPlayer() ); @@ -973,7 +931,7 @@ void Core::Entity::Player::setGcRankAt( uint8_t index, uint8_t rank ) setSyncFlag( PlayerSyncFlags::GC ); } -const uint8_t * Core::Entity::Player::getStateFlags() const +const uint8_t* Core::Entity::Player::getStateFlags() const { return m_stateFlags; } @@ -1086,21 +1044,16 @@ void Core::Entity::Player::update( int64_t currTime ) m_lastUpdate = currTime; - // @TODO needs to happen in a if check. Don't want autoattacking while an action is being performed. if( !checkAction() ) { - if( m_targetId ) + if( m_targetId && m_currentStance == Entity::Actor::Stance::Active && isAutoattackOn() ) { auto mainWeap = m_pInventory->getItemAt( Inventory::GearSet0, Inventory::EquipSlot::MainHand ); + // @TODO i dislike this, iterating over all in range actors when you already know the id of the actor you need... for( auto actor : m_inRangeActors ) { - if( isAutoattackOn() && - actor->getId() == m_targetId && - actor->isAlive() && - mainWeap && - m_currentStance == Entity::Actor::Stance::Active - ) + if( actor->getId() == m_targetId && actor->isAlive() && mainWeap ) { // default autoattack range // TODO make this dependant on bnpc size @@ -1644,9 +1597,7 @@ uint32_t Core::Entity::Player::getCFPenaltyMinutes() const // check if penalty timestamp already passed current time if (currentTimestamp > endTimestamp) - { return 0; - } auto deltaTime = endTimestamp - currentTimestamp; return static_cast< uint32_t > ( ceil( static_cast< float > (deltaTime) / 60 ) ); diff --git a/src/servers/Server_Zone/Actor/PlayerEvent.cpp b/src/servers/Server_Zone/Actor/PlayerEvent.cpp index f0bf77fe..721456e9 100644 --- a/src/servers/Server_Zone/Actor/PlayerEvent.cpp +++ b/src/servers/Server_Zone/Actor/PlayerEvent.cpp @@ -18,6 +18,10 @@ #include "src/servers/Server_Zone/Network/PacketWrappers/EventPlayPacket.h" #include "src/servers/Server_Zone/Network/PacketWrappers/EventFinishPacket.h" +#include "src/servers/Server_Zone/Action/EventAction.h" +#include "src/servers/Server_Zone/Action/EventItemAction.h" + +#include "src/servers/Server_Zone/Event/Event.h" #include "src/servers/Server_Zone/Event/Event.h" #include "Server_Zone/ServerZone.h" @@ -230,6 +234,50 @@ void Core::Entity::Player::eventFinish( uint32_t eventId, uint32_t freePlayer ) } } +void Core::Entity::Player::eventActionStart( uint32_t eventId, + uint32_t action, + ActionCallback finishCallback, + ActionCallback interruptCallback, + uint64_t additional ) +{ + Action::ActionPtr pEventAction( new Action::EventAction( shared_from_this(), eventId, action, + finishCallback, interruptCallback, additional ) ); + + setCurrentAction( pEventAction ); + auto pEvent = getEvent( eventId ); + + if( !pEvent && getEventCount() ) + { + // We're trying to play a nested event, need to start it first. + eventStart( getId(), eventId, Event::Event::Nest, 0, 0 ); + pEvent = getEvent( eventId ); + } + else if( !pEvent ) + { + g_log.error( "Could not find event " + std::to_string( eventId ) + ", event has not been started!" ); + return; + } + + if( pEvent ) + pEvent->setPlayedScene( true ); + pEventAction->onStart(); +} + + +void Core::Entity::Player::eventItemActionStart( uint32_t eventId, + uint32_t action, + ActionCallback finishCallback, + ActionCallback interruptCallback, + uint64_t additional ) +{ + Action::ActionPtr pEventItemAction( new Action::EventItemAction( shared_from_this(), eventId, action, + finishCallback, interruptCallback, additional ) ); + + setCurrentAction( pEventItemAction ); + + pEventItemAction->onStart(); +} + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void Core::Entity::Player::onLogin() From 62837b83ae33400d4b30805e487460de1cd759ae Mon Sep 17 00:00:00 2001 From: Mordred Date: Sun, 1 Oct 2017 18:43:18 +0200 Subject: [PATCH 11/11] More refactoring, clean up --- src/servers/Server_Zone/Actor/Actor.cpp | 15 +++++++-------- src/servers/Server_Zone/Actor/BattleNpc.h | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/servers/Server_Zone/Actor/Actor.cpp b/src/servers/Server_Zone/Actor/Actor.cpp index 1b4e3c38..dd350a4c 100644 --- a/src/servers/Server_Zone/Actor/Actor.cpp +++ b/src/servers/Server_Zone/Actor/Actor.cpp @@ -53,13 +53,13 @@ std::string Core::Entity::Actor::getName() const /*! \return true if the actor is of type player */ bool Core::Entity::Actor::isPlayer() const { - return ( m_type == ActorType::Player ? true : false ); + return m_type == ActorType::Player; } /*! \return true if the actor is of type mob */ bool Core::Entity::Actor::isMob() const { - return ( m_type == ActorType::BattleNpc ? true : false ); + return m_type == ActorType::BattleNpc; } /*! \return list of actors currently in range */ @@ -240,10 +240,7 @@ bool Core::Entity::Actor::face( const Common::FFXIVARR_POSITION3& p ) setRotation( newRot ); - if( oldRot != newRot ) - return true; - - return false; + return oldRot != newRot ? true : false; } /*! @@ -629,7 +626,8 @@ void Core::Entity::Actor::addStatusEffect( StatusEffect::StatusEffectPtr pEffect /*! \param StatusEffectPtr to be applied to the actor */ void Core::Entity::Actor::addStatusEffectById( uint32_t id, int32_t duration, Entity::Actor& pSource, uint16_t param ) { - StatusEffect::StatusEffectPtr effect( new StatusEffect::StatusEffect( id, pSource.shared_from_this(), shared_from_this(), duration, 3000 ) ); + StatusEffect::StatusEffectPtr effect( new StatusEffect::StatusEffect( id, pSource.shared_from_this(), + shared_from_this(), duration, 3000 ) ); effect->setParam( param ); addStatusEffect( effect ); } @@ -639,7 +637,8 @@ void Core::Entity::Actor::addStatusEffectByIdIfNotExist( uint32_t id, int32_t du { if( !m_pStatusEffectContainer->hasStatusEffect( id ) ) { - StatusEffect::StatusEffectPtr effect( new StatusEffect::StatusEffect( id, pSource.shared_from_this(), shared_from_this(), duration, 3000 ) ); + StatusEffect::StatusEffectPtr effect( new StatusEffect::StatusEffect( id, pSource.shared_from_this(), + shared_from_this(), duration, 3000 ) ); effect->setParam( param ); addStatusEffect( effect ); } diff --git a/src/servers/Server_Zone/Actor/BattleNpc.h b/src/servers/Server_Zone/Actor/BattleNpc.h index d13d082b..f74f9536 100644 --- a/src/servers/Server_Zone/Actor/BattleNpc.h +++ b/src/servers/Server_Zone/Actor/BattleNpc.h @@ -104,7 +104,7 @@ private: uint32_t m_unk2; std::set< HateListEntry* > m_hateList; ActorPtr m_pOwner; - int32_t m_timeOfDeath; + uint32_t m_timeOfDeath; uint32_t m_mobType; };