This commit is contained in:
aozhiwei 2024-03-25 21:23:58 +08:00
parent a05a1b7db0
commit 0342dce056
3 changed files with 60 additions and 21 deletions

View File

@ -319,17 +319,12 @@ void CustomBattle::OnEnter(std::shared_ptr<cs::CMJoin> 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();
}
}

View File

@ -7,7 +7,7 @@ class SocketDisconnectHandler;
class Room;
class CustomTeam;
class CustomMember;
class CustomBattle
class CustomBattle : public std::enable_shared_from_this<CustomBattle>
{
public:
@ -53,6 +53,7 @@ private:
void CalcTeam1AverageHeroLv();
void NotifyState();
void GameStart();
private:
bool parse_ok_ = false;

View File

@ -86,16 +86,7 @@ class RoomMgr : public a8::Singleton<RoomMgr>
std::shared_ptr<CustomMember> GetCustomMemberBySocket(int socket_handle);
void ReBindCustomMemberSocket(std::shared_ptr<CustomMember> p);
void UnBindCustomMemberSocket(int socket_handle);
private:
void InstallReportStateTimer();
std::shared_ptr<Room> GetRoomByIdx(int room_idx);
std::shared_ptr<Room> GetJoinableRoom(std::shared_ptr<CustomBattle> 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<Room> CreateRoom(RoomType_e room_type,
int game_times,
int creator_register_time,
@ -104,6 +95,15 @@ class RoomMgr : public a8::Singleton<RoomMgr>
int map_id,
RoomMode_e room_mode,
std::shared_ptr<CustomBattle> custom_battle);
private:
void InstallReportStateTimer();
std::shared_ptr<Room> 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<CustomBattle> GetCustomRoom(const std::string& room_uuid);