diff --git a/server/gameserver/matchpool.cc b/server/gameserver/matchpool.cc new file mode 100644 index 00000000..90738318 --- /dev/null +++ b/server/gameserver/matchpool.cc @@ -0,0 +1,66 @@ +#include "precompile.h" + +#include + +#include "cs_proto.pb.h" +#include "matchpool.h" +#include "GGListener.h" +#include "matchteam.h" + +void MatchPool::Init() +{ +} + +void MatchPool::UnInit() +{ + +} + +void MatchPool::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg) +{ +} + +MatchTeam* MatchPool::GetTeam(const std::string& team_uuid) +{ + auto itr = team_hash_.find(team_uuid); + return itr != team_hash_.end() ? itr->second : nullptr; +} + +void MatchPool::TraverseTeam(std::function func) +{ + if (!func) { + return; + } + bool stop = false; + for (auto& pair : team_hash_) { + if (pair.second) { + func(pair.second, stop); + if (stop){ + return; + } + } + } +} + +std::tuple* MatchPool::GetMatchInfo(int socket_handle) +{ + auto itr = socket_hash_.find(socket_handle); + return itr != socket_hash_.end() ? &itr->second : nullptr; +} + +void MatchPool::RemoveTeam(const std::string& team_uuid) +{ + auto itr = team_hash_.find(team_uuid); + if (itr != team_hash_.end()) { + delete itr->second; + team_hash_.erase(itr); + } +} + +void MatchPool::RemoveSocket(int socket_handle) +{ + auto itr = socket_hash_.find(socket_handle); + if (itr != socket_hash_.end()) { + socket_hash_.erase(itr); + } +} diff --git a/server/gameserver/matchpool.h b/server/gameserver/matchpool.h new file mode 100644 index 00000000..ae7c5a74 --- /dev/null +++ b/server/gameserver/matchpool.h @@ -0,0 +1,36 @@ +#pragma once + +namespace cs +{ + class CMJoin; +} + +class MatchTeam; +class MatchPool : public a8::Singleton +{ + private: + MatchPool() {}; + friend class a8::Singleton; + +public: + a8::TimerAttacher timer_attacher; + + void Init(); + void UnInit(); + + void _CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg); + +private: + + void TraverseTeam(std::function func); + + bool NeedMatch(const cs::CMJoin& msg); + MatchTeam* GetTeam(const std::string& team_uuid); + std::tuple* GetMatchInfo(int socket_handle); + void RemoveTeam(const std::string& team_uuid); + void RemoveSocket(int socket_handle); + +private: + std::map team_hash_; + std::map> socket_hash_; +}; diff --git a/server/gameserver/matchteam.h b/server/gameserver/matchteam.h index 46665f21..1a2537cd 100644 --- a/server/gameserver/matchteam.h +++ b/server/gameserver/matchteam.h @@ -1,4 +1,4 @@ - #pragma once +#pragma once #include "cs_proto.pb.h"