示例#1
0
        public Tuple <List <string>, Dictionary <string, EmoteInfo> > GetEmoteInfo()
        {
            string query = "SELECT * FROM emoteinfo";
            Dictionary <string, EmoteInfo> emoteInfo = new Dictionary <string, EmoteInfo>();
            List <string> emoteNames = new List <string>();

            DataTable dataTable = new DataTable();

            //Open connection if none
            if (m_Connection.Ping() == false)
            {
                m_Connection.Open();
            }

            MySqlDataAdapter adapter = new MySqlDataAdapter(query, m_Connection);

            adapter.Fill(dataTable);

            //Go into the datatable that was recieved from the database
            //Take it and put it into an emoteinfo format and add to the dictionary
            foreach (DataRow dataRow in dataTable.Rows)
            {
                EmoteInfo eData = new EmoteInfo(Convert.ToInt32(dataRow[0]), Convert.ToString(dataRow[1]), Convert.ToSingle(dataRow[2]), Convert.ToSingle(dataRow[3]),
                                                Convert.ToSingle(dataRow[4]), Convert.ToSingle(dataRow[5]), Convert.ToSingle(dataRow[6]), Convert.ToSingle(dataRow[7]));

                emoteInfo.Add((string)dataRow[1], eData);

                emoteNames.Add((string)dataRow[1]);
            }

            this.CloseConnection();

            return(Tuple.Create(emoteNames, emoteInfo));
        }
示例#2
0
        private void HandleBuySellCommand(bool aBuying, EmoteInfo aEmoteInfo, float aAmount, OnMessageReceivedArgs e)
        {
            bool val = false;

            if (aAmount <= 0)
            {
                return;
            }

            if (aBuying == true)
            {
                val = m_Database.BuyEmote(aEmoteInfo, aAmount, e.ChatMessage.Username);
            }

            else if (aBuying == false)
            {
                val = m_Database.SellEmote(aEmoteInfo, aAmount, e.ChatMessage.Username);
            }

            if (val == true)
            {
                if (aBuying == true)
                {
                    m_ClientList[e.ChatMessage.Channel].SendMessage(e.ChatMessage.Channel, "@" + e.ChatMessage.Username + ", you have sucessfully bought " + aAmount + " of " + aEmoteInfo.GetName());
                }

                else if (aBuying == false)
                {
                    m_ClientList[e.ChatMessage.Channel].SendMessage(e.ChatMessage.Channel, "@" + e.ChatMessage.Username + ", you have sucessfully sold " + aAmount + " of " + aEmoteInfo.GetName());
                }
            }
        }
示例#3
0
        private void HandleBuySellCommand(bool aBuying, EmoteInfo aEmoteInfo, float aAmount, string aUser, string aChannelName, bool aWhisper)
        {
            bool val = false;

            if (aAmount <= 0)
            {
                return;
            }

            if (aBuying == true)
            {
                val = m_Database.BuyEmote(aEmoteInfo, aAmount, aUser);
            }

            else if (aBuying == false)
            {
                val = m_Database.SellEmote(aEmoteInfo, aAmount, aUser);
            }

            if (val == true)
            {
                if (aBuying == true)
                {
                    //m_ClientList[aChannelName].SendMessage(aChannelName, "@" + aUser + ", you have sucessfully bought " + aAmount + " of " + aEmoteInfo.GetName());
                    if (aWhisper == false)
                    {
                        SendMessageToChatGeneric("@" + aUser + ", you have sucessfully bought " + aAmount + " of " + aEmoteInfo.GetName(), aChannelName);
                    }

                    else if (aWhisper == true)
                    {
                        SendWhisperGeneric("You have sucessfully bought " + aAmount + " of " + aEmoteInfo.GetName(), aUser);
                    }
                }

                else if (aBuying == false)
                {
                    //m_ClientList[aChannelName].SendMessage(aChannelName, "@" + aUser + ", you have sucessfully sold " + aAmount + " of " + aEmoteInfo.GetName());
                    if (aWhisper == false)
                    {
                        SendMessageToChatGeneric("@" + aUser + ", you have sucessfully sold " + aAmount + " of " + aEmoteInfo.GetName(), aChannelName);
                    }

                    else if (aWhisper == true)
                    {
                        SendWhisperGeneric("You have sucessfully sold " + aAmount + " of " + aEmoteInfo.GetName(), aUser);
                    }
                }
            }
        }
示例#4
0
        public void RecordHistory(EmoteInfo aEmoteInfo)
        {
            string query = "INSERT INTO emoterecords VALUES (" + aEmoteInfo.GetID() + ", CURRENT_TIMESTAMP, " + aEmoteInfo.GetValue() + ", " + aEmoteInfo.GetAverage() + ")";

            MySqlCommand cmd = new MySqlCommand(query, m_Connection);

            if (m_Connection.Ping() == false)
            {
                m_Connection.Open();
            }

            cmd.ExecuteNonQuery();

            this.CloseConnection();
            return;
        }
示例#5
0
        public void UploadEmoteValues(EmoteInfo aEmoteInfo)
        {
            string query = "UPDATE emoteinfo SET CurrentValue = " + aEmoteInfo.GetValue() +
                           ", LowestValue = " + aEmoteInfo.GetLowestValue() +
                           ", HighestValue = " + aEmoteInfo.GetHighestValue() +
                           ", AmountBought = " + aEmoteInfo.GetAmountBought() +
                           ", AmountSold = " + aEmoteInfo.GetAmountSold() +
                           ", Average = " + aEmoteInfo.GetAverage() +
                           " WHERE EmoteName = '" + aEmoteInfo.GetName() + "'";

            MySqlCommand cmd = new MySqlCommand(query, m_Connection);

            if (m_Connection.Ping() == false)
            {
                m_Connection.Open();
            }

            cmd.ExecuteNonQuery();

            this.CloseConnection();

            return;
        }
示例#6
0
        public bool SellEmote(EmoteInfo aEmoteInfo, float aAmount, string aUsername)
        {
            //Update the user amount for that emote
            int ID = GetUserID(aUsername);

            string queryEmoteCost = "SELECT CurrentValue FROM emoteinfo WHERE EmoteName = '" + aEmoteInfo.GetName() + "'";
            float  emoteCost      = -1;

            string queryCheckIfEmoteInDB = "SELECT COUNT(EmoteName) FROM emoteinfo WHERE EmoteName = '" + aEmoteInfo.GetName() + "'";

            MySqlCommand cmdCost  = new MySqlCommand(queryEmoteCost, m_Connection);
            MySqlCommand cmdCheck = new MySqlCommand(queryCheckIfEmoteInDB, m_Connection);

            if (m_Connection.Ping() == false)
            {
                m_Connection.Open();
            }

            if (Convert.ToInt32(cmdCheck.ExecuteScalar()) == 0)
            {
                Console.WriteLine("Tried looking for an emote, but it does not exist in the database");
                return(false);
            }

            emoteCost = Convert.ToSingle(cmdCost.ExecuteScalar());

            float userMoney = GetMoney(aUsername);

            //Check if user is even in the database for moneywise
            if (userMoney == -1)
            {
                return(false);
            }

            float totalSellValue;

            totalSellValue = aAmount * aEmoteInfo.GetValue();

            //Check for error
            if (totalSellValue <= 0)
            {
                Console.WriteLine("Error: sell value is less than 0, something went wrong");
                Console.WriteLine("Emote Value: " + aEmoteInfo.GetValue());
                return(false);
            }

            //Check if they have enough in the database
            string       queryCheckSellAmount = "SELECT Amount FROM emotecount WHERE EmoteName = '" + aEmoteInfo.GetName() + "' AND DatabaseUserID = " + ID;
            MySqlCommand cmdGetAmountOfEmote  = new MySqlCommand(queryCheckSellAmount, m_Connection);

            if (m_Connection.Ping() == false)
            {
                m_Connection.Open();
            }

            float emoteAmount = Convert.ToSingle(cmdGetAmountOfEmote.ExecuteScalar());

            if (emoteAmount < aAmount)
            {
                Console.WriteLine("Not enough emotes to sell.");
                this.CloseConnection();
                return(false);
            }

            //Update the amount of that emote that was bought
            aEmoteInfo.SetAmountSold(aEmoteInfo.GetAmountSold() + aAmount);

            userMoney += totalSellValue;

            SetMoney(aUsername, userMoney);

            //Effect market value
            float valueDecrease;

            valueDecrease = aEmoteInfo.GetValue() / totalSellValue;

            aEmoteInfo.SetValue(aEmoteInfo.GetValue() - valueDecrease);

            if (m_Connection.Ping() == false)
            {
                m_Connection.Open();
            }

            string       queryUpdateUserAmount  = "UPDATE emotecount SET Amount = Amount - " + aAmount + " WHERE EmoteName = '" + aEmoteInfo.GetName() + "' AND DatabaseUserID = " + ID;
            MySqlCommand cmdUpdateUserEmoteData = new MySqlCommand(queryUpdateUserAmount, m_Connection);

            cmdUpdateUserEmoteData.ExecuteNonQuery();

            this.CloseConnection();

            return(true);
        }
示例#7
0
        public bool BuyEmote(EmoteInfo aEmoteInfo, float aAmount, string aUsername)
        {
            string queryEmoteCost = "SELECT CurrentValue FROM emoteinfo WHERE EmoteName = '" + aEmoteInfo.GetName() + "'";
            float  emoteCost      = -1;

            string queryCheckIfEmoteInDB = "SELECT COUNT(EmoteName) FROM emoteinfo WHERE EmoteName = '" + aEmoteInfo.GetName() + "'";

            MySqlCommand cmdCost  = new MySqlCommand(queryEmoteCost, m_Connection);
            MySqlCommand cmdCheck = new MySqlCommand(queryCheckIfEmoteInDB, m_Connection);

            if (m_Connection.Ping() == false)
            {
                m_Connection.Open();
            }

            if (Convert.ToInt32(cmdCheck.ExecuteScalar()) == 0)
            {
                Console.WriteLine("Tried looking for an emote, but it does not exist in the database");
                return(false);
            }

            emoteCost = Convert.ToSingle(cmdCost.ExecuteScalar());

            float userMoney = GetMoney(aUsername);

            //Check if user is even in the database for moneywise
            if (userMoney == -1)
            {
                return(false);
            }

            float totalCost;

            totalCost = aAmount * aEmoteInfo.GetValue();

            //Check for error
            if (totalCost <= 0)
            {
                Console.WriteLine("Error: total cost is less than 0, something went wrong");
                Console.WriteLine("Emote Value: " + aEmoteInfo.GetValue());
                return(false);
            }

            //Check if user has enough money to buy that amount
            if (totalCost > userMoney)
            {
                Console.WriteLine("User does not have enough money to buy the amount they want");
                Console.WriteLine("Total Cost: " + totalCost + " UserMoney: " + userMoney);
                return(false);
            }

            //Update the amount of that emote that was bought
            aEmoteInfo.SetAmountBought(aEmoteInfo.GetAmountBought() + aAmount);

            userMoney -= totalCost;
            userMoney *= -1;

            SetMoney(aUsername, userMoney);

            //Effect market value
            float valueIncrease;

            valueIncrease = aEmoteInfo.GetValue() / totalCost;

            aEmoteInfo.SetValue(aEmoteInfo.GetValue() + valueIncrease);

            //Update the user amount for that emote

            int ID = GetUserID(aUsername);

            //Make a query to check if we need to put that emote into the db for that user

            string       queryCheckIfInEmoteCount = "SELECT COUNT(*) FROM emotecount WHERE EmoteName = '" + aEmoteInfo.GetName() + "' AND DatabaseUserID = " + ID;
            MySqlCommand cmdCheckEmoteCount       = new MySqlCommand(queryCheckIfInEmoteCount, m_Connection);

            if (m_Connection.Ping() == false)
            {
                m_Connection.Open();
            }

            if (Convert.ToInt32(cmdCheckEmoteCount.ExecuteScalar()) == 0)
            {
                /*
                 * string queryUpdateEmoteCount = "INSERT INTO emotecount VALUES ('" + aEmoteInfo.GetName() + "', " + ID + ", 0)";
                 * MySqlCommand cmdUpdateEmoteCount = new MySqlCommand(queryUpdateEmoteCount, m_Connection);
                 *
                 * cmdUpdateEmoteCount.ExecuteNonQuery();
                 */

                this.AddToEmoteCount(aUsername, aEmoteInfo.GetName());
            }

            if (m_Connection.Ping() == false)
            {
                m_Connection.Open();
            }

            string       updateUserAmount       = "UPDATE emotecount SET Amount = Amount + " + aAmount + " WHERE EmoteName = '" + aEmoteInfo.GetName() + "' AND DatabaseUserID = " + ID;
            MySqlCommand cmdUpdateUserEmoteData = new MySqlCommand(updateUserAmount, m_Connection);

            cmdUpdateUserEmoteData.ExecuteNonQuery();

            this.CloseConnection();
            return(true);
        }