Beispiel #1
0
        public bool Parse(IrcConnection aConnection, IrcEventArgs aEvent)
        {
            string tMessage = Helper.RemoveSpecialIrcChars(aEvent.Data.Message);
            Log.Debug("Parse() " + aEvent.Data.Nick + " " + tMessage);

            return Parse(aConnection, tMessage, aEvent);
        }
Beispiel #2
0
 private void CheckVersion(IrcConnection aConnection, string aNick, string aVersion)
 {
     Log.Info("Parse() received version reply from " + aNick + ": " + aVersion);
     if (aVersion.ToLower().Contains("iroffer"))
     {
         FireXdccList(this, new Model.Domain.EventArgs<Model.Domain.Server, string, string>(aConnection.Server, aNick, "XDCC HELP"));
     }
 }
 protected override bool ParseInternal(IrcConnection aConnection, string aMessage, IrcEventArgs aEvent)
 {
     Bot tBot = aConnection.Server.Bot(aEvent.Data.Nick);
     if (tBot != null)
     {
         return ParseInternal(aConnection, tBot, aMessage);
     }
     return false;
 }
Beispiel #4
0
 public static void IrcConnectionList()
 {
     IrcConnection irc = new IrcConnection();
     irc.OnReadLine += new ReadLineEventHandler(IrcConnectionListCallback);
     irc.Connect(SERVER, PORT);
     irc.WriteLine(Rfc2812.Nick(NICK), Priority.Critical);
     irc.WriteLine(Rfc2812.User(NICK, 0, REALNAME), Priority.Critical);
     irc.WriteLine(Rfc2812.List(CHANNEL));
     irc.Listen();
 }
Beispiel #5
0
 protected override bool ParseInternal(IrcConnection aConnection, string aMessage, IrcEventArgs aEvent)
 {
     foreach (var parser in _ircParsers)
     {
         if (parser.Parse(aConnection, aMessage, aEvent))
         {
             return true;
         }
     }
     return false;
 }
Beispiel #6
0
 protected override bool ParseInternal(IrcConnection aConnection, string aMessage, IrcEventArgs aEvent)
 {
     var args = aEvent as CtcpEventArgs;
     if (args != null)
     {
         if (args.CtcpCommand == "DCC")
         {
             return ParseInternal(aConnection, args.Data.Nick, args.CtcpParameter);
         }
     }
     return false;
 }
Beispiel #7
0
        protected override bool ParseInternal(IrcConnection aConnection, string aMessage, IrcEventArgs aEvent)
        {
            var regexes = new string[]
            {
                ".* XDCC LIST ALL(\"|'|)\\s*.*"
            };
            var match = Helper.Match(aMessage, regexes);
            if (match.Success)
            {
                FireXdccList(this, new EventArgs<Model.Domain.Server, string, string>(aConnection.Server, aEvent.Data.Nick, "XDCC LIST ALL"));
                return true;
            }

            regexes = new string[]
            {
                ".* XDCC LIST(\"|'|)\\s*.*"
            };
            match = Helper.Match(aMessage, regexes);
            if (match.Success)
            {
                FireXdccList(this, new EventArgs<Model.Domain.Server, string, string>(aConnection.Server, aEvent.Data.Nick, "XDCC LIST"));
                return true;
            }

            regexes = new string[]
            {
                ".* XDCC SEND LIST(\"|'|)\\s*.*"
            };
            match = Helper.Match(aMessage, regexes);
            if (match.Success)
            {
                FireXdccList(this, new EventArgs<Model.Domain.Server, string, string>(aConnection.Server, aEvent.Data.Nick, "XDCC SEND LIST"));
                return true;
            }

            regexes = new string[]
            {
                "^group: (?<group>[-a-z0-9_,.{}\\[\\]\\(\\)]+) .*"
            };
            match = Helper.Match(aMessage, regexes);
            if (match.Success)
            {
                FireXdccList(this, new EventArgs<Model.Domain.Server, string, string>(aConnection.Server, aEvent.Data.Nick, "XDCC LIST " + match.Groups["group"].ToString()));
                return true;
            }
            return false;
        }
Beispiel #8
0
 protected override bool ParseInternal(IrcConnection aConnection, string aMessage, IrcEventArgs aEvent)
 {
     var args = aEvent as CtcpEventArgs;
     if (args != null)
     {
         if (args.CtcpCommand == Rfc2812.Version())
         {
             CheckVersion(aConnection, aEvent.Data.Nick, aMessage);
         }
     }
     else if (aEvent.Data.Type == ReceiveType.QueryNotice)
     {
         if (aMessage.StartsWith("\u0001" + Rfc2812.Version() + " "))
         {
             CheckVersion(aConnection, aEvent.Data.Nick, aMessage.Substring(9));
         }
     }
     return false;
 }
Beispiel #9
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="connection"></param>
 public WriteThread(IrcConnection connection)
 {
     _Connection = connection;
 }
Beispiel #10
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="connection"></param>
 public ReadThread(IrcConnection connection)
 {
     _Connection = connection;
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="connection"></param>
 public WriteThread(IrcConnection connection)
 {
     _Connection = connection;
     QueuedEvent = new AutoResetEvent(false);
 }
Beispiel #12
0
            /// <summary>
            /// 
            /// </summary>
            /// <param name="connection"></param>
            public WriteThread(IrcConnection connection)
            {
                _Connection = connection;
                QueuedEvent = new AutoResetEvent(false);

                SendBuffer = new ConcurrentDictionary<Priority, ConcurrentQueue<String>>();

                SendBuffer[Priority.High] = new ConcurrentQueue<String>();
                SendBuffer[Priority.AboveMedium] = new ConcurrentQueue<String>();
                SendBuffer[Priority.Medium] = new ConcurrentQueue<String>();
                SendBuffer[Priority.BelowMedium] = new ConcurrentQueue<String>();
                SendBuffer[Priority.Low] = new ConcurrentQueue<String>();
            }
Beispiel #13
0
 protected abstract bool ParseInternal(IrcConnection aConnection, string aMessage, IrcEventArgs aEvent);
        protected override bool ParseInternal(IrcConnection aConnection, string aUser, string aMessage)
        {
            Bot tBot = aConnection.Server.Bot(aUser);
            if (tBot == null)
            {
                return false;
            }

            Packet tPacket = tBot.OldestActivePacket();
            if (tPacket == null)
            {
                Log.Error("Parse() DCC not activated from " + tBot);
                return false;
            }

            if (tPacket.Connected)
            {
                Log.Error("Parse() ignoring dcc from " + tBot + " because " + tPacket + " is already connected");
                return false;
            }

            bool isOk = false;

            int tPort = 0;
            File tFile = FileActions.TryGetFile(tPacket.RealName, tPacket.RealSize);
            Int64 startSize = 0;

            if (tFile != null)
            {
                if (tFile.Connected)
                {
                    return false;
                }
                if (tFile.CurrentSize > Settings.Default.FileRollbackBytes)
                {
                    startSize = tFile.CurrentSize - Settings.Default.FileRollbackBytes;
                }
            }

            string[] tDataList = aMessage.Split(' ');
            if (tDataList[0] == "SEND")
            {
                Log.Info("Parse() DCC from " + tBot);

                // if the name of the file contains spaces, we have to replace em
                if (aMessage.StartsWith("SEND \""))
                {
                    Match tMatch = Regex.Match(aMessage, "SEND \"(?<packet_name>.+)\"(?<bot_data>[^\"]+)$");
                    if (tMatch.Success)
                    {
                        tDataList = ("SEND " + tMatch.Groups["packet_name"].ToString().Replace(" ", "_").Replace("'", "") + tMatch.Groups["bot_data"]).Split(' ');
                    }
                }

                try
                {
                    tBot.IP = TryCalculateIp(tDataList[2]);
                    tBot.Commit();
                }
                catch (Exception ex)
                {
                    Log.Fatal("Parse() " + tBot + " - can not parse bot ip from string: " + aMessage, ex);
                    return false;
                }

                try
                {
                    tPort = int.Parse(tDataList[3]);
                }
                catch (Exception ex)
                {
                    Log.Fatal("Parse() " + tBot + " - can not parse bot port from string: " + aMessage, ex);
                    return false;
                }

                // we cant connect to port <= 0
                if (tPort <= 0)
                {
                    Log.Error("Parse() " + tBot + " submitted wrong port: " + tPort + ", disabling packet");
                    tPacket.Enabled = false;
                    tPacket.Commit();

                    FireNotificationAdded(Notification.Types.BotSubmittedWrongData, tBot);
                    return false;
                }

                tPacket.RealName = tDataList[1];

                if (tPacket.Name.Difference(tPacket.RealName) > 0.7)
                {
                    FireNotificationAdded(Notification.Types.PacketNameDifferent, tPacket);
                }

                try
                {
                    tPacket.RealSize = Int64.Parse(tDataList[4]);
                }
                catch (Exception ex)
                {
                    Log.Fatal("Parse() " + tBot + " - can not parse packet size from string: " + aMessage, ex);
                    return false;
                }

                if (tPacket.RealSize <= 0)
                {
                    Log.Error("Parse() " + tBot + " submitted wrong file size: " + tPacket.RealSize + ", disabling packet");
                    tPacket.Enabled = false;
                    tPacket.Commit();

                    FireNotificationAdded(Notification.Types.BotSubmittedWrongData, tBot);
                    return false;
                }

                if (tFile != null)
                {
                    if (tFile.Connected)
                    {
                        Log.Error("Parse() file for " + tPacket + " from " + tBot + " already in use or not found, disabling packet");
                        tPacket.Enabled = false;
                        FireUnRequestFromBot(this, new EventArgs<Server, Bot>(aConnection.Server, tBot));
                    }
                    else if (tFile.CurrentSize > 0)
                    {
                        Log.Info("Parse() try resume from " + tBot + " for " + tPacket + " @ " + startSize);
                        FireSendMessage(this, new EventArgs<Server, SendType, string, string>(aConnection.Server, SendType.CtcpRequest, tBot.Name, "DCC RESUME " + tPacket.RealName + " " + tPort + " " + startSize));
                    }
                    else
                    {
                        isOk = true;
                    }
                }
                else
                {
                    isOk = true;
                }
            }
            else if (tDataList[0] == "ACCEPT")
            {
                Log.Info("Parse() DCC resume accepted from " + tBot);

                try
                {
                    tPort = int.Parse(tDataList[2]);
                }
                catch (Exception ex)
                {
                    Log.Fatal("Parse() " + tBot + " - can not parse bot port from string: " + aMessage, ex);
                    return false;
                }

                try
                {
                    startSize = Int64.Parse(tDataList[3]);
                }
                catch (Exception ex)
                {
                    Log.Fatal("Parse() " + tBot + " - can not parse packet startSize from string: " + aMessage, ex);
                    return false;
                }

                isOk = true;
            }

            tPacket.Commit();
            if (isOk)
            {
                Log.Info("Parse() downloading from " + tBot + " - Starting: " + startSize + " - Size: " + tPacket.RealSize);
                FireAddDownload(this, new EventArgs<Packet, long, System.Net.IPAddress, int>(tPacket, startSize, tBot.IP, tPort));
                return true;
            }

            return false;
        }
Beispiel #15
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="connection"></param>
 public IdleWorkerThread(IrcConnection connection)
 {
     _Connection = connection;
 }
Beispiel #16
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="connection"></param>
 public IdleWorkerThread(IrcConnection connection)
 {
     _Connection = connection;
 }
Beispiel #17
0
 public bool Parse(IrcConnection aConnection, string aMessage, IrcEventArgs aEvent)
 {
     return ParseInternal(aConnection, aMessage, aEvent);
 }
Beispiel #18
0
 protected abstract bool ParseInternal(IrcConnection aConnection, string aUser, string aMessage);
Beispiel #19
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="connection"></param>
 public WriteThread(IrcConnection connection)
 {
     _Connection = connection;
 }
Beispiel #20
0
        protected override bool ParseInternal(IrcConnection aConnection, string aMessage, IrcEventArgs aEvent)
        {
            Model.Domain.Channel tChan = null;

            if (aEvent.Data.Type == ReceiveType.QueryNotice)
            {
                if (!String.IsNullOrEmpty(aEvent.Data.Nick))
                {
                    var user = aConnection.Client.GetIrcUser(aEvent.Data.Nick);
                    if (user != null)
                    {
                        foreach (string channel in user.JoinedChannels)
                        {
                            tChan = aConnection.Server.Channel(channel);
                            if (tChan != null)
                            {
                                break;
                            }
                        }
                    }
                }
            }
            else
            {
                tChan = aConnection.Server.Channel(aEvent.Data.Channel);
            }

            if (tChan != null)
            {
                string[] regexes =
                {
                    "#(?<pack_id>\\d+)(\u0240|)\\s+(\\d*)x\\s+\\[\\s*(?<pack_size>[\\<\\>\\d.]+)(?<pack_add>[BbGgiKMs]+)\\]\\s+(?<pack_name>.*)"
                };
                var match = Helper.Match(aMessage, regexes);
                if (match.Success)
                {
                    string tUserName = aEvent.Data.Nick;
                    Bot tBot = aConnection.Server.Bot(tUserName);
                    Model.Domain.Packet newPacket = null;

                    bool insertBot = false;
                    if (tBot == null)
                    {
                        insertBot = true;
                        tBot = new Bot {Name = tUserName, Connected = true, LastMessage = "initial creation", LastContact = DateTime.Now};
                    }

                    try
                    {
                        int tPacketId;
                        try
                        {
                            tPacketId = int.Parse(match.Groups["pack_id"].ToString());
                        }
                        catch (Exception ex)
                        {
                            Log.Fatal("Parse() " + tBot + " - can not parse packet id from string: " + aMessage, ex);
                            return false;
                        }

                        Model.Domain.Packet tPack = tBot.Packet(tPacketId);
                        if (tPack == null)
                        {
                            tPack = new Model.Domain.Packet();
                            newPacket = tPack;
                            tPack.Id = tPacketId;
                            tBot.AddPacket(tPack);
                        }
                        tPack.LastMentioned = DateTime.Now;

                        string name = RemoveSpecialIrcCharsFromPacketName(match.Groups["pack_name"].ToString());
                        if (tPack.Name != name && tPack.Name != "")
                        {
                            tPack.Enabled = false;
                            if (!tPack.Connected)
                            {
                                tPack.RealName = "";
                                tPack.RealSize = 0;
                            }
                        }
                        tPack.Name = name;

                        double tPacketSizeFormated;
                        string stringSize = match.Groups["pack_size"].ToString().Replace("<", "").Replace(">", "");
                        if (Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator == ",")
                        {
                            stringSize = stringSize.Replace('.', ',');
                        }
                        double.TryParse(stringSize, out tPacketSizeFormated);

                        string tPacketAdd = match.Groups["pack_add"].ToString().ToLower();

                        if (tPacketAdd == "k" || tPacketAdd == "kb")
                        {
                            tPack.Size = (Int64) (tPacketSizeFormated * 1024);
                        }
                        else if (tPacketAdd == "m" || tPacketAdd == "mb")
                        {
                            tPack.Size = (Int64) (tPacketSizeFormated * 1024 * 1024);
                        }
                        else if (tPacketAdd == "g" || tPacketAdd == "gb")
                        {
                            tPack.Size = (Int64) (tPacketSizeFormated * 1024 * 1024 * 1024);
                        }

                        if (tPack.Commit() && newPacket == null)
                        {
                            Log.Info("Parse() updated " + tPack + " from " + tBot);
                        }
                    }
                    catch (FormatException) {}

                    // insert bot if ok
                    if (insertBot)
                    {
                        if (tChan.AddBot(tBot))
                        {
                            Log.Info("Parse() inserted " + tBot);
                        }
                        else
                        {
                            var duplicateBot = tChan.Bot(tBot.Name);
                            if (duplicateBot != null)
                            {
                                tBot = duplicateBot;
                            }
                            else
                            {
                                Log.Error("Parse() cant insert " + tBot + " into " + tChan);
                            }
                        }
                    }
                    // and insert packet _AFTER_ this
                    if (newPacket != null)
                    {
                        tBot.AddPacket(newPacket);
                        Log.Info("Parse() inserted " + newPacket + " into " + tBot);
                    }

                    tBot.Commit();
                    tChan.Commit();
                    return true;
                }
            }
            return false;
        }
Beispiel #21
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="connection"></param>
 public ReadThread(IrcConnection connection)
 {
     _Connection = connection;
 }
Beispiel #22
0
        protected override bool ParseInternal(IrcConnection aConnection, string aMessage, IrcEventArgs aEvent)
        {
            if (aEvent.Data.Nick != null && aEvent.Data.Nick.ToLower() == "nickserv")
            {
                if (Helper.Match(aMessage, ".*Password incorrect.*").Success)
                {
                    Log.Error("password wrong");
                }

                else if (Helper.Match(aMessage, ".*(The given email address has reached it's usage limit of 1 user|This nick is being held for a registered user).*").Success)
                {
                    Log.Error("nick or email already used");
                }

                if (Helper.Match(aMessage, ".*Your nick isn't registered.*").Success)
                {
                    Log.Info("registering nick");
                    if (Settings.Default.AutoRegisterNickserv && Settings.Default.IrcPasswort != "" && Settings.Default.IrcRegisterEmail != "")
                    {
                        FireWriteLine(this, new EventArgs<Server, string>(aConnection.Server, aEvent.Data.Nick + " register " + Settings.Default.IrcPasswort + " " + Settings.Default.IrcRegisterEmail));
                    }
                }

                else if (Helper.Match(aMessage, ".*Nickname is .*in use.*").Success)
                {
                    FireWriteLine(this, new EventArgs<Server, string>(aConnection.Server, aEvent.Data.Nick + " ghost " + Settings.Default.IrcNick + " " + Settings.Default.IrcPasswort));
                    FireWriteLine(this, new EventArgs<Server, string>(aConnection.Server, aEvent.Data.Nick + " recover " + Settings.Default.IrcNick + " " + Settings.Default.IrcPasswort));
                    FireWriteLine(this, new EventArgs<Server, string>(aConnection.Server, Rfc2812.Nick(Settings.Default.IrcNick)));
                }

                else if (Helper.Match(aMessage, ".*Services Enforcer.*").Success)
                {
                    FireWriteLine(this, new EventArgs<Server, string>(aConnection.Server, aEvent.Data.Nick + " recover " + Settings.Default.IrcNick + " " + Settings.Default.IrcPasswort));
                    FireWriteLine(this, new EventArgs<Server, string>(aConnection.Server, aEvent.Data.Nick + " release " + Settings.Default.IrcNick + " " + Settings.Default.IrcPasswort));
                    FireWriteLine(this, new EventArgs<Server, string>(aConnection.Server, Rfc2812.Nick(Settings.Default.IrcNick)));
                }

                else if (Helper.Match(aMessage, ".*(This nickname is registered and protected|This nick is being held for a registered user|msg NickServ IDENTIFY).*").Success)
                {
                    if (Settings.Default.IrcPasswort != "" && !_authenticatedServer.Contains(aConnection.Server))
                    {
                        _authenticatedServer.Add(aConnection.Server);
                        //TODO check if we are really registered
                        FireWriteLine(this, new EventArgs<Server, string>(aConnection.Server, aEvent.Data.Nick + " identify " + Settings.Default.IrcPasswort));
                    }
                    else
                    {
                        Log.Error("nick is already registered and i got no password");
                    }
                }

                else if (Helper.Match(aMessage, ".*You must have been using this nick for at least 30 seconds to register.*").Success)
                {
                    //TODO sleep the given time and reregister
                    FireWriteLine(this, new EventArgs<Server, string>(aConnection.Server, aEvent.Data.Nick + " register " + Settings.Default.IrcPasswort + " " + Settings.Default.IrcRegisterEmail));
                }

                else if (Helper.Match(aMessage, ".*Please try again with a more obscure password.*").Success)
                {
                    Log.Error("password is unsecure");
                }

                else if (Helper.Match(aMessage, ".*(A passcode has been sent to|This nick is awaiting an e-mail verification code).*").Success)
                {
                    Log.Error("confirm email");
                }

                else if (Helper.Match(aMessage, ".*Nickname .*registered under your account.*").Success)
                {
                    Log.Info("nick registered succesfully");
                }

                else if (Helper.Match(aMessage, ".*Password accepted.*").Success)
                {
                    Log.Info("password accepted");
                }

                else if (Helper.Match(aMessage, ".*Please type .*to complete registration.*").Success)
                {
                    Match tMatch = Regex.Match(aMessage, ".* NickServ confirm (?<code>[^\\s]+) .*", RegexOptions.IgnoreCase);
                    if (tMatch.Success)
                    {
                        FireWriteLine(this, new EventArgs<Server, string>(aConnection.Server, aEvent.Data.Nick + " confirm " + tMatch.Groups["code"]));
                        Log.Info("Parse(" + aEvent.Data.RawMessage + ") - confirming nickserv");
                    }
                    else
                    {
                        Log.Error("Parse(" + aEvent.Data.RawMessage + ") - cant find nickserv code");
                    }
                }

                else if (Helper.Match(aMessage, ".*Your password is.*").Success)
                {
                    Log.Info("password accepted");
                }

                Log.Error("unknow command: " + aEvent.Data.RawMessage);
                return true;
            }
            return false;
        }