1
This commit is contained in:
parent
4ffe973386
commit
127b8a82b7
66
server/gameserver/matchpool.cc
Normal file
66
server/gameserver/matchpool.cc
Normal 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);
|
||||
}
|
||||
}
|
36
server/gameserver/matchpool.h
Normal file
36
server/gameserver/matchpool.h
Normal 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_;
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user