11package club .asynclab .asyncraft .asyncauth .mixin ;
22
33import club .asynclab .asyncraft .asyncauth .util .UtilComponent ;
4+ import net .minecraft .network .Connection ;
45import net .minecraft .network .chat .Component ;
6+ import net .minecraft .network .protocol .login .ClientboundLoginDisconnectPacket ;
57import net .minecraft .server .network .ServerLoginPacketListenerImpl ;
68import org .objectweb .asm .Opcodes ;
9+ import org .slf4j .Logger ;
10+ import org .spongepowered .asm .mixin .Final ;
711import org .spongepowered .asm .mixin .Mixin ;
812import org .spongepowered .asm .mixin .Shadow ;
13+ import org .spongepowered .asm .mixin .Unique ;
914import org .spongepowered .asm .mixin .injection .At ;
1015import org .spongepowered .asm .mixin .injection .Inject ;
1116import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
@@ -15,17 +20,40 @@ public abstract class MixinServerLoginPacketListenerImpl {
1520 @ Shadow
1621 private int tick ;
1722
23+ @ Final
24+ @ Shadow
25+ Connection connection ;
26+
27+ @ Final
28+ @ Shadow
29+ static Logger LOGGER ;
30+
1831 @ Shadow
1932 public static int MAX_TICKS_BEFORE_LOGIN = 600 ;
2033
2134 @ Shadow
22- public abstract void disconnect (Component reason );
35+ public abstract String getUserName ();
36+
37+ // @Shadow
38+ // public abstract void disconnect(Component reason);
2339
2440 @ Inject (method = "tick" , at = @ At (value = "FIELD" , target = "Lnet/minecraft/server/network/ServerLoginPacketListenerImpl;tick:I" , opcode = Opcodes .GETFIELD ), cancellable = true )
2541 private void onTick (CallbackInfo ci ) {
2642 if (MAX_TICKS_BEFORE_LOGIN != 0 && this .tick ++ == MAX_TICKS_BEFORE_LOGIN ) {
2743 this .disconnect (UtilComponent .getTranslatableComponent ("multiplayer.disconnect.slow_login" ));
2844 }
2945 ci .cancel ();
46+
47+ }
48+
49+ @ Unique
50+ private void disconnect (Component pReason ) {
51+ try {
52+ LOGGER .info ("Disconnecting {}: {}" , this .getUserName (), pReason .getString ());
53+ this .connection .send (new ClientboundLoginDisconnectPacket (pReason ));
54+ this .connection .disconnect (pReason );
55+ } catch (Exception exception ) {
56+ LOGGER .error ("Error whilst disconnecting player" , exception );
57+ }
3058 }
3159}
0 commit comments