Exemple #1
0
        /// <summary>
        /// connect host mode
        /// </summary>
        internal static void ConnectLocalServer()
        {
            if (LogFilter.Debug)
            {
                Debug.Log("Client Connect Local Server");
            }

            RegisterSystemHandlers(true);

            connectState = ConnectState.Connected;

            // create local connection objects and connect them
            ULocalConnectionToServer connectionToServer = new ULocalConnectionToServer();
            ULocalConnectionToClient connectionToClient = new ULocalConnectionToClient();

            connectionToServer.connectionToClient = connectionToClient;
            connectionToClient.connectionToServer = connectionToServer;

            connection = connectionToServer;
            connection.SetHandlers(handlers);

            // create server connection to local client
            NetworkServer.SetLocalConnection(connectionToClient);
            connectionToClient.Send(new ConnectMessage());
        }
Exemple #2
0
        public static void DisconnectAll()
        {
            DisconnectAllConnections();
            s_LocalConnection = null;

            active            = false;
            localClientActive = false;
        }
Exemple #3
0
        // called by LocalClient to add itself. dont call directly.
        internal static void SetLocalConnection(ULocalConnectionToClient conn)
        {
            if (localConnection != null)
            {
                Debug.LogError("Local Connection already exists");
                return;
            }

            localConnection = conn;
            OnConnected(localConnection);
        }
Exemple #4
0
 internal static void RemoveLocalClient(NetworkConnection localClientConnection)
 {
     if (s_LocalConnection != null)
     {
         s_LocalConnection.Disconnect();
         s_LocalConnection.Dispose();
         s_LocalConnection = null;
     }
     s_LocalClientActive = false;
     RemoveConnection(0);
 }
Exemple #5
0
        internal static void InternalDisconnectAll()
        {
            DisconnectAllConnections();

            if (s_LocalConnection != null)
            {
                s_LocalConnection.Disconnect();
                s_LocalConnection.Dispose();
                s_LocalConnection = null;
            }

            s_Active            = false;
            s_LocalClientActive = false;
        }
Exemple #6
0
        public static void DisconnectAll()
        {
            DisconnectAllConnections();

            if (s_LocalConnection != null)
            {
                s_LocalConnection.Disconnect();
                s_LocalConnection.Dispose();
                s_LocalConnection = null;
            }

            active            = false;
            localClientActive = false;
        }
Exemple #7
0
        // called by LocalClient to add itself. dont call directly.
        internal static int AddLocalClient(LocalClient localClient)
        {
            if (s_LocalConnection != null)
            {
                Debug.LogError("Local Connection already exists");
                return(-1);
            }

            s_LocalConnection = new ULocalConnectionToClient(localClient);
            s_LocalConnection.connectionId = 0;
            AddConnection(s_LocalConnection);

            s_LocalConnection.InvokeHandlerNoData((short)MsgType.Connect);
            return(0);
        }
Exemple #8
0
        // called by LocalClient to add itself. dont call directly.
        internal static int AddLocalClient(LocalClient localClient)
        {
            if (s_LocalConnection != null)
            {
                Debug.LogError("Local Connection already exists");
                return(-1);
            }

            s_LocalConnection = new ULocalConnectionToClient(localClient)
            {
                connectionId = 0
            };
            OnConnected(s_LocalConnection);
            return(0);
        }
Exemple #9
0
        internal void InternalConnectLocalServer()
        {
            // create local connection to server
            connection = new ULocalConnectionToServer();
            SetHandlers(connection);

            // create server connection to local client
            ULocalConnectionToClient connectionToClient = new ULocalConnectionToClient(this);

            NetworkServer.SetLocalConnection(connectionToClient);

            connectState = ConnectState.Connected;

            active = true;
            RegisterSystemHandlers(true);

            packetQueue.Enqueue(MessagePacker.Pack(new ConnectMessage()));
        }
Exemple #10
0
        public static void ConnectHost()
        {
            logger.Log("Client Connect Host to Server");

            RegisterSystemHandlers(true);

            connectState = ConnectState.Connected;

            // create local connection objects and connect them
            ULocalConnectionToServer connectionToServer = new ULocalConnectionToServer();
            ULocalConnectionToClient connectionToClient = new ULocalConnectionToClient();

            connectionToServer.connectionToClient = connectionToClient;
            connectionToClient.connectionToServer = connectionToServer;

            connection = connectionToServer;
            connection.SetHandlers(handlers);

            // create server connection to local client
            NetworkServer.SetLocalConnection(connectionToClient);
        }
        // connect host mode
        internal static void ConnectLocalServer()
        {
            if (LogFilter.Debug)
            {
                Debug.Log("Client Connect Local Server");
            }

            RegisterSystemHandlers(true);

            connectState = ConnectState.Connected;

            // create local connection to server
            connection = new ULocalConnectionToServer();
            connection.SetHandlers(handlers);

            // create server connection to local client
            ULocalConnectionToClient connectionToClient = new ULocalConnectionToClient();

            NetworkServer.SetLocalConnection(connectionToClient);

            localClientPacketQueue.Enqueue(new BufferHolder(MessagePacker.PackWriter(new ConnectMessage())));
        }
Exemple #12
0
        static bool SetupLocalPlayerForConnection(NetworkConnection conn, NetworkIdentity identity)
        {
            if (LogFilter.Debug)
            {
                Debug.Log("NetworkServer SetupLocalPlayerForConnection netID:" + identity.netId);
            }

            ULocalConnectionToClient localConnection = conn as ULocalConnectionToClient;

            if (localConnection != null)
            {
                if (LogFilter.Debug)
                {
                    Debug.Log("NetworkServer AddPlayer handling ULocalConnectionToClient");
                }

                // Spawn this player for other players, instead of SpawnObject:
                if (identity.netId == 0)
                {
                    // it is allowed to provide an already spawned object as the new player object.
                    // so dont spawn it again.
                    identity.OnStartServer(true);
                }
                identity.RebuildObservers(true);
                SendSpawnMessage(identity, null);

                // Set up local player instance on the client instance and update local object map
                localConnection.localClient.AddLocalPlayer(identity);
                identity.SetClientOwner(conn);

                // Trigger OnAuthority
                identity.ForceAuthority(true);

                // Trigger OnStartLocalPlayer
                identity.SetLocalPlayer();
                return(true);
            }
            return(false);
        }
Exemple #13
0
        internal void ConnectHost(NetworkServer server)
        {
            if (LogFilter.Debug)
            {
                Debug.Log("Client Connect Host to Server");
            }

            RegisterSystemHandlers(true);

            connectState = ConnectState.Connected;

            // create local connection objects and connect them
            var connectionToServer = new ULocalConnectionToServer();
            var connectionToClient = new ULocalConnectionToClient();

            connectionToServer.connectionToClient = connectionToClient;
            connectionToClient.connectionToServer = connectionToServer;

            connection = connectionToServer;
            connection.SetHandlers(handlers);

            // create server connection to local client
            server.SetLocalConnection(connectionToClient);
        }
Exemple #14
0
        public static void SetClientReady(NetworkConnection conn)
        {
            if (LogFilter.Debug)
            {
                Debug.Log("SetClientReadyInternal for conn:" + conn.connectionId);
            }

            if (conn.isReady)
            {
                if (LogFilter.Debug)
                {
                    Debug.Log("SetClientReady conn " + conn.connectionId + " already ready");
                }
                return;
            }

            if (conn.playerController == null)
            {
                // this is now allowed
                if (LogFilter.Debug)
                {
                    Debug.LogWarning("Ready with no player object");
                }
            }

            conn.isReady = true;

            ULocalConnectionToClient localConnection = conn as ULocalConnectionToClient;

            if (localConnection != null)
            {
                if (LogFilter.Debug)
                {
                    Debug.Log("NetworkServer Ready handling ULocalConnectionToClient");
                }

                // Setup spawned objects for local player
                // Only handle the local objects for the first player (no need to redo it when doing more local players)
                // and don't handle player objects here, they were done above
                foreach (NetworkIdentity identity in NetworkIdentity.spawned.Values)
                {
                    // Need to call OnStartClient directly here, as it's already been added to the local object dictionary
                    // in the above SetLocalPlayer call
                    if (identity.gameObject != null)
                    {
                        bool visible = identity.OnCheckObserver(conn);
                        if (visible)
                        {
                            identity.AddObserver(conn);
                        }
                        if (!identity.isClient)
                        {
                            if (LogFilter.Debug)
                            {
                                Debug.Log("LocalClient.SetSpawnObject calling OnStartClient");
                            }
                            identity.OnStartClient();
                        }
                    }
                }
                return;
            }

            // Spawn/update all current server objects
            if (LogFilter.Debug)
            {
                Debug.Log("Spawning " + NetworkIdentity.spawned.Count + " objects for conn " + conn.connectionId);
            }

            conn.Send((short)MsgType.SpawnStarted, new ObjectSpawnStartedMessage());

            foreach (NetworkIdentity identity in NetworkIdentity.spawned.Values)
            {
                if (identity == null)
                {
                    Debug.LogWarning("Invalid object found in server local object list (null NetworkIdentity).");
                    continue;
                }
                if (!identity.gameObject.activeSelf)
                {
                    continue;
                }

                if (LogFilter.Debug)
                {
                    Debug.Log("Sending spawn message for current server objects name='" + identity.name + "' netId=" + identity.netId);
                }

                bool visible = identity.OnCheckObserver(conn);
                if (visible)
                {
                    identity.AddObserver(conn);
                }
            }

            conn.Send((short)MsgType.SpawnFinished, new ObjectSpawnFinishedMessage());
        }