Esempio n. 1
0
        private void DoChatMessageReceived(string receiver, string sender, string message)
        {
            Channel channel = channels.Find(c => c.ChannelName == receiver);

            if (channel == null)
            {
                return;
            }

            Color foreColor;

            // Handle ACTION
            if (message.Contains("ACTION"))
            {
                message = message.Remove(0, 7);
                message = "====> " + sender + " " + message;
                sender  = String.Empty;

                // Replace Funky's game identifiers with real game names
                for (int i = 0; i < gameCollection.GameList.Count; i++)
                {
                    message = message.Replace("new " + gameCollection.GetGameIdentifierFromIndex(i) + " game",
                                              "new " + gameCollection.GetFullGameNameFromIndex(i) + " game");
                }

                foreColor = Color.White;
            }
            else
            {
                // Color parsing
                if (message.Contains(Convert.ToString((char)03)))
                {
                    if (message.Length < 3)
                    {
                        foreColor = cDefaultChatColor;
                    }
                    else
                    {
                        string colorString = message.Substring(1, 2);
                        message = message.Remove(0, 3);
                        int colorIndex = Conversions.IntFromString(colorString, -1);
                        // Try to parse message color info; if fails, use default color
                        if (colorIndex < ircChatColors.Length && colorIndex > -1)
                        {
                            foreColor = ircChatColors[colorIndex].XnaColor;
                        }
                        else
                        {
                            foreColor = cDefaultChatColor;
                        }
                    }
                }
                else
                {
                    foreColor = cDefaultChatColor;
                }
            }

            if (message.Length > 1 && message[message.Length - 1] == '\u001f')
            {
                message = message.Remove(message.Length - 1);
            }

            channel.AddMessage(new ChatMessage(sender, foreColor, DateTime.Now, message.Replace('\r', ' ')));
        }