new API and rematch WIP
This commit is contained in:
@@ -142,13 +142,30 @@ public static class Cupid
|
||||
}
|
||||
|
||||
/// <summary>Matchmaker GET / body: <c>"0"</c> while waiting; otherwise a JSON room object.</summary>
|
||||
public static CupidRoom? ParseRoom(string data)
|
||||
public static CupidRoom? ParseRoom(string data) => ParseRoom(data, 0, null);
|
||||
|
||||
/// <inheritdoc cref="ParseRoom(string)"/>
|
||||
/// <param name="currentUserId">Used to pick <c>for_red</c> vs <c>for_blue</c> when both list the same players.</param>
|
||||
/// <param name="teamDisambiguation">Optional hint (e.g. <see cref="GameManager.MyTeam"/>) when the roster is duplicated on both sides.</param>
|
||||
public static CupidRoom? ParseRoom(string data, int currentUserId, Team? teamDisambiguation)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(data))
|
||||
return null;
|
||||
string t = data.Trim();
|
||||
if (t == "0")
|
||||
return null;
|
||||
|
||||
if (t.IndexOf("\"for_red\"", StringComparison.Ordinal) >= 0)
|
||||
{
|
||||
MatchmadeResponse env = JsonUtility.FromJson<MatchmadeResponse>(t);
|
||||
if (env == null || !env.ok || !MatchmadeResponse.IsMatchReady(env))
|
||||
return null;
|
||||
MatchmadeTeamPayload branch = MatchmadeResponse.SelectTeamPayload(env, currentUserId, teamDisambiguation);
|
||||
if (branch == null || branch.Port <= 0)
|
||||
return null;
|
||||
return ToCupidRoom(branch);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
CupidRoom room = JsonUtility.FromJson<CupidRoom>(t);
|
||||
@@ -161,6 +178,32 @@ public static class Cupid
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static CupidRoom ToCupidRoom(MatchmadeTeamPayload p)
|
||||
{
|
||||
var room = new CupidRoom
|
||||
{
|
||||
GameName = p.GameName ?? "",
|
||||
Port = p.Port,
|
||||
InitTime = p.InitTime,
|
||||
match_id = p.match_id,
|
||||
your_team = p.your_team ?? ""
|
||||
};
|
||||
if (p.Players != null)
|
||||
{
|
||||
room.Players = new CupidQueueEntry[p.Players.Length];
|
||||
for (int i = 0; i < p.Players.Length; i++)
|
||||
{
|
||||
room.Players[i] = new CupidQueueEntry
|
||||
{
|
||||
Name = p.Players[i].Name,
|
||||
LastSeen = p.Players[i].LastSeen,
|
||||
UserId = p.Players[i].UserId
|
||||
};
|
||||
}
|
||||
}
|
||||
return room;
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
|
||||
Reference in New Issue
Block a user