diff --git a/src/GlobalVar.lua b/src/GlobalVar.lua index 395cb64..07f2c84 100644 --- a/src/GlobalVar.lua +++ b/src/GlobalVar.lua @@ -19,6 +19,7 @@ START_RESET_TIME = START_RESET_TIME_BASE - TIME_ZONE * 3600 STRUCT_VERSION = 3 -- 数据结构版本 IOS_SID = 4 -- 判断是不是ios设备 +UO_SID = 6 -- 判断是不是联运渠道 MAX_ROLE_NUM = 1000000 -- 属性枚举 diff --git a/src/actions/RoleAction.lua b/src/actions/RoleAction.lua index d9abeb5..0481432 100644 --- a/src/actions/RoleAction.lua +++ b/src/actions/RoleAction.lua @@ -1020,8 +1020,6 @@ function _M.achiveRpc(agent, data) return true end - - function _M.chatRpc(agent, data) local role = agent.role local roleId = role:getProperty("id") @@ -1036,10 +1034,21 @@ function _M.chatRpc(agent, data) -- 判断禁言 local result = nil - local SERV = string_format(".chated%d", math.random(1, 5)) - local legal, mod = skynet.call(SERV, "lua", "check", content) - if not legal then - content = mod or "" + local sdkResult + if role:getProperty("sid") == UO_SID then + sdkResult = role:uoChatSDK(content) + else + sdkResult = role:biliChatSDK(content) + end + + if sdkResult and sdkResult ~= content then + content = sdkResult + else + local SERV = string_format(".chated%d", math.random(1, 5)) + local legal, mod = skynet.call(SERV, "lua", "check", content) + if not legal then + content = mod or "" + end end if content == "" then diff --git a/src/models/RolePlugin.lua b/src/models/RolePlugin.lua index fa61758..02a68a6 100644 --- a/src/models/RolePlugin.lua +++ b/src/models/RolePlugin.lua @@ -1,3 +1,6 @@ +local httpc = require("http.httpc") +local md5 = require "md5" +local cjson = require "shared.json" local serverId = tonumber(skynet.getenv("servId")) local RolePlugin = {} @@ -1756,7 +1759,7 @@ function RolePlugin.bind(Role) rechargeId = rechargeId, createTime = skynet.timex(), transactionId = transactionId, - sid = role:getProperty("sid"), + sid = self:getProperty("sid"), }) order:create() -- 正在进行中的订单 缓存 @@ -2155,6 +2158,105 @@ function RolePlugin.bind(Role) return hero:getProperty("faith") end + local function table_keys( t ) + local keys = {} + for k, _ in pairs( t ) do + keys[#keys + 1] = k + end + return keys + end + + local function makeStr(params, key, urlsign) + local keys = table_keys(params) + table.sort(keys) + local sign2Str, requestStr = "", "" + for _, key in ipairs(keys) do + sign2Str = sign2Str .. (urlsign and urlencode(params[key]) or params[key]) + requestStr = requestStr .. string.format("%s=%s&",key,urlencode(params[key])) + end + local sign = md5.sumhexa(sign2Str .. key):lower() + requestStr = requestStr .. string.format("sign=%s",sign) + + return requestStr + end + + function Role:biliChatSDK(content) + if content == "" then return end + local base64Content = base64.encode(content) + local uids = self:getProperty("uid"):split2("_") + local uid = uids[2] or self:getProperty("uid") + + local urls = { + "http://pnew.biligame.net", + "http://pserver.bilibiligame.net" + } + local secret = "8920e9dcf0cb4ebca87393ce48021ead" + + local headers = { + ["User-Agent"] = 'Mozilla/5.0 GameServer', + ["Content-Type"] = "application/x-www-form-urlencoded", + } + + local send = { + game_id = 4818, + uid = uid, + merchant_id = 1, + server_id = 3957, + version = "1", + timestamp = math.floor(skynet.timex() * 1000), + content = base64Content, + } + + local params = makeStr(send, secret) + local status, body = httpc.request("POST", urls[1], "/api/server/censor", {}, headers, params) + if tonumber(status) ~= 200 then + status, body = httpc.request("POST", urls[2], "/api/server/censor", {}, headers, params) + end + if tonumber(status) ~= 200 then + return + end + local result = json.decode(body) + if not result or result.code ~= 0 then + return + end + return result.data.content + end + + function Role:uoChatSDK(content) + if content == "" then return end + local base64Content = base64.encode(content) + local uids = self:getProperty("uid"):split2("_") + local uid = uids[2] or self:getProperty("uid") + + local urls = { + "http://uosdk.biligame.com", + } + local secret = "4243b5fb44b64175a20a53dcfb1346eb" + + local headers = { + ["User-Agent"] = 'Mozilla/5.0 CP-Game-Server', + ["Content-Type"] = "application/x-www-form-urlencoded", + } + + local send = { + app_id = 4821, + user_id = uid, + timestamp = math.floor(skynet.timex() * 1000), + content = base64Content, + } + + local params = makeStr(send, secret, true) + local status, body = httpc.request("POST", urls[1], "/api/server/censor", {}, headers, params) + if tonumber(status) ~= 200 then + return + end + local result = json.decode(body) + if not result or result.code ~= 0 then + return + end + return result.data.content + end + end return RolePlugin \ No newline at end of file diff --git a/src/shared/base64.lua b/src/shared/base64.lua new file mode 100644 index 0000000..89e4cbb --- /dev/null +++ b/src/shared/base64.lua @@ -0,0 +1,155 @@ +local base64 = {} +local string = string + +base64.__code = { + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', + 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', + 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', + 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', + }; +base64.__decode = {} +for k,v in pairs(base64.__code) do + base64.__decode[string.byte(v,1)] = k - 1 +end + +function base64.encode(text) + local len = string.len(text) + local left = len % 3 + len = len - left + local res = {} + local index = 1 + for i = 1, len, 3 do + local a = string.byte(text, i ) + local b = string.byte(text, i + 1) + local c = string.byte(text, i + 2) + -- num = a<<16 + b<<8 + c + local num = a * 65536 + b * 256 + c + for j = 1, 4 do + --tmp = num >> ((4 -j) * 6) + local tmp = math.floor(num / (2 ^ ((4-j) * 6))) + --curPos = tmp&0x3f + local curPos = tmp % 64 + 1 + res[index] = base64.__code[curPos] + index = index + 1 + end + end + + if left == 1 then + base64.__left1(res, index, text, len) + elseif left == 2 then + base64.__left2(res, index, text, len) + end + return table.concat(res) +end + +function base64.__left2(res, index, text, len) + local num1 = string.byte(text, len + 1) + num1 = num1 * 1024 --lshift 10 + local num2 = string.byte(text, len + 2) + num2 = num2 * 4 --lshift 2 + local num = num1 + num2 + + local tmp1 = math.floor(num / 4096) --rShift 12 + local curPos = tmp1 % 64 + 1 + res[index] = base64.__code[curPos] + + local tmp2 = math.floor(num / 64) + curPos = tmp2 % 64 + 1 + res[index + 1] = base64.__code[curPos] + + curPos = num % 64 + 1 + res[index + 2] = base64.__code[curPos] + + res[index + 3] = "=" +end + +function base64.__left1(res, index,text, len) + local num = string.byte(text, len + 1) + num = num * 16 + + tmp = math.floor(num / 64) + local curPos = tmp % 64 + 1 + res[index ] = base64.__code[curPos] + + curPos = num % 64 + 1 + res[index + 1] = base64.__code[curPos] + + res[index + 2] = "=" + res[index + 3] = "=" +end + +function base64.decode(text) + local len = string.len(text) + local left = 0 + if string.sub(text, len - 1) == "==" then + left = 2 + len = len - 4 + elseif string.sub(text, len) == "=" then + left = 1 + len = len - 4 + end + + local res = {} + local index = 1 + local decode = base64.__decode + for i =1, len, 4 do + local a = decode[string.byte(text,i )] + local b = decode[string.byte(text,i + 1)] + local c = decode[string.byte(text,i + 2)] + local d = decode[string.byte(text,i + 3)] + + --num = a<<18 + b<<12 + c<<6 + d + local num = a * 262144 + b * 4096 + c * 64 + d + + local e = string.char(num % 256) + num = math.floor(num / 256) + local f = string.char(num % 256) + num = math.floor(num / 256) + res[index ] = string.char(num % 256) + res[index + 1] = f + res[index + 2] = e + index = index + 3 + end + + if left == 1 then + base64.__decodeLeft1(res, index, text, len) + elseif left == 2 then + base64.__decodeLeft2(res, index, text, len) + end + return table.concat(res) +end + +function base64.__decodeLeft1(res, index, text, len) + local decode = base64.__decode + local a = decode[string.byte(text, len + 1)] + local b = decode[string.byte(text, len + 2)] + local c = decode[string.byte(text, len + 3)] + local num = a * 4096 + b * 64 + c + + local num1 = math.floor(num / 1024) % 256 + local num2 = math.floor(num / 4) % 256 + res[index] = string.char(num1) + res[index + 1] = string.char(num2) +end + +function base64.__decodeLeft2(res, index, text, len) + local decode = base64.__decode + local a = decode[string.byte(text, len + 1)] + local b = decode[string.byte(text, len + 2)] + local num = a * 64 + b + num = math.floor(num / 16) + res[index] = string.char(num) +end + +function base64.test() + local data = "a\193\207=" + local abc = base64.encode(data) + print(abc) + + def = base64.decode(abc) + if def == data then + print("yes") + end +end + +return base64 \ No newline at end of file diff --git a/src/shared/init.lua b/src/shared/init.lua index 7b51117..adad564 100644 --- a/src/shared/init.lua +++ b/src/shared/init.lua @@ -2,4 +2,5 @@ require("shared.functions") require("shared.debug") json = require("shared.json") -MsgPack = require "cmsgpack" \ No newline at end of file +MsgPack = require "cmsgpack" +base64 = require("shared.base64") \ No newline at end of file -- libgit2 0.21.2