Beispiel #1
0
 internal int get_nick_access(string tmp_nick, string channel)
 {
     List<int> access_num = new List<int>();
     int top_access = Conf.Default_Level;
     access_num.Add(Conf.Default_Level);
     try
     {
         Nick_Info nick_info = get_nick_info(tmp_nick, channel);
         if (nick_info != null)
         {
             access_num.Add(nick_info.Access);
         }
         else
         {
             Nick_Info new_nick = new Nick_Info();
             new_nick.Nick = tmp_nick;
             new_nick.Access = Conf.Default_Level;
             new_nick.Identified = false;
             add_nick_info(new_nick, channel);
             nick_info = new_nick;
         }
         if (nick_info.Nick.Equals(nick, StringComparison.InvariantCultureIgnoreCase))
         {
             access_num.Add(Conf.Owner_Level);
         }
         if (!nick_info.Identified)
         {
             nick_info.Identified = get_nick_ident(nick_info.Nick);
         }
         if (nick_info.Identified == true)
         {
             foreach (Modules.Module module in Conf.Modules)
             {
                 if (module.Class_Name.Equals("access"))
                 {
                     bool chan_allowed = true;
                     foreach (string blacklist in module.Blacklist)
                     {
                         if (blacklist.Equals(channel, StringComparison.InvariantCultureIgnoreCase))
                         {
                             chan_allowed = false;
                             break;
                         }
                     }
                     if (chan_allowed)
                     {
                         Modules.access acc = new Modules.access();
                         access_num.AddRange(acc.get_access_list(tmp_nick, channel, this));
                     }
                     break;
                 }
             }
         }
         if (nick_info.Identified == true)
         {
             foreach (string owner in Conf.Owners)
             {
                 if (tmp_nick.Equals(owner, StringComparison.InvariantCultureIgnoreCase))
                 {
                     access_num.Add(Conf.Owner_Level);
                 }
             }
         }
         foreach (int access in access_num)
         {
             if (access > top_access)
             {
                 top_access = access;
             }
         }
         if (top_access == Conf.Default_Level && channel != null)
         {
             top_access = get_nick_chan_access(tmp_nick, channel);
             if (top_access != Conf.Default_Level)
             {
                 nick_info.Access = top_access;
             }
         }
     }
     catch (Exception ex)
     {
         lock (controller.errorlock)
         {
             controller.log_error(ex, Conf.Logs_Path);
         }
     }
     return top_access;
 }
Beispiel #2
0
 internal void add_nick_info(Nick_Info nick, string channel)
 {
     Channel_Info chan = get_chan_info(channel);
     if (chan != null)
     {
         chan.Nicks.Add(nick);
     }
     else
     {
         add_chan_info(channel);
         chan = get_chan_info(channel);
         chan.Nicks.Add(nick);
     }
 }
Beispiel #3
0
 internal void del_nick_info(Nick_Info nick, string channel)
 {
     Channel_Info chan = get_chan_info(channel);
     if (chan != null)
     {
         chan.Nicks.Remove(nick);
     }
 }
Beispiel #4
0
        internal void parse_stream(string data_line)
        {
            string[] ex;
            string type = "base";
            int nick_access = Conf.User_Level;
            string line_nick = "";
            string channel = "";
            bool bot_command = false;
            string command = "";
            restart = false;
            char[] charSeparator = new char[] { ' ' };
            ex = data_line.Split(charSeparator, 5, StringSplitOptions.RemoveEmptyEntries);

            if (ex[0] == "PING")
            {
                sendData("PONG", ex[1]);
            }

            string[] user_info = ex[0].Split('@');
            string[] name = user_info[0].Split('!');
            if (name.GetUpperBound(0) > 0)
            {
                line_nick = name[0].TrimStart(':');
                channel = ex[2].TrimStart(':');

                type = "line";
                // On Message Events events
                if (ex[1].Equals("privmsg", StringComparison.InvariantCultureIgnoreCase))
                {
                    if (ex.GetUpperBound(0) >= 3) // If valid Input
                    {
                        command = ex[3].ToLower(); //grab the command sent
                        string msg_type = command.TrimStart(':');
                        if (msg_type.StartsWith(Conf.Command) == true)
                        {
                            bot_command = true;
                            command = command.Remove(0, 2);
                        }

                        if (ex[2].StartsWith("#") == true) // From Channel
                        {
                            nick_access = get_nick_access(line_nick, channel);
                            type = "channel";
                        }
                        else // From Query
                        {
                            foreach (Channel_Info chan in Conf.Channel_List)
                            {
                                int tmp_nick_access = get_nick_access(line_nick, chan.Channel);
                                if (tmp_nick_access > nick_access)
                                {
                                    nick_access = tmp_nick_access;
                                }
                            }
                            channel = line_nick;
                            type = "query";
                        }
                    }
                }

                // On Invite events
                if (ex[1].Equals("invite", StringComparison.InvariantCultureIgnoreCase))
                {
                    type = "invite";
                }

                // On JOIN events
                if (ex[1].Equals("join", StringComparison.InvariantCultureIgnoreCase))
                {
                    type = "join";
                    Nick_Info info = get_nick_info(line_nick, channel);
                    if (info == null)
                    {
                        Channel_Info chan_info = get_chan_info(channel);
                        if (chan_info == null)
                        {
                            add_chan_info(channel);
                        }
                        info = new Nick_Info();
                        info.Nick = line_nick;
                        info.Access = get_nick_chan_access(line_nick, channel);
                        add_nick_info(info, channel);
                    }
                }

                // On user QUIT events
                if (ex[1].Equals("quit", StringComparison.InvariantCultureIgnoreCase))
                {
                    type = "quit";
                    if (line_nick.Equals(Nick, StringComparison.InvariantCultureIgnoreCase))
                    {
                        Conf.Channel_List.Clear();
                    }
                    else
                    {
                        foreach (Channel_Info chan_info in Conf.Channel_List)
                        {
                            Nick_Info info = get_nick_info(line_nick, chan_info.Channel);
                            if (info != null)
                            {
                                del_nick_info(info, chan_info.Channel);
                            }
                        }
                    }
                }

                // On user PART events
                if (ex[1].Equals("part", StringComparison.InvariantCultureIgnoreCase))
                {
                    type = "part";
                    if (line_nick.Equals(Nick, StringComparison.InvariantCultureIgnoreCase))
                    {
                        del_chan_info(channel);
                    }
                    else
                    {
                        Nick_Info info = get_nick_info(line_nick, channel);
                        if (info != null)
                        {
                            del_nick_info(info, channel);
                        }
                    }
                }

                // On user KICK events
                if (ex[1].Equals("kick", StringComparison.InvariantCultureIgnoreCase))
                {
                    type = "kick";
                    if (ex[3].Equals(Nick, StringComparison.InvariantCultureIgnoreCase))
                    {
                        del_chan_info(channel);
                    }
                    else
                    {
                        Nick_Info info = get_nick_info(ex[3], channel);
                        if (info != null)
                        {
                            del_nick_info(info, channel);
                        }
                    }
                }

                // On user Nick Change events
                if (ex[1].Equals("nick", StringComparison.InvariantCultureIgnoreCase))
                {
                    type = "nick";
                    foreach (Channel_Info chan_info in Conf.Channel_List)
                    {
                        foreach (Nick_Info nick_info in chan_info.Nicks)
                        {
                            if (nick_info.Nick.Equals(line_nick))
                            {
                                nick_info.Nick = channel;
                            }
                        }
                    }
                }

                // On ChanServ Mode Change
                if (ex[1].Equals("mode", StringComparison.InvariantCultureIgnoreCase))
                {
                    type = "mode";
                    if (ex.GetUpperBound(0) > 3)
                    {
                        char[] arr = ex[3].ToCharArray();
                        string[] change_nicks = ex[4].Split(charSeparator, StringSplitOptions.RemoveEmptyEntries);
                        int nick_index = 0;
                        bool add_sub = true;
                        foreach (char c in arr)
                        {
                            if (c.Equals('+'))
                            {
                                add_sub = true;
                            }
                            else if (c.Equals('-'))
                            {
                                add_sub = false;
                            }
                            else if (c.Equals('q') || c.Equals('a') || c.Equals('o') || c.Equals('h') || c.Equals('v'))
                            {
                                Nick_Info nick_info = get_nick_info(change_nicks[nick_index], channel);
                                if (nick_info != null)
                                {
                                    int change_access = get_access_num(c.ToString(), true);
                                    if (add_sub)
                                    {
                                        if (change_access > nick_info.Access)
                                        {
                                            nick_info.Access = change_access;
                                        }
                                    }
                                    else
                                    {
                                        nick_info.Access = get_nick_chan_access(change_nicks[nick_index], channel);
                                    }
                                }
                                else
                                {
                                    Nick_Info info = new Nick_Info();
                                    info.Nick = line_nick;
                                    if (add_sub)
                                    {
                                        info.Access = get_access_num(c.ToString(), true);
                                    }
                                    else
                                    {
                                        info.Access = get_nick_chan_access(change_nicks[nick_index], channel);
                                    }
                                    add_nick_info(info, channel);
                                }
                                nick_index++;
                            }
                            else if (c.Equals('p') || c.Equals('s'))
                            {
                                Channel_Info chan_info = get_chan_info(channel);
                                if (chan_info != null)
                                {
                                    if (add_sub)
                                    {
                                        chan_info.Show = false;
                                    }
                                    else
                                    {
                                        chan_info.Show = true;
                                    }
                                }
                            }
                        }
                    }
                    else if(ex.GetUpperBound(0) > 2)
                    {
                        char[] arr = ex[3].ToCharArray();
                        string mod_nick = ex[2];
                        bool add_sub = true;
                        foreach (char c in arr)
                        {
                            if (c.Equals('+'))
                            {
                                add_sub = true;
                            }
                            else if (c.Equals('-'))
                            {
                                add_sub = false;
                            }
                            else if (c.Equals('q') || c.Equals('a') || c.Equals('o') || c.Equals('h') || c.Equals('v'))
                            {
                                Nick_Info nick_info = get_nick_info(mod_nick, channel);
                                if (nick_info != null)
                                {
                                    int change_access = get_access_num(c.ToString(), true);
                                    if (add_sub)
                                    {
                                        if (change_access > nick_info.Access)
                                        {
                                            nick_info.Access = change_access;
                                        }
                                    }
                                    else
                                    {
                                        nick_info.Access = get_nick_chan_access(mod_nick, channel);
                                    }
                                }
                                else
                                {
                                    Nick_Info info = new Nick_Info();
                                    info.Nick = line_nick;
                                    if (add_sub)
                                    {
                                        info.Access = get_access_num(c.ToString(), true);
                                    }
                                    else
                                    {
                                        info.Access = get_nick_chan_access(mod_nick, channel);
                                    }
                                    add_nick_info(info, channel);
                                }
                            }
                        }
                    }
                }
            }

            string[] ignored_nicks = Conf.Ignore_List.Split(',');
            bool run_modules = true;
            foreach (string ignore_nick in ignored_nicks)
            {
                if (ignore_nick.Equals(line_nick, StringComparison.InvariantCultureIgnoreCase))
                {
                    run_modules = false;
                    break;
                }
            }
            if (run_modules)
            {
                //Run Enabled Modules
                foreach (Modules.Module module in Conf.Modules)
                {
                    bool module_allowed = !module.Blacklist.Contains(line_nick) && !module.Blacklist.Contains(channel);
                    if (module_allowed == true)
                    {
                        BackgroundWorker work = new BackgroundWorker();
                        work.DoWork += (sender, e) => backgroundWorker_RunModule(sender, e, this, module, ex, command, nick_access, line_nick, channel, bot_command, type);
                        work.RunWorkerAsync(2000);
                    }
                }
            }
        }