Fix /map motd not setting motd when you don't provide a map name, reduce code duplication of SendMotd/SendUserMotd and also show the server name when joining levels with a custom motd less than 64 characters.

This commit is contained in:
UnknownShadow200 2016-07-22 15:03:07 +10:00
parent 6bcced8415
commit cb6f9c1758
2 changed files with 22 additions and 31 deletions

View File

@ -63,6 +63,8 @@ namespace MCGalaxy.Commands.World {
const string opts = "theme|finite|ai|edge|grass|ps|physicspeed|overload|motd|death|killer|fall|drown|unload"
+ "|realmowner|chat|load|loadongoto|leaf|leafdecay|flow|randomflow|tree|growtrees|buildable|deletable";
if (!opts.Contains(opt)) return false;
// In rare case someone uses /map motd motd My MOTD
if (opt == "motd" && (args.Length == 1 || !args[1].CaselessStarts("motd "))) return true;
bool optHasArg = opt == "ps" || opt == "physicspeed" || opt == "overload"
|| opt == "fall" || opt == "drown" || opt == "realmowner";

View File

@ -298,44 +298,33 @@ namespace MCGalaxy {
}
}
public void SendMotd() {
byte[] buffer = new byte[131];
buffer[0] = Opcode.Handshake;
buffer[1] = (byte)8;
bool cp437 = HasCpeExt(CpeExt.FullCP437);
public void SendMotd() { SendMapMotd(true); }
NetUtils.Write(Server.name, buffer, 2, cp437);
if (!String.IsNullOrEmpty(group.MOTD))
NetUtils.Write(group.MOTD, buffer, 66, cp437);
else
NetUtils.Write(Server.motd, buffer, 66, cp437);
public void SendUserMOTD() { SendMapMotd(false); }
bool canPlace = Block.canPlace(this, Block.blackrock);
buffer[130] = canPlace ? (byte)100 : (byte)0;
if (OnSendMOTD != null) OnSendMOTD(this, buffer);
SendRaw(buffer);
}
public void SendUserMOTD() {
void SendMapMotd(bool ignoreLevelMotd) {
byte[] buffer = new byte[131];
buffer[0] = Opcode.Handshake;
buffer[1] = Server.version;
bool cp437 = HasCpeExt(CpeExt.FullCP437);
if (level.motd == "ignore") {
if (ignoreLevelMotd || level.motd == "ignore") {
NetUtils.Write(Server.name, buffer, 2, cp437);
if (!String.IsNullOrEmpty(group.MOTD) )
NetUtils.Write(group.MOTD, buffer, 66, cp437);
else
NetUtils.Write(Server.motd, buffer, 66, cp437);
} else {
} else if (level.motd.Length > 64) {
NetUtils.Write(level.motd, buffer, 2, cp437);
if (level.motd.Length > 64)
NetUtils.Write(level.motd.Substring(64), buffer, 66, cp437);
} else {
NetUtils.Write(Server.name, buffer, 2, cp437);
NetUtils.Write(level.motd, buffer, 66, cp437);
}
bool canPlace = Block.canPlace(this, Block.blackrock);
buffer[130] = canPlace ? (byte)100 : (byte)0;
if (OnSendMOTD != null) OnSendMOTD(this, buffer);
SendRaw(buffer);
}