From 2d4d6c65794ce5ddb1e309b001ddbe9f015d6a1c Mon Sep 17 00:00:00 2001 From: Mordred Date: Sat, 17 Mar 2018 11:36:56 +0100 Subject: [PATCH 1/6] Fixed an issue where players were removed from the wrong zone --- .../sapphire_zone/Zone/InstanceContent.cpp | 8 ++------ src/servers/sapphire_zone/Zone/Zone.cpp | 20 ++++++++++++------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/servers/sapphire_zone/Zone/InstanceContent.cpp b/src/servers/sapphire_zone/Zone/InstanceContent.cpp index 6e66f22c..69cd5c20 100644 --- a/src/servers/sapphire_zone/Zone/InstanceContent.cpp +++ b/src/servers/sapphire_zone/Zone/InstanceContent.cpp @@ -107,17 +107,13 @@ void Core::InstanceContent::onUpdate( uint32_t currTime ) if( m_boundPlayerIds.size() == 0 ) return; - for( const auto playerId : m_boundPlayerIds ) + for( auto playerId : m_boundPlayerIds ) { auto it = m_playerMap.find( playerId ); if( it == m_playerMap.end() ) return; - } - - for( const auto& playerIt : m_playerMap ) - { - const auto& player = playerIt.second; + auto player = it->second; if( !player->isLoadingComplete() || !player->isDirectorInitialized() || !player->isOnEnterEventDone() || diff --git a/src/servers/sapphire_zone/Zone/Zone.cpp b/src/servers/sapphire_zone/Zone/Zone.cpp index 85c8db59..ad76612c 100644 --- a/src/servers/sapphire_zone/Zone/Zone.cpp +++ b/src/servers/sapphire_zone/Zone/Zone.cpp @@ -226,19 +226,21 @@ void Core::Zone::pushActor( Entity::ActorPtr pActor ) void Core::Zone::removeActor( Entity::ActorPtr pActor ) { - auto pCell = pActor->getCellPtr(); - if( pCell ) - { - pCell->removeActor( pActor ); - pCell = nullptr; - } + /* TODO: have to wait and see if removal of this actually breaks anything + this however is potentially removing a player from a zone he does not belong to */ + //auto pCell = pActor->getCellPtr(); + //if( pCell ) + //{ + // pCell->removeActor( pActor ); + // pCell = nullptr; + //} if( pActor->isPlayer() ) { // If it's a player and he's inside boundaries - update his nearby cells if( pActor->getPos().x <= _maxX && pActor->getPos().x >= _minX && - pActor->getPos().z <= _maxY && pActor->getPos().z >= _minY ) + pActor->getPos().z <= _maxY && pActor->getPos().z >= _minY ) { uint32_t x = getPosX( pActor->getPos().x ); uint32_t y = getPosY( pActor->getPos().z ); @@ -539,7 +541,11 @@ void Core::Zone::updateActorPosition( Entity::Actor &actor ) { if( pOldCell ) + { + auto pLog = g_fw.get< Logger >(); + pLog->debug( std::string( __FUNCTION__ ) + "removeActor" ); pOldCell->removeActor( actor.shared_from_this() ); + } pCell->addActor( actor.shared_from_this() ); actor.setCell( pCell ); From c4ec162f0f8c8eac39d17736784934387afb6525 Mon Sep 17 00:00:00 2001 From: Mordred Date: Sat, 17 Mar 2018 18:06:13 +0100 Subject: [PATCH 2/6] Improved handling of actors in zones generally --- src/servers/sapphire_zone/Zone/Cell.cpp | 8 ++++++++ .../sapphire_zone/Zone/TerritoryMgr.cpp | 5 +++-- src/servers/sapphire_zone/Zone/Zone.cpp | 20 +++++++++---------- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/servers/sapphire_zone/Zone/Cell.cpp b/src/servers/sapphire_zone/Zone/Cell.cpp index 6259da07..899fdc4c 100644 --- a/src/servers/sapphire_zone/Zone/Cell.cpp +++ b/src/servers/sapphire_zone/Zone/Cell.cpp @@ -3,6 +3,10 @@ #include "Actor/Chara.h" #include "Forwards.h" #include "Zone.h" +#include + +#include "Framework.h" +extern Core::Framework g_fw; // TODO: the entire zone / areahandling is a bit outdated ( in parts i used this for the 1.0 iteration ) // likely this could be greatly improved or redone @@ -32,6 +36,8 @@ void Core::Cell::init( uint32_t x, uint32_t y, ZonePtr pZone ) void Core::Cell::addActor( Entity::ActorPtr pAct ) { + auto pLog = g_fw.get< Core::Logger >(); + pLog->debug( "Adding actor to cell in " + this->m_pZone->getName() ); if( pAct->isPlayer() ) ++m_playerCount; @@ -40,6 +46,8 @@ void Core::Cell::addActor( Entity::ActorPtr pAct ) void Core::Cell::removeActor( Entity::ActorPtr pAct ) { + auto pLog = g_fw.get< Core::Logger >(); + pLog->debug( "Removing actor from cell in " + this->m_pZone->getName() ); if( pAct->isPlayer() ) --m_playerCount; diff --git a/src/servers/sapphire_zone/Zone/TerritoryMgr.cpp b/src/servers/sapphire_zone/Zone/TerritoryMgr.cpp index 84d5d99a..500f2d93 100644 --- a/src/servers/sapphire_zone/Zone/TerritoryMgr.cpp +++ b/src/servers/sapphire_zone/Zone/TerritoryMgr.cpp @@ -314,6 +314,7 @@ Core::TerritoryMgr::InstanceIdList Core::TerritoryMgr::getInstanceContentIdList( bool Core::TerritoryMgr::movePlayer( uint32_t territoryId, Core::Entity::PlayerPtr pPlayer ) { auto pZone = getZoneByTerriId( territoryId ); + assert( pZone ); return movePlayer( pZone, pPlayer ); } @@ -333,8 +334,8 @@ bool Core::TerritoryMgr::movePlayer( ZonePtr pZone, Core::Entity::PlayerPtr pPla // mark character as zoning in progress pPlayer->setLoadingComplete( false ); - if( pPlayer->getLastPing() != 0 ) - pPlayer->getCurrentZone()->removeActor( pPlayer ); + //if( pPlayer->getLastPing() != 0 ) + // pPlayer->getCurrentZone()->removeActor( pPlayer ); pPlayer->setCurrentZone( pZone ); pZone->pushActor( pPlayer ); diff --git a/src/servers/sapphire_zone/Zone/Zone.cpp b/src/servers/sapphire_zone/Zone/Zone.cpp index ad76612c..ba5d5869 100644 --- a/src/servers/sapphire_zone/Zone/Zone.cpp +++ b/src/servers/sapphire_zone/Zone/Zone.cpp @@ -225,15 +225,14 @@ void Core::Zone::pushActor( Entity::ActorPtr pActor ) void Core::Zone::removeActor( Entity::ActorPtr pActor ) { + float mx = pActor->getPos().x; + float my = pActor->getPos().z; + uint32_t cx = getPosX( mx ); + uint32_t cy = getPosY( my ); - /* TODO: have to wait and see if removal of this actually breaks anything - this however is potentially removing a player from a zone he does not belong to */ - //auto pCell = pActor->getCellPtr(); - //if( pCell ) - //{ - // pCell->removeActor( pActor ); - // pCell = nullptr; - //} + Cell* pCell = getCellPtr(cx, cy); + if( pCell && pCell->hasActor( pActor ) ) + pCell->removeActor( pActor ); if( pActor->isPlayer() ) { @@ -418,8 +417,7 @@ void Core::Zone::updateSessions( bool changedWeather ) // this session is not linked to this area anymore, remove it from zone session list if( ( !pPlayer->getCurrentZone() ) || ( pPlayer->getCurrentZone() != shared_from_this() ) ) { - if( pPlayer->getCellPtr() ) - removeActor( pSession->getPlayer() ); + removeActor( pSession->getPlayer() ); it = m_sessionSet.erase(it ); continue; @@ -543,7 +541,7 @@ void Core::Zone::updateActorPosition( Entity::Actor &actor ) if( pOldCell ) { auto pLog = g_fw.get< Logger >(); - pLog->debug( std::string( __FUNCTION__ ) + "removeActor" ); + pLog->debug( std::string( __FUNCTION__ ) + " -> removeActor() ...moving cell..." ); pOldCell->removeActor( actor.shared_from_this() ); } From dcdca5927f4f7dbef283a543bc078a06026fd6f3 Mon Sep 17 00:00:00 2001 From: Perize Date: Sun, 18 Mar 2018 17:40:00 +0900 Subject: [PATCH 3/6] Added pvp duel packetdef --- src/common/Common.h | 8 +++++++- src/common/Network/PacketDef/Ipcs.h | 1 + src/common/Network/PacketDef/Zone/ServerZoneDef.h | 12 ++++++++++++ .../sapphire_zone/Network/Handlers/ActionHandler.cpp | 4 ++++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/common/Common.h b/src/common/Common.h index aadddb7b..61b4ce9c 100644 --- a/src/common/Common.h +++ b/src/common/Common.h @@ -557,7 +557,7 @@ namespace Common { SetTitle = 0x1F4, SetStatusIcon = 0x1F8, - + LimitBreakGauge = 0x1F9, // Max level, amount, build type (chop sound), lb type(0=pve lb 1=pvp lb) SetHomepoint = 0x1FB, SetFavorite = 0x1FC, LearnTeleport = 0x1FD, @@ -586,6 +586,12 @@ namespace Common { ToggleOrchestrionUnlock = 0x396, Dismount = 0x3a0 + + SetPvPState = 0x5E0, // param3 must be 6 to engage a duel (hardcoded in the client) + EndDuelSession = 0x5E1, // because someone went oob? + StartDuelCountdown = 0x5E2, // begins a countdown; also does some duel bgm thing. + StartDuel = 0x5E3, // actually all it does is set the challenger actor id; + DuelResultScreen = 0x5E4, // win/lose thing, also reset a target id just like what EndDuelSession does. }; enum struct ChatType : uint16_t diff --git a/src/common/Network/PacketDef/Ipcs.h b/src/common/Network/PacketDef/Ipcs.h index 0925c62b..82af4c8c 100644 --- a/src/common/Network/PacketDef/Ipcs.h +++ b/src/common/Network/PacketDef/Ipcs.h @@ -164,6 +164,7 @@ namespace Packets { PrepareZoning = 0x027C, // updated 4.2 ActorGauge = 0x027D, // updated 4.2 + DuelChallenge = 0x0277, // 4.2; this is the responsible for opening an ui PerformNote = 0x0286, // updated 4.2 // Unknown IPC types that still need to be sent diff --git a/src/common/Network/PacketDef/Zone/ServerZoneDef.h b/src/common/Network/PacketDef/Zone/ServerZoneDef.h index a835386f..0a5fcd26 100644 --- a/src/common/Network/PacketDef/Zone/ServerZoneDef.h +++ b/src/common/Network/PacketDef/Zone/ServerZoneDef.h @@ -1363,6 +1363,18 @@ struct FFXIVIpcObjectDespawn : FFXIVIpcBasePacket uint8_t padding[7]; }; +struct FFXIVIpcDuelChallenge : FFXIVIpcBasePacket +{ + uint8_t otherClassJobId; + uint8_t otherLevel; // class job level + uint8_t challengeByYou; // 0 if the other challenges you, 1 if you challenges the other. + uint8_t otherItemLevel; + + uint32_t otherActorId; + + char otherName[32]; +}; + } /* Server */ } /* Packets */ diff --git a/src/servers/sapphire_zone/Network/Handlers/ActionHandler.cpp b/src/servers/sapphire_zone/Network/Handlers/ActionHandler.cpp index d099be24..48010f02 100644 --- a/src/servers/sapphire_zone/Network/Handlers/ActionHandler.cpp +++ b/src/servers/sapphire_zone/Network/Handlers/ActionHandler.cpp @@ -103,6 +103,10 @@ enum ClientTrigger CompanionActionUnlock = 0x6A6, OpenPerformInstrumentUI = 0x71C, + + OpenDuelUI = 0x898, // Open a duel ui + DuelRequestResult = 0x899, // either accept/reject + }; void Core::Network::GameConnection::actionHandler( const Packets::GamePacket& inPacket, From 4a723907ef36dfe943a407ff003c4d5e3088b5e9 Mon Sep 17 00:00:00 2001 From: Mordred <30826167+SapphireMordred@users.noreply.github.com> Date: Sun, 18 Mar 2018 10:23:59 +0100 Subject: [PATCH 4/6] Update Ipcs.h --- src/common/Network/PacketDef/Ipcs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/Network/PacketDef/Ipcs.h b/src/common/Network/PacketDef/Ipcs.h index 82af4c8c..e8174617 100644 --- a/src/common/Network/PacketDef/Ipcs.h +++ b/src/common/Network/PacketDef/Ipcs.h @@ -164,7 +164,7 @@ namespace Packets { PrepareZoning = 0x027C, // updated 4.2 ActorGauge = 0x027D, // updated 4.2 - DuelChallenge = 0x0277, // 4.2; this is the responsible for opening an ui + DuelChallenge = 0x0277, // 4.2; this is the responsible for opening an ui PerformNote = 0x0286, // updated 4.2 // Unknown IPC types that still need to be sent From d74c49218d794c4729f16aade83e9e953c1fbf6f Mon Sep 17 00:00:00 2001 From: Perize Date: Sun, 18 Mar 2018 19:06:32 +0900 Subject: [PATCH 5/6] Added the duty action because why not --- src/common/Common.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/common/Common.h b/src/common/Common.h index 61b4ce9c..e72ae95c 100644 --- a/src/common/Common.h +++ b/src/common/Common.h @@ -587,11 +587,18 @@ namespace Common { ToggleOrchestrionUnlock = 0x396, Dismount = 0x3a0 + // PvP Duel SetPvPState = 0x5E0, // param3 must be 6 to engage a duel (hardcoded in the client) EndDuelSession = 0x5E1, // because someone went oob? StartDuelCountdown = 0x5E2, // begins a countdown; also does some duel bgm thing. StartDuel = 0x5E3, // actually all it does is set the challenger actor id; DuelResultScreen = 0x5E4, // win/lose thing, also reset a target id just like what EndDuelSession does. + + // Duty Action + SetDutyActionId = 0x5E8, // ContentExAction + SetDutyActionHud = 0x5E9, // disable/enable + SetDutyActionActive = 0x5EA, + SetDutyActionRemaining = 0x5EB, }; enum struct ChatType : uint16_t From 506ecfc19bcdc02cc7d5f63aa37107c4aeaa1086 Mon Sep 17 00:00:00 2001 From: Perize Date: Sun, 18 Mar 2018 19:32:42 +0900 Subject: [PATCH 6/6] typo fix --- src/common/Common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/Common.h b/src/common/Common.h index e72ae95c..03be85bc 100644 --- a/src/common/Common.h +++ b/src/common/Common.h @@ -585,7 +585,7 @@ namespace Common { DisableCurrentFestival = 0x386, ToggleOrchestrionUnlock = 0x396, - Dismount = 0x3a0 + Dismount = 0x3A0, // PvP Duel SetPvPState = 0x5E0, // param3 must be 6 to engage a duel (hardcoded in the client)