mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-05-25 02:57:45 +00:00
Decouple shared ptr (avoid potential dangling ptr), FriendList stuff
This commit is contained in:
parent
1332d580df
commit
f7f44950cb
8 changed files with 151 additions and 15 deletions
10
src/servers/Server_Zone/Actor/Group/FriendList.cpp
Normal file
10
src/servers/Server_Zone/Actor/Group/FriendList.cpp
Normal file
|
@ -0,0 +1,10 @@
|
|||
#include <cassert>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include <Server_Common/Network/PacketDef/Ipcs.h>
|
||||
#include <Server_Common/Network/PacketDef/Zone/ServerZoneDef.h>
|
||||
#include <Server_Zone/Actor/Actor.h>
|
||||
#include <Server_Zone/Actor/Player.h>
|
||||
#include <Server_Zone/ServerZone.h>
|
||||
#include <Server_Common/Network/GamePacketNew.h>
|
||||
#include "FriendList.h"
|
81
src/servers/Server_Zone/Actor/Group/FriendList.h
Normal file
81
src/servers/Server_Zone/Actor/Group/FriendList.h
Normal file
|
@ -0,0 +1,81 @@
|
|||
#ifndef _FRIENDLIST_H
|
||||
#define _FRIENDLIST_H
|
||||
|
||||
#include <src/servers/Server_Common/Common.h>
|
||||
#include <Server_Common/Forwards.h>
|
||||
#include <Server_Zone/Actor/Group/Group.h>
|
||||
#include <Server_Zone/Forwards.h>
|
||||
#include <boost/enable_shared_from_this.hpp>
|
||||
#include <set>
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
|
||||
|
||||
|
||||
namespace Core {
|
||||
namespace Entity {
|
||||
namespace Group {
|
||||
|
||||
class FriendList;
|
||||
using FriendListPtr = boost::shared_ptr< FriendList >;
|
||||
|
||||
struct GroupMember
|
||||
{
|
||||
uint64_t contentId;
|
||||
char name[32];
|
||||
uint32_t category;
|
||||
uint64_t inviterId;
|
||||
};
|
||||
|
||||
enum class GroupType : uint8_t
|
||||
{
|
||||
None,
|
||||
Party,
|
||||
FriendList,
|
||||
FreeCompany,
|
||||
Linkshell,
|
||||
FreeCompanyPetition,
|
||||
Blacklist,
|
||||
ContentGroup
|
||||
};
|
||||
|
||||
class FriendList : public Group
|
||||
{
|
||||
private:
|
||||
GroupType m_type{ GroupType::FriendList };
|
||||
uint64_t m_id{ 0 };
|
||||
uint64_t m_ownerId{ 0 };
|
||||
uint32_t m_maxCapacity{ 200 };
|
||||
uint32_t m_maxRoles{ 8 };
|
||||
time_point m_createTime{ std::chrono::steady_clock::now() };
|
||||
std::map< uint64_t, GroupMember > m_members;
|
||||
std::map< uint64_t, uint64_t > m_invites; // <recipient, sender>
|
||||
|
||||
|
||||
virtual Core::Network::Packets::GamePacketPtr addMember( PlayerPtr pSender, PlayerPtr pRecipient, uint64_t senderId = 0, uint64_t recipientId = 0 );
|
||||
virtual Core::Network::Packets::GamePacketPtr inviteMember( PlayerPtr pSender, PlayerPtr pRecipient, uint64_t senderId = 0, uint64_t recipientId = 0 );
|
||||
virtual Core::Network::Packets::GamePacketPtr removeMember( PlayerPtr pSender, PlayerPtr pRecipient, uint64_t senderId = 0, uint64_t recipientId = 0 );
|
||||
virtual Core::Network::Packets::GamePacketPtr kickMember( PlayerPtr pSender, PlayerPtr pRecipient, uint64_t senderId = 0, uint64_t recipientId = 0 );
|
||||
virtual void sendPacketToMembers( Core::Network::Packets::GamePacketPtr pPacket, bool invitesToo = false );
|
||||
|
||||
virtual void load();
|
||||
virtual void update();
|
||||
virtual void disband();
|
||||
public:
|
||||
FriendList( uint64_t id, uint64_t ownerId, uint32_t maxCapacity, time_point createTime ) :
|
||||
m_id( id ), m_ownerId( m_ownerId ), m_maxCapacity( maxCapacity ), m_createTime( createTime ){};
|
||||
~FriendList(){};
|
||||
|
||||
bool isParty() const;
|
||||
bool isFriendList() const;
|
||||
bool isFreeCompany() const;
|
||||
bool isLinkshell() const;
|
||||
bool isFreeCompanyPetition() const;
|
||||
bool isBlacklist() const;
|
||||
bool isContentGroup() const;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
#endif // ! _FRIENDLIST_H
|
|
@ -1,6 +1,7 @@
|
|||
#include <cassert>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
#include <Server_Zone/Session.h>
|
||||
#include <Server_Common/Network/PacketDef/Ipcs.h>
|
||||
#include <Server_Common/Network/PacketDef/Zone/ServerZoneDef.h>
|
||||
#include <Server_Zone/Actor/Actor.h>
|
||||
|
@ -9,6 +10,8 @@
|
|||
#include <Server_Common/Network/GamePacketNew.h>
|
||||
#include "Group.h"
|
||||
|
||||
extern Core::ServerZone g_serverZone;
|
||||
|
||||
// todo: i fuckin have no fuckin clue how to use group manager classes, why not just have a map of <id, group>?
|
||||
// todo: invite map in g_serverZone.getGroupMgr(GroupType) and look up
|
||||
|
||||
|
@ -46,7 +49,7 @@ Core::Network::Packets::GamePacketPtr Core::Entity::Group::Group::addMember( Pla
|
|||
GroupMember member;
|
||||
member.inviterId = senderId;
|
||||
member.role = 0;
|
||||
member.pPlayer = pRecipient;
|
||||
member.contentId = recipientId;
|
||||
m_members.emplace( recipientId, member );
|
||||
}
|
||||
else
|
||||
|
@ -59,14 +62,12 @@ Core::Network::Packets::GamePacketPtr Core::Entity::Group::Group::addMember( Pla
|
|||
void Core::Entity::Group::Group::sendPacketToMembers( Core::Network::Packets::GamePacketPtr pPacket, bool invitesToo )
|
||||
{
|
||||
assert( pPacket );
|
||||
if( pPacket )
|
||||
{
|
||||
for( const auto& member : m_members )
|
||||
{
|
||||
if( member.second.pPlayer )
|
||||
auto pSession = g_serverZone.getSession( member.second.name );
|
||||
if( pSession )
|
||||
{
|
||||
member.second.pPlayer->queuePacket( pPacket );
|
||||
}
|
||||
pSession->getPlayer()->queuePacket( pPacket );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,8 @@ using GroupPtr = boost::shared_ptr< Group >;
|
|||
struct GroupMember
|
||||
{
|
||||
uint64_t inviterId;
|
||||
PlayerPtr pPlayer;
|
||||
uint64_t contentId;
|
||||
std::string name;
|
||||
uint32_t role;
|
||||
};
|
||||
|
||||
|
@ -49,11 +50,7 @@ private:
|
|||
std::map< uint64_t, uint64_t > m_invites; // <recipient, sender>
|
||||
|
||||
|
||||
virtual Core::Network::Packets::GamePacketPtr addMember( PlayerPtr pSender, PlayerPtr pRecipient, uint64_t senderId = 0, uint64_t recipientId = 0 );
|
||||
virtual Core::Network::Packets::GamePacketPtr inviteMember( PlayerPtr pSender, PlayerPtr pRecipient, uint64_t senderId = 0, uint64_t recipientId = 0 );
|
||||
virtual Core::Network::Packets::GamePacketPtr removeMember( PlayerPtr pSender, PlayerPtr pRecipient, uint64_t senderId = 0, uint64_t recipientId = 0 );
|
||||
virtual Core::Network::Packets::GamePacketPtr kickMember( PlayerPtr pSender, PlayerPtr pRecipient, uint64_t senderId = 0, uint64_t recipientId = 0 );
|
||||
virtual void sendPacketToMembers( Core::Network::Packets::GamePacketPtr pPacket, bool invitesToo = false );
|
||||
|
||||
|
||||
virtual void load();
|
||||
virtual void update();
|
||||
|
@ -70,6 +67,12 @@ public:
|
|||
bool isFreeCompanyPetition() const;
|
||||
bool isBlacklist() const;
|
||||
bool isContentGroup() const;
|
||||
|
||||
virtual Core::Network::Packets::GamePacketPtr addMember(PlayerPtr pSender, PlayerPtr pRecipient, uint64_t senderId = 0, uint64_t recipientId = 0);
|
||||
virtual Core::Network::Packets::GamePacketPtr inviteMember(PlayerPtr pSender, PlayerPtr pRecipient, uint64_t senderId = 0, uint64_t recipientId = 0);
|
||||
virtual Core::Network::Packets::GamePacketPtr removeMember(PlayerPtr pSender, PlayerPtr pRecipient, uint64_t senderId = 0, uint64_t recipientId = 0);
|
||||
virtual Core::Network::Packets::GamePacketPtr kickMember(PlayerPtr pSender, PlayerPtr pRecipient, uint64_t senderId = 0, uint64_t recipientId = 0);
|
||||
virtual void sendPacketToMembers(Core::Network::Packets::GamePacketPtr pPacket, bool invitesToo = false);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
#include "../FriendList.h"
|
||||
#include "FriendListMgr.h"
|
39
src/servers/Server_Zone/Actor/Group/Manager/FriendListMgr.h
Normal file
39
src/servers/Server_Zone/Actor/Group/Manager/FriendListMgr.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
#ifndef _FRIENDLISTMGR_H
|
||||
#define _FRIENDLISTMGR_H
|
||||
|
||||
#include <map>
|
||||
#include <cstdint>
|
||||
|
||||
#include <boost/enable_shared_from_this.hpp>
|
||||
#include <Server_Zone/Forwards.h>
|
||||
#include <Server_Zone/Actor/Group/Group.h>
|
||||
|
||||
#include <Server_Zone/Actor/Group/Manager/GroupMgr.h>
|
||||
|
||||
namespace Core {
|
||||
namespace Entity {
|
||||
namespace Group {
|
||||
|
||||
class FriendListMgr : public GroupMgr
|
||||
{
|
||||
private:
|
||||
GroupType m_type{ GroupType::None };
|
||||
uint64_t m_groupCount{ 0 };
|
||||
uint32_t m_maxEntries{ 0xFFFFFFFF };
|
||||
std::map< uint64_t, GroupPtr > m_groups; // < groupid, groupPtr >
|
||||
std::map< uint64_t, uint64_t > m_invites; // < recipient, groupid >
|
||||
virtual GroupPtr createGroup( PlayerPtr pOwner ) = 0;
|
||||
|
||||
public:
|
||||
FriendListMgr( GroupType type, uint32_t maxEntries ) :
|
||||
m_type( type ), m_maxEntries( maxEntries ){};
|
||||
~FriendListMgr(){};
|
||||
|
||||
GroupPtr findGroupByInviteIdForPlayer( uint64_t playerId ) const;
|
||||
GroupPtr findGroupById( uint64_t groupId ) const;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
#endif /* ! _FRIENDLISTMGR_H */
|
|
@ -32,7 +32,7 @@ private:
|
|||
friend virtual void load();
|
||||
friend virtual void update();
|
||||
friend virtual void disband();
|
||||
//*/
|
||||
*/
|
||||
public:
|
||||
GroupMgr( GroupType type, uint32_t maxEntries ) :
|
||||
m_type( type ), m_maxEntries( maxEntries ){};
|
||||
|
|
Loading…
Add table
Reference in a new issue