Skip to content

Commit

Permalink
Full Pong result information: MOTD, Sub MOTD and default gamemode.
Browse files Browse the repository at this point in the history
But... But they do not seem to work... Let it go :D
  • Loading branch information
boybook committed Oct 25, 2017
1 parent 83060d6 commit 21718db
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
17 changes: 13 additions & 4 deletions src/main/java/cn/nukkit/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ public class Server {
this.properties = new Config(this.dataPath + "server.properties", Config.PROPERTIES, new ConfigSection() {
{
put("motd", "Nukkit Server For Minecraft: PE");
put("sub-motd", "Powered by Nukkit");
put("server-port", 19132);
put("server-ip", "0.0.0.0");
put("view-distance", 10);
Expand Down Expand Up @@ -1185,15 +1186,19 @@ public boolean getForceGamemode() {
}

public static String getGamemodeString(int mode) {
return getGamemodeString(mode, false);
}

public static String getGamemodeString(int mode, boolean direct) {
switch (mode) {
case Player.SURVIVAL:
return "%gameMode.survival";
return direct ? "Survival" : "%gameMode.survival";
case Player.CREATIVE:
return "%gameMode.creative";
return direct ? "Creative" : "%gameMode.creative";
case Player.ADVENTURE:
return "%gameMode.adventure";
return direct ? "Adventure" : "%gameMode.adventure";
case Player.SPECTATOR:
return "%gameMode.spectator";
return direct ? "Spectator" : "%gameMode.spectator";
}
return "UNKNOWN";
}
Expand Down Expand Up @@ -1281,6 +1286,10 @@ public String getMotd() {
return this.getPropertyString("motd", "Nukkit Server For Minecraft: PE");
}

public String getSubMotd() {
return this.getPropertyString("sub-motd", "Powered by Nukkit");
}

public boolean getForceResources() {
return this.getPropertyBoolean("force-resources", false);
}
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/cn/nukkit/network/Network.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class Network {
private double download = 0;

private String name;
private String subName;

public Network(Server server) {
this.registerPackets();
Expand Down Expand Up @@ -91,7 +92,7 @@ public void registerInterface(SourceInterface interfaz) {
this.advancedInterfaces.add((AdvancedSourceInterface) interfaz);
((AdvancedSourceInterface) interfaz).setNetwork(this);
}
interfaz.setName(this.name);
interfaz.setName(this.name + "!@#" + this.subName);
}

public void unregisterInterface(SourceInterface interfaz) {
Expand All @@ -108,9 +109,17 @@ public String getName() {
return name;
}

public String getSubName() {
return subName;
}

public void setSubName(String subName) {
this.subName = subName;
}

public void updateName() {
for (SourceInterface interfaz : this.interfaces) {
interfaz.setName(this.name);
interfaz.setName(this.name + "!@#" + this.subName);
}
}

Expand Down
8 changes: 5 additions & 3 deletions src/main/java/cn/nukkit/network/RakNetInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,16 @@ public void notifyACK(String identifier, int identifierACK) {
@Override
public void setName(String name) {
QueryRegenerateEvent info = this.server.getQueryInformation();

String[] names = name.split("!@#"); //Split double names within the program
this.handler.sendOption("name",
"MCPE;" + Utils.rtrim(name.replace(";", "\\;"), '\\') + ";" +
"MCPE;" + Utils.rtrim(names[0].replace(";", "\\;"), '\\') + ";" +
ProtocolInfo.CURRENT_PROTOCOL + ";" +
ProtocolInfo.MINECRAFT_VERSION_NETWORK + ";" +
info.getPlayerCount() + ";" +
info.getMaxPlayerCount() + ";" +
Server.getInstance().getServerUniqueId().toString());
this.server.getServerUniqueId().toString() + ";" +
(names.length > 1 ? Utils.rtrim(names[1].replace(";", "\\;"), '\\') : "") + ";" +
Server.getGamemodeString(this.server.getDefaultGamemode(), true) + ";");
}

public void setPortCheck(boolean value) {
Expand Down

1 comment on commit 21718db

@boybook
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Full Pong result information: MOTD, Sub MOTD and default gamemode.
But... But they do not seem to work... Let it go :D

Please sign in to comment.