Handler.lua 12 KB

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