· 6 years ago · Jul 22, 2019, 12:48 PM
1package net.minecraft.server.v1_7_R4;
2
3import com.google.common.base.Joiner;
4import com.google.common.collect.ImmutableSet;
5import java.net.SocketAddress;
6import java.util.ArrayList;
7import java.util.Iterator;
8import java.util.List;
9import java.util.Queue;
10import java.util.UUID;
11import javax.crypto.SecretKey;
12import net.minecraft.util.com.google.common.collect.Queues;
13import net.minecraft.util.com.google.common.util.concurrent.ThreadFactoryBuilder;
14import net.minecraft.util.com.mojang.authlib.properties.Property;
15import net.minecraft.util.io.netty.channel.Channel;
16import net.minecraft.util.io.netty.channel.ChannelFutureListener;
17import net.minecraft.util.io.netty.channel.ChannelHandlerContext;
18import net.minecraft.util.io.netty.channel.SimpleChannelInboundHandler;
19import net.minecraft.util.io.netty.channel.nio.NioEventLoopGroup;
20import net.minecraft.util.io.netty.util.AttributeKey;
21import net.minecraft.util.io.netty.util.concurrent.GenericFutureListener;
22import net.minecraft.util.org.apache.commons.lang3.Validate;
23import org.apache.logging.log4j.LogManager;
24import org.apache.logging.log4j.Logger;
25import org.apache.logging.log4j.Marker;
26import org.apache.logging.log4j.MarkerManager;
27import org.bukkit.Bukkit;
28import org.bukkit.event.player.GCheatEvent;
29import org.spigotmc.SpigotCompressor;
30import org.spigotmc.SpigotConfig;
31import org.spigotmc.SpigotDecompressor;
32
33public class NetworkManager
34 extends SimpleChannelInboundHandler {
35 private static final Logger i = LogManager.getLogger();
36 public static final Marker a = MarkerManager.getMarker("NETWORK");
37 public static final Marker b = MarkerManager.getMarker("NETWORK_PACKETS", a);
38 public static final Marker c = MarkerManager.getMarker("NETWORK_STAT", a);
39 public static final AttributeKey d = new AttributeKey("protocol");
40 public static final AttributeKey e = new AttributeKey("receivable_packets");
41 public static final AttributeKey f = new AttributeKey("sendable_packets");
42 public static final NioEventLoopGroup g = new NioEventLoopGroup(false, (new ThreadFactoryBuilder()).setNameFormat("Netty Client IO #%d").setDaemon(true).build());
43 public static final NetworkStatistics h = new NetworkStatistics();
44
45 private final boolean j;
46
47 private final Queue k;
48
49 private final Queue l;
50 private Channel m;
51 public SocketAddress n;
52 public UUID spoofedUUID;
53 public Property[] spoofedProfile;
54 public boolean preparing;
55 private PacketListener o;
56 private EnumProtocol p;
57 private IChatBaseComponent q;
58 private boolean r;
59 public static final AttributeKey<Integer> protocolVersion = new AttributeKey("protocol_version");
60 public static final ImmutableSet<Integer> SUPPORTED_VERSIONS = ImmutableSet.of(Integer.valueOf(4), Integer.valueOf(5), Integer.valueOf(47), Integer.valueOf(107), Integer.valueOf(108), Integer.valueOf(109), new Integer[] { null, (new Integer[2][0] = Integer.valueOf(110)).valueOf(210) }); public static final int CURRENT_VERSION = 5; private int version; public boolean stopReadingPackets; private Packet[] packets; private long[] limitTimes; public long lastTickNetworkProcessed; public long ticksSinceLastPacket; private int numOfH; private List<Long> numOfHLogs; private int numOfI; private List<Long> numOfILogs; private long lastKTick;
61 public long currentTime;
62 public long lastVehicleTick;
63 public int numOfFlyingPacketsInARow;
64
65 public static int getVersion(Channel attr) {
66 Integer ver = (Integer)attr.attr(protocolVersion).get();
67 return (ver != null) ? ver.intValue() : 5;
68 }
69
70 public int getVersion() {
71 if (this.version == 0) {
72 Integer ver = (Integer)this.m.attr(protocolVersion).get();
73 if (ver == null) {
74 return 5;
75 }
76 this.version = ver.intValue();
77 }
78 return this.version;
79 }
80 public NetworkManager(boolean flag) { this.k = Queues.newConcurrentLinkedQueue();
81 this.l = Queues.newConcurrentLinkedQueue();
82 this.preparing = true;
83 this.version = 0;
84 this.stopReadingPackets = false;
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415 this.packets = new Packet[10];
416 this.limitTimes = new long[12];
417 this.lastTickNetworkProcessed = MinecraftServer.currentTick;
418 this.ticksSinceLastPacket = -1L;
419 this.numOfH = 0;
420 this.numOfHLogs = new ArrayList();
421 this.numOfI = 0;
422 this.numOfILogs = new ArrayList();
423 this.lastKTick = MinecraftServer.currentTick;
424 this.currentTime = System.currentTimeMillis();
425 this.lastVehicleTick = -1L;
426 this.numOfFlyingPacketsInARow = 0; this.j = flag; this.limitTimes[0] = 4000L; this.limitTimes[1] = 4000L; this.limitTimes[2] = 4000L; this.limitTimes[3] = 4000L; this.limitTimes[4] = 5000L; this.limitTimes[5] = 6000L; this.limitTimes[6] = 7000L; this.limitTimes[7] = 7000L; this.limitTimes[8] = 7000L; this.limitTimes[9] = 7000L; this.limitTimes[10] = 7000L; this.limitTimes[11] = 7000L; } public void channelActive(ChannelHandlerContext channelhandlercontext) throws Exception { super.channelActive(channelhandlercontext); this.m = channelhandlercontext.channel(); this.n = this.m.remoteAddress(); this.preparing = false; a(EnumProtocol.HANDSHAKING); } public void a(EnumProtocol enumprotocol) { this.p = (EnumProtocol)this.m.attr(d).getAndSet(enumprotocol); this.m.attr(e).set(enumprotocol.a(this.j)); this.m.attr(f).set(enumprotocol.b(this.j)); this.m.config().setAutoRead(true); i.debug("Enabled auto read"); }
427 public void channelInactive(ChannelHandlerContext channelhandlercontext) throws Exception { close(new ChatMessage("disconnect.endOfStream", new Object[0])); }
428 public void exceptionCaught(ChannelHandlerContext channelhandlercontext, Throwable throwable) { ChatMessage chatmessage; if (throwable instanceof net.minecraft.util.io.netty.handler.timeout.TimeoutException) { chatmessage = new ChatMessage("disconnect.timeout", new Object[0]); } else { chatmessage = new ChatMessage("disconnect.genericReason", new Object[] { "Internal Exception: " + throwable }); } close(chatmessage); if (MinecraftServer.getServer().isDebugging()) throwable.printStackTrace(); }
429 public void a() { i();
430 EnumProtocol enumprotocol = (EnumProtocol)this.m.attr(d).get();
431
432 if (this.p != enumprotocol) {
433 if (this.p != null) {
434 this.o.a(this.p, enumprotocol);
435 }
436
437 this.p = enumprotocol;
438 }
439
440 if (this.o != null) {
441
442 boolean processed = false;
443
444 int i = SpigotConfig.maxPacketsPerPlayer; while (true) { Packet packet; if ((packet = (Packet)this.k.poll()) != null && i >= 0)
445
446 {
447 if (this.stopReadingPackets || !isConnected() || !this.m.config().isAutoRead()) {
448 continue;
449 }
450
451
452
453
454 if (!processed) {
455 this.ticksSinceLastPacket = MinecraftServer.currentTick - this.lastTickNetworkProcessed;
456 this.lastTickNetworkProcessed = MinecraftServer.currentTick;
457 this.currentTime = System.currentTimeMillis();
458 processed = true;
459 }
460
461
462
463 if (this.o instanceof PlayerConnection)
464 { PlayerConnection connection = (PlayerConnection)this.o;
465
466
467 if (packet instanceof PacketPlayInKeepAlive)
468 { ((PlayerConnection)this.o).handleKeepAliveSync((PacketPlayInKeepAlive)packet);
469
470
471 }
472
473 else if (packet instanceof PacketPlayInChat || packet instanceof PacketPlayInCustomPayload)
474 { packet.handle(this.o); }
475
476 else
477
478 { if (connection.isAntiCheatActivated() &&
479 !MinecraftServer.getServer().getAllowFlight() && !connection.player.abilities.canFly && !connection.player.abilities.canInstantlyBuild) {
480 boolean eventFired = false;
481 int size = connection.lastPacketsQueue.size();
482 if (size >= this.packets.length) {
483
484 if (packet instanceof PacketPlayInUseEntity && ((PacketPlayInUseEntity)packet).c() == EnumEntityUseAction.ATTACK) {
485
486
487
488
489
490
491
492
493
494
495 for (int j = 0; j < this.packets.length; j++) {
496 this.packets[j] = (Packet)connection.lastPacketsQueue.removeLast();
497 }
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570 Class packet0Class = this.packets[0].getClass();
571 if (packet0Class.equals(PacketPlayInArmAnimation.class))
572 {
573
574
575 if (this.packets[1].getClass().equals(PacketPlayInUseEntity.class) && this.packets[2].getClass().equals(PacketPlayInArmAnimation.class) && ((PacketPlayInUseEntity)this.packets[true])
576 .c() == EnumEntityUseAction.ATTACK && getVersion() <= 47) {
577
578 if (this.packets[3].getClass().equals(PacketPlayInUseEntity.class) && this.packets[4].getClass().equals(PacketPlayInArmAnimation.class) && ((PacketPlayInUseEntity)this.packets[3])
579 .c() == EnumEntityUseAction.ATTACK) {
580 if (this.packets[5].getClass().equals(PacketPlayInUseEntity.class) && this.packets[6].getClass().equals(PacketPlayInArmAnimation.class) && ((PacketPlayInUseEntity)this.packets[5])
581 .c() == EnumEntityUseAction.ATTACK) {
582 if (this.packets[7].getClass().equals(PacketPlayInUseEntity.class) && this.packets[8].getClass().equals(PacketPlayInArmAnimation.class) && ((PacketPlayInUseEntity)this.packets[7])
583 .c() == EnumEntityUseAction.ATTACK) {
584 if (connection.hackDebug) {
585 Bukkit.getLogger().info(connection.getPlayer().getName() + " was caught using kill aura K");
586 }
587
588 if (this.lastKTick != MinecraftServer.currentTick) {
589 Bukkit.getPluginManager().callEvent(new GCheatEvent(connection.getPlayer(), GCheatEvent.Type.KILL_AURA, GCheatEvent.Level.ADMIN, connection.getPlayer().getName() + " is using Kill Aura Type K (Experimental) " + this.ticksSinceLastPacket));
590 this.lastKTick = MinecraftServer.currentTick;
591 }
592 } else {
593 if (connection.hackDebug) {
594 Bukkit.getLogger().info(connection.getPlayer().getName() + " was caught using kill aura J");
595 }
596
597 Bukkit.getPluginManager().callEvent(new GCheatEvent(connection.getPlayer(), GCheatEvent.Type.KILL_AURA, GCheatEvent.Level.ADMIN, connection.getPlayer().getName() + " is using Kill Aura Type J (Experimental) " + this.ticksSinceLastPacket));
598 }
599 } else {
600 if (connection.hackDebug) {
601 Bukkit.getLogger().info(connection.getPlayer().getName() + " was caught using kill aura I");
602 }
603
604 this.numOfILogs.add(Long.valueOf(this.ticksSinceLastPacket));
605
606 if (++this.numOfI == 3) {
607 Bukkit.getPluginManager().callEvent(new GCheatEvent(connection.getPlayer(), GCheatEvent.Type.KILL_AURA, GCheatEvent.Level.ADMIN, connection.getPlayer().getName() + " is using Kill Aura Type I | " + Joiner.on(" ").join(this.numOfILogs)));
608 this.numOfI = 0;
609 this.numOfILogs.clear();
610 }
611 }
612 } else {
613 if (connection.hackDebug) {
614 Bukkit.getLogger().info(connection.getPlayer().getName() + " was caught using kill aura H");
615 }
616
617 this.numOfHLogs.add(Long.valueOf(this.ticksSinceLastPacket));
618
619 if (++this.numOfH == 5) {
620 Bukkit.getPluginManager().callEvent(new GCheatEvent(connection.getPlayer(), GCheatEvent.Type.KILL_AURA, GCheatEvent.Level.ADMIN, connection.getPlayer().getName() + " is using Kill Aura Type H | " + Joiner.on(" ").join(this.numOfHLogs)));
621 this.numOfH = 0;
622 this.numOfHLogs.clear();
623 }
624 }
625 } else {
626
627 int numberOfPreviousPacketPlayInPositionLooks = 0;
628 boolean foundPrevHitPacket = false;
629 for (int j = 1; j < this.packets.length; j++) {
630 Class packetJClass = this.packets[j].getClass();
631 if (packetJClass.equals(PacketPlayInPositionLook.class) || packetJClass.equals(PacketPlayInPosition.class) || packetJClass
632 .equals(PacketPlayInLook.class) || packetJClass.equals(PacketPlayInFlying.class)) {
633 numberOfPreviousPacketPlayInPositionLooks++;
634 foundPrevHitPacket = true;
635 } else if (packetJClass.equals(PacketPlayInUseEntity.class)) {
636 break;
637 }
638 }
639
640 if (foundPrevHitPacket) {
641
642 PacketPlayInUseEntity packetPlayInUseEntity = (PacketPlayInUseEntity)packet;
643 EnumEntityUseAction action = packetPlayInUseEntity.c();
644 WorldServer worldserver = MinecraftServer.getServer().getWorldServer(connection.player.dimension);
645 Entity entity = packetPlayInUseEntity.a(worldserver);
646
647 boolean validData = false;
648 validData = (action == EnumEntityUseAction.ATTACK && entity != connection.player && entity != null && entity instanceof EntityPlayer);
649
650 if (validData) {
651 EntityPlayer entityPlayer = (EntityPlayer)entity;
652 validData = entityPlayer.playerConnection.hasMovedInHalfSecond;
653 }
654
655
656 if (validData) {
657 List<Long> times = (List)connection.killAuraViolationsTypeC.get(Integer.valueOf(numberOfPreviousPacketPlayInPositionLooks));
658
659
660 if (connection.hackDebug) {
661 Bukkit.getLogger().info(connection.getPlayer().getName() + " has sent " + numberOfPreviousPacketPlayInPositionLooks + " position packets since last hit");
662 }
663
664 if (connection.killAuraViolationsTypeC.size() > 1) {
665 connection.killAuraViolationsTypeC.clear();
666
667 if (connection.hackDebug) {
668 Bukkit.getLogger().info("Reset");
669 }
670 }
671
672
673
674
675
676
677
678
679
680 if (times == null) {
681 times = new ArrayList<Long>();
682 connection.killAuraViolationsTypeC.put(Integer.valueOf(numberOfPreviousPacketPlayInPositionLooks), times);
683 }
684
685
686
687
688
689
690 long currentTime = System.currentTimeMillis();
691 int typeCViolations = 0;
692 times.add(Long.valueOf(currentTime));
693
694
695 for (Iterator<Long> iterator = times.iterator(); iterator.hasNext(); ) {
696 Long time = (Long)iterator.next();
697 long timeLimiter = (numberOfPreviousPacketPlayInPositionLooks < 12) ? this.limitTimes[numberOfPreviousPacketPlayInPositionLooks] : 4000L;
698 if (time.longValue() + timeLimiter >= currentTime) {
699 typeCViolations++; continue;
700 }
701 iterator.remove();
702 }
703
704
705
706 if (typeCViolations >= 10) {
707 if (connection.hackDebug) {
708 Bukkit.getLogger().info(connection.getPlayer().getName() + " was caught using kill aura with lvl " + numberOfPreviousPacketPlayInPositionLooks);
709 }
710
711 Bukkit.getPluginManager().callEvent(new GCheatEvent(connection.getPlayer(), GCheatEvent.Type.KILL_AURA, GCheatEvent.Level.ADMIN, connection.getPlayer().getName() + " is using Kill Aura Type C (Experimental). " + numberOfPreviousPacketPlayInPositionLooks));
712 times.clear();
713 eventFired = true;
714 }
715 }
716 }
717 }
718 }
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750 for (int j = this.packets.length - 1; j >= 0; j--) {
751 connection.lastPacketsQueue.add(this.packets[j]);
752 }
753 } else if (packet instanceof PacketPlayInBlockPlace) {
754 for (int j = 0; j < 3; j++) {
755 this.packets[j] = (Packet)connection.lastPacketsQueue.removeLast();
756 }
757
758 if (this.packets[0] instanceof PacketPlayInFlying && this.packets[1] instanceof PacketPlayInBlockPlace && this.packets[2] instanceof PacketPlayInBlockDig) {
759 Bukkit.getPluginManager().callEvent(new GCheatEvent(connection.getPlayer(), GCheatEvent.Type.FAST_EAT_MACHINE_GUN, GCheatEvent.Level.MOD, connection.getPlayer().getName() + " is eating or shooting too fast Type A."));
760 }
761
762
763 for (int j = 2; j >= 0; j--) {
764 connection.lastPacketsQueue.add(this.packets[j]);
765 }
766 } else if (packet instanceof PacketPlayInHeldItemSlot) {
767 for (int j = 0; j < 3; j++) {
768 this.packets[j] = (Packet)connection.lastPacketsQueue.removeLast();
769 }
770
771 if (this.packets[0] instanceof PacketPlayInBlockPlace && this.packets[1] instanceof PacketPlayInFlying && this.packets[2] instanceof PacketPlayInBlockDig) {
772 Bukkit.getPluginManager().callEvent(new GCheatEvent(connection.getPlayer(), GCheatEvent.Type.FAST_EAT_MACHINE_GUN, GCheatEvent.Level.MOD, connection.getPlayer().getName() + " is eating or shooting too fast Type B."));
773 }
774
775
776 for (int j = 2; j >= 0; j--) {
777 connection.lastPacketsQueue.add(this.packets[j]);
778 }
779 }
780
781
782 if (connection.isDigging) {
783 if (packet instanceof PacketPlayInFlying) {
784 connection.typeRStage = 1;
785 } else if (packet instanceof PacketPlayInArmAnimation) {
786 if (connection.typeRStage == 1) {
787 connection.typeRStage = 2;
788 } else if (connection.typeRStage == 2) {
789 connection.typeRStage = 0;
790 if (connection.digHorizontalMovement > 1) {
791 connection.typeRThreshold++;
792 if (connection.typeRThreshold >= 3) {
793 if (connection.hackDebug) {
794 Bukkit.getLogger().info(connection.getPlayer().getName() + " was caught using kill aura R (" + connection.typeRThreshold + ")");
795 }
796 Bukkit.getPluginManager().callEvent(new GCheatEvent(connection.getPlayer(), GCheatEvent.Type.KILL_AURA, GCheatEvent.Level.ADMIN, connection.getPlayer().getName() + " is using Kill Aura Type R (Experimental) (" + connection.typeRThreshold + ")."));
797 }
798 }
799 }
800 } else {
801 connection.typeRStage = 0;
802 }
803 } else {
804 connection.typeRStage = 0;
805 }
806 }
807
808
809
810
811
812
813
814
815
816 if (size == 10) {
817 connection.lastPacketsQueue.removeFirst();
818 }
819
820 connection.lastPacketsQueue.add(packet);
821
822
823 if (eventFired) {
824 connection.lastPacketsQueue.clear();
825 }
826
827 if (connection.hackDebug) {
828 Bukkit.getLogger().info(connection.getPlayer().getName() + " has received packet " + packet.toString() + " " + MinecraftServer.currentTick);
829 }
830 }
831
832
833
834
835 packet.handle(this.o); } continue; } } else { break; } packet.handle(this.o);
836 i--; }
837
838 this.o.a();
839 }
840
841 this.m.flush(); }
842 protected void a(ChannelHandlerContext channelhandlercontext, Packet packet) { if (this.m.isOpen()) if (packet.a()) { packet.handle(this.o); if (packet instanceof PacketPlayInKeepAlive) this.k.add(packet); } else { if (this.o instanceof PlayerConnection) { PlayerConnection connection = (PlayerConnection)this.o; if (connection.hackDebug) Bukkit.getLogger().info(connection.getPlayer().getName() + " raw packet " + packet + " at " + System.currentTimeMillis()); if (packet instanceof PacketPlayInChat || packet instanceof PacketPlayInCustomPayload) { this.k.add(packet); return; } if (packet instanceof PacketPlayInFlying) { connection.movesReceived++; connection.typeE2Swing = false; if (packet.getClass() != PacketPlayInFlying.class) { this.numOfFlyingPacketsInARow = 0; } else if (++this.numOfFlyingPacketsInARow == 21 && connection.isAntiCheatActivated()) { runSync(new GCheatEvent(connection.getPlayer(), GCheatEvent.Type.REGEN, GCheatEvent.Level.ADMIN, connection.getPlayer().getName() + " is using Regen Type B")); } } if (!connection.player.abilities.canInstantlyBuild) if (connection.lastAttackPlayerTime == 0L || this.currentTime - connection.lastAttackPlayerTime > 5000L || !connection.isAntiCheatActivated()) { connection.typeOStage = connection.typeOThreshold = 0; connection.typePStage = connection.typePThreshold = connection.typePOther = 0; connection.typeQStage = connection.typeQThreshold = 0; } else { if (connection.typeOStage == 0) { if (packet instanceof PacketPlayInArmAnimation) connection.typeOStage = 1; } else if (connection.typeOStage == 1) { if (packet instanceof PacketPlayInBlockDig && ((PacketPlayInBlockDig)packet).g() == 0) { connection.typeOStage = 2; } else { connection.typeOStage = 0; } } else if (connection.typeOStage == 2) { if (packet instanceof PacketPlayInBlockDig && ((PacketPlayInBlockDig)packet).g() == 1) { if (++connection.typeOThreshold == 5) { connection.typeOThreshold = 0; runSync(new GCheatEvent(connection.getPlayer(), GCheatEvent.Type.KILL_AURA, GCheatEvent.Level.ADMIN, connection.getPlayer().getName() + " is using Kill Aura Type O (Experimental)")); } } else { connection.typeOThreshold = 0; } connection.typeOStage = 0; } if (connection.typePStage == 0) { if (packet instanceof PacketPlayInArmAnimation) connection.typePStage = 1; } else if (connection.typePStage == 1) { if (packet instanceof PacketPlayInBlockDig && ((PacketPlayInBlockDig)packet).g() == 0) { connection.typePStage = 2; } else { connection.typePStage = 0; } } else if (connection.typePStage == 2) { if (packet instanceof PacketPlayInBlockDig && ((PacketPlayInBlockDig)packet).g() == 1) { if (++connection.typePThreshold == 5) { if (connection.typePOther > 0) runSync(new GCheatEvent(connection.getPlayer(), GCheatEvent.Type.KILL_AURA, GCheatEvent.Level.ADMIN, connection.getPlayer().getName() + " is using Kill Aura Type P (Experimental) " + connection.typePOther)); connection.typePThreshold = connection.typePOther = 0; } connection.typePStage = 0; } else if (packet instanceof PacketPlayInArmAnimation) { connection.typePStage = 3; } else { connection.typePStage = connection.typePThreshold = connection.typePOther = 0; } } else if (connection.typePStage == 3) { if (packet instanceof PacketPlayInFlying) { connection.typePStage = 4; } else { connection.typePStage = connection.typePThreshold = connection.typePOther = 0; } } else if (connection.typePStage == 4) { if (packet instanceof PacketPlayInBlockDig && ((PacketPlayInBlockDig)packet).g() == 1) { connection.typePOther++; connection.typePStage = 0; } else { connection.typePStage = connection.typePThreshold = connection.typePOther = 0; } } if (connection.typeQStage != 1 && packet instanceof PacketPlayInBlockDig && ((PacketPlayInBlockDig)packet).g() == 0) connection.typeQThreshold = 0; if (connection.typeQStage == 0) { if (packet instanceof PacketPlayInArmAnimation) connection.typeQStage = 1; } else if (connection.typeQStage == 1) { if (packet instanceof PacketPlayInBlockDig && ((PacketPlayInBlockDig)packet).g() == 0) { connection.typeQStage = 2; } else { connection.typeQStage = 0; } } else if (connection.typeQStage == 2) { if (packet instanceof PacketPlayInFlying) { connection.typeQStage = 3; } else { connection.typeQStage = 0; } } else if (connection.typeQStage == 3) { if (packet instanceof PacketPlayInBlockDig && ((PacketPlayInBlockDig)packet).g() == 1 && ++connection.typeQThreshold == 5) { connection.typeQThreshold = 0; runSync(new GCheatEvent(connection.getPlayer(), GCheatEvent.Type.KILL_AURA, GCheatEvent.Level.ADMIN, connection.getPlayer().getName() + " is using Kill Aura Type Q (Experimental)")); } connection.typeQStage = 0; } } if (packet instanceof PacketPlayInArmAnimation) connection.typeE2Swing = true; if (connection.movesReceived > 20L && getVersion() <= 47 && !connection.typeE2Swing && connection.isAntiCheatActivated() && packet instanceof PacketPlayInUseEntity && ((PacketPlayInUseEntity)packet).c() == EnumEntityUseAction.ATTACK) runSync(new GCheatEvent(connection.getPlayer(), GCheatEvent.Type.KILL_AURA, GCheatEvent.Level.ADMIN, connection.getPlayer().getName() + " is using Kill Aura Type E2.")); if (connection.isAntiCheatActivated())
843 if (packet instanceof PacketPlayInFlying && ((PacketPlayInFlying)packet).hasPos) { if (((PacketPlayInFlying)packet).i()) { connection.criticalTypeBStage = 1; connection.criticalTypeBY = ((PacketPlayInFlying)packet).d(); } else if (connection.criticalTypeBStage == 1 && ((PacketPlayInFlying)packet).d() < connection.criticalTypeBY) { connection.criticalTypeBStage = 2; connection.criticalTypeBHeight = connection.criticalTypeBY - ((PacketPlayInFlying)packet).d(); connection.criticalTypeBY = ((PacketPlayInFlying)packet).d(); } else if (connection.criticalTypeBStage == 2 && ((PacketPlayInFlying)packet).d() > connection.criticalTypeBY) { connection.criticalTypeBStage = 3; connection.criticalTypeBY = ((PacketPlayInFlying)packet).d(); } else if (connection.criticalTypeBStage == 3 && ((PacketPlayInFlying)packet).d() < connection.criticalTypeBY) { connection.criticalTypeBStage = 4; connection.criticalTypeBY = ((PacketPlayInFlying)packet).d(); } else { connection.criticalTypeBStage = 0; } } else { if (packet instanceof PacketPlayInArmAnimation && connection.criticalTypeBStage == 4) { String msg = String.format("%s is using Criticals Type B %.4f", new Object[] { connection.getPlayer().getName(), Double.valueOf(connection.criticalTypeBHeight) }); runSync(new GCheatEvent(connection.getPlayer(), GCheatEvent.Type.CRIT, GCheatEvent.Level.ADMIN, msg)); } connection.criticalTypeBStage = 0; } if (getVersion() <= 47) { if (connection.justSentSprint)
844 if (packet instanceof PacketPlayInFlying) { connection.justSentSprint = false; } else if (packet instanceof PacketPlayInEntityAction && (((PacketPlayInEntityAction)packet).d() == 1 || ((PacketPlayInEntityAction)packet).d() == 2)) { connection.justSentSprint = false; } else { long now = System.currentTimeMillis(); if (now - connection.lastSprintViolationTime > 1000L) { connection.lastSprintViolationTime = now; runSync(new GCheatEvent(connection.getPlayer(), GCheatEvent.Type.UNKNOWN, GCheatEvent.Level.ADMIN, connection.getPlayer().getName() + " is using Bad Packets Type A (" + packet.getClass().getSimpleName() + ")")); } connection.justSentSprint = false; } if (packet instanceof PacketPlayInEntityAction && (((PacketPlayInEntityAction)packet).d() == 4 || ((PacketPlayInEntityAction)packet).d() == 5))
845 connection.justSentSprint = true; } } this.k.add(packet); } } public SocketAddress getSocketAddress() { return this.n; }
846 public void a(PacketListener packetlistener) { Validate.notNull(packetlistener, "packetListener", new Object[0]); i.debug("Set listener of {} to {}", new Object[] { this, packetlistener }); this.o = packetlistener; }
847 public void handle(Packet packet, GenericFutureListener... agenericfuturelistener) { if (this.m != null && this.m.isOpen()) { i(); b(packet, agenericfuturelistener); } else { this.l.add(new QueuedPacket(packet, agenericfuturelistener)); } }
848 private void b(Packet packet, GenericFutureListener[] agenericfuturelistener) { EnumProtocol enumprotocol = EnumProtocol.a(packet); if (enumprotocol == null) enumprotocol = EnumProtocol.PLAY; EnumProtocol enumprotocol1 = (EnumProtocol)this.m.attr(d).get(); if (enumprotocol1 != enumprotocol) { i.debug("Disabled auto read"); this.m.config().setAutoRead(false); } if (this.m.eventLoop().inEventLoop()) { if (enumprotocol != enumprotocol1) a(enumprotocol); this.m.writeAndFlush(packet).addListeners(agenericfuturelistener).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE); } else { this.m.eventLoop().execute(new QueuedProtocolSwitch(this, enumprotocol, enumprotocol1, packet, agenericfuturelistener)); } }
849 private void i() { if (this.m != null && this.m.isOpen()) { QueuedPacket queuedpacket; while ((queuedpacket = (QueuedPacket)this.l.poll()) != null)
850 b(QueuedPacket.a(queuedpacket), QueuedPacket.b(queuedpacket)); } } public void close(IChatBaseComponent ichatbasecomponent) { this.preparing = false;
851
852 if (this.m.isOpen()) {
853 this.m.close();
854 this.q = ichatbasecomponent;
855 } }
856
857
858
859 public boolean c() { return (this.m instanceof net.minecraft.util.io.netty.channel.local.LocalChannel || this.m instanceof net.minecraft.util.io.netty.channel.local.LocalServerChannel); }
860
861
862 public void a(SecretKey secretkey) {
863 this.m.pipeline().addBefore("splitter", "decrypt", new PacketDecrypter(MinecraftEncryption.a(2, secretkey)));
864 this.m.pipeline().addBefore("prepender", "encrypt", new PacketEncrypter(MinecraftEncryption.a(1, secretkey)));
865 this.r = true;
866 }
867
868
869 public boolean isConnected() { return (this.m != null && this.m.isOpen()); }
870
871
872
873 public PacketListener getPacketListener() { return this.o; }
874
875
876
877 public IChatBaseComponent f() { return this.q; }
878
879
880
881 public void g() { this.m.config().setAutoRead(false); }
882
883
884
885 protected void channelRead0(ChannelHandlerContext channelhandlercontext, Object object) { a(channelhandlercontext, (Packet)object); }
886
887
888
889 static Channel a(NetworkManager networkmanager) { return networkmanager.m; }
890
891
892
893
894
895 public SocketAddress getRawAddress() { return this.m.remoteAddress(); }
896
897
898
899
900
901
902 public void enableCompression() {
903 if (this.m.pipeline().get("protocol_lib_decoder") != null) {
904 this.m.pipeline().addBefore("protocol_lib_decoder", "decompress", new SpigotDecompressor());
905 } else {
906 this.m.pipeline().addBefore("decoder", "decompress", new SpigotDecompressor());
907 }
908
909 this.m.pipeline().addBefore("encoder", "compress", new SpigotCompressor());
910 }
911
912
913
914
915 public Channel getChannel() { return this.m; }
916
917
918
919
920
921 private void runSync(Runnable r) { (MinecraftServer.getServer()).processQueue.add(r); }
922
923 private void runSync(final GCheatEvent event) {
924 (MinecraftServer.getServer()).processQueue.add(new Runnable()
925 {
926 public void run() {
927 if (((PlayerConnection)this.this$0.o).hackDebug) {
928 Bukkit.getLogger().info(event.getMsg());
929 }
930 Bukkit.getPluginManager().callEvent(event);
931 }
932 });
933 }
934}