From 4b91640ad91769ed117178324abf5873d2d69cec Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sat, 16 Mar 2024 14:13:53 +0800 Subject: [PATCH 01/14] 1 --- server/gameserver/custom_battle.cc | 12 ------------ server/gameserver/custom_battle.h | 1 - 2 files changed, 13 deletions(-) diff --git a/server/gameserver/custom_battle.cc b/server/gameserver/custom_battle.cc index fdb95028..42aaaa22 100644 --- a/server/gameserver/custom_battle.cc +++ b/server/gameserver/custom_battle.cc @@ -136,18 +136,6 @@ void CustomBattle::ParseResult(a8::XObject& obj) parse_ok_ = true; } -bool CustomBattle::CanAdd(const std::string& account_id, const std::string& session_id) -{ - auto member = GetMemberByAccountId(account_id); - if (!member) { - return false; - } - if (member->IsJoined()) { - return false; - } - return true; -} - std::shared_ptr CustomBattle::GetMemberByAccountId(const std::string& account_id) { auto itr = member_id_hash_.find(account_id); diff --git a/server/gameserver/custom_battle.h b/server/gameserver/custom_battle.h index 1679e80e..777648a1 100644 --- a/server/gameserver/custom_battle.h +++ b/server/gameserver/custom_battle.h @@ -25,7 +25,6 @@ class CustomBattle int GetNodeId() { return zone_id_; } int GetStartTime() { return start_time_; } void ParseResult(a8::XObject& obj); - bool CanAdd(const std::string& account_id, const std::string& session_id); std::shared_ptr GetTeamByAccountId(const std::string& account_id); std::shared_ptr GetMemberByAccountId(const std::string& account_id); std::shared_ptr GetTeamByTeamUuid(const std::string& team_uuid); From 0a50e4ae91c915add43ef7c78df13bb2e825b921 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sun, 17 Mar 2024 10:32:18 +0800 Subject: [PATCH 02/14] 1 --- server/gameserver/custom_battle.h | 14 ++++++++------ server/gameserver/roommgr.cc | 21 ++++++++------------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/server/gameserver/custom_battle.h b/server/gameserver/custom_battle.h index 777648a1..2dd00de7 100644 --- a/server/gameserver/custom_battle.h +++ b/server/gameserver/custom_battle.h @@ -1,8 +1,7 @@ #pragma once -const int CUSTOM_ROOM_PVP = 0; -const int CUSTOM_ROOM_MOBA = 1; -const int CUSTOM_ROOM_NORMAL = 2; +const int CUSTOM_ROOM_CUSTOM = 0; +const int CUSTOM_ROOM_NORMAL = 1; class Room; class CustomTeam; @@ -36,13 +35,16 @@ class CustomBattle void TraverseTeamList(std::function)> cb); void TraverseObList(std::function)> cb); void SetCustomRoomType(int custom_room_type) { custom_room_type_ = custom_room_type; } - bool IsPvp() { return custom_room_type_ == CUSTOM_ROOM_PVP; } - bool IsMoba() { return custom_room_type_ == CUSTOM_ROOM_MOBA; } + bool IsNormalMode() { return custom_room_type_ == CUSTOM_ROOM_NORMAL; } + bool IsCustomMode() { return custom_room_type_ == CUSTOM_ROOM_CUSTOM; } + bool IsPvp() { return !is_moba_; } + bool IsMoba() { return is_moba_; } private: bool parse_ok_ = false; Room *room_ = nullptr; - int custom_room_type_ = CUSTOM_ROOM_PVP; + int custom_room_type_ = CUSTOM_ROOM_CUSTOM; + bool is_moba_ = false; std::string room_id_; std::string room_uuid_; int zone_id_ = 0; diff --git a/server/gameserver/roommgr.cc b/server/gameserver/roommgr.cc index ef6b9ef0..4b9342c6 100644 --- a/server/gameserver/roommgr.cc +++ b/server/gameserver/roommgr.cc @@ -1084,11 +1084,11 @@ void RoomMgr::SendGetCustomBattleData(std::shared_ptr join_msg, { std::string url; JsonDataMgr::Instance()->GetApiUrl(url); - if (custom_room_type == CUSTOM_ROOM_MOBA) { + if (custom_room_type == CUSTOM_ROOM_CUSTOM) { if (url.find('?') != std::string::npos) { - url += "&c=Battle&a=getMobaBattleData"; + url += "&c=Battle&a=getCustomBattleDataNew"; } else { - url += "?&c=Battle&a=getMobaBattleData"; + url += "?&c=Battle&a=getCustomBattleDataNew"; } } else if (custom_room_type == CUSTOM_ROOM_NORMAL) { if (url.find('?') != std::string::npos) { @@ -1096,13 +1096,8 @@ void RoomMgr::SendGetCustomBattleData(std::shared_ptr join_msg, } else { url += "?&c=Battle&a=getNormalBattleData"; } - } else { - if (url.find('?') != std::string::npos) { - url += "&c=Battle&a=getCustomBattleData"; - } else { - url += "?&c=Battle&a=getCustomBattleData"; - } + A8_ABORT(); } auto url_params = a8::MutableXObject::CreateObject(); url_params->SetVal("account_id", join_msg->account_id()); @@ -1183,14 +1178,14 @@ void RoomMgr::DispatchSpecRoom(f8::MsgHdr* hdr, const cs::CMJoin& msg) a8::Split(head, strings, ':'); if (strings.size() > 1) { if (strings.at(1) == "custom_room") { - _CMJoinCustomBattle(hdr, msg, CUSTOM_ROOM_PVP); + _CMJoinCustomBattle(hdr, msg, CUSTOM_ROOM_CUSTOM); } else if (strings.at(1) == "normal_room") { _CMJoinCustomBattle(hdr, msg, CUSTOM_ROOM_NORMAL); - } else if (strings.at(1) == "moba_room") { - _CMJoinCustomBattle(hdr, msg, CUSTOM_ROOM_MOBA); + } else { + A8_ABORT(); } } else { - _CMJoinCustomBattle(hdr, msg, CUSTOM_ROOM_PVP); + A8_ABORT(); } } From 45b58339cbf4c06008bd9909e35ad5f9c8c88733 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sun, 17 Mar 2024 10:52:10 +0800 Subject: [PATCH 03/14] 1 --- server/gameserver/roommgr.cc | 56 ++++++++++++++++++++++-------------- server/gameserver/roommgr.h | 6 ++++ 2 files changed, 41 insertions(+), 21 deletions(-) diff --git a/server/gameserver/roommgr.cc b/server/gameserver/roommgr.cc index 4b9342c6..a865312c 100644 --- a/server/gameserver/roommgr.cc +++ b/server/gameserver/roommgr.cc @@ -334,6 +334,16 @@ std::shared_ptr RoomMgr::GetJoinableRoom(const cs::CMJoin& msg, nullptr); } +std::shared_ptr RoomMgr::GetJoinableRoom(std::shared_ptr custom_battle, + const RoomType_e self_room_type, + int game_times, + int creator_register_time, + int proto_version, + int channel) +{ + return nullptr; +} + std::shared_ptr RoomMgr::GetRoomByUuid(const std::string& room_uuid) { auto itr = room_hash_.find(room_uuid); @@ -1015,29 +1025,33 @@ void RoomMgr::_CMJoinCustomBattle(f8::MsgHdr* hdr, const cs::CMJoin& msg, int cu int proto_version = msg.proto_version(); int channel = f8::ExtractChannelIdFromAccountId(msg.account_id()); std::shared_ptr room = nullptr; - if (p->IsPvp()) { - room = RoomMgr::Instance()->CreateRoom - (*join_msg, - self_room_type, - game_times, - register_time, - join_msg->proto_version(), - channel, - msg.mapid(), - p); + if (p->IsNormalMode()) { + } else { - room = RoomMgr::Instance()->CreateRoom - (*join_msg, - self_room_type, - game_times, - register_time, - join_msg->proto_version(), - channel, - msg.mapid(), - nullptr); + if (p->IsPvp()) { + room = RoomMgr::Instance()->CreateRoom + (*join_msg, + self_room_type, + game_times, + register_time, + join_msg->proto_version(), + channel, + msg.mapid(), + p); + } else { + room = RoomMgr::Instance()->CreateRoom + (*join_msg, + self_room_type, + game_times, + register_time, + join_msg->proto_version(), + channel, + msg.mapid(), + nullptr); + } + p->SetRoom(room.get()); + room->InitWithCustomBattle(ip_saddr, socket_handle, join_msg, p); } - p->SetRoom(room.get()); - room->InitWithCustomBattle(ip_saddr, socket_handle, join_msg, p); }; SendGetCustomBattleData(join_msg, cb, custom_room_type); } diff --git a/server/gameserver/roommgr.h b/server/gameserver/roommgr.h index 96964850..12cfa015 100644 --- a/server/gameserver/roommgr.h +++ b/server/gameserver/roommgr.h @@ -96,6 +96,12 @@ class RoomMgr : public a8::Singleton int creator_register_time, int proto_version, int channel); + std::shared_ptr GetJoinableRoom(std::shared_ptr custom_battle, + const RoomType_e self_room_type, + int game_times, + int creator_register_time, + int proto_version, + int channel); void ReportServerState(int instance_id, const std::string& host, int port); void FreeOverRoom(const std::string& room_uuid); bool IsLimitJoin(); From 312de4a951476d4f65c35897e27dcf7b228d4a9b Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 18 Mar 2024 17:42:15 +0800 Subject: [PATCH 04/14] 1 --- server/gameserver/custom_battle.h | 2 ++ server/gameserver/pbutils.cc | 6 ++++++ server/gameserver/room.h | 2 ++ server/gameserver/roommgr.cc | 11 ++++++++++- 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/server/gameserver/custom_battle.h b/server/gameserver/custom_battle.h index 2dd00de7..9987f538 100644 --- a/server/gameserver/custom_battle.h +++ b/server/gameserver/custom_battle.h @@ -22,6 +22,7 @@ class CustomBattle const std::shared_ptr& GetRawData() { return raw_data_; } int GetZoneId() { return zone_id_; } int GetNodeId() { return zone_id_; } + int GetMapId() { return map_id_; } int GetStartTime() { return start_time_; } void ParseResult(a8::XObject& obj); std::shared_ptr GetTeamByAccountId(const std::string& account_id); @@ -49,6 +50,7 @@ class CustomBattle std::string room_uuid_; int zone_id_ = 0; int node_id_ = 0; + int map_id_ = 0; int start_time_ = 0; std::string sign_; std::shared_ptr raw_data_; diff --git a/server/gameserver/pbutils.cc b/server/gameserver/pbutils.cc index c70b53bd..db86551c 100644 --- a/server/gameserver/pbutils.cc +++ b/server/gameserver/pbutils.cc @@ -2669,6 +2669,12 @@ int Room::InitWithCustomBattle(long ip_saddr, int socket_handle, std::shared_ptr return 0; } +int Room::JoinWithCustomBattle(long ip_saddr, int socket_handle, std::shared_ptr msg, + std::shared_ptr p) +{ + return 0; +} + void SyncObject::FillSMSyncPosition(cs::SMSyncPosition& sync_msg) { if (!c.Get()) { diff --git a/server/gameserver/room.h b/server/gameserver/room.h index 04d27ced..8944392a 100644 --- a/server/gameserver/room.h +++ b/server/gameserver/room.h @@ -282,6 +282,8 @@ public: int GenShotUniid() { return ++current_shot_uniid_; } int InitWithCustomBattle(long ip_saddr, int socket_handle, std::shared_ptr msg, std::shared_ptr p); + int JoinWithCustomBattle(long ip_saddr, int socket_handle, std::shared_ptr msg, + std::shared_ptr p); void CreateAndroid(int android_num, std::shared_ptr team = nullptr); int GetFullLevelIdx() { return ++curr_full_level_idx_;} std::shared_ptr GetRoomOb(); diff --git a/server/gameserver/roommgr.cc b/server/gameserver/roommgr.cc index a865312c..ee0a448b 100644 --- a/server/gameserver/roommgr.cc +++ b/server/gameserver/roommgr.cc @@ -1026,7 +1026,16 @@ void RoomMgr::_CMJoinCustomBattle(f8::MsgHdr* hdr, const cs::CMJoin& msg, int cu int channel = f8::ExtractChannelIdFromAccountId(msg.account_id()); std::shared_ptr room = nullptr; if (p->IsNormalMode()) { - + room = RoomMgr::Instance()->GetJoinableRoom(p, + self_room_type, + game_times, + register_time, + proto_version, + channel + ); + if (!room) { + } + room->JoinWithCustomBattle(ip_saddr, socket_handle, join_msg, p); } else { if (p->IsPvp()) { room = RoomMgr::Instance()->CreateRoom From e26fa22fac81f06e21f86f9ba5b542181f7dd44b Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 18 Mar 2024 18:01:53 +0800 Subject: [PATCH 05/14] 1 --- server/gameserver/roommgr.cc | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/server/gameserver/roommgr.cc b/server/gameserver/roommgr.cc index ee0a448b..e11bb411 100644 --- a/server/gameserver/roommgr.cc +++ b/server/gameserver/roommgr.cc @@ -1034,7 +1034,29 @@ void RoomMgr::_CMJoinCustomBattle(f8::MsgHdr* hdr, const cs::CMJoin& msg, int cu channel ); if (!room) { + if (p->IsPvp()) { + room = RoomMgr::Instance()->CreateRoom + (*join_msg, + self_room_type, + game_times, + register_time, + join_msg->proto_version(), + channel, + msg.mapid(), + p); + } else { + room = RoomMgr::Instance()->CreateRoom + (*join_msg, + self_room_type, + game_times, + register_time, + join_msg->proto_version(), + channel, + msg.mapid(), + nullptr); + } } + p->SetRoom(room.get()); room->JoinWithCustomBattle(ip_saddr, socket_handle, join_msg, p); } else { if (p->IsPvp()) { From ba91e05c2dae1aef41e53578da0c10c688b5adc9 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 18 Mar 2024 19:10:37 +0800 Subject: [PATCH 06/14] 1 --- server/gameserver/pbutils.cc | 107 +++++++++++++++++++++++++++++++++++ server/gameserver/roommgr.cc | 2 +- 2 files changed, 108 insertions(+), 1 deletion(-) diff --git a/server/gameserver/pbutils.cc b/server/gameserver/pbutils.cc index db86551c..1f8c81bc 100644 --- a/server/gameserver/pbutils.cc +++ b/server/gameserver/pbutils.cc @@ -2672,6 +2672,113 @@ int Room::InitWithCustomBattle(long ip_saddr, int socket_handle, std::shared_ptr int Room::JoinWithCustomBattle(long ip_saddr, int socket_handle, std::shared_ptr msg, std::shared_ptr p) { + std::vector> room_teams; + std::vector> net_teams; + p->TraverseTeamList + ( + [this, &room_teams, &net_teams] (std::shared_ptr team) -> bool + { + auto new_team = NewTeam(); + new_team->SetInitTeamMemberNum(0); + new_team->SetAutoFill(true); + room_teams.push_back(new_team); + net_teams.push_back(team); + return true; + }); + if (room_teams.empty()) { + abort(); + } + if (IsMobaModeRoom() && + room_teams.size() > 2) { + abort(); + } + cs::CMJoin join_msg = *msg; + for (size_t i = 0; i < net_teams.size(); ++i) { + auto net_team = net_teams.at(i); + auto room_team = room_teams.at(i); + room_team->SetInitTeamMemberNum(net_team->GetMemberNum()); + net_team->TraverseMember + ( + [join_msg, p, room_team] (std::shared_ptr m) mutable -> bool + { + Player* hum = InternalCreatePlayer(p, m, room_team, join_msg); + return true; + } + ); + } + if (IsMobaModeRoom()) { + if (room_teams.size() < 2) { + auto new_team = NewTeam(); + new_team->SetInitTeamMemberNum(0); + new_team->SetAutoFill(true); + room_teams.push_back(new_team); + } + int side = a8::RandEx(1, 2); + for (size_t i = 0; i < 2; ++i) { + auto team = room_teams.at(i); + if (team->GetMemberNum() < MAX_TEAM_NUM) { + CreateAndroid(MAX_TEAM_NUM - team->GetMemberNum(), team); + } + if (i == 0) { + moba_team_a_ = team.get(); + } else { + moba_team_b_ = team.get(); + } + team->TraverseMembers + ( + [this, side] (Human* hum) -> bool + { + hum->side = side; + std::shared_ptr born_point = std::make_shared(); + born_point->wo_meta = std::get<0>(GetMapMeta()->moba_born_points.at(side - 1)); + hum->SetBornPoint(born_point); + hum->InitMobaRoad(); +#ifdef MYDEBUG + a8::XPrintf("moba init uniid:%d team_id:%d side:%d wo_meta:%d\n", + { + hum->GetUniId(), + hum->GetTeam()->GetTeamId(), + hum->side, + (long long)hum->GetBornPoint()->wo_meta.get() + }); +#endif + return true; + }); + if (side == 1) { + side = 2; + } else { + side = 1; + } + } + } + { + p->TraverseObList + ( + [this, join_msg, p] (std::shared_ptr m) mutable -> bool + { + auto new_team = NewViewTeam(); + new_team->SetInitTeamMemberNum(0); + new_team->SetAutoFill(true); + Player* hum = InternalCreatePlayer(p, m, new_team, join_msg, + [p] (Player* hum) + { + a8::SetBitFlag(hum->status, CS_IsOb); + p->GetRoom()->GetRoomOb()->AddOb(hum); + }); + return true; + }); + } + { + auto hum = GetPlayerByAccountId(msg->account_id()); + if (hum) { + hum->ReJoin(ip_saddr, socket_handle, msg); + } else { + auto hum = p->GetRoom()->GetRoomOb()->GetByAccountId(msg->account_id()); + if (hum) { + hum->ReJoin(ip_saddr, socket_handle, msg); + } + } + } return 0; } diff --git a/server/gameserver/roommgr.cc b/server/gameserver/roommgr.cc index e11bb411..74045951 100644 --- a/server/gameserver/roommgr.cc +++ b/server/gameserver/roommgr.cc @@ -1043,7 +1043,7 @@ void RoomMgr::_CMJoinCustomBattle(f8::MsgHdr* hdr, const cs::CMJoin& msg, int cu join_msg->proto_version(), channel, msg.mapid(), - p); + nullptr); } else { room = RoomMgr::Instance()->CreateRoom (*join_msg, From e99af3f4ac7cf6dd5d931341a536430f2c1d3242 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 18 Mar 2024 19:41:06 +0800 Subject: [PATCH 07/14] 1 --- server/gameserver/custom_battle.cc | 9 ++++++++- server/gameserver/roommgr.cc | 13 +++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/server/gameserver/custom_battle.cc b/server/gameserver/custom_battle.cc index 42aaaa22..d380e567 100644 --- a/server/gameserver/custom_battle.cc +++ b/server/gameserver/custom_battle.cc @@ -5,6 +5,8 @@ #include "custom_member.h" #include "netdata.h" +#include "mt/Map.h" + void CustomBattle::Init() { ob_team_ = std::make_shared(); @@ -27,9 +29,14 @@ void CustomBattle::ParseResult(a8::XObject& obj) room_uuid_ = obj.Get("room_uuid").GetString(); zone_id_ = obj.Get("zone_id"); node_id_ = obj.Get("node_id"); + map_id_ = obj.Get("map_id"); start_time_ = obj.Get("start_time"); sign_ = obj.Get("sign").GetString(); - + const mt::Map* map_meta = mt::Map::GetById(map_id_); + if (!map_meta) { + parse_ok_ = false; + return; + } { auto team_list = obj.At("team_list"); if (!team_list || !team_list->IsArray()) { diff --git a/server/gameserver/roommgr.cc b/server/gameserver/roommgr.cc index 74045951..e99fc8c6 100644 --- a/server/gameserver/roommgr.cc +++ b/server/gameserver/roommgr.cc @@ -125,15 +125,15 @@ void RoomMgr::_CMJoin(f8::MsgHdr* hdr, const cs::CMJoin& msg) }); #endif } + if (!msg.payload_data().empty()) { + DispatchSpecRoom(hdr, msg); + return; + } const mt::Map* map_meta = mt::Map::GetById(msg.mapid()); if (!map_meta || !map_meta->IsOpen()) { JoinErrorHandle(msg, 3, hdr->socket_handle); return; } - if (!msg.payload_data().empty()) { - DispatchSpecRoom(hdr, msg); - return; - } std::shared_ptr join_msg = std::make_shared(); *join_msg = msg; std::vector> join_msgs{join_msg}; @@ -1019,6 +1019,11 @@ void RoomMgr::_CMJoinCustomBattle(f8::MsgHdr* hdr, const cs::CMJoin& msg, int cu } return; } + const mt::Map* map_meta = mt::Map::GetById(p->GetMapId()); + if (!map_meta || !map_meta->IsOpen()) { + RoomMgr::Instance()->JoinErrorHandle(msg, 3, socket_handle); + return; + } int game_times = 0; RoomType_e self_room_type = RoomType_OldBrid1; time_t register_time = f8::ExtractRegisterTimeFromSessionId(msg.session_id()); From 22e8a2e5510c367b703fa473638ae51d6ecf5b16 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 18 Mar 2024 20:02:22 +0800 Subject: [PATCH 08/14] 1 --- server/gameserver/custom_battle.cc | 7 ++++++- server/gameserver/custom_battle.h | 1 + server/gameserver/roommgr.cc | 14 ++++++++++---- server/gameserver/roommgr.h | 1 + 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/server/gameserver/custom_battle.cc b/server/gameserver/custom_battle.cc index d380e567..4bb62481 100644 --- a/server/gameserver/custom_battle.cc +++ b/server/gameserver/custom_battle.cc @@ -33,7 +33,7 @@ void CustomBattle::ParseResult(a8::XObject& obj) start_time_ = obj.Get("start_time"); sign_ = obj.Get("sign").GetString(); const mt::Map* map_meta = mt::Map::GetById(map_id_); - if (!map_meta) { + if (!map_meta || !map_meta->IsOpen()) { parse_ok_ = false; return; } @@ -215,3 +215,8 @@ void CustomBattle::TraverseObList(std::function GetTeamByAccountId(const std::string& account_id); diff --git a/server/gameserver/roommgr.cc b/server/gameserver/roommgr.cc index e99fc8c6..cb45dc80 100644 --- a/server/gameserver/roommgr.cc +++ b/server/gameserver/roommgr.cc @@ -331,6 +331,7 @@ std::shared_ptr RoomMgr::GetJoinableRoom(const cs::CMJoin& msg, proto_version, channel, msg.mapid(), + (RoomMode_e)msg.room_mode(), nullptr); } @@ -517,6 +518,7 @@ std::shared_ptr RoomMgr::CreateRoom(const cs::CMJoin& msg, int creator_proto_version, int creator_channel, int map_id, + RoomMode_e room_mode, std::shared_ptr custom_battle) { int room_idx = AllocRoomIdx(); @@ -1047,7 +1049,8 @@ void RoomMgr::_CMJoinCustomBattle(f8::MsgHdr* hdr, const cs::CMJoin& msg, int cu register_time, join_msg->proto_version(), channel, - msg.mapid(), + p->GetMapId(), + p->GetRoomMode(), nullptr); } else { room = RoomMgr::Instance()->CreateRoom @@ -1057,7 +1060,8 @@ void RoomMgr::_CMJoinCustomBattle(f8::MsgHdr* hdr, const cs::CMJoin& msg, int cu register_time, join_msg->proto_version(), channel, - msg.mapid(), + p->GetMapId(), + p->GetRoomMode(), nullptr); } } @@ -1072,7 +1076,8 @@ void RoomMgr::_CMJoinCustomBattle(f8::MsgHdr* hdr, const cs::CMJoin& msg, int cu register_time, join_msg->proto_version(), channel, - msg.mapid(), + p->GetMapId(), + p->GetRoomMode(), p); } else { room = RoomMgr::Instance()->CreateRoom @@ -1082,7 +1087,8 @@ void RoomMgr::_CMJoinCustomBattle(f8::MsgHdr* hdr, const cs::CMJoin& msg, int cu register_time, join_msg->proto_version(), channel, - msg.mapid(), + p->GetMapId(), + p->GetRoomMode(), nullptr); } p->SetRoom(room.get()); diff --git a/server/gameserver/roommgr.h b/server/gameserver/roommgr.h index 12cfa015..ab919ad5 100644 --- a/server/gameserver/roommgr.h +++ b/server/gameserver/roommgr.h @@ -114,6 +114,7 @@ class RoomMgr : public a8::Singleton int creator_proto_version, int creator_channel, int map_id, + RoomMode_e room_mode, std::shared_ptr custom_battle); void JoinErrorHandle(const cs::CMJoin& msg, int error_code, int socket_handle); std::string GenTeamHashData(const std::string& team_uuid, std::map* team_hash); From e057e00e8db98d67279f6fda9efbcec6ae37ca0c Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 18 Mar 2024 20:09:02 +0800 Subject: [PATCH 09/14] 1 --- server/gameserver/custom_battle.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/server/gameserver/custom_battle.cc b/server/gameserver/custom_battle.cc index 4bb62481..9469af24 100644 --- a/server/gameserver/custom_battle.cc +++ b/server/gameserver/custom_battle.cc @@ -37,6 +37,9 @@ void CustomBattle::ParseResult(a8::XObject& obj) parse_ok_ = false; return; } + { + is_moba_ = map_meta->is_moba() ? true : false; + } { auto team_list = obj.At("team_list"); if (!team_list || !team_list->IsArray()) { @@ -218,5 +221,9 @@ void CustomBattle::TraverseObList(std::function Date: Mon, 18 Mar 2024 20:13:51 +0800 Subject: [PATCH 10/14] 1 --- server/gameserver/roommgr.cc | 22 +++++++++------------- server/gameserver/roommgr.h | 3 +-- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/server/gameserver/roommgr.cc b/server/gameserver/roommgr.cc index cb45dc80..8504b994 100644 --- a/server/gameserver/roommgr.cc +++ b/server/gameserver/roommgr.cc @@ -324,8 +324,7 @@ std::shared_ptr RoomMgr::GetJoinableRoom(const cs::CMJoin& msg, } } } - return CreateRoom(msg, - self_room_type, + return CreateRoom(self_room_type, game_times, creator_register_time, proto_version, @@ -511,8 +510,7 @@ int RoomMgr::AllocRoomIdx() return current_room_idx_; } -std::shared_ptr RoomMgr::CreateRoom(const cs::CMJoin& msg, - RoomType_e room_type, +std::shared_ptr RoomMgr::CreateRoom(RoomType_e room_type, int game_times, int creator_register_time, int creator_proto_version, @@ -530,14 +528,16 @@ std::shared_ptr RoomMgr::CreateRoom(const cs::CMJoin& msg, init_info.room_idx = room_idx; init_info.room_uuid = f8::App::Instance()->NewGlobalUuid(); init_info.room_type = room_type; - init_info.room_mode = (RoomMode_e)msg.room_mode(); + init_info.room_mode = room_mode; init_info.init_map_id = map_id; init_info.creator_game_times = game_times; init_info.creator_register_time = creator_register_time; init_info.creator_proto_version = creator_proto_version; init_info.creator_channel = creator_channel; +#if 0 init_info.pve_instance_id = msg.pve_instance_id(); init_info.pve_human_num = std::max(1, msg.team_members_size()); +#endif init_info.custom_battle = custom_battle; if (GetRoomByUuid(init_info.room_uuid)) { A8_ABORT(); @@ -1043,8 +1043,7 @@ void RoomMgr::_CMJoinCustomBattle(f8::MsgHdr* hdr, const cs::CMJoin& msg, int cu if (!room) { if (p->IsPvp()) { room = RoomMgr::Instance()->CreateRoom - (*join_msg, - self_room_type, + (self_room_type, game_times, register_time, join_msg->proto_version(), @@ -1054,8 +1053,7 @@ void RoomMgr::_CMJoinCustomBattle(f8::MsgHdr* hdr, const cs::CMJoin& msg, int cu nullptr); } else { room = RoomMgr::Instance()->CreateRoom - (*join_msg, - self_room_type, + (self_room_type, game_times, register_time, join_msg->proto_version(), @@ -1070,8 +1068,7 @@ void RoomMgr::_CMJoinCustomBattle(f8::MsgHdr* hdr, const cs::CMJoin& msg, int cu } else { if (p->IsPvp()) { room = RoomMgr::Instance()->CreateRoom - (*join_msg, - self_room_type, + (self_room_type, game_times, register_time, join_msg->proto_version(), @@ -1081,8 +1078,7 @@ void RoomMgr::_CMJoinCustomBattle(f8::MsgHdr* hdr, const cs::CMJoin& msg, int cu p); } else { room = RoomMgr::Instance()->CreateRoom - (*join_msg, - self_room_type, + (self_room_type, game_times, register_time, join_msg->proto_version(), diff --git a/server/gameserver/roommgr.h b/server/gameserver/roommgr.h index ab919ad5..6b5c3913 100644 --- a/server/gameserver/roommgr.h +++ b/server/gameserver/roommgr.h @@ -107,8 +107,7 @@ class RoomMgr : public a8::Singleton bool IsLimitJoin(); int AllocRoomIdx(); - std::shared_ptr CreateRoom(const cs::CMJoin& msg, - RoomType_e room_type, + std::shared_ptr CreateRoom(RoomType_e room_type, int game_times, int creator_register_time, int creator_proto_version, From 7c27125a5d4cdd222e35929043f70bb656437a49 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 18 Mar 2024 20:44:55 +0800 Subject: [PATCH 11/14] 1 --- server/gameserver/custom_battle.cc | 5 +++ server/gameserver/custom_battle.h | 1 + server/gameserver/room.cc | 5 +++ server/gameserver/room.h | 1 + server/gameserver/roommgr.cc | 49 +++++++++++++++++++++--------- server/gameserver/roommgr.h | 7 +---- 6 files changed, 48 insertions(+), 20 deletions(-) diff --git a/server/gameserver/custom_battle.cc b/server/gameserver/custom_battle.cc index 9469af24..784caa73 100644 --- a/server/gameserver/custom_battle.cc +++ b/server/gameserver/custom_battle.cc @@ -227,3 +227,8 @@ RoomMode_e CustomBattle::GetRoomMode() return kPvpMode; } } + +RoomType_e CustomBattle::GetRoomType() +{ + +} diff --git a/server/gameserver/custom_battle.h b/server/gameserver/custom_battle.h index 5a21ae75..6541cd5d 100644 --- a/server/gameserver/custom_battle.h +++ b/server/gameserver/custom_battle.h @@ -23,6 +23,7 @@ class CustomBattle int GetZoneId() { return zone_id_; } int GetNodeId() { return zone_id_; } int GetMapId() { return map_id_; } + RoomType_e GetRoomType(); RoomMode_e GetRoomMode(); int GetStartTime() { return start_time_; } void ParseResult(a8::XObject& obj); diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index 3e3f7884..4affffb8 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -3600,3 +3600,8 @@ void Room::DecAliveCount() alive_count_chged_frameno_ = GetFrameNo(); --PerfMonitor::Instance()->alive_count; } + +bool Room::CanJoin(std::shared_ptr p) +{ + return false; +} diff --git a/server/gameserver/room.h b/server/gameserver/room.h index 8944392a..4359aa7c 100644 --- a/server/gameserver/room.h +++ b/server/gameserver/room.h @@ -209,6 +209,7 @@ public: int self_channel, int init_map_id, const cs::CMJoin& msg); + bool CanJoin(std::shared_ptr p); void OnPlayerOffline(Player* hum); void FillSMUiUpdate(cs::SMUiUpdate& msg); void NotifyUiUpdate(); diff --git a/server/gameserver/roommgr.cc b/server/gameserver/roommgr.cc index 8504b994..6e3a8210 100644 --- a/server/gameserver/roommgr.cc +++ b/server/gameserver/roommgr.cc @@ -334,13 +334,40 @@ std::shared_ptr RoomMgr::GetJoinableRoom(const cs::CMJoin& msg, nullptr); } -std::shared_ptr RoomMgr::GetJoinableRoom(std::shared_ptr custom_battle, - const RoomType_e self_room_type, - int game_times, - int creator_register_time, - int proto_version, - int channel) +std::shared_ptr RoomMgr::GetJoinableRoom(std::shared_ptr p) { + if (p->IsMoba()) { + return nullptr; + } + if (p->IsCustomMode()) { + return nullptr; + } + std::vector>> group_rooms; + for (int i = 0; i < RoomType_Max; ++i) { + group_rooms.push_back(std::vector>()); + } + #if 0 + for (auto& pair : inactive_room_hash_) { + auto& room = pair.second; + if (!room->GetCustomBattle() && + room->CanJoin(msg.account_id(), + self_room_type, + (RoomMode_e)msg.room_mode(), + proto_version, + channel, + msg.mapid(), + msg)) { + if (!msg.team_uuid().empty() && room->HaveMyTeam(msg.team_uuid())) { + return room; + } + group_rooms[room->GetRoomType()].push_back(room); + } + } + #endif + + if (!group_rooms[p->GetRoomType()].empty()) { + return group_rooms[p->GetRoomType()][rand() % group_rooms[p->GetRoomType()].size()]; + } return nullptr; } @@ -1027,19 +1054,13 @@ void RoomMgr::_CMJoinCustomBattle(f8::MsgHdr* hdr, const cs::CMJoin& msg, int cu return; } int game_times = 0; - RoomType_e self_room_type = RoomType_OldBrid1; + RoomType_e self_room_type = p->GetRoomType(); time_t register_time = f8::ExtractRegisterTimeFromSessionId(msg.session_id()); int proto_version = msg.proto_version(); int channel = f8::ExtractChannelIdFromAccountId(msg.account_id()); std::shared_ptr room = nullptr; if (p->IsNormalMode()) { - room = RoomMgr::Instance()->GetJoinableRoom(p, - self_room_type, - game_times, - register_time, - proto_version, - channel - ); + room = RoomMgr::Instance()->GetJoinableRoom(p); if (!room) { if (p->IsPvp()) { room = RoomMgr::Instance()->CreateRoom diff --git a/server/gameserver/roommgr.h b/server/gameserver/roommgr.h index 6b5c3913..97ba59dc 100644 --- a/server/gameserver/roommgr.h +++ b/server/gameserver/roommgr.h @@ -96,12 +96,7 @@ class RoomMgr : public a8::Singleton int creator_register_time, int proto_version, int channel); - std::shared_ptr GetJoinableRoom(std::shared_ptr custom_battle, - const RoomType_e self_room_type, - int game_times, - int creator_register_time, - int proto_version, - int channel); + 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(); From ea20fcbf97cf01d1f5e5f861be0a90339239b8b7 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 18 Mar 2024 20:53:43 +0800 Subject: [PATCH 12/14] 1 --- server/gameserver/roommgr.cc | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/server/gameserver/roommgr.cc b/server/gameserver/roommgr.cc index 6e3a8210..160e9dec 100644 --- a/server/gameserver/roommgr.cc +++ b/server/gameserver/roommgr.cc @@ -346,28 +346,35 @@ std::shared_ptr RoomMgr::GetJoinableRoom(std::shared_ptr p) for (int i = 0; i < RoomType_Max; ++i) { group_rooms.push_back(std::vector>()); } - #if 0 for (auto& pair : inactive_room_hash_) { auto& room = pair.second; if (!room->GetCustomBattle() && - room->CanJoin(msg.account_id(), - self_room_type, - (RoomMode_e)msg.room_mode(), - proto_version, - channel, - msg.mapid(), - msg)) { - if (!msg.team_uuid().empty() && room->HaveMyTeam(msg.team_uuid())) { - return room; - } - group_rooms[room->GetRoomType()].push_back(room); + room->CanJoin(p)) { + group_rooms.at(room->GetRoomType()).push_back(room); } } - #endif - if (!group_rooms[p->GetRoomType()].empty()) { + if (!group_rooms.at(p->GetRoomType()).empty()) { return group_rooms[p->GetRoomType()][rand() % group_rooms[p->GetRoomType()].size()]; } + if (p->GetRoomType() == kPvpRankMode) { + } else { + if (p->GetRoomType() == RoomType_OldBrid2) { + for (auto& room : group_rooms[RoomType_OldBrid3]) { + if (room->GetGasInactiveReaminTime() > 8 && + room->GetPlayerNum() + 8 < room->GetRoomMaxPlayerNum()) { + return room; + } + } + } else if (p->GetRoomType() == RoomType_OldBrid3) { + for (auto& room : group_rooms[RoomType_OldBrid2]) { + if (room->GetGasInactiveReaminTime() > 8 && + room->GetPlayerNum() + 8 < room->GetRoomMaxPlayerNum()) { + return room; + } + } + } + } return nullptr; } From 8ee1248e216ba8e1f6436f377d243f1fa9ccb932 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 18 Mar 2024 21:01:55 +0800 Subject: [PATCH 13/14] 1 --- server/gameserver/custom_battle.cc | 23 ++++++++++++++++++++++- server/gameserver/custom_battle.h | 1 + 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/server/gameserver/custom_battle.cc b/server/gameserver/custom_battle.cc index 784caa73..75f43061 100644 --- a/server/gameserver/custom_battle.cc +++ b/server/gameserver/custom_battle.cc @@ -6,6 +6,7 @@ #include "netdata.h" #include "mt/Map.h" +#include "mt/Param.h" void CustomBattle::Init() { @@ -230,5 +231,25 @@ RoomMode_e CustomBattle::GetRoomMode() RoomType_e CustomBattle::GetRoomType() { - + if (IsMoba()) { + return RoomType_MidBrid; + } + if (IsCustomMode()) { + return RoomType_MidBrid; + } + if (GetRoomMode() == kPvpRankMode) { + auto rank_mode_conf = mt::Param::GetRankModeConfByHeroLv(team1_average_hero_lv_); + if (!rank_mode_conf) { + abort(); + } + return rank_mode_conf->room_type; + } else { + if (team1_average_hero_lv_ < mt::Param::s().new_room_max_level) { + return RoomType_OldBrid1; + } + if (team1_average_hero_lv_ < mt::Param::s().mid_room_max_level) { + return RoomType_OldBrid2; + } + return RoomType_OldBrid3; + } } diff --git a/server/gameserver/custom_battle.h b/server/gameserver/custom_battle.h index 6541cd5d..ba710613 100644 --- a/server/gameserver/custom_battle.h +++ b/server/gameserver/custom_battle.h @@ -54,6 +54,7 @@ class CustomBattle int node_id_ = 0; int map_id_ = 0; int start_time_ = 0; + int team1_average_hero_lv_ = 0; std::string sign_; std::shared_ptr raw_data_; std::map> uuid_hash_; From 8424bd57a7dd6cd6bdff736c84005e68d9f8a034 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 19 Mar 2024 15:30:56 +0800 Subject: [PATCH 14/14] 1 --- server/gameserver/custom_battle.cc | 20 ++++++++++++++ server/gameserver/custom_battle.h | 6 ++++ server/gameserver/custom_team.cc | 22 +++++++++++++++ server/gameserver/custom_team.h | 1 + server/gameserver/room.cc | 44 +++++++++++++++++++++++++++++- server/gameserver/team.cc | 1 + 6 files changed, 93 insertions(+), 1 deletion(-) diff --git a/server/gameserver/custom_battle.cc b/server/gameserver/custom_battle.cc index 75f43061..3dce9f4f 100644 --- a/server/gameserver/custom_battle.cc +++ b/server/gameserver/custom_battle.cc @@ -67,6 +67,7 @@ void CustomBattle::ParseResult(a8::XObject& obj) team->team_uuid_ = team_uuid; team->is_view_ = false; uuid_hash_[team->team_uuid_] = team; + team_list_.push_back(team); } for (int ii = 0; ii < member_list->Size(); ++ii) { auto member_obj = member_list->At(ii); @@ -144,6 +145,7 @@ void CustomBattle::ParseResult(a8::XObject& obj) raw_data_ = std::make_shared(); obj.DeepCopy(*raw_data_); + CalcTeam1AverageHeroLv(); parse_ok_ = true; } @@ -229,6 +231,13 @@ RoomMode_e CustomBattle::GetRoomMode() } } +void CustomBattle::CalcTeam1AverageHeroLv() +{ + if (!team_list_.empty()) { + team1_average_hero_lv_ = team_list_.at(0)->GetAverageHeroLv(); + } +} + RoomType_e CustomBattle::GetRoomType() { if (IsMoba()) { @@ -253,3 +262,14 @@ RoomType_e CustomBattle::GetRoomType() return RoomType_OldBrid3; } } + +std::shared_ptr CustomBattle::GetTeamByIdx(int idx) +{ + if (GetTeamNum() <= 0) { + return nullptr; + } + if (idx < 0 || idx >= GetTeamNum()) { + return nullptr; + } + return team_list_.at(idx); +} diff --git a/server/gameserver/custom_battle.h b/server/gameserver/custom_battle.h index ba710613..fca744fb 100644 --- a/server/gameserver/custom_battle.h +++ b/server/gameserver/custom_battle.h @@ -28,6 +28,7 @@ class CustomBattle int GetStartTime() { return start_time_; } void ParseResult(a8::XObject& obj); std::shared_ptr GetTeamByAccountId(const std::string& account_id); + std::shared_ptr GetTeamByIdx(int idx); std::shared_ptr GetMemberByAccountId(const std::string& account_id); std::shared_ptr GetTeamByTeamUuid(const std::string& team_uuid); std::shared_ptr GetObByAccountId(const std::string& account_id); @@ -43,6 +44,10 @@ class CustomBattle bool IsPvp() { return !is_moba_; } bool IsMoba() { return is_moba_; } +private: + + void CalcTeam1AverageHeroLv(); + private: bool parse_ok_ = false; Room *room_ = nullptr; @@ -57,6 +62,7 @@ class CustomBattle int team1_average_hero_lv_ = 0; std::string sign_; std::shared_ptr raw_data_; + std::vector> team_list_; std::map> uuid_hash_; std::shared_ptr ob_team_; std::map> account_hash_; diff --git a/server/gameserver/custom_team.cc b/server/gameserver/custom_team.cc index a831a185..bf79927f 100644 --- a/server/gameserver/custom_team.cc +++ b/server/gameserver/custom_team.cc @@ -1,6 +1,8 @@ #include "precompile.h" #include "custom_team.h" +#include "custom_member.h" +#include "netdata.h" std::shared_ptr CustomTeam::GetMember(const std::string& account_id) { @@ -21,3 +23,23 @@ int CustomTeam::GetMemberNum() { return member_hash_.size(); } + +int CustomTeam::GetAverageHeroLv() +{ + if (GetMemberNum() <= 0) { + return 0; + } + int total_hero_lv = 0; + TraverseMember + ( + [&total_hero_lv] (std::shared_ptr m) -> bool + { + long long hero_uniid = 0; + int hero_lv = 0; + int quality = 0; + m->GetNetData()->GetHeroLvQuality(hero_uniid, hero_lv, quality); + total_hero_lv += hero_lv; + return true; + }); + return total_hero_lv / GetMemberNum(); +} diff --git a/server/gameserver/custom_team.h b/server/gameserver/custom_team.h index e3b26243..4393a02e 100644 --- a/server/gameserver/custom_team.h +++ b/server/gameserver/custom_team.h @@ -10,6 +10,7 @@ class CustomTeam bool IsView() { return is_view_; } void TraverseMember(std::function)> cb); int GetMemberNum(); + int GetAverageHeroLv(); private: std::string team_uuid_; diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index 4affffb8..d9f57990 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -3603,5 +3603,47 @@ void Room::DecAliveCount() bool Room::CanJoin(std::shared_ptr p) { - return false; + if (p->IsMoba()) { + return false; + } + if (!p->IsNormalMode()) { + return false; + } + if (p->GetTeamNum() > 1) { + return false; + } + if (p->GetTeamNum() < 1) { + return false; + } + + if (lock_room_) { + return false; + } + if (IsCustomBattle()) { + return false; + } + if (IsMobaModeRoom()) { + return false; + } + if (room_mode_ != p->GetRoomMode()) { + return false; + } + if (GetGasData().GetGasMode() != GasInactive) { + return false; + } + if (map_meta_->map_id() != p->GetMapId()) { + return false; + } + + auto p_team = p->GetTeamByIdx(0); + if (GetPlayerNum() + p_team->GetMemberNum() > GetRoomMaxPlayerNum()) { + return false; + } + int try_count = 0; + while (GetHumanNum() + p_team->GetMemberNum() > GetRoomMaxPlayerNum() && + try_count < 100) { + ++try_count; + RandRemoveAndroid(); + } + return GetHumanNum() + p_team->GetMemberNum() <= GetRoomMaxPlayerNum(); } diff --git a/server/gameserver/team.cc b/server/gameserver/team.cc index 134f6c17..8acfb96b 100644 --- a/server/gameserver/team.cc +++ b/server/gameserver/team.cc @@ -373,6 +373,7 @@ void Team::GenBattleReportData(Human* player, a8::MutableXObject* params) } member_pb->SetVal("move_distance", hum->stats->move_distance); member_pb->SetVal("full_level_idx", hum->stats->full_level_idx); + member_pb->SetVal("hero_level", hum->GetHeroLevel()); member_pb->SetVal("is_run_away", hum->stats->is_run_away); member_pb->SetVal("hero_id", hum->meta->id());