Handler.lua 13 KB

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