Can use pervisit/perbuild on unloaded maps too

This commit is contained in:
UnknownShadow200 2018-04-01 10:55:37 +10:00
parent 7a1cdbc4ed
commit d140333461
9 changed files with 72 additions and 91 deletions

View File

@ -87,7 +87,7 @@ namespace MCGalaxy.Commands.Info {
DataRow row = Blocks.Rows[i];
string name = row["Username"].ToString().Trim();
DateTime time = DateTime.Parse(row["TimePerformed"].ToString());
DateTime time = PlayerData.ParseDate(row["TimePerformed"]);
TimeSpan delta = time - BlockDB.Epoch;
entry.TimeDelta = (int)delta.TotalSeconds;
entry.Flags = BlockDBFlags.ManualPlace;

View File

@ -53,11 +53,18 @@ namespace MCGalaxy.Commands.World {
Command.SuperRequiresArgs(name, p, "level"); return;
}
Level level = args.Length == 1 ? p.level : Matcher.FindLevels(p, args[0]);
if (level == null) return;
string map = args.Length == 1 ? p.level.name : Matcher.FindMaps(p, args[0]);
if (map == null) return;
Level lvl;
LevelConfig cfg = LevelInfo.GetConfig(map, out lvl);
int offset = args.Length == 1 ? 0 : 1;
AccessController access = visit ? level.VisitAccess : level.BuildAccess;
AccessController access;
if (lvl == null) {
access = new LevelAccessController(cfg, map, visit);
} else {
access = visit ? lvl.VisitAccess : lvl.BuildAccess;
}
Do(p, args, offset, max, access);
}

View File

@ -129,7 +129,7 @@ namespace MCGalaxy.DB {
return data;
}
static DateTime ParseDate(object value) {
internal static DateTime ParseDate(object value) {
if (value is DateTime) return (DateTime)value;
return DateTime.Parse(value.ToString());
}

View File

@ -198,16 +198,9 @@ namespace MCGalaxy {
public sealed class LevelAccessController : AccessController {
public readonly bool IsVisit;
readonly Level lvl;
readonly LevelConfig cfg;
readonly string lvlName;
public LevelAccessController(Level lvl, bool isVisit) {
this.lvl = lvl;
this.cfg = lvl.Config;
IsVisit = isVisit;
}
public LevelAccessController(LevelConfig cfg, string levelName, bool isVisit) {
this.cfg = cfg;
this.lvlName = levelName;
@ -238,9 +231,7 @@ namespace MCGalaxy {
get { return IsVisit ? cfg.VisitBlacklist : cfg.BuildBlacklist; }
}
protected override string ColoredName {
get { return lvl != null ? lvl.ColoredName : cfg.Color + lvlName; }
}
protected override string ColoredName { get { return cfg.Color + lvlName; } }
protected override string Action { get { return IsVisit ? "go to" : "build in"; } }
protected override string ActionIng { get { return IsVisit ? "going to" : "building in"; } }
protected override string Type { get { return IsVisit ? "visit" : "build"; } }
@ -248,12 +239,8 @@ namespace MCGalaxy {
public override void OnPermissionChanged(Player p, Group grp, string type) {
Update();
Logger.Log(LogType.UserActivity, "{0} rank changed to {1} on {2}.", type, grp.Name, lvl.name);
Chat.MessageLevel(lvl, type + " rank changed to " + grp.ColoredName + "%S.");
if (p != null && p.level != lvl) {
Player.Message(p, "{0} rank changed to {1} %Son {2}%S.", type, grp.ColoredName, ColoredName);
}
string msg = type + " rank changed to " + grp.ColoredName;
DoChange(p, msg);
}
public override void OnListChanged(Player p, string name, bool whitelist, bool removedFromOpposite) {
@ -264,63 +251,50 @@ namespace MCGalaxy {
} else {
msg += " %Swas " + type + (whitelist ? " whitelisted" : " blacklisted");
}
DoChange(p, msg);
}
Update();
Logger.Log(LogType.UserActivity, "{0} on {1}", msg, lvl.name);
Chat.MessageLevel(lvl, msg);
void DoChange(Player p, string msg) {
Level lvl = LevelInfo.FindExact(lvlName);
Update(lvl);
Logger.Log(LogType.UserActivity, "{0} %Son {1}", msg, lvlName);
if (lvl != null) Chat.MessageLevel(lvl, msg);
if (p != null && p.level != lvl) {
Player.Message(p, "{0} on %S{1}", msg, ColoredName);
Player.Message(p, "{0} %Son {1}", msg, ColoredName);
}
}
void Update() {
Level.SaveSettings(lvl);
UpdateAllowBuild();
UpdateAllowVisit();
}
void UpdateAllowBuild() {
if (IsVisit) return;
void Update(Level lvl) {
cfg.Save(LevelInfo.PropertiesPath(lvlName));
if (lvl == null) return;
if (IsVisit && lvl == Server.mainLevel) return;
Player[] players = PlayerInfo.Online.Items;
foreach (Player p in players) {
if (p.level != lvl) continue;
AccessResult access = Check(p);
p.AllowBuild = access == AccessResult.Whitelisted || access == AccessResult.Allowed;
}
}
bool allowed = access == AccessResult.Whitelisted || access == AccessResult.Allowed;
void UpdateAllowVisit() {
if (!IsVisit || lvl == Server.mainLevel) return;
Player[] players = PlayerInfo.Online.Items;
foreach (Player p in players) {
if (p.level != lvl) continue;
AccessResult access = Check(p);
bool allowVisit = access == AccessResult.Whitelisted || access == AccessResult.Allowed;
if (allowVisit) continue;
Player.Message(p, "&cNo longer allowed to visit %S{0}", lvl.ColoredName);
if (!IsVisit) {
p.AllowBuild = allowed;
} else if (!allowed) {
Player.Message(p, "&cNo longer allowed to visit %S{0}", ColoredName);
PlayerActions.ChangeMap(p, Server.mainLevel);
}
}
}
}
public enum AccessResult {
/// <summary> The player is whitelisted and always allowed. </summary>
Whitelisted,
/// <summary> The player is blacklisted and never allowed. </summary>
Blacklisted,
/// <summary> The player is allowed (by their rank) </summary>
Allowed,
/// <summary> The player's rank is below the minimum rank allowed. </summary>
BelowMinRank,
/// <summary> The player's rank is above the maximum rank allowed. </summary>
AboveMaxRank,
}

View File

@ -70,7 +70,7 @@ namespace MCGalaxy {
/// <remarks> true if both worldChat and Server.worldChat are true. </remarks>
public bool SeesServerWideChat { get { return Config.ServerWideChat && ServerConfig.ServerWideChat; } }
internal readonly object queueLock = new object(), saveLock = new object(), savePropsLock = new object(), botsIOLock = new object();
internal readonly object queueLock = new object(), saveLock = new object(), botsIOLock = new object();
public List<ulong> blockqueue = new List<ulong>();
BufferedBlockSender bulkSender;

View File

@ -73,8 +73,8 @@ namespace MCGalaxy {
spawnz = (ushort)(Length / 2);
rotx = 0; roty = 0;
VisitAccess = new LevelAccessController(this, true);
BuildAccess = new LevelAccessController(this, false);
VisitAccess = new LevelAccessController(Config, name, true);
BuildAccess = new LevelAccessController(Config, name, false);
listCheckExists = new SparseBitSet(Width, Height, Length);
listUpdateExists = new SparseBitSet(Width, Height, Length);
}
@ -219,11 +219,8 @@ namespace MCGalaxy {
public static void SaveSettings(Level lvl) {
if (lvl.IsMuseum) return; // museums do not save properties
lock (lvl.savePropsLock) {
string propsPath = LevelInfo.PropertiesPath(lvl.MapName);
LevelConfig.Save(propsPath, lvl.Config, lvl.name);
}
string path = LevelInfo.PropertiesPath(lvl.MapName);
lvl.Config.Save(path);
}
// Returns true if ListCheck does not already have an check in the position.

View File

@ -260,7 +260,7 @@ namespace MCGalaxy {
[ConfigInt("RoundsHumanWon", "Game", 0)]
public int RoundsHumanWon = 0;
readonly object saveLock = new object();
public string Color {
get {
LevelPermission maxPerm = VisitMin;
@ -280,12 +280,15 @@ namespace MCGalaxy {
}
}
public static void Save(string path, LevelConfig config, string lvlname) {
public void Save(string path) {
try {
string mapName = Path.GetFileNameWithoutExtension(path);
lock (saveLock) {
using (StreamWriter w = new StreamWriter(path)) {
w.WriteLine("#Level properties for " + lvlname);
w.WriteLine("#Drown-time in seconds is [drown time] * 200 / 3 / 1000");
ConfigElement.Serialise(Server.levelConfig, " settings", w, config);
w.WriteLine("#Level properties for " + mapName);
w.WriteLine("#Drown-time is in tenths of a second");
ConfigElement.Serialise(Server.levelConfig, " settings", w, this);
}
}
} catch (Exception ex) {
Logger.Log(LogType.Warning, "Failed to save level properties!");

View File

@ -117,7 +117,7 @@ namespace MCGalaxy {
return "levels/level properties/" + name + ".properties";
}
internal static LevelConfig GetConfig(string map, out Level lvl) {
public static LevelConfig GetConfig(string map, out Level lvl) {
lvl = FindExact(map);
if (lvl != null) return lvl.Config;

View File

@ -128,9 +128,9 @@ namespace MCGalaxy.Network {
data[j++] = (byte)(x >> 8); data[j++] = (byte)x;
data[j++] = (byte)(y >> 8); data[j++] = (byte)y;
data[j++] = (byte)(z >> 8); data[j++] = (byte)z;
BlockID block = Block.ToRaw(blocks[i]);
data[j++] = (byte)(block >> 8);
data[j++] = (byte)block;
BlockID raw = Block.ToRaw(blocks[i]);
data[j++] = (byte)(raw >> 8);
data[j++] = (byte)raw;
}
return data;
}