diff --git a/server/gameserver/player.cc b/server/gameserver/player.cc index 0bc3f5f..579bf99 100644 --- a/server/gameserver/player.cc +++ b/server/gameserver/player.cc @@ -909,6 +909,10 @@ void Player::ProcPrepareItems2(const ::google::protobuf::RepeatedPtrField< cs::M void Player::_CMReconnect(f8::MsgHdr& hdr, const cs::CMReconnect& msg) { + int old_socket_handle = socket_handle; + if (socket_handle != 0) { + PlayerMgr::Instance()->RemovePlayerBySocket(socket_handle); + } socket_handle = hdr.socket_handle; TouchAllLayerHumanList ( @@ -923,6 +927,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::_CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg) diff --git a/server/gameserver/playermgr.cc b/server/gameserver/playermgr.cc index 2db99ad..ae8dbd3 100644 --- a/server/gameserver/playermgr.cc +++ b/server/gameserver/playermgr.cc @@ -198,5 +198,4 @@ void PlayerMgr::DecAccountNum(const std::string& account_id) void PlayerMgr::ReBindSocket(Player* hum) { socket_hash_[hum->socket_handle] = hum; - IncAccountNum(hum->account_id); } diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index bbcd570..bbf48ac 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -769,7 +769,7 @@ bool Room::CanJoin(const std::string& accountid, void Room::OnPlayerOffline(Player* hum) { if (GetOnlinePlayerNum() <= 0) { - xtimer.AddDeadLineTimer + xtimer.AddDeadLineTimerAndAttach ( SERVER_FRAME_RATE * 40, a8::XParams() @@ -777,11 +777,12 @@ void Room::OnPlayerOffline(Player* hum) [] (const a8::XParams& param) { Room* room = (Room*)param.sender.GetUserData(); - if (room->GetOnlinePlayerNum() <= 0) { + if (room->GetOnlinePlayerNum() <= 0 && !room->added_to_over_room) { GameLog::Instance()->ForceOver(room); RoomMgr::Instance()->AddOverRoom(room->room_uuid_); } - }); + }, + &timer_attacher.timer_list_); } } diff --git a/server/gameserver/room.h b/server/gameserver/room.h index c7dcbec..db5ab31 100644 --- a/server/gameserver/room.h +++ b/server/gameserver/room.h @@ -43,6 +43,7 @@ public: GridService* grid_service = nullptr; MapService* map_service = nullptr; bool debug_trace = false; + bool added_to_over_room = false; ~Room(); void InitData(RoomInitInfo& init_info); diff --git a/server/gameserver/roommgr.cc b/server/gameserver/roommgr.cc index f6b65df..3b5a612 100644 --- a/server/gameserver/roommgr.cc +++ b/server/gameserver/roommgr.cc @@ -288,6 +288,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; a8::Timer::Instance()->AddRepeatTimerAndAttach (1000 * 5, a8::XParams()