forked from git-mirrors/GeyserConnect
Add address config and start of server list edit
This commit is contained in:
parent
3679fd5034
commit
ff54bd4580
7 changed files with 110 additions and 23 deletions
|
@ -4,6 +4,7 @@ package org.geysermc.multi;
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import org.geysermc.connector.utils.WebUtils;
|
||||||
import org.geysermc.multi.utils.PlayerStorageManager;
|
import org.geysermc.multi.utils.PlayerStorageManager;
|
||||||
import org.geysermc.multi.utils.Server;
|
import org.geysermc.multi.utils.Server;
|
||||||
|
|
||||||
|
@ -13,6 +14,11 @@ import java.util.List;
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
public class GeyserMultiConfig {
|
public class GeyserMultiConfig {
|
||||||
|
|
||||||
|
private String address;
|
||||||
|
|
||||||
|
@JsonProperty("remote-address")
|
||||||
|
private String remoteAddress;
|
||||||
|
|
||||||
private int port;
|
private int port;
|
||||||
|
|
||||||
@JsonProperty("max-players")
|
@JsonProperty("max-players")
|
||||||
|
@ -30,6 +36,13 @@ public class GeyserMultiConfig {
|
||||||
@JsonProperty("custom-servers")
|
@JsonProperty("custom-servers")
|
||||||
private CustomServersSection customServers;
|
private CustomServersSection customServers;
|
||||||
|
|
||||||
|
public void checkRemoteIP() {
|
||||||
|
if ("auto".equals(remoteAddress)) {
|
||||||
|
remoteAddress = WebUtils.getBody("https://icanhazip.com/").trim();
|
||||||
|
MasterServer.getInstance().getLogger().debug("Auto set remote IP to: " + remoteAddress);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public static class GeyserConfigSection {
|
public static class GeyserConfigSection {
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,8 @@ public class MasterServer {
|
||||||
|
|
||||||
logger.setDebug(geyserMultiConfig.isDebugMode());
|
logger.setDebug(geyserMultiConfig.isDebugMode());
|
||||||
|
|
||||||
|
geyserMultiConfig.checkRemoteIP();
|
||||||
|
|
||||||
this.generalThreadPool = Executors.newScheduledThreadPool(32);
|
this.generalThreadPool = Executors.newScheduledThreadPool(32);
|
||||||
|
|
||||||
// Start a timer to keep the thread running
|
// Start a timer to keep the thread running
|
||||||
|
@ -80,7 +82,7 @@ public class MasterServer {
|
||||||
private void start(int port) {
|
private void start(int port) {
|
||||||
logger.info("Starting...");
|
logger.info("Starting...");
|
||||||
|
|
||||||
InetSocketAddress bindAddress = new InetSocketAddress("0.0.0.0", port);
|
InetSocketAddress bindAddress = new InetSocketAddress(geyserMultiConfig.getAddress(), port);
|
||||||
bdServer = new BedrockServer(bindAddress);
|
bdServer = new BedrockServer(bindAddress);
|
||||||
|
|
||||||
bdPong = new BedrockPong();
|
bdPong = new BedrockPong();
|
||||||
|
@ -112,7 +114,7 @@ public class MasterServer {
|
||||||
|
|
||||||
// Start server up
|
// Start server up
|
||||||
bdServer.bind().join();
|
bdServer.bind().join();
|
||||||
logger.info("Server started on 0.0.0.0:" + port);
|
logger.info("Server started on " + geyserMultiConfig.getAddress() + ":" + port);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
|
|
|
@ -170,7 +170,7 @@ public class PacketHandler implements BedrockPacketHandler {
|
||||||
window.setResponse(packet.getFormData().trim());
|
window.setResponse(packet.getFormData().trim());
|
||||||
|
|
||||||
// Resend the form if they closed it
|
// Resend the form if they closed it
|
||||||
if (window.getResponse() == null && id != FormID.DIRECT_CONNECT) {
|
if (window.getResponse() == null && !id.isHandlesNull()) {
|
||||||
player.resendWindow();
|
player.resendWindow();
|
||||||
} else {
|
} else {
|
||||||
// Send the response to the correct response function
|
// Send the response to the correct response function
|
||||||
|
|
|
@ -1,15 +1,29 @@
|
||||||
package org.geysermc.multi.ui;
|
package org.geysermc.multi.ui;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
public enum FormID {
|
public enum FormID {
|
||||||
MAIN,
|
MAIN,
|
||||||
DIRECT_CONNECT,
|
DIRECT_CONNECT(true),
|
||||||
|
EDIT_SERVERS(true),
|
||||||
ADD_SERVER,
|
ADD_SERVER,
|
||||||
REMOVE_SERVER,
|
REMOVE_SERVER,
|
||||||
CONNECTING,
|
CONNECTING,
|
||||||
ERROR;
|
ERROR;
|
||||||
|
|
||||||
|
private boolean handlesNull;
|
||||||
|
|
||||||
private static final FormID[] VALUES = values();
|
private static final FormID[] VALUES = values();
|
||||||
|
|
||||||
|
FormID() {
|
||||||
|
this(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
FormID(boolean handlesNull) {
|
||||||
|
this.handlesNull = handlesNull;
|
||||||
|
}
|
||||||
|
|
||||||
public static FormID fromId(int id) {
|
public static FormID fromId(int id) {
|
||||||
return id >= 0 && id < VALUES.length ? VALUES[id] : ERROR;
|
return id >= 0 && id < VALUES.length ? VALUES[id] : ERROR;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,9 +26,6 @@ public class UIHandler {
|
||||||
public static FormWindow getServerList(List<Server> servers) {
|
public static FormWindow getServerList(List<Server> servers) {
|
||||||
SimpleFormWindow window = new SimpleFormWindow("Servers", "");
|
SimpleFormWindow window = new SimpleFormWindow("Servers", "");
|
||||||
|
|
||||||
window.getButtons().add(new FormButton("Direct connect"));
|
|
||||||
window.getButtons().add(new FormButton("Edit servers"));
|
|
||||||
|
|
||||||
// Add a button for each global server
|
// Add a button for each global server
|
||||||
for (Server server : MasterServer.getInstance().getGeyserMultiConfig().getServers()) {
|
for (Server server : MasterServer.getInstance().getGeyserMultiConfig().getServers()) {
|
||||||
window.getButtons().add(new FormButton(server.toString(), new FormImage(FormImage.FormImageType.URL, "https://eu.mc-api.net/v3/server/favicon/" + server.getAddress() + ":" + server.getPort() + ".png")));
|
window.getButtons().add(new FormButton(server.toString(), new FormImage(FormImage.FormImageType.URL, "https://eu.mc-api.net/v3/server/favicon/" + server.getAddress() + ":" + server.getPort() + ".png")));
|
||||||
|
@ -39,6 +36,9 @@ public class UIHandler {
|
||||||
for (Server server : servers) {
|
for (Server server : servers) {
|
||||||
window.getButtons().add(new FormButton(server.toString(), new FormImage(FormImage.FormImageType.URL, "https://eu.mc-api.net/v3/server/favicon/" + server.getAddress() + ":" + server.getPort() + ".png")));
|
window.getButtons().add(new FormButton(server.toString(), new FormImage(FormImage.FormImageType.URL, "https://eu.mc-api.net/v3/server/favicon/" + server.getAddress() + ":" + server.getPort() + ".png")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window.getButtons().add(new FormButton("Edit servers"));
|
||||||
|
window.getButtons().add(new FormButton("Direct connect"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return window;
|
return window;
|
||||||
|
@ -68,6 +68,23 @@ public class UIHandler {
|
||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a list of servers for the client to edit
|
||||||
|
*
|
||||||
|
* @param servers A list of {@link Server} objects
|
||||||
|
* @return A {@link SimpleFormWindow} object
|
||||||
|
*/
|
||||||
|
public static FormWindow getEditServerList(List<Server> servers) {
|
||||||
|
SimpleFormWindow window = new SimpleFormWindow("Edit Servers", "Select a server to edit");
|
||||||
|
|
||||||
|
// Add a button for each personal server
|
||||||
|
for (Server server : servers) {
|
||||||
|
window.getButtons().add(new FormButton(server.toString(), new FormImage(FormImage.FormImageType.URL, "https://eu.mc-api.net/v3/server/favicon/" + server.getAddress() + ":" + server.getPort() + ".png")));
|
||||||
|
}
|
||||||
|
|
||||||
|
return window;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle the server list response
|
* Handle the server list response
|
||||||
*
|
*
|
||||||
|
@ -75,23 +92,28 @@ public class UIHandler {
|
||||||
* @param data The form response data
|
* @param data The form response data
|
||||||
*/
|
*/
|
||||||
public static void handleServerListResponse(Player player, SimpleFormResponse data) {
|
public static void handleServerListResponse(Player player, SimpleFormResponse data) {
|
||||||
switch (data.getClickedButtonId()) {
|
|
||||||
case 0:
|
|
||||||
player.sendWindow(FormID.DIRECT_CONNECT, getDirectConnect());
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
// Get the server
|
|
||||||
List<Server> servers = new ArrayList<>(MasterServer.getInstance().getGeyserMultiConfig().getServers());
|
List<Server> servers = new ArrayList<>(MasterServer.getInstance().getGeyserMultiConfig().getServers());
|
||||||
servers.addAll(player.getServers());
|
servers.addAll(player.getServers());
|
||||||
Server server = servers.get(data.getClickedButtonId() - 2);
|
|
||||||
|
// Cant be done in a switch as we need to calculate the last 2 buttons
|
||||||
|
if (data.getClickedButtonId() == servers.size()) {
|
||||||
|
player.sendWindow(FormID.EDIT_SERVERS, getEditServerList(player.getServers()));
|
||||||
|
} else if (data.getClickedButtonId() == servers.size() + 1) {
|
||||||
|
player.sendWindow(FormID.DIRECT_CONNECT, getDirectConnect());
|
||||||
|
} else {
|
||||||
|
// Get the server
|
||||||
|
Server server = servers.get(data.getClickedButtonId());
|
||||||
|
|
||||||
player.sendToServer(server);
|
player.sendToServer(server);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the direct connect response
|
||||||
|
*
|
||||||
|
* @param player The player that submitted the response
|
||||||
|
* @param data The form response data
|
||||||
|
*/
|
||||||
public static void handleDirectConnectResponse(Player player, CustomFormResponse data) {
|
public static void handleDirectConnectResponse(Player player, CustomFormResponse data) {
|
||||||
// Take them back to the main menu if they close the direct connect window
|
// Take them back to the main menu if they close the direct connect window
|
||||||
if (data == null) {
|
if (data == null) {
|
||||||
|
@ -99,6 +121,36 @@ public class UIHandler {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
player.sendToServer(new Server(data.getInputResponses().get(0), Integer.valueOf(data.getInputResponses().get(1))));
|
try {
|
||||||
|
String address = data.getInputResponses().get(0);
|
||||||
|
int port = Integer.valueOf(data.getInputResponses().get(1));
|
||||||
|
|
||||||
|
// Make sure we got an address and port
|
||||||
|
if (address == null || "".equals(address) || port <= 0 || port >= 65535) {
|
||||||
|
player.resendWindow();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
player.sendToServer(new Server(address, port));
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
player.resendWindow();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle the edit server list response
|
||||||
|
*
|
||||||
|
* @param player The player that submitted the response
|
||||||
|
* @param data The form response data
|
||||||
|
*/
|
||||||
|
public static void handleEditServerListResponse(Player player, SimpleFormResponse data) {
|
||||||
|
// Take them back to the main menu if they close the edit server list window
|
||||||
|
if (data == null) {
|
||||||
|
player.sendWindow(FormID.MAIN, getServerList(player.getServers()));;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Just redisplay the form for now
|
||||||
|
player.resendWindow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -155,8 +155,8 @@ public class Player {
|
||||||
*/
|
*/
|
||||||
public void connectToProxy() {
|
public void connectToProxy() {
|
||||||
TransferPacket transferPacket = new TransferPacket();
|
TransferPacket transferPacket = new TransferPacket();
|
||||||
transferPacket.setAddress("127.0.0.1"); // Need to find a good way of getting this
|
transferPacket.setAddress(MasterServer.getInstance().getGeyserMultiConfig().getRemoteAddress());
|
||||||
transferPacket.setPort(MasterServer.getInstance().getGeyserProxy().getGeyserConfig().getBedrock().getPort());
|
transferPacket.setPort(MasterServer.getInstance().getGeyserMultiConfig().getGeyser().getPort());
|
||||||
session.sendPacket(transferPacket);
|
session.sendPacket(transferPacket);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,12 @@
|
||||||
# GeyserMulti Configuration File
|
# GeyserMulti Configuration File
|
||||||
# --------------------------------
|
# --------------------------------
|
||||||
|
|
||||||
|
# The IP address that will listen for connections
|
||||||
|
address: 0.0.0.0
|
||||||
|
|
||||||
|
# The IP address remote clients use to connect, can be set to 'auto' to fetch from the web
|
||||||
|
remote-address: auto
|
||||||
|
|
||||||
# The port that will listen for connections
|
# The port that will listen for connections
|
||||||
port: 19132
|
port: 19132
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue