#pragma once #include #include #include #include #include "netdata.h" namespace cs { class CMJoin; class CMReconnect; class CMPing; } namespace MetaData { struct Map; struct MapTplThing; } class GridService; class MapService; class MapInstance; class Building; struct RoomInitInfo { int room_idx = 0; RoomMode_e room_mode = kPvpMode; long long room_uuid = 0; RoomType_e room_type = RoomType_NewBrid; int creator_game_times = 0; int creator_register_time = 0; int creator_proto_version = 0; int creator_channel = 0; bool force_entry_newbie_room = false; int init_map_id = 0; int pve_instance_id = 0; int pve_human_num = 0; bool is_newbie_room = false; const mt::Map* map_meta = nullptr; std::string map_tpl_name; GridService* grid_service = nullptr; MapService* map_service = nullptr; std::shared_ptr map_instance; std::vector* mini_room_spawn_points = nullptr; std::vector* normal_room_spawn_points = nullptr; std::vector* room_monster_spawn_points = nullptr; mt::MapTplThing* level0room_born_point_meta = nullptr; const mt::MapTplThing* level1room_born_point_meta = nullptr; std::vector* loots = nullptr; std::vector* level0room_spec_things = nullptr; }; class Room; class MatchTeam; class RoomMgr : public a8::Singleton { public: enum { HID = HID_RoomMgr }; private: RoomMgr() {}; friend class a8::Singleton; public: void Init(); void UnInit(); void Update(int delta_time); void _CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg); void _CMReconnect(f8::MsgHdr& hdr, const cs::CMReconnect& msg); void _CMPing(f8::MsgHdr& hdr, const cs::CMPing& msg); void ActiveRoom(long long room_uuid); int RoomNum(); int OverRoomNum(); Room* GetRoomByUuid(long long uuid); void AddOverRoom(long long room_uuid); bool IsGM(const std::string& account_id); void JoinTeam(MatchTeam* team); void SendGetBattleData(int mode, std::vector>& join_msgs, std::function< void(std::vector>&)> cb); int GetMatchMode() { return match_mode_; }; void SetMatchMode(int mode); private: void InstallReportStateTimer(); Room* GetRoomByIdx(int room_idx); Room* GetJoinableRoom(const cs::CMJoin& msg, const RoomType_e self_room_type, int game_times, int creator_register_time, int proto_version, int channel); Room* GetJoinableRoom(MatchTeam* team); void ReportServerState(int instance_id, const std::string& host, int port); void FreeOverRoom(long long room_uuid); bool IsLimitJoin(); void EnterNewBie(f8::MsgHdr& hdr, const cs::CMJoin& msg); int AllocRoomIdx(); Room* CreateRoom(const cs::CMJoin& msg, RoomType_e room_type, int game_times, int creator_register_time, int creator_proto_version, 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); void TeamRoomTimeOut(const std::string& team_uuid); void AdjustCMJoin(cs::CMJoin* msg); private: int current_room_idx_ = 0; int match_mode_ = 0; std::map inactive_room_hash_; std::map room_hash_; std::map room_idx_hash_; std::map over_room_hash_; f8::Attacher reportstate_timer_attacher_; std::map gm_hash_; std::map> team_room_hash_; };