Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
}
}
81 changes: 81 additions & 0 deletions Runtime/Matchmaking/DTOs/BackfillRequestDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
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, BackfillAssignedTicket<A>> Tickets;

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

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

public class BackfillAssignment : DeploymentDTO
{
[JsonProperty("request_id")]
public string RequestID;
}

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

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

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

public class SimpleBackfillRequestDTO : BackfillRequestDTO<BackfillTicketAttributesDTO>
{
public SimpleBackfillRequestDTO()
: base("", null) { }

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

public class BackfillTicketAttributesDTO : LatenciesAttributesDTO
{
[JsonProperty("backfill_group_size")]
public string[] BackfillGroupSize;
Comment thread
orcist marked this conversation as resolved.

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.

35 changes: 35 additions & 0 deletions Runtime/Matchmaking/DTOs/BackfillResponseDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
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;

[JsonIgnore]
public DateTime? CreatedAt;

#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
18 changes: 16 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 All @@ -28,4 +31,15 @@ public override string ToString()
return JsonConvert.SerializeObject(this);
}
}

public class BackfillAssignedTicket<A> : InjectedTicketDTO<A>
{
#nullable enable
[JsonIgnore]
public DateTime? AssignedAt;

[JsonIgnore]
public DateTime? JoinedAt;
#nullable disable
}
}
2 changes: 1 addition & 1 deletion Runtime/Matchmaking/GroupClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public void StopMatchmaking(Action onCompletedDelegate = null)
{
Polling = false;

if (Group.Current is null)
if (Group.Current is null || Group.Current.GroupID is null)
{
if (onCompletedDelegate is not null)
{
Expand Down
Loading