예제 #1
0
        public override void Initialize()
        {
            PlayerHooks.PlayerPostLogin += OnPlayerPostLogin;
            ServerApi.Hooks.NetGreetPlayer.Register(this, OnGreetPlayer);

            SettingsParser.CreateFile(Path.Combine(TShock.SavePath, "ReportSettings.txt"),
                new[]
                {
                    "Unread string=[Unread]",
                    "Unhandled string=[Unhandled]",
                    "Default string=null"
                });

            Db = Database.InitDb("Reports");

            Commands.ChatCommands.Add(new Command("reports.report", Report, "report")
            {
                AllowServer = false,
                HelpDesc = new[]
                {
                    "Create an admin-viewable report for a player",
                    "Usage: /report <player> [reason]"
                }
            });
            Commands.ChatCommands.Add(new Command("reports.report.check", CheckReports, "creport", "creports",
                "checkreports")
            {
                HelpDesc = new[]
                {
                    "View any reports filed by players",
                    "Usage: /creports [search|id|page <number>]"
                }
            });
            Commands.ChatCommands.Add(new Command("reports.report.teleport", RTeleport, "rtp", "rteleport")
            {
                HelpDesc = new[]
                {
                    "Teleports you to the location your last read report was created at",
                    "Usage: /rtp"
                },
                AllowServer = false
            });
            Commands.ChatCommands.Add(new Command("reports.report.delete", DeleteReports, "dreport", "dreports",
                "deletereports")
            {
                HelpDesc = new[]
                {
                    "Deletes a report, or a range of reports",
                    "Usage: /dreports id",
                    "Usage: /dreports id id2 id3 ... idn"
                }
            });
            Commands.ChatCommands.Add(new Command("reports.report.handle", HandleReports, "hreport", "hreports", "handle")
            {
                HelpDesc = new[]
                {
                    "Set a handled state on a single report, or range of reports.",
                    "This means that they will not be displayed as new reports."
                }
            });
            Commands.ChatCommands.Add(new Command("reports.reload", ReloadSettings, "rsettings")
            {
                HelpDesc = new[]
                {
                    "Reloads the ReportSettings.txt file"
                }
            });
            Commands.ChatCommands.Add(new Command("reports.admin.reseed", ReseedDb, "reseed")
            {
                HelpDesc = new[]
                {
                    "Reseeds the auto-increment value of the reports database.",
                    "You should only use this if you know what the above sentence means.",
                    "Your reports database must be empty for this command to work."
                }
            });
        }
예제 #2
0
        public static Database InitDb(string name)
        {
            IDbConnection db;
            if (TShock.Config.StorageType.ToLower() == "sqlite")
                db =
                    new SqliteConnection(string.Format("uri=file://{0},Version=3",
                        Path.Combine(TShock.SavePath, name + ".sqlite")));
            else if (TShock.Config.StorageType.ToLower() == "mysql")
            {
                try
                {
                    var host = TShock.Config.MySqlHost.Split(':');
                    db = new MySqlConnection
                    {
                        ConnectionString = string.Format("Server={0}; Port={1}; Database={2}; Uid={3}; Pwd={4}",
                            host[0],
                            host.Length == 1 ? "3306" : host[1],
                            TShock.Config.MySqlDbName,
                            TShock.Config.MySqlUsername,
                            TShock.Config.MySqlPassword
                            )
                    };
                }
                catch (MySqlException x)
                {
                    TShock.Log.Error(x.ToString());
                    throw new Exception("MySQL not setup correctly.");
                }
            }
            else
                throw new Exception("Invalid storage type.");

            var database = new Database(db);
            return database;
        }