static void Log(GSInstance gsInstance, string message) { if (gsInstance.TraceMessages) { gsInstance.GSPlatform.DebugMsg("Queue: " + message); } }
public RTSessionImpl(string connectToken, string hostName, int tcpPort, int udpPort, bool useOnlyWebSockets, GSInstance instance = null) { ConnectToken = connectToken; this.TcpPort = tcpPort; this.FastPort = udpPort; this.hostName = hostName; this.useOnlyWebSockets = useOnlyWebSockets; this.instance = instance; ActivePeers = new List <int>(); }
static internal void HandleMessage(GSInstance gsInstance, GSObject messageData) { var message = GSMessage.CreateMessageFromObject(gsInstance, messageData); if (_AllMessages != null) { _AllMessages(message); } message.NotifyListeners(); }
private static GSRequest StringToRequest(GSInstance gsInstance, String requestString) { object parsed = GSJson.From(requestString); if (parsed is IDictionary <string, object> ) { String json = ((IDictionary <string, object>)parsed) ["rq"].ToString(); String signature = ((IDictionary <string, object>)parsed) ["sg"].ToString(); String properSig = gsInstance.GSPlatform.MakeHmac(json, gsInstance.GSPlatform.ApiSecret); if (properSig.Equals(signature)) { return(new GSRequest((IDictionary <string, object>)GSJson.From(json))); } } return(null); }
/// <summary> /// Factory method which creates a strongly typed message from the object data provided. /// </summary> internal static GSMessage CreateMessageFromObject(GSInstance gsInstance, GSObject messageData) { if (messageData.ContainsKey("extCode")) { if (handlers.ContainsKey(messageData.Type + "_" + messageData.GetString("extCode"))) { var message = handlers[messageData.Type + "_" + messageData.GetString("extCode")](messageData); message.gsInstance = gsInstance; return(message); } } if (handlers.ContainsKey(messageData.Type)) { var message = handlers[messageData.Type](messageData); message.gsInstance = gsInstance; return(message); } return(null); }
public static LinkedList <GSRequest> Read(GSInstance gsInstance) { Log(gsInstance, "Reading Persistent Queue"); LinkedList <GSRequest> persistantQueue = new LinkedList <GSRequest> (); String path = GetPath(gsInstance); QueueReader qr = new QueueReader(); qr.Initialize(path); string content = qr.ReadFully(); qr.Dispose(); if (content != null) { using (StringReader reader = new StringReader(content)) { string line = null; do { line = reader.ReadLine(); if (line != null && line.Trim().Length > 0) { GSRequest request = StringToRequest(gsInstance, line); if (request != null) { Log(gsInstance, "read " + request.JSON); persistantQueue.AddLast(request); } } }while (line != null); } } return(persistantQueue); }
//Configure the SDK with a FindMatchResponse public void Configure(FindMatchResponse response, Action <int> OnPlayerConnect, Action <int> OnPlayerDisconnect, Action <bool> OnReady, Action <RTPacket> OnPacket, GSInstance instance = null) { if (!response.Port.HasValue) { Debug.Log("Response does not contain a port, exiting."); return; } Configure(response.Host, response.Port.Value, response.AccessToken, OnPlayerConnect, OnPlayerDisconnect, OnReady, OnPacket, instance); }
//Configure the SDK manually public void Configure(string host, int port, string accessToken, Action <int> OnPlayerConnect, Action <int> OnPlayerDisconnect, Action <bool> OnReady, Action <RTPacket> OnPacket, GSInstance instance = null) { m_OnPlayerConnect = OnPlayerConnect; m_OnPlayerDisconnect = OnPlayerDisconnect; m_OnReady = OnReady; m_OnPacket = OnPacket; #if UNITY_WEBGL && !UNITY_EDITOR lastSessionId++; currSessionId = lastSessionId; GSCreateRTSession(instance.name, currSessionId, accessToken, host, port); #else if (session != null) { session.Stop(); } session = GameSparksRT .SessionBuilder() .SetHost(host) .SetPort(port) .SetConnectToken(accessToken) .SetListener(this) .SetGSInstance(instance) #if UNITY_XBOXONE && !UNITY_EDITOR .UseOnlyWebSockets(true) #endif .Build(); #endif }
public Connection(string remoteHost, int port, IRTSessionInternal session) { emptyStream.Wrap(new BinaryWriteMemoryStream()); this.session = session; #if __WINDOWS__ try { Task <EndpointPair> t = Task.Run <EndpointPair>(() => ResolveDNS(remoteHost, port)); t.Wait(); endPoint = t.Result; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); } #else GSInstance instance = session.GetGSInstance(); ResolveRemoteEndpoint(remoteHost, port); }
public static void Write(GSInstance gsInstance, List <GSRequest> queue) { try { String path = GetPath(gsInstance); File.WriteAllText(path, String.Empty); QueueWriter qw = new QueueWriter(); qw.Initialize(path); foreach (var request in queue) { if (request != null) { IDictionary <String, Object> queuedItem = new Dictionary <string, object>(); String json = request.JSON; if (json != null) { Log(gsInstance, "write " + json); queuedItem.Add("rq", json); queuedItem.Add("sg", gsInstance.GSPlatform.MakeHmac(json, gsInstance.GSPlatform.ApiSecret)); qw.WriteLine(GSJson.To(queuedItem)); } } } Log(gsInstance, "Writing Data to disk. "); qw.Dispose(); } catch (Exception e) { Log(gsInstance, e.ToString()); } }
private static string GetPath(GSInstance gsInstance) { return(Path.Combine(gsInstance.GSPlatform.PersistentDataPath, GetFileName(gsInstance))); }
private static string GetFileName(GSInstance gsInstance) { return(string.Format(DataFileName, gsInstance.Name, gsInstance.GSPlatform.UserId)); }
public GameSparksRTSessionBuilder SetGSInstance(GSInstance instance = null) { this.instance = instance; return(this); }