добавлен значок сервера
This commit is contained in:
@@ -20,4 +20,5 @@ dependencies {
|
||||
implementation libs.reactor
|
||||
implementation libs.guava
|
||||
implementation libs.yaml
|
||||
implementation libs.ioutils
|
||||
}
|
||||
|
||||
@@ -14,8 +14,13 @@ import mc.server.config.Config;
|
||||
import mc.server.di.ConfigModule;
|
||||
import mc.server.di.DaggerServerComponent;
|
||||
import mc.server.di.ServerComponent;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Base64;
|
||||
import java.util.Collections;
|
||||
|
||||
@Slf4j
|
||||
@@ -58,6 +63,10 @@ public class Main {
|
||||
serverInfo.players().sample(Collections.emptyList());
|
||||
serverInfo.description(config.motd());
|
||||
|
||||
if (config.iconPath() != null) {
|
||||
serverInfo.favicon(faviconToBase64(config.iconPath()));
|
||||
}
|
||||
|
||||
StatusServerResponse response = new StatusServerResponse();
|
||||
response.setInfo(serverInfo);
|
||||
|
||||
@@ -75,4 +84,15 @@ public class Main {
|
||||
|
||||
server.bind(config.server().host(), config.server().port());
|
||||
}
|
||||
|
||||
private static String faviconToBase64(Path iconPath) {
|
||||
try {
|
||||
return "data:image/png;base64," +
|
||||
Base64.getEncoder().encodeToString(
|
||||
IOUtils.toByteArray(Files.newInputStream(iconPath)));
|
||||
} catch (IOException e) {
|
||||
log.error("Can't read icon '{}'", iconPath.toAbsolutePath(), e);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,5 +9,5 @@ players:
|
||||
online: 0
|
||||
|
||||
icon:
|
||||
enable: false
|
||||
path: favicon.png
|
||||
enable: true
|
||||
path: src/main/resources/favicon.png
|
||||
BIN
server/src/main/resources/favicon.png
Normal file
BIN
server/src/main/resources/favicon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
Reference in New Issue
Block a user