1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-25 11:07:45 +00:00

Half work on templating SocialManager, more refactoring

This commit is contained in:
Maru 2017-12-21 03:45:56 -02:00
parent 9e152f253f
commit c8f2ee7305
29 changed files with 63 additions and 37 deletions

View file

@ -6,8 +6,8 @@
#include <Server_Common/Common.h> #include <Server_Common/Common.h>
#include <Server_Common/Network/PacketDef/Zone/ServerZoneDef.h> #include <Server_Common/Network/PacketDef/Zone/ServerZoneDef.h>
#include <Server_Zone/Actor/Social/FriendList.h> #include <Server_Zone/Social/FriendList.h>
#include <Server_Zone/Actor/Social/Manager/FriendListMgr.h> #include <Server_Zone/Social/Manager/FriendListMgr.h>
#include <Server_Common/Common.h> #include <Server_Common/Common.h>
#include "Actor.h" #include "Actor.h"

View file

@ -8,8 +8,6 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR} )
file(GLOB SERVER_PUBLIC_INCLUDE_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} file(GLOB SERVER_PUBLIC_INCLUDE_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
/*.h /*.h
Actor/*.h Actor/*.h
Actor/Social/*.h
Actor/Social/Manager/*.h
Action/*.h Action/*.h
DebugCommand/*.h DebugCommand/*.h
Event/*.h Event/*.h
@ -19,6 +17,8 @@ file(GLOB SERVER_PUBLIC_INCLUDE_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
Network/*.h Network/*.h
Network/Handlers/*.h Network/Handlers/*.h
Network/PacketWrappers/*.h Network/PacketWrappers/*.h
Social/*.h
Social/Manager/*.h
Script/*.h Script/*.h
StatusEffect/*.h StatusEffect/*.h
Zone/*.h) Zone/*.h)
@ -37,6 +37,8 @@ file(GLOB SERVER_SOURCE_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
Network/*.c* Network/*.c*
Network/Handlers/*.c* Network/Handlers/*.c*
Network/PacketWrappers/*.c* Network/PacketWrappers/*.c*
Social/*.c*
Social/Manager/*.c*
Script/*.c* Script/*.c*
StatusEffect/*.c* StatusEffect/*.c*
Zone/*.c*) Zone/*.c*)

View file

@ -1,4 +1,5 @@
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <random>
#include <Server_Common/Common.h> #include <Server_Common/Common.h>
#include <Server_Common/Version.h> #include <Server_Common/Version.h>
@ -348,6 +349,30 @@ void Core::DebugCommandHandler::add( char * data, Entity::Player& player, boost:
pBNpc->setCurrentZone( pZone ); pBNpc->setCurrentZone( pZone );
pZone->pushActor( pBNpc ); pZone->pushActor( pBNpc );
}
else if( subCommand == "sspawn" )
{
int32_t model, name, count, distCoefficient, i;
sscanf( params.c_str(), "%d %d %d %d", &model, &name, &count, &distCoefficient );
for ( i = 0; i < count; i++ )
{
Common::FFXIVARR_POSITION3 posC = player.getPos();
std::mt19937 gen( rand() * 1000 );
std::uniform_int_distribution<int> dis( distCoefficient * -1, distCoefficient );
posC.x += dis( gen );
posC.z += dis( gen );
Entity::BattleNpcPtr pBNpc( new Entity::BattleNpc( model, name, posC ) );
auto pZone = player.getCurrentZone();
pBNpc->setCurrentZone( pZone );
pZone->pushActor( pBNpc );
}
} }
else if( subCommand == "op" ) else if( subCommand == "op" )
{ {

View file

@ -36,7 +36,7 @@
#include "Event/EventHelper.h" #include "Event/EventHelper.h"
#include "Action/Action.h" #include "Action/Action.h"
#include "Action/ActionTeleport.h" #include "Action/ActionTeleport.h"
#include "Actor/Social/Manager/FriendListMgr.h" #include "Social/Manager/FriendListMgr.h"
extern Core::Logger g_log; extern Core::Logger g_log;
@ -44,7 +44,7 @@ extern Core::ServerZone g_serverZone;
extern Core::ZoneMgr g_zoneMgr; extern Core::ZoneMgr g_zoneMgr;
extern Core::Data::ExdData g_exdData; extern Core::Data::ExdData g_exdData;
extern Core::DebugCommandHandler g_gameCommandMgr; extern Core::DebugCommandHandler g_gameCommandMgr;
extern Core::Entity::Social::FriendListMgr g_friendListMgr; extern Core::Social::SocialMgr g_socialMgr;
using namespace Core::Common; using namespace Core::Common;
using namespace Core::Network::Packets; using namespace Core::Network::Packets;

View file

@ -220,7 +220,7 @@ void Core::ServerZone::run( int32_t argc, char* argv[] )
return; return;
} }
g_friendListMgr.init(); g_friendListMgr = Core::Social::SocialMgr<Common::SocialListType::FriendList>();
Network::HivePtr hive( new Network::Hive() ); Network::HivePtr hive( new Network::Hive() );
Network::addServerToHive< Network::GameConnection >( m_ip, m_port, hive ); Network::addServerToHive< Network::GameConnection >( m_ip, m_port, hive );

View file

@ -5,7 +5,7 @@
#include <Server_Common/Network/PacketDef/Zone/ServerZoneDef.h> #include <Server_Common/Network/PacketDef/Zone/ServerZoneDef.h>
#include <Server_Common/Network/GamePacketNew.h> #include <Server_Common/Network/GamePacketNew.h>
#include <Server_Common/Forwards.h> #include <Server_Common/Forwards.h>
#include <Server_Zone/Actor/Social/Group.h> #include <Server_Zone/Social/Group.h>
#include <Server_Zone/Forwards.h> #include <Server_Zone/Forwards.h>
#include <boost/enable_shared_from_this.hpp> #include <boost/enable_shared_from_this.hpp>
#include <set> #include <set>

View file

@ -6,17 +6,16 @@
#include <boost/enable_shared_from_this.hpp> #include <boost/enable_shared_from_this.hpp>
#include <Server_Zone/Forwards.h> #include <Server_Zone/Forwards.h>
#include <Server_Zone/Actor/Social/Group.h> #include <Server_Zone/Social/Group.h>
#include <Server_Zone/Actor/Social/FriendList.h> #include <Server_Zone/Social/FriendList.h>
#include <Server_Zone/Actor/Social/Manager/GroupMgr.h> #include <Server_Zone/Social/Manager/SocialMgr.h>
#include <Server_Zone/Forwards.h> #include <Server_Zone/Forwards.h>
namespace Core { namespace Core {
namespace Entity {
namespace Social { namespace Social {
class FriendListMgr : public GroupMgr class FriendListMgr
{ {
public: public:
FriendListMgr(); FriendListMgr();
@ -32,7 +31,7 @@ public:
private: private:
// todo: can we handle this m_groups grouptype better..? // todo: can we handle this m_groups grouptype better..?
GroupType m_type{ GroupType::FriendList }; //GroupType m_type{ GroupType::FriendList };
}; };

View file

@ -1,19 +1,19 @@
#include "../Group.h" #include "../Group.h"
#include "GroupMgr.h" #include "SocialMgr.h"
using namespace Core::Entity;
Social::GroupMgr::GroupMgr() template< class T >
Core::Social::SocialMgr::GroupMgr()
{ {
} }
Social::GroupMgr::~GroupMgr() Core::Social::SocialMgr::~GroupMgr()
{ {
} }
Social::GroupPtr Social::GroupMgr::findGroupByInviteIdForPlayer( uint64_t playerId ) const T Core::Social::SocialMgr::findGroupByInviteIdForPlayer( uint64_t playerId ) const
{ {
auto it = m_invites.find( playerId ); auto it = m_invites.find( playerId );
if( it != m_invites.end() ) if( it != m_invites.end() )
@ -23,7 +23,7 @@ Social::GroupPtr Social::GroupMgr::findGroupByInviteIdForPlayer( uint64_t player
return nullptr; return nullptr;
} }
Social::GroupPtr Social::GroupMgr::findGroupById( uint64_t groupId ) const T Core::Social::SocialMgr::findGroupById( uint64_t groupId ) const
{ {
auto it = m_groups.find( groupId ); auto it = m_groups.find( groupId );
if( it != m_groups.end() ) if( it != m_groups.end() )
@ -33,13 +33,13 @@ Social::GroupPtr Social::GroupMgr::findGroupById( uint64_t groupId ) const
return nullptr; return nullptr;
} }
uint64_t Social::GroupMgr::generateGroupId() uint64_t Core::Social::SocialMgr::GroupMgr::generateGroupId()
{ {
m_lastGroupId++; m_lastGroupId++;
return m_lastGroupId; return m_lastGroupId;
} }
bool Social::GroupMgr::hasInvite( uint64_t playerId ) const bool Core::Social::SocialMgr::hasInvite( uint64_t playerId ) const
{ {
auto it = m_invites.find( playerId ); auto it = m_invites.find( playerId );
if ( it != m_invites.end() ) if ( it != m_invites.end() )

View file

@ -6,23 +6,23 @@
#include <boost/enable_shared_from_this.hpp> #include <boost/enable_shared_from_this.hpp>
#include <Server_Zone/Forwards.h> #include <Server_Zone/Forwards.h>
#include <Server_Zone/Actor/Social/Group.h> #include <Social/Group.h>
namespace Core { namespace Core {
namespace Entity {
namespace Social { namespace Social {
class GroupMgr template< class T >
class SocialMgr
{ {
public: public:
GroupMgr(); SocialMgr();
virtual ~GroupMgr(); virtual ~SocialMgr();
virtual GroupPtr findGroupByInviteIdForPlayer( uint64_t playerId ) const; T findGroupByInviteIdForPlayer( uint64_t playerId ) const;
virtual GroupPtr findGroupById( uint64_t groupId ) const; T findGroupById( uint64_t groupId ) const;
/* /*
template <typename GroupPtr>
GroupPtr findGroup( uint64_t arg ) T findGroup( uint64_t groupId )
{ {
auto it = m_groups.find( groupId ); auto it = m_groups.find( groupId );
if ( it != m_groups.end() ) if ( it != m_groups.end() )
@ -35,10 +35,11 @@ public:
bool hasInvite( uint64_t playerId ) const; bool hasInvite( uint64_t playerId ) const;
protected: protected:
GroupType m_type{ GroupType::None }; // those would be implemented in T, so you'd have T.m_type and T.m_maxEntries
uint64_t m_groupCount{ 0 }; // GroupType m_type{ GroupType::None };
uint32_t m_maxEntries{ 0xFFFFFFFF }; // uint32_t m_maxEntries{ 0xFFFFFFFF };
uint64_t m_groupCount{ 0 };
std::map< uint64_t, uint64_t > m_invites; std::map< uint64_t, uint64_t > m_invites;
uint64_t m_lastGroupId{ 0 }; uint64_t m_lastGroupId{ 0 };
@ -61,11 +62,10 @@ protected:
virtual uint64_t generateGroupId(); virtual uint64_t generateGroupId();
private: private:
std::map< uint64_t, GroupPtr > m_groups; std::map< uint64_t, T > m_groups;
}; };
} }
} }
};
#endif /* ! _GROUPMGR_H */ #endif /* ! _GROUPMGR_H */