Commit 8583f6eee632e51e05e479aec2ee67dfa13c5eba

Authored by chenyueqi
1 parent 4f40cc1a

动态屏蔽字

src/GlobalVar.lua
... ... @@ -19,6 +19,7 @@ START_RESET_TIME = START_RESET_TIME_BASE - TIME_ZONE * 3600
19 19 STRUCT_VERSION = 3 -- 数据结构版本
20 20  
21 21 IOS_SID = 4 -- 判断是不是ios设备
  22 +UO_SID = 6 -- 判断是不是联运渠道
22 23  
23 24 MAX_ROLE_NUM = 1000000
24 25 -- 属性枚举
... ...
src/actions/RoleAction.lua
... ... @@ -1020,8 +1020,6 @@ function _M.achiveRpc(agent, data)
1020 1020 return true
1021 1021 end
1022 1022  
1023   -
1024   -
1025 1023 function _M.chatRpc(agent, data)
1026 1024 local role = agent.role
1027 1025 local roleId = role:getProperty("id")
... ... @@ -1036,10 +1034,21 @@ function _M.chatRpc(agent, data)
1036 1034 -- 判断禁言
1037 1035 local result = nil
1038 1036  
1039   - local SERV = string_format(".chated%d", math.random(1, 5))
1040   - local legal, mod = skynet.call(SERV, "lua", "check", content)
1041   - if not legal then
1042   - content = mod or ""
  1037 + local sdkResult
  1038 + if role:getProperty("sid") == UO_SID then
  1039 + sdkResult = role:uoChatSDK(content)
  1040 + else
  1041 + sdkResult = role:biliChatSDK(content)
  1042 + end
  1043 +
  1044 + if sdkResult and sdkResult ~= content then
  1045 + content = sdkResult
  1046 + else
  1047 + local SERV = string_format(".chated%d", math.random(1, 5))
  1048 + local legal, mod = skynet.call(SERV, "lua", "check", content)
  1049 + if not legal then
  1050 + content = mod or ""
  1051 + end
1043 1052 end
1044 1053  
1045 1054 if content == "" then
... ...
src/models/RolePlugin.lua
  1 +local httpc = require("http.httpc")
  2 +local md5 = require "md5"
  3 +local cjson = require "shared.json"
1 4  
2 5 local serverId = tonumber(skynet.getenv("servId"))
3 6 local RolePlugin = {}
... ... @@ -1756,7 +1759,7 @@ function RolePlugin.bind(Role)
1756 1759 rechargeId = rechargeId,
1757 1760 createTime = skynet.timex(),
1758 1761 transactionId = transactionId,
1759   - sid = role:getProperty("sid"),
  1762 + sid = self:getProperty("sid"),
1760 1763 })
1761 1764 order:create()
1762 1765 -- 正在进行中的订单 缓存
... ... @@ -2155,6 +2158,105 @@ function RolePlugin.bind(Role)
2155 2158 return hero:getProperty("faith")
2156 2159 end
2157 2160  
  2161 + local function table_keys( t )
  2162 + local keys = {}
  2163 + for k, _ in pairs( t ) do
  2164 + keys[#keys + 1] = k
  2165 + end
  2166 + return keys
  2167 + end
  2168 +
  2169 + local function makeStr(params, key, urlsign)
  2170 + local keys = table_keys(params)
  2171 + table.sort(keys)
  2172 + local sign2Str, requestStr = "", ""
  2173 + for _, key in ipairs(keys) do
  2174 + sign2Str = sign2Str .. (urlsign and urlencode(params[key]) or params[key])
  2175 + requestStr = requestStr .. string.format("%s=%s&",key,urlencode(params[key]))
  2176 + end
  2177 + local sign = md5.sumhexa(sign2Str .. key):lower()
  2178 + requestStr = requestStr .. string.format("sign=%s",sign)
  2179 +
  2180 + return requestStr
  2181 + end
  2182 +
  2183 + function Role:biliChatSDK(content)
  2184 + if content == "" then return end
  2185 + local base64Content = base64.encode(content)
  2186 + local uids = self:getProperty("uid"):split2("_")
  2187 + local uid = uids[2] or self:getProperty("uid")
  2188 +
  2189 + local urls = {
  2190 + "http://pnew.biligame.net",
  2191 + "http://pserver.bilibiligame.net"
  2192 + }
  2193 + local secret = "8920e9dcf0cb4ebca87393ce48021ead"
  2194 +
  2195 + local headers = {
  2196 + ["User-Agent"] = 'Mozilla/5.0 GameServer',
  2197 + ["Content-Type"] = "application/x-www-form-urlencoded",
  2198 + }
  2199 +
  2200 + local send = {
  2201 + game_id = 4818,
  2202 + uid = uid,
  2203 + merchant_id = 1,
  2204 + server_id = 3957,
  2205 + version = "1",
  2206 + timestamp = math.floor(skynet.timex() * 1000),
  2207 + content = base64Content,
  2208 + }
  2209 +
  2210 + local params = makeStr(send, secret)
  2211 + local status, body = httpc.request("POST", urls[1], "/api/server/censor", {}, headers, params)
  2212 + if tonumber(status) ~= 200 then
  2213 + status, body = httpc.request("POST", urls[2], "/api/server/censor", {}, headers, params)
  2214 + end
  2215 + if tonumber(status) ~= 200 then
  2216 + return
  2217 + end
  2218 + local result = json.decode(body)
  2219 + if not result or result.code ~= 0 then
  2220 + return
  2221 + end
  2222 + return result.data.content
  2223 + end
  2224 +
  2225 + function Role:uoChatSDK(content)
  2226 + if content == "" then return end
  2227 + local base64Content = base64.encode(content)
  2228 + local uids = self:getProperty("uid"):split2("_")
  2229 + local uid = uids[2] or self:getProperty("uid")
  2230 +
  2231 + local urls = {
  2232 + "http://uosdk.biligame.com",
  2233 + }
  2234 + local secret = "4243b5fb44b64175a20a53dcfb1346eb"
  2235 +
  2236 + local headers = {
  2237 + ["User-Agent"] = 'Mozilla/5.0 CP-Game-Server',
  2238 + ["Content-Type"] = "application/x-www-form-urlencoded",
  2239 + }
  2240 +
  2241 + local send = {
  2242 + app_id = 4821,
  2243 + user_id = uid,
  2244 + timestamp = math.floor(skynet.timex() * 1000),
  2245 + content = base64Content,
  2246 + }
  2247 +
  2248 + local params = makeStr(send, secret, true)
  2249 + local status, body = httpc.request("POST", urls[1], "/api/server/censor", {}, headers, params)
  2250 + if tonumber(status) ~= 200 then
  2251 + return
  2252 + end
  2253 + local result = json.decode(body)
  2254 + if not result or result.code ~= 0 then
  2255 + return
  2256 + end
  2257 + return result.data.content
  2258 + end
  2259 +
2158 2260 end
2159 2261  
2160 2262 return RolePlugin
2161 2263 \ No newline at end of file
... ...
src/shared/base64.lua 0 → 100644
... ... @@ -0,0 +1,155 @@
  1 +local base64 = {}
  2 +local string = string
  3 +
  4 +base64.__code = {
  5 + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
  6 + 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
  7 + 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  8 + 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/',
  9 + };
  10 +base64.__decode = {}
  11 +for k,v in pairs(base64.__code) do
  12 + base64.__decode[string.byte(v,1)] = k - 1
  13 +end
  14 +
  15 +function base64.encode(text)
  16 + local len = string.len(text)
  17 + local left = len % 3
  18 + len = len - left
  19 + local res = {}
  20 + local index = 1
  21 + for i = 1, len, 3 do
  22 + local a = string.byte(text, i )
  23 + local b = string.byte(text, i + 1)
  24 + local c = string.byte(text, i + 2)
  25 + -- num = a<<16 + b<<8 + c
  26 + local num = a * 65536 + b * 256 + c
  27 + for j = 1, 4 do
  28 + --tmp = num >> ((4 -j) * 6)
  29 + local tmp = math.floor(num / (2 ^ ((4-j) * 6)))
  30 + --curPos = tmp&0x3f
  31 + local curPos = tmp % 64 + 1
  32 + res[index] = base64.__code[curPos]
  33 + index = index + 1
  34 + end
  35 + end
  36 +
  37 + if left == 1 then
  38 + base64.__left1(res, index, text, len)
  39 + elseif left == 2 then
  40 + base64.__left2(res, index, text, len)
  41 + end
  42 + return table.concat(res)
  43 +end
  44 +
  45 +function base64.__left2(res, index, text, len)
  46 + local num1 = string.byte(text, len + 1)
  47 + num1 = num1 * 1024 --lshift 10
  48 + local num2 = string.byte(text, len + 2)
  49 + num2 = num2 * 4 --lshift 2
  50 + local num = num1 + num2
  51 +
  52 + local tmp1 = math.floor(num / 4096) --rShift 12
  53 + local curPos = tmp1 % 64 + 1
  54 + res[index] = base64.__code[curPos]
  55 +
  56 + local tmp2 = math.floor(num / 64)
  57 + curPos = tmp2 % 64 + 1
  58 + res[index + 1] = base64.__code[curPos]
  59 +
  60 + curPos = num % 64 + 1
  61 + res[index + 2] = base64.__code[curPos]
  62 +
  63 + res[index + 3] = "="
  64 +end
  65 +
  66 +function base64.__left1(res, index,text, len)
  67 + local num = string.byte(text, len + 1)
  68 + num = num * 16
  69 +
  70 + tmp = math.floor(num / 64)
  71 + local curPos = tmp % 64 + 1
  72 + res[index ] = base64.__code[curPos]
  73 +
  74 + curPos = num % 64 + 1
  75 + res[index + 1] = base64.__code[curPos]
  76 +
  77 + res[index + 2] = "="
  78 + res[index + 3] = "="
  79 +end
  80 +
  81 +function base64.decode(text)
  82 + local len = string.len(text)
  83 + local left = 0
  84 + if string.sub(text, len - 1) == "==" then
  85 + left = 2
  86 + len = len - 4
  87 + elseif string.sub(text, len) == "=" then
  88 + left = 1
  89 + len = len - 4
  90 + end
  91 +
  92 + local res = {}
  93 + local index = 1
  94 + local decode = base64.__decode
  95 + for i =1, len, 4 do
  96 + local a = decode[string.byte(text,i )]
  97 + local b = decode[string.byte(text,i + 1)]
  98 + local c = decode[string.byte(text,i + 2)]
  99 + local d = decode[string.byte(text,i + 3)]
  100 +
  101 + --num = a<<18 + b<<12 + c<<6 + d
  102 + local num = a * 262144 + b * 4096 + c * 64 + d
  103 +
  104 + local e = string.char(num % 256)
  105 + num = math.floor(num / 256)
  106 + local f = string.char(num % 256)
  107 + num = math.floor(num / 256)
  108 + res[index ] = string.char(num % 256)
  109 + res[index + 1] = f
  110 + res[index + 2] = e
  111 + index = index + 3
  112 + end
  113 +
  114 + if left == 1 then
  115 + base64.__decodeLeft1(res, index, text, len)
  116 + elseif left == 2 then
  117 + base64.__decodeLeft2(res, index, text, len)
  118 + end
  119 + return table.concat(res)
  120 +end
  121 +
  122 +function base64.__decodeLeft1(res, index, text, len)
  123 + local decode = base64.__decode
  124 + local a = decode[string.byte(text, len + 1)]
  125 + local b = decode[string.byte(text, len + 2)]
  126 + local c = decode[string.byte(text, len + 3)]
  127 + local num = a * 4096 + b * 64 + c
  128 +
  129 + local num1 = math.floor(num / 1024) % 256
  130 + local num2 = math.floor(num / 4) % 256
  131 + res[index] = string.char(num1)
  132 + res[index + 1] = string.char(num2)
  133 +end
  134 +
  135 +function base64.__decodeLeft2(res, index, text, len)
  136 + local decode = base64.__decode
  137 + local a = decode[string.byte(text, len + 1)]
  138 + local b = decode[string.byte(text, len + 2)]
  139 + local num = a * 64 + b
  140 + num = math.floor(num / 16)
  141 + res[index] = string.char(num)
  142 +end
  143 +
  144 +function base64.test()
  145 + local data = "a\193\207="
  146 + local abc = base64.encode(data)
  147 + print(abc)
  148 +
  149 + def = base64.decode(abc)
  150 + if def == data then
  151 + print("yes")
  152 + end
  153 +end
  154 +
  155 +return base64
0 156 \ No newline at end of file
... ...
src/shared/init.lua
... ... @@ -2,4 +2,5 @@ require(&quot;shared.functions&quot;)
2 2 require("shared.debug")
3 3  
4 4 json = require("shared.json")
5   -MsgPack = require "cmsgpack"
6 5 \ No newline at end of file
  6 +MsgPack = require "cmsgpack"
  7 +base64 = require("shared.base64")
7 8 \ No newline at end of file
... ...