A utility class to send a network message with no contents.

Inheritance: UnityEngine.Networking.MessageBase
Ejemplo n.º 1
0
 public static NetSystem.EmptyMessage GetEmptyMessage()
 {
     if (_emptyMessage == null)
     {
         _emptyMessage = new NetSystem.EmptyMessage();
     }
     return(_emptyMessage);
 }
    public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId)
    {
        // check MaxPlayersPerConnection
        int numPlayersForConnection = 0;
        foreach (var player in conn.playerControllers)
        {
            if (player.IsValid)
                numPlayersForConnection += 1;
        }

        if (numPlayersForConnection >= maxPlayersPerConnection)
        {
            if (LogFilter.logWarn) { Debug.LogWarning("NetworkLobbyManager no more players for this connection."); }

            var errorMsg = new EmptyMessage();
            conn.Send(MsgType.LobbyAddPlayerFailed, errorMsg);
            return;
        }

        byte slot = FindSlot();
        if (slot == Byte.MaxValue)
        {
            if (LogFilter.logWarn) { Debug.LogWarning("NetworkLobbyManager no space for more players"); }

            var errorMsg = new EmptyMessage();
            conn.Send(MsgType.LobbyAddPlayerFailed, errorMsg);
            return;
        }

        var newLobbyGameObject = OnLobbyServerCreateLobbyPlayer(conn, playerControllerId);
        if (newLobbyGameObject == null)
        {
            newLobbyGameObject = (GameObject)Instantiate(playerPrefab.gameObject, Vector3.zero, Quaternion.identity);
        }

        var newLobbyPlayer = newLobbyGameObject.GetComponent<CaptainsMessPlayer>();
        newLobbyPlayer.slot = slot;
        lobbySlots[slot] = newLobbyPlayer;

        NetworkServer.AddPlayerForConnection(conn, newLobbyGameObject, playerControllerId);
    }
        public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId)
        {
            if (Application.loadedLevelName != this.m_LobbyScene)
            return;

            // see how many players are playing from a connection
              int num = 0;
              using (List<PlayerController>.Enumerator enumerator = conn.playerControllers.GetEnumerator())
              {
            while (enumerator.MoveNext())
            {
              if (enumerator.Current.IsValid)
            ++num;
            }
              }

            // default value is one player per connection
              if (num >= this.maxPlayersPerConnection)
              {
            if (LogFilter.logWarn)
              Debug.LogWarning((object) "NetworkLobbyManager no more players for this connection.");
            EmptyMessage emptyMessage = new EmptyMessage();
            conn.Send((short) 45, (MessageBase) emptyMessage);
              }
              else // if the connection meets the value set for maxPlayersPerConnection then attempt to fill a lobby slot with that player
              {
            byte slot = this.FindSlot();
            if ((int) slot == (int) byte.MaxValue) // then all lobby slots are full, no more room in game
            {
              if (LogFilter.logWarn)
            Debug.LogWarning((object) "NetworkLobbyManager no space for more players");
              EmptyMessage emptyMessage = new EmptyMessage();
              conn.Send((short) 45, (MessageBase) emptyMessage);
            }
            else // set up the lobby player to be spawned into the lobby scene
            {
              GameObject player = this.OnLobbyServerCreateLobbyPlayer(conn, playerControllerId);

              if ((UnityEngine.Object) player == (UnityEngine.Object) null)
            player = (GameObject) UnityEngine.Object.Instantiate((UnityEngine.Object) this.lobbyPlayerPrefab.gameObject, Vector3.zero, Quaternion.identity);

              NetworkLobbyPlayer component = player.GetComponent<NetworkLobbyPlayer>();
              component.slot = slot;
              this.lobbySlots[(int) slot] = component;
              NetworkServer.AddPlayerForConnection(conn, player, playerControllerId);
            }
              }
        }
Ejemplo n.º 4
0
    public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId)
    {
        //UIConsole.Log ("OnServerAddPlayer " + Application.loadedLevelName);
        if (CheckIfLobbyScene ())
        {
            base.OnServerAddPlayer (conn, playerControllerId);
            if(_lobbyInfo!=null)
                NetworkServer.Destroy(_lobbyInfo.gameObject);

            _lobbyInfo = ((GameObject)Instantiate(lobbyInfoPrefab)).GetComponent<LobbyPlayerInfo>();
            NetworkServer.Spawn(_lobbyInfo.gameObject);
        }
        else
        {
            int num = 0;
            foreach (PlayerController current in conn.playerControllers)
            {
                if (current.IsValid)
                {
                    num++;
                }
            }
            if (num > this.maxPlayersPerConnection)
            {
                UnityEngine.Networking.NetworkSystem.EmptyMessage msg = new UnityEngine.Networking.NetworkSystem.EmptyMessage ();
                conn.Send (45, msg);
                return;
            }

            if(resetSpawnPointsOnSceneChange)
            {
                GameObject.Find("RespawnManager").GetComponent<RespawnPointsManager>().SetupInitialSpawnPoints();
                resetSpawnPointsOnSceneChange = false;
            }

            Vector3 spawnPos = GameObject.Find("RespawnManager").GetComponent<RespawnPointsManager>().GetInitialSpawnPoint();
            //UIConsole.Log());
            GameObject player = (GameObject)Object.Instantiate(onlinePlayerPrefab,spawnPos,Quaternion.identity);
            NetworkServer.AddPlayerForConnection(conn,player,playerControllerId);
                //UIConsole.Log("FAILED TO ADD PLAYER");

        }
    }
Ejemplo n.º 5
0
 public bool SendReturnToLobby()
 {
     if ((base.client == null) || !base.client.isConnected)
     {
         return false;
     }
     EmptyMessage msg = new EmptyMessage();
     base.client.Send(0x2e, msg);
     return true;
 }
Ejemplo n.º 6
0
 public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId)
 {
     if (Application.loadedLevelName == this.m_LobbyScene)
     {
         int num = 0;
         foreach (PlayerController controller in conn.playerControllers)
         {
             if (controller.IsValid)
             {
                 num++;
             }
         }
         if (num >= this.maxPlayersPerConnection)
         {
             if (LogFilter.logWarn)
             {
                 Debug.LogWarning("NetworkLobbyManager no more players for this connection.");
             }
             EmptyMessage msg = new EmptyMessage();
             conn.Send(0x2d, msg);
         }
         else
         {
             byte index = this.FindSlot();
             if (index == 0xff)
             {
                 if (LogFilter.logWarn)
                 {
                     Debug.LogWarning("NetworkLobbyManager no space for more players");
                 }
                 EmptyMessage message2 = new EmptyMessage();
                 conn.Send(0x2d, message2);
             }
             else
             {
                 GameObject obj2 = this.OnLobbyServerCreateLobbyPlayer(conn, playerControllerId);
                 if (obj2 == null)
                 {
                     obj2 = (GameObject) UnityEngine.Object.Instantiate(this.lobbyPlayerPrefab.gameObject, Vector3.zero, Quaternion.identity);
                 }
                 NetworkLobbyPlayer component = obj2.GetComponent<NetworkLobbyPlayer>();
                 component.slot = index;
                 this.lobbySlots[index] = component;
                 NetworkServer.AddPlayerForConnection(conn, obj2, playerControllerId);
             }
         }
     }
 }
Ejemplo n.º 7
0
 private void _OnServerGotPlayerInfo(NetworkMessage msg)
 {
     MessageDefine.PlayerInfoMessage infoMsg = msg.ReadMessage<MessageDefine.PlayerInfoMessage>();
     NetworkedPlayerInfo info;
     info.name = infoMsg.name;
     if (m_playerInfos == null)
         m_playerInfos = new Dictionary<int, NetworkedPlayerInfo>();
     m_playerInfos.Add(msg.conn.connectionId, info);
     var ack = new EmptyMessage();
     NetworkServer.SendToClient(msg.conn.connectionId, MessageDefine.ServerGotPlayerInfoMsgId, ack);
 }
Ejemplo n.º 8
0
    public bool SendReturnToLobby()
    {
        if (client == null || !client.isConnected)
        {
            return false;
        }

        var msg = new EmptyMessage();
        client.Send(MsgType.LobbyReturnToLobby, msg);
        return true;
    }
 public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId)
 {
   if (SceneManager.GetSceneAt(0).name != this.m_LobbyScene)
     return;
   int num = 0;
   using (List<PlayerController>.Enumerator enumerator = conn.playerControllers.GetEnumerator())
   {
     while (enumerator.MoveNext())
     {
       if (enumerator.Current.IsValid)
         ++num;
     }
   }
   if (num >= this.maxPlayersPerConnection)
   {
     if (LogFilter.logWarn)
       Debug.LogWarning((object) "NetworkLobbyManager no more players for this connection.");
     EmptyMessage emptyMessage = new EmptyMessage();
     conn.Send((short) 45, (MessageBase) emptyMessage);
   }
   else
   {
     byte slot = this.FindSlot();
     if ((int) slot == (int) byte.MaxValue)
     {
       if (LogFilter.logWarn)
         Debug.LogWarning((object) "NetworkLobbyManager no space for more players");
       EmptyMessage emptyMessage = new EmptyMessage();
       conn.Send((short) 45, (MessageBase) emptyMessage);
     }
     else
     {
       GameObject player = this.OnLobbyServerCreateLobbyPlayer(conn, playerControllerId);
       if ((Object) player == (Object) null)
         player = (GameObject) Object.Instantiate((Object) this.lobbyPlayerPrefab.gameObject, Vector3.zero, Quaternion.identity);
       NetworkLobbyPlayer component = player.GetComponent<NetworkLobbyPlayer>();
       component.slot = slot;
       this.lobbySlots[(int) slot] = component;
       NetworkServer.AddPlayerForConnection(conn, player, playerControllerId);
     }
   }
 }