A High level network connection. This is used for connections from client-to-server and for connection from server-to-client.

Inheritance: IDisposable
 public int AddLocal(NetworkConnection conn)
 {
     this.m_LocalConnections.Add(conn);
     int num = -this.m_LocalConnections.Count;
     conn.connectionId = num;
     return num;
 }
 public override void OnClientDisconnect(UnityEngine.Networking.NetworkConnection conn)
 {
     base.OnClientDisconnect(conn);
     Debug.Log(NetworkServer.connections);
     // server_ip = "";
     StartGameClient();
 }
Beispiel #3
0
    public override void OnClientDisconnect(UnityEngine.Networking.NetworkConnection conn)
    {
        base.OnClientDisconnect(conn);

        server_ip = "";
        StartGameClient();
    }
 public int Add(int connId, NetworkConnection conn)
 {
     if (connId < 0)
     {
         if (LogFilter.logWarn)
         {
             Debug.LogWarning("ConnectionArray Add bad id " + connId);
         }
         return -1;
     }
     if ((connId < this.m_Connections.Count) && (this.m_Connections[connId] != null))
     {
         if (LogFilter.logWarn)
         {
             Debug.LogWarning("ConnectionArray Add dupe at " + connId);
         }
         return -1;
     }
     while (connId > (this.m_Connections.Count - 1))
     {
         this.m_Connections.Add(null);
     }
     this.m_Connections[connId] = conn;
     return connId;
 }
Beispiel #5
0
        /// <summary>Called on clients when a network error occurs.</summary>
        public override void OnClientError(NetworkConnection conn, int errorCode)
        {
            Log("OnClientError");

            //ChangeTo(mainMenuPanel);
            //infoPanel.Display("Cient error : " + (errorCode == 6 ? "timeout" : errorCode.ToString()), "Close", null);
        }
 public bool SendToTransport(NetworkConnection conn, int channelId)
 {
     byte num;
     bool flag = true;
     if (!conn.TransportSend(this.m_Buffer, (ushort) this.m_Position, channelId, out num) && (!this.m_IsReliable || (num != 4)))
     {
         if (LogFilter.logError)
         {
             Debug.LogError(string.Concat(new object[] { "Failed to send internal buffer channel:", channelId, " bytesToSend:", this.m_Position }));
         }
         flag = false;
     }
     if (num != 0)
     {
         if (this.m_IsReliable && (num == 4))
         {
             NetworkDetailStats.IncrementStat(NetworkDetailStats.NetworkDirection.Outgoing, 30, "msg", 1);
             return false;
         }
         if (LogFilter.logError)
         {
             Debug.LogError(string.Concat(new object[] { "Send Error: ", (NetworkError) num, " channel:", channelId, " bytesToSend:", this.m_Position }));
         }
         flag = false;
     }
     this.m_Position = 0;
     return flag;
 }
 internal void AddObserver(NetworkConnection conn)
 {
     if (this.m_Observers == null)
     {
         if (LogFilter.logError)
         {
             Debug.LogError("AddObserver for " + base.gameObject + " observer list is null");
         }
     }
     else if (this.m_ObserverConnections.Contains(conn.connectionId))
     {
         if (LogFilter.logDebug)
         {
             Debug.Log(string.Concat(new object[] { "Duplicate observer ", conn.address, " added for ", base.gameObject }));
         }
     }
     else
     {
         if (LogFilter.logDev)
         {
             Debug.Log(string.Concat(new object[] { "Added observer ", conn.address, " added for ", base.gameObject }));
         }
         this.m_Observers.Add(conn);
         this.m_ObserverConnections.Add(conn.connectionId);
         conn.AddToVisList(this);
     }
 }
Beispiel #8
0
        public override void OnLobbyClientSceneChanged(NetworkConnection conn) {
			if (!conn.playerControllers [0].unetView.isLocalPlayer)
				return;

			if (SceneManager.GetActiveScene ().name == lobbyScene) {
				if (topPanel.isInGame) {
					ChangeTo (lobbyPanel);
					if (isMatchmaking) {
						if (conn.playerControllers [0].unetView.isServer) {
							backDelegate = StopHostToMenu;
						} else {
							backDelegate = QuitLobbyToMenu;
						}
					} else {
						if (conn.playerControllers [0].unetView.isClient) {
							backDelegate = StopHostToMenu;
						} else {
							backDelegate = QuitLobbyToMenu;
						}
					}
				} else {
					ChangeTo (mainMenuPanel);
				}

				topPanel.ToggleVisibility (true);
				topPanel.isInGame = false;
			} else {
				ChangeTo (null);
				Destroy (GameObject.Find ("MainMenuUI(Clone)"));

				backDelegate = StopGameClbk;
				topPanel.isInGame = true;
				topPanel.ToggleVisibility (false);
			}
		}
Beispiel #9
0
        /// <summary>This is called on the client when the client is finished loading a new networked scene</summary>
        public override void OnLobbyClientSceneChanged(NetworkConnection conn)
        {
            Log("OnLobbyClientSceneChanged:{0}", conn);

            if (OnUNetSceneChanged != null)
                OnUNetSceneChanged(conn);
        }
        public override void OnServerDisconnect(NetworkConnection conn)
        {
            MyDebug.LogF("NetworkManagerCallbacks,OnServerDisconnect: {0})", conn.address);
            base.OnServerDisconnect(conn);

            if (NetworkPlayManager.Instance.OnServerDisconnect != null)
                NetworkPlayManager.Instance.OnServerDisconnect();
        }
 protected virtual void OnDisconnect(UnityEngine.Networking.NetworkConnection conn)
 {
     if (lobbyManager != null)
     {
         LobbyManager.s_Singleton.ShowDefaultPanel();
         LobbyManager.s_Singleton.ShowInfoPopup("Disconnected from server");
         lobbyManager.Disconnect();
     }
 }
 public override void OnLobbyClientConnect(NetworkConnection conn)
 {
     base.OnLobbyClientConnect(conn);
     Type serverType = typeof(NetworkServer);
     FieldInfo info = serverType.GetField("maxPacketSize",
         BindingFlags.NonPublic | BindingFlags.Static);
     ushort maxPackets = 1500;
     info.SetValue(null, maxPackets);
 }
Beispiel #13
0
        /// <summary>Called on the client when connected to a server</summary>
        public override void OnClientConnect(NetworkConnection conn)
        {
            Log("OnClientConnect:{0}", conn);

            base.OnClientConnect(conn);

            if (OnUNetClientConnect != null)
                OnUNetClientConnect();
        }
Beispiel #14
0
 public override void OnServerConnect(UnityEngine.Networking.NetworkConnection connection)
 {
     if (m_Client != null && m_Client.connection.connectionId != connection.connectionId)
     {
         if (OnClientHasConnected != null)
         {
             OnClientHasConnected(connection.connectionId);
         }
     }
 }
Beispiel #15
0
 /// <summary>
 /// returns NetworkUsers associated  to a NetworkConnection
 /// </summary>
 /// <param name="conn"></param>
 /// <returns>returns NetworkUsers associated  to a NetworkConnection</returns>
 private static RoR2.NetworkUser[] GetConnectionNetworkUsers(UnityEngine.Networking.NetworkConnection conn)
 {
     System.Collections.Generic.List <UnityEngine.Networking.PlayerController> playerControllers = conn.playerControllers;
     RoR2.NetworkUser[] array = new RoR2.NetworkUser[playerControllers.Count];
     for (int i = 0; i < playerControllers.Count; i++)
     {
         array[i] = playerControllers[i].gameObject.GetComponent <RoR2.NetworkUser>();
     }
     return(array);
 }
Beispiel #16
0
 private static void ClientsideConnect(UnityEngine.Networking.NetworkConnection connection)
 {
     try {
         ModListMessage msg = new ModListMessage(localModList, false);
         connection.SendByChannel(messageIndex, msg, QosChannelIndex.defaultReliable.intVal);
         MessageWaitClientAsync(connection, messageWaitTimeClient);
     } catch (Exception e) {
         Fail(e, "ClientsideConnect");
     }
 }
        // NetBehaviour override
        public override bool OnCheckObserver(NetworkConnection newObserver)
        {
            if (this.forceHidden)
            {
                return false;
            }

            PlayerController playerController = newObserver.playerControllers[0];
            Vector3 position = playerController.unetView.get_gameObject().get_transform().get_position();
            return (position - base.get_transform().get_position()).get_magnitude() < (float)this.visRange;
        }
        /// <summary>
        /// Called on the client when ever the scene changes.
        /// 
        /// todo: Don't handle player spawning in here. We currently do it here because we want to spawn
        /// a player object as soon as we change to the online scene. However further down the road we
        /// will have more than just one scene and will eventually run into problems where this function
        /// is called for every scene. Which we don't want potentially. Rather we will not be unloading
        /// spawned player objects on scene changes.
        /// </summary>
        /// <param name="conn"></param>
        public override void OnClientSceneChanged(NetworkConnection conn)
        {
            base.OnClientSceneChanged(conn);
            Debug.Log("OnClientSceneChanged");

            // spawn our player
            var msg = new AddPlayerMessage();
            msg.playerPrefabIndex = networkPrefabIndex;
            msg.name = localPlayerName;
            ClientScene.AddPlayer(conn, 0, msg);
        }
Beispiel #19
0
        protected virtual void OnDisconnect(UnityEngine.Networking.NetworkConnection conn)
        {
            if (lobbyManager != null)
            {
                LobbyManager.s_Singleton.ShowDefaultPanel();

                infoPanel.Display("Disconnected from server", "Cancel", null);

                lobbyManager.Disconnect();
            }
        }
 private static bool CheckConnectionIsReadyToBegin(NetworkConnection conn)
 {
     foreach (PlayerController controller in conn.playerControllers)
     {
         if (controller.IsValid && !controller.gameObject.GetComponent<NetworkLobbyPlayer>().readyToBegin)
         {
             return false;
         }
     }
     return true;
 }
Beispiel #21
0
        public override void OnClientConnect(NetworkConnection conn)
        {
            base.OnClientConnect (conn);

            infoPanel.gameObject.SetActive (false);

            if (!NetworkServer.active) {//only for pure client (not self hosting client)
                ChangeTo (lobbyPanel);
                backDelegate = StopClientClbk;
                SetServerInfo ("Client", networkAddress);
            }
        }
        /// <summary>
        /// Called on the server when a new client connects and is requesting to be spawned as a player object.
        /// </summary>
        /// <param name="conn"></param>
        /// <param name="playerControllerId"></param>
        /// <param name="netMsg"></param>
        public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId, NetworkReader netMsg)
        {
            //base.OnServerAddPlayer(conn, playerControllerId, netMsg);

            var msg = netMsg.ReadMessage<AddPlayerMessage>();
            Debug.Log("Adding player... " + msg.name + " " + playerPrefabs[msg.playerPrefabIndex].name);
            GameObject player = (GameObject)Instantiate(playerPrefabs[msg.playerPrefabIndex], Vector3.zero, Quaternion.identity);

            var gamePlayer = player.GetComponent<GamePlayer>();
            gamePlayer.displayName = msg.name;

            NetworkServer.AddPlayerForConnection(conn, player, playerControllerId);
        }
        public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId)
        {
            GameObject player = (GameObject)Instantiate(playerPrefab);
			
		    player.AppendTo(playersContainer);
			player.transform.position = startPositions[0].position;
			startPositions.RemoveAt(0);
			
	        NetworkServer.AddPlayerForConnection(conn, player, playerControllerId);
			PlayerController controller = player.GetComponent<PlayerController>();
            
			controller.Init();
        }
        public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId)
        {
            GameObject player;
            Debug.Log ("Adding Player");
            // Ensure that client always spawns on client side, host always spawns on server side
            player = (GameObject)GameObject.Instantiate(playerPrefab, manager.GetStartPosition().transform.position, Quaternion.identity);
            player.transform.SetParent(imageTarget);

            //GameObject.Find ("Notification").GetComponent<Text> ().text = "A new Player joined the game.";
            //GameObject.Find ("NPanel").SetActive (true);
            //StartCoroutine (HideNotification ());
            NetworkServer.AddPlayerForConnection (conn, player, playerControllerId);
        }
 internal bool InvokeHandler(short msgType, NetworkConnection conn, NetworkReader reader, int channelId)
 {
     if (this.m_MsgHandlers.ContainsKey(msgType))
     {
         this.m_MessageInfo.msgType = msgType;
         this.m_MessageInfo.conn = conn;
         this.m_MessageInfo.reader = reader;
         this.m_MessageInfo.channelId = channelId;
         NetworkMessageDelegate networkMessageDelegate = this.m_MsgHandlers[msgType];
         networkMessageDelegate(this.m_MessageInfo);
         return true;
     }
     return false;
 }
        public static void OnServerDisconnect(NetworkConnection conn)
        {
            var id = conn.connectionId;

            if (!proxies.ContainsKey(id))
            {
                Debug.LogWarning("Proxy destruction requested for client " + id + " but proxy wasn't registered");
                return;
            }

            var proxy = proxies[id];
            NetworkServer.Destroy(proxy);

            proxies.Remove(id);
        }
 public ChannelBuffer(NetworkConnection conn, int bufferSize, byte cid, bool isReliable)
 {
   this.m_Connection = conn;
   this.m_MaxPacketSize = bufferSize - 100;
   this.m_CurrentPacket = new ChannelPacket(this.m_MaxPacketSize, isReliable);
   this.m_ChannelId = cid;
   this.m_MaxPendingPacketCount = 16;
   this.m_IsReliable = isReliable;
   if (!isReliable)
     return;
   this.m_PendingPackets = new Queue<ChannelPacket>();
   if (ChannelBuffer.s_FreePackets != null)
     return;
   ChannelBuffer.s_FreePackets = new List<ChannelPacket>();
 }
        public override void OnServerConnect(NetworkConnection conn)
        {
            if (conn.address != "localServer")
            {
                var guilder = Instantiate(Guider);
            }

            NumberOfPlayer++;
            Debug.Log("NumberOfPlayer");
            World.SetActive(true);
            if (NumberOfPlayer == 2)
            {
                GameStarted = true;
                var guiderConroller = Instantiate(GuiderController);
                NetworkServer.Spawn(guiderConroller);
            }
        }
Beispiel #29
0
 public ChannelBuffer(NetworkConnection conn, int bufferSize, byte cid, bool isReliable)
 {
     this.m_Connection = conn;
     this.m_MaxPacketSize = bufferSize - 100;
     this.m_CurrentPacket = new ChannelPacket(this.m_MaxPacketSize, isReliable);
     this.m_ChannelId = cid;
     this.m_MaxPendingPacketCount = 0x10;
     this.m_IsReliable = isReliable;
     if (isReliable)
     {
         this.m_PendingPackets = new List<ChannelPacket>();
         if (s_FreePackets == null)
         {
             s_FreePackets = new List<ChannelPacket>();
         }
     }
 }
    private void OnGamePlayerConnected(UnityEngine.Networking.NetworkConnection conn)
    {
        if (DEBUG)
        {
            Debug.Log("OnPlayerConnected");
        }
        ConnectedPlayerCount++;

        if (ConnectedPlayerCount >= MIN_REQ_PLAYERS)
        {
            _innerProcess.MoveNext(Command.EnoughPlayersJoined);
        }
        OnStateUpdate();

        if (_meshTransferProcess.CurrentState.Equals(MeshServerLifecycle.ProcessState.HasMesh))
        {
            _networkLobbyManager.ClientGetMesh(_meshServerAddress, _meshServerPort, conn.connectionId);
        }
    }
Beispiel #31
0
 public bool AssignClientAuthority(NetworkConnection conn)
 {
     if (!this.isServer)
     {
         if (LogFilter.logError)
         {
             Debug.LogError("AssignClientAuthority can only be call on the server for spawned objects.");
         }
         return false;
     }
     if (!this.localPlayerAuthority)
     {
         if (LogFilter.logError)
         {
             Debug.LogError("AssignClientAuthority can only be used for NetworkIdentity component with LocalPlayerAuthority set.");
         }
         return false;
     }
     if ((this.m_ClientAuthorityOwner != null) && (conn != this.m_ClientAuthorityOwner))
     {
         if (LogFilter.logError)
         {
             Debug.LogError("AssignClientAuthority for " + base.gameObject + " already has an owner. Use RemoveClientAuthority() first.");
         }
         return false;
     }
     if (conn == null)
     {
         if (LogFilter.logError)
         {
             Debug.LogError("AssignClientAuthority for " + base.gameObject + " owner cannot be null. Use RemoveClientAuthority() instead.");
         }
         return false;
     }
     this.m_ClientAuthorityOwner = conn;
     this.m_ClientAuthorityOwner.AddOwnedObject(this);
     ClientAuthorityMessage msg = new ClientAuthorityMessage {
         netId = this.netId,
         authority = true
     };
     conn.Send(15, msg);
     return true;
 }
 public int Add(int connId, NetworkConnection conn)
 {
   if (connId < 0)
   {
     if (LogFilter.logWarn)
       Debug.LogWarning((object) ("ConnectionArray Add bad id " + (object) connId));
     return -1;
   }
   if (connId < this.m_Connections.Count && this.m_Connections[connId] != null)
   {
     if (LogFilter.logWarn)
       Debug.LogWarning((object) ("ConnectionArray Add dupe at " + (object) connId));
     return -1;
   }
   while (connId > this.m_Connections.Count - 1)
     this.m_Connections.Add((NetworkConnection) null);
   this.m_Connections[connId] = conn;
   return connId;
 }
 internal void AssignAuthorityCallback(NetworkConnection conn, NetworkIdentity uv, bool authorityState)
 {
     PeerAuthorityMessage msg = new PeerAuthorityMessage {
         connectionId = conn.connectionId,
         netId = uv.netId,
         authorityState = authorityState
     };
     if (LogFilter.logDebug)
     {
         Debug.Log("AssignAuthorityCallback send for netId" + uv.netId);
     }
     for (int i = 0; i < NetworkServer.connections.Count; i++)
     {
         NetworkConnection connection = NetworkServer.connections[i];
         if (connection != null)
         {
             connection.Send(0x12, msg);
         }
     }
 }
Beispiel #34
0
        public override void OnStartLocalPlayer()
        {
            //I kept this part in, because I don't know if this is the function that sets isLocalPlayer to true,
            //or this function triggers after isLocalPlayer is set to true.
            base.OnStartLocalPlayer();

            NetworkIdentity identity = this.GetComponent<NetworkIdentity>();
            if (this.isServer) {
                this.owner = identity.connectionToClient;
            }
            else {
                this.owner = identity.connectionToServer;
            }

            //Initializing remaining variables
            this.doesGlobalManagerExist = false;

            //On initialization, make the client (local client and remote clients) tell the server to call on an [ClientRpc] method.
            CmdCall();
        }
    private void OnPlayerGameLoaded(UnityEngine.Networking.NetworkConnection conn)
    {
        foreach (var lobbyPlayer in GameObject.FindObjectsOfType <NetworkCompat.NetworkLobbyPlayer> ())
        {
            if (lobbyPlayer.serverId == conn.connectionId)
            {
                lobbyPlayer.gameLoaded = true;
            }
        }

        if (AreAllGamePlayersLoaded())
        {
            if (OnAllPlayersLoadedEvent != null)
            {
                OnAllPlayersLoadedEvent();
            }
        }

        OnStateUpdate();
    }
    private void OnGamePlayerDisconnected(UnityEngine.Networking.NetworkConnection conn)
    {
        if (DEBUG)
        {
            Debug.Log("OnPlayerDisconnected");
        }
        ConnectedPlayerCount--;

        if (OnPlayerDisconnectEvent != null)
        {
            OnPlayerDisconnectEvent();
        }

        foreach (var lobbyPlayer in GameObject.FindObjectsOfType <NetworkCompat.NetworkLobbyPlayer> ())
        {
            if (lobbyPlayer.serverId == conn.connectionId)
            {
                lobbyPlayer.playingGame = false;
            }
        }

        if (AreAllGamePlayersLoaded())
        {
            if (OnAllPlayersLoadedEvent != null)
            {
                OnAllPlayersLoadedEvent();
            }
        }

        if (CurrentState().Equals(ServerLifecycle.ProcessState.CountingDown))
        {
            _networkLobbyManager.AllClientsCancelGameCountdown("not enough players");
            CancelInvoke();
        }

        if (ConnectedPlayerCount < MIN_REQ_PLAYERS)
        {
            _innerProcess.MoveNext(Command.TooFewPlayersRemaining);
        }
        OnStateUpdate();
    }
 public override bool OnCheckObserver(NetworkConnection newObserver)
 {
   if (this.forceHidden)
     return false;
   GameObject gameObject = (GameObject) null;
   using (List<PlayerController>.Enumerator enumerator = newObserver.playerControllers.GetEnumerator())
   {
     while (enumerator.MoveNext())
     {
       PlayerController current = enumerator.Current;
       if (current != null && (Object) current.gameObject != (Object) null)
       {
         gameObject = current.gameObject;
         break;
       }
     }
   }
   if ((Object) gameObject == (Object) null)
     return false;
   return (double) (gameObject.transform.position - this.transform.position).magnitude < (double) this.visRange;
 }
 public NetworkClient(NetworkConnection conn)
 {
     this.m_NetworkConnectionClass = typeof(NetworkConnection);
     this.m_ServerIp = "";
     this.m_ClientId = -1;
     this.m_ClientConnectionId = -1;
     this.m_MessageHandlers = new NetworkMessageHandlers();
     this.m_AsyncConnect = ConnectState.None;
     this.m_RequestedServerHost = "";
     if (LogFilter.logDev)
     {
         Debug.Log("Client created version " + UnityEngine.Networking.Version.Current);
     }
     this.m_MsgBuffer = new byte[0xffff];
     this.m_MsgReader = new NetworkReader(this.m_MsgBuffer);
     AddClient(this);
     SetActive(true);
     this.m_Connection = conn;
     this.m_AsyncConnect = ConnectState.Connected;
     conn.SetHandlers(this.m_MessageHandlers);
     this.RegisterSystemHandlers(false);
 }
 public override bool OnCheckObserver(NetworkConnection newObserver)
 {
     if (this.forceHidden)
     {
         return false;
     }
     GameObject gameObject = null;
     foreach (PlayerController controller in newObserver.playerControllers)
     {
         if ((controller != null) && (controller.gameObject != null))
         {
             gameObject = controller.gameObject;
             break;
         }
     }
     if (gameObject == null)
     {
         return false;
     }
     Vector3 vector2 = gameObject.transform.position - base.transform.position;
     return (vector2.magnitude < this.visRange);
 }
 public bool ContainsPlayer(GameObject player, out NetworkConnection conn)
 {
     conn = null;
     if (player != null)
     {
         for (int i = this.LocalIndex; i < this.m_Connections.Count; i++)
         {
             conn = this.Get(i);
             if (conn != null)
             {
                 for (int j = 0; j < conn.playerControllers.Count; j++)
                 {
                     if (conn.playerControllers[j].IsValid && (conn.playerControllers[j].gameObject == player))
                     {
                         return true;
                     }
                 }
             }
         }
     }
     return false;
 }
 public override void OnClientDisconnect(NetworkConnection conn)
 {
     OnLobbyClientDisconnect(conn);
     base.OnClientDisconnect(conn);
 }
 /// <summary>
 /// This allows customization of the creation of the GamePlayer object on the server.
 /// <para>By default the gamePlayerPrefab is used to create the game-player, but this function allows that behaviour to be customized. The object returned from the function will be used to replace the lobby-player on the connection.</para>
 /// </summary>
 /// <param name="conn">The connection the player object is for.</param>
 /// <param name="playerControllerId">The controllerId of the player on the connnection.</param>
 /// <returns>A new GamePlayer object.</returns>
 public virtual GameObject OnLobbyServerCreateGamePlayer(NetworkConnection conn, short playerControllerId)
 {
     return(null);
 }
 /// <summary>
 /// This is called on the server when a client disconnects.
 /// </summary>
 /// <param name="conn">The connection that disconnected.</param>
 public virtual void OnLobbyServerDisconnect(NetworkConnection conn)
 {
 }
Beispiel #44
0
 public override void OnServerDisconnect(NetworkConnection conn)
 {
     base.OnServerDisconnect(conn);
     Debug.Log("ServerDisconnect");
 }
 /// <summary>
 /// This is called on the server when a player is removed.
 /// </summary>
 /// <param name="conn">The connection the player object is for.</param>
 /// <param name="playerControllerId">The controllerId of the player that was removed.</param>
 public virtual void OnLobbyServerPlayerRemoved(NetworkConnection conn, short playerControllerId)
 {
 }
 /// <summary>
 /// This is called on the client when disconnected from a server.
 /// </summary>
 /// <param name="conn">The connection that disconnected.</param>
 public virtual void OnLobbyClientDisconnect(NetworkConnection conn)
 {
 }
Beispiel #47
0
 protected virtual void OnDisconnect(UnityEngine.Networking.NetworkConnection conn)
 {
     ShowErrorPanel();
 }
Beispiel #48
0
 public override void OnClientConnect(UnityEngine.Networking.NetworkConnection conn)
 {
     base.OnClientConnect(conn);
 }
Beispiel #49
0
 public override void OnClientError(UnityEngine.Networking.NetworkConnection conn, int errorCode)
 {
     base.OnClientError(conn, errorCode);
     StartGameClient();
 }
Beispiel #50
0
        /// <summary>
        ///   <para>This adds a player object for this client. This causes an AddPlayer message to be sent to the server, and NetworkManager.OnServerAddPlayer will be called. If an extra message was passed to AddPlayer, then OnServerAddPlayer will be called with a NetworkReader that contains the contents of the message.</para>
        /// </summary>
        /// <param name="readyConn">The connection to become ready for this client.</param>
        /// <param name="playerControllerId">The local player ID number.</param>
        /// <param name="extraMessage">An extra message object that can be passed to the server for this player.</param>
        /// <returns>
        ///   <para>True if player was added.</para>
        /// </returns>
        public static bool AddPlayer(NetworkConnection readyConn, short playerControllerId, MessageBase extraMessage)
        {
            if ((int)playerControllerId < 0)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError((object)("ClientScene::AddPlayer: playerControllerId of " + (object)playerControllerId + " is negative"));
                }
                return(false);
            }
            if ((int)playerControllerId > 32)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError((object)("ClientScene::AddPlayer: playerControllerId of " + (object)playerControllerId + " is too high, max is " + (object)32));
                }
                return(false);
            }
            if ((int)playerControllerId > 16 && LogFilter.logWarn)
            {
                Debug.LogWarning((object)("ClientScene::AddPlayer: playerControllerId of " + (object)playerControllerId + " is unusually high"));
            }
            while ((int)playerControllerId >= ClientScene.s_LocalPlayers.Count)
            {
                ClientScene.s_LocalPlayers.Add(new PlayerController());
            }
            if (readyConn == null)
            {
                if (!ClientScene.s_IsReady)
                {
                    if (LogFilter.logError)
                    {
                        Debug.LogError((object)"Must call AddPlayer() with a connection the first time to become ready.");
                    }
                    return(false);
                }
            }
            else
            {
                ClientScene.s_IsReady         = true;
                ClientScene.s_ReadyConnection = readyConn;
            }
            PlayerController playerController;

            if (ClientScene.s_ReadyConnection.GetPlayerController(playerControllerId, out playerController) && playerController.IsValid && (Object)playerController.gameObject != (Object)null)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError((object)("ClientScene::AddPlayer: playerControllerId of " + (object)playerControllerId + " already in use."));
                }
                return(false);
            }
            if (LogFilter.logDebug)
            {
                Debug.Log((object)("ClientScene::AddPlayer() for ID " + (object)playerControllerId + " called with connection [" + (object)ClientScene.s_ReadyConnection + "]"));
            }
            if (ClientScene.s_ReconnectId == -1)
            {
                AddPlayerMessage addPlayerMessage = new AddPlayerMessage();
                addPlayerMessage.playerControllerId = playerControllerId;
                if (extraMessage != null)
                {
                    NetworkWriter writer = new NetworkWriter();
                    extraMessage.Serialize(writer);
                    addPlayerMessage.msgData = writer.ToArray();
                    addPlayerMessage.msgSize = (int)writer.Position;
                }
                ClientScene.s_ReadyConnection.Send((short)37, (MessageBase)addPlayerMessage);
            }
            else
            {
                if (LogFilter.logDebug)
                {
                    Debug.Log((object)("ClientScene::AddPlayer reconnect " + (object)ClientScene.s_ReconnectId));
                }
                if (ClientScene.s_Peers == null)
                {
                    ClientScene.SetReconnectId(-1, (PeerInfoMessage[])null);
                    if (LogFilter.logError)
                    {
                        Debug.LogError((object)"ClientScene::AddPlayer: reconnecting, but no peers.");
                    }
                    return(false);
                }
                foreach (PeerInfoMessage peer in ClientScene.s_Peers)
                {
                    if (peer.playerIds != null && peer.connectionId == ClientScene.s_ReconnectId)
                    {
                        foreach (PeerInfoPlayer playerId in peer.playerIds)
                        {
                            ReconnectMessage reconnectMessage = new ReconnectMessage();
                            reconnectMessage.oldConnectionId    = ClientScene.s_ReconnectId;
                            reconnectMessage.netId              = playerId.netId;
                            reconnectMessage.playerControllerId = playerId.playerControllerId;
                            if (extraMessage != null)
                            {
                                NetworkWriter writer = new NetworkWriter();
                                extraMessage.Serialize(writer);
                                reconnectMessage.msgData = writer.ToArray();
                                reconnectMessage.msgSize = (int)writer.Position;
                            }
                            ClientScene.s_ReadyConnection.Send((short)47, (MessageBase)reconnectMessage);
                        }
                    }
                }
                ClientScene.SetReconnectId(-1, (PeerInfoMessage[])null);
            }
            return(true);
        }
Beispiel #51
0
 /// <summary>
 ///   <para>This adds a player object for this client. This causes an AddPlayer message to be sent to the server, and NetworkManager.OnServerAddPlayer will be called. If an extra message was passed to AddPlayer, then OnServerAddPlayer will be called with a NetworkReader that contains the contents of the message.</para>
 /// </summary>
 /// <param name="readyConn">The connection to become ready for this client.</param>
 /// <param name="playerControllerId">The local player ID number.</param>
 /// <param name="extraMessage">An extra message object that can be passed to the server for this player.</param>
 /// <returns>
 ///   <para>True if player was added.</para>
 /// </returns>
 public static bool AddPlayer(NetworkConnection readyConn, short playerControllerId)
 {
     return(ClientScene.AddPlayer(readyConn, playerControllerId, (MessageBase)null));
 }
 internal void ClearClientOwner()
 {
     this.m_ClientAuthorityOwner = (NetworkConnection)null;
 }
 internal void SetConnectionToServer(NetworkConnection conn)
 {
     this.m_ConnectionToServer = conn;
 }
 internal void SetConnectionToClient(NetworkConnection conn, short newPlayerControllerId)
 {
     this.m_PlayerId           = newPlayerControllerId;
     this.m_ConnectionToClient = conn;
 }
 public override void OnClientConnect(NetworkConnection conn)
 {
     OnLobbyClientConnect(conn);
     CallOnClientEnterLobby();
     base.OnClientConnect(conn);
 }
Beispiel #56
0
 public override void OnServerRemovePlayer(NetworkConnection conn, PlayerController player)
 {
     base.OnServerRemovePlayer(conn, player);
     //ServerManagement._instance.RpcRemovePlayer(player.playerControllerId);
     Debug.Log("RemovePlayer : " + player.playerControllerId);
 }
 /// <summary>
 /// This is called on the client when the client is finished loading a new networked scene.
 /// </summary>
 /// <param name="conn">The connection that finished loading a new networked scene.</param>
 public virtual void OnLobbyClientSceneChanged(NetworkConnection conn)
 {
 }
Beispiel #58
0
 public override void OnClientDisconnect(NetworkConnection conn)
 {
     base.OnClientDisconnect(conn);
     Debug.Log("ClientConnect");
 }
        public void Connect(EndPoint secureTunnelEndPoint)
        {
            bool usePlatformSpecificProtocols = NetworkTransport.DoesEndPointUsePlatformProtocols(secureTunnelEndPoint);

            this.PrepareForConnect(usePlatformSpecificProtocols);
            if (LogFilter.logDebug)
            {
                Debug.Log("Client Connect to remoteSockAddr");
            }
            if (secureTunnelEndPoint == null)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("Connect failed: null endpoint passed in");
                }
                this.m_AsyncConnect = ConnectState.Failed;
            }
            else if ((secureTunnelEndPoint.AddressFamily != AddressFamily.InterNetwork) && (secureTunnelEndPoint.AddressFamily != AddressFamily.InterNetworkV6))
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("Connect failed: Endpoint AddressFamily must be either InterNetwork or InterNetworkV6");
                }
                this.m_AsyncConnect = ConnectState.Failed;
            }
            else
            {
                string fullName = secureTunnelEndPoint.GetType().FullName;
                if (fullName == "System.Net.IPEndPoint")
                {
                    IPEndPoint point = (IPEndPoint)secureTunnelEndPoint;
                    this.Connect(point.Address.ToString(), point.Port);
                }
                else if (((fullName != "UnityEngine.XboxOne.XboxOneEndPoint") && (fullName != "UnityEngine.PS4.SceEndPoint")) && (fullName != "UnityEngine.PSVita.SceEndPoint"))
                {
                    if (LogFilter.logError)
                    {
                        Debug.LogError("Connect failed: invalid Endpoint (not IPEndPoint or XboxOneEndPoint or SceEndPoint)");
                    }
                    this.m_AsyncConnect = ConnectState.Failed;
                }
                else
                {
                    byte error = 0;
                    this.m_RemoteEndPoint = secureTunnelEndPoint;
                    this.m_AsyncConnect   = ConnectState.Connecting;
                    try
                    {
                        this.m_ClientConnectionId = NetworkTransport.ConnectEndPoint(this.m_ClientId, this.m_RemoteEndPoint, 0, out error);
                    }
                    catch (Exception exception)
                    {
                        if (LogFilter.logError)
                        {
                            Debug.LogError("Connect failed: Exception when trying to connect to EndPoint: " + exception);
                        }
                        this.m_AsyncConnect = ConnectState.Failed;
                        return;
                    }
                    if (this.m_ClientConnectionId == 0)
                    {
                        if (LogFilter.logError)
                        {
                            Debug.LogError("Connect failed: Unable to connect to EndPoint (" + error + ")");
                        }
                        this.m_AsyncConnect = ConnectState.Failed;
                    }
                    else
                    {
                        this.m_Connection = (NetworkConnection)Activator.CreateInstance(this.m_NetworkConnectionClass);
                        this.m_Connection.SetHandlers(this.m_MessageHandlers);
                        this.m_Connection.Initialize(this.m_ServerIp, this.m_ClientId, this.m_ClientConnectionId, this.m_HostTopology);
                    }
                }
            }
        }
        /// <summary>
        ///   <para>This causes the set of players that can see this object to be rebuild. The OnRebuildObservers callback function will be invoked on each NetworkBehaviour.</para>
        /// </summary>
        /// <param name="initialize">True if this is the first time.</param>
        public void RebuildObservers(bool initialize)
        {
            if (this.m_Observers == null)
            {
                return;
            }
            bool flag1 = false;
            bool flag2 = false;
            HashSet <NetworkConnection> observers            = new HashSet <NetworkConnection>();
            HashSet <NetworkConnection> networkConnectionSet = new HashSet <NetworkConnection>((IEnumerable <NetworkConnection>) this.m_Observers);

            for (int index = 0; index < this.m_NetworkBehaviours.Length; ++index)
            {
                NetworkBehaviour networkBehaviour = this.m_NetworkBehaviours[index];
                flag2 |= networkBehaviour.OnRebuildObservers(observers, initialize);
            }
            if (!flag2)
            {
                if (!initialize)
                {
                    return;
                }
                foreach (NetworkConnection connection in NetworkServer.connections)
                {
                    if (connection != null && connection.isReady)
                    {
                        this.AddObserver(connection);
                    }
                }
                using (List <NetworkConnection> .Enumerator enumerator = NetworkServer.localConnections.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        NetworkConnection current = enumerator.Current;
                        if (current != null && current.isReady)
                        {
                            this.AddObserver(current);
                        }
                    }
                }
            }
            else
            {
                using (HashSet <NetworkConnection> .Enumerator enumerator = observers.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        NetworkConnection current = enumerator.Current;
                        if (current != null)
                        {
                            if (!current.isReady)
                            {
                                if (LogFilter.logWarn)
                                {
                                    Debug.LogWarning((object)("Observer is not ready for " + (object)this.gameObject + " " + (object)current));
                                }
                            }
                            else if (initialize || !networkConnectionSet.Contains(current))
                            {
                                current.AddToVisList(this);
                                if (LogFilter.logDebug)
                                {
                                    Debug.Log((object)("New Observer for " + (object)this.gameObject + " " + (object)current));
                                }
                                flag1 = true;
                            }
                        }
                    }
                }
                using (HashSet <NetworkConnection> .Enumerator enumerator = networkConnectionSet.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        NetworkConnection current = enumerator.Current;
                        if (!observers.Contains(current))
                        {
                            current.RemoveFromVisList(this, false);
                            if (LogFilter.logDebug)
                            {
                                Debug.Log((object)("Removed Observer for " + (object)this.gameObject + " " + (object)current));
                            }
                            flag1 = true;
                        }
                    }
                }
                if (initialize)
                {
                    using (List <NetworkConnection> .Enumerator enumerator = NetworkServer.localConnections.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            NetworkConnection current = enumerator.Current;
                            if (!observers.Contains(current))
                            {
                                this.OnSetLocalVisibility(false);
                            }
                        }
                    }
                }
                if (!flag1)
                {
                    return;
                }
                this.m_Observers = new List <NetworkConnection>((IEnumerable <NetworkConnection>)observers);
                this.m_ObserverConnections.Clear();
                using (List <NetworkConnection> .Enumerator enumerator = this.m_Observers.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        this.m_ObserverConnections.Add(enumerator.Current.connectionId);
                    }
                }
            }
        }