set favicon server
This commit is contained in:
@@ -26,6 +26,7 @@ ext {
|
|||||||
netty: ['io.netty:netty-all:4.1.22.Final'],
|
netty: ['io.netty:netty-all:4.1.22.Final'],
|
||||||
slf4j: ["org.slf4j:slf4j-api:$slf4j_version",
|
slf4j: ["org.slf4j:slf4j-api:$slf4j_version",
|
||||||
"org.slf4j:jcl-over-slf4j:$slf4j_version"],
|
"org.slf4j:jcl-over-slf4j:$slf4j_version"],
|
||||||
|
commons: ['commons-io:commons-io:2.6']
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,5 +42,6 @@ dependencies {
|
|||||||
/* COMPONENTS */
|
/* COMPONENTS */
|
||||||
implementation library.guice
|
implementation library.guice
|
||||||
implementation library.netty
|
implementation library.netty
|
||||||
|
implementation library.commons
|
||||||
implementation project(':protocol')
|
implementation project(':protocol')
|
||||||
}
|
}
|
||||||
@@ -1,21 +1,24 @@
|
|||||||
package mc.server.network.impl.handler;
|
package mc.server.network.impl.handler;
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import mc.protocol.ProtocolConstant;
|
import mc.protocol.ProtocolConstant;
|
||||||
import mc.protocol.dto.ServerInfo;
|
import mc.protocol.dto.ServerInfo;
|
||||||
import mc.protocol.status.client.StatusServerRequest;
|
import mc.protocol.status.client.StatusServerRequest;
|
||||||
import mc.protocol.status.server.StatusServerResponse;
|
import mc.protocol.status.server.StatusServerResponse;
|
||||||
import mc.protocol.text.Text;
|
import mc.protocol.text.Text;
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Base64;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RequiredArgsConstructor(onConstructor = @__({ @Inject }))
|
|
||||||
public class StatusHandler extends AbstractPacketHandler<StatusServerRequest> {
|
public class StatusHandler extends AbstractPacketHandler<StatusServerRequest> {
|
||||||
|
|
||||||
|
private static final String FAVICON_HEADER = "data:image/png;base64,";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void channelRead1(ChannelHandlerContext ctx, StatusServerRequest packet) {
|
protected void channelRead1(ChannelHandlerContext ctx, StatusServerRequest packet) throws Exception {
|
||||||
log.info("{}", packet);
|
log.info("{}", packet);
|
||||||
|
|
||||||
final ServerInfo.Version version = new ServerInfo.Version();
|
final ServerInfo.Version version = new ServerInfo.Version();
|
||||||
@@ -25,10 +28,16 @@ public class StatusHandler extends AbstractPacketHandler<StatusServerRequest> {
|
|||||||
final ServerInfo serverInfo = new ServerInfo();
|
final ServerInfo serverInfo = new ServerInfo();
|
||||||
serverInfo.setVersion(version);
|
serverInfo.setVersion(version);
|
||||||
serverInfo.setDescription(Text.of("MC-SERVER 1.8.8"));
|
serverInfo.setDescription(Text.of("MC-SERVER 1.8.8"));
|
||||||
|
serverInfo.setFaviconBase64(getEmbeddedIconBase64());
|
||||||
|
|
||||||
StatusServerResponse response = new StatusServerResponse();
|
StatusServerResponse response = new StatusServerResponse();
|
||||||
response.setServerInfoDto(serverInfo);
|
response.setServerInfoDto(serverInfo);
|
||||||
|
|
||||||
ctx.channel().writeAndFlush(response);
|
ctx.channel().writeAndFlush(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getEmbeddedIconBase64() throws IOException {
|
||||||
|
return FAVICON_HEADER + Base64.getEncoder()
|
||||||
|
.encodeToString(IOUtils.toByteArray(getClass().getResourceAsStream("/icon.png")));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
src/main/resources/icon.png
Normal file
BIN
src/main/resources/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.6 KiB |
Reference in New Issue
Block a user