1
This commit is contained in:
parent
19aaa6cd42
commit
ca79b13b23
@ -58,7 +58,7 @@ bool MatchMgr::NeedMatch(const cs::CMJoin& msg)
|
||||
msg.team_mode() == 1 &&
|
||||
msg.auto_fill() &&
|
||||
msg.team_members().size() > 0 &&
|
||||
msg.team_members().size() < 4;
|
||||
msg.team_members().size() < MAX_TEAM_NUM;
|
||||
if (need) {
|
||||
MatchTeam* team = GetTeam(msg.team_uuid());
|
||||
if (team && !team->IsValidMember(msg)) {
|
||||
@ -73,3 +73,19 @@ MatchTeam* MatchMgr::GetTeam(const std::string& team_uuid)
|
||||
auto itr = team_hash_.find(team_uuid);
|
||||
return itr != team_hash_.end() ? itr->second : nullptr;
|
||||
}
|
||||
|
||||
void MatchMgr::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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ public:
|
||||
void _CMMatchCancel(f8::MsgHdr& hdr, const cs::CMMatchCancel& msg);
|
||||
void _CMMatchChoose(f8::MsgHdr& hdr, const cs::CMMatchChoose& msg);
|
||||
void _CMMatchStartGame(f8::MsgHdr& hdr, const cs::CMMatchStartGame& msg);
|
||||
void TraverseTeam(std::function<void (MatchTeam*, bool&)> func);
|
||||
|
||||
bool NeedMatch(const cs::CMJoin& msg);
|
||||
MatchTeam* GetTeam(const std::string& team_uuid);
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "cs_proto.pb.h"
|
||||
#include "matchteam.h"
|
||||
#include "matchmgr.h"
|
||||
#include "GGListener.h"
|
||||
|
||||
struct RawTeamMember
|
||||
{
|
||||
@ -63,6 +64,11 @@ bool MatchTeam::IsValidMember(const cs::CMJoin& msg)
|
||||
|
||||
void MatchTeam::Update()
|
||||
{
|
||||
if (master_team_ == this) {
|
||||
UpdateMaster();
|
||||
} else {
|
||||
UpdateSlave();
|
||||
}
|
||||
master_team_->SyncMatchInfo();
|
||||
}
|
||||
|
||||
@ -74,4 +80,82 @@ void MatchTeam::SyncMatchInfo()
|
||||
}
|
||||
notifymsg.mutable_info()->set_phase(phase_);
|
||||
notifymsg.mutable_info()->set_countdown(countdown_);
|
||||
for (auto& member : curr_member_hash_) {
|
||||
if (member->socket_handle != 0) {
|
||||
GGListener::Instance()->SendToClient(member->socket_handle, 0, notifymsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MatchTeam::TryCombineTeam()
|
||||
{
|
||||
MatchTeam* matched_team = nullptr;
|
||||
MatchMgr::Instance()->TraverseTeam
|
||||
(
|
||||
[this, &matched_team] (MatchTeam* team, bool& stop)
|
||||
{
|
||||
if (team == this) {
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void MatchTeam::UpdateMaster()
|
||||
{
|
||||
switch (phase_) {
|
||||
case kMatchCombining:
|
||||
{
|
||||
if (GetPredictMemberNum() < MAX_TEAM_NUM) {
|
||||
TryCombineTeam();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case kMatchChoose:
|
||||
{
|
||||
|
||||
}
|
||||
break;
|
||||
case kMatchLock:
|
||||
{
|
||||
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void MatchTeam::UpdateSlave()
|
||||
{
|
||||
switch (phase_) {
|
||||
case kMatchCombining:
|
||||
{
|
||||
}
|
||||
break;
|
||||
case kMatchChoose:
|
||||
{
|
||||
|
||||
}
|
||||
break;
|
||||
case kMatchLock:
|
||||
{
|
||||
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int MatchTeam::GetPredictMemberNum()
|
||||
{
|
||||
int num = GetRawMemberNum();
|
||||
for (auto& pair : combined_team_hash_) {
|
||||
num += pair.second->GetRawMemberNum();
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
@ -27,7 +27,12 @@ class MatchTeam
|
||||
|
||||
private:
|
||||
void Update();
|
||||
void UpdateMaster();
|
||||
void UpdateSlave();
|
||||
void SyncMatchInfo();
|
||||
void TryCombineTeam();
|
||||
int GetPredictMemberNum();
|
||||
int GetRawMemberNum() { return raw_member_hash_.size(); };
|
||||
|
||||
private:
|
||||
int phase_= kMatchCombining;
|
||||
|
Loading…
x
Reference in New Issue
Block a user