Пример #1
0
        public async Task <IActionResult> Clientguid(string clientguid)
        {
            long decimalNetworkId = clientguid.ConvertGuidToLong(System.Globalization.NumberStyles.Integer);
            var  clientInfo       = Manager.GetActiveClients()
                                    .FirstOrDefault(c => c.NetworkId == decimalNetworkId);

            if (clientInfo != null)
            {
                rankName = clientInfo.Level.ClanTag(Config);

                customRankName = await _metaService.GetPersistentMeta("rank", clientInfo);

                if (customRankName == null)
                {
                    await _metaService.AddPersistentMeta("rank", "none", clientInfo);

                    customRankName = await _metaService.GetPersistentMeta("rank", clientInfo);
                }

                if (!(customRankName.Value.Contains("none")) && !(customRankName.Value.Contains("None")) && !(customRankName.Value.Contains("NONE")))
                {
                    rankName = customRankName.Value;
                }

                var sb = new StringBuilder();
                sb.AppendLine(rankName);

                return(Content(sb.ToString()));
            }

            return(Content("Error: Client info is null"));
        }
Пример #2
0
 public async void LockerGunStatus(EFClient client, string mapName)
 {
     if ((await _metaService.GetPersistentMeta($"{mapName}_gun", client)) == null)
     {
         await _metaService.AddPersistentMeta($"{mapName}_gun", "none", client);
     }
 }
Пример #3
0
 public async Task <int> GetBankMeta(EFClient C)
 {
     if (await _metaService.GetPersistentMeta("BankBalance", C) == null)
     {
         _ = _metaService.AddPersistentMeta("BankBalance", "0", C);
         return(0);
     }
     return(Convert.ToInt32((await _metaService.GetPersistentMeta("BankBalance", C)).Value));
 }
Пример #4
0
        public override async Task ExecuteAsync(GameEvent E)
        {
            //var S = E.Owner;
            rank_string = "none";
            if (E.Data != null)
            {
                rank_string = E.Data;
            }
            var rank_player_var = await _metaService.GetPersistentMeta(rank, E.Target);

            if (rank_player_var == null)
            {
                await _metaService.AddPersistentMeta(rank, "none", E.Target);

                rank_player_var = await _metaService.GetPersistentMeta(rank, E.Target);
            }

            if (rank_string.Length > 0 && rank_string.Length < 9)
            {
                await _metaService.AddPersistentMeta(rank, rank_string, E.Target);

                rank_player_var = await _metaService.GetPersistentMeta(rank, E.Target);

                if (rank_player_var.Value == "none" || rank_player_var.Value == "None" || rank_player_var.Value == "NONE")
                {
                    //E.Origin.Tell(E.Target.Name + "'s rank has been reset");
                    rank_string = E.Target.Level.ClanTag(Config);
                    E.Origin.Tell(E.Target.Name + "'s rank has been reset to: " + rank_string);
                }

                else
                {
                    rank_string = rank_player_var.Value;
                    E.Origin.Tell("New rank set: [" + rank_player_var.Value + "]" + E.Target.Name);
                }
            }
            else
            {
                E.Origin.Tell($"invalid rank length (between 1-8 characters), set rank to none, or use !ResetRank to reset");
            }


            await E.Owner.ExecuteCommandAsync("setclantag" + " " + E.Target.ClientNumber + " " + rank_string);
        }
Пример #5
0
        public async Task OnEventAsync(GameEvent E, Server S)// => Task.CompletedTask;
        {
            if (E.Type == GameEvent.EventType.Join || E.Type == GameEvent.EventType.ChangePermission)
            {
                Thread.Sleep(10000);
                var rank_player_var = await _metaService.GetPersistentMeta(rank, E.Origin);

                rankName = E.Origin.Level.ClanTag(Config);

                rank_player_var = await _metaService.GetPersistentMeta("rank", E.Origin);

                if (rank_player_var == null)
                {
                    await _metaService.AddPersistentMeta("rank", "none", E.Origin);

                    rank_player_var = await _metaService.GetPersistentMeta("rank", E.Origin);
                }

                if (!(rank_player_var.Value.Contains("none")) && !(rank_player_var.Value.Contains("None")) && !(rank_player_var.Value.Contains("NONE")))
                {
                    rankName = rank_player_var.Value;
                }

                await S.ExecuteCommandAsync("setclantag" + " " + E.Origin.ClientNumber + " " + rankName);
            }
            if (E.Type == GameEvent.EventType.Start || E.Type == GameEvent.EventType.MapEnd || E.Type == GameEvent.EventType.MapChange)
            {
                Thread.Sleep(10000);
                IList <EFClient> currentclients = E.Owner.Manager.GetActiveClients();
                foreach (EFClient client in currentclients)
                {
                    var rank_player_var = await _metaService.GetPersistentMeta(rank, client);

                    rankName = client.Level.ClanTag(Config);

                    rank_player_var = await _metaService.GetPersistentMeta("rank", client);

                    if (rank_player_var == null)
                    {
                        await _metaService.AddPersistentMeta("rank", "none", client);

                        rank_player_var = await _metaService.GetPersistentMeta("rank", client);
                    }

                    if (!(rank_player_var.Value.Contains("none")) && !(rank_player_var.Value.Contains("None")) && !(rank_player_var.Value.Contains("NONE")))
                    {
                        rankName = rank_player_var.Value;
                    }

                    await S.ExecuteCommandAsync("setclantag" + " " + client.ClientNumber + " " + rankName);
                }
            }
            //return Task.CompletedTask;
        }
Пример #6
0
        public override async Task ExecuteAsync(GameEvent gameEvent)
        {
            var availableTags = await _metaService.GetPersistentMeta(EFMeta.ClientTagName);

            var matchingTag = availableTags.FirstOrDefault(tag => tag.Value == gameEvent.Data);

            if (matchingTag == null)
            {
                gameEvent.Origin.Tell(_translationLookup["COMMANDS_SET_CLIENT_TAG_FAIL"].FormatExt(gameEvent.Data));
                return;
            }

            gameEvent.Target.Tag = matchingTag.Value;
            await _metaService.AddPersistentMeta(EFMeta.ClientTag, string.Empty, gameEvent.Target, matchingTag);

            gameEvent.Origin.Tell(_translationLookup["COMMANDS_SET_CLIENT_TAG_SUCCESS"].FormatExt(matchingTag.Value));
        }
Пример #7
0
        public override async Task ExecuteAsync(GameEvent gameEvent)
        {
            var tags = await _metaService.GetPersistentMeta(EFMeta.ClientTagName);

            gameEvent.Origin.Tell(tags.Select(tag => tag.Value));
        }
Пример #8
0
        public async Task <IActionResult> ProfileAsync(int id, MetaType?metaFilterType)
        {
            var client = await Manager.GetClientService().Get(id);

            if (client == null)
            {
                return(NotFound());
            }

            var activePenalties = (await Manager.GetPenaltyService().GetActivePenaltiesAsync(client.AliasLinkId, client.IPAddress));


            int    displayLevelInt = (int)client.Level;
            string displayLevel    = client.Level.ToLocalizedLevelName();

            if (!Authorized && client.Level.ShouldHideLevel())
            {
                displayLevelInt = (int)Permission.User;
                displayLevel    = Permission.User.ToLocalizedLevelName();
            }

            var clientDto = new PlayerInfo()
            {
                Name      = client.Name,
                Level     = displayLevel,
                LevelInt  = displayLevelInt,
                ClientId  = client.ClientId,
                IPAddress = client.IPAddressString,
                NetworkId = client.NetworkId,
                Meta      = new List <InformationResponse>(),
                Aliases   = client.AliasLink.Children
                            .Select(_alias => _alias.Name)
                            .GroupBy(_alias => _alias.StripColors())
                            // we want the longest "duplicate" name
                            .Select(_grp => _grp.OrderByDescending(_name => _name.Length).First())
                            .Distinct()
                            .OrderBy(a => a)
                            .ToList(),
                IPs = client.AliasLink.Children
                      .Where(i => i.IPAddress != null)
                      .OrderByDescending(i => i.DateAdded)
                      .Select(i => i.IPAddress.ConvertIPtoString())
                      .Prepend(client.CurrentAlias.IPAddress.ConvertIPtoString())
                      .Distinct()
                      .ToList(),
                HasActivePenalty = activePenalties.Any(_penalty => _penalty.Type != PenaltyType.Flag),
                Online           = Manager.GetActiveClients().FirstOrDefault(c => c.ClientId == client.ClientId) != null,
                TimeOnline       = (DateTime.UtcNow - client.LastConnection).HumanizeForCurrentCulture(),
                LinkedAccounts   = client.LinkedAccounts,
                MetaFilterType   = metaFilterType
            };

            var meta = await _metaService.GetRuntimeMeta <InformationResponse>(new ClientPaginationRequest
            {
                ClientId = client.ClientId,
                Before   = DateTime.UtcNow
            }, MetaType.Information);

            var gravatar = await _metaService.GetPersistentMeta("GravatarEmail", client);

            if (gravatar != null)
            {
                clientDto.Meta.Add(new InformationResponse()
                {
                    Key   = "GravatarEmail",
                    Type  = MetaType.Other,
                    Value = gravatar.Value
                });
            }

            clientDto.ActivePenalty = activePenalties.OrderByDescending(_penalty => _penalty.Type).FirstOrDefault();
            clientDto.Meta.AddRange(Authorized ? meta : meta.Where(m => !m.IsSensitive));

            string strippedName = clientDto.Name.StripColors();

            ViewBag.Title = strippedName.Substring(strippedName.Length - 1).ToLower()[0] == 's' ?
                            strippedName + "'" :
                            strippedName + "'s";
            ViewBag.Title      += " " + Localization["WEBFRONT_CLIENT_PROFILE_TITLE"];
            ViewBag.Description = $"Client information for {strippedName}";
            ViewBag.Keywords    = $"IW4MAdmin, client, profile, {strippedName}";

            return(View("Profile/Index", clientDto));
        }
Пример #9
0
        private async Task <IEnumerable <InformationResponse> > GetProfileMeta(ClientPaginationRequest request)
        {
            var metaList    = new List <InformationResponse>();
            var lastMapMeta = await _metaService.GetPersistentMeta("LastMapPlayed", new EFClient()
            {
                ClientId = request.ClientId
            });

            if (lastMapMeta != null)
            {
                metaList.Add(new InformationResponse()
                {
                    ClientId      = request.ClientId,
                    MetaId        = lastMapMeta.MetaId,
                    Key           = Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_META_LAST_MAP"],
                    Value         = lastMapMeta.Value,
                    ShouldDisplay = true,
                    Type          = MetaType.Information,
                    Column        = 1,
                    Order         = 6
                });
            }

            var lastServerMeta = await _metaService.GetPersistentMeta("LastServerPlayed", new EFClient()
            {
                ClientId = request.ClientId
            });

            if (lastServerMeta != null)
            {
                metaList.Add(new InformationResponse()
                {
                    ClientId      = request.ClientId,
                    MetaId        = lastServerMeta.MetaId,
                    Key           = Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_META_LAST_SERVER"],
                    Value         = lastServerMeta.Value,
                    ShouldDisplay = true,
                    Type          = MetaType.Information,
                    Column        = 0,
                    Order         = 6
                });
            }

            var client = await _clientEntityService.Get(request.ClientId);

            if (client == null)
            {
                _logger.LogWarning("No client found with id {clientId} when generating profile meta", request.ClientId);
                return(metaList);
            }

            metaList.Add(new InformationResponse()
            {
                ClientId      = client.ClientId,
                Key           = _transLookup["WEBFRONT_PROFILE_META_PLAY_TIME"],
                Value         = TimeSpan.FromHours(client.TotalConnectionTime / 3600.0).HumanizeForCurrentCulture(),
                ShouldDisplay = true,
                Column        = 1,
                Order         = 0,
                Type          = MetaType.Information
            });

            metaList.Add(new InformationResponse()
            {
                ClientId      = client.ClientId,
                Key           = _transLookup["WEBFRONT_PROFILE_META_FIRST_SEEN"],
                Value         = (DateTime.UtcNow - client.FirstConnection).HumanizeForCurrentCulture(),
                ShouldDisplay = true,
                Column        = 1,
                Order         = 1,
                Type          = MetaType.Information
            });

            metaList.Add(new InformationResponse()
            {
                ClientId      = client.ClientId,
                Key           = _transLookup["WEBFRONT_PROFILE_META_LAST_SEEN"],
                Value         = (DateTime.UtcNow - client.LastConnection).HumanizeForCurrentCulture(),
                ShouldDisplay = true,
                Column        = 1,
                Order         = 2,
                Type          = MetaType.Information
            });

            metaList.Add(new InformationResponse()
            {
                ClientId      = client.ClientId,
                Key           = Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_META_CONNECTIONS"],
                Value         = client.Connections.ToString("#,##0", new System.Globalization.CultureInfo(Utilities.CurrentLocalization.LocalizationName)),
                ShouldDisplay = true,
                Column        = 1,
                Order         = 3,
                Type          = MetaType.Information
            });

            metaList.Add(new InformationResponse()
            {
                ClientId    = client.ClientId,
                Key         = Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_META_MASKED"],
                Value       = client.Masked ? Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_META_TRUE"] : Utilities.CurrentLocalization.LocalizationIndex["WEBFRONT_CLIENT_META_FALSE"],
                IsSensitive = true,
                Column      = 1,
                Order       = 4,
                Type        = MetaType.Information
            });

            return(metaList);
        }