ConvertToUInt64() public method

Converts this SteamID into it's 64bit integer form.
public ConvertToUInt64 ( ) : System.UInt64
return System.UInt64
Esempio n. 1
0
        /// <summary>
        /// Logs onto the Steam network as a persistent game server.
        /// The client should already have been connected at this point.
        /// Results are return in a <see cref="SteamUser.LoggedOnCallback"/>.
        /// </summary>
        /// <param name="details">The details to use for logging on.</param>
        /// <exception cref="ArgumentNullException">No logon details were provided.</exception>
        /// <exception cref="ArgumentException">Username or password are not set within <paramref name="details"/>.</exception>
        public void LogOn(LogOnDetails details)
        {
            if (details == null)
            {
                throw new ArgumentNullException("details");
            }

            if (string.IsNullOrEmpty(details.Username) || string.IsNullOrEmpty(details.Password))
            {
                throw new ArgumentException("LogOn requires a username and password to be set in 'details'.");
            }

            var logon = new ClientMsgProtobuf <CMsgClientLogon>(EMsg.ClientLogon);

            SteamID gsId = new SteamID(0, 0, Client.ConnectedUniverse, EAccountType.GameServer);

            logon.ProtoHeader.client_sessionid = 0;
            logon.ProtoHeader.steamid          = gsId.ConvertToUInt64();

            uint localIp = NetHelpers.GetIPAddress(this.Client.LocalIP);

            logon.Body.obfustucated_private_ip = localIp ^ MsgClientLogon.ObfuscationMask;

            logon.Body.protocol_version = MsgClientLogon.CurrentProtocol;

            logon.Body.client_os_type     = ( uint )Utils.GetOSType();
            logon.Body.game_server_app_id = ( int )details.AppID;
            logon.Body.machine_id         = Utils.GenerateMachineID();

            logon.Body.account_name = details.Username;
            logon.Body.password     = details.Password;

            this.Client.Send(logon);
        }
Esempio n. 2
0
        /// <summary>
        /// Invites a user to a chat room.
        /// The results of this action will be available through the <see cref="ChatActionResultCallback"/> callback.
        /// </summary>
        /// <param name="steamIdUser">The SteamID of the user to invite.</param>
        /// <param name="steamIdChat">The SteamID of the chat room to invite the user to.</param>
        public void InviteUserToChat(SteamID steamIdUser, SteamID steamIdChat)
        {
            if (steamIdUser == null)
            {
                throw new ArgumentNullException(nameof(steamIdUser));
            }

            if (steamIdChat == null)
            {
                throw new ArgumentNullException(nameof(steamIdChat));
            }

            SteamID chatId = steamIdChat.ConvertToUInt64(); // copy the steamid so we don't modify it

            if (chatId.IsClanAccount)
            {
                // this steamid is incorrect, so we'll fix it up
                chatId.AccountInstance = (uint)SteamID.ChatInstanceFlags.Clan;
                chatId.AccountType     = EAccountType.Chat;
            }

            var inviteMsg = new ClientMsgProtobuf <CMsgClientChatInvite>(EMsg.ClientChatInvite);

            inviteMsg.Body.steam_id_chat    = chatId;
            inviteMsg.Body.steam_id_invited = steamIdUser;
            // steamclient also sends the steamid of the user that did the invitation
            // we'll mimic that behavior
            inviteMsg.Body.steam_id_patron = Client.SteamID ?? new SteamID();

            this.Client.Send(inviteMsg);
        }
Esempio n. 3
0
        /// <summary>
        /// Logs onto the Steam network as a persistent game server.
        /// The client should already have been connected at this point.
        /// Results are return in a <see cref="SteamUser.LoggedOnCallback"/>.
        /// </summary>
        /// <param name="details">The details to use for logging on.</param>
        /// <exception cref="System.ArgumentNullException">No logon details were provided.</exception>
        /// <exception cref="System.ArgumentException">Username or password are not set within <paramref name="details"/>.</exception>
        public void LogOn( LogOnDetails details )
        {
            if ( details == null )
            {
                throw new ArgumentNullException( "details" );
            }

            if ( string.IsNullOrEmpty( details.Username ) || string.IsNullOrEmpty( details.Password ) )
            {
                throw new ArgumentException( "LogOn requires a username and password to be set in 'details'." );
            }

            var logon = new ClientMsgProtobuf<CMsgClientLogon>( EMsg.ClientLogon );

            SteamID gsId = new SteamID( 0, 0, Client.ConnectedUniverse, EAccountType.GameServer );

            logon.ProtoHeader.client_sessionid = 0;
            logon.ProtoHeader.steamid = gsId.ConvertToUInt64();

            uint localIp = NetHelpers.GetIPAddress( this.Client.LocalIP );
            logon.Body.obfustucated_private_ip = localIp ^ MsgClientLogon.ObfuscationMask;

            logon.Body.protocol_version = MsgClientLogon.CurrentProtocol;

            logon.Body.client_os_type = ( uint )Utils.GetOSType();
            logon.Body.game_server_app_id = ( int )details.AppID;
            logon.Body.machine_id = Utils.GenerateMachineID();

            logon.Body.account_name = details.Username;
            logon.Body.password = details.Password;

            this.Client.Send( logon );
        }
Esempio n. 4
0
        /// <summary>
        /// Logs the client into the Steam3 network as an anonymous user.
        /// The client should already have been connected at this point.
        /// Results are returned in a <see cref="LoggedOnCallback"/>.
        /// </summary>
        /// <param name="details">The details to use for logging on.</param>
        public void LogOnAnonymous(AnonymousLogOnDetails details)
        {
            if (details == null)
            {
                throw new ArgumentNullException(nameof(details));
            }

            if (!this.Client.IsConnected)
            {
                this.Client.PostCallback(new LoggedOnCallback(EResult.NoConnection));
                return;
            }

            var logon = new ClientMsgProtobuf <CMsgClientLogon>(EMsg.ClientLogon);

            SteamID auId = new SteamID(0, 0, Client.Universe, EAccountType.AnonUser);

            logon.ProtoHeader.client_sessionid = 0;
            logon.ProtoHeader.steamid          = auId.ConvertToUInt64();

            logon.Body.protocol_version = MsgClientLogon.CurrentProtocol;
            logon.Body.client_os_type   = ( uint )details.ClientOSType;
            logon.Body.client_language  = details.ClientLanguage;
            logon.Body.cell_id          = details.CellID ?? Client.Configuration.CellID;

            logon.Body.machine_id = HardwareUtils.GetMachineID(Client.Configuration.MachineInfoProvider);

            this.Client.Send(logon);
        }
Esempio n. 5
0
        /// <summary>
        /// Sends a load theirs inventory request.
        /// </summary>
        public void LoadForeignInventory(SteamID backpackId, int appid, int contextid)
        {
            var service    = string.Format(TradeURLAction, "foreigninventory");
            var webRequest = CreateSteamRequest(service, LoginData);

            var fields = new NameValueCollection();

            fields.Add("sessionid", LoginData.SessionId);
            fields.Add("steamid", backpackId.ConvertToUInt64().ToString());
            fields.Add("appid", appid.ToString());
            fields.Add("contextid", contextid.ToString());

            var query     = fields.ConstructQueryString();
            var queryData = Encoding.ASCII.GetBytes(query);

            webRequest.ContentType   = "application/x-www-form-urlencoded";
            webRequest.ContentLength = queryData.Length;

            // Write the request
            using (Stream stream = webRequest.GetRequestStream())
            {
                stream.Write(queryData, 0, queryData.Length);
            }

            // Perform the request
            var res = webRequest.BeginGetResponse(
                new AsyncCallback(ProcessForeignInventory), webRequest);
        }
Esempio n. 6
0
        /// <summary>
        /// Attempts to leave a chat room.
        /// </summary>
        /// <param name="steamId">The SteamID of the chat room.</param>
        public void LeaveChat(SteamID steamId)
        {
            if (steamId == null)
            {
                throw new ArgumentNullException(nameof(steamId));
            }

            SteamID chatId = steamId.ConvertToUInt64(); // copy the steamid so we don't modify it

            var leaveChat = new ClientMsg <MsgClientChatMemberInfo>();

            if (chatId.IsClanAccount)
            {
                // this steamid is incorrect, so we'll fix it up
                chatId.AccountInstance = ( uint )SteamID.ChatInstanceFlags.Clan;
                chatId.AccountType     = EAccountType.Chat;
            }

            leaveChat.Body.SteamIdChat = chatId;
            leaveChat.Body.Type        = EChatInfoType.StateChange;

            var localSteamID = Client.SteamID?.ConvertToUInt64() ?? default; // SteamID can be null if not connected - will be ultimately ignored in Client.Send.

            leaveChat.Write(localSteamID);                                   // ChatterActedOn
            leaveChat.Write(( uint )EChatMemberStateChange.Left);            // StateChange
            leaveChat.Write(localSteamID);                                   // ChatterActedBy

            Client.Send(leaveChat);
        }
Esempio n. 7
0
        /// <summary>
        /// Sends a message to a chat room.
        /// </summary>
        /// <param name="steamIdChat">The SteamID of the chat room.</param>
        /// <param name="type">The message type.</param>
        /// <param name="message">The message.</param>
        public void SendChatRoomMessage(SteamID steamIdChat, EChatEntryType type, string message)
        {
            if (steamIdChat == null)
            {
                throw new ArgumentNullException(nameof(steamIdChat));
            }

            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            SteamID chatId = steamIdChat.ConvertToUInt64(); // copy the steamid so we don't modify it

            if (chatId.IsClanAccount)
            {
                // this steamid is incorrect, so we'll fix it up
                chatId.AccountInstance = ( uint )SteamID.ChatInstanceFlags.Clan;
                chatId.AccountType     = EAccountType.Chat;
            }

            var chatMsg = new ClientMsg <MsgClientChatMsg>();

            chatMsg.Body.ChatMsgType     = type;
            chatMsg.Body.SteamIdChatRoom = chatId;
            chatMsg.Body.SteamIdChatter  = Client.SteamID ?? new SteamID(); // Can be null if not connected - will ultimately be ignored in Client.Send.

            chatMsg.WriteNullTermString(message, Encoding.UTF8);

            this.Client.Send(chatMsg);
        }
Esempio n. 8
0
        /// <summary>
        /// Unbans the specified SteamID from the given chat room.
        /// </summary>
        /// <param name="steamIdChat">The SteamID of chat room to unban the member from.</param>
        /// <param name="steamIdMember">The SteamID of the member to unban from the chat.</param>
        public void UnbanChatMember(SteamID steamIdChat, SteamID steamIdMember)
        {
            if (steamIdChat == null)
            {
                throw new ArgumentNullException(nameof(steamIdChat));
            }

            if (steamIdMember == null)
            {
                throw new ArgumentNullException(nameof(steamIdMember));
            }

            SteamID chatId = steamIdChat.ConvertToUInt64(); // copy the steamid so we don't modify it

            var unbanMember = new ClientMsg <MsgClientChatAction>();

            if (chatId.IsClanAccount)
            {
                // this steamid is incorrect, so we'll fix it up
                chatId.AccountInstance = ( uint )SteamID.ChatInstanceFlags.Clan;
                chatId.AccountType     = EAccountType.Chat;
            }

            unbanMember.Body.SteamIdChat        = chatId;
            unbanMember.Body.SteamIdUserToActOn = steamIdMember;

            unbanMember.Body.ChatAction = EChatAction.UnBan;

            this.Client.Send(unbanMember);
        }
Esempio n. 9
0
        /// <summary>
        /// Logs the client into the Steam3 network as an anonymous game server.
        /// The client should already have been connected at this point.
        /// Results are returned in a <see cref="SteamUser.LoggedOnCallback"/>.
        /// </summary>
        /// <param name="appId">The AppID served by this game server, or 0 for the default.</param>
        public void LogOnAnonymous(uint appId = 0)
        {
            if (!this.Client.IsConnected)
            {
                this.Client.PostCallback(new SteamUser.LoggedOnCallback(EResult.NoConnection));
                return;
            }

            var logon = new ClientMsgProtobuf <CMsgClientLogon>(EMsg.ClientLogon);

            SteamID gsId = new SteamID(0, 0, Client.ConnectedUniverse, EAccountType.AnonGameServer);

            logon.ProtoHeader.client_sessionid = 0;
            logon.ProtoHeader.steamid          = gsId.ConvertToUInt64();

            uint localIp = NetHelpers.GetIPAddress(this.Client.LocalIP);

            logon.Body.obfustucated_private_ip = localIp ^ MsgClientLogon.ObfuscationMask;

            logon.Body.protocol_version = MsgClientLogon.CurrentProtocol;

            logon.Body.client_os_type     = ( uint )Utils.GetOSType();
            logon.Body.game_server_app_id = ( int )appId;
            logon.Body.machine_id         = HardwareUtils.GetMachineID();

            this.Client.Send(logon);
        }
Esempio n. 10
0
 public GenericInventory(SteamID steamId, SteamID botId, bool inTrade = false)
 {
     ConstructTask = Task.Factory.StartNew(() =>
     {
         this.UserId = steamId;
         this.BotId = botId;
         string baseInventoryUrl = "http://steamcommunity.com/profiles/" + steamId.ConvertToUInt64() + "/inventory/";
         string response = RetryWebRequest(baseInventoryUrl, botId);
         Regex reg = new Regex("var g_rgAppContextData = (.*?);");
         Match m = reg.Match(response);
         if (m.Success)
         {
             try
             {
                 string json = m.Groups[1].Value;
                 var schemaResult = JsonConvert.DeserializeObject<Dictionary<int, InventoryApps>>(json);
                 foreach (var app in schemaResult)
                 {
                     int appId = app.Key;
                     InventoryTasks[appId] = new Dictionary<long, Task>();
                     foreach (var contextId in app.Value.RgContexts.Keys)
                     {
                         InventoryTasks[appId][contextId] = Task.Factory.StartNew(() =>
                         {
                             string inventoryUrl = string.Format("http://steamcommunity.com/profiles/{0}/inventory/json/{1}/{2}/", steamId.ConvertToUInt64(), appId, contextId);
                             var inventory = FetchInventory(inventoryUrl, steamId, botId, appId, contextId);
                             if (!inventories.ContainsKey(appId))
                                 inventories[appId] = new Dictionary<long, Inventory>();
                             if (inventory != null && !inventories[appId].ContainsKey(contextId))
                                 inventories[appId].Add(contextId, inventory);
                         });
                     }
                 }
             }
             catch (Exception ex)
             {
                 Success = false;
                 Console.WriteLine(ex);
             }
         }
         else
         {
             Success = false;
             IsPrivate = true;
         }
     });
 }
Esempio n. 11
0
        /// <summary>
        /// Logs the client into the Steam3 network.
        /// The client should already have been connected at this point.
        /// Results are returned in a <see cref="LoggedOnCallback"/>.
        /// </summary>
        /// <param name="details">The details to use for logging on.</param>
        /// <exception cref="ArgumentNullException">No logon details were provided.</exception>
        /// <exception cref="ArgumentException">Username or password are not set within <paramref name="details"/>.</exception>
        public void LogOn(LogOnDetails details)
        {
            if (details == null)
            {
                throw new ArgumentNullException("details");
            }
            if (string.IsNullOrEmpty(details.Username) || string.IsNullOrEmpty(details.Password))
            {
                throw new ArgumentException("LogOn requires a username and password to be set in 'details'.");
            }
            if (!this.Client.IsConnected)
            {
                this.Client.PostCallback(new LoggedOnCallback(EResult.NoConnection));
                return;
            }

            var logon = new ClientMsgProtobuf <CMsgClientLogon>(EMsg.ClientLogon);

            SteamID steamId = new SteamID(details.AccountID, details.AccountInstance, Client.ConnectedUniverse, EAccountType.Individual);

            uint localIp = NetHelpers.GetIPAddress(this.Client.LocalIP);

            logon.ProtoHeader.client_sessionid = 0;
            logon.ProtoHeader.steamid          = steamId.ConvertToUInt64();

            logon.Body.obfustucated_private_ip = localIp ^ MsgClientLogon.ObfuscationMask;

            logon.Body.account_name = details.Username;
            logon.Body.password     = details.Password;

            logon.Body.protocol_version = MsgClientLogon.CurrentProtocol;
            logon.Body.client_os_type   = ( uint )Utils.GetOSType();
            logon.Body.client_language  = "english";

            logon.Body.steam2_ticket_request = details.RequestSteam2Ticket;

            // we're now using the latest steamclient package version, this is required to get a proper sentry file for steam guard
            logon.Body.client_package_version = 1771; // todo: determine if this is still required

            // this is not a proper machine id that Steam accepts
            // but it's good enough for identifying a machine
            logon.Body.machine_id = Utils.GenerateMachineID();


            // steam guard
            logon.Body.auth_code       = details.AuthCode;
            logon.Body.two_factor_code = details.TwoFactorCode;

            logon.Body.sha_sentryfile     = details.SentryFileHash;
            logon.Body.eresult_sentryfile = ( int )(details.SentryFileHash != null ? EResult.OK : EResult.FileNotFound);


            this.Client.Send(logon);
        }
Esempio n. 12
0
        public static SteamID ChatFromClan(SteamID clanId)
        {
            if (!clanId.IsClanAccount)
                throw new ArgumentException("clanId is not a clan account");

            SteamID chatId = clanId.ConvertToUInt64();

            chatId.AccountInstance = (uint)SteamID.ChatInstanceFlags.Clan;
            chatId.AccountType = EAccountType.Chat;

            return chatId;
        }
Esempio n. 13
0
        public static SteamID ClanFromChat(SteamID chatId)
        {
            if (!chatId.IsChatAccount)
                throw new ArgumentException("chatId is not a chat account");

            SteamID clanId = chatId.ConvertToUInt64();

            clanId.AccountInstance = 0;
            clanId.AccountType = EAccountType.Clan;

            return clanId;
        }
Esempio n. 14
0
        public static void OpenProfile( SteamID steamId )
        {
            string friendUrl = string.Format( "http://www.steamcommunity.com/profiles/{0}", steamId.ConvertToUInt64() );

            if ( Util.IsMono() )
            {
                Process.Start( string.Format( "xdg-open {0:s}", friendUrl ) );
            }
            else
            {
                Process.Start( friendUrl );
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Gets the inventory for the given Steam ID using the Steam Community website.
        /// </summary>
        /// <returns>The inventory for the given user. </returns>
        /// <param name='steamid'>The Steam identifier. </param>
        public static dynamic GetInventory(SteamID steamid)
        {
            string url = String.Format (
                "http://steamcommunity.com/profiles/{0}/inventory/json/440/2/?trading=1",
                steamid.ConvertToUInt64 ()
            );

            try
            {
                string response = SteamWeb.Fetch (url, "GET", null, null, true);
                return JsonConvert.DeserializeObject (response);
            }
            catch (Exception)
            {
                return JsonConvert.DeserializeObject ("{\"success\":\"false\"}");
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Attempts to join a chat room.
        /// </summary>
        /// <param name="steamId">The SteamID of the chat room.</param>
        public void JoinChat(SteamID steamId)
        {
            SteamID chatId = steamId.ConvertToUInt64(); // copy the steamid so we don't modify it

            var joinChat = new ClientMsg <MsgClientJoinChat>();

            if (chatId.IsClanAccount)
            {
                // this steamid is incorrect, so we'll fix it up
                chatId.AccountInstance = ( uint )SteamID.ChatInstanceFlags.Clan;
                chatId.AccountType     = EAccountType.Chat;
            }

            joinChat.Body.SteamIdChat = chatId;

            Client.Send(joinChat);
        }
Esempio n. 17
0
        public void LongConstructorAndSetterGetterValid()
        {
            SteamID sid = new SteamID( 103582791432294076 );

            Assert.Equal( 2772668u, sid.AccountID );
            Assert.Equal( SteamID.AllInstances, sid.AccountInstance );
            Assert.Equal( EUniverse.Public, sid.AccountUniverse );
            Assert.Equal( EAccountType.Clan, sid.AccountType );

            sid.SetFromUInt64( 157626004137848889 );

            Assert.Equal( 12345u, sid.AccountID );
            Assert.Equal( SteamID.WebInstance, sid.AccountInstance );
            Assert.Equal( EUniverse.Beta, sid.AccountUniverse );
            Assert.Equal( EAccountType.GameServer, sid.AccountType );

            Assert.Equal( 157626004137848889ul, sid.ConvertToUInt64() );
        }
Esempio n. 18
0
        /// <summary>
        /// Logs the client into the Steam3 network as an anonymous user.
        /// The client should already have been connected at this point.
        /// Results are returned in a <see cref="LoggedOnCallback"/>.
        /// </summary>
        public void LogOnAnonymous()
        {
            var logon = new ClientMsgProtobuf <CMsgClientLogon>(EMsg.ClientLogon);

            SteamID auId = new SteamID(0, 0, Client.ConnectedUniverse, EAccountType.AnonUser);

            logon.ProtoHeader.client_sessionid = 0;
            logon.ProtoHeader.steamid          = auId.ConvertToUInt64();

            logon.Body.protocol_version = MsgClientLogon.CurrentProtocol;
            logon.Body.client_os_type   = ( uint )Utils.GetOSType();

            // this is not a proper machine id that Steam accepts
            // but it's good enough for identifying a machine
            logon.Body.machine_id = Utils.GenerateMachineID();

            this.Client.Send(logon);
        }
Esempio n. 19
0
        /// <summary>
        /// Attempts to join a chat room.
        /// </summary>
        /// <param name="steamId">The SteamID of the chat room.</param>
        public void JoinChat(SteamID steamId)
        {
            if (steamId == null)
            {
                throw new ArgumentNullException(nameof(steamId));
            }

            SteamID chatId = steamId.ConvertToUInt64(); // copy the steamid so we don't modify it

            var joinChat = new ClientMsg <MsgClientJoinChat>();

            if (chatId.IsClanAccount)
            {
                chatId = chatId.ToChatID();
            }

            joinChat.Body.SteamIdChat = chatId;

            Client.Send(joinChat);
        }
Esempio n. 20
0
        public static bool isBotAdmin(SteamID steamid)
        {
            try
            {
                if(steamid.ConvertToUInt64() == Convert.ToUInt64(File.ReadAllText("admin.txt")))
                {
                    return true;
                }

                steamFriends.SendChatMessage(steamid, EChatEntryType.ChatMsg, "You Are Not A Bot Admin...");
                Console.WriteLine(steamFriends.GetFriendPersonaName(steamid) + " are attempted to use as admin while not an admin!");

                return false;
            }
            catch(Exception e)
            {
                Console.WriteLine(e.Message);
                return false;
            }
        }
Esempio n. 21
0
        /// <summary>
        /// Bans the specified chat member from the given chat room.
        /// </summary>
        /// <param name="steamIdChat">The SteamID of chat room to ban the member from.</param>
        /// <param name="steamIdMember">The SteamID of the member to ban from the chat.</param>
        public void BanChatMember( SteamID steamIdChat, SteamID steamIdMember )
        {
            SteamID chatId = steamIdChat.ConvertToUInt64(); // copy the steamid so we don't modify it

            var banMember = new ClientMsg<MsgClientChatAction>();

            if ( chatId.IsClanAccount )
            {
                // this steamid is incorrect, so we'll fix it up
                chatId.AccountInstance = ( uint )SteamID.ChatInstanceFlags.Clan;
                chatId.AccountType = EAccountType.Chat;
            }

            banMember.Body.SteamIdChat = chatId;
            banMember.Body.SteamIdUserToActOn = steamIdMember;

            banMember.Body.ChatAction = EChatAction.Ban;

            this.Client.Send( banMember );
        }
Esempio n. 22
0
        /// <summary>
        /// Bans the specified chat member from the given chat room.
        /// </summary>
        /// <param name="steamIdChat">The SteamID of chat room to ban the member from.</param>
        /// <param name="steamIdMember">The SteamID of the member to ban from the chat.</param>
        public void BanChatMember(SteamID steamIdChat, SteamID steamIdMember)
        {
            SteamID chatId = steamIdChat.ConvertToUInt64(); // copy the steamid so we don't modify it

            var banMember = new ClientMsg <MsgClientChatAction>();

            if (chatId.IsClanAccount)
            {
                // this steamid is incorrect, so we'll fix it up
                chatId.AccountInstance = ( uint )SteamID.ChatInstanceFlags.Clan;
                chatId.AccountType     = EAccountType.Chat;
            }

            banMember.Body.SteamIdChat        = chatId;
            banMember.Body.SteamIdUserToActOn = steamIdMember;

            banMember.Body.ChatAction = EChatAction.Ban;

            this.Client.Send(banMember);
        }
Esempio n. 23
0
        /// <summary>
        /// Sends a message to a chat room.
        /// </summary>
        /// <param name="steamIdChat">The SteamID of the chat room.</param>
        /// <param name="type">The message type.</param>
        /// <param name="message">The message.</param>
        public void SendChatRoomMessage(SteamID steamIdChat, EChatEntryType type, string message)
        {
            SteamID chatId = steamIdChat.ConvertToUInt64(); // copy the steamid so we don't modify it

            if (chatId.IsClanAccount)
            {
                // this steamid is incorrect, so we'll fix it up
                chatId.AccountInstance = ( uint )SteamID.ChatInstanceFlags.Clan;
                chatId.AccountType     = EAccountType.Chat;
            }

            var chatMsg = new ClientMsg <MsgClientChatMsg>();

            chatMsg.Body.ChatMsgType     = type;
            chatMsg.Body.SteamIdChatRoom = chatId;
            chatMsg.Body.SteamIdChatter  = Client.SteamID;

            chatMsg.WriteNullTermString(message, Encoding.UTF8);

            this.Client.Send(chatMsg);
        }
Esempio n. 24
0
        /// <summary>
        /// Attempts to leave a chat room.
        /// </summary>
        /// <param name="steamId">The SteamID of the chat room.</param>
        public void LeaveChat(SteamID steamId)
        {
            SteamID chatId = steamId.ConvertToUInt64(); // copy the steamid so we don't modify it

            var leaveChat = new ClientMsg <MsgClientChatMemberInfo>();

            if (chatId.IsClanAccount)
            {
                // this steamid is incorrect, so we'll fix it up
                chatId.AccountInstance = ( uint )SteamID.ChatInstanceFlags.Clan;
                chatId.AccountType     = EAccountType.Chat;
            }

            leaveChat.Body.SteamIdChat = chatId;
            leaveChat.Body.Type        = EChatInfoType.StateChange;

            leaveChat.Write(Client.SteamID.ConvertToUInt64());    // ChatterActedOn
            leaveChat.Write(( uint )EChatMemberStateChange.Left); // StateChange
            leaveChat.Write(Client.SteamID.ConvertToUInt64());    // ChatterActedBy

            Client.Send(leaveChat);
        }
Esempio n. 25
0
        public static ImmutableArray<byte> CreateServerTicket(
                SteamID id, ImmutableArray<byte> auth, byte[] ownershipTicket) {
            long size = 8 + // steam ID
                        auth.Length +
                        4 + // length of ticket
                        ownershipTicket.Length;

            MemoryStream stream = new MemoryStream();
            using (var writer = new BinaryWriter(stream)) {
                writer.Write((ushort) size);
                writer.Write(id.ConvertToUInt64());

                writer.Write(auth.ToArray());

                writer.Write(ownershipTicket.Length);
                writer.Write(ownershipTicket);

                writer.Write(0);
            }

            return stream.ToArray().ToImmutableArray();
        }
Esempio n. 26
0
        /// <summary>
        /// Initializes a trade session.
        /// </summary>
        public void Initialize()
        {
            if (LoginData.SessionId.Length == 0)
            {
                throw new Exception("Invalid Steam web session id cookie");
            }

            // Clean up the session id.
            LoginData.SessionId = Uri.UnescapeDataString(LoginData.SessionId);

            TradeURL       = string.Format(STEAM_TRADE_URL, OtherSteamId.ConvertToUInt64());
            TradeURLAction = TradeURL + "/{0}/";

            var webRequest = CreateSteamRequest(TradeURL, LoginData, "GET");

            // Perform the request
            var res = webRequest.BeginGetResponse(
                new AsyncCallback(ProcessInitial), webRequest);

            StatusTimer = new Timer(new TimerCallback(HandleStatusTimer), null,
                                    Timeout.Infinite, Timeout.Infinite);
        }
Esempio n. 27
0
        /// <summary>
        /// Logs onto the Steam network as a persistent game server.
        /// The client should already have been connected at this point.
        /// Results are return in a <see cref="SteamUser.LoggedOnCallback"/>.
        /// </summary>
        /// <param name="details">The details to use for logging on.</param>
        /// <exception cref="System.ArgumentNullException">No logon details were provided.</exception>
        /// <exception cref="System.ArgumentException">Username or password are not set within <paramref name="details"/>.</exception>
        public void LogOn(LogOnDetails details)
        {
            if (details == null)
            {
                throw new ArgumentNullException("details");
            }

            if (string.IsNullOrEmpty(details.Token))
            {
                throw new ArgumentException("LogOn requires a game server token to be set in 'details'.");
            }

            if (!this.Client.IsConnected)
            {
                this.Client.PostCallback(new SteamUser.LoggedOnCallback(EResult.NoConnection));
                return;
            }

            var logon = new ClientMsgProtobuf <CMsgClientLogon>(EMsg.ClientLogonGameServer);

            SteamID gsId = new SteamID(0, 0, Client.Universe, EAccountType.GameServer);

            logon.ProtoHeader.client_sessionid = 0;
            logon.ProtoHeader.steamid          = gsId.ConvertToUInt64();

            uint localIp = NetHelpers.GetIPAddress(this.Client.LocalIP);

            logon.Body.obfustucated_private_ip = localIp ^ MsgClientLogon.ObfuscationMask;

            logon.Body.protocol_version = MsgClientLogon.CurrentProtocol;

            logon.Body.client_os_type     = ( uint )Utils.GetOSType();
            logon.Body.game_server_app_id = ( int )details.AppID;
            logon.Body.machine_id         = HardwareUtils.GetMachineID();

            logon.Body.game_server_token = details.Token;

            this.Client.Send(logon);
        }
Esempio n. 28
0
        /// <summary>
        /// Logs the client into the Steam3 network as an anonymous user.
        /// The client should already have been connected at this point.
        /// Results are returned in a <see cref="LoggedOnCallback"/>.
        /// </summary>
        /// <param name="details">The details to use for logging on.</param>
        public void LogOnAnonymous(AnonymousLogOnDetails details)
        {
            if (!this.Client.IsConnected)
            {
                this.Client.PostCallback(new LoggedOnCallback(EResult.NoConnection));
                return;
            }

            var logon = new ClientMsgProtobuf <CMsgClientLogon>(EMsg.ClientLogon);

            SteamID auId = new SteamID(0, 0, Client.ConnectedUniverse, EAccountType.AnonUser);

            logon.ProtoHeader.client_sessionid = 0;
            logon.ProtoHeader.steamid          = auId.ConvertToUInt64();

            logon.Body.protocol_version = MsgClientLogon.CurrentProtocol;
            logon.Body.client_os_type   = ( uint )details.ClientOSType;
            logon.Body.client_language  = details.ClientLanguage;
            logon.Body.cell_id          = details.CellID;

            logon.Body.machine_id = MachineIdUtils.GenerateMachineID();

            this.Client.Send(logon);
        }
Esempio n. 29
0
        /// <summary>
        /// Attempts to join a chat room.
        /// </summary>
        /// <param name="steamId">The SteamID of the chat room.</param>
        public void JoinChat( SteamID steamId )
        {
            SteamID chatId = steamId.ConvertToUInt64(); // copy the steamid so we don't modify it

            var joinChat = new ClientMsg<MsgClientJoinChat>();

            if ( chatId.IsClanAccount )
            {
                // this steamid is incorrect, so we'll fix it up
                chatId.AccountInstance = ( uint )SteamID.ChatInstanceFlags.Clan;
                chatId.AccountType = EAccountType.Chat;
            }

            joinChat.Body.SteamIdChat = chatId;

            Client.Send( joinChat );

        }
Esempio n. 30
0
		private dynamic getInventory (SteamID steamid)
		{

			var request = CreateSteamRequest(String.Format("http://steamcommunity.com/profiles/{0}/inventory/json/440/2/?trading=1",steamid.ConvertToUInt64()),"GET");
			
			HttpWebResponse resp = request.GetResponse() as HttpWebResponse;
			Stream str = resp.GetResponseStream();
			StreamReader reader = new StreamReader(str);
			string res = reader.ReadToEnd();

			dynamic json = JsonConvert.DeserializeObject(res);

			return json;

		}
Esempio n. 31
0
		public void initTrade (SteamID me, SteamID other, CookieCollection cookies)
		{
			//Cleanup again
			cleanTrade();

			//Setup
			meSID = me;
			otherSID = other;
			version = 1;
			logpos = 0;
			WebCookies = cookies;
			sessionid = cookies[0].Value;
			
			baseTradeURL = String.Format (STEAM_TRADE_URL, otherSID.ConvertToUInt64 ());
			
			this.WebCookies = cookies;


			
			printConsole ("[TradeSystem] Init Trade with " + otherSID, ConsoleColor.DarkGreen);
			

			try {

				//poll? poll.
				poll ();

			} catch (Exception) {
				printConsole ("[TradeSystem][ERROR] Failed to connect to Steam!", ConsoleColor.Red);
				//Send a message on steam
				MainClass.steamFriends.SendChatMessage(otherSID,EChatEntryType.ChatMsg,"Sorry, There was a problem connecting to Steam Trading.  Try again in a few minutes.");
				cleanTrade();
			}



			

			printConsole ("[TradeSystem] Getting Player Inventories...", ConsoleColor.Yellow);

			int good = 0;

			OtherItems = getInventory (otherSID);
			if (OtherItems.success=="true") {
				printConsole ("[TradeSystem] Got Other player's inventory!", ConsoleColor.Green); 
				good++;
			} else {

			}
				

			MyItems = getInventory (meSID);
			if (MyItems.success=="true") {
				printConsole ("[TradeSystem] Got the bot's inventory!", ConsoleColor.Green); 
				good++;
			}

			if (good == 2) {
				printConsole ("[TradeSystem] All is a go! Starting to Poll!", ConsoleColor.Green);

				//Timer
				pollTimer = new System.Threading.Timer (TimerCallback, null, 0, 1000);

				//Send MOTD
				sendChat ("Welcome to SteamBot!");
			} else {
				printConsole ("[TradeSystem][ERROR] status was not good! ABORT ABORT ABORT!", ConsoleColor.Red);

				//Poll once to send an error message
				poll ();

				//send error
				sendChat("SteamBot has an error!  Please try trading the bot again in a few minutes.  This is Steam's fault NOT mine.");

				//Poll again so they can read it
				poll ();
			}


			/*
			 * How to Loop through the inventory:
			foreach(var child in OtherItems.rgInventory.Children())
			{
			    Console.WriteLine("Item ID: {0}", child.First.id);
			}
			*/
		}
Esempio n. 32
0
        /// <summary>
        /// Logs the client into the Steam3 network as an anonymous user.
        /// The client should already have been connected at this point.
        /// Results are returned in a <see cref="LoggedOnCallback"/>.
        /// </summary>
        /// <param name="details">The details to use for logging on.</param>
        public void LogOnAnonymous( AnonymousLogOnDetails details )
        {
            if ( !this.Client.IsConnected )
            {
                this.Client.PostCallback( new LoggedOnCallback( EResult.NoConnection ) );
                return;
            }

            var logon = new ClientMsgProtobuf<CMsgClientLogon>( EMsg.ClientLogon );

            SteamID auId = new SteamID( 0, 0, Client.ConnectedUniverse, EAccountType.AnonUser );

            logon.ProtoHeader.client_sessionid = 0;
            logon.ProtoHeader.steamid = auId.ConvertToUInt64();

            logon.Body.protocol_version = MsgClientLogon.CurrentProtocol;
            logon.Body.client_os_type = ( uint )details.ClientOSType;
            logon.Body.client_language = details.ClientLanguage;
            logon.Body.cell_id = details.CellID;

            logon.Body.machine_id = HardwareUtils.GetMachineID();

            this.Client.Send( logon );
        }
Esempio n. 33
0
 public static string GetCalculatorURL(SteamID steamID)
 {
     return new Uri(Settings.Current.BaseURL, string.Format("/calculator/?player={0}", steamID.ConvertToUInt64())).AbsoluteUri;
 }
Esempio n. 34
0
        /// <summary>
        /// Invites a user to a chat room.
        /// The results of this action will be available through the <see cref="ChatActionResultCallback"/> callback.
        /// </summary>
        /// <param name="steamIdUser">The SteamID of the user to invite.</param>
        /// <param name="steamIdChat">The SteamID of the chat room to invite the user to.</param>
        public void InviteUserToChat( SteamID steamIdUser, SteamID steamIdChat )
        {
            SteamID chatId = steamIdChat.ConvertToUInt64(); // copy the steamid so we don't modify it

            if ( chatId.IsClanAccount )
            {
                // this steamid is incorrect, so we'll fix it up
                chatId.AccountInstance = (uint)SteamID.ChatInstanceFlags.Clan;
                chatId.AccountType = EAccountType.Chat;
            }

            var inviteMsg = new ClientMsgProtobuf<CMsgClientChatInvite>( EMsg.ClientChatInvite );

            inviteMsg.Body.steam_id_chat = chatId;
            inviteMsg.Body.steam_id_invited = steamIdUser;
            // steamclient also sends the steamid of the user that did the invitation
            // we'll mimic that behavior
            inviteMsg.Body.steam_id_patron = Client.SteamID;

            this.Client.Send( inviteMsg );
        }
Esempio n. 35
0
        /// <summary>
        /// Fetchs the inventories of both the bot and the other user as well as the TF2 item schema.
        /// </summary>
        /// <param name='me'>
        /// The <see cref="SteamID"/> of the bot.
        /// </param>
        /// <param name='other'>
        /// The <see cref="SteamID"/> of the other trade partner.
        /// </param>
        /// <remarks>
        /// This should be done anytime a new user is traded with or the inventories are out of date. It should
        /// be done sometime before calling <see cref="CreateTrade"/>.
        /// </remarks>
        public void InitializeTrade(SteamID me, SteamID other)
        {
            // fetch other player's inventory from the Steam API.
            otherInventoryTask = Task.Factory.StartNew(() => Inventory.FetchInventory(other.ConvertToUInt64(), ApiKey, SteamWeb));

            //if (OtherInventory == null)
            //{
            //    throw new InventoryFetchException (other);
            //}

            // fetch our inventory from the Steam API.
            myInventoryTask = Task.Factory.StartNew(() => Inventory.FetchInventory(me.ConvertToUInt64(), ApiKey, SteamWeb));

            // check that the schema was already successfully fetched
            if (Trade.CurrentSchema == null)
                Trade.CurrentSchema = Schema.FetchSchema (ApiKey);

            if (Trade.CurrentSchema == null)
                throw new TradeException ("Could not download the latest item schema.");
        }
Esempio n. 36
0
        /// <summary>
        /// Accepts the invite to a Steam Group
        /// </summary>
        /// <param name="group">SteamID of the group to accept the invite from.</param>
        private void AcceptGroupInvite(SteamID group)
        {
            var acceptMsg = new ClientMsg<CMsgGroupInviteAction>((int)EMsg.ClientAcknowledgeClanInvite);

            acceptMsg.Body.GroupID = group.ConvertToUInt64();
            acceptMsg.Body.AcceptInvite = true;

            SteamClient.Send(acceptMsg);
            Log.Success("Accepted group invite to {0}.", group.ToString());
        }
Esempio n. 37
0
        /// <summary>
        /// Connects this instance to the server.
        /// </summary>
        /// <returns><c>true</c> if the connection was a success; otherwise, <c>false</c>.</returns>
        public bool Connect()
        {
            byte[] encryptedKey = null;

            // TODO: handle other universes?
            byte[] universeKey = KeyDictionary.GetPublicKey(EUniverse.Public);
            using (var rsa = new RSACrypto(universeKey))
            {
                encryptedKey = rsa.Encrypt(sessionKey);
            }

            string payload;

            if (appTicket == null)
            {
                payload = String.Format("sessionkey={0}&anonymoususer=1&steamid={1}", WebHelpers.UrlEncode(encryptedKey), steamID.ConvertToUInt64());
            }
            else
            {
                byte[] encryptedTicket = CryptoHelper.SymmetricEncrypt(appTicket, sessionKey);
                payload = String.Format("sessionkey={0}&appticket={1}", WebHelpers.UrlEncode(encryptedKey), WebHelpers.UrlEncode(encryptedTicket));
            }

            webClient.Headers.Clear();
            webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");

            string response;

            try
            {
                response = webClient.UploadString(BuildCommand(endPoint, "initsession"), payload);
            }
            catch (WebException e)
            {
                LogWebException("Connect", e);
                return(false);
            }

            var responsekv  = KeyValue.LoadFromString(response);
            var sessionidn  = responsekv.Children.Where(c => c.Name == "sessionid").First();
            var reqcountern = responsekv.Children.Where(c => c.Name == "req-counter").First();

            sessionID  = (ulong)(sessionidn.AsLong(0));
            reqcounter = reqcountern.AsLong(0);

            try
            {
                AuthDepot();
            }
            catch (WebException e)
            {
                LogWebException("AuthDepot", e);
                return(false);
            }

            return(true);
        }
Esempio n. 38
0
        /// <summary>
        /// Accepts the invite to a Steam Group
        /// </summary>
        /// <param name="group">SteamID of the group to accept the invite from.</param>
        private void AcceptGroupInvite(SteamID group)
        {
            var AcceptInvite = new ClientMsg<CMsgGroupInviteAction>((int)EMsg.ClientAcknowledgeClanInvite);

            AcceptInvite.Body.GroupID = group.ConvertToUInt64();
            AcceptInvite.Body.AcceptInvite = true;

            this.SteamClient.Send(AcceptInvite);
        }
Esempio n. 39
0
        /// <summary>
        /// Declines the invite to a Steam Group
        /// </summary>
        /// <param name="group">SteamID of the group to decline the invite from.</param>
        private void DeclineGroupInvite(SteamID group)
        {
            var DeclineInvite = new ClientMsg<CMsgGroupInviteAction>((int)EMsg.ClientAcknowledgeClanInvite);

            DeclineInvite.Body.GroupID = group.ConvertToUInt64();
            DeclineInvite.Body.AcceptInvite = false;

            this.SteamClient.Send(DeclineInvite);
        }
Esempio n. 40
0
        /// <summary>
        /// Invites a use to the specified Steam Group
        /// </summary>
        /// <param name="user">SteamID of the user to invite.</param>
        /// <param name="groupId">SteamID of the group to invite the user to.</param>
        public void InviteUserToGroup(SteamID user, SteamID groupId)
        {
            var InviteUser = new ClientMsg<CMsgInviteUserToGroup>((int)EMsg.ClientInviteUserToClan);

            InviteUser.Body.GroupID = groupId.ConvertToUInt64();
            InviteUser.Body.Invitee = user.ConvertToUInt64();
            InviteUser.Body.UnknownInfo = true;

            this.SteamClient.Send(InviteUser);
        }
Esempio n. 41
0
        bool HandleTradeSessionStart(SteamID other)
        {
            if (CurrentTrade != null)
                return false;

            try
            {
                tradeManager.InitializeTrade(SteamUser.SteamID, other);
                CurrentTrade = tradeManager.StartTrade (SteamUser.SteamID, other);
            }
            catch (SteamTrade.Exceptions.InventoryFetchException ie)
            {
                // we shouldn't get here because the inv checks are also
                // done in the TradeProposedCallback handler.
                string response = String.Empty;

                if (ie.FailingSteamId.ConvertToUInt64() == other.ConvertToUInt64())
                {
                    response = "Trade failed. Could not correctly fetch your backpack. Either the inventory is inaccessible or your backpack is private.";
                }
                else
                {
                    response = "Trade failed. Could not correctly fetch my backpack.";
                }

                SteamFriends.SendChatMessage(other,
                                             EChatEntryType.ChatMsg,
                                             response);

                log.Info ("Bot sent other: " + response);

                CurrentTrade = null;
                return false;
            }

            CurrentTrade.OnClose += CloseTrade;
            SubscribeTrade (CurrentTrade, GetUserHandler (other));

            return true;
        }
Esempio n. 42
0
 UserHandler GetUserHandler(SteamID sid)
 {
     if (!userHandlers.ContainsKey (sid))
     {
         userHandlers [sid.ConvertToUInt64 ()] = CreateHandler (this, sid);
     }
     return userHandlers [sid.ConvertToUInt64 ()];
 }
Esempio n. 43
0
        /// <summary>
        /// Attempts to leave a chat room.
        /// </summary>
        /// <param name="steamId">The SteamID of the chat room.</param>
        public void LeaveChat( SteamID steamId )
        {
            SteamID chatId = steamId.ConvertToUInt64(); // copy the steamid so we don't modify it

            var leaveChat = new ClientMsg<MsgClientChatMemberInfo>();

            if ( chatId.IsClanAccount )
            {
                // this steamid is incorrect, so we'll fix it up
                chatId.AccountInstance = ( uint )SteamID.ChatInstanceFlags.Clan;
                chatId.AccountType = EAccountType.Chat;
            }

            leaveChat.Body.SteamIdChat = chatId;
            leaveChat.Body.Type = EChatInfoType.StateChange;

            leaveChat.Write( Client.SteamID.ConvertToUInt64() ); // ChatterActedOn
            leaveChat.Write( ( uint )EChatMemberStateChange.Left ); // StateChange
            leaveChat.Write( Client.SteamID.ConvertToUInt64() ); // ChatterActedBy

            Client.Send( leaveChat );
        }
        private bool Respond(SteamID toID, SteamID userID, string message, bool room)
        {
            bool messageSent = false;
            CheckIfDBExists(userID);
            Dictionary<ulong, DB> db = Options.NotificationOptions.DB;

            db[userID].userID = userID.ConvertToUInt64();
            db[userID].seen = DateTime.Now;
            db[userID].name = Bot.steamFriends.GetFriendPersonaName(userID);

            string[] query = StripCommand(message, Options.NotificationOptions.SeenCommand);
            if (query != null && query.Length == 2)
            {
                if (!db.ContainsKey(Convert.ToUInt64(query[1])) || db[Convert.ToUInt64(query[1])] == null)
                {
                    SendMessageAfterDelay(toID, "The user " + query[1] + " was not found.", room);
                    messageSent = true;
                }
                else
                {
                    SendMessageAfterDelay(toID, string.Format("I last saw {0} on {1} at {2}", db[Convert.ToUInt64(query[1])].name, db[Convert.ToUInt64(query[1])].seen.ToShortDateString(), db[Convert.ToUInt64(query[1])].seen.ToShortTimeString()), room);
                    messageSent = true;
                }
            }

            query = StripCommand(message, Options.NotificationOptions.APICommand);
            if(query != null && userID != toID)
            {
                SendMessageAfterDelay(toID, "This command will only work in private to protect privacy.", room);
                messageSent = true;
            }
            else if(query != null && query.Length == 2 && userID == toID)
            {
                CheckIfDBExists(userID);
                string api = query[1];
                db[userID.ConvertToUInt64()].pb.apikey = api;
                PushbulletClient client = new PushbulletClient(api);
                PushNoteRequest note = new PushNoteRequest()
                {
                    Title = "Test note",
                    Body = "This is a test. If you receive this then you have successfully registered an API key with the bot."
                };

                PushResponse response = client.PushNote(note);
                if(response == null)
                {
                    SendMessageAfterDelay(toID, "Your push failed. Most likely your API key is incorrect.", room);
                    messageSent = true;
                }
                else
                {
                    SendMessageAfterDelay(toID, "Your push was a success.", room);
                    messageSent = true;
                }
            }

            query = StripCommand(message, Options.NotificationOptions.FilterCommand);
            if(query != null && query.Length == 1)
            {
                SendMessageAfterDelay(toID, "Available sub commands: add, list, clear, delete", room);
                messageSent = true;
            }
            else if(query != null && query.Length >= 2)
            {
                if(query[1] == "add" && query.Length >= 3)
                {

                    List<string> words = new List<string>();
                    words = db[userID].pb.filter;
                    // !filter add banshee test 1 2 3
                    for (int i = 2; i < query.Length; i++)
                    {
                        words.Add(query[i]);
                    }

                    db[userID].pb.filter = words;
                    SendMessageAfterDelay(toID, "Your filter has been successfully modified.", room);
                    messageSent = true;
                }
                else if(query[1] == "list" && query.Length == 2)
                {
                    if (db[userID].pb.filter.Count > 0)
                    {
                        string words = string.Join(", ", db[userID].pb.filter);
                        SendMessageAfterDelay(userID, "Your filter: " + words, false);
                        messageSent = true;
                    }
                    else
                    {
                        SendMessageAfterDelay(userID, "Your filter is empty. Use \"!filter add <words>\" to add to your filter", false);
                        messageSent = true;
                    }
                }
                else if(query[1] == "clear" && query.Length == 2)
                {
                    db[userID].pb.filter.Clear();
                    SendMessageAfterDelay(toID, "Your filter has been cleared", room);
                    messageSent = true;
                }
                else if(query[1] == "delete" && query.Length == 3)
                {
                    db[userID].pb.filter.Remove(query[2]);
                    SendMessageAfterDelay(toID, "The filter \"" + query[2] + "\" has been removed", room);
                    messageSent = true;
                }
            }

            query = StripCommand(message, Options.NotificationOptions.ClearCommand);
            if(query != null)
            {
                db[userID] = null;
                SendMessageAfterDelay(toID, "Your database file has been cleared.", room);
                messageSent = true;
            }

            foreach (DB d in db.Values)
            {
                if (d == null || d.pb == null || d.pb.filter == null || d.pb.filter.Count == 0)
                {
                    return false;
                }
                foreach (string word in d.pb.filter)
                {
                    if (message.ToLower().Contains(word.ToLower()) && userID.ConvertToUInt64() != d.userID)
                    {
                        if (d.pb.apikey != null && d.pb.apikey != "")
                        {
                            PushbulletClient client = new PushbulletClient(d.pb.apikey);
                            PushNoteRequest note = new PushNoteRequest();
                            note.Title = string.Format("Steam message from {0}/{1} in {2}", db[userID.ConvertToUInt64()].name, userID.ConvertToUInt64(), toID.ConvertToUInt64());
                            note.Body = message;
                            client.PushNote(note);
                            Log.Instance.Verbose("{0}/{1}: Sending pushbullet for {2}/{3}", Bot.username, Name, db[d.userID].name, db[d.userID].userID);
                            return true;
                        }
                    }
                }
            }

            return messageSent;
        }
Esempio n. 45
0
        /// <summary>
        /// Sends a message to a chat room.
        /// </summary>
        /// <param name="steamIdChat">The SteamID of the chat room.</param>
        /// <param name="type">The message type.</param>
        /// <param name="message">The message.</param>
        public void SendChatRoomMessage( SteamID steamIdChat, EChatEntryType type, string message )
        {
            SteamID chatId = steamIdChat.ConvertToUInt64(); // copy the steamid so we don't modify it

            if ( chatId.IsClanAccount )
            {
                // this steamid is incorrect, so we'll fix it up
                chatId.AccountInstance = ( uint )SteamID.ChatInstanceFlags.Clan;
                chatId.AccountType = EAccountType.Chat;
            }

            var chatMsg = new ClientMsg<MsgClientChatMsg>();

            chatMsg.Body.ChatMsgType = type;
            chatMsg.Body.SteamIdChatRoom = chatId;
            chatMsg.Body.SteamIdChatter = Client.SteamID;

            chatMsg.WriteNullTermString( message, Encoding.UTF8 );

            this.Client.Send( chatMsg );
        }
Esempio n. 46
0
        /// <summary>
        /// Logs the client into the Steam3 network.
        /// The client should already have been connected at this point.
        /// Results are returned in a <see cref="LoggedOnCallback"/>.
        /// </summary>
        /// <param name="details">The details to use for logging on.</param>
        /// <exception cref="ArgumentNullException">No logon details were provided.</exception>
        /// <exception cref="ArgumentException">Username or password are not set within <paramref name="details"/>.</exception>
        public void LogOn( LogOnDetails details )
        {
            if ( details == null )
            {
                throw new ArgumentNullException( "details" );
            }
            if ( string.IsNullOrEmpty( details.Username ) || ( string.IsNullOrEmpty( details.Password ) && string.IsNullOrEmpty( details.LoginKey ) ) )
            {
                throw new ArgumentException( "LogOn requires a username and password to be set in 'details'." );
            }
            if ( !string.IsNullOrEmpty( details.LoginKey ) && !details.ShouldRememberPassword )
            {
                // Prevent consumers from screwing this up.
                // If should_remember_password is false, the login_key is ignored server-side.
                // The inverse is not applicable (you can log in with should_remember_password and no login_key).
                throw new ArgumentException( "ShouldRememberPassword is required to be set to true in order to use LoginKey." );
            }
            if ( !this.Client.IsConnected )
            {
                this.Client.PostCallback( new LoggedOnCallback( EResult.NoConnection ) );
                return;
            }

            var logon = new ClientMsgProtobuf<CMsgClientLogon>( EMsg.ClientLogon );

            SteamID steamId = new SteamID( details.AccountID, details.AccountInstance, Client.ConnectedUniverse, EAccountType.Individual );

            if ( details.LoginID.HasValue )
            {
                logon.Body.obfustucated_private_ip = details.LoginID.Value;
            }
            else
            {
                uint localIp = NetHelpers.GetIPAddress( this.Client.LocalIP );
                logon.Body.obfustucated_private_ip = localIp ^ MsgClientLogon.ObfuscationMask;
            }

            logon.ProtoHeader.client_sessionid = 0;
            logon.ProtoHeader.steamid = steamId.ConvertToUInt64();

            logon.Body.account_name = details.Username;
            logon.Body.password = details.Password;
            logon.Body.should_remember_password = details.ShouldRememberPassword;

            logon.Body.protocol_version = MsgClientLogon.CurrentProtocol;
            logon.Body.client_os_type = ( uint )details.ClientOSType;
            logon.Body.client_language = details.ClientLanguage;
            logon.Body.cell_id = details.CellID;

            logon.Body.steam2_ticket_request = details.RequestSteam2Ticket;

            // we're now using the latest steamclient package version, this is required to get a proper sentry file for steam guard
            logon.Body.client_package_version = 1771; // todo: determine if this is still required
            logon.Body.machine_id = HardwareUtils.GetMachineID();

            // steam guard 
            logon.Body.auth_code = details.AuthCode;
            logon.Body.two_factor_code = details.TwoFactorCode;

            logon.Body.login_key = details.LoginKey;

            logon.Body.sha_sentryfile = details.SentryFileHash;
            logon.Body.eresult_sentryfile = ( int )( details.SentryFileHash != null ? EResult.OK : EResult.FileNotFound );


            this.Client.Send( logon );
        }
Esempio n. 47
0
        public bool load(ulong appid,List<uint> types, SteamID steamid)
        {
            dynamic invResponse;
            Item tmpItemData;
            ItemDescription tmpDescription;

            loaded = false;

            try
            {
                for (int i = 0; i < types.Count; i++)
                {
                    string response = SteamWeb.Fetch(string.Format("http://steamcommunity.com/profiles/{0}/inventory/json/{1}/{2}/?trading=1", steamid.ConvertToUInt64(),appid, types[i]), "GET", null, null, true);

                    invResponse = JsonConvert.DeserializeObject(response);

                    if (invResponse.success == false)
                    {
                        errors.Add("Fail to open backpack: " + invResponse.Error);
                        return false;
                    }

                    //rgInventory = Items on Steam Inventory
                    foreach (var item in invResponse.rgInventory)
                    {

                        foreach (var itemId in item)
                        {
                            tmpItemData = new Item();
                            tmpItemData.id = itemId.id;
                            tmpItemData.classid = itemId.classid;

                            items.Add((ulong)itemId.id, tmpItemData);
                            break;
                        }
                    }

                    // rgDescriptions = Item Schema (sort of)
                    foreach (var description in invResponse.rgDescriptions)
                    {
                        foreach (var classid_instanceid in description)// classid + '_' + instenceid
                        {
                            tmpDescription = new ItemDescription();
                            tmpDescription.name = classid_instanceid.name;
                            tmpDescription.type = classid_instanceid.type;
                            tmpDescription.marketable = (bool) classid_instanceid.marketable;
                            tmpDescription.tradable = (bool) classid_instanceid.marketable;

                            tmpDescription.metadata = classid_instanceid.descriptions;

                            descriptions.Add((ulong)classid_instanceid.classid, tmpDescription);
                            break;
                        }
                    }

                }//end for (inventory type)
            }//end try
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                errors.Add("Exception: " + e.Message);
                return false;
            }
            loaded = true;
            return true;
        }
Esempio n. 48
0
        /// <summary>
        /// Declines the invite to a Steam Group
        /// </summary>
        /// <param name="group">SteamID of the group to decline the invite from.</param>
        private void DeclineGroupInvite(SteamID group)
        {
            var declineMsg = new ClientMsg<CMsgGroupInviteAction>((int)EMsg.ClientAcknowledgeClanInvite);

            declineMsg.Body.GroupID = group.ConvertToUInt64();
            declineMsg.Body.AcceptInvite = false;

            SteamClient.Send(declineMsg);
            Log.Info("Declined group invite to {0}.", group.ToString());
        }
Esempio n. 49
0
        /// <summary>
        /// Logs the client into the Steam3 network.
        /// The client should already have been connected at this point.
        /// Results are returned in a <see cref="LoggedOnCallback"/>.
        /// </summary>
        /// <param name="details">The details to use for logging on.</param>
        /// <exception cref="ArgumentNullException">No logon details were provided.</exception>
        /// <exception cref="ArgumentException">Username or password are not set within <paramref name="details"/>.</exception>
        public void LogOn(LogOnDetails details)
        {
            if (details == null)
            {
                throw new ArgumentNullException("details");
            }
            if (string.IsNullOrEmpty(details.Username) || (string.IsNullOrEmpty(details.Password) && string.IsNullOrEmpty(details.LoginKey)))
            {
                throw new ArgumentException("LogOn requires a username and password to be set in 'details'.");
            }
            if (!string.IsNullOrEmpty(details.LoginKey) && !details.ShouldRememberPassword)
            {
                // Prevent consumers from screwing this up.
                // If should_remember_password is false, the login_key is ignored server-side.
                // The inverse is not applicable (you can log in with should_remember_password and no login_key).
                throw new ArgumentException("ShouldRememberPassword is required to be set to true in order to use LoginKey.");
            }
            if (!this.Client.IsConnected)
            {
                this.Client.PostCallback(new LoggedOnCallback(EResult.NoConnection));
                return;
            }

            var logon = new ClientMsgProtobuf <CMsgClientLogon>(EMsg.ClientLogon);

            SteamID steamId = new SteamID(details.AccountID, details.AccountInstance, Client.ConnectedUniverse, EAccountType.Individual);

            if (details.LoginID.HasValue)
            {
                logon.Body.obfustucated_private_ip = details.LoginID.Value;
            }
            else
            {
                uint localIp = NetHelpers.GetIPAddress(this.Client.LocalIP);
                logon.Body.obfustucated_private_ip = localIp ^ MsgClientLogon.ObfuscationMask;
            }

            logon.ProtoHeader.client_sessionid = 0;
            logon.ProtoHeader.steamid          = steamId.ConvertToUInt64();

            logon.Body.account_name             = details.Username;
            logon.Body.password                 = details.Password;
            logon.Body.should_remember_password = details.ShouldRememberPassword;

            logon.Body.protocol_version = MsgClientLogon.CurrentProtocol;
            logon.Body.client_os_type   = ( uint )details.ClientOSType;
            logon.Body.client_language  = details.ClientLanguage;
            logon.Body.cell_id          = details.CellID;

            logon.Body.steam2_ticket_request = details.RequestSteam2Ticket;

            // we're now using the latest steamclient package version, this is required to get a proper sentry file for steam guard
            logon.Body.client_package_version = 1771; // todo: determine if this is still required
            logon.Body.machine_id             = HardwareUtils.GetMachineID();

            // steam guard
            logon.Body.auth_code       = details.AuthCode;
            logon.Body.two_factor_code = details.TwoFactorCode;

            logon.Body.login_key = details.LoginKey;

            logon.Body.sha_sentryfile     = details.SentryFileHash;
            logon.Body.eresult_sentryfile = ( int )(details.SentryFileHash != null ? EResult.OK : EResult.FileNotFound);


            this.Client.Send(logon);
        }
        private void CheckIfDBExists(SteamID userID)
        {
            if (!Options.NotificationOptions.DB.ContainsKey(userID))
            {
                Options.NotificationOptions.DB.Add(userID.ConvertToUInt64(), new DB());
                Options.NotificationOptions.DB[userID.ConvertToUInt64()].pb = new PushBullet();
            }

            if (Options.NotificationOptions.DB[userID].pb.filter == null)
            {
                Options.NotificationOptions.DB[userID].pb.filter = new List<string>();
            }
        }