Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions Runtime/Matchmaking/Api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class Api
internal string PATH_TICKETS = "tickets";
internal string PATH_GROUP_TICKETS = "group-tickets";
internal string PATH_GROUP_UP = "groups";
internal string PATH_BACKFILL = "backfills";

public Api(MonoBehaviour parent, string authToken, string baseUrl)
{
Expand All @@ -27,6 +28,8 @@ public Api(MonoBehaviour parent, string authToken, string baseUrl)
BaseUrl = baseUrl;
}

#region Utility

public void GetMonitor(
Action<MonitorResponseDTO, UnityWebRequest> onSuccessDelegate,
Action<string, UnityWebRequest> onErrorDelegate
Expand Down Expand Up @@ -82,7 +85,9 @@ Action<string, UnityWebRequest> onErrorDelegate
onErrorDelegate
);
}
#endregion

#region Server-to-Server Tickets
public void CreateTicketAsync<T, A>(
T ticket,
Action<TicketResponseDTO, UnityWebRequest> onSuccessDelegate,
Expand Down Expand Up @@ -190,7 +195,9 @@ Action<string, UnityWebRequest> onErrorDelegate
onErrorDelegate
);
}
#endregion

#region Client Group-Up
public void CreateGroup<G, A>(
G group,
Action<GroupUpResponseDTO, UnityWebRequest> onSuccessDelegate,
Expand Down Expand Up @@ -381,5 +388,87 @@ Action<string, UnityWebRequest> onErrorDelegate
onErrorDelegate
);
}
#endregion

#region Server Backfill
public void CreateBackfill<B, A>(
B backfill,
Action<BackfillResponseDTO<A>, UnityWebRequest> onSuccessDelegate,
Action<string, UnityWebRequest> onErrorDelegate
)
where B : BackfillRequestDTO<A>
{
Request.Post(
$"{BaseUrl}/{PATH_BACKFILL}",
AuthToken,
JsonConvert.SerializeObject(backfill),
(string response, UnityWebRequest request) =>
{
try
{
BackfillResponseDTO<A> backfillRes = JsonConvert.DeserializeObject<
BackfillResponseDTO<A>
>(response);
onSuccessDelegate(backfillRes, request);
}
catch (Exception e)
{
L.Error(
$"Couldn't parse backfill, consider updating Matchmaking SDK. {e.Message}"
);
throw;
}
},
onErrorDelegate
);
}

public void GetBackfill<A>(
string backfillID,
Action<BackfillResponseDTO<A>, UnityWebRequest> onSuccessDelegate,
Action<string, UnityWebRequest> onErrorDelegate
)
{
Request.Get(
$"{BaseUrl}/{PATH_BACKFILL}/{backfillID}",
AuthToken,
(string response, UnityWebRequest request) =>
{
try
{
BackfillResponseDTO<A> backfillRes = JsonConvert.DeserializeObject<
BackfillResponseDTO<A>
>(response);
onSuccessDelegate(backfillRes, request);
}
catch (Exception e)
{
L.Error(
$"Couldn't parse backfill, consider updating Matchmaking SDK. {e.Message}"
);
throw;
}
},
onErrorDelegate
);
}

public void DeleteBackfill(
string backfillID,
Action<UnityWebRequest> onSuccessDelegate,
Action<string, UnityWebRequest> onErrorDelegate
)
{
Request.Delete(
$"{BaseUrl}/{PATH_BACKFILL}/{backfillID}",
AuthToken,
(string response, UnityWebRequest request) =>
{
onSuccessDelegate(request);
},
onErrorDelegate
);
}
#endregion
}
}
72 changes: 72 additions & 0 deletions Runtime/Matchmaking/DTOs/BackfillRequestDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Edgegap.Matchmaking
{
public abstract class BackfillRequestDTO<A>
{
[JsonProperty("profile")]
public string Profile;

[JsonProperty("attributes")]
public BackfillAttributes Attributes;

[JsonProperty("tickets")]
public Dictionary<string, InjectedTicketDTO<A>> Tickets;

public BackfillRequestDTO(string profile, BackfillAttributes attributes)
{
Profile = profile;
Attributes = attributes;
}

public override string ToString()
{
return JsonConvert.SerializeObject(this);
}
}

public class BackfillAttributes
{
[JsonProperty("assignment")]
public DeploymentDTO Assignment;

public BackfillAttributes(DeploymentDTO assignment)
{
Assignment = assignment;
}

public override string ToString()
{
return JsonConvert.SerializeObject(this);
}
}

public class SimpleBackfillRequestDTO : BackfillRequestDTO<BackfillTicketAttributesDTO>
{
public SimpleBackfillRequestDTO(
string profile,
BackfillAttributes attributes,
Dictionary<string, InjectedTicketDTO<BackfillTicketAttributesDTO>> tickets
)
: base(profile, attributes)
{
Tickets = tickets;
}
}

public class BackfillTicketAttributesDTO : LatenciesAttributesDTO
{
[JsonProperty("backfill_group_size")]
public string[] BackfillGroupSize;

public BackfillTicketAttributesDTO(
Dictionary<string, float> beacons,
string[] backfillGroupSize
)
: base(beacons)
{
BackfillGroupSize = backfillGroupSize;
}
}
}
2 changes: 2 additions & 0 deletions Runtime/Matchmaking/DTOs/BackfillRequestDTO.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions Runtime/Matchmaking/DTOs/BackfillResponseDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Edgegap.Matchmaking
{
public class BackfillResponseDTO<A>
{
[JsonProperty("id")]
public string ID;

[JsonProperty("profile")]
public string Profile;

[JsonProperty("tickets")]
public Dictionary<string, InjectedTicketDTO<A>> Tickets;

[JsonProperty("status")]
public string Status;

#nullable enable
[JsonProperty("assigned_ticket")]
public InjectedTicketDTO<A>? AssignedTicket;

#nullable disable

public override string ToString()
{
return JsonConvert.SerializeObject(this);
}
}
}
2 changes: 2 additions & 0 deletions Runtime/Matchmaking/DTOs/BackfillResponseDTO.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions Runtime/Matchmaking/DTOs/GroupUpRequestDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ public SimpleGroupUpRequestDTO(
}
}

public class BackfillGroupUpRequestDTO : GroupUpRequestDTO<BackfillTicketAttributesDTO>
{
public BackfillGroupUpRequestDTO(
Dictionary<string, float> latencyBeacons,
string[] backfillGroupSize,
bool isReady = false
)
: base("backfill-example", isReady)
{
Attributes = new BackfillTicketAttributesDTO(latencyBeacons, backfillGroupSize);
}
}

public class AdvancedGroupUpRequestDTO : GroupUpRequestDTO<AdvancedGroupUpAttributesDTO>
{
public AdvancedGroupUpRequestDTO(
Expand Down
7 changes: 5 additions & 2 deletions Runtime/Matchmaking/DTOs/InjectedTicketDTO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ public class InjectedTicketDTO<A>
[JsonProperty("group_id")]
public string GroupID;

[JsonProperty("team_id")]
public string TeamID;
#nullable enable
[JsonProperty("team_id", NullValueHandling = NullValueHandling.Ignore)]
public string? TeamID;

#nullable disable

[JsonProperty("attributes")]
public A Attributes;
Expand Down
Loading