Esempio n. 1
0
        public static void Disconnect()
        {
            byte error;

            NetworkTransport.Disconnect(hostId, connectionId, out error);

            // Remove all players
            foreach (NetworkedEntity e in EntityManager.ents.Values)
            {
                GameObject.Destroy(e.gameObject);
            }
            EntityManager.ents.Clear();

            hostId          = -1;
            isServer        = false;
            currentLobby    = null;
            nextPlayerIndex = 1;

            NetworkEvents.onDisconnect?.Invoke();
            connectionToPlayer.Clear();
            isConnected = false;
        }
Esempio n. 2
0
        public static void HostLobby(LobbyInfo i)
        {
            ConnectionConfig config            = new ConnectionConfig();
            int          myReliableChannelId   = config.AddChannel(QosType.Reliable);
            int          myUnreliableChannelId = config.AddChannel(QosType.Unreliable);
            HostTopology topology = new HostTopology(config, 10);

            hostId       = NetworkTransport.AddHost(topology, 8080);
            isServer     = true;
            currentLobby = i;
            if (!i.isServer)
            {
                // Connect the host
                connectedClients.Add(0);
                connectionToPlayer[0] = 0;

                SpawnPlayerPrefab(true);
            }

            MonoBehaviour.Instantiate(Resources.Load("Server Entity", typeof(GameObject)) as GameObject);
            isConnected = true;
            EntityManager.StartServer();
        }