aozhiwei e47ab524b8 1
2022-11-17 16:59:28 +08:00

859 lines
30 KiB
C++

#include "precompile.h"
#include <a8/timer.h>
#include <a8/mutable_xobject.h>
#include "roommgr.h"
#include "room.h"
#include "cs_proto.pb.h"
#include "GGListener.h"
#include "player.h"
#include "playermgr.h"
#include "app.h"
#include "metamgr.h"
#include "jsondatamgr.h"
#include "playermgr.h"
#include "mapmgr.h"
#include "perfmonitor.h"
#include "matchmgr.h"
#include "matchteam.h"
#include "httpproxy.h"
#include "framework/cpp/httpclientpool.h"
#include "framework/cpp/utils.h"
const int ROOM_NUM_UP_LIMIT = 1000;
const int HUM_NUM_DOWN_LIMIT = 2500;
static RoomType_e GetHumanRoomType(const cs::CMJoin& msg, int& game_times)
{
#if 1
return RT_OldBrid1;
#else
game_times = 0;
std::vector<std::string> tmp_strings;
a8::Split(msg.pre_settlement_info(), tmp_strings, ',');
if (tmp_strings.size() < 3) {
return RT_NewBrid;
}
//游戏次数,吃鸡数,击杀数,段位
game_times = a8::XValue(tmp_strings[0]);
int room_rank = tmp_strings.size() > 3 ? a8::XValue(tmp_strings[3]).GetInt() : 0;
time_t register_time = f8::ExtractRegisterTimeFromSessionId(msg.session_id());
#if 1
#else
if (!f8::IsOnlineEnv() || RoomMgr::Instance()->IsGM(msg)) {
game_times = 0;
if (!msg.team_uuid().empty()) {
game_times = 1;
}
}
#endif
if (!msg.team_uuid().empty() && msg.team_members().size() > 1) {
for (auto& team_member : msg.team_members()) {
if (team_member.rank() > 0) {
if (team_member.rank() > room_rank) {
room_rank = team_member.rank();
register_time = team_member.create_time();
} else if(team_member.rank() == room_rank &&
team_member.create_time() > register_time) {
register_time = team_member.create_time();
}
}
}
} else {
#if 0
if (msg.force_entry_newbie_room()) {
return RT_NewBrid;
}
#endif
if (game_times <= 0) {
return RT_NewBrid;
} else if (game_times == 1) {
return RT_MidBrid;
}
}
if (!msg.team_uuid().empty() && msg.team_members().size() > 1) {
if (room_rank >= 0 && room_rank <= 6) {
return RT_OldBrid1;
} else if (a8::BetweenDays(Global::g_nowtime, register_time) <= 0) {
return RT_OldBrid2;
} else {
return RT_OldBrid3;
}
} else {
if (room_rank >= 0 && room_rank <= 6) {
//黄金段位以下
return RT_OldBrid1;
} else if (a8::BetweenDays(Global::g_nowtime, register_time) <= 0) {
//第一天,黄金段位以上
return RT_OldBrid2;
} else {
//其他
return RT_OldBrid3;
}
}
#endif
}
void RoomMgr::Init()
{
InstallReportStateTimer();
}
void RoomMgr::UnInit()
{
for (auto& pair : room_hash_) {
pair.second->UnInit();
delete pair.second;
}
for (auto& pair : over_room_hash_) {
pair.second->UnInit();
delete pair.second;
}
}
void RoomMgr::Update(int delta_time)
{
long long real_alive_count = 0;
for (auto& pair : room_hash_) {
Room* room = pair.second;
room->Update(delta_time);
real_alive_count += room->RealAliveCount();
}
PerfMonitor::Instance()->real_alive_count = real_alive_count;
}
void RoomMgr::_CMJoin(f8::MsgHdr& hdr, const cs::CMJoin& msg)
{
#if 0
if (msg.proto_version() < 2021073001) {
JoinErrorHandle(msg, 6, hdr.socket_handle);
return;
}
#endif
if (IsLimitJoin()) {
JoinErrorHandle(msg, 2, hdr.socket_handle);
return;
}
#if 1
{
cs::CMJoin* mutable_msg = (cs::CMJoin*)&msg;
if (mutable_msg->room_mode() != kChiJiMode) {
mutable_msg->set_room_mode(kChiJiMode);
}
}
#endif
if (MatchMgr::Instance()->NeedMatch(msg)) {
MatchMgr::Instance()->_CMJoin(hdr, msg);
return;
}
std::shared_ptr<cs::CMJoin> join_msg = std::make_shared<cs::CMJoin>();
*join_msg = msg;
std::vector<std::shared_ptr<cs::CMJoin>> join_msgs{join_msg};
auto ip_saddr = hdr.ip_saddr;
auto socket_handle = hdr.socket_handle;
auto cb =
[ip_saddr, socket_handle, join_msg]
(std::vector<std::shared_ptr<BattleDataContext>>& results)
{
cs::CMJoin& msg = *join_msg;
if (RoomMgr::Instance()->IsLimitJoin()) {
RoomMgr::Instance()->JoinErrorHandle(msg, 2, socket_handle);
return;
}
int game_times = 0;
RoomType_e self_room_type = GetHumanRoomType(msg, game_times);
if (self_room_type < RT_OldBrid1) {
self_room_type = RT_OldBrid1;
}
time_t register_time = f8::ExtractRegisterTimeFromSessionId(msg.session_id());
int proto_version = msg.proto_version();
int channel = f8::ExtractChannelIdFromAccountId(msg.account_id());
Room* room = RoomMgr::Instance()->GetJoinableRoom
(
msg,
self_room_type,
game_times,
register_time,
proto_version,
channel
);
if (!room) {
#ifdef DEBUG
a8::XPrintf("GetJoinableRoom error %s\n", {msg.account_id()});
#endif
RoomMgr::Instance()->JoinErrorHandle(msg, 3, socket_handle);
return;
}
Player* hum = room->NewPlayer();
hum->proto_version = msg.proto_version();
hum->hero_uniid = a8::XValue(msg.hero_uniid());
hum->battle_uuid = results.at(0)->battle_uuid;
hum->is_valid_battle = results.at(0)->is_valid_battle;
hum->payload = results.at(0)->payload;
PlayerMgr::Instance()->
CreatePlayerByCMJoin(hum,
ip_saddr,
socket_handle,
msg
);
hum->meta = MetaMgr::Instance()->GetPlayer(msg.hero_id());
if (!hum->meta) {
hum->meta = MetaMgr::Instance()->human_meta;
}
hum->room = room;
room->AddPlayer(hum);
hum->SetBattleContext(results.at(0));
hum->GetBattleContext()->Init(hum);
hum->ProcSkillList();
hum->SetHP(hum->GetBattleContext()->GetMaxHP());
hum->SetMaxHP(hum->GetHP());
PlayerMgr::Instance()->IncAccountNum(msg.account_id());
if (JsonDataMgr::Instance()->channel != 0 &&
JsonDataMgr::Instance()->channel != channel) {
a8::UdpLog::Instance()->Warning
("join room channel not match channel:%d account_id:%s",
{
JsonDataMgr::Instance()->channel,
msg.account_id()
});
}
RoomMgr::Instance()->OnJoinRoomOk(msg, hum);
};
SendGetBattleData(0, join_msgs, cb);
}
void RoomMgr::_CMReconnect(f8::MsgHdr& hdr, const cs::CMReconnect& msg)
{
auto send_reconnect_failed =
[] (int socket_handle, int errcode, const std::string& errmsg)
{
cs::SMReconnect respmsg;
respmsg.set_errcode(errcode);
respmsg.set_errmsg(errmsg);
GGListener::Instance()->SendToClient(socket_handle, 0, respmsg);
a8::Timer::Instance()->AddDeadLineTimer
(
1000 * 3,
a8::XParams()
.SetSender(socket_handle),
[] (const a8::XParams& param)
{
GGListener::Instance()->ForceCloseChildSocket(param.sender);
}
);
};
Room* room = GetRoomByUuid(a8::XValue(msg.room_uuid()));
if (!room) {
send_reconnect_failed(hdr.socket_handle, 1,
TEXT("battle_server_reconnect_failreason_room_destoryed", "房间已销毁"));
a8::UdpLog::Instance()->Debug
("房间已销毁 %s",
{
msg.room_uuid()
});
return;
}
if (room->GetRoomMode() != kChiJiMode) {
send_reconnect_failed(hdr.socket_handle, 1,
TEXT("battle_server_reconnect_failreason_only_chiji", "只有吃鸡模式支持重连"));
return;
}
Player* hum = room->GetPlayerByAccountId(msg.account_id());
if (!hum) {
send_reconnect_failed(hdr.socket_handle, 1,
TEXT("battle_server_reconnect_failreason_notfound_accountid", "accountid未在房间列表"));
return;
}
hum->_CMReconnect(hdr, msg);
}
void RoomMgr::_CMPing(f8::MsgHdr& hdr, const cs::CMPing& msg)
{
cs::SMPing respmsg;
GGListener::Instance()->SendToClient(hdr.socket_handle, 0, respmsg);
}
int RoomMgr::RoomNum()
{
return room_hash_.size();
}
int RoomMgr::OverRoomNum()
{
return over_room_hash_.size();
}
Room* RoomMgr::GetJoinableRoom(const cs::CMJoin& msg,
const RoomType_e self_room_type,
int game_times,
int creator_register_time,
int proto_version,
int channel
)
{
std::vector<std::vector<Room*>> group_rooms;
for (int i = 0; i < RT_Max; ++i) {
group_rooms.push_back(std::vector<Room*>());
}
for (auto& pair : inactive_room_hash_) {
Room* room = pair.second;
if (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);
}
}
if (!group_rooms[self_room_type].empty()) {
return group_rooms[self_room_type][rand() % group_rooms[self_room_type].size()];
}
if (self_room_type == RT_NewBrid) {
return CreateRoom(msg,
self_room_type,
game_times,
creator_register_time,
proto_version,
channel,
msg.mapid());
}
if (self_room_type == RT_MidBrid) {
return CreateRoom(msg,
self_room_type,
game_times,
creator_register_time,
proto_version,
channel,
msg.mapid());
}
for (int i = 0; i < RT_Max; ++i) {
for (Room* room : group_rooms[i]) {
if (room->GetRoomType() == self_room_type) {
return room;
}
}
}
return CreateRoom(msg,
self_room_type,
game_times,
creator_register_time,
proto_version,
channel,
msg.mapid());
}
Room* RoomMgr::GetJoinableRoom(MatchTeam* team)
{
for (auto& pair : inactive_room_hash_) {
Room* room = pair.second;
if (room->CanJoin(team)) {
return room;
}
}
int game_times = 0;
RoomType_e self_room_type = RT_OldBrid1;
time_t register_time = f8::ExtractRegisterTimeFromSessionId(team->GetOwner()->msg->session_id());
int proto_version = team->GetOwner()->msg->proto_version();
int channel = f8::ExtractChannelIdFromAccountId(team->GetOwner()->msg->account_id());
return CreateRoom(*team->GetOwner()->msg,
self_room_type,
game_times,
register_time,
proto_version,
channel,
team->GetOwner()->msg->mapid());
}
Room* RoomMgr::GetRoomByUuid(long long room_uuid)
{
auto itr = room_hash_.find(room_uuid);
return itr != room_hash_.end() ? itr->second : nullptr;
}
Room* RoomMgr::GetRoomByIdx(int room_idx)
{
auto itr = room_idx_hash_.find(room_idx);
return itr != room_idx_hash_.end() ? itr->second : nullptr;
}
void RoomMgr::AddOverRoom(long long room_uuid)
{
auto callback =
[] (const a8::XParams& param)
{
Room* room = RoomMgr::Instance()->GetRoomByUuid(param.sender);
if (room) {
RoomMgr::Instance()->room_hash_.erase(room->GetRoomUuid());
RoomMgr::Instance()->over_room_hash_[room->GetRoomUuid()] = room;
RoomMgr::Instance()->FreeOverRoom(param.sender);
}
};
inactive_room_hash_.erase(room_uuid);
Room* room = GetRoomByUuid(room_uuid);
if (room) {
room->added_to_over_room = true;
a8::Timer::Instance()->AddRepeatTimerAndAttach
(1000 * 5,
a8::XParams()
.SetSender(room_uuid),
callback,
&room->timer_attacher.timer_list_);
}
}
void RoomMgr::ActiveRoom(long long room_uuid)
{
inactive_room_hash_.erase(room_uuid);
}
void RoomMgr::ReportServerState(int instance_id, const std::string& host, int port)
{
auto on_ok =
[] (a8::XParams& param, a8::XObject& data)
{
a8::Timer::Instance()->AddDeadLineTimerAndAttach
(1000,
a8::XParams()
.SetSender(param.sender)
.SetParam1(param.param1)
.SetParam2(param.param2),
[] (const a8::XParams& param)
{
RoomMgr::Instance()->ReportServerState(
param.sender,
param.param1,
param.param2
);
},
&RoomMgr::Instance()->reportstate_timer_attacher_.timer_list_);
};
auto on_error =
[] (a8::XParams& param, const std::string& response)
{
a8::Timer::Instance()->AddDeadLineTimerAndAttach
(1000,
a8::XParams()
.SetSender(param.sender)
.SetParam1(param.param1)
.SetParam2(param.param2),
[] (const a8::XParams& param)
{
RoomMgr::Instance()->ReportServerState(
param.sender,
param.param1,
param.param2
);
},
&RoomMgr::Instance()->reportstate_timer_attacher_.timer_list_);
};
std::string url = a8::Format("http://%s:%d/webapp/index.php?c=GS&a=report&",
{
host,
port
});
a8::MutableXObject* url_params = a8::MutableXObject::NewObject();
url_params->SetVal("node_id", App::Instance()->node_id);
url_params->SetVal("instance_id", App::Instance()->instance_id);
url_params->SetVal("ip", JsonDataMgr::Instance()->ip);
url_params->SetVal("port", JsonDataMgr::Instance()->listen_port);
url_params->SetVal("online_num", PlayerMgr::Instance()->OnlineNum());
url_params->SetVal("room_num", RoomNum());
url_params->SetVal("channel", JsonDataMgr::Instance()->channel);
url_params->SetVal("alive_count", PerfMonitor::Instance()->real_alive_count);
url_params->SetVal("servicing", App::Instance()->servicing ? 1 : 0);
f8::HttpClientPool::Instance()->HttpGet(a8::XParams()
.SetSender(instance_id)
.SetParam1(host)
.SetParam2(port),
on_ok,
on_error,
url.c_str(),
*url_params,
rand() % MAX_SYS_HTTP_NUM
);
delete url_params;
}
void RoomMgr::FreeOverRoom(long long room_uuid)
{
auto itr = over_room_hash_.find(room_uuid);
if (itr != over_room_hash_.end()) {
--PerfMonitor::Instance()->room_num[itr->second->GetRoomType()];
itr->second->UnInit();
room_idx_hash_.erase(itr->second->GetRoomIdx());
delete itr->second;
over_room_hash_.erase(itr);
}
}
void RoomMgr::InstallReportStateTimer()
{
reportstate_timer_attacher_.ClearTimerList();
auto master_svr_cluster_conf = JsonDataMgr::Instance()->GetMasterServerClusterConf();
for (int i = 0; i < master_svr_cluster_conf->Size(); ++i) {
auto master_svr_conf = master_svr_cluster_conf->At(i);
int instance_id = master_svr_conf->At("instance_id")->AsXValue();
std::string remote_ip = master_svr_conf->At("ip")->AsXValue();
int remote_port = master_svr_conf->At("listen_port")->AsXValue();
a8::Timer::Instance()->AddDeadLineTimerAndAttach
(1000 + (i + 1),
a8::XParams()
.SetSender(instance_id)
.SetParam1(remote_ip)
.SetParam2(remote_port),
[] (const a8::XParams& param)
{
RoomMgr::Instance()->ReportServerState(
param.sender,
param.param1,
param.param2
);
},
&reportstate_timer_attacher_.timer_list_);
}
}
bool RoomMgr::IsLimitJoin()
{
return RoomNum() >= ROOM_NUM_UP_LIMIT ||
(
PerfMonitor::Instance()->real_alive_count >= HUM_NUM_DOWN_LIMIT
);
}
int RoomMgr::AllocRoomIdx()
{
do {
if (current_room_idx_ < 0) {
current_room_idx_ = 0;
}
if (current_room_idx_ >= (MAX_ROOM_IDX - 3)) {
current_room_idx_ = 0;
}
} while (GetRoomByIdx(++current_room_idx_));
return current_room_idx_;
}
Room* RoomMgr::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)
{
int room_idx = AllocRoomIdx();
if (room_idx < 1) {
return nullptr;
}
RoomInitInfo init_info;
{
init_info.room_idx = room_idx;
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;
init_info.creator_channel = creator_channel;
init_info.pve_instance_id = msg.pve_instance_id();
init_info.pve_human_num = std::max(1, msg.team_members_size());
#if 0
init_info.force_entry_newbie_room = msg.force_entry_newbie_room();
#endif
if (GetRoomByUuid(init_info.room_uuid)) {
A8_ABORT();
}
if (GetRoomByIdx(init_info.room_idx)) {
A8_ABORT();
}
}
Room* room = new Room();
MapMgr::Instance()->AttachRoom(room, init_info);
room->InitData(init_info);
room->Init();
inactive_room_hash_[room->GetRoomUuid()] = room;
room_hash_[room->GetRoomUuid()] = room;
room_idx_hash_[room->GetRoomIdx()] = room;
++PerfMonitor::Instance()->room_num[room->GetRoomType()];
#ifdef DEBUG
a8::UdpLog::Instance()->Debug("createroom room_idx:%d room_uuid:%d room_type:%d",
{
room->GetRoomIdx(),
room->GetRoomUuid(),
room->GetRoomType()
});
#endif
return room;
}
void RoomMgr::JoinErrorHandle(const cs::CMJoin& msg, int error_code, int socket_handle)
{
{
cs::SMJoinedNotify notifymsg;
notifymsg.set_error_code(error_code);
GGListener::Instance()->SendToClient(socket_handle, 0, notifymsg);
}
{
a8::Timer::Instance()->AddDeadLineTimer
(1000 * 2,
a8::XParams()
.SetSender(socket_handle),
[] (const a8::XParams& param)
{
GGListener::Instance()->ForceCloseChildSocket(param.sender);
});
}
a8::UdpLog::Instance()->Warning
("join error errcode:%d accountid:%s max_mainloop_rundelay:%d "
"room_num:%d player_num:%d online_num:%d",
{
error_code,
msg.account_id(),
PerfMonitor::Instance()->max_run_delay_time,
RoomMgr::Instance()->RoomNum(),
PerfMonitor::Instance()->entity_num[ET_Player],
PlayerMgr::Instance()->OnlineNum(),
});
}
bool RoomMgr::IsGM(const std::string& account_id)
{
return gm_hash_.find(account_id) != gm_hash_.end();
}
void RoomMgr::JoinTeam(MatchTeam* team)
{
Room* room = GetJoinableRoom(team);
if (!room) {
return;
}
room->AddTeam(team);
}
std::string RoomMgr::GenTeamHashData(const std::string& team_uuid, std::map<std::string, long long>* team_hash)
{
std::string data;
data += a8::Format("team_uuid:%s ", {team_uuid});
for (auto pair : *team_hash) {
data += a8::Format("%s->%d ", {pair.first, pair.second});
}
return data;
}
void RoomMgr::OnJoinRoomOk(const cs::CMJoin& msg, Player* hum)
{
if (msg.team_uuid().empty()) {
return;
}
std::map<std::string, long long>* team_hash = nullptr;
{
auto itr = team_room_hash_.find(msg.team_uuid());
if (itr == team_room_hash_.end()) {
team_room_hash_[msg.team_uuid()] = std::map<std::string, long long>();
itr = team_room_hash_.find(msg.team_uuid());
team_hash = &itr->second;
for (auto& team_member : msg.team_members()) {
team_hash->insert(std::make_pair(team_member.account_id(), 0));
}
a8::Timer::Instance()->AddDeadLineTimer
(1000 * 60,
a8::XParams()
.SetSender(msg.team_uuid()),
[] (const a8::XParams& params)
{
RoomMgr::Instance()->TeamRoomTimeOut(params.sender);
}
);
} else {
team_hash = &itr->second;
}
}
if (!team_hash) {
A8_ABORT();
}
hum->init_team_member_num = team_hash->size();
{
auto itr = team_hash->find(hum->account_id);
if (itr != team_hash->end()) {
itr->second = hum->room->GetRoomUuid();
} else {
a8::UdpLog::Instance()->Warning
("team_data:%s account_id:%s not exists",
{
GenTeamHashData(msg.team_uuid(), team_hash),
hum->account_id
});
}
}
}
void RoomMgr::TeamRoomTimeOut(const std::string& team_uuid)
{
std::map<std::string, long long>* team_hash = nullptr;
{
auto itr = team_room_hash_.find(team_uuid);
if (itr != team_room_hash_.end()) {
team_hash = &itr->second;
}
}
if (team_hash) {
bool ok = true;
for (auto pair : *team_hash) {
if (pair.second == 0) {
ok = false;
break;
}
}
if (!ok) {
a8::UdpLog::Instance()->Warning
("team match failed team_data:%s ",
{
GenTeamHashData(team_uuid, team_hash),
});
}
team_room_hash_.erase(team_uuid);
} else {
a8::UdpLog::Instance()->Warning
("team not found team_uuid:s",
{
team_uuid
});
}
}
void RoomMgr::SendGetBattleData(int mode,
std::vector<std::shared_ptr<cs::CMJoin>>& join_msgs,
std::function<
void(std::vector<std::shared_ptr<BattleDataContext>>&)> cb)
{
if (join_msgs.empty()) {
abort();
}
std::shared_ptr<std::vector<std::shared_ptr<BattleDataContext>>> result =
std::make_shared<std::vector<std::shared_ptr<BattleDataContext>>>();
bool is_old_version = false;
for (auto& msg : join_msgs) {
std::shared_ptr<BattleDataContext> context = std::make_shared<BattleDataContext>();
context->join_msg = msg;
context->battle_uuid = App::Instance()->NewUuid();
context->errcode = 100;
context->errmsg = "";
result->push_back(context);
if (msg->proto_version() < 2022032201) {
is_old_version = true;
}
}
{
std::string url;
JsonDataMgr::Instance()->GetApiUrl(url);
if (url.find('?') != std::string::npos) {
url += "&c=Battle&a=getBattleDataNew";
} else {
url += "?&c=Battle&a=getBattleDataNew";
}
auto url_params = a8::MutableXObject::CreateObject();
{
auto members = a8::MutableXObject::CreateArray();
int i = 0;
for (auto msg : join_msgs) {
auto member = a8::MutableXObject::CreateObject();
member->SetVal("account_id", msg->account_id());
member->SetVal("session_id", msg->session_id());
member->SetVal("hero_uniid", msg->hero_uniid());
member->SetVal("battle_uuid", result->at(i)->battle_uuid);
member->SetVal("weapon_uuid1",
msg->weapons().size() > 0 ? msg->weapons(0).weapon_uniid() : "");
member->SetVal("weapon_uuid2",
msg->weapons().size() > 1 ? msg->weapons(1).weapon_uniid() : "");
#if 0
member->SetVal("cmjoin", f8::PbToJson(msg.get()));
#endif
++i;
members->Push(*member.get());
}
url_params->SetVal("account_id", join_msgs[0]->account_id());
url_params->SetVal("session_id", join_msgs[0]->session_id());
url_params->SetVal("mode", mode);
url_params->SetVal("members", members->ToJsonStr());
}
HttpProxy::Instance()->HttpGet
(
a8::XParams()
.SetSender(new std::shared_ptr<std::vector<std::shared_ptr<BattleDataContext>>>(result))
.SetParam1(new std::function<
void(std::vector<std::shared_ptr<BattleDataContext>>&)>(cb)),
[] (a8::XParams& param, a8::XObject& data)
{
a8::UdpLog::Instance()->Info
("GetBattleData ok %s",
{
data.ToJsonStr()
});
auto result = (std::shared_ptr<std::vector<std::shared_ptr<BattleDataContext>>>*)param.sender.GetUserData();
auto cb = (std::function<
void(std::vector<std::shared_ptr<BattleDataContext>>&)>*)param.param1.GetUserData();
if (data.GetType() == a8::XOT_OBJECT) {
int match_mode = data.Get("match_mode");
RoomMgr::Instance()->SetMatchMode(match_mode ? 1 : 0);
if (data.HasKey("members")) {
auto members = data.At("members");
if (members->GetType() == a8::XOT_ARRAY && members->Size() == (*result->get()).size()) {
for (int i = 0; i < members->Size(); ++i) {
auto& ctx = (*result->get()).at(i);
auto member = members->At(i);
if (member->GetType() == a8::XOT_OBJECT) {
ctx->ParseResult(*member);
}
}
}
}
}
(*cb)(*result->get());
delete cb;
delete result;
},
[] (a8::XParams& param, const std::string& response)
{
a8::UdpLog::Instance()->Warning
("GetBattleData error %s",
{
response
});
auto result = (std::shared_ptr<std::vector<std::shared_ptr<BattleDataContext>>>*)param.sender.GetUserData();
auto cb = (std::function<
void(std::vector<std::shared_ptr<BattleDataContext>>&)>*)param.param1.GetUserData();
(*cb)(*result->get());
for (auto& context : *result->get()) {
}
delete cb;
delete result;
},
url.c_str(),
*url_params
);
}
}
void RoomMgr::SetMatchMode(int mode)
{
match_mode_ = mode;
}