Exemplo n.º 1
0
 void OnItemChanged(NetworkIdentity _, NetworkIdentity newValue)
 {
     Debug.Log("Received item: " + newValue.gameObject);
     currentItemBase = newValue.GetComponent <ItemBase>();
 }
Exemplo n.º 2
0
        public void CommandMessageCallsCommandTest()
        {
            // listen
            NetworkServer.Listen(1);
            Assert.That(NetworkServer.connections.Count, Is.EqualTo(0));

            // add connection
            ULocalConnectionToClient connection = new ULocalConnectionToClient();

            connection.connectionToServer = new ULocalConnectionToServer();
            NetworkServer.AddConnection(connection);

            // set as authenticated, otherwise removeplayer is rejected
            connection.isAuthenticated = true;

            // add an identity with two networkbehaviour components
            GameObject      go       = new GameObject();
            NetworkIdentity identity = go.AddComponent <NetworkIdentity>();

            identity.netId = 42;
            // for authority check
            identity.connectionToClient = connection;
            CommandTestNetworkBehaviour comp0 = go.AddComponent <CommandTestNetworkBehaviour>();

            Assert.That(comp0.called, Is.EqualTo(0));
            CommandTestNetworkBehaviour comp1 = go.AddComponent <CommandTestNetworkBehaviour>();

            Assert.That(comp1.called, Is.EqualTo(0));
            connection.identity = identity;

            // register the command delegate, otherwise it's not found
            NetworkBehaviour.RegisterCommandDelegate(typeof(CommandTestNetworkBehaviour), nameof(CommandTestNetworkBehaviour.CommandGenerated), CommandTestNetworkBehaviour.CommandGenerated);

            // identity needs to be in spawned dict, otherwise command handler
            // won't find it
            NetworkIdentity.spawned[identity.netId] = identity;

            // serialize a removeplayer message into an arraysegment
            CommandMessage message = new CommandMessage {
                componentIndex = 0,
                functionHash   = NetworkBehaviour.GetMethodHash(typeof(CommandTestNetworkBehaviour), nameof(CommandTestNetworkBehaviour.CommandGenerated)),
                netId          = identity.netId,
                payload        = new ArraySegment <byte>(new byte[0])
            };
            NetworkWriter writer = new NetworkWriter();

            MessagePacker.Pack(message, writer);
            ArraySegment <byte> segment = writer.ToArraySegment();

            // call transport.OnDataReceived with the message
            // -> calls NetworkServer.OnRemovePlayerMessage
            //    -> destroys conn.identity and sets it to null
            Transport.activeTransport.OnServerDataReceived.Invoke(0, segment, 0);

            // was the command called in the first component, not in the second one?
            Assert.That(comp0.called, Is.EqualTo(1));
            Assert.That(comp1.called, Is.EqualTo(0));

            //  send another command for the second component
            comp0.called           = 0;
            message.componentIndex = 1;
            writer = new NetworkWriter();
            MessagePacker.Pack(message, writer);
            segment = writer.ToArraySegment();
            Transport.activeTransport.OnServerDataReceived.Invoke(0, segment, 0);

            // was the command called in the second component, not in the first one?
            Assert.That(comp0.called, Is.EqualTo(0));
            Assert.That(comp1.called, Is.EqualTo(1));

            // sending a command without authority should fail
            // (= if connectionToClient is not what we received the data on)
            // set wrong authority
            identity.connectionToClient = new ULocalConnectionToClient();
            comp0.called = 0;
            comp1.called = 0;
            Transport.activeTransport.OnServerDataReceived.Invoke(0, segment, 0);
            Assert.That(comp0.called, Is.EqualTo(0));
            Assert.That(comp1.called, Is.EqualTo(0));
            // restore authority
            identity.connectionToClient = connection;

            // sending a component with wrong netId should fail
            // wrong netid
            message.netId += 1;
            writer         = new NetworkWriter();
            // need to serialize the message again with wrong netid
            MessagePacker.Pack(message, writer);
            ArraySegment <byte> segmentWrongNetId = writer.ToArraySegment();

            comp0.called = 0;
            comp1.called = 0;
            Transport.activeTransport.OnServerDataReceived.Invoke(0, segmentWrongNetId, 0);
            Assert.That(comp0.called, Is.EqualTo(0));
            Assert.That(comp1.called, Is.EqualTo(0));

            // clean up
            NetworkBehaviour.ClearDelegates();
            NetworkIdentity.spawned.Clear();
            NetworkBehaviour.ClearDelegates();
            NetworkServer.Shutdown();
            // destroy the test gameobject AFTER server was stopped.
            // otherwise isServer is true in OnDestroy, which means it would try
            // to call Destroy(go). but we need to use DestroyImmediate in
            // Editor
            GameObject.DestroyImmediate(go);
        }
Exemplo n.º 3
0
 public UNetServerCollection(NetworkIdentity owner, int slotCount, ILogger logger = null)
     : base(owner, slotCount, logger)
 {
     OnSlotsChanged += NotifyOnSlotsChanged;
     OnSizeChanged  += NotifyOnSizeChanged;
 }
Exemplo n.º 4
0
 public void SetUp()
 {
     gameObject = new GameObject();
     identity   = gameObject.AddComponent <NetworkIdentity>();
 }
Exemplo n.º 5
0
 [Command] public void CmdSetPlayer(NetworkIdentity playerNetworkIdentity)
 {
     seatedPlayer = playerNetworkIdentity.GetComponent <PlayerBehaviour>();
     RpcSetPlayer(playerNetworkIdentity);
 }
Exemplo n.º 6
0
 internal PlayerController(GameObject go, short playerControllerId)
 {
     gameObject = go;
     unetView   = go.GetComponent <NetworkIdentity>();
     this.playerControllerId = playerControllerId;
 }
Exemplo n.º 7
0
 public void CmdSetAuthority(NetworkIdentity grabID, NetworkIdentity playerID)
 {
     grabID.AssignClientAuthority(playerID.connectionToClient);
 }
Exemplo n.º 8
0
 public UseTrapEvent(PlayerController player, Card card, NetworkIdentity[] targets, int[] indices) : base(player)
 {
     cardId           = card.netIdentity;
     flattenedTargets = targets;
     indexes          = indices;
 }
Exemplo n.º 9
0
 public CardDrawnEvent(PlayerController player, Card card) : base(player)
 {
     cardId = card.netIdentity;
 }
Exemplo n.º 10
0
 private void Start()
 {
     networkIdentity      = GetComponent <NetworkIdentity>();
     playerNetworkActions = gameObject.GetComponent <PlayerNetworkActions>();
     playerScript         = gameObject.GetComponent <PlayerScript>();
 }
Exemplo n.º 11
0
 private void ChangeAuthority(NetworkIdentity position, string tag)
 {
     StartCoroutine(CheckOtherPlayer(tag, position));
 }
Exemplo n.º 12
0
 // Update is called once per frame
 void Update()
 {
     identity = GameObject.FindObjectOfType <NetworkIdentity>();
     setPlayerID();
 }
Exemplo n.º 13
0
 void Start()
 {
     ps = GetComponentInChildren <ParticleSystem>();
     networkIdentity = GetComponent <NetworkIdentity>();
 }
Exemplo n.º 14
0
 public bool SyncVarNetworkIdentityEqualExposed(NetworkIdentity ni, uint netIdField)
 {
     return(SyncVarNetworkIdentityEqual(ni, netIdField));
 }
 public void RpcInstantiateCustomPlayer(NetworkIdentity playerNetID, GameObject spawnedObject)
 {
     instantiateCustomPlayer(playerNetID, spawnedObject);
 }
Exemplo n.º 16
0
 public UseTrapEvent(PlayerController player, Card card) : base(player)
 {
     cardId           = card.netIdentity;
     flattenedTargets = null;
     indexes          = null;
 }
 public void CmdSetAuthority(NetworkIdentity playerNetID)
 {
     setAuthority(playerNetID);
 }
Exemplo n.º 18
0
 public static NetworkIdentity GetClientLocalPlayerIdentity(NetworkIdentity objectIdentity)
 {
     return(GetClientLocalPlayer(objectIdentity).netIdentity);
 }
 public void CmdRespawnCustomPlayer(NetworkIdentity playerNetID, GameObject oldCharacter)
 {
     instantiateCustomPlayer(playerNetID, oldCharacter);
 }
Exemplo n.º 20
0
 [ClientRpc] public void RpcSetPlayer(NetworkIdentity playerNetworkIdentity)
 {
     seatedPlayer = playerNetworkIdentity.GetComponent <PlayerBehaviour>();
 }
Exemplo n.º 21
0
 /// <summary>
 /// Called on the server when a client removes a player.
 /// <para>The default implementation of this function destroys the corresponding player object.</para>
 /// </summary>
 /// <param name="conn">The connection to remove the player from.</param>
 /// <param name="player">The player identity to remove.</param>
 public override void OnServerRemovePlayer(NetworkConnection conn, NetworkIdentity player)
 {
     base.OnServerRemovePlayer(conn, player);
 }
    public void Target_UCE_StartUpgradePlaceableObjectClient(NetworkConnection target, NetworkIdentity ni)
    {
        if (ni != null)
        {
            UCE_PlaceableObject po = ni.GetComponent<UCE_PlaceableObject>();
            Entity e = po.GetComponent<Entity>();

            if (e != null)
            {
                LookAtY(po.gameObject.transform.position);
                UCE_myPlaceableObject = po;
                UCE_setTimer(po.getUpgradeCost(e.level).duration);
                UCE_CastbarShow(UCE_MSG_PLACEABLEOBJECT_UPGRADE, po.getUpgradeCost(e.level).duration);
            }
        }
    }
Exemplo n.º 23
0
 public static void SendToReady <T>(NetworkIdentity identity, T msg, bool includeSelf = true, int channelId = Channels.DefaultReliable) where T : struct, NetworkMessage
 {
     NetworkServer.SendToReady <T>(identity, msg, includeSelf, channelId);
 }
Exemplo n.º 24
0
 public void SendNetworkIdentityToServer(NetworkIdentity value)
 {
     onSendNetworkIdentityCalled?.Invoke(value);
 }
Exemplo n.º 25
0
 public static void SendToReady <T>(NetworkIdentity identity, T msg, int channelId = Channels.DefaultReliable) where T : struct, NetworkMessage
 {
     SendToReady(identity, msg, true, channelId);
 }
Exemplo n.º 26
0
 private void ReplaceName(NetworkIdentity pdaId, string newName)
 {
     //messengerSystem.ReplaceName(pdaID, newName);
 }
Exemplo n.º 27
0
 static public void SendToClientOfPlayer <T>(NetworkIdentity player, T msg) where T : struct, NetworkMessage
 {
     NetworkServer.SendToClientOfPlayer <T>(player, msg);
 }
Exemplo n.º 28
0
    private void NetUpdate(
        SpriteDataSO NewSpriteDataSO = null,
        int NewVariantIndex          = -1,
        int NewCataloguePage         = -1,
        bool NewPushTexture          = false,
        bool NewEmpty           = false,
        bool NewPushClear       = false,
        bool NewClearPallet     = false,
        Color?NewSetColour      = null,
        List <Color> NewPalette = null,
        bool NewAnimateOnce     = false)
    {
        if (NetworkThis == false)
        {
            return;
        }
        if (SpriteHandlerManager.Instance == null)
        {
            return;
        }
        if (NetworkIdentity == null)
        {
            if (this?.gameObject == null)
            {
                return;
            }
            var NetID = SpriteHandlerManager.GetRecursivelyANetworkBehaviour(this.gameObject);
            if (NetID == null)
            {
                Logger.LogError("Was unable to find A NetworkBehaviour for ",
                                Category.Sprites);
                return;
            }

            NetworkIdentity = NetID;
            if (NetworkIdentity == null)
            {
                var gamename = "";
                if (this?.gameObject != null)
                {
                    gamename = gameObject.name;
                }
                Logger.LogError("Was unable to find A NetworkBehaviour for " + gamename,
                                Category.Sprites);
            }
        }

        if (CustomNetworkManager.Instance._isServer == false)
        {
            return;
        }

        SpriteHandlerManager.SpriteChange spriteChange = null;

        if (SpriteHandlerManager.Instance.QueueChanges.ContainsKey(this))
        {
            spriteChange = SpriteHandlerManager.Instance.QueueChanges[this];
        }
        else
        {
            spriteChange = SpriteHandlerManager.GetSpriteChange();
        }

        if (NewSpriteDataSO != null)
        {
            if (NewSpriteDataSO.setID == -1)
            {
                Logger.Log("NewSpriteDataSO NO ID!" + NewSpriteDataSO.name, Category.Sprites);
            }
            if (spriteChange.Empty)
            {
                spriteChange.Empty = false;
            }
            spriteChange.PresentSpriteSet = NewSpriteDataSO.setID;
        }

        if (NewVariantIndex != -1)
        {
            spriteChange.VariantIndex = NewVariantIndex;
        }

        if (NewCataloguePage != -1)
        {
            spriteChange.CataloguePage = NewCataloguePage;
        }

        if (NewPushTexture)
        {
            if (spriteChange.PushClear)
            {
                spriteChange.PushClear = false;
            }
            spriteChange.PushTexture = NewPushTexture;
        }

        if (NewEmpty)
        {
            if (spriteChange.PresentSpriteSet != -1)
            {
                spriteChange.PresentSpriteSet = -1;
            }
            spriteChange.Empty = NewEmpty;
        }

        if (NewPushClear)
        {
            if (spriteChange.PushTexture)
            {
                spriteChange.PushTexture = false;
            }
            spriteChange.PushClear = NewPushClear;
        }

        if (NewAnimateOnce)
        {
            if (spriteChange.AnimateOnce)
            {
                spriteChange.AnimateOnce = false;
            }
            spriteChange.AnimateOnce = NewAnimateOnce;
        }

        if (NewClearPallet)
        {
            if (spriteChange.Pallet != null)
            {
                spriteChange.Pallet = null;
            }
            spriteChange.ClearPallet = NewClearPallet;
        }

        if (NewSetColour != null)
        {
            spriteChange.SetColour = NewSetColour;
        }

        if (NewPalette != null)
        {
            if (spriteChange.ClearPallet)
            {
                spriteChange.ClearPallet = false;
            }
            spriteChange.Pallet = NewPalette;
        }

        if (NetworkIdentity.netId == 0)
        {
            //Logger.Log("ID hasn't been set for " + this.transform.parent);
            StartCoroutine(WaitForNetInitialisation(spriteChange));
        }
        else
        {
            SpriteHandlerManager.Instance.QueueChanges[this] = spriteChange;
        }
    }
Exemplo n.º 29
0
 public CardSelectionEvent(PlayerController player, PlayerController source, int cardSeed, CardGenerationFlags cardFlags) : base(player)
 {
     srcPlayer = source.netIdentity;
     seed      = cardSeed;
     flags     = cardFlags;
 }
 internal PlayerController(GameObject go, short playerControllerId)
 {
   this.gameObject = go;
   this.unetView = go.GetComponent<NetworkIdentity>();
   this.playerControllerId = playerControllerId;
 }
    OnGrabbedBehaviour onb; // component defining the behaviour of this GO when it is grabbed by a player
                            // this component can implement different functionality for different GO´s


    //***************************************************************************************************

    // these variables should be set up on the server

    // TODO: implement a mechanism for storing consequent authority requests from different clients
    // e.g. manage a situation where a client requests authority over an object that is currently being manipulated by another client

    //*****************************************************************************************************

    // TODO: avoid sending two or more consecutive RemoveClientAuthority or AssignClientAUthority commands for the same client and shared object
    // a mechanism preventing such situations can be implemented either on the client or on the server

    // Use this for initialization
    void Start()
    {
        netID = this.gameObject.GetComponent <NetworkIdentity>();
        onb   = this.gameObject.AddComponent <OnGrabbedBehaviour>();
    }