Ejemplo n.º 1
0
        private async Task ResolveServerList()
        {
            DebugWrite("Resolving server list");

            IEnumerable <ServerRecord> serverList = await configuration.ServerListProvider.FetchServerListAsync().ConfigureAwait(false);

            IReadOnlyCollection <ServerRecord> endpointList = serverList.ToList();

            if (endpointList.Count == 0 && configuration.AllowDirectoryFetch)
            {
                DebugWrite("Server list provider had no entries, will query SteamDirectory");
                endpointList = await SteamDirectory.LoadAsync(configuration).ConfigureAwait(false);
            }

            if (endpointList.Count == 0 && configuration.AllowDirectoryFetch)
            {
                DebugWrite("Could not query SteamDirectory, falling back to cm0");
                var cm0 = await Dns.GetHostAddressesAsync("cm0.steampowered.com").ConfigureAwait(false);

                endpointList = cm0.Select(ipaddr => ServerRecord.CreateSocketServer(new IPEndPoint(ipaddr, 27015))).ToList();
            }

            DebugWrite("Resolved {0} servers", endpointList.Count);
            ReplaceList(endpointList);
        }
Ejemplo n.º 2
0
        private async Task ResolveServerList()
        {
            DebugWrite("Resolving server list");

            IEnumerable <IPEndPoint> serverList = await ServerListProvider.FetchServerListAsync().ConfigureAwait(false);

            List <IPEndPoint> endpointList = serverList.ToList();

            if (endpointList.Count == 0 && canFetchDirectory)
            {
                DebugWrite("Server list provider had no entries, will query SteamDirectory");
                var directoryList = await SteamDirectory.LoadAsync(CellID).ConfigureAwait(false);

                endpointList = directoryList.ToList();
            }

            if (endpointList.Count == 0 && canFetchDirectory)
            {
                DebugWrite("Could not query SteamDirectory, falling back to cm0");
                var cm0 = await Dns.GetHostAddressesAsync("cm0.steampowered.com").ConfigureAwait(false);

                endpointList = cm0.Select(ipaddr => new IPEndPoint(ipaddr, 27015)).ToList();
            }

            DebugWrite("Resolved {0} servers", endpointList.Count);
            ReplaceList(endpointList);
        }
Ejemplo n.º 3
0
        private static async Task RegisterBots(StringComparer botsComparer)
        {
            if (botsComparer == null)
            {
                ArchiLogger.LogNullError(nameof(botsComparer));

                return;
            }

            if (Bot.Bots.Count > 0)
            {
                return;
            }

            // Ensure that we ask for a list of servers if we don't have any saved servers available
            IEnumerable <ServerRecord> servers = await GlobalDatabase.ServerListProvider.FetchServerListAsync().ConfigureAwait(false);

            if (servers?.Any() != true)
            {
                ArchiLogger.LogGenericInfo(string.Format(Strings.Initializing, nameof(SteamDirectory)));

                SteamConfiguration steamConfiguration = SteamConfiguration.Create(builder => builder.WithProtocolTypes(GlobalConfig.SteamProtocols).WithCellID(GlobalDatabase.CellID).WithServerListProvider(GlobalDatabase.ServerListProvider).WithHttpClientFactory(() => WebBrowser.GenerateDisposableHttpClient()));

                try {
                    await SteamDirectory.LoadAsync(steamConfiguration).ConfigureAwait(false);

                    ArchiLogger.LogGenericInfo(Strings.Success);
                } catch {
                    ArchiLogger.LogGenericWarning(Strings.BotSteamDirectoryInitializationFailed);
                    await Task.Delay(5000).ConfigureAwait(false);
                }
            }

            HashSet <string> botNames;

            try {
                botNames = Directory.EnumerateFiles(SharedInfo.ConfigDirectory, "*" + SharedInfo.ConfigExtension).Select(Path.GetFileNameWithoutExtension).Where(botName => !string.IsNullOrEmpty(botName) && IsValidBotName(botName)).ToHashSet(botsComparer);
            } catch (Exception e) {
                ArchiLogger.LogGenericException(e);

                return;
            }

            if (botNames.Count == 0)
            {
                ArchiLogger.LogGenericWarning(Strings.ErrorNoBotsDefined);

                return;
            }

            if (botNames.Count > MaximumRecommendedBotsCount)
            {
                ArchiLogger.LogGenericWarning(string.Format(Strings.WarningExcessiveBotsCount, MaximumRecommendedBotsCount));
                await Task.Delay(10000).ConfigureAwait(false);
            }

            await Utilities.InParallel(botNames.OrderBy(botName => botName).Select(Bot.RegisterBot)).ConfigureAwait(false);
        }
Ejemplo n.º 4
0
        void steam_connection()
        {
            uint cellid = 0;

            // if we've previously connected and saved our cellid, load it.
            if (File.Exists("cellid.txt"))
            {
                if (!uint.TryParse(File.ReadAllText("cellid.txt"), out cellid))
                {
                    Console.WriteLine("Error parsing cellid from cellid.txt. Continuing with cellid 0.");
                    Log.w("Error parsing cellid from cellid.txt. Continuing with cellid 0.");
                    cellid = 0;
                }
                else
                {
                    Console.WriteLine($"Using persisted cell ID {cellid}");
                    Log.w($"Using persisted cell ID {cellid}");
                }
            }

            var config = SteamConfiguration.Create(b =>
                                                   b.WithCellID(cellid)
                                                   .WithServerListProvider(new FileStorageServerListProvider("servers_list.bin")));

            Log.w("Created new server list");

            steamClient = new SteamClient(config);
            Log.w("Creating client...");
            steamWorkshop = new SteamWorkshop();
            SteamDirectory.LoadAsync(config);
            Log.w("Loading steam directory");
            steamClient.AddHandler(steamWorkshop);

            manager = new CallbackManager(steamClient);

            steamUser = steamClient.GetHandler <SteamUser>();

            manager.Subscribe <SteamClient.ConnectedCallback>(OnConnected);
            manager.Subscribe <SteamUser.LoggedOnCallback>(OnLoggedOn);
            manager.Subscribe <SteamUser.LoggedOffCallback>(OnLoggedOff);
            manager.Subscribe <SteamClient.DisconnectedCallback>(OnDisconnect);
            manager.Subscribe <SteamUser.UpdateMachineAuthCallback>(OnMachineAuth);
            manager.Subscribe <SteamUser.LoginKeyCallback>(OnLoginKey);

            steamClient.Connect();
            Log.w("Connecting to steam...");
            while (isRunning)
            {
                try {
                    manager.RunWaitCallbacks(TimeSpan.FromSeconds(1));
                }
                catch (Exception)
                {
                }
            }
        }
Ejemplo n.º 5
0
        private async Task UpdateCMListViaWebAPI()
        {
            Log.WriteInfo("Web API", "Updating CM list");

            try
            {
                var servers = (await SteamDirectory.LoadAsync(SharedConfig, int.MaxValue, CancellationToken.None)).ToList();

                Log.WriteInfo("Web API", "Got {0} CMs", servers.Count);

                UpdateCMList(servers);
            }
            catch (Exception e)
            {
                Log.WriteError("Web API", "{0}", e);
            }
        }
Ejemplo n.º 6
0
        private async Task UpdateCMListViaWebAPI()
        {
            Log.WriteInfo("Updating CM list using webapi");

            try
            {
                var globalServers     = (await SteamDirectory.LoadAsync(SharedConfig, int.MaxValue, CancellationToken.None)).ToList();
                var chinaRealmServers = (await LoadChinaCMList(SharedConfig)).Where(s => !globalServers.Contains(s)).ToList();
                var servers           = globalServers.Concat(chinaRealmServers);

                Log.WriteInfo($"Got {globalServers.Count} servers plus {chinaRealmServers.Count} chinese servers");

                UpdateCMList(servers);
            }
            catch (Exception e)
            {
                Log.WriteError($"Web API Exception: {e}");
            }
        }