/// <summary> /// Creates a local ChatMessage instance for given text and /// style settings. /// </summary> /// <param name="Text"></param> /// <param name="IsBold"></param> /// <param name="IsCursive"></param> /// <param name="IsUnderline"></param> /// <param name="Color"></param> /// <returns></returns> public static ChatMessage GetChatMessageForString( string Text, bool IsBold = false, bool IsCursive = false, bool IsUnderline = false, ChatColor Color = ChatColor.Red) { ChatStyle style = new ChatStyle( 0, Text.Length, IsBold, IsCursive, IsUnderline, Color); ChatMessage message = new ChatMessage(); message.FullString = Text; message.Styles.Add(style); return message; }
public unsafe override void ReadFrom(ref byte* Buffer) { base.ReadFrom(ref Buffer); Message = new ChatMessage(ChatMessageType.ServerChatMessage, LookupList, ref Buffer); }
public MessageMessage(ChatMessage Message, LockingDictionary<uint, string> LookupList) : base(MessageTypeGameMode.Message) { this.LookupList = LookupList; this.Message = Message; }
public override int ReadFrom(byte[] Buffer, int StartIndex = 0) { int cursor = StartIndex; cursor += base.ReadFrom(Buffer, cursor); Message = new ChatMessage(ChatMessageType.ServerChatMessage, LookupList, Buffer, cursor); cursor += Message.ByteLength; return cursor - StartIndex; }
/// <summary> /// Creates a colored IRC message string from a ChatMessage instance /// </summary> /// <param name="ChatMessage"></param> /// <returns></returns> public static string CreateIRCMessageFromChatMessage(ChatMessage ChatMessage) { // prefix string s = String.Empty; // insert styles as IRC chatstyles foreach (ChatStyle style in ChatMessage.Styles) { // bold if (style.IsBold) s += IRCCOLOR_BOLD; // italic if (style.IsCursive) s += IRCCOLOR_ITALIC; // underline if (style.IsUnderline) s += IRCCOLOR_UNDERLINE; // init IRC color s += IRCCOLOR_START; // add color with lightgrey background switch (style.Color) { case ChatColor.Black: s += IRCCOLOR_BLACK + "," + IRCCOLOR_GREY; break; case ChatColor.Blue: s += IRCCOLOR_BLUE + "," + IRCCOLOR_GREY;; break; case ChatColor.Green: s += IRCCOLOR_GREEN + "," + IRCCOLOR_GREY;; break; case ChatColor.Purple: case ChatColor.Violet: // no match s += IRCCOLOR_PURPLE + "," + IRCCOLOR_GREY;; break; case ChatColor.Red: case ChatColor.BrightRed: // no IRC match s += IRCCOLOR_RED + "," + IRCCOLOR_GREY;; break; case ChatColor.White: s += IRCCOLOR_WHITE + "," + IRCCOLOR_GREY;; break; case ChatColor.LightGreen: s += IRCCOLOR_LIGHTGREEN + "," + IRCCOLOR_GREY; ; break; case ChatColor.Yellow: s += IRCCOLOR_YELLOW + "," + IRCCOLOR_GREY; ; break; case ChatColor.Pink: case ChatColor.Magenta: // no IRC match s += IRCCOLOR_LIGHTPINK + "," + IRCCOLOR_GREY; ; break; case ChatColor.Orange: s += IRCCOLOR_ORANGE + "," + IRCCOLOR_GREY; ; break; case ChatColor.Cyan: case ChatColor.Aquamarine: // no IRC match s += IRCCOLOR_LIGHTCYAN + "," + IRCCOLOR_GREY; ; break; case ChatColor.Teal: s += IRCCOLOR_TEAL + "," + IRCCOLOR_GREY; ; break; case ChatColor.DarkGrey: // no IRC match s += IRCCOLOR_LIGHTGREY + "," + IRCCOLOR_GREY; ; break; } // now copy textchunk of this style to output s += ChatMessage.FullString.Substring(style.StartIndex, style.Length); // appendix s += IRCCOLOR_TERM; } // IRC does not allow \r \n and \0 // since player messages should not contain them at all (except for shopbot) // we remove them here as a final step (don't do earlier!) // not worth the work to keeping the last chatstyle to the next irc message start s = s.Replace("\r", String.Empty).Replace("\n", String.Empty).Replace(Environment.NewLine, String.Empty).Replace("\0", String.Empty); // return return s; }