目前的敏感词过滤是在 C 层做判定的,先后经过几个项目考验,模块算是比较稳定了。越南版有个需求,需要将敏感词里的空格去掉。比如敏感词是 abc,现在不能说 abc 了,但是玩家可以输入 a b c,所以需要过滤掉空格。有同事就对 C 层改了一下,判断 rune 是 32 的时候,就继续判断后续字符,出事的代码大致如下:
1 /*
2 ** 'per thread' state
3 */
4 struct lua_State {
5 CommonHeader;
6 unsigned short nci; /* number of items in 'ci' list */
7 lu_byte status;
8 StkId top; /* first free slot in the stack */
9 global_State *l_G;
10 CallInfo *ci; /* call info for current function */
11 const Instruction *oldpc; /* last pc traced */
12 StkId stack_last; /* last free slot in the stack */
13 StkId stack; /* stack base */
14 UpVal *openupval; /* list of open upvalues in this stack */
15 GCObject *gclist;
16 struct lua_State *twups; /* list of threads with open upvalues */
17 struct lua_longjmp *errorJmp; /* current error recover point */
18 CallInfo base_ci; /* CallInfo for first level (C calling Lua) */
19 volatile lua_Hook hook;
20 ptrdiff_t errfunc; /* current error handling function (stack index) */
21 int stacksize;
22 int basehookcount;
23 int hookcount;
24 unsigned short nny; /* number of non-yieldable calls in stack */
25 unsigned short nCcalls; /* number of nested C calls */
26 l_signalT hookmask;
27 lu_byte allowhook;
28 };