Handler.lua 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. Json = Json or require("common.Json")
  2. local Config = require("Config")
  3. local CommonDefine = require("common.CommonDefine")
  4. local Log = require("common.Log")
  5. local CommonDB = require("common.CommonDB")
  6. local LogDefine = require("common.LogDefine")
  7. local Msg = require("core.Msg")
  8. local ObjHuman = require("core.ObjHuman")
  9. local CreateRole = require("role.CreateRole")
  10. local PlatformDefine = require("platform.Define")
  11. local PfLogic = require("platform.PfLogic")
  12. local LuaMongo = _G.lua_mongo
  13. local DB = require("common.DB")
  14. local RoleDBLogic = require("role.RoleDBLogic")
  15. local Util = require("common.Util")
  16. local AuthCheck = require("scene.AuthCheck")
  17. local ApiLogic = require("platform.ApiLogic")
  18. local CDKLoigc = require("present.CDK")
  19. local MailManager = require("mail.MailManager")
  20. local QQBigShot = require("platform.QQBigShot")
  21. local BanLogic = require("scene.BanLogic")
  22. local function HumanLogin_Handle(human, params)
  23. -- 单次上报时长设置为登录时间
  24. human.db.onlineTimeDayReport = os.time()
  25. -- print("[HumanLogin_Handle] 进入了判断")
  26. --table.print_lua_table(params)
  27. if params.dwkLevel then
  28. print("[HumanLogin_Handle] 获取到的等级 dwkLevel = "..params.dwkLevel)
  29. QQBigShot.QQBigShot_HumanLoginHandle(human, params.dwkLevel)
  30. end
  31. end
  32. -- 是否禁止登录
  33. local function isBan(uuid, channelId, account, appId)
  34. return BanLogic.CheckBan(uuid, channelId, account, appId)
  35. end
  36. -- 判断是否属于白名单IP
  37. local function isWhiteIp(ip)
  38. if not ip then
  39. return false
  40. end
  41. if not Config.WHITEIP_LIST or #Config.WHITEIP_LIST == 0 then
  42. return true
  43. end
  44. if table.find(Config.WHITEIP_LIST, ip) then
  45. return true
  46. end
  47. return false
  48. end
  49. --在线玩家列表不再从 ObjHuman.onlineAccount 获取, 改为从 ObjHuman.onlineNewUniqueTag 获取
  50. function CG_TEST_PROTO(fd,msg)
  51. -- print("============ CG_TEST_PROTO============", msg.param)
  52. local param = Json.Decode(msg.param)
  53. local uTag
  54. if param.type == "UseCDKV2" or param.type == "UseCDK" or param.type == "UseFixCDK" then
  55. uTag = RoleDBLogic.Generateuuid(param.channel_id, msg.account, msg.serverTag)
  56. end
  57. -- Util.printTable(param)
  58. if param.type == "UseCDKV2" then
  59. -- local human = ObjHuman.onlineAccount[msg.account]
  60. local human = ObjHuman.onlineNewUniqueTag[uTag]
  61. if not human then
  62. -- 玩家不在线 做一个离线处理
  63. return
  64. end
  65. CDKLoigc.cdkDoV2(human,{
  66. itemList = param.itemList,
  67. })
  68. elseif param.type == "UseCDK" then
  69. -- local human = ObjHuman.onlineAccount[msg.account]
  70. local human = ObjHuman.onlineNewUniqueTag[uTag]
  71. if not human then
  72. -- 玩家不在线 做一个离线处理
  73. return
  74. end
  75. local batch = Json.Decode(param.batchInfo)
  76. CDKLoigc.cdkDo(human,{
  77. itemList = Json.Decode(batch.itenList),
  78. serverList = Json.Decode(batch.serverList),
  79. batch = tonumber(batch.batch),
  80. useCnt = tonumber(batch.cnt),
  81. err = param.err,
  82. })
  83. elseif param.type == "UseFixCDK" then
  84. -- local human = ObjHuman.onlineAccount[msg.account]
  85. local human = ObjHuman.onlineNewUniqueTag[uTag]
  86. if not human then
  87. -- 玩家不在线 做一个离线处理
  88. return
  89. end
  90. CDKLoigc.cdkFixDo(human,param.code) --
  91. elseif param.type == "sendMail" then
  92. local mail = Json.Decode(param.mail)
  93. MailManager.add(MailManager.SYSTEM,mail.uuid,mail.title,mail.content,mail.items,nil,nil,nil,nil,nil,nil,mail.expire)
  94. elseif param.type == "kickAllUser" then
  95. -- for _,h in pairs(ObjHuman.onlineAccount) do
  96. -- ObjHuman.doDisconnect(h, CommonDefine.DISCONNECT_KICK_ALL)
  97. -- sendDisconnect(h.fd,CommonDefine.DISCONNECT_KICK_ALL)
  98. -- end
  99. for _,h in pairs(ObjHuman.onlineNewUniqueTag) do
  100. ObjHuman.doDisconnect(h, CommonDefine.DISCONNECT_KICK_ALL)
  101. sendDisconnect(h.fd,CommonDefine.DISCONNECT_KICK_ALL)
  102. end
  103. elseif param.type == "setBan" then
  104. local banInfo = {
  105. roleBanInfo = param.roleBanInfo,
  106. accountBanInfo = param.accountBanInfo,
  107. appBanInfo = param.appBanInfo
  108. }
  109. BanLogic.Update_Ban_Info(banInfo)
  110. elseif param.type == "deliverGoods" then
  111. local uTag = RoleDBLogic.Generateuuid(param.channel_id, msg.account, msg.serverTag)
  112. local human = ObjHuman.onlineNewUniqueTag[uTag]
  113. if not human then
  114. Log.write(Log.LOGID_DEBUG, "[deliverGoods] 玩家不在线 account=" .. tostring(msg.account) .. " orderId=" .. tostring(param.orderId))
  115. return
  116. end
  117. local items = {}
  118. if param.goods and #param.goods > 0 then
  119. for _, good in ipairs(param.goods) do
  120. table.insert(items, {good.Id, good.Num})
  121. end
  122. end
  123. Log.write(Log.LOGID_DEBUG, "[deliverGoods] 开始发货 account=" .. tostring(msg.account) .. " orderId=" .. tostring(param.orderId) .. " itemCnt=" .. #items)
  124. youxiSdkReward(human, items)
  125. end
  126. end
  127. function CG_AA_DISCONNECT(human)
  128. if type(human) ~= "table" then return end
  129. ObjHuman.doDisconnect(human, CommonDefine.DISCONNECT_NORMAL)
  130. end
  131. function setLoginParams(human, msg, params)
  132. human.lang = msg.lang
  133. human.region = (msg.region == "") and "CN" or string.upper(msg.region)
  134. human.ip = (msg.ip ~= "") and msg.ip or _G.global.get_ip_from_fd(human.fd)
  135. -- 有些字段重复赋值,看看以后要不要干掉。。。
  136. human.pf = params.pf
  137. human.isIOS = params.isIOS or 0
  138. human.vopenid = params.openid or ""
  139. human.openkey = params.openkey or ""
  140. human.phpChanelID = params.phpChanelID or ""
  141. human.appid = params.appid
  142. human.gameName = params.gameName or ""
  143. human.version = params.version or nil
  144. human.serverTag = msg.serverTag
  145. human.deviceNo = params.deviceNo or "" --设备号
  146. human.pf_info = human.pf_info or {}
  147. human.pf_info.openid = params.openid or ""
  148. human.pf_info.openkey = params.openkey or ""
  149. human.pf_info.pf = params.pf or ""
  150. human.pf_info.pfkey = params.pfkey or ""
  151. human.pf_info.zoneid = params.zoneid or 0
  152. human.pf_info.serverid = params.serverid or 0
  153. human.pf_info.tcTime = os.time()
  154. human.pf_info.lvYellow = params.lvYellow or 0
  155. human.pf_info.yearYellow = params.yearYellow or 0
  156. human.pf_info.superYellow = params.superYellow or 0
  157. human.pf_info.lvBlue = params.lvBlue or 0
  158. human.pf_info.yearBlue = params.yearBlue or 0
  159. human.pf_info.superBlue = params.superBlue or 0
  160. human.pf_info.validTimeBlue = params.validTimeBlue or 0
  161. human.pf_info.vipSevenk = params.vipSevenk or 0
  162. human.pf_info.validTimeSevenk = params.validTimeSevenk or 0
  163. human.pf_info.phpChanelID = params.phpChanelID or ""
  164. human.pf_info.phoneSystem = params.phoneSystem or "android"
  165. human.pf_info.from_openid = params.from_openid or ""
  166. end
  167. function sendDisconnect(fd, errCode)
  168. local mm = Msg.gc.GC_DISCONNECT
  169. mm.code = errCode
  170. mm.msg = CommonDefine.DISCONNECT_MSG[errCode]
  171. Msg.send(mm, fd)
  172. end
  173. function CG_ASK_LOGIN(fd, msg)
  174. -- 测试支付回调 有时间换个地方
  175. if msg.account == "H1EqhbpA80jt0Jw6Q3T2" then
  176. Log.write(Log.LOGID_OSS_DELIVER, "[测试支付回调] 开始处理, account=" .. msg.account .. ", serverTag=" .. msg.serverTag)
  177. -- 解析支付参数
  178. local payParams = Json.Decode(msg.params)
  179. if not payParams then
  180. Log.write(Log.LOGID_OSS_DELIVER, "[测试支付回调] 解析参数失败, params=" .. tostring(msg.params))
  181. return
  182. end
  183. Log.write(Log.LOGID_OSS_DELIVER, "[测试支付回调] 解析参数成功, params=" .. Json.Encode(payParams))
  184. -- 构建发货请求参数
  185. oJsonInput = {
  186. type=1,
  187. id=payParams.id,--商品id
  188. cnt=payParams.cnt, --数量
  189. money=payParams.money, -- 金额
  190. account=payParams.account, --账号
  191. serverTag = msg.serverTag, --区服标识
  192. order=payParams.order,--订单号
  193. region="cn",
  194. channelID = payParams.channel_id
  195. }
  196. Log.write(Log.LOGID_OSS_DELIVER, "[测试支付回调] 构建发货请求, oJsonInput=" .. Json.Encode(oJsonInput))
  197. -- 调用发货接口
  198. Log.write(Log.LOGID_OSS_DELIVER, "[测试支付回调] 开始调用发货接口, order=" .. tostring(payParams.order))
  199. local buyRet = ApiLogic.deliver(oJsonInput,{})
  200. if buyRet then
  201. Log.write(Log.LOGID_OSS_DELIVER, "[测试支付回调] 发货接口返回成功, result=" .. Json.Encode(buyRet))
  202. else
  203. Log.write(Log.LOGID_OSS_DELIVER, "[测试支付回调] 发货接口返回失败或无返回值")
  204. end
  205. Log.write(Log.LOGID_OSS_DELIVER, "[测试支付回调] 处理完成")
  206. return
  207. end
  208. if _G.is_middle == true then return end
  209. --判断是否是数字类型
  210. if type(fd) ~= "number" then
  211. assert()
  212. end
  213. if msg.account == "" then
  214. return sendDisconnect(fd, CommonDefine.DISCONNECT_AUTH_FAIL)
  215. end
  216. if Config.IS_CHECK_IP == true and not isWhiteIp(msg.ip) then
  217. return
  218. end
  219. --如果在线人数大于最大可容纳在线人数时,断开链接
  220. local onlineCnt = ObjHuman.getOnlineCnt()
  221. if onlineCnt >= CommonDefine.MAX_ONLINE_COUNT then
  222. return sendDisconnect(fd, CommonDefine.DISCONNECT_MAX_ONLINE)
  223. end
  224. --目前暂未校验,返回的都是true,后续如果需要校验,再看看是否需要把区服标识传入
  225. local retAuth = AuthCheck.authCheck(msg.account, msg.authkey, msg.timestamp, msg.ip)
  226. if retAuth ~= true then
  227. return sendDisconnect(fd, CommonDefine.DISCONNECT_AUTH_FAIL)
  228. end
  229. local account = msg.account
  230. local serverTag = msg.serverTag
  231. local params = Json.Decode(msg.params)
  232. print("CG_ASK_LOGIN", msg.account, msg.serverTag, params.phpChanelID, type(params.phpChanelID), params.deviceNo, type(params.deviceNo))
  233. --如果是已经登录的,也断开连接
  234. --local human_old = ObjHuman.onlineAccount[account]
  235. local uTag = RoleDBLogic.Generateuuid(params.phpChanelID, account, serverTag)
  236. local human_old = ObjHuman.onlineNewUniqueTag[uTag]
  237. if human_old then
  238. ObjHuman.doDisconnect(human_old, CommonDefine.DISCONNECT_DUPLICATE)
  239. end
  240. --创建新角色
  241. -- local human = ObjHuman.create(fd, account, human_old and human_old.db, nil)
  242. local human = ObjHuman.create(fd, account, human_old and human_old.db, uTag)
  243. setLoginParams(human, msg, params) -- 设置登录参数
  244. -- 禁止登录检测
  245. if isBan(human.db and human.db._id, params.phpChanelID, account, params.deviceNo) then
  246. return sendDisconnect(fd, CommonDefine.DISCONNECT_AUTH_FAIL)
  247. end
  248. if human.db == nil then
  249. -- 新号
  250. -- local ip,time = CommonDB.getBanIp(msg.ip)
  251. -- if (time and time > os.time()) then
  252. -- ObjHuman.doDisconnect(human, CommonDefine.DISCONNECT_BANIP)
  253. -- return
  254. -- else
  255. -- CommonDB.delBanIp(msg.ip)
  256. -- end
  257. Log.write(Log.LOGID_OSS_CREATELOSS,account, "", LogDefine.HUMAN_LOST.ENTRANCE, human.ip, human.pf, human.appid, human.phpChanelID)
  258. CreateRole.createNewRole(human)
  259. HumanLogin_Handle(human, params)
  260. else
  261. -- 封号
  262. -- if human.db.banUserTime == -1 or
  263. -- (human.db.banUserTime and human.db.banUserTime > os.time()) then
  264. -- ObjHuman.doDisconnect(human, CommonDefine.DISCONNECT_BANUSER)
  265. -- return
  266. -- end
  267. -- local ip,time = CommonDB.getBanIp(msg.ip)
  268. -- if (time and time > os.time()) then
  269. -- ObjHuman.doDisconnect(human, CommonDefine.DISCONNECT_BANIP)
  270. -- return
  271. -- else
  272. -- CommonDB.delBanIp(msg.ip)
  273. -- end
  274. ObjHuman.onLogin(human, nil)
  275. HumanLogin_Handle(human, params)
  276. end
  277. -- 存储美团相关参数(如果存在)
  278. if human.db then
  279. -- mtSubscribe 改为由专门协议处理,这里不再从登录参数写入
  280. if params.mtFrom2floor ~= nil then
  281. local from2floor = tonumber(params.mtFrom2floor) or 0
  282. -- 只在“当天第一次从2楼进入”时,将 mtFrom2floor 置为 1
  283. -- 如果当天已经被服务器逻辑(领取奖励或11点邮件)置为 0,则本日内前端不能再次覆盖为 1
  284. if from2floor == 1 then
  285. local now = os.time()
  286. local todayStart = Util.getDayStartTime(now)
  287. human.db.mtFrom2floorDay = human.db.mtFrom2floorDay or 0
  288. if not Util.isSameDay(human.db.mtFrom2floorDay) then
  289. human.db.mtFrom2floor = 1
  290. human.db.mtFrom2floorDay = todayStart
  291. end
  292. end
  293. end
  294. end
  295. end
  296. function CG_HEART_BEAT(human, msg)
  297. local msgRet = Msg.gc.GC_HEART_BEAT
  298. msgRet.timeStamp = os.time()
  299. Msg.send(msgRet, human.fd)
  300. end
  301. -- 记录fps
  302. local FPS_TB = {["guaji"]=1, ["zhandou"]=1, ["zhucheng"]=1, ["buzhen"]=1}
  303. function CG_PHONE_FPS(human, msg)
  304. if FPS_TB[msg.fpsType] == nil then return end
  305. human.db.fpsTb = human.db.fpsTb or {}
  306. human.db.fpsTb[msg.fpsType] = { lv = human.db.lv, startFps = msg.startFps, endFps = msg.endFps}
  307. end
  308. function CG_HEART_BEAT_M(human)
  309. end
  310. function CG_ASK_DISCONNECT(human)
  311. ObjHuman.doDisconnect(human, CommonDefine.DISCONNECT_NORMAL)
  312. end
  313. function CG_CLIENT_ERROR(human, msg)
  314. Log.write(Log.LOGID_OSS_CLIENT_ERR, human.db and human.db._id or "", human.db and human.db.account or human.account, human.db and human.db.name or "", msg.err)
  315. end
  316. function CG_CLIENT_LOAD_ERROR(human, msg)
  317. Log.write(Log.LOGID_OSS_CLIENT_LOAD_ERR, human.db and human.db._id or "", human.db and human.db.account or human.account, human.db and human.db.name or "", msg.err)
  318. end
  319. IOS_FLAG_CHARGECLOSE = 0 -- 提示关闭
  320. IOS_FLAG_CHARGEOPENTIP = 1 -- 提示开放
  321. IOS_FLAG_CHARGEOPEN = 2 -- 充值开放
  322. function getIosChargeOpenFlag(human)
  323. if PfLogic.isFkwTishen() == true then
  324. if human.isIOS == 1 then
  325. return IOS_FLAG_CHARGECLOSE
  326. end
  327. end
  328. if PfLogic.isKunTangTishen() == true then
  329. return IOS_FLAG_CHARGECLOSE
  330. end
  331. return IOS_FLAG_CHARGEOPEN
  332. end
  333. function canCharge(human)
  334. if getIosChargeOpenFlag(human) == IOS_FLAG_CHARGECLOSE then
  335. return
  336. end
  337. return true
  338. end