diff --git a/server/gameserver/roommgr.cc b/server/gameserver/roommgr.cc index dd92572..8d8f177 100644 --- a/server/gameserver/roommgr.cc +++ b/server/gameserver/roommgr.cc @@ -103,40 +103,20 @@ void RoomMgr::Update(int delta_time) void RoomMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg) { - RoomType_e self_room_type = GetHumanRoomType(msg); if (IsLimitJoin()) { - { - cs::SMJoinedNotify notifymsg; - notifymsg.set_error_code(2); - GGListener::Instance()->SendToClient(hdr.socket_handle, hdr.seqid, notifymsg); - } - { - a8::Timer::Instance()-> - AddDeadLineTimer(1000 * 2, - a8::XParams() - .SetSender(hdr.socket_handle), - [] (const a8::XParams& param) - { - GGListener::Instance()->ForceCloseChildSocket(param.sender); - }); - } - a8::UdpLog::Instance()->Warning("room is full! accountid:%s max_mainloop_rundelay:%d " - "room_num:%d player_num:%d online_num:%d", - { - msg.account_id(), - App::Instance()->perf.max_run_delay_time, - RoomMgr::Instance()->RoomNum(), - App::Instance()->perf.entity_num[ET_Player], - PlayerMgr::Instance()->OnlineNum(), - }); - return; + JoinErrorHandle(msg, 2, hdr.socket_handle); + return; } + RoomType_e self_room_type = GetHumanRoomType(msg); Room* room = GetJoinableRoom(msg, self_room_type); if (!room) { + JoinErrorHandle(msg, 3, hdr.socket_handle); + return; } - Player* hum = PlayerMgr::Instance()->CreatePlayerByCMJoin(hdr.ip_saddr, - hdr.socket_handle, - msg); + Player* hum = PlayerMgr::Instance()-> + CreatePlayerByCMJoin(hdr.ip_saddr, + hdr.socket_handle, + msg); hum->meta = hum_meta_; hum->ProcPrepareItems(msg.prepare_items()); hum->ProcPrepareItems2(msg.prepare_items2()); @@ -498,7 +478,7 @@ int RoomMgr::AllocRoomIdx() Room* RoomMgr::CreateRoom(RoomType_e room_type) { int room_idx = AllocRoomIdx(); - if (room_idx == -1) { + if (room_idx < 1) { return nullptr; } Room* room = new Room(); @@ -523,3 +503,32 @@ Room* RoomMgr::CreateRoom(RoomType_e room_type) room_idx_hash_[room->room_idx] = room; return room; } + +void RoomMgr::JoinErrorHandle(const cs::CMJoin& msg, int error_code, int socket_handle) +{ + { + cs::SMJoinedNotify notifymsg; + notifymsg.set_error_code(error_code); + GGListener::Instance()->SendToClient(socket_handle, 0, notifymsg); + } + { + a8::Timer::Instance()-> + AddDeadLineTimer(1000 * 2, + a8::XParams() + .SetSender(socket_handle), + [] (const a8::XParams& param) + { + GGListener::Instance()->ForceCloseChildSocket(param.sender); + }); + } + a8::UdpLog::Instance()->Warning("join error errcode:%d accountid:%s max_mainloop_rundelay:%d " + "room_num:%d player_num:%d online_num:%d", + { + error_code, + msg.account_id(), + App::Instance()->perf.max_run_delay_time, + RoomMgr::Instance()->RoomNum(), + App::Instance()->perf.entity_num[ET_Player], + PlayerMgr::Instance()->OnlineNum(), + }); +} diff --git a/server/gameserver/roommgr.h b/server/gameserver/roommgr.h index 9cc0427..1011f9c 100644 --- a/server/gameserver/roommgr.h +++ b/server/gameserver/roommgr.h @@ -63,6 +63,7 @@ class RoomMgr : public a8::Singleton int AllocUniid(); int AllocRoomIdx(); Room* CreateRoom(RoomType_e room_type); + void JoinErrorHandle(const cs::CMJoin& msg, int error_code, int socket_handle); private: std::map inactive_room_hash_;