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
124 changes: 124 additions & 0 deletions Runtime/MatchmakingInjectedVariableStore.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Newtonsoft.Json;
using UnityEngine;

namespace Edgegap.Gen2SDK
{
using L = Logger;

public class AdvancedTicketsEqualityVariables
{
[JsonProperty("selected_game_mode")]
public string SelectedGameMode;

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

public class AdvancedTicketsIntersectionVariables
{
[JsonProperty("selected_map")]
public List<string> SelectedMap;

[JsonProperty("selected_region")]
public List<string> SelectedRegion;

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

public class MatchmakingInjectedVariableStore<T, A, E, I>
where T : TicketsRequestDTO<A>
{
public List<string> TicketIds { get; private set; }
public Dictionary<string, T> TicketsData { get; private set; }
public string MatchId { get; private set; }
public string MatchProfile { get; private set; }
public E Equality { get; private set; }
public I Intersection { get; private set; }
public Dictionary<string, List<string>> Teams {get; private set;}
public Dictionary<string, List<string>> Groups {get; private set;}

public MatchmakingInjectedVariableStore() {
try
{
IDictionary envs = Environment.GetEnvironmentVariables();
TicketsData = new Dictionary<string, T>();

foreach (DictionaryEntry envEntry in envs)
{
string key = envEntry.Key.ToString();

if (key.StartsWith("MM_TICKET_") && !key.Contains("_IDS"))
{
string id = key.Split(
"MM_TICKET_",
StringSplitOptions.RemoveEmptyEntries
)[0];

TicketsData[id] =
JsonConvert.DeserializeObject<T>(
envEntry.Value.ToString()
);
}
else if (key == "MM_MATCH_PROFILE")
{
MatchProfile = envEntry.Value.ToString();
}
else if (key == "MM_TICKET_IDS")
{
TicketIds = JsonConvert.DeserializeObject<List<string>>(
envEntry.Value.ToString()
);
}
else if (key == "MM_MATCH_ID")
{
MatchId = envEntry.Value.ToString();
}
else if (key == "MM_EQUALITY")
{
Equality = JsonConvert.DeserializeObject<E>(
envEntry.Value.ToString()
);
}
else if (key == "MM_INTERSECTION")
{
Intersection = JsonConvert.DeserializeObject<I>(
envEntry.Value.ToString()
);
}
else if (key == "MM_TEAMS")
{
Teams = JsonConvert.DeserializeObject<Dictionary<string, List<string>>>(
envEntry.Value.ToString()
);
}
else if (key == "MM_GROUPS")
{
Groups = JsonConvert.DeserializeObject<Dictionary<string, List<string>>>(
envEntry.Value.ToString()
);
}
}

foreach (string id in TicketIds)
{
if (!TicketsData.ContainsKey(id))
{
L._Warn($"Couldn't find injected ticket body for injected ticket ID {id}.");
}
}
}
catch (Exception e)
{
L._Error($"Couldn't parse envs, consider updating Gen2 SDK. {e.Message}");
}
}
}
}
11 changes: 11 additions & 0 deletions Runtime/MatchmakingInjectedVariableStore.cs.meta

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

34 changes: 34 additions & 0 deletions Samples~/AdvancedExample/MatchmakingServerDataStoreExample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Newtonsoft.Json;
using UnityEngine;
using Edgegap.Gen2SDK;

using MyTicketsRequestDTO = Edgegap.Gen2SDK.AdvancedTicketsRequestDTO;
using MyTicketsAttributes = Edgegap.Gen2SDK.AdvancedTicketsAttributesDTO;
using MyTicketsEqualityVariables = Edgegap.Gen2SDK.AdvancedTicketsEqualityVariables;
using MyTicketsIntersectionVariables = Edgegap.Gen2SDK.AdvancedTicketsIntersectionVariables;

public class MatchmakingServerDataStoreExample : MonoBehaviour
{
public static MatchmakingServerDataStoreExample Instance { get; private set; }
public MatchmakingInjectedVariableStore<MyTicketsRequestDTO, MyTicketsAttributes, MyTicketsEqualityVariables, MyTicketsIntersectionVariables> MmInjectedVariableStore;

public void Awake()
{
if (Application.isBatchMode)
{
// If there is an instance, and it's not me, delete myself.
if (Instance != null && Instance != this)
{
Destroy(this);
}
else if (Instance == null)
{
Instance = this;
MmInjectedVariableStore = new MatchmakingInjectedVariableStore<MyTicketsRequestDTO, MyTicketsAttributes, MyTicketsEqualityVariables, MyTicketsIntersectionVariables>();
}
}
}
}
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
"displayName": "Simple Example",
"description": "Minimal Recommended Gen2 Example.",
"path": "Samples~/SimpleExample"
},
{
"displayName": "Advanced Example",
"description": "Advanced Gen2 Example.",
"path": "Samples~/AdvancedExample"
}
],
"dependencies": {
Expand Down