private Task TryGameLoginAsync(string username, string password)
        {
            return(Task.Run(
                       async() =>
            {
                for (var i = 0; i < 5; ++i)
                {
                    if (this.AppState == EAppState.ManuallyStopped)
                    {
                        return;
                    }

                    this.AppState = EAppState.WaitingForLogin;

                    try
                    {
                        this.api.TryLoginAsync(username, password).Wait();
                        this.AppState = EAppState.Ready;
                        break;
                    }
                    catch (Exception)
                    {
                        // ignored
                        this.AppState = EAppState.LoginFailed;
                        await Task.Delay(1000);
                    }
                }
            }));
        }
Example #2
0
    void Update()
    {
        if (eNextAppState != appState.State)
        {
            if (eNextAppState == EAppState.None)
            {
                Application.Quit();
                return;
            }
            else
            {
                if (appState != null)
                {
                    appState.OnExit();
                }

                appState      = AppStateFactory.Create(eNextAppState);
                eNextAppState = appState.State;
                appState.OnEnter();
            }
        }

        eNextAppState = appState.OnUpdate();

        UIManager.I.Update();
    }
Example #3
0
        internal void Add(UInt32 id, EAppState state = EAppState.k_EAppStateInvalid)
        {
            if (GetAppById(id) != null)
            {
                return;
            }

            var app = new App(_steam, id, state);

            _list.Add(app);
        }
Example #4
0
    public static IAppState Create(EAppState state)
    {
        switch (state)
        {
        case EAppState.GameRun:
            return(new GameRunState());

        case EAppState.HotFix:
            return(new HotFixState());

        default:
            return(null);
        }
    }
Example #5
0
        internal App(Steam steam, UInt32 id, EAppState state = EAppState.k_EAppStateInvalid)
        {
            _log = LogManager.GetLogger(this);

            _steam = steam;
            Id     = id;
            State  = state;

            _isGame = true;

            if (_steam.GetAppData(Id, "state") == "eStateTool" ||
                !string.IsNullOrEmpty(_steam.GetAppData(Id, "DLCForAppID")) ||
                _steam.GetAppData(Id, "IsMediaFile") == "1")
            {
                _isGame = false;
            }

            _log.DebugFormat("New app created with id {0} ({1}) and state {2}, installed == {3}, playable == {4}", Id, Name, State, Installed, Playable);
        }
Example #6
0
 void Start()
 {
     appState      = AppStateFactory.Create(EAppState.GameRun);
     eNextAppState = appState.State;
     appState.OnEnter();
 }
        private Task TryGameLoginAsync(StarSonataApi ssApi, DiscordApi discordApi, Settings settings)
        {
            return(Task.Run(
                       async() =>
            {
                var connected = false;
                var semaphoreEntered = false;
                try
                {
                    semaphoreEntered = await this.loginSemaphore.WaitAsync(0).ConfigureAwait(false);
                    if (semaphoreEntered)
                    {
                        for (var i = 0; i < 10; ++i)
                        {
                            if (this.AppState == EAppState.ManuallyStopped)
                            {
                                return;
                            }

                            this.AppState = EAppState.WaitingForLogin;

                            try
                            {
                                ssApi.TryLoginAsync(settings.GameUsername, settings.GamePassword).Wait();
                            }
                            catch (Exception)
                            {
                                // ignored
                            }

                            if (!ssApi.IsConnected)
                            {
                                lock (this)
                                {
                                    this.lastError = DateTime.Now;
                                }

                                discordApi.SendMessageAsync(
                                    settings.ErrorChannel,
                                    $"Error: Login attempt {i + 1} of 10 failed. Trying again in 30 seconds.")
                                .Forget();
                                Task.Delay(TimeSpan.FromSeconds(1)).Wait();
                            }
                            else
                            {
                                connected = true;
                                if (this.AppState == EAppState.ManuallyStopped)
                                {
                                    this.PreStoppedState = EAppState.Ready;
                                }
                                else
                                {
                                    this.AppState = EAppState.Ready;
                                }

                                break;
                            }
                        }

                        if (!connected)
                        {
                            lock (this)
                            {
                                this.lastError = DateTime.Now;
                            }

                            await discordApi.SendMessageAsync(
                                settings.ErrorChannel,
                                "Error: Was unable to establish a connection. Will retry in 5 minutes")
                            .ConfigureAwait(false);
                            Task.Delay(TimeSpan.FromMinutes(0.1)).ContinueWith(
                                t => { this.TryGameLoginAsync(ssApi, discordApi, settings).Forget(); })
                            .Forget();
                        }
                    }
                }
                finally
                {
                    if (semaphoreEntered)
                    {
                        this.loginSemaphore.Release();
                    }
                }
            }));
        }
        private void HandleCommands(Settings settings, DiscordApi discordApi, StarSonataApi ssApi, string commandText)
        {
            if (commandText.Equals("!wtfkill", StringComparison.OrdinalIgnoreCase))
            {
                discordApi.SendMessageAsync(settings.CommandChannel, "`:( Okay`", true).Forget();
                Thread.Sleep(1000);
                Environment.Exit(-1);
            }

            if (commandText.Equals("!kill", StringComparison.OrdinalIgnoreCase))
            {
                discordApi.MessagingDisabled = true;
                this.PreStoppedState         = this.AppState;
                this.AppState = EAppState.ManuallyStopped;
                discordApi.SendMessageAsync(settings.CommandChannel, "`Processing stopped`", true).Forget();
            }

            if (commandText.Equals("!continue", StringComparison.OrdinalIgnoreCase) &&
                this.AppState == EAppState.ManuallyStopped)
            {
                discordApi.MessagingDisabled = false;
                this.AppState = this.PreStoppedState;
                discordApi.SendMessageAsync(settings.CommandChannel, "`Processing started`", true).Forget();
                if (this.AppState == EAppState.WaitingForLogin)
                {
                    this.TryGameLoginAsync(ssApi, discordApi, settings).Forget();
                }
            }

            if (commandText.Equals("!help"))
            {
                var eb = new EmbedBuilder();
                eb.WithTitle("Commands");
                eb.AddInlineField("!status", "Returns the current bot status.");
                eb.AddInlineField("!kill", "Stop processing. Use this if the bot is messing up.");
                eb.AddInlineField("!continue", "Continue processing. Use this to continue after a !kill command.");
                eb.AddInlineField(
                    "!wtfkill",
                    "Will kill the bots process. Only use this if !kill doesn't work no one is around who can fix it.");
                discordApi.EmbedObjectAsync(settings.CommandChannel, eb.Build(), true).Forget();
            }

            if (commandText.Equals("!status"))
            {
                var eb = new EmbedBuilder();
                eb.WithTitle("Bot Status");
                eb.AddInlineField("Status", this.AppState.ToString());
                eb.AddInlineField("Uptime", (DateTime.Now - this.startTime).ToPrettyFormat());
                lock (this)
                {
                    if (this.lastError.HasValue)
                    {
                        eb.AddInlineField(
                            "Last Error",
                            (DateTime.Now - this.lastError.Value).ToPrettyFormat() + " ago");
                    }
                }

                discordApi.EmbedObjectAsync(settings.CommandChannel, eb.Build(), true).Forget();
            }
        }
 public bool GetAppStateInfo(UInt32 unAppID, ref EAppReleaseState peReleaseState, ref EAppOwernshipFlags peOwernshipFlags, ref EAppState peAppState)
 {
     return(this.GetFunction <NativeGetAppStateInfoUEEE>(this.Functions.GetAppStateInfo41)(this.ObjectAddress, unAppID, ref peReleaseState, ref peOwernshipFlags, ref peAppState));
 }
Example #10
0
    public EAppState OnUpdate()
    {
        EAppState appState = EAppState.HotFix;

        if (NextHotFixPipeline != HotFixSystem.I.HotFixPipeline)
        {
            HotFixSystem.I.HotFixPipeline = NextHotFixPipeline;

            switch (HotFixSystem.I.HotFixPipeline)
            {
            case EHotFixPipeline.CheckBuildVersion:
                CoroutineUtil.I.StartCoroutine(CheckBuildVersionCoroutine());
                break;

            case EHotFixPipeline.InitAssets:
                CoroutineUtil.I.StartCoroutine(InitAssets());
                break;

            case EHotFixPipeline.CheckAssetsList:
                CoroutineUtil.I.StartCoroutine(CheckAssetsListCoroutine());
                break;

            case EHotFixPipeline.WaitUserConfirm:
                HotFixSystem.I.UserConfirm = false;
                break;

            case EHotFixPipeline.FixAssets:
                RecodeTime      = 0;
                downloadedBytes = 0;
                CoroutineUtil.I.StartCoroutine(DownLoadZip());
                CoroutineUtil.I.StartCoroutine(Unzip());
                break;

            case EHotFixPipeline.Success:
                appState = EAppState.GameRun;
                break;

            case EHotFixPipeline.FixBuild:
            case EHotFixPipeline.Fail:
            case EHotFixPipeline.FailRemote:
                if (VersionHelper.StreamingVersion == null || VersionHelper.StreamingVersion.BuildType.Equals("develop"))
                {
                    appState = EAppState.GameRun;
                }
                break;

            default:
                break;
            }
        }

        if (HotFixSystem.I.HotFixPipeline == EHotFixPipeline.WaitUserConfirm)
        {
            if (HotFixSystem.I.UserConfirm)
            {
                NextHotFixPipeline = EHotFixPipeline.FixAssets;
            }
        }

        if (HttpReq != null)
        {
            HotFixSystem.I.HotFixSize = HotFixSystem.I.HotFixFullSize + HttpReq.downloadedBytes;
            RecodeTime += Time.unscaledDeltaTime;
            if (RecodeTime >= 0.5f)
            {
                HotFixSystem.I.DownloadSpeed = (ulong)((double)(HotFixSystem.I.HotFixSize - downloadedBytes) / (double)RecodeTime);
                downloadedBytes = HotFixSystem.I.HotFixSize;
                RecodeTime      = 0;
            }
        }

        return(appState);
    }
 public bool GetAppStateInfo(UInt32 unAppID, ref EAppReleaseState peReleaseState, ref EAppOwnershipFlags peOwnershipFlags, ref EAppState peAppState, ref CSteamID pSteamID)
 {
     UInt64 s0 = 0; var result = this.GetFunction <NativeGetAppStateInfoUEEEC>(this.Functions.GetAppStateInfo49)(this.ObjectAddress, unAppID, ref peReleaseState, ref peOwnershipFlags, ref peAppState, ref s0); pSteamID = new CSteamID(s0); return(result);
 }