コード例 #1
0
 protected virtual void OnChannelJoin(object sender, IRC_EventArgs e)
 {
     if (ChannelJoin != null)
     {
         ChannelJoin(sender, e);
     }
 }
コード例 #2
0
 protected virtual void OnUserModified(object sender, IRC_EventArgs e)
 {
     if (UserModified != null)
     {
         UserModified(sender, e);
     }
 }
コード例 #3
0
 protected virtual void OnMessageReceived(object sender, IRC_EventArgs e)
 {
     if (MessageReceived != null)
     {
         MessageReceived(sender, e);
     }
 }
コード例 #4
0
        private void HandleData(string data)
        {
            string[] exp = data.Split(' ');
            string[] cmd = exp;

            if (exp.Length > 1)
            {
                if (exp[0].StartsWith(":"))
                {
                    cmd = FrameworkString.SelectRange(exp, 1, exp.Length);
                }
            }

            int nCmd = -1;

            try
            {
                nCmd = Convert.ToInt32(cmd[0]);
            }
            catch (Exception) { }

            if (Enum.IsDefined(typeof(IRC_RESPONSE), nCmd))
            {
                switch ((IRC_RESPONSE)nCmd)
                {
                case IRC_RESPONSE.WELCOME:
                {
                    _registered = true;
                    OnRegistered(this, EventArgs.Empty);
                    break;
                }

                case IRC_RESPONSE.ERROR_CHANNEL_BANNED:
                {
                    IRC_EventArgs args = new IRC_EventArgs(cmd[1]);
                    args.Succesful = false;
                    args.Flag      = (int)IRC_CHANNEL_ERROR.BANNED;

                    OnChannelJoin(this, args);
                    break;
                }

                case IRC_RESPONSE.ERROR_CHANNEL_FULL:
                {
                    IRC_EventArgs args = new IRC_EventArgs(cmd[1]);
                    args.Succesful = false;
                    args.Flag      = (int)IRC_CHANNEL_ERROR.FULL;

                    OnChannelJoin(this, args);
                    break;
                }

                case IRC_RESPONSE.ERROR_CHANNEL_PASSWORD_INVALID:
                {
                    IRC_EventArgs args = new IRC_EventArgs(cmd[1]);
                    args.Succesful = false;
                    args.Flag      = (int)IRC_CHANNEL_ERROR.WRONG_PASSWORD;

                    OnChannelJoin(this, args);
                    break;
                }

                case IRC_RESPONSE.ERROR_CHANNEL_INVITE_ONLY:
                {
                    IRC_EventArgs args = new IRC_EventArgs(cmd[1]);
                    args.Succesful = false;
                    args.Flag      = (int)IRC_CHANNEL_ERROR.INVITE_ONLY;

                    OnChannelJoin(this, args);
                    break;
                }

                case IRC_RESPONSE.ERROR_TOO_MANY_CHANNELS:
                {
                    IRC_EventArgs args = new IRC_EventArgs(cmd[1]);
                    args.Succesful = false;
                    args.Flag      = (int)IRC_CHANNEL_ERROR.TOO_MANY;

                    OnChannelJoin(this, args);
                    break;
                }

                case IRC_RESPONSE.NAMES:
                {
                    break;
                }

                case IRC_RESPONSE.NAMES_END:
                {
                    IRC_EventArgs args = new IRC_EventArgs(cmd[2]);
                    args.Succesful = true;

                    OnChannelJoin(this, args);
                    break;
                }

                case IRC_RESPONSE.ERROR_NICK_IN_USE:
                {
                    SetNick(Nick + "_");
                    break;
                }
                }
            }
            else
            {
                switch (cmd[0])
                {
                case "PING":
                {
                    SendLine("PONG :" + data.Replace("PING :", ""));
                    break;
                }

                case "PRIVMSG":
                {
                    IRC_User user = StringToUser(exp[0]);

                    string[] temp = FrameworkString.SelectRange(cmd, 2, cmd.Length);
                    temp[0] = temp[0].Substring(1, temp[0].Length - 1);

                    IRC_EventArgs args = new IRC_EventArgs(cmd[1]);
                    args.User    = user;
                    args.Message = FrameworkString.Concat(temp, " ");

                    OnMessageReceived(this, args);
                    break;
                }

                case "JOIN":
                {
                    IRC_User user = StringToUser(exp[0]);

                    IRC_EventArgs args = new IRC_EventArgs(cmd[1]);
                    args.Flag = (int)IRC_USER_ACTION.JOIN;
                    args.User = user;

                    OnUserModified(this, args);
                    break;
                }

                case "PART":
                {
                    IRC_User user = StringToUser(exp[0]);

                    IRC_EventArgs args = new IRC_EventArgs(cmd[1]);
                    args.Flag = (int)IRC_USER_ACTION.LEAVE;
                    args.User = user;

                    OnUserModified(this, args);
                    break;
                }

                case "MODE":
                {
                    break;
                }

                case "NICK":
                {
                    break;
                }
                }
            }
        }