This commit is contained in:
aozhiwei 2021-09-27 09:19:27 +00:00
parent f10b913092
commit 19aaa6cd42
3 changed files with 47 additions and 3 deletions

View File

@ -33,4 +33,5 @@ public:
private: private:
std::map<std::string, MatchTeam*> team_hash_; std::map<std::string, MatchTeam*> team_hash_;
std::map<int, std::string> socket_hash_;
}; };

View File

@ -8,12 +8,21 @@
struct RawTeamMember struct RawTeamMember
{ {
MatchTeam* team = nullptr;
long long add_tick = 0;
int socket_handle = 0; int socket_handle = 0;
std::shared_ptr<cs::CMJoin> msg; cs::CMJoin msg;
void FillMFMatchTeamMember(cs::MFMatchTeamMember* msg)
{
}
}; };
void MatchTeam::Init(f8::MsgHdr& hdr, const cs::CMJoin& msg) void MatchTeam::Init(f8::MsgHdr& hdr, const cs::CMJoin& msg)
{ {
master_team_ = this;
create_tick_ = a8::XGetTickCount(); create_tick_ = a8::XGetTickCount();
a8::Timer::Instance()->AddRepeatTimerAndAttach a8::Timer::Instance()->AddRepeatTimerAndAttach
(1000, (1000,
@ -25,11 +34,20 @@ void MatchTeam::Init(f8::MsgHdr& hdr, const cs::CMJoin& msg)
team->Update(); team->Update();
}, },
&timer_attacher.timer_list_); &timer_attacher.timer_list_);
AddRawMember(hdr, msg);
} }
void MatchTeam::AddRawMember(f8::MsgHdr& hdr, const cs::CMJoin& msg) void MatchTeam::AddRawMember(f8::MsgHdr& hdr, const cs::CMJoin& msg)
{ {
std::shared_ptr<RawTeamMember> member = std::make_shared<RawTeamMember>();
member->team = this;
member->add_tick = a8::XGetTickCount();
member->socket_handle = hdr.socket_handle;
member->msg = msg;
raw_member_hash_[msg.account_id()] = member;
if (!first_member_) {
first_member_ = member;
}
} }
bool MatchTeam::IsRawMember(const std::string &account_id) bool MatchTeam::IsRawMember(const std::string &account_id)
@ -45,5 +63,15 @@ bool MatchTeam::IsValidMember(const cs::CMJoin& msg)
void MatchTeam::Update() void MatchTeam::Update()
{ {
master_team_->SyncMatchInfo();
}
void MatchTeam::SyncMatchInfo()
{
cs::SMUpdateMatchInfo notifymsg;
for (auto member : curr_member_hash_) {
member->FillMFMatchTeamMember(notifymsg.mutable_info()->add_members());
}
notifymsg.mutable_info()->set_phase(phase_);
notifymsg.mutable_info()->set_countdown(countdown_);
} }

View File

@ -1,5 +1,12 @@
#pragma once #pragma once
enum MatchTeamPhase_e
{
kMatchCombining = 1,
kMatchChoose = 2,
kMatchLock = 3
};
namespace cs namespace cs
{ {
class CMJoin; class CMJoin;
@ -20,9 +27,17 @@ class MatchTeam
private: private:
void Update(); void Update();
void SyncMatchInfo();
private: private:
int phase_= kMatchCombining;
int countdown_ = 0;
long long create_tick_ = 0; long long create_tick_ = 0;
std::map<std::string, std::shared_ptr<RawTeamMember>> raw_member_hash_; std::map<std::string, std::shared_ptr<RawTeamMember>> raw_member_hash_;
std::shared_ptr<RawTeamMember> first_member_; std::shared_ptr<RawTeamMember> first_member_;
std::map<std::string, MatchTeam*> combined_team_hash_;
MatchTeam* master_team_ = nullptr;
std::list<std::shared_ptr<RawTeamMember>> curr_member_hash_;
}; };