mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 04:32:50 -04:00
Fix /banedit to actually work
This commit is contained in:
parent
b7f3c4523b
commit
57ab1949b7
@ -93,10 +93,10 @@ namespace MCGalaxy.Commands.CPE {
|
||||
|
||||
internal static void FilterURL(ref string url) {
|
||||
// a lot of people try linking to the dropbox page instead of directly to file, so we auto correct them
|
||||
if (url.StartsWith("http://www.dropbox")) {
|
||||
if (url.CaselessStarts("http://www.dropbox")) {
|
||||
url = "http://dl.dropbox" + url.Substring("http://www.dropbox".Length);
|
||||
url = url.Replace("?dl=0", "");
|
||||
} else if (url.StartsWith("https://www.dropbox")) {
|
||||
} else if (url.CaselessStarts("https://www.dropbox")) {
|
||||
url = "https://dl.dropbox" + url.Substring("https://www.dropbox".Length);
|
||||
url = url.Replace("?dl=0", "");
|
||||
}
|
||||
|
@ -39,28 +39,28 @@ namespace MCGalaxy.Commands.Info {
|
||||
|
||||
foreach (string line in rankings) {
|
||||
string[] args = line.SplitSpaces();
|
||||
int offset;
|
||||
TimeSpan delta;
|
||||
string oldRank, newRank;
|
||||
int offset;
|
||||
|
||||
if (args.Length <= 6) {
|
||||
delta = DateTime.UtcNow - long.Parse(args[2]).FromUnixTime();
|
||||
offset = 3;
|
||||
newRank = args[3]; oldRank = args[4];
|
||||
offset = 5;
|
||||
} else {
|
||||
// Backwards compatibility with old format
|
||||
int min = int.Parse(args[2]), hour = int.Parse(args[3]);
|
||||
int day = int.Parse(args[4]), month = int.Parse(args[5]), year = int.Parse(args[6]);
|
||||
|
||||
delta = DateTime.Now - new DateTime(year, month, day, hour, min, 0);
|
||||
offset = 7;
|
||||
newRank = args[7]; oldRank = args[8];
|
||||
offset = 9;
|
||||
}
|
||||
|
||||
string newRank = Group.GetColoredName(args[offset]);
|
||||
string oldRank = Group.GetColoredName(args[offset + 1]);
|
||||
|
||||
offset += 2;
|
||||
string reason = args.Length <= offset ? "(no reason given)" : args[offset].Replace("%20", " ");
|
||||
|
||||
Player.Message(p, "&aFrom {0} &ato {1} &a{2} ago",
|
||||
oldRank, newRank, delta.Shorten(true, false));
|
||||
Group.GetColoredName(oldRank), Group.GetColoredName(newRank),
|
||||
delta.Shorten(true, false));
|
||||
Player.Message(p, "&aBy %S{0}&a, reason: %S{1}",
|
||||
PlayerInfo.GetColoredName(p, args[1]), reason);
|
||||
}
|
||||
|
@ -177,8 +177,8 @@ namespace MCGalaxy.SQL {
|
||||
transaction = connection.BeginTransaction();
|
||||
}
|
||||
|
||||
public override IDbCommand CreateCommand(string query) {
|
||||
return new MySqlCommand(query, (MySqlConnection)connection, (MySqlTransaction)transaction);
|
||||
public override IDbCommand CreateCommand(string sql) {
|
||||
return new MySqlCommand(sql, (MySqlConnection)connection, (MySqlTransaction)transaction);
|
||||
}
|
||||
|
||||
public override IDataParameter CreateParam(string paramName, DbType type) {
|
||||
@ -195,8 +195,8 @@ namespace MCGalaxy.SQL {
|
||||
return new MySqlConnection(connString);
|
||||
}
|
||||
|
||||
protected override IDbCommand CreateCommand(string query, IDbConnection conn) {
|
||||
return new MySqlCommand(query, (MySqlConnection)conn);
|
||||
protected override IDbCommand CreateCommand(string sql, IDbConnection conn) {
|
||||
return new MySqlCommand(sql, (MySqlConnection)conn);
|
||||
}
|
||||
|
||||
protected override IDbDataParameter CreateParameter() {
|
||||
|
@ -161,8 +161,8 @@ namespace MCGalaxy.SQL {
|
||||
transaction = connection.BeginTransaction();
|
||||
}
|
||||
|
||||
public override IDbCommand CreateCommand(string query) {
|
||||
return new SQLiteCommand(query, (SQLiteConnection)connection, (SQLiteTransaction)transaction);
|
||||
public override IDbCommand CreateCommand(string sql) {
|
||||
return new SQLiteCommand(sql, (SQLiteConnection)connection, (SQLiteTransaction)transaction);
|
||||
}
|
||||
|
||||
public override IDataParameter CreateParam(string paramName, DbType type) {
|
||||
@ -177,8 +177,8 @@ namespace MCGalaxy.SQL {
|
||||
return new SQLiteConnection(connString);
|
||||
}
|
||||
|
||||
protected override IDbCommand CreateCommand(string query, IDbConnection conn) {
|
||||
return new SQLiteCommand(query, (SQLiteConnection)conn);
|
||||
protected override IDbCommand CreateCommand(string sql, IDbConnection conn) {
|
||||
return new SQLiteCommand(sql, (SQLiteConnection)conn);
|
||||
}
|
||||
|
||||
protected override IDbDataParameter CreateParameter() {
|
||||
|
@ -22,13 +22,10 @@ namespace MCGalaxy.SQL {
|
||||
|
||||
public abstract class BulkTransaction : IDisposable {
|
||||
protected IDbConnection connection;
|
||||
protected IDbTransaction transaction;
|
||||
|
||||
protected IDbTransaction transaction;
|
||||
|
||||
public abstract IDbCommand CreateCommand(string query);
|
||||
|
||||
public abstract IDataParameter CreateParam(string paramName, DbType type);
|
||||
|
||||
public abstract IDbCommand CreateCommand(string sql);
|
||||
public abstract IDataParameter CreateParam(string paramName, DbType type);
|
||||
|
||||
public void Commit() {
|
||||
try {
|
||||
@ -58,14 +55,14 @@ namespace MCGalaxy.SQL {
|
||||
connection = null;
|
||||
}
|
||||
|
||||
public bool Execute(string query) {
|
||||
public bool Execute(string sql) {
|
||||
try {
|
||||
using (IDbCommand cmd = CreateCommand(query)) {
|
||||
using (IDbCommand cmd = CreateCommand(sql)) {
|
||||
cmd.ExecuteNonQuery();
|
||||
return true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.IO.File.AppendAllText("MySQL_error.log", DateTime.Now + " " + query + "\r\n");
|
||||
System.IO.File.AppendAllText("MySQL_error.log", DateTime.Now + " " + sql + "\r\n");
|
||||
Logger.LogError(e);
|
||||
return false;
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ namespace MCGalaxy.SQL {
|
||||
|
||||
public ColumnDesc(string col, ColumnType type)
|
||||
: this(col, type, 0, false, false, false) { }
|
||||
public ColumnDesc(string col, ColumnType type, ushort maxLen = 0)
|
||||
public ColumnDesc(string col, ColumnType type, ushort maxLen)
|
||||
: this(col, type, maxLen, false, false, false) { }
|
||||
|
||||
public ColumnDesc(string col, ColumnType type, ushort maxLen = 0,
|
||||
|
@ -27,18 +27,18 @@ namespace MCGalaxy.SQL {
|
||||
protected abstract bool MultipleSchema { get; }
|
||||
|
||||
protected abstract IDbConnection CreateConnection(string connString);
|
||||
protected abstract IDbCommand CreateCommand(string query, IDbConnection conn);
|
||||
protected abstract IDbCommand CreateCommand(string sql, IDbConnection conn);
|
||||
protected abstract IDbDataParameter CreateParameter();
|
||||
|
||||
|
||||
/// <summary> Executes an SQL command that does not return any results. </summary>
|
||||
public void Execute(string query, string connString, bool createDB = false) {
|
||||
public void Execute(string sql, string connString, bool createDB = false) {
|
||||
using (IDbConnection conn = CreateConnection(connString)) {
|
||||
conn.Open();
|
||||
if (!createDB && MultipleSchema)
|
||||
conn.ChangeDatabase(ServerConfig.MySQLDatabaseName);
|
||||
|
||||
using (IDbCommand cmd = CreateCommand(query, conn)) {
|
||||
using (IDbCommand cmd = CreateCommand(sql, conn)) {
|
||||
FillParams(cmd);
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
@ -47,13 +47,13 @@ namespace MCGalaxy.SQL {
|
||||
}
|
||||
|
||||
/// <summary> Excecutes an SQL query, invoking a callback on the returned rows one by one. </summary>
|
||||
public object Iterate(string query, string connString, object arg, ReaderCallback callback) {
|
||||
public object Iterate(string sql, string connString, object arg, ReaderCallback callback) {
|
||||
using (IDbConnection conn = CreateConnection(connString)) {
|
||||
conn.Open();
|
||||
if (MultipleSchema)
|
||||
conn.ChangeDatabase(ServerConfig.MySQLDatabaseName);
|
||||
|
||||
using (IDbCommand cmd = CreateCommand(query, conn)) {
|
||||
using (IDbCommand cmd = CreateCommand(sql, conn)) {
|
||||
FillParams(cmd);
|
||||
using (IDataReader reader = cmd.ExecuteReader()) {
|
||||
while (reader.Read()) { arg = callback(reader, arg); }
|
||||
|
@ -27,7 +27,7 @@ namespace MCGalaxy.Eco {
|
||||
static ColumnDesc[] createEconomy = new ColumnDesc[] {
|
||||
new ColumnDesc("player", ColumnType.VarChar, 20, priKey: true),
|
||||
new ColumnDesc("money", ColumnType.Int32),
|
||||
new ColumnDesc("total", ColumnType.Integer),
|
||||
new ColumnDesc("total", ColumnType.Int32),
|
||||
new ColumnDesc("purchase", ColumnType.VarChar, 255),
|
||||
new ColumnDesc("payment", ColumnType.VarChar, 255),
|
||||
new ColumnDesc("salary", ColumnType.VarChar, 255),
|
||||
|
@ -72,14 +72,14 @@ namespace MCGalaxy {
|
||||
}
|
||||
|
||||
static void AddBanEntry(string pl, string who, string reason, string stealth, string oldrank) {
|
||||
string datetime = DateTime.UtcNow.ToUnixTime().ToString();
|
||||
string data = pl + " " + who + " " + reason + " " + stealth + " " + datetime + " " + oldrank;
|
||||
string time = DateTime.UtcNow.ToUnixTime().ToString();
|
||||
string data = pl + " " + who + " " + reason + " " + stealth + " " + time + " " + oldrank;
|
||||
bans.Append(data);
|
||||
}
|
||||
|
||||
static void AddUnbanEntry(string pl, string who, string reason) {
|
||||
string datetime = DateTime.UtcNow.ToUnixTime().ToString();
|
||||
string data = pl + " " + who + " " + reason + " " + datetime;
|
||||
string time = DateTime.UtcNow.ToUnixTime().ToString();
|
||||
string data = pl + " " + who + " " + reason + " " + time;
|
||||
unbans.Append(data);
|
||||
}
|
||||
|
||||
@ -135,36 +135,32 @@ namespace MCGalaxy {
|
||||
return new DateTime(year, month, day, hour, minute, 0).ToUniversalTime();
|
||||
}
|
||||
|
||||
|
||||
/// <summary> Deletes the ban information about the user. </summary>
|
||||
|
||||
public static bool DeleteBan(string name) { return DeleteInfo(name, bans); }
|
||||
|
||||
/// <summary> Deletes the unban information about the user. </summary>
|
||||
public static bool DeleteUnban(string name) { return DeleteInfo(name, unbans); }
|
||||
|
||||
static bool DeleteInfo(string name, PlayerMetaList list) {
|
||||
name = name.ToLower();
|
||||
bool success = false;
|
||||
bool found = false;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
foreach (string line in File.ReadAllLines(list.file)) {
|
||||
string[] parts = line.SplitSpaces();
|
||||
if (parts.Length <= 1 || parts[1] != name)
|
||||
if (parts.Length > 1 && parts[1] == name) {
|
||||
found = true;
|
||||
} else {
|
||||
sb.AppendLine(line);
|
||||
else
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
File.WriteAllText(list.file, sb.ToString());
|
||||
return success;
|
||||
|
||||
if (found) File.WriteAllText(list.file, sb.ToString());
|
||||
return found;
|
||||
}
|
||||
|
||||
|
||||
/// <summary> Change the ban reason for the given user. </summary>
|
||||
public static bool ChangeBanReason(string who, string reason) {
|
||||
return ChangeReason(who, reason, bans);
|
||||
}
|
||||
|
||||
/// <summary> Change the unban reason for the given user. </summary>
|
||||
public static bool ChangeUnbanReason(string who, string reason) {
|
||||
return ChangeReason(who, reason, unbans);
|
||||
}
|
||||
@ -172,22 +168,22 @@ namespace MCGalaxy {
|
||||
static bool ChangeReason(string who, string reason, PlayerMetaList list) {
|
||||
who = who.ToLower();
|
||||
reason = reason.Replace(" ", "%20");
|
||||
bool success = false;
|
||||
bool found = false;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
foreach (string line in File.ReadAllLines(list.file)) {
|
||||
string[] parts = line.SplitSpaces();
|
||||
if (parts.Length > 2 && parts[1] == who) {
|
||||
success = true;
|
||||
found = true;
|
||||
parts[2] = reason;
|
||||
sb.AppendLine(String.Join(" ", parts));
|
||||
} else {
|
||||
sb.AppendLine(line);
|
||||
}
|
||||
}
|
||||
|
||||
if (success)
|
||||
File.WriteAllText(list.file, sb.ToString());
|
||||
return success;
|
||||
if (found) File.WriteAllText(list.file, sb.ToString());
|
||||
return found;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user