Rise 5.99 PacketDebugger module 2 files, 56 lines

Rise 5.99 PacketDebugger: Full Source Analysis

PacketDebugger is a wire-silent observer used to probe anticheat behavior.

dev/rise/module/impl/other/PacketDebugger.java · GitHub source ↗

Published 2026-08-13 · Updated 2026-08-13

Packets This Module Uses

Analysis

Overview

PacketDebugger is a wire-silent observer used to probe anticheat behavior. Its send handler timestamps C0F confirm-transaction packets (window id, uid and inter-packet interval in milliseconds) and C00 keepalives (key and interval), and its receive side prints the channel name of incoming S3F custom payloads, all through Rise.addChatMessage. It cancels nothing and rewrites nothing; the chat lines are the entire output. The tool is the manual counterpart of the server-side ledgers that anticheats run: keepalive cadence, transaction acks and plugin channels are the metrics a player watches to spot an anticheat's probing or a server's set-back pattern.

Observer design

The handler is an instanceof dispatch over the outgoing packet. C0F entries print the window id and uid plus the elapsed time since the previous transaction, computed from the module's own lastTransaction field; C00 entries print the keepalive key and the elapsed time since the previous keepalive; S3F entries print only the channel name, which is enough to identify plugin channels and anticheat payloads. The lastKeepAlive and lastTransaction fields are plain millisecond timestamps, so the printed intervals are the raw inter-packet gaps.

What the metrics expose

Keepalive intervals reveal the server's tick health and the player's ping, and their pattern changes when a keepalive-ledger plugin interferes with the vanilla echo exchange. Transaction uids and window ids expose confirm-transaction probing, the technique NCP and similar ledgers use to re-sync inventories, and the C0F cadence betrays the probe interval. S3F channel names identify the payload channels a server registers, which is how a player detects anticheat channels before they fire. None of this observation has a wire effect.

Detection surface

The module emits nothing, so no server-side check can detect it; the honest countering claim is that the checks which matter are the ones monitoring the traffic it observes. The pinned S02 and S08 chips are the response channels the tool is used to watch: S08 set-back teleports and S02 anticheat warning messages are what the debugger helps a player notice and time.

source PacketDebugger.java

PacketDebugger.java42 lines · JavaOriginal ↗
1
/*
2
 Copyright Alan Wood 2021
3
 None of this code to be reused without my written permission
4
 Intellectual Rights owned by Alan Wood
5
 */
6
package dev.rise.module.impl.other;
7
8
import dev.rise.Rise;
9
import dev.rise.event.impl.packet.PacketSendEvent;
10
import dev.rise.module.Module;
11
import dev.rise.module.api.ModuleInfo;
12
import dev.rise.module.enums.Category;
13
import net.minecraft.network.Packet;
14
import net.minecraft.network.play.client.C00PacketKeepAlive;
15
import net.minecraft.network.play.client.C0FPacketConfirmTransaction;
16
import net.minecraft.network.play.server.S3FPacketCustomPayload;
17
18
@ModuleInfo(name = "PacketDebugger", description = "Debugger for detecting anticheats", category = Category.OTHER)
19
public final class PacketDebugger extends Module {
20
    private long lastKeepAlive;
21
    private long lastTransaction;
22
23
    @Override
24
    public void onPacketSend(PacketSendEvent event) {
25
26
        Packet p = event.getPacket();
27
28
        if (p instanceof C0FPacketConfirmTransaction) {
29
            long lastPacket = System.currentTimeMillis() - lastTransaction;
30
            Rise.addChatMessage("Transaction: " + ((C0FPacketConfirmTransaction) event.getPacket()).getWindowId()
31
                    + " " + ((C0FPacketConfirmTransaction) event.getPacket()).getUid() + " " + lastPacket + "ms");
32
            this.lastTransaction = System.currentTimeMillis();
33
        } else if (p instanceof C00PacketKeepAlive) {
34
            long lastPacket = System.currentTimeMillis() - lastKeepAlive;
35
            Rise.addChatMessage("KeepAlive: " + ((C00PacketKeepAlive) event.getPacket()).getKey() + " " + lastPacket + "ms");
36
            this.lastKeepAlive = System.currentTimeMillis();
37
        } else if (p instanceof S3FPacketCustomPayload) {
38
            Rise.addChatMessage("Payload: " + ((S3FPacketCustomPayload) event.getPacket()).getChannelName());
39
        }
40
41
    }
42
}

What this file does

The module file: the instanceof dispatch over the outgoing packet, the two millisecond timestamp fields, and the chat output for C0F, C00 and S3F packets. It is the complete implementation of the observer.

source PacketSendEvent.java (hooked event)

PacketSendEvent.java14 lines · JavaOriginal ↗
1
package dev.rise.event.impl.packet;
2
3
import dev.rise.event.api.Event;
4
import lombok.AllArgsConstructor;
5
import lombok.Getter;
6
import lombok.Setter;
7
import net.minecraft.network.Packet;
8
9
@Getter
10
@Setter
11
@AllArgsConstructor
12
public final class PacketSendEvent extends Event {
13
    private Packet<?> packet;
14
}

What this file does

The event class the handler hooks: a 14-line Packet wrapper built with lombok getter and setter plus an all-args constructor, fired for every outbound packet. The module's instanceof chain reads its payload, which is the entire integration surface of the debugger.

anticheat Countering Checks

The anticheat code that detects or counters the techniques this module uses. Full source, with the detection mechanism explained below each box.

anticheat KeepAliveFrequency (keepalive ledger)

KeepAliveFrequency.java101 lines · Java
1
/*
2
 * This program is free software: you can redistribute it and/or modify
3
 *   it under the terms of the GNU General Public License as published by
4
 *   the Free Software Foundation, either version 3 of the License, or
5
 *   (at your option) any later version.
6
 *
7
 *   This program is distributed in the hope that it will be useful,
8
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 *   GNU General Public License for more details.
11
 *
12
 *   You should have received a copy of the GNU General Public License
13
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
14
 */
15
package fr.neatmonster.nocheatplus.checks.net;
16
17
import org.bukkit.entity.Player;
18
19
import fr.neatmonster.nocheatplus.checks.Check;
20
import fr.neatmonster.nocheatplus.checks.CheckType;
21
import fr.neatmonster.nocheatplus.players.IPlayerData;
22
import fr.neatmonster.nocheatplus.utilities.CheckUtils;
23
24
public class KeepAliveFrequency extends Check {
25
26
    public KeepAliveFrequency() {
27
        super(CheckType.NET_KEEPALIVEFREQUENCY);
28
    }
29
    
30
    /**
31
     * Checks hasBypass on violation only.
32
     * @param player
33
     * @param time
34
     * @param data
35
     * @param cc
36
     * @return If to cancel.
37
     */
38
    public boolean check(final Player player, final long time, final NetData data, final NetConfig cc, final IPlayerData pData) {
39
        final long now = System.currentTimeMillis();
40
        final long joinTime = pData.getLastJoinTime();
41
        if (joinTime > 0L && now < joinTime + cc.keepAliveFrequencyStartupDelay) {
42
            return false;
43
        }
44
        if (data.keepAliveExpectedResponse && !data.keepAliveDuplicateId) {
45
            return false;
46
        }
47
        data.keepAliveFreq.add(time, 1f);
48
        final float first = data.keepAliveFreq.bucketScore(0);
49
        
50
        if (first > 1f) {
51
            // Trigger a violation.
52
            final float fullScore = data.keepAliveFreq.score(1f);
53
            if (isModeledBoundaryBurst(data, fullScore, first)) {
54
                return false;
55
            }
56
            final double vl = Math.max(first - getFirstBucketViolationLimit(data), fullScore - data.keepAliveFreq.numberOfBuckets());
57
            final boolean cancel = executeActions(player, vl, 1.0, cc.keepAliveFrequencyActions).willCancel();
58
            return cancel;
59
        }
60
        return false;
61
    }
62
63
    private boolean isModeledBoundaryBurst(final NetData data, final float fullScore, final float first) {
64
        // KeepAlive model: if outgoing tracking is unavailable, only treat small monotonic id bursts as timing leftovers.
65
        if (data.keepAliveDuplicateId || fullScore > data.keepAliveFreq.numberOfBuckets() + 2f) {
66
            return false;
67
        }
68
        // Folia/netty can timestamp two adjacent valid replies in the same millisecond; do not cancel a single pair.
69
        return first <= 2f || isUntrackedMonotonicBurst(data, fullScore, first);
70
    }
71
72
    private boolean isUntrackedMonotonicBurst(final NetData data, final float fullScore, final float first) {
73
        if (data.keepAliveOutgoingSeen || fullScore > data.keepAliveFreq.numberOfBuckets()) {
74
            return false;
75
        }
76
        if (!data.keepAlivePacketIdAvailable || !data.keepAlivePreviousPacketIdAvailable) {
77
            return false;
78
        }
79
        if (data.keepAlivePacketId <= data.keepAlivePreviousPacketId) {
80
            return false;
81
        }
82
        return first <= getFallbackFirstBucketLimit(data);
83
    }
84
85
    private float getFirstBucketViolationLimit(final NetData data) {
86
        if (data.keepAliveDuplicateId) {
87
            return 1f;
88
        }
89
        if (!data.keepAliveOutgoingSeen
90
                && data.keepAlivePacketIdAvailable
91
                && data.keepAlivePreviousPacketIdAvailable
92
                && data.keepAlivePacketId > data.keepAlivePreviousPacketId) {
93
            return getFallbackFirstBucketLimit(data);
94
        }
95
        return 2f;
96
    }
97
98
    private float getFallbackFirstBucketLimit(final NetData data) {
99
        return Math.max(3f, Math.min(6f, data.keepAliveFreq.numberOfBuckets() / 4f));
100
    }
101
}

How it counteracts this module

KeepAliveFrequency is the server-side ledger for exactly the C00 data the debugger prints: every echoed key is matched against the pending request list, pruned after 30 seconds and capped at 40, replies are timestamped into ActionFrequency buckets, and the check flags more than one counted reply in a second with the duplicate-id path tightening the limit. The debugger only reads the stream, so the ledger sees a 1:1 vanilla echo flow and stays silent; the entry documents the ledger the module is used to observe.

anticheat TeleportQueue (S08 ack accounting)

TeleportQueue.java370 lines · Java
1
/*
2
 * This program is free software: you can redistribute it and/or modify
3
 *   it under the terms of the GNU General Public License as published by
4
 *   the Free Software Foundation, either version 3 of the License, or
5
 *   (at your option) any later version.
6
 *
7
 *   This program is distributed in the hope that it will be useful,
8
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 *   GNU General Public License for more details.
11
 *
12
 *   You should have received a copy of the GNU General Public License
13
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
14
 */
15
package fr.neatmonster.nocheatplus.checks.net.model;
16
17
import java.util.Iterator;
18
import java.util.LinkedList;
19
import java.util.concurrent.locks.Lock;
20
import java.util.concurrent.locks.ReentrantLock;
21
22
import fr.neatmonster.nocheatplus.compat.AlmostBoolean;
23
24
/**
25
 * Queue outgoing teleport locations (DataPacketFlying), in order to cancel
26
 * other moving until the client acknowledges previous teleport locations. In
27
 * fact this might only queue a single location.
28
 * 
29
 * @author asofold
30
 *
31
 */
32
public class TeleportQueue {
33
34
    public static enum AckResolution {
35
        /** Waiting for ACK. */
36
        WAITING,
37
        /** Packet is ACK. */
38
        ACK,
39
        /** Not waiting for an ACK. */
40
        IDLE
41
    }
42
43
    public static class AckReference {
44
        public int lastOutgoingId = Integer.MIN_VALUE;
45
        /**
46
         * The maximum of confirmed ids. Once lastOutgoingId is reached, we
47
         * assume all teleports are done. Until then this id may get adjusted if
48
         * lower than lastOutgoingId. Note that the id will be circling within 0
49
         * to Integer.MAX_VALUE - 1, systematically increasing until back to 0,
50
         * thus this value can be greater than lastOutGoingId, which should be
51
         * treated as 'bad luck', resetting this to Integer.MIN_VALUE.
52
         */
53
        public int maxConfirmedId = Integer.MIN_VALUE;
54
    }
55
56
    // TODO: Consider passing a reentrant lock in the constructor (e.g. one lock per NetData).
57
    private final Lock lock = new ReentrantLock();
58
59
    /** Validated outgoing teleport locations, expected to be confirmed by the client. */
60
    private final LinkedList<CountableLocation> expectIncoming = new LinkedList<CountableLocation>();
61
    /** Location from a Bukkit event, which we expect an outgoing teleport for. */
62
    private DataLocation expectOutgoing = null;
63
64
    private long maxAge = 4000; // TODO: configurable
65
    private int maxQueueSize = 60; // TODO: configurable
66
67
    /**
68
     * Queried from the primary thread (read only), reset with outgoing
69
     * teleport.
70
     */
71
    private CountableLocation lastAck = null;
72
73
    private AckReference lastAckReference = new AckReference();
74
75
    /**
76
     * Maximum age in milliseconds, older entries expire.
77
     * @return
78
     */
79
    public long getMaxAge() {
80
        return maxAge;
81
    }
82
83
    /**
84
     * The last confirmed teleport location (read-only by primary thread),
85
     * resets with outgoing teleport.
86
     * 
87
     * @return
88
     */
89
    public CountableLocation getLastAck() {
90
        return lastAck;
91
    }
92
93
    /**
94
     * Get the reference of the last ack, not resetting, but updating with
95
     * incoming acks. This always is the same object, it might only by updated
96
     * on a successful ACK, depending on what's needed (current use is to cancel
97
     * packets on processAck returning WAITING).
98
     * 
99
     * @return
100
     */
101
    public AckReference getLastAckReference() {
102
        return lastAckReference;
103
    }
104
105
    /**
106
     * Compact diagnostic snapshot for NET_MOVING false-positive analysis.
107
     */
108
    public String getDebugState(final long now) {
109
        final StringBuilder builder = new StringBuilder(300);
110
        lock.lock();
111
        builder.append("expectOutgoing=").append(expectOutgoing == null ? "none" : expectOutgoing.toString());
112
        builder.append(",expectIncomingSize=").append(expectIncoming.size());
113
        if (!expectIncoming.isEmpty()) {
114
            builder.append(",incomingFirst=").append(formatCountable(expectIncoming.getFirst(), now));
115
            builder.append(",incomingLast=").append(formatCountable(expectIncoming.getLast(), now));
116
        }
117
        builder.append(",lastAck=").append(lastAck == null ? "none" : formatCountable(lastAck, now));
118
        builder.append(",ackRef=lastOutgoing:").append(lastAckReference.lastOutgoingId)
119
                .append("/maxConfirmed:").append(lastAckReference.maxConfirmedId);
120
        builder.append(",maxAge=").append(maxAge);
121
        lock.unlock();
122
        return builder.toString();
123
    }
124
125
    private String formatCountable(final CountableLocation ref, final long now) {
126
        final StringBuilder builder = new StringBuilder(160);
127
        builder.append(ref.toString());
128
        builder.append(",age=");
129
        builder.append(now >= ref.time ? now - ref.time : -(ref.time - now));
130
        return builder.toString();
131
    }
132
133
    /**
134
     * Call for Bukkit events (expect this packet to be sent).<br>
135
     * TODO: The method name is misleading, as this also should be called with
136
     * expected outgoing packet.
137
     * 
138
     * @param packetData
139
     */
140
    public void onTeleportEvent(final double x, final double y, final double z, final float yaw, final float pitch) {
141
        lock.lock();
142
        lastAck = null;
143
        expectOutgoing = new DataLocation(x, y, z, yaw, pitch);
144
        lock.unlock();
145
    }
146
147
    /**
148
     * Call for outgoing teleport packets. Lazily checks for expiration and max
149
     * queue size. Update teleportId (Integer.MIN_VALUE means that it isn't
150
     * provided).
151
     * 
152
     * @param x
153
     * @param y
154
     * @param z
155
     * @param yaw
156
     * @param pitch
157
     * @param teleportId
158
     * @return
159
     */
160
    public CountableLocation onOutgoingTeleport(final double x, final double y, final double z, 
161
            final float yaw, final float pitch, final int teleportId) {
162
        CountableLocation res = null;
163
        final long time = System.currentTimeMillis();
164
        lock.lock();
165
        lastAckReference.lastOutgoingId = teleportId;
166
        if (lastAckReference.maxConfirmedId > lastAckReference.lastOutgoingId) {
167
            lastAckReference.maxConfirmedId = Integer.MIN_VALUE; // Some data loss accepted here.
168
        }
169
        // Only register this location, if it matches the location from a Bukkit event.
170
        if (expectOutgoing != null) {
171
            if (expectOutgoing.isSamePosAndLook(x, y, z, yaw, pitch)) {
172
                // Add to queue.
173
                if (!expectIncoming.isEmpty()) {
174
                    // Lazy expiration check.
175
                    final Iterator<CountableLocation> it = expectIncoming.iterator();
176
                    while (it.hasNext()) {
177
                        final CountableLocation ref = it.next();
178
                        if (time < ref.time) {
179
                            // Time ran backwards. Force keep entries.
180
                            ref.time = time;
181
                        }
182
                        else if (time - maxAge > ref.time) {
183
                            it.remove();
184
                        } else {
185
                            break;
186
                        }
187
                    }
188
                    if (!expectIncoming.isEmpty()) {
189
                        final CountableLocation last = expectIncoming.getLast();
190
                        if (last.isSamePosAndLook(x, y, z, yaw, pitch)) {
191
                            last.time = time;
192
                            last.count ++;
193
                            last.teleportId = teleportId;
194
                            res = last;
195
                        }
196
                    }
197
                }
198
                // Add a new entry, if not merged with last.
199
                if (res == null) {
200
                    res = new CountableLocation(x, y, z, yaw, pitch, 1, time, teleportId);
201
                    expectIncoming.addLast(res);
202
                    // Don't exceed maxQueueSize.
203
                    if (expectIncoming.size() > maxQueueSize) {
204
                        expectIncoming.removeFirst();
205
                    }
206
                }
207
            }
208
            // Reset in any case.
209
            expectOutgoing = null;
210
        }
211
        lock.unlock();
212
        return res;
213
    }
214
215
    /**
216
     * Process ack on receiving a 'confirm teleport' packet.
217
     * 
218
     * @param teleportId
219
     * @return YES, if this teleport id is explicitly matched (not necessarily
220
     *         the latest one), MAYBE if it's a unique id smaller than than
221
     *         maxConfirmedId. NO, if it's not a valid ack - it could be some
222
     *         other special condition, like Integer overflow, or timeout.
223
     */
224
    public AlmostBoolean processAck(final int teleportId) {
225
        /*
226
         * Return values are subject to change, e.g.: (ACK_LATEST_POS),
227
         * ACK_LATEST_ID, ACK_OUTDATED_POS, ACK_OUTDATED_ID, UNKNOWN
228
         */
229
        if (teleportId == Integer.MIN_VALUE) {
230
            // Could consider to return MAYBE for not knowing, needs elaborating on context and use cases.
231
            return AlmostBoolean.NO;
232
        }
233
        lock.lock();
234
        if (teleportId == lastAckReference.lastOutgoingId) {
235
            lastAckReference.maxConfirmedId = teleportId;
236
            // Abort here for efficiency.
237
            expectIncoming.clear();
238
            lock.unlock();
239
            return AlmostBoolean.YES;
240
        }
241
        AlmostBoolean ackState = AlmostBoolean.NO;
242
        final Iterator<CountableLocation> it = expectIncoming.iterator();
243
        while (it.hasNext()) {
244
            final CountableLocation ref = it.next();
245
            // No expiration checks here.
246
            if (ref.teleportId == teleportId) {
247
                // Match an outdated id.
248
                // Remove all preceding older entries and this one.
249
                while (ref != expectIncoming.getFirst()) {
250
                    expectIncoming.removeFirst();
251
                }
252
                expectIncoming.removeFirst();
253
                // The count doesn't count anymore.
254
                ref.count = 0;
255
                ackState = AlmostBoolean.YES;
256
                break;
257
            }
258
        }
259
        // Update lastAckReference only if within the safe area.
260
        if (teleportId < lastAckReference.lastOutgoingId 
261
                && teleportId > lastAckReference.maxConfirmedId) {
262
            // Allow update.
263
            lastAckReference.maxConfirmedId = teleportId;
264
            if (ackState == AlmostBoolean.NO) {
265
                // Adjust to maybe, as long as the id is increasing within unique range.
266
                ackState = AlmostBoolean.MAYBE;
267
            }
268
        }
269
        else {
270
            lastAckReference.maxConfirmedId = Integer.MIN_VALUE;
271
        }
272
        lock.unlock();
273
        return ackState;
274
    }
275
276
    /**
277
     * Accept a movement packet that matches the teleport location from a Bukkit
278
     * event before ProtocolLib has observed the matching outgoing position.
279
     */
280
    public boolean consumeExpectedOutgoingPosition(final DataPacketFlying packetData) {
281
        if (packetData == null || !packetData.hasPos) {
282
            return false;
283
        }
284
        lock.lock();
285
        final boolean match = expectOutgoing != null && expectOutgoing.isSamePos(packetData);
286
        if (match) {
287
            expectOutgoing = null;
288
        }
289
        lock.unlock();
290
        return match;
291
    }
292
293
    /**
294
     * Test if the move is an ACK move (or no ACK is expected), adjust internals
295
     * if necessary.
296
     * 
297
     * @param packetData
298
     * @return ACK, if the packet matches an expected ACK position. IDLE, if no
299
     *         ACK is expected or on timeout. CANCEL, if still waiting for an
300
     *         ACK.
301
     */
302
    public AckResolution processAck(final DataPacketFlying packetData) {
303
        // Check packet.
304
        if (!packetData.hasPos || !packetData.hasLook) {
305
            // Applies, if we don't have a teleport-confirm event.
306
            return AckResolution.IDLE;
307
        }
308
        // Check queue.
309
        final AckResolution res;
310
311
        lock.lock();
312
        if (expectIncoming.isEmpty()) {
313
            res = AckResolution.IDLE;
314
        } else {
315
            res = getAckResolution(packetData);
316
        }
317
        lock.unlock();
318
319
        return res;
320
    }
321
322
    /**
323
     * Check queue (lock is handled outside of this method). Does check for
324
     * expiration of entries. Must only be called under lock.
325
     * 
326
     * @param packetData
327
     * @return
328
     */
329
    private AckResolution getAckResolution(final DataPacketFlying packetData) {
330
        // Iterate from oldest to newest.
331
        final Iterator<CountableLocation> it = expectIncoming.iterator();
332
        while (it.hasNext()) {
333
            final CountableLocation ref = it.next();
334
            if (packetData.time - maxAge >= ref.time) {
335
                it.remove();
336
            }
337
            else if (packetData.isSamePosAndLook(ref)) {
338
                // Match.
339
                // Remove all preceding older entries.
340
                while (ref != expectIncoming.getFirst()) {
341
                    expectIncoming.removeFirst();
342
                }
343
                // Decrease count and remove the matching entry if count is down to 0.
344
                if (--ref.count <= 0) { // (Lots of safety margin.)
345
                    expectIncoming.removeFirst(); // Do not use the iterator here.
346
                }
347
                lastAck = ref;
348
                return AckResolution.ACK;
349
            }
350
            else {
351
                // Skip until match or none found.
352
                // TODO: Consider settings like maxSkipCount or strictly return WAITING.
353
                if (packetData.time < ref.time) {
354
                    // Time ran backwards, update to now.
355
                    ref.time = packetData.time;
356
                }
357
            }
358
        }
359
        // No match.
360
        return expectIncoming.isEmpty() ? AckResolution.IDLE : AckResolution.WAITING;
361
    }
362
363
    public void clear() {
364
        lock.lock();
365
        expectIncoming.clear();
366
        expectOutgoing = null;
367
        lock.unlock();
368
    }
369
370
}

How it counteracts this module

TeleportQueue is the S08 accounting the debugger's users watch for: each server teleport is queued, the follow-up C06 is matched by isSamePosAndLook, and unmatched entries age out after 4000ms. A set-back produces exactly the S08-then-C06 pattern the module helps a player time. Because the module never touches the packets, the ledger's behavior is indistinguishable from vanilla; the honest claim is that the check is the observed surface, not a detector of the observer.

anticheat PlayerEventListener (teleport ledger)

PlayerEventListener.java214 lines · Java
1
/*
2
 * This file is part of Hawk Anticheat.
3
 * Copyright (C) 2018 Hawk Development Team
4
 *
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
17
 */
18
19
package me.islandscout.hawk.module;
20
21
import me.islandscout.hawk.Hawk;
22
import me.islandscout.hawk.HawkPlayer;
23
import me.islandscout.hawk.event.bukkit.HawkAsyncPlayerAbilitiesEvent;
24
import me.islandscout.hawk.event.bukkit.HawkAsyncPlayerMetadataEvent;
25
import me.islandscout.hawk.event.bukkit.HawkAsyncPlayerVelocityChangeEvent;
26
import me.islandscout.hawk.util.Debug;
27
import me.islandscout.hawk.util.Pair;
28
import me.islandscout.hawk.util.ServerUtils;
29
import me.islandscout.hawk.wrap.WrappedWatchableObject;
30
import me.islandscout.hawk.wrap.entity.MetaData;
31
import org.bukkit.Location;
32
import org.bukkit.entity.HumanEntity;
33
import org.bukkit.entity.Player;
34
import org.bukkit.event.EventHandler;
35
import org.bukkit.event.EventPriority;
36
import org.bukkit.event.Listener;
37
import org.bukkit.event.inventory.InventoryCloseEvent;
38
import org.bukkit.event.inventory.InventoryOpenEvent;
39
import org.bukkit.event.player.*;
40
import org.bukkit.event.vehicle.VehicleEnterEvent;
41
import org.bukkit.event.vehicle.VehicleExitEvent;
42
import org.bukkit.util.Vector;
43
44
import java.util.List;
45
46
public class PlayerEventListener implements Listener {
47
48
    private final Hawk hawk;
49
50
    public PlayerEventListener(Hawk hawk) {
51
        this.hawk = hawk;
52
53
        hawk.getHawkSyncTaskScheduler().addRepeatingTask(new Runnable() {
54
            @Override
55
            public void run() {
56
                for(HawkPlayer pp : hawk.getHawkPlayers()) {
57
                    Player p = pp.getPlayer();
58
                    pp.setPing(ServerUtils.getPing(p));
59
                }
60
            }
61
        }, 40);
62
    }
63
64
    @EventHandler(priority = EventPriority.LOWEST)
65
    public void onLogin(PlayerLoginEvent e) {
66
        Player p = e.getPlayer();
67
        hawk.addProfile(p); //This line is necessary since it must get called BEFORE hawk listens to the player's packets
68
        hawk.getHawkPlayer(p).setOnline(true);
69
    }
70
71
    //Set protocol version
72
    @EventHandler
73
    public void onJoin(PlayerJoinEvent e) {
74
        hawk.getHawkPlayer(e.getPlayer()).setClientVersion(ServerUtils.getProtocolVersion(e.getPlayer()));
75
    }
76
77
    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
78
    public void onQuit(PlayerQuitEvent e) {
79
        hawk.getHawkPlayer(e.getPlayer()).setOnline(false);
80
        hawk.removeProfile(e.getPlayer().getUniqueId()); //TODO call this elsewhere
81
        hawk.getCheckManager().removeData(e.getPlayer());
82
    }
83
84
    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
85
    public void onVelocity(HawkAsyncPlayerVelocityChangeEvent e) {
86
        if(e.isAdditive())
87
            return;
88
        HawkPlayer pp = hawk.getHawkPlayer(e.getPlayer());
89
        Vector vector = e.getVelocity();
90
91
        List<Pair<Vector, Long>> pendingVelocities = pp.getPendingVelocities();
92
        pendingVelocities.add(new Pair<>(vector, System.currentTimeMillis()));
93
        if(pendingVelocities.size() > 20)
94
            pendingVelocities.remove(0);
95
    }
96
97
    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
98
    public void onInventoryOpenServerSide(InventoryOpenEvent e) {
99
        HumanEntity hE = e.getPlayer();
100
        if(!(hE instanceof Player))
101
            return;
102
103
        //Fixes issues regarding the client not releasing item usage when a server inventory is opened.
104
        //Consumables may not have this issue.
105
        HawkPlayer pp = hawk.getHawkPlayer((Player) hE);
106
        pp.sendSimulatedAction(new Runnable() {
107
            @Override
108
            public void run() {
109
                pp.setBlocking(false);
110
                pp.setPullingBow(false);
111
                pp.setInventoryOpen((byte)2);
112
            }
113
        });
114
    }
115
116
    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
117
    public void onInventoryCloseServerSide(InventoryCloseEvent e) {
118
        HumanEntity hE = e.getPlayer();
119
        if(!(hE instanceof Player))
120
            return;
121
122
        HawkPlayer pp = hawk.getHawkPlayer((Player) hE);
123
        pp.sendSimulatedAction(new Runnable() {
124
            @Override
125
            public void run() {
126
                pp.setInventoryOpen((byte)0);
127
            }
128
        });
129
    }
130
131
    @EventHandler
132
    public void sendMetadataEvent(HawkAsyncPlayerMetadataEvent e) {
133
        List<WrappedWatchableObject> objects = e.getMetaData();
134
        for(WrappedWatchableObject object : objects) {
135
            if(object.getIndex() == 0) {
136
                Player p = e.getPlayer();
137
                HawkPlayer pp = hawk.getHawkPlayer(p);
138
                byte status = (byte)object.getObject();
139
140
                //bitmask
141
                if((status & 16) == 16) {
142
                    pp.addMetaDataUpdate(new MetaData(MetaData.Type.USE_ITEM, true));
143
                } else {
144
                    pp.addMetaDataUpdate(new MetaData(MetaData.Type.USE_ITEM, false));
145
                }
146
                if((status & 8) == 8) {
147
                    pp.addMetaDataUpdate(new MetaData(MetaData.Type.SPRINT, true));
148
                } else {
149
                    pp.addMetaDataUpdate(new MetaData(MetaData.Type.SPRINT, false));
150
                }
151
                /*if((status & 2) == 2) {
152
                    pp.addMetaDataUpdate(new MetaData(MetaData.Type.SNEAK, true));
153
                } else {
154
                    pp.addMetaDataUpdate(new MetaData(MetaData.Type.SNEAK, false));
155
                }*/
156
157
                break;
158
            }
159
        }
160
    }
161
162
    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
163
    public void vehicleEnter(VehicleEnterEvent e) {
164
        if(e.getEntered() instanceof Player) {
165
            HawkPlayer pp = hawk.getHawkPlayer((Player)e.getEntered());
166
            pp.sendSimulatedAction(new Runnable() {
167
                @Override
168
                public void run() {
169
                    pp.setInVehicle(true);
170
                }
171
            });
172
        }
173
    }
174
175
    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
176
    public void vehicleExit(VehicleExitEvent e) {
177
        if(e.getExited() instanceof Player) {
178
            HawkPlayer pp = hawk.getHawkPlayer((Player)e.getExited());
179
            pp.sendSimulatedAction(new Runnable() {
180
                @Override
181
                public void run() {
182
                    pp.setInVehicle(false);
183
                }
184
            });
185
        }
186
    }
187
188
    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
189
    public void abilitiesServerSide(HawkAsyncPlayerAbilitiesEvent e) {
190
        HawkPlayer pp = hawk.getHawkPlayer(e.getPlayer());
191
        pp.sendSimulatedAction(new Runnable() {
192
            @Override
193
            public void run() {
194
                pp.setAllowedToFly(e.isAllowedToFly());
195
                pp.setFlying(e.isFlying());
196
                pp.setInCreative(e.isCreativeMode());
197
            }
198
        });
199
    }
200
201
    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
202
    public void teleport(PlayerTeleportEvent e) {
203
        HawkPlayer pp = hawk.getHawkPlayer(e.getPlayer());
204
205
        Location tpLoc = e.getTo().clone();
206
        tpLoc.setYaw(tpLoc.getYaw() % 360F);
207
        tpLoc.setPitch(tpLoc.getPitch() % 360F);
208
209
        pp.addPendingTeleport(tpLoc);
210
211
        //Exception ee = new Exception();
212
        //ee.printStackTrace();
213
    }
214
}

How it counteracts this module

Hawk's PlayerEventListener is the receive-side teleport handler: it converts incoming teleport packets and pushes them into the per-player pending-teleport ledger that movement checks such as GroundSpoof and Fly consume on the next move. It is Hawk's counterpart to the S08 pattern the debugger watches for. The module neither cancels nor forges teleports, so the ledger receives normal vanilla entries; an honest gap entry.

anticheat MorePackets (movement rate ledger)

MorePackets.java49 lines · Java
1
package me.vrekt.arc.check.moving;
2
3
import me.vrekt.arc.Arc;
4
import me.vrekt.arc.check.Check;
5
import me.vrekt.arc.check.CheckType;
6
import me.vrekt.arc.data.moving.MovingData;
7
import org.bukkit.Bukkit;
8
import org.bukkit.ChatColor;
9
import org.bukkit.entity.Player;
10
11
public class MorePackets extends Check {
12
13
    private int maxPackets, kickThreshold = 0;
14
15
    public MorePackets() {
16
        super(CheckType.MOREPACKETS);
17
18
        maxPackets = Arc.getCheckManager().getValueInt(CheckType.MOREPACKETS, "max-packets");
19
        kickThreshold = Arc.getCheckManager().getValueInt(CheckType.MOREPACKETS, "max-packets-kick");
20
    }
21
22
    public boolean check(Player player, MovingData data) {
23
24
        int flyingPackets = data.getFlyingPackets();
25
        int movingPackets = data.getPositionPackets();
26
27
        // check if we are sending more packets then allowed.
28
        if (flyingPackets > maxPackets || movingPackets > maxPackets) {
29
            checkViolation(player, "sending too many packets");
30
            if (flyingPackets > kickThreshold || movingPackets > kickThreshold) {
31
                // we are sending over the limit, kick.
32
                Bukkit.getScheduler().runTaskLater(Arc.getPlugin(), () -> {
33
                    // broadcast to staff.
34
                    Bukkit.broadcast(ChatColor.DARK_GRAY + "[" + ChatColor.RED + "Arc" + ChatColor.DARK_GRAY + "] " + ChatColor.BLUE
35
                            + player.getName() + ChatColor.WHITE + " was kicked for sending too many packets. ", "arc.violations");
36
                    // prevent async player kick.
37
                    player.kickPlayer("You are sending too many packets.");
38
                }, 5);
39
                return false;
40
            }
41
            data.setCancelMovingPackets(true);
42
            return true;
43
        }
44
45
        data.setCancelMovingPackets(false);
46
        return false;
47
    }
48
49
}

How it counteracts this module

Arc v2's MorePackets is the rate ledger for the movement stream the debugger monitors: per-second flying and position counters read from MovingData, with max-packets, default 30, flagging and max-packets-kick, default 70, kicking for sending too many packets. The debugger itself contributes zero packets, so the counters never move on its account. The entry frames the check as the boundary a flooding test would trip, which is exactly what the tool is used to calibrate.

← Back to Analysis Hub