This commit is contained in:
aozhiwei 2022-10-24 09:49:43 +08:00
parent 4ffe973386
commit 127b8a82b7
3 changed files with 103 additions and 1 deletions

View File

@ -0,0 +1,66 @@
#include "precompile.h"
#include <a8/timer.h>
#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<void (MatchTeam*, bool&)> func)
{
if (!func) {
return;
}
bool stop = false;
for (auto& pair : team_hash_) {
if (pair.second) {
func(pair.second, stop);
if (stop){
return;
}
}
}
}
std::tuple<std::string, MatchTeam*>* 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);
}
}

View File

@ -0,0 +1,36 @@
#pragma once
namespace cs
{
class CMJoin;
}
class MatchTeam;
class MatchPool : public a8::Singleton<MatchPool>
{
private:
MatchPool() {};
friend class a8::Singleton<MatchPool>;
public:
a8::TimerAttacher timer_attacher;
void Init();
void UnInit();
void _CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg);
private:
void TraverseTeam(std::function<void (MatchTeam*, bool&)> func);
bool NeedMatch(const cs::CMJoin& msg);
MatchTeam* GetTeam(const std::string& team_uuid);
std::tuple<std::string, MatchTeam*>* GetMatchInfo(int socket_handle);
void RemoveTeam(const std::string& team_uuid);
void RemoveSocket(int socket_handle);
private:
std::map<std::string, MatchTeam*> team_hash_;
std::map<int, std::tuple<std::string, MatchTeam*>> socket_hash_;
};

View File

@ -1,4 +1,4 @@
#pragma once #pragma once
#include "cs_proto.pb.h" #include "cs_proto.pb.h"