Exemplo n.º 1
0
        public static WhoInfo GetUser(Irc server, string nick)
        {
            bool    gotWho = false;
            WhoInfo wi     = null;

            server.Writer.SendMessage(RFC1459.IrcCommands.Who(nick, false));
            while (!gotWho)
            {
                RFC1459.ReplyCode code;
                string            message, prefix, command;
                string[]          parameters;

                message = server.Reader.ReadLine( );
                RFC1459.IrcCommands.ParseReply(message, out prefix, out command, out parameters);
                if (Enum.TryParse <RFC1459.ReplyCode> (command, out code))
                {
                    switch (code)
                    {
                    case RFC1459.ReplyCode.RPL_WHOREPLY:
                        wi = WhoInfo.Parse(new IrcMessage(prefix, command, parameters));
                        break;

                    case RFC1459.ReplyCode.RPL_ENDOFWHO:
                        gotWho = true;
                        break;
                    }
                }
            }
            return(wi);
        }
Exemplo n.º 2
0
 public Channel(Irc Parent, string Name, string Key)
 {
     this.parent  = Parent;
     this.channel = Name;
     this.key     = Key;
     this.modes   = string.Empty;
 }
Exemplo n.º 3
0
 public Channel( Irc Parent, string Name, string Key )
 {
     this.parent = Parent;
     this.channel = Name;
     this.key = Key;
     this.modes = string.Empty;
 }
Exemplo n.º 4
0
 public static void Execute( string command, Irc irc, Channel chan, string callee, object[] args )
 {
     Func<Irc, string, string, object[], int> func = commands[ command ];
     if ( chan != null )
         func.Invoke ( irc, chan.Name, callee, args );
     else
         func.Invoke ( irc, string.Empty, callee, args );
 }
 public Channel( Irc Parent, string Name, string Key )
 {
     this.parent = Parent;
     this.channel = Name;
     this.key = Key;
     this.modes = string.Empty;
     streamer = Streamer.GetProfile ( Name.Replace ( "#", "" ) );
     Irc.Format ( "Caught Streamer: {0}", ConsoleColor.Green, streamer.name );
 }
Exemplo n.º 6
0
 public Channel(Irc Parent, string Name, string Key)
 {
     this.parent  = Parent;
     this.channel = Name;
     this.key     = Key;
     this.modes   = string.Empty;
     streamer     = Streamer.GetProfile(Name.Replace("#", ""));
     Irc.Format("Caught Streamer: {0}", ConsoleColor.Green, streamer.name);
 }
 private static void SendMessage(Irc irc, string channel, string nick, string message, params object[] args)
 {
     if (string.IsNullOrEmpty(channel))
     {
         irc.SendMessage(nick, string.Format(message, args));
     }
     else
     {
         irc.GetChannel(channel).SendMessage(string.Format(message, args));
     }
 }
        public static void Execute(string command, Irc irc, Channel chan, string callee, object[] args)
        {
            Func <Irc, string, string, object[], int> func = commands[command];

            if (chan != null)
            {
                func.Invoke(irc, chan.Name, callee, args);
            }
            else
            {
                func.Invoke(irc, string.Empty, callee, args);
            }
        }
Exemplo n.º 9
0
        public void Save(Irc irc)
        {
            IConfig             server  = null;;
            string              host    = irc.Host;
            string              nick    = irc.Nick;
            string              user    = irc.Username;
            string              real    = irc.Realname;
            int                 port    = irc.Port;
            string              owner   = irc.Owner;
            string              nspass  = irc.NickPass;
            string              srvpass = irc.ServerPass;
            Stack <ChannelData> buffer  = irc.ChannelBuffer;

            if (!string.IsNullOrEmpty(nspass))
            {
                nspass = new SymCryptography(SymCryptography.ServiceProviderEnum.Rijndael).Encrypt(nspass);
            }

            // Last known code
            RFC1459.ReplyCode lkc    = irc.Code;
            ConsoleColor      colour = irc.Colour;

            if (config.Configs[irc.Server] == null)
            {
                server = config.AddConfig(irc.Server);
            }
            else
            {
                server = config.Configs[irc.Server];
            }

            server.Set("Host", host);
            server.Set("Port", port);
            server.Set("Nick", nick);
            server.Set("Server_Password", srvpass);
            server.Set("Username", user);
            server.Set("Realname", real);
            server.Set("NickPassword", nspass);
            server.Set("Owner", owner);
            server.Set("LastKnownCode", ( int )lkc);
            server.Set("Colour", ( int )colour);
            server.Set("MainChannel", "{nokey}");
            server.Set("MainKey", "{nokey}");

            if (buffer.Count > 0)
            {
                server.Set("Channels", string.Join(",", buffer.ToArray( )));
            }

            config.Save( );
        }
Exemplo n.º 10
0
        public static Permissions GetPermission(string Nick, Irc s)
        {
            i = s;
            User[] users          = ReadUsers( );
            var    availablenicks = new List <string> (users.Select((U) => U.Name));

            if (availablenicks.Contains(Nick))
            {
                foreach (User user in users.Where(user => user.Name == Nick))
                {
                    User u = getUser(Nick);
                    try
                    {
                        if (user.Host == u.Host)
                        {
                            if (!bool.Parse(user.Banned))
                            {
                                return(( Permissions )Enum.Parse(typeof(Permissions), user.Permission));
                            }
                            else
                            {
                                s.SendMessage(Nick, "You're not allowed to use my Private Messaging system!");
                            }
                        }
                        else
                        {
                            s.Format(
                                "Host Mismatch on user \"{0}\" with host \"{1}\". Real host is \"{2}\". Using Guest permissions.",
                                ConsoleColor.DarkRed,
                                user.Name,
                                user.Host,
                                u.Host
                                );

                            /*s.SendMessage ( Nick,
                             *            string.Format (
                             *                "You are {0}, however the host I have on record does not match! If you find this in error, please contact {1} for further assistance.",
                             *                Nick, s.Owner ) );
                             */
                        }
                    }
                    catch (Exception ex)
                    {
                        s.SendErrorToFile(ex, Nick);
                        break;
                    }
                }
            }
            return(Permissions.Guest);
        }
Exemplo n.º 11
0
        private static void Main(string[] args)
        {
            if (!SanityCheck( ))
            {
                Console.WriteLine("The bot has failed to complete its sanity check...\r\nPlease press any key to exit the Bot...");
                Console.ReadKey(true);
                return;
            }

            // Start the timer on ground zero
            global::BlizzetaZero.Kernel.Global.BeginUptime( );

            // Auth.Authenticate(); Thread t = new Thread ( new ThreadStart ( LaunchGamePanel ) );
            // t.Start ( );
            Console.Title        = Global.Title;
            Console.WindowWidth += 60;

            _settings = new Settings( );
            CoreCommands.IncludeBuiltInCommands( );
            SetCharSet( );
            CarpeDiem( );

            Irc irc = new Irc(Global.Nick,
                              Global.Realname,
                              Global.Username,
                              "",
                              Global.IrcServer,
                              Global.ServerPassword,
                              Global.Port,
                              RFC1459.ReplyCode.ERR_UNKNOWNMODE,
                              ConsoleColor.Green,
                              "#blizzardothegreat",
                              "",
                              "blizzardothegreat",
                              "#blizzetabot",
                              "");

            try
            {
                irc.OnMotd += irc_OnMotd;
                irc.Connect(irc.Host);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Exemplo n.º 12
0
        public static Permissions GetPermission( string Nick, Irc s )
        {
            i = s;
            User[] users = ReadUsers ( );
            var availablenicks = new List<string> ( users.Select ( ( U ) => U.Name ) );

            if ( availablenicks.Contains ( Nick ) )
                foreach ( User user in users.Where ( user => user.Name == Nick ) )
                {
                    User u = getUser ( Nick );
                    try
                    {
                        if ( user.Host == u.Host )
                        {
                            if ( !bool.Parse ( user.Banned ) )
                            {
                                return ( Permissions ) Enum.Parse ( typeof ( Permissions ), user.Permission );
                            }
                            else
                            {
                                s.SendMessage ( Nick, "You're not allowed to use my Private Messaging system!" );
                            }
                        }
                        else
                        {
                            s.Format (
                                "Host Mismatch on user \"{0}\" with host \"{1}\". Real host is \"{2}\". Using Guest permissions.",
                                ConsoleColor.DarkRed,
                                user.Name,
                                user.Host,
                                u.Host
                                );
                            /*s.SendMessage ( Nick,
                                          string.Format (
                                              "You are {0}, however the host I have on record does not match! If you find this in error, please contact {1} for further assistance.",
                                              Nick, s.Owner ) );
                                                                */
                        }
                    }
                    catch ( Exception ex )
                    {
                        s.SendErrorToFile ( ex, Nick );
                        break;
                    }
                }
            return Permissions.Guest;
        }
Exemplo n.º 13
0
        public Irc Read(string server)
        {
            Irc          _irc;
            string       host, nick, password, srvPass, owner, user, real, channel, key, additional;
            int          port;
            ConsoleColor colour;

            RFC1459.ReplyCode lkc;
            IConfig           irc = config.Configs[server];

            nick     = irc.GetString("Nick");
            real     = irc.GetString("Realname");
            user     = irc.GetString("Username");
            host     = irc.GetString("Host");
            srvPass  = irc.GetString("Server_Password");
            port     = irc.GetInt("Port");
            owner    = irc.GetString("Owner");
            password = irc.GetString("NickPassword");
            if (!string.IsNullOrEmpty(password))
            {
                password = new SymCryptography(SymCryptography.ServiceProviderEnum.Rijndael).Decrypt(password);
            }
            lkc        = (RFC1459.ReplyCode)irc.GetInt("LastKnownCode");
            colour     = ( ConsoleColor )irc.GetInt("Colour");
            channel    = irc.GetString("MainChannel");
            key        = irc.GetString("MainKey");
            additional = irc.GetString("Channels");

            Stack <ChannelData> chanBuffer = new Stack <ChannelData> ( );

            foreach (string ch in additional.Split(','))
            {
                string[] chankey = ch.Split(':');
                chanBuffer.Push(new ChannelData( )
                {
                    Channel = chankey[0], Key = chankey[1]
                });
            }

            _irc = new Irc(nick, real, user, password, host, "", port, lkc, colour, channel, key);
            _irc.ChannelBuffer = chanBuffer;

            return(_irc);
        }
Exemplo n.º 14
0
        private static void Main(string[] args)
        {
            Console.WindowWidth += 60;

            CoreCommands.IncludeBuiltInCommands( );
            SetCharSet( );
            Irc irc = new Irc("BlizzetaZero", "Blizzeta Zero Bot 7.0", "Blizzeta", "#Blizzeta");

            try
            {
                irc.Colour  = ConsoleColor.Green;
                irc.OnMotd += irc_OnMotd;
                irc.Connect("irc.ringoflightning.net");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Exemplo n.º 15
0
        private static void Main( string[] args )
        {
            Console.WindowWidth += 60;

            CoreCommands.IncludeBuiltInCommands ( );
            SetCharSet ( );
            Irc irc = new Irc ( "BlizzetaZero", "Blizzeta Zero Bot 7.0", "Blizzeta", "#Blizzeta" );

            try
            {
                irc.Colour = ConsoleColor.Green;
                irc.OnMotd += irc_OnMotd;
                irc.Connect ( "irc.ringoflightning.net" );
            }
            catch ( Exception e )
            {
                Console.WriteLine ( e.Message );
            }
        }
 private static void SendMessage( Irc irc, string channel, string nick, string message, params object[] args )
 {
     if ( string.IsNullOrEmpty ( channel ) )
         irc.SendMessage ( nick, string.Format ( message, args ) );
     else
         irc.GetChannel ( channel ).SendMessage ( string.Format ( message, args ) );
 }
        public static XElement GetUserXmlProfile(string name, bool falseAdmin = false, Irc i = null)
        {
            XDocument xdc = xDoc;
            XElement  xel = xdc.Descendants("Users").Descendants("User").Where((x) => x.Attribute("name").Value == name).FirstOrDefault( );

            if (falseAdmin)
            {
                i.SendMessage(name, "You do not have permission to manipulate another user, only yourself.");
            }

            return(xel);
        }
        public static void IncludeBuiltInCommands( )
        {
            #region check

            AddCommand("check", (i, c, n, o) =>
            {
                Channel chan  = i.GetChannel(c);
                Permissions p = User.GetUser(chan.Streamer, n).GetPermission( );
                Dictionary <string, Func <int> > subcmd = new Dictionary <string, Func <int> > ( );
                subcmd.Add("permission", () =>
                {
                    // TODO: Add permissions check
                    i.GetChannel(c).SendMessage(string.Format("{0}, Your Permissions are \"{1}\"", n, p));
                    return(0);
                });

                subcmd.Add("time", () =>
                {
                    // TODO: Add configuration for callee
                    DateTime dt = DateTime.Now;
                    Irc.Format("Current Time: {0:dddd MMMM dd, yyyy} at {0:HH:mm:ss}", ConsoleColor.Yellow, dt);
                    i.GetChannel(c).SendMessage(string.Format("{0} time is {1:dddd MMMM dd, yyyy} at {1:HH:mm:ss}", CheckS(i.Owner), dt));
                    return(0);
                });
                subcmd.Add("uptime", () =>
                {
                    Irc.Format("Uptime: {0}", ConsoleColor.DarkGreen);
                    i.GetChannel(c).SendMessage(string.Format("{0}, I've been up for {1} {2}, {3} {4}, {5} {6}, and {7} {8}"));
                    return(0);
                });

                try
                {
                    subcmd[o[0] as string].Invoke( );
                }
                catch (Exception ex)
                {
                    i.SendMessage(c, "Invalid command");
                }

                return(0);
            });

            #endregion check

            #region clear

            AddCommand("clear", (i, c, n, o) =>
            {
                Channel chan  = i.GetChannel(c);
                Permissions p = User.GetUser(chan.Streamer, n).GetPermission( );
                if (p <= Permissions.Root)
                {
                    Console.Clear( );
                }
                else
                {
                    i.SendMessage(n, "Let me clean that nose of yours... in other words... \"MIND YOUR DAMN BUSINESS!\" o_o");
                }
                return(0);
            });

            #endregion clear

            #region get

            AddCommand("get", (i, c, n, o) =>
            {
                Permissions p = User.GetUserProfile(n).GetPermission( );
                Dictionary <string, Func <int> > subcmd = new Dictionary <string, Func <int> > ( );

                subcmd.Add("say", () =>
                {
                    i.SendMessage(n, ignoreSay ? "I'm ignoring say." : "I'm not ignoring say.");
                    return(0);
                });

                if (p <= Permissions.Operator)
                {
                    subcmd[o[0] as string].Invoke( );
                }
                else
                {
                    i.GetChannel(c).SendMessage(SpecialMessage(n));
                }
                return(0);
            });

            #endregion get

            #region set

            AddCommand("set", (i, c, n, o) =>
            {
                Permissions p = User.GetUserProfile(n).GetPermission( );
                Dictionary <string, Func <int> > subcmd = new Dictionary <string, Func <int> > ( );

                subcmd.Add("say", () =>
                {
                    string val = (o[1] as string).ToLower( );
                    if (val == "on" || val == "true")
                    {
                        ignoreSay = false;
                    }
                    else if (val == "off" || val == "false")
                    {
                        ignoreSay = true;
                    }
                    return(0);
                });

                return(0);
            });

            #endregion set

            #region help

            AddCommand("help", (i, c, n, o) =>
            {
                Permissions p = User.GetUserProfile(n).GetPermission( );

                // + help [-mpuv] [command] [subcommand]

                /*
                 *  Options:
                 *      -m | --more         : More Command
                 *      -p | --permissions  : Permissions Command
                 *      -u | --usage        : Usage Command
                 *      -v | --version      : Version Command
                 */

                return(0);
            });

            #endregion help

            #region join

            AddCommand("join", (i, c, n, o) =>
            {
                Channel chan  = i.GetChannel(c);
                Permissions p = User.GetUser(chan.Streamer, n).GetPermission( );
                if (p <= Permissions.Administrator)
                {
                    bool chanExists = i.Channels.Exists(new Predicate <Channel> ((ch) =>
                    {
                        return(ch.Name == o[0] as string);
                    }));

                    if (!chanExists)
                    {
                        if (o.Length > 1)
                        {
                            i.Join(o[0] as string, o[1] as string);
                            return(0);
                        }
                        else if (o.Length > 0)
                        {
                            i.Join(o[0] as string, string.Empty);
                            return(0);
                        }
                        else
                        {
                            i.SendMessage(c, "I can't join without a channel name");
                        }
                    }
                    else
                    {
                        i.SendMessage(c, string.Format("I'm already in {0}!", o[0] as string));
                    }
                }
                else
                {
                    i.SendMessage(n, SpecialMessage(n));
                }
                return(-1);
            });

            #endregion join

            #region list

            AddCommand("list", (i, c, n, o) =>
            {
                Channel chan  = i.GetChannel(c);
                Permissions p = User.GetUser(chan.Streamer, n).GetPermission( );

                if (p <= Permissions.Administrator)
                {
                    Channel[] chans = i.Channels.ToArray( );
                    i.SendMessage(n, "I am in these channels:");
                    foreach (Channel channel in chans)
                    {
                        i.SendMessage(n, string.Format(channel.Name));
                    }
                }
                else
                {
                    i.GetChannel(c).SendMessage(SpecialMessage(n));
                }
                return(0);
            });

            #endregion list

            #region Topic

            AddCommand("topic", (i, c, n, o) =>
            {
                Channel chan  = i.GetChannel(c);
                Permissions p = User.GetUser(chan.Streamer, n).GetPermission( );
                if (p <= Permissions.Operator)
                {
                    string msg = string.Join(" ", o as string[], 1, o.Length - 1);
                }

                return(0);
            });

            #endregion Topic

            #region Playlist

            AddCommand("playlist", (i, c, n, o) =>
            {
                Channel chan  = i.GetChannel(c);
                Permissions p = User.GetUser(chan.Streamer, n).GetPermission( );
                if (p <= Permissions.Administrator)
                {
                    i.GetChannel(c).SendMessage(string.Format("{0} playlist: http://playlist.blizzeta.net", CheckS(i.Owner)));
                }
                return(0);
            });

            #endregion Playlist

            #region Game

            AddCommand("game", (i, c, n, o) =>
            {
                Channel chan  = i.GetChannel(c);
                Permissions p = User.GetUser(chan.Streamer, n).GetPermission( );
                if (p <= Permissions.User)
                {
                }
                return(0);
            });

            #endregion Game

            #region account

            AddCommand("acc", (i, c, n, o) =>
            {
                Channel chan  = i.GetChannel(c);
                Permissions p = User.GetUser(chan.Streamer, n).GetPermission( );

                Streamer streamer = Streamer.GetProfile(c.Replace("#", ""));
                string userdb     = string.Format("{0}\\users.xml");
                XDocument xDoc    = XDocument.Load(userdb);
                i.SendNotice(n, string.Format("Please see {0} or a mod for assistance.", streamer.name));

                #region depcode WORK ON THIS

                Dictionary <string, Func <int> > subcmd = new Dictionary <string, Func <int> > ( );

                subcmd.Add("streamer", () =>
                {
                    Dictionary <string, Func <int> > subsubcmd = new Dictionary <string, Func <int> > ( );

                    subsubcmd.Add("register", new Func <int> (() =>
                    {
                        string channel = c.Replace("#", "");
                        string botnick = Streamer.GetProfile(i.Nick).name;
                        if (p <= Permissions.Administrator && channel.Equals(botnick))
                        {
                            string nc = o[3] as string;
                            Streamer.CreateProfile(nc);
                            i.GetChannel(c).SendMessage(string.Format("Streamer \"{0}\" has registered!", nc));
                            i.Join(string.Format("#{0}", nc));
                        }
                        else
                        {
                            i.GetChannel(c).SendMessage(string.Format("{0}, I can only register streamers on my profile and with the approval of an Administrator", n));
                        }
                        return(0);
                    }));

                    subsubcmd[o[2] as string].Invoke( );

                    return(0);
                });

                subcmd.Add("register", () =>
                {
                    string uname = ((o.Length > 1 ? (string.IsNullOrEmpty(o[1] as string) ? n : o[1] as string) : n));
                    Irc.Format("<Accounts> Formatting and adding {0}", ConsoleColor.Green, uname);

                    User u = chan.Streamer.users.Single((U) =>
                    {
                        bool b = (U.name == uname);

                        if (b)
                        {
                            chan.SendMessage(string.Format("{0} is already registered! "));
                        }

                        return(b);
                    });

                    XAttribute xName = new XAttribute("name", o.Length > 1 ? o[1] as string : n);
                    XAttribute xPerm = new XAttribute("permission", (p <= Permissions.Root ?
                                                                     (o.Length > 2 ?
                                                                      Enum.GetName(typeof(Permissions), o[2] as string)
                            : Enum.GetName(typeof(Permissions), Permissions.User))
                        : Enum.GetName(typeof(Permissions), Permissions.User)));
                    XAttribute xBanned = new XAttribute("banned", false);

                    //XAttribute xToken = new XAttribute ( "token",
                    //    Token.Generate ( xName.Value, c, ( Permissions ) Enum.Parse ( typeof ( Permissions ), xPerm.Value ) ).TokenData );
                    XElement xUser = new XElement("User");
                    xUser.Add(xName, xPerm, xBanned);   //, xToken );

                    XElement xUsers = xDoc.Element("Users");
                    xUsers.Add(xUser);

                    xDoc.Save(userdb);
                    i.GetChannel(c).SendMessage(string.Format("Welcome {0}!", uname));

                    return(0);
                });

                subcmd.Add("ban", () =>
                {
                    if (p <= Permissions.Operator)
                    {
                        XElement xel = xDoc.Descendants("Users")
                                       .Descendants("User")
                                       .Where((x) => x.Attribute("name")
                                              .Value == o[1] as string).FirstOrDefault( );

                        xel.SetAttributeValue("banned", true);

                        xDoc.Save(userdb);
                    }
                    return(0);
                });

                subcmd.Add("unban", () =>
                {
                    if (p <= Permissions.Operator)
                    {
                        XElement xel = xDoc.Descendants("Users")
                                       .Descendants("User")
                                       .Where((x) => x.Attribute("name")
                                              .Value == o[1] as string).FirstOrDefault( );

                        xel.SetAttributeValue("banned", false);

                        xDoc.Save(userdb);
                    }
                    return(0);
                });

                // 0 1 2 promote user permission
                subcmd.Add("promote", () =>
                {
                    Dictionary <string, Func <int> > perms = new Dictionary <string, Func <int> > ( );
                    XElement xel = xDoc.Descendants("Users")
                                   .Descendants("User")
                                   .Where((x) => x.Attribute("name")
                                          .Value == o[1] as string).FirstOrDefault( );
                    perms.Add("administrator", new Func <int> (() =>
                    {
                        if (p == Permissions.Root)
                        {
                            xel.SetAttributeValue("permission", Permissions.Administrator);

                            xDoc.Save(userdb);
                        }
                        else
                        {
                            i.SendMessage(n, "I'm sorry, Only Root Users can set Admin on other users.");
                        }
                        return(0);
                    }));

                    perms.Add("operator", new Func <int> (() =>
                    {
                        if (p <= Permissions.Administrator)
                        {
                            xDoc.Descendants("Users")
                            .Descendants("User")
                            .Where((x) => x.Attribute("name")
                                   .Value == o[1] as string).FirstOrDefault( );

                            xel.SetAttributeValue("permission", Permissions.Operator);

                            xDoc.Save(userdb);
                        }
                        else
                        {
                            i.SendMessage(n, "I'm sorry, Only Administrative Users can set Operator on other users.");
                        }

                        return(0);
                    }));

                    try
                    {
                        if (p <= Permissions.Administrator)
                        {
                            perms[o[2] as string].Invoke( );
                        }
                    }
                    catch (Exception)
                    {
                        i.SendNotice(n, "+acc promote <user> <permission>");
                    }
                    return(0);
                });

                subcmd.Add("demote", () =>
                {
                    if (p <= Permissions.Administrator)
                    {
                        XElement xel = xDoc.Descendants("Users")
                                       .Descendants("User")
                                       .Where((x) => x.Attribute("name")
                                              .Value == o[1] as string).FirstOrDefault( );
                        Permissions perm = ( Permissions )Enum.Parse(typeof(Permissions), xel.Attribute("permission").Value);

                        // We check to see if an Administrator is trying to revoke Administrator or
                        // Root. If Administrator < Operator <-- TRUE If Administrator <
                        // Administrator <-- FALSE If Administrator < Root <-- FALSE If Root < Root
                        // <-- FALSE

                        if (xel.Attribute("name").Value == i.Owner)
                        {
                            i.SendNotice(n, string.Format("God-Mode: De-Ranking {0}", xel.Attribute("name").Value));
                            xel.SetAttributeValue("permission", Permissions.User);
                        }
                        else if (p < perm)
                        {
                            xel.SetAttributeValue("permission", Permissions.User);
                        }
                        else
                        {
                            i.SendNotice(n, "You cannot De-Rank either yourself, a higher user, or someone on the same rank as yourself.");
                        }

                        xDoc.Save(streamer.config);
                    }
                    return(0);
                });

                subcmd.Add("bye", () =>
                {
                    XElement xel = o.Length < 2 ? User.GetUserXmlProfile(n) : (p <= Scripts.Permissions.Administrator ? User.GetUserXmlProfile(o[1] as string) : User.GetUserXmlProfile(n, true, i));
                    string name  = xel.Attribute("name").Value;

                    Irc.Format("Selected {0}!", ConsoleColor.DarkGreen, name);

                    if (p <= Permissions.Administrator)
                    {
                        i.GetChannel(c).SendMessage(string.Format("Account {0} has been deregistered by an Administrator!", name));
                    }
                    else
                    {
                        i.GetChannel(c).SendMessage(string.Format("Sorry to see you go {0}! :(", name));
                    }

                    xel.Remove( );

                    xDoc.Save(userdb);

                    return(0);
                });

                try
                {
                    if (System.IO.File.Exists(userdb))
                    {
                        try
                        {
                            subcmd[o[0] as string].Invoke( );
                        }
                        catch (Exception ex)
                        {
                            i.SendMessage(c, "Invalid command");
                        }
                    }
                    else
                    {
                        i.GetChannel(c).SendMessage(string.Format("There is no Database. Use +createdb to send an Access code to {0} for a new File.", i.Owner));
                    }
                }
                catch (Exception ex)
                {
                    i.GetChannel(c).SendMessage(ex.Message);
                    Console.WriteLine(ex);
                }

                #endregion depcode WORK ON THIS

                return(0);
            });

            #endregion account

            #region part

            AddCommand("part", (i, c, n, o) =>
            {
                Permissions p = User.GetUserProfile(n).GetPermission( );
                if (p <= Permissions.Administrator)
                {
                    string[] format = o as string[];
                    string channel  = format[0];
                    i.Part(channel, string.Join(" ", format, 1, format.Length - 1));
                }
                else
                {
                    i.GetChannel(c).SendMessage(SpecialMessage(n));
                }
                return(0);
            });

            #endregion part

            #region quit

            AddCommand("quit", (i, c, n, o) =>
            {
                Permissions p = User.GetUserProfile(n).GetPermission( );
                if (p <= Permissions.Administrator)
                {
                    i.Disconnect(string.Join(" ", o as string[]));
                }
                else
                {
                    i.GetChannel(c).SendMessage(SpecialMessage(n));
                }
                return(0);
            });

            #endregion quit

            #region raw

            AddCommand("raw", (i, c, n, o) =>
            {
                Permissions p = User.GetUserProfile(n).GetPermission( );
                if (p <= Permissions.Root)
                {
                    i.Raw(string.Join(" ", o));
                }
                else
                {
                    SendMessage(i, c, n, SpecialMessage(n));
                }
                return(0);
            });

            #endregion raw

            #region reboot

            AddCommand("reboot", (i, c, n, o) =>
            {
                Permissions p = User.GetUserProfile(n).GetPermission( );

                if (p <= Permissions.Administrator)
                {
                    System.Diagnostics.Process pr = new System.Diagnostics.Process( )
                    {
                        StartInfo = new System.Diagnostics.ProcessStartInfo( )
                        {
                            FileName = System.Reflection.Assembly.GetExecutingAssembly( ).GetName( ).Name + ".exe"
                        }
                    };
                    i.Disconnect("Rebooting!");
                    pr.Start( );
                    Environment.Exit(0);
                }
                else
                {
                    i.SendMessage(n, "You may not reboot me. Only an Administrator or the Owner may do so.");
                }
                return(0);
            });

            #endregion reboot

            #region say

            AddCommand("say", (i, c, n, o) =>
            {
                Permissions p = User.GetUserProfile(n).GetPermission( );
                if (p <= Permissions.User)
                {
                    if (!ignoreSay)
                    {
                        SendMessage(i, c, n, string.Join(" ", o as string[]));
                    }
                }
                else
                {
                    SendMessage(i, c, n, SpecialMessage(n));
                }

                return(0);
            });

            #endregion say

            #region Uptime

            AddCommand("uptime", (i, c, n, o) =>
            {
                i.GetChannel(c).SendMessage(string.Format("I have been online for {0}", Global.FormatUptime( )));
                return(0);
            });

            #endregion Uptime

            #region version

            AddCommand("version", (i, c, n, o) =>
            {
                // No Permissions needed
                Dictionary <string, Func <int> > arguments = new Dictionary <string, Func <int> > ( );
                arguments.Add("core", new Func <int> (() =>
                {
                    i.GetChannel(c).SendMessage(string.Format("{0}; Core Version {1}", Global.Title, Global.Core));
                    return(0);
                }));

                arguments.Add("scripts", new Func <int> (() =>
                {
                    i.GetChannel(c).SendMessage(string.Format("{0}; Scripts Version {1}", Global.Title, Global.Scripts));
                    return(0);
                }));

                try
                {
                    arguments[o[0] as string].Invoke( );
                }
                catch
                {
                    i.GetChannel(c).SendMessage(string.Format("{0}; For more information, see \"core\" and \"scripts\"", Global.Title));
                }
                return(0);
            });

            #endregion version
        }
Exemplo n.º 19
0
        public void Save( Irc irc )
        {
            IConfig server = null; ;
            string host = irc.Host;
            string nick = irc.Nick;
            string user = irc.Username;
            string real = irc.Realname;
            int port = irc.Port;
            string owner = irc.Owner;
            string nspass = irc.NickPass;
            string srvpass = irc.ServerPass;
            Stack<ChannelData> buffer = irc.ChannelBuffer;

            if ( !string.IsNullOrEmpty ( nspass ) )
                nspass = new SymCryptography ( SymCryptography.ServiceProviderEnum.Rijndael ).Encrypt ( nspass );

            // Last known code
            RFC1459.ReplyCode lkc = irc.Code;
            ConsoleColor colour = irc.Colour;
            if ( config.Configs[ irc.Server ] == null )
                server = config.AddConfig ( irc.Server );
            else
                server = config.Configs[ irc.Server ];

            server.Set ( "Host", host );
            server.Set ( "Port", port );
            server.Set ( "Nick", nick );
            server.Set ( "Server_Password", srvpass );
            server.Set ( "Username", user );
            server.Set ( "Realname", real );
            server.Set ( "NickPassword", nspass );
            server.Set ( "Owner", owner );
            server.Set ( "LastKnownCode", ( int ) lkc );
            server.Set ( "Colour", ( int ) colour );
            server.Set ( "MainChannel", "{nokey}" );
            server.Set ( "MainKey", "{nokey}" );

            if ( buffer.Count > 0 )
                server.Set ( "Channels", string.Join ( ",", buffer.ToArray ( ) ) );

            config.Save ( );
        }
Exemplo n.º 20
0
        public Irc Read( string server )
        {
            Irc _irc;
            string host, nick, password, srvPass, owner, user, real, channel, key, additional;
            int port;
            ConsoleColor colour;
            RFC1459.ReplyCode lkc;
            IConfig irc = config.Configs[ server ];

            nick = irc.GetString ( "Nick" );
            real = irc.GetString ( "Realname" );
            user = irc.GetString ( "Username" );
            host = irc.GetString ( "Host" );
            srvPass = irc.GetString ( "Server_Password" );
            port = irc.GetInt ( "Port" );
            owner = irc.GetString ( "Owner" );
            password = irc.GetString ( "NickPassword" );
            if ( !string.IsNullOrEmpty ( password ) )
                password = new SymCryptography ( SymCryptography.ServiceProviderEnum.Rijndael ).Decrypt ( password );
            lkc = ( RFC1459.ReplyCode ) irc.GetInt ( "LastKnownCode" );
            colour = ( ConsoleColor ) irc.GetInt ( "Colour" );
            channel = irc.GetString ( "MainChannel" );
            key = irc.GetString ( "MainKey" );
            additional = irc.GetString ( "Channels" );

            Stack<ChannelData> chanBuffer = new Stack<ChannelData> ( );

            foreach ( string ch in additional.Split ( ',' ) )
            {
                string[] chankey = ch.Split ( ':' );
                chanBuffer.Push ( new ChannelData ( ) { Channel = chankey[ 0 ], Key = chankey[ 1 ] } );
            }

            _irc = new Irc ( nick, real, user, password, host, "", port, lkc, colour, channel, key );
            _irc.ChannelBuffer = chanBuffer;

            return _irc;
        }
Exemplo n.º 21
0
        private static void Main ( string[] args )
        {
            if ( !SanityCheck ( ) )
            {
                Console.WriteLine ( "The bot has failed to complete its sanity check...\r\nPlease press any key to exit the Bot..." );
                Console.ReadKey ( true );
                return;
            }

            // Start the timer on ground zero 
            global::BlizzetaZero.Kernel.Global.BeginUptime ( );

            // Auth.Authenticate(); Thread t = new Thread ( new ThreadStart ( LaunchGamePanel ) );
            // t.Start ( );
            Console.Title = Global.Title;
            Console.WindowWidth += 60;

            _settings = new Settings ( );
            CoreCommands.IncludeBuiltInCommands ( );
            SetCharSet ( );
            CarpeDiem ( );

            Irc irc = new Irc ( Global.Nick,
                Global.Realname,
                Global.Username,
                "",
                Global.IrcServer,
                Global.ServerPassword,
                Global.Port,
                RFC1459.ReplyCode.ERR_UNKNOWNMODE,
                ConsoleColor.Green,
                "#blizzardothegreat",
                "",
                "blizzardothegreat",
                "#blizzetabot",
                "" );
            try
            {
                irc.OnMotd += irc_OnMotd;
                irc.Connect ( irc.Host );
            }
            catch ( Exception e )
            {
                Console.WriteLine ( e.Message );
            }
        }
Exemplo n.º 22
0
        public static WhoInfo GetUser( Irc server, string nick )
        {
            bool gotWho = false;
            WhoInfo wi = null;
            server.Writer.SendMessage ( RFC1459.IrcCommands.Who ( nick, false ) );
            while ( !gotWho )
            {
                RFC1459.ReplyCode code;
                string message, prefix, command;
                string[] parameters;

                message = server.Reader.ReadLine ( );
                RFC1459.IrcCommands.ParseReply ( message, out prefix, out command, out parameters );
                if ( Enum.TryParse<RFC1459.ReplyCode> ( command, out code ) )
                    switch ( code )
                    {
                        case RFC1459.ReplyCode.RPL_WHOREPLY:
                            wi = WhoInfo.Parse ( new IrcMessage ( prefix, command, parameters ) );
                            break;

                        case RFC1459.ReplyCode.RPL_ENDOFWHO:
                            gotWho = true;
                            break;
                    }
            }
            return wi;
        }
        public static XElement GetUserXmlProfile( string name, bool falseAdmin = false, Irc i = null )
        {
            XDocument xdc = xDoc;
            XElement xel = xdc.Descendants ( "Users" ).Descendants ( "User" ).Where ( ( x ) => x.Attribute ( "name" ).Value == name ).FirstOrDefault ( );

            if ( falseAdmin )
                i.SendMessage ( name, "You do not have permission to manipulate another user, only yourself." );

            return xel;
        }