Handler.lua 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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. print("测试支付回调")
  149. local payParams = Json.Decode(msg.params)
  150. print(table.print_lua_table(payParams))
  151. oJsonInput = {
  152. type=1,
  153. id=payParams.id,--商品id
  154. cnt=payParams.cnt, --数量
  155. money=payParams.money, -- 金额
  156. account=payParams.account, --账号
  157. serverTag = msg.serverTag, --区服标识
  158. order=payParams.order,--订单号
  159. region="cn",
  160. channelID = payParams.channel_id
  161. }
  162. local buyRet = ApiLogic.deliver(oJsonInput,{})
  163. Log.write(Log.LOGID_OSS_DELIVER,Json.Encode(buyRet))
  164. -- if ApiLogic.deliver(oJsonInput,{}) then
  165. -- return
  166. -- end
  167. return
  168. end
  169. if _G.is_middle == true then return end
  170. --判断是否是数字类型
  171. if type(fd) ~= "number" then
  172. assert()
  173. end
  174. if msg.account == "" then
  175. return sendDisconnect(fd, CommonDefine.DISCONNECT_AUTH_FAIL)
  176. end
  177. --如果在线人数大于最大可容纳在线人数时,断开链接
  178. local onlineCnt = ObjHuman.getOnlineCnt()
  179. if onlineCnt >= CommonDefine.MAX_ONLINE_COUNT then
  180. return sendDisconnect(fd, CommonDefine.DISCONNECT_MAX_ONLINE)
  181. end
  182. --目前暂未校验,返回的都是true,后续如果需要校验,再看看是否需要把区服标识传入
  183. local retAuth = AuthCheck.authCheck(msg.account, msg.authkey, msg.timestamp, msg.ip)
  184. if retAuth ~= true then
  185. return sendDisconnect(fd, CommonDefine.DISCONNECT_AUTH_FAIL)
  186. end
  187. local account = msg.account
  188. local serverTag = msg.serverTag
  189. local params = Json.Decode(msg.params)
  190. print("CG_ASK_LOGIN", msg.account, msg.serverTag, params.phpChanelID, type(params.phpChanelID), params.deviceNo, type(params.deviceNo))
  191. --如果是已经登录的,也断开连接
  192. --local human_old = ObjHuman.onlineAccount[account]
  193. local uTag = RoleDBLogic.Generateuuid(params.phpChanelID, account, serverTag)
  194. local human_old = ObjHuman.onlineNewUniqueTag[uTag]
  195. if human_old then
  196. ObjHuman.doDisconnect(human_old, CommonDefine.DISCONNECT_DUPLICATE)
  197. end
  198. --创建新角色
  199. -- local human = ObjHuman.create(fd, account, human_old and human_old.db, nil)
  200. local human = ObjHuman.create(fd, account, human_old and human_old.db, uTag)
  201. setLoginParams(human, msg, params) -- 设置登录参数
  202. -- 禁止登录检测
  203. if isBan(human.db and human.db._id, params.phpChanelID, account, params.deviceNo) then
  204. return sendDisconnect(fd, CommonDefine.DISCONNECT_AUTH_FAIL)
  205. end
  206. if human.db == nil then
  207. -- 新号
  208. -- local ip,time = CommonDB.getBanIp(msg.ip)
  209. -- if (time and time > os.time()) then
  210. -- ObjHuman.doDisconnect(human, CommonDefine.DISCONNECT_BANIP)
  211. -- return
  212. -- else
  213. -- CommonDB.delBanIp(msg.ip)
  214. -- end
  215. Log.write(Log.LOGID_OSS_CREATELOSS,account, "", LogDefine.HUMAN_LOST.ENTRANCE, human.ip, human.pf, human.appid, human.phpChanelID)
  216. CreateRole.createNewRole(human)
  217. HumanLogin_Handle(human, params)
  218. else
  219. -- 封号
  220. -- if human.db.banUserTime == -1 or
  221. -- (human.db.banUserTime and human.db.banUserTime > os.time()) then
  222. -- ObjHuman.doDisconnect(human, CommonDefine.DISCONNECT_BANUSER)
  223. -- return
  224. -- end
  225. -- local ip,time = CommonDB.getBanIp(msg.ip)
  226. -- if (time and time > os.time()) then
  227. -- ObjHuman.doDisconnect(human, CommonDefine.DISCONNECT_BANIP)
  228. -- return
  229. -- else
  230. -- CommonDB.delBanIp(msg.ip)
  231. -- end
  232. ObjHuman.onLogin(human, nil)
  233. HumanLogin_Handle(human, params)
  234. end
  235. end
  236. function CG_HEART_BEAT(human, msg)
  237. local msgRet = Msg.gc.GC_HEART_BEAT
  238. msgRet.timeStamp = os.time()
  239. Msg.send(msgRet, human.fd)
  240. end
  241. -- 记录fps
  242. local FPS_TB = {["guaji"]=1, ["zhandou"]=1, ["zhucheng"]=1, ["buzhen"]=1}
  243. function CG_PHONE_FPS(human, msg)
  244. if FPS_TB[msg.fpsType] == nil then return end
  245. human.db.fpsTb = human.db.fpsTb or {}
  246. human.db.fpsTb[msg.fpsType] = { lv = human.db.lv, startFps = msg.startFps, endFps = msg.endFps}
  247. end
  248. function CG_HEART_BEAT_M(human)
  249. end
  250. function CG_ASK_DISCONNECT(human)
  251. ObjHuman.doDisconnect(human, CommonDefine.DISCONNECT_NORMAL)
  252. end
  253. function CG_CLIENT_ERROR(human, msg)
  254. 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)
  255. end
  256. function CG_CLIENT_LOAD_ERROR(human, msg)
  257. 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)
  258. end
  259. IOS_FLAG_CHARGECLOSE = 0 -- 提示关闭
  260. IOS_FLAG_CHARGEOPENTIP = 1 -- 提示开放
  261. IOS_FLAG_CHARGEOPEN = 2 -- 充值开放
  262. function getIosChargeOpenFlag(human)
  263. if PfLogic.isFkwTishen() == true then
  264. if human.isIOS == 1 then
  265. return IOS_FLAG_CHARGECLOSE
  266. end
  267. end
  268. if PfLogic.isKunTangTishen() == true then
  269. return IOS_FLAG_CHARGECLOSE
  270. end
  271. return IOS_FLAG_CHARGEOPEN
  272. end
  273. function canCharge(human)
  274. if getIosChargeOpenFlag(human) == IOS_FLAG_CHARGECLOSE then
  275. return
  276. end
  277. return true
  278. end