Beispiel #1
0
        public override void Initialize(NetworkObject obj)
        {
            // We have already initialized this object
            if (networkObject != null && networkObject.AttachedBehavior != null)
            {
                return;
            }

            networkObject = (GuyWithMovementNetworkObject)obj;
            networkObject.AttachedBehavior = this;

            base.SetupHelperRpcs(networkObject);
            networkObject.RegisterRpc("SyncMovementHistory", SyncMovementHistory, typeof(byte[]));

            MainThreadManager.Run(NetworkStart);

            networkObject.onDestroy += DestroyGameObject;

            if (!obj.IsOwner)
            {
                if (!skipAttachIds.ContainsKey(obj.NetworkId))
                {
                    ProcessOthers(gameObject.transform, obj.NetworkId + 1);
                }
                else
                {
                    skipAttachIds.Remove(obj.NetworkId);
                }
            }

            if (obj.Metadata == null)
            {
                return;
            }

            byte transformFlags = obj.Metadata[0];

            if (transformFlags == 0)
            {
                return;
            }

            BMSByte metadataTransform = new BMSByte();

            metadataTransform.Clone(obj.Metadata);
            metadataTransform.MoveStartIndex(1);

            if ((transformFlags & 0x01) != 0 && (transformFlags & 0x02) != 0)
            {
                MainThreadManager.Run(() =>
                {
                    transform.position = ObjectMapper.Instance.Map <Vector3>(metadataTransform);
                    transform.rotation = ObjectMapper.Instance.Map <Quaternion>(metadataTransform);
                });
            }
            else if ((transformFlags & 0x01) != 0)
            {
                MainThreadManager.Run(() => { transform.position = ObjectMapper.Instance.Map <Vector3>(metadataTransform); });
            }
            else if ((transformFlags & 0x02) != 0)
            {
                MainThreadManager.Run(() => { transform.rotation = ObjectMapper.Instance.Map <Quaternion>(metadataTransform); });
            }
        }
Beispiel #2
0
        public override void Initialize(NetworkObject obj)
        {
            // We have already initialized this object
            if (networkObject != null && networkObject.AttachedBehavior != null)
            {
                return;
            }

            networkObject = (NetworkAudioProfileNetworkObject)obj;
            networkObject.AttachedBehavior = this;

            base.SetupHelperRpcs(networkObject);
            networkObject.RegisterRpc("Attach", Attach, typeof(uint));
            networkObject.RegisterRpc("Detach", Detach, typeof(uint));
            networkObject.RegisterRpc("FetchSource", FetchSource, typeof(string), typeof(int));
            networkObject.RegisterRpc("Play", Play, typeof(int));
            networkObject.RegisterRpc("Pause", Pause);

            networkObject.onDestroy += DestroyGameObject;

            if (!obj.IsOwner)
            {
                if (!skipAttachIds.ContainsKey(obj.NetworkId))
                {
                    ProcessOthers(gameObject.transform, obj.NetworkId + 1);
                }
                else
                {
                    skipAttachIds.Remove(obj.NetworkId);
                }
            }

            if (obj.Metadata != null)
            {
                byte transformFlags = obj.Metadata[0];

                if (transformFlags != 0)
                {
                    BMSByte metadataTransform = new BMSByte();
                    metadataTransform.Clone(obj.Metadata);
                    metadataTransform.MoveStartIndex(1);

                    if ((transformFlags & 0x01) != 0 && (transformFlags & 0x02) != 0)
                    {
                        MainThreadManager.Run(() =>
                        {
                            transform.position = ObjectMapper.Instance.Map <Vector3>(metadataTransform);
                            transform.rotation = ObjectMapper.Instance.Map <Quaternion>(metadataTransform);
                        });
                    }
                    else if ((transformFlags & 0x01) != 0)
                    {
                        MainThreadManager.Run(() => { transform.position = ObjectMapper.Instance.Map <Vector3>(metadataTransform); });
                    }
                    else if ((transformFlags & 0x02) != 0)
                    {
                        MainThreadManager.Run(() => { transform.rotation = ObjectMapper.Instance.Map <Quaternion>(metadataTransform); });
                    }
                }
            }

            MainThreadManager.Run(() =>
            {
                NetworkStart();
                networkObject.Networker.FlushCreateActions(networkObject);
            });
        }
Beispiel #3
0
        public override void Initialize(NetworkObject obj)
        {
            // We have already initialized this object
            if (networkObject != null && networkObject.AttachedBehavior != null)
            {
                return;
            }

            networkObject = (NodeServiceNetworkObject)obj;
            networkObject.AttachedBehavior = this;

            base.SetupHelperRpcs(networkObject);
            networkObject.RegisterRpc("RegisterNode", RegisterNode, typeof(uint));
            networkObject.RegisterRpc("RegisterScene", RegisterScene, typeof(bool), typeof(byte[]));
            networkObject.RegisterRpc("UnregisterScene", UnregisterScene, typeof(bool), typeof(byte[]));
            networkObject.RegisterRpc("ConfirmScene", ConfirmScene, typeof(byte[]));
            networkObject.RegisterRpc("LookupScene", LookupScene, typeof(byte[]));
            networkObject.RegisterRpc("ReceiveLookupScene", ReceiveLookupScene, typeof(uint), typeof(byte[]));
            networkObject.RegisterRpc("RelayInstantiateInNode", RelayInstantiateInNode, typeof(byte[]));
            networkObject.RegisterRpc("InstantiateInNode", InstantiateInNode, typeof(byte[]));
            networkObject.RegisterRpc("RelayConfirmInstantiateInNode", RelayConfirmInstantiateInNode, typeof(byte[]));
            networkObject.RegisterRpc("ConfirmInstantiateInNode", ConfirmInstantiateInNode, typeof(byte[]));
            networkObject.RegisterRpc("RelayCreateNetworkSceneInNode", RelayCreateNetworkSceneInNode, typeof(byte[]));
            networkObject.RegisterRpc("CreateNetworkSceneInNode", CreateNetworkSceneInNode, typeof(byte[]));
            networkObject.RegisterRpc("RelayConfirmCreateNetworkSceneInNode", RelayConfirmCreateNetworkSceneInNode, typeof(byte[]));
            networkObject.RegisterRpc("ConfirmCreateNetworkSceneInNode", ConfirmCreateNetworkSceneInNode, typeof(byte[]));

            networkObject.onDestroy += DestroyGameObject;

            if (!obj.IsOwner)
            {
                if (!skipAttachIds.ContainsKey(obj.NetworkId))
                {
                    uint newId = obj.NetworkId + 1;
                    ProcessOthers(gameObject.transform, ref newId);
                }
                else
                {
                    skipAttachIds.Remove(obj.NetworkId);
                }
            }

            if (obj.Metadata != null)
            {
                byte transformFlags = obj.Metadata[0];

                if (transformFlags != 0)
                {
                    BMSByte metadataTransform = new BMSByte();
                    metadataTransform.Clone(obj.Metadata);
                    metadataTransform.MoveStartIndex(1);

                    if ((transformFlags & 0x01) != 0 && (transformFlags & 0x02) != 0)
                    {
                        MainThreadManager.Run(() =>
                        {
                            transform.position = ObjectMapper.Instance.Map <Vector3>(metadataTransform);
                            transform.rotation = ObjectMapper.Instance.Map <Quaternion>(metadataTransform);
                        });
                    }
                    else if ((transformFlags & 0x01) != 0)
                    {
                        MainThreadManager.Run(() => { transform.position = ObjectMapper.Instance.Map <Vector3>(metadataTransform); });
                    }
                    else if ((transformFlags & 0x02) != 0)
                    {
                        MainThreadManager.Run(() => { transform.rotation = ObjectMapper.Instance.Map <Quaternion>(metadataTransform); });
                    }
                }
            }

            MainThreadManager.Run(() =>
            {
                NetworkStart();
                networkObject.Networker.FlushCreateActions(networkObject);
            });
        }
Beispiel #4
0
        public override void Initialize(NetworkObject obj)
        {
            // We have already initialized this object
            if (networkObject != null && networkObject.AttachedBehavior != null)
            {
                return;
            }

            networkObject = (EntityNetworkObject)obj;
            networkObject.AttachedBehavior = this;

            base.SetupHelperRpcs(networkObject);
            networkObject.RegisterRpc("UpdateTeam", UpdateTeam, typeof(string));
            networkObject.RegisterRpc("UpdateModule", UpdateModule, typeof(int), typeof(string), typeof(float), typeof(float), typeof(float), typeof(float), typeof(float), typeof(bool));
            networkObject.RegisterRpc("UpdateHealth", UpdateHealth, typeof(float));
            networkObject.RegisterRpc("UpdateShield", UpdateShield, typeof(float));
            networkObject.RegisterRpc("UpdateMaxHealth", UpdateMaxHealth, typeof(float));
            networkObject.RegisterRpc("UpdateMaxShield", UpdateMaxShield, typeof(float));
            networkObject.RegisterRpc("UpdateAcceleration", UpdateAcceleration, typeof(float));
            networkObject.RegisterRpc("UpdateSpeed", UpdateSpeed, typeof(float));
            networkObject.RegisterRpc("UpdateAgility", UpdateAgility, typeof(float));
            networkObject.RegisterRpc("UpdateVerticalInput", UpdateVerticalInput, typeof(int));
            networkObject.RegisterRpc("UpdateHorizontalInput", UpdateHorizontalInput, typeof(int));
            networkObject.RegisterRpc("UpdateName", UpdateName, typeof(string));
            networkObject.RegisterRpc("Sync", Sync, typeof(float), typeof(Vector3), typeof(Quaternion), typeof(Vector3));
            networkObject.RegisterRpc("Init", Init);

            networkObject.onDestroy += DestroyGameObject;

            if (!obj.IsOwner)
            {
                if (!skipAttachIds.ContainsKey(obj.NetworkId))
                {
                    uint newId = obj.NetworkId + 1;
                    ProcessOthers(gameObject.transform, ref newId);
                }
                else
                {
                    skipAttachIds.Remove(obj.NetworkId);
                }
            }

            if (obj.Metadata != null)
            {
                byte transformFlags = obj.Metadata[0];

                if (transformFlags != 0)
                {
                    BMSByte metadataTransform = new BMSByte();
                    metadataTransform.Clone(obj.Metadata);
                    metadataTransform.MoveStartIndex(1);

                    if ((transformFlags & 0x01) != 0 && (transformFlags & 0x02) != 0)
                    {
                        MainThreadManager.Run(() =>
                        {
                            transform.position = ObjectMapper.Instance.Map <Vector3>(metadataTransform);
                            transform.rotation = ObjectMapper.Instance.Map <Quaternion>(metadataTransform);
                        });
                    }
                    else if ((transformFlags & 0x01) != 0)
                    {
                        MainThreadManager.Run(() => { transform.position = ObjectMapper.Instance.Map <Vector3>(metadataTransform); });
                    }
                    else if ((transformFlags & 0x02) != 0)
                    {
                        MainThreadManager.Run(() => { transform.rotation = ObjectMapper.Instance.Map <Quaternion>(metadataTransform); });
                    }
                }
            }

            MainThreadManager.Run(() =>
            {
                NetworkStart();
                networkObject.Networker.FlushCreateActions(networkObject);
            });
        }
Beispiel #5
0
        public override void Initialize(NetworkObject obj)
        {
            // We have already initialized this object
            if (networkObject != null && networkObject.AttachedBehavior != null)
            {
                return;
            }

            networkObject = (PlayerNetworkObject)obj;
            networkObject.AttachedBehavior = this;

            /*
             *          base.SetupHelperRpcs(networkObject);
             *          networkObject.RegisterRpc("Shoot", Shoot, typeof(Vector3), typeof(Vector3));
             *          networkObject.RegisterRpc("Die", Die, typeof(string));
             *          networkObject.RegisterRpc("SwitchWeapon", SwitchWeapon, typeof(int));
             *          networkObject.RegisterRpc("TakeDamage", TakeDamage, typeof(int), typeof(Vector3), typeof(Vector3));
             *          networkObject.RegisterRpc("SetupPlayer", SetupPlayer, typeof(int), typeof(string));
             */

            networkObject.onDestroy += DestroyGameObject;

            ///if (!obj.IsOwner)
            if (networkObject.IsRemote)
            {
                if (!skipAttachIds.ContainsKey((uint)networkObject.frameSender.UID))
                {
                    ProcessOthers(gameObject.transform, (uint)networkObject.frameSender.UID + 1);
                }
                else
                {
                    skipAttachIds.Remove((uint)networkObject.frameSender.UID);
                }
            }

            if (obj.Metadata != null)
            {
                byte transformFlags = obj.Metadata[0];

                if (transformFlags != 0)
                {
                    BMSByte metadataTransform = new BMSByte();
                    metadataTransform.Clone(obj.Metadata);
                    metadataTransform.MoveStartIndex(1);

                    if ((transformFlags & 0x01) != 0 && (transformFlags & 0x02) != 0)
                    {
                        MainThreadManager.Run(() =>
                        {
                            transform.position = ObjectMapper.Instance.Map <Vector3>(metadataTransform);
                            transform.rotation = ObjectMapper.Instance.Map <Quaternion>(metadataTransform);
                        });
                    }
                    else if ((transformFlags & 0x01) != 0)
                    {
                        MainThreadManager.Run(() => { transform.position = ObjectMapper.Instance.Map <Vector3>(metadataTransform); });
                    }
                    else if ((transformFlags & 0x02) != 0)
                    {
                        MainThreadManager.Run(() => { transform.rotation = ObjectMapper.Instance.Map <Quaternion>(metadataTransform); });
                    }
                }
            }

            MainThreadManager.Run(() =>
            {
                NetworkStart();
                if (!networkObject.IsRemote)
                {
                    networkObject.Networker.FlushCreateActions(networkObject);
                }
            });
        }
Beispiel #6
0
        public override void Initialize(NetworkObject obj)
        {
            // We have already initialized this object
            if (networkObject != null && networkObject.AttachedBehavior != null)
            {
                return;
            }

            networkObject = (TowerNetworkObject)obj;
            networkObject.AttachedBehavior = this;

            base.SetupHelperRpcs(networkObject);
            networkObject.RegisterRpc("SignalEntry", SignalEntry, typeof(int));
            networkObject.RegisterRpc("SignalExit", SignalExit, typeof(int));

            networkObject.onDestroy += DestroyGameObject;

            if (!obj.IsOwner)
            {
                if (!skipAttachIds.ContainsKey(obj.NetworkId))
                {
                    uint newId = obj.NetworkId + 1;
                    ProcessOthers(gameObject.transform, ref newId);
                }
                else
                {
                    skipAttachIds.Remove(obj.NetworkId);
                }
            }

            if (obj.Metadata != null)
            {
                byte transformFlags = obj.Metadata[0];

                if (transformFlags != 0)
                {
                    BMSByte metadataTransform = new BMSByte();
                    metadataTransform.Clone(obj.Metadata);
                    metadataTransform.MoveStartIndex(1);

                    bool changePos      = (transformFlags & 0x01) != 0;
                    bool changeRotation = (transformFlags & 0x02) != 0;
                    if (changePos || changeRotation)
                    {
                        MainThreadManager.Run(() =>
                        {
                            if (changePos)
                            {
                                transform.position = ObjectMapper.Instance.Map <Vector3>(metadataTransform);
                            }
                            if (changeRotation)
                            {
                                transform.rotation = ObjectMapper.Instance.Map <Quaternion>(metadataTransform);
                            }
                        });
                    }
                }
            }

            MainThreadManager.Run(() =>
            {
                gameObject.SetActive(true);
                NetworkStart();
                networkObject.Networker.FlushCreateActions(networkObject);
            });
        }
Beispiel #7
0
        public override void Initialize(NetworkObject obj)
        {
            // We have already initialized this object
            if (networkObject != null && networkObject.AttachedBehavior != null)
            {
                return;
            }

            networkObject = (TestNetworkObject)obj;
            networkObject.AttachedBehavior = this;

            base.SetupHelperRpcs(networkObject);
            networkObject.RegisterRpc("FuncBlank", FuncBlank);
            networkObject.RegisterRpc("FuncByte", FuncByte, typeof(byte));
            networkObject.RegisterRpc("FuncChar", FuncChar, typeof(char));
            networkObject.RegisterRpc("FuncShort", FuncShort, typeof(short));
            networkObject.RegisterRpc("FuncUShort", FuncUShort, typeof(ushort));
            networkObject.RegisterRpc("FuncBool", FuncBool, typeof(bool));
            networkObject.RegisterRpc("FuncInt", FuncInt, typeof(int));
            networkObject.RegisterRpc("FuncUInt", FuncUInt, typeof(uint));
            networkObject.RegisterRpc("FuncFloat", FuncFloat, typeof(float));
            networkObject.RegisterRpc("FuncLong", FuncLong, typeof(long));
            networkObject.RegisterRpc("FuncULong", FuncULong, typeof(ulong));
            networkObject.RegisterRpc("FuncDouble", FuncDouble, typeof(double));
            networkObject.RegisterRpc("FuncString", FuncString, typeof(string));
            networkObject.RegisterRpc("FuncByteArray", FuncByteArray, typeof(byte[]));
            networkObject.RegisterRpc("FuncAll", FuncAll, typeof(byte), typeof(char), typeof(short), typeof(ushort), typeof(bool), typeof(int), typeof(uint), typeof(float), typeof(long), typeof(ulong), typeof(double), typeof(string), typeof(byte[]));

            networkObject.onDestroy += DestroyGameObject;

            if (!obj.IsOwner)
            {
                if (!skipAttachIds.ContainsKey(obj.NetworkId))
                {
                    ProcessOthers(gameObject.transform, obj.NetworkId + 1);
                }
                else
                {
                    skipAttachIds.Remove(obj.NetworkId);
                }
            }

            if (obj.Metadata != null)
            {
                byte transformFlags = obj.Metadata[0];

                if (transformFlags != 0)
                {
                    BMSByte metadataTransform = new BMSByte();
                    metadataTransform.Clone(obj.Metadata);
                    metadataTransform.MoveStartIndex(1);

                    if ((transformFlags & 0x01) != 0 && (transformFlags & 0x02) != 0)
                    {
                        MainThreadManager.Run(() =>
                        {
                            transform.position = ObjectMapper.Instance.Map <Vector3>(metadataTransform);
                            transform.rotation = ObjectMapper.Instance.Map <Quaternion>(metadataTransform);
                        });
                    }
                    else if ((transformFlags & 0x01) != 0)
                    {
                        MainThreadManager.Run(() => { transform.position = ObjectMapper.Instance.Map <Vector3>(metadataTransform); });
                    }
                    else if ((transformFlags & 0x02) != 0)
                    {
                        MainThreadManager.Run(() => { transform.rotation = ObjectMapper.Instance.Map <Quaternion>(metadataTransform); });
                    }
                }
            }

            MainThreadManager.Run(() =>
            {
                NetworkStart();
                networkObject.Networker.FlushCreateActions(networkObject);
            });
        }
		/// <summary>
		/// Tells the client to change their scene to the given scene.  This is often called
		/// after the server has changed to that scene to ensure that the server will always
		/// load up the scene before the client does
		/// </summary>
		/// <param name="netWorker">The current <see cref="NetWorker"/> that will be sending the message</param>
		/// <param name="targetPlayer">The particular player that will be receiving this message</param>
		/// <param name="sceneName">The name of the scene in which the client should load</param>
		public static void ChangeClientScene(NetWorker netWorker, NetworkingPlayer targetPlayer, string sceneName)
		{
			if (!netWorker.IsServer) throw new NetworkException("Only the server can call this method, the specified NetWorker is not a server");

			BMSByte data = new BMSByte();
			data.Clone(Encryptor.Encoding.GetBytes(sceneName));
			data.InsertRange(0, new byte[1] { 2 });
			netWorker.WriteRaw(targetPlayer, data);
		}
        public override void Initialize(NetworkObject obj)
        {
            // We have already initialized this object
            if (networkObject != null && networkObject.AttachedBehavior != null)
            {
                return;
            }

            networkObject = (CubeForgeGameNetworkObject)obj;
            networkObject.AttachedBehavior = this;

            base.SetupHelperRpcs(networkObject);
            networkObject.RegisterRpc("InitializeMap", InitializeMap, typeof(Vector3), typeof(Vector3), typeof(byte[]));
            networkObject.RegisterRpc("CreatePrimitive", CreatePrimitive, typeof(byte), typeof(Vector3));
            networkObject.RegisterRpc("DestroyPrimitive", DestroyPrimitive, typeof(Vector3));
            networkObject.RegisterRpc("TestMe", TestMe, typeof(string));

            MainThreadManager.Run(() =>
            {
                NetworkStart();
                networkObject.Networker.FlushCreateActions(networkObject);
            });

            networkObject.onDestroy += DestroyGameObject;

            if (!obj.IsOwner)
            {
                if (!skipAttachIds.ContainsKey(obj.NetworkId))
                {
                    uint newId = obj.NetworkId + 1;
                    ProcessOthers(gameObject.transform, ref newId);
                }
                else
                {
                    skipAttachIds.Remove(obj.NetworkId);
                }
            }

            if (obj.Metadata == null)
            {
                return;
            }

            byte transformFlags = obj.Metadata[0];

            if (transformFlags == 0)
            {
                return;
            }

            BMSByte metadataTransform = new BMSByte();

            metadataTransform.Clone(obj.Metadata);
            metadataTransform.MoveStartIndex(1);

            if ((transformFlags & 0x01) != 0 && (transformFlags & 0x02) != 0)
            {
                MainThreadManager.Run(() =>
                {
                    transform.position = ObjectMapper.Instance.Map <Vector3>(metadataTransform);
                    transform.rotation = ObjectMapper.Instance.Map <Quaternion>(metadataTransform);
                });
            }
            else if ((transformFlags & 0x01) != 0)
            {
                MainThreadManager.Run(() => { transform.position = ObjectMapper.Instance.Map <Vector3>(metadataTransform); });
            }
            else if ((transformFlags & 0x02) != 0)
            {
                MainThreadManager.Run(() => { transform.rotation = ObjectMapper.Instance.Map <Quaternion>(metadataTransform); });
            }
        }
Beispiel #10
0
        public override void Initialize(NetworkObject obj)
        {
            // We have already initialized this object
            if (networkObject != null && networkObject.AttachedBehavior != null)
            {
                return;
            }

            networkObject = (RPCPackagerNetworkObject)obj;
            networkObject.AttachedBehavior = this;

            base.SetupHelperRpcs(networkObject);
            networkObject.RegisterRpc("SendPackage", SendPackage, typeof(byte[]));
            networkObject.RegisterRpc("PlayerJoinedGame", PlayerJoinedGame, typeof(ushort), typeof(ushort), typeof(string), typeof(uint));
            networkObject.RegisterRpc("UpdatePlayerName", UpdatePlayerName, typeof(ushort), typeof(ushort), typeof(string));
            networkObject.RegisterRpc("PlayerLeftGame", PlayerLeftGame, typeof(ushort), typeof(ushort), typeof(uint));
            networkObject.RegisterRpc("PlayerChangeTeams", PlayerChangeTeams, typeof(ushort), typeof(ushort));

            networkObject.onDestroy += DestroyGameObject;

            if (!obj.IsOwner)
            {
                if (!skipAttachIds.ContainsKey(obj.NetworkId))
                {
                    uint newId = obj.NetworkId + 1;
                    ProcessOthers(gameObject.transform, ref newId);
                }
                else
                {
                    skipAttachIds.Remove(obj.NetworkId);
                }
            }

            if (obj.Metadata != null)
            {
                byte transformFlags = obj.Metadata[0];

                if (transformFlags != 0)
                {
                    BMSByte metadataTransform = new BMSByte();
                    metadataTransform.Clone(obj.Metadata);
                    metadataTransform.MoveStartIndex(1);

                    if ((transformFlags & 0x01) != 0 && (transformFlags & 0x02) != 0)
                    {
                        MainThreadManager.Run(() =>
                        {
                            transform.position = ObjectMapper.Instance.Map <Vector3>(metadataTransform);
                            transform.rotation = ObjectMapper.Instance.Map <Quaternion>(metadataTransform);
                        });
                    }
                    else if ((transformFlags & 0x01) != 0)
                    {
                        MainThreadManager.Run(() => { transform.position = ObjectMapper.Instance.Map <Vector3>(metadataTransform); });
                    }
                    else if ((transformFlags & 0x02) != 0)
                    {
                        MainThreadManager.Run(() => { transform.rotation = ObjectMapper.Instance.Map <Quaternion>(metadataTransform); });
                    }
                }
            }

            MainThreadManager.Run(() =>
            {
                NetworkStart();
                networkObject.Networker.FlushCreateActions(networkObject);
            });
        }
Beispiel #11
0
        public override void Initialize(NetworkObject obj)
        {
            // We have already initialized this object
            if (networkObject != null && networkObject.AttachedBehavior != null)
            {
                return;
            }

            networkObject = (PlayerNetworkObject)obj;
            networkObject.AttachedBehavior = this;

            base.SetupHelperRpcs(networkObject);
            networkObject.RegisterRpc("UpdateName", UpdateName, typeof(string));
            networkObject.RegisterRpc("UpdatePing", UpdatePing, typeof(int));
            networkObject.RegisterRpc("UpdateKills", UpdateKills, typeof(int));
            networkObject.RegisterRpc("Shoot", Shoot, typeof(Vector3), typeof(Vector3));
            networkObject.RegisterRpc("TakeDamage", TakeDamage, typeof(int), typeof(uint), typeof(Vector3), typeof(Vector3));
            networkObject.RegisterRpc("UpdateId", UpdateId, typeof(uint));
            networkObject.RegisterRpc("Spawn", Spawn, typeof(Vector3), typeof(Quaternion));

            networkObject.onDestroy += DestroyGameObject;

            if (!obj.IsOwner)
            {
                if (!skipAttachIds.ContainsKey(obj.NetworkId))
                {
                    ProcessOthers(gameObject.transform, obj.NetworkId + 1);
                }
                else
                {
                    skipAttachIds.Remove(obj.NetworkId);
                }
            }

            if (obj.Metadata != null)
            {
                byte transformFlags = obj.Metadata[0];

                if (transformFlags != 0)
                {
                    BMSByte metadataTransform = new BMSByte();
                    metadataTransform.Clone(obj.Metadata);
                    metadataTransform.MoveStartIndex(1);

                    if ((transformFlags & 0x01) != 0 && (transformFlags & 0x02) != 0)
                    {
                        MainThreadManager.Run(() =>
                        {
                            transform.position = ObjectMapper.Instance.Map <Vector3>(metadataTransform);
                            transform.rotation = ObjectMapper.Instance.Map <Quaternion>(metadataTransform);
                        });
                    }
                    else if ((transformFlags & 0x01) != 0)
                    {
                        MainThreadManager.Run(() => { transform.position = ObjectMapper.Instance.Map <Vector3>(metadataTransform); });
                    }
                    else if ((transformFlags & 0x02) != 0)
                    {
                        MainThreadManager.Run(() => { transform.rotation = ObjectMapper.Instance.Map <Quaternion>(metadataTransform); });
                    }
                }
            }

            MainThreadManager.Run(() =>
            {
                NetworkStart();
                networkObject.Networker.FlushCreateActions(networkObject);
            });
        }
		/// <summary>
		/// This method is used on the client to attempt to connect to the server through the NAT hole punch server
		/// </summary>
		/// <param name="socket">This is the socket that is being used for the communication with the server</param>
		/// <param name="port">This is the port number that this client is bound to</param>
		/// <param name="requestHost">This is the host address of the server that this client is trying to connect to</param>
		/// <param name="requestPort">This is the host port of the server that this client is trying to connect to</param>
		/// <param name="proxyHost">This is the NAT hole punch server host address</param>
		/// <param name="proxyPort">This is the NAT hole punch server port number</param>
		/// <returns></returns>
		public static bool RequestNat(CrossPlatformUDP socket, ushort port, string requestHost, ushort requestPort, string proxyHost, ushort proxyPort = PORT)
		{
#if !NETFX_CORE
			IPEndPoint endpoint = new IPEndPoint(IPAddress.Parse(proxyHost), proxyPort);

			List<byte> data = new List<byte>(new byte[] { 4, 4, 2 });
			data.AddRange(BitConverter.GetBytes(port));
			data.AddRange(BitConverter.GetBytes(requestPort));
			data.AddRange(Encryptor.Encoding.GetBytes(requestHost));

			try
			{
				int tryCount = 10;
				while (socket.ReadClient.Available == 0)
				{
					socket.ReadClient.Send(data.ToArray(), data.Count, endpoint);
					Thread.Sleep(500);

					if (--tryCount <= 0)
						throw new Exception("Unable to contact proxy host");
				}

				string endpointStr = "";
				BMSByte otherBytes = socket.ReadClient.Receive(ref endpoint, ref endpointStr);

				BMSByte found = new BMSByte();
				found.Clone(otherBytes);

				if (found.byteArr[2] == 0)
					return false;

				ushort targetPort = System.BitConverter.ToUInt16(found.byteArr, 3);
				string targetHost = Encryptor.Encoding.GetString(found.byteArr, 5, found.byteArr.Length - 6);

				IPEndPoint targetEndpoint = new IPEndPoint(IPAddress.Parse(targetHost), targetPort);

				tryCount = 20;
				while (socket.ReadClient.Available == 0)
				{
					socket.ReadClient.Send(new byte[] { 4, 4, 0 }, 3, targetEndpoint);
					Thread.Sleep(500);

					if (--tryCount <= 0)
						throw new Exception("Unable to contact proxy host");
				}

#if UNITY_EDITOR
				Debug.Log("Connected via NAT traversal");
#endif
			}
#if UNITY_EDITOR
			catch (Exception e)
			{
				Debug.LogException(e);
			}
#else
			catch { }
#endif
#endif

			return true;
		}
Beispiel #13
0
        public override void Initialize(NetworkObject obj)
        {
            // We have already initialized this object
            if (networkObject != null && networkObject.AttachedBehavior != null)
            {
                return;
            }

            networkObject = (NetworkedPlayerNetworkObject)obj;
            networkObject.AttachedBehavior = this;

            base.SetupHelperRpcs(networkObject);
            networkObject.RegisterRpc("Attack", Attack);
            networkObject.RegisterRpc("ChangeName", ChangeName, typeof(string));
            networkObject.RegisterRpc("Jump", Jump, typeof(bool));
            networkObject.RegisterRpc("Land", Land);
            networkObject.RegisterRpc("Die", Die, typeof(string), typeof(int));
            networkObject.RegisterRpc("TryHit", TryHit, typeof(uint), typeof(string), typeof(int), typeof(Vector3));
            networkObject.RegisterRpc("Init", Init, typeof(int), typeof(Vector3));
            networkObject.RegisterRpc("ToggleFlag", ToggleFlag, typeof(bool));
            networkObject.RegisterRpc("Knockback", Knockback, typeof(Vector3));
            networkObject.RegisterRpc("DebugAttack", DebugAttack);
            networkObject.RegisterRpc("Hitmarker", Hitmarker);
            networkObject.RegisterRpc("Respawn", Respawn);
            networkObject.RegisterRpc("Dash", Dash);

            networkObject.onDestroy += DestroyGameObject;

            if (!obj.IsOwner)
            {
                if (!skipAttachIds.ContainsKey(obj.NetworkId))
                {
                    uint newId = obj.NetworkId + 1;
                    ProcessOthers(gameObject.transform, ref newId);
                }
                else
                {
                    skipAttachIds.Remove(obj.NetworkId);
                }
            }

            if (obj.Metadata != null)
            {
                byte transformFlags = obj.Metadata[0];

                if (transformFlags != 0)
                {
                    BMSByte metadataTransform = new BMSByte();
                    metadataTransform.Clone(obj.Metadata);
                    metadataTransform.MoveStartIndex(1);

                    if ((transformFlags & 0x01) != 0 && (transformFlags & 0x02) != 0)
                    {
                        MainThreadManager.Run(() =>
                        {
                            transform.position = ObjectMapper.Instance.Map <Vector3>(metadataTransform);
                            transform.rotation = ObjectMapper.Instance.Map <Quaternion>(metadataTransform);
                        });
                    }
                    else if ((transformFlags & 0x01) != 0)
                    {
                        MainThreadManager.Run(() => { transform.position = ObjectMapper.Instance.Map <Vector3>(metadataTransform); });
                    }
                    else if ((transformFlags & 0x02) != 0)
                    {
                        MainThreadManager.Run(() => { transform.rotation = ObjectMapper.Instance.Map <Quaternion>(metadataTransform); });
                    }
                }
            }

            MainThreadManager.Run(() =>
            {
                NetworkStart();
                networkObject.Networker.FlushCreateActions(networkObject);
            });
        }
        public override void Initialize(NetworkObject obj)
        {
            // We have already initialized this object
            if (networkObject != null && networkObject.AttachedBehavior != null)
            {
                return;
            }

            networkObject = (MoveCube1NetworkObject)obj;
            networkObject.AttachedBehavior = this;

            base.SetupHelperRpcs(networkObject);
            networkObject.RegisterRpc("MoveUp", MoveUp);
            networkObject.RegisterRpc("MoveDown", MoveDown);

            networkObject.onDestroy += DestroyGameObject;

            if (!obj.IsOwner)
            {
                if (!skipAttachIds.ContainsKey(obj.NetworkId))
                {
                    uint newId = obj.NetworkId + 1;
                    ProcessOthers(gameObject.transform, ref newId);
                }
                else
                {
                    skipAttachIds.Remove(obj.NetworkId);
                }
            }

            if (obj.Metadata != null)
            {
                byte transformFlags = obj.Metadata[0];

                if (transformFlags != 0)
                {
                    BMSByte metadataTransform = new BMSByte();
                    metadataTransform.Clone(obj.Metadata);
                    metadataTransform.MoveStartIndex(1);

                    if ((transformFlags & 0x01) != 0 && (transformFlags & 0x02) != 0)
                    {
                        MainThreadManager.Run(() =>
                        {
                            transform.position = ObjectMapper.Instance.Map <Vector3>(metadataTransform);
                            transform.rotation = ObjectMapper.Instance.Map <Quaternion>(metadataTransform);
                        });
                    }
                    else if ((transformFlags & 0x01) != 0)
                    {
                        MainThreadManager.Run(() => { transform.position = ObjectMapper.Instance.Map <Vector3>(metadataTransform); });
                    }
                    else if ((transformFlags & 0x02) != 0)
                    {
                        MainThreadManager.Run(() => { transform.rotation = ObjectMapper.Instance.Map <Quaternion>(metadataTransform); });
                    }
                }
            }

            MainThreadManager.Run(() =>
            {
                NetworkStart();
                networkObject.Networker.FlushCreateActions(networkObject);
            });
        }
Beispiel #15
0
        private static void Program1()
        {
            ConsoleBehavior obj = null;

            string serverIP = "127.0.0.1";

            //string hostIP = "0.0.0.0";
            //ushort port = NetWorker.DEFAULT_PORT;
            //ushort masterServerPort = 15940;
            //string natHost = "0.0.0.0";

            BMSLog.Instance.RegisterLoggerService(new ConsoleLogger());

            Console.Write("server or client: ");
            string serverOrClient = Console.ReadLine().ToLower();

            if (serverOrClient == "client" || serverOrClient == "c")
            {
                networkHandle = new TCPClient();
                ((TCPClient)networkHandle).Connect(serverIP /*, port*/);
            }
            else if (serverOrClient == "server" || serverOrClient == "s")
            {
                networkHandle = new TCPServer(32);
                ((TCPServer)networkHandle).Connect();
                //RegisterOnMasterServer(networkHandle, 32, serverIP, masterServerPort);
            }

            //if (serverOrClient == "client" || serverOrClient == "c")
            //{
            //	networkHandle = new UDPClient();
            //	((UDPClient)networkHandle).Connect(serverIP/*, port, natHost*/);
            //}
            //else if (serverOrClient == "server" || serverOrClient == "s")
            //{
            //	networkHandle = new UDPServer(32);
            //	((UDPServer)networkHandle).Connect(/*hostIP, port, natHost*/);
            //}
            else
            {
                Console.WriteLine("Invalid");
                return;
            }

            networkHandle.textMessageReceived   += ReadTextMessage;
            networkHandle.binaryMessageReceived += ReadBinaryMessage;
            NetworkObject.Factory        = new NetworkObjectFactory();
            networkHandle.objectCreated += (NetworkObject target) =>
            {
                if (target is ConsoleNetworkObject)
                {
                    obj = new ConsoleDerivedNetworkObject();
                    obj.Initialize(target);
                }
            };

            networkHandle.serverAccepted += (sender) =>
            {
                if (networkHandle is IClient)
                {
                    new ConsoleNetworkObject(networkHandle);
                }
            };

            while (true)
            {
                Console.Write("Enter a message: ");
                string message = Console.ReadLine();

                if (message == "disconnect")
                {
                    networkHandle.Disconnect(false);
                }
                else if (message == "exit")
                {
                    break;
                }
                else if (message == "file")
                {
                    BMSByte data = new BMSByte();
                    data.Clone(System.IO.File.ReadAllBytes("testSend.txt"));
                    data.InsertRange(0, new byte[1] {
                        212
                    });

                    if (networkHandle is TCPServer)
                    {
                        ((TCPServer)networkHandle).SendAll(new Binary(networkHandle.Time.Timestep, false, data, Receivers.All, 55, true));
                    }
                    else if (networkHandle is TCPClient)
                    {
                        ((TCPClient)networkHandle).Send(new Binary(networkHandle.Time.Timestep, true, data, Receivers.All, 55, true));
                    }
                    else if (networkHandle is BaseUDP)
                    {
                        ((BaseUDP)networkHandle).Send(new Binary(networkHandle.Time.Timestep, false, data, Receivers.All, 55, false), false);
                    }
                }
                else if (message == "rpc")
                {
                    obj.networkObject.SendRpc(ConsoleBehavior.RPC_HELLO_WORLD, Receivers.AllBuffered, null, "World!");
                }
                else if (message.StartsWith("set num to "))
                {
                    obj.networkObject.Num = int.Parse(message.Substring("set name to ".Length));
                }
                else if (message == "num")
                {
                    Console.WriteLine("Number is currently " + obj.networkObject.Num);
                }
                else
                {
                    if (networkHandle is TCPServer)
                    {
                        obj.networkObject.SendRpc(ConsoleBehavior.RPC_HELLO_WORLD, Receivers.Others, message);
                    }
                    //                        ((TCPServer)networkHandle).SendAll(Text.CreateFromString(networkHandle.Time.Timestep, message, false, Receivers.All, 55, true));
                    else if (networkHandle is TCPClient)
                    {
                        ((TCPClient)networkHandle).Send(Text.CreateFromString(networkHandle.Time.Timestep, message, true, Receivers.All, 55, true));
                    }
                    else if (networkHandle is BaseUDP)
                    {
                        ((BaseUDP)networkHandle).Send(Text.CreateFromString(networkHandle.Time.Timestep, message, false, Receivers.All, 55, false), true);
                    }
                }
            }
        }
		public async void ConnectAndRead(string hostAddress, ushort port, NetworkingStream stream)
		{
			try
			{
				serverHost = new HostName(hostAddress);

				// Try to connect asynchronously
				await socket.ConnectAsync(serverHost, port.ToString());

				Connected = true;
				OnConnected();
				SendAsync(stream);

				byte[] bytes = null;

				Task tReadResponse = Task.Run(async () =>
				{
					DataReader reader = new DataReader(socket.InputStream);
					uint messageSize = await reader.LoadAsync(sizeof(uint));
					if (messageSize != sizeof(uint))
					{
						Disconnect();

						// socket was closed
						return;
					}

					bytes = new byte[messageSize];
					reader.ReadBytes(bytes);
					messageSize = BitConverter.ToUInt32(bytes, 0);
					await reader.LoadAsync(messageSize);

					bytes = new byte[messageSize];

					// TODO:  This may read the first 4 bytes again for the size, make sure it doesn't
					reader.ReadBytes(bytes);
				});

				tReadResponse.Wait();

				Disconnect();

				BMSByte tmp = new BMSByte();
				tmp.Clone(bytes);
				//return new NetworkingStream(Networking.ProtocolType.TCP).Consume(this, null, tmp);
			}
			catch (Exception e)
			{
				ErrorDisconnect(e.Message);
			}
		}
        public override void Initialize(NetworkObject obj)
        {
            // We have already initialized this object
            if (networkObject != null && networkObject.AttachedBehavior != null)
            {
                return;
            }

            networkObject = (PlayerCharacterNetworkObject)obj;
            networkObject.AttachedBehavior = this;

            base.SetupHelperRpcs(networkObject);
            networkObject.RegisterRpc("SendInputs", SendInputs, typeof(ulong), typeof(Vector3), typeof(Quaternion));
            networkObject.RegisterRpc("StartGame", StartGame);
            networkObject.RegisterRpc("FireWeapon", FireWeapon, typeof(ulong), typeof(byte), typeof(Vector3), typeof(Vector3));
            networkObject.RegisterRpc("WeaponFired", WeaponFired, typeof(ulong), typeof(byte));
            networkObject.RegisterRpc("SetLocalPlayerId", SetLocalPlayerId, typeof(uint));
            networkObject.RegisterRpc("Die", Die, typeof(uint));
            networkObject.RegisterRpc("WeaponImpacted", WeaponImpacted, typeof(ulong), typeof(byte), typeof(long), typeof(Vector3));
            networkObject.RegisterRpc("Kill", Kill, typeof(uint));
            networkObject.RegisterRpc("UpdatePosition", UpdatePosition, typeof(ulong), typeof(Vector3), typeof(Quaternion), typeof(Vector3));
            networkObject.RegisterRpc("SendInputBuffer", SendInputBuffer, typeof(uint), typeof(byte[]));

            networkObject.onDestroy += DestroyGameObject;

            if (!obj.IsOwner)
            {
                if (!skipAttachIds.ContainsKey(obj.NetworkId))
                {
                    ProcessOthers(gameObject.transform, obj.NetworkId + 1);
                }
                else
                {
                    skipAttachIds.Remove(obj.NetworkId);
                }
            }

            if (obj.Metadata != null)
            {
                byte transformFlags = obj.Metadata[0];

                if (transformFlags != 0)
                {
                    BMSByte metadataTransform = new BMSByte();
                    metadataTransform.Clone(obj.Metadata);
                    metadataTransform.MoveStartIndex(1);

                    if ((transformFlags & 0x01) != 0 && (transformFlags & 0x02) != 0)
                    {
                        MainThreadManager.Run(() =>
                        {
                            transform.position = ObjectMapper.Instance.Map <Vector3>(metadataTransform);
                            transform.rotation = ObjectMapper.Instance.Map <Quaternion>(metadataTransform);
                        });
                    }
                    else if ((transformFlags & 0x01) != 0)
                    {
                        MainThreadManager.Run(() => { transform.position = ObjectMapper.Instance.Map <Vector3>(metadataTransform); });
                    }
                    else if ((transformFlags & 0x02) != 0)
                    {
                        MainThreadManager.Run(() => { transform.rotation = ObjectMapper.Instance.Map <Quaternion>(metadataTransform); });
                    }
                }
            }

            MainThreadManager.Run(() =>
            {
                NetworkStart();
                networkObject.Networker.FlushCreateActions(networkObject);
            });
        }
		/// <summary>
		/// Tells the client to change their scene to the given scene.  This is often called
		/// after the server has changed to that scene to ensure that the server will always
		/// load up the scene before the client does
		/// </summary>
		/// <param name="port">The port of the <see cref="NetWorker"/> that is to send the message</param>
		/// <param name="targetPlayer">The particular player that will be receiving this message</param>
		/// <param name="sceneName">The name of the scene in which the client should load</param>
		public static void ChangeClientScene(ushort port, NetworkingPlayer targetPlayer, string sceneName)
		{
			if (!Sockets.ContainsKey(port)) throw new NetworkException("There isn't a server running using the specified port on this machine");
			if (!Sockets[port].IsServer) throw new NetworkException("Writing to particular players can only be done by the server, the NetWorker on the specified port is not a server");

			BMSByte data = new BMSByte();
			data.Clone(Encryptor.Encoding.GetBytes(sceneName));
			data.InsertRange(0, new byte[1] { 2 });
			Sockets[port].WriteRaw(data, false);
		}
Beispiel #19
0
        public override void Initialize(NetworkObject obj)
        {
            // We have already initialized this object
            if (networkObject != null && networkObject.AttachedBehavior != null)
            {
                return;
            }

            networkObject = (MasterNetworkObject)obj;
            networkObject.AttachedBehavior = this;

            base.SetupHelperRpcs(networkObject);
            networkObject.RegisterRpc("SendMessage", SendMessage, typeof(string));
            networkObject.RegisterRpc("AddActivePlayer", AddActivePlayer, typeof(string), typeof(bool));
            networkObject.RegisterRpc("RemoveActivePlayer", RemoveActivePlayer, typeof(string));
            networkObject.RegisterRpc("ClientLoadMothership", ClientLoadMothership, typeof(string));
            networkObject.RegisterRpc("StartTravel", StartTravel, typeof(string));
            networkObject.RegisterRpc("CheckTravel", CheckTravel);
            networkObject.RegisterRpc("EnterOrbit", EnterOrbit, typeof(int));
            networkObject.RegisterRpc("LeaveOrbit", LeaveOrbit);
            networkObject.RegisterRpc("ColonizePlanet", ColonizePlanet);
            networkObject.RegisterRpc("CanColonize", CanColonize);
            networkObject.RegisterRpc("LandOnPlanet", LandOnPlanet);
            networkObject.RegisterRpc("CanLandOnPlanet", CanLandOnPlanet);
            networkObject.RegisterRpc("ClientEnterOrbit", ClientEnterOrbit);
            networkObject.RegisterRpc("SendCallbackToClient", SendCallbackToClient, typeof(string), typeof(bool), typeof(string));
            networkObject.RegisterRpc("SendEventTrigger", SendEventTrigger, typeof(string), typeof(bool));
            networkObject.RegisterRpc("CalculateTravelTime", CalculateTravelTime, typeof(int), typeof(bool));
            networkObject.RegisterRpc("SendBmcRequest", SendBmcRequest, typeof(string), typeof(string));
            networkObject.RegisterRpc("SendBmcCallbackToClient", SendBmcCallbackToClient, typeof(string), typeof(string));
            networkObject.RegisterRpc("StartMiningMission", StartMiningMission, typeof(byte), typeof(byte), typeof(byte), typeof(bool));
            networkObject.RegisterRpc("LogBook", LogBook, typeof(int), typeof(string));

            networkObject.onDestroy += DestroyGameObject;

            if (!obj.IsOwner)
            {
                if (!skipAttachIds.ContainsKey(obj.NetworkId))
                {
                    ProcessOthers(gameObject.transform, obj.NetworkId + 1);
                }
                else
                {
                    skipAttachIds.Remove(obj.NetworkId);
                }
            }

            if (obj.Metadata != null)
            {
                byte transformFlags = obj.Metadata[0];

                if (transformFlags != 0)
                {
                    BMSByte metadataTransform = new BMSByte();
                    metadataTransform.Clone(obj.Metadata);
                    metadataTransform.MoveStartIndex(1);

                    if ((transformFlags & 0x01) != 0 && (transformFlags & 0x02) != 0)
                    {
                        MainThreadManager.Run(() =>
                        {
                            transform.position = ObjectMapper.Instance.Map <Vector3>(metadataTransform);
                            transform.rotation = ObjectMapper.Instance.Map <Quaternion>(metadataTransform);
                        });
                    }
                    else if ((transformFlags & 0x01) != 0)
                    {
                        MainThreadManager.Run(() => { transform.position = ObjectMapper.Instance.Map <Vector3>(metadataTransform); });
                    }
                    else if ((transformFlags & 0x02) != 0)
                    {
                        MainThreadManager.Run(() => { transform.rotation = ObjectMapper.Instance.Map <Quaternion>(metadataTransform); });
                    }
                }
            }

            MainThreadManager.Run(() =>
            {
                NetworkStart();
                networkObject.Networker.FlushCreateActions(networkObject);
            });
        }