Inheritance: Terraria.Plugins.Common.DatabaseHandlerBase
Ejemplo n.º 1
0
        private bool InitServerMetdataHandler()
        {
            this.serverMetadataHandler = new ServerMetadataHandler(ProtectorPlugin.SqlLiteDatabaseFile);

            try {
                this.ServerMetadataHandler.EstablishConnection();
            } catch (Exception ex) {
                this.Trace.WriteLineError(
                    "An error occured while opening the database connection. This plugin will be disabled. Exception details: \n" + ex
                    );
                this.Trace.WriteLineError("THIS PLUGIN IS DISABLED, EVERYTHING IS UNPROTECTED!");

                this.Dispose();
                return(false);
            }

            try {
                this.serverMetadataHandler.EnsureDataStructure();
            } catch (Exception ex) {
                this.Trace.WriteLineError(
                    "An error occured while ensuring the database structure. This plugin will be disabled. Exception details: \n" + ex
                    );
                this.Trace.WriteLineError("THIS PLUGIN IS DISABLED, EVERYTHING IS UNPROTECTED!");

                this.Dispose();
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
 public ProtectionManager(
     PluginTrace pluginTrace, Configuration config, ChestManager chestManager, ServerMetadataHandler serverMetadataHandler, WorldMetadata worldMetadata
     )
 {
     this.PluginTrace = pluginTrace;
       this.config = config;
       this.ChestManager = chestManager;
       this.ServerMetadataHandler = serverMetadataHandler;
       this.WorldMetadata = worldMetadata;
 }
Ejemplo n.º 3
0
        public ProtectionManager(
            PluginTrace pluginTrace, Configuration config, ServerMetadataHandler serverMetadataHandler, WorldMetadata worldMetadata
            )
        {
            this.PluginTrace = pluginTrace;
              this.config = config;
              this.ServerMetadataHandler = serverMetadataHandler;
              this.WorldMetadata = worldMetadata;

              this.RefillTimers = new TimerManager(pluginTrace);
              this.RefillTimerCallbackHandler = this.RefillChestTimer_Callback;
        }
Ejemplo n.º 4
0
        public ChestManager(
            PluginTrace pluginTrace, Configuration config, ServerMetadataHandler serverMetadataHandler, WorldMetadata worldMetadata
            )
        {
            this.PluginTrace           = pluginTrace;
            this.config                = config;
            this.ServerMetadataHandler = serverMetadataHandler;
            this.WorldMetadata         = worldMetadata;

            this.RefillTimers = new TimerManager(pluginTrace);
            this.RefillTimerCallbackHandler = this.RefillChestTimer_Callback;
        }
 public ProtectionManager(
     PluginTrace pluginTrace, Configuration config, ChestManager chestManager, ServerMetadataHandler serverMetadataHandler, WorldMetadata worldMetadata
     )
 {
     this.PluginTrace           = pluginTrace;
     this.config                = config;
     this.ChestManager          = chestManager;
     this.ServerMetadataHandler = serverMetadataHandler;
     this.WorldMetadata         = worldMetadata;
 }
        public UserInteractionHandler(
            PluginTrace trace, PluginInfo pluginInfo, Configuration config, ServerMetadataHandler serverMetadataHandler,
            WorldMetadata worldMetadata, ProtectionManager protectionManager, ChestManager chestManager,
            PluginCooperationHandler pluginCooperationHandler, Func<Configuration> reloadConfigurationCallback
            )
            : base(trace)
        {
            Contract.Requires<ArgumentNullException>(trace != null);
              Contract.Requires<ArgumentException>(!pluginInfo.Equals(PluginInfo.Empty));
              Contract.Requires<ArgumentNullException>(config != null);
              Contract.Requires<ArgumentNullException>(serverMetadataHandler != null);
              Contract.Requires<ArgumentNullException>(worldMetadata != null);
              Contract.Requires<ArgumentNullException>(protectionManager != null);
              Contract.Requires<ArgumentNullException>(pluginCooperationHandler != null);
              Contract.Requires<ArgumentNullException>(reloadConfigurationCallback != null);

              this.PluginInfo = pluginInfo;
              this.Config = config;
              this.ServerMetadataHandler = serverMetadataHandler;
              this.WorldMetadata = worldMetadata;
              this.ChestManager = chestManager;
              this.ProtectionManager = protectionManager;
              this.PluginCooperationHandler = pluginCooperationHandler;
              this.ReloadConfigurationCallback = reloadConfigurationCallback;

              this.PlayerIndexChestDictionary = new Dictionary<int,DPoint>(20);
              this.ChestPlayerIndexDictionary = new Dictionary<DPoint,int>(20);

              #region Command Setup
              base.RegisterCommand(
            new[] { "protector" }, this.RootCommand_Exec, this.RootCommand_HelpCallback
              );
              base.RegisterCommand(
            new[] { "protect", "pt" },
            this.ProtectCommand_Exec, this.ProtectCommand_HelpCallback, ProtectorPlugin.ManualProtect_Permission,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "deprotect", "dp" },
            this.DeprotectCommand_Exec, this.DeprotectCommand_HelpCallback, ProtectorPlugin.ManualDeprotect_Permission,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "protectioninfo", "ptinfo", "pi" }, this.ProtectionInfoCommand_Exec, this.ProtectionInfoCommand_HelpCallback,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "share" }, this.ShareCommand_Exec, this.ShareCommandHelpCallback,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "unshare" }, this.UnshareCommand_Exec, this.UnshareCommand_HelpCallback,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "sharepublic" }, this.SharePublicCommand_Exec, this.SharePublicCommandHelpCallback,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "unsharepublic" }, this.UnsharePublicCommand_Exec, this.UnsharePublicCommand_HelpCallback,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "sharegroup" }, this.ShareGroupCommand_Exec, this.ShareGroupCommand_HelpCallback,
            ProtectorPlugin.ShareWithGroups_Permission,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "unsharegroup" }, this.UnshareGroupCommand_Exec, this.UnshareGroup_HelpCallback,
            ProtectorPlugin.ShareWithGroups_Permission,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "lockchest", "lchest" },
            this.LockChestCommand_Exec, this.LockChestCommand_HelpCallback, ProtectorPlugin.Utility_Permission,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "swapchest", "schest" },
            this.SwapChestCommand_Exec, this.SwapChestCommand_HelpCallback, ProtectorPlugin.Utility_Permission,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "refillchest", "rchest" },
            this.RefillChestCommand_Exec, this.RefillChestCommand_HelpCallback, ProtectorPlugin.SetRefillChests_Permission,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "refillchestmany", "rchestmany" },
            this.RefillChestManyCommand_Exec, this.RefillChestManyCommand_HelpCallback, ProtectorPlugin.Utility_Permission
              );
              base.RegisterCommand(
            new[] { "bankchest", "bchest" },
            this.BankChestCommand_Exec, this.BankChestCommand_HelpCallback, ProtectorPlugin.SetBankChests_Permission,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "dumpbankchest", "dbchest" },
            this.DumpBankChestCommand_Exec, this.DumpBankChestCommand_HelpCallback, ProtectorPlugin.DumpBankChests_Permission,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "tradechest", "tchest" },
            this.TradeChestCommand_Exec, this.TradeChestCommand_HelpCallback, ProtectorPlugin.SetTradeChests_Permission,
            allowServer: false
              );
              #endregion

              #if DEBUG
              base.RegisterCommand(new[] { "fc" }, args => {
            for (int i= 0; i < Main.chest.Length; i++) {
              if (i != ChestManager.DummyChestIndex)
            Main.chest[i] = Main.chest[i] ?? new Chest();
            }
              }, requiredPermission: Permissions.maintenance);
              base.RegisterCommand(new[] { "fcnames" }, args => {
            for (int i= 0; i < Main.chest.Length; i++) {
              if (i != ChestManager.DummyChestIndex) {
            Main.chest[i] = Main.chest[i] ?? new Chest();
            Main.chest[i].name = "Chest!";
              }
            }
              }, requiredPermission: Permissions.maintenance);
              #endif
        }
        public UserInteractionHandler(
            PluginTrace trace, PluginInfo pluginInfo, Configuration config, ServerMetadataHandler serverMetadataHandler,
            WorldMetadata worldMetadata, ProtectionManager protectionManager, PluginCooperationHandler pluginCooperationHandler,
            Func<Configuration> reloadConfigurationCallback
            )
            : base(trace)
        {
            Contract.Requires<ArgumentNullException>(trace != null);
              Contract.Requires<ArgumentException>(!pluginInfo.Equals(PluginInfo.Empty));
              Contract.Requires<ArgumentNullException>(config != null);
              Contract.Requires<ArgumentNullException>(serverMetadataHandler != null);
              Contract.Requires<ArgumentNullException>(worldMetadata != null);
              Contract.Requires<ArgumentNullException>(protectionManager != null);
              Contract.Requires<ArgumentNullException>(pluginCooperationHandler != null);
              Contract.Requires<ArgumentNullException>(reloadConfigurationCallback != null);

              this.PluginInfo = pluginInfo;
              this.Config = config;
              this.ServerMetadataHandler = serverMetadataHandler;
              this.WorldMetadata = worldMetadata;
              this.ProtectionManager = protectionManager;
              this.PluginCooperationHandler = pluginCooperationHandler;
              this.ReloadConfigurationCallback = reloadConfigurationCallback;

              #region Command Setup
              base.RegisterCommand(
            new[] { "protector" }, this.RootCommand_Exec, this.RootCommand_HelpCallback
              );
              base.RegisterCommand(
            new[] { "protect", "pt" },
            this.ProtectCommand_Exec, this.ProtectCommand_HelpCallback, ProtectorPlugin.ManualProtect_Permission,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "deprotect", "dp" },
            this.DeprotectCommand_Exec, this.DeprotectCommand_HelpCallback, ProtectorPlugin.ManualDeprotect_Permission,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "protectioninfo", "ptinfo", "pi" }, this.ProtectionInfoCommand_Exec, this.ProtectionInfoCommand_HelpCallback,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "share" }, this.ShareCommand_Exec, this.ShareCommandHelpCallback,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "unshare" }, this.UnshareCommand_Exec, this.UnshareCommand_HelpCallback,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "sharepublic" }, this.SharePublicCommand_Exec, this.SharePublicCommandHelpCallback,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "unsharepublic" }, this.UnsharePublicCommand_Exec, this.UnsharePublicCommand_HelpCallback,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "sharegroup" }, this.ShareGroupCommand_Exec, this.ShareGroupCommand_HelpCallback,
            ProtectorPlugin.ShareWithGroups_Permission,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "unsharegroup" }, this.UnshareGroupCommand_Exec, this.UnshareGroup_HelpCallback,
            ProtectorPlugin.ShareWithGroups_Permission,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "lockchest", "lchest" },
            this.LockChestCommand_Exec, this.LockChestCommand_HelpCallback, ProtectorPlugin.Utility_Permission,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "refillchest", "rchest" },
            this.RefillChestCommand_Exec, this.RefillChestCommand_HelpCallback, ProtectorPlugin.SetRefillChests_Permission,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "refillchestmany", "rchestmany" },
            this.RefillChestManyCommand_Exec, this.RefillChestManyCommand_HelpCallback, ProtectorPlugin.Utility_Permission
              );
              base.RegisterCommand(
            new[] { "bankchest", "bchest" },
            this.BankChestCommand_Exec, this.BankChestCommand_HelpCallback, ProtectorPlugin.SetBankChests_Permission,
            allowServer: false
              );
              base.RegisterCommand(
            new[] { "dumpbankchest", "dbchest" },
            this.DumpBankChestCommand_Exec, this.DumpBankChestCommand_HelpCallback, ProtectorPlugin.DumpBankChests_Permission,
            allowServer: false
              );
              #endregion
        }
        private bool InitServerMetdataHandler()
        {
            this.serverMetadataHandler = new ServerMetadataHandler(ProtectorPlugin.SqlLiteDatabaseFile);

              try {
            this.ServerMetadataHandler.EstablishConnection();
              } catch (Exception ex) {
            this.Trace.WriteLineError(
              "An error occured while opening the database connection. This plugin will be disabled. Exception details: \n" + ex
            );
            this.Trace.WriteLineError("THIS PLUGIN IS DISABLED, EVERYTHING IS UNPROTECTED!");

            this.Dispose();
            return false;
              }

              try {
            this.serverMetadataHandler.EnsureDataStructure();
              } catch (Exception ex) {
            this.Trace.WriteLineError(
              "An error occured while ensuring the database structure. This plugin will be disabled. Exception details: \n" + ex
            );
            this.Trace.WriteLineError("THIS PLUGIN IS DISABLED, EVERYTHING IS UNPROTECTED!");

            this.Dispose();
            return false;
              }

              return true;
        }