This commit is contained in:
aozhiwei 2023-09-21 17:40:43 +08:00
parent ac92dfecf2
commit 82819a0c98
2 changed files with 10 additions and 0 deletions

View File

@ -67,6 +67,7 @@ void CustomBattle::ParseResult(a8::XObject& obj)
parse_ok_ = false; parse_ok_ = false;
return; return;
} }
member_id_hash_[member->account_id_] = member;
team->member_hash_[member->account_id_] = member; team->member_hash_[member->account_id_] = member;
account_hash_[member->account_id_] = team; account_hash_[member->account_id_] = team;
} }
@ -82,6 +83,12 @@ bool CustomBattle::CanAdd(const std::string& account_id, const std::string& sess
return true; return true;
} }
std::shared_ptr<CustomMember> CustomBattle::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<CustomTeam> CustomBattle::GetTeamByAccountId(const std::string& account_id) std::shared_ptr<CustomTeam> CustomBattle::GetTeamByAccountId(const std::string& account_id)
{ {
auto itr = account_hash_.find(account_id); auto itr = account_hash_.find(account_id);

View File

@ -2,6 +2,7 @@
class Room; class Room;
class CustomTeam; class CustomTeam;
class CustomMember;
class CustomBattle class CustomBattle
{ {
public: public:
@ -21,6 +22,7 @@ class CustomBattle
void ParseResult(a8::XObject& obj); void ParseResult(a8::XObject& obj);
bool CanAdd(const std::string& account_id, const std::string& session_id); bool CanAdd(const std::string& account_id, const std::string& session_id);
std::shared_ptr<CustomTeam> GetTeamByAccountId(const std::string& account_id); std::shared_ptr<CustomTeam> GetTeamByAccountId(const std::string& account_id);
std::shared_ptr<CustomMember> GetMemberByAccountId(const std::string& account_id);
std::shared_ptr<CustomTeam> GetTeamByTeamUuid(const std::string& team_uuid); std::shared_ptr<CustomTeam> GetTeamByTeamUuid(const std::string& team_uuid);
private: private:
@ -35,4 +37,5 @@ class CustomBattle
std::shared_ptr<a8::XObject> raw_data_; std::shared_ptr<a8::XObject> raw_data_;
std::map<std::string, std::shared_ptr<CustomTeam>> uuid_hash_; std::map<std::string, std::shared_ptr<CustomTeam>> uuid_hash_;
std::map<std::string, std::shared_ptr<CustomTeam>> account_hash_; std::map<std::string, std::shared_ptr<CustomTeam>> account_hash_;
std::map<std::string, std::shared_ptr<CustomMember>> member_id_hash_;
}; };