forked from git-mirrors/GeyserConnect
Add welcome message
This commit is contained in:
parent
d180ab3795
commit
11bd70bdc9
7 changed files with 37 additions and 2 deletions
|
@ -52,6 +52,9 @@ public class GeyserConnectConfig {
|
||||||
|
|
||||||
private String motd;
|
private String motd;
|
||||||
|
|
||||||
|
@JsonProperty("welcome-file")
|
||||||
|
private String welcomeFile = "welcome.txt";
|
||||||
|
|
||||||
@JsonProperty("debug-mode")
|
@JsonProperty("debug-mode")
|
||||||
private boolean debugMode;
|
private boolean debugMode;
|
||||||
|
|
||||||
|
|
|
@ -119,6 +119,11 @@ public class MasterServer {
|
||||||
|
|
||||||
storageManager.setupStorage();
|
storageManager.setupStorage();
|
||||||
|
|
||||||
|
// Create the base welcome.txt file
|
||||||
|
try {
|
||||||
|
FileUtils.fileOrCopiedFromResource(new File(MasterServer.getInstance().getGeyserConnectConfig().getWelcomeFile()), "welcome.txt", (x) -> x);
|
||||||
|
} catch (IOException ignored) { }
|
||||||
|
|
||||||
start(geyserConnectConfig.getPort());
|
start(geyserConnectConfig.getPort());
|
||||||
|
|
||||||
logger.start();
|
logger.start();
|
||||||
|
|
|
@ -48,8 +48,9 @@ import org.geysermc.connector.entity.attribute.AttributeType;
|
||||||
import org.geysermc.connector.network.BedrockProtocol;
|
import org.geysermc.connector.network.BedrockProtocol;
|
||||||
import org.geysermc.connector.network.session.auth.BedrockClientData;
|
import org.geysermc.connector.network.session.auth.BedrockClientData;
|
||||||
import org.geysermc.connector.utils.AttributeUtils;
|
import org.geysermc.connector.utils.AttributeUtils;
|
||||||
import org.geysermc.connector.utils.LanguageUtils;
|
import org.geysermc.connector.utils.FileUtils;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.security.interfaces.ECPublicKey;
|
import java.security.interfaces.ECPublicKey;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -203,7 +204,17 @@ public class PacketHandler implements BedrockPacketHandler {
|
||||||
public boolean handle(SetLocalPlayerAsInitializedPacket packet) {
|
public boolean handle(SetLocalPlayerAsInitializedPacket packet) {
|
||||||
masterServer.getLogger().debug("Player initialized: " + player.getDisplayName());
|
masterServer.getLogger().debug("Player initialized: " + player.getDisplayName());
|
||||||
|
|
||||||
player.sendWindow(FormID.MAIN, UIHandler.getServerList(player.getServers()));;
|
String message = "";
|
||||||
|
try {
|
||||||
|
File messageFile = FileUtils.fileOrCopiedFromResource(new File(MasterServer.getInstance().getGeyserConnectConfig().getWelcomeFile()), "welcome.txt", (x) -> x);
|
||||||
|
message = new String(FileUtils.readAllBytes(messageFile));
|
||||||
|
} catch (IOException ignored) { }
|
||||||
|
|
||||||
|
if (!message.trim().isEmpty()) {
|
||||||
|
player.sendWindow(FormID.WELCOME, UIHandler.getMessageWindow(message));
|
||||||
|
} else {
|
||||||
|
player.sendWindow(FormID.MAIN, UIHandler.getServerList(player.getServers()));
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -225,6 +236,10 @@ public class PacketHandler implements BedrockPacketHandler {
|
||||||
} else {
|
} else {
|
||||||
// Send the response to the correct response function
|
// Send the response to the correct response function
|
||||||
switch (id) {
|
switch (id) {
|
||||||
|
case WELCOME:
|
||||||
|
player.sendWindow(FormID.MAIN, UIHandler.getServerList(player.getServers()));
|
||||||
|
break;
|
||||||
|
|
||||||
case MAIN:
|
case MAIN:
|
||||||
UIHandler.handleServerListResponse(player, (SimpleFormResponse) window.getResponse());
|
UIHandler.handleServerListResponse(player, (SimpleFormResponse) window.getResponse());
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -30,6 +30,7 @@ import lombok.Getter;
|
||||||
@Getter
|
@Getter
|
||||||
public enum FormID {
|
public enum FormID {
|
||||||
|
|
||||||
|
WELCOME,
|
||||||
MAIN,
|
MAIN,
|
||||||
DIRECT_CONNECT(true),
|
DIRECT_CONNECT(true),
|
||||||
EDIT_SERVERS(true),
|
EDIT_SERVERS(true),
|
||||||
|
|
|
@ -182,6 +182,13 @@ public class UIHandler {
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static FormWindow getMessageWindow(String message) {
|
||||||
|
CustomFormWindow window = new CustomFormBuilder("Notice")
|
||||||
|
.addComponent(new LabelComponent(message))
|
||||||
|
.build();
|
||||||
|
return window;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle the server list response
|
* Handle the server list response
|
||||||
*
|
*
|
||||||
|
|
|
@ -20,6 +20,10 @@ max-players: 100
|
||||||
# MOTD to display
|
# MOTD to display
|
||||||
motd: "GeyserConnect Proxy"
|
motd: "GeyserConnect Proxy"
|
||||||
|
|
||||||
|
# Welcome message file, if file exists and is not empty this will show on join
|
||||||
|
# This is loaded live so will update without a server restart
|
||||||
|
welcome-file: welcome.txt
|
||||||
|
|
||||||
# Config for the Geyser listener
|
# Config for the Geyser listener
|
||||||
geyser:
|
geyser:
|
||||||
# The port that will listen for connections
|
# The port that will listen for connections
|
||||||
|
|
0
src/main/resources/welcome.txt
Normal file
0
src/main/resources/welcome.txt
Normal file
Loading…
Add table
Reference in a new issue