Example #1
0
        public void Configure(Core.ServerQueryConnection.Models.Subscribers subscriber, Core.ServerQueryConnection.ServerQueryConnection ServerQueryConnection)
        {
            this.Subscriber = subscriber;

            //dependencyManager = new AddonDependencyManager(this.Subscriber);

            this.ServerQueryConnection = ServerQueryConnection;
        }
Example #2
0
        public void UserInitialize(Bot.ComponentList ComponentList)
        {
            // Hello
            this.Name = this.GetType().Name;
            ModelCustomizer.AddModelCustomization(Hooks.ModelCustomizer.OnModelCreating);

            this.ServerQueryConnection = ComponentList[typeof(Core.ServerQueryConnection.ServerQueryConnection).Name] as Core.ServerQueryConnection.ServerQueryConnection;
            this.ServerQueryAddon      = ComponentList[typeof(Core.ServerQueryShell.ServerQueryShell).Name] as Core.ServerQueryShell.ServerQueryShell;
            this.testAddon             = ComponentList[typeof(TestAddon).Name] as TestAddon;

            // Native serverquery events are in queryRunner object.
            this.ServerQueryConnection.BotCommandAttempt += ServerQueryConnection_BotCommandReceived;
            this.ServerQueryConnection.QueryRunner.Notifications.ClientMoved += Notifications_ClientMoved;
        }
Example #3
0
        public void UserInitialize(Bot.ComponentList ComponentList)
        {
            // Hello
            this.Name = this.GetType().Name;
            ModelCustomizer.AddModelCustomization(Hooks.ModelCustomizer.OnModelCreating);

            this.ServerQueryConnection = ComponentList[typeof(Core.ServerQueryConnection.ServerQueryConnection).Name] as Core.ServerQueryConnection.ServerQueryConnection;
            this.testAddon             = ComponentList[typeof(TestAddon.TestAddon).Name] as TestAddon.TestAddon;

            // Native serverquery events are in queryRunner object.
            this.ServerQueryConnection.QueryRunner.Notifications.ClientMoved  += Notifications_ClientMoved;
            this.ServerQueryConnection.QueryRunner.Notifications.ClientJoined += onClientConnect;

            BotHasReturnedMessage(); //Tell everyone you're back
        }
Example #4
0
        private string SendServerQueryCommand(Command cmd, Models.ServerQueryUser user)
        {
            Lyralei.Core.ServerQueryConnection.Models.Subscribers subscriberUserCredentials = new Lyralei.Core.ServerQueryConnection.Models.Subscribers()
            {
                AdminPassword      = user.ServerQueryPassword,
                AdminUsername      = user.ServerQueryUsername,
                ServerIp           = Subscriber.ServerIp,
                ServerPort         = Subscriber.ServerPort,
                SubscriberId       = Subscriber.SubscriberId,
                SubscriberUniqueId = Subscriber.SubscriberUniqueId,
                VirtualServerId    = Subscriber.VirtualServerId,
            };

            using (Core.ServerQueryConnection.ServerQueryConnection ServerQueryConnection = new Core.ServerQueryConnection.ServerQueryConnection(subscriberUserCredentials))
            {
                Thread thread = new Thread((ThreadStart) new SynchronizationCallback(ServerQueryConnection.InitializeQuiet));
                thread.Start();
                thread.Join();

                var result = ServerQueryConnection.QueryRunner.SendCommand(cmd);

                return(result);
            }
        }
Example #5
0
        public void ServerQueryUserRegistrationCommand(BotCommandEventArgs e)
        {
            using (var db = new CoreContext())
            {
                var user = UserManager.QueryUser(Subscriber.SubscriberId, Subscriber.SubscriberUniqueId, e.MessageInfo.InvokerUniqueId);

                Models.ServerQueryUser sqUser = new Models.ServerQueryUser()
                {
                    UserId = user.UserId,
                    Users  = user,
                    //SubscriberId = user.SubscriberId,
                    ServerQueryUsername = e.CommandInfo["username"].Value,
                    ServerQueryPassword = e.CommandInfo["password"].Value,
                };

                Lyralei.Core.ServerQueryConnection.Models.Subscribers subscriberUserCredentials = new Lyralei.Core.ServerQueryConnection.Models.Subscribers()
                {
                    AdminPassword      = sqUser.ServerQueryPassword,
                    AdminUsername      = sqUser.ServerQueryUsername,
                    ServerIp           = Subscriber.ServerIp,
                    ServerPort         = Subscriber.ServerPort,
                    SubscriberId       = Subscriber.SubscriberId,
                    SubscriberUniqueId = Subscriber.SubscriberUniqueId,
                    VirtualServerId    = Subscriber.VirtualServerId,
                };

                Core.ServerQueryConnection.ServerQueryConnection ServerQueryConnection = new Core.ServerQueryConnection.ServerQueryConnection(subscriberUserCredentials);

                Thread thread = new Thread((ThreadStart) new SynchronizationCallback(ServerQueryConnection.InitializeQuiet));
                thread.Start();
                thread.Join();

                try
                {
                    if (ServerQueryConnection.AsyncTcpDispatcher.IsConnected)
                    {
                        var test = ServerQueryConnection.whoAmI;

                        if (test == null)
                        {
                            throw new Exception("Login failure");
                        }
                        if (test.IsErroneous)
                        {
                            throw new Exception(test.ResponseText);
                        }
                        else
                        {
                            db.ServerQueryUser.Add(sqUser);
                            db.SaveChanges();

                            ServerQueryConnection.Logout();
                            ServerQueryConnection.Disconnect();

                            //User successfully registered
                            ServerQueryConnection.TextReply(e.MessageInfo, "Successfully registered! You can now execute serverquery commands directly to me based on your user permissions.");
                        }
                    }
                }
                catch (Exception ex)
                {
                    logger.Debug(ex, "User failed to register");
                    ServerQueryConnection.TextReply(e.MessageInfo, "Whoops! Did you put in the right details?");
                }
            }
        }
Example #6
0
        private void onBotCommand(object sender, CommandParameterGroup cmdPG, MessageReceivedEventArgs e)
        {
            //Command cmd = new Command("help", new string[] { "serverinfo", "additionaltest" });
            Command cmd = new Command(cmdPG);

            //userManager.GetUserInformation

            if (cmd.Name.ToLower() == "serverquery")
            {
                try
                {
                    if (cmdPG.Exists(cmdP => cmdP.Name.ToLower() == "action" && cmdP.Value.ToLower() == "register"))
                    {
                        CommandParameter Username = null;
                        CommandParameter Password = null;

                        if (cmdPG.Exists(cmdP => (Username = cmdP).Name.ToLower() == "username") && cmdPG.Exists(cmdP => (Password = cmdP).Name.ToLower() == "password"))
                        {
                            using (var db = new CoreContext())
                            {
                                var user = UserManager.QueryUser(Subscriber.SubscriberId, Subscriber.SubscriberUniqueId, e.InvokerUniqueId);

                                Models.ServerQueryUser sqUser = new Models.ServerQueryUser()
                                {
                                    UserId = user.UserId,
                                    Users  = user,
                                    //SubscriberId = user.SubscriberId,
                                    ServerQueryUsername = Username.Value,
                                    ServerQueryPassword = Password.Value,
                                };

                                Lyralei.Core.ServerQueryConnection.Models.Subscribers subscriberUserCredentials = new Lyralei.Core.ServerQueryConnection.Models.Subscribers()
                                {
                                    AdminPassword      = sqUser.ServerQueryPassword,
                                    AdminUsername      = sqUser.ServerQueryUsername,
                                    ServerIp           = Subscriber.ServerIp,
                                    ServerPort         = Subscriber.ServerPort,
                                    SubscriberId       = Subscriber.SubscriberId,
                                    SubscriberUniqueId = Subscriber.SubscriberUniqueId,
                                    VirtualServerId    = Subscriber.VirtualServerId,
                                };

                                Core.ServerQueryConnection.ServerQueryConnection ServerQueryConnection = new Core.ServerQueryConnection.ServerQueryConnection(subscriberUserCredentials);

                                Thread thread = new Thread((ThreadStart) new SynchronizationCallback(ServerQueryConnection.InitializeQuiet));
                                thread.Start();

                                thread.Join();

                                //do
                                //{
                                //    Thread.Sleep(5);
                                //} while (t.ThreadState == ThreadState.Running);

                                try
                                {
                                    if (ServerQueryConnection.AsyncTcpDispatcher.IsConnected)
                                    {
                                        var test = ServerQueryConnection.whoAmI;

                                        if (test == null)
                                        {
                                            throw new Exception("Login failed");
                                        }
                                        if (test.IsErroneous)
                                        {
                                            throw new Exception(test.ResponseText);
                                        }
                                        else
                                        {
                                            db.ServerQueryUser.Add(sqUser);
                                            db.SaveChanges();

                                            ServerQueryConnection.QueryRunner.Logout();
                                            ServerQueryConnection.AsyncTcpDispatcher.Disconnect();

                                            //User successfully registered
                                            ServerQueryConnection.TextReply(e, "Successfully registered! You can now execute serverquery commands directly to me based on your user permissions.");
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    throw ex;
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    logger.Debug(ex, "User sent invalid command: {0}");

                    ServerQueryConnection.TextReply(e, "Error, please check your command and try again.");
                }
            }

            foreach (CommandName cmdName in Enum.GetValues(typeof(CommandName)))
            {
                if (cmdName.ToString().ToLower() == cmd.Name.ToLower())
                {
                    Models.ServerQueryUser serverQueryUser = null;

                    try
                    {
                        using (var db = new CoreContext())
                        {
                            //user = userManager.GetUser(e.InvokerUniqueId);
                            var User = db.Users.Single(usr => usr.UserTeamSpeakClientUniqueId == e.InvokerUniqueId && usr.SubscriberUniqueId == Subscriber.SubscriberUniqueId);
                            serverQueryUser = db.ServerQueryUser.Single(sqUser => sqUser.Users.UserId == User.UserId);
                        }
                    }
                    catch (Exception ex) when(ex.Message == "Sequence contains no elements")
                    {
                        ServerQueryConnection.TextReply(e, "You do not have access to this command.");
                        return;
                    }
                    catch (Exception)
                    {
                        ServerQueryConnection.TextReply(e, "There was an error performing this command.");
                        return;
                    }

                    try
                    {
                        string result = SendServerQueryCommand(cmd, serverQueryUser);

                        //string result = SendServerQueryCommand(cmd, serverQueryUser);
                        this.ServerQueryConnection.QueryRunner.SendTextMessage(MessageTarget.Client, e.InvokerClientId, result);
                    }
                    catch (Exception)
                    {
                        ServerQueryConnection.TextReply(e, "There was an error performing this command, or you lacked permissions.");
                        return;
                    }

                    break;
                }
            }
        }
Example #7
0
        public void UserInitialize(AddonInjections CoreList)
        {
            this.ServerQueryConnection = CoreList[typeof(ServerQueryConnection.ServerQueryConnection).Name] as ServerQueryConnection.ServerQueryConnection;

            ServerQueryConnection.BotCommandAttempt += onBotCommandAttempt;

            // Hard-coded for now..
            //addons.Add(new Core.InputOwner.InputOwnerAddon());
            //addons.Add(new Core.Test.TestAddon());
            //addons.Add(new Core.ServerQuery.ServerQueryAddon());

            List <IAddon> failedAddons = new List <IAddon>();

            // Configure each addon with the basic stuff
            for (int addonIndex = 0; addonIndex < addons.Count; addonIndex++)
            {
                try
                {
                    addons[addonIndex].Configure(this.Subscriber, this.ServerQueryConnection);
                }
                catch (Exception)
                {
                    logger.Error("Removing addon {0}: failed to load during configuration", addons[addonIndex].CoreName);
                    addons.RemoveAt(addonIndex);
                }
            }

            // Wire up any injection requests by the addons to addon manager
            foreach (IAddon addon in addons)
            {
                addon.InjectionRequest += onInjectionRequest;
            }

            // Initialize each addon
            for (int addonIndex = 0; addonIndex < addons.Count; addonIndex++)
            {
                try
                {
                    addons[addonIndex].Initialize();
                }
                catch (Exception ex)
                {
                    logger.Error(ex, "Removing addon {0}: failed to load during initialization", addons[addonIndex].CoreName);
                    addons.RemoveAt(addonIndex);
                }
            }

            // Let addons define their dependencies
            for (int addonIndex = 0; addonIndex < addons.Count; addonIndex++)
            {
                try
                {
                    addons[addonIndex].DefineDependencies();
                }
                catch (Exception ex)
                {
                    logger.Error(ex, "Removing addon {0}: failed to load during dependency definitions", addons[addonIndex].CoreName);
                    addons.RemoveAt(addonIndex);
                }
            }

            // Initialize the dependencies
            for (int addonIndex = 0; addonIndex < addons.Count; addonIndex++)
            {
                try
                {
                    addons[addonIndex].InitializeDependencies();
                }
                catch (Exception ex)
                {
                    logger.Error(ex, "Removing addon {0}: failed to load during dependency initialization", addons[addonIndex].CoreName);
                    addons.RemoveAt(addonIndex);
                }
            }

            // Get command schemas from addons
            for (int addonIndex = 0; addonIndex < addons.Count; addonIndex++)
            {
                try
                {
                    CommandRuleSets cmds = addons[addonIndex].DefineCommandSchemas();

                    if (cmds != null)
                    {
                        foreach (var cmd in cmds)
                        {
                            commands.ValidateAddSchema(cmd);
                        }
                    }
                }
                catch (Exception ex)
                {
                    logger.Warn(ex, "addon {0}: Could not load command schemas", addons[addonIndex].CoreName);
                }
            }
        }