From f07f400287182b38b0704ba6f295db160b464d88 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 11 Aug 2020 16:25:36 +0800 Subject: [PATCH] 1 --- server/gameserver/player.cc | 12 ++++++++++++ server/gameserver/room.cc | 9 +++++---- server/gameserver/room.h | 1 + server/gameserver/roommgr.cc | 8 +++++++- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/server/gameserver/player.cc b/server/gameserver/player.cc index 6f9a327..7b408df 100644 --- a/server/gameserver/player.cc +++ b/server/gameserver/player.cc @@ -914,6 +914,11 @@ void Player::_CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg) void Player::_CMReconnect(f8::MsgHdr& hdr, const cs::CMReconnect& msg) { + int old_socket_handle = socket_handle; + if (socket_handle != 0) { + GGListener::Instance()->ForceCloseChildSocket(socket_handle); + PlayerMgr::Instance()->RemovePlayerBySocket(socket_handle); + } socket_handle = hdr.socket_handle; #if 0 TouchAllLayerHumanList @@ -930,6 +935,13 @@ void Player::_CMReconnect(f8::MsgHdr& hdr, const cs::CMReconnect& msg) respmsg.set_errmsg("战斗重连成功"); SendNotifyMsg(respmsg); PlayerMgr::Instance()->ReBindSocket(this); + a8::UdpLog::Instance()->Debug + ("战斗服重连成功 %s %d %d", + { + account_id, + hdr.socket_handle, + old_socket_handle + }); } void Player::UpdateDropWeapon() diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index f887042..959fdca 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -747,18 +747,19 @@ bool Room::CanJoin(const std::string& accountid) void Room::OnPlayerOffline(Player* hum) { if (GetOnlinePlayerNum() <= 0) { - xtimer.AddDeadLineTimer + xtimer.AddDeadLineTimerAndAttach ( - SERVER_FRAME_RATE * 40, + SERVER_FRAME_RATE * 15, a8::XParams() .SetSender(this), [] (const a8::XParams& param) { Room* room = (Room*)param.sender.GetUserData(); - if (room->GetOnlinePlayerNum() <= 0) { + if (room->GetOnlinePlayerNum() <= 0 && !room->added_to_over_room) { RoomMgr::Instance()->AddOverRoom(room->room_uuid); } - }); + }, + &xtimer_attacher.timer_list_); } } diff --git a/server/gameserver/room.h b/server/gameserver/room.h index 9030048..b18a422 100644 --- a/server/gameserver/room.h +++ b/server/gameserver/room.h @@ -49,6 +49,7 @@ public: long long pending_request = 0; long long last_debugout_tick = 0; a8::Vec2 last_player_jump_pos; + bool added_to_over_room = false; ~Room(); void Init(); diff --git a/server/gameserver/roommgr.cc b/server/gameserver/roommgr.cc index 6d4deb0..d5f471c 100644 --- a/server/gameserver/roommgr.cc +++ b/server/gameserver/roommgr.cc @@ -128,7 +128,7 @@ void RoomMgr::_CMReconnect(f8::MsgHdr& hdr, const cs::CMReconnect& msg) .SetSender(socket_handle), [] (const a8::XParams& param) { - GGListener::Instance()->ForceCloseClient(param.sender); + GGListener::Instance()->ForceCloseChildSocket(param.sender); } ); }; @@ -136,6 +136,11 @@ void RoomMgr::_CMReconnect(f8::MsgHdr& hdr, const cs::CMReconnect& msg) Room* room = GetRoomByUuid(a8::XValue(msg.room_uuid())); if (!room) { send_reconnect_failed(hdr.socket_handle, 1, "房间已销毁"); + a8::UdpLog::Instance()->Debug + ("房间已销毁 %s", + { + msg.room_uuid() + }); return; } Player* hum = room->GetPlayerByAccountId(msg.account_id()); @@ -190,6 +195,7 @@ void RoomMgr::AddOverRoom(long long room_uuid) inactive_room_hash_.erase(room_uuid); Room* room = GetRoomByUuid(room_uuid); if (room) { + room->added_to_over_room = true; room->game_over_tick = a8::XGetTickCount(); room->game_over_timer = a8::Timer::Instance()->AddRepeatTimer(500, a8::XParams()