/// <summary> /// Send new position to the server. /// </summary> /// <param name="newLocation">New position</param> /// <returns>Success?</returns> public async Task <bool> SendPositionUpdateAsync(LatLng newLocation) { var payload = new PositionUpdatePayload(newLocation); TaskCompletionSource <bool> success = new TaskCompletionSource <bool>(); WebSocket.SendAsync(JsonConvert.SerializeObject(new Packet(Intent.PositionUpdate, payload)), b => { success.SetResult(b); }); return(await success.Task); }
public override void OnPacket(Packet packet) { if (packet.Intent != Intent.PositionUpdate) { return; } PositionUpdatePayload positionUpdate = packet.GetPayload <PositionUpdatePayload>(); ServerPlayer player = Connection.RequirePlayer(); // Update position player.Position = positionUpdate.NewPosition; }