fix packet handlers
This commit is contained in:
@@ -4,12 +4,11 @@ import io.netty.channel.ChannelHandlerContext;
|
|||||||
import io.netty.channel.SimpleChannelInboundHandler;
|
import io.netty.channel.SimpleChannelInboundHandler;
|
||||||
import mc.protocol.Packet;
|
import mc.protocol.Packet;
|
||||||
|
|
||||||
public abstract class AbstractPacketHandler<P extends Packet> extends SimpleChannelInboundHandler<Packet> {
|
public abstract class AbstractPacketHandler<P extends Packet> extends SimpleChannelInboundHandler<P> {
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Override
|
@Override
|
||||||
protected void channelRead0(ChannelHandlerContext ctx, Packet msg) throws Exception {
|
protected void channelRead0(ChannelHandlerContext ctx, P msg) throws Exception {
|
||||||
channelRead1(ctx, (P) msg);
|
channelRead1(ctx, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void channelRead1(ChannelHandlerContext ctx, P packet) throws Exception;
|
protected abstract void channelRead1(ChannelHandlerContext ctx, P packet) throws Exception;
|
||||||
|
|||||||
@@ -1,20 +1,38 @@
|
|||||||
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.State;
|
||||||
|
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 static mc.server.network.impl.NettyConstants.ATTR_STATE;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor(onConstructor = @__({ @Inject }))
|
||||||
public class StatusHandler extends AbstractPacketHandler<StatusServerRequest> {
|
public class StatusHandler extends AbstractPacketHandler<StatusServerRequest> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void channelRead1(ChannelHandlerContext ctx, StatusServerRequest packet) {
|
protected void channelRead1(ChannelHandlerContext ctx, StatusServerRequest packet) {
|
||||||
log.info("{}", packet);
|
log.info("{}", packet);
|
||||||
|
|
||||||
StatusServerResponse response = new StatusServerResponse();
|
final ServerInfo.Version version = new ServerInfo.Version();
|
||||||
response.setInfo("some info server text");
|
version.setName(ProtocolConstant.PROTOCOL_VERSION_VALUE);
|
||||||
|
version.setProtocol(ProtocolConstant.PROTOCOL_VERSION);
|
||||||
|
|
||||||
ctx.channel().writeAndFlush(response).channel().disconnect();
|
final ServerInfo serverInfo = new ServerInfo();
|
||||||
|
serverInfo.setVersion(version);
|
||||||
|
serverInfo.setDescription(Text.of("MC-SERVER 1.8.8"));
|
||||||
|
|
||||||
|
StatusServerResponse response = new StatusServerResponse();
|
||||||
|
response.setServerInfoDto(serverInfo);
|
||||||
|
|
||||||
|
ctx.channel().writeAndFlush(response)/*.channel().disconnect()*/;
|
||||||
|
ctx.channel().attr(ATTR_STATE).set(State.PLAY); //TODO просто что бы был UnknownPacket
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user