Exemplo n.º 1
0
        public IrcProxyInstance(TcpClient client, string _password, IAL _baseIal)
        {
            this._client   = client;
            this._password = _password;
            this._baseIal  = _baseIal;

            _clientThread = new Thread(threadMethod);

            _clientThread.Start();
        }
Exemplo n.º 2
0
        private static string buildMessage(string messageFormat, params string[] args)
        {
            string builtString = String.Format(messageFormat, args);

            if (builtString.StartsWith("#ACTION"))
            {
                builtString = IAL.wrapCTCP("ACTION", builtString.Substring(8));
            }
            return(builtString);
        }
Exemplo n.º 3
0
        public IrcProxy(IAL baseIrcAccessLayer, int port, string password)
        {
            if (Configuration.singleton()["enableProxy"] != "true")
            {
                return;
            }

            _listener = new TcpListener(new IPEndPoint(IPAddress.Any, port));

            _baseIal       = baseIrcAccessLayer;
            this._password = password;

            this.registerInstance();

            _t = new Thread(listenerThread);
            _t.Start();
        }
Exemplo n.º 4
0
        private static void initialiseBot(string configFile)
        {
            string username;
            string password;
            string schema;
            uint   port   = 0;
            string server = username = password = schema = "";

            Configuration.readHmbotConfigFile(configFile, ref server, ref username, ref password, ref port, ref schema);

            _dbal = DAL.singleton(server, port, username, password, schema);

            if (!_dbal.connect())
            {
                // can't connect to database, DIE
                return;
            }

            Configuration.singleton();

            debugChannel = Configuration.singleton()["channelDebug"];

            _ircNetwork = uint.Parse(Configuration.singleton()["ircNetwork"]);

            _trigger = Configuration.singleton()["commandTrigger"];

            irc = new IAL(_ircNetwork);

            new IrcProxy(irc, int.Parse(Configuration.singleton()["proxyPort"]), Configuration.singleton()["proxyPassword"]);

            setupEvents();

            if (!irc.connect())
            {
                // if can't connect to irc, die
                return;
            }

            new MonitorService(62167, "Helpmebot v6 (Nagios Monitor service)");

            // ACC notification monitor
            AccNotifications.getInstance();
        }
Exemplo n.º 5
0
        private void threadMethod()
        {
            try
            {
                _sr = new StreamReader(_client.GetStream());
                _sw = new StreamWriter(_client.GetStream());

                bool rcvdNick, rcvdUser, rcvdPass;
                rcvdPass = rcvdNick = rcvdUser = false;

                _sw.WriteLine(":helpmebot.srv.stwalkerster.net NOTICE * :*** Looking up your hostname...");
                _sw.WriteLine(":helpmebot.srv.stwalkerster.net NOTICE * :*** Checking Ident");
                _sw.WriteLine(":helpmebot.srv.stwalkerster.net NOTICE * :*** Found your hostname");
                _sw.WriteLine(":helpmebot.srv.stwalkerster.net NOTICE * :*** No Ident response");



                while (!(rcvdNick && rcvdUser && rcvdPass))
                {
                    string[] l = _sr.ReadLine().Split(' ');
                    if (l[0] == "NICK")
                    {
                        rcvdNick = true;
                    }
                    if (l[0] == "USER")
                    {
                        rcvdUser = true;
                    }
                    if (l[0] == "PASS")
                    {
                        if (l[1] == _password)
                        {
                            rcvdPass = true;
                        }
                    }
                }

                _sw.WriteLine(":irc.helpmebot.org.uk 001 " + _baseIal.ircNickname + " :Welcome to the Helpmebot IRC Gateway.");
                _sw.WriteLine(":irc.helpmebot.org.uk 002 " + _baseIal.ircNickname + " :Your Host is helpmebot.srv.stwalkerster.net, running version Helpmebot/6.0");
                _sw.WriteLine(":irc.helpmebot.org.uk 003 " + _baseIal.ircNickname + " :This server was created " + DateTime.Now.ToString());
                _sw.WriteLine(":irc.helpmebot.org.uk 004 " + _baseIal.ircNickname + " " + _baseIal.ServerInfo);
                _sw.Flush();

                foreach (var c in _baseIal.activeChannels)
                {
                    _sw.WriteLine(":" + _baseIal.myIdentity + " JOIN " + c);
                    _sw.Flush();
                    _baseIal.ircNames(c);
                    _baseIal.ircTopic(c);
                }



                _sw.Flush();
                _baseIal.dataRecievedEvent += baseIalDataRecievedEvent;

                while (_client.Connected)
                {
                    string line       = _sr.ReadLine();
                    string source     = null;
                    string command    = null;
                    string parameters = null;
                    IAL.basicParser(line, ref source, ref command, ref parameters);

                    if (command == "QUIT")
                    {
                        _sr.Close();
                        _baseIal.dataRecievedEvent -= baseIalDataRecievedEvent;
                        break;
                    }

                    _baseIal.sendRawLine(line);
                }
            }
            catch (ThreadAbortException ex)
            {
            }
            finally
            {
                _client.Close();
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Handles the command.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="destination">The destination.</param>
        /// <param name="command">The command.</param>
        /// <param name="args">The args.</param>
        public void handleCommand(User source, string destination, string command, string[] args)
        {
            Logger.instance().addToLog("Handling recieved message...", Logger.LogTypes.General);

            // if on ignore list, ignore!
            if (source.accessLevel == User.UserRights.Ignored)
            {
                return;
            }

            // flip destination over if required
            if (destination == Helpmebot6.irc.ircNickname)
            {
                destination = source.nickname;
            }


            /*
             * check category codes
             */
            if (WatcherController.instance().isValidKeyword(command))
            {
                int argsLength = GlobalFunctions.realArrayLength(args);

                string[] newArgs     = new string[argsLength + 1];
                int      newArrayPos = 1;
                for (int i = 0; i < args.Length; i++)
                {
                    if (!String.IsNullOrEmpty(args[i]))
                    {
                        newArgs[newArrayPos] = args[i];
                    }
                    newArrayPos++;
                }
                newArgs[0] = command;
                string directedTo          = findRedirection(destination, ref newArgs);
                CommandResponseHandler crh = new CategoryWatcher().run(source, destination, newArgs);
                this.handleCommandResponseHandler(source, destination, directedTo, crh);
                return;
            }

            /*
             * Check for a valid command
             * search for a class that can handle this command.
             */

            // Create a new object which holds the type of the command handler, if it exists.
            // if the command handler doesn't exist, then this won't be set to a value
            Type commandHandler =
                Type.GetType("helpmebot6.Commands." + command.Substring(0, 1).ToUpper() + command.Substring(1).ToLower());

            // check the type exists
            if (commandHandler != null)
            {
                string directedTo = findRedirection(destination, ref args);

                // create a new instance of the commandhandler.
                // cast to genericcommand (which holds all the required methods to run the command)
                // run the command.
                CommandResponseHandler response = ((GenericCommand)Activator.CreateInstance(commandHandler)).run(
                    source, destination, args);
                this.handleCommandResponseHandler(source, destination, directedTo, response);
                return;
            }

            /*
             * Check for a learned word
             */
            {
                WordLearner.RemeberedWord rW  = WordLearner.remember(command);
                CommandResponseHandler    crh = new CommandResponseHandler();
                string wordResponse           = rW.phrase;
                string directedTo             = "";
                if (wordResponse != String.Empty)
                {
                    if (source.accessLevel < User.UserRights.Normal)
                    {
                        crh.respond(new Message().get("accessDenied"),
                                    CommandResponseDestination.PrivateMessage);
                        string[] aDArgs = { source.ToString(), MethodBase.GetCurrentMethod().Name };
                        crh.respond(new Message().get("accessDeniedDebug", aDArgs),
                                    CommandResponseDestination.ChannelDebug);
                    }
                    else
                    {
                        wordResponse = String.Format(wordResponse, args);
                        if (rW.action)
                        {
                            crh.respond(IAL.wrapCTCP("ACTION", wordResponse));
                        }
                        else
                        {
                            directedTo = findRedirection(destination, ref args);
                            crh.respond(wordResponse);
                        }
                        this.handleCommandResponseHandler(source, destination, directedTo, crh);
                    }
                    return;
                }
            }
        }