Exemplo n.º 1
0
        /// <summary>Disconnects the client and stops all network traffic.</summary>
        private void Disconnect()
        {
            Debug.Log($"{tcp.socket.Client.RemoteEndPoint} has disconnected.");

            ThreadManager.ExecuteOnMainThread(() => {
                UnityEngine.Object.Destroy(player.gameObject);
                player = null;
            });

            tcp.Disconnect();
            udp.Disconnect();

            ServerSend.PlayerDisconnected(id);
        }
Exemplo n.º 2
0
        public static void Stop()
        {
            foreach (Client c in clients.Values)
            {
                ServerSend.PlayerDisconnected(c.id);
            }
            clients.Clear();
            foreach (Entity e in entities.Values)
            {
                GameObject.Destroy(e.gameObject);
            }
            entities.Clear();

            if (tcpListener != null)
            {
                tcpListener.Stop();
            }
            if (udpListener != null)
            {
                udpListener.Close();
            }
        }