diff --git a/server/gameserver/app.cc b/server/gameserver/app.cc index b3d9a56..8e38614 100755 --- a/server/gameserver/app.cc +++ b/server/gameserver/app.cc @@ -59,7 +59,7 @@ static void SavePerfLog() RoomMgr::Instance()->RoomNum() }); if (App::Instance()->HasFlag(4)) { - a8::XPrintf("max_mainloop_rundelay:%d max_dispatchmsg_time:%d room_num:%d online_num:%d\n", + a8::XPrintf("mainloop_time:%d netmsg_time:%d room:%d online:%d\n", { App::Instance()->perf.max_run_delay_time, App::Instance()->perf.max_dispatchmsg_time, diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index 3eb9fad..f341c9e 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -1147,6 +1147,7 @@ void Room::OnGameOver() pair.second->SendGameOver(); } } + RoomMgr::Instance()->AddOverRoom(room_uuid); } void Room::RandRemoveAndroid() diff --git a/server/gameserver/roommgr.cc b/server/gameserver/roommgr.cc index fdae389..7d73527 100644 --- a/server/gameserver/roommgr.cc +++ b/server/gameserver/roommgr.cc @@ -131,11 +131,6 @@ int RoomMgr::RoomNum() return room_hash_.size(); } -int RoomMgr::ActiveRoomNum() -{ - return room_hash_.size() - over_room_hash_.size(); -} - Room* RoomMgr::GetJoinableRoom(const std::string& account_id) { for (auto& pair : inactive_room_hash_) { @@ -146,12 +141,27 @@ Room* RoomMgr::GetJoinableRoom(const std::string& account_id) return nullptr; } -Room* RoomMgr::GetRoomByUuid(long long uuid) +Room* RoomMgr::GetRoomByUuid(long long room_uuid) { - auto itr = room_hash_.find(uuid); + auto itr = room_hash_.find(room_uuid); return itr != room_hash_.end() ? itr->second : nullptr; } +void RoomMgr::AddOverRoom(long long room_uuid) +{ + a8::Timer::Instance()->AddDeadLineTimer(1000, + a8::XParams() + .SetSender(room_uuid), + [] (const a8::XParams& param) + { + Room* room = RoomMgr::Instance()->GetRoomByUuid(param.sender); + if (room) { + RoomMgr::Instance()->room_hash_.erase(room->room_uuid); + RoomMgr::Instance()->over_room_hash_[room->room_uuid] = room; + } + }); +} + void RoomMgr::RemoveFromInactiveRoomHash(long long room_uuid) { inactive_room_hash_.erase(room_uuid); @@ -169,7 +179,7 @@ void RoomMgr::ReportServerState(int instance_id, const std::string& host, int po url_params->SetVal("ip", JsonDataMgr::Instance()->ip); url_params->SetVal("port", JsonDataMgr::Instance()->listen_port); url_params->SetVal("online_num", PlayerMgr::Instance()->OnlineNum()); - url_params->SetVal("room_num", ActiveRoomNum()); + url_params->SetVal("room_num", RoomNum()); f8::HttpClientPool::Instance()->HttpGet(a8::XParams() .SetSender(instance_id) .SetParam1(host) diff --git a/server/gameserver/roommgr.h b/server/gameserver/roommgr.h index aa5603c..ae16cb8 100644 --- a/server/gameserver/roommgr.h +++ b/server/gameserver/roommgr.h @@ -23,8 +23,8 @@ class RoomMgr : public a8::Singleton void _CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg); void RemoveFromInactiveRoomHash(long long room_uuid); int RoomNum(); - int ActiveRoomNum(); Room* GetRoomByUuid(long long uuid); + void AddOverRoom(long long room_uuid); private: Room* GetJoinableRoom(const std::string& account_id);