diff --git a/server/gameserver/human.cc b/server/gameserver/human.cc index 0ffbcec..00c894d 100644 --- a/server/gameserver/human.cc +++ b/server/gameserver/human.cc @@ -1867,9 +1867,10 @@ void Human::InternalSendGameOver() }; auto on_error = [] (a8::XParams& param, const std::string& response) { - a8::UdpLog::Instance()->Error("battleReport params: ", + a8::UdpLog::Instance()->Error("battleReport params: %s response: %s", { - param.param2 + param.param2, + response }); long long room_uuid = param.sender; int hum_uniid = param.param1; @@ -1901,7 +1902,7 @@ void Human::InternalSendGameOver() f8::HttpClientPool::Instance()->HttpGet( a8::XParams() .SetSender(room->room_uuid) - .SetParam1(entity_uniid), + .SetParam1(entity_uniid) .SetParam2(data), on_ok, on_error, diff --git a/server/gameserver/playermgr.cc b/server/gameserver/playermgr.cc index 197fee3..720dbc5 100644 --- a/server/gameserver/playermgr.cc +++ b/server/gameserver/playermgr.cc @@ -3,6 +3,7 @@ #include "playermgr.h" #include "player.h" #include "cs_proto.pb.h" +#include "room.h" void PlayerMgr::Init() { @@ -14,10 +15,10 @@ void PlayerMgr::UnInit() void PlayerMgr::_SS_WSP_SocketDisconnect(f8::MsgHdr& hdr, const ss::SS_WSP_SocketDisconnect& msg) { - auto itr = socket_hash_.find(hdr.socket_handle); - if (itr != socket_hash_.end()) { - itr->second->socket_handle = 0; - socket_hash_.erase(itr); + Player* hum = GetPlayerBySocket(hdr.socket_handle); + if (hum) { + RemovePlayerBySocket(hdr.socket_handle); + hum->room->OnPlayerOffline(hum); } } @@ -78,11 +79,19 @@ void PlayerMgr::OnClientDisconnect(a8::XParams& param) } } for (int socket_handle : socket_list) { - socket_hash_.erase(socket_handle); + Player* hum = GetPlayerBySocket(socket_handle); + if (hum) { + RemovePlayerBySocket(socket_handle); + hum->room->OnPlayerOffline(hum); + } } } void PlayerMgr::RemovePlayerBySocket(int socket_handle) { - socket_hash_.erase(socket_handle); + auto itr = socket_hash_.find(socket_handle); + if (itr != socket_hash_.end()) { + itr->second->socket_handle = 0; + socket_hash_.erase(itr); + } } diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index 0c930f6..c7ff655 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -713,6 +713,19 @@ bool Room::CanJoin(const std::string& accountid) } } +void Room::OnPlayerOffline(Player* hum) +{ + bool has_player = false; + for (auto& pair : accountid_hash_) { + if (pair.second->socket_handle != 0) { + has_player = true; + } + } + if (!has_player) { + RoomMgr::Instance()->AddOverRoom(room_uuid); + } +} + std::set* Room::GetAliveTeam() { for (auto& pair : team_hash_) { diff --git a/server/gameserver/room.h b/server/gameserver/room.h index 11002d3..e9955c8 100644 --- a/server/gameserver/room.h +++ b/server/gameserver/room.h @@ -88,6 +88,7 @@ public: int GetAliveTeamNum(); std::set* GetAliveTeam(); bool CanJoin(const std::string& accountid); + void OnPlayerOffline(Player* hum); private: unsigned short AllocUniid();