From ef984b28f0339b879222cf3bb005297f79e0c46b Mon Sep 17 00:00:00 2001 From: DmitriyMX Date: Wed, 28 Apr 2021 19:31:39 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=B7=D0=BD=D0=B0=D1=87=D0=BE=D0=BA=20=D1=81=D0=B5?= =?UTF-8?q?=D1=80=D0=B2=D0=B5=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs.gradle | 3 ++- .../packets/server/StatusServerResponse.java | 13 +++++++++--- server/build.gradle | 1 + server/src/main/java/mc/server/Main.java | 20 ++++++++++++++++++ server/src/main/resources/config.yml | 4 ++-- server/src/main/resources/favicon.png | Bin 0 -> 1675 bytes 6 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 server/src/main/resources/favicon.png diff --git a/libs.gradle b/libs.gradle index fc2589b..a4eb76f 100644 --- a/libs.gradle +++ b/libs.gradle @@ -16,7 +16,8 @@ ext { netty : 'io.netty:netty-all:4.1.22.Final', reactor : 'io.projectreactor:reactor-core:3.4.5', yaml : 'org.yaml:snakeyaml:1.28', - json : 'com.eclipsesource.minimal-json:minimal-json:0.9.5' + json : 'com.eclipsesource.minimal-json:minimal-json:0.9.5', + ioutils : 'commons-io:commons-io:2.6' ] libs.logger = [ diff --git a/protocol/src/main/java/mc/protocol/packets/server/StatusServerResponse.java b/protocol/src/main/java/mc/protocol/packets/server/StatusServerResponse.java index a238d20..32b26c7 100644 --- a/protocol/src/main/java/mc/protocol/packets/server/StatusServerResponse.java +++ b/protocol/src/main/java/mc/protocol/packets/server/StatusServerResponse.java @@ -48,6 +48,8 @@ import java.util.stream.Collector; * "favicon": "data:image/png;base64,<data>" * } * + * + *

`$.favicon` должен быть формата PNG и размеры 64x64 px

*/ @Data public class StatusServerResponse implements ServerSidePacket { @@ -59,11 +61,16 @@ public class StatusServerResponse implements ServerSidePacket { @Override public void writeSelf(NetByteBuf netByteBuf) { - netByteBuf.writeString(Json.object() + JsonObject jsonObject = Json.object() .add("version", createVersionObj()) .add("players", createPlayersObj()) - .add("description", Json.object().add("text", info.description())) - .toString()); + .add("description", Json.object().add("text", info.description())); + + if (info.favicon() != null && !info.favicon().isEmpty()) { + jsonObject.add("favicon", info.favicon()); + } + + netByteBuf.writeString(jsonObject.toString()); } private JsonObject createVersionObj() { diff --git a/server/build.gradle b/server/build.gradle index 46c8b98..3854cf5 100644 --- a/server/build.gradle +++ b/server/build.gradle @@ -20,4 +20,5 @@ dependencies { implementation libs.reactor implementation libs.guava implementation libs.yaml + implementation libs.ioutils } diff --git a/server/src/main/java/mc/server/Main.java b/server/src/main/java/mc/server/Main.java index 0592fa1..c07e3c1 100644 --- a/server/src/main/java/mc/server/Main.java +++ b/server/src/main/java/mc/server/Main.java @@ -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 ""; + } + } } diff --git a/server/src/main/resources/config.yml b/server/src/main/resources/config.yml index af6b6aa..81df62d 100644 --- a/server/src/main/resources/config.yml +++ b/server/src/main/resources/config.yml @@ -9,5 +9,5 @@ players: online: 0 icon: - enable: false - path: favicon.png \ No newline at end of file + enable: true + path: src/main/resources/favicon.png \ No newline at end of file diff --git a/server/src/main/resources/favicon.png b/server/src/main/resources/favicon.png new file mode 100644 index 0000000000000000000000000000000000000000..d512fc5472e1d4b4573ba22b5e3e71587dbd4c9f GIT binary patch literal 1675 zcmV;626Xv}P)09zrl&^1WzcGf>6{pC7KKEp~p(7 zm8$R+BqT&YDrzr1B0?|WNG@&Q)Kgp3N=;EK4kUb5;xDLFQ7H?^5{eKeBm_fnt9);4 z_pn}j*IwH*J2STPlPs-g-^_dS+u4~n@6BpcQ&VUHf&eZ8_=ZvbTL2dT7&48Zlvb7b zWGbk@IDkU&w+{BsqbR#>t3NK?x*}u~Fo3erLlWB^vb8%Pv0Z5doP}xJElKUw!>yvO zvoabJC13)kF_$IS!i&pA-4h~>1O)0youCA81SSzd02{oOy^Me#(LSBG!vOFzZzbLl zunv>ycEuMkC(ICQ1s(zlywz-H;Z9ZWW}5U?3LZ=s>>jR;tiWJoJf zw-5CQ_z4`7NgE>svoEgDYHWu5;9OG&Pkzm3mLSdy4dU>?XFOGcl+vm`)fxfZ4n-@F z$z)&{%r1$mpxZKd-HS2Xdx)26p7GAxI{*OLY!-<`0>NNo_e9tA>y*+#dzl*nM@0Kttz#*yDvK`y0*UpH(X>rVM`=}ojZD5?-?68 zq@O*oAGpUcqZTpe|NcS26u0jodJ?uL0i9_bW z_df{fuSbHe>%US;Pg?}Y3}8Ai{Ui;auiD@8`Fxm}eSv&FkFG=6uy3{yxxs?>ov>&iFj2AYnKF#@HDT^oJ?v4^y(6l?EFLn)FF< z&!Nv9|DWEx>pGj;p?VT@gGGXL0-oNyTUFMI4zfaJc6d`jsUOhyZg1&2^>`W|b_B3J z}SADsBhDam=pu7tF21QY! zHr^DC17%nElnM=gpO5)x_XJfV6bgY-dKysd2jm)r!diuRyu3TL6L1uQXYSnKkAz*z zbE|8JMz;b0mX}xHM*(49<594blX76Clq0kgpu}Cv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