Esempio n. 1
0
        private void serverCommandPRIVMSG(IRCCommand cmd)
        {
            string handle = cmd.parameters[0].StartsWith("#") ? cmd.parameters[0] : cmd.shortPrefix;

            if (cmd is CTCPCommand)
            {
                CTCPCommand c = (CTCPCommand)cmd;
                if (c.ctcpCommand == "ACTION")
                {
                    chatWindow.addToChannel(handle, "*", cmd.shortPrefix + " " + c.ctcpParameters);
                }
                else if ((c.ctcpCommand == "VERSION") && !handle.StartsWith("#"))
                {
                    if (c.ctcpParameters == null)
                    {
                        chatWindow.addToChannel(handle, "*", "VERSION");

                        client.send(new CTCPCommand(null, handle, "VERSION", "Internet Relay Chat Plugin " + version + " for Kerbal Space Program"));
                    }
                    else
                    {
                        chatWindow.addToChannel(handle, "*", handle + " uses client: " + c.ctcpParameters);
                    }
                }
            }
            else
            {
                chatWindow.addToChannel(handle, cmd.shortPrefix, cmd.parameters.Last());
            }
        }
Esempio n. 2
0
 private void logSendCommand(IRCCommand cmd)
 {
     if (config.debug)
     {
         chatWindow.addToChannel(DEBUG_CHANNEL_HANDLE, "CLIENT", cmd.ToString());
     }
 }
Esempio n. 3
0
 private void serverCommandEndOfMotd(IRCCommand cmd)
 {
     if (config.twitch)
     {
         client.send(new IRCCommand(null, "CAP", "REQ", "twitch.tv/membership"));
     }
 }
Esempio n. 4
0
 private void speak(string handler, string sender, string text, IRCCommand cmd = null)
 {
     if (handler != "(Debug)")
     {
         SpeechLibWrapper.Speak(sender + " : " + text);
     }
 }
Esempio n. 5
0
        private void serverCommandTOPIC(IRCCommand cmd)
        {
            string topic = null;

            if (cmd.parameters.Length > 1)
            {
                topic = cmd.parameters.Last();
            }
            chatWindow.setChannelTopic(cmd.parameters[0], topic);
            chatWindow.addToChannel(cmd.parameters[0], "*", cmd.shortPrefix + " sets channel topic to: " + (topic ?? ""));
        }
Esempio n. 6
0
        private void serverCommandKICK(IRCCommand cmd)
        {
            string text = cmd.shortPrefix + " kicked " + cmd.parameters[1] + " from " + cmd.parameters[0];

            if (cmd.parameters.Length > 2)
            {
                text += " (" + cmd.parameters[2] + ")";
            }
            chatWindow.addToChannel(cmd.parameters[0], "*", text);
            chatWindow.removeChannelName(cmd.parameters[0], cmd.parameters[1]);
        }
Esempio n. 7
0
 private void serverCommandPART(IRCCommand cmd)
 {
     if (cmd.shortPrefix != config.nick)
     {
         string text = cmd.shortPrefix + " has left " + cmd.parameters[0];
         if (cmd.parameters.Length > 1)
         {
             text += " (" + cmd.parameters[1] + ")";
         }
         chatWindow.addToChannel(cmd.parameters[0], "*", text, cmd);
         chatWindow.removeChannelName(cmd.parameters[0], cmd.shortPrefix);
     }
 }
Esempio n. 8
0
        private void serverCommandNICK(IRCCommand cmd)
        {
            string oldName = cmd.shortPrefix;
            string newName = cmd.parameters.Last();

            string[] channelsContainingName = chatWindow.getChannelsContainingName(oldName);
            for (int ix = 0; ix < channelsContainingName.Length; ix++)
            {
                string handle = channelsContainingName[ix];
                chatWindow.renameInChannel(handle, oldName, newName);
                chatWindow.addToChannel(handle, "*", oldName + " is now known as " + newName);
            }
        }
Esempio n. 9
0
        private void handleServerCommand(IRCCommand cmd)
        {
            bool unknown = !serverCommandHandlers.ContainsKey(cmd.command);

            if (config.debug)
            {
                chatWindow.addToChannel(DEBUG_CHANNEL_HANDLE, "SERVER", (unknown ? "(unknown) " : "") + cmd);
            }

            if (!unknown)
            {
                serverCommandHandlers[cmd.command](cmd);
            }
        }
Esempio n. 10
0
 private void serverCommandMODE(IRCCommand cmd)
 {
     // channel mode
     if (cmd.parameters[0].StartsWith("#"))
     {
         string channel = cmd.parameters[0];
         string mode    = cmd.parameters[1];
         if ((mode == "+o") || (mode == "-o") || (mode == "+v") || (mode == "-v"))
         {
             string name = cmd.parameters[2];
             chatWindow.changeUserModeInChannel(channel, name, mode);
             chatWindow.addToChannel(channel, "*", cmd.shortPrefix + " sets mode " + mode + " on " + name);
         }
     }
 }
Esempio n. 11
0
        public void addToBuffer(string sender, string text, IRCCommand cmd = null)
        {
            User user = usersForTabCompletion.SingleOrDefault(u => u.name == sender);

            if (user != null)
            {
                usersForTabCompletion.Remove(user);
                usersForTabCompletion.Insert(0, user);
            }

            if (lastSeenLineNeedsReset)
            {
                unseenIdx = backBuffer.Count();
                lastSeenLineNeedsReset = false;
            }

            ChannelMessageRenderer entry = messageRendererFactory.get(this, sender, text);

            backBuffer.Add(entry);
            if (backBuffer.Count() > MAX_BACK_BUFFER_LINES)
            {
                backBuffer.RemoveRange(0, backBuffer.Count() - MAX_BACK_BUFFER_LINES);
                if (unseenIdx > -1)
                {
                    unseenIdx--;
                }
            }

            Boolean nickInText = (this.highlightName && text.Contains(config.nick.ToLower()));

            if ((!handle.StartsWith("#") && !handle.StartsWith("(") && !handle.EndsWith(")")) || nickInText)
            {
                channelHighlightedPrivateMessage = true;
            }
            if ((cmd != null) &&
                ((cmd.command == "JOIN") || (cmd.command == "PART") || (cmd.command == "QUIT")))
            {
                channelHighlightedJoin = true;
            }
            else
            {
                channelHighlightedMessage = true;
            }

            backBufferScrollPosition = new Vector2(0, float.MaxValue);
        }
Esempio n. 12
0
        private void serverCommandQUIT(IRCCommand cmd)
        {
            string text = cmd.shortPrefix + " has quit";

            if (cmd.parameters.Length > 0)
            {
                text += " (" + cmd.parameters[0] + ")";
            }

            string[] channelsContainingName = chatWindow.getChannelsContainingName(cmd.shortPrefix);
            for (int ix = 0; ix < channelsContainingName.Length; ix++)
            {
                string handle = channelsContainingName[ix];

                chatWindow.addToChannel(handle, "*", text, cmd);
                chatWindow.removeChannelName(handle, cmd.shortPrefix);
            }
        }
Esempio n. 13
0
 public void send(IRCCommand cmd)
 {
     if (onCommandSent != null)
     {
         onCommandSent(new IRCCommandEvent(cmd));
     }
     byte[] data = Encoding.UTF8.GetBytes(cmd.ToString() + "\r\n");
     try
     {
         stream.Write(data, 0, data.Length);
     }
     catch (SocketException ex)
     {
         handleException(ex, true);
     }
     catch (IOException ex)
     {
         handleException(ex, true);
     }
 }
Esempio n. 14
0
 public void send(string cmdAndParams)
 {
     if (onCommandSent != null)
     {
         onCommandSent(new IRCCommandEvent(IRCCommand.fromLine(cmdAndParams)));
     }
     byte[] data = Encoding.UTF8.GetBytes(cmdAndParams + "\r\n");
     try
     {
         stream.Write(data, 0, data.Length);
     }
     catch (SocketException ex)
     {
         handleException(ex, true);
     }
     catch (IOException ex)
     {
         handleException(ex, true);
     }
 }
Esempio n. 15
0
        public void addToChannel(string handle, string sender, string text, IRCCommand cmd = null)
        {
            TextInputState textInputState = GetInputState();
            ChannelGUI     channelGUI     = getChannelGUI(handle);

            channelGUI.addToBuffer(sender, text, cmd);

            // show this channel if no channel is visible yet
            if (currentChannelGUI == null)
            {
                currentChannelGUI        = channelGUI;
                currentChannelGUI.hidden = false;
            }

            RestoreInputFocus(textInputState);

            if (config.tts)
            {
                speak(handle, sender, text, cmd);
            }
        }
Esempio n. 16
0
 private void serverCommandEndOfNames(IRCCommand cmd)
 {
     chatWindow.endOfChannelNames(cmd.parameters[cmd.parameters.Length - 2]);
 }
Esempio n. 17
0
 public IRCCommandEvent(IRCCommand command)
 {
     this.command = command;
 }
Esempio n. 18
0
 private void serverCommandPING(IRCCommand cmd)
 {
     client.send(new IRCCommand(null, "PONG", cmd.parameters[0]));
 }
Esempio n. 19
0
 private void serverCommandNOTICE(IRCCommand cmd)
 {
     chatWindow.addToChannel(NOTICE_CHANNEL_HANDLE, cmd.shortPrefix ?? "SERVER", cmd.parameters.Last());
 }
Esempio n. 20
0
 private void serverCommandNameReply(IRCCommand cmd)
 {
     string[] names = cmd.parameters.Last().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
     chatWindow.addChannelNames(cmd.parameters[cmd.parameters.Length - 2], names);
 }
Esempio n. 21
0
 private void serverCommandJOIN(IRCCommand cmd)
 {
     chatWindow.addToChannel(cmd.parameters[0], "*", cmd.shortPrefix + " has joined " + cmd.parameters[0], cmd);
     chatWindow.addSingleChannelName(cmd.parameters[0], cmd.shortPrefix);
 }
Esempio n. 22
0
 private void serverCommandTopic(IRCCommand cmd)
 {
     chatWindow.setChannelTopic(cmd.parameters[cmd.parameters.Length - 2], cmd.parameters.Last());
     chatWindow.addToChannel(cmd.parameters[cmd.parameters.Length - 2], "*", "Channel topic is: " + cmd.parameters.Last());
 }
Esempio n. 23
0
        public void update()
        {
            if (connected)
            {
                try
                {
                    if (stream.CanRead)
                    {
                        //while (stream.DataAvailable)
                        while (client.Available > 0)
                        {
                            int numBytes = stream.Read(buffer, 0, buffer.Length);
                            if (numBytes > 0)
                            {
                                string text = Encoding.UTF8.GetString(buffer, 0, numBytes);
                                textBuffer.Append(text);
                            }
                        }
                    }
                }
                catch (SocketException ex)
                {
                    handleException(ex, true);
                }

                if (textBuffer.Length > 0)
                {
                    for (; ;)
                    {
                        int pos = textBuffer.ToString().IndexOf("\r\n");
                        if (pos >= 0)
                        {
                            string line = textBuffer.ToString().Substring(0, pos);
                            textBuffer.Remove(0, pos + 2);

                            if (onCommandReceived != null)
                            {
                                try
                                {
                                    IRCCommand cmd = IRCCommand.fromLine(line);
                                    onCommandReceived(new IRCCommandEvent(cmd));
                                }
                                catch (ArgumentException e)
                                {
                                    Debug.LogException(e);
                                }
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                }

                // send something to socket to potentially trigger SocketException elsewhere when reading
                // off the socket
                long now = DateTime.UtcNow.Ticks / 10000L;
                if ((now - lastServerPing) >= SERVER_PING_INTERVAL)
                {
                    lastServerPing = now;
                    send("PING :" + now);
                }

                // only send auto joins if we've been connected for AUTO_JOIN_DELAY millis to allow time for post-connection stuff (user, nick)
                // and if AUTO_JOIN_TIME_BETWEEN_ATTEMPTS has elapsed since the last auto join happened, to avoid other join spam
                if (!autoJoinsSent &&
                    ((now - lastAutoJoinsSentTime) >= AUTO_JOIN_TIME_BETWEEN_ATTEMPTS) &&
                    ((now - connectTime) >= AUTO_JOIN_DELAY))
                {
                    autoJoinChannels();
                }
            }
        }