示例#1
0
        public async Task <bool> RebookSkin()
        {
            if (!IsBooked || !BookingMode || BookingTimeLeft < TimeSpan.FromSeconds(2) || Cars == null)
            {
                return(false);
            }

            var carEntry = SelectedCarEntry;

            if (carEntry == null)
            {
                return(false);
            }

            var correctId = GetCorrectId(carEntry.Id);

            if (correctId == null)
            {
                Logging.Error("Can’t find correct ID");
                return(false);
            }

            PrepareBookingUi();

            var result = await Task.Run(() => KunosApiProvider.TryToBook(Ip, PortHttp, Password, correctId, carEntry.AvailableSkin?.Id,
                                                                         DriverName.GetOnline(), ""));

            if (result?.IsSuccessful != true)
            {
                return(false);
            }

            ProcessBookingResponse(result);
            return(true);
        }
示例#2
0
        private async Task Join(object o)
        {
            var carEntry = SelectedCarEntry;

            if (carEntry == null || Cars == null)
            {
                return;
            }

            var correctId = GetCorrectId(carEntry.Id);

            if (correctId == null)
            {
                Logging.Error("Can’t find correct ID");
                return;
            }

            if (!IsBookedForPlayer && BookingMode && !ReferenceEquals(o, ActualJoin) && !ReferenceEquals(o, ForceJoin))
            {
                if (_factory == null)
                {
                    Logging.Error("Booking: UI factory is missing");
                    return;
                }

                PrepareBookingUi();
                ProcessBookingResponse(await Task.Run(() => KunosApiProvider.TryToBook(Ip, PortHttp, Password, correctId, carEntry.AvailableSkin?.Id,
                                                                                       DriverName.GetOnline(), "")));
                return;
            }

            DisposeHelper.Dispose(ref _ui);
            IsBooked            = false;
            BookingErrorMessage = null;

            var properties = new Game.StartProperties(new Game.BasicProperties {
                CarId                = carEntry.Id,
                CarSkinId            = carEntry.AvailableSkin?.Id,
                TrackId              = Track?.Id,
                TrackConfigurationId = Track?.LayoutId
            }, null, null, null, new Game.OnlineProperties {
                RequestedCar   = correctId,
                ServerIp       = Ip,
                ServerName     = DisplayName,
                ServerPort     = PortRace,
                ServerHttpPort = PortHttp,
                Guid           = SteamIdHelper.Instance.Value,
                Password       = Password
            });

            var now = DateTime.Now;
            await GameWrapper.StartAsync(properties);

            var whatsGoingOn = properties.GetAdditional <WhatsGoingOn>();

            WrongPassword = whatsGoingOn?.Type == WhatsGoingOnType.OnlineWrongPassword;

            if (whatsGoingOn == null)
            {
                LastConnected = now;
                FileBasedOnlineSources.AddRecent(this).Forget();
                UpdateStats();
            }
        }