mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-22 12:05:51 -04:00
few less allocations
This commit is contained in:
parent
dd02b68dcb
commit
c7ce45e64c
@ -61,7 +61,7 @@ namespace MCGalaxy.Blocks {
|
||||
}
|
||||
|
||||
public void MessageCannotUse(Player p, string action) {
|
||||
Player.Message(p, "Only {0} can {1} {2}",
|
||||
Player.Message(p, "Only {0} can {1} {2}",
|
||||
Describe(), action, Block.GetName(p, ID));
|
||||
}
|
||||
|
||||
@ -92,8 +92,9 @@ namespace MCGalaxy.Blocks {
|
||||
|
||||
// Custom permissions set by the user.
|
||||
if (File.Exists(Paths.BlockPermsFile)) {
|
||||
string[] lines = File.ReadAllLines(Paths.BlockPermsFile);
|
||||
ProcessLines(lines);
|
||||
using (StreamReader r = new StreamReader(Paths.BlockPermsFile)) {
|
||||
ProcessLines(r);
|
||||
}
|
||||
} else {
|
||||
Save();
|
||||
}
|
||||
@ -103,9 +104,11 @@ namespace MCGalaxy.Blocks {
|
||||
}
|
||||
}
|
||||
|
||||
static void ProcessLines(string[] lines) {
|
||||
static void ProcessLines(StreamReader r) {
|
||||
string[] args = new string[4];
|
||||
foreach (string line in lines) {
|
||||
string line;
|
||||
|
||||
while ((line = r.ReadLine()) != null) {
|
||||
if (line.Length == 0 || line[0] == '#') continue;
|
||||
// Format - ID : Lowest : Disallow : Allow
|
||||
line.Replace(" ", "").FixedSplit(args, ':');
|
||||
|
@ -109,36 +109,37 @@ namespace MCGalaxy.Commands {
|
||||
lock (ioLock) {
|
||||
if (!File.Exists(Paths.CmdExtraPermsFile)) Save();
|
||||
|
||||
LoadCore();
|
||||
using (StreamReader r = new StreamReader(Paths.CmdExtraPermsFile)) {
|
||||
ProcessLines(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void LoadCore() {
|
||||
static void ProcessLines(StreamReader r) {
|
||||
string[] args = new string[5];
|
||||
using (StreamReader r = new StreamReader(Paths.CmdExtraPermsFile)) {
|
||||
string line;
|
||||
while ((line = r.ReadLine()) != null) {
|
||||
if (line.Length == 0 || line[0] == '#' || line.IndexOf(':') == -1) continue;
|
||||
// Format - Name:Num : Lowest : Disallow : Allow
|
||||
line.Replace(" ", "").FixedSplit(args, ':');
|
||||
string line;
|
||||
|
||||
while ((line = r.ReadLine()) != null) {
|
||||
if (line.Length == 0 || line[0] == '#' || line.IndexOf(':') == -1) continue;
|
||||
// Format - Name:Num : Lowest : Disallow : Allow
|
||||
line.Replace(" ", "").FixedSplit(args, ':');
|
||||
|
||||
try {
|
||||
LevelPermission min;
|
||||
List<LevelPermission> allowed, disallowed;
|
||||
|
||||
try {
|
||||
LevelPermission min;
|
||||
List<LevelPermission> allowed, disallowed;
|
||||
|
||||
// Old format - Name:Num : Lowest : Description
|
||||
if (IsDescription(args[3])) {
|
||||
min = (LevelPermission)int.Parse(args[2]);
|
||||
allowed = null; disallowed = null;
|
||||
} else {
|
||||
Deserialise(args, 2, out min, out allowed, out disallowed);
|
||||
}
|
||||
|
||||
Set(args[0], int.Parse(args[1]), "", min, allowed, disallowed);
|
||||
} catch (Exception ex) {
|
||||
Logger.Log(LogType.Warning, "Hit an error on the extra command perms " + line);
|
||||
Logger.LogError(ex);
|
||||
// Old format - Name:Num : Lowest : Description
|
||||
if (IsDescription(args[3])) {
|
||||
min = (LevelPermission)int.Parse(args[2]);
|
||||
allowed = null; disallowed = null;
|
||||
} else {
|
||||
Deserialise(args, 2, out min, out allowed, out disallowed);
|
||||
}
|
||||
|
||||
Set(args[0], int.Parse(args[1]), "", min, allowed, disallowed);
|
||||
} catch (Exception ex) {
|
||||
Logger.Log(LogType.Warning, "Hit an error on the extra command perms " + line);
|
||||
Logger.LogError(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -97,8 +97,9 @@ namespace MCGalaxy.Commands {
|
||||
}
|
||||
|
||||
if (File.Exists(Paths.CmdPermsFile)) {
|
||||
string[] lines = File.ReadAllLines(Paths.CmdPermsFile);
|
||||
ProcessLines(lines);
|
||||
using (StreamReader r = new StreamReader(Paths.CmdPermsFile)) {
|
||||
ProcessLines(r);
|
||||
}
|
||||
} else {
|
||||
Save();
|
||||
}
|
||||
@ -108,9 +109,11 @@ namespace MCGalaxy.Commands {
|
||||
}
|
||||
}
|
||||
|
||||
static void ProcessLines(string[] lines) {
|
||||
static void ProcessLines(StreamReader r) {
|
||||
string[] args = new string[4];
|
||||
foreach (string line in lines) {
|
||||
string line;
|
||||
|
||||
while ((line = r.ReadLine()) != null) {
|
||||
if (line.Length == 0 || line[0] == '#') continue;
|
||||
// Format - Name : Lowest : Disallow : Allow
|
||||
line.Replace(" ", "").FixedSplit(args, ':');
|
||||
@ -120,7 +123,7 @@ namespace MCGalaxy.Commands {
|
||||
List<LevelPermission> allowed, disallowed;
|
||||
|
||||
Deserialise(args, 1, out min, out allowed, out disallowed);
|
||||
Set(args[0], min, allowed, disallowed);
|
||||
Set(args[0], min, allowed, disallowed);
|
||||
} catch {
|
||||
Logger.Log(LogType.Warning, "Hit an error on the command " + line); continue;
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ namespace MCGalaxy.Commands.Moderation {
|
||||
|
||||
List<string> reports = new List<string>();
|
||||
if (File.Exists("extra/reported/" + target + ".txt")) {
|
||||
reports = new List<string>(File.ReadAllLines("extra/reported/" + target + ".txt"));
|
||||
reports = Utils.ReadAllLinesList("extra/reported/" + target + ".txt");
|
||||
}
|
||||
|
||||
ItemPerms checkPerms = CommandExtraPerms.Find(name, 1);
|
||||
|
@ -30,8 +30,8 @@ namespace MCGalaxy.Commands.Building {
|
||||
public override LevelPermission defaultRank { get { return LevelPermission.Admin; } }
|
||||
|
||||
public override void Use(Player p, string message) {
|
||||
BrushArgs args = new BrushArgs(p, message.ToLower(), Block.Air);
|
||||
Brush brush = BrushFactory.Find("replace").Construct(args);
|
||||
BrushArgs args = new BrushArgs(p, message, Block.Air);
|
||||
Brush brush = BrushFactory.Find("Replace").Construct(args);
|
||||
if (brush == null) return;
|
||||
|
||||
Vec3S32 max = new Vec3S32(p.level.Width - 1, p.level.Height - 1, p.level.Length - 1);
|
||||
|
@ -38,9 +38,9 @@ namespace MCGalaxy {
|
||||
char separator = '=', bool trimValue = true) {
|
||||
if (!File.Exists(path)) return false;
|
||||
|
||||
using (StreamReader reader = new StreamReader(path)) {
|
||||
using (StreamReader r = new StreamReader(path)) {
|
||||
string line, key, value;
|
||||
while ((line = reader.ReadLine()) != null) {
|
||||
while ((line = r.ReadLine()) != null) {
|
||||
ParseLine(line, separator, out key, out value);
|
||||
if (key == null) continue;
|
||||
|
||||
|
@ -22,12 +22,12 @@ using BlockID = System.UInt16;
|
||||
|
||||
namespace MCGalaxy.Drawing.Brushes {
|
||||
|
||||
/// <summary> Contains helper methods for brushes that have blocks with
|
||||
/// <summary> Contains helper methods for brushes that have blocks with
|
||||
/// optional frequency counts (e.g. random and cloudy brushes) </summary>
|
||||
public static class FrequencyBrush {
|
||||
|
||||
public static BlockID[] GetBlocks(BrushArgs args, out int[] count,
|
||||
Predicate<string> argFilter, Predicate<string> argHandler) {
|
||||
Predicate<string> argFilter, Predicate<string> argHandler) {
|
||||
string[] parts = args.Message.SplitSpaces();
|
||||
Player p = args.Player;
|
||||
BlockID[] blocks;
|
||||
@ -45,18 +45,14 @@ namespace MCGalaxy.Drawing.Brushes {
|
||||
continue;
|
||||
}
|
||||
|
||||
BlockID block;
|
||||
int sepIndex = parts[i].IndexOf('/');
|
||||
string name = sepIndex >= 0 ? parts[i].Substring(0, sepIndex) : parts[i];
|
||||
if (!CommandParser.GetBlockIfAllowed(p, name, out block, true)) return null;
|
||||
int sepIndex = parts[i].IndexOf('/');
|
||||
string arg = sepIndex >= 0 ? parts[i].Substring(0, sepIndex) : parts[i];
|
||||
if (!CommandParser.GetBlockIfAllowed(p, arg, out blocks[j], true)) return null;
|
||||
|
||||
blocks[j] = block;
|
||||
if (sepIndex < 0) { j++; continue; }
|
||||
|
||||
int chance = 0;
|
||||
if (!CommandParser.GetInt(p, parts[i].Substring(sepIndex + 1), "Frequency", ref chance, 1, 10000)) return null;
|
||||
|
||||
count[j] = chance;
|
||||
if (sepIndex >= 0) {
|
||||
arg = parts[i].Substring(sepIndex + 1);
|
||||
if (!CommandParser.GetInt(p, arg, "Frequency", ref count[j], 1, 10000)) return null;
|
||||
}
|
||||
j++;
|
||||
}
|
||||
return blocks;
|
||||
@ -96,7 +92,7 @@ namespace MCGalaxy.Drawing.Brushes {
|
||||
}
|
||||
|
||||
public sealed class RandomBrushFactory : BrushFactory {
|
||||
public override string Name { get { return "Random"; } }
|
||||
public override string Name { get { return "Random"; } }
|
||||
public override string[] Help { get { return HelpString; } }
|
||||
|
||||
static string[] HelpString = new string[] {
|
||||
|
@ -41,7 +41,7 @@ namespace MCGalaxy.Games {
|
||||
if (Running) EndRound();
|
||||
if (Running) VoteAndMoveToNextMap();
|
||||
}
|
||||
|
||||
|
||||
protected override bool SetMap(string map) {
|
||||
bool success = base.SetMap(map);
|
||||
if (success) UpdateMapConfig();
|
||||
|
@ -46,23 +46,23 @@ namespace MCGalaxy {
|
||||
public string Color;
|
||||
public string ColoredName { get { return Color + Name; } }
|
||||
|
||||
[ConfigInt("Limit", null, 0)]
|
||||
[ConfigInt("Limit", null, 0, 0)]
|
||||
public int DrawLimit;
|
||||
[ConfigInt("MaxUndo", null, 0)]
|
||||
[ConfigInt("MaxUndo", null, 0, 0)]
|
||||
public int MaxUndo;
|
||||
[ConfigString("MOTD", null, "", true)]
|
||||
public string MOTD = "";
|
||||
[ConfigInt("GenVolume", null, mapGenLimit)]
|
||||
public int GenVolume = mapGenLimit;
|
||||
[ConfigInt("OSMaps", null, 3)]
|
||||
[ConfigInt("OSMaps", null, 3, 0)]
|
||||
public int OverseerMaps = 3;
|
||||
[ConfigBool("AfkKicked", null, true)]
|
||||
public bool AfkKicked = true;
|
||||
[ConfigInt("AfkKickMinutes", null, 45)]
|
||||
[ConfigInt("AfkKickMinutes", null, 45, 0)]
|
||||
public int AfkKickMinutes = 45;
|
||||
[ConfigString("Prefix", null, "", true)]
|
||||
public string Prefix = "";
|
||||
[ConfigInt("CopySlots", null, 0)]
|
||||
[ConfigInt("CopySlots", null, 0, 0)]
|
||||
public int CopySlots = 1;
|
||||
[ConfigString("Filename", null, "", true, ".,_-+=")]
|
||||
internal string filename;
|
||||
|
@ -683,7 +683,10 @@ namespace MCGalaxy {
|
||||
|
||||
byte bindIndex;
|
||||
if (byte.TryParse(cmdName, out bindIndex) && bindIndex < CmdBindings.Length) {
|
||||
if (CmdArgsBindings[bindIndex] == null) { SendMessage("No command is bound to: /" + cmdName); return null; }
|
||||
if (CmdArgsBindings[bindIndex] == null) {
|
||||
SendMessage("No command is bound to: %T/" + cmdName); return null;
|
||||
}
|
||||
|
||||
cmdName = CmdBindings[bindIndex];
|
||||
cmdArgs = CmdArgsBindings[bindIndex] + " " + cmdArgs;
|
||||
cmdArgs = cmdArgs.TrimEnd(' ');
|
||||
@ -695,7 +698,7 @@ namespace MCGalaxy {
|
||||
Command command = Command.Find(cmdName);
|
||||
if (command == null) {
|
||||
if (Block.Parse(this, cmdName) != Block.Invalid) {
|
||||
cmdArgs = cmdName.ToLower(); cmdName = "mode";
|
||||
cmdArgs = cmdName; cmdName = "mode";
|
||||
command = Command.Find("Mode");
|
||||
} else {
|
||||
Logger.Log(LogType.CommandUsage, "{0} tried to use unknown command: /{1} {2}", name, cmdName, cmdArgs);
|
||||
|
@ -34,10 +34,8 @@ namespace MCGalaxy.Scripting {
|
||||
public const string DllDir = "extra/commands/dll/";
|
||||
public const string ErrorPath = "logs/errors/compiler.log";
|
||||
|
||||
static readonly string divider = new string('-', 25);
|
||||
static readonly string divider = new string('-', 25);
|
||||
protected CodeDomProvider compiler;
|
||||
protected CompilerParameters args = new CompilerParameters();
|
||||
protected CompilerResults results;
|
||||
|
||||
public abstract string Ext { get; }
|
||||
public abstract string ProviderName { get; }
|
||||
@ -94,7 +92,7 @@ namespace MCGalaxy.Scripting {
|
||||
args.OutputAssembly = dstPath;
|
||||
|
||||
List<string> source = ReadSourceCode(srcPath, args);
|
||||
results = CompileSource(source.Join(Environment.NewLine), args);
|
||||
CompilerResults results = CompileSource(source.Join(Environment.NewLine), args);
|
||||
if (!results.Errors.HasErrors) return true;
|
||||
|
||||
sb = new StringBuilder();
|
||||
|
@ -109,11 +109,11 @@ namespace MCGalaxy {
|
||||
}
|
||||
}
|
||||
|
||||
static string NextStatement(StreamReader reader, List<string> buffer) {
|
||||
static string NextStatement(StreamReader r, List<string> buffer) {
|
||||
buffer.Clear();
|
||||
string line = null;
|
||||
|
||||
while ((line = reader.ReadLine()) != null) {
|
||||
while ((line = r.ReadLine()) != null) {
|
||||
if (line.StartsWith("--")) continue; // comment
|
||||
line = line.Trim();
|
||||
if (line.Length == 0) continue; // whitespace
|
||||
|
@ -151,8 +151,8 @@ namespace MCGalaxy.Tasks {
|
||||
if (!File.Exists(Paths.TempRanksFile)) return;
|
||||
|
||||
// Check if empty, or not old form
|
||||
using (StreamReader reader = new StreamReader(Paths.TempRanksFile)) {
|
||||
string line = reader.ReadLine();
|
||||
using (StreamReader r = new StreamReader(Paths.TempRanksFile)) {
|
||||
string line = r.ReadLine();
|
||||
if (line == null) return;
|
||||
string[] parts = line.SplitSpaces();
|
||||
if (parts.Length < 9) return;
|
||||
|
Loading…
x
Reference in New Issue
Block a user