Пример #1
0
        public override void OnMessage(string message, EChatEntryType type)
        {
            if (IsAdmin)
            {
                //creating a new trade offer
                var offer = Bot.NewTradeOffer(OtherSID);

                //offer.Items.AddMyItem(0, 0, 0);
                if (offer.Items.NewVersion)
                {
                    string newOfferId;
                    if (offer.Send(out newOfferId))
                    {
                        Bot.AcceptAllMobileTradeConfirmations();
                        Log.Success("Trade offer sent : Offer ID " + newOfferId);
                    }
                }

                //creating a new trade offer with token
                var offerWithToken = Bot.NewTradeOffer(OtherSID);

                //offer.Items.AddMyItem(0, 0, 0);
                if (offerWithToken.Items.NewVersion)
                {
                    string newOfferId;
                    // "token" should be replaced with the actual token from the other user
                    if (offerWithToken.SendWithToken(out newOfferId, "token"))
                    {
                        Bot.AcceptAllMobileTradeConfirmations();
                        Log.Success("Trade offer sent : Offer ID " + newOfferId);
                    }
                }
            }
        }
Пример #2
0
        public override void OnTradeOfferUpdated(TradeOffer offer)
        {
            switch (offer.OfferState)
            {
            case TradeOfferState.TradeOfferStateAccepted:
                Log.Info($"Trade offer {offer.TradeOfferId} has been completed!");
                //SendChatMessage("Trade completed, thank you!");
                break;

            case TradeOfferState.TradeOfferStateActive:
                if (IsAdmin)
                {
                    offer.Accept();
                    Bot.AcceptAllMobileTradeConfirmations();
                    SendChatMessage("Accepted admin tradeoffer");
                }
                break;

            case TradeOfferState.TradeOfferStateNeedsConfirmation:
            case TradeOfferState.TradeOfferStateInEscrow:
                //Trade is still active but incomplete
                break;

            case TradeOfferState.TradeOfferStateCountered:
                Log.Info($"Trade offer {offer.TradeOfferId} was countered");
                break;

            default:
                Log.Info($"Trade offer {offer.TradeOfferId} failed");
                break;
            }
        }
Пример #3
0
        public override void OnNewTradeOffer(TradeOffer offer)
        {
            if (IsAdmin)
            {
                Log.Info("New Tradeoffer from admin! Accepting and confirming.");
                //Make this log something somewhere that tells us the trade value of outgoing items.
                offer.Accept();
                Bot.AcceptAllMobileTradeConfirmations();
            }
            else
            {
                string password = System.IO.File.ReadAllText(@"../cstrade_admin_password.txt");
                string postData = "password="******"&other_steam_id=" + OtherSID.ConvertToUInt64();

                string url           = "http://skinbonanza.com/backend/check_bot.php";
                var    updaterequest = (HttpWebRequest)WebRequest.Create(url);

                var data = Encoding.ASCII.GetBytes(postData);

                updaterequest.Method        = "POST";
                updaterequest.ContentType   = "application/x-www-form-urlencoded";
                updaterequest.ContentLength = data.Length;

                using (var stream = updaterequest.GetRequestStream()) {
                    stream.Write(data, 0, data.Length);
                }

                for (int attempts = 0;; attempts++)
                {
                    try
                    {
                        var response       = (HttpWebResponse)updaterequest.GetResponse();
                        var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
                        if (responseString.Contains("success"))
                        {
                            Log.Success("Confirming trade from fellow bot.");
                            offer.Accept();
                            Bot.AcceptAllMobileTradeConfirmations();
                        }
                        break;
                    } catch (Exception e) {
                        Log.Error(e.Message);
                        if (attempts > 4)
                        {
                            offer.Decline();
                            throw e;
                        }
                    }
                }
            }
        }
Пример #4
0
        public override void OnNewTradeOffer(TradeOffer offer)
        {
            //receiving a trade offer
            if (IsAdmin)
            {
                //parse inventories of bot and other partner
                //either with webapi or generic inventory
                //Bot.GetInventory();
                //Bot.GetOtherInventory(OtherSID);

                var myItems    = offer.Items.GetMyItems();
                var theirItems = offer.Items.GetTheirItems();
                Log.Info("They want " + myItems.Count + " of my items.");
                Log.Info("And I will get " + theirItems.Count + " of their items.");

                //do validation logic etc
                if (DummyValidation(myItems, theirItems))
                {
                    string tradeid;
                    if (offer.Accept(out tradeid))
                    {
                        Bot.AcceptAllMobileTradeConfirmations();
                        Log.Success("Accepted trade offer successfully : Trade ID: " + tradeid);
                    }
                }
                else
                {
                    // maybe we want different items or something

                    //offer.Items.AddMyItem(0, 0, 0);
                    //offer.Items.RemoveTheirItem(0, 0, 0);
                    if (offer.Items.NewVersion)
                    {
                        string newOfferId;
                        string tradeError;
                        if (offer.CounterOffer(out newOfferId, out tradeError))
                        {
                            Bot.AcceptAllMobileTradeConfirmations();
                            Log.Success("Counter offered successfully : New Offer ID: " + newOfferId);
                        }
                    }
                }
            }
            else
            {
                //we don't know this user so we can decline
                if (offer.Decline())
                {
                    Log.Info("Declined trade offer : " + offer.TradeOfferId + " from untrusted user " + OtherSID.ConvertToUInt64());
                }
            }
        }
Пример #5
0
        public void _OnTradeAwaitingConfirmation(long tradeOfferID)
        {
            Bot.AcceptAllMobileTradeConfirmations();
            TradeOffer tradeOffer;

            if (Bot.TryGetTradeOffer(tradeOfferID.ToString(), out tradeOffer))
            {
                if (tradeOffer.OfferState == TradeOfferState.TradeOfferStateNeedsConfirmation)
                {
                    OnTradeAwaitingConfirmation(tradeOfferID);
                }
            }
        }
Пример #6
0
 public void _OnTradeAwaitingConfirmation(long tradeOfferID)
 {
     Bot.AcceptAllMobileTradeConfirmations();
     OnTradeAwaitingConfirmation(tradeOfferID);
 }
Пример #7
0
        private void OnNewTradeOffer(TradeOffer offer)
        {
            var myItems    = offer.Items.GetMyItems();
            var theirItems = offer.Items.GetTheirItems();

            if (myItems.Count == 0)
            {
                offer.Accept();
                Bot.SteamFriends.SendChatMessage(ownerID, EChatEntryType.ChatMsg, "I received a donation offer!");
                Bot.AcceptAllMobileTradeConfirmations();
                Log.Success("Received a donation-offer");
            }
            else
            {
                Bot.TradeOfferEscrowDuration CurrentEscrow = Bot.GetEscrowDuration(offer.TradeOfferId);

                //Check if trader has delayed trades
                if (CurrentEscrow.DaysTheirEscrow > 2)
                {
                    Log.Error("Trade offer has been declined due to escrow.");
                    Bot.SteamFriends.SendChatMessage(ownerID, EChatEntryType.ChatMsg, "Incoming trade offer has been declined due to escrow.");
                    offer.Decline();
                }
                else
                {
                    List <long> contextId = new List <long>();
                    contextId.Add(2);
                    contextId.Add(6);

                    mySteamInventory.load(440, contextId, Bot.SteamClient.SteamID);
                    OtherSteamInventory.load(440, contextId, offer.PartnerSteamId);

                    int MyRef = 0;
                    int MyKey = 0;

                    int TheirRef = 0;
                    int TheirKey = 0;

                    #region User
                    for (int count = 0; count < theirItems.Count; count++)
                    {
                        if (theirItems[count].AppId == 440)
                        {
                            if (OtherSteamInventory.getDescription((ulong)theirItems[count].AssetId).name == "Scrap Metal")
                            {
                                TheirRef += 1;
                            }
                            else if (OtherSteamInventory.getDescription((ulong)theirItems[count].AssetId).name == "Reclaimed Metal")
                            {
                                TheirRef += 3;
                            }
                            else if (OtherSteamInventory.getDescription((ulong)theirItems[count].AssetId).name == "Refined Metal")
                            {
                                TheirRef += 9;
                            }
                            else if (OtherSteamInventory.getDescription((ulong)theirItems[count].AssetId).name == "Mann Co. Supply Crate Key")
                            {
                                TheirKey++;
                            }
                        }
                    }
                    #endregion
                    #region Bot
                    for (int count = 0; count < myItems.Count; count++)
                    {
                        if (mySteamInventory.getDescription((ulong)myItems[count].AssetId).name == "Scrap Metal")
                        {
                            MyRef += 1;
                        }
                        else if (mySteamInventory.getDescription((ulong)myItems[count].AssetId).name == "Reclaimed Metal")
                        {
                            MyRef += 3;
                        }
                        else if (mySteamInventory.getDescription((ulong)myItems[count].AssetId).name == "Refined Metal")
                        {
                            MyRef += 9;
                        }
                        else if (mySteamInventory.getDescription((ulong)myItems[count].AssetId).name == "Mann Co. Supply Crate Key")
                        {
                            MyRef += 9;
                        }
                    }
                    #endregion
                    #region Calculate
                    Console.Write(" - TheirKey: " + TheirKey);
                    Console.Write(" - Buyprice: " + buyPrice);
                    Console.WriteLine(" - MyRef: " + MyRef);
                    Console.Write(" - MyKey: " + MyKey);
                    Console.Write(" - SellPrice: " + sellPrice);
                    Console.WriteLine(" - TheirRef: " + TheirRef);
                    if (((TheirKey * buyPrice) == MyRef) && ((MyKey * sellPrice) == TheirRef))
                    {
                        Log.Success("[#" + offer.TradeOfferId + "] Accepted Offer.");
                        offer.Accept();
                        Bot.AcceptAllMobileTradeConfirmations();
                        Bot.SteamFriends.SendChatMessage(ownerID, EChatEntryType.ChatMsg, "I've done a succesful offer with " + Bot.SteamFriends.GetFriendPersonaName(offer.PartnerSteamId) + ".");
                    }
                    else if (IsAdmin)
                    {
                        string tradeid;
                        offer.Accept(out tradeid);
                        Log.Success("[ADMINOFFER] Accepted trade offer successfully : Trade ID: " + tradeid);
                        Bot.AcceptAllMobileTradeConfirmations();
                    }
                    else
                    {
                        Log.Success("[#" + offer.TradeOfferId + "] Declined Offer.");
                        offer.Decline();
                        Bot.AcceptAllMobileTradeConfirmations();
                    }
                    #endregion
                }
            }
        }
Пример #8
0
        public override void OnMessage(string message, EChatEntryType type)
        {
            message = message.ToLower();
            Log.Success(Bot.SteamFriends.GetFriendPersonaName(OtherSID) + " : " + message);
            Bot.SteamFriends.SendChatMessage(ownerID, EChatEntryType.ChatMsg, Bot.SteamFriends.GetFriendPersonaName(OtherSID) + " : " + message);
            #region Buy
            if (message.StartsWith("!buy"))
            {
                if (message == "!buy")
                {
                    SendChatMessage("You have to put a amount in. Ex: !buy 2 for buying 2 keys.");
                }
                else
                {
                    bool notEnough = false;
                    SendChatMessage("Your request will be dealt with shortly.");
                    int amount = 0;

                    if (message.Substring(6) == "x")
                    {
                        amount = 0;
                        SendChatMessage("You didn't enter a number. Ex: !buy 2 for buying 2 keys.");
                    }
                    else
                    {
                        try
                        {
                            amount = int.Parse(message.Substring(5));
                        }
                        catch
                        {
                            SendChatMessage("You didn't put a valid number in. Example: !buy 2 for buying 2 keys");
                        }
                    }
                    // Check if the user has escrow.
                    if (Bot.GetEscrowDuration(new SteamID(OtherSID), "").DaysTheirEscrow > 2)
                    {
                        SendChatMessage("Sorry, You require to have an account with a valid Phone Authenticator.");
                    }
                    else
                    {
                        // Bot adds keys. User adds metal.

                        List <long> contextId = new List <long>();
                        contextId.Add(2);
                        contextId.Add(6);

                        mySteamInventory.load(440, contextId, Bot.SteamClient.SteamID);
                        OtherSteamInventory.load(440, contextId, OtherSID);

                        #region User-part
                        //Checking users stock.
                        int UserRefCount   = 0;
                        int UserRecCount   = 0;
                        int UserScrapCount = 0;
                        int KeysInStock    = 0;
                        foreach (GenericInventory.Item item in OtherSteamInventory.items.Values)
                        {
                            if (OtherSteamInventory.getDescription(item.assetid).name == "Refined Metal" && OtherSteamInventory.getDescription(item.assetid).tradable)
                            {
                                UserRefCount++;
                            }
                            else if (OtherSteamInventory.getDescription(item.assetid).name == "Reclaimed Metal" && OtherSteamInventory.getDescription(item.assetid).tradable)
                            {
                                UserRecCount++;
                            }
                            else if (OtherSteamInventory.getDescription(item.assetid).name == "Scrap Metal" && OtherSteamInventory.getDescription(item.assetid).tradable)
                            {
                                UserScrapCount++;
                            }
                        }

                        int     MetalRequired       = amount * sellPrice;
                        int     OfferChangeRequired = 0;
                        decimal RefRequired         = Math.Floor((decimal)MetalRequired / 9);
                        if (UserRefCount < RefRequired)
                        {
                            RefRequired = UserRefCount;
                        }
                        decimal metalRequiredR = MetalRequired - (RefRequired * 9);
                        decimal RecRequired    = Math.Floor((decimal)metalRequiredR / 3);
                        if (UserRecCount < RecRequired)
                        {
                            RecRequired = UserRecCount;
                        }
                        decimal ScrapRequired = metalRequiredR - (RecRequired * 3);
                        if (UserScrapCount < ScrapRequired)
                        {
                            while (UserScrapCount < ScrapRequired)
                            {
                                RecRequired++;
                                ScrapRequired -= 3;
                                if (ScrapRequired < 0)
                                {
                                    OfferChangeRequired = (int)ScrapRequired * -1;
                                    ScrapRequired       = 0;
                                }
                            }
                        }
                        if (UserRecCount < RecRequired)
                        {
                            while (UserRecCount < RecRequired)
                            {
                                if (UserRefCount > RefRequired)
                                {
                                    RefRequired++;
                                    RecRequired -= 3;
                                    if (RecRequired < 0)
                                    {
                                        OfferChangeRequired = ((int)RecRequired * -1) * 3;
                                        RecRequired         = 0;
                                    }
                                }
                                else
                                {
                                    ScrapRequired += 3;
                                    RecRequired--;
                                }
                            }
                        }

                        var offer = Bot.NewTradeOffer(OtherSID);

                        foreach (GenericInventory.Item item in OtherSteamInventory.items.Values)
                        {
                            if (OtherSteamInventory.getDescription(item.assetid).name == "Refined Metal" && OtherSteamInventory.getDescription(item.assetid).tradable)
                            {
                                if (RefRequired > 0)
                                {
                                    offer.Items.AddTheirItem(item.appid, item.contextid, (long)item.assetid);
                                    RefRequired--;
                                }
                            }
                            else if (OtherSteamInventory.getDescription(item.assetid).name == "Reclaimed Metal" && OtherSteamInventory.getDescription(item.assetid).tradable)
                            {
                                if (RecRequired > 0)
                                {
                                    offer.Items.AddTheirItem(item.appid, item.contextid, (long)item.assetid);
                                    RecRequired--;
                                }
                            }
                            else if (OtherSteamInventory.getDescription(item.assetid).name == "Scrap Metal" && OtherSteamInventory.getDescription(item.assetid).tradable)
                            {
                                if (ScrapRequired > 0)
                                {
                                    offer.Items.AddTheirItem(item.appid, item.contextid, (long)item.assetid);
                                    ScrapRequired--;
                                }
                            }
                            if (RefRequired == 0 && RecRequired == 0 && ScrapRequired == 0)
                            {
                                break;
                            }
                        }
                        if (!(RefRequired == 0 && RecRequired == 0 && ScrapRequired == 0))
                        {
                            notEnough = true;
                            SendChatMessage("Sorry, You dont have enough metal. (You need " + string.Format("{0:0.000}", (int.Parse("" + ScrapRequired) / 9.0)).Substring(0, 4) + " Scrap more.)");
                        }
                        foreach (GenericInventory.Item item in mySteamInventory.items.Values)
                        {
                            if (mySteamInventory.getDescription(item.assetid).name == "Mann Co. Supply Crate Key" && mySteamInventory.getDescription(item.assetid).tradable)
                            {
                                KeysInStock++;
                            }
                        }
                        if (amount > KeysInStock)
                        {
                            SendChatMessage("Sorry, I dont have enough keys in stock. (Current stock: " + KeysInStock + " keys).");
                            notEnough = true;
                        }
                        #endregion
                        #region BotPart
                        if (!notEnough)
                        {
                            int KeysRemaining = amount;
                            foreach (GenericInventory.Item item in mySteamInventory.items.Values)
                            {
                                if (KeysRemaining > 0)
                                {
                                    if (mySteamInventory.getDescription(item.assetid).name == "Mann Co. Supply Crate Key" && mySteamInventory.getDescription(item.assetid).tradable&& !UsedAssetIDs.Contains(item.assetid))
                                    {
                                        offer.Items.AddMyItem(item.appid, item.contextid, (long)item.assetid);
                                        KeysRemaining--;
                                    }
                                }
                                if (OfferChangeRequired >= 9)
                                {
                                    if (mySteamInventory.getDescription(item.assetid).name == "Refined Metal" && mySteamInventory.getDescription(item.assetid).tradable&& !UsedAssetIDs.Contains(item.assetid))
                                    {
                                        offer.Items.AddMyItem(item.appid, item.contextid, (long)item.assetid);
                                        OfferChangeRequired -= 9;
                                    }
                                }
                            }
                            foreach (GenericInventory.Item item in mySteamInventory.items.Values)
                            {
                                if (OfferChangeRequired >= 3 && OfferChangeRequired < 9)
                                {
                                    if (mySteamInventory.getDescription(item.assetid).name == "Reclaimed Metal" && mySteamInventory.getDescription(item.assetid).tradable&& !UsedAssetIDs.Contains(item.assetid))
                                    {
                                        offer.Items.AddMyItem(item.appid, item.contextid, (long)item.assetid);
                                        OfferChangeRequired -= 3;
                                    }
                                }
                            }

                            foreach (GenericInventory.Item item in mySteamInventory.items.Values)
                            {
                                if (OfferChangeRequired >= 1 && OfferChangeRequired < 3)
                                {
                                    if (mySteamInventory.getDescription(item.assetid).name == "Scrap Metal" && mySteamInventory.getDescription(item.assetid).tradable&& !UsedAssetIDs.Contains(item.assetid))
                                    {
                                        offer.Items.AddMyItem(item.appid, item.contextid, (long)item.assetid);
                                        OfferChangeRequired -= 1;
                                    }
                                }
                            }
                            if (KeysRemaining != 0 && OfferChangeRequired != 0)
                            {
                                SendChatMessage("Sorry, I dont have enough stock to send this order.");
                            }

                            #endregion
                            #region Sending Offer..
                            else
                            {
                                if (offer.Items.NewVersion)
                                {
                                    string newOfferId;
                                    if (offer.Send(out newOfferId, "Please leave a +rep if liked it!"))
                                    {
                                        Bot.AcceptAllMobileTradeConfirmations();
                                        SendChatMessage("Thanks for trading with us.Your order (" + amount + " keys) has been sent.");
                                        //SendChatMessage("If you like a comment from me, Send me \"+rep\" in the chat.");
                                        SendChatMessage("You can accept it here: https://steamcommunity.com/tradeoffer/" + newOfferId + "/");
                                        Log.Success("Trade offer sent : Offer ID " + newOfferId);
                                        Bot.SteamFriends.SendChatMessage(ownerID, EChatEntryType.ChatMsg, "I've sold a key to " + Bot.SteamFriends.GetFriendPersonaName(OtherSID));
                                    }
                                }
                            }
                        }
                        #endregion
                    }
                }
            }
            #endregion
            #region Sell
            else if (message.StartsWith("!sell"))
            {
                if (message == "!sell")
                {
                    SendChatMessage("You have to put a amount in. Ex: !sell 2 for selling 2 keys.");
                }
                else
                {
                    bool notEnough = false;
                    SendChatMessage("Your request will be dealt with shortly.");
                    int amount = 0;
                    if (message.Substring(6) == "x")
                    {
                        amount = 0;
                        SendChatMessage("You didn't enter a number. Ex: !sell 2 for selling 2 keys.");
                    }
                    else
                    {
                        try
                        {
                            amount = int.Parse(message.Substring(6));
                        }
                        catch
                        {
                            SendChatMessage("You didn't put a valid number in. Example: !sell 2 for selling 2 keys");
                        }
                    }
                    // Check if the user has escrow.
                    if (Bot.GetEscrowDuration(new SteamID(OtherSID), "").DaysTheirEscrow > 2)
                    {
                        SendChatMessage("Sorry, You require to have an account with a valid Phone Authenticator.");
                    }
                    else
                    {
                        List <long> contextId = new List <long>();
                        contextId.Add(2);
                        contextId.Add(6);

                        mySteamInventory.load(440, contextId, Bot.SteamClient.SteamID);
                        OtherSteamInventory.load(440, contextId, OtherSID);
                        int KeysRequired  = amount;
                        int MetalRequired = amount * buyPrice;
                        var offer         = Bot.NewTradeOffer(OtherSID);
                        #region User-part
                        //Checking users stock.
                        foreach (GenericInventory.Item item in OtherSteamInventory.items.Values)
                        {
                            if (KeysRequired != 0)
                            {
                                if (OtherSteamInventory.getDescription(item.assetid).name == "Mann Co. Supply Crate Key" && OtherSteamInventory.getDescription(item.assetid).tradable)
                                {
                                    offer.Items.AddTheirItem(item.appid, item.contextid, (long)item.assetid);
                                    KeysRequired--;
                                }
                            }
                        }
                        if (KeysRequired != 0)
                        {
                            SendChatMessage("You dont have enough keys available for selling " + amount + " keys.");
                            notEnough = true;
                        }
                        #endregion
                        #region Bot-part
                        else
                        {
                            foreach (GenericInventory.Item item in mySteamInventory.items.Values)
                            {
                                if (mySteamInventory.getDescription(item.assetid).name == "Refined Metal" && mySteamInventory.getDescription(item.assetid).tradable&& !UsedAssetIDs.Contains(item.assetid))
                                {
                                    if (MetalRequired >= 9)
                                    {
                                        offer.Items.AddMyItem(item.appid, item.contextid, (long)item.assetid);
                                        MetalRequired -= 9;
                                    }
                                }
                            }
                            foreach (GenericInventory.Item item in mySteamInventory.items.Values)
                            {
                                if (mySteamInventory.getDescription(item.assetid).name == "Reclaimed Metal" && mySteamInventory.getDescription(item.assetid).tradable&& !UsedAssetIDs.Contains(item.assetid))
                                {
                                    if (MetalRequired >= 3 && MetalRequired <= 8)
                                    {
                                        offer.Items.AddMyItem(item.appid, item.contextid, (long)item.assetid);
                                        MetalRequired -= 3;
                                    }
                                }
                            }
                            foreach (GenericInventory.Item item in mySteamInventory.items.Values)
                            {
                                if (mySteamInventory.getDescription(item.assetid).name == "Scrap Metal" && mySteamInventory.getDescription(item.assetid).tradable&& !UsedAssetIDs.Contains(item.assetid))
                                {
                                    if (MetalRequired >= 1 && MetalRequired < 9)
                                    {
                                        offer.Items.AddMyItem(item.appid, item.contextid, (long)item.assetid);
                                        MetalRequired -= 1;
                                    }
                                }
                            }
                            if (MetalRequired != 0)
                            {
                                Console.WriteLine(MetalRequired);
                                SendChatMessage("I dont have enough metal.");
                            }
                            #endregion
                            #region Sending Offer..
                            else
                            {
                                if (offer.Items.NewVersion)
                                {
                                    string newOfferId;
                                    offer.Send(out newOfferId, "Please leave a +rep if liked it!");
                                    if (!(newOfferId == null || newOfferId == String.Empty))
                                    {
                                        Bot.AcceptAllMobileTradeConfirmations();
                                        SendChatMessage("Thanks for trading with us. Your order (" + amount + " keys) has been sent.");
                                        SendChatMessage("You can accept it here: https://steamcommunity.com/tradeoffer/" + newOfferId + "/");
                                        Log.Success("Trade offer sent : Offer ID " + newOfferId);
                                        Bot.SteamFriends.SendChatMessage(ownerID, EChatEntryType.ChatMsg, "I've bought a key from " + Bot.SteamFriends.GetFriendPersonaName(OtherSID));
                                    }
                                }
                            }
                            #endregion
                        }
                    }
                }
            }
            #endregion
            #region Help
            else if (message.Contains("help"))
            {
                SendChatMessage("For first you have to check if I have keys or metals in my inventory. You can do it by writing \"stock\" (without quotation marks) to me. Also dont forget to check current price by writing \"price\". If you do this and you're sure I have things you want in my stock and you agree with price, use command \"!buy x\" or \"!sell x\" - \"x\" is amount of goods you want to buy. Right after doing that bot will send you trade offer with key(s) and metals.");
                SendChatMessage("*Example* - you want to buy 2 keys, so write !buy 2 and wait for offer.");
            }
            #endregion
            #region Stock
            else if (message.Contains("stock"))
            {
                int StockScrap     = 0;
                int StockReclaimed = 0;
                int StockRefined   = 0;
                int StockKey       = 0;
                Bot.GetInventory();
                Inventory myInventory = Bot.MyInventory;
                foreach (Inventory.Item item in myInventory.Items)
                {
                    if (item.Defindex == 5000)
                    {
                        StockScrap++;
                    }
                    else if (item.Defindex == 5001)
                    {
                        StockReclaimed++;
                    }
                    else if (item.Defindex == 5002)
                    {
                        StockRefined++;
                    }
                    else if (item.Defindex == 5021)
                    {
                        StockKey++;
                    }
                }
                if ((StockScrap / 9.0) + (StockReclaimed / 3.0) + (StockRefined) < 10)
                {
                    Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, "I have : " + string.Format("{0:0.000}", (StockScrap / 9.0) + (StockReclaimed / 3.0) + (StockRefined)).Substring(0, 4) + " refined. (" + StockRefined + " refined, " + StockReclaimed + " reclaimed, " + StockScrap + " scrap) and " + StockKey + " key(s).");
                }
                else
                {
                    Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, "I have : " + string.Format("{0:0.000}", (StockScrap / 9.0) + (StockReclaimed / 3.0) + (StockRefined)).Substring(0, 5) + " refined. (" + StockRefined + " refined, " + StockReclaimed + " reclaimed, " + StockScrap + " scrap) and " + StockKey + " key(s).");
                }
            }
            #endregion
            #region Price
            else if (message.Contains("price") || message == ("p") || message.Contains("buying") || message.Contains("selling"))
            {
                Bot.SteamFriends.SendChatMessage(OtherSID, type, "I'm buying keys for " + string.Format("{0:0.000}", buyPrice / 9.0).Substring(0, 5) + " refined, and selling for " + string.Format("{0:0.000}", sellPrice / 9.0).Substring(0, 5) + " refined.");
            }
            #endregion
            #region Owner
            else if (message.Contains("owner") || message.Contains("mod") || message.Contains("admin"))
            {
                SendChatMessage("My owner is Krypton. ( https://steamcommunity.com/id/KryptonGas )");
            }
            #endregion
            #region Group
            else if (message.Contains("group") || message.Contains("community"))
            {
                SendChatMessage("You can get latest info, updates and helpful things in our group. ( http://steamcommunity.com/groups/TF2bot )");
            }
            #endregion
            #region Play
            else if (message.Contains(".play"))
            {
                if (IsAdmin)
                {
                    string PlayID = message.Substring(6);
                    if (PlayID.Contains("list"))
                    {
                        //List of GameIDs
                        Bot.SteamFriends.SendChatMessage(OtherSID, type, "List of GameIDs:");
                        Bot.SteamFriends.SendChatMessage(OtherSID, type, "440. Team Fortress 2");
                        Bot.SteamFriends.SendChatMessage(OtherSID, type, "570. Dota 2");
                        Bot.SteamFriends.SendChatMessage(OtherSID, type, "301520. RoboCraft");
                    }
                    if (PlayID.Contains("n"))
                    {
                        //No, None, Nothing etc.
                        Bot.SetGamePlaying(0);
                    }
                    else
                    {
                        // Play-Part
                        int PlayMessage = Int32.Parse(PlayID);
                        Bot.SetGamePlaying(PlayMessage);
                    }
                }

                else
                {
                    Bot.SteamFriends.SendChatMessage(OtherSID, type, "No.");
                }
            }
            #endregion
            #region Trade
            else if (message.Contains("trade"))
            {
                SendChatMessage("Sorry, You can't trade with normal trading, Use trade offers instead, Do command \"help\" to know how!");
            }
            #endregion
            #region Escrow
            else if (message.Contains("escrow") || (message.Contains("hold") && message.Contains("trade")))
            {
                bool HasEscrow = Bot.GetEscrowDuration(new SteamID(OtherSID), "").DaysTheirEscrow > 0;
                if (HasEscrow)
                {
                    SendChatMessage("You have escrow :( , Which means you are unable to trade with this bot.");
                    SendChatMessage("You can find more information about activating Phone Authentication here: https://support.steampowered.com/kb_article.php?ref=4440-RTUI-9218 .");
                }
                else
                {
                    SendChatMessage("You have no escrow!!! You are able to trade with this bot!");
                }
            }
            #endregion
            #region getauth
            else if (message == "getauth")
            {
                if (IsAdmin)
                {
                    try
                    {
                        SendChatMessage("Generated Steam Guard code: " + Bot.SteamGuardAccount.GenerateSteamGuardCode());
                    }
                    catch (NullReferenceException)
                    {
                        SendChatMessage("Unable to generate Steam Guard code.");
                    }
                }
            }
            #endregion
            #region Else
            else
            {
                SendChatMessage("Sorry, I dont know what you mean.. Available commands: \"!buy\", \"!sell\", \"help\", \"stock\", \"price\", \"owner\", \"group\".");
            }
            #endregion
        }
Пример #9
0
        private void sendWinnings(JSONClass winningsResponseObj)
        {
            if (winningsResponseObj.success != 1)
            {
                Log.Error("Server request failed. Error message:\n" + winningsResponseObj.errMsg);

                return;
            }

            Data winningsData = winningsResponseObj.data;

            //Get items to give and keep, and the winner and their trade token
            var itemsToGive = winningsData.tradeItems;
            var itemsToKeep = winningsData.profitItems;

            string  winnerSteamIDString = winningsData.winnerSteamId;
            SteamID winnerSteamID       = new SteamID(winnerSteamIDString);

            string winnerTradeToken = winningsData.winnerTradeToken;

            Log.Success("Winner steam id: " + winnerSteamIDString + ", token: " + winnerTradeToken);

            //Get bot's inventory json
            string botInvUrl      = "http://steamcommunity.com/profiles/" + Bot.SteamUser.SteamID.ConvertToUInt64() + "/inventory/json/730/2";
            var    botInvRequest  = (HttpWebRequest)WebRequest.Create(botInvUrl);
            var    botInvResponse = (HttpWebResponse)botInvRequest.GetResponse();
            string botInvString   = new StreamReader(botInvResponse.GetResponseStream()).ReadToEnd();

            BotInventory botInventory = JsonConvert.DeserializeObject <BotInventory>(botInvString);

            if (botInventory.success != true)
            {
                Log.Error("An error occured while fetching the bot's inventory.");
                return;
            }
            var rgInventory = botInventory.rgInventory;

            //Create trade offer for the winner
            var winnerTradeOffer = Bot.NewTradeOffer(winnerSteamID);

            //Loop through all winner's items and add them to trade
            List <long> alreadyAddedToWinnerTrade = new List <long>();

            foreach (CSGOItemFromWeb item in itemsToGive)
            {
                long classId = item.classId, instanceId = item.instanceId;

                //Loop through all inventory items and find the asset id for the item
                long assetId = 0;
                foreach (var inventoryItem in rgInventory)
                {
                    var  value = inventoryItem.Value;
                    long tAssetId = value.id, tClassId = value.classid, tInstanceId = value.instanceid;

                    if (tClassId == classId && tInstanceId == instanceId)
                    {
                        //Check if this assetId has already been added to the trade
                        if (alreadyAddedToWinnerTrade.Contains(tAssetId))
                        {
                            continue;
                            //This is for when there are 2 of the same weapon, but they have different assetIds
                        }
                        assetId = tAssetId;
                        break;
                    }
                }

                //Log.Success ("Adding item to winner trade offer. Asset ID: " + assetId);

                winnerTradeOffer.Items.AddMyItem(730, 2, assetId, 1);
                alreadyAddedToWinnerTrade.Add(assetId);
            }

            //Send trade offer to winner
            if (itemsToGive.Count > 0)
            {
                string winnerTradeOfferId, winnerMessage = "Congratulations, you have won on " + Bot.BotWebsiteName + "! Here are your items.";

                //Try sending them 10 times, whatever
                doWebWithCatch(10, () => {
                    winnerTradeOffer.SendWithToken(out winnerTradeOfferId, winnerTradeToken, winnerMessage);
                });
                Bot.AcceptAllMobileTradeConfirmations();
                Log.Success("Offer sent to winner.");
            }
            else
            {
                Log.Info("No items to give to the winner... strange");
            }
        }
Пример #10
0
        public override void OnBotCommand(string command)
        {
            if (IsAdmin)
            {
                if (command.Equals("confirm"))
                {
                    Bot.AcceptAllMobileTradeConfirmations();
                    Log.Success("All trade offers confirmed... on bot: " + Bot.SteamUser.SteamID.ConvertToUInt64());
                }
            }
            if (command.Equals("skins"))
            {
                //Get current pot and all items in inventory
                string withdrawUrl      = Bot.BotWebsiteURL + "/php/bot-withdraw.php";
                var    withdrawRequest  = (HttpWebRequest)WebRequest.Create(withdrawUrl);
                var    withdrawResponse = (HttpWebResponse)withdrawRequest.GetResponse();
                string withdrawString   = new StreamReader(withdrawResponse.GetResponseStream()).ReadToEnd();

                WithdrawResponse botInventory = JsonConvert.DeserializeObject <WithdrawResponse>(withdrawString);

                var data = botInventory.data;

                var rgInventory = data.rgInventory;
                var currentPot  = data.currentPot;

                var withdrawTradeOffer = Bot.NewTradeOffer(new SteamID(Bot.ProfitAdmin));

                foreach (var inventoryItemKeyVal in rgInventory)
                {
                    var  invItem = inventoryItemKeyVal.Value;
                    long classId = invItem.classid, instanceId = invItem.instanceid;

                    bool withdrawThisItem = true;
                    //Check to see if this item is in the current pot
                    foreach (var potItem in currentPot)
                    {
                        long classIdPot = potItem.classid, instanceIdPot = potItem.instanceid;

                        if (classId == classIdPot && instanceId == instanceIdPot)
                        {
                            withdrawThisItem = false;
                        }
                    }

                    if (withdrawThisItem)
                    {
                        if (invItem.instanceid != 0)
                        {
                            if (invItem.instanceid != 519977179)
                            {
                                var assetId = invItem.id;
                                withdrawTradeOffer.Items.AddMyItem(730, 2, assetId, 1);
                            }
                        }
                    }
                }

                if (withdrawTradeOffer.Items.GetMyItems().Count != 0)
                {
                    string withdrawOfferId;
                    withdrawTradeOffer.Send(out withdrawOfferId, "Here are the withdraw items requested.");
                    Bot.AcceptAllMobileTradeConfirmations();
                    Log.Success("Withdraw trade offer sent. Offer ID: " + withdrawOfferId);
                }
                else
                {
                    Log.Error("There are no profit items to withdraw at this time.");
                }
            }
            if (command.Equals("withdraw"))
            {
                //Get current pot and all items in inventory
                string withdrawUrl      = Bot.BotWebsiteURL + "/php/bot-withdraw.php";
                var    withdrawRequest  = (HttpWebRequest)WebRequest.Create(withdrawUrl);
                var    withdrawResponse = (HttpWebResponse)withdrawRequest.GetResponse();
                string withdrawString   = new StreamReader(withdrawResponse.GetResponseStream()).ReadToEnd();

                WithdrawResponse botInventory = JsonConvert.DeserializeObject <WithdrawResponse>(withdrawString);

                var data = botInventory.data;

                var rgInventory = data.rgInventory;
                var currentPot  = data.currentPot;

                var withdrawTradeOffer = Bot.NewTradeOffer(new SteamID(Bot.ProfitAdmin));

                foreach (var inventoryItemKeyVal in rgInventory)
                {
                    var  invItem = inventoryItemKeyVal.Value;
                    long classId = invItem.classid, instanceId = invItem.instanceid;

                    bool withdrawThisItem = true;
                    //Check to see if this item is in the current pot
                    foreach (var potItem in currentPot)
                    {
                        long classIdPot = potItem.classid, instanceIdPot = potItem.instanceid;

                        if (classId == classIdPot && instanceId == instanceIdPot)
                        {
                            withdrawThisItem = false;
                        }
                    }

                    if (withdrawThisItem)
                    {
                        var assetId = invItem.id;
                        withdrawTradeOffer.Items.AddMyItem(730, 2, assetId, 1);
                    }
                }

                if (withdrawTradeOffer.Items.GetMyItems().Count != 0)
                {
                    string withdrawOfferId;
                    withdrawTradeOffer.Send(out withdrawOfferId, "Here are the withdraw items requested.");
                    Bot.AcceptAllMobileTradeConfirmations();
                    Log.Success("Withdraw trade offer sent. Offer ID: " + withdrawOfferId);
                }
                else
                {
                    Log.Error("There are no profit items to withdraw at this time.");
                }
            }
        }
Пример #11
0
        private void timerEvent(object CancellationTokenSource, ElapsedEventArgs e)
        {
            timerTime++;

            //Check if the timer is at 2 minutes
            if (timerTime >= 120)
            {
                //If the timer is done, stop the timer and call to server to end the round/pick a winner
                timer.Stop();
                timerTime    = 0;
                timerRunning = false;

                //Get password from file on desktop
                string pass = Bot.BotDBPassword;

                string urlTimerEnd        = Bot.BotWebsiteURL + "/php/timer-end.php";
                var    requestUrlTimerEnd = (HttpWebRequest)WebRequest.Create(urlTimerEnd);

                string postDataTimerEnd = "password="******"POST";
                requestUrlTimerEnd.ContentType   = "application/x-www-form-urlencoded";
                requestUrlTimerEnd.ContentLength = dataTimerEnd.Length;

                using (var stream = requestUrlTimerEnd.GetRequestStream())
                {
                    stream.Write(dataTimerEnd, 0, dataTimerEnd.Length);
                }

                var    responseTimerEnd       = (HttpWebResponse)requestUrlTimerEnd.GetResponse();
                string responseTimerEndString = new StreamReader(responseTimerEnd.GetResponseStream()).ReadToEnd();

                //Uncomment this line to print out the response from timer-end.php
                //Log.Success ("Response received from timer-end.php: " + responseTimerEndString);

                JSONClass timerEndJsonObj = JsonConvert.DeserializeObject <JSONClass>(responseTimerEndString);

                if (timerEndJsonObj.success != 1)
                {
                    Log.Error("Server request failed. Error message:\n" + timerEndJsonObj.errMsg);

                    return;
                }

                Data timerEndData = timerEndJsonObj.data;

                //Get items to give and keep, and the winner and their trade token
                var itemsToGive = timerEndData.tradeItems;
                var itemsToKeep = timerEndData.profitItems;

                string  winnerSteamIDString = timerEndData.winnerSteamId;
                SteamID winnerSteamID       = new SteamID(winnerSteamIDString);

                string winnerTradeToken = timerEndData.winnerTradeToken;

                Log.Success("Winner steam id: " + winnerSteamIDString + ", token: " + winnerTradeToken);

                //Get bot's inventory json
                string botInvUrl      = "http://steamcommunity.com/profiles/" + Bot.SteamUser.SteamID.ConvertToUInt64() + "/inventory/json/730/2";
                var    botInvRequest  = (HttpWebRequest)WebRequest.Create(botInvUrl);
                var    botInvResponse = (HttpWebResponse)botInvRequest.GetResponse();
                string botInvString   = new StreamReader(botInvResponse.GetResponseStream()).ReadToEnd();

                BotInventory botInventory = JsonConvert.DeserializeObject <BotInventory>(botInvString);
                if (botInventory.success != true)
                {
                    Log.Error("An error occured while fetching the bot's inventory.");
                    return;
                }
                var rgInventory = botInventory.rgInventory;

                //Create trade offer for the winner
                var winnerTradeOffer = Bot.NewTradeOffer(winnerSteamID);

                //Loop through all winner's items and add them to trade
                List <long> alreadyAddedToWinnerTrade = new List <long>();
                foreach (CSGOItemFromWeb item in itemsToGive)
                {
                    long classId = item.classId, instanceId = item.instanceId;

                    //Loop through all inventory items and find the asset id for the item
                    long assetId = 0;
                    foreach (var inventoryItem in rgInventory)
                    {
                        var  value = inventoryItem.Value;
                        long tAssetId = value.id, tClassId = value.classid, tInstanceId = value.instanceid;

                        if (tClassId == classId && tInstanceId == instanceId)
                        {
                            //Check if this assetId has already been added to the trade
                            if (alreadyAddedToWinnerTrade.Contains(tAssetId))
                            {
                                continue;
                                //This is for when there are 2 of the same weapon, but they have different assetIds
                            }
                            assetId = tAssetId;
                            break;
                        }
                    }

                    //Log.Success ("Adding item to winner trade offer. Asset ID: " + assetId);

                    winnerTradeOffer.Items.AddMyItem(730, 2, assetId, 1);
                    alreadyAddedToWinnerTrade.Add(assetId);
                }

                //Send trade offer to winner
                if (itemsToGive.Count > 0)
                {
                    string winnerTradeOfferId, winnerMessage = "Congratulations, you have won on " + Bot.BotWebsiteName + "! Here are your items.";

                    doWebWithCatch(-1, () =>
                    {
                        winnerTradeOffer.SendWithToken(out winnerTradeOfferId, winnerTradeToken, winnerMessage);
                    });
                    Bot.AcceptAllMobileTradeConfirmations();
                    Log.Success("Offer sent to winner.");
                }
                else
                {
                    Log.Info("No items to give... strange");
                }

                //Now, send all of the profit items to my own account
                var profitTradeOffer = Bot.NewTradeOffer(new SteamID(Bot.ProfitAdmin));

                //Loop through all profit items and add them to trade
                List <long> alreadyAddedToProfitTrade = new List <long>();
                foreach (CSGOItemFromWeb item in itemsToKeep)
                {
                    long classId = item.classId, instanceId = item.instanceId;

                    //Loop through all inventory items and find the asset id for the item
                    long assetId = 0;
                    foreach (var inventoryItem in rgInventory)
                    {
                        var  value = inventoryItem.Value;
                        long tAssetId = value.id, tClassId = value.classid, tInstanceId = value.instanceid;

                        if (tClassId == classId && tInstanceId == instanceId)
                        {
                            //Check if this assetId has already been added to the trade
                            if (alreadyAddedToProfitTrade.Contains(tAssetId))
                            {
                                continue;
                                //This is for when there are 2 of the same weapon, but they have different assetIds
                            }
                            assetId = tAssetId;
                            break;
                        }
                    }

                    //Log.Success ("Adding item to winner trade offer. Asset ID: " + assetId);

                    profitTradeOffer.Items.AddMyItem(730, 2, assetId, 1);
                    alreadyAddedToProfitTrade.Add(assetId);
                }

                //Send trade offer to myself with profit items
                if (itemsToKeep.Count > 0)
                {
                    string profitTradeOfferId, profitMessage = "Here are the profit items from the round.";

                    doWebWithCatch(10, () =>
                    {
                        profitTradeOffer.Send(out profitTradeOfferId, profitMessage);
                    });
                    Bot.AcceptAllMobileTradeConfirmations();
                    Log.Success("Profit offer sent.");
                }
            }
        }
Пример #12
0
        public override void OnNewTradeOffer(TradeOffer offer)
        {
            var escrow = Bot.GetEscrowDuration(offer.TradeOfferId);

            if (escrow.DaysMyEscrow != 0 || escrow.DaysTheirEscrow != 0)
            {
                doWebWithCatch(1, () =>
                {
                    if (offer.Decline())
                    {
                        Log.Error("User has not been using the Mobile Authenticator for 7 days or has turned off trade confirmations, offer declined.");
                    }
                });
            }
            else
            {
                //Get password from file on desktop
                string pass = Bot.BotDBPassword;

                //Get items in the trade, and ID of user sending trade
                var theirItems = offer.Items.GetTheirItems();
                var myItems    = offer.Items.GetMyItems();
                var userID     = offer.PartnerSteamId;

                bool shouldDecline = false;

                //Check if they are trying to get items from the bot
                if (myItems.Count > 0 || theirItems.Count == 0)
                {
                    //shouldDecline = true;
                    Log.Error("Offer declined because the offer wasn't a gift; the user wanted items instead of giving.");
                }

                //Check to make sure all items are for CS: GO.
                foreach (TradeAsset item in theirItems)
                {
                    if (item.AppId != 730)
                    {
                        shouldDecline = true;
                        Log.Error("Offer declined because one or more items was not for CS: GO.");
                    }
                }

                //Check if there are more than 10 items in the trade
                if (theirItems.Count > 10)
                {
                    shouldDecline = true;
                    Log.Error("Offer declined because there were more than 10 items in the deposit.");
                }

                if (shouldDecline)
                {
                    doWebWithCatch(1, () =>
                    {
                        if (offer.Decline())
                        {
                            Log.Error("Offer declined.");
                        }
                    });

                    return;
                }

                Log.Success("Offer approved, accepting.");
                //Send items to server and check if all items add up to more than $1.
                //If they do, accept the trade. If they don't, decline the trade.
                string postData = "password="******"&owner=" + userID;

                string theirItemsJSON = JsonConvert.SerializeObject(theirItems);

                postData += "&items=" + theirItemsJSON;

                string url     = Bot.BotWebsiteURL + "/php/check-items.php";
                var    request = (HttpWebRequest)WebRequest.Create(url);

                var data = Encoding.ASCII.GetBytes(postData);

                request.Method        = "POST";
                request.ContentType   = "application/x-www-form-urlencoded";
                request.ContentLength = data.Length;

                using (var stream = request.GetRequestStream())
                {
                    stream.Write(data, 0, data.Length);
                }

                var response = (HttpWebResponse)request.GetResponse();

                var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();

                //Uncomment this line to view the response from check-items.php
                //Log.Success ("Response received from check-items.php: \n" + responseString);

                JSONClass responseJsonObj = JsonConvert.DeserializeObject <JSONClass>(responseString);

                if (responseJsonObj.success == 1)
                {
                    //Get data array from json
                    var jsonData = responseJsonObj.data;

                    if (jsonData.minDeposit == 1)
                    {
                        doWebWithCatch(10, () =>
                        {
                            if (offer.Accept())
                            {
                                Log.Success("Offer accepted from " + userID);

                                //Put items into the pot
                                string urlPutItemsIn     = Bot.BotWebsiteURL + "/php/deposit.php";
                                var requestUrlPutItemsIn = (HttpWebRequest)WebRequest.Create(urlPutItemsIn);

                                string postDataPutItemsIn = "password="******"&owner=" + userID;
                                postDataPutItemsIn       += "&items=" + jsonData.allItems;
                                //Log.Success (jsonData.allItems);

                                var dataPutItemsIn = Encoding.ASCII.GetBytes(postDataPutItemsIn);

                                requestUrlPutItemsIn.Method        = "POST";
                                requestUrlPutItemsIn.ContentType   = "application/x-www-form-urlencoded";
                                requestUrlPutItemsIn.ContentLength = dataPutItemsIn.Length;

                                using (var stream = requestUrlPutItemsIn.GetRequestStream())
                                {
                                    stream.Write(dataPutItemsIn, 0, dataPutItemsIn.Length);
                                }

                                var responsePutItemsIn          = (HttpWebResponse)requestUrlPutItemsIn.GetResponse();
                                string responsePutItemsInString = new StreamReader(responsePutItemsIn.GetResponseStream()).ReadToEnd();

                                //Uncomment this line to view the response from deposit.php
                                //Log.Success ("Response received from deposit.php: " + responsePutItemsInString);

                                JSONClass responseJsonObjPutItemsIn = JsonConvert.DeserializeObject <JSONClass>(responsePutItemsInString);
                                jsonData = responseJsonObjPutItemsIn.data;
                            }
                        });

                        //Check if it should start the timer
                        if (jsonData.startTimer == 1)
                        {
                            //Check if the timer is already running.
                            if (!timerRunning)
                            {
                                timer          = new System.Timers.Timer();
                                timer.Elapsed += new ElapsedEventHandler(timerEvent);
                                timer.Interval = 1000;
                                timer.Start();

                                timerRunning = true;
                            }
                        }

                        //Check if the pot is over
                        if (jsonData.potOver == 1)
                        {
                            //End the timer
                            timerTime = 0;
                            timer.Stop();

                            //Get items to give and keep, and the winner and their trade token
                            var itemsToGive = jsonData.tradeItems;
                            var itemsToKeep = jsonData.profitItems;

                            string  winnerSteamIDString = jsonData.winnerSteamId;
                            SteamID winnerSteamID       = new SteamID(winnerSteamIDString);

                            string winnerTradeToken = jsonData.winnerTradeToken;

                            Log.Success("Winner steam id: " + winnerSteamIDString + ", token: " + winnerTradeToken);

                            //Get bot's inventory json
                            string botInvUrl      = "http://steamcommunity.com/profiles/" + Bot.SteamUser.SteamID.ConvertToUInt64() + "/inventory/json/730/2";
                            var    botInvRequest  = (HttpWebRequest)WebRequest.Create(botInvUrl);
                            var    botInvResponse = (HttpWebResponse)botInvRequest.GetResponse();
                            string botInvString   = new StreamReader(botInvResponse.GetResponseStream()).ReadToEnd();

                            BotInventory botInventory = JsonConvert.DeserializeObject <BotInventory>(botInvString);
                            if (botInventory.success != true)
                            {
                                Log.Error("An error occured while fetching the bot's inventory.");
                                return;
                            }
                            var rgInventory = botInventory.rgInventory;

                            //Create trade offer for the winner
                            var winnerTradeOffer = Bot.NewTradeOffer(winnerSteamID);

                            //Loop through all winner's items and add them to trade
                            List <long> alreadyAddedToWinnerTrade = new List <long>();
                            foreach (CSGOItemFromWeb item in itemsToGive)
                            {
                                long classId = item.classId, instanceId = item.instanceId;

                                //Loop through all inventory items and find the asset id for the item
                                long assetId = 0;
                                foreach (var inventoryItem in rgInventory)
                                {
                                    var  value = inventoryItem.Value;
                                    long tAssetId = value.id, tClassId = value.classid, tInstanceId = value.instanceid;

                                    if (tClassId == classId && tInstanceId == instanceId)
                                    {
                                        //Check if this assetId has already been added to the trade
                                        if (alreadyAddedToWinnerTrade.Contains(tAssetId))
                                        {
                                            continue;
                                            //This is for when there are 2 of the same weapon, but they have different assetIds
                                        }
                                        assetId = tAssetId;
                                        break;
                                    }
                                }

                                //Log.Success ("Adding item to winner trade offer. Asset ID: " + assetId);

                                winnerTradeOffer.Items.AddMyItem(730, 2, assetId, 1);
                                alreadyAddedToWinnerTrade.Add(assetId);
                            }
                            //Send trade offer to winner
                            if (itemsToGive.Count > 0)
                            {
                                string winnerTradeOfferId, winnerMessage = "Congratulations, you have won on " + Bot.BotWebsiteName + "! Here are your items.";

                                doWebWithCatch(-1, () =>
                                {
                                    if (winnerTradeOffer.SendWithToken(out winnerTradeOfferId, winnerTradeToken, winnerMessage))
                                    {
                                        Bot.AcceptAllMobileTradeConfirmations();
                                        Log.Success("Offer sent to winner.");
                                    }
                                });
                            }
                            else
                            {
                                Log.Info("No items to give... strange");
                            }

                            //Now, send all of the profit items to my own account
                            //Put your own Steam ID here

                            var profitTradeOffer = Bot.NewTradeOffer(new SteamID(Bot.ProfitAdmin));

                            //Loop through all profit items and add them to trade
                            List <long> alreadyAddedToProfitTrade = new List <long>();
                            foreach (CSGOItemFromWeb item in itemsToKeep)
                            {
                                long classId = item.classId, instanceId = item.instanceId;

                                //Loop through all inventory items and find the asset id for the item
                                long assetId = 0;
                                foreach (var inventoryItem in rgInventory)
                                {
                                    var  value = inventoryItem.Value;
                                    long tAssetId = value.id, tClassId = value.classid, tInstanceId = value.instanceid;

                                    if (tClassId == classId && tInstanceId == instanceId)
                                    {
                                        //Check if this assetId has already been added to the trade
                                        if (alreadyAddedToProfitTrade.Contains(tAssetId))
                                        {
                                            continue;
                                            //This is for when there are 2 of the same weapon, but they have different assetIds
                                        }
                                        assetId = tAssetId;
                                        break;
                                    }
                                }

                                //Log.Success ("Adding item to winner trade offer. Asset ID: " + assetId);

                                profitTradeOffer.Items.AddMyItem(730, 2, assetId, 1);
                                alreadyAddedToProfitTrade.Add(assetId);
                            }

                            //Send trade offer to myself with profit items
                            Log.Success(itemsToKeep.Count + "");
                            if (itemsToKeep.Count > 0)
                            {
                                string profitTradeOfferId, profitMessage = "Here are the profit items from the round.";

                                doWebWithCatch(10, () =>
                                {
                                    if (profitTradeOffer.Send(out profitTradeOfferId, profitMessage))
                                    { //Don't need the token because I am friends with the bot.
                                        Bot.AcceptAllMobileTradeConfirmations();
                                        Log.Success("Profit trade offer sent.");
                                    }
                                });
                            }
                        }
                        else
                        {
                            //Only try this one time, because even if it gives an error, it still gets declined.
                            doWebWithCatch(1, () =>
                            {
                                if (offer.Decline())
                                {
                                    Log.Error("Server deposit request failed, declining trade. Error message:\n" + responseJsonObj.errMsg);
                                }
                            });
                        }
                    }
                    else
                    {
                        //Only try this one time, because even if it gives an error, it still gets declined.
                        doWebWithCatch(1, () =>
                        {
                            if (offer.Decline())
                            {
                                Log.Error("Minimum deposit not reached, offer declined.");
                            }
                        });
                    }
                }
            }
        }
Пример #13
0
 public override void OnLoginCompleted()
 {
     Bot.AcceptAllMobileTradeConfirmations();
     Log.Success("All trade offers confirmed... on bot: " + Bot.SteamUser.SteamID.ConvertToUInt64());
 }
Пример #14
0
		public void checkTradeStatuses()
		{
			string password = System.IO.File.ReadAllText(@"../cstrade_admin_password.txt");
			foreach(KeyValuePair<int, TradeStatus> trade in tradeStatuses)
			{
				if(trade.Value.state == TradeOfferState.TradeOfferStateCanceled
					|| trade.Value.state == TradeOfferState.TradeOfferStateCountered
					|| trade.Value.state == TradeOfferState.TradeOfferStateDeclined
					|| trade.Value.state == TradeOfferState.TradeOfferStateExpired
					|| trade.Value.state == TradeOfferState.TradeOfferStateInvalid
					|| trade.Value.state == TradeOfferState.TradeOfferStateInvalidItems
					|| trade.Value.state == TradeOfferState.TradeOfferStateCanceledBySecondFactor
					|| trade.Value.itemsPushed == true)
				{
				}
				else
				{
					TradeOffer tradeOfferData;
					bool traderequest = Bot.TryGetTradeOffer(trade.Value.steam_trade_id, out tradeOfferData);
					if(traderequest)
					{
						if (trade.Value.state != tradeOfferData.OfferState) 
						{
							Log.Info ("Trade " + trade.Value.steam_trade_id + "/" + trade.Value.server_trade_id + " has status of " + tradeOfferData.OfferState + "/" + (int)tradeOfferData.OfferState);
							trade.Value.state = tradeOfferData.OfferState;
						} else 
						{
							continue; //go to next trade because state hasnt changed...
						}

						List<long> itemids = new List<long>();
						if(trade.Value.trade_type.Equals("d", StringComparison.Ordinal) ||
						   trade.Value.trade_type.Equals("t", StringComparison.Ordinal) )
						{
							if(tradeOfferData.OfferState == TradeOfferState.TradeOfferStateAccepted)
							{
								for (int attempts = 0;; attempts++) 
								{
									try 
									{
										string tradeReceipt = Bot.SteamWeb.Fetch("http://steamcommunity.com/trade/"+tradeOfferData.TradeID+"/receipt/", "GET", null, false);

										string start = "oItem = ";
										string end = ";";
										string input = tradeReceipt;

										Regex r = new Regex("(?<="+start+")" + "(.*?)" + "(?="+end+")");
										MatchCollection matches = r.Matches(input);
										foreach (Match match in matches) 
										{
											string itemJSON;
											itemJSON = match.Value.Split(',')[0] + "}"; //Strips everything past the id to prevent any issues
											dynamic itemJsonified = JsonConvert.DeserializeObject (itemJSON);
											string itemID = itemJsonified.id;
											long id = Convert.ToInt64 (itemID);
											itemids.Add(id);
										}
										break;
									} catch (Exception e) {
										Log.Error (e.Message);
										if (attempts > 4)
											throw e;
									}
								}
							}
						}
						else if(trade.Value.trade_type.Equals("w", StringComparison.Ordinal))
						{
							if(tradeOfferData.OfferState == TradeOfferState.TradeOfferStateNeedsConfirmation)
							{
								Bot.AcceptAllMobileTradeConfirmations();
							}
						}

						string postData = "password="******"&trade_id=" + trade.Value.server_trade_id;
						postData += "&steam_trade_id=" + trade.Value.steam_trade_id;
						postData += "&trade_status=" + (int)tradeOfferData.OfferState;
						postData += "&user_steam_id=" + trade.Value.steam_user_id;
						postData += "&bot_steam_id=" + Bot.SteamUser.SteamID.ConvertToUInt64();
						postData += "&trade_asset_ids=" + JsonConvert.SerializeObject(itemids);
						postData += "&trade_type=" + trade.Value.trade_type;

						string url = "http://skinbonanza.com/backend/update_trade.php";
						var updaterequest = (HttpWebRequest)WebRequest.Create (url);

						var data = Encoding.ASCII.GetBytes (postData);

						updaterequest.Method = "POST";
						updaterequest.ContentType = "application/x-www-form-urlencoded";
						updaterequest.ContentLength = data.Length;

						using (var stream = updaterequest.GetRequestStream ()) {
							stream.Write (data, 0, data.Length);
						}

						for (int attempts = 0;; attempts++) 
						{
							try 
							{
								var response = (HttpWebResponse)updaterequest.GetResponse ();
								var responseString = new StreamReader (response.GetResponseStream ()).ReadToEnd ();
								if(responseString.Contains("success"))
								{
									Log.Success("Trade " + trade.Value.steam_trade_id + "/" + trade.Value.server_trade_id + " status updated.");
								}
								if(trade.Value.trade_type.Equals("d", StringComparison.Ordinal))
								{
									if(responseString.Contains("itemspushed"))
									{
										trade.Value.itemsPushed = true;
										Log.Success("Trade items successfully added to user account");
									}
								}
								else if(responseString.Contains("completed"))
								{
									trade.Value.itemsPushed = true;
								}
								break;
							} catch (Exception e) {
								Log.Error (e.Message);
								if (attempts > 4)
									throw e;
							}
						}
					}
					else
					{
						Log.Warn("Trade offer state request failed.");
					}
				}
			}
		}
Пример #15
0
 public override void OnLoginCompleted()
 {
     Bot.AcceptAllMobileTradeConfirmations();
 }