示例#1
0
        /// <summary>
        /// Queue a position update on the FlightContextFactory. The FlightContextFactory will handle further
        /// processing of this position update.
        /// </summary>
        /// <param name="positionUpdate">The position update to queue</param>
        public void Process(PositionUpdate positionUpdate)
        {
            if (positionUpdate == null)
            {
                return;
            }

            EnsureContextAvailable(positionUpdate.Aircraft);

            if (_flightContextDictionary.TryGetValue(positionUpdate.Aircraft, out var flightContext))
            {
                var previousPoint = flightContext.CurrentPosition;

                if (flightContext.Process(positionUpdate))
                {
                    _map.Add(positionUpdate);
                    _map.Remove(previousPoint);

                    if (_map.Nearby(previousPoint, 2).ToList().Count(q => q.Aircraft == positionUpdate.Aircraft) > 1)
                    {
                        Debugger.Break();
                    }
                }
            }
        }
示例#2
0
    public IEnumerator UpdateTime(DateTime time, string type, int decorId, int eventId)
    {
        PositionUpdate data = new PositionUpdate();

        data.player_id = PlayerPrefs.GetInt("PlayerId");
        data.item_id   = decorId;
//        data.rotation =
        data.position = "";
        data.cool_down_time_event_id = eventId;
        if (type.ToLower().Contains("busy"))
        {
            data.cool_time    = "";
            data.is_busy_time = time.ToString();
        }
        else if (type.ToLower().Contains("cool"))
        {
            data.cool_time    = time.ToString();
            data.is_busy_time = "";
        }
        CoroutineWithData cd = new CoroutineWithData(DownloadContent.Instance, DownloadContent.Instance.SendPositions(data));

        yield return(cd.coroutine);

        if (cd.result.ToString() == "True" || cd.result.ToString() == "true")
        {
            print("updated");
        }
    }
示例#3
0
文件: Logger.cs 项目: thijser/ARGAME
        public void OnPositionUpdate(PositionUpdate update)
        {
            if (update.Type != UpdateType.UpdatePosition && update.Type != UpdateType.UpdateRotation)
            {
                return;
            }

            int updateID = update.Id;

            if (timeKeeper.ContainsKey(updateID) && positionKeeper.ContainsKey(updateID))
            {
                TimeSpan span     = DateTime.Now - timeKeeper[updateID];
                Vector2  movement = positionKeeper[updateID] - update.Coordinate;

                float dist = Mathf.Sqrt(movement.x * movement.x + movement.y * movement.y);

                if (span.Seconds > 1 && dist > PositionLogThreshold)
                {
                    WriteLog(string.Format("marker #{0} moved to position = ({1}, {2}), rotation = {3}", update.Id, update.Coordinate.x, update.Coordinate.y, update.Rotation));

                    positionKeeper[updateID] = update.Coordinate;
                    timeKeeper[updateID]     = DateTime.Now;
                }
            }
            else
            {
                positionKeeper[updateID] = update.Coordinate;
                timeKeeper[updateID]     = DateTime.Now;

                WriteLog(string.Format("marker #{0} registered, position = ({1}, {2}), rotation = {3}", update.Id, update.Coordinate.x, update.Coordinate.y, update.Rotation));
            }
        }
示例#4
0
        override public PositionUpdate Decode_OP_MobUpdate(byte[] mobUpdatePacket)
        {
            PositionUpdate PosUpdate = new PositionUpdate();

            ByteStream Buffer = new ByteStream(mobUpdatePacket);

            PosUpdate.SpawnID = Buffer.ReadUInt16();

            Buffer.SkipBytes(2);

            UInt32 Word1 = Buffer.ReadUInt32();

            UInt32 Word2 = Buffer.ReadUInt32();

            UInt16 Word3 = Buffer.ReadUInt16();

            PosUpdate.p.y = Utils.EQ19ToFloat((Int32)(Word1 & 0x7FFFF));

            // Z is in the top 13 bits of Word1 and the bottom 6 of Word2

            UInt32 ZPart1 = Word1 >> 19;    // ZPart1 now has low order bits of Z in bottom 13 bits
            UInt32 ZPart2 = Word2 & 0x3F;   // ZPart2 now has high order bits of Z in bottom 6 bits

            ZPart2 = ZPart2 << 13;

            PosUpdate.p.z = Utils.EQ19ToFloat((Int32)(ZPart1 | ZPart2));

            PosUpdate.p.x = Utils.EQ19ToFloat((Int32)(Word2 >> 6) & 0x7FFFF);

            PosUpdate.p.heading = Utils.EQ19ToFloat((Int32)(Word3 & 0xFFF));

            PosUpdate.HighRes = false;

            return(PosUpdate);
        }
示例#5
0
        override public List <PositionUpdate> GetHighResolutionMovementUpdates()
        {
            List <PositionUpdate> Updates = new List <PositionUpdate>();

            List <byte[]> UpdatePackets = GetPacketsOfType("OP_NPCMoveUpdate", PacketDirection.ServerToClient);

            foreach (byte[] UpdatePacket in UpdatePackets)
            {
                PositionUpdate PosUpdate = new PositionUpdate();

                BitStream bs = new BitStream(UpdatePacket, 13);

                PosUpdate.SpawnID = bs.readUInt(16);

                UInt32 VFlags = bs.readUInt(6);

                PosUpdate.p.y = (float)bs.readInt(19) / (float)(1 << 3);

                PosUpdate.p.x = (float)bs.readInt(19) / (float)(1 << 3);

                PosUpdate.p.z = (float)bs.readInt(19) / (float)(1 << 3);

                PosUpdate.p.heading = (float)bs.readInt(12) / (float)(1 << 3);

                Updates.Add(PosUpdate);
            }

            return(Updates);
        }
示例#6
0
    override public void SubscribeToPositionUpdate(PositionUpdate positionUpdateFunction)
    {
        // SINGLE SUBSCRIBER
        // If there is already subscriber, unsubscribe them all, and subscribe the new one
        if (OnPositionUpdate != null && OnPositionUpdate.GetInvocationList().Length > 0)
        {
//			Debug.Log ("There is already a subscriber");
            OnPositionUpdate = null;
        }
        if (currentSubscriber != null)
        {
//			Debug.Log ("Reset current subscriber");
            currentSubscriber = null;
        }
        OnPositionUpdate += positionUpdateFunction;
        currentSubscriber = positionUpdateFunction.Target as MonoBehaviour;

        // added on 04 May 2016
//		currentSubscriber.transform.position = m_position;
//		var anglex = transform.rotation.eulerAngles.x;
//		var angley = currentSubscriber.transform.rotation.eulerAngles.y;
//		var anglez = transform.rotation.eulerAngles.z;
//		currentSubscriber.transform.rotation = Quaternion.Euler (anglex, angley, anglez);

//		followerPosition = currentSubscriber.transform.position;
//		followerRotation = currentSubscriber.transform.rotation;
    }
示例#7
0
    public IEnumerator SetPosition()
    {
        PositionUpdate data = new PositionUpdate();

        data.player_id = PlayerPrefs.GetInt("PlayerId");
        foreach (var downloaded_item in DownloadContent.Instance.downloaded_items)
        {
            if (downloaded_item.Name.Trim('"') == decorInfo.Name.Trim('"'))
            {
                data.item_id = downloaded_item.Item_id;
            }
        }

        data.position = SerializeVector3Array(this.transform.position);
        data.rotation = sprites.FindIndex(x => x == gameObject.GetComponent <SpriteRenderer> ().sprite) + "_" + Placed;
        data.cool_down_time_event_id = 0;
        data.cool_time    = "";
        data.is_busy_time = "";

        CoroutineWithData cd = new CoroutineWithData(DownloadContent.Instance, DownloadContent.Instance.SendPositions(data));

        yield return(cd.coroutine);

        if (cd.result.ToString() == "True" || cd.result.ToString() == "true")
        {
            this.transform.GetChild(1).gameObject.SetActive(false);
            this.gameObject.GetComponent <DragSnap> ().enabled = false;
            PlayerPrefs.SetInt("Direction" + decorInfo.Name, direction);
            objPosition = this.transform.position;
            PlayerPrefs.SetString("ObjPosition" + decorInfo.Name, SerializeVector3Array(objPosition));
            ScreenAndPopupCall.Instance.placementbutton.onClick.RemoveAllListeners();
            ScreenAndPopupCall.Instance.placementbutton.gameObject.SetActive(false);
            ScreenAndPopupCall.Instance.placementbutton.interactable = false;

            if (mouseDown != 0)
            {
                OnMouseDown();
            }

            //		GameManager.Instance.AddExperiencePoints (2f);
            if (!tutorial._SofaPlaced && tutorial.purchaseSofa > 1)
            {
                tutorial.PurchaseSofa();
            }

            if (!tutorial._QuestAttended && tutorial._PublicAreaAccessed && tutorial.questAttended > 8)
            {
//				tutorial.QuestAttendingStart ();
            }
//			transform.GetComponent<DragSnap> ().FindNeartGameObject ();
            /// Bug fixed of Sprint 6 on Date 16/11/2016
//			for (int i = 0; i < DecorController.Instance.PlacedDecors.Count; i++) {
            this.GetComponent <DragSnap> ().FindNearGameObjectFinal(this.transform.FindChild("New Sprite"));
            transform.FindChild("Check").GetComponent <SpriteRenderer> ().color = Color.white;
//				print (i);
//			}
        }
        transform.FindChild("Check").gameObject.SetActive(false);
    }
示例#8
0
 public void updatePosition(PositionUpdate update)
 {
     if (isActivePlayer)
     {
         return;
     }
     gameobject.GetComponent <VelocityInterpolator>().updateTransform(update.pos, update.rot, update.vel);
 }
示例#9
0
    virtual public void UnsubscribeToPositionUpdate(PositionUpdate fnc)
    {
        //reduce counter
        subscribers--;

        //unsubscribe
        OnPositionUpdate -= fnc;
    }
示例#10
0
    private void HandleServerMessage(ModelInterface msg)
    {
        PositionUpdate pu = msg as PositionUpdate;

        if (pu != null)
        {
            return;
        }
    }
示例#11
0
    public void SubscribeToPositionUpdate(PositionUpdate fnc, Vector3 pos, Quaternion ori)
    {
        if (subscribers == 0)
        {
            SetInitialPosition(pos, ori);
        }

        SubscribeToPositionUpdate(fnc);
    }
示例#12
0
    public static PositionUpdate ToModel(string networkString)
    {
        PositionUpdate req = JsonConvert.DeserializeObject <PositionUpdate>(networkString);

        if (req != null && req.type == "PositionUpdate")
        {
            return(req);
        }
        return(null);
    }
示例#13
0
    virtual public void SubscribeToPositionUpdate(PositionUpdate positionUpdateFunction)
    {
        //add to counter
        subscribers++;

        //subscribe
        OnPositionUpdate += positionUpdateFunction;

        //trigger initial event
        positionUpdateFunction(m_position, m_rotation);
    }
    void PlayerPositionUpdate()
    {
        PositionUpdate playerPosition = new PositionUpdate();

        playerPosition.cmd        = commands.POSITION_UPDATE;
        playerPosition.position.X = currentPlayers[myAddress].transform.position.x;
        playerPosition.position.Y = currentPlayers[myAddress].transform.position.y;
        playerPosition.position.Z = currentPlayers[myAddress].transform.position.z;
        Byte[] sendBytes = Encoding.ASCII.GetBytes(JsonUtility.ToJson(playerPosition));
        udp.Send(sendBytes, sendBytes.Length);
    }
示例#15
0
    override protected void TriggerPositionUpdate(Vector3 pos, Quaternion ori)
    {
        // Make a temporary copy of the event to avoid possibility of
        // a race condition if the last subscribesr unsubscribes
        // immediately after the null check and before the event is raised.
        PositionUpdate handler = OnPositionUpdate;

        if (handler != null)
        {
            handler(pos, ori);
        }
    }
示例#16
0
        // ToDo: Add information about the aircrafts climbrate and so on, if possible
        internal static PositionUpdate NormalizeData(FlightContext context, PositionUpdate position)
        {
            if (position == null ||
                context.Flight.PositionUpdates.Count < 2 ||
                (!double.IsNaN(position.Heading) && !double.IsNaN(position.Speed)))
            {
                return(position);
            }

            var previousPosition =
                context.Flight.PositionUpdates.LastOrDefault();

            if (previousPosition == null)
            {
                return(position);
            }

            double?heading = null;
            double?speed   = null;

            if (double.IsNaN(position.Heading))
            {
                heading = Geo.DegreeBearing(previousPosition.Location, position.Location);
            }

            if (double.IsNaN(position.Speed))
            {
                // 1. Get the distance (meters)
                // 2. Calculate the time difference (seconds)
                // 3. Convert to knots (1.94384449 is a constant)
                var    distance       = previousPosition.Location.DistanceTo(position.Location);
                double timeDifference = (position.TimeStamp - previousPosition.TimeStamp).Milliseconds;

                if (timeDifference < 50)
                {
                    return(null);
                }

                if (distance != 0)
                {
                    speed = distance / (timeDifference / 1000) * 1.94384449;
                }
                else
                {
                    speed = 0;
                }
            }

            position.Speed   = speed ?? position.Speed;
            position.Heading = heading ?? position.Heading;

            return(position);
        }
示例#17
0
        public virtual void RequestPhysicsPositionUpdate()
        {
            // Make a temporary copy of the event to avoid possibility of
            // a race condition if the last subscriber unsubscribes
            // immediately after the null check and before the event is raised.
            PositionUpdate handler = OnPositionUpdate;

            if (handler != null)
            {
                handler();
            }
        }
示例#18
0
 public void OnPositionUpdatedFromNetwork(PositionUpdate update)
 {
     if (IsLocalPlayer)
     {
         MyLogger.LogWarning("Received position update from server for local player: " + update.Id);
     }
     else
     {
         transform.position = new Vector3(update.X, update.Y, update.Z);
         transform.rotation = Quaternion.Euler(new Vector3(update.RotX, update.RotY, update.RotZ));
     }
 }
示例#19
0
 private void HandlePositionUpdate(PositionUpdate pu)
 {
     List<Entity> entities = pu.entities;
     foreach(Entity entity in entities)
     {
         if(entity.GUID == this.player.GUID)
         {
             this.player.ProcessServerMessage(entity);
         }
         else
         {
             this.ProcessOtherPlayersPositions(entity);
         }
     }
 }
示例#20
0
    /// <summary>
    /// Tells each client handler to send a message to their client containing the new positions of the objects
    /// </summary>
    private void UpdateObjectPositions()
    {
        //TODO: only send velocity updates, only send pos updates when the direction is changed
        Debug.Log(_networkingObjects.Count + " items should be updated");

        foreach (var handler in _clientHandlers)
        {
            foreach (var networkingObject in _networkingObjects)
            {
                Vector3        pos            = networkingObject.transform.position;
                PositionUpdate positionUpdate = new PositionUpdate(pos.x, pos.z, networkingObject.GetNetworkID());
                Debug.Log("Sending the pos update for the object with the ID: " + networkingObject.GetNetworkID());
                handler.SendPacket(positionUpdate.Serialize(), 0);
            }
        }
    }
示例#21
0
        /// <summary>
        /// Applies the <see cref="PositionUpdate"/> to the corresponding <see cref="Marker"/>
        /// in this <see cref="MarkerHolder"/>.
        /// </summary>
        /// <param name="update">The <see cref="PositionUpdate"/>, not null.</param>
        public virtual void OnPositionUpdate(PositionUpdate update)
        {
            Assert.IsNotNull(update);
            T marker = this.GetMarkerOrCreate(update.Id);

            if (update.Type == UpdateType.UpdatePosition)
            {
                marker.RemotePosition = new MarkerPosition(update);
                marker.gameObject.SetActive(true);
            }
            else
            {
                Assert.AreEqual(UpdateType.DeletePosition, update.Type);
                marker.gameObject.SetActive(false);
            }
        }
示例#22
0
    /*
     * Set the position for a non player snake. Does nothing if pos is not valid
     * */
    void UpdateNPSnakePosition(PositionUpdate pos)
    {
        int id = pos.id;

        if (ValidateNPID(id) && CheckUpToDate(id, pos.timestamp))
        {
            float elapsedTime = Math.Abs(GameManager.instance.gameTime - pos.timestamp);

            var expected = GlobalConsts.ClampToRange(pos.position + (pos.direction * 4 * elapsedTime / 1000), new Vector2(25f, 25f));

            lastUpdateTimes[id] = pos.timestamp;

            npTargets[id].position = expected;
            npTargets[id].up       = pos.direction;
        }
    }
    public static ModelInterface ToModel(String networkString)
    {
        ModelInterface mi = null;

        mi = PositionUpdate.ToModel(networkString);
        if (mi != null)
        {
            return(mi);
        }

        if (mi == null)
        {
            Debug.Log("FAILED! FAILED! FAILED! to add new network model: " + networkString);
        }

        return(mi);
    }
示例#24
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MarkerPosition"/> class.
        /// </summary>
        /// <param name="update">The serverUpdate, must be of type UpdatePosition.</param>
        public MarkerPosition(PositionUpdate update)
        {
            if (update == null)
            {
                throw new ArgumentNullException("update");
            }

            if (update.Type != UpdateType.UpdatePosition)
            {
                throw new ArgumentException("UpdateType is not UpdatePosition.", "update");
            }

            this.TimeStamp = DateTime.Now;
            this.Position  = new Vector3(update.Coordinate[0], 0, -update.Coordinate[1]);
            this.Rotation  = Quaternion.Euler(0, update.Rotation, 0);
            this.Scale     = Vector3.one;
            this.ID        = update.Id;
        }
示例#25
0
        /// <summary>
        /// Constructs a correct type of marker for the level.
        /// </summary>
        /// <param name="level">The level GameObject to assign the Marker to.</param>
        /// <param name="properties">The <see cref="LevelProperties"/> object describing the level.</param>
        /// <returns>The constructed marker.</returns>
        private Marker ConstructMarker(GameObject level, LevelProperties properties)
        {
            Vector3 position = new Vector3(
                (this.BoardSize.x - properties.Width) / 2,
                0,
                -(this.BoardSize.y - properties.Height) / 2);

            Debug.Log("Level position: " + position);

            GameObject levelMarker = new GameObject("LevelMarker");

            this.AddBoard(levelMarker);

            if (GameObject.Find("MetaWorld") == null)
            {
                RemoteMarker remoteMarker = levelMarker.AddComponent <RemoteMarker>();
                remoteMarker.Id          = LevelMarkerID;
                remoteMarker.ScaleFactor = 1f;
                GameObject.Find("RemoteController")
                .GetComponent <RemoteMarkerHolder>()
                .AddMarker(remoteMarker as RemoteMarker);
            }
            else
            {
                LocalMarker localMarker = levelMarker.AddComponent <LocalMarker>();
                localMarker.Id = LevelMarkerID;
                GameObject.Find("MetaWorld")
                .GetComponent <LocalMarkerHolder>()
                .AddMarker(localMarker as LocalMarker);
            }

            level.transform.parent        = levelMarker.transform;
            level.transform.localPosition = position;

            Marker marker = levelMarker.GetComponent <Marker>();

            // Simulate a PositionUpdate from the server.
            PositionUpdate update = new PositionUpdate(UpdateType.UpdatePosition, Vector3.zero, 0, LevelMarkerID);

            marker.RemotePosition       = new MarkerPosition(update);
            marker.RemotePosition.Scale = Vector3.one;

            return(marker);
        }
示例#26
0
        private void Config_LogKalmanDataReceived(object sender, LogDataReceivedEventArgs e)
        {
            _firstValueTracked = true;

            _historyVarianceX.Add((float)e.GetVariable("kalman.varPX"));
            _historyVarianceY.Add((float)e.GetVariable("kalman.varPY"));
            _historyVarianceZ.Add((float)e.GetVariable("kalman.varPZ"));

            _historyVarianceX.RemoveAt(0);
            _historyVarianceY.RemoveAt(0);
            _historyVarianceZ.RemoveAt(0);

            VarianceX = CalculatueMax(_historyVarianceX) - CalculatueMin(_historyVarianceX);
            VarianceY = CalculatueMax(_historyVarianceY) - CalculatueMin(_historyVarianceY);
            VarianceZ = CalculatueMax(_historyVarianceZ) - CalculatueMin(_historyVarianceZ);

            CurrentPosition = new Position((float)e.GetVariable("kalman.stateX"), (float)e.GetVariable("kalman.stateY"), (float)e.GetVariable("kalman.stateZ"));
            PositionUpdate?.Invoke(this, new PositionUpdateEventArgs(CurrentPosition));
            _waitForVarianceUpdate.Set();
        }
示例#27
0
    void HandleInboundMessage(UdpMessage message)
    {
        switch (message.Event)
        {
        case "connected": Connected?.Invoke(); break;

        case "position": PositionUpdate?.Invoke(Deserialize <PositionUpdate>(message.Data.ToString())); break;

        case "newplayer": NewPlayer?.Invoke(new Guid(message.Data.ToString())); break;

        case "playerdisconnected": PlayerDisconnected?.Invoke(new Guid(message.Data.ToString())); break;

        case "newnetobj": NewNetObj?.Invoke(Deserialize <NetObj>(message.Data.ToString())); break;

        case "destroynetobj": NetObjDestroyed?.Invoke(new Guid(message.Data.ToString())); break;

        case "owner-changed": OwnerChanged?.Invoke(new Guid(message.Data.ToString())); break;

        default: Debug.LogError("Received invalid inbound message event: " + message.Event); break;
        }
    }
示例#28
0
        override public List <PositionUpdate> GetLowResolutionMovementUpdates()
        {
            List <PositionUpdate> Updates = new List <PositionUpdate>();

            List <byte[]> UpdatePackets = GetPacketsOfType("OP_MobUpdate", PacketDirection.ServerToClient);

            foreach (byte[] MobUpdatePacket in UpdatePackets)
            {
                PositionUpdate PosUpdate = new PositionUpdate();

                ByteStream Buffer = new ByteStream(MobUpdatePacket);

                PosUpdate.SpawnID = Buffer.ReadUInt16();

                UInt32 Word1 = Buffer.ReadUInt32();

                UInt32 Word2 = Buffer.ReadUInt32();

                UInt16 Word3 = Buffer.ReadUInt16();

                PosUpdate.p.y = Utils.EQ19ToFloat((Int32)(Word1 & 0x7FFFF));

                // Z is in the top 13 bits of Word1 and the bottom 6 of Word2

                UInt32 ZPart1 = Word1 >> 19;    // ZPart1 now has low order bits of Z in bottom 13 bits
                UInt32 ZPart2 = Word2 & 0x3F;   // ZPart2 now has low order bits of Z in bottom 6 bits

                ZPart2 = ZPart2 << 13;

                PosUpdate.p.z = Utils.EQ19ToFloat((Int32)(ZPart1 | ZPart2));

                PosUpdate.p.x = Utils.EQ19ToFloat((Int32)(Word2 >> 6) & 0x7FFFF);

                PosUpdate.p.heading = Utils.EQ19ToFloat((Int32)(Word3 & 0xFFF));

                Updates.Add(PosUpdate);
            }

            return(Updates);
        }
示例#29
0
        private async Task UpdatePositionAsync(PositionUpdate source)
        {
            var position = await _context.Positions.SingleOrDefaultAsync(p => p.Id == source.Id);

            if (position == null)
            {
                position = new Position()
                {
                    Id = source.Id
                };
                _context.Positions.Add(position);
            }

            position.Category  = source.Category;
            position.Nickname  = source.Nickname;
            position.Latitude  = source.Latitude;
            position.Longitude = source.Longitude;
            position.Altitude  = source.Altitude;
            position.Timestamp = source.Timestamp;

            position.Heading  = 0;
            position.Accuracy = 0;
            position.Speed    = 0;

            position.History.Add(new DAL.PositionHistory()
            {
                Altitude  = position.Altitude,
                Timestamp = position.Timestamp,
                Latitude  = position.Latitude,
                Longitude = position.Longitude,

                Heading  = 0,
                Accuracy = 0,
                Speed    = 0
            });

            await _context.SaveChangesAsync();
        }
示例#30
0
    public void updatePosition(PositionUpdate update)
    {
        if (!isLoggedIn())
        {
            return;
        }
        this.transform = update;
        //Debug.Log(acc.id + ": " + (Vector3)update.pos);
        if (acc.id != update.affectedPlayer)
        {
            Debug.LogWarning(acc.getName() + " (" + acc.id + ") tried to spoof position update for " + update.affectedPlayer);
            return;
        }

        foreach (Client c in ServerNetworkManager.clients)
        {
            if (!c.isLoggedIn())
            {
                continue;
            }
            c.sendUnreliable(update);
        }
    }
示例#31
0
    private static void receiveUDP(byte[] data)
    {
        try
        {
            //Debug.Log("Received udp from server at " + (tcpClient.Client.RemoteEndPoint as IPEndPoint));
            UDPNetworkMessage message = UDPNetworkMessage.DeserializeObject <UDPNetworkMessage>(data);
            //Debug.Log("UDP Received message of id " + message.getMessageID());
            switch (message.getMessageID())
            {
            case PositionUpdate.ID:
                MainThread.runAction(() =>
                {
                    lock (playersByID)
                    {
                        PositionUpdate posUpdate = (PositionUpdate)message;
                        if (playersByID.ContainsKey(posUpdate.affectedPlayer))
                        {
                            playersByID[posUpdate.affectedPlayer].updatePosition(posUpdate);
                        }
                    }
                });
                break;

            case ChunkData.ID:
                ChunkData chunkData = (ChunkData)message;
                receiveChunk(chunkData);
                break;

            default:
                Debug.LogWarning("Unknown network message with id " + message.getMessageID());
                break;
            }
        }catch (Exception ex)
        {
            Debug.LogError("Error parsing UDP message " + ex);
        }
    }