Przeglądaj źródła

新增敏感词校验

neo 1 rok temu
rodzic
commit
4d11978a1c

+ 5 - 0
dev/modules/user.lua

@@ -1,6 +1,7 @@
1 1
 local code = require("code")
2 2
 local util_player = require("utils.util_player")
3 3
 local util_global = require("utils.util_global")
4
+local util_sensitive = require("utils.util_sensitive")
4 5
 
5 6
 local playerData = require("data.player")
6 7
 
@@ -124,6 +125,10 @@ function root:itf_update_nickname(role, msg)
124 125
     if is_empty(nickname) then
125 126
         return code.PARAMTER_ERROR
126 127
     end
128
+    -- 检查敏感词
129
+    if util_sensitive:is_sensitive(nickname) then
130
+        return code.USR.INCLUDE_SENSITIVE
131
+    end
127 132
     self:redis_update_key_info("nickname", nickname)
128 133
     return code.OK
129 134
 end

+ 2 - 2
dev/utils/util_match.lua

@@ -508,7 +508,7 @@ function root:band_room(uid, roomId, costItems)
508 508
     end
509 509
     battleData:band_room(uid, roomId, costItems)
510 510
     -- 消耗道具
511
-    local keyEvent = string.format("room-seat-down-%s", tostring(roomId))
511
+    local keyEvent = string.format("battle-seat-down-%s", tostring(roomId))
512 512
     bagData:consume_items(uid, costItems, keyEvent)
513 513
 end
514 514
 -- 解绑房间
@@ -520,7 +520,7 @@ function root:unband_room(uid, ty)
520 520
     local costItems = battleData:get_room_cost_items(uid)
521 521
     if (ty == "leave" or ty == "dismiss" or ty == "seat") and not is_empty(costItems) then
522 522
         -- 返回物品
523
-        local keyEvent = string.format("room-%s", ty)
523
+        local keyEvent = string.format("battle-%s", ty)
524 524
         bagData:add_items(uid, costItems, keyEvent)
525 525
     end
526 526
     battleData:band_room(uid)

+ 49 - 0
dev/utils/util_sensitive.lua

@@ -0,0 +1,49 @@
1
+--[[
2
+Descripttion:敏感词
3
+version:
4
+Author: Neo,Huang
5
+Date: 2023-11-19 21:20:05
6
+LastEditors: Neo,Huang
7
+LastEditTime: 2023-11-19 21:23:40
8
+--]]
9
+local const = require("const.const")
10
+local httpc = require("http.httpc")
11
+local md5 = require("md5")
12
+
13
+local root = {}
14
+
15
+-- 是否包含敏感词
16
+function root:is_sensitive(words)
17
+    if is_nil(words) then
18
+        return false
19
+    end
20
+    -- 过滤数字
21
+    local word = ""
22
+    for i = 1, string.len(words) do
23
+        local c = string.sub(words, i, i)
24
+        if not (c >= "0" and c <= "9") then
25
+            word = word .. c
26
+        end
27
+    end
28
+    set_log("is_sensitive words[%s] word[%s]", tostring(words), tostring(word))
29
+    if is_nil(word) then
30
+        return false
31
+    end
32
+
33
+    local host = skynet.getenv("server_3rd")
34
+    if is_empty(host) then
35
+        -- 不检查敏感词
36
+        return false
37
+    end
38
+    local url = "/sensitive/checkword?"
39
+    local body = string.format("word=%s", word)
40
+    local auth = md5.sumhexa(body .. const.SALT_MD5)
41
+    body = string.format("%s&sign=%s", body, auth)
42
+    local code, ret = httpc.get(host, url .. body)
43
+    if ret and string.match(ret, "false") then
44
+        return true
45
+    end
46
+    return false
47
+end
48
+
49
+return root

+ 5 - 0
nodes/web/controllers/usr.lua

@@ -5,6 +5,7 @@ local util_user = require("utils.util_user")
5 5
 local util_global = require("utils.util_global")
6 6
 local lib_game_mysql = require("lib_game_mysql")
7 7
 local lib_game_redis = require("lib_game_redis")
8
+local util_sensitive = require("utils.util_sensitive")
8 9
 
9 10
 local accountModule = require("modules.account")
10 11
 
@@ -153,6 +154,10 @@ function root.usr_register_by_phone(msg)
153 154
         -- return code.USR.ALREADY_REGISTER
154 155
         return root.usr_login_by_phone(msg)
155 156
     end
157
+    -- 敏感词
158
+    if util_sensitive:is_sensitive(msg.nickname) then
159
+        return code.USR.INCLUDE_SENSITIVE
160
+    end
156 161
     local uid = util_global:gen_user_id()
157 162
     -- 注册账号
158 163
     local err = moduleData:hset(account, "account", "account", account)

+ 3 - 5
nodes/web/lib/webapp.lua

@@ -1,13 +1,11 @@
1 1
 local md5 = require "md5"
2 2
 
3 3
 local code = require "code"
4
+local const = require("const.const")
4 5
 local lfsUtil = require "utils.lfsUtil"
5 6
 local staticfile = require "staticfile"
6 7
 local protoUtil = require "utils.protoUtil"
7 8
 
8
-local SALT_MD5 = "b8JKMN1UhanX" -- 商城md5 验签
9
-local GAME_SALT_MD5 = "0bdb9a5863c8c9063a42f38a9d5166fe" -- 游戏服加盐 md5
10
-
11 9
 local root = {}
12 10
 
13 11
 local controllerList = {}
@@ -284,9 +282,9 @@ local function l_is_match_sign(path, query, body)
284 282
 	local salt = ""
285 283
 	local sign = query.sign
286 284
 	if path == "/pb" then
287
-		salt = GAME_SALT_MD5
285
+		salt = const.GAME_SALT_MD5
288 286
 	elseif path == "/json" then
289
-		salt = SALT_MD5
287
+		salt = const.SALT_MD5
290 288
 	end
291 289
 	log.info("l_is_match_sign salt[%s]", tostring(salt))
292 290
 	if not sign then

+ 2 - 0
run/ali-test/common.conf

@@ -5,4 +5,6 @@ logpath = "/home/neo/workspace/box-server/log/"
5 5
 statistic_path = "/home/neo/workspace/box-server/log/statistic/"
6 6
 zip_statistic_path = "/home/neo/workspace/box-server/log/zip_path/"
7 7
 
8
+server_3rd = "127.0.0.1:7344"
9
+
8 10
 system = 'linux'

+ 2 - 0
run/neo-test1/common.conf

@@ -5,4 +5,6 @@ logpath = "/home/neo/work/box/box-server/log/"
5 5
 statistic_path = "/home/neo/work/box/box-server/log/statistic/"
6 6
 zip_statistic_path = "/home/neo/work/box/box-server/log/zip_path/"
7 7
 
8
+server_3rd = "192.168.10.14:7344"
9
+
8 10
 system = 'linux'