Show server version in heartbeat, add AABB struct

This commit is contained in:
UnknownShadow200 2017-02-09 11:01:20 +11:00
parent 077f181084
commit c5876ee307
6 changed files with 132 additions and 26 deletions

View File

@ -623,6 +623,7 @@
<Compile Include="util\Formatting\MultiPageOutput.cs" />
<Compile Include="util\IO\BufferedBlockSender.cs" />
<Compile Include="util\IO\Paths.cs" />
<Compile Include="util\Math\AABB.cs" />
<Compile Include="util\Math\DirUtils.cs" />
<Compile Include="util\Math\Vectors.cs" />
<Compile Include="util\NET_20.cs" />

View File

@ -71,7 +71,7 @@ namespace MCGalaxy {
"&version=7" +
"&salt=" + Server.salt +
"&users=" + PlayerCount() +
"&software=MCGalaxy";
"&software=" + Uri.EscapeDataString("MCGalaxy " + Server.VersionString);
}
static int PlayerCount() {

View File

@ -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<string> Devs = new List<string>(), Mods = new List<string>();
internal static readonly List<string> opstats = new List<string>(
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<string> 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
}

View File

@ -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);
}
}
}

View File

@ -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 {
/// <summary> Fixed-point min coordinate of this bounding box. </summary>
public Vec3S32 Min;
/// <summary> Fixed-point max coordinate of this bounding box. </summary>
public Vec3S32 Max;
/// <summary> World/block coordinate of the min coordinate of this bounding box. </summary>
public Vec3S32 BlockMin { get { return new Vec3S32(Min.X >> 5, Min.Y >> 5, Min.Z >> 5); } }
/// <summary> World/block coordinate of the max coordinate of this bounding box. </summary>
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);
}
/// <summary> Returns a new bounding box, with the minimum and maximum coordinates
/// of the original bounding box scaled away from origin the given value. </summary>
public AABB Scale(float scale) {
return new AABB(Min * scale, Max * scale);
}
/// <summary> Determines whether this bounding box intersects
/// the given bounding box on any axes. </summary>
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;
}
/// <summary> Determines whether this bounding box entirely contains
/// the given bounding box on all axes. </summary>
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;
}
/// <summary> Determines whether this bounding box entirely contains
/// the coordinates on all axes. </summary>
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;
}
}
}

View File

@ -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);