Beispiel #1
0
        public MyClasses.Rs3Player GetRs3PlayerGainz(string name)
        {
            var             mysqlSettings    = settings.GetMySqlSettings();
            string          connectionString = string.Format("Server={0}; database={1}; UID={2}; password={3}", mysqlSettings.ip, mysqlSettings.database, mysqlSettings.username, mysqlSettings.password);
            MySqlConnection mySqlConnection  = new MySqlConnection(connectionString);

            MyClasses.Rs3Player rs3Player = new MyClasses.Rs3Player();
            rs3Player.Skillvalues = new List <MyClasses.skillvalues>();
            MySqlConnection mySqlConnection2 = new MySqlConnection(connectionString);

            mySqlConnection2.Open();
            string query  = "SELECT ID,Level,Name,Rank,Xp,Username,SyncTime FROM " + settings.Rs3PlayerSkillGainzTable + " WHERE username = '******'";
            var    cmd    = new MySqlCommand(query, mySqlConnection2);
            var    reader = cmd.ExecuteReader();

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    MyClasses.skillvalues skillvalues = new MyClasses.skillvalues();
                    skillvalues.ID     = Convert.ToInt32(reader.GetString(0));
                    skillvalues.Level  = Convert.ToInt16(reader.GetString(1));
                    skillvalues.Name   = reader.GetString(2);
                    skillvalues.Rank   = Convert.ToInt64(reader.GetString(3));
                    skillvalues.Xp     = Convert.ToInt32(reader.GetString(4));
                    rs3Player.Name     = reader.GetString(5);
                    rs3Player.SyncTime = reader.GetString(6);
                    rs3Player.Skillvalues.Add(skillvalues);
                }
                mySqlConnection2.Close();
                return(rs3Player);
            }
            mySqlConnection.Close();
            return(null);
        }
        public async Task <MyClasses.Rs3Player> Calculate(string Username)
        {
            //needs complete rework, change input to take in the Rs3player classes instead of username string

            MyClasses.Rs3Player rs3PlayerAPI = await Rs3API.GetRs3Player(Username);

            MyClasses.Rs3Player rs3PlayerDB = MySqlFunctions.GetRs3PlayerDB(Username);
            if (rs3PlayerAPI == null)
            {
                rs3PlayerAPI       = new MyClasses.Rs3Player();
                rs3PlayerAPI.Error = "Player \"" + Username + "\" Doesn's Exist in the RS Database!";
                return(rs3PlayerAPI);
            }
            if (rs3PlayerDB == null)
            {
                //New User Add him to DB
                //MySqlFunctions.InsertIntoDBPlayers(rs3PlayerAPI, true);
                rs3PlayerDB       = new MyClasses.Rs3Player();
                rs3PlayerDB.Error = "Player \"" + Username + "\" Doesn's Exist in the Bot Database!";
                return(rs3PlayerDB);
            }
            MySqlFunctions.InsertIntoDBPlayers(rs3PlayerAPI);


            MyClasses.Rs3Player rs3PlayerGainzInsert = new MyClasses.Rs3Player();
            rs3PlayerGainzInsert.Name        = Username;
            rs3PlayerGainzInsert.Skillvalues = new List <MyClasses.skillvalues>();
            //old user Calculate and Update Info
            foreach (MyClasses.skillvalues skillvaluesAPI in rs3PlayerAPI.Skillvalues)
            {
                foreach (MyClasses.skillvalues skillvaluesDB in rs3PlayerDB.Skillvalues)
                {
                    if (skillvaluesAPI.ID == skillvaluesDB.ID)
                    {
                        MyClasses.skillvalues skillvaluesGainz = new MyClasses.skillvalues();
                        skillvaluesGainz    = skillvaluesDB;
                        skillvaluesGainz.Xp = skillvaluesAPI.Xp - skillvaluesDB.Xp;
                        rs3PlayerGainzInsert.Skillvalues.Add(skillvaluesGainz);
                    }
                }
            }
            rs3PlayerGainzInsert.SyncTime = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss");
            MySqlFunctions.InsertIntoDBPlayerGainz(rs3PlayerGainzInsert);

            MyClasses.Rs3Player rs3PlayerGainz = new MyClasses.Rs3Player();
            rs3PlayerGainz = MySqlFunctions.GetRs3PlayerGainz(Username);

            return(rs3PlayerGainz);
        }
Beispiel #3
0
        public MyClasses.Rs3Player GetRs3PlayerDBSince(string name, string since)
        {
            var             mysqlSettings    = settings.GetMySqlSettings();
            string          connectionString = string.Format("Server={0}; database={1}; UID={2}; password={3}", mysqlSettings.ip, mysqlSettings.database, mysqlSettings.username, mysqlSettings.password);
            MySqlConnection mySqlConnection  = new MySqlConnection(connectionString);

            mySqlConnection.Close();
            mySqlConnection.Open();
            string query  = "SELECT ID,Level,name,Rank,Xp,SyncTime FROM " + settings.Rs3PlayerSkillsTable + " WHERE Username='******' And SyncTime Like '" + since + "%' order by SyncTime Desc";
            var    cmd    = new MySqlCommand(query, mySqlConnection);
            var    reader = cmd.ExecuteReader();

            if (reader.HasRows)
            {
                MyClasses.Rs3Player rs3Player = new MyClasses.Rs3Player();
                rs3Player.Name        = name;
                rs3Player.Skillvalues = new List <MyClasses.skillvalues>();

                while (reader.Read())
                {
                    MyClasses.skillvalues skillvalues = new MyClasses.skillvalues();
                    skillvalues.ID    = Convert.ToInt32(reader.GetString(0));
                    skillvalues.Level = Convert.ToInt16(reader.GetString(1));
                    skillvalues.Name  = reader.GetString(2);
                    skillvalues.Rank  = Convert.ToInt64(reader.GetString(3));
                    skillvalues.Xp    = Convert.ToInt64(reader.GetString(4));
                    rs3Player.Skillvalues.Add(skillvalues);
                    rs3Player.SyncTime = reader.GetString(5);
                    if (skillvalues.ID == 28)
                    {
                        break;
                    }
                }
                mySqlConnection.Close();
                return(rs3Player);
            }
            else
            {
                MyClasses.Rs3Player rs3Player = new MyClasses.Rs3Player();
                rs3Player.Error = "No Data Available For The Requested Date (" + since + ")";
                mySqlConnection.Close();
                return(rs3Player);
            }
        }