55import com .google .gson .JsonElement ;
66import com .google .gson .JsonObject ;
77import com .google .gson .JsonParser ;
8+ import com .viaversion .viaversion .api .protocol .version .ProtocolVersion ;
89import com .viaversion .viaversion .util .ChatColorUtil ;
910import io .netty .buffer .ByteBuf ;
1011import io .netty .buffer .ByteBufUtil ;
2425import net .raphimc .vialegacy .protocols .release .protocol1_6_1to1_5_2 .ClientboundPackets1_5_2 ;
2526import net .raphimc .vialegacy .protocols .release .protocol1_6_1to1_5_2 .ServerboundPackets1_5_2 ;
2627import net .raphimc .vialegacy .protocols .release .protocol1_7_2_5to1_6_4 .types .Types1_6_4 ;
27- import net .raphimc .vialoader .util .VersionEnum ;
2828import net .raphimc .viaproxy .proxy .session .LegacyProxyConnection ;
2929import net .raphimc .viaproxy .proxy .session .ProxyConnection ;
3030import net .raphimc .viaproxy .proxy .util .ExceptionUtil ;
4343import java .util .concurrent .TimeUnit ;
4444
4545public class EaglerServerHandler extends MessageToMessageCodec <WebSocketFrame , ByteBuf > {
46- private final VersionEnum version ;
46+ private final ProtocolVersion version ;
4747 private final String password ;
4848 private final NetClient proxyConnection ;
4949 private final Map <UUID , String > uuidStringMap = new HashMap <>();
@@ -53,7 +53,7 @@ public class EaglerServerHandler extends MessageToMessageCodec<WebSocketFrame, B
5353 private ByteBuf serverBoundPartialPacket = Unpooled .EMPTY_BUFFER ;
5454 private ByteBuf clientBoundPartialPacket = Unpooled .EMPTY_BUFFER ;
5555 public EaglerServerHandler (NetClient proxyConnection , String password ) {
56- this .version = proxyConnection instanceof ProxyConnection ? ((ProxyConnection ) proxyConnection ).getServerVersion () : VersionEnum .r1_5_2 ;
56+ this .version = proxyConnection instanceof ProxyConnection ? ((ProxyConnection ) proxyConnection ).getServerVersion () : LegacyProtocolVersion .r1_5_2 ;
5757 this .password = password ;
5858 this .proxyConnection = proxyConnection ;
5959 }
@@ -71,7 +71,7 @@ public void encode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) {
7171 out .add (Unpooled .EMPTY_BUFFER );
7272 return ;
7373 }
74- if (version .isNewerThan ( VersionEnum . r1_6_4 )) {
74+ if (version .newerThanOrEqualTo ( ProtocolVersion . v1_7_2 )) {
7575 if (in .readableBytes () >= 2 && in .getUnsignedByte (0 ) == 0xFE && in .getUnsignedByte (1 ) == 0x01 ) {
7676 handshakeState = -1 ;
7777 out .add (new TextWebSocketFrame ("Accept: MOTD" ));
@@ -282,7 +282,7 @@ public void decode(ChannelHandlerContext ctx, WebSocketFrame in, List<Object> ou
282282 ByteBuf bb = ctx .alloc ().buffer ();
283283 bb .writeByte ((byte ) 0xFF );
284284 StringBuilder sb = new StringBuilder ("\u00A7 1\0 " );
285- sb .append (LegacyProtocolVersion . getRealProtocolVersion ( version .getVersion () )).append ("\0 " );
285+ sb .append (version .getVersion ()).append ("\0 " );
286286 sb .append (version .getName ()).append ("\0 " );
287287 sb .append (motdSb ).append ("\0 " );
288288 sb .append (online ).append ("\0 " );
@@ -307,7 +307,7 @@ public void decode(ChannelHandlerContext ctx, WebSocketFrame in, List<Object> ou
307307 JsonObject resp = new JsonObject ();
308308 JsonObject versionObj = new JsonObject ();
309309 versionObj .addProperty ("name" , version .getName ());
310- versionObj .addProperty ("protocol" , LegacyProtocolVersion . getRealProtocolVersion ( version .getVersion () ));
310+ versionObj .addProperty ("protocol" , version .getVersion ());
311311 resp .add ("version" , versionObj );
312312 JsonObject playersObj = new JsonObject ();
313313 playersObj .addProperty ("max" , max );
@@ -358,7 +358,7 @@ public void decode(ChannelHandlerContext ctx, WebSocketFrame in, List<Object> ou
358358 JsonObject resp = new JsonObject ();
359359 JsonObject versionObj = new JsonObject ();
360360 versionObj .addProperty ("name" , version .getName ());
361- versionObj .addProperty ("protocol" , LegacyProtocolVersion . getRealProtocolVersion ( version .getVersion () ));
361+ versionObj .addProperty ("protocol" , version .getVersion ());
362362 resp .add ("version" , versionObj );
363363 JsonObject playersObj = new JsonObject ();
364364 playersObj .addProperty ("max" , serverInfo .max );
@@ -401,7 +401,7 @@ public void decode(ChannelHandlerContext ctx, WebSocketFrame in, List<Object> ou
401401 handshakeState = -1 ;
402402 return ;
403403 }
404- if (version .isNewerThan ( VersionEnum . r1_6_4 )) {
404+ if (version .newerThanOrEqualTo ( ProtocolVersion . v1_7_2 )) {
405405 if (handshakeState == 0 ) {
406406 out .add (Unpooled .EMPTY_BUFFER );
407407 } else if (handshakeState == 1 ) {
@@ -440,7 +440,7 @@ public void decode(ChannelHandlerContext ctx, WebSocketFrame in, List<Object> ou
440440 bb .writeBytes (clientBoundPartialPacket );
441441 clientBoundPartialPacket .release ();
442442 clientBoundPartialPacket = Unpooled .EMPTY_BUFFER ;
443- bb .writeBytes (in .content ());
443+ bb .writeBytes (in .content ()); // todo: do i need to reset this??????
444444 int readerIndex = 0 ;
445445 try {
446446 while (bb .isReadable ()) {
0 commit comments