This commit is contained in:
aozhiwei 2023-09-21 17:12:28 +08:00
parent 96841a0deb
commit 05b70acfa0
3 changed files with 45 additions and 0 deletions

View File

@ -1,6 +1,9 @@
#include "precompile.h" #include "precompile.h"
#include "custom_battle.h" #include "custom_battle.h"
#include "custom_team.h"
#include "custom_member.h"
#include "netdata.h"
void CustomBattle::Init() void CustomBattle::Init()
{ {
@ -25,6 +28,45 @@ void CustomBattle::ParseResult(a8::XObject& obj)
start_time_ = obj.Get("start_time"); start_time_ = obj.Get("start_time");
sign_ = obj.Get("sign").GetString(); 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();
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<CustomTeam>();
team->team_uuid_ = team_uuid;
uuid_hash_[team->team_uuid_] = team;
}
for (int ii = 0; ii < member_list->Size(); ++ii) {
auto member_obj = member_list->At(i);
if (!member_obj || !member_obj->IsObject()) {
parse_ok_ = false;
return;
}
auto member = std::make_shared<CustomMember>();
member->account_id_ = member_obj->Get("account_id").GetString();
member->session_id_ = member_obj->Get("session_id").GetString();
member->battle_context_ = std::make_shared<BattleDataContext>();
team->member_hash_[member->account_id_] = member;
account_hash_[member->account_id_] = team;
}
}
raw_data_ = std::make_shared<a8::XObject>(); raw_data_ = std::make_shared<a8::XObject>();
obj.DeepCopy(*raw_data_); obj.DeepCopy(*raw_data_);
parse_ok_ = true; parse_ok_ = true;

View File

@ -10,5 +10,7 @@ class CustomMember
private: private:
std::string account_id_; std::string account_id_;
std::string session_id_;
std::shared_ptr<BattleDataContext> battle_context_; std::shared_ptr<BattleDataContext> battle_context_;
friend class CustomBattle;
}; };

View File

@ -11,4 +11,5 @@ class CustomTeam
private: private:
std::string team_uuid_; std::string team_uuid_;
std::map<std::string, std::shared_ptr<CustomMember>> member_hash_; std::map<std::string, std::shared_ptr<CustomMember>> member_hash_;
friend class CustomBattle;
}; };