diff --git a/MCGalaxy/Blocks/Behaviour/BlockBehaviour.cs b/MCGalaxy/Blocks/Behaviour/BlockBehaviour.cs
index 177ac8128..0a0e0e6e6 100644
--- a/MCGalaxy/Blocks/Behaviour/BlockBehaviour.cs
+++ b/MCGalaxy/Blocks/Behaviour/BlockBehaviour.cs
@@ -45,8 +45,8 @@ namespace MCGalaxy.Blocks {
case Block.C4: return PlaceBehaviour.C4;
case Block.C4Detonator: return PlaceBehaviour.C4Det;
}
-
- if (props[block.Index].StackId != Block.Air) return PlaceBehaviour.Stack(block);
+
+ if (props[block.Index].StackId != Block.Air) return PlaceBehaviour.Stack(block);
return null;
}
diff --git a/MCGalaxy/Blocks/Block.Convert.cs b/MCGalaxy/Blocks/Block.Convert.cs
index 85b4d673b..38f79c840 100644
--- a/MCGalaxy/Blocks/Block.Convert.cs
+++ b/MCGalaxy/Blocks/Block.Convert.cs
@@ -19,9 +19,9 @@ using System;
namespace MCGalaxy {
public sealed partial class Block {
-
- static string[] coreNames = new string[Block.Count];
- public static string Name(byte block) { return coreNames[block]; }
+
+ static string[] coreNames = new string[Block.Count];
+ public static string Name(byte block) { return coreNames[block]; }
public static byte Byte(string type) {
byte block;
diff --git a/MCGalaxy/Blocks/Physics/HunterPhysics.cs b/MCGalaxy/Blocks/Physics/HunterPhysics.cs
index 52a2db383..40ec2bebe 100644
--- a/MCGalaxy/Blocks/Physics/HunterPhysics.cs
+++ b/MCGalaxy/Blocks/Physics/HunterPhysics.cs
@@ -39,7 +39,7 @@ namespace MCGalaxy.Blocks.Physics {
index = lvl.PosToInt((ushort)(x + Math.Sign(closest.Pos.BlockX - x)), y, z);
if (MoveTo(lvl, block, C.b, index, target)) return;
}
-
+
dirsVisited++;
if (dirsVisited >= 3) break;
goto case 4;
@@ -88,7 +88,7 @@ namespace MCGalaxy.Blocks.Physics {
index = lvl.PosToInt((ushort)(x - Math.Sign(closest.Pos.BlockX - x)), y, z);
if (MoveTo(lvl, block, C.b, index, target)) return;
}
-
+
dirsVisited++;
if (dirsVisited >= 3) break;
goto case 4;
@@ -128,7 +128,7 @@ namespace MCGalaxy.Blocks.Physics {
}
static void RandomlyMove(Level lvl, ref Check C, ExtBlock block, Random rand,
- ushort x, ushort y, ushort z, byte target) {
+ ushort x, ushort y, ushort z, byte target) {
switch (rand.Next(1, 15)) {
case 1:
if (MoveTo(lvl, block, C.b, lvl.PosToInt(x, (ushort)(y - 1), z), target)) return;
diff --git a/MCGalaxy/Chat/EmotesHandler.cs b/MCGalaxy/Chat/EmotesHandler.cs
index a78c048fd..3249b834e 100644
--- a/MCGalaxy/Chat/EmotesHandler.cs
+++ b/MCGalaxy/Chat/EmotesHandler.cs
@@ -39,7 +39,7 @@ namespace MCGalaxy {
{ "vv", '▼' }, { "down", '▼' },
{ "house", '⌂' }
};
-
+
/// Conversion for code page 437 characters from index 0 to 31 to unicode.
public const string ControlCharReplacements = "\0☺☻♥♦♣♠•◘○◙♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼";
diff --git a/MCGalaxy/Commands/Alias.cs b/MCGalaxy/Commands/Alias.cs
index c0c70149a..c350c0231 100644
--- a/MCGalaxy/Commands/Alias.cs
+++ b/MCGalaxy/Commands/Alias.cs
@@ -78,10 +78,10 @@ namespace MCGalaxy.Commands {
public static Alias Find(string cmd) {
foreach (Alias alias in aliases) {
- if (alias.Trigger.CaselessEq(cmd)) return alias;
+ if (alias.Trigger.CaselessEq(cmd)) return alias;
}
foreach (Alias alias in coreAliases) {
- if (alias.Trigger.CaselessEq(cmd)) return alias;
+ if (alias.Trigger.CaselessEq(cmd)) return alias;
}
return null;
}
diff --git a/MCGalaxy/Commands/Bots/CmdBot.cs b/MCGalaxy/Commands/Bots/CmdBot.cs
index c1972dd51..4db303179 100644
--- a/MCGalaxy/Commands/Bots/CmdBot.cs
+++ b/MCGalaxy/Commands/Bots/CmdBot.cs
@@ -48,10 +48,7 @@ namespace MCGalaxy.Commands.Bots {
}
void AddBot(Player p, string botName) {
- if (!p.level.BuildAccess.CheckDetailed(p)) {
- Player.Message(p, "Hence, you cannot add bots to this map.");
- return;
- }
+ if (!LevelInfo.ValidateAction(p, p.level.name, "add bots to this level")) return;
if (BotExists(p.level, botName)) {
Player.Message(p, "A bot with that name already exists."); return;
@@ -77,10 +74,7 @@ namespace MCGalaxy.Commands.Bots {
}
void RemoveBot(Player p, string botName) {
- if (!p.level.BuildAccess.CheckDetailed(p)) {
- Player.Message(p, "Hence, you cannot remove bots from this map.");
- return;
- }
+ if (!LevelInfo.ValidateAction(p, p.level.name, "remove bots from this level")) return;
if (botName.CaselessEq("all")) {
PlayerBot.RemoveLoadedBots(p.level, false);
@@ -97,6 +91,7 @@ namespace MCGalaxy.Commands.Bots {
void SetBotText(Player p, string botName, string text) {
PlayerBot bot = Matcher.FindBots(p, botName);
if (bot == null) return;
+ if (!LevelInfo.ValidateAction(p, p.level.name, "set bot text of that bot")) return;
if (text == null) {
Player.Message(p, "Removed text shown when bot {0} %Sclicked on", bot.ColoredName);
diff --git a/MCGalaxy/Commands/Bots/CmdBotSet.cs b/MCGalaxy/Commands/Bots/CmdBotSet.cs
index 6190c18de..4a6947ae7 100644
--- a/MCGalaxy/Commands/Bots/CmdBotSet.cs
+++ b/MCGalaxy/Commands/Bots/CmdBotSet.cs
@@ -34,12 +34,8 @@ namespace MCGalaxy.Commands.Bots {
if (message.Length == 0) { Help(p); return; }
string[] args = message.SplitSpaces();
PlayerBot bot = Matcher.FindBots(p, args[0]);
- if (bot == null) return;
-
- if (p != null && !bot.level.BuildAccess.CheckDetailed(p)) {
- Player.Message(p, "Hence, you cannot change the AI of bots on this map.");
- return;
- }
+ if (bot == null) return;
+ if (!LevelInfo.ValidateAction(p, p.level.name, "change AI of bots in this level")) return;
if (args.Length == 1) {
bot.Instructions.Clear();
diff --git a/MCGalaxy/Commands/Bots/CmdBotSummon.cs b/MCGalaxy/Commands/Bots/CmdBotSummon.cs
index a9c6300a2..6cc77ba7f 100644
--- a/MCGalaxy/Commands/Bots/CmdBotSummon.cs
+++ b/MCGalaxy/Commands/Bots/CmdBotSummon.cs
@@ -27,10 +27,7 @@ namespace MCGalaxy.Commands.Bots {
public override void Use(Player p, string message) {
if (message.Length == 0) { Help(p); return; }
- if (!p.level.BuildAccess.CheckDetailed(p)) {
- Player.Message(p, "Hence, you cannot summon bots on this map.");
- return;
- }
+ if (!LevelInfo.ValidateAction(p, p.level.name, "summon that bot")) return;
PlayerBot bot = Matcher.FindBots(p, message);
if (bot == null) return;
diff --git a/MCGalaxy/Commands/CPE/CmdTexture.cs b/MCGalaxy/Commands/CPE/CmdTexture.cs
index 38a5d028e..dc4fb6341 100644
--- a/MCGalaxy/Commands/CPE/CmdTexture.cs
+++ b/MCGalaxy/Commands/CPE/CmdTexture.cs
@@ -68,6 +68,7 @@ namespace MCGalaxy.Commands.CPE {
Player.Message(p, "Set server's default terrain to " + path);
UpdateGlobally(p, false);
} else if (scope == "level") {
+ if (!LevelInfo.ValidateAction(p, p.level.name, "set texture of this level")) return;
p.level.Config.Terrain = url;
Player.Message(p, "Set level's terrain to " + path);
UpdateLevel(p);
@@ -76,6 +77,7 @@ namespace MCGalaxy.Commands.CPE {
Player.Message(p, "Set server's default texture pack to " + path);
UpdateGlobally(p, true);
} else if (scope == "levelzip") {
+ if (!LevelInfo.ValidateAction(p, p.level.name, "set texture pack of this level")) return;
p.level.Config.TexturePack = url;
Player.Message(p, "Set level's texture pack to " + path);
UpdateLevel(p);
diff --git a/MCGalaxy/Commands/Chat/CmdColor.cs b/MCGalaxy/Commands/Chat/CmdColor.cs
index 8256ef6c4..eab18dd38 100644
--- a/MCGalaxy/Commands/Chat/CmdColor.cs
+++ b/MCGalaxy/Commands/Chat/CmdColor.cs
@@ -33,10 +33,7 @@ namespace MCGalaxy.Commands.Chatting {
public override void Use(Player p, string message) { UseBotOrPlayer(p, message, "color"); }
protected override void SetBotData(Player p, PlayerBot bot, string colName) {
- if (p != null && !bot.level.BuildAccess.CheckDetailed(p)) {
- Player.Message(p, "Hence, you cannot change the color of that bot.");
- return;
- }
+ if (!LevelInfo.ValidateAction(p, bot.level.name, "change color of that bot")) return;
string color = colName.Length == 0 ? "&1" : Matcher.FindColor(p, colName);
if (color == null) return;
diff --git a/MCGalaxy/Commands/Chat/CmdInbox.cs b/MCGalaxy/Commands/Chat/CmdInbox.cs
index 06609e829..06f88ab35 100644
--- a/MCGalaxy/Commands/Chat/CmdInbox.cs
+++ b/MCGalaxy/Commands/Chat/CmdInbox.cs
@@ -80,7 +80,7 @@ namespace MCGalaxy.Commands.Chatting {
if (num >= Inbox.Rows.Count) {
Player.Message(p, "Message #{0} does not exist.", num); return;
}
-
+
OutputMessage(p, Inbox.Rows[num]);
}
}
diff --git a/MCGalaxy/Commands/CommandList.cs b/MCGalaxy/Commands/CommandList.cs
index 962be230d..2cfaa0a02 100644
--- a/MCGalaxy/Commands/CommandList.cs
+++ b/MCGalaxy/Commands/CommandList.cs
@@ -39,7 +39,7 @@ namespace MCGalaxy {
/// Finds the command which has the given name or shortcut, or null if not found.
public Command Find(string name) {
foreach (Command cmd in commands) {
- if (cmd.name.CaselessEq(name) || cmd.shortcut.CaselessEq(name)) return cmd;
+ if (cmd.name.CaselessEq(name) || cmd.shortcut.CaselessEq(name)) return cmd;
}
return null;
}
diff --git a/MCGalaxy/Commands/EntityPropertyCmd.cs b/MCGalaxy/Commands/EntityPropertyCmd.cs
index dad903f2f..134e01487 100644
--- a/MCGalaxy/Commands/EntityPropertyCmd.cs
+++ b/MCGalaxy/Commands/EntityPropertyCmd.cs
@@ -35,10 +35,7 @@ namespace MCGalaxy.Commands {
if (isBot) {
if (!CheckExtraPerm(p, 2)) return;
- if (p != null && !bot.level.BuildAccess.CheckDetailed(p)) {
- Player.Message(p, "Hence, you cannot change the " + type + " of that bot.");
- return;
- }
+ if (!LevelInfo.ValidateAction(p, bot.level.name, "change the " + type + " of that bot")) return;
SetBotData(p, bot, args.Length > 2 ? args[2] : "");
} else {
if (p != who && !CheckExtraPerm(p, 1)) return;
diff --git a/MCGalaxy/Commands/Information/CmdSearch.cs b/MCGalaxy/Commands/Information/CmdSearch.cs
index c31377f30..6eed5f6dc 100644
--- a/MCGalaxy/Commands/Information/CmdSearch.cs
+++ b/MCGalaxy/Commands/Information/CmdSearch.cs
@@ -79,7 +79,7 @@ namespace MCGalaxy.Commands.Info {
static void SearchRanks(Player p, string keyword, string modifier) {
List ranks = new List();
foreach (Group g in Group.GroupList) {
- if (g.Name.CaselessContains(keyword)) {
+ if (g.Name.CaselessContains(keyword)) {
ranks.Add(g.ColoredName);
}
}
diff --git a/MCGalaxy/Commands/Maintenance/CmdBlockDB.cs b/MCGalaxy/Commands/Maintenance/CmdBlockDB.cs
index 1902d3835..47edc6bfe 100644
--- a/MCGalaxy/Commands/Maintenance/CmdBlockDB.cs
+++ b/MCGalaxy/Commands/Maintenance/CmdBlockDB.cs
@@ -38,6 +38,7 @@ namespace MCGalaxy.Commands.Maintenance {
lvl = Matcher.FindLevels(p, args[1]);
if (lvl == null) return;
}
+ if (!LevelInfo.ValidateAction(p, lvl.name, "change BlockDB state of this level")) return;
if (args[0].CaselessEq("clear")) {
Player.Message(p, "Clearing &cALL %Sblock changes for {0}%S...", lvl.ColoredName);
diff --git a/MCGalaxy/Commands/Moderation/CmdUndoPlayer.cs b/MCGalaxy/Commands/Moderation/CmdUndoPlayer.cs
index 6cd90b024..e65a6f9a2 100644
--- a/MCGalaxy/Commands/Moderation/CmdUndoPlayer.cs
+++ b/MCGalaxy/Commands/Moderation/CmdUndoPlayer.cs
@@ -105,7 +105,7 @@ namespace MCGalaxy.Commands.Moderation {
}
public override void SendMessage(byte id, string message, bool colorParse = true) {
- Logger.Log(LogType.ConsoleMessage, message);
+ Logger.Log(LogType.ConsoleMessage, message);
}
}
diff --git a/MCGalaxy/Commands/World/CmdBlockProperties.cs b/MCGalaxy/Commands/World/CmdBlockProperties.cs
index 9f0b20206..891ab1fd0 100644
--- a/MCGalaxy/Commands/World/CmdBlockProperties.cs
+++ b/MCGalaxy/Commands/World/CmdBlockProperties.cs
@@ -50,6 +50,8 @@ namespace MCGalaxy.Commands.World {
Player.Message(p, "Cannot use level scope from {0}.", src);
return null;
}
+
+ if (!LevelInfo.ValidateAction(p, p.level.name, "change block properties in this level")) return null;
return p.level.Props;
}
diff --git a/MCGalaxy/Commands/World/CmdCopyLVL.cs b/MCGalaxy/Commands/World/CmdCopyLVL.cs
index 822b1156b..d3fa12dba 100644
--- a/MCGalaxy/Commands/World/CmdCopyLVL.cs
+++ b/MCGalaxy/Commands/World/CmdCopyLVL.cs
@@ -37,15 +37,18 @@ namespace MCGalaxy.Commands.World {
if (args.Length < 2) {
Player.Message(p, "You did not specify the destination level name."); return;
}
-
- string src = args[0], dst = args[1];
if (p != null && !p.group.CanExecute("newlvl")) {
Player.Message(p, "You cannot use /copylvl as you cannot use /newlvl."); return;
}
+
+ string src = args[0];
src = Matcher.FindMaps(p, src);
if (src == null) return;
+ if (!LevelInfo.ValidateAction(p, src, "copy this level")) return;
+
+ string dst = args[1];
if (!Formatter.ValidName(p, dst, "level")) return;
- if (LevelInfo.MapExists(dst)) { Player.Message(p, "The level \"" + dst + "\" already exists."); return; }
+ if (LevelInfo.MapExists(dst)) { Player.Message(p, "Level \"" + dst + "\" already exists."); return; }
try {
LevelActions.CopyLevel(src, dst);
diff --git a/MCGalaxy/Commands/World/CmdDeleteLvl.cs b/MCGalaxy/Commands/World/CmdDeleteLvl.cs
index 145e589ee..f15b0ed8f 100644
--- a/MCGalaxy/Commands/World/CmdDeleteLvl.cs
+++ b/MCGalaxy/Commands/World/CmdDeleteLvl.cs
@@ -35,26 +35,14 @@ namespace MCGalaxy.Commands.World {
if (!Formatter.ValidName(p, message, "level")) return;
string map = Matcher.FindMaps(p, message);
if (map == null) return;
+
+ if (map.CaselessEq(ServerConfig.MainLevel)) { Player.Message(p, "Cannot delete the main level."); return; }
+ if (!LevelInfo.ValidateAction(p, map, "delete this level")) return;
- Level lvl = LevelInfo.FindExact(map);
- if (lvl != null && p != null && !lvl.BuildAccess.CheckDetailed(p)) {
- Player.Message(p, "Hence you cannot delete this level."); return;
- }
- if (lvl == Server.mainLevel) { Player.Message(p, "Cannot delete the main level."); return; }
-
- LevelPermission perbuild = GetPerBuildPermission(map);
- if (p != null && perbuild > p.Rank) {
- Player.Message(p, "%cYou can't delete levels with a perbuild rank higher than yours!"); return;
- }
Player.Message(p, "Created backup.");
LevelActions.Delete(map.ToLower());
}
- LevelPermission GetPerBuildPermission(string level) {
- string value = LevelInfo.FindOfflineProperty(level, "perbuild");
- return Group.ParsePermOrName(value, LevelPermission.Guest);
- }
-
public override void Help(Player p) {
Player.Message(p, "%T/DeleteLvl [map]");
Player.Message(p, "%HCompletely deletes [map] (portals, MBs, everything");
diff --git a/MCGalaxy/Commands/World/CmdFixGrass.cs b/MCGalaxy/Commands/World/CmdFixGrass.cs
index a5fedc56c..34bfcf835 100644
--- a/MCGalaxy/Commands/World/CmdFixGrass.cs
+++ b/MCGalaxy/Commands/World/CmdFixGrass.cs
@@ -30,9 +30,7 @@ namespace MCGalaxy.Commands.World {
public override void Use(Player p, string message) {
int totalFixed = 0;
Level lvl = p.level;
- if (!lvl.BuildAccess.CheckDetailed(p)) {
- Player.Message(p, "Hence you cannot use %T/fixgrass %Son this map"); return;
- }
+ if (!LevelInfo.ValidateAction(p, lvl.name, "use %T/fixgrass %Son this level")) return;
if (message.Length == 0) {
FixDirtAndGrass(p, lvl, ref totalFixed);
diff --git a/MCGalaxy/Commands/World/CmdMain.cs b/MCGalaxy/Commands/World/CmdMain.cs
index 88ec02483..76dff9232 100644
--- a/MCGalaxy/Commands/World/CmdMain.cs
+++ b/MCGalaxy/Commands/World/CmdMain.cs
@@ -42,9 +42,12 @@ namespace MCGalaxy.Commands.World {
} else {
if (!CheckExtraPerm(p, 1)) return;
if (!Formatter.ValidName(p, message, "level")) return;
+ if (!LevelInfo.ValidateAction(p, ServerConfig.MainLevel, "set main to another level")) return;
string map = Matcher.FindMaps(p, message);
if (map == null) return;
+ if (!LevelInfo.ValidateAction(p, map, "set main to this level")) return;
+
Server.SetMainLevel(map);
SrvProperties.Save();
Player.Message(p, "Set main level to {0}", Server.mainLevel.ColoredName);
diff --git a/MCGalaxy/Commands/World/CmdMap.cs b/MCGalaxy/Commands/World/CmdMap.cs
index 1139b7cd6..ffb3efbf7 100644
--- a/MCGalaxy/Commands/World/CmdMap.cs
+++ b/MCGalaxy/Commands/World/CmdMap.cs
@@ -50,7 +50,7 @@ namespace MCGalaxy.Commands.World {
string map = Matcher.FindMaps(p, args[0]);
if (map == null) return;
- PrintMapInfo(p, GetConfig(map));
+ PrintMapInfo(p, LevelInfo.GetConfig(map, out lvl));
return;
} else {
lvl = Matcher.FindLevels(p, args[0]);
@@ -63,20 +63,11 @@ namespace MCGalaxy.Commands.World {
if (!CheckExtraPerm(p, 1)) return;
if (opt.CaselessEq("realmowner") && !CheckExtraPerm(p, 2)) return;
+ if (!LevelInfo.ValidateAction(p, lvl.name, "change map settings of this level")) return;
if (SetMapOption(p, lvl, opt, value)) return;
Player.Message(p, "Could not find option entered.");
}
- static LevelConfig GetConfig(string map) {
- Level lvl = LevelInfo.FindExact(map);
- if (lvl != null) return lvl.Config;
-
- string propsPath = LevelInfo.PropertiesPath(map);
- LevelConfig cfg = new LevelConfig();
- LevelConfig.Load(propsPath, cfg);
- return cfg;
- }
-
static bool IsMapOption(string[] args) {
string opt = LevelOptions.Map(args[0].ToLower());
if (!ValidOption(opt)) return false;
diff --git a/MCGalaxy/Commands/World/CmdPause.cs b/MCGalaxy/Commands/World/CmdPause.cs
index 6a105e993..0a470a003 100644
--- a/MCGalaxy/Commands/World/CmdPause.cs
+++ b/MCGalaxy/Commands/World/CmdPause.cs
@@ -44,9 +44,11 @@ namespace MCGalaxy.Commands.World {
}
}
+ if (!LevelInfo.ValidateAction(p, lvl.name, "pause physics on this level")) return;
bool enabled = lvl.physPause;
lvl.PhysicsEnabled = enabled;
lvl.physPause = !lvl.physPause;
+
if (enabled) {
Chat.MessageGlobal("Physics on {0} %Swere re-enabled.", lvl.ColoredName);
} else {
diff --git a/MCGalaxy/Commands/World/CmdPhysics.cs b/MCGalaxy/Commands/World/CmdPhysics.cs
index 4b3031bc5..1bb7fccbf 100644
--- a/MCGalaxy/Commands/World/CmdPhysics.cs
+++ b/MCGalaxy/Commands/World/CmdPhysics.cs
@@ -38,6 +38,8 @@ namespace MCGalaxy.Commands.World {
level = Matcher.FindLevels(p, args[0]);
if (level == null) return;
}
+
+ if (!LevelInfo.ValidateAction(p, level.name, "set physics of this level")) return;
SetPhysics(level, state);
}
diff --git a/MCGalaxy/Commands/World/CmdRenameLvl.cs b/MCGalaxy/Commands/World/CmdRenameLvl.cs
index 323e8fc09..83a5812eb 100644
--- a/MCGalaxy/Commands/World/CmdRenameLvl.cs
+++ b/MCGalaxy/Commands/World/CmdRenameLvl.cs
@@ -40,6 +40,7 @@ namespace MCGalaxy.Commands.World {
if (LevelInfo.MapExists(newName)) { Player.Message(p, "Level already exists."); return; }
if (lvl == Server.mainLevel) { Player.Message(p, "Cannot rename the main level."); return; }
+ if (!LevelInfo.ValidateAction(p, lvl.name, "rename this level")) return;
List players = lvl.getPlayers();
lvl.Unload();
diff --git a/MCGalaxy/Commands/World/CmdResizeLvl.cs b/MCGalaxy/Commands/World/CmdResizeLvl.cs
index 77b734105..7c368c334 100644
--- a/MCGalaxy/Commands/World/CmdResizeLvl.cs
+++ b/MCGalaxy/Commands/World/CmdResizeLvl.cs
@@ -42,6 +42,7 @@ namespace MCGalaxy.Commands.World {
public static bool DoResize(Player p, string[] args) {
Level lvl = Matcher.FindLevels(p, args[0]);
if (lvl == null) return true;
+ if (!LevelInfo.ValidateAction(p, lvl.name, "resize this level")) return false;
ushort x = 0, y = 0, z = 0;
if (!CmdNewLvl.CheckMapAxis(p, args[1], "Width", ref x)) return false;
diff --git a/MCGalaxy/Commands/World/CmdRestore.cs b/MCGalaxy/Commands/World/CmdRestore.cs
index 54db5cc02..2afba54bb 100644
--- a/MCGalaxy/Commands/World/CmdRestore.cs
+++ b/MCGalaxy/Commands/World/CmdRestore.cs
@@ -44,12 +44,13 @@ namespace MCGalaxy.Commands.World {
}
}
+ if (!LevelInfo.ValidateAction(p, lvl.name, "restore a backup of this level")) return;
if (File.Exists(LevelInfo.BackupPath(lvl.name, args[0]))) {
try {
DoRestore(lvl, args[0]);
- } catch (Exception ex) {
- Logger.LogError(ex);
- Logger.Log(LogType.Warning, "Restore failed");
+ } catch (Exception ex) {
+ Logger.LogError(ex);
+ Logger.Log(LogType.Warning, "Restore failed");
}
} else {
Player.Message(p, "Backup " + args[0] + " does not exist.");
diff --git a/MCGalaxy/Commands/World/CmdSetspawn.cs b/MCGalaxy/Commands/World/CmdSetspawn.cs
index 50059bf97..16a14e277 100644
--- a/MCGalaxy/Commands/World/CmdSetspawn.cs
+++ b/MCGalaxy/Commands/World/CmdSetspawn.cs
@@ -26,6 +26,7 @@ namespace MCGalaxy.Commands.World {
public override void Use(Player p, string message) {
if (message.Length > 0) { Help(p); return; }
+ if (!LevelInfo.ValidateAction(p, p.level.name, "set spawn of this level")) return;
Player.Message(p, "Spawn location set to your current position.");
p.level.spawnx = (ushort)p.Pos.BlockX;
p.level.spawny = (ushort)p.Pos.BlockY;
diff --git a/MCGalaxy/Commands/other/CmdBack.cs b/MCGalaxy/Commands/other/CmdBack.cs
index 0aba0c157..5ea1b0df6 100644
--- a/MCGalaxy/Commands/other/CmdBack.cs
+++ b/MCGalaxy/Commands/other/CmdBack.cs
@@ -26,7 +26,7 @@ namespace MCGalaxy.Commands.Misc {
if (p.PreTeleportMap.Length == 0) {
Player.Message(p, "You have not teleported anywhere yet"); return;
}
-
+
if (!p.level.name.CaselessEq(p.PreTeleportMap))
PlayerActions.ChangeMap(p, p.PreTeleportMap);
p.SendPos(Entities.SelfID, p.PreTeleportPos, new Orientation(0, 0));
diff --git a/MCGalaxy/CorePlugin/ConnectHandler.cs b/MCGalaxy/CorePlugin/ConnectHandler.cs
index 53e16557b..1b35b8803 100644
--- a/MCGalaxy/CorePlugin/ConnectHandler.cs
+++ b/MCGalaxy/CorePlugin/ConnectHandler.cs
@@ -61,7 +61,7 @@ namespace MCGalaxy.Core {
static void LoadWaypoints(Player p) {
try {
- p.Waypoints.Filename = "extra/Waypoints/" + p.name + ".save";
+ p.Waypoints.Filename = "extra/Waypoints/" + p.name + ".save";
p.Waypoints.Load();
} catch (IOException ex) {
Player.Message(p, "Error loading waypoints.");
diff --git a/MCGalaxy/CorePlugin/CorePlugin.cs b/MCGalaxy/CorePlugin/CorePlugin.cs
index 99ddcb257..f7bcf280f 100644
--- a/MCGalaxy/CorePlugin/CorePlugin.cs
+++ b/MCGalaxy/CorePlugin/CorePlugin.cs
@@ -41,7 +41,7 @@ namespace MCGalaxy.Core {
OnEcoTransactionEvent.Register(EcoHandlers.HandleEcoTransaction, Priority.Critical);
OnModActionEvent.Register(ModActionHandler.HandleModAction, Priority.Critical);
- OnGroupLoadEvent.Register(MiscHandlers.HandleGroupLoad, Priority.Critical);
+ OnGroupLoadEvent.Register(MiscHandlers.HandleGroupLoad, Priority.Critical);
clearTask = Server.Background.QueueRepeat(IPThrottler.CleanupTask, null,
TimeSpan.FromMinutes(10));
diff --git a/MCGalaxy/Database/Stats/TopStat.cs b/MCGalaxy/Database/Stats/TopStat.cs
index 22ffa303b..5a07e0b5d 100644
--- a/MCGalaxy/Database/Stats/TopStat.cs
+++ b/MCGalaxy/Database/Stats/TopStat.cs
@@ -27,7 +27,7 @@ namespace MCGalaxy.DB {
/// Formats a value in a column.
public delegate string TopStatFormatter(string input);
-
+
/// Outputs ordered stats from a column in a database table.
public sealed class TopStat {
diff --git a/MCGalaxy/Drawing/DrawOps/BezierDrawOp.cs b/MCGalaxy/Drawing/DrawOps/BezierDrawOp.cs
index 6f9956528..2d1780ab7 100644
--- a/MCGalaxy/Drawing/DrawOps/BezierDrawOp.cs
+++ b/MCGalaxy/Drawing/DrawOps/BezierDrawOp.cs
@@ -21,70 +21,70 @@ using MCGalaxy.Drawing.Brushes;
using MCGalaxy.Maths;
namespace MCGalaxy.Drawing.Ops {
- public class BezierDrawOp : DrawOp {
- public override string Name { get { return "Bezier"; } }
- public bool WallsMode;
- public int MaxLength = int.MaxValue;
-
- public override long BlocksAffected(Level lvl, Vec3S32[] marks) {
- Vec3S32 p0 = marks[0], p2 = marks[1], p1 = marks[2];
- return (long)((p1 - p0).Length + (p1 - p2).Length);
- }
+ public class BezierDrawOp : DrawOp {
+ public override string Name { get { return "Bezier"; } }
+ public bool WallsMode;
+ public int MaxLength = int.MaxValue;
+
+ public override long BlocksAffected(Level lvl, Vec3S32[] marks) {
+ Vec3S32 p0 = marks[0], p2 = marks[1], p1 = marks[2];
+ return (long)((p1 - p0).Length + (p1 - p2).Length);
+ }
- static Vec3F32 offset = new Vec3F32(0.5f);
- public override void Perform(Vec3S32[] marks, Brush brush, DrawOpOutput output) {
- points.Add(marks[0]);
- // Want to rasterize bezier curve from centre of 'grid'
- TesselateCurve(marks[0] + offset, marks[2] + offset, marks[1] + offset, 0);
-
- List buffer = new List();
- for (int i = 0; i < points.Count - 1; i++) {
- LineDrawOp.DrawLine(points[i].X, points[i].Y, points[i].Z, 1000000,
- points[i+1].X, points[i+1].Y, points[i+1].Z, buffer);
-
- foreach (Vec3S32 P in buffer) {
- output(Place((ushort)P.X, (ushort)P.Y, (ushort)P.Z, brush));
- }
- }
- }
-
- List points = new List();
- const float objspace_flatness_squared = 0.35f * 0.35f;
-
- // Based off stbtt__tesselate_curve from https://github.com/nothings/stb/blob/master/stb_truetype.h
- void TesselateCurve(Vec3F32 p0, Vec3F32 p1, Vec3F32 p2, int n) {
- // midpoint
- Vec3F32 m;
- m.X = (p0.X + 2 * p1.X + p2.X) * 0.25f;
- m.Y = (p0.Y + 2 * p1.Y + p2.Y) * 0.25f;
- m.Z = (p0.Z + 2 * p1.Z + p2.Z) * 0.25f;
-
- // versus directly drawn line
- Vec3F32 d;
- d.X = (p0.X + p2.X) * 0.5f - m.X;
- d.Y = (p0.Y + p2.Y) * 0.5f - m.Y;
- d.Z = (p0.Z + p2.Z) * 0.5f - m.Z;
-
- if (n > 16) return; // 65536 segments on one curve better be enough!
-
- // half-pixel error allowed... need to be smaller if AA
- if (d.X * d.X + d.Y * d.Y + d.Z * d.Z > objspace_flatness_squared) {
- Vec3F32 p0_p1 = new Vec3F32((p0.X + p1.X) * 0.5f, (p0.Y + p1.Y) * 0.5f, (p0.Z + p1.Z) * 0.5f);
- TesselateCurve(p0, p0_p1, m, n + 1);
-
- Vec3F32 p1_p2 = new Vec3F32((p1.X + p2.X) * 0.5f, (p1.Y + p2.Y) * 0.5f, (p1.Z + p2.Z) * 0.5f);
- TesselateCurve(m, p1_p2, p2, n + 1);
- } else {
- // TODO: do we need to round properly here or not
- points.Add(new Vec3S32((int)p2.X, (int)p2.Y, (int)p2.Z));
- }
- }
+ static Vec3F32 offset = new Vec3F32(0.5f);
+ public override void Perform(Vec3S32[] marks, Brush brush, DrawOpOutput output) {
+ points.Add(marks[0]);
+ // Want to rasterize bezier curve from centre of 'grid'
+ TesselateCurve(marks[0] + offset, marks[2] + offset, marks[1] + offset, 0);
+
+ List buffer = new List();
+ for (int i = 0; i < points.Count - 1; i++) {
+ LineDrawOp.DrawLine(points[i].X, points[i].Y, points[i].Z, 1000000,
+ points[i+1].X, points[i+1].Y, points[i+1].Z, buffer);
+
+ foreach (Vec3S32 P in buffer) {
+ output(Place((ushort)P.X, (ushort)P.Y, (ushort)P.Z, brush));
+ }
+ }
+ }
+
+ List points = new List();
+ const float objspace_flatness_squared = 0.35f * 0.35f;
+
+ // Based off stbtt__tesselate_curve from https://github.com/nothings/stb/blob/master/stb_truetype.h
+ void TesselateCurve(Vec3F32 p0, Vec3F32 p1, Vec3F32 p2, int n) {
+ // midpoint
+ Vec3F32 m;
+ m.X = (p0.X + 2 * p1.X + p2.X) * 0.25f;
+ m.Y = (p0.Y + 2 * p1.Y + p2.Y) * 0.25f;
+ m.Z = (p0.Z + 2 * p1.Z + p2.Z) * 0.25f;
+
+ // versus directly drawn line
+ Vec3F32 d;
+ d.X = (p0.X + p2.X) * 0.5f - m.X;
+ d.Y = (p0.Y + p2.Y) * 0.5f - m.Y;
+ d.Z = (p0.Z + p2.Z) * 0.5f - m.Z;
+
+ if (n > 16) return; // 65536 segments on one curve better be enough!
+
+ // half-pixel error allowed... need to be smaller if AA
+ if (d.X * d.X + d.Y * d.Y + d.Z * d.Z > objspace_flatness_squared) {
+ Vec3F32 p0_p1 = new Vec3F32((p0.X + p1.X) * 0.5f, (p0.Y + p1.Y) * 0.5f, (p0.Z + p1.Z) * 0.5f);
+ TesselateCurve(p0, p0_p1, m, n + 1);
+
+ Vec3F32 p1_p2 = new Vec3F32((p1.X + p2.X) * 0.5f, (p1.Y + p2.Y) * 0.5f, (p1.Z + p2.Z) * 0.5f);
+ TesselateCurve(m, p1_p2, p2, n + 1);
+ } else {
+ // TODO: do we need to round properly here or not
+ points.Add(new Vec3S32((int)p2.X, (int)p2.Y, (int)p2.Z));
+ }
+ }
- /*static ushort Round(float value) {
- int valueI = (int)value;
- int floored = value < valueI ? valueI - 1 : valueI;
- float frac = (value % 1.0f);
- return (ushort)(floored + (frac > 0.5f ? 1 : 0));
- }*/
- }
+ /*static ushort Round(float value) {
+ int valueI = (int)value;
+ int floored = value < valueI ? valueI - 1 : valueI;
+ float frac = (value % 1.0f);
+ return (ushort)(floored + (frac > 0.5f ? 1 : 0));
+ }*/
+ }
}
diff --git a/MCGalaxy/Drawing/DrawOps/DrawOp.cs b/MCGalaxy/Drawing/DrawOps/DrawOp.cs
index b97007b88..ea598e050 100644
--- a/MCGalaxy/Drawing/DrawOps/DrawOp.cs
+++ b/MCGalaxy/Drawing/DrawOps/DrawOp.cs
@@ -30,9 +30,9 @@ namespace MCGalaxy {
}
namespace MCGalaxy.Drawing.Ops {
-
- /// Performs on action on a block output from a draw operation.
- public delegate void DrawOpOutput(DrawOpBlock block);
+
+ /// Performs on action on a block output from a draw operation.
+ public delegate void DrawOpOutput(DrawOpBlock block);
public abstract partial class DrawOp {
diff --git a/MCGalaxy/Drawing/DrawOps/DrawOpPerformer.cs b/MCGalaxy/Drawing/DrawOps/DrawOpPerformer.cs
index 1ab28b059..9c30d5b13 100644
--- a/MCGalaxy/Drawing/DrawOps/DrawOpPerformer.cs
+++ b/MCGalaxy/Drawing/DrawOps/DrawOpPerformer.cs
@@ -192,7 +192,7 @@ namespace MCGalaxy.Drawing.Ops {
// Potentially buffer the block change
if (op.TotalModified == reloadThreshold) {
if (p == null || !p.Ignores.DrawOutput) {
- Player.Message(p, "Changed over {0} blocks, preparing to reload map..", reloadThreshold);
+ Player.Message(p, "Changed over {0} blocks, preparing to reload map..", reloadThreshold);
}
lock (lvl.queueLock)
diff --git a/MCGalaxy/Drawing/Image/PixelGetter.cs b/MCGalaxy/Drawing/Image/PixelGetter.cs
index c5d8ba524..0251cd30f 100644
--- a/MCGalaxy/Drawing/Image/PixelGetter.cs
+++ b/MCGalaxy/Drawing/Image/PixelGetter.cs
@@ -23,7 +23,7 @@ using MCGalaxy.Drawing.Ops;
namespace MCGalaxy.Drawing {
public delegate void PixelGetterCallback(Pixel pixel, DrawOpOutput output);
-
+
public sealed class PixelGetter : IDisposable {
Bitmap bmp;
diff --git a/MCGalaxy/Economy/Awards.cs b/MCGalaxy/Economy/Awards.cs
index 5be442f62..816c4e079 100644
--- a/MCGalaxy/Economy/Awards.cs
+++ b/MCGalaxy/Economy/Awards.cs
@@ -70,7 +70,7 @@ namespace MCGalaxy.Eco {
if (value.IndexOf(',') != -1) {
foreach (string award in value.Split(',')) {
pl.Awards.Add(award);
- }
+ }
} else {
pl.Awards.Add(value);
}
diff --git a/MCGalaxy/Games/ZombieSurvival/ZSConfig.cs b/MCGalaxy/Games/ZombieSurvival/ZSConfig.cs
index 418c14a8f..2181dce82 100644
--- a/MCGalaxy/Games/ZombieSurvival/ZSConfig.cs
+++ b/MCGalaxy/Games/ZombieSurvival/ZSConfig.cs
@@ -128,9 +128,9 @@ namespace MCGalaxy.Games {
}
static void ZSLineProcessor(string key, string value) {
- if (!ConfigElement.Parse(Server.zombieConfig, key, value, null)) {
+ if (!ConfigElement.Parse(Server.zombieConfig, key, value, null)) {
Logger.Log(LogType.Warning, "\"{0}\" was not a recognised zombie survival property key.", key);
- }
+ }
}
}
}
diff --git a/MCGalaxy/Generator/MapGen.cs b/MCGalaxy/Generator/MapGen.cs
index 7e8a7857b..b93f2fb82 100644
--- a/MCGalaxy/Generator/MapGen.cs
+++ b/MCGalaxy/Generator/MapGen.cs
@@ -20,7 +20,7 @@ using System.Collections.Generic;
namespace MCGalaxy.Generator {
- /// Holds arguments for a map generator.
+ /// Holds arguments for a map generator.
public struct MapGenArgs {
public Player Player;
public Level Level;
@@ -28,9 +28,9 @@ namespace MCGalaxy.Generator {
public bool UseSeed;
public int Seed;
}
-
- /// Represents a map generator, returning whether map generation succeeded or not.
- public delegate bool MapGenerator(MapGenArgs args);
+
+ /// Represents a map generator, returning whether map generation succeeded or not.
+ public delegate bool MapGenerator(MapGenArgs args);
/// Maintains a list of map generator instances.
public static class MapGen {
diff --git a/MCGalaxy/Generator/RealisticGenParams.cs b/MCGalaxy/Generator/RealisticGenParams.cs
index e6d3d50f6..8c336be15 100644
--- a/MCGalaxy/Generator/RealisticGenParams.cs
+++ b/MCGalaxy/Generator/RealisticGenParams.cs
@@ -19,9 +19,9 @@ using System;
using System.Collections.Generic;
namespace MCGalaxy.Generator {
-
+
public delegate ushort CalcLiquidLevel(ushort lvlHeight);
-
+
public sealed class RealisticGenParams {
public float RangeLow = 0.2f;
public float RangeHigh = 0.8f;
diff --git a/MCGalaxy/Generator/SimpleGen.cs b/MCGalaxy/Generator/SimpleGen.cs
index c6dab5165..5061bbcb7 100644
--- a/MCGalaxy/Generator/SimpleGen.cs
+++ b/MCGalaxy/Generator/SimpleGen.cs
@@ -21,8 +21,8 @@ using System.Collections.Generic;
namespace MCGalaxy.Generator {
public static class SimpleGen {
- delegate byte NextBlock();
-
+ delegate byte NextBlock();
+
public static void RegisterGenerators() {
MapGen.RegisterSimpleGen("island", GenSimple);
MapGen.RegisterSimpleGen("mountains", GenSimple);
diff --git a/MCGalaxy/Levels/LevelConfig.cs b/MCGalaxy/Levels/LevelConfig.cs
index bd18a88c5..70dc2020d 100644
--- a/MCGalaxy/Levels/LevelConfig.cs
+++ b/MCGalaxy/Levels/LevelConfig.cs
@@ -201,7 +201,7 @@ namespace MCGalaxy {
}
- public static bool Load(string path, LevelConfig config) {
+ public static bool Load(string path, LevelConfig config) {
return PropertiesFile.Read(path, ref config, LineProcessor);
}
diff --git a/MCGalaxy/Levels/LevelInfo.cs b/MCGalaxy/Levels/LevelInfo.cs
index d0feba545..88bf83f93 100644
--- a/MCGalaxy/Levels/LevelInfo.cs
+++ b/MCGalaxy/Levels/LevelInfo.cs
@@ -88,32 +88,36 @@ namespace MCGalaxy {
public static string PropertiesPath(string name) {
return "levels/level properties/" + name + ".properties";
}
-
- public static string FindOfflineProperty(string name, string propKey) {
- string path = PropertiesPath(name);
- if (!File.Exists(path)) return null;
-
- string[] lines = null;
- try {
- lines = File.ReadAllLines(path);
- } catch {
- return null;
+ internal static LevelConfig GetConfig(string map, out Level lvl) {
+ lvl = FindExact(map);
+ if (lvl != null) return lvl.Config;
+
+ string propsPath = PropertiesPath(map);
+ LevelConfig cfg = new LevelConfig();
+ LevelConfig.Load(propsPath, cfg);
+ return cfg;
+ }
+
+ internal static bool ValidateAction(Player p, string map, string action) {
+ if (p == null) return true;
+ LevelAccessController visit, build;
+ Level lvl = null;
+ LevelConfig cfg = GetConfig(map, out lvl);
+
+ if (lvl != null) {
+ visit = lvl.VisitAccess;
+ build = lvl.BuildAccess;
+ } else {
+ visit = new LevelAccessController(cfg, map, true);
+ build = new LevelAccessController(cfg, map, false);
}
- foreach (string line in lines) {
- try {
- if (line.Length == 0 || line[0] == '#') continue;
- int index = line.IndexOf(" = ");
- if (index == -1) continue;
-
- string key = line.Substring(0, index).ToLower();
- if (key == propKey) return line.Substring(index + 3);
- } catch (Exception e) {
- Logger.LogError(e);
- }
+ if (!visit.CheckDetailed(p) || !build.CheckDetailed(p)) {
+ Player.Message(p, "Hence, you cannot {0}.", action);
+ return false;
}
- return null;
+ return true;
}
}
}
\ No newline at end of file
diff --git a/MCGalaxy/Plugins/PluginManager.cs b/MCGalaxy/Plugins/PluginManager.cs
index 465d5e3c4..89e39cb6b 100644
--- a/MCGalaxy/Plugins/PluginManager.cs
+++ b/MCGalaxy/Plugins/PluginManager.cs
@@ -89,7 +89,7 @@ namespace MCGalaxy {
instance.Load(startup);
Logger.Log(LogType.SystemActivity, "Plugin: {0} loaded...build: {1}", instance.name, instance.build);
} else {
- Logger.Log(LogType.SystemActivity, "Plugin: {0} was not loaded, you can load it with /pload", instance.name);
+ Logger.Log(LogType.SystemActivity, "Plugin: {0} was not loaded, you can load it with /pload", instance.name);
}
Logger.Log(LogType.SystemActivity, instance.welcome);
} catch (Exception e) {
diff --git a/MCGalaxy/Scripting/Scripting.cs b/MCGalaxy/Scripting/Scripting.cs
index 35ed7aa0e..fe3a2fb21 100644
--- a/MCGalaxy/Scripting/Scripting.cs
+++ b/MCGalaxy/Scripting/Scripting.cs
@@ -50,8 +50,8 @@ namespace MCGalaxy.Scripting {
compiler = CodeDomProvider.CreateProvider(ProviderName);
if (compiler == null) {
Logger.Log(LogType.Warning,
- "WARNING: Provider {0} is missing, you will be unable to compile {1} commands.",
- ProviderName, Ext);
+ "WARNING: Provider {0} is missing, you will be unable to compile {1} commands.",
+ ProviderName, Ext);
// TODO: Should we log "You must have .net developer tools. (You need a visual studio)" ?
}
}
diff --git a/MCGalaxy/Server/Server.Init.cs b/MCGalaxy/Server/Server.Init.cs
index 7752b8e1d..2344f4009 100644
--- a/MCGalaxy/Server/Server.Init.cs
+++ b/MCGalaxy/Server/Server.Init.cs
@@ -91,7 +91,7 @@ namespace MCGalaxy {
}
static void SetupSocket(SchedulerTask task) {
- Logger.Log(LogType.SystemActivity, "Creating listening socket on port {0}... ", ServerConfig.Port);
+ Logger.Log(LogType.SystemActivity, "Creating listening socket on port {0}... ", ServerConfig.Port);
Listener = new TcpListen();
IPAddress ip;
diff --git a/MCGalaxy/util/App.cs b/MCGalaxy/util/App.cs
index 3d2abbd5b..39bec13e9 100644
--- a/MCGalaxy/util/App.cs
+++ b/MCGalaxy/util/App.cs
@@ -56,7 +56,7 @@ namespace MCGalaxy.Gui {
}
} catch (Exception ex) {
Logger.LogError(ex);
- }
+ }
try {
string level = null;