1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-27 22:57:45 +00:00

Merge pull request #856 from hkAlice/3.3

[3.x] chatchannel fetch by player id; general cleanup;
This commit is contained in:
Mordred 2023-02-02 06:48:36 +01:00 committed by GitHub
commit 0929726ea5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
35 changed files with 107 additions and 143 deletions

View file

@ -22,7 +22,7 @@ struct FFXIVChatFrom : FFXIVIpcBasePacket< ChatFrom >
* Structural representation of the packet sent by the server as
* message from a chat channel that the player is associated to
*/
struct FFXIVChatToChannel : FFXIVIpcBasePacket< Chat >
struct FFXIVChatToChannel : FFXIVIpcBasePacket< ChatToChannel >
{
uint64_t channelID;
uint64_t speakerCharacterID;

View file

@ -41,7 +41,7 @@ namespace Sapphire::Network::Packets
{
SyncReply = 0x0065,
LoginReply = 0x0066,
Chat = 0x0067,
ChatToChannel = 0x0067,
RegionInfo = 0x0069,
MoveTerritory = 0x006A,

View file

@ -45,7 +45,7 @@ namespace Sapphire::Network::Packets::WorldPackets::Server
* Structural representation of the packet sent by the server
* carrying chat messages
*/
struct FFXIVIpcChat : FFXIVIpcBasePacket< Chat >
struct FFXIVIpcChat : FFXIVIpcBasePacket< ChatToChannel >
{
uint16_t type;
uint8_t __padding1;

View file

@ -164,7 +164,7 @@ namespace Sapphire::World::Manager
if( !pAchv )
continue;
auto achvExdData = pAchv->data();
auto& achvExdData = pAchv->data();
if( achvExdData.ConditionArg[ 1 ] <= static_cast< int32_t >( achvData.progressData[ dataKey.u32 ] ) )
unlockAchievement( player, achvId );

View file

@ -1,7 +1,5 @@
#include <Network/PacketWrappers/ChatToChannelPacket.h>
#include <Logging/Logger.h>
#include <Network/CommonNetwork.h>
#include <Network/GamePacket.h>
#include <Network/PacketDef/Chat/ServerChatDef.h>
#include <Service.h>
#include "ChatChannelMgr.h"
@ -65,10 +63,10 @@ void ChatChannelMgr::addToChannel( uint64_t channelId, Entity::Player& player )
}
auto& channelMembers = m_channels[ channelId ];
auto pPlayer = player.getAsPlayer();
auto id = player.getId();
if( std::find( channelMembers.begin(), channelMembers.end(), pPlayer ) == channelMembers.end() )
m_channels[ channelId ].emplace_back( player.getAsPlayer() );
if( std::find( channelMembers.begin(), channelMembers.end(), id ) == channelMembers.end() )
m_channels[ channelId ].emplace_back( id );
}
void ChatChannelMgr::removeFromChannel( uint64_t channelId, Entity::Player& player )
@ -87,9 +85,9 @@ void ChatChannelMgr::removeFromChannel( uint64_t channelId, Entity::Player& play
}
auto& channelMembers = m_channels[ channelId ];
auto pPlayer = player.getAsPlayer();
auto id = player.getId();
auto it = std::find( channelMembers.begin(), channelMembers.end(), pPlayer );
auto it = std::find( channelMembers.begin(), channelMembers.end(), id );
if( it != channelMembers.end() )
channelMembers.erase( it );
}
@ -112,34 +110,26 @@ void ChatChannelMgr::sendMessageToChannel( uint64_t channelId, Entity::Player& s
auto& channelMembers = m_channels[ channelId ];
auto& server = Common::Service< World::WorldServer >::ref();
// send message to all players in chat channel
for( const auto& pPlayer : channelMembers )
for( const auto id : channelMembers )
{
// skip sender from getting their own message
if( pPlayer->getId() == sender.getId() )
if( id == sender.getId() )
continue;
auto pSession = server.getSession( pPlayer->getCharacterId() );
auto pSession = server.getSession( id );
// check if player is online to recv message
if( !pSession )
{
Logger::error( std::string( __FUNCTION__ ) + ": Session not found for player#{}", pPlayer->getCharacterId() );
continue;
}
auto pPlayer = server.getPlayer( id );
// prepare message packet, associating message and sender info with channel data
auto chatToChannelPacket = makeChatPacket< Server::FFXIVChatToChannel >( pPlayer->getId() );
strcpy( chatToChannelPacket->data().message, message.c_str() );
strcpy( chatToChannelPacket->data().speakerName, sender.getName().c_str() );
chatToChannelPacket->data().channelID = channelId;
chatToChannelPacket->data().speakerCharacterID = sender.getCharacterId();
chatToChannelPacket->data().speakerEntityID = sender.getId();
chatToChannelPacket->data().type = 0; // player message type (eg. GM, etc)
auto chatToChannelPacket = std::make_shared< Packets::Server::ChatToChannelPacket >( *pPlayer, sender, channelId, message );
pSession->getChatConnection()->queueOutPacket( chatToChannelPacket );
}
}

View file

@ -6,7 +6,7 @@
namespace Sapphire::Data
{
using ChatChannelMembers = std::vector< Entity::PlayerPtr >;
using ChatChannelMembers = std::vector< uint32_t >;
union ChatChannel
{

View file

@ -536,7 +536,7 @@ void DebugCommandMgr::add( char* data, Entity::Player& player, std::shared_ptr<
sscanf( params.c_str(), "%d", &id );
player.setRewardFlag( static_cast< Common::UnlockEntry >( id ) );
}
else if ( subCommand == "effect")
else if( subCommand == "effect" )
{
uint16_t param1;
sscanf( params.c_str(), "%hu", &param1 );

View file

@ -1,5 +1,4 @@
#ifndef _ACTORCONTROL142_H
#define _ACTORCONTROL142_H
#pragma once
#include <Network/GamePacket.h>
#include <Network/PacketDef/Zone/ServerZoneDef.h>
@ -44,6 +43,4 @@ namespace Sapphire::Network::Packets::WorldPackets::Server
return std::make_shared< ActorControlPacket >( args... );
}
}
#endif /*_ACTORCONTROL142_H*/
}

View file

@ -1,5 +1,4 @@
#ifndef _ACTORCONTROL143_H
#define _ACTORCONTROL143_H
#pragma once
#include <Network/GamePacket.h>
#include <Network/PacketDef/Zone/ServerZoneDef.h>
@ -47,6 +46,4 @@ namespace Sapphire::Network::Packets::WorldPackets::Server
return std::make_shared< ActorControlSelfPacket >( args... );
}
}
#endif /*_ACTORCONTROL143_H*/
}

View file

@ -1,5 +1,4 @@
#ifndef _ACTORCONTROL144_H
#define _ACTORCONTROL144_H
#pragma once
#include <Network/GamePacket.h>
#include <Network/PacketDef/Zone/ServerZoneDef.h>
@ -46,6 +45,4 @@ namespace Sapphire::Network::Packets::WorldPackets::Server
return std::make_shared< ActorControlTargetPacket >( args... );
}
}
#endif /*_ACTORCONTROL144_H*/
}

View file

@ -1,5 +1,4 @@
#ifndef _CHATPACKET_H
#define _CHATPACKET_H
#pragma once
#include <Network/GamePacket.h>
#include <Network/PacketDef/Zone/ServerZoneDef.h>
@ -32,6 +31,4 @@ namespace Sapphire::Network::Packets::WorldPackets::Server
};
};
}
#endif /*_CHATPACKET_H*/
}

View file

@ -0,0 +1,41 @@
#pragma once
#include "Forwards.h"
#include "Actor/Player.h"
#include <Network/GamePacket.h>
#include <Network/PacketDef/Chat/ServerChatDef.h>
namespace Sapphire::Network::Packets::Server
{
/**
* @brief The Chat packet.
*/
class ChatToChannelPacket : public ChatChannelPacket< FFXIVChatToChannel >
{
public:
ChatToChannelPacket( Entity::Player& target,
Entity::Player& sender,
uint64_t channelId,
const std::string& msg ) :
ChatChannelPacket< FFXIVChatToChannel >( target.getId(), target.getId() )
{
initialize( sender, channelId, msg );
};
private:
void initialize( Entity::Player& sender, uint64_t channelId, const std::string& msg )
{
strcpy( m_data.message, msg.c_str() );
strcpy( m_data.speakerName, sender.getName().c_str() );
m_data.channelID = channelId;
m_data.speakerCharacterID = sender.getCharacterId();
m_data.speakerEntityID = sender.getId();
m_data.type = 0;
};
};
}

View file

@ -1,5 +1,4 @@
#ifndef SAPPHIRE_EFFECTPACKET_H
#define SAPPHIRE_EFFECTPACKET_H
#pragma once
#include <Network/GamePacket.h>
#include <Network/PacketDef/Zone/ServerZoneDef.h>
@ -96,6 +95,4 @@ namespace Sapphire::Network::Packets::WorldPackets::Server
uint8_t m_sourceEffectCount{ 0 };
};
}
#endif //SAPPHIRE_EFFECTPACKET_H
}

View file

@ -1,5 +1,4 @@
#ifndef _EVENTFINISH_H
#define _EVENTFINISH_H
#pragma once
#include <Network/GamePacket.h>
@ -34,6 +33,4 @@ namespace Sapphire::Network::Packets::WorldPackets::Server
};
};
}
#endif /*_EVENTFINISH_H*/
}

View file

@ -1,5 +1,4 @@
#ifndef _EVENTLOGMESSAGE_H
#define _EVENTLOGMESSAGE_H
#pragma once
#include <Network/GamePacket.h>
#include <Network/PacketDef/Zone/ServerZoneDef.h>
@ -123,6 +122,4 @@ namespace Sapphire::Network::Packets::WorldPackets::Server
std::copy( args.begin(), args.end(), m_data.args );
};
};
}
#endif /*_EVENTLOGMESSAGE_H*/
}

View file

@ -1,5 +1,4 @@
#ifndef _EVENTPLAY_H
#define _EVENTPLAY_H
#pragma once
#include <Network/GamePacket.h>
#include <Actor/Player.h>
@ -338,6 +337,4 @@ namespace Sapphire::Network::Packets::WorldPackets::Server
}
};
};
}
#endif /*_EVENTPLAY_H*/
}

View file

@ -1,4 +1,5 @@
#pragma once
#include <Network/GamePacket.h>
#include <Actor/Player.h>
#include <Event/EventHandler.h>

View file

@ -1,5 +1,4 @@
#ifndef _EVENTSTART_H
#define _EVENTSTART_H
#pragma once
#include <Network/GamePacket.h>
#include "Forwards.h"
@ -40,5 +39,4 @@ namespace Sapphire::Network::Packets::WorldPackets::Server
};
};
}
#endif /*_EVENTSTART_H*/
}

View file

@ -1,7 +1,6 @@
#pragma once
#include <Network/GamePacket.h>
#include "Forwards.h"
namespace Sapphire::Network::Packets::WorldPackets::Server
@ -36,5 +35,4 @@ namespace Sapphire::Network::Packets::WorldPackets::Server
{
return std::make_shared< HudParamPacket >( args... );
}
}
}

View file

@ -1,7 +1,6 @@
#pragma once
#include <Network/GamePacket.h>
#include "Forwards.h"
namespace Sapphire::Network::Packets::WorldPackets::Server
@ -40,5 +39,4 @@ namespace Sapphire::Network::Packets::WorldPackets::Server
{
return std::make_shared< InitZonePacket >( args... );
}
}
}

View file

@ -1,5 +1,4 @@
#ifndef _CORE_NETWORK_PACKETS_EXAMINEPACKET_H
#define _CORE_NETWORK_PACKETS_EXAMINEPACKET_H
#pragma once
#include <Network/PacketDef/Zone/ServerZoneDef.h>
#include <Network/GamePacket.h>
@ -9,7 +8,6 @@
#include "Inventory/Item.h"
#include "StatusEffect/StatusEffect.h"
namespace Sapphire::Network::Packets::WorldPackets::Server
{
@ -86,6 +84,4 @@ namespace Sapphire::Network::Packets::WorldPackets::Server
};
};
}
#endif /*_CORE_NETWORK_PACKETS_EXAMINEPACKET_H*/
}

View file

@ -6,7 +6,6 @@
namespace Sapphire::Network::Packets::WorldPackets::Server
{
class InviteUpdatePacket : public ZoneChannelPacket< FFXIVIpcInviteUpdate >
{
public:
@ -28,5 +27,4 @@ namespace Sapphire::Network::Packets::WorldPackets::Server
strcpy( m_data.InviteName, player.getName().c_str() );
};
};
}

View file

@ -1,7 +1,6 @@
#pragma once
#include <Network/GamePacket.h>
#include "Forwards.h"
#include <Util/Util.h>
#include <Util/UtilMath.h>
@ -49,4 +48,3 @@ namespace Sapphire::Network::Packets::WorldPackets::Server
return std::make_shared< LinkshellResultPacket >( args... );
}
}

View file

@ -1,5 +1,4 @@
#ifndef _MODELEQUIPPACKET_H
#define _MODELEQUIPPACKET_H
#pragma once
#include <Network/GamePacket.h>
#include "Actor/Player.h"
@ -40,6 +39,4 @@ namespace Sapphire::Network::Packets::WorldPackets::Server
};
};
}
#endif /*_MODELEQUIPPACKET_H*/
}

View file

@ -1,5 +1,4 @@
#ifndef _MOVEACTORPACKET_H
#define _MOVEACTORPACKET_H
#pragma once
#include <Network/GamePacket.h>
#include <Network/PacketDef/Zone/ServerZoneDef.h>
@ -7,7 +6,6 @@
#include "Actor/Player.h"
#include "Forwards.h"
namespace Sapphire::Network::Packets::WorldPackets::Server
{
@ -39,7 +37,4 @@ namespace Sapphire::Network::Packets::WorldPackets::Server
};
};
}
#endif /*_MOVEACTORPACKET_H*/
}

View file

@ -1,5 +1,4 @@
#ifndef _QUESTMESSAGE_H
#define _QUESTMESSAGE_H
#pragma once
#include <Network/GamePacket.h>
#include "Forwards.h"
@ -31,6 +30,4 @@ namespace Sapphire::Network::Packets::WorldPackets::Server
};
};
}
#endif /* _QUESTMESSAGE_H */
}

View file

@ -1,5 +1,4 @@
#ifndef _PLAYERSPAWN_H
#define _PLAYERSPAWN_H
#pragma once
#include <Network/PacketDef/Zone/ServerZoneDef.h>
#include <Network/GamePacket.h>
@ -107,6 +106,4 @@ namespace Sapphire::Network::Packets::WorldPackets::Server
};
};
}
#endif /*_PlayerSpawn_H*/
}

View file

@ -1,5 +1,4 @@
#ifndef _CORE_NETWORK_PACKETS_PINGPACKET_H
#define _CORE_NETWORK_PACKETS_PINGPACKET_H
#pragma once
#include <Network/GamePacket.h>
@ -28,6 +27,4 @@ namespace Sapphire::Network::Packets::WorldPackets::Server
};
};
}
#endif /*_CORE_NETWORK_PACKETS_CPINGPACKET_H*/
}

View file

@ -1,5 +1,4 @@
#ifndef _CORE_NETWORK_PACKETS_INITUIPACKET_H
#define _CORE_NETWORK_PACKETS_INITUIPACKET_H
#pragma once
#include <Network/GamePacket.h>
#include <Network/PacketDef/Zone/ServerZoneDef.h>
@ -89,6 +88,4 @@ namespace Sapphire::Network::Packets::WorldPackets::Server
{
return std::make_shared< PlayerSetupPacket >( args... );
}
}
#endif /*_CORE_NETWORK_PACKETS_CINITUIPACKET_H*/
}

View file

@ -1,5 +1,4 @@
#ifndef _PLAYERSPAWN_H
#define _PLAYERSPAWN_H
#pragma once
#include <Network/PacketDef/Zone/ServerZoneDef.h>
#include <Network/GamePacket.h>
@ -160,6 +159,4 @@ namespace Sapphire::Network::Packets::WorldPackets::Server
};
};
}
#endif /*_PlayerSpawn_H*/
}

View file

@ -1,4 +1,5 @@
#pragma once
#include <Network/GamePacket.h>
#include "Actor/Player.h"
#include <Network/PacketDef/Zone/ServerZoneDef.h>

View file

@ -1,5 +1,4 @@
#ifndef _SERVERNOTICEPACKET_H
#define _SERVERNOTICEPACKET_H
#pragma once
#include <Network/GamePacket.h>
#include <Network/PacketDef/Zone/ServerZoneDef.h>
@ -27,6 +26,4 @@ namespace Sapphire::Network::Packets::WorldPackets::Server
};
};
}
#endif /*_SERVERNOTICEPACKET_H*/
}

View file

@ -1,5 +1,4 @@
#ifndef _UPDATEHPMPTP_H
#define _UPDATEHPMPTP_H
#pragma once
#include <Network/GamePacket.h>
#include <Actor/Chara.h>
@ -30,6 +29,4 @@ namespace Sapphire::Network::Packets::WorldPackets::Server
};
};
}
#endif /*_UPDATEHPMPTP_H*/
}

View file

@ -1,5 +1,4 @@
#ifndef _INVENTORY_SLOT_UPDATE_PACKET_H
#define _INVENTORY_SLOT_UPDATE_PACKET_H
#pragma once
#include <Network/GamePacket.h>
#include "Actor/Player.h"
@ -51,6 +50,4 @@ namespace Sapphire::Network::Packets::WorldPackets::Server
};
};
}
#endif /*_MODELEQUIPPACKET_H*/
}

View file

@ -60,7 +60,8 @@ Territory::Territory() :
m_weatherOverride( Common::Weather::None ),
m_lastMobUpdate( 0 ),
m_nextEObjId( START_EOBJ_ID ),
m_nextActorId( START_GAMEOBJECT_ID )
m_nextActorId( START_GAMEOBJECT_ID ),
m_inRangeDistance( 80.f )
{
}