Memeware 7.3 Spammer module 2 files, 74 lines

Memeware 7.3 Spammer: Full Source Analysis

Memeware 7.3's Spammer is a one-second chat broadcaster: a single LWJEB handler on UpdateEvent checks a wall-clock Timer, and whenever 1000ms have elapsed it sends exactly one chat message through…

me/memewaredevs/client/module/misc/Spammer.java · GitHub source ↗

Published 2026-08-12 · Updated 2026-08-12

Packets This Module Uses

Analysis

Overview

Memeware 7.3's Spammer is a one-second chat broadcaster: a single LWJEB handler on UpdateEvent checks a wall-clock Timer, and whenever 1000ms have elapsed it sends exactly one chat message through ChatUtil.sendChat - a direct C01PacketChatMessage enqueue. The text comes from two modes registered via addModes. 'Aids' walks 121 lines of Jake Paul's 'It's everyday bro' lyrics from a Java properties ResourceBundle (jakepaul.properties), sending one line per second in order and wrapping at line 121; 'Memeware' cycles 10 advertisement lines from fart.properties ('Memeware by Dort#0001 aka professional bhopper', 'Memeware > ALL', 'DORT > ALL'). The module has no timing jitter, no cooldown beyond the fixed second, and no awareness of server chat rules - it emits a constant one-packet-per-second stream of template text for as long as it is enabled.

Architecture

The module is one @Handler Consumer<UpdateEvent> plus a util Timer (a millisecond stopwatch over System.nanoTime) and an int message index. onEnable resets the index to 0. Each tick the handler asks timer.delay(1000L) - elapsed wall-clock milliseconds since the last reset - and when the answer is true it picks the mode branch, builds one message, sends it, and calls timer.reset(). Because the gate is wall-clock and the handler runs once per tick, the actual cadence is one message per elapsed second, slightly stretched by tick granularity. The index handling differs per mode: 'Aids' increments before sending, so it emits Jake.1 through Jake.121 then wraps to 0; 'Memeware' checks the wrap condition (index > 9 resets to 0) before sending, so it emits memeware.0 through memeware.9 on a 10-message cycle.

Template sources

SpamUtil loads two ResourceBundles by fully qualified name from the spammer/ package: jakepaul.properties for Aids and fart.properties for Memeware. getAids and getMemeware wrap ResourceBundle.getString in a try/catch that returns '!' + key + '!' on MissingResourceException, which is the module's only failure mode - in practice every key the index walks exists. The Aids pool is the notable one: 121 lines that are mostly the 'It's everyday bro' song, and the pool itself contains consecutive duplicate lines (Jake.38/39/40, Jake.77/78/79, Jake.94/95/96, Jake.120 are all 'It's everyday bro'), so the rotation emits byte-identical messages back to back. The Memeware pool is ten ad lines referencing the client and its staff, several sharing the words 'Memeware' and 'DORT'. ChatUtil.sendChat wraps each line in a C01PacketChatMessage and pushes it through sendQueue.addToSendQueue, the same path vanilla chat uses - no length check, no event-bus detour, and because the lines never start with '.', the Commands module's interceptor leaves them alone.

Wire behavior

The server sees a fixed-rate chat stream: one C01 per second, sustained for as long as the module stays enabled, with content drawn from two tiny closed pools. There is no randomization of order, no jitter in the interval, and no pause when chat is muted or when a server-side rule would object - the Timer just keeps firing. The stream is also content-blind to the client's own Commands module: sendChat goes straight to the send queue, and since none of the template lines carry the dot prefix, the two modules coexist without interfering. The practical consequence is that the module's traffic is the most regular, most repetitive chat a server can measure - a textbook rate signature - while the individual messages remain ordinary-looking C01 packets.

source Spammer.java (one-second chat broadcaster)

Spammer.java48 lines · JavaOriginal ↗
1
package me.memewaredevs.client.module.misc;
2
3
import me.hippo.api.lwjeb.annotation.Handler;
4
import me.memewaredevs.client.event.events.UpdateEvent;
5
import me.memewaredevs.client.module.Module;
6
import me.memewaredevs.client.util.ChatUtil;
7
import me.memewaredevs.client.util.misc.Timer;
8
9
import java.util.function.Consumer;
10
11
public class Spammer extends Module {
12
13
    private Timer timer = new Timer();
14
15
    private int currentMessage;
16
17
    public Spammer() {
18
        super("Spammer", 0, Category.MISC);
19
        this.addModes("Aids", "Memeware");
20
    }
21
22
    @Handler
23
    public Consumer<UpdateEvent> eventConsumer0 = (event) -> {
24
        if (timer.delay(1000L)) {
25
            if (isMode("Aids")) {
26
                ++this.currentMessage;
27
                ChatUtil.sendChat(SpamUtil.getAids("Jake." + this.currentMessage));
28
                if (this.currentMessage >= 121) {
29
                    this.currentMessage = 0;
30
                }
31
                timer.reset();
32
            }
33
            if (isMode("Memeware")) {
34
                if (this.currentMessage > 9) {
35
                    this.currentMessage = 0;
36
                }
37
                ChatUtil.sendChat(SpamUtil.getMemeware("memeware." + this.currentMessage));
38
                ++this.currentMessage;
39
                timer.reset();
40
            }
41
        }
42
    };
43
44
    @Override
45
    public void onEnable() {
46
        this.currentMessage = 0;
47
    }
48
}

What this file does

The whole module is the eventConsumer0 field plus a util Timer and an int index. The UpdateEvent handler gates on timer.delay(1000L), builds one message from the active mode's bundle lookup, sends it via ChatUtil.sendChat, and resets the timer. 'Aids' increments the index before sending, covering Jake.1..Jake.121 from jakepaul.properties and wrapping at 121; 'Memeware' wraps at index 10 and covers memeware.0..memeware.9 from fart.properties. onEnable resets the index, so toggling restarts the rotation. The cadence is a fixed one message per wall-clock second with no jitter: the util Timer compares System.nanoTime()/1000000 against the last reset, so the gate is real elapsed time, not tick count, and the handler's per-tick execution just quantizes it. The send path is ChatUtil.sendChat, a direct sendQueue.addToSendQueue of a C01PacketChatMessage - no length validation, no anti-spam awareness, no interaction with the Commands interceptor since the template lines carry no dot prefix.

source SpamUtil.java (ResourceBundle template lookup)

SpamUtil.java26 lines · JavaOriginal ↗
1
package me.memewaredevs.client.module.misc;
2
3
import java.util.MissingResourceException;
4
import java.util.ResourceBundle;
5
6
public class SpamUtil {
7
8
	private static ResourceBundle jakeSpamResource = ResourceBundle.getBundle("me.memewaredevs.client.module.misc.spammer.jakepaul");
9
	private static ResourceBundle memewareResource = ResourceBundle.getBundle("me.memewaredevs.client.module.misc.spammer.fart");
10
11
	public static String getAids(String key) {
12
		try {
13
			return jakeSpamResource.getString(key);
14
		} catch (MissingResourceException e) {
15
			return '!' + key + '!';
16
		}
17
	}
18
19
	public static String getMemeware(String key) {
20
		try {
21
			return memewareResource.getString(key);
22
		} catch (MissingResourceException e) {
23
			return '!' + key + '!';
24
		}
25
	}
26
}

What this file does

This is the message source for both modes. It holds two static ResourceBundles - jakeSpamResource from 'me.memewaredevs.client.module.misc.spammer.jakepaul' and memewareResource from the same package's 'fart' bundle - and exposes getAids(key) and getMemeware(key), each a getString call guarded by MissingResourceException that returns '!' + key + '!' on a missing entry. The bundles are loaded once per class initialization, so the 121 lyric lines and 10 ad lines live entirely in the two .properties files under module/misc/spammer/. The '!' + key + '!' fallback is the module's only resilience: if a bundle is missing or a key is absent, the spammer broadcasts the literal placeholder instead of crashing the tick handler. The lookup layer keeps the module code free of message content, which is also why the pools are invisible in the module source itself.

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 NoCheatPlus Text (chat frequency and repeat analysis)

Text.java331 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.chat;
16
17
import java.util.Collections;
18
import java.util.LinkedList;
19
import java.util.List;
20
import java.util.Map;
21
22
import org.bukkit.entity.Player;
23
24
import fr.neatmonster.nocheatplus.NCPAPIProvider;
25
import fr.neatmonster.nocheatplus.checks.Check;
26
import fr.neatmonster.nocheatplus.checks.CheckType;
27
import fr.neatmonster.nocheatplus.checks.chat.analysis.MessageLetterCount;
28
import fr.neatmonster.nocheatplus.checks.chat.analysis.WordLetterCount;
29
import fr.neatmonster.nocheatplus.checks.chat.analysis.engine.LetterEngine;
30
import fr.neatmonster.nocheatplus.checks.combined.CombinedData;
31
import fr.neatmonster.nocheatplus.components.NoCheatPlusAPI;
32
import fr.neatmonster.nocheatplus.components.registry.feature.INotifyReload;
33
import fr.neatmonster.nocheatplus.config.ConfigFile;
34
import fr.neatmonster.nocheatplus.config.ConfigManager;
35
import fr.neatmonster.nocheatplus.players.IPlayerData;
36
import fr.neatmonster.nocheatplus.utilities.ColorUtil;
37
import fr.neatmonster.nocheatplus.utilities.StringUtil;
38
39
/**
40
 * Some alternative more or less advanced analysis methods.
41
 * @author asofold
42
 *
43
 */
44
public class Text extends Check implements INotifyReload {
45
46
    private LetterEngine engine = null;
47
48
    /** Not really cancelled but above threshold for actions. */
49
    private String lastCancelledMessage = "";
50
    private long lastCancelledTime = 0;
51
52
    private String lastGlobalMessage = "";
53
    private long lastGlobalTime = 0;
54
55
    public Text() {
56
        super(CheckType.CHAT_TEXT);
57
        init();
58
    }
59
60
    /**
61
     * Start analysis.
62
     * @param player
63
     *          The player who issued the message.
64
     * @param message
65
     *          The message to check.
66
     * @param captcha 
67
     *          Used for starting captcha on failure, if configured so.
68
     * @param alreadyCancelled 
69
     * @return
70
     */
71
    public boolean check(final Player player, final String message, 
72
                         final ChatConfig cc, final IPlayerData pData,
73
                         final ICaptcha captcha, boolean isMainThread, final boolean alreadyCancelled) {
74
        final ChatData data = pData.getGenericInstance(ChatData.class);
75
        synchronized (data) {
76
            return unsafeCheck(player, message, captcha, cc, data, pData, isMainThread, alreadyCancelled);
77
        }
78
    }
79
80
    private void init() {
81
        // Set some things from the global config.
82
        final ConfigFile config = ConfigManager.getConfigFile();
83
        final NoCheatPlusAPI api = NCPAPIProvider.getNoCheatPlusAPI();
84
        if (engine != null) {
85
            engine.clear();
86
            api.removeComponent(engine);
87
        }
88
        engine = new LetterEngine(config);
89
        api.addComponent(engine);
90
    }
91
92
    @Override
93
    public void onReload() {
94
        synchronized(engine) {
95
            engine.clear();
96
        }
97
        init();
98
    }
99
100
    /**
101
     * Check without further synchronization.
102
     * @param player
103
     * @param message
104
     * @param captcha
105
     * @param cc
106
     * @param data
107
     * @param isMainThread 
108
     * @param alreadyCancelled 
109
     * @return
110
     */
111
    private boolean unsafeCheck(final Player player, final String message, final ICaptcha captcha,
112
                                final ChatConfig cc, final ChatData data, final IPlayerData pData,
113
                                boolean isMainThread, final boolean alreadyCancelled) {
114
115
        // Test captcha.
116
        if (captcha.shouldCheckCaptcha(player, cc, data, pData)) {
117
            captcha.checkCaptcha(player, message, cc, data, isMainThread);
118
            return true;
119
        } 
120
        else if (alreadyCancelled) {
121
            // Skip checking.
122
            return true;
123
        }
124
125
        final long time = System.currentTimeMillis();
126
        final String lcMessage = message.trim().toLowerCase();
127
        boolean cancel = false;
128
        final boolean debug = pData.isDebugActive(type);
129
        final List<String> debugParts;
130
        if (debug) {
131
            debugParts = new LinkedList<String>();
132
            debugParts.add("Message (length=" + message.length()+"): ");
133
        }
134
        else debugParts = null;
135
136
        // Update the frequency interval weights.
137
        data.chatFrequency.update(time);
138
139
        // Score for this message (violation score).
140
        float score = 0;
141
        final MessageLetterCount letterCounts = new MessageLetterCount(message);
142
        final int msgLen = message.length();
143
144
145
146
        // (Following: random/made up criteria.)
147
        // TODO: Create tests for all methods with wordlists, fake chat (refactor for that).
148
        // Full message processing. ------------
149
        // Upper case.
150
        if (letterCounts.fullCount.upperCase > msgLen / 3) {
151
            // TODO: Regard chunks of 48 or so letters of the message for this?
152
            final float wUpperCase = 0.6f * letterCounts.fullCount.getUpperCaseRatio();
153
            score += wUpperCase  * cc.textMessageUpperCase;
154
        }
155
156
        // Letters vs. word length.
157
        if (msgLen > 4) {
158
            final float fullRep = letterCounts.fullCount.getLetterCountRatio();
159
            // Long messages: very small and very big are bad !
160
            // 128 is a quick attempt to make one long message possible on 1.11.
161
            final float wRepetition = (float) Math.min(msgLen, 128) / 15.0f * Math.abs(0.5f - fullRep);
162
            score += wRepetition * cc.textMessageLetterCount;
163
164
            // Number of words vs. length of message
165
            final float fnWords = (float) letterCounts.words.length / (float) msgLen;
166
            if (fnWords > 0.75f) { // TODO: balance or configure or remove ?
167
                score += fnWords  * cc.textMessagePartition;
168
            }
169
        }
170
171
        final CombinedData cData = pData.getGenericInstance(CombinedData.class);
172
        final long timeout = 8000; // TODO: maybe set dynamically in data.
173
        // Repetition of last message.
174
        if (cc.textMsgRepeatSelf != 0f && time - data.chatLastTime < timeout) {
175
            if (StringUtil.isSimilar(lcMessage, data.chatLastMessage, 0.8f)) {
176
                final float timeWeight = (float) (timeout - (time - data.chatLastTime)) / (float) timeout; 
177
                score += cc.textMsgRepeatSelf * timeWeight;
178
            }
179
        }
180
        // Repetition of last global message.
181
        if (cc.textMsgRepeatGlobal != 0f && time - lastGlobalTime < timeout) {
182
            if (StringUtil.isSimilar(lcMessage, lastGlobalMessage, 0.8f)) {
183
                final float timeWeight = (float) (timeout - (time - lastGlobalTime)) / (float) timeout; 
184
                score += cc.textMsgRepeatGlobal * timeWeight;
185
            }
186
        }
187
        // Repetition of last cancelled message.
188
        if (cc.textMsgRepeatCancel != 0f && time - lastCancelledTime < timeout) {
189
            if (StringUtil.isSimilar(lcMessage, lastCancelledMessage, 0.8f)) {
190
                final float timeWeight = (float) (timeout - (time - lastCancelledTime)) / (float) timeout; 
191
                score += cc.textMsgRepeatCancel * timeWeight;
192
            }
193
        }
194
        // Chat quickly after join.
195
        if (cc.textMsgAfterJoin != 0f && time - cData.lastJoinTime < timeout) {
196
            final float timeWeight = (float) (timeout - (time - cData.lastJoinTime)) / (float) timeout;
197
            score += cc.textMsgAfterJoin * timeWeight; 
198
        }
199
        // Chat without moving.
200
        if (cc.textMsgNoMoving != 0f && time - cData.lastMoveTime > timeout) {
201
            score += cc.textMsgNoMoving;
202
        }
203
204
205
206
        // Per word checks. -------------------
207
        float wWords = 0.0f;
208
        final float avwLen = (float) msgLen / (float) letterCounts.words.length; 
209
        for (final WordLetterCount word : letterCounts.words) {
210
            float wWord = 0.0f;
211
            final int wLen = word.word.length();
212
            // TODO: ? used letters vs. word length.
213
214
            // Length of word vs. av. word length.
215
            final float fLenAv = Math.abs(avwLen - (float) wLen) / avwLen;
216
            wWord += fLenAv * cc.textMessageLengthAv;
217
218
            // Length of word vs. message length;
219
            final float fLenMsg = (float) wLen / (float) msgLen;
220
            wWord += fLenMsg * cc.textMessageLengthMsg;
221
222
            // Not letter:
223
            float notLetter = word.getNotLetterRatio();
224
            notLetter *= notLetter;
225
            wWord += notLetter * cc.textMessageNoLetter;
226
227
            wWord *= wWord; // TODO: quadratic ? (configurable)
228
            wWords += wWord;
229
        }
230
        wWords /= (float) letterCounts.words.length;
231
        score += wWords;
232
233
        if (debug && score > 0f) {
234
            debugParts.add("Simple score: " + StringUtil.fdec3.format(score));
235
        }
236
237
        // Engine:
238
        // TODO: more fine grained sync !
239
        float wEngine = 0f;
240
        final Map<String, Float> engMap;
241
        synchronized (engine) {
242
            engMap = engine.process(letterCounts, player.getName(), cc, data);
243
            // TODO: more fine grained sync !s
244
            // TODO: different methods (add or max or add+max or something else).
245
            for (final Float res : engMap.values()) {
246
                if (cc.textEngineMaximum) {
247
                    wEngine = Math.max(wEngine, res.floatValue());
248
                }
249
                else wEngine += res.floatValue();
250
            }
251
        }
252
        score += wEngine;
253
254
255
        // Wrapping it up. --------------------
256
        // Add weight to frequency counts.
257
        final float normalScore = Math.max(cc.textFreqNormMin, score);
258
        data.chatFrequency.add(time, normalScore);
259
        final float accumulated = cc.textFreqNormWeight * data.chatFrequency.score(cc.textFreqNormFactor);
260
        final boolean normalViolation = accumulated > cc.textFreqNormLevel;
261
        final float shortTermScore = Math.max(cc.textFreqShortTermMin, score);
262
        data.chatShortTermFrequency.add(time, shortTermScore);
263
        // TODO: very short term (1st bucket) or do it indirectly.
264
        final float shortTermAccumulated = cc.textFreqShortTermWeight * data.chatShortTermFrequency.score(cc.textFreqShortTermFactor);
265
        final boolean shortTermViolation = shortTermAccumulated > cc.textFreqShortTermLevel;
266
267
        if (normalViolation || shortTermViolation) {
268
            lastCancelledMessage = lcMessage;
269
            lastCancelledTime = time;
270
271
            final double added;
272
            if (shortTermViolation) {
273
                added = (shortTermAccumulated - cc.textFreqShortTermLevel)/ 3.0;
274
            } 
275
            else added = (accumulated - cc.textFreqNormLevel) / 10.0; 
276
            data.textVL += added;
277
278
            if (captcha.shouldStartCaptcha(player, cc, data, pData)) {
279
                captcha.sendNewCaptcha(player, cc, data);
280
                cancel = true;
281
            }
282
            else {
283
                if (shortTermViolation) {
284
                    if (executeActions(player, data.textVL, added, cc.textFreqShortTermActions).willCancel()) {
285
                        cancel = true;
286
                    }
287
                }
288
                else if (normalViolation) {
289
                    if (executeActions(player, data.textVL, added, cc.textFreqNormActions).willCancel()) {
290
                        cancel = true;
291
                    }
292
                }
293
            }
294
        }
295
        else if (cc.chatWarningCheck && time - data.chatWarningTime > cc.chatWarningTimeout && (100f * accumulated / cc.textFreqNormLevel > cc.chatWarningLevel || 100f * shortTermAccumulated / cc.textFreqShortTermLevel > cc.chatWarningLevel)) {
296
            NCPAPIProvider.getNoCheatPlusAPI().sendMessageOnTick(player.getName(), ColorUtil.replaceColors(cc.chatWarningMessage));
297
            data.chatWarningTime = time;
298
        }
299
        else {
300
            data.textVL *= 0.95;
301
            if (cc.textAllowVLReset && normalScore < 2.0f * cc.textFreqNormWeight && shortTermScore < 2.0f * cc.textFreqShortTermWeight) {
302
                // Reset the VL.
303
                // Maybe elaborate on resetting conditions (after some timeout just divide by two or so?).
304
                data.textVL = 0.0;
305
            }
306
        }
307
308
        if (debug) {
309
            final List<String> keys = new LinkedList<String>(engMap.keySet());
310
            Collections.sort(keys);
311
            for (String key : keys) {
312
                Float s = engMap.get(key);
313
                if (s.floatValue() > 0.0f)
314
                    debugParts.add(key + ":" + StringUtil.fdec3.format(s));
315
            }
316
            if (wEngine > 0.0f)
317
                debugParts.add("Engine score (" + (cc.textEngineMaximum?"max":"sum") + "): " + StringUtil.fdec3.format(wEngine));
318
319
            debugParts.add("Final score: " +  StringUtil.fdec3.format(score));
320
            debugParts.add("Normal: min=" +  StringUtil.fdec3.format(cc.textFreqNormMin) +", weight=" +  StringUtil.fdec3.format(cc.textFreqNormWeight) + " => accumulated=" + StringUtil.fdec3.format(accumulated));
321
            debugParts.add("Short-term: min=" +  StringUtil.fdec3.format(cc.textFreqShortTermMin) +", weight=" +  StringUtil.fdec3.format(cc.textFreqShortTermWeight) + " => accumulated=" + StringUtil.fdec3.format(shortTermAccumulated));
322
            debugParts.add("vl: " + StringUtil.fdec3.format(data.textVL));
323
            debug(player, StringUtil.join(debugParts, " | "));
324
            debugParts.clear();
325
        }
326
327
        lastGlobalMessage = data.chatLastMessage = lcMessage;
328
        lastGlobalTime = data.chatLastTime = time;
329
        return cancel;
330
    }
331
}

How it counteracts this module

NCP's Text check is built for exactly this traffic shape. Every message scores content (uppercase ratio beyond a third, letter-count and partition ratios, squared per-word notLetter scores - lines 150-231) and then feeds two ActionFrequency accumulators, chatFrequency and chatShortTermFrequency, each with a minimum score floor and windowed totals compared against cc.textFreqNormLevel and cc.textFreqShortTermLevel (lines 257-265). A sustained one-message-per-second stream keeps both accumulators at their floors permanently, and since the module sends continuously, the windowed scores stay above the violation levels until the module is disabled; each violation adds to textVL and triggers the captcha or configured actions (lines 267-294).

The content path has an even more direct hit. The Aids pool contains consecutive duplicate lines - Jake.38/39/40, Jake.77/78/79, Jake.94/95/96 are all 'It's everyday bro' - so the rotation itself emits byte-identical messages back to back, and isSimilar(lcMessage, chatLastMessage, 0.8f) within the 8000ms window (lines 174-179) fires on those transitions; at one message per second the window comfortably spans the duplicates. The stand-still penalty (textMsgNoMoving, lines 200-202) also applies: a player camping a spot while spamming accrues flat extra weight after 8 seconds without movement. The only part of the module that dodges the repeat path is the rotation itself - most pool lines differ from their neighbors - but the frequency accumulators do not care about content, and the Memeware-mode pool repeats shared words ('Memeware', 'DORT', 'ALL') across its ten lines, which feeds the per-word paths instead.

anticheat NoCheatPlus Captcha (auto-armed chat gate)

Captcha.java115 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.chat;
16
17
import java.util.concurrent.ThreadLocalRandom;
18
19
import org.bukkit.entity.Player;
20
21
import fr.neatmonster.nocheatplus.checks.Check;
22
import fr.neatmonster.nocheatplus.checks.CheckType;
23
import fr.neatmonster.nocheatplus.players.DataManager;
24
import fr.neatmonster.nocheatplus.players.IPlayerData;
25
import fr.neatmonster.nocheatplus.utilities.ColorUtil;
26
27
/**
28
 * NOTE: EARLY REFACTORING STATE, MOST METHODS NEED SYNC OVER DATA !
29
 * @author mc_dev
30
 *
31
 */
32
public class Captcha extends Check implements ICaptcha{
33
34
    public Captcha() {
35
        super(CheckType.CHAT_CAPTCHA);
36
    }
37
38
    @Override
39
    public void checkCaptcha(Player player, String message, ChatConfig cc, ChatData data, boolean isMainThread) {
40
        // Correct answer to the captcha?
41
        if (message.equals(data.captchaGenerated)) {
42
            // Yes, clear their data and do not worry anymore about them.
43
            data.reset();
44
            data.captchaStarted = false;
45
            player.sendMessage(ColorUtil.replaceColors(cc.captchaSuccess));
46
        } 
47
        else {
48
            // Increment their tries number counter.
49
            data.captchTries++;
50
            data.captchaVL ++;
51
            // Have they failed too man times?
52
            if (data.captchTries > cc.captchaTries) {
53
                // Find out if we need to kick the player or not.
54
                executeActions(player, data.captchaVL, 1, cc.captchaActions);
55
                // (Resetting captcha tries is done on quit/kick).
56
            }
57
            // Display the question again (if not kicked).
58
            if (player.isOnline()) {
59
                sendCaptcha(player, cc, data);
60
            }
61
        }
62
    }
63
64
    @Override
65
    public void sendNewCaptcha(Player player, ChatConfig cc, ChatData data) {
66
        // Display a captcha to the player.
67
        generateCaptcha(cc, data, true);
68
        sendCaptcha(player, cc, data);
69
        data.captchaStarted = true;
70
    }
71
72
    @Override
73
    public void generateCaptcha(ChatConfig cc, ChatData data, boolean reset) {
74
        if (reset) data.captchTries = 0;
75
        final char[] chars = new char[cc.captchaLength];
76
        for (int i = 0; i < cc.captchaLength; i++) {
77
            chars[i] = cc.captchaCharacters.charAt(ThreadLocalRandom.current().nextInt(cc.captchaCharacters.length()));
78
        }
79
        data.captchaGenerated = new String(chars);
80
    }
81
82
    @Override
83
    public void resetCaptcha(Player player){
84
        final IPlayerData pData = DataManager.getPlayerData(player);
85
        ChatData data = pData.getGenericInstance(ChatData.class);
86
        synchronized (data) {
87
            resetCaptcha(player, pData.getGenericInstance(ChatConfig.class), data, pData);
88
        }
89
    }
90
91
    @Override
92
    public void resetCaptcha(Player player, ChatConfig cc, ChatData data, IPlayerData pData) {
93
        data.captchTries = 0;
94
        if (shouldCheckCaptcha(player, cc, data, pData) || shouldStartCaptcha(player, cc, data, pData)){
95
            generateCaptcha(cc, data, true);
96
        }
97
    }
98
99
    @Override
100
    public void sendCaptcha(Player player, ChatConfig cc, ChatData data) {
101
        player.sendMessage(ColorUtil.replaceColors(cc.captchaQuestion.replace("[captcha]", data.captchaGenerated)));
102
    }
103
104
    @Override
105
    public boolean shouldStartCaptcha(Player player, ChatConfig cc, ChatData data, IPlayerData pData) {
106
        // TODO: Only call if IWorldData.isCheckActive(CHAT_CAPTCHA) has returned true?
107
        return !data.captchaStarted && pData.isCheckActive(CheckType.CHAT_CAPTCHA, player);
108
    }
109
110
    @Override
111
    public boolean shouldCheckCaptcha(Player player, ChatConfig cc, ChatData data, IPlayerData pData) {
112
        // TODO: Only call if IWorldData.isCheckActive(CHAT_CAPTCHA) has returned true?
113
        return data.captchaStarted  && pData.isCheckActive(CheckType.CHAT_CAPTCHA, player);
114
    }
115
}

How it counteracts this module

Captcha is the escalation every Text violation reaches: when shouldStartCaptcha returns true (CHAT_CAPTCHA active and no captcha started yet, lines 105-108), Text calls sendNewCaptcha on the first violation (Text line 278), which generates a random string of cc.captchaLength characters and sends it to the player (lines 65-70). From then on checkCaptcha requires message.equals(data.captchaGenerated) - an exact match (line 41). Every other message increments captchTries and captchaVL, re-displays the question, and once captchTries exceeds cc.captchaTries executes cc.captchaActions (lines 47-61).

The Spammer cannot answer by construction: its timer fires every second regardless of what the server asked, and the message it sends is the next template line, never the generated captcha string. So once the frequency accumulators arm the captcha, the module converts itself into a guaranteed-wrong-answer machine - one failed attempt per second - and walks straight into the kick/ban ladder. The only ways out are manual: the user must disable the module and type the captcha by hand. The module has no detection of the captcha question, no pause path, and no way to feed the answer back, which turns NCP's weakest defense into a decisive one against this particular client behavior.

anticheat NoCheatPlus LetterEngine (learned word-profile processors)

LetterEngine.java153 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.chat.analysis.engine;
16
17
import java.util.ArrayList;
18
import java.util.HashMap;
19
import java.util.List;
20
import java.util.Map;
21
22
import org.bukkit.entity.Player;
23
24
import fr.neatmonster.nocheatplus.checks.CheckType;
25
import fr.neatmonster.nocheatplus.checks.chat.ChatConfig;
26
import fr.neatmonster.nocheatplus.checks.chat.ChatData;
27
import fr.neatmonster.nocheatplus.checks.chat.analysis.MessageLetterCount;
28
import fr.neatmonster.nocheatplus.checks.chat.analysis.engine.processors.FlatWords;
29
import fr.neatmonster.nocheatplus.checks.chat.analysis.engine.processors.FlatWords.FlatWordsSettings;
30
import fr.neatmonster.nocheatplus.checks.chat.analysis.engine.processors.SimilarWordsBKL;
31
import fr.neatmonster.nocheatplus.checks.chat.analysis.engine.processors.SimilarWordsBKL.SimilarWordsBKLSettings;
32
import fr.neatmonster.nocheatplus.checks.chat.analysis.engine.processors.WordPrefixes;
33
import fr.neatmonster.nocheatplus.checks.chat.analysis.engine.processors.WordPrefixes.WordPrefixesSettings;
34
import fr.neatmonster.nocheatplus.checks.chat.analysis.engine.processors.WordProcessor;
35
import fr.neatmonster.nocheatplus.components.data.IData;
36
import fr.neatmonster.nocheatplus.components.registry.feature.ConsistencyChecker;
37
import fr.neatmonster.nocheatplus.components.registry.feature.IHaveCheckType;
38
import fr.neatmonster.nocheatplus.components.registry.feature.IRemoveData;
39
import fr.neatmonster.nocheatplus.config.ConfPaths;
40
import fr.neatmonster.nocheatplus.config.ConfigFile;
41
import fr.neatmonster.nocheatplus.logging.StaticLog;
42
43
44
/**
45
 * Process words.
46
 * @author asofold
47
 *
48
 */
49
public class LetterEngine implements IRemoveData, IHaveCheckType, ConsistencyChecker{
50
51
    /** Global processors */
52
    protected final List<WordProcessor> processors = new ArrayList<WordProcessor>();
53
54
    /**
55
     * Mapping players to data.
56
     */
57
    protected final EnginePlayerDataMap dataMap;
58
59
    public LetterEngine(ConfigFile config){
60
        // Add word processors.
61
        // NOTE: These settings should be compared to the per player settings done in the EnginePlayerConfig constructor.
62
        if (config.getBoolean(ConfPaths.CHAT_TEXT_GL_WORDS_CHECK, false)) {
63
            FlatWordsSettings settings = new FlatWordsSettings();
64
            settings.maxSize = 1000;
65
            settings.applyConfig(config, ConfPaths.CHAT_TEXT_GL_WORDS);
66
            processors.add(new FlatWords("glWords",settings));
67
        }
68
        if (config.getBoolean(ConfPaths.CHAT_TEXT_GL_PREFIXES_CHECK , false)) {
69
            WordPrefixesSettings settings = new WordPrefixesSettings();
70
            settings.maxAdd = 2000;
71
            settings.applyConfig(config, ConfPaths.CHAT_TEXT_GL_PREFIXES);
72
            processors.add(new WordPrefixes("glPrefixes", settings));
73
        }
74
        if (config.getBoolean(ConfPaths.CHAT_TEXT_GL_SIMILARITY_CHECK , false)) {
75
            SimilarWordsBKLSettings settings = new SimilarWordsBKLSettings();
76
            settings.maxSize = 1000;
77
            settings.applyConfig(config, ConfPaths.CHAT_TEXT_GL_SIMILARITY);
78
            processors.add(new SimilarWordsBKL("glSimilarity", settings));
79
        }
80
        // TODO: At least expiration duration configurable? (Entries expire after 10 minutes.)
81
        dataMap = new EnginePlayerDataMap(600000L, 100, 0.75f);
82
    }
83
84
    public Map<String, Float> process(final MessageLetterCount letterCount, final String playerName, final ChatConfig cc, final ChatData data) {
85
        final Map<String, Float> result = new HashMap<String, Float>();
86
        // Global processors.
87
        if (cc.textGlobalCheck) {
88
            for (final WordProcessor processor : processors) {
89
                try {
90
                    result.put(processor.getProcessorName(), processor.process(letterCount) * cc.textGlobalWeight);
91
                }
92
                catch( final Exception e) {
93
                    StaticLog.logSevere("chat.text: processor("+processor.getProcessorName()+") generated an exception: " + e.getClass().getSimpleName() + ": " + e.getMessage());
94
                    StaticLog.logSevere(e);
95
                    continue;
96
                }
97
            }
98
        }
99
100
        // Per player processors.
101
        if (cc.textPlayerCheck) {
102
            final EnginePlayerData engineData = dataMap.get(playerName, cc); 
103
            for (final WordProcessor processor : engineData.processors){
104
                try {
105
                    result.put(processor.getProcessorName(), processor.process(letterCount) * cc.textPlayerWeight);
106
                }
107
                catch( final Exception e) {
108
                    StaticLog.logSevere("chat.text: processor("+processor.getProcessorName()+") generated an exception: " + e.getClass().getSimpleName() + ": " + e.getMessage());
109
                    StaticLog.logSevere(e);
110
                    continue;
111
                }
112
            }
113
        }
114
115
        return result;
116
    }
117
118
    public void clear() {
119
        for (WordProcessor processor : processors) {
120
            processor.clear();
121
        }
122
        processors.clear();
123
        dataMap.clear();
124
    }
125
126
    @Override
127
    public IData removeData(final String playerName) {
128
        return dataMap.remove(playerName);
129
    }
130
131
    @Override
132
    public void removeAllData() {
133
        dataMap.clear();
134
    }
135
136
    @Override
137
    public final CheckType getCheckType() {
138
        return CheckType.CHAT_TEXT;
139
    }
140
141
    @Override
142
    public void checkConsistency(final Player[] onlinePlayers) {
143
        // Use consistency checking to release some memory.
144
        final long now = System.currentTimeMillis();
145
        if (now < dataMap.lastExpired) {
146
            dataMap.clear();
147
            return;
148
        }
149
        if (now - dataMap.lastExpired > dataMap.durExpire) {
150
            dataMap.expire(now - dataMap.durExpire);
151
        }
152
    }
153
}

How it counteracts this module

LetterEngine is the optional content-analysis layer Text invokes at line 242 (engine.process(letterCounts, player.getName(), cc, data)); its returned weights are summed or maxed into the message score per cc.textEngineMaximum (Text lines 245-251). It runs config-gated global processors - FlatWords, WordPrefixes and SimilarWordsBKL (BK-Levenshtein tree with range 2, 30-second expiry, 1000-entry cap) - plus per-player processors whose data expires after 10 minutes (600000ms, line 81), each weighted by cc.textGlobalWeight / cc.textPlayerWeight.

For the Spammer, the per-player profile is the relevant mechanism: the engine learns the distribution of words a player actually uses, and the module's closed template pools are the opposite of that distribution. The Aids mode replays the same 121 lyric lines forever, and the Memeware mode reuses 'Memeware', 'DORT' and 'ALL' across ten of its lines, so repeated words and word-prefixes from the learned set accumulate processor weight on every cycle; SimilarWordsBKL additionally scores near-duplicate words within edit range. Because the spammer emits one message per second, the engine gets constant reinforcement instead of the sparse, varied input a human produces. The honest caveat is configuration: the processors only run when the corresponding CHAT_TEXT_GL_*_CHECK / textPlayerCheck flags are enabled, so this layer is an amplifier for the frequency check rather than a standalone detector.

← Back to Analysis Hub