瀏覽代碼

新增敏感词校验

neo 1 年之前
父節點
當前提交
4d11978a1c

+ 5 - 0
dev/modules/user.lua

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

+ 2 - 2
dev/utils/util_match.lua

@@ -508,7 +508,7 @@ function root:band_room(uid, roomId, costItems)
508
     end
508
     end
509
     battleData:band_room(uid, roomId, costItems)
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
     bagData:consume_items(uid, costItems, keyEvent)
512
     bagData:consume_items(uid, costItems, keyEvent)
513
 end
513
 end
514
 -- 解绑房间
514
 -- 解绑房间
@@ -520,7 +520,7 @@ function root:unband_room(uid, ty)
520
     local costItems = battleData:get_room_cost_items(uid)
520
     local costItems = battleData:get_room_cost_items(uid)
521
     if (ty == "leave" or ty == "dismiss" or ty == "seat") and not is_empty(costItems) then
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
         bagData:add_items(uid, costItems, keyEvent)
524
         bagData:add_items(uid, costItems, keyEvent)
525
     end
525
     end
526
     battleData:band_room(uid)
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
 local util_global = require("utils.util_global")
5
 local util_global = require("utils.util_global")
6
 local lib_game_mysql = require("lib_game_mysql")
6
 local lib_game_mysql = require("lib_game_mysql")
7
 local lib_game_redis = require("lib_game_redis")
7
 local lib_game_redis = require("lib_game_redis")
8
+local util_sensitive = require("utils.util_sensitive")
8
 
9
 
9
 local accountModule = require("modules.account")
10
 local accountModule = require("modules.account")
10
 
11
 
@@ -153,6 +154,10 @@ function root.usr_register_by_phone(msg)
153
         -- return code.USR.ALREADY_REGISTER
154
         -- return code.USR.ALREADY_REGISTER
154
         return root.usr_login_by_phone(msg)
155
         return root.usr_login_by_phone(msg)
155
     end
156
     end
157
+    -- 敏感词
158
+    if util_sensitive:is_sensitive(msg.nickname) then
159
+        return code.USR.INCLUDE_SENSITIVE
160
+    end
156
     local uid = util_global:gen_user_id()
161
     local uid = util_global:gen_user_id()
157
     -- 注册账号
162
     -- 注册账号
158
     local err = moduleData:hset(account, "account", "account", account)
163
     local err = moduleData:hset(account, "account", "account", account)

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

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

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

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

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

@@ -5,4 +5,6 @@ logpath = "/home/neo/work/box/box-server/log/"
5
 statistic_path = "/home/neo/work/box/box-server/log/statistic/"
5
 statistic_path = "/home/neo/work/box/box-server/log/statistic/"
6
 zip_statistic_path = "/home/neo/work/box/box-server/log/zip_path/"
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
 system = 'linux'
10
 system = 'linux'