public Dictionary <int, BotGameLog> ReadAllRows()
        {
            if (connection == null)
            {
                if (!OpenConn())
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("[DatabaseInterface] Failed to open the database connection.");
                    Console.ResetColor();
                    return(null);
                }
            }

            MySqlCommand cmd = connection.CreateCommand();

            cmd.CommandText = $"SELECT * FROM `logs`;";
            MySqlDataReader reader = cmd.ExecuteReader();
            Dictionary <int, BotGameLog> entries = new Dictionary <int, BotGameLog>();

            while (reader.Read())
            {
                BotGameLog log = new BotGameLog(DateTime.FromBinary((long)reader["Date"]), (GameResult)(int)reader["GameResult"], (string)reader["GameType"], (GainPowerResult)(int)reader["GainPowerResult"]);
                entries.Add((int)reader["ID"], log);
            }

            return(entries);
        }
Пример #2
0
        public void GameTickLoop_GameFinished(object sender, GameFinishedEventArgs e)
        {
            StopGame();
            CurrentGame.Gain_Power();
            GainPowerResult result = GainPowerResult.Unknown;

            while (result == GainPowerResult.Unknown || result == GainPowerResult.Pending)
            {
                result = Get_GainPowerResult();
                Thread.Sleep(1000);
            }
            BotGameLog gameLog = new BotGameLog(DateTime.Now, CurrentGame.GameResult, CurrentGame.GetType().Name, result);

            GameLogs.Add(gameLog);
            if (!DatabaseInterface.Write(gameLog))
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("[BotInstance] WARNING: Failed to save the game result log. It will show up in the process memory but will not be stored permanently.");
                Console.ResetColor();
            }
            Console.WriteLine($"[BotInstance] Finished game\nGameResult => {CurrentGame.GameResult}\nGainPowerResult => {result}");
            Thread th = new Thread(new ThreadStart(() =>
            {
                Console.WriteLine("[BotInstance] Queue game start...");
                WebBrowser.Load(@"https://rollercoin.com/game/choose_game");
                Thread.Sleep(TimeSpan.FromMinutes(5));
                Console.WriteLine("[BotInstance] Queue game end...");
                Run();
            }));

            th.IsBackground = true;
            th.Start();
            DestroyGame();
        }
        public bool Write(BotGameLog log)
        {
            if (connection == null)
            {
                if (!OpenConn())
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("[DatabaseInterface] Failed to open the database connection.");
                    Console.ResetColor();
                    return(false);
                }
            }

            MySqlCommand cmd = connection.CreateCommand();

            cmd.CommandText = $"INSERT INTO `logs` (`ID`, `Date`, `GameResult`, `GameType`, `GainPowerResult`) VALUES (NULL, '{log.Date.ToBinary()}', '{(int)log.GameResult}', '{log.GameType}', '{(int)log.GainPowerResult}');";
            cmd.ExecuteNonQuery();
            return(true);
        }