Handler.lua 7.3 KB

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