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
Binary file modified EdgeMultiplay.unitypackage
Binary file not shown.
2 changes: 1 addition & 1 deletion EdgeMultiplay/Scripts/DataContracts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ public Dictionary<string, string> playerTagsDict
{
if(playerTags != null)
{
return Tag.HashtableToDictionary(playerTags);
return Util.HashtableToDictionary(playerTags);
}
else
{
Expand Down
33 changes: 27 additions & 6 deletions EdgeMultiplay/Scripts/EdgeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace EdgeMultiplay
/// EdgeManager have many static variables, your app/game should have only one EdgeManager
/// </summary>
[RequireComponent(typeof(MobiledgeX.LocationService))]
[RequireComponent(typeof(EdgeEventsManager))]
[AddComponentMenu("EdgeMultiplay/EdgeManager")]
public class EdgeManager : MonoBehaviour
{
Expand Down Expand Up @@ -124,7 +125,22 @@ private void Awake()
{
Destroy(gameObject);
}
integration = new MobiledgeXIntegration();
integration = new MobiledgeXIntegration(FindObjectOfType<EdgeEventsManager>());
integration.matchingEngine.EnableEdgeEvents = true;
integration.NewFindCloudletHandler += HandleFindCloudlet;
}

private void HandleFindCloudlet(EdgeEventsStatus edgeEventstatus, FindCloudletEvent fcEvent)
{
print("NewFindCloudlet triggered status is " + edgeEventstatus.status + ", Trigger" + fcEvent.trigger);
if (fcEvent.newCloudlet != null)
{
print("New Cloudlet FQDN: " + fcEvent.newCloudlet.Fqdn);
}
if (edgeEventstatus.status == Status.error)
{
print("Error received: " + edgeEventstatus.error_msg);
}
}

void Update()
Expand Down Expand Up @@ -219,7 +235,7 @@ public async Task ConnectToServer(bool useAnyCarrierNetwork = true, bool useFall
integration.useFallbackLocation = useFallBackLocation;
wsClient = new MobiledgeXWebSocketClient();
await integration.RegisterAndFindCloudlet();
integration.GetAppPort(LProto.L_PROTO_TCP);
integration.GetAppPort(LProto.Tcp);
string url = integration.GetUrl("ws") + path;
Uri uri = new Uri(url);
if (wsClient.isOpen())
Expand All @@ -230,6 +246,11 @@ public async Task ConnectToServer(bool useAnyCarrierNetwork = true, bool useFall
await wsClient.Connect(@uri);
EdgeMultiplayCallbacks.connectedToEdge();
}
catch (AppPortException appPortException)
{
EdgeMultiplayCallbacks.failureToConnect(appPortException.Message);
Debug.LogError("EdgeMultiplay: Failed to connect to Edge, Error finding AppPort");
}
catch (Exception e)
{
EdgeMultiplayCallbacks.failureToConnect(e.Message);
Expand Down Expand Up @@ -279,7 +300,7 @@ public static void JoinOrCreateRoom(string playerName, int playerAvatar, int max
Hashtable playertagsHashtable;
if (playerTags != null)
{
playertagsHashtable = Tag.DictionaryToHashtable(playerTags);
playertagsHashtable = Util.DictionaryToHashtable(playerTags);
}
else
{
Expand Down Expand Up @@ -336,7 +357,7 @@ public static void CreateRoom(string playerName, int playerAvatar, int maxPlayer
Hashtable playertagsHashtable;
if (playerTags != null)
{
playertagsHashtable = Tag.DictionaryToHashtable(playerTags);
playertagsHashtable = Util.DictionaryToHashtable(playerTags);
}
else
{
Expand Down Expand Up @@ -367,7 +388,7 @@ public static void JoinRoom(string roomId, string playerName, int playerAvatar,
Hashtable playertagsHashtable;
if (playerTags != null)
{
playertagsHashtable = Tag.DictionaryToHashtable(playerTags);
playertagsHashtable = Util.DictionaryToHashtable(playerTags);
}
else
{
Expand Down Expand Up @@ -527,7 +548,7 @@ void HandleWebSocketMessage(string message)
}
else
{
udpClient = new MobiledgeXUDPClient(integration.GetHost(), integration.GetAppPort(LProto.L_PROTO_UDP).public_port);
udpClient = new MobiledgeXUDPClient(integration.GetHost(), integration.GetAppPort(LProto.Udp).PublicPort);
}
SendUDPMessage(new GamePlayEvent(){eventName = "Start"});
break;
Expand Down
51 changes: 51 additions & 0 deletions EdgeMultiplay/Scripts/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace EdgeMultiplay
Expand Down Expand Up @@ -162,5 +164,54 @@ public static Quaternion ConvertFloatArrayToQuaternion(float[] floatArray, int s
throw new Exception("floatArray starting from the start index doesn't qualify to create a Vector3");
}
}

/// <summary>
/// Converts a Hashtable to Dictionary<string, string>
/// </summary>
/// <param name="htable">Hashtable</param>
/// <returns>Dictionary<string, string></returns>
public static Dictionary<string, string> HashtableToDictionary(Hashtable htable)
{
Dictionary<string, string> dict = new Dictionary<string, string>();
if (htable == null)
{
return null;
}
foreach (var key in htable.Keys)
{
if (htable[key] == null)
{
continue;
}
dict[key.ToString()] = htable[key].ToString();
Debug.Log("Key: " + key + ", Value: " + dict[key.ToString()]);
}
return dict;
}

/// <summary>
/// Converts a Dictionary<string, string> to Hashtable
/// </summary>
/// <param name="dict">Dictionary<string, string></param>
/// <returns>Hashtable</returns>
public static Hashtable DictionaryToHashtable(Dictionary<string, string> dict)
{
Hashtable htable = new Hashtable();
if (dict == null)
{
return null;
}
foreach (KeyValuePair<string, string> entry in dict)
{
if (entry.Value == null)
{
continue;
}
htable.Add(entry.Key, entry.Value);
Debug.Log("Key: " + entry.Key + ", Value: " + htable[entry.Key]);
}
return htable;
}

}
}
4 changes: 4 additions & 0 deletions EdgeMultiplay/link.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<linker>
<assembly fullname="System.Runtime.Serialization" preserve="all"/>
<assembly fullname="System.Runtime.Serialization.Json" preserve="all"/>
</linker>
7 changes: 7 additions & 0 deletions EdgeMultiplay/link.xml.meta

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