From f7c5b46ed351b636d44d720a08c6aa017736e891 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 8 Dec 2020 11:15:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B8=B8=E6=88=8F=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E9=80=89=E6=8B=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/gameserver/mapinstance.h | 1 + server/gameserver/mapmgr.cc | 62 ++++++++++++++----------- server/gameserver/mapmgr.h | 2 + server/gameserver/metadata.cc | 38 +++++++++++++++ server/gameserver/metadata.h | 4 ++ server/gameserver/metamgr.cc | 9 ++++ server/gameserver/metamgr.h | 3 ++ server/gameserver/room.cc | 24 ++++------ server/gameserver/roommgr.cc | 13 ++++-- server/gameserver/roommgr.h | 3 +- server/gameserver/types.h | 1 + server/tools/protobuild/cs_proto.proto | 1 + server/tools/protobuild/metatable.proto | 3 ++ 13 files changed, 118 insertions(+), 46 deletions(-) diff --git a/server/gameserver/mapinstance.h b/server/gameserver/mapinstance.h index 257de9d..ad56f37 100644 --- a/server/gameserver/mapinstance.h +++ b/server/gameserver/mapinstance.h @@ -22,6 +22,7 @@ class MapInstance void UnInit(); void AttachRoom(Room* room, RoomInitInfo& init_info); + MetaData::Map* GetMapMeta() { return map_meta_; } private: void CreateThings(); diff --git a/server/gameserver/mapmgr.cc b/server/gameserver/mapmgr.cc index d3e9c1c..375b307 100644 --- a/server/gameserver/mapmgr.cc +++ b/server/gameserver/mapmgr.cc @@ -8,23 +8,30 @@ void MapMgr::Init() { - { - MapInstance* map_instance = new MapInstance(); - map_instance->map_id = 2001; - map_instance->Init(); - instance_hash_[map_instance->map_id] = map_instance; + std::list* maps = MetaMgr::Instance()->GetMaps(); + if (maps) { + for (auto& map_meta : *maps) { + MapInstance* map_instance = new MapInstance(); + map_instance->map_id = map_meta.i->map_id(); + map_instance->Init(); + instance_hash_[map_instance->map_id] = map_instance; + { + auto itr = mode_hash_.find(map_meta.i->map_mode()); + if (itr != mode_hash_.end()) { + itr->second.push_back(map_instance); + } else { + mode_hash_[map_meta.i->map_mode()] = std::vector({map_instance}); + } + } + } + } else { + abort(); } - if (MetaMgr::Instance()->GetMap(3001)) { - MapInstance* map_instance = new MapInstance(); - map_instance->map_id = 3001; - map_instance->Init(); - instance_hash_[map_instance->map_id] = map_instance; + if (mode_hash_.find(kZombieMode) == mode_hash_.end()) { + abort(); } - if (MetaMgr::Instance()->GetMap(4001)) { - MapInstance* map_instance = new MapInstance(); - map_instance->map_id = 4001; - map_instance->Init(); - instance_hash_[map_instance->map_id] = map_instance; + if (mode_hash_.find(kChiJiMode) == mode_hash_.end()) { + abort(); } } @@ -39,19 +46,14 @@ void MapMgr::UnInit() void MapMgr::AttachRoom(Room* room, RoomInitInfo& init_info) { - MapInstance* map_instance = GetMapInstance(2001); - if (init_info.room_mode == kZombieMode) { - if (init_info.creator_channel == kWxChannelId && - init_info.creator_proto_version == cs::ProtoVersion) { - map_instance = GetMapInstance(4001); - } else { - if (init_info.creator_proto_version == cs::ProtoVersion) { - map_instance = GetMapInstance(4001); - } else { - map_instance = GetMapInstance(3001); - } - } + MapInstance* map_instance = init_info.init_map_id == 0 ? + RandMapInstance(init_info.room_mode) : GetMapInstance(init_info.init_map_id); + if (!map_instance) { + map_instance = RandMapInstance(init_info.room_mode); + } else if (map_instance->GetMapMeta()->i->map_mode() != init_info.room_mode) { + map_instance = RandMapInstance(init_info.room_mode); } + if (!map_instance) { abort(); } @@ -63,3 +65,9 @@ MapInstance* MapMgr::GetMapInstance(int map_id) auto itr = instance_hash_.find(map_id); return itr != instance_hash_.end() ? itr->second : nullptr; } + +MapInstance* MapMgr::RandMapInstance(int map_mode) +{ + auto itr = mode_hash_.find(map_mode); + return itr != mode_hash_.end() ? itr->second[rand() % itr->second.size()] : nullptr; +} diff --git a/server/gameserver/mapmgr.h b/server/gameserver/mapmgr.h index c064490..1923d9a 100644 --- a/server/gameserver/mapmgr.h +++ b/server/gameserver/mapmgr.h @@ -16,7 +16,9 @@ public: private: MapInstance* GetMapInstance(int map_id); + MapInstance* RandMapInstance(int map_mode); private: std::map instance_hash_; + std::map> mode_hash_; }; diff --git a/server/gameserver/metadata.cc b/server/gameserver/metadata.cc index 4d9a06e..b53dd65 100644 --- a/server/gameserver/metadata.cc +++ b/server/gameserver/metadata.cc @@ -38,6 +38,44 @@ namespace MetaData airdrops.push_back(a8::XValue(str).GetInt()); } } + { + std::vector strings; + a8::Split(i->refresh_robot(), strings, '|'); + if (strings.size() != 2) { + abort(); + } + { + std::vector strings2; + a8::Split(strings[0], strings2, '-'); + if (strings2.size() != 2) { + abort(); + } + refresh_robot_min_num = a8::XValue(strings2[0]); + refresh_robot_max_num = a8::XValue(strings2[1]); + } + { + std::vector strings2; + a8::Split(strings[1], strings2, '-'); + if (strings2.size() != 2) { + abort(); + } + refresh_robot_min_time = a8::XValue(strings2[0]); + refresh_robot_max_time = a8::XValue(strings2[1]); + } + if (refresh_robot_min_num >= refresh_robot_max_num) { + abort(); + } + if (refresh_robot_min_time >= refresh_robot_max_time) { + abort(); + } + if (refresh_robot_min_num <= 0 || refresh_robot_max_num <= 0 || + refresh_robot_min_time <= 0 || refresh_robot_max_time <= 0) { + abort(); + } + } + if (i->player() < 20) { + abort(); + } } std::string Map::RandTemplate() diff --git a/server/gameserver/metadata.h b/server/gameserver/metadata.h index a7739f4..72f62cb 100755 --- a/server/gameserver/metadata.h +++ b/server/gameserver/metadata.h @@ -23,6 +23,10 @@ namespace MetaData std::vector> template_list; int rand_space = 0; std::vector airdrops; + int refresh_robot_min_num = 0; + int refresh_robot_max_num = 0; + int refresh_robot_min_time = 0; + int refresh_robot_max_time = 0; void Init(); std::string RandTemplate(); diff --git a/server/gameserver/metamgr.cc b/server/gameserver/metamgr.cc index 2adab43..e80c656 100755 --- a/server/gameserver/metamgr.cc +++ b/server/gameserver/metamgr.cc @@ -339,10 +339,12 @@ public: METAMGR_READ(level1room_robot_autodie_distance, 500); METAMGR_READ_STR(level1room_born_point, ""); + #if 0 METAMGR_READ(refresh_robot_min_num, 5); METAMGR_READ(refresh_robot_max_num, 10); METAMGR_READ(refresh_robot_min_time, 5); METAMGR_READ(refresh_robot_max_time, 10); + #endif } if (MetaMgr::Instance()->K < 0.01f) { abort(); @@ -406,6 +408,7 @@ private: } } + #if 0 { if (MetaMgr::Instance()->refresh_robot_min_num > MetaMgr::Instance()->refresh_robot_max_num) { @@ -416,6 +419,7 @@ private: abort(); } } + #endif } void BindToMetaData() @@ -667,6 +671,11 @@ MetaData::Map* MetaMgr::GetMap(int map_id) return itr != loader_->gamemap_hash.end() ? itr->second : nullptr; } +std::list* MetaMgr::GetMaps() +{ + return &loader_->map_list; +} + MetaData::MapThing* MetaMgr::GetMapThing(int mapthing_id) { auto itr = loader_->mapthing_hash.find(mapthing_id); diff --git a/server/gameserver/metamgr.h b/server/gameserver/metamgr.h index 76a9aae..7cb7171 100755 --- a/server/gameserver/metamgr.h +++ b/server/gameserver/metamgr.h @@ -20,6 +20,7 @@ class MetaMgr : public a8::Singleton double GetSysParamAsFloat(const std::string& param_name, double def_val = 0.0f); std::string GetSysParamAsString(const std::string& param_name, const char* def_val = ""); MetaData::Map* GetMap(int map_id); + std::list* GetMaps(); MetaData::MapThing* GetMapThing(int mapthing_id); MetaData::Player* GetPlayer(int id); MetaData::Equip* GetEquip(int id); @@ -120,10 +121,12 @@ class MetaMgr : public a8::Singleton int level1room_robot_autodie_distance = 0; std::string level1room_born_point; + #if 0 int refresh_robot_min_num = 0; int refresh_robot_max_num = 0; int refresh_robot_min_time = 0; int refresh_robot_max_time = 0; + #endif int other_fill_interval = 0; float android_attack_range = 0; diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index 1aab7f1..17b8cd0 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -28,8 +28,10 @@ #include "framework/cpp/utils.h" +#if 0 const size_t NORMAL_ROOM_MAX_PLAYER_NUM = 40; const size_t MINI_ROOM_MAX_PLAYER_NUM = 20; +#endif const int SHUA_RANGE = 580; @@ -228,10 +230,10 @@ void Room::ShuaAndroid() if (gas_data_.gas_mode != GasInactive) { return; } - int robot_num = a8::RandEx(MetaMgr::Instance()->refresh_robot_min_num, - MetaMgr::Instance()->refresh_robot_max_num); - int refresh_time = a8::RandEx(MetaMgr::Instance()->refresh_robot_min_time, - MetaMgr::Instance()->refresh_robot_max_time); + int robot_num = a8::RandEx(map_meta_->refresh_robot_min_num, + map_meta_->refresh_robot_max_num); + int refresh_time = a8::RandEx(map_meta_->refresh_robot_min_time, + map_meta_->refresh_robot_max_time); if (robot_num > 0 && refresh_time > 0) { if (IsMiniRoom()) { #if 0 @@ -742,16 +744,6 @@ bool Room::CanJoin(const std::string& accountid, int self_proto_version, int self_channel) { - #if 1 - if (creator_channel_ == kWxChannelId) { - if (self_channel != creator_channel_) { - return false; - } - if (self_proto_version != creator_proto_version_) { - return false; - } - } - #endif if (self_room_mode < kChiJiMode) { self_room_mode = kChiJiMode; } @@ -3323,6 +3315,9 @@ int Room::GetOnlinePlayerNum() size_t Room::GetRoomMaxPlayerNum() { + #if 1 + return map_meta_->i->player(); + #else if (room_mode_ == kZombieMode) { return MetaMgr::Instance()->zbmode_player_num; } else { @@ -3332,6 +3327,7 @@ size_t Room::GetRoomMaxPlayerNum() return NORMAL_ROOM_MAX_PLAYER_NUM; } } + #endif } void Room::InitAndroidAI() diff --git a/server/gameserver/roommgr.cc b/server/gameserver/roommgr.cc index 27b2903..3aace70 100644 --- a/server/gameserver/roommgr.cc +++ b/server/gameserver/roommgr.cc @@ -266,7 +266,8 @@ Room* RoomMgr::GetJoinableRoom(const cs::CMJoin& msg, game_times, creator_register_time, proto_version, - channel); + channel, + msg.map_id()); } if (self_room_type == RT_MidBrid) { return CreateRoom(msg, @@ -274,7 +275,8 @@ Room* RoomMgr::GetJoinableRoom(const cs::CMJoin& msg, game_times, creator_register_time, proto_version, - channel); + channel, + msg.map_id()); } for (int i = 0; i < RT_Max; ++i) { for (Room* room : group_rooms[i]) { @@ -288,7 +290,8 @@ Room* RoomMgr::GetJoinableRoom(const cs::CMJoin& msg, game_times, creator_register_time, proto_version, - channel); + channel, + msg.map_id()); } Room* RoomMgr::GetRoomByUuid(long long room_uuid) @@ -468,7 +471,8 @@ Room* RoomMgr::CreateRoom(const cs::CMJoin& msg, int game_times, int creator_register_time, int creator_proto_version, - int creator_channel) + int creator_channel, + int map_id) { int room_idx = AllocRoomIdx(); if (room_idx < 1) { @@ -480,6 +484,7 @@ Room* RoomMgr::CreateRoom(const cs::CMJoin& msg, init_info.room_uuid = App::Instance()->NewUuid(); init_info.room_type = room_type; init_info.room_mode = (RoomMode_e)msg.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; diff --git a/server/gameserver/roommgr.h b/server/gameserver/roommgr.h index 0b7e339..d928d3f 100644 --- a/server/gameserver/roommgr.h +++ b/server/gameserver/roommgr.h @@ -51,7 +51,8 @@ class RoomMgr : public a8::Singleton int game_times, int creator_register_time, int creator_proto_version, - int creator_channel); + int creator_channel, + int map_id); void JoinErrorHandle(const cs::CMJoin& msg, int error_code, int socket_handle); std::string GenTeamHashData(const std::string& team_uuid, std::map* team_hash); void OnJoinRoomOk(const cs::CMJoin& msg, Player* hum); diff --git a/server/gameserver/types.h b/server/gameserver/types.h index 99a524b..ce31a3d 100755 --- a/server/gameserver/types.h +++ b/server/gameserver/types.h @@ -164,6 +164,7 @@ struct RoomInitInfo int creator_proto_version = 0; int creator_channel = 0; bool force_entry_newbie_room = false; + int init_map_id = 0; const MetaData::Map* map_meta = nullptr; std::string map_tpl_name; diff --git a/server/tools/protobuild/cs_proto.proto b/server/tools/protobuild/cs_proto.proto index f13a02e..95ad389 100755 --- a/server/tools/protobuild/cs_proto.proto +++ b/server/tools/protobuild/cs_proto.proto @@ -754,6 +754,7 @@ message CMJoin optional bool force_entry_newbie_room = 50; //是否强制进新手房 repeated MFTeamMember team_members = 51; //包括自己 optional int32 room_mode = 52; //0:吃鸡模式 1:僵尸模式 + optional int32 map_id = 53; //地图id 0:随机地图 } //断线重连 diff --git a/server/tools/protobuild/metatable.proto b/server/tools/protobuild/metatable.proto index 112126c..f6e1e8a 100755 --- a/server/tools/protobuild/metatable.proto +++ b/server/tools/protobuild/metatable.proto @@ -28,6 +28,9 @@ message Map optional float map_height = 5; optional string airdrops = 6; optional int32 terminator_airdrop = 7; + optional int32 player = 8; + optional string refresh_robot = 9; + optional int32 map_mode = 10; } message MapThing