Exemplo n.º 1
0
        public void Steam2RenderIsValid()
        {
            SteamID sid = 76561197969249708;

            Assert.Equal("STEAM_0:0:4491990", sid.Render(steam3: false));

            sid.AccountUniverse = EUniverse.Beta;
            Assert.Equal("STEAM_2:0:4491990", sid.Render(steam3: false));

            sid.AccountType = EAccountType.GameServer;
            Assert.Equal("157625991261918636", sid.Render(steam3: false));
        }
Exemplo n.º 2
0
        public void RendersSteam3ByDefault()
        {
            SteamID sid = 76561197969249708;

            Assert.Equal("[U:1:8983980]", sid.Render());
            Assert.Equal("[U:1:8983980]", sid.ToString());
        }
Exemplo n.º 3
0
        static void OnFriendsList(SteamFriends.FriendsListCallback callback)
        {
            // at this point, the client has received it's friends list

            int friendCount = steamFriends.GetFriendCount();

            Console.WriteLine("We have {0} friends", friendCount);

            for (int x = 0; x < friendCount; x++)
            {
                // steamids identify objects that exist on the steam network, such as friends, as an example
                SteamID steamIdFriend = steamFriends.GetFriendByIndex(x);

                // we'll just display the STEAM_ rendered version
                Console.WriteLine("Friend: {0}", steamIdFriend.Render());
            }

            // we can also iterate over our friendslist to accept or decline any pending invites

            foreach (var friend in callback.FriendList)
            {
                if (friend.Relationship == EFriendRelationship.RequestRecipient)
                {
                    // this user has added us, let's add him back
                    steamFriends.AddFriend(friend.SteamID);
                }
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Saves a new admin.
 /// </summary>
 private void SaveAdmin(SteamID steamID)
 {
     using (var file = new StreamWriter(_adminListPath))
     {
         file.WriteLine(steamID.Render());
         file.Flush();
     }
 }
Exemplo n.º 5
0
        public void updateName(SteamID updatedID)
        {
            if (!master.Contains(updatedID))
            {
                master.Add(updatedID);
            }

            if (!indexHelper.Contains(updatedID) && !updatedID.AccountType.Equals(EAccountType.Clan))
            {
                if (!((steamFriends.GetFriendPersonaState(updatedID).Equals(EPersonaState.Offline) && checkBox1.Checked) || (steamFriends.GetFriendPersonaState(updatedID).Equals(EPersonaState.Busy) && checkBox2.Checked) || (steamFriends.GetFriendPersonaState(updatedID).Equals(EPersonaState.Away) && checkBox3.Checked) || (steamFriends.GetFriendPersonaState(updatedID).Equals(EPersonaState.Snooze) && checkBox4.Checked)))
                {
                    if (steamFriends.GetFriendPersonaName(updatedID).Equals(""))
                    {
                        checkedListBox1.Items.Add(updatedID.Render());
                    }
                    else
                    {
                        checkedListBox1.Items.Add(steamFriends.GetFriendPersonaName(updatedID));
                    }
                    indexHelper.Add(updatedID);
                }
            }
            else if (indexHelper.Contains(updatedID))
            {
                if (!((steamFriends.GetFriendPersonaState(updatedID).Equals(EPersonaState.Offline) && checkBox1.Checked) || (steamFriends.GetFriendPersonaState(updatedID).Equals(EPersonaState.Busy) && checkBox2.Checked) || (steamFriends.GetFriendPersonaState(updatedID).Equals(EPersonaState.Away) && checkBox3.Checked) || (steamFriends.GetFriendPersonaState(updatedID).Equals(EPersonaState.Snooze) && checkBox4.Checked)))
                {
                    checkedListBox1.Items[indexHelper.IndexOf(updatedID)] = steamFriends.GetFriendPersonaName(updatedID);
                }
            }

            if (indexHelper.Contains(updatedID))
            {
                if (steamFriends.GetFriendPersonaState(updatedID).Equals(EPersonaState.Offline) && checkBox1.Checked)
                {
                    checkedListBox1.Items.RemoveAt(indexHelper.IndexOf(updatedID));
                    indexHelper.Remove(updatedID);
                }

                if (steamFriends.GetFriendPersonaState(updatedID).Equals(EPersonaState.Busy) && checkBox2.Checked)
                {
                    checkedListBox1.Items.RemoveAt(indexHelper.IndexOf(updatedID));
                    indexHelper.Remove(updatedID);
                }

                if (steamFriends.GetFriendPersonaState(updatedID).Equals(EPersonaState.Away) && checkBox3.Checked)
                {
                    checkedListBox1.Items.RemoveAt(indexHelper.IndexOf(updatedID));
                    indexHelper.Remove(updatedID);
                }

                if (steamFriends.GetFriendPersonaState(updatedID).Equals(EPersonaState.Snooze) && checkBox4.Checked)
                {
                    checkedListBox1.Items.RemoveAt(indexHelper.IndexOf(updatedID));
                    indexHelper.Remove(updatedID);
                }
            }
        }
Exemplo n.º 6
0
        public static bool IsBlacklisted(this SteamID steamID, uint game = TitanAccount.CSGO_APPID)
        {
            if (Titan.Instance.Options.DisableBlacklist)
            {
                return(false);
            }

            switch (game)
            {
            case TitanAccount.CSGO_APPID:
                return(CSGOBlackList.Contains(steamID.Render(false)));

            case TitanAccount.TF2_APPID:
                return(TF2BlackList.Contains(steamID.Render(false)));

            default:
                return(false);
            }
        }
Exemplo n.º 7
0
        public static string ExpandSteamID(SteamID input)
        {
            string displayInstance = input.AccountInstance.ToString();

            switch (input.AccountInstance)
            {
            case SteamID.AllInstances:
                displayInstance = "all (0)";
                break;

            case SteamID.DesktopInstance:
                displayInstance = "desktop (1)";
                break;

            case SteamID.ConsoleInstance:
                displayInstance = "console (2)";
                break;

            case SteamID.WebInstance:
                displayInstance = "web (4)";
                break;

            case ( uint )SteamID.ChatInstanceFlags.Clan:
                displayInstance = "clan (524288 / 0x80000)";
                break;

            case ( uint )SteamID.ChatInstanceFlags.Lobby:
                displayInstance = "lobby (262144 / 0x40000)";
                break;

            case ( uint )SteamID.ChatInstanceFlags.MMSLobby:
                displayInstance = "mms lobby (131072 / 0x20000)";
                break;
            }

            return(string.Format("{0} / {1} (UInt64 = {2}, IsValid = {3}, Universe = {4}, Instance = {5}, Type = {6}, AccountID = {7})",
                                 input.Render(), input.Render(true), input.ConvertToUInt64(), input.IsValid, input.AccountUniverse, displayInstance, input.AccountType, input.AccountID));
        }
Exemplo n.º 8
0
        /*
         * From VoiDeD's bot: https://github.com/VoiDeD/steam-irc-bot/blob/cedb7636e529fa226188ce102f5ee1337f8bed63/SteamIrcBot/Utils/Utils.cs#L191
         */
        private static string ExpandSteamID(SteamID input)
        {
            string displayInstance = input.AccountInstance.ToString();

            switch (input.AccountInstance)
            {
            case SteamID.AllInstances:
                displayInstance = "All";
                break;

            case SteamID.DesktopInstance:
                displayInstance = "Desktop";
                break;

            case SteamID.ConsoleInstance:
                displayInstance = "Console";
                break;

            case SteamID.WebInstance:
                displayInstance = "Web";
                break;

            case (uint)SteamID.ChatInstanceFlags.Clan:
                displayInstance = "Clan";
                break;

            case (uint)SteamID.ChatInstanceFlags.Lobby:
                displayInstance = "Lobby";
                break;

            case (uint)SteamID.ChatInstanceFlags.MMSLobby:
                displayInstance = "MMS Lobby";
                break;
            }

            return(string.Format("{0} / {1} {2}(UInt64: {3}, AccountID: {4}, IsValid: {5}, Universe: {6}, Instance: {7}, Type: {8})",
                                 input.Render(), input.Render(true), Colors.DARKGRAY, input.ConvertToUInt64(), input.AccountID, input.IsValid, input.AccountUniverse, displayInstance, input.AccountType));
        }
Exemplo n.º 9
0
        private void OnFriendsList(SteamFriends.FriendsListCallback callback)
        {
            Console.WriteLine($"We have {SteamFriends.GetFriendCount()} friends");

            foreach (var friend in callback.FriendList)
            {
                SteamID steamIdFriend = friend.SteamID;
                if (friend.Relationship == EFriendRelationship.RequestRecipient)
                {
                    SteamFriends.AddFriend(steamIdFriend);
                }
                Console.WriteLine($"Friend: {steamIdFriend.Render()}");
            }
        }
Exemplo n.º 10
0
        /*
         * From VoiDeD's bot: https://github.com/VoiDeD/steam-irc-bot/blob/cedb7636e529fa226188ce102f5ee1337f8bed63/SteamIrcBot/Utils/Utils.cs#L191
         */
        private static string ExpandSteamID(SteamID input)
        {
            var displayInstance = input.AccountInstance switch
            {
                SteamID.AllInstances => "All",
                SteamID.DesktopInstance => "Desktop",
                SteamID.ConsoleInstance => "Console",
                SteamID.WebInstance => "Web",
                (uint)SteamID.ChatInstanceFlags.Clan => "Clan",
                (uint)SteamID.ChatInstanceFlags.Lobby => "Lobby",
                (uint)SteamID.ChatInstanceFlags.MMSLobby => "MMS Lobby",
                _ => input.AccountInstance.ToString()
            };

            return($"{input.Render()} / {input.ConvertToUInt64()} {Colors.DARKGRAY}(AccountID: {input.AccountID}, Universe: {input.AccountUniverse}, Instance: {displayInstance}, Type: {input.AccountType}){(input.IsValid ? "" : $"{Colors.RED} (not valid)")}");
        }
Exemplo n.º 11
0
        public async Task <IHttpActionResult> GetOneForEnhancedSteam(ulong steamId64)
        {
            var steamId = new SteamID(steamId64);
            var user    = await _userManager.FindBySteamIdAsync(steamId.Render(true));

            if (user == null)
            {
                return(NotFound());
            }
            var steamCnUid = await _userManager.GetSteamCnUidAsync(user.Id);

            return(Ok(new
            {
                KeylolLink = $"https://www.keylol.com/user/{user.IdCode}",
                SteamCnLink = steamCnUid == null ? null : $"http://steamcn.com/?{steamCnUid}"
            }));
        }
Exemplo n.º 12
0
        public void Steam3StringSymmetric()
        {
            var steamIds = new[]
            {
                "[U:1:123]",
                "[U:1:123:2]",
                "[G:1:626]",
                "[A:2:165:1234]",
            };

            foreach (var steamId in steamIds)
            {
                SteamID sid    = new SteamID();
                bool    parsed = sid.SetFromSteam3String(steamId);
                Assert.True(parsed);
                Assert.Equal(steamId, sid.Render(steam3: true));
            }
        }
Exemplo n.º 13
0
        public bool Add(string steamID)
        {
            var parsedSID = new SteamID(steamID);

            if (!parsedSID.IsValid)
            {
                return(false);
            }

            if (config.Data.Users.Contains(parsedSID.Render()))
            {
                return(false);
            }
            else
            {
                config.Data.Users.Add(steamID);
                config.Save();
            }

            return(true);
        }
Exemplo n.º 14
0
        static void OnFriendsList(SteamFriends.FriendsListCallback callback)
        {
            int friendCount = steamFriends.GetFriendCount();

            Console.WriteLine($"[SteamBot] Bot has {0} friends", friendCount);

            for (int x = 0; x < friendCount; x++)
            {
                SteamID steamIdFriend = steamFriends.GetFriendByIndex(x);

                Console.WriteLine($"[SteamBot] Friend: {0}", steamIdFriend.Render());
            }


            foreach (var friend in callback.FriendList)
            {
                if (friend.Relationship == EFriendRelationship.RequestRecipient)
                {
                    steamFriends.AddFriend(friend.SteamID);
                }
            }
        }
Exemplo n.º 15
0
        static void OnFriendsList(SteamFriends.FriendsListCallback callback)
        {
            // at this point, the client has received it's friends list

            int friendCount = steamFriends.GetFriendCount();

            Console.WriteLine("We have {0} friends", friendCount);

            for (int x = 0; x < friendCount; x++)
            {
                // steamids identify objects that exist on the steam network, such as friends, as an example
                SteamID steamIdFriend = steamFriends.GetFriendByIndex(x);


                AccountController.getAccount(user).AddFriend(new Friend()
                {
                    steamFrindsID = "" + steamIdFriend.ConvertToUInt64().ToString(), chatLog = new ArrayList(), SteamIDObject = steamIdFriend
                });

                // we'll just display the STEAM_ rendered version
                Console.WriteLine("Friend: {0}", steamIdFriend.Render());
            }

            // we can also iterate over our friendslist to accept or decline any pending invites
            if (SteamTwoProperties.jsonSetting.autoAddFriendSetting)
            {
                foreach (var friend in callback.FriendList)
                {
                    if (friend.Relationship == EFriendRelationship.RequestRecipient)
                    {
                        // this user has added us, let's add him back
                        steamFriends.AddFriend(friend.SteamID);
                    }
                }
            }
        }
Exemplo n.º 16
0
        internal User(string name, SteamID id, EPersonaState state, byte[] bhash, List <Message> msgs = null, int newmsg = 0)
        {
            this._Game = null;
            if (msgs == null)
            {
                this._Messages = new List <Message>();
            }
            else
            {
                this._Messages = msgs;
            }
            this._NewMessages = newmsg;
            string steamid = id.Render();

            this._AccountID = id.AccountID;
            ulong id64 = id.ConvertToUInt64();

            this._Name      = name ?? steamid;
            this._SteamID   = id;
            this._SteamID64 = id64;
            this._State     = state;
            this._Avatar    = this.CreateAvatar(bhash);
            this._Extra     = null;
        }
Exemplo n.º 17
0
        static void groupChatCommands(string command, string Message, SteamID steamID, SteamID chatID)
        {
            string[] args;
            string   name;

            switch (command.ToLower())
            {
                //Commands go here: "!" for user commands, "#" for admin commands.
                #region Announce message to all in friendslist
            case "#announce":
                args = separate(1, ' ', Message);
                if (args[0] == "-1")
                {
                    return;
                }

                Console.WriteLine("Bot is attempting to announce: {0}\n", args[1]);

                int friendCount = SteamBot.steamFriends.GetFriendCount();

                for (int x = 0; x < friendCount; x++)
                {
                    SteamID       steamIdFriend = SteamBot.steamFriends.GetFriendByIndex(x);
                    EPersonaState personaState  = SteamBot.steamFriends.GetFriendPersonaState(steamIdFriend);

                    //This prevents bot from messaging people who are in any other state than "Online" - including busy, away etc.
                    if (personaState.ToString() == "Online")
                    {
                        SteamBot.steamFriends.SendChatMessage(steamIdFriend, EChatEntryType.ChatMsg, args[1]);
                        Console.WriteLine("{0} : {1}", steamIdFriend.Render(), args[1]);
                    }
                }
                break;
                #endregion

                #region Add Admin
            case "#addadmin":
                args = separate(1, ' ', Message);
                if (args[0] == "-1")
                {
                    return;
                }

                Json.Config.addAdmin(args[1]);

                SteamBot.steamFriends.SendChatMessage(steamID, EChatEntryType.ChatMsg,
                                                      "User was added as admin. ID: " + args[1]
                                                      );
                break;
                #endregion

                #region Reload Config
            case "#reloadconfig":
                Json.Config.reloadConfig();
                SteamBot.steamFriends.SendChatRoomMessage(chatID, EChatEntryType.ChatMsg, "Config was reloaded by user");
                Console.WriteLine("Config was reloaded by user: {0}", steamID);
                break;
                #endregion

                #region Request Gather Status
            case "!status":


                break;
                #endregion

                #region Am I admin?
            case "!amiadmin":
                Json.Config.reloadConfig();
                SteamBot.steamFriends.RequestFriendInfo(steamID, EClientPersonaStateFlag.PlayerName);
                name = SteamBot.steamFriendsName;

                if (Json.Config.isAdmin(steamID) == true)
                {
                    SteamBot.steamFriends.SendChatRoomMessage(chatID, EChatEntryType.ChatMsg, name + " has admin privileges!");
                }
                else
                {
                    SteamBot.steamFriends.SendChatRoomMessage(chatID, EChatEntryType.ChatMsg, name + " does not have admin privileges!");
                }
                break;
                #endregion

                #region Add Friend
            case "#addfriend":
                args = separate(1, ' ', Message);

                Console.WriteLine("Attempting to add friend: {0}", args[1]);

                SteamBot.steamFriends.AddFriend(Convert.ToUInt64(args[1]));
                break;
                #endregion

                #region Set Persona Name
            case "#personaname":
                args = separate(1, ' ', Message);
                SteamBot.steamFriends.SetPersonaName(args[1]);
                break;
                #endregion
            }
        }
        void OnFriendsList(SteamFriends.FriendsListCallback callback)
        {
            // at this point, the client has received it's friends list

            int friendCount = _steamFriends.GetFriendCount();

            Console.WriteLine("We have {0} friends", friendCount);

            for (int x = 0; x < friendCount; x++)
            {
                // steamids identify objects that exist on the steam network, such as friends, as an example
                SteamID steamIdFriend = _steamFriends.GetFriendByIndex(x);
                // we'll just display the STEAM_ rendered version
                Console.WriteLine("Friend: {0}", steamIdFriend.Render());

                if (_cmd == Command.SendAll)
                {
                    _steamFriends.SendChatMessage(steamIdFriend, EChatEntryType.ChatMsg, _messageText);
                    Thread.Sleep(500);
                }
                else if (_cmd == Command.SendSingle)
                {
                    if (_userId == steamIdFriend.ConvertToUInt64().ToString())
                    {
                        _steamFriends.SendChatMessage(steamIdFriend, EChatEntryType.ChatMsg, _messageText);
                        _isMessageSent = true;
                        break;
                    }
                }
                else if (_cmd == Command.AcceptFriends)
                {
                    foreach (var friend in callback.FriendList)
                    {
                        if (friend.Relationship == EFriendRelationship.RequestRecipient)
                        {
                            // this _user has added us, let's add him back and send him a message
                            _steamFriends.AddFriend(friend.SteamID);
                            _steamFriends.SendChatMessage(friend.SteamID, EChatEntryType.ChatMsg, _messageText);
                            _isMessageSent = true;
                        }
                    }
                }
                else if (_cmd == Command.GetAllIds)
                {
                    foreach (var friend in callback.FriendList)
                    {
                        if (!_friendsIds.ContainsKey(friend.SteamID.ConvertToUInt64().ToString()))
                        {
                            var val = _steamFriends.RequestProfileInfo(friend.SteamID).ToTask().Result;
                            _friendsIds[friend.SteamID.ConvertToUInt64().ToString()] = val.RealName;
                        }
                    }
                    _isMessageSent = true;
                }
                else if (_cmd == Command.GetFriendInfo)
                {
                    if (_userId == steamIdFriend.ConvertToUInt64().ToString())
                    {
                        var val = _steamFriends.RequestProfileInfo(steamIdFriend).ToTask().Result;
                        _friendInfoVm.country    = val.CountryName;
                        _friendInfoVm.summary    = val.Summary;
                        _friendInfoVm.realName   = val.RealName;
                        _friendInfoVm.headline   = val.Headline;
                        _friendInfoVm.state      = val.StateName;
                        _friendInfoVm.steamId    = steamIdFriend.ToString();
                        _friendInfoVm.profileUrl = "https://steamcommunity.com/profiles/" + steamIdFriend.ConvertToUInt64().ToString();
                        string html;
                        using (WebClient client = new WebClient())
                        {
                            client.Headers[HttpRequestHeader.UserAgent] = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2";
                            html = client.DownloadString("https://steamid.xyz/" + val.SteamID.ConvertToUInt64().ToString());
                        }
                        _friendInfoVm.image_url = GetImagesInHTMLString(html);
                        _isMessageSent          = true;
                    }
                }
            }
            if (_cmd == Command.SendAll)
            {
                _isMessageSent = true;
            }
        }
Exemplo n.º 19
0
        void DumpType(object obj, TreeNode node)
        {
            Type propType = (obj != null ? obj.GetType() : null);

            if (obj == null)
            {
                node.Text += "<null>";
                return;
            }

            if (propType != null)
            {
                if (propType.IsValueType)
                {
                    node.Text += obj.ToString();
                    return;
                }
                else if (propType == typeof(string))
                {
                    node.Text += string.Format("\"{0}\"", obj);
                    return;
                }
                else if (propType == typeof(SteamID))
                {
                    SteamID sId = obj as SteamID;
                    node.Text += string.Format("{0} ({1}) ", sId.ConvertToUInt64(), sId.Render());
                }
                else if (obj is byte[])
                {
                    byte[] data = obj as byte[];

                    node.Text += string.Format("byte[ {0} ]", data.Length);

                    if (data.Length == 0)
                    {
                        return;
                    }

                    node.ContextMenu = new ContextMenu(new[] {
                        new MenuItem("Save to File...", delegate(object sender, EventArgs e)
                        {
                            var dialog = new SaveFileDialog {
                                DefaultExt = "bin", SupportMultiDottedExtensions = true
                            };
                            var result = dialog.ShowDialog(this);
                            if (result == DialogResult.OK)
                            {
                                File.WriteAllBytes(dialog.FileName, data);
                            }
                        }),
                    });

                    const int MaxBinLength = 400;
                    if (data.Length > MaxBinLength)
                    {
                        node.Nodes.Add(string.Format("Length exceeded {0} bytes!", MaxBinLength));
                        return;
                    }

                    Action <object> setAsRadioSelected = delegate(object sender)
                    {
                        var senderItem = (MenuItem)sender;
                        foreach (MenuItem item in senderItem.Parent.MenuItems)
                        {
                            item.Checked = false;
                        }
                        senderItem.Checked = true;
                    };

                    node.ContextMenu.MenuItems.Add(new MenuItem("-"));    // Separator

                    MenuItem intialMenuItem;

                    node.ContextMenu.MenuItems.Add(new MenuItem("Display as ASCII", delegate(object sender, EventArgs e)
                    {
                        setAsRadioSelected(sender);
                        node.Nodes.Clear();

                        var strAscii = Encoding.ASCII.GetString(data).Replace("\0", "\\0");
                        node.Nodes.Add(strAscii);
                        node.Expand();
                    })
                    {
                        RadioCheck = true
                    });

                    node.ContextMenu.MenuItems.Add(new MenuItem("Display as UTF-8", delegate(object sender, EventArgs e)
                    {
                        setAsRadioSelected(sender);
                        node.Nodes.Clear();

                        var strUnicode = Encoding.UTF8.GetString(data).Replace("\0", "\\0");
                        node.Nodes.Add(strUnicode);
                        node.Expand();
                    })
                    {
                        RadioCheck = true
                    });

                    node.ContextMenu.MenuItems.Add((intialMenuItem = new MenuItem("Display as Hexadecimal", delegate(object sender, EventArgs e)
                    {
                        setAsRadioSelected(sender);
                        node.Nodes.Clear();

                        var hexString = data.Aggregate(new StringBuilder(), (str, value) => str.Append(value.ToString("X2"))).ToString();
                        node.Nodes.Add(hexString);
                        node.Expand();
                    })
                    {
                        RadioCheck = true, Checked = true
                    }));

                    node.ContextMenu.MenuItems.Add(new MenuItem("Display as Binary KeyValues", delegate(object sender, EventArgs e)
                    {
                        setAsRadioSelected(sender);
                        node.Nodes.Clear();

                        var kv = new KeyValue();
                        bool didRead;
                        using (var ms = new MemoryStream(data))
                        {
                            try
                            {
                                didRead = kv.ReadAsBinary(ms);
                            }
                            catch (InvalidDataException)
                            {
                                didRead = false;
                            }
                        }

                        if (!didRead)
                        {
                            node.Nodes.Add("Not a valid KeyValues object!");
                        }
                        else
                        {
                            node.Nodes.Add(BuildKeyValuesNode(kv.Children[0]));
                        }

                        node.ExpandAll();
                    })
                    {
                        RadioCheck = true
                    });

                    intialMenuItem.PerformClick();

                    return;
                }
                else if (TypeIsDictionary(propType))
                {
                    IDictionary dict = obj as IDictionary;
                    foreach (DictionaryEntry pair in dict)
                    {
                        TreeNode subNode = new TreeNode(string.Format(
                                                            "[ {0} ]: ", pair.Key.ToString()));
                        node.Nodes.Add(subNode);

                        DumpType(pair.Value, subNode);
                    }

                    return;
                }
                else if (TypeIsArray(propType))
                {
                    Type innerType = null;
                    int  count     = 0;
                    bool truncated = false;


                    foreach (var subObj in obj as IEnumerable)
                    {
                        innerType = subObj.GetType();

                        count++;

                        if (count <= 100)
                        {
                            TreeNode subNode = new TreeNode(string.Format(
                                                                "[ {0} ]: {1}",
                                                                count - 1,
                                                                (innerType.IsValueType ? "" : innerType.Name)
                                                                ));
                            node.Nodes.Add(subNode);

                            DumpType(subObj, subNode);
                        }
                        else
                        {
                            truncated = true;
                        }
                    }

                    if (truncated)
                    {
                        TreeNode truncNode = new TreeNode("Array truncated: more than 100 entries!");
                        node.Nodes.Add(truncNode);
                    }

                    node.Text += string.Format(
                        "{0}[ {1} ]",
                        (innerType == null ? propType.Name : innerType.Name),
                        count
                        );

                    return;
                }

                node.Text += propType.Name;
            }

            foreach (var property in obj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                var      subObject = property.GetValue(obj, null);
                TreeNode subNode   = new TreeNode(property.Name + ": ");
                node.Nodes.Add(subNode);

                DumpType(subObject, subNode);
            }
        }
Exemplo n.º 20
0
        private void OnDelayedActionReceived(object sender, BasicDeliverEventArgs basicDeliverEventArgs)
        {
            try
            {
                using (var streamReader = new StreamReader(new MemoryStream(basicDeliverEventArgs.Body)))
                {
                    var serializer = new JsonSerializer();
                    var actionDto  =
                        serializer.Deserialize <SteamBotDelayedActionDto>(new JsonTextReader(streamReader));
                    switch (actionDto.Type)
                    {
                    case SteamBotDelayedActionType.SendChatMessage:
                    {
                        var steamId = new SteamID();
                        steamId.SetFromSteam3String((string)actionDto.Properties.SteamId);
                        var message = (string)actionDto.Properties.Message;
                        SteamFriends.SendChatMessage(steamId, EChatEntryType.ChatMsg, message);
                        try
                        {
                            if ((bool)actionDto.Properties.LogMessage)
                            {
                                var friendName = SteamFriends.GetFriendPersonaName(steamId);
                                _logger.Info($"#{SequenceNumber} [Chat TX] To {friendName} ({steamId}): {message}");
                            }
                        }
                        catch (RuntimeBinderException)
                        {
                        }
                        break;
                    }

                    case SteamBotDelayedActionType.RemoveFriend:
                    {
                        var steamId = new SteamID();
                        steamId.SetFromSteam3String((string)actionDto.Properties.SteamId);
                        var skip = SteamFriends.GetFriendRelationship(steamId) != EFriendRelationship.Friend;
                        try
                        {
                            if (!skip && (bool)actionDto.Properties.OnlyIfNotKeylolUser)
                            {
                                var result = _coordinator.Consume(
                                    coordinator => coordinator.IsKeylolUser(steamId.Render(true), Id));
                                if (!result.HasNoException || result.Value)
                                {
                                    skip = true;
                                }
                            }
                        }
                        catch (RuntimeBinderException)
                        {
                        }
                        if (!skip)
                        {
                            try
                            {
                                SteamFriends.SendChatMessage(steamId, EChatEntryType.ChatMsg,
                                                             (string)actionDto.Properties.Message);
                            }
                            catch (RuntimeBinderException)
                            {
                            }
                            SteamFriends.RemoveFriend(steamId);
                        }
                        break;
                    }

                    default:
                        _logger.Fatal($"#{SequenceNumber} Invalid delay action type: {actionDto.Type}.");
                        break;
                    }
                    _mqChannel.BasicAck(basicDeliverEventArgs.DeliveryTag, false);
                }
            }
            catch (Exception e)
            {
                _mqChannel.BasicNack(basicDeliverEventArgs.DeliveryTag, false, false);
                _logger.Fatal($"#{SequenceNumber} Unhandled MQ consumer exception.", e);
            }
        }
Exemplo n.º 21
0
        public void RendersOutOfRangeAccountTypeAsLowercaseI()
        {
            SteamID sid = new SteamID(123, EUniverse.Beta, (EAccountType)(-1));

            Assert.Equal("[i:2:123]", sid.Render(steam3: true));
        }
 static void AddSteamIDValue(TreeNode node, SteamID steamID)
 {
     SetNodeValueWithCopyMenu(node, string.Format("{0} ({1}) ", steamID.Render(steam3: true), steamID.ConvertToUInt64()));
 }
Exemplo n.º 23
0
        void DumpType(object obj, TreeNode node)
        {
            Type propType = (obj != null ? obj.GetType() : null);

            if (obj == null)
            {
                node.Text += "<null>";
                return;
            }

            if (propType != null)
            {
                if (propType.IsValueType)
                {
                    node.Text += obj.ToString();
                    return;
                }
                else if (propType == typeof(string))
                {
                    node.Text += string.Format("\"{0}\"", obj);
                    return;
                }
                else if (propType == typeof(SteamID))
                {
                    SteamID sId = obj as SteamID;
                    node.Text += string.Format("{0} ({1}) ", sId.ConvertToUInt64(), sId.Render());
                }
                else if (obj is byte[])
                {
                    byte[] data = obj as byte[];

                    node.Text += string.Format("byte[ {0} ]", data.Length);

                    if (data.Length == 0)
                    {
                        return;
                    }

                    const int MaxBinLength = 400;
                    if (data.Length > MaxBinLength)
                    {
                        node.Nodes.Add(string.Format("Length exceeded {0} bytes!", MaxBinLength));
                        return;
                    }

                    string strAscii   = Encoding.ASCII.GetString(data).Replace("\0", "\\0");
                    string strUnicode = Encoding.UTF8.GetString(data).Replace("\0", "\\0");
                    string hexString  = data.Aggregate(new StringBuilder(), (str, value) => str.Append(value.ToString("X2"))).ToString();

                    node.Nodes.Add(string.Format("{0}: {1}", "ASCII", strAscii));
                    node.Nodes.Add(string.Format("{0}: {1}", "UTF8", strUnicode));
                    node.Nodes.Add(string.Format("{0}: {1}", "Binary", hexString));

                    return;
                }
                else if (TypeIsDictionary(propType))
                {
                    IDictionary dict = obj as IDictionary;
                    foreach (DictionaryEntry pair in dict)
                    {
                        TreeNode subNode = new TreeNode(string.Format(
                                                            "[ {0} ]: ", pair.Key.ToString()));
                        node.Nodes.Add(subNode);

                        DumpType(pair.Value, subNode);
                    }

                    return;
                }
                else if (TypeIsArray(propType))
                {
                    Type innerType = null;
                    int  count     = 0;
                    bool truncated = false;


                    foreach (var subObj in obj as IEnumerable)
                    {
                        innerType = subObj.GetType();

                        count++;

                        if (count <= 100)
                        {
                            TreeNode subNode = new TreeNode(string.Format(
                                                                "[ {0} ]: {1}",
                                                                count - 1,
                                                                (innerType.IsValueType ? "" : innerType.Name)
                                                                ));
                            node.Nodes.Add(subNode);

                            DumpType(subObj, subNode);
                        }
                        else
                        {
                            truncated = true;
                        }
                    }

                    if (truncated)
                    {
                        TreeNode truncNode = new TreeNode("Array truncated: more than 100 entries!");
                        node.Nodes.Add(truncNode);
                    }

                    node.Text += string.Format(
                        "{0}[ {1} ]",
                        (innerType == null ? propType.Name : innerType.Name),
                        count
                        );

                    return;
                }

                node.Text += propType.Name;
            }

            foreach (var property in obj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                var      subObject = property.GetValue(obj, null);
                TreeNode subNode   = new TreeNode(property.Name + ": ");
                node.Nodes.Add(subNode);

                DumpType(subObject, subNode);
            }
        }
Exemplo n.º 24
0
 public static bool IsBlacklisted(SteamID steamID)
 {
     return(!Titan.Instance.Options.DisableBlacklist && BlackList.Contains(steamID.Render()));
 }