aozhiwei e250e63ef3 1
2021-09-28 02:21:51 +00:00

113 lines
3.5 KiB
C++

#pragma once
#include <a8/timer_attacher.h>
namespace cs
{
class CMJoin;
class CMReconnect;
}
namespace MetaData
{
struct Map;
struct MapTplThing;
}
class GridService;
class MapService;
class MapInstance;
class Building;
struct RoomInitInfo
{
int room_idx = 0;
RoomMode_e room_mode = kChiJiMode;
long long room_uuid = 0;
RoomType_e room_type = RT_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;
const MetaData::Map* map_meta = nullptr;
std::string map_tpl_name;
GridService* grid_service = nullptr;
MapService* map_service = nullptr;
MapInstance* map_instance = nullptr;
const std::vector<MetaData::MapTplThing*>* mini_room_spawn_points = nullptr;
const std::vector<MetaData::MapTplThing*>* normal_room_spawn_points = nullptr;
const std::vector<MetaData::MapTplThing*>* room_monster_spawn_points = nullptr;
const MetaData::MapTplThing* level0room_born_point_meta = nullptr;
const MetaData::MapTplThing* level1room_born_point_meta = nullptr;
const std::vector<MetaData::MapTplThing*>* loots = nullptr;
const std::vector<Building*>* buildings = nullptr;
const std::vector<MetaData::MapTplThing*>* level0room_spec_things = nullptr;
};
class Room;
class MatchTeam;
class RoomMgr : public a8::Singleton<RoomMgr>
{
public:
enum { HID = HID_RoomMgr };
private:
RoomMgr() {};
friend class a8::Singleton<RoomMgr>;
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 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);
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();
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<std::string, long long>* team_hash);
void OnJoinRoomOk(const cs::CMJoin& msg, Player* hum);
void TeamRoomTimeOut(const std::string& team_uuid);
private:
int current_room_idx_ = 0;
std::map<long long, Room*> inactive_room_hash_;
std::map<long long, Room*> room_hash_;
std::map<int, Room*> room_idx_hash_;
std::map<long long, Room*> over_room_hash_;
a8::TimerAttacher reportstate_timer_attacher_;
std::map<std::string, int> gm_hash_;
std::map<std::string, std::map<std::string, long long>> team_room_hash_;
};