Пример #1
0
        internal static PlayerServerViewModel BuildViewModelForTransferedPlayer(ArkServerContext context, string steamId, ulong[] playerIds)
        {
            if (playerIds == null || playerIds.Length == 0)
            {
                return(null);
            }

            //there will be no player profile so most data cannot be set
            //a tribe where the player is a member may exist tho

            var tribe = context.Tribes?.FirstOrDefault(x => playerIds.Any(y => x.MemberIds.Contains((int)y)));

            if (tribe == null)
            {
                return(null);
            }
            var playerId = playerIds.First(x => tribe.MemberIds.Contains((int)x));

            var vm = new PlayerServerViewModel
            {
                ClusterKey = context.Config.Key,
                SteamId    = steamId,
                TribeId    = tribe.Id,
                TribeName  = tribe.Name,
                SavedAt    = tribe.SavedAt
            };

            vm.Creatures.AddRange(BuildCreatureViewModelsForPlayerId(context, playerId));

            return(vm);
        }
Пример #2
0
        /// <param name="id">steamId</param>
        /// <returns></returns>
        public PlayerViewModel Get(string id)
        {
            var result = new PlayerViewModel
            {
            };

            var players = _contextManager.Servers.ToDictionary(x => x.Config.Key, x => x.Players?.FirstOrDefault(y => y.SteamId.Equals(id, StringComparison.OrdinalIgnoreCase)));

            foreach (var context in _contextManager.Servers)
            {
                PlayerServerViewModel vm = null;

                var player = players[context.Config.Key];
                if (player == null)
                {
                    vm = BuildViewModelForTransferedPlayer(context, id, players.Values.Where(x => x != null).Select(x => x.Id).ToArray());                 //player have local profile on other server
                }
                else
                {
                    vm = BuildViewModelForPlayer(context, player);  //player with local profile
                }
                if (vm == null)
                {
                    continue;
                }

                result.Servers.Add(context.Config.Key, vm);
                result.MapNames.Add(context.Config.Key, context.SaveState?.MapName);
            }

            foreach (var context in _contextManager.Clusters)
            {
                var cloudInventory = context.CloudInventories?.FirstOrDefault(x => x.SteamId.Equals(id, StringComparison.OrdinalIgnoreCase));
                if (cloudInventory == null)
                {
                    continue;
                }

                var vm = BuildClusterViewModelForPlayer(context, cloudInventory);
                if (vm == null)
                {
                    continue;
                }

                result.Clusters.Add(context.Config.Key, vm);
            }

            return(result);
        }
Пример #3
0
        internal static PlayerServerViewModel BuildViewModelForPlayer(ArkServerContext context, ArkPlayer player)
        {
            var vm = new PlayerServerViewModel
            {
                ClusterKey    = context.Config.Key,
                SteamId       = player.SteamId,
                CharacterName = player.CharacterName,
                Gender        = player.Gender.ToString(),
                Level         = player.CharacterLevel,
                Latitude      = player.Location?.Latitude,
                Longitude     = player.Location?.Longitude,
                TopoMapX      = player.Location?.TopoMapX,
                TopoMapY      = player.Location?.TopoMapY,
                EngramPoints  = player.TotalEngramPoints,
                TribeId       = player.TribeId,
                TribeName     = player.TribeId.HasValue ? context.Tribes.FirstOrDefault(x => x.Id == player.TribeId.Value)?.Name : null,
                SavedAt       = player.SavedAt
            };

            vm.Creatures.AddRange(BuildCreatureViewModelsForPlayerId(context, player.Id));

            return(vm);
        }
Пример #4
0
        public ActionResult <PlayerViewModel> Get([PlayerId] string id)
        {
            var demoMode = IsDemoMode() ? new DemoMode() : null;
            var result   = new PlayerViewModel
            {
            };

            var uservm = WebApiHelper.GetUser(HttpContext, _config);

            // access control
            var incProfile            = HasFeatureAccess("player", "profile", id);
            var incProfileDetailed    = HasFeatureAccess("player", "profile-detailed", id);
            var incCreatures          = HasFeatureAccess("player", "creatures", id);
            var incCreaturesBaseStats = HasFeatureAccess("player", "creatures-basestats", id);
            var incCreaturesCloud     = HasFeatureAccess("player", "creatures-cloud", id);
            var incCrops       = HasFeatureAccess("player", "crops", id);
            var incGenerators  = HasFeatureAccess("player", "generators", id);
            var incKibblesEggs = HasFeatureAccess("player", "kibbles-eggs", id);
            var incTribeLog    = HasFeatureAccess("player", "tribelog", id);

            var players = _contextManager.Servers.ToDictionary(x => x.Config.Key, x => x.Players?.FirstOrDefault(y => y.SteamId.Equals(id, StringComparison.OrdinalIgnoreCase)));

            foreach (var context in _contextManager.Servers)
            {
                PlayerServerViewModel vm = null;

                var player = players[context.Config.Key];
                if (player == null)
                {
                    vm = BuildViewModelForTransferedPlayer(
                        context,
                        _config,
                        id,
                        players.Values.Where(x => x != null).Select(x => x.Id).ToArray(),
                        demoMode,
                        incProfile,
                        incProfileDetailed,
                        incCreatures,
                        incCreaturesBaseStats,
                        incCreaturesCloud,
                        incCrops,
                        incGenerators,
                        incKibblesEggs,
                        incTribeLog); //player have local profile on other server
                }
                else
                {
                    vm = BuildViewModelForPlayer(
                        context,
                        _config,
                        player,
                        demoMode,
                        incProfile,
                        incProfileDetailed,
                        incCreatures,
                        incCreaturesBaseStats,
                        incCreaturesCloud,
                        incCrops,
                        incGenerators,
                        incKibblesEggs,
                        incTribeLog); //player with local profile
                }

                if (vm == null)
                {
                    continue;
                }

                result.Servers.Add(context.Config.Key, vm);
                result.MapNames.Add(context.Config.Key, context.SaveState?.MapName);
            }

            foreach (var context in _contextManager.Clusters)
            {
                var cloudInventory = context.Inventories?.FirstOrDefault(x => x.SteamId.Equals(id, StringComparison.OrdinalIgnoreCase));
                if (cloudInventory == null)
                {
                    continue;
                }

                var vm = BuildClusterViewModelForPlayer(context, cloudInventory, demoMode, incCreaturesCloud);
                if (vm == null)
                {
                    continue;
                }

                result.Clusters.Add(context.Config.Key, vm);
            }

            return(result);
        }
Пример #5
0
        internal static PlayerServerViewModel BuildViewModelForPlayer(
            ArkServerContext context,
            IConfig config,
            ArkPlayer player,
            DemoMode demoMode,
            bool incProfile,
            bool incProfileDetailed,
            bool incCreatures,
            bool incCreaturesBaseStats,
            bool incCreaturesCloud,
            bool incCrops,
            bool incGenerators,
            bool incKibblesEggs,
            bool incTribeLog)
        {
            var tribe = player.Tribe;
            var vm    = new PlayerServerViewModel
            {
                ClusterKey    = context.Config.Key,
                SteamId       = player.SteamId,
                FakeSteamId   = demoMode?.GetSteamId(player.SteamId),
                CharacterName = demoMode?.GetPlayerName(player.Id) ?? player.CharacterName,
                TribeId       = player.TribeId,
                TribeName     = tribe != null?demoMode?.GetTribeName(tribe.Id) ?? tribe?.Name : null,
                SavedAt       = player.SavedAt
            };

            if (incProfileDetailed)
            {
                vm.Latitude  = player.Location?.Latitude;
                vm.Longitude = player.Location?.Longitude;
                vm.TopoMapX  = player.Location?.TopoMapX;
                vm.TopoMapY  = player.Location?.TopoMapY;

                if (!player.IsExternalPlayer)
                {
                    vm.Gender       = player.Gender.ToString();
                    vm.Level        = player.CharacterLevel;
                    vm.EngramPoints = player.TotalEngramPoints;
                }
            }

            if (incCreatures)
            {
                vm.Creatures.AddRange(BuildCreatureViewModelsForPlayerId(context, config, player.Id, demoMode, incCreaturesBaseStats));
            }
            if (incKibblesEggs)
            {
                vm.KibblesAndEggs = BuildKibblesAndEggsViewModelsForPlayerId(context, player.Id);
            }
            if (incCrops)
            {
                vm.CropPlots = BuildCropPlotViewModelsForPlayerId(context, player.Id);
            }
            if (incGenerators)
            {
                vm.Generators = BuildGeneratorViewModelsForPlayerId(context, player.Id);
            }
            if (incTribeLog)
            {
                vm.TribeLog = BuildTribeLogViewModelsForPlayerId(context, player.Id, config.WebApp.TribeLogLimit, config.WebApp.TribeLogColors);
            }

            return(vm);
        }
Пример #6
0
        internal static PlayerServerViewModel BuildViewModelForTransferedPlayer(
            ArkServerContext context,
            IConfig config,
            string steamId,
            int[] playerIds,
            DemoMode demoMode,
            bool incProfile,
            bool incProfileDetailed,
            bool incCreatures,
            bool incCreaturesBaseStats,
            bool incCreaturesCloud,
            bool incCrops,
            bool incGenerators,
            bool incKibblesEggs,
            bool incTribeLog)
        {
            if (playerIds == null || playerIds.Length == 0)
            {
                return(null);
            }

            //there will be no player profile so most data cannot be set
            //a tribe where the player is a member may exist tho

            //note: potentially there could be multiple tribes with the same player, which player.Tribe protects us against. here we just select the first one which is not optimal
            var tribe = context.Tribes?.FirstOrDefault(x => playerIds.Any(y => x.MemberIds.Contains(y)));

            if (tribe == null)
            {
                return(null);
            }
            var playerId = playerIds.First(x => tribe.MemberIds.Contains(x));

            var vm = new PlayerServerViewModel
            {
                ClusterKey = context.Config.Key,
                SteamId    = steamId,
                TribeId    = tribe.Id,
                TribeName  = demoMode?.GetTribeName(tribe.Id) ?? tribe.Name,
                SavedAt    = tribe.SavedAt
            };

            if (demoMode != null)
            {
                vm.FakeSteamId = demoMode.GetSteamId(steamId);
            }

            if (incCreatures)
            {
                vm.Creatures.AddRange(BuildCreatureViewModelsForPlayerId(context, config, playerId, demoMode, incCreaturesBaseStats));
            }
            if (incKibblesEggs)
            {
                vm.KibblesAndEggs = BuildKibblesAndEggsViewModelsForPlayerId(context, playerId);
            }
            if (incCrops)
            {
                vm.CropPlots = BuildCropPlotViewModelsForPlayerId(context, playerId);
            }
            if (incGenerators)
            {
                vm.Generators = BuildGeneratorViewModelsForPlayerId(context, playerId);
            }
            if (incTribeLog)
            {
                vm.TribeLog = BuildTribeLogViewModelsForPlayerId(context, playerId, config.WebApp.TribeLogLimit, config.WebApp.TribeLogColors);
            }

            return(vm);
        }
Пример #7
0
        internal static PlayerServerViewModel BuildViewModelForTransferedPlayer(
            ArkServerContext context,
            IConfig config,
            string steamId,
            int[] playerIds,
            DemoMode demoMode,
            bool incProfile,
            bool incProfileDetailed,
            bool incCreatures,
            bool incCreaturesBaseStats,
            bool incCreaturesCloud,
            bool incCrops,
            bool incGenerators,
            bool incKibblesEggs,
            bool incTribeLog)
        {
            if (playerIds == null || playerIds.Length == 0)
            {
                return(null);
            }

            //there will be no player profile so most data cannot be set
            //a tribe where the player is a member may exist tho

            var tribe = context.Tribes?.FirstOrDefault(x => playerIds.Any(y => x.MemberIds.Contains((int)y)));

            if (tribe == null)
            {
                return(null);
            }
            var playerId = playerIds.First(x => tribe.MemberIds.Contains((int)x));

            var vm = new PlayerServerViewModel
            {
                ClusterKey = context.Config.Key,
                SteamId    = steamId,
                TribeId    = tribe.Id,
                TribeName  = demoMode?.GetTribeName(tribe.Id) ?? tribe.Name,
                SavedAt    = tribe.SavedAt
            };

            if (demoMode != null)
            {
                vm.FakeSteamId = demoMode.GetSteamId(steamId);
            }

            if (incCreatures)
            {
                vm.Creatures.AddRange(BuildCreatureViewModelsForPlayerId(context, config, playerId, demoMode, incCreaturesBaseStats));
            }
            if (incKibblesEggs)
            {
                vm.KibblesAndEggs = BuildKibblesAndEggsViewModelsForPlayerId(context, playerId);
            }
            if (incCrops)
            {
                vm.CropPlots = BuildCropPlotViewModelsForPlayerId(context, playerId);
            }
            if (incGenerators)
            {
                vm.ElectricalGenerators = BuildElectricalGeneratorViewModelsForPlayerId(context, playerId);
            }
            if (incTribeLog)
            {
                vm.TribeLog = BuildTribeLogViewModelsForPlayerId(context, playerId, 100);
            }

            return(vm);
        }