/// <summary> /// Requests a list of servers from the Steam game master server. /// Results are returned in a <see cref="QueryCallback"/>. /// The returned <see cref="AsyncJob{T}"/> can also be awaited to retrieve the callback result. /// </summary> /// <param name="details">The details for the request.</param> /// <returns>The Job ID of the request. This can be used to find the appropriate <see cref="QueryCallback"/>.</returns> public AsyncJob <QueryCallback> ServerQuery(QueryDetails details) { var query = new ClientMsgProtobuf <CMsgClientGMSServerQuery>(EMsg.ClientGMSServerQuery); query.SourceJobID = Client.GetNextJobID(); query.Body.app_id = details.AppID; if (details.GeoLocatedIP != null) { query.Body.geo_location_ip = NetHelpers.GetIPAddress(details.GeoLocatedIP); } query.Body.filter_text = details.Filter; query.Body.region_code = ( uint )details.Region; query.Body.max_servers = details.MaxServers; this.Client.Send(query); return(new AsyncJob <QueryCallback>(this.Client, query.SourceJobID)); }
/// <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.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 = HardwareUtils.GetMachineID(); logon.Body.game_server_token = details.Token; this.Client.Send(logon); }
/// <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); }
internal ServerListCallback(CMsgClientServerList serverList) { Servers = serverList.servers .Select(s => new { Type = ( EServerType )s.server_type, EndPoint = new IPEndPoint(NetHelpers.GetIPAddress(s.server_ip), ( int )s.server_port) }) .GroupBy(s => s.Type) .ToDictionary(grp => grp.Key, grp => new ReadOnlyCollection <IPEndPoint>(grp.Select(s => s.EndPoint).ToList())); }
public IPAddress ToIPAddress() { return(NetHelpers.GetIPAddress(NetHelpers.EndianSwap(IPAddress))); }
internal CMListCallback(CMsgClientCMList cmMsg) { var cmList = cmMsg.cm_addresses .Zip(cmMsg.cm_ports, (addr, port) => ServerRecord.CreateSocketServer(new IPEndPoint(NetHelpers.GetIPAddress(addr), ( int )port))); var websocketList = cmMsg.cm_websocket_addresses.Select((addr) => ServerRecord.CreateWebSocketServer(addr)); Servers = new ReadOnlyCollection <ServerRecord>(cmList.Concat(websocketList).ToList()); }