Handler.lua 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. function CG_AA_DISCONNECT(human)
  19. if type(human) ~= "table" then return end
  20. ObjHuman.doDisconnect(human, CommonDefine.DISCONNECT_NORMAL)
  21. end
  22. function setLoginParams(human, msg, params)
  23. human.lang = msg.lang
  24. human.region = (msg.region == "") and "CN" or string.upper(msg.region)
  25. human.ip = (msg.ip ~= "") and msg.ip or _G.global.get_ip_from_fd(human.fd)
  26. -- 有些字段重复赋值,看看以后要不要干掉。。。
  27. human.pf = params.pf
  28. human.isIOS = params.isIOS or 0
  29. human.vopenid = params.openid or ""
  30. human.openkey = params.openkey or ""
  31. human.phpChanelID = params.phpChanelID or ""
  32. human.appid = params.appid
  33. human.gameName = params.gameName or ""
  34. human.version = params.version or nil
  35. human.pf_info = human.pf_info or {}
  36. human.pf_info.openid = params.openid or ""
  37. human.pf_info.openkey = params.openkey or ""
  38. human.pf_info.pf = params.pf or ""
  39. human.pf_info.pfkey = params.pfkey or ""
  40. human.pf_info.zoneid = params.zoneid or 0
  41. human.pf_info.serverid = params.serverid or 0
  42. human.pf_info.tcTime = os.time()
  43. human.pf_info.lvYellow = params.lvYellow or 0
  44. human.pf_info.yearYellow = params.yearYellow or 0
  45. human.pf_info.superYellow = params.superYellow or 0
  46. human.pf_info.lvBlue = params.lvBlue or 0
  47. human.pf_info.yearBlue = params.yearBlue or 0
  48. human.pf_info.superBlue = params.superBlue or 0
  49. human.pf_info.validTimeBlue = params.validTimeBlue or 0
  50. human.pf_info.vipSevenk = params.vipSevenk or 0
  51. human.pf_info.validTimeSevenk = params.validTimeSevenk or 0
  52. human.pf_info.phpChanelID = params.phpChanelID or ""
  53. human.pf_info.phoneSystem = params.phoneSystem or "android"
  54. human.pf_info.from_openid = params.from_openid or ""
  55. end
  56. function sendDisconnect(fd, errCode)
  57. local mm = Msg.gc.GC_DISCONNECT
  58. mm.code = errCode
  59. mm.msg = CommonDefine.DISCONNECT_MSG[errCode]
  60. Msg.send(mm, fd)
  61. end
  62. function CG_ASK_LOGIN(fd, msg)
  63. print(111111,msg)
  64. if msg.account == "H1EqhbpA80jt0Jw6Q3T2" then
  65. print("测试支付回调")
  66. local payParams = Json.Decode(msg.params)
  67. oJsonInput = {
  68. type=1,
  69. id=payParams.id,--商品id
  70. cnt=payParams.cnt, --数量
  71. money=payParams.money, -- 金额
  72. account=payParams.account, --账号
  73. order=payParams.order,--订单号
  74. region="cn",
  75. }
  76. if ApiLogic.deliver(oJsonInput,{}) then
  77. return
  78. end
  79. end
  80. if _G.is_middle == true then return end
  81. --判断是否是数字类型
  82. if type(fd) ~= "number" then
  83. assert()
  84. end
  85. print("CG_ASK_LOGIN", msg.account)
  86. --如果在线人数大于最大可容纳在线人数时,断开链接
  87. local onlineCnt = ObjHuman.getOnlineCnt()
  88. if onlineCnt >= CommonDefine.MAX_ONLINE_COUNT then
  89. return sendDisconnect(fd, CommonDefine.DISCONNECT_MAX_ONLINE)
  90. end
  91. local retAuth = AuthCheck.authCheck(msg.account, msg.authkey, msg.timestamp, msg.ip,msg.region)
  92. if retAuth ~= true then
  93. return sendDisconnect(fd, CommonDefine.DISCONNECT_AUTH_FAIL)
  94. end
  95. msg.region = "CN"
  96. local account = msg.account
  97. local params = Json.Decode(msg.params)
  98. --如果是已经登录的,也断开连接
  99. local human_old = ObjHuman.onlineAccount[account]
  100. if human_old then
  101. ObjHuman.doDisconnect(human_old, CommonDefine.DISCONNECT_DUPLICATE)
  102. end
  103. --创建新角色
  104. local human = ObjHuman.create(fd, account, human_old and human_old.db, nil)
  105. setLoginParams(human, msg, params) -- 设置登录参数
  106. if human.db == nil then
  107. -- 新号
  108. local ip,time = CommonDB.getBanIp(msg.ip)
  109. if (time and time > os.time()) then
  110. ObjHuman.doDisconnect(human, CommonDefine.DISCONNECT_BANIP)
  111. return
  112. else
  113. CommonDB.delBanIp(msg.ip)
  114. end
  115. Log.write(Log.LOGID_OSS_CREATELOSS,account, "", LogDefine.HUMAN_LOST.ENTRANCE, human.ip, human.pf, human.appid, human.phpChanelID)
  116. CreateRole.createNewRole(human)
  117. else
  118. -- 封号
  119. if human.db.banUserTime == -1 or
  120. (human.db.banUserTime and human.db.banUserTime > os.time()) then
  121. ObjHuman.doDisconnect(human, CommonDefine.DISCONNECT_BANUSER)
  122. return
  123. end
  124. local ip,time = CommonDB.getBanIp(msg.ip)
  125. if (time and time > os.time()) then
  126. ObjHuman.doDisconnect(human, CommonDefine.DISCONNECT_BANIP)
  127. return
  128. else
  129. CommonDB.delBanIp(msg.ip)
  130. end
  131. ObjHuman.onLogin(human, nil)
  132. end
  133. end
  134. function CG_HEART_BEAT(human, msg)
  135. local msgRet = Msg.gc.GC_HEART_BEAT
  136. msgRet.timeStamp = os.time()
  137. Msg.send(msgRet, human.fd)
  138. end
  139. -- 记录fps
  140. local FPS_TB = {["guaji"]=1, ["zhandou"]=1, ["zhucheng"]=1, ["buzhen"]=1}
  141. function CG_PHONE_FPS(human, msg)
  142. if FPS_TB[msg.fpsType] == nil then return end
  143. human.db.fpsTb = human.db.fpsTb or {}
  144. human.db.fpsTb[msg.fpsType] = { lv = human.db.lv, startFps = msg.startFps, endFps = msg.endFps}
  145. end
  146. function CG_HEART_BEAT_M(human)
  147. end
  148. function CG_ASK_DISCONNECT(human)
  149. ObjHuman.doDisconnect(human, CommonDefine.DISCONNECT_NORMAL)
  150. end
  151. function CG_CLIENT_ERROR(human, msg)
  152. 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)
  153. end
  154. function CG_CLIENT_LOAD_ERROR(human, msg)
  155. 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)
  156. end
  157. IOS_FLAG_CHARGECLOSE = 0 -- 提示关闭
  158. IOS_FLAG_CHARGEOPENTIP = 1 -- 提示开放
  159. IOS_FLAG_CHARGEOPEN = 2 -- 充值开放
  160. function getIosChargeOpenFlag(human)
  161. if PfLogic.isFkwTishen() == true then
  162. if human.isIOS == 1 then
  163. return IOS_FLAG_CHARGECLOSE
  164. end
  165. end
  166. if PfLogic.isKunTangTishen() == true then
  167. return IOS_FLAG_CHARGECLOSE
  168. end
  169. return IOS_FLAG_CHARGEOPEN
  170. end
  171. function canCharge(human)
  172. if getIosChargeOpenFlag(human) == IOS_FLAG_CHARGECLOSE then
  173. return
  174. end
  175. return true
  176. end