public async Task <MyClasses.Rs3Player> RegisterPlayer(string Username)
        {
            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);
            }
            else
            {
                if (rs3PlayerDB != null)
                {
                    rs3PlayerDB       = new MyClasses.Rs3Player();
                    rs3PlayerDB.Error = "Player \"" + Username + "\" is Already Being Tracked!";
                    return(rs3PlayerDB);
                }
                else
                {
                    MySqlFunctions.InsertIntoDBPlayers(rs3PlayerAPI);
                    return(rs3PlayerAPI);
                }
            }
        }
示例#2
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);
        }
示例#3
0
        public void InsertIntoDBPlayers(MyClasses.Rs3Player rs3Player)
        {
            //New User
            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.Open();
            string query  = "Insert Into " + settings.Rs3PlayerTable + " (Name) VALUES ('" + rs3Player.Name.ToLower() + "')";
            var    cmd    = new MySqlCommand(query, mySqlConnection);
            var    reader = cmd.ExecuteNonQuery();

            mySqlConnection.Close();

            foreach (MyClasses.skillvalues skillvalues in rs3Player.Skillvalues)
            {
                mySqlConnection.Open();
                query = "Insert Into " + settings.Rs3PlayerSkillsTable + " (Username,Name,Level,XP,Rank,ID,SyncTime) " +
                        "VALUES ('" + rs3Player.Name.ToLower() + "','" + skillvalues.Name + "','" + skillvalues.Level + "','" + skillvalues.Xp + "','" + skillvalues.Rank + "','" + skillvalues.ID + "','" + rs3Player.SyncTime + "')";
                cmd    = new MySqlCommand(query, mySqlConnection);
                reader = cmd.ExecuteNonQuery();
                mySqlConnection.Close();
            }
        }
        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);
        }
        public async Task <MyClasses.Rs3Player> GetCurrentStats(string Username)
        {
            MyClasses.Rs3Player rs3PlayerAPI = await Rs3API.GetRs3Player(Username);

            if (rs3PlayerAPI != null)
            {
                return(rs3PlayerAPI);
            }
            else
            {
                rs3PlayerAPI       = new MyClasses.Rs3Player();
                rs3PlayerAPI.Error = "Player \"" + Username + "\" Doesn's Exist in the RS Database!";
                return(rs3PlayerAPI);
            }
        }
示例#6
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);
            }
        }