diff options
| author | Matthew <pugmatt@gmail.com> | 2020-12-15 23:25:42 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-15 23:25:42 -0500 |
| commit | 37d2c34ff97efbc74652c58bf1ba8d749b9c41c5 (patch) | |
| tree | 991d181238fd79f6d694cfaaf5b562999d4b6000 | |
| parent | 382fd504bec9c586f7ae52a78260b533cce208ce (diff) | |
| parent | 26168fb5c8a038b5469ceea65975a35a7e940587 (diff) | |
| download | BedrockConnect-1.6.tar.gz BedrockConnect-1.6.tar.bz2 BedrockConnect-1.6.zip | |
Merge pull request #125 from Technoguyfication/master1.6
Add support for global custom servers
7 files changed, 154 insertions, 11 deletions
@@ -188,6 +188,7 @@ buildNumber.properties *.launch .settings/ *.sublime-workspace +.vscode/ # IDE - VSCode .vscode/* @@ -208,4 +209,4 @@ testem.log # System Files .DS_Store -Thumbs.db
\ No newline at end of file +Thumbs.db @@ -60,12 +60,37 @@ The following arguments can be placed in the startup command to ajust settings: | nodb | If true, use JSON files for data instead of MySQL | false | | generatedns | If true, generate a DNS zone file using user input (Only needed if you're using the mod0Umleitung DNS software) | false | | kick_inactive | If true, players will be kicked after 10 minutes of inactivity with the serverlist UI | true | +| custom_servers| Sets the path to a custom server file, for specifying your servers in the list for all players. See [custom servers](#defining-your-own-custom-servers). | | MySQL example: ``` java -jar BedrockConnect-1.0-SNAPSHOT.jar mysql_pass=test123 server_limit=10 ``` +# Defining your own custom servers + +When hosting your own serverlist server, you add your own custom servers to the top of the serverlist for all players. To get started, create a JSON file and follow this format: +```json +[ + { + "name": "My Custom Server 1", + "iconUrl": "https://i.imgur.com/3BmFZRE.png", + "address": "mc1.example.com", + "port": 19132 + }, + { + "name": "My Custom Server 2", + "iconUrl": "https://i.imgur.com/3BmFZRE.png", + "address": "mc2.example.com", + "port": 19132 + } +] +``` + +Then, add this argument to your startup script: `custom_servers=[path to json file]` + +The icon URL is not required, if omitted it will show the default icon. + # Libraries used - [NukkitX Bedrock Protocol Library](https://github.com/NukkitX/Protocol) diff --git a/serverlist-server/src/main/com/pyratron/pugmatt/bedrockconnect/BedrockConnect.java b/serverlist-server/src/main/com/pyratron/pugmatt/bedrockconnect/BedrockConnect.java index 1f4b2ce..afa1351 100644 --- a/serverlist-server/src/main/com/pyratron/pugmatt/bedrockconnect/BedrockConnect.java +++ b/serverlist-server/src/main/com/pyratron/pugmatt/bedrockconnect/BedrockConnect.java @@ -23,6 +23,7 @@ public class BedrockConnect { public static Server server; public static boolean noDB = false; + public static String customServers = null; public static boolean kickInactive = true; public static void main(String[] args) { @@ -59,6 +60,8 @@ public class BedrockConnect { port = getArgValue(str, "port"); if(str.startsWith("nodb=")) noDB = true; + if(str.startsWith("custom_servers=")) + customServers = getArgValue(str, "custom_servers"); if(str.startsWith("generatedns=")) { String ip; try { @@ -131,6 +134,9 @@ public class BedrockConnect { System.out.println("\nServer Limit: " + serverLimit + "\n" + "Port: " + port + "\n"); + CustomServerHandler.initialize(); + System.out.printf("Loaded %d custom servers\n", CustomServerHandler.getServers().length); + if(!noDB) { MySQL = new MySQL(hostname, database, username, password); diff --git a/serverlist-server/src/main/com/pyratron/pugmatt/bedrockconnect/CustomServer.java b/serverlist-server/src/main/com/pyratron/pugmatt/bedrockconnect/CustomServer.java new file mode 100644 index 0000000..579718f --- /dev/null +++ b/serverlist-server/src/main/com/pyratron/pugmatt/bedrockconnect/CustomServer.java @@ -0,0 +1,38 @@ +package main.com.pyratron.pugmatt.bedrockconnect; + +public class CustomServer { + public final String DEFAULT_ICON = "https://i.imgur.com/3BmFZRE.png"; + + private String name; + private String iconUrl; + private String address; + private int port; + + public CustomServer(String name, String iconUrl, String address, int port) { + super(); + + this.name = name; + this.iconUrl = iconUrl; + this.address = address; + this.port = port; + } + + public String getName() { + return name; + } + + public String getIconUrl() { + if (iconUrl == null) + return DEFAULT_ICON; + else + return iconUrl; + } + + public String getAddress() { + return address; + } + + public int getPort() { + return port; + } +} diff --git a/serverlist-server/src/main/com/pyratron/pugmatt/bedrockconnect/CustomServerHandler.java b/serverlist-server/src/main/com/pyratron/pugmatt/bedrockconnect/CustomServerHandler.java new file mode 100644 index 0000000..1c79d09 --- /dev/null +++ b/serverlist-server/src/main/com/pyratron/pugmatt/bedrockconnect/CustomServerHandler.java @@ -0,0 +1,56 @@ +package main.com.pyratron.pugmatt.bedrockconnect; + +import java.io.FileReader; +import java.io.IOException; +import java.io.Reader; +import java.util.ArrayList; +import java.util.Iterator; + +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; + +public class CustomServerHandler { + private static ArrayList<CustomServer> servers = new ArrayList<CustomServer>(); + + /** + * Loads any custom servers into memory + */ + public static void initialize() { + String serverFile = BedrockConnect.customServers; + if (serverFile == null) { + return; + } + + JSONParser parser = new JSONParser(); + try (Reader reader = new FileReader(serverFile)) { + + JSONArray serverList = (JSONArray) parser.parse(reader); + + @SuppressWarnings("unchecked") + Iterator<JSONObject> i = serverList.iterator(); + while (i.hasNext()) { + JSONObject obj = i.next(); + String name = (String) obj.get("name"); + String iconUrl = (String) obj.get("iconUrl"); + String address = (String) obj.get("address"); + int port = ((Long) obj.get("port")).intValue(); + + servers.add(new CustomServer(name, iconUrl, address, port)); + } + + } catch (IOException e) { + e.printStackTrace(); + } catch (ParseException e) { + e.printStackTrace(); + } + + } + + public static CustomServer[] getServers() { + CustomServer[] arr = new CustomServer[servers.size()]; + arr = servers.toArray(arr); + return arr; + } +} diff --git a/serverlist-server/src/main/com/pyratron/pugmatt/bedrockconnect/gui/UIForms.java b/serverlist-server/src/main/com/pyratron/pugmatt/bedrockconnect/gui/UIForms.java index 4a97b0b..19e0f13 100644 --- a/serverlist-server/src/main/com/pyratron/pugmatt/bedrockconnect/gui/UIForms.java +++ b/serverlist-server/src/main/com/pyratron/pugmatt/bedrockconnect/gui/UIForms.java @@ -4,6 +4,9 @@ import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.nukkitx.protocol.bedrock.packet.ModalFormRequestPacket; +import main.com.pyratron.pugmatt.bedrockconnect.CustomServer; +import main.com.pyratron.pugmatt.bedrockconnect.CustomServerHandler; + import java.lang.reflect.Array; import java.util.ArrayList; import java.util.List; @@ -24,12 +27,16 @@ public class UIForms { out.addProperty("content", ""); JsonArray buttons = new JsonArray(); + CustomServer[] customServers = CustomServerHandler.getServers(); buttons.add(UIComponents.createButton("Connect to a Server")); buttons.add(UIComponents.createButton("Remove a Server")); for(int i=0;i<servers.size();i++) { buttons.add(UIComponents.createButton(servers.get(i), "https://i.imgur.com/3BmFZRE.png", "url")); } + for (CustomServer cs : customServers) { + buttons.add(UIComponents.createButton(cs.getName(), cs.getIconUrl(), "url")); + } buttons.add(UIComponents.createButton("The Hive", "https://forum.playhive.com/uploads/default/original/1X/0d05e3240037f7592a0f16b11b57c08eba76f19c.png", "url")); buttons.add(UIComponents.createButton("Mineplex", "https://www.mineplex.com/assets/www-mp/img/footer/footer_smalllogo.png", "url")); buttons.add(UIComponents.createButton("CubeCraft Games", "https://i.imgur.com/aFH1NUr.png", "url")); diff --git a/serverlist-server/src/main/com/pyratron/pugmatt/bedrockconnect/listeners/PacketHandler.java b/serverlist-server/src/main/com/pyratron/pugmatt/bedrockconnect/listeners/PacketHandler.java index 5199cb1..d30cb6b 100644 --- a/serverlist-server/src/main/com/pyratron/pugmatt/bedrockconnect/listeners/PacketHandler.java +++ b/serverlist-server/src/main/com/pyratron/pugmatt/bedrockconnect/listeners/PacketHandler.java @@ -23,6 +23,8 @@ import io.netty.util.AsciiString; import io.netty.util.internal.ThreadLocalRandom; import main.com.pyratron.pugmatt.bedrockconnect.BCPlayer; import main.com.pyratron.pugmatt.bedrockconnect.BedrockConnect; +import main.com.pyratron.pugmatt.bedrockconnect.CustomServer; +import main.com.pyratron.pugmatt.bedrockconnect.CustomServerHandler; import main.com.pyratron.pugmatt.bedrockconnect.Server; import main.com.pyratron.pugmatt.bedrockconnect.gui.UIComponents; import main.com.pyratron.pugmatt.bedrockconnect.gui.UIForms; @@ -943,32 +945,40 @@ public class PacketHandler implements BedrockPacketHandler { session.sendPacketImmediately(UIForms.createRemoveServer(player.getServerList())); } else { // Choosing Server + CustomServer[] customServers = CustomServerHandler.getServers(); + List<String> playerServers = server.getPlayer(uuid).getServerList(); + int serverIndex = chosen - 2; + // If server chosen is a featued server - if(chosen-2 > player.getServerList().size()-1) { - int featuredServer = (chosen - 2) - (player.getServerList().size() - 1); + if(serverIndex + 1 > playerServers.size() + customServers.length) { + int featuredServer = serverIndex - playerServers.size() - customServers.length; switch (featuredServer) { - case 1: // Hive + case 0: // Hive transfer("54.39.75.136", 19132); break; - case 2: // Mineplex + case 1: // Mineplex transfer("108.178.12.125", 19132); break; - case 3: // Cubecraft + case 2: // Cubecraft transfer("play.cubecraft.net", 19132); break; - case 4: // Lifeboat + case 3: // Lifeboat transfer("63.143.40.66", 19132); break; - case 5: // Mineville + case 4: // Mineville transfer("52.234.131.7", 19132); break; - case 6: // Galaxite + case 5: // Galaxite transfer("51.89.152.241", 19132); break; } - } else { // If server chosen is not a featured server - String address = player.getServerList().get(chosen-2); + } else if (serverIndex + 1 > playerServers.size() && serverIndex - playerServers.size() < customServers.length) { // if server is a custom server + CustomServer server = customServers[serverIndex - playerServers.size()]; + transfer(server.getAddress(), server.getPort()); + + } else { // if server is a player server + String address = server.getPlayer(uuid).getServerList().get(chosen-2); if (address.split(":").length > 1) { String ip = address.split(":")[0]; |
