示例#1
0
        private SteamProfileInfos LoadSteamProfile(SteamTrade.SteamWeb steamWeb, SteamID steamID)
        {
            if (LastTimeRefreshed == null || (DateTime.Now - LastTimeRefreshed).TotalMinutes > 5)
            {
                LastTimeRefreshed = DateTime.Now;
                string response = steamWeb.Fetch("http://steamcommunity.com/profiles/" + steamID.ConvertToUInt64() + "/?xml=1", "GET");

                if (response != String.Empty)
                {
                    response = response.Replace("\t", "").Replace("\n", "").Replace("\r", "").Trim();
                    int index = response.IndexOf("<profile>");
                    if (index != -1)
                    {
                        response = response.Substring(index);
                        XmlSerializer serializer = new XmlSerializer(typeof(SteamProfileInfos));
                        using (TextReader reader = new StringReader(response))
                        {
                            backup = (SteamProfileInfos)serializer.Deserialize(reader);
                            return(backup);
                        }
                    }
                }
            }

            return(backup);
        }
示例#2
0
        public static string GetCountryCode(SteamProfileInfos sp)
        {
            if (sp == null)
            {
                return("en");
            }
            else
            {
                string country = sp.Location;
                country = RemoveBetween(country.Split(' ')[0], '(', ')').Trim();

                var        regions       = CultureInfo.GetCultures(CultureTypes.SpecificCultures).Select(x => new RegionInfo(x.LCID));
                RegionInfo englishRegion = regions.FirstOrDefault(region => region.EnglishName.Contains(country));

                if (englishRegion == null)
                {
                    Console.WriteLine("Country \"" + country + "\" not found !");
                    return("en");
                }
                else
                {
                    return(englishRegion.TwoLetterISORegionName.ToLower());
                }
            }
        }
示例#3
0
        private void PrintChatMessage(SteamID partenar, string message, string[] data = null)
        {
            string sentences = "";

            data = data ?? new string[0];

            try
            {
                SteamProfileInfos spi = bot.GetSteamProfileInfo(partenar);
                sentences = String.Format(bot.Translation.GetSentence(message, CountryCode.GetCountryCode(spi)), data);
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(ex);
                Console.ForegroundColor = ConsoleColor.White;
                sentences = "Error while loading the response... Sorry!";
            }

            foreach (string s in sentences.Split(new string[] { "\\n" }, StringSplitOptions.None))
            {
                //Timeout to prevent spam here.
                SendChatMessage(partenar, s);
            }
        }
示例#4
0
        private void PrintChatMessage(SteamID partenar, string message)
        {
            SteamProfileInfos spi       = bot.GetSteamProfileInfo(partenar);
            string            sentences = bot.Translation.GetSentence(message, CountryCode.GetCountryCode(spi.Location));

            foreach (string s in sentences.Split(new string[] { "\\n" }, StringSplitOptions.None))
            {
                SendChatMessage(partenar, s);
            }
        }
示例#5
0
        private void PrintChatMessage(SteamID partenar, string message, string[] data = null)
        {
            data = data ?? new string[0];

            SteamProfileInfos spi = bot.GetSteamProfileInfo(partenar);

            string sentences = String.Format(bot.Translation.GetSentence(message, CountryCode.GetCountryCode(spi)), data);

            foreach (string s in sentences.Split(new string[] { "\\n" }, StringSplitOptions.None))
            {
                SendChatMessage(partenar, s);
            }
        }
示例#6
0
        public static string GetCountryCode(SteamProfileInfos sp)
        {
            try
            {
                if (sp == null)
                {
                    return("en");
                }
                else
                {
                    string country = sp.Location.Substring(sp.Location.LastIndexOf(" ") + 1);
                    country = RemoveBetween(country.Split(' ')[0], '(', ')').Trim();

                    var        regions       = CultureInfo.GetCultures(CultureTypes.SpecificCultures).Select(x => new RegionInfo(x.LCID));
                    RegionInfo englishRegion = regions.FirstOrDefault(region => region.EnglishName.Contains(country));

                    if (englishRegion == null)
                    {
                        Console.WriteLine("Country \"" + country + "\" not found !");
                        return("en");
                    }
                    else
                    {
                        return(englishRegion.TwoLetterISORegionName.ToLower());
                    }
                }
            }
            catch (Exception e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Error while fetching country code. Assumed 'en'. Details here : ");
                if (sp.Location == null)
                {
                    Console.WriteLine("Location null !");
                }
                else
                {
                    Console.WriteLine("Faulty country >>> " + sp.Location.Substring(sp.Location.LastIndexOf(" ") + 1));
                }
                Console.WriteLine("Send to Arkarr please!");
                Console.ForegroundColor = ConsoleColor.White;

                return("en");
            }
        }
示例#7
0
        private void ReportPlayer(Bot bot, GameServerRequest gsr)
        {
            GameServer gs = bot.Manager.GetServerByID(gsr.ServerID);

            string[] ids          = gsr.Arguments.Split('/');
            SteamID  steamID      = GetSteamIDFromString(ids[0]);
            SteamID  reportedDude = GetSteamIDFromString(ids[1]);

            SteamProfileInfos spGuy  = bot.GetSteamProfileInfo(steamID);
            SteamProfileInfos spDude = bot.GetSteamProfileInfo(reportedDude);

            if (spDude != null && spGuy != null)
            {
                string firstMsg = String.Format("{0} ({1}) reported {2} ({3}) for \"{4}\" @ {5} ({6}) !", spGuy.Name, steamID.ToString(), spDude.Name, reportedDude.ToString(), ids[2], DateTime.Now.ToString("dd/MM/yyyy"), DateTime.Now.ToString("HH:mm"));

                /*string[] data = { spGuy.Name, steamID.ToString(), spDude.Name, reportedDude.ToString(), ids[2], DateTime.Now.ToString("dd/MM/yyyy"), DateTime.Now.ToString("HH:mm") };
                 * string firstMsg = String.Format("REPORT_MSG_1", data);*/
                string secondMsg = String.Format("Name of server : {0}", gs.Name);
                string thirdMsg  = String.Format("Direct URL : steam://connect/{0}:{1}", gs.IP, gs.Port);

                foreach (SteamID steamid in bot.Friends)
                {
                    if (bot.Config.IsAdmin(steamid) || bot.Config.IsAdmin(steamid))
                    {
                        bot.SteamFriends.SendChatMessage(steamid, EChatEntryType.ChatMsg, firstMsg);
                        Thread.Sleep(100);
                        bot.SteamFriends.SendChatMessage(steamid, EChatEntryType.ChatMsg, secondMsg);
                        Thread.Sleep(100);
                        bot.SteamFriends.SendChatMessage(steamid, EChatEntryType.ChatMsg, thirdMsg);
                    }
                }
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("One of the following steam ID is wrong !");
                Console.WriteLine("> " + ids[0]);
                Console.WriteLine("> " + ids[1]);
                Console.WriteLine("Report was denied !");
                Console.ForegroundColor = ConsoleColor.White;
            }
        }