public void GenerationIsThreadSafe() { var provider = new CountingMachineInfoProvider(); var trigger = new ManualResetEventSlim(); var threads = new Thread[100]; for (var i = 0; i < threads.Length; i++) { threads[i] = new Thread(state => { var provider = (IMachineInfoProvider)state; trigger.Wait(); HardwareUtils.Init(provider); HardwareUtils.GetMachineID(provider); }); threads[i].Start(provider); } trigger.Set(); for (var i = 0; i < threads.Length; i++) { threads[i].Join(); } Assert.Equal(3, provider.TotalInvocations); }
public void MachineInfoIsProcessedInBackground() { var provider = new ThreadRejectingMachineInfoProvider(Thread.CurrentThread.ManagedThreadId); HardwareUtils.Init(provider); // Should not throw HardwareUtils.GetMachineID(provider); }
public void ExceptionBubblesUp() { var provider = new ThrowingMachineInfoProvider(); HardwareUtils.Init(provider); var exception = Assert.Throws <InvalidOperationException>(() => HardwareUtils.GetMachineID(provider)); Assert.Equal("This provider only throws.", exception.Message); }
private async Task LoginAsync(LoginInfo info) { uint instance = 0; if (info.AccountId != 0) { instance = 2; } else if (info.AccountType != AccountType.AnonUser) { instance = 1; } await NetLog.InfoAsync($"Logging in as {info.Username ?? (instance == 0 ? "an anonymous user" : "a console user")}").ConfigureAwait(false); byte[] machineId = await HardwareUtils.GetMachineId().ConfigureAwait(false); // while we set up the logon object, we will start to get the machine ID var body = new CMsgClientLogon { protocol_version = 65579, client_os_type = (uint)(info.AccountId == 0 ? HardwareUtils.GetCurrentOsType() : OsType.PS3), client_language = GetConfig <SteamNetworkConfig>().Language.GetApiLanguageCode(), cell_id = (uint)GetConfig <SteamNetworkConfig>().CellId, }; if (machineId != null && machineId.Length != 0) { body.machine_id = machineId; } if (info.AccountType != AccountType.AnonUser) { body.account_name = info.Username; body.password = info.Password; body.should_remember_password = info.ShouldRememberPassword; body.steam2_ticket_request = info.RequestSteam2Ticket; body.two_factor_code = info.TwoFactorCode; body.auth_code = info.AuthCode; body.login_key = info.LoginKey; body.sha_sentryfile = info.SentryFileHash; body.eresult_sentryfile = (int)(info.SentryFileHash is null ? Result.FileNotFound : Result.OK); body.client_package_version = 1771; body.obfustucated_private_ip = (uint)(GetConfig <SteamNetworkConfig>().LoginId < 0 ? LocalIp.ToUInt32() ^ _obfuscationMask : GetConfig <SteamNetworkConfig>().LoginId); body.supports_rate_limit_response = true; } var logon = NetworkMessage .CreateProtobufMessage(MessageType.ClientLogon, body) .WithClientInfo(new SteamId(info.AccountId, GetConfig <SteamNetworkConfig>().DefaultUniverse, info.AccountType, instance), 0); await SendAsync(logon.Serialize()).ConfigureAwait(false); }
public void ProviderIsNotRetained() { WeakReference Setup() { var provider = new CountingMachineInfoProvider(); HardwareUtils.Init(provider); HardwareUtils.GetMachineID(provider); return(new WeakReference(provider)); } var provider = Setup(); GC.Collect(); Assert.False(provider.IsAlive); }
/// <summary> /// Sets the currently playing game to a mod for the specified app /// </summary> /// <param name="appId"></param> /// <param name="modId"></param> /// <returns></returns> public async Task SetPlayingGameAsync(int appId, long modId) { GameId id = new GameId(appId, GameType.Mod, modId); var body = new CMsgClientGamesPlayed { client_os_type = (uint)HardwareUtils.GetCurrentOsType(), }; body.games_played.Add(new CMsgClientGamesPlayed.GamePlayed { game_id = id }); var message = NetworkMessage.CreateProtobufMessage(MessageType.ClientGamesPlayed, body); await SendAsync(message).ConfigureAwait(false); }
public void ResultIsCached() { var provider = new CountingMachineInfoProvider(); HardwareUtils.Init(provider); HardwareUtils.GetMachineID(provider); var invocations = provider.TotalInvocations; for (var i = 0; i < 100; i++) { HardwareUtils.Init(provider); HardwareUtils.GetMachineID(provider); } Assert.Equal(invocations, provider.TotalInvocations); }
/// <summary> /// Logs into the Steam network as an anonymous game server /// </summary> /// <param name="appId"></param> /// <returns></returns> public async Task LoginGameServerAnonymousAsync(int appId) { CMsgClientLogon logon = new CMsgClientLogon() { protocol_version = _currentProtocolVer, obfustucated_private_ip = (uint)(GetConfig <SteamNetworkConfig>().LoginId < 0 ? LocalIp.ToUInt32() ^ _obfuscationMask : GetConfig <SteamNetworkConfig>().LoginId), client_os_type = (uint)HardwareUtils.GetCurrentOsType(), game_server_app_id = appId, machine_id = await HardwareUtils.GetMachineId().ConfigureAwait(false), }; NetworkMessage message = NetworkMessage .CreateProtobufMessage(MessageType.ClientLogon, logon) .WithClientInfo(SteamId.CreateAnonymousGameServer(GetConfig <SteamNetworkConfig>().DefaultUniverse), 0); await SendAsync(message.Serialize()).ConfigureAwait(false); }
/// <summary> /// Sets the currently playing game to a shortcut of the specified name /// </summary> /// <param name="game"></param> /// <returns></returns> public async Task SetPlayingGameAsync(string game) { GameId id = GameId.Shortcut; var body = new CMsgClientGamesPlayed { client_os_type = (uint)HardwareUtils.GetCurrentOsType(), }; body.games_played.Add(new CMsgClientGamesPlayed.GamePlayed { game_id = id, game_extra_info = game }); var message = NetworkMessage.CreateProtobufMessage(MessageType.ClientGamesPlayed, body); await SendAsync(message).ConfigureAwait(false); }
public void GeneratesMessageObject() { var provider = new StaticMachineInfoProvider(); HardwareUtils.Init(provider); var messageObjectData = HardwareUtils.GetMachineID(provider); var kv = new KeyValue(); using (var ms = new MemoryStream(messageObjectData)) { Assert.True(kv.TryReadAsBinary(ms)); } Assert.Equal("MessageObject", kv.Name); Assert.Equal("3018ba91fc5a72f8b3f74501af6dd6da331b6cbc", kv["BB3"].AsString()); Assert.Equal("5d7e7734714b64bd6d88fef3ddbbf7ab4a749c5e", kv["FF2"].AsString()); Assert.Equal("a1807176456746ba2a3f5574bf47677a919dab49", kv["3B3"].AsString()); }
/// <summary> /// Logs into the Steam network as a game server /// </summary> /// <param name="appId"></param> /// <param name="token"></param> /// <returns></returns> public async Task LoginGameServerAsync(int appId, string token) { if (string.IsNullOrWhiteSpace(token)) { throw new ArgumentException("The token cannot be null or whitespace", nameof(token)); } CMsgClientLogon logon = new CMsgClientLogon() { protocol_version = _currentProtocolVer, obfustucated_private_ip = (uint)(GetConfig <SteamNetworkConfig>().LoginId < 0 ? LocalIp.ToUInt32() ^ _obfuscationMask : GetConfig <SteamNetworkConfig>().LoginId), client_os_type = (uint)HardwareUtils.GetCurrentOsType(), game_server_app_id = appId, machine_id = await HardwareUtils.GetMachineId().ConfigureAwait(false), game_server_token = token }; NetworkMessage message = NetworkMessage .CreateProtobufMessage(MessageType.ClientLogonGameServer, logon) .WithClientInfo(new SteamId(0, GetConfig <SteamNetworkConfig>().DefaultUniverse, AccountType.GameServer, 0), 0); await SendAsync(message.Serialize()).ConfigureAwait(false); }