Exemple #1
0
        private static async Task GetApp(HttpListenerContext context)
        {
            var appid = context.Request.QueryString.Get("appid");

            if (appid == null)
            {
                throw new MissingFieldException("appid parameter is missing");
            }

            var result = await AppCommand.GetAppData(uint.Parse(appid));

            await WriteJsonResponse(result, context.Response);
        }
Exemple #2
0
        public override async Task OnCommand(CommandArguments command)
        {
            if (string.IsNullOrWhiteSpace(command.Message))
            {
                command.Reply($"Usage:{Colors.OLIVE} players <appid or partial game name>");

                return;
            }

            if (!uint.TryParse(command.Message, out var appID))
            {
                appID = await AppCommand.TrySearchAppId(command);

                if (appID == 0)
                {
                    return;
                }
            }

            var task = Steam.Instance.UserStats.GetNumberOfCurrentPlayers(appID);

            task.Timeout = TimeSpan.FromSeconds(10);
            var callback = await task;

            if (appID == 0)
            {
                appID = 753;
            }

            var name = Steam.GetAppName(appID, out var appType);

            if (callback.Result != EResult.OK)
            {
                command.Reply($"Unable to request player count for {Colors.BLUE}{name}{Colors.NORMAL}: {Colors.RED}{callback.Result}{Colors.NORMAL} -{Colors.DARKBLUE} {SteamDB.GetAppUrl(appID, "graphs")}");

                return;
            }

            var  numPlayers = callback.NumPlayers;
            uint dailyPlayers;

            await using (var db = await Database.GetConnectionAsync())
            {
                dailyPlayers = await db.ExecuteScalarAsync <uint>("SELECT `MaxDailyPlayers` FROM `OnlineStats` WHERE `AppID` = @appID", new { appID });

                if (appID == 753 && numPlayers == 0)
                {
                    numPlayers = await db.ExecuteScalarAsync <uint>("SELECT `CurrentPlayers` FROM `OnlineStats` WHERE `AppID` = @appID", new { appID });
                }
            }

            if (dailyPlayers < numPlayers)
            {
                dailyPlayers = numPlayers;
            }

            var type = "playing";

            switch (appType)
            {
            case EAppType.Tool:
            case EAppType.Config:
            case EAppType.Application:
                type = "using";
                break;

            case EAppType.Media:
            case EAppType.Series:
            case EAppType.Video:
                type = "watching";
                break;

            case EAppType.Demo:
                type = "demoing";
                break;

            case EAppType.Guide:
            case EAppType.Comic:
                type = "reading";
                break;

            case EAppType.Hardware:
                type = "bricking";
                break;
            }

            command.Reply(
                $"{Colors.OLIVE}{numPlayers:N0}{Colors.NORMAL} {type} {Colors.BLUE}{name}{Colors.NORMAL} - 24h:{Colors.GREEN} {dailyPlayers:N0}{Colors.NORMAL} -{Colors.DARKBLUE} {SteamDB.GetAppUrl(appID, "graphs")}"
                );
        }
        public override async Task OnCommand(CommandArguments command)
        {
            if (string.IsNullOrWhiteSpace(command.Message))
            {
                command.Reply("Usage:{0} players <appid or partial game name>", Colors.OLIVE);

                return;
            }

            string name;

            if (!uint.TryParse(command.Message, out var appID))
            {
                appID = await AppCommand.TrySearchAppId(command);

                if (appID == 0)
                {
                    return;
                }
            }

            var callback = await Steam.Instance.UserStats.GetNumberOfCurrentPlayers(appID);

            if (appID == 0)
            {
                appID = 753;
            }

            name = Steam.GetAppName(appID, out var appType);

            if (callback.Result != EResult.OK)
            {
                command.Reply($"Unable to request player count for {Colors.BLUE}{name}{Colors.NORMAL}: {Colors.RED}{callback.Result}{Colors.NORMAL} -{Colors.DARKBLUE} {SteamDB.GetAppURL(appID, "graphs")}");

                return;
            }

            var type = "playing";

            switch (appType)
            {
            case "Tool":
            case "Config":
            case "Application":
                type = "using";
                break;

            case "Legacy Media":
            case "Series":
            case "Video":
                type = "watching";
                break;

            case "Demo":
                type = "demoing";
                break;

            case "Guide":
                type = "reading";
                break;

            case "Hardware":
                type = "bricking";
                break;
            }

            command.Reply(
                "{0}{1:N0}{2} {3} {4}{5}{6} -{7} {8}",
                Colors.OLIVE, callback.NumPlayers, Colors.NORMAL,
                type,
                Colors.BLUE, name, Colors.NORMAL,
                Colors.DARKBLUE, SteamDB.GetAppURL(appID, "graphs")
                );
        }