· 6 years ago · Aug 01, 2019, 01:02 PM
1
2import com.google.common.base.Joiner;
3import com.google.common.collect.ImmutableSet;
4import java.net.SocketAddress;
5import java.util.ArrayList;
6import java.util.Iterator;
7import java.util.List;
8import java.util.Queue;
9import java.util.UUID;
10import javax.crypto.SecretKey;
11import net.minecraft.util.com.google.common.collect.Queues;
12import net.minecraft.util.com.google.common.util.concurrent.ThreadFactoryBuilder;
13import net.minecraft.util.com.mojang.authlib.properties.Property;
14import net.minecraft.util.io.netty.channel.Channel;
15import net.minecraft.util.io.netty.channel.ChannelFutureListener;
16import net.minecraft.util.io.netty.channel.ChannelHandlerContext;
17import net.minecraft.util.io.netty.channel.SimpleChannelInboundHandler;
18import net.minecraft.util.io.netty.channel.nio.NioEventLoopGroup;
19import net.minecraft.util.io.netty.util.AttributeKey;
20import net.minecraft.util.io.netty.util.concurrent.GenericFutureListener;
21import net.minecraft.util.org.apache.commons.lang3.Validate;
22import org.apache.logging.log4j.LogManager;
23import org.apache.logging.log4j.Logger;
24import org.apache.logging.log4j.Marker;
25import org.apache.logging.log4j.MarkerManager;
26import org.bukkit.Bukkit;
27import org.bukkit.event.player.GCheatEvent;
28import org.spigotmc.SpigotCompressor;
29import org.spigotmc.SpigotConfig;
30import org.spigotmc.SpigotDecompressor;
31
32public class NetworkManager
33 extends SimpleChannelInboundHandler {
34 private static final Logger i = LogManager.getLogger();
35 public static final Marker a = MarkerManager.getMarker("NETWORK");
36 public static final Marker b = MarkerManager.getMarker("NETWORK_PACKETS", a);
37 public static final Marker c = MarkerManager.getMarker("NETWORK_STAT", a);
38 public static final AttributeKey d = new AttributeKey("protocol");
39 public static final AttributeKey e = new AttributeKey("receivable_packets");
40 public static final AttributeKey f = new AttributeKey("sendable_packets");
41 public static final NioEventLoopGroup g = new NioEventLoopGroup(false, (new ThreadFactoryBuilder()).setNameFormat("Netty Client IO #%d").setDaemon(true).build());
42 public static final NetworkStatistics h = new NetworkStatistics();
43
44 private final boolean j;
45
46 private final Queue k;
47
48 private final Queue l;
49 private Channel m;
50 public SocketAddress n;
51 public UUID spoofedUUID;
52 public Property[] spoofedProfile;
53 public boolean preparing;
54 private PacketListener o;
55 private EnumProtocol p;
56 private IChatBaseComponent q;
57 private boolean r;
58 public static final AttributeKey<Integer> protocolVersion = new AttributeKey("protocol_version");
59 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;
60 public long currentTime;
61 public long lastVehicleTick;
62 public int numOfFlyingPacketsInARow;
63
64 public static int getVersion(Channel attr) {
65 Integer ver = (Integer)attr.attr(protocolVersion).get();
66 return (ver != null) ? ver.intValue() : 5;
67 }
68
69 public int getVersion() {
70 if (this.version == 0) {
71 Integer ver = (Integer)this.m.attr(protocolVersion).get();
72 if (ver == null) {
73 return 5;
74 }
75 this.version = ver.intValue();
76 }
77 return this.version;
78 }
79 public NetworkManager(boolean flag) { this.k = Queues.newConcurrentLinkedQueue();
80 this.l = Queues.newConcurrentLinkedQueue();
81 this.preparing = true;
82 this.version = 0;
83 this.stopReadingPackets = false;
84
85 this.packets = new Packet[10];
86 this.limitTimes = new long[12];
87 this.lastTickNetworkProcessed = MinecraftServer.currentTick;
88 this.ticksSinceLastPacket = -1L;
89 this.numOfH = 0;
90 this.numOfHLogs = new ArrayList();
91 this.numOfI = 0;
92 this.numOfILogs = new ArrayList();
93 this.lastKTick = MinecraftServer.currentTick;
94 this.currentTime = System.currentTimeMillis();
95 this.lastVehicleTick = -1L;
96 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"); }
97 public void channelInactive(ChannelHandlerContext channelhandlercontext) throws Exception { close(new ChatMessage("disconnect.endOfStream", new Object[0])); }
98 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(); }
99 public void a() { i();
100 EnumProtocol enumprotocol = (EnumProtocol)this.m.attr(d).get();
101
102 if (this.p != enumprotocol) {
103 if (this.p != null) {
104 this.o.a(this.p, enumprotocol);
105 }
106
107 this.p = enumprotocol;
108 }
109
110 if (this.o != null) {
111
112 boolean processed = false;
113
114 int i = SpigotConfig.maxPacketsPerPlayer; while (true) { Packet packet; if ((packet = (Packet)this.k.poll()) != null && i >= 0)
115
116 {
117 if (this.stopReadingPackets || !isConnected() || !this.m.config().isAutoRead()) {
118 continue;
119 }
120
121
122
123
124 if (!processed) {
125 this.ticksSinceLastPacket = MinecraftServer.currentTick - this.lastTickNetworkProcessed;
126 this.lastTickNetworkProcessed = MinecraftServer.currentTick;
127 this.currentTime = System.currentTimeMillis();
128 processed = true;
129 }
130
131
132
133 if (this.o instanceof PlayerConnection)
134 { PlayerConnection connection = (PlayerConnection)this.o;
135
136
137 if (packet instanceof PacketPlayInKeepAlive)
138 { ((PlayerConnection)this.o).handleKeepAliveSync((PacketPlayInKeepAlive)packet);
139
140
141 }
142
143 else if (packet instanceof PacketPlayInChat || packet instanceof PacketPlayInCustomPayload)
144 { packet.handle(this.o); }
145
146 else
147
148 { if (connection.isAntiCheatActivated() &&
149 !MinecraftServer.getServer().getAllowFlight() && !connection.player.abilities.canFly && !connection.player.abilities.canInstantlyBuild) {
150 boolean eventFired = false;
151 int size = connection.lastPacketsQueue.size();
152 if (size >= this.packets.length) {
153
154 if (packet instanceof PacketPlayInUseEntity && ((PacketPlayInUseEntity)packet).c() == EnumEntityUseAction.ATTACK) {
155
156
157
158
159
160
161
162
163
164
165 for (int j = 0; j < this.packets.length; j++) {
166 this.packets[j] = (Packet)connection.lastPacketsQueue.removeLast();
167 }
168
169 Class packet0Class = this.packets[0].getClass();
170 if (packet0Class.equals(PacketPlayInArmAnimation.class))
171 {
172
173
174 if (this.packets[1].getClass().equals(PacketPlayInUseEntity.class) && this.packets[2].getClass().equals(PacketPlayInArmAnimation.class) && ((PacketPlayInUseEntity)this.packets[true])
175 .c() == EnumEntityUseAction.ATTACK && getVersion() <= 47) {
176
177 if (this.packets[3].getClass().equals(PacketPlayInUseEntity.class) && this.packets[4].getClass().equals(PacketPlayInArmAnimation.class) && ((PacketPlayInUseEntity)this.packets[3])
178 .c() == EnumEntityUseAction.ATTACK) {
179 if (this.packets[5].getClass().equals(PacketPlayInUseEntity.class) && this.packets[6].getClass().equals(PacketPlayInArmAnimation.class) && ((PacketPlayInUseEntity)this.packets[5])
180 .c() == EnumEntityUseAction.ATTACK) {
181 if (this.packets[7].getClass().equals(PacketPlayInUseEntity.class) && this.packets[8].getClass().equals(PacketPlayInArmAnimation.class) && ((PacketPlayInUseEntity)this.packets[7])
182 .c() == EnumEntityUseAction.ATTACK) {
183 if (connection.hackDebug) {
184 Bukkit.getLogger().info(connection.getPlayer().getName() + " was caught using kill aura K");
185 }
186
187 if (this.lastKTick != MinecraftServer.currentTick) {
188 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));
189 this.lastKTick = MinecraftServer.currentTick;
190 }
191 } else {
192 if (connection.hackDebug) {
193 Bukkit.getLogger().info(connection.getPlayer().getName() + " was caught using kill aura J");
194 }
195
196 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));
197 }
198 } else {
199 if (connection.hackDebug) {
200 Bukkit.getLogger().info(connection.getPlayer().getName() + " was caught using kill aura I");
201 }
202
203 this.numOfILogs.add(Long.valueOf(this.ticksSinceLastPacket));
204
205 if (++this.numOfI == 3) {
206 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)));
207 this.numOfI = 0;
208 this.numOfILogs.clear();
209 }
210 }
211 } else {
212 if (connection.hackDebug) {
213 Bukkit.getLogger().info(connection.getPlayer().getName() + " was caught using kill aura H");
214 }
215
216 this.numOfHLogs.add(Long.valueOf(this.ticksSinceLastPacket));
217
218 if (++this.numOfH == 5) {
219 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)));
220 this.numOfH = 0;
221 this.numOfHLogs.clear();
222 }
223 }
224 } else {
225
226 int numberOfPreviousPacketPlayInPositionLooks = 0;
227 boolean foundPrevHitPacket = false;
228 for (int j = 1; j < this.packets.length; j++) {
229 Class packetJClass = this.packets[j].getClass();
230 if (packetJClass.equals(PacketPlayInPositionLook.class) || packetJClass.equals(PacketPlayInPosition.class) || packetJClass
231 .equals(PacketPlayInLook.class) || packetJClass.equals(PacketPlayInFlying.class)) {
232 numberOfPreviousPacketPlayInPositionLooks++;
233 foundPrevHitPacket = true;
234 } else if (packetJClass.equals(PacketPlayInUseEntity.class)) {
235 break;
236 }
237 }
238
239 if (foundPrevHitPacket) {
240
241 PacketPlayInUseEntity packetPlayInUseEntity = (PacketPlayInUseEntity)packet;
242 EnumEntityUseAction action = packetPlayInUseEntity.c();
243 WorldServer worldserver = MinecraftServer.getServer().getWorldServer(connection.player.dimension);
244 Entity entity = packetPlayInUseEntity.a(worldserver);
245
246 boolean validData = false;
247 validData = (action == EnumEntityUseAction.ATTACK && entity != connection.player && entity != null && entity instanceof EntityPlayer);
248
249 if (validData) {
250 EntityPlayer entityPlayer = (EntityPlayer)entity;
251 validData = entityPlayer.playerConnection.hasMovedInHalfSecond;
252 }
253
254
255 if (validData) {
256 List<Long> times = (List)connection.killAuraViolationsTypeC.get(Integer.valueOf(numberOfPreviousPacketPlayInPositionLooks));
257
258
259 if (connection.hackDebug) {
260 Bukkit.getLogger().info(connection.getPlayer().getName() + " has sent " + numberOfPreviousPacketPlayInPositionLooks + " position packets since last hit");
261 }
262
263 if (connection.killAuraViolationsTypeC.size() > 1) {
264 connection.killAuraViolationsTypeC.clear();
265
266 if (connection.hackDebug) {
267 Bukkit.getLogger().info("Reset");
268 }
269 }
270
271
272
273
274
275
276
277
278
279 if (times == null) {
280 times = new ArrayList<Long>();
281 connection.killAuraViolationsTypeC.put(Integer.valueOf(numberOfPreviousPacketPlayInPositionLooks), times);
282 }
283
284
285
286
287
288
289 long currentTime = System.currentTimeMillis();
290 int typeCViolations = 0;
291 times.add(Long.valueOf(currentTime));
292
293
294 for (Iterator<Long> iterator = times.iterator(); iterator.hasNext(); ) {
295 Long time = (Long)iterator.next();
296 long timeLimiter = (numberOfPreviousPacketPlayInPositionLooks < 12) ? this.limitTimes[numberOfPreviousPacketPlayInPositionLooks] : 4000L;
297 if (time.longValue() + timeLimiter >= currentTime) {
298 typeCViolations++; continue;
299 }
300 iterator.remove();
301 }
302
303
304
305 if (typeCViolations >= 10) {
306 if (connection.hackDebug) {
307 Bukkit.getLogger().info(connection.getPlayer().getName() + " was caught using kill aura with lvl " + numberOfPreviousPacketPlayInPositionLooks);
308 }
309
310 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));
311 times.clear();
312 eventFired = true;
313 }
314 }
315 }
316 }
317 }
318
319
320 for (int j = this.packets.length - 1; j >= 0; j--) {
321 connection.lastPacketsQueue.add(this.packets[j]);
322 }
323 } else if (packet instanceof PacketPlayInBlockPlace) {
324 for (int j = 0; j < 3; j++) {
325 this.packets[j] = (Packet)connection.lastPacketsQueue.removeLast();
326 }
327
328 if (this.packets[0] instanceof PacketPlayInFlying && this.packets[1] instanceof PacketPlayInBlockPlace && this.packets[2] instanceof PacketPlayInBlockDig) {
329 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."));
330 }
331
332
333 for (int j = 2; j >= 0; j--) {
334 connection.lastPacketsQueue.add(this.packets[j]);
335 }
336 } else if (packet instanceof PacketPlayInHeldItemSlot) {
337 for (int j = 0; j < 3; j++) {
338 this.packets[j] = (Packet)connection.lastPacketsQueue.removeLast();
339 }
340
341 if (this.packets[0] instanceof PacketPlayInBlockPlace && this.packets[1] instanceof PacketPlayInFlying && this.packets[2] instanceof PacketPlayInBlockDig) {
342 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."));
343 }
344
345
346 for (int j = 2; j >= 0; j--) {
347 connection.lastPacketsQueue.add(this.packets[j]);
348 }
349 }
350
351
352 if (connection.isDigging) {
353 if (packet instanceof PacketPlayInFlying) {
354 connection.typeRStage = 1;
355 } else if (packet instanceof PacketPlayInArmAnimation) {
356 if (connection.typeRStage == 1) {
357 connection.typeRStage = 2;
358 } else if (connection.typeRStage == 2) {
359 connection.typeRStage = 0;
360 if (connection.digHorizontalMovement > 1) {
361 connection.typeRThreshold++;
362 if (connection.typeRThreshold >= 3) {
363 if (connection.hackDebug) {
364 Bukkit.getLogger().info(connection.getPlayer().getName() + " was caught using kill aura R (" + connection.typeRThreshold + ")");
365 }
366 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 + ")."));
367 }
368 }
369 }
370 } else {
371 connection.typeRStage = 0;
372 }
373 } else {
374 connection.typeRStage = 0;
375 }
376 }
377
378
379
380
381
382
383
384
385
386 if (size == 10) {
387 connection.lastPacketsQueue.removeFirst();
388 }
389
390 connection.lastPacketsQueue.add(packet);
391
392
393 if (eventFired) {
394 connection.lastPacketsQueue.clear();
395 }
396
397 if (connection.hackDebug) {
398 Bukkit.getLogger().info(connection.getPlayer().getName() + " has received packet " + packet.toString() + " " + MinecraftServer.currentTick);
399 }
400 }
401
402
403
404
405 packet.handle(this.o); } continue; } } else { break; } packet.handle(this.o);
406 i--; }
407
408 this.o.a();
409 }
410
411 this.m.flush(); }
412 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())
413 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)
414 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))
415 connection.justSentSprint = true; } } this.k.add(packet); } } public SocketAddress getSocketAddress() { return this.n; }
416 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; }
417 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)); } }
418 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)); } }
419 private void i() { if (this.m != null && this.m.isOpen()) { QueuedPacket queuedpacket; while ((queuedpacket = (QueuedPacket)this.l.poll()) != null)
420 b(QueuedPacket.a(queuedpacket), QueuedPacket.b(queuedpacket)); } } public void close(IChatBaseComponent ichatbasecomponent) { this.preparing = false;
421
422 if (this.m.isOpen()) {
423 this.m.close();
424 this.q = ichatbasecomponent;
425 } }
426
427
428
429 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); }
430
431
432 public void a(SecretKey secretkey) {
433 this.m.pipeline().addBefore("splitter", "decrypt", new PacketDecrypter(MinecraftEncryption.a(2, secretkey)));
434 this.m.pipeline().addBefore("prepender", "encrypt", new PacketEncrypter(MinecraftEncryption.a(1, secretkey)));
435 this.r = true;
436 }
437
438
439 public boolean isConnected() { return (this.m != null && this.m.isOpen()); }
440
441
442
443 public PacketListener getPacketListener() { return this.o; }
444
445
446
447 public IChatBaseComponent f() { return this.q; }
448
449
450
451 public void g() { this.m.config().setAutoRead(false); }
452
453
454
455 protected void channelRead0(ChannelHandlerContext channelhandlercontext, Object object) { a(channelhandlercontext, (Packet)object); }
456
457
458
459 static Channel a(NetworkManager networkmanager) { return networkmanager.m; }
460
461
462
463
464
465 public SocketAddress getRawAddress() { return this.m.remoteAddress(); }
466
467
468
469
470
471
472 public void enableCompression() {
473 if (this.m.pipeline().get("protocol_lib_decoder") != null) {
474 this.m.pipeline().addBefore("protocol_lib_decoder", "decompress", new SpigotDecompressor());
475 } else {
476 this.m.pipeline().addBefore("decoder", "decompress", new SpigotDecompressor());
477 }
478
479 this.m.pipeline().addBefore("encoder", "compress", new SpigotCompressor());
480 }
481
482
483
484
485 public Channel getChannel() { return this.m; }
486
487
488
489
490
491 private void runSync(Runnable r) { (MinecraftServer.getServer()).processQueue.add(r); }
492
493 private void runSync(final GCheatEvent event) {
494 (MinecraftServer.getServer()).processQueue.add(new Runnable()
495 {
496 public void run() {
497 if (((PlayerConnection)this.this$0.o).hackDebug) {
498 Bukkit.getLogger().info(event.getMsg());
499 }
500 Bukkit.getPluginManager().callEvent(event);
501 }
502 });
503 }
504}