コード例 #1
0
    public ActionResult <IEnumerable <TopPlayerOnlineResponse> > Get()
    {
        var response = _tempusCacheService.TopPlayersOnline.Select(x => new TopPlayerOnlineResponse
        {
            Rank       = x.Rank,
            RankClass  = x.RankClass,
            TempusId   = x.Id,
            SteamName  = x.Name,
            RealName   = _tempusCacheService.GetRealName(x.Id),
            ServerInfo = new ServerInfoShortResponse
            {
                CurrentMap     = x.Server.GameInfo.CurrentMap,
                Id             = x.Server.ServerInfo.Id,
                CurrentPlayers = x.Server.GameInfo.PlayerCount,
                MaxPlayers     = x.Server.GameInfo.MaxPlayers,
                Alias          = x.Server.ServerInfo.Shortname,
                IpAddress      = x.Server.ServerInfo.Addr + ":" + x.Server.ServerInfo.Port,
                Name           = x.Server.ServerInfo.Name
            }
        });

        if (!response.Any())
        {
            return(NoContent());
        }

        return(Ok(response));
    }
コード例 #2
0
ファイル: ActivityController.cs プロジェクト: Hona/TempusHub
    private List <RecordResponse> TransformRecordData(IEnumerable <RecordWithZonedData> recordBase)
    {
        var output = recordBase.Select(x =>
        {
            var cachedRecord = x.Record as CachedTempusRecordBase;

            return(new RecordResponse
            {
                PlayerInfo = new PlayerResponse
                {
                    Id = x.Record.PlayerInfo.Id,
                    Steamid = x.Record.PlayerInfo.Steamid,
                    Name = x.Record.PlayerInfo.Name,
                    RealName = null
                },
                CachedTime = cachedRecord?.CachedTime,
                MapInfo = x.Record.MapInfo,
                RecordInfo = x.Record.RecordInfo,
                ZoneInfo = x.Record.ZoneInfo
            });
        }).ToList();

        foreach (var record in output)
        {
            var realName = _tempusCacheService.GetRealName(record.PlayerInfo.Id);

            if (realName == null)
            {
                continue;
            }

            var realNamePlayer = new PlayerResponse
            {
                Id       = record.PlayerInfo.Id,
                Name     = record.PlayerInfo.Name,
                Steamid  = record.PlayerInfo.Steamid,
                RealName = realName
            };

            record.PlayerInfo = realNamePlayer;
        }

        return(output);
    }