private static void OnServerKilled(NGServerInstance instance) { if (ConnectionsManager.KillServer != null) { ConnectionsManager.KillServer(instance); } }
private static void OnServerUpdated(NGServerInstance instance) { if (ConnectionsManager.UpdateServer != null) { ConnectionsManager.UpdateServer(instance); } }
private static void OnServerAdded(NGServerInstance instance) { if (ConnectionsManager.NewServer != null) { ConnectionsManager.NewServer(instance); } }
public NGServerInstance Find(Client client) { NGServerInstance instance = null; lock (this.NGServerInstances) { instance = this.NGServerInstances.Find(s => s.client == client); } return(instance); }
public NGServerInstance Find(string endPoint) { NGServerInstance instance = null; lock (this.NGServerInstances) { instance = this.NGServerInstances.Find(s => s.endPoint == endPoint); } return(instance); }
private bool TryKillServer(NGServerInstance instance) { if (instance.client == null) { this.NGServerInstances.Remove(instance); if (this.KillServer != null) { this.KillServer(instance); } return(true); } return(false); }
public NGServerInstance AddServer(string deviceName, string endPoint) { NGServerInstance instance = new NGServerInstance() { deviceName = deviceName, endPoint = endPoint, pingMaxLastTime = Utility.ConvertToUnixTimestamp(DateTime.Now) + AutoDetectUDPListener.UDPServerPingLifetime }; lock (this.NGServerInstances) { this.NGServerInstances.Add(instance); } if (this.NewServer != null) { this.NewServer(instance); } return(instance); }
private static void AsyncOpenClient(object credentials) { EditorWindow window = (credentials as object[])[0] as EditorWindow; AbstractTcpClient clientProvider = (credentials as object[])[1] as AbstractTcpClient; string address = (string)(credentials as object[])[2]; int port = (int)(credentials as object[])[3]; Action <Client> onComplete = (credentials as object[])[4] as Action <Client>; Client client = clientProvider.CreateClient(address, port); try { if (client != null) { Utility.RegisterIntervalCallback(ConnectionsManager.Update, 0); ConnectionsManager.clients.Add(client); string server = address + ':' + port; NGServerInstance instance = ConnectionsManager.udpListener.Find(server); if (instance == null) { instance = ConnectionsManager.udpListener.AddServer(server, server); } instance.users.Add(window); instance.client = client; } onComplete(client); } catch (Exception ex) { InternalNGDebug.LogException(ex); InternalNGDebug.LogError("Connection on " + address + ":" + port + " failed."); InternalNGDebug.LogError("Make sure your firewall allows TCP connection on " + port + "."); InternalNGDebug.LogError("Check if Stripping Level is not set on \"Use micro mscorlib\"."); InternalNGDebug.LogError("Try to connect Unity Profiler to guarantee the device is reachable."); InternalNGDebug.LogError("Find more tips at: https://bitbucket.org/Mikilo/neguen-tools/wiki/Home#markdown-header-31-guidances"); } }
private void CheckNGServersAlive() { lock (this.NGServerInstances) { double now = Utility.ConvertToUnixTimestamp(DateTime.Now); for (int i = 0; i < this.NGServerInstances.Count; i++) { if (this.NGServerInstances[i].pingMaxLastTime + AutoDetectUDPListener.UDPServerPingLifetime < now) { //InternalNGDebug.InternalLog(this.NGServerInstances[i].endPoint + " is dead"); NGServerInstance instance = this.NGServerInstances[i]; if (this.TryKillServer(instance) == true) { --i; } } } } }
public static Thread OpenClient(EditorWindow user, AbstractTcpClient clientProvider, string address, int port, Action <Client> onComplete) { string server = address + ':' + port; NGServerInstance instance = ConnectionsManager.udpListener.Find(server); if (instance != null && instance.client != null) { instance.users.Add(user); onComplete(instance.client); return(null); } else { Thread connectingThread = new Thread(ConnectionsManager.AsyncOpenClient) { Name = "Connecting Client" }; connectingThread.Start(new object[] { user, clientProvider, address, port, onComplete }); return(connectingThread); } }
/// <summary>Removes a user from the connection. Closes the Client in the very near future if no one is using it, giving time for ultimate packets.</summary> /// <param name="client"></param> public static void Close(Client client, EditorWindow user = null) { NGServerInstance instance = ConnectionsManager.udpListener.Find(client); if (instance == null) { return; } if (user != null) { user.Repaint(); instance.users.Remove(user); } else { for (int i = 0; i < instance.users.Count; i++) { instance.users[i].Repaint(); } instance.users.Clear(); } // Nobody is on this connection anymore. Drop it. if (instance.users.Count == 0) { if (ConnectionsManager.ClientClosed != null) { ConnectionsManager.ClientClosed(client); } // Give Client the time to send the disconnect packet. EditorApplication.delayCall += () => Utility.StartBackgroundTask(ConnectionsManager.DelayDiscAndClean(user, client)); instance.client = null; } }
private void OnInstanceUpdated(NGServerInstance instance) { EditorApplication.delayCall += this.editorWindow.Repaint; }