in Gems/AWSGameLift/Code/AWSGameLiftServer/Source/AWSGameLiftServerManager.cpp [194:282]
bool AWSGameLiftServerManager::BuildServerMatchBackfillPlayer(
const AWSGameLiftPlayer& player, Aws::GameLift::Server::Model::Player& outBackfillPlayer)
{
outBackfillPlayer.SetPlayerId(player.m_playerId.c_str());
outBackfillPlayer.SetTeam(player.m_team.c_str());
for (auto latencyPair : player.m_latencyInMs)
{
outBackfillPlayer.AddLatencyInMs(latencyPair.first.c_str(), latencyPair.second);
}
for (auto attributePair : player.m_playerAttributes)
{
Aws::GameLift::Server::Model::AttributeValue playerAttribute;
rapidjson::Document attributeDocument;
rapidjson::ParseResult parseResult = attributeDocument.Parse(attributePair.second.c_str());
// player attribute json content should always be a single member object
if (parseResult && attributeDocument.IsObject() && attributeDocument.MemberCount() == 1)
{
if ((attributeDocument.HasMember(AWSGameLiftMatchmakingPlayerAttributeSTypeName) ||
attributeDocument.HasMember(AWSGameLiftMatchmakingPlayerAttributeSServerTypeName)) &&
attributeDocument.MemberBegin()->value.IsString())
{
playerAttribute = Aws::GameLift::Server::Model::AttributeValue(
attributeDocument.MemberBegin()->value.GetString());
}
else if ((attributeDocument.HasMember(AWSGameLiftMatchmakingPlayerAttributeNTypeName) ||
attributeDocument.HasMember(AWSGameLiftMatchmakingPlayerAttributeNServerTypeName)) &&
attributeDocument.MemberBegin()->value.IsNumber())
{
playerAttribute = Aws::GameLift::Server::Model::AttributeValue(
attributeDocument.MemberBegin()->value.GetDouble());
}
else if ((attributeDocument.HasMember(AWSGameLiftMatchmakingPlayerAttributeSDMTypeName) ||
attributeDocument.HasMember(AWSGameLiftMatchmakingPlayerAttributeSDMServerTypeName)) &&
attributeDocument.MemberBegin()->value.IsObject())
{
playerAttribute = Aws::GameLift::Server::Model::AttributeValue::ConstructStringDoubleMap();
for (auto iter = attributeDocument.MemberBegin()->value.MemberBegin();
iter != attributeDocument.MemberBegin()->value.MemberEnd(); iter++)
{
if (iter->name.IsString() && iter->value.IsNumber())
{
playerAttribute.AddStringAndDouble(iter->name.GetString(), iter->value.GetDouble());
}
else
{
AZ_Error(AWSGameLiftServerManagerName, false, AWSGameLiftMatchmakingPlayerAttributeInvalidErrorMessage,
player.m_playerId.c_str(), "String double map key must be string type and value must be number type");
return false;
}
}
}
else if ((attributeDocument.HasMember(AWSGameLiftMatchmakingPlayerAttributeSLTypeName) ||
attributeDocument.HasMember(AWSGameLiftMatchmakingPlayerAttributeSLServerTypeName)) &&
attributeDocument.MemberBegin()->value.IsArray())
{
playerAttribute = Aws::GameLift::Server::Model::AttributeValue::ConstructStringList();
for (auto iter = attributeDocument.MemberBegin()->value.Begin();
iter != attributeDocument.MemberBegin()->value.End(); iter++)
{
if (iter->IsString())
{
playerAttribute.AddString(iter->GetString());
}
else
{
AZ_Error(AWSGameLiftServerManagerName, false, AWSGameLiftMatchmakingPlayerAttributeInvalidErrorMessage,
player.m_playerId.c_str(), "String list element must be string type");
return false;
}
}
}
else
{
AZ_Error(AWSGameLiftServerManagerName, false, AWSGameLiftMatchmakingPlayerAttributeInvalidErrorMessage,
player.m_playerId.c_str(), "S, N, SDM or SLM is expected as attribute type.");
return false;
}
}
else
{
AZ_Error(AWSGameLiftServerManagerName, false, AWSGameLiftMatchmakingPlayerAttributeInvalidErrorMessage,
player.m_playerId.c_str(), rapidjson::GetParseError_En(parseResult.Code()));
return false;
}
outBackfillPlayer.AddPlayerAttribute(attributePair.first.c_str(), playerAttribute);
}
return true;
}