mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 12:42:22 -04:00
More consistent permission denied messages for moderation commands
This commit is contained in:
parent
2275533601
commit
6e9dcc2ed2
@ -73,7 +73,7 @@ namespace MCGalaxy.Blocks.Extended {
|
||||
|
||||
static PortalExit ParseExit(IDataRecord record) {
|
||||
PortalExit data = new PortalExit();
|
||||
data.Map = record.GetString(0).Cp437ToUnicode();
|
||||
data.Map = record.GetText(0).Cp437ToUnicode();
|
||||
|
||||
data.X = (ushort)record.GetInt32(1);
|
||||
data.Y = (ushort)record.GetInt32(2);
|
||||
|
@ -64,7 +64,7 @@ namespace MCGalaxy {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected static void MessageTooHighRank(Player p, string action, bool canAffectOwnRank) {
|
||||
protected internal static void MessageTooHighRank(Player p, string action, bool canAffectOwnRank) {
|
||||
MessageTooHighRank(p, action, p.group, canAffectOwnRank);
|
||||
}
|
||||
|
||||
|
@ -38,25 +38,19 @@ namespace MCGalaxy.Commands.Moderation {
|
||||
reason = ModActionCmd.ExpandReason(p, reason);
|
||||
if (reason == null) return;
|
||||
|
||||
Group group = PlayerInfo.GetGroup(target);
|
||||
if (!CheckPerms(target, group, p)) return;
|
||||
Group group = ModActionCmd.CheckTarget(p, "ban", target);
|
||||
if (group == null) return;
|
||||
|
||||
if (group.Permission == LevelPermission.Banned) {
|
||||
Player.Message(p, "{0} %Sis already banned.", PlayerInfo.GetColoredName(p, target));
|
||||
return;
|
||||
}
|
||||
|
||||
ModAction action = new ModAction(target, p, ModActionType.Ban, reason);
|
||||
action.targetGroup = group;
|
||||
OnModActionEvent.Call(action);
|
||||
}
|
||||
|
||||
static bool CheckPerms(string name, Group group, Player p) {
|
||||
if (group.Permission == LevelPermission.Banned) {
|
||||
Player.Message(p, "{0} %Sis already banned.", PlayerInfo.GetColoredName(p, name));
|
||||
return false;
|
||||
}
|
||||
if (p != null && group.Permission >= p.Rank) {
|
||||
MessageTooHighRank(p, "ban", false); return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Help(Player p) {
|
||||
Player.Message(p, "%T/Ban [player] <reason>");
|
||||
Player.Message(p, "%HBans a player (and kicks them if online).");
|
||||
|
@ -31,8 +31,9 @@ namespace MCGalaxy.Commands.Moderation {
|
||||
|
||||
Player who = PlayerInfo.FindMatches(p, args[0]);
|
||||
if (who == null) return;
|
||||
if (p != null && p == who) { Player.Message(p, "Cannot freeze yourself."); return; }
|
||||
if (p != null && who.Rank >= p.Rank) { MessageTooHighRank(p, "freeze", false); return; }
|
||||
|
||||
Group group = ModActionCmd.CheckTarget(p, "freeze", who.name);
|
||||
if (group == null) return;
|
||||
|
||||
if (who.frozen) {
|
||||
string reason = args.Length > 1 ? args[1] : "";
|
||||
|
@ -34,12 +34,12 @@ namespace MCGalaxy.Commands.Moderation {
|
||||
if (Server.muted.Contains(args[0])) Unmute(p, args[0], args);
|
||||
return;
|
||||
}
|
||||
if (p != null && p == who) { Player.Message(p, "You cannot mute or unmute yourself."); return; }
|
||||
|
||||
if (who.muted) {
|
||||
Unmute(p, who.name, args);
|
||||
} else {
|
||||
if (p != null && who.Rank >= p.Rank) { MessageTooHighRank(p, "mute", false); return; }
|
||||
Group group = ModActionCmd.CheckTarget(p, "mute", who.name);
|
||||
if (group == null) return;
|
||||
|
||||
TimeSpan duration = TimeSpan.FromSeconds(ServerConfig.ChatSpamMuteTime);
|
||||
if (args.Length > 1) {
|
||||
@ -60,6 +60,8 @@ namespace MCGalaxy.Commands.Moderation {
|
||||
reason = ModActionCmd.ExpandReason(p, reason);
|
||||
if (reason == null) return;
|
||||
|
||||
if (p != null && p.name == name) { Player.Message(p, "You cannot unmute yourself."); return; }
|
||||
|
||||
ModAction action = new ModAction(name, p, ModActionType.Unmuted, reason);
|
||||
OnModActionEvent.Call(action);
|
||||
}
|
||||
|
@ -35,10 +35,9 @@ namespace MCGalaxy.Commands.Moderation {
|
||||
args[0], ref reason);
|
||||
if (target == null) return;
|
||||
|
||||
Group grp = PlayerInfo.GetGroup(target);
|
||||
if (p != null && grp.Permission >= p.Rank) {
|
||||
MessageTooHighRank(p, "temp ban", false); return;
|
||||
}
|
||||
Group group = ModActionCmd.CheckTarget(p, "temp ban", target);
|
||||
if (group == null) return;
|
||||
|
||||
if (Server.tempBans.Contains(target)) {
|
||||
Player.Message(p, "{0} %Sis already temp-banned.", PlayerInfo.GetColoredName(p, target));
|
||||
return;
|
||||
@ -52,7 +51,7 @@ namespace MCGalaxy.Commands.Moderation {
|
||||
if (reason == null) return;
|
||||
|
||||
ModAction action = new ModAction(target, p, ModActionType.Ban, reason, span);
|
||||
action.targetGroup = grp;
|
||||
action.targetGroup = group;
|
||||
OnModActionEvent.Call(action);
|
||||
}
|
||||
|
||||
|
@ -27,28 +27,18 @@ namespace MCGalaxy.Commands.Moderation {
|
||||
public override void Use(Player p, string message) {
|
||||
if (message.Length == 0) { Help(p); return; }
|
||||
string[] args = message.SplitSpaces(2);
|
||||
Player who = PlayerInfo.FindMatches(p, args[0]);
|
||||
|
||||
string reason = args.Length == 1 ? "you know why." : args[1];
|
||||
string target = ModActionCmd.FindName(p, "warn", "Warn", "", args[0], ref reason);
|
||||
if (target == null) return;
|
||||
|
||||
reason = ModActionCmd.ExpandReason(p, reason);
|
||||
if (reason == null) return;
|
||||
|
||||
if (who == null) { WarnOffline(p, args, reason); return; }
|
||||
if (who == p) { Player.Message(p, "you can't warn yourself"); return; }
|
||||
if (p != null && p.Rank <= who.Rank) {
|
||||
MessageTooHighRank(p, "warn", false); return;
|
||||
}
|
||||
Group group = ModActionCmd.CheckTarget(p, "warn", target);
|
||||
if (group == null) return;
|
||||
|
||||
ModAction action = new ModAction(who.name, p, ModActionType.Warned, reason);
|
||||
OnModActionEvent.Call(action);
|
||||
}
|
||||
|
||||
static void WarnOffline(Player p, string[] args, string reason) {
|
||||
Player.Message(p, "Searching PlayerDB..");
|
||||
string offName = PlayerDB.MatchNames(p, args[0]);
|
||||
if (offName == null) return;
|
||||
|
||||
ModAction action = new ModAction(offName, p, ModActionType.Warned, reason);
|
||||
ModAction action = new ModAction(target, p, ModActionType.Warned, reason);
|
||||
OnModActionEvent.Call(action);
|
||||
}
|
||||
|
||||
|
@ -31,6 +31,7 @@ namespace MCGalaxy.Commands.Moderation {
|
||||
/// <summary> Expands @[rule number] to the actual rule with that number. </summary>
|
||||
public static string ExpandReason(Player p, string reason) {
|
||||
if (reason.Length == 0 || reason[0] != '@') return reason;
|
||||
|
||||
reason = reason.Substring(1);
|
||||
int num;
|
||||
if (!int.TryParse(reason, out num)) return "@" + reason;
|
||||
@ -126,6 +127,18 @@ namespace MCGalaxy.Commands.Moderation {
|
||||
}
|
||||
}
|
||||
|
||||
internal static Group CheckTarget(Player p, string action, string target) {
|
||||
if (p != null && target == p.name) {
|
||||
Player.Message(p, "You canot {0} yourself", action); return null;
|
||||
}
|
||||
|
||||
Group group = PlayerInfo.GetGroup(target);
|
||||
if (p != null && p.Rank <= group.Permission) {
|
||||
Command.MessageTooHighRank(p, action, false); return null;
|
||||
}
|
||||
return group;
|
||||
}
|
||||
|
||||
|
||||
/// <summary> Finds the matching name(s) for the input name,
|
||||
/// and requires a confirmation message for non-existent players. </summary>
|
||||
|
@ -140,17 +140,19 @@ namespace MCGalaxy.SQL {
|
||||
List<string[]> fields = new List<string[]>();
|
||||
Database.Iterate("DESCRIBE `" + table + "`", fields, Database.ReadFields);
|
||||
|
||||
const int i_name = 0, i_type = 1, i_null = 2, i_key = 3, i_def = 4, i_extra = 5;
|
||||
string pri = "";
|
||||
|
||||
for (int i = 0; i < fields.Count; i++) {
|
||||
string[] field = fields[i];
|
||||
if (field[i_key].CaselessEq("pri")) pri = field[i_name];
|
||||
|
||||
if (field[3].CaselessEq("pri")) pri = field[0];
|
||||
string value = field[2].CaselessEq("no") ? "NOT NULL" : "DEFAULT NULL";
|
||||
if (field[4].Length > 0) value += " DEFAULT '" + field[4] + "'";
|
||||
if (field[5].Length > 0) value += " " + field[5];
|
||||
string meta = field[i_null].CaselessEq("no") ? "NOT NULL" : "DEFAULT NULL";
|
||||
if (field[i_def].Length > 0) meta += " DEFAULT '" + field[i_def] + "'";
|
||||
if (field[i_extra].Length > 0) meta += " " + field[i_extra];
|
||||
|
||||
string suffix = pri.Length == 0 && (i == fields.Count - 1) ? "" : ",";
|
||||
w.WriteLine("`{0}` {1} {2}{3}", field[0], field[1], value, suffix);
|
||||
w.WriteLine("`{0}` {1} {2}{3}", field[i_name], field[i_type], meta, suffix);
|
||||
}
|
||||
|
||||
if (pri.Length > 0) w.Write("PRIMARY KEY (`{0}`)", pri);
|
||||
|
@ -33,14 +33,14 @@ namespace MCGalaxy.SQL {
|
||||
return (int)Backend.ReadRows(table, "COUNT(*)", 0, ReadInt, modifier, args);
|
||||
}
|
||||
|
||||
static object ReadString(IDataRecord record, object arg) { return record.GetString(0); }
|
||||
static object ReadString(IDataRecord record, object arg) { return record.GetText(0); }
|
||||
public static string ReadString(string table, string column,
|
||||
string modifier = "", params object[] args) {
|
||||
return (string)Backend.ReadRows(table, column, null, ReadString, modifier, args);
|
||||
}
|
||||
|
||||
internal static object ReadList(IDataRecord record, object arg) {
|
||||
((List<string>)arg).Add(record.GetString(0)); return arg;
|
||||
((List<string>)arg).Add(record.GetText(0)); return arg;
|
||||
}
|
||||
internal static List<string> GetStrings(string sql, params object[] args) {
|
||||
List<string> values = new List<string>();
|
||||
@ -50,7 +50,7 @@ namespace MCGalaxy.SQL {
|
||||
|
||||
internal static object ReadFields(IDataRecord record, object arg) {
|
||||
string[] field = new string[record.FieldCount];
|
||||
for (int i = 0; i < field.Length; i++) { field[i] = record.GetString(i); }
|
||||
for (int i = 0; i < field.Length; i++) { field[i] = record.GetText(i); }
|
||||
((List<string[]>)arg).Add(field);
|
||||
return arg;
|
||||
}
|
||||
@ -108,19 +108,23 @@ namespace MCGalaxy.SQL {
|
||||
}
|
||||
|
||||
|
||||
internal static string GetText(this IDataRecord record, int col) {
|
||||
return record.IsDBNull(col) ? "" : record.GetString(col);
|
||||
}
|
||||
|
||||
internal static string GetText(this IDataRecord record, string name) {
|
||||
int i = record.GetOrdinal(name);
|
||||
return record.IsDBNull(i) ? "" : record.GetString(i);
|
||||
int col = record.GetOrdinal(name);
|
||||
return record.IsDBNull(col) ? "" : record.GetString(col);
|
||||
}
|
||||
|
||||
internal static int GetInt(this IDataRecord record, string name) {
|
||||
int i = record.GetOrdinal(name);
|
||||
return record.IsDBNull(i) ? 0 : record.GetInt32(i);
|
||||
int col = record.GetOrdinal(name);
|
||||
return record.IsDBNull(col) ? 0 : record.GetInt32(col);
|
||||
}
|
||||
|
||||
internal static long GetLong(this IDataRecord record, string name) {
|
||||
int i = record.GetOrdinal(name);
|
||||
return record.IsDBNull(i) ? 0 : record.GetInt64(i);
|
||||
int col = record.GetOrdinal(name);
|
||||
return record.IsDBNull(col) ? 0 : record.GetInt64(col);
|
||||
}
|
||||
|
||||
internal static DateTime GetDateTime(this IDataRecord record, string name) {
|
||||
|
@ -16,9 +16,7 @@
|
||||
permissions and limitations under the Licenses.
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
|
||||
namespace MCGalaxy.SQL {
|
||||
|
||||
|
@ -107,7 +107,7 @@ namespace MCGalaxy.DB {
|
||||
|
||||
public static string MatchNames(Player p, string name) {
|
||||
List<string> names = new List<string>();
|
||||
MatchMulti("Players", "Name", names, Database.ReadList);
|
||||
MatchMulti(name, "Name", names, Database.ReadList);
|
||||
|
||||
int matches;
|
||||
return Matcher.Find(p, name, out matches, names,
|
||||
@ -116,7 +116,7 @@ namespace MCGalaxy.DB {
|
||||
|
||||
public static string[] MatchValues(Player p, string name, string columns) {
|
||||
List<string[]> name_values = new List<string[]>();
|
||||
MatchMulti("Players", columns, name_values, Database.ReadFields);
|
||||
MatchMulti(name, columns, name_values, Database.ReadFields);
|
||||
|
||||
int matches;
|
||||
return Matcher.Find(p, name, out matches, name_values,
|
||||
@ -130,7 +130,7 @@ namespace MCGalaxy.DB {
|
||||
|
||||
public static PlayerData Match(Player p, string name) {
|
||||
List<PlayerData> stats = new List<PlayerData>();
|
||||
MatchMulti("Players", "*", stats, Database.ReadList);
|
||||
MatchMulti(name, "*", stats, ReadStats);
|
||||
|
||||
int matches;
|
||||
return Matcher.Find(p, name, out matches, stats,
|
||||
|
@ -109,7 +109,7 @@ namespace MCGalaxy {
|
||||
|
||||
static object ReadAccounts(IDataRecord record, object arg) {
|
||||
List<string> names = (List<string>)arg;
|
||||
string name = record.GetString(0);
|
||||
string name = record.GetText(0);
|
||||
|
||||
if (!names.CaselessContains(name)) names.Add(name);
|
||||
return arg;
|
||||
|
Loading…
x
Reference in New Issue
Block a user