diff --git a/MCGalaxy/MCGalaxy_.csproj b/MCGalaxy/MCGalaxy_.csproj index 903fc32c5..2e3a58bfa 100644 --- a/MCGalaxy/MCGalaxy_.csproj +++ b/MCGalaxy/MCGalaxy_.csproj @@ -623,6 +623,7 @@ + diff --git a/MCGalaxy/Network/ClassiCube.cs b/MCGalaxy/Network/ClassiCube.cs index cef114dc4..c756718ce 100644 --- a/MCGalaxy/Network/ClassiCube.cs +++ b/MCGalaxy/Network/ClassiCube.cs @@ -71,7 +71,7 @@ namespace MCGalaxy { "&version=7" + "&salt=" + Server.salt + "&users=" + PlayerCount() + - "&software=MCGalaxy"; + "&software=" + Uri.EscapeDataString("MCGalaxy " + Server.VersionString); } static int PlayerCount() { diff --git a/MCGalaxy/Server/Server.Fields.cs b/MCGalaxy/Server/Server.Fields.cs index e4fcfb445..0eeb582c7 100644 --- a/MCGalaxy/Server/Server.Fields.cs +++ b/MCGalaxy/Server/Server.Fields.cs @@ -55,13 +55,22 @@ namespace MCGalaxy { public static PlayerMetaList AutoloadMaps = new PlayerMetaList("text/autoload.txt"); public static PlayerMetaList RankInfo = new PlayerMetaList("text/rankinfo.txt"); public static PlayerMetaList TempRanks = new PlayerMetaList("text/tempranks.txt"); - public static PlayerMetaList Notes = new PlayerMetaList("text/notes.txt"); + public static PlayerMetaList Notes = new PlayerMetaList("text/notes.txt"); public static Version Version { get { return System.Reflection.Assembly.GetAssembly(typeof(Server)).GetName().Version; } } + static string versionString = null; + static object versionLock = new object(); + + // Cache getting the version public static string VersionString { get { - Version v = Version; - return v.Major + "." + v.Minor + "." + v.Build + "." + v.Revision; + lock (versionLock) { + if (versionString == null) { + Version v = Version; + versionString = v.Major + "." + v.Minor + "." + v.Build + "." + v.Revision; + } + return versionString; + } } } @@ -84,7 +93,7 @@ namespace MCGalaxy { public static readonly List Devs = new List(), Mods = new List(); internal static readonly List opstats = new List( - new string[] { "ban", "tempban", "xban", "banip", "kickban", "kick", + new string[] { "ban", "tempban", "xban", "banip", "kickban", "kick", "warn", "mute", "freeze", "demote", "promote", "setrank" } ); public static List Opstats { get { return opstats; } } @@ -118,7 +127,7 @@ namespace MCGalaxy { public static int YesVotes = 0, NoVotes = 0; public static bool voting = false, votingforlevel = false; - public static LavaSurvival lava; + public static LavaSurvival lava; public static CountdownGame Countdown; public static Scheduler MainScheduler, Background; @@ -168,11 +177,11 @@ namespace MCGalaxy { [ConfigBool("tablist-bots", "Tablist", null, false)] public static bool TablistBots = false; - [ConfigString("server-name", "General", null, + [ConfigString("server-name", "General", null, "[MCGalaxy] Default", false, "![]&:.,{}~-+()?_/\\' ", 64)] public static string name = "[MCGalaxy] Default"; [ConfigString("motd", "General", null, "Welcome", - false, "=![]&:.,{}~-+()?_/\\' ", 128)] + false, "=![]&:.,{}~-+()?_/\\' ", 128)] public static string motd = "Welcome!"; [ConfigInt("max-players", "Server", null, 12, 1, 128)] public static int players = 12; @@ -262,7 +271,7 @@ namespace MCGalaxy { [ConfigEnum("irc-controller-verify", "IRC bot", null, IRCControllerVerify.HalfOp, typeof(IRCControllerVerify))] public static IRCControllerVerify IRCVerify = IRCControllerVerify.HalfOp; [ConfigPerm("irc-controller-rank", "IRC bot", null, LevelPermission.Nobody)] - public static LevelPermission ircControllerRank = LevelPermission.Nobody; + public static LevelPermission ircControllerRank = LevelPermission.Nobody; [ConfigBool("admin-verification", "Admin", null, true)] public static bool verifyadmins = true; @@ -273,10 +282,10 @@ namespace MCGalaxy { public static bool restartOnError = true; [ConfigInt("rplimit", "Other", null, 500, 0, 50000)] public static int rpLimit = 500; - [ConfigInt("rplimit-norm", "Other", null, 10000, 0, 50000)] + [ConfigInt("rplimit-norm", "Other", null, 10000, 0, 50000)] public static int rpNormLimit = 10000; - [ConfigInt("backup-time", "Backup", null, 300, 1)] + [ConfigInt("backup-time", "Backup", null, 300, 1)] public static int backupInterval = 300; public static int blockInterval = 60; [ConfigString("backup-location", "Backup", null, "")] @@ -308,7 +317,7 @@ namespace MCGalaxy { [ConfigBool("check-updates", "Update", null, false)] public static bool checkUpdates = true; - [ConfigBool("UseMySQL", "Database", null, false)] + [ConfigBool("UseMySQL", "Database", null, false)] public static bool useMySQL = false; [ConfigString("host", "Database", null, "127.0.0.1")] public static string MySQLHost = "127.0.0.1"; @@ -336,7 +345,7 @@ namespace MCGalaxy { [ConfigBool("global-chat-enabled", "Other", null, true)] public static bool UseGlobalChat = true; - [ConfigInt("afk-minutes", "Other", null, 10)] + [ConfigInt("afk-minutes", "Other", null, 10)] public static int afkminutes = 10; [ConfigInt("afk-kick", "Other", null, 45)] public static int afkkick = 45; @@ -364,7 +373,7 @@ namespace MCGalaxy { [ConfigString("money-name", "Other", null, "moneys")] public static string moneys = "moneys"; - public static LevelPermission opchatperm = LevelPermission.Operator; + public static LevelPermission opchatperm = LevelPermission.Operator; public static LevelPermission adminchatperm = LevelPermission.Admin; [ConfigBool("log-heartbeat", "Other", null, false)] @@ -372,26 +381,26 @@ namespace MCGalaxy { [ConfigBool("admins-join-silent", "Other", null, false)] public static bool adminsjoinsilent = false; public static bool mono { get { return (Type.GetType("Mono.Runtime") != null); } } - [ConfigString("server-owner", "Other", null, "Notch")] + [ConfigString("server-owner", "Other", null, "Notch")] public static string server_owner = "Notch"; - [ConfigBool("guest-limit-notify", "Other", null, false)] + [ConfigBool("guest-limit-notify", "Other", null, false)] public static bool guestLimitNotify = false; - [ConfigBool("guest-join-notify", "Other", null, true)] + [ConfigBool("guest-join-notify", "Other", null, true)] public static bool guestJoinNotify = true; - [ConfigBool("guest-leave-notify", "Other", null, true)] + [ConfigBool("guest-leave-notify", "Other", null, true)] public static bool guestLeaveNotify = true; [ConfigString("default-texture-url", "General", null, "", true, null, NetUtils.StringSize)] public static string defaultTerrainUrl = ""; - [ConfigString("default-texture-pack-url", "General", null, "", true, null, NetUtils.StringSize)] + [ConfigString("default-texture-pack-url", "General", null, "", true, null, NetUtils.StringSize)] public static string defaultTextureUrl = ""; //hackrank stuff [ConfigBool("kick-on-hackrank", "Other", null, true)] public static bool hackrank_kick = true; - [ConfigInt("hackrank-kick-time", "Other", null, 5)] + [ConfigInt("hackrank-kick-time", "Other", null, 5)] public static int hackrank_kick_time = 5; //seconds, it converts it to milliseconds in the command. - [ConfigBool("show-empty-ranks", "Other", null, false)] + [ConfigBool("show-empty-ranks", "Other", null, false)] public static bool showEmptyRanks = false; [ConfigInt("review-cooldown", "Review", null, 600, 0, 600)] @@ -401,7 +410,7 @@ namespace MCGalaxy { public static int DrawReloadLimit = 10000; [ConfigInt("map-gen-limit-admin", "Other", null, 225 * 1000 * 1000)] public static int MapGenLimitAdmin = 225 * 1000 * 1000; - [ConfigInt("map-gen-limit", "Other", null, 30 * 1000 * 1000)] + [ConfigInt("map-gen-limit", "Other", null, 30 * 1000 * 1000)] public static int MapGenLimit = 30 * 1000 * 1000; #endregion } diff --git a/MCGalaxy/util/Formatting/Matcher.cs b/MCGalaxy/util/Formatting/Matcher.cs index a371b6794..68e0ede65 100644 --- a/MCGalaxy/util/Formatting/Matcher.cs +++ b/MCGalaxy/util/Formatting/Matcher.cs @@ -103,21 +103,25 @@ namespace MCGalaxy { if (itemName.IndexOf(name, comp) < 0) continue; match = item; matches++; - if (matches <= limit) + if (matches <= limit) { nameMatches.Append(itemName).Append(", "); - else if (matches == limit + 1) + } else if (matches == limit + 1) { nameMatches.Append("(and more)").Append(", "); + } } if (matches == 0) { - Player.Message(pl, "No " + group + " match \"" + name + "\"."); return default(T); + Player.Message(pl, "No " + group + " match \"" + name + "\"."); + return default(T); } else if (matches == 1) { return match; } else { string count = matches > limit ? limit + "+ " : matches + " "; string names = nameMatches.ToString(0, nameMatches.Length - 2); + Player.Message(pl, count + group + " match \"" + name + "\":"); - Player.Message(pl, names); return default(T); + Player.Message(pl, names); + return default(T); } } } diff --git a/MCGalaxy/util/Math/AABB.cs b/MCGalaxy/util/Math/AABB.cs new file mode 100644 index 000000000..cb6d0dbbf --- /dev/null +++ b/MCGalaxy/util/Math/AABB.cs @@ -0,0 +1,88 @@ +/* + Copyright 2015 MCGalaxy + + Dual-licensed under the Educational Community License, Version 2.0 and + the GNU General Public License, Version 3 (the "Licenses"); you may + not use this file except in compliance with the Licenses. You may + obtain a copy of the Licenses at + + http://www.opensource.org/licenses/ecl2.php + http://www.gnu.org/licenses/gpl-3.0.html + + Unless required by applicable law or agreed to in writing, + software distributed under the Licenses are distributed on an "AS IS" + BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + or implied. See the Licenses for the specific language governing + permissions and limitations under the Licenses. + */ +using System; + +namespace MCGalaxy { + + public struct AABB { + + /// Fixed-point min coordinate of this bounding box. + public Vec3S32 Min; + + /// Fixed-point max coordinate of this bounding box. + public Vec3S32 Max; + + /// World/block coordinate of the min coordinate of this bounding box. + public Vec3S32 BlockMin { get { return new Vec3S32(Min.X >> 5, Min.Y >> 5, Min.Z >> 5); } } + + /// World/block coordinate of the max coordinate of this bounding box. + public Vec3S32 BlockMax { get { return new Vec3S32(Max.X >> 5, Max.Y >> 5, Max.Z >> 5); } } + + + public AABB(int x1, int y1, int z1, int x2, int y2, int z2) { + Min.X = x1; Min.Y = y1; Min.Z = z1; + Max.X = x2; Max.Y = y2; Max.Z = z2; + } + + public AABB(Vec3S32 min, Vec3S32 max) { + Min = min; + Max = max; + } + + public static AABB Make(Vec3S32 pos, Vec3S32 size) { + return new AABB(pos.X - size.X / 2, pos.Y, pos.Z - size.Z / 2, + pos.X + size.X / 2, pos.Y + size.Y, pos.Z + size.Z / 2); + } + + /// Returns a new bounding box, with the minimum and maximum coordinates + /// of the original bounding box scaled away from origin the given value. + public AABB Scale(float scale) { + return new AABB(Min * scale, Max * scale); + } + + /// Determines whether this bounding box intersects + /// the given bounding box on any axes. + public bool Intersects(AABB other) { + if (Max.X >= other.Min.X && Min.X <= other.Max.X) { + if (Max.Y < other.Min.Y || Min.Y > other.Max.Y) { + return false; + } + return Max.Z >= other.Min.Z && Min.Z <= other.Max.Z; + } + return false; + } + + /// Determines whether this bounding box entirely contains + /// the given bounding box on all axes. + public bool Contains(AABB other) { + return other.Min.X >= Min.X && other.Min.Y >= Min.Y && other.Min.Z >= Min.Z && + other.Max.X <= Max.X && other.Max.Y <= Max.Y && other.Max.Z <= Max.Z; + } + + /// Determines whether this bounding box entirely contains + /// the coordinates on all axes. + public bool Contains(Vec3S32 P) { + return P.X >= Min.X && P.Y >= Min.Y && P.Z >= Min.Z && + P.X <= Max.X && P.Y <= Max.Y && P.Z <= Max.Z; + } + + public override string ToString() { + return Min + " : " + Max; + } + } +} \ No newline at end of file diff --git a/MCGalaxy/util/Math/Vectors.cs b/MCGalaxy/util/Math/Vectors.cs index d1249cee6..f64527264 100644 --- a/MCGalaxy/util/Math/Vectors.cs +++ b/MCGalaxy/util/Math/Vectors.cs @@ -165,6 +165,10 @@ namespace MCGalaxy { return new Vec3S32(a.X / b, a.Y / b, a.Z / b); } + public static Vec3S32 operator * (Vec3S32 a, float b) { + return new Vec3S32((int)(a.X * b), (int)(a.Y * b), (int)(a.Z * b)); + } + public override bool Equals(object obj) { return (obj is Vec3S32) && Equals((Vec3S32)obj);