// Needs it's own function because at RegisterNewPlayer() the player.LocalPlayer var hasn't been set yet
 public void SetLocalPlayer(NetworkIdentity playerNetworkIdentity, int id)
 {
     localPlayer = players[id];
     if (playerNetworkIdentity.isServer)
     {
         networkIdentity.AssignClientAuthority(playerNetworkIdentity.connectionToClient);
         GameTimer.onTimerReachedZero += EndGame;
     }
 }
Example #2
0
        public IEnumerator AssignAuthority()
        {
            serverIdentity2.AssignClientAuthority(serverPlayer);
            Assert.That(serverIdentity2.Owner, Is.EqualTo(serverPlayer));

            yield return(new WaitForSeconds(0.1f));

            Assert.That(clientIdentity2.HasAuthority, Is.True);
        }
Example #3
0
    public void CmdDestroy(GameObject gameObject)
    {
        NetworkIdentity id = GetComponent <NetworkIdentity>();

        id.AssignClientAuthority(connectionToClient);

        if (id.AssignClientAuthority(connectionToClient) == true)
        {
            NetworkServer.Destroy(gameObject);
        }
    }
Example #4
0
 private void CmdGetAuth(NetworkIdentity objectId, NetworkIdentity playerId)
 {
     if (objectId.clientAuthorityOwner != playerId.connectionToClient)
     {
         if (objectId.clientAuthorityOwner != null)
         {
             objectId.RemoveClientAuthority(objectId.clientAuthorityOwner);
             objectId.AssignClientAuthority(playerId.connectionToClient);
         }
     }
     objectId.AssignClientAuthority(playerId.connectionToClient);
 }
Example #5
0
 // should only be called on server (by an Actor)
 // assign the authority over this game object to a client with NetworkConnection conn
 public void AssignClientAuthority(NetworkConnection conn)
 {
     if (netID.clientAuthorityOwner == null) //no client has authority
     {
         netID.AssignClientAuthority(conn);
     }
     else
     {
         //requestAuth.Add(conn);
         netID.RemoveClientAuthority(netID.clientAuthorityOwner);
         netID.AssignClientAuthority(conn);
     }
 }
Example #6
0
 public void CmdCallCheckLines(GameObject coord)
 {
     objNetId = gridManager.currentGrid.GetComponent <NetworkIdentity>();
     objNetId.AssignClientAuthority(connectionToClient);
     gridManager.currentGrid.RpcCheckLines(coord);
     objNetId.RemoveClientAuthority(connectionToClient);
 }
    // Use this for initialization
    void Start()
    {
        this.enabled = true;

        // Reset the ready states.
        foreach (PlayerSelect playerSelect in m_playerSelections)
        {
            playerSelect.setIsReady(false);
        }
        GameObject lobbyObject = GameObject.FindGameObjectWithTag("LobbyManager");

        if (lobbyObject)
        {
            m_lobbyManager = lobbyObject.GetComponent <LobbyManager>();
            if (m_lobbyManager)
            {
                for (int i = 0; i < m_lobbyManager.lobbySlots.Length; ++i)
                {
                    NetworkIdentity netId = m_playerSelections[i].GetComponent <NetworkIdentity>();
                    if (netId)
                    {
                        netId.AssignClientAuthority(m_lobbyManager.lobbySlots[i].connectionToClient);
                    }
                }
            }
        }
    }
    void CmdStun(GameObject caller)
    {
        NetworkIdentity objNetId = caller.GetComponent <NetworkIdentity>();

        objNetId.AssignClientAuthority(connectionToClient);

        if (caller.GetComponent <EspinhosoScript>())
        {
            caller.GetComponent <Rigidbody2D>().velocity    = new Vector2(0, 0);
            caller.GetComponent <EspinhosoScript>().stunned = true;
            RpccallstunTrigger(caller, true);
        }
        else if (caller.GetComponent <OwlScript>())
        {
            caller.GetComponent <OwlScript>().stunned = true;
            RpccallstunTrigger(caller, true);
        }
        else if (caller.GetComponent <Clawscrip>())
        {
            caller.GetComponent <Rigidbody2D>().velocity = new Vector2(0, 0);
            caller.GetComponent <Clawscrip>().stunned    = true;
            RpccallstunTrigger(caller, true);
        }
        objNetId.RemoveClientAuthority(connectionToClient);
    }
Example #9
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="clientToReceiveAuthority">Client to receive authority of the object</param>
    /// <param name="netIdentityOfObj">Network identity of the gameObject that will have its player auth modified</param>
    public void SetPlayerAuthorityToHeldObject(NetworkIdentity clientToReceiveAuthority, NetworkIdentity netIdentityOfObj)
    {
        Debug.Log("Changing authority of " + netIdentityOfObj.gameObject.name + " to " + clientToReceiveAuthority.GetComponent <PlayerMove>().PlayerID);

        // Remove prior ownership if necessary
        // TODO: consider removing authority (back to server) after letting go of heldObj
        if (netIdentityOfObj.clientAuthorityOwner != null)
        {
            if (netIdentityOfObj.clientAuthorityOwner != clientToReceiveAuthority.connectionToClient)
            {
                NetworkIdentity netIdentityToRemove = null;

                if (clientToReceiveAuthority.isLocalPlayer)
                {
                    netIdentityToRemove = GetNonLocalPlayer().GetComponent <NetworkIdentity>();
                }
                else
                {
                    netIdentityToRemove = GetLocalPlayer().GetComponent <NetworkIdentity>();
                }

                netIdentityOfObj.RemoveClientAuthority(netIdentityToRemove.GetComponent <NetworkIdentity>().connectionToClient);
            }
        }

        netIdentityOfObj.AssignClientAuthority((clientToReceiveAuthority.connectionToClient));
    }
Example #10
0
 void CmdActivateGenerator(GameObject obj)
 {
     objNetId = obj.GetComponent <NetworkIdentity>();
     objNetId.AssignClientAuthority(connectionToClient);
     RpcActivateGenerator(obj);
     objNetId.RemoveClientAuthority(connectionToClient);
 }
 private void OnTriggerEnter(Collider other)
 {
     if (other.tag == "Player")
     {
         stat = other.GetComponent <PlayerStat>();
         if (stat.getInterract())
         {
             updaetText();
             NetworkIdentity id = other.GetComponent <NetworkIdentity>();
             id.AssignClientAuthority(NetworkClient.connection);
             screenOn.SetActive(true);
             stat.setOnInteract(true);
             move = other.GetComponent <Player_Movement>();
             stat.getCamPlayer().GetComponent <MouseLook>().enabled = false;
             save               = other.gameObject;
             move.enabled       = false;
             canvas.worldCamera = stat.getCamPlayer();
             focusCamOnScreen(stat.getCamPlayer().GetComponent <Transform>());
         }
         else
         {
             stat.setStatusInterract(true);
         }
     }
 }
Example #12
0
    public void CmdSetAuth(NetworkInstanceId objectId)
    {
        //First find the object on the network.
        GameObject netObject = NetworkServer.FindLocalObject(objectId);
        //Get the network Identity of the object.
        NetworkIdentity netId = netObject.GetComponent <NetworkIdentity>();
        //Find the owner of the object.
        NetworkConnection netObjectOwner = netId.clientAuthorityOwner;

        //Check if this player is currently the owner.
        if (netObjectOwner == m_playerNetId.connectionToClient)
        {
            return;
        }
        else
        {
            //If this object is currently owned by someone else, we remove authority from the previous owner.
            if (netObjectOwner != null)
            {
                netId.RemoveClientAuthority(netObjectOwner);
            }
            //Assign this client to the authority of the object.
            netId.AssignClientAuthority(m_playerNetId.connectionToClient);
        }
    }
    void CmdRequestPilotAuthority()
    {
        ShipMovement shipScriptRef = playerShipRef.GetComponent <ShipMovement>();

        //Debug.Log("Requesting pilot authority. pilotSeatOccupied is: " + shipScriptRef.pilotSeatOccupied);

        if (shipScriptRef.pilotSeatOccupied == false) // if, on serverside, pilot seat is NOT occupied
        {
            // pilot seat is vacant, give this player the pilot seat
            //Debug.Log("pilotSeatOccupied is false, therefore we are giving requesting player the pilot seat authority");
            NetworkIdentity   newPlayerID    = playerConnRef.GetComponent <NetworkIdentity>();
            NetworkIdentity   shipID         = playerShipRef.GetComponent <NetworkIdentity>();
            NetworkConnection otherShipOwner = shipID.clientAuthorityOwner;

            if (otherShipOwner != newPlayerID.connectionToClient)  //  if this player is not already set to own the ship
            {
                // Debug.Log("We are not the current owner of this pilot seat, so we will receive pilot seat authority");
                if (otherShipOwner != null)  //  if the ship actually DOES have any owner at all
                {
                    //Debug.Log("there actually was a different owner, so we are removing his authority");
                    shipID.RemoveClientAuthority(otherShipOwner);
                }
                shipID.AssignClientAuthority(newPlayerID.connectionToClient);  //  Give ownership to the requesting client
            }
            //else
            //{
            //    Debug.Log("We are already the owner of the ship. Doing nothing");
            //}
            shipScriptRef.setPilotSeatOccupied(true); // communicate to all clients that pilot seat is now occupied
            RpcReceivePilotSeat();                    // on proper client's computer, their ship will have pilot controls enabled
        }
    }
        void NetworkDestroy(GameObject Object)
        {
            //Get the NetworkIdentity assigned to the object
            NetworkIdentity id = Object.GetComponent <NetworkIdentity>();

            // Check if we successfully got the NetworkIdentity Component from our object, if not we return(essentially do nothing).
            if (id == null)
            {
                return;
            }
            // First check if the objects NetworkIdentity can be transferred, or if it is server only.
            if (id.localPlayerAuthority == true)
            {
                // Do we already own this NetworkIdentity? If so, don't do anything.
                if (id.hasAuthority == false)
                {
                    // If we do not already have authority over the NetworkIdentity, assign authority.
                    // Keep in mind, using connectionToClient to get this NetworkIdentity is only valid for Network Player Objects.
                    if (id.AssignClientAuthority(connectionToClient) == true)
                    {
                        // If takeover was successful, we can now destroy our GameObject.
                        Network.Destroy(Object);
                    }
                }
                else
                {
                    // Do nothing because we already have ownership of this NetworkIdentity.
                }
            }
            else
            {
                //Server only, so we can't do anything.
            }
        }
Example #15
0
    public void TakeControl(NetworkIdentity networkId)
    {
        if (null != networkId.clientAuthorityOwner)
        {
            networkId.RemoveClientAuthority(networkId.clientAuthorityOwner);
        }

        if (m_playerNumber != Player.Bot)
        {
            networkId.AssignClientAuthority(connectionToClient);
        }
        else
        {
            networkId.AssignClientAuthority(GameManager.Instance.GetPlayer(Player.Player1).GetComponent <NetworkIdentity> ().connectionToClient);
        }
    }
Example #16
0
 void CmdStopTeleport(GameObject obj)
 {
     objNetId = obj.GetComponent <NetworkIdentity> ();
     objNetId.AssignClientAuthority(connectionToClient);
     Rpc_StopTeleport(obj);
     objNetId.RemoveClientAuthority(connectionToClient);
 }
Example #17
0
    public static void assignObjectToPlayer(NetworkIdentity netIdObject, NetworkIdentity playerId, float delay)
    {
        if (delay >= 0)
        {
            GameObject goNetworkUtils          = new GameObject("NetworkUtilsDelayInstance");
            NetworkUtilsDelayInstance instance = goNetworkUtils.AddComponent <NetworkUtilsDelayInstance> ();
            instance.init(true, netIdObject, playerId, delay);
        }
        else if (null != netIdObject)
        {
            netIdObject.localPlayerAuthority = true;
            NetworkConnection otherOwner = netIdObject.clientAuthorityOwner;

            if (otherOwner == playerId.connectionToClient)
            {
                return;
            }
            else if (otherOwner != null)
            {
                netIdObject.RemoveClientAuthority(otherOwner);
            }

            netIdObject.AssignClientAuthority(playerId.connectionToClient);
        }
    }
Example #18
0
 void CmdMove(GameObject padre, GameObject bola) //se invoca en el server y comunica al propio que este objeto es padre de la bola
 {
     objNetId = bola.GetComponent <NetworkIdentity>();
     objNetId.AssignClientAuthority(connectionToClient);
     RpcMove(padre, bola); //se invoca en el server y comunica a los clientes que este objeto es padre de la bola
     objNetId.RemoveClientAuthority(connectionToClient);
 }
Example #19
0
    void CmdRelease(GameObject piece)
    {
        NetworkIdentity pieceId = gameObject.GetComponent <NetworkIdentity>();

        if (!isServer && pieceId.GetComponent <NetworkIdentity>().hasAuthority)
        {
            pieceId.RemoveClientAuthority(connectionToClient);
        }
        pieceId.AssignClientAuthority(connectionToClient);

        if (piece.GetComponent <PieceHover>().isShivering || piece.GetComponent <PieceHover>().isBlinking)
        {
            piece.GetComponent <PieceHover>().NotHover();
        }

        isSnapped = false;
        piece.transform.parent = null;
        StartCoroutine(PieceFall(piece));
        hasFall = true;

        if (!audioSource.isPlaying)
        {
            audioSource.PlayOneShot(fallSound);
        }
        if (!isServer && pieceId.GetComponent <NetworkIdentity>().hasAuthority)
        {
            pieceId.RemoveClientAuthority(connectionToClient);
        }
        isplayed = false;
        Debug.Log("cmd release");
    }
Example #20
0
    void CmdSnapCombinedC(GameObject gameObject, Vector3 offset)
    {
        NetworkIdentity pieceId = gameObject.GetComponent <NetworkIdentity>();

        if (!isServer && pieceId.GetComponent <NetworkIdentity>().hasAuthority)
        {
            pieceId.RemoveClientAuthority(connectionToClient);
        }
        pieceId.AssignClientAuthority(connectionToClient);

        if (piece.GetComponent <PieceHover>().isShivering)
        {
            piece.GetComponent <PieceHover>().NotHover();
        }

        isSnapped = true;
        hasFall   = false;

        gameObject.GetComponent <CombinedBehavior>().isTappedC = true;
        if (gameObject.GetComponent <CombinedBehavior>().isTappedH == true)
        {
            gameObject.transform.position = gameObject.transform.position + offset / 2;
        }
        Debug.Log("CmdSnapCombinedC: " + gameObject.GetComponent <CombinedBehavior>().offsetC);
    }
Example #21
0
 public void CmdDisableHybernate(GameObject obj)
 {
     objNetId = obj.GetComponent <NetworkIdentity>();
     objNetId.AssignClientAuthority(connectionToClient);
     RpcDisableHybernate(obj);
     objNetId.RemoveClientAuthority(connectionToClient);
 }
 void CmdPutInHeldItem(GameObject handOject, GameObject player)
 {
     objNetId = handOject.GetComponent <NetworkIdentity>();
     objNetId.AssignClientAuthority(connectionToClient);
     RpcPutInHeldItem(handOject, player);
     objNetId.RemoveClientAuthority(connectionToClient);
 }
Example #23
0
    void CmdSnap(GameObject gameObject)
    {
        NetworkIdentity pieceId = gameObject.GetComponent <NetworkIdentity>();

        if (!isServer && pieceId.GetComponent <NetworkIdentity>().hasAuthority)
        {
            pieceId.RemoveClientAuthority(connectionToClient);
        }
        pieceId.AssignClientAuthority(connectionToClient);

        if (piece.GetComponent <PieceHover>().isShivering || piece.GetComponent <PieceHover>().isBlinking)
        {
            piece.GetComponent <PieceHover>().NotHover();
        }

        piece.transform.parent   = camera;
        piece.transform.rotation = Quaternion.identity;
        isSnapped  = true;
        isSnapping = true;
        hasFall    = false;

        if (!audioSource.isPlaying && !isplayed)
        {
            audioSource.PlayOneShot(snapSound);
            isplayed = true;
        }
        if (!isServer && pieceId.GetComponent <NetworkIdentity>().hasAuthority)
        {
            pieceId.RemoveClientAuthority(connectionToClient);
        }
        Debug.Log("cmd snap");
    }
Example #24
0
 void CmdPaint(GameObject obj, Color col)
 {
     objNetId = obj.GetComponent <NetworkIdentity> ();               // get the object's network ID
     objNetId.AssignClientAuthority(connectionToClient);             // assign authority to the player who is changing the color
     RpcPaint(obj, col);                                             // usse a Client RPC function to "paint" the object on all clients
     objNetId.RemoveClientAuthority(connectionToClient);             // remove the authority from the player who changed the color
 }
Example #25
0
    public void CmdRotate(GameObject obj, float euler)
    {
        NetworkIdentity id = obj.GetComponent <NetworkIdentity>();

        id.AssignClientAuthority(connectionToClient);
        RpcRotate(obj, euler);
    }
 void CmdChangeColor(GameObject go, Color c)
 {
     objNetId = go.GetComponent <NetworkIdentity>();
     objNetId.AssignClientAuthority(connectionToClient);
     RpcUpdateTower(go, c);
     objNetId.RemoveClientAuthority(connectionToClient);
 }
Example #27
0
    [Command]// (serveur)
    public void CmdAddLocalAuthority(GameObject obj)
    {
        NetworkInstanceId nIns   = obj.GetComponent <NetworkIdentity>().netId;
        GameObject        client = NetworkServer.FindLocalObject(nIns);
        NetworkIdentity   ni     = client.GetComponent <NetworkIdentity>();

        ni.AssignClientAuthority(connectionToClient);
    }
 public void CmdAssignClientAuthority(NetworkIdentity id, NetworkConnection conn)
 {
     if (conn == null)
     {
         Debug.Log("conn null");
     }
     id.AssignClientAuthority(conn);
 }
Example #29
0
    void CmdSkip()
    {
        NetworkIdentity NI = turnManager.GetComponent <NetworkIdentity>();

        NI.AssignClientAuthority(connectionToClient);
        RpcSkip(turnManager);
        NI.RemoveClientAuthority(connectionToClient);
    }
Example #30
0
    void CmdSetMultipliers(int c1, int c2, int c3, int c4, int c5, int c6, int c7, int c8, int c9, string c)
    {
        NetworkIdentity NI = turnManager.GetComponent <NetworkIdentity>();

        NI.AssignClientAuthority(connectionToClient);
        RpcSetMultipliers(c1, c2, c3, c4, c5, c6, c7, c8, c9, turnManager, c);
        NI.RemoveClientAuthority(connectionToClient);
    }