Example #1
0
        public UpdateNetworkedBuilding Deserialize(NetworkingStream stream)
        {
            this.buildingUID = ObjectMapper.Map <int>(stream);
            this.health      = ObjectMapper.Map <int>(stream);

            return(this);
        }
    public void ResolveRangedCombat(NetworkingPlayer player, NetworkingStream data)
    {
        SmartObject byt = EasySerialization.EasyDeserialize<SmartObject>(ref data);
        int origin = (int) byt.GetObject("obj_0");
        int target = (int) byt.GetObject("obj_1");

        if(scene_combat_model.FindCombatInstance(origin, target) == null)
            return;

        Combat_Model model = scene_combat_model.FindCombatInstance(origin, target);

        if(player.NetworkId != (ulong) 0 && Networking.PrimarySocket.Me.NetworkId == (ulong) 0) {
            int random_dice = Random.Range(1, 6);
            if(random_dice >= 5) {
                model.target.entity_model.stats.wounds -= 2;
            } else if(random_dice >= 3) {
                model.target.entity_model.stats.wounds -= 1;
            } else if(random_dice >= 1) {

            }
            model.origin.entity_model.stats.attacks -= 1;
            Network_Command_Manager.instance.CallCustomRPC(ResolveRangedCombat, NetworkReceivers.Others, origin, target);
            Network_Command_Manager.instance.ToNetController<Host_Controller>().ProcessUpdateEntities(new Entity_Model[2] { model.origin.entity_model, model.target.entity_model });
            model.Destroy();
        } else if(player.NetworkId == (ulong) 0 && Networking.PrimarySocket.Me.NetworkId != (ulong) 0) {
            model.Destroy();
        }
    }
		public override void Write(NetworkingStream stream)
		{
			if (!Connected)
				throw new NetworkException("You must first be connected to a network before you can send packets.");

			SendAsync(stream);
		}
 //    public void ReadCombatRegister(NetworkingPlayer arg1, NetworkingStream arg2){
 //        SmartObject request = Networking_Utilities.EasyDeserialize<SmartObject> (ref arg2);
 //        switch (request.GetString("type")){
 //        case "Ranged":
 //            CallOnMainThread(delegate {
 //                CallOnMainThread(delegate(object[] obj2) {
 //                    Entity_Controller.instance.AttemptRangedAttack((Entity)obj2[0], (Entity)obj2[1]);
 //                }, new object[2]{Entity_Model.FindEntitybyID(request.GetInt("origin")), Entity_Model.FindEntitybyID(request.GetInt("target"))});
 //            });
 //            break;
 //        }
 //    }
 public void ReadRequest(NetworkingPlayer arg1, NetworkingStream arg2)
 {
     Debug_Console.i.add("New event remote called id " + EventHelper.GetEventId("SERVER_REQUEST") + ", name " + "SERVER_REQUEST");
     SmartObject request = EasySerialization.EasyDeserialize<SmartObject>(ref arg2);
     switch(request.GetString("type")) {
         case "ROTATE_ENTITY":
             CallMainThread(delegate (object[] obj) {
                 if(Entity_Actions.Attempt_Rotate_Entity(((Entity_Model) obj[0]).GetParent, (Vector3) obj[1])) {
                     Debug.Log("Rotation was done successfully");
                     ProcessUpdateEntities(new Entity_Model[1] { ((Entity_Model) obj[0]).GetParent.entity_model });
                 }
             }, new object[2] { request.GetEntity("Entity"), request.GetVec3("Target") });
             break;
         case "MOVE_ENTITY":
             CallMainThread(delegate (object[] obj) {
                 Entity_Actions.Attempt_Move_Entity(((Entity_Model) obj[0]).GetParent, (Vector3) obj[1], delegate (Entity_Model entity_model) {
                     Host_Controller.instance.ToNetController<Host_Controller>().ProcessUpdateEntities(new Entity_Model[1] { entity_model });
                 });
             }, new object[2] { request.GetEntity("Entity"), request.GetVec3("Target") });
             break;
         case "PLAYER_READY":
             Turn_Controller.instance.server_players.GetPlayerByID((int) arg1.NetworkId).ready = true;
             break;
     }
 }
 public virtual void ReceiveTreeInstancesStream(NetworkingPlayer player, NetworkingStream stream)
 {
     BeardedManStudios.Network.Unity.MainThreadManager.Run(() =>
     {
         var data = ForgeNetworkingNetworkData.Deserialize(stream);
         data.UnPack();
     });
 }
 public void SendChat(NetworkingPlayer player, NetworkingStream stream)
 {
     SmartObject obj = EasySerialization.EasyDeserialize<SmartObject>(ref stream);
     string input = (string) obj.GetObject("obj_0");
     ulong sender_id = (ulong) obj.GetObject("obj_1");
     string sender_name = (Turn_Controller.instance.server_players.GetPlayerByID(sender_id) != null) ? Turn_Controller.instance.server_players.GetPlayerByID(sender_id).name : "Server";
     Debug_Console.i.add(sender_name + " :" + input);
 }
 private void Deserialize(NetworkingStream stream)
 {
     num = ObjectMapper.Map<int>(stream);
     buul = ObjectMapper.Map<bool>(stream);
     money = ObjectMapper.Map<float>(stream);
     first = ObjectMapper.Map<string>(stream);
     big = ObjectMapper.Map<double>(stream);
     v2 = ObjectMapper.Map<Vector2>(stream);
     v3 = ObjectMapper.Map<Vector3>(stream);
     v4 = ObjectMapper.Map<Vector4>(stream);
 }
        public static ForgeNetworkingNetworkData Deserialize(NetworkingStream stream)
        {
            ForgeNetworkingNetworkData instance = new ForgeNetworkingNetworkData();

            instance.terrainID      = ObjectMapper.Map <string>(stream);
            instance.treeInstanceID = ObjectMapper.Map <int>(stream);
            instance._health        = ObjectMapper.Map <int>(stream);
            instance.eventType      = ObjectMapper.Map <PacketType>(stream);

            return(instance);
        }
Example #9
0
 private void Deserialize(NetworkingStream stream)
 {
     num   = ObjectMapper.Map <int>(stream);
     buul  = ObjectMapper.Map <bool>(stream);
     money = ObjectMapper.Map <float>(stream);
     first = ObjectMapper.Map <string>(stream);
     big   = ObjectMapper.Map <double>(stream);
     v2    = ObjectMapper.Map <Vector2>(stream);
     v3    = ObjectMapper.Map <Vector3>(stream);
     v4    = ObjectMapper.Map <Vector4>(stream);
 }
        void HandleData (MessageType messageType, NetworkingStream stream) {

            LSUtility.bufferBytes.FastClear ();

            for (int i = 0; i < stream.Bytes.Size - 1; i++) {
                LSUtility.bufferBytes.Add (stream.Bytes [stream.Bytes.StartIndex (i)]);
            }
            byte[] data = LSUtility.bufferBytes.ToArray ();
            switch (messageType) {
           
        }

         BMSByte bufferBites = new BMSByte ();
Example #11
0
        public CreateNetworkedBuilding Deserialize(NetworkingStream stream)
        {
            this.pos    = ObjectMapper.Map <Vector3>(stream);
            this.rot    = ObjectMapper.Map <Quaternion>(stream);
            this.health = ObjectMapper.Map <int>(stream);
            this.id     = ObjectMapper.Map <int>(stream);

            this.placedOnID = ObjectMapper.Map <int>(stream);
            this.prefabID   = ObjectMapper.Map <int>(stream);

            this.requesterID = ObjectMapper.Map <ulong>(stream);

            return(this);
        }
        void HandleData(MessageType messageType, NetworkingStream stream)
        {
            LSUtility.bufferBytes.FastClear();

            for (int i = 0; i < stream.Bytes.Size - 1; i++)
            {
                LSUtility.bufferBytes.Add(stream.Bytes [stream.Bytes.StartIndex(i)]);
            }
            byte[] data = LSUtility.bufferBytes.ToArray();
            switch (messageType)
            {
            }

            BMSByte bufferBites = new BMSByte();
 public void AttemptRangedAttack(NetworkingPlayer player, NetworkingStream data)
 {
     SmartObject obj = EasySerialization.EasyDeserialize<SmartObject>(ref data);
     int origin = (int) obj.GetObject("obj_0");
     int target = (int) obj.GetObject("obj_1");
     if(player.NetworkId != (ulong) 0 && Networking.PrimarySocket.Me.NetworkId == (ulong) 0) {
         //			RaycastHit hit;
         //			if(Physics.Linecast(Entity_Model.FindEntitybyID(origin).transform.position, Entity_Model.FindEntitybyID(target).transform.position, out hit, no_characters)){
         combat_controller.scene_combat_model.AddRangeInstance(Entity_Model.FindEntitybyID(origin), Entity_Model.FindEntitybyID(target));
         Network_Command_Manager.instance.CallCustomRPC(AttemptRangedAttack, NetworkReceivers.Others, origin, target);
         Debug_Console.i.add("This server was asked to create combat");
         //			}
     } else if(player.NetworkId == (ulong) 0 && Networking.PrimarySocket.Me.NetworkId != (ulong) 0) {
         combat_controller.scene_combat_model.AddRangeInstance(Entity_Model.FindEntitybyID(origin), Entity_Model.FindEntitybyID(target));
         Debug_Console.i.add("server sent combat");
     }
 }
		/// <summary>
		/// Constructor for the NetworkingStream with a passed in stream
		/// </summary>
		/// <param name="stream">The stream passed in to be used</param>
		public NetworkingStreamRPC(NetworkingStream stream)
		{
			// TODO:  Check for null NetworkedBehavior or if it is the base class
			if (ReferenceEquals(stream.NetworkedBehavior, null))
				return;

#if NETFX_CORE
			IEnumerable<PropertyInfo> properties = stream.GetType().GetRuntimeProperties();
#else
			PropertyInfo[] properties = stream.GetType().GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
#endif
			foreach (PropertyInfo property in properties)
			{
				if (property.CanRead && property.CanWrite)
					property.SetValue(this, property.GetValue(stream, null), null);
			}

			NetworkedBehavior.InvokeRPC(this);
		}
 public void ResetBetweenPhase(NetworkingPlayer player, NetworkingStream stream)
 {
     if(Networking.PrimarySocket.Me.NetworkId == (ulong) 0) {
         foreach(Combat_Model combat in Combat_Controller.instance.scene_combat_model.combat_instances.ToArray()) {
             combat.Destroy();
         }
         Combat_Controller.instance.scene_combat_model.combat_groups = new List<Melee_Combat_Group_Model>();
         Combat_Controller.instance.scene_combat_model.first_initative = new List<Melee_Combat_Group_Model>();
         Combat_Controller.instance.scene_combat_model.second_initative = new List<Melee_Combat_Group_Model>();
         Network_Command_Manager.instance.CallCustomRPC(ResetBetweenPhase, NetworkReceivers.Others, server_players.active_team);
     } else if(player.NetworkId == (ulong) 0 && Networking.PrimarySocket.Me.NetworkId != (ulong) 0) {
         foreach(Combat_Model combat in Combat_Controller.instance.scene_combat_model.combat_instances.ToArray()) {
             combat.Destroy();
         }
         Combat_Controller.instance.scene_combat_model.combat_groups = new List<Melee_Combat_Group_Model>();
         Combat_Controller.instance.scene_combat_model.first_initative = new List<Melee_Combat_Group_Model>();
         Combat_Controller.instance.scene_combat_model.second_initative = new List<Melee_Combat_Group_Model>();
     }
 }
		public async void ConnectAndWrite(string hostAddress, ushort port, NetworkingStream stream)
		{
			try
			{
				serverHost = new HostName(hostAddress);

				await socket.ConnectAsync(serverHost, port.ToString());

				Connected = true;
				OnConnected();
				
				SendAsync(stream);
				Disconnect();
			}
			catch (Exception e)
			{
				ErrorDisconnect(e.Message);
			}
		}
		private async void WriteAndClose(StreamSocket targetSocket, NetworkingStream stream)
		{
			try
			{
				DataWriter writer = new DataWriter(targetSocket.OutputStream);
				writer.WriteBytes(stream.Bytes.byteArr);

				// Send synchronously
				await writer.StoreAsync();

				OnDataSent(stream);

				writer.DetachStream();
				writer.Dispose();
				targetSocket.Dispose();
			}
			catch// (Exception e)
			{
				targetSocket.Dispose();
				//Networking.Error(e.Message);
			}
		}
		/// <summary>
		/// Constructor for the NetworkingStream with a passed in stream
		/// </summary>
		/// <param name="stream">The stream passed in to be used</param>
		public NetworkingStreamRPC(NetworkingStream stream, bool skipCall = false)
		{
			FailedExecution = false;

			// TODO:  Check for null NetworkedBehavior or if it is the base class
			if (!skipCall && ReferenceEquals(stream.NetworkedBehavior, null))
				return;

#if NETFX_CORE
			IEnumerable<PropertyInfo> properties = stream.GetType().GetRuntimeProperties();
#else
			PropertyInfo[] properties = stream.GetType().GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
#endif
			foreach (PropertyInfo property in properties)
			{
				if (property.CanRead && property.CanWrite)
					property.SetValue(this, property.GetValue(stream, null), null);
			}

			if (!skipCall)
				FailedExecution = !NetworkedBehavior.InvokeRPC(this);
			else
				Bytes = new BMSByte().Clone(stream.Bytes);
		}
		/// <summary>
		/// Write to the server with a Networking Stream
		/// </summary>
		/// <param name="stream">Networking Stream to write</param>
		public override void Write(NetworkingStream stream)
		{
			if (!Connected)
				throw new NetworkException(5, "The network could not be written to because no connection has been opened");

			if (!netStream.CanWrite)
				return;

			// Send the message to the connected TcpServer.
			Send(stream.Bytes.Compress().byteArr, stream.Bytes.Size);
			OnDataSent(stream);
		}
		public override void Write(NetworkingStream stream) { }
Example #21
0
		public static void WriteUDP(string ip, ushort port, string updateidentifier, NetworkingStream stream, bool reliable = false)
		{
			//CrossPlatformUDP.Write(ip, port, updateidentifier, stream, reliable);
		}
		public override void Write(NetworkingPlayer player, NetworkingStream stream)
		{
			throw new NetworkException(11, "This is a method planned for the future and has not been implemented yet.");
		}
Example #23
0
		/// <summary>
		/// Write to the TCP given a NetWorker(Socket) with a stream of data
		/// </summary>
		/// <param name="port">Port of the given NetWorker(Socket)</param>
		/// <param name="stream">The stream of data to be written</param>
		public static void WriteTCP(ushort port, NetworkingStream stream)
		{
			Sockets[port].Write(stream);
		}
Example #24
0
		/// <summary>
		/// Write to the TCP given a NetWorker(Socket) with a stream of data
		/// </summary>
		/// <param name="socket">The NetWorker(Socket) to write with</param>
		/// <param name="stream">The stream of data to be written</param>
		public static void WriteTCP(NetWorker socket, NetworkingStream stream)
		{
			socket.Write(stream);
		}
 private void ReadFromNetwork(NetworkingPlayer sender, NetworkingStream stream)
 {
     ServerDeserialize(stream);
 }
Example #26
0
		/// <summary>
		/// Writes a <see cref="NetworkingStream"/> to a particular <see cref="NetWorker"/>
		/// </summary>
		/// <param name="socket">NetWorker(Socket) to write with</param>
		/// <param name="identifier">Unique identifier to be used</param>
		/// <param name="stream">The stream of data to be written</param>
		/// <param name="reliable">If this be a reliable UDP</param>
		public static void WriteUDP(NetWorker socket, string identifier, NetworkingStream stream, bool reliable = false)
		{
			socket.Write(identifier, stream, reliable);
		}
		public override void Write(NetworkingPlayer player, NetworkingStream stream) { }
		public void DeserializeManualProperties(NetworkingStream stream)
		{
			foreach (NetRef<object> obj in ManualProperties)
			{
				if (!interpolateFloatingValues || obj.IgnoreLerp)
				{
					if (obj.Assign(ObjectMapper.Map(obj.Value.GetType(), stream)))
						obj.Callback(this, true);
				}
				else
					obj.Lerp(ObjectMapper.Map(obj.Value.GetType(), stream));
			}
		}
Example #29
0
 private void ReadFromNetwork(NetworkingPlayer sender, NetworkingStream stream)
 {
     ServerDeserialize(stream);
 }
		private Vector3 GetNextSerializedTransform(SerializeVector3Properties type, NetworkingStream stream, Vector3 standard)
		{
			switch (type)
			{
				case SerializeVector3Properties.X:
					standard.x = ObjectMapper.Map<float>(stream);
					break;
				case SerializeVector3Properties.Y:
					standard.y = ObjectMapper.Map<float>(stream);
					break;
				case SerializeVector3Properties.Z:
					standard.z = ObjectMapper.Map<float>(stream);
					break;
				case SerializeVector3Properties.XY:
					standard.x = ObjectMapper.Map<float>(stream);
					standard.y = ObjectMapper.Map<float>(stream);
					break;
				case SerializeVector3Properties.XZ:
					standard.x = ObjectMapper.Map<float>(stream);
					standard.z = ObjectMapper.Map<float>(stream);
					break;
				case SerializeVector3Properties.YZ:
					standard.y = ObjectMapper.Map<float>(stream);
					standard.z = ObjectMapper.Map<float>(stream);
					break;
				case SerializeVector3Properties.XYZ:
					return ObjectMapper.Map<Vector3>(stream);
			}

			return standard;
		}
Example #31
0
 private void ReadFromNetwork(NetworkingPlayer sender, NetworkingStream stream)
 {
     Debug.Log("Reading");
     Deserialize(stream);
 }
Example #32
0
		/// <summary>
		/// Writes a <see cref="NetworkingStream"/> to a particular <see cref="NetWorker"/> that is
		/// running on a particular port
		/// </summary>
		/// <param name="port">Port of the given NetWorker(Socket)</param>
		/// <param name="identifier">Unique identifier to be used</param>
		/// <param name="stream">The stream of data to be written</param>
		/// <param name="reliable">If this be a reliable UDP</param>
		public static void WriteUDP(ushort port, string identifier, NetworkingStream stream, bool reliable = false)
		{
			if (!Sockets.ContainsKey(port))
				throw new NetworkException("There isn't a server running using the specified port on this machine");

			Sockets[port].Write(identifier, stream, reliable);
		}
        private void ServerDeserialize(NetworkingStream stream)
        {
            string recievedResponse = ObjectMapper.Map <string>(stream);

            Debug.Log("Received response: " + recievedResponse);
        }
Example #34
0
 private void ServerDeserialize(NetworkingStream stream)
 {
     string recievedResponse = ObjectMapper.Map<string>(stream);
     Debug.Log("Received response: " + recievedResponse);
 }
Example #35
0
		/// <summary>
		/// Writes a <see cref="NetworkingStream"/> to a particular <see cref="NetWorker"/> that is
		/// running on a particular port directly to a player (if the port is a server)
		/// </summary>
		/// <param name="port">The port that the <see cref="NetWorker"/> is listening on</param>
		/// <param name="player">The player that this server will be writing this message to</param>
		/// <param name="stream">The data stream that is to be written to the player</param>
		/// <exception cref="NetworkException">Thrown when there is not a <see cref="NetWorker"/> on the supplied port</exception>
		/// <exception cref="NetworkException">Thrown when the <see cref="NetWorker"/> on the specified port is not a server</exception>
		public static void Write(ushort port, NetworkingPlayer player, NetworkingStream stream)
		{
			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");

			Sockets[port].Write(player, stream);
		}
		/// <summary>
		/// Prepare this to be Deserialized if it is not the owner
		/// </summary>
		/// <param name="stream">Stream of data to use</param>
		public void PrepareDeserialize(NetworkingStream stream)
		{
			if ((IsOwner && !serverIsAuthority) || (OwningNetWorker.IsServer && serverIsAuthority))
				return;

			newData.Reset();
			newData.Bytes.Clone(stream.Bytes);
			newData.ManualReady(stream.FrameIndex);

			Deserialize(newData);
		}
Example #37
0
		/// <summary>
		/// Writes a <see cref="NetworkingStream"/> to a particular <see cref="NetWorker"/> directly to a player (if the port is a server)
		/// </summary>
		/// <param name="socket">NetWorker(Socket) to write with</param>
		/// <param name="player">Player to be written to server</param>
		/// <param name="stream">The stream of data to be written</param>
		/// <exception cref="NetworkException">Thrown when there is not a <see cref="NetWorker"/> on the supplied port</exception>
		/// <exception cref="NetworkException">Thrown when the <see cref="NetWorker"/> on the specified port is not a server</exception>
		public static void Write(NetWorker socket, NetworkingPlayer player, NetworkingStream stream)
		{
			if (!socket.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");

			socket.Write(player, stream);
		}
		/// <summary>
		/// Only Deserialize the stream of data that is not the owner
		/// </summary>
		/// <param name="stream">Stream of data to use</param>
		public override void Deserialize(NetworkingStream stream)
		{
			if ((IsOwner && !serverIsAuthority) || (OwningNetWorker.IsServer && serverIsAuthority))
				return;

			stream.ResetByteReadIndex();

			targetFrame = stream.FrameIndex;

			targetPosition = GetNextSerializedTransform(serializePosition, stream, targetPosition);
			targetRotation = GetNextSerializedTransform(serializeRotation, stream, targetRotation);
			targetScale = GetNextSerializedTransform(serializeScale, stream, targetScale);

			if (Properties == null)
				return;

			foreach (NetRef<object> obj in Properties)
			{
				// Only allow the server to replicate this variable across the network
				if (obj.serverOnly && !OwningNetWorker.IsServer)
				{
					ObjectMapper.Map(obj.Value.GetType(), stream);
					continue;
				}

				if (!interpolateFloatingValues || obj.IgnoreLerp || !DataInitialized)
				{
					if (obj.Assign(ObjectMapper.Map(obj.Value.GetType(), stream)))
						obj.Callback(this, true);
				}
				else
					obj.Lerp(ObjectMapper.Map(obj.Value.GetType(), stream));
			}
		}
Example #39
0
        /// <summary>
        /// Check the argument update with the stream and start index
        /// </summary>
        /// <param name="stream">Stream to be updated</param>
        /// <param name="start">Start index</param>
        public ulong SetupInstantiateId(NetworkingStream stream, int start)
        {
            if (MethodName == INSTANTIATE_METHOD_NAME)
            {
                idReplacer = BitConverter.GetBytes(SimpleNetworkedMonoBehavior.GenerateUniqueId());

                for (int i = 0; i < idReplacer.Length; i++)
                    stream.Bytes.byteArr[start + sizeof(ulong) + i] = idReplacer[i];
            }

            return SimpleNetworkedMonoBehavior.ObjectCounter;
        }