Exemplo n.º 1
0
        /*
        * m_user:
        *  ar[0] = prefix
        *  ar[1] = command
        *  ar[2] = username
        *  ar[3] = user modes
        *  ar[4] = unused
        *  ar[5] = real name
        */
        public virtual void m_user(IRCConnection src, string[] ar)
        {
            if (this.IsUser(src))
            {
                if (((IRCUserConnection)src).IsRegistered())
                {
                    src.SendCommand(ReplyCodes.ERR_ALREADYREGISTRED, ":Unauthorized command (already registered)");
                    return;
                }
            }

            if (!(src.SimpleClient is SimpleUser))
            {
                src.SendCommand("ERROR", ":Internal error");
                this.CloseLink(src);
                return;
            }

            if (!RFC2812.IsValidUserName(ar[2]))
            {
                return; // ignore message
            }
            if (ar.Length > 5)
            {
                src.SetUser(ar[2], ar[3], ar[4], ar[5]);
                Logger.LogMsg("Got valid USER command from " + src);
                if (((SimpleUser)src.SimpleClient).NickName != string.Empty)
                    this.RegisterUser(src);
            }
            else
            {
                // <command> :Not enough parameters
                src.SendCommand(ReplyCodes.ERR_NEEDMOREPARAMS, ar[1], ":Not enough parameters");
            }
        }
Exemplo n.º 2
0
        /*
        * m_restart:
        */
        private void m_restart(IRCConnection src, string[] ar)
        {
            if (!this.IsUser(src) || !((IRCUserConnection)src).UserMode.HasMode(IRCUserModes.MODE_OP))
            {
                // :Permission Denied- You're not an IRC operator
                src.SendCommand(ReplyCodes.ERR_NOPRIVILEGES,
                        ((IRCUserConnection)src).NickName,
                        ":Permission Denied- You're not an IRC operator");
                return;
            }

            // Close all links
            foreach (IRCConnection con in this.Clients)
            {
                if (this.IsServer(con))
                {
                    con.SendCommand(((IRCUserConnection)src).SimpleUser, "ERROR", ":Restarted by " + src);
                    this.CloseLink(con);
                }
                else if (this.IsUser(con))
                {
                    ((IRCUserConnection)con).Notice("Server Restarting. " + src);
                    this.CloseLink(con, "Server Restarting");
                }
                else
                {
                    this.CloseLink(con, "Server Restarting");
                }
            }

            Logger.LogMsg("RESTART by " + src);
            MainClass.Restart();
        }
Exemplo n.º 3
0
        /*
        * m_rehash:
        */
        public virtual void m_rehash(IRCConnection src, string[] ar)
        {
            if (!this.IsUser(src) || !((IRCUserConnection)src).UserMode.HasMode(IRCUserModes.MODE_OP))
            {
                src.SendCommand(ReplyCodes.ERR_NOPRIVILEGES,
                        ((IRCUserConnection)src).NickName,
                        ":Permission Denied- You're not an IRC operator");
                return;
            }

            Logger.LogMsg("REHASH command from " + src);
            SettingsHost settingsHost = ((SettingsHost)ServiceManager.Services[typeof(SettingsHost)]);
            // <config file> :Rehashing
            src.SendCommand(ReplyCodes.ERR_NOPRIVILEGES, ((IRCUserConnection)src).NickName,
                    settingsHost.ConfigFile, ":Rehashing");
            // Rehash
            settingsHost.Reload();
        }
Exemplo n.º 4
0
        // TODO: SendCommand anpassen
        /*
           ERR_NEEDMOREPARAMS              ERR_NOSUCHCHANNEL
           ERR_NOTONCHANNEL
        */
        private void m_part(IRCConnection src, string[] ar)
        {
            SimpleUser usr = null; // TODO

            if (this.IsServer(src))
            {
                throw new NotImplementedException("remote /part");
                //usr = this.Search(ar[0]); // TODO
                if (usr == null)
                {
                    return;
                }
            }
            else if (!this.IsUser(src))
            {
                // ERR
                src.SendLine("ERROR");
                return;
            }
            else
            {
                usr = (SimpleUser)src.SimpleClient;
            }

            #if false
            if (ar.Length > 4) // zuviel parameter
            {
                src.SendLine("to much parameters");
                return;
            }
            #endif
            if (ar.Length < 3)
            {
                // <command> :Not enough parameters
                src.SendCommand(ReplyCodes.ERR_NEEDMOREPARAMS, usr.NickName, ar[1], ":Not enough parameters");
                return;
            }

            Channel chan;
            string msg = string.Empty;
            if (ar.Length > 3)
                msg = ar[3];
            else
                msg = usr.NickName;

            string[] chans = ar[2].Split(new char[',']);
            foreach (string schan in chans)
            {
                chan = this.GetChannel(schan);
                if (chan == null)
                {
                    // <channel name> :No such channel
                    src.SendCommand(ReplyCodes.ERR_NOSUCHCHANNEL, usr.NickName, chan.Name, ":No such channel");
                    continue;
                }
                else if (!chan.HasUser(usr))
                {
                    // <channel> :You're not on that channel
                    src.SendCommand(ReplyCodes.ERR_NOTONCHANNEL, usr.NickName, chan.Name, ":You're not on that channel");
                    continue;
                }
                this.Part(usr, chan, msg);
            }
        }