Ejemplo n.º 1
0
        public static string GetTrimmedPlayerName(string name, int worldId)
        {
            var isPil2NameFormat         = false;
            var isLegacyJaegerNameFormat = false;

            if (WorldService.IsJaegerWorldId(worldId))
            {
                if (_pil2NameRegex.Match(name).Success)
                {
                    isPil2NameFormat = true;
                }
                else if (_legacyJaegerNameRegex.Match(name).Success)
                {
                    isLegacyJaegerNameFormat = true;
                }
            }

            var trimmed    = name;
            var initLength = name.Length;

            if (isPil2NameFormat)
            {
                trimmed = name.Substring(0, initLength - 3);
            }
            else if (isLegacyJaegerNameFormat)
            {
                // Remove outfit tag from beginning of name
                var idx = name.IndexOf("x");
                if (idx >= 0 && idx < 5 && (idx != initLength - 1))
                {
                    trimmed = name.Substring(idx + 1, initLength - idx - 1);
                }
            }

            if (!isPil2NameFormat && _factionSufficRegex.Match(trimmed).Success)
            {
                // Remove faction abbreviation from end of name
                var end = trimmed.Length - 2;
                trimmed = trimmed.Substring(0, end);
            }

            if (string.IsNullOrWhiteSpace(trimmed) || trimmed.Length <= 1)
            {
                trimmed = name;
            }

            return(trimmed);
        }