Beispiel #1
0
 private static void     OnServerKilled(NGServerInstance instance)
 {
     if (ConnectionsManager.KillServer != null)
     {
         ConnectionsManager.KillServer(instance);
     }
 }
Beispiel #2
0
 private static void     OnServerUpdated(NGServerInstance instance)
 {
     if (ConnectionsManager.UpdateServer != null)
     {
         ConnectionsManager.UpdateServer(instance);
     }
 }
Beispiel #3
0
 private static void     OnServerAdded(NGServerInstance instance)
 {
     if (ConnectionsManager.NewServer != null)
     {
         ConnectionsManager.NewServer(instance);
     }
 }
Beispiel #4
0
        public NGServerInstance Find(Client client)
        {
            NGServerInstance instance = null;

            lock (this.NGServerInstances)
            {
                instance = this.NGServerInstances.Find(s => s.client == client);
            }

            return(instance);
        }
Beispiel #5
0
        public NGServerInstance Find(string endPoint)
        {
            NGServerInstance instance = null;

            lock (this.NGServerInstances)
            {
                instance = this.NGServerInstances.Find(s => s.endPoint == endPoint);
            }

            return(instance);
        }
Beispiel #6
0
        private bool    TryKillServer(NGServerInstance instance)
        {
            if (instance.client == null)
            {
                this.NGServerInstances.Remove(instance);

                if (this.KillServer != null)
                {
                    this.KillServer(instance);
                }

                return(true);
            }

            return(false);
        }
Beispiel #7
0
        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);
        }
Beispiel #8
0
        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");
            }
        }
Beispiel #9
0
        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;
                        }
                    }
                }
            }
        }
Beispiel #10
0
        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);
            }
        }
Beispiel #11
0
        /// <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;
            }
        }
Beispiel #12
0
 private void    OnInstanceUpdated(NGServerInstance instance)
 {
     EditorApplication.delayCall += this.editorWindow.Repaint;
 }