diff --git a/server/gameserver/roommgr.cc b/server/gameserver/roommgr.cc index c51ab1a..e0d98d6 100644 --- a/server/gameserver/roommgr.cc +++ b/server/gameserver/roommgr.cc @@ -175,6 +175,7 @@ void RoomMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg) msg.account_id() }); } + OnJoinRoomOk(msg, hum); } 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(); } + +std::string RoomMgr::GenTeamHashData(const std::string& team_uuid, std::map* 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* 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(); + 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* 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 + }); + } +} diff --git a/server/gameserver/roommgr.h b/server/gameserver/roommgr.h index 2869345..0b7e339 100644 --- a/server/gameserver/roommgr.h +++ b/server/gameserver/roommgr.h @@ -53,6 +53,9 @@ class RoomMgr : public a8::Singleton int creator_proto_version, int creator_channel); void JoinErrorHandle(const cs::CMJoin& msg, int error_code, int socket_handle); + std::string GenTeamHashData(const std::string& team_uuid, std::map* team_hash); + void OnJoinRoomOk(const cs::CMJoin& msg, Player* hum); + void TeamRoomTimeOut(const std::string& team_uuid); private: int current_room_idx_ = 0; @@ -63,5 +66,5 @@ class RoomMgr : public a8::Singleton std::map over_room_hash_; a8::TimerAttacher reportstate_timer_attacher_; std::map gm_hash_; - std::map team_hash_; + std::map> team_room_hash_; };