Beispiel #1
0
 private void InternaReceiveCompleted(IRCSharp.Kernel.Model.Query.IRCCommandQuery data)
 {
     if (data != null)
     {
         OnReceiveCompleted(data);
     }
 }
        public override IRCSharp.Kernel.Model.Query.IRCCommandQuery Execute(IRCSharp.Kernel.Model.Query.UserdefinedCommandQuery query)
        {
            //You could use the authenticationProvider to either protect certain users from reading or writing. The default implementation is an XML based user and command list
            //where you can configure user and command authentication and permissions:
            IRCSharp.Kernel.Security.User userWrite;
            base.authenticationProvider.MayUserWriteToCommand(query.From, "hello", out userWrite);
            {

            }

            IRCSharp.Kernel.Security.User userRead;
            base.authenticationProvider.MayUserReadFromCommand(query.From, "hello", out userRead);
            {

            }

            //Execute rights is handled by the system if using the IRCSharp.Kernel.SecureManager.

            //This is how you get the parameters from the query
            Console.WriteLine("hello from command: " + query.CommandName);
            foreach (string param in query.Parameters)
            {
                Console.WriteLine("param in command: " + param);
            }
            return null;
        }
Beispiel #3
0
 public void OnReceiveCompleted(IRCSharp.Kernel.Model.Query.IRCCommandQuery query)
 {
     if (ReceiveCompleted != null)
     {
         ReceiveCompleted(query);
     }
 }
Beispiel #4
0
        public bool AddQuery(IRCSharp.Kernel.Model.Query.IRCCommandQuery query)
        {
            Int64 userId;
            Int64 channelId;
            bool addedQuery = false;

            if (TryGetUserId(query, out userId))
            {
                if (TryGetChannelId(query, out channelId, userId))
                {
                    addedQuery = TryAddQueryToChannel(query, channelId, userId) || addedQuery;
                }
                else
                {
                    addedQuery = TryCreateChannelToUser(query, userId, out channelId) || addedQuery;
                    addedQuery = TryAddQueryToChannel(query, channelId, userId) || addedQuery;
                }
            }
            else
            {
                addedQuery = TryCreateUser(query, out userId) || addedQuery;
                addedQuery = TryCreateChannelToUser(query, userId, out channelId) || addedQuery;
                addedQuery = TryAddQueryToChannel(query, channelId, userId) || addedQuery;
            }

            return addedQuery;
        }
Beispiel #5
0
        public List<Model.Query.IRCCommandQuery> FireUserdefinedCommand(IRCSharp.Kernel.Model.Query.IRCCommandQuery query)
        {
            List<Model.Query.IRCCommandQuery> results = null;
            Model.Query.UserdefinedCommandQuery userdefinedCommandQuery;
            if (Parser.UserdefinedCommand.UserdefinedCommandParser.TryParse(query, out userdefinedCommandQuery))
            {
                List<CommandInformation<string>> userdefinedInformationCommands = this.GetUserdefinedCommand(userdefinedCommandQuery.CommandName);

                if (userdefinedInformationCommands != null)
                {
                    results = new List<Model.Query.IRCCommandQuery>();
                    foreach (var userdefinedCommandInformation in userdefinedInformationCommands)
                    {
                        ICommand<string, Model.Query.UserdefinedCommandQuery> command = Reflection.ReflectionUtil.LoadTypeOf<ICommand<string, Model.Query.UserdefinedCommandQuery>>(userdefinedCommandInformation.CommandType);
                        Model.Query.IRCCommandQuery output = command.Execute(userdefinedCommandQuery);

                        if (output != null)
                        {
                            results.Add(output);
                        }
                    }
                }
            }

            return results;
        }
Beispiel #6
0
 public IncomingThread(IRCSharp.Kernel.Model.Query.IRCCommandQuery query, Manager.CommandManager commandManager, Model.Query.Writer.IRCWriter<System.IO.Stream> ircWriter)
     : base("incoming_thread")
 {
     _commandManager = commandManager;
     _ircWriter = ircWriter;
     _query = query;
 }
Beispiel #7
0
        public List<Model.Query.IRCCommandQuery> FireIRCCommand(IRCSharp.Kernel.Model.Query.IRCCommandQuery query)
        {
            List<CommandInformation<Model.Query.IRCCommand>> ircCommandInformation = this.GetIRCCommand(query.Command);
            List<Model.Query.IRCCommandQuery> results = null;

            if (ircCommandInformation != null)
            {
                results = new List<Model.Query.IRCCommandQuery>();
                foreach (var commandInformation in ircCommandInformation)
                {
                    ICommand<Model.Query.IRCCommand, Model.Query.IRCCommandQuery> command = Reflection.ReflectionUtil.LoadTypeOf<ICommand<Model.Query.IRCCommand, Model.Query.IRCCommandQuery>>(commandInformation.CommandType);
                    if (command != null)
                    {
                        var queryResult = command.Execute(query);

                        if (queryResult != null)
                        {
                            results.Add(queryResult);
                        }
                    }
                }
            }

            return results;
        }
Beispiel #8
0
        public override Model.Query.IRCCommandQuery Execute(IRCSharp.Kernel.Model.Query.IRCCommandQuery query)
        {
            string[] commands = query.Parameter.Split(':');
            Model.Query.IRCCommandQuery pongQuery = null;

            Parser.IRC.IRCQueryParser.TryParse(query.Network, "PONG " + commands[1], out pongQuery);

            return pongQuery;
        }
Beispiel #9
0
        public List<IRCSharp.Kernel.Model.Query.IRCCommandQuery> FireUserdefinedCommand(IRCSharp.Kernel.Model.Query.IRCCommandQuery query)
        {
            List<IRCSharp.Kernel.Model.Query.IRCCommandQuery> commands = null;
            IRCSharp.Kernel.Model.Query.UserdefinedCommandQuery userdefinedCommandQuery;
            if (IRCSharp.Kernel.Parser.UserdefinedCommand.UserdefinedCommandParser.TryParse(query, out userdefinedCommandQuery))
            {
                IRCSharp.Kernel.Security.User user;
                if (_authenticationProvider.MayUserExecuteCommand(query.From, userdefinedCommandQuery.CommandName, out user))
                {
                    commands = _commandManager.FireUserdefinedCommand(query); //TODO make a FireUserdefinedCommand(Model.Query.UserdefinedCommandQuery query) in CommandManager. We do not need to parse userdefined query twice.
                }
            }

            return commands;
        }
        public static bool TryParse(IRCSharp.Kernel.Model.Query.IRCCommandQuery ircQuery, out IRCSharp.Kernel.Model.Query.UserdefinedCommandQuery userdefinedCommandQuery)
        {
            UserdefinedCommandParser parser = new UserdefinedCommandParser();
            bool parsed = false;
            Model.Query.UserdefinedCommandQuery query = null;
            if (ircQuery.Command == Model.Query.IRCCommand.PRIVMSG && IsUserdefinedCommand(ircQuery.Parameter))
            {
                string commandName = parser.ParseCommandName(ircQuery.Parameter);
                IList<string> commandNameParameters = parser.ParseCommandParameters(ircQuery.Parameter);
                query = new Model.Query.UserdefinedCommandQuery(commandName, ircQuery);
                query.AddParameters(commandNameParameters);
                parsed = true;
            }

            userdefinedCommandQuery = query;
            return parsed;
        }
Beispiel #11
0
        private bool TryAddQueryToChannel(IRCSharp.Kernel.Model.Query.IRCCommandQuery query, Int64 channelId, Int64 userId)
        {
            bool created = true;
            System.Data.SQLite.SQLiteCommand command = _connection.CreateCommand();
            command.CommandText = "insert into Query (rawQuery, channelId, userId) values(@rawQuery, @channelId, @userId); SELECT last_insert_rowid();";
            command.Parameters.AddWithValue("@rawQuery", query.RawLine);
            command.Parameters.AddWithValue("@channelId", channelId);
            command.Parameters.AddWithValue("@userId", userId);

            try
            {
                channelId = (Int64)command.ExecuteScalar();
            }
            catch (Exception) //TODO propper exception handling needed here
            {
                created = false;
            }

            return created;
        }
Beispiel #12
0
 public void AddQuery(IRCSharp.Kernel.Model.Query.IRCCommandQuery query)
 {
     _databaseDal.AddQuery(query);
 }
Beispiel #13
0
 public List<IRCSharp.Kernel.Model.Query.IRCCommandQuery> FireIRCCommand(IRCSharp.Kernel.Model.Query.IRCCommandQuery query)
 {
     return _commandManager.FireIRCCommand(query);
 }
Beispiel #14
0
 public IrcMessage(IrcClientWrapper clientWrapper, IRCSharp.IRC.IrcMessage message)
     : base(new IrcUser(clientWrapper, message.Sender), message.Channel, message.Message, message.Action)
 {
     Client = clientWrapper;
 }
Beispiel #15
0
 public IrcUser(IrcClientWrapper client, IRCSharp.IRC.IrcUser user)
     : base(user.Nick, user.Ident, user.Hostmask)
 {
     Client = client;
 }
Beispiel #16
0
 public IRCCommandAttribute(IRCSharp.Kernel.Model.Query.IRCCommand name)
 {
     Name = name;
 }
Beispiel #17
0
 public List<IRCSharp.Kernel.CommandInformation<IRCSharp.Kernel.Model.Query.IRCCommand>> GetIRCCommand(IRCSharp.Kernel.Model.Query.IRCCommand type)
 {
     return _commandManager.GetIRCCommand(type);
 }
Beispiel #18
0
 public void InsertUserdefinedCommand(IRCSharp.Kernel.CommandInformation<string> command)
 {
     _commandManager.InsertUserdefinedCommand(command);
 }
Beispiel #19
0
 public void InsertIRCCommand(Type commandType, IRCSharp.Kernel.Model.Query.IRCCommand name, string absoluteFilePath)
 {
     _commandManager.InsertIRCCommand(commandType, name, absoluteFilePath);
 }
Beispiel #20
0
 public void InsertIRCCommand(IRCSharp.Kernel.CommandInformation<IRCSharp.Kernel.Model.Query.IRCCommand> command)
 {
     _commandManager.InsertIRCCommand(command);
 }
Beispiel #21
0
 public void WriteToBot(IRCSharp.Kernel.Model.Query.IRCCommandQuery query)
 {
     MSMQ.MSMQWriter<IRCSharp.Kernel.Model.Query.IRCCommandQuery> writer = new MSMQ.MSMQWriter<IRCSharp.Kernel.Model.Query.IRCCommandQuery>(Configuration.MessageServerConfiguration.BotServerOutgoingPath);
     writer.SendMessage(query);
     writer.Close();
 }
Beispiel #22
0
        private bool TryGetUserId(IRCSharp.Kernel.Model.Query.IRCCommandQuery query, out Int64 userId)
        {
            bool foundUser = false;
            userId = -1;

            System.Data.SQLite.SQLiteCommand command = _connection.CreateCommand();

            command.CommandText = "select id from User where nick = @nick and network = @network";
            command.Parameters.AddWithValue("@nick", query.Nick);
            command.Parameters.AddWithValue("@network", query.Network);
            command.Prepare();
            System.Data.SQLite.SQLiteDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                if (userId != -1 && foundUser) //means that there is more than one user with that nick. That is NOT possible on the same network!!
                {
                    /*
                     * TODO: Create log entry, and get the first possible channelId
                     * Now, this is infact wrong to log statistics for two different users, on one entry, so the statistics is infact invalid.
                     */
                    break;
                }

                userId = reader.GetInt32(reader.GetOrdinal("id"));
                foundUser = true;
            }
            reader.Close();

            return foundUser;
        }
Beispiel #23
0
        private bool TryCreateUser(IRCSharp.Kernel.Model.Query.IRCCommandQuery query, out Int64 userId)
        {
            bool created = true;
            System.Data.SQLite.SQLiteCommand command = _connection.CreateCommand();
            command.CommandText = "insert into User (nick,network) values(@nick, @network); SELECT last_insert_rowid();";
            command.Parameters.AddWithValue("@nick", query.Nick);
            command.Parameters.AddWithValue("@network", query.Network);
            try
            {
                object obj = command.ExecuteScalar();
                userId = (Int64)obj;
            }
            catch (Exception) //TODO propper exception handling needed here
            {
                created = false;
                userId = default(int);
            }

            return created;
        }
Beispiel #24
0
 public override IRCSharp.Kernel.Model.Query.IRCCommandQuery Execute(IRCSharp.Kernel.Model.Query.IRCCommandQuery query)
 {
     return null;
 }