Handler.lua 6.0 KB

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