Exemple #1
0
        private void CreateTradeOffer(Bot bot, GameServerRequest gsr)
        {
            float  tradeValue = -1;
            string message    = gsr.Arguments;

            //STEAM_0:1:42047781/2514414967/NULL/999900.00 //TOOOOOOOOO DOOOOOOOOOOOOOO
            string[] assetIDs     = null;
            string[] myAssetIDs   = null;
            string[] steamIDitems = message.Split('/');
            SteamID  steamid      = GetSteamIDFromString(steamIDitems[0]);

            TradeOffer to = bot.TradeOfferManager.NewOffer(steamid);

            GameServer gameServer = bot.Manager.GetServerByID(gsr.ServerID);

            if (steamIDitems[1].Length > 1 && steamIDitems[1] != "NULL")
            {
                assetIDs = steamIDitems[1].Split(',');

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

                bot.OtherGenericInventory.load((int)Games.CSGO, contextId, steamid);

                foreach (GenericInventory.Item item in bot.OtherGenericInventory.items.Values)
                {
                    if (Array.IndexOf(assetIDs, item.assetid.ToString()) > -1)
                    {
                        GenericInventory.ItemDescription description = bot.OtherGenericInventory.getDescription(item.assetid);
                        to.Items.AddTheirItem(item.appid, item.contextid, (long)item.assetid);
                    }
                }
                bot.OtherGenericInventory.load((int)Games.TF2, contextId, steamid);

                foreach (GenericInventory.Item item in bot.OtherGenericInventory.items.Values)
                {
                    if (Array.IndexOf(assetIDs, item.assetid.ToString()) > -1)
                    {
                        GenericInventory.ItemDescription description = bot.OtherGenericInventory.getDescription(item.assetid);
                        to.Items.AddTheirItem(item.appid, item.contextid, (long)item.assetid);
                    }
                }
                bot.OtherGenericInventory.load((int)Games.Dota2, contextId, steamid);

                foreach (GenericInventory.Item item in bot.OtherGenericInventory.items.Values)
                {
                    if (Array.IndexOf(assetIDs, item.assetid.ToString()) > -1)
                    {
                        GenericInventory.ItemDescription description = bot.OtherGenericInventory.getDescription(item.assetid);
                        to.Items.AddTheirItem(item.appid, item.contextid, (long)item.assetid);
                    }
                }
            }

            if (steamIDitems[2].Length > 1 && steamIDitems[2] != "NULL")
            {
                myAssetIDs = steamIDitems[2].Split(',');

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

                bot.MyGenericInventory.load((int)Games.CSGO, contextId, steamid);

                foreach (GenericInventory.Item item in bot.OtherGenericInventory.items.Values)
                {
                    if (Array.IndexOf(myAssetIDs, item.assetid.ToString()) > -1)
                    {
                        GenericInventory.ItemDescription description = bot.OtherGenericInventory.getDescription(item.assetid);
                        to.Items.AddTheirItem(item.appid, item.contextid, (long)item.assetid);
                    }
                }

                bot.MyGenericInventory.load((int)Games.TF2, contextId, steamid);

                foreach (GenericInventory.Item item in bot.OtherGenericInventory.items.Values)
                {
                    if (Array.IndexOf(myAssetIDs, item.assetid.ToString()) > -1)
                    {
                        GenericInventory.ItemDescription description = bot.OtherGenericInventory.getDescription(item.assetid);
                        to.Items.AddTheirItem(item.appid, item.contextid, (long)item.assetid);
                    }
                }

                bot.MyGenericInventory.load((int)Games.Dota2, contextId, steamid);

                foreach (GenericInventory.Item item in bot.OtherGenericInventory.items.Values)
                {
                    if (Array.IndexOf(myAssetIDs, item.assetid.ToString()) > -1)
                    {
                        GenericInventory.ItemDescription description = bot.OtherGenericInventory.getDescription(item.assetid);
                        to.Items.AddTheirItem(item.appid, item.contextid, (long)item.assetid);
                    }
                }
            }

            if (steamIDitems[3] != "NULL")
            {
                tradeValue = float.Parse(steamIDitems[3], CultureInfo.InvariantCulture);
            }

            string offerId;

            to.Send(out offerId, String.Format("\"{0}\" the {1}@{2}", gameServer.Name, DateTime.Now.ToString("dd/MM/yyyy"), DateTime.Now.ToString("HH:mm")));

            if (offerId != "")
            {
                bot.Manager.Send(gsr.ServerID, gsr.ModuleID, NetworkCode.ASteambotCode.CreateTradeOffer, offerId);
                bot.TradeoffersGS.Add(offerId, gsr.ModuleID + "|" + tradeValue);
                bot.TradeOfferValue.Add(offerId, tradeValue);

                bot.AcceptMobileTradeConfirmation(offerId);
            }
            else
            {
                bot.Manager.Send(gsr.ServerID, gsr.ModuleID, NetworkCode.ASteambotCode.CreateTradeOffer, "-1");
            }
        }
        private void CreateTradeOffer(Bot bot, GameServerRequest gsr)
        {
            float  tradeValue = -1;
            string message    = gsr.Arguments;

            string[] assetIDs     = null;
            string[] myAssetIDs   = null;
            string[] steamIDitems = message.Split('/');
            SteamID  steamid      = GetSteamIDFromString(steamIDitems[0]);

            if (!steamid.IsValid)
            {
                return;
            }

            TradeOffer to = bot.TradeOfferManager.NewOffer(steamid);

            GameServer gameServer = bot.Manager.GetServerByID(gsr.ServerID);

            if (steamIDitems[1].Length > 1 && steamIDitems[1] != "NULL")
            {
                assetIDs = steamIDitems[1].Split(',');

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

                bot.OtherGenericInventory.load((int)Games.CSGO, contextId, steamid);

                foreach (GenericInventory.Item item in bot.OtherGenericInventory.items.Values)
                {
                    if (Array.IndexOf(assetIDs, item.assetid.ToString()) > -1)
                    {
                        GenericInventory.ItemDescription description = (ItemDescription)bot.OtherGenericInventory.getDescription(item.assetid);
                        to.Items.AddTheirItem(item.appid, item.contextid, (long)item.assetid);
                    }
                }
                bot.OtherGenericInventory.load((int)Games.TF2, contextId, steamid);

                foreach (GenericInventory.Item item in bot.OtherGenericInventory.items.Values)
                {
                    if (Array.IndexOf(assetIDs, item.assetid.ToString()) > -1)
                    {
                        GenericInventory.ItemDescription description = (ItemDescription)bot.OtherGenericInventory.getDescription(item.assetid);
                        to.Items.AddTheirItem(item.appid, item.contextid, (long)item.assetid);
                    }
                }
                bot.OtherGenericInventory.load((int)Games.Dota2, contextId, steamid);

                foreach (GenericInventory.Item item in bot.OtherGenericInventory.items.Values)
                {
                    if (Array.IndexOf(assetIDs, item.assetid.ToString()) > -1)
                    {
                        GenericInventory.ItemDescription description = (ItemDescription)bot.OtherGenericInventory.getDescription(item.assetid);
                        to.Items.AddTheirItem(item.appid, item.contextid, (long)item.assetid);
                    }
                }
            }

            if (steamIDitems[2].Length > 1 && steamIDitems[2] != "NULL")
            {
                myAssetIDs = steamIDitems[2].Split(',');

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

                bot.MyGenericInventory.load((int)Games.CSGO, contextId, bot.getSteamID());

                foreach (GenericInventory.Item item in bot.MyGenericInventory.items.Values)
                {
                    if (Array.IndexOf(myAssetIDs, item.assetid.ToString()) > -1)
                    {
                        ItemDescription description = (ItemDescription)bot.MyGenericInventory.getDescription(item.assetid);
                        to.Items.AddMyItem(item.appid, item.contextid, (long)item.assetid);
                    }
                }

                bot.MyGenericInventory.load((int)Games.TF2, contextId, bot.getSteamID());

                foreach (GenericInventory.Item item in bot.MyGenericInventory.items.Values)
                {
                    if (Array.IndexOf(myAssetIDs, item.assetid.ToString()) > -1)
                    {
                        ItemDescription description = (ItemDescription)bot.MyGenericInventory.getDescription(item.assetid);
                        to.Items.AddMyItem(item.appid, item.contextid, (long)item.assetid);
                    }
                }

                bot.MyGenericInventory.load((int)Games.Dota2, contextId, bot.getSteamID());

                foreach (GenericInventory.Item item in bot.MyGenericInventory.items.Values)
                {
                    if (Array.IndexOf(myAssetIDs, item.assetid.ToString()) > -1)
                    {
                        ItemDescription description = (ItemDescription)bot.MyGenericInventory.getDescription(item.assetid);
                        to.Items.AddMyItem(item.appid, item.contextid, (long)item.assetid);
                    }
                }
            }

            if (steamIDitems[3] != "NULL")
            {
                tradeValue = float.Parse(steamIDitems[3], CultureInfo.InvariantCulture);
            }

            string offerId = "";

            string token = bot.GetToken(steamid);

            if (bot.Friends.Contains(steamid.ConvertToUInt64()))
            {
                to.Send(out offerId, String.Format("\"{0}\" the {1}@{2}", gameServer.Name, DateTime.Now.ToString("dd/MM/yyyy"), DateTime.Now.ToString("HH:mm")));
            }
            else if (token != null)
            {
                to.SendWithToken(out offerId, token, String.Format("\"{0}\" the {1}@{2}", gameServer.Name, DateTime.Now.ToString("dd/MM/yyyy"), DateTime.Now.ToString("HH:mm")));
            }
            else
            {
                bot.Manager.Send(gsr.ServerID, gsr.ModuleID, NetworkCode.ASteambotCode.TradeToken, steamid.ConvertToUInt64().ToString() + "/" + "trade_token_not_found");
            }

            if (offerId != "")
            {
                bot.Manager.Send(gsr.ServerID, gsr.ModuleID, NetworkCode.ASteambotCode.CreateTradeOffer, steamid.ConvertToUInt64() + "/" + offerId);
                bot.TradeoffersGS.Add(offerId, gsr.ServerID + "|" + gsr.ModuleID + "|" + tradeValue);
                bot.TradeOfferValue.Add(offerId, tradeValue);

                bot.AcceptMobileTradeConfirmation(offerId);

                bot.UpdateTradeOfferInDatabase(to, tradeValue);
            }
            else
            {
                if (token != null)
                {
                    bot.Manager.Send(gsr.ServerID, gsr.ModuleID, NetworkCode.ASteambotCode.TradeToken, steamid.ConvertToUInt64().ToString() + "/" + "trade_token_invalid");
                }

                bot.Manager.Send(gsr.ServerID, gsr.ModuleID, NetworkCode.ASteambotCode.CreateTradeOffer, steamid.ConvertToUInt64() + "/" + "-1");
            }
        }