添加组队校验

This commit is contained in:
aozhiwei 2020-08-31 15:12:31 +08:00
parent 5012b4117d
commit a1be31c98b
2 changed files with 94 additions and 1 deletions

View File

@ -175,6 +175,7 @@ void RoomMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg)
msg.account_id() msg.account_id()
}); });
} }
OnJoinRoomOk(msg, hum);
} }
void RoomMgr::_CMReconnect(f8::MsgHdr& hdr, const cs::CMReconnect& msg) void RoomMgr::_CMReconnect(f8::MsgHdr& hdr, const cs::CMReconnect& msg)
@ -544,3 +545,92 @@ bool RoomMgr::IsGM(const std::string& account_id)
{ {
return gm_hash_.find(account_id) != gm_hash_.end(); return gm_hash_.find(account_id) != gm_hash_.end();
} }
std::string RoomMgr::GenTeamHashData(const std::string& team_uuid, std::map<std::string, long long>* team_hash)
{
std::string data;
data += a8::Format("team_uuid:%s ", {team_uuid});
for (auto pair : *team_hash) {
data += a8::Format("%s->%d ", {pair.first, pair.second});
}
return data;
}
void RoomMgr::OnJoinRoomOk(const cs::CMJoin& msg, Player* hum)
{
if (msg.team_members().size() <= 1) {
return;
}
std::map<std::string, long long>* team_hash = nullptr;
{
auto itr = team_room_hash_.find(msg.team_uuid());
if (itr == team_room_hash_.end()) {
team_room_hash_[msg.team_uuid()] = std::map<std::string, long long>();
itr = team_room_hash_.find(msg.team_uuid());
team_hash = &itr->second;
for (auto& team_member : msg.team_members()) {
team_hash->insert(std::make_pair(team_member.account_id(), 0));
}
a8::Timer::Instance()->AddDeadLineTimer
(1000 * 60,
a8::XParams()
.SetSender(msg.team_uuid()),
[] (const a8::XParams& params)
{
RoomMgr::Instance()->TeamRoomTimeOut(params.sender);
}
);
} else {
team_hash = &itr->second;
}
}
if (!team_hash) {
abort();
}
{
auto itr = team_hash->find(hum->account_id);
if (itr != team_hash->end()) {
itr->second = hum->room->GetRoomUuid();
} else {
a8::UdpLog::Instance()->Warning
("team_data:%s account_id:%s not exists",
{
GenTeamHashData(msg.team_uuid(), team_hash),
hum->account_id
});
}
}
}
void RoomMgr::TeamRoomTimeOut(const std::string& team_uuid)
{
std::map<std::string, long long>* team_hash = nullptr;
{
auto itr = team_room_hash_.find(team_uuid);
if (itr != team_room_hash_.end()) {
team_hash = &itr->second;
}
}
if (team_hash) {
bool ok = true;
for (auto pair : *team_hash) {
if (pair.second == 0) {
ok = false;
break;
}
}
if (!ok) {
a8::UdpLog::Instance()->Warning
("team match failed team_data:%s ",
{
GenTeamHashData(team_uuid, team_hash),
});
}
} else {
a8::UdpLog::Instance()->Warning
("team not found team_uuid:s",
{
team_uuid
});
}
}

View File

@ -53,6 +53,9 @@ class RoomMgr : public a8::Singleton<RoomMgr>
int creator_proto_version, int creator_proto_version,
int creator_channel); int creator_channel);
void JoinErrorHandle(const cs::CMJoin& msg, int error_code, int socket_handle); void JoinErrorHandle(const cs::CMJoin& msg, int error_code, int socket_handle);
std::string GenTeamHashData(const std::string& team_uuid, std::map<std::string, long long>* team_hash);
void OnJoinRoomOk(const cs::CMJoin& msg, Player* hum);
void TeamRoomTimeOut(const std::string& team_uuid);
private: private:
int current_room_idx_ = 0; int current_room_idx_ = 0;
@ -63,5 +66,5 @@ class RoomMgr : public a8::Singleton<RoomMgr>
std::map<long long, Room*> over_room_hash_; std::map<long long, Room*> over_room_hash_;
a8::TimerAttacher reportstate_timer_attacher_; a8::TimerAttacher reportstate_timer_attacher_;
std::map<std::string, int> gm_hash_; std::map<std::string, int> gm_hash_;
std::map<std::string, int> team_hash_; std::map<std::string, std::map<std::string, long long>> team_room_hash_;
}; };