sounds and screens with improved matchmaker
This commit is contained in:
@@ -12,36 +12,66 @@ public static class Cupid
|
||||
private static int port;
|
||||
public static int Port => port;
|
||||
|
||||
private static string password;
|
||||
private static string bearerToken;
|
||||
public static string BearerToken => bearerToken;
|
||||
|
||||
private static CupidSettings settings = null;
|
||||
public static CupidSettings Settings => settings;
|
||||
|
||||
public static bool isInitialized => settings!=null;
|
||||
public static bool isInitialized => settings != null;
|
||||
|
||||
|
||||
public static int RoomPort =-1;
|
||||
public static int RoomPort = -1;
|
||||
|
||||
|
||||
public static async Task Init(string _serverAddress, int _port, string _password){
|
||||
serverAddress= _serverAddress;
|
||||
public static async Task Init(string _serverAddress, int _port, string _bearerToken)
|
||||
{
|
||||
serverAddress = _serverAddress;
|
||||
port = _port;
|
||||
password = _password;
|
||||
bearerToken = _bearerToken ?? "";
|
||||
|
||||
using (UnityWebRequest www = UnityWebRequest.Get(CupidURI + "/settings?password="+password))
|
||||
if (string.IsNullOrEmpty(bearerToken))
|
||||
{
|
||||
Logger.Log("Cupid: no bearer token; configure auth before matchmaking.");
|
||||
settings = null;
|
||||
return;
|
||||
}
|
||||
|
||||
using (UnityWebRequest www = UnityWebRequest.Get(CupidURI + "/settings"))
|
||||
{
|
||||
www.SetRequestHeader("Authorization", "Bearer " + bearerToken);
|
||||
var operation = www.SendWebRequest();
|
||||
while (!operation.isDone)
|
||||
{
|
||||
await Task.Yield();
|
||||
}
|
||||
|
||||
try{
|
||||
settings = JsonUtility.FromJson<CupidSettings>(www.downloadHandler.text);
|
||||
if(settings==null){throw new NullReferenceException();}
|
||||
try
|
||||
{
|
||||
if (www.result != UnityWebRequest.Result.Success)
|
||||
{
|
||||
Logger.Log("Cupid settings request failed: " + www.error);
|
||||
Logger.Log(www.downloadHandler != null ? www.downloadHandler.text : "");
|
||||
settings = null;
|
||||
return;
|
||||
}
|
||||
|
||||
string body = www.downloadHandler != null ? www.downloadHandler.text : "";
|
||||
if (string.IsNullOrWhiteSpace(body))
|
||||
{
|
||||
settings = null;
|
||||
return;
|
||||
}
|
||||
|
||||
settings = JsonUtility.FromJson<CupidSettings>(body);
|
||||
if (settings == null) { throw new NullReferenceException(); }
|
||||
Logger.Log("Cupid init success");
|
||||
}catch(Exception e){
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.Log("Error retreiving settings from server " + e.Message);
|
||||
Logger.Log(www.downloadHandler.text);
|
||||
Logger.Log(www.downloadHandler != null ? www.downloadHandler.text : "");
|
||||
settings = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -59,13 +89,25 @@ public static class Cupid
|
||||
}
|
||||
}
|
||||
|
||||
public static CupidRoom? ParseRoom(string data){
|
||||
CupidRoom? room = null;
|
||||
try{
|
||||
room = JsonUtility.FromJson<CupidRoom>(data);
|
||||
}catch{}
|
||||
|
||||
return room;
|
||||
/// <summary>Matchmaker GET / body: <c>"0"</c> while waiting; otherwise a JSON room object.</summary>
|
||||
public static CupidRoom? ParseRoom(string data)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(data))
|
||||
return null;
|
||||
string t = data.Trim();
|
||||
if (t == "0")
|
||||
return null;
|
||||
try
|
||||
{
|
||||
CupidRoom room = JsonUtility.FromJson<CupidRoom>(t);
|
||||
if (room.Port <= 0)
|
||||
return null;
|
||||
return room;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,14 +120,20 @@ public class CupidSettings
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public struct CupidRoom{
|
||||
public struct CupidRoom
|
||||
{
|
||||
public CupidQueueEntry[] Players;
|
||||
public string GameName;
|
||||
public int Port;
|
||||
public uint InitTime;
|
||||
public long InitTime;
|
||||
public int match_id;
|
||||
public string your_team;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public struct CupidQueueEntry{
|
||||
string Name;
|
||||
uint LastSeen;
|
||||
public struct CupidQueueEntry
|
||||
{
|
||||
public string Name;
|
||||
public long LastSeen;
|
||||
public int UserId;
|
||||
}
|
||||
Reference in New Issue
Block a user