コード例 #1
0
ファイル: HomeController.cs プロジェクト: zDasi/fivem
        public async Task <IActionResult> Index()
        {
            var resCount = GetResources().Count(a => GetResourceState(a) == "started");

            var data = new IndexData();

            data.Add("Players", $"{GetNumPlayerIndices()}/{GetConvarInt("sv_maxClients", 0)}");
            data.Add("Resources", $"{resCount} running, {GetNumResources()} loaded");

            data.ResourceCount = resCount;

            var numPlayers     = GetNumPlayerIndices();
            var totalPing      = 0;
            var totalPingCount = 0;

            for (int i = 0; i < numPlayers; i++)
            {
                var index = GetPlayerFromIndex(i);
                var ping  = GetPlayerPing(index);

                if (ping > 0)
                {
                    totalPing += ping;
                    totalPingCount++;
                }
            }

            if (totalPingCount > 0)
            {
                data.AverageLatency = (int)((double)totalPing / totalPingCount);
            }

            return(View(data));
        }
コード例 #2
0
ファイル: HomeController.cs プロジェクト: drewomix/fivem-1
        public async Task <IActionResult> Index()
        {
            if (!User.Identity.IsAuthenticated && cache.TryGetValue <IndexData>("homeData", out var viewData))
            {
                return(View(viewData));
            }

            viewData = await HttpServer.QueueTick(() =>
            {
                var resCount = GetResources().Count(a => GetResourceState(a) == "started");

                var data = new IndexData();
                data.Add("Players", $"{GetNumPlayerIndices()}/{GetConvarInt("sv_maxClients", 0)}");
                data.Add("Resources", $"{resCount} running, {GetNumResources()} loaded");

                data.ResourceCount = resCount;

                var numPlayers     = GetNumPlayerIndices();
                var totalPing      = 0;
                var totalPingCount = 0;

                for (int i = 0; i < numPlayers; i++)
                {
                    var index = GetPlayerFromIndex(i);
                    var ping  = GetPlayerPing(index);

                    if (ping > 0)
                    {
                        totalPing += ping;
                        totalPingCount++;
                    }
                }

                if (totalPingCount > 0)
                {
                    data.AverageLatency = (int)((double)totalPing / totalPingCount);
                }

                return(data);
            });

            cache.Set("homeData", viewData, TimeSpan.FromSeconds(30));

            return(View(viewData));
        }