From 0342dce056ff5ba70939223ef1a50cead52371e3 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 25 Mar 2024 21:23:58 +0800 Subject: [PATCH] 1 --- server/gameserver/custom_battle.cc | 60 ++++++++++++++++++++++++------ server/gameserver/custom_battle.h | 3 +- server/gameserver/roommgr.h | 18 ++++----- 3 files changed, 60 insertions(+), 21 deletions(-) diff --git a/server/gameserver/custom_battle.cc b/server/gameserver/custom_battle.cc index aea67a88..d062c524 100644 --- a/server/gameserver/custom_battle.cc +++ b/server/gameserver/custom_battle.cc @@ -319,17 +319,12 @@ void CustomBattle::OnEnter(std::shared_ptr join_msg, long ip_saddr, pair.second->is_ready_ = 1; OnMemberReady(pair.second.get()); } - if (GetRoom()) { - #if 0 - if (GetRoom()->GetGasData().GetGasMode() != GasInactive) { - return; - } - #endif - auto hum = GetRoom()->GetPlayerByAccountId(join_msg->account_id()); - if (hum) { - hum->ReJoin(ip_saddr, socket_handle, join_msg); - } - return; + } + if (state_ == 1) { + NotifyState(); + auto hum = GetRoom()->GetPlayerByAccountId(join_msg->account_id()); + if (hum) { + hum->ReJoin(ip_saddr, socket_handle, join_msg); } } } @@ -338,6 +333,49 @@ void CustomBattle::OnMemberReady(CustomMember* member) { if (state_ == 0 && AllIsReady()) { state_ = 1; + GameStart(); } NotifyState(); } + +void CustomBattle::GameStart() +{ + if (IsNormalMode()) { + auto room = RoomMgr::Instance()->GetJoinableRoom(shared_from_this()); + if (!room) { + int game_times = 0; + RoomType_e self_room_type = GetRoomType(); + //time_t register_time = f8::ExtractRegisterTimeFromSessionId(msg.session_id()); + //int proto_version = msg.proto_version(); + //int channel = f8::ExtractChannelIdFromAccountId(msg.account_id()); + time_t register_time = 0; + int proto_version = 0; + int channel = 0; + if (IsPvp()) { + room = RoomMgr::Instance()->CreateRoom + (self_room_type, + game_times, + register_time, + proto_version, + channel, + GetMapId(), + GetRoomMode(), + nullptr); + } else { + room = RoomMgr::Instance()->CreateRoom + (self_room_type, + game_times, + register_time, + proto_version, + channel, + GetMapId(), + GetRoomMode(), + nullptr); + } + } + SetRoom(room.get()); + //room->JoinWithCustomBattle(ip_saddr, socket_handle, join_msg, p); + } else { + abort(); + } +} diff --git a/server/gameserver/custom_battle.h b/server/gameserver/custom_battle.h index 673218e7..e1d0c459 100644 --- a/server/gameserver/custom_battle.h +++ b/server/gameserver/custom_battle.h @@ -7,7 +7,7 @@ class SocketDisconnectHandler; class Room; class CustomTeam; class CustomMember; -class CustomBattle +class CustomBattle : public std::enable_shared_from_this { public: @@ -53,6 +53,7 @@ private: void CalcTeam1AverageHeroLv(); void NotifyState(); + void GameStart(); private: bool parse_ok_ = false; diff --git a/server/gameserver/roommgr.h b/server/gameserver/roommgr.h index e55f37c0..bac1e59c 100644 --- a/server/gameserver/roommgr.h +++ b/server/gameserver/roommgr.h @@ -86,16 +86,7 @@ class RoomMgr : public a8::Singleton std::shared_ptr GetCustomMemberBySocket(int socket_handle); void ReBindCustomMemberSocket(std::shared_ptr p); void UnBindCustomMemberSocket(int socket_handle); - - private: - void InstallReportStateTimer(); - std::shared_ptr GetRoomByIdx(int room_idx); std::shared_ptr GetJoinableRoom(std::shared_ptr p); - void ReportServerState(int instance_id, const std::string& host, int port); - void FreeOverRoom(const std::string& room_uuid); - bool IsLimitJoin(); - - int AllocRoomIdx(); std::shared_ptr CreateRoom(RoomType_e room_type, int game_times, int creator_register_time, @@ -104,6 +95,15 @@ class RoomMgr : public a8::Singleton int map_id, RoomMode_e room_mode, std::shared_ptr custom_battle); + + private: + void InstallReportStateTimer(); + std::shared_ptr GetRoomByIdx(int room_idx); + void ReportServerState(int instance_id, const std::string& host, int port); + void FreeOverRoom(const std::string& room_uuid); + bool IsLimitJoin(); + + int AllocRoomIdx(); void JoinErrorHandle(const cs::CMJoin& msg, int error_code, int socket_handle); void AdjustCMJoin(cs::CMJoin* msg); std::shared_ptr GetCustomRoom(const std::string& room_uuid);