StripColors() public static method

Strips all ampersand color codes, and unescapes doubled-up ampersands.
public static StripColors ( [ input ) : string
input [
return string
Example #1
0
        public static void Log(LogType type, [NotNull] string message, [NotNull] params object[] args)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }
            if (args.Length > 0)
            {
                try
                {
                    message = String.Format(message, args);
                }
                catch (Exception e) {
                    message = e.StackTrace + "\n" + message;
                }
            }
            if (!Enabled)
            {
                return;
            }

            message = Color.StripColors(message, true);
            string line = DateTime.Now.ToString(TimeFormat, formatter) + " > " + GetPrefix(type) + message;     // localized

            lock ( LogLock ) {
                RaiseLoggedEvent(message, line, type);

                RecentMessages.Enqueue(line);
                while (RecentMessages.Count > MaxRecentMessages)
                {
                    RecentMessages.Dequeue();
                }

                if (LogFileOptions[(int)type])
                {
                    try {
                        File.AppendAllText(Path.Combine(Paths.LogPath, CurrentLogFileName),
                                           line + Environment.NewLine);
                    } catch (Exception ex) {
                        string errorMessage = "Logger.Log: " + ex;
                        line = String.Format("{0} > {1}{2}",
                                             DateTime.Now.ToString(TimeFormat, formatter),   // localized
                                             GetPrefix(LogType.Error),
                                             errorMessage);
                        RaiseLoggedEvent(errorMessage,
                                         line,
                                         LogType.Error);
                    }
                }
            }
        }
Example #2
0
        internal HeartbeatData([NotNull] Uri heartbeatUri)
        {
            if (heartbeatUri == null)
            {
                throw new ArgumentNullException("heartbeatUri");
            }
            IsPublic        = ConfigKey.IsPublic.Enabled();
            MaxPlayers      = ConfigKey.MaxPlayers.GetInt();
            PlayerCount     = Server.CountPlayers(false);
            Port            = Server.Port;
            ProtocolVersion = Config.ProtocolVersion;
            Salt            = Heartbeat.Salt;
            ServerName      = Color.StripColors(ConfigKey.ServerName.GetString(), false);

            if (Heartbeat.sendUptime)
            {
                string uptime     = "[Uptime: " + (DateTime.UtcNow.Subtract(Server.StartTime)).ToMiniString() + "]";
                string namePadded = ServerName.PadRight(64, ' ');
                ServerName = namePadded.Remove(namePadded.Length - uptime.Length, uptime.Length) + uptime;
            }
            CustomData   = new Dictionary <string, string>();
            HeartbeatUri = heartbeatUri;
        }
Example #3
0
 public static void SendChannelMessage([NotNull] string line)
 {
     if (line == null)
     {
         throw new ArgumentNullException("line");
     }
     if (channelNames == null)
     {
         return;                        // in case IRC bot is disabled.
     }
     if (ConfigKey.IRCUseColor.Enabled())
     {
         line = Color.ToIRCColorCodes(line);
     }
     else
     {
         line = NonPrintableChars.Replace(line, "");
         line = Color.StripColors(line).Trim();
     }
     for (int i = 0; i < channelNames.Length; i++)
     {
         SendRawMessage(IRCCommands.Privmsg(channelNames[i], line));
     }
 }
Example #4
0
        public static Position FromString(string text)
        {
            Position pos = new Position();

            try {
                // New ToPlainString format
                if (text.IndexOf('_') >= 0)
                {
                    string[] bits = text.Split('_');
                    pos.X = int.Parse(bits[0]);
                    pos.Y = int.Parse(bits[1]);
                    pos.Z = int.Parse(bits[2]);
                    pos.R = byte.Parse(bits[3]);
                    pos.L = byte.Parse(bits[4]);
                    return(pos);
                }

                // Backwards compatibility with old format
                string pat = @"\(X:(.*)Y:(.*) Z:(.*) R:(.*) L:(.*)\)";
                Regex  r   = new Regex(pat, RegexOptions.IgnoreCase);
                text = Color.StripColors(text, true);
                Match m = r.Match(text);
                while (m.Success)
                {
                    for (int i = 1; i <= 5; i++)
                    {
                        string g = m.Groups[i].ToString();
                        switch (i)
                        {
                        case 1:
                            pos.X = int.Parse(g);
                            break;

                        case 2:
                            pos.Y = int.Parse(g);
                            break;

                        case 3:
                            pos.Z = int.Parse(g);
                            break;

                        case 4:
                            pos.R = byte.Parse(g);
                            break;

                        case 5:
                            pos.L = byte.Parse(g);
                            break;

                        default:
                            break;
                        }
                    }
                    m = m.NextMatch();
                }
            } catch (Exception ex) {
                Logger.Log(LogType.Error, "Position.FromString() failed to get a position");
                Logger.Log(LogType.Error, ex.ToString());
            }
            return(pos);
        }