1
This commit is contained in:
parent
f88b77ecad
commit
37aec4b915
@ -84,26 +84,28 @@ void CustomBattle::ParseResult(a8::XObject& obj)
|
|||||||
ob_team_->team_uuid_ = "";
|
ob_team_->team_uuid_ = "";
|
||||||
ob_team_->is_view_ = true;
|
ob_team_->is_view_ = true;
|
||||||
auto ob_list = obj.At("ob_list");
|
auto ob_list = obj.At("ob_list");
|
||||||
for (int i = 0; i < ob_list->Size(); ++i) {
|
if (ob_list && ob_list->IsArray()) {
|
||||||
auto member_obj = ob_list->At(i);
|
for (int i = 0; i < ob_list->Size(); ++i) {
|
||||||
if (!member_obj || !member_obj->IsObject()) {
|
auto member_obj = ob_list->At(i);
|
||||||
parse_ok_ = false;
|
if (!member_obj || !member_obj->IsObject()) {
|
||||||
return;
|
parse_ok_ = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto member = std::make_shared<CustomMember>();
|
||||||
|
member->team_ = ob_team_.get();
|
||||||
|
member->account_id_ = member_obj->Get("account_id").GetString();
|
||||||
|
member->session_id_ = member_obj->Get("session_id").GetString();
|
||||||
|
member->name_ = member_obj->Get("name").GetString();
|
||||||
|
member->sex_ = member_obj->Get("sex");
|
||||||
|
member->battle_context_ = std::make_shared<BattleDataContext>();
|
||||||
|
member->battle_context_->ParseResult(*member_obj);
|
||||||
|
if (!member->battle_context_->parse_ok) {
|
||||||
|
parse_ok_ = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
account_hash_[member->account_id_] = ob_team_;
|
||||||
|
ob_id_hash_[member->account_id_] = member;
|
||||||
}
|
}
|
||||||
auto member = std::make_shared<CustomMember>();
|
|
||||||
member->team_ = ob_team_.get();
|
|
||||||
member->account_id_ = member_obj->Get("account_id").GetString();
|
|
||||||
member->session_id_ = member_obj->Get("session_id").GetString();
|
|
||||||
member->name_ = member_obj->Get("name").GetString();
|
|
||||||
member->sex_ = member_obj->Get("sex");
|
|
||||||
member->battle_context_ = std::make_shared<BattleDataContext>();
|
|
||||||
member->battle_context_->ParseResult(*member_obj);
|
|
||||||
if (!member->battle_context_->parse_ok) {
|
|
||||||
parse_ok_ = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
account_hash_[member->account_id_] = ob_team_;
|
|
||||||
ob_id_hash_[member->account_id_] = member;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
const int CUSTOM_ROOM_PVP = 0;
|
||||||
|
const int CUSTOM_ROOM_MOBA = 1;
|
||||||
|
|
||||||
class Room;
|
class Room;
|
||||||
class CustomTeam;
|
class CustomTeam;
|
||||||
class CustomMember;
|
class CustomMember;
|
||||||
@ -32,10 +35,14 @@ class CustomBattle
|
|||||||
void TraverseMemberList(std::function<bool (CustomMember*)> func);
|
void TraverseMemberList(std::function<bool (CustomMember*)> func);
|
||||||
void TraverseTeamList(std::function<bool (std::shared_ptr<CustomTeam>)> cb);
|
void TraverseTeamList(std::function<bool (std::shared_ptr<CustomTeam>)> cb);
|
||||||
void TraverseObList(std::function<bool (std::shared_ptr<CustomMember>)> cb);
|
void TraverseObList(std::function<bool (std::shared_ptr<CustomMember>)> cb);
|
||||||
|
void SetCustomRoomType(int custom_room_type) { custom_room_type_ = custom_room_type_; }
|
||||||
|
bool IsPvp() { return custom_room_type_ == CUSTOM_ROOM_PVP; }
|
||||||
|
bool IsMoba() { return custom_room_type_ == CUSTOM_ROOM_MOBA; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool parse_ok_ = false;
|
bool parse_ok_ = false;
|
||||||
Room *room_ = nullptr;
|
Room *room_ = nullptr;
|
||||||
|
int custom_room_type_ = CUSTOM_ROOM_PVP;
|
||||||
std::string room_id_;
|
std::string room_id_;
|
||||||
std::string room_uuid_;
|
std::string room_uuid_;
|
||||||
int zone_id_ = 0;
|
int zone_id_ = 0;
|
||||||
|
@ -1,176 +0,0 @@
|
|||||||
#include "precompile.h"
|
|
||||||
|
|
||||||
#include <f8/app.h>
|
|
||||||
|
|
||||||
#include "mobabattle.h"
|
|
||||||
#include "netdata.h"
|
|
||||||
|
|
||||||
int MobaTeam::GetMemberNum()
|
|
||||||
{
|
|
||||||
return member_hash_.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MobaTeam::TraverseMember(std::function<bool (std::shared_ptr<MobaMember>)> cb)
|
|
||||||
{
|
|
||||||
for (auto& pair : member_hash_) {
|
|
||||||
if (!cb(pair.second)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<MobaTeam> MobaBattle::GetTeamByAccountId(const std::string& account_id)
|
|
||||||
{
|
|
||||||
auto itr = account_hash_.find(account_id);
|
|
||||||
return itr != account_hash_.end() ? itr->second : nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<MobaMember> MobaBattle::GetMemberByAccountId(const std::string& account_id)
|
|
||||||
{
|
|
||||||
auto itr = member_id_hash_.find(account_id);
|
|
||||||
return itr != member_id_hash_.end() ? itr->second : nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<MobaTeam> MobaBattle::GetTeamByTeamUuid(const std::string& team_uuid)
|
|
||||||
{
|
|
||||||
auto itr = uuid_hash_.find(team_uuid);
|
|
||||||
return itr != uuid_hash_.end() ? itr->second : nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
int MobaBattle::GetMemberNum()
|
|
||||||
{
|
|
||||||
return member_id_hash_.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
int MobaBattle::GetTeamNum()
|
|
||||||
{
|
|
||||||
return uuid_hash_.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MobaBattle::TraverseMemberList(std::function<bool (MobaMember*)> func)
|
|
||||||
{
|
|
||||||
for (auto& pair : member_id_hash_) {
|
|
||||||
if (!func(pair.second.get())) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MobaBattle::TraverseTeam(std::function<bool (std::shared_ptr<MobaTeam>)> cb)
|
|
||||||
{
|
|
||||||
for (auto& pair : uuid_hash_) {
|
|
||||||
if (!cb(pair.second)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MobaBattle::ParseResult(a8::XObject& obj)
|
|
||||||
{
|
|
||||||
if (!obj.HasKey("errcode")) {
|
|
||||||
parse_ok_ = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//room_id_ = obj.Get("room_id").GetString();
|
|
||||||
room_uuid_ = obj.Get("room_uuid").GetString();
|
|
||||||
zone_id_ = obj.Get("zone_id");
|
|
||||||
node_id_ = obj.Get("node_id");
|
|
||||||
start_time_ = obj.Get("start_time");
|
|
||||||
sign_ = obj.Get("sign").GetString();
|
|
||||||
|
|
||||||
auto team_list = obj.At("team_list");
|
|
||||||
if (!team_list || !team_list->IsArray()) {
|
|
||||||
parse_ok_ = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (int i = 0;i < team_list->Size(); ++i) {
|
|
||||||
auto team_obj = team_list->At(i);
|
|
||||||
if (!team_obj || !team_obj->IsObject()) {
|
|
||||||
parse_ok_ = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
std::string team_uuid = team_obj->Get("team_uuid").GetString();
|
|
||||||
int is_view = team_obj->Get("is_view").GetInt();
|
|
||||||
auto member_list = team_obj->At("members");
|
|
||||||
if (!member_list ||
|
|
||||||
!member_list->IsArray()) {
|
|
||||||
parse_ok_ = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
auto team = GetTeamByTeamUuid(team_uuid);
|
|
||||||
if (!team) {
|
|
||||||
team = std::make_shared<MobaTeam>();
|
|
||||||
team->team_uuid_ = team_uuid;
|
|
||||||
team->is_view_ = is_view ? true : false;
|
|
||||||
uuid_hash_[team->team_uuid_] = team;
|
|
||||||
}
|
|
||||||
for (int ii = 0; ii < member_list->Size(); ++ii) {
|
|
||||||
auto member_obj = member_list->At(ii);
|
|
||||||
if (!member_obj || !member_obj->IsObject()) {
|
|
||||||
parse_ok_ = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
auto member = std::make_shared<MobaMember>();
|
|
||||||
member->team_ = team.get();
|
|
||||||
member->account_id_ = member_obj->Get("account_id").GetString();
|
|
||||||
#ifdef MYDEBUG
|
|
||||||
member->account_id_ = member->account_id_ + "1111";
|
|
||||||
#endif
|
|
||||||
member->session_id_ = member_obj->Get("session_id").GetString();
|
|
||||||
member->name_ = member_obj->Get("name").GetString();
|
|
||||||
member->battle_context_ = std::make_shared<BattleDataContext>();
|
|
||||||
member->battle_context_->battle_uuid = f8::App::Instance()->NewGlobalUuid();
|
|
||||||
member->battle_context_->ParseResult(*member_obj);
|
|
||||||
if (!member->battle_context_->parse_ok) {
|
|
||||||
parse_ok_ = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
member_id_hash_[member->account_id_] = member;
|
|
||||||
team->member_hash_[member->account_id_] = member;
|
|
||||||
account_hash_[member->account_id_] = team;
|
|
||||||
#ifdef MYDEBUG
|
|
||||||
{
|
|
||||||
auto team = GetTeamByTeamUuid(team_uuid + "1111");
|
|
||||||
if (!team) {
|
|
||||||
team = std::make_shared<MobaTeam>();
|
|
||||||
team->team_uuid_ = team_uuid + "1111";
|
|
||||||
team->is_view_ = true;
|
|
||||||
ob_team_hash_[team->team_uuid_] = team;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto member = std::make_shared<MobaMember>();
|
|
||||||
member->team_ = team.get();
|
|
||||||
member->account_id_ = member_obj->Get("account_id").GetString();
|
|
||||||
member->session_id_ = member_obj->Get("session_id").GetString();
|
|
||||||
member->name_ = member_obj->Get("name").GetString();
|
|
||||||
member->battle_context_ = std::make_shared<BattleDataContext>();
|
|
||||||
member->battle_context_->battle_uuid = f8::App::Instance()->NewGlobalUuid();
|
|
||||||
member->battle_context_->ParseResult(*member_obj);
|
|
||||||
if (!member->battle_context_->parse_ok) {
|
|
||||||
abort();
|
|
||||||
}
|
|
||||||
ob_id_hash_[member->account_id_] = member;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
raw_data_ = std::make_shared<a8::XObject>();
|
|
||||||
obj.DeepCopy(*raw_data_);
|
|
||||||
parse_ok_ = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MobaBattle::TraverseObList(std::function<bool (std::shared_ptr<MobaMember>)> cb)
|
|
||||||
{
|
|
||||||
for (auto& pair : ob_id_hash_) {
|
|
||||||
if (!cb(pair.second)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<MobaMember> MobaBattle::GetObByAccountId(const std::string& account_id)
|
|
||||||
{
|
|
||||||
auto itr = ob_id_hash_.find(account_id);
|
|
||||||
return itr != ob_id_hash_.end() ? itr->second : nullptr;
|
|
||||||
}
|
|
@ -1,96 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
class Room;
|
|
||||||
class MobaTeam;
|
|
||||||
class MobaMember;
|
|
||||||
class Player;
|
|
||||||
struct BattleDataContext;
|
|
||||||
|
|
||||||
class MobaMember
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
void Join(Player* hum);
|
|
||||||
MobaTeam* GetTeam() { return team_; }
|
|
||||||
bool IsJoined() { return joined_; }
|
|
||||||
int GetJoinTime() { return join_time_; }
|
|
||||||
bool IsView();
|
|
||||||
const std::string& GetAccountId() { return account_id_; }
|
|
||||||
const std::string& GetSessionId() { return session_id_; }
|
|
||||||
const std::string& GetName() { return name_; }
|
|
||||||
const std::string& GetAvatarUrl() { return avatar_url_; }
|
|
||||||
int GetHeadFrame() { return head_frame_; }
|
|
||||||
int GetSex() { return sex_; }
|
|
||||||
std::shared_ptr<BattleDataContext>& GetNetData() { return battle_context_; };
|
|
||||||
|
|
||||||
private:
|
|
||||||
MobaTeam *team_ = nullptr;
|
|
||||||
bool joined_ = false;
|
|
||||||
int join_time_ = 0;
|
|
||||||
std::string account_id_;
|
|
||||||
std::string session_id_;
|
|
||||||
std::string name_;
|
|
||||||
std::string avatar_url_;
|
|
||||||
int head_frame_ = 0;
|
|
||||||
int sex_ = 0;
|
|
||||||
std::shared_ptr<BattleDataContext> battle_context_;
|
|
||||||
friend class MobaBattle;
|
|
||||||
};
|
|
||||||
|
|
||||||
class MobaTeam
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
std::string GetTeamUuid() { return team_uuid_; }
|
|
||||||
int GetMemberNum();
|
|
||||||
void TraverseMember(std::function<bool (std::shared_ptr<MobaMember>)> cb);
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::string team_uuid_;
|
|
||||||
bool is_view_ = false;
|
|
||||||
std::map<std::string, std::shared_ptr<MobaMember>> member_hash_;
|
|
||||||
friend class MobaBattle;
|
|
||||||
};
|
|
||||||
|
|
||||||
class MobaBattle
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
void Init();
|
|
||||||
void UnInit();
|
|
||||||
|
|
||||||
bool GetParseOk() { return parse_ok_; }
|
|
||||||
Room* GetRoom() { return room_; }
|
|
||||||
void SetRoom(Room* room) { room_ = room; }
|
|
||||||
const std::string& GetRoomUuid() { return room_uuid_; }
|
|
||||||
const std::string& GetSign() { return sign_; }
|
|
||||||
const std::shared_ptr<a8::XObject>& GetRawData() { return raw_data_; }
|
|
||||||
int GetZoneId() { return zone_id_; }
|
|
||||||
int GetNodeId() { return zone_id_; }
|
|
||||||
int GetStartTime() { return start_time_; }
|
|
||||||
void ParseResult(a8::XObject& obj);
|
|
||||||
std::shared_ptr<MobaTeam> GetTeamByAccountId(const std::string& account_id);
|
|
||||||
std::shared_ptr<MobaMember> GetMemberByAccountId(const std::string& account_id);
|
|
||||||
std::shared_ptr<MobaMember> GetObByAccountId(const std::string& account_id);
|
|
||||||
std::shared_ptr<MobaTeam> GetTeamByTeamUuid(const std::string& team_uuid);
|
|
||||||
int GetMemberNum();
|
|
||||||
int GetTeamNum();
|
|
||||||
void TraverseMemberList(std::function<bool (MobaMember*)> func);
|
|
||||||
void TraverseObList(std::function<bool (std::shared_ptr<MobaMember>)> func);
|
|
||||||
void TraverseTeam(std::function<bool (std::shared_ptr<MobaTeam>)> cb);
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool parse_ok_ = false;
|
|
||||||
Room *room_ = nullptr;
|
|
||||||
std::string room_uuid_;
|
|
||||||
int zone_id_ = 0;
|
|
||||||
int node_id_ = 0;
|
|
||||||
int start_time_ = 0;
|
|
||||||
std::string sign_;
|
|
||||||
std::shared_ptr<a8::XObject> raw_data_;
|
|
||||||
std::map<std::string, std::shared_ptr<MobaTeam>> uuid_hash_;
|
|
||||||
std::map<std::string, std::shared_ptr<MobaTeam>> ob_team_hash_;
|
|
||||||
std::map<std::string, std::shared_ptr<MobaTeam>> account_hash_;
|
|
||||||
std::map<std::string, std::shared_ptr<MobaMember>> member_id_hash_;
|
|
||||||
std::map<std::string, std::shared_ptr<MobaMember>> ob_id_hash_;
|
|
||||||
};
|
|
@ -46,7 +46,6 @@
|
|||||||
#include "sandtable.h"
|
#include "sandtable.h"
|
||||||
#include "frameeventdata.h"
|
#include "frameeventdata.h"
|
||||||
#include "batchsync.h"
|
#include "batchsync.h"
|
||||||
#include "mobabattle.h"
|
|
||||||
#include "roommgr.h"
|
#include "roommgr.h"
|
||||||
#include "bornpoint.h"
|
#include "bornpoint.h"
|
||||||
#include "roomob.h"
|
#include "roomob.h"
|
||||||
@ -2548,225 +2547,6 @@ void Room::NotifyKillList(const std::vector<int>& uniid_list)
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
int Room::InitWithMobaBattle(long ip_saddr, int socket_handle, std::shared_ptr<cs::CMJoin> msg,
|
|
||||||
std::shared_ptr<MobaBattle> p)
|
|
||||||
{
|
|
||||||
std::vector<std::shared_ptr<MobaTeam>> moba_teams;
|
|
||||||
p->TraverseTeam
|
|
||||||
(
|
|
||||||
[&moba_teams] (std::shared_ptr<MobaTeam> team) -> bool
|
|
||||||
{
|
|
||||||
moba_teams.push_back(team);
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
if (moba_teams.size() < 1 ||
|
|
||||||
moba_teams.size() > 2) {
|
|
||||||
abort();
|
|
||||||
}
|
|
||||||
std::vector<std::shared_ptr<Team>> room_teams;
|
|
||||||
{
|
|
||||||
auto new_team = NewTeam();
|
|
||||||
new_team->SetInitTeamMemberNum(0);
|
|
||||||
new_team->SetAutoFill(true);
|
|
||||||
room_teams.push_back(new_team);
|
|
||||||
moba_team_a_ = new_team.get();
|
|
||||||
}
|
|
||||||
{
|
|
||||||
auto new_team = NewTeam();
|
|
||||||
new_team->SetInitTeamMemberNum(0);
|
|
||||||
new_team->SetAutoFill(true);
|
|
||||||
room_teams.push_back(new_team);
|
|
||||||
moba_team_b_ = new_team.get();
|
|
||||||
}
|
|
||||||
cs::CMJoin join_msg = *msg;
|
|
||||||
for (size_t i = 0; i < moba_teams.size(); ++i) {
|
|
||||||
auto new_team = room_teams.at(i);
|
|
||||||
if (i == 1 && moba_teams.at(0)->GetTeamUuid() == moba_teams.at(1)->GetTeamUuid()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
new_team->SetInitTeamMemberNum(room_teams.at(i)->GetMemberNum());
|
|
||||||
moba_teams.at(i)->TraverseMember
|
|
||||||
(
|
|
||||||
[ip_saddr, socket_handle, join_msg, p, new_team] (std::shared_ptr<MobaMember> m) mutable -> bool
|
|
||||||
{
|
|
||||||
Player* hum = p->GetRoom()->NewPlayer();
|
|
||||||
//hum->ip_saddr = ip_saddr;
|
|
||||||
//hum->socket_handle = socket_handle;
|
|
||||||
hum->name = m->GetName();
|
|
||||||
hum->room = p->GetRoom();
|
|
||||||
hum->proto_version = join_msg.proto_version();
|
|
||||||
#if 0
|
|
||||||
hum->hero_uniid = a8::XValue(join_msg->hero_uniid());
|
|
||||||
#endif
|
|
||||||
hum->battle_uuid = m->GetNetData()->battle_uuid;
|
|
||||||
hum->is_valid_battle = m->GetNetData()->is_valid_battle;
|
|
||||||
hum->payload = m->GetNetData()->payload;
|
|
||||||
#if 1
|
|
||||||
join_msg.set_account_id(m->GetAccountId());
|
|
||||||
join_msg.set_session_id(m->GetSessionId());
|
|
||||||
join_msg.set_team_uuid(m->GetTeam()->GetTeamUuid());
|
|
||||||
join_msg.set_name(m->GetName());
|
|
||||||
join_msg.set_avatar_url(m->GetAvatarUrl());
|
|
||||||
join_msg.set_head_frame(m->GetHeadFrame());
|
|
||||||
join_msg.set_sex(m->GetSex());
|
|
||||||
join_msg.set_hero_id(m->GetNetData()->GetHeroId());
|
|
||||||
#endif
|
|
||||||
PlayerMgr::Instance()->
|
|
||||||
CreatePlayerByCMJoin(hum,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
join_msg
|
|
||||||
);
|
|
||||||
hum->meta = mt::Hero::GetById(join_msg.hero_id());
|
|
||||||
if (!hum->meta) {
|
|
||||||
hum->meta = mt::Param::s().human_meta;
|
|
||||||
}
|
|
||||||
hum->SetNetData(m->GetNetData());
|
|
||||||
hum->GetNetData()->Init(hum);
|
|
||||||
{
|
|
||||||
long long hero_uniid = 0;
|
|
||||||
int hero_lv = 1;
|
|
||||||
int quality = 1;
|
|
||||||
hum->GetNetData()->GetHeroLvQuality(hero_uniid, hero_lv, quality);
|
|
||||||
hum->hero_uniid = hero_uniid;
|
|
||||||
}
|
|
||||||
p->GetRoom()->AddPlayer(hum);
|
|
||||||
hum->ProcSkillList();
|
|
||||||
hum->SetHP(hum->GetNetData()->GetMaxHP());
|
|
||||||
hum->SetMaxHP(hum->GetHP());
|
|
||||||
PlayerMgr::Instance()->IncAccountNum(join_msg.account_id());
|
|
||||||
RoomMgr::Instance()->OnJoinRoomOk(join_msg, hum);
|
|
||||||
new_team->AddMember(hum);
|
|
||||||
#ifdef MYDEBUG
|
|
||||||
a8::XPrintf("moba init1 uniid:%d team_id:%d side:%d\n",
|
|
||||||
{
|
|
||||||
hum->GetUniId(),
|
|
||||||
hum->GetTeam()->GetTeamId(),
|
|
||||||
hum->side
|
|
||||||
});
|
|
||||||
#endif
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
//int side = a8::RandEx(1, 2);
|
|
||||||
int side = 1;
|
|
||||||
for (size_t i = 0; i < 2; ++i) {
|
|
||||||
auto team = room_teams.at(i);
|
|
||||||
if (team->GetMemberNum() < MAX_TEAM_NUM) {
|
|
||||||
CreateAndroid(MAX_TEAM_NUM - team->GetMemberNum(), team);
|
|
||||||
}
|
|
||||||
team->TraverseMembers
|
|
||||||
(
|
|
||||||
[this, side] (Human* hum) -> bool
|
|
||||||
{
|
|
||||||
hum->side = side;
|
|
||||||
std::shared_ptr<BornPoint> born_point = std::make_shared<BornPoint>();
|
|
||||||
born_point->wo_meta = std::get<0>(GetMapMeta()->moba_born_points.at(side - 1));
|
|
||||||
hum->SetBornPoint(born_point);
|
|
||||||
hum->InitMobaRoad();
|
|
||||||
#ifdef MYDEBUG
|
|
||||||
a8::XPrintf("moba init uniid:%d team_id:%d side:%d wo_meta:%d\n",
|
|
||||||
{
|
|
||||||
hum->GetUniId(),
|
|
||||||
hum->GetTeam()->GetTeamId(),
|
|
||||||
hum->side,
|
|
||||||
(long long)hum->GetBornPoint()->wo_meta.get()
|
|
||||||
});
|
|
||||||
#endif
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
if (side == 1) {
|
|
||||||
side = 2;
|
|
||||||
} else {
|
|
||||||
side = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
{
|
|
||||||
p->TraverseObList
|
|
||||||
(
|
|
||||||
[ip_saddr, socket_handle, join_msg, p] (std::shared_ptr<MobaMember> m) mutable -> bool
|
|
||||||
{
|
|
||||||
Player* hum = p->GetRoom()->NewPlayer();
|
|
||||||
//hum->ip_saddr = ip_saddr;
|
|
||||||
//hum->socket_handle = socket_handle;
|
|
||||||
hum->name = m->GetName();
|
|
||||||
hum->room = p->GetRoom();
|
|
||||||
hum->proto_version = join_msg.proto_version();
|
|
||||||
#if 0
|
|
||||||
hum->hero_uniid = a8::XValue(join_msg->hero_uniid());
|
|
||||||
#endif
|
|
||||||
hum->battle_uuid = m->GetNetData()->battle_uuid;
|
|
||||||
hum->is_valid_battle = m->GetNetData()->is_valid_battle;
|
|
||||||
hum->payload = m->GetNetData()->payload;
|
|
||||||
#if 1
|
|
||||||
join_msg.set_account_id(m->GetAccountId());
|
|
||||||
join_msg.set_session_id(m->GetSessionId());
|
|
||||||
join_msg.set_team_uuid(m->GetTeam()->GetTeamUuid());
|
|
||||||
join_msg.set_name(m->GetName());
|
|
||||||
join_msg.set_avatar_url(m->GetAvatarUrl());
|
|
||||||
join_msg.set_head_frame(m->GetHeadFrame());
|
|
||||||
join_msg.set_sex(m->GetSex());
|
|
||||||
join_msg.set_hero_id(m->GetNetData()->GetHeroId());
|
|
||||||
#endif
|
|
||||||
PlayerMgr::Instance()->
|
|
||||||
CreatePlayerByCMJoin(hum,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
join_msg
|
|
||||||
);
|
|
||||||
hum->meta = mt::Hero::GetById(join_msg.hero_id());
|
|
||||||
if (!hum->meta) {
|
|
||||||
hum->meta = mt::Param::s().human_meta;
|
|
||||||
}
|
|
||||||
hum->SetNetData(m->GetNetData());
|
|
||||||
hum->GetNetData()->Init(hum);
|
|
||||||
{
|
|
||||||
long long hero_uniid = 0;
|
|
||||||
int hero_lv = 1;
|
|
||||||
int quality = 1;
|
|
||||||
hum->GetNetData()->GetHeroLvQuality(hero_uniid, hero_lv, quality);
|
|
||||||
hum->hero_uniid = hero_uniid;
|
|
||||||
}
|
|
||||||
a8::SetBitFlag(hum->status, CS_IsOb);
|
|
||||||
p->GetRoom()->GetRoomOb()->AddOb(hum);
|
|
||||||
p->GetRoom()->AddPlayer(hum);
|
|
||||||
hum->ProcSkillList();
|
|
||||||
hum->SetHP(hum->GetNetData()->GetMaxHP());
|
|
||||||
hum->SetMaxHP(hum->GetHP());
|
|
||||||
PlayerMgr::Instance()->IncAccountNum(join_msg.account_id());
|
|
||||||
RoomMgr::Instance()->OnJoinRoomOk(join_msg, hum);
|
|
||||||
//new_team->AddMember(hum);
|
|
||||||
//hum->ReJoin(ip_saddr, socket_handle, msg, p);
|
|
||||||
#ifdef MYDEBUG
|
|
||||||
a8::XPrintf("moba init11 uniid:%d team_id:%d side:%d\n",
|
|
||||||
{
|
|
||||||
hum->GetUniId(),
|
|
||||||
hum->GetTeam()->GetTeamId(),
|
|
||||||
hum->side
|
|
||||||
});
|
|
||||||
#endif
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
#if 1
|
|
||||||
{
|
|
||||||
auto hum = GetPlayerByAccountId(msg->account_id());
|
|
||||||
if (hum) {
|
|
||||||
hum->ReJoin(ip_saddr, socket_handle, msg);
|
|
||||||
} else {
|
|
||||||
auto hum = p->GetRoom()->GetRoomOb()->GetByAccountId(msg->account_id());
|
|
||||||
if (hum) {
|
|
||||||
hum->ReJoin(ip_saddr, socket_handle, msg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#ifdef MYDEBUG
|
|
||||||
a8::XPrintf("InitWithMobaBattle\n", {});
|
|
||||||
#endif
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Room::InitWithCustomBattle(long ip_saddr, int socket_handle, std::shared_ptr<cs::CMJoin> msg,
|
int Room::InitWithCustomBattle(long ip_saddr, int socket_handle, std::shared_ptr<cs::CMJoin> msg,
|
||||||
std::shared_ptr<CustomBattle> p)
|
std::shared_ptr<CustomBattle> p)
|
||||||
{
|
{
|
||||||
|
@ -42,7 +42,6 @@ struct FrameEventData;
|
|||||||
class SandTable;
|
class SandTable;
|
||||||
class BatchSync;
|
class BatchSync;
|
||||||
class CustomBattle;
|
class CustomBattle;
|
||||||
class MobaBattle;
|
|
||||||
class RoomAgent;
|
class RoomAgent;
|
||||||
class RoomOb;
|
class RoomOb;
|
||||||
|
|
||||||
@ -284,8 +283,6 @@ public:
|
|||||||
Team* GetMobaEnemyTeam(Team* self_team);
|
Team* GetMobaEnemyTeam(Team* self_team);
|
||||||
RoomAgent* GetRoomAgent() { return room_agent_; }
|
RoomAgent* GetRoomAgent() { return room_agent_; }
|
||||||
int GenShotUniid() { return ++current_shot_uniid_; }
|
int GenShotUniid() { return ++current_shot_uniid_; }
|
||||||
int InitWithMobaBattle(long ip_saddr, int socket_handle, std::shared_ptr<cs::CMJoin> msg,
|
|
||||||
std::shared_ptr<MobaBattle> p);
|
|
||||||
int InitWithCustomBattle(long ip_saddr, int socket_handle, std::shared_ptr<cs::CMJoin> msg,
|
int InitWithCustomBattle(long ip_saddr, int socket_handle, std::shared_ptr<cs::CMJoin> msg,
|
||||||
std::shared_ptr<CustomBattle> p);
|
std::shared_ptr<CustomBattle> p);
|
||||||
void CreateAndroid(int android_num, std::shared_ptr<Team> team = nullptr);
|
void CreateAndroid(int android_num, std::shared_ptr<Team> team = nullptr);
|
||||||
|
@ -24,7 +24,6 @@
|
|||||||
#include "custom_battle.h"
|
#include "custom_battle.h"
|
||||||
#include "custom_team.h"
|
#include "custom_team.h"
|
||||||
#include "custom_member.h"
|
#include "custom_member.h"
|
||||||
#include "mobabattle.h"
|
|
||||||
#include "tracemgr.h"
|
#include "tracemgr.h"
|
||||||
|
|
||||||
#include "mt/Param.h"
|
#include "mt/Param.h"
|
||||||
@ -44,9 +43,6 @@
|
|||||||
static const int ROOM_NUM_UP_LIMIT = 1000;
|
static const int ROOM_NUM_UP_LIMIT = 1000;
|
||||||
static const int HUM_NUM_DOWN_LIMIT = 2500;
|
static const int HUM_NUM_DOWN_LIMIT = 2500;
|
||||||
|
|
||||||
static const int CUSTOM_ROOM_PVP = 0;
|
|
||||||
static const int CUSTOM_ROOM_MOBA = 1;
|
|
||||||
|
|
||||||
static RoomType_e GetHumanRoomType(const std::shared_ptr<BattleDataContext> netdata)
|
static RoomType_e GetHumanRoomType(const std::shared_ptr<BattleDataContext> netdata)
|
||||||
{
|
{
|
||||||
long long hero_uniid = 0;
|
long long hero_uniid = 0;
|
||||||
@ -1017,18 +1013,6 @@ std::shared_ptr<CustomBattle> RoomMgr::GetHisCustomRoom(const std::string& room_
|
|||||||
return itr != his_custom_room_hash_.end() ? itr->second : nullptr;
|
return itr != his_custom_room_hash_.end() ? itr->second : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<MobaBattle> RoomMgr::GetMobaRoom(const std::string& room_uuid)
|
|
||||||
{
|
|
||||||
auto itr = moba_room_hash_.find(room_uuid);
|
|
||||||
return itr != moba_room_hash_.end() ? itr->second : nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<MobaBattle> RoomMgr::GetHisMobaRoom(const std::string& room_uuid)
|
|
||||||
{
|
|
||||||
auto itr = his_moba_room_hash_.find(room_uuid);
|
|
||||||
return itr != his_moba_room_hash_.end() ? itr->second : nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void RoomMgr::_CMJoinCustomBattle(f8::MsgHdr* hdr, const cs::CMJoin& msg, int custom_room_type)
|
void RoomMgr::_CMJoinCustomBattle(f8::MsgHdr* hdr, const cs::CMJoin& msg, int custom_room_type)
|
||||||
{
|
{
|
||||||
if (msg.payload_data().empty()) {
|
if (msg.payload_data().empty()) {
|
||||||
@ -1047,32 +1031,37 @@ void RoomMgr::_CMJoinCustomBattle(f8::MsgHdr* hdr, const cs::CMJoin& msg, int cu
|
|||||||
RoomMgr::Instance()->JoinErrorHandle(*join_msg, 2, socket_handle);
|
RoomMgr::Instance()->JoinErrorHandle(*join_msg, 2, socket_handle);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (f8::App::Instance()->GetNowTime() - p->GetStartTime() > 30) {
|
auto member = p->GetMemberByAccountId(join_msg->account_id());
|
||||||
RoomMgr::Instance()->JoinErrorHandle(*join_msg, 2, socket_handle);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
auto team = p->GetTeamByAccountId(msg.account_id());
|
|
||||||
if (!team) {
|
|
||||||
RoomMgr::Instance()->JoinErrorHandle(*join_msg, 2, socket_handle);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
auto member = team->GetMember(msg.account_id());
|
|
||||||
if (!member) {
|
if (!member) {
|
||||||
RoomMgr::Instance()->JoinErrorHandle(*join_msg, 2, socket_handle);
|
member = p->GetObByAccountId(join_msg->account_id());
|
||||||
|
if (!member) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (p->IsMoba()) {
|
||||||
|
if (p->GetTeamNum() < 0 ||
|
||||||
|
p->GetTeamNum() > 2) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (p->GetRoom()) {
|
||||||
|
if (p->GetRoom()->GetGasData().GetGasMode() != GasInactive) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto hum = p->GetRoom()->GetPlayerByAccountId(join_msg->account_id());
|
||||||
|
if (hum) {
|
||||||
|
hum->ReJoin(ip_saddr, socket_handle, join_msg);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!p->CanAdd(join_msg->account_id(), join_msg->session_id())) {
|
int game_times = 0;
|
||||||
RoomMgr::Instance()->JoinErrorHandle(*join_msg, 2, socket_handle);
|
RoomType_e self_room_type = RoomType_OldBrid1;
|
||||||
return;
|
time_t register_time = f8::ExtractRegisterTimeFromSessionId(msg.session_id());
|
||||||
}
|
int proto_version = msg.proto_version();
|
||||||
member->GetNetData()->join_msg = join_msg;
|
int channel = f8::ExtractChannelIdFromAccountId(msg.account_id());
|
||||||
if (!p->GetRoom()) {
|
std::shared_ptr<Room> room = nullptr;
|
||||||
int game_times = 0;
|
if (p->IsPvp()) {
|
||||||
RoomType_e self_room_type = GetHumanRoomType(member->GetNetData());
|
room = RoomMgr::Instance()->CreateRoom
|
||||||
time_t register_time = f8::ExtractRegisterTimeFromSessionId(msg.session_id());
|
|
||||||
int proto_version = msg.proto_version();
|
|
||||||
int channel = f8::ExtractChannelIdFromAccountId(msg.account_id());
|
|
||||||
auto room = RoomMgr::Instance()->CreateRoom
|
|
||||||
(*join_msg,
|
(*join_msg,
|
||||||
self_room_type,
|
self_room_type,
|
||||||
game_times,
|
game_times,
|
||||||
@ -1081,51 +1070,26 @@ void RoomMgr::_CMJoinCustomBattle(f8::MsgHdr* hdr, const cs::CMJoin& msg, int cu
|
|||||||
channel,
|
channel,
|
||||||
msg.mapid(),
|
msg.mapid(),
|
||||||
p);
|
p);
|
||||||
p->SetRoom(room.get());
|
} else {
|
||||||
|
room = RoomMgr::Instance()->CreateRoom
|
||||||
|
(*join_msg,
|
||||||
|
self_room_type,
|
||||||
|
game_times,
|
||||||
|
register_time,
|
||||||
|
join_msg->proto_version(),
|
||||||
|
channel,
|
||||||
|
msg.mapid(),
|
||||||
|
nullptr);
|
||||||
}
|
}
|
||||||
Player* hum = p->GetRoom()->NewPlayer();
|
p->SetRoom(room.get());
|
||||||
hum->room = p->GetRoom();
|
room->InitWithCustomBattle(ip_saddr, socket_handle, join_msg, p);
|
||||||
hum->proto_version = msg.proto_version();
|
|
||||||
#if 0
|
|
||||||
hum->hero_uniid = a8::XValue(msg.hero_uniid());
|
|
||||||
#endif
|
|
||||||
hum->battle_uuid = member->GetNetData()->battle_uuid;
|
|
||||||
hum->is_valid_battle = member->GetNetData()->is_valid_battle;
|
|
||||||
hum->payload = member->GetNetData()->payload;
|
|
||||||
msg.set_session_id(member->GetSessionId());
|
|
||||||
msg.set_team_uuid(team->GetTeamUuid());
|
|
||||||
PlayerMgr::Instance()->
|
|
||||||
CreatePlayerByCMJoin(hum,
|
|
||||||
ip_saddr,
|
|
||||||
socket_handle,
|
|
||||||
msg
|
|
||||||
);
|
|
||||||
hum->meta = mt::Hero::GetById(msg.hero_id());
|
|
||||||
if (!hum->meta) {
|
|
||||||
hum->meta = mt::Param::s().human_meta;
|
|
||||||
}
|
|
||||||
hum->SetNetData(member->GetNetData());
|
|
||||||
hum->GetNetData()->Init(hum);
|
|
||||||
{
|
|
||||||
long long hero_uniid = 0;
|
|
||||||
int hero_lv = 1;
|
|
||||||
int quality = 1;
|
|
||||||
hum->GetNetData()->GetHeroLvQuality(hero_uniid, hero_lv, quality);
|
|
||||||
hum->hero_uniid = hero_uniid;
|
|
||||||
}
|
|
||||||
p->GetRoom()->AddPlayer(hum);
|
|
||||||
hum->ProcSkillList();
|
|
||||||
hum->SetHP(hum->GetNetData()->GetMaxHP());
|
|
||||||
hum->SetMaxHP(hum->GetHP());
|
|
||||||
member->Join(hum);
|
|
||||||
PlayerMgr::Instance()->IncAccountNum(msg.account_id());
|
|
||||||
RoomMgr::Instance()->OnJoinRoomOk(msg, hum);
|
|
||||||
};
|
};
|
||||||
SendGetCustomBattleData(join_msg, cb);
|
SendGetCustomBattleData(join_msg, cb, custom_room_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RoomMgr::SendGetCustomBattleData(std::shared_ptr<cs::CMJoin> join_msg,
|
void RoomMgr::SendGetCustomBattleData(std::shared_ptr<cs::CMJoin> join_msg,
|
||||||
std::function<void(int, const std::string, std::shared_ptr<CustomBattle>)> cb)
|
std::function<void(int, const std::string, std::shared_ptr<CustomBattle>)> cb,
|
||||||
|
int custom_room_type)
|
||||||
{
|
{
|
||||||
auto pos = join_msg->payload_data().find('|');
|
auto pos = join_msg->payload_data().find('|');
|
||||||
std::string head;
|
std::string head;
|
||||||
@ -1165,10 +1129,18 @@ void RoomMgr::SendGetCustomBattleData(std::shared_ptr<cs::CMJoin> join_msg,
|
|||||||
{
|
{
|
||||||
std::string url;
|
std::string url;
|
||||||
JsonDataMgr::Instance()->GetApiUrl(url);
|
JsonDataMgr::Instance()->GetApiUrl(url);
|
||||||
if (url.find('?') != std::string::npos) {
|
if (custom_room_type == CUSTOM_ROOM_MOBA) {
|
||||||
url += "&c=Battle&a=getCustomBattleData";
|
if (url.find('?') != std::string::npos) {
|
||||||
|
url += "&c=Battle&a=getMobaBattleData";
|
||||||
|
} else {
|
||||||
|
url += "?&c=Battle&a=getMobaBattleData";
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
url += "?&c=Battle&a=getCustomBattleData";
|
if (url.find('?') != std::string::npos) {
|
||||||
|
url += "&c=Battle&a=getCustomBattleData";
|
||||||
|
} else {
|
||||||
|
url += "?&c=Battle&a=getCustomBattleData";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
auto url_params = a8::MutableXObject::CreateObject();
|
auto url_params = a8::MutableXObject::CreateObject();
|
||||||
url_params->SetVal("account_id", join_msg->account_id());
|
url_params->SetVal("account_id", join_msg->account_id());
|
||||||
@ -1176,7 +1148,7 @@ void RoomMgr::SendGetCustomBattleData(std::shared_ptr<cs::CMJoin> join_msg,
|
|||||||
url_params->SetVal("__POST", join_msg->payload_data());
|
url_params->SetVal("__POST", join_msg->payload_data());
|
||||||
HttpProxy::Instance()->HttpGet
|
HttpProxy::Instance()->HttpGet
|
||||||
(
|
(
|
||||||
[cb]
|
[cb, custom_room_type]
|
||||||
(bool ok, a8::XObject* rsp_obj, f8::HttpContext* ctx)
|
(bool ok, a8::XObject* rsp_obj, f8::HttpContext* ctx)
|
||||||
{
|
{
|
||||||
if (ok) {
|
if (ok) {
|
||||||
@ -1208,6 +1180,7 @@ void RoomMgr::SendGetCustomBattleData(std::shared_ptr<cs::CMJoin> join_msg,
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto custom_battle = std::make_shared<CustomBattle>();
|
auto custom_battle = std::make_shared<CustomBattle>();
|
||||||
|
custom_battle->SetCustomRoomType(custom_room_type);
|
||||||
custom_battle->ParseResult(*rsp_obj);
|
custom_battle->ParseResult(*rsp_obj);
|
||||||
if (custom_battle->GetParseOk()) {
|
if (custom_battle->GetParseOk()) {
|
||||||
cb(0, "", custom_battle);
|
cb(0, "", custom_battle);
|
||||||
@ -1230,62 +1203,6 @@ void RoomMgr::SendGetCustomBattleData(std::shared_ptr<cs::CMJoin> join_msg,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RoomMgr::_CMJoinMoba(f8::MsgHdr* hdr, const cs::CMJoin& msg)
|
|
||||||
{
|
|
||||||
std::shared_ptr<cs::CMJoin> join_msg = std::make_shared<cs::CMJoin>();
|
|
||||||
*join_msg = msg;
|
|
||||||
auto ip_saddr = hdr->ip_saddr;
|
|
||||||
auto socket_handle = hdr->socket_handle;
|
|
||||||
auto cb =
|
|
||||||
[join_msg, ip_saddr, socket_handle]
|
|
||||||
(int errcode, const std::string errmsg, std::shared_ptr<MobaBattle> p)
|
|
||||||
{
|
|
||||||
auto& msg = *join_msg;
|
|
||||||
if (errcode) {
|
|
||||||
RoomMgr::Instance()->JoinErrorHandle(*join_msg, 2, socket_handle);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
auto member = p->GetMemberByAccountId(join_msg->account_id());
|
|
||||||
if (!member) {
|
|
||||||
member = p->GetObByAccountId(join_msg->account_id());
|
|
||||||
if (!member) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (p->GetTeamNum() < 0 ||
|
|
||||||
p->GetTeamNum() > 2) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (p->GetRoom()) {
|
|
||||||
if (p->GetRoom()->GetGasData().GetGasMode() != GasInactive) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
auto hum = p->GetRoom()->GetPlayerByAccountId(join_msg->account_id());
|
|
||||||
if (hum) {
|
|
||||||
hum->ReJoin(ip_saddr, socket_handle, join_msg);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int game_times = 0;
|
|
||||||
RoomType_e self_room_type = RoomType_OldBrid1;
|
|
||||||
time_t register_time = f8::ExtractRegisterTimeFromSessionId(msg.session_id());
|
|
||||||
int proto_version = msg.proto_version();
|
|
||||||
int channel = f8::ExtractChannelIdFromAccountId(msg.account_id());
|
|
||||||
auto room = RoomMgr::Instance()->CreateRoom
|
|
||||||
(*join_msg,
|
|
||||||
self_room_type,
|
|
||||||
game_times,
|
|
||||||
register_time,
|
|
||||||
join_msg->proto_version(),
|
|
||||||
channel,
|
|
||||||
msg.mapid(),
|
|
||||||
nullptr);
|
|
||||||
p->SetRoom(room.get());
|
|
||||||
room->InitWithMobaBattle(ip_saddr, socket_handle, join_msg, p);
|
|
||||||
};
|
|
||||||
SendGetMobaBattleData(join_msg, cb);
|
|
||||||
}
|
|
||||||
|
|
||||||
void RoomMgr::DispatchSpecRoom(f8::MsgHdr* hdr, const cs::CMJoin& msg)
|
void RoomMgr::DispatchSpecRoom(f8::MsgHdr* hdr, const cs::CMJoin& msg)
|
||||||
{
|
{
|
||||||
if (msg.payload_data().empty() ||
|
if (msg.payload_data().empty() ||
|
||||||
@ -1312,112 +1229,6 @@ void RoomMgr::DispatchSpecRoom(f8::MsgHdr* hdr, const cs::CMJoin& msg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RoomMgr::SendGetMobaBattleData(std::shared_ptr<cs::CMJoin> join_msg,
|
|
||||||
std::function<void(int, const std::string, std::shared_ptr<MobaBattle>)> cb)
|
|
||||||
{
|
|
||||||
auto pos = join_msg->payload_data().find('|');
|
|
||||||
std::string head;
|
|
||||||
std::string body;
|
|
||||||
if (pos == std::string::npos) {
|
|
||||||
cb(1, "moba battle data error", nullptr);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
head = join_msg->payload_data().substr(0, pos);
|
|
||||||
body = join_msg->payload_data().substr(pos + 1);
|
|
||||||
auto data = std::make_shared<a8::XObject>();
|
|
||||||
if (!data->ReadFromJsonString(body) ||
|
|
||||||
!data->IsObject()) {
|
|
||||||
cb(1, "moba battle data error", nullptr);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int start_time = data->Get("start_time", "").GetInt();
|
|
||||||
if (f8::App::Instance()->GetNowTime() - start_time > 40) {
|
|
||||||
cb(2, "moba battle is started", nullptr);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
std::string room_uuid = data->Get("room_uuid", "").GetString();
|
|
||||||
if (room_uuid.empty()) {
|
|
||||||
cb(1, "moba battle data error", nullptr);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
auto his_room = GetHisMobaRoom(room_uuid);
|
|
||||||
if (his_room) {
|
|
||||||
cb(2, "moba battle is dissolution", nullptr);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
auto cur_room = GetMobaRoom(room_uuid);
|
|
||||||
if (cur_room) {
|
|
||||||
cb(0, "", cur_room);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
{
|
|
||||||
std::string url;
|
|
||||||
JsonDataMgr::Instance()->GetApiUrl(url);
|
|
||||||
if (url.find('?') != std::string::npos) {
|
|
||||||
url += "&c=Battle&a=getMobaBattleData";
|
|
||||||
} else {
|
|
||||||
url += "?&c=Battle&a=getMobaBattleData";
|
|
||||||
}
|
|
||||||
auto url_params = a8::MutableXObject::CreateObject();
|
|
||||||
url_params->SetVal("account_id", join_msg->account_id());
|
|
||||||
url_params->SetVal("session_id", join_msg->session_id());
|
|
||||||
url_params->SetVal("__POST", join_msg->payload_data());
|
|
||||||
HttpProxy::Instance()->HttpGet
|
|
||||||
(
|
|
||||||
[cb]
|
|
||||||
(bool ok, a8::XObject* rsp_obj, f8::HttpContext* ctx)
|
|
||||||
{
|
|
||||||
if (ok) {
|
|
||||||
f8::UdpLog::Instance()->Info
|
|
||||||
("GetBattleData ok %s",
|
|
||||||
{
|
|
||||||
rsp_obj->ToJsonStr()
|
|
||||||
});
|
|
||||||
if (rsp_obj->GetType() != a8::XOT_OBJECT ||
|
|
||||||
!rsp_obj->HasKey("errcode")) {
|
|
||||||
cb(1, "", nullptr);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int errcode = rsp_obj->Get("errcode", "").GetInt();
|
|
||||||
std::string errmsg = rsp_obj->Get("errmsg", "").GetString();
|
|
||||||
if (errcode) {
|
|
||||||
cb(1, "", nullptr);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
std::string room_uuid = rsp_obj->Get("room_uuid", "").GetString();
|
|
||||||
if (room_uuid.empty()) {
|
|
||||||
cb(1, "moba battle data error", nullptr);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
auto cur_room = RoomMgr::Instance()->GetMobaRoom(room_uuid);
|
|
||||||
if (cur_room) {
|
|
||||||
cb(0, "", cur_room);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto moba_battle = std::make_shared<MobaBattle>();
|
|
||||||
moba_battle->ParseResult(*rsp_obj);
|
|
||||||
if (moba_battle->GetParseOk()) {
|
|
||||||
cb(0, "", moba_battle);
|
|
||||||
RoomMgr::Instance()->moba_room_hash_[moba_battle->GetRoomUuid()] = moba_battle;
|
|
||||||
} else {
|
|
||||||
cb(1, "", moba_battle);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
f8::UdpLog::Instance()->Warning
|
|
||||||
("GetMobaBattleData error %s",
|
|
||||||
{
|
|
||||||
""
|
|
||||||
});
|
|
||||||
cb(1, "moba battle data error", nullptr);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
url.c_str(),
|
|
||||||
*url_params
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RoomMgr::HasTask()
|
bool RoomMgr::HasTask()
|
||||||
{
|
{
|
||||||
return !room_hash_.empty();
|
return !room_hash_.empty();
|
||||||
|
@ -25,7 +25,6 @@ class MapService;
|
|||||||
class MapInstance;
|
class MapInstance;
|
||||||
class Building;
|
class Building;
|
||||||
class CustomBattle;
|
class CustomBattle;
|
||||||
class MobaBattle;
|
|
||||||
struct RoomInitInfo
|
struct RoomInitInfo
|
||||||
{
|
{
|
||||||
int room_idx = 0;
|
int room_idx = 0;
|
||||||
@ -121,14 +120,10 @@ class RoomMgr : public a8::Singleton<RoomMgr>
|
|||||||
void AdjustCMJoin(cs::CMJoin* msg);
|
void AdjustCMJoin(cs::CMJoin* msg);
|
||||||
std::shared_ptr<CustomBattle> GetCustomRoom(const std::string& room_uuid);
|
std::shared_ptr<CustomBattle> GetCustomRoom(const std::string& room_uuid);
|
||||||
std::shared_ptr<CustomBattle> GetHisCustomRoom(const std::string& room_uuid);
|
std::shared_ptr<CustomBattle> GetHisCustomRoom(const std::string& room_uuid);
|
||||||
std::shared_ptr<MobaBattle> GetMobaRoom(const std::string& room_uuid);
|
|
||||||
std::shared_ptr<MobaBattle> GetHisMobaRoom(const std::string& room_uuid);
|
|
||||||
void _CMJoinCustomBattle(f8::MsgHdr* hdr, const cs::CMJoin& msg, int custom_room_type);
|
void _CMJoinCustomBattle(f8::MsgHdr* hdr, const cs::CMJoin& msg, int custom_room_type);
|
||||||
void _CMJoinMoba(f8::MsgHdr* hdr, const cs::CMJoin& msg);
|
|
||||||
void SendGetCustomBattleData(std::shared_ptr<cs::CMJoin> join_msg,
|
void SendGetCustomBattleData(std::shared_ptr<cs::CMJoin> join_msg,
|
||||||
std::function<void(int, const std::string, std::shared_ptr<CustomBattle>)> cb);
|
std::function<void(int, const std::string, std::shared_ptr<CustomBattle>)> cb,
|
||||||
void SendGetMobaBattleData(std::shared_ptr<cs::CMJoin> join_msg,
|
int custom_room_type);
|
||||||
std::function<void(int, const std::string, std::shared_ptr<MobaBattle>)> cb);
|
|
||||||
void DispatchSpecRoom(f8::MsgHdr* hdr, const cs::CMJoin& msg);
|
void DispatchSpecRoom(f8::MsgHdr* hdr, const cs::CMJoin& msg);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -144,6 +139,4 @@ class RoomMgr : public a8::Singleton<RoomMgr>
|
|||||||
std::map<std::string, std::map<std::string, std::string>> team_room_hash_;
|
std::map<std::string, std::map<std::string, std::string>> team_room_hash_;
|
||||||
std::map<std::string, std::shared_ptr<CustomBattle>> custom_room_hash_;
|
std::map<std::string, std::shared_ptr<CustomBattle>> custom_room_hash_;
|
||||||
std::map<std::string, std::shared_ptr<CustomBattle>> his_custom_room_hash_;
|
std::map<std::string, std::shared_ptr<CustomBattle>> his_custom_room_hash_;
|
||||||
std::map<std::string, std::shared_ptr<MobaBattle>> moba_room_hash_;
|
|
||||||
std::map<std::string, std::shared_ptr<MobaBattle>> his_moba_room_hash_;
|
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user