Handler.lua 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. CDKLoigc.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. print(table.print_lua_table(payParams))
  90. oJsonInput = {
  91. type=1,
  92. id=payParams.id,--商品id
  93. cnt=payParams.cnt, --数量
  94. money=payParams.money, -- 金额
  95. account=payParams.account, --账号
  96. order=payParams.order,--订单号
  97. region="cn",
  98. }
  99. local buyRet = ApiLogic.deliver(oJsonInput,{})
  100. Log.write(Log.LOGID_OSS_DELIVER,Json.Encode(buyRet))
  101. -- if ApiLogic.deliver(oJsonInput,{}) then
  102. -- return
  103. -- end
  104. return
  105. end
  106. if _G.is_middle == true then return end
  107. --判断是否是数字类型
  108. if type(fd) ~= "number" then
  109. assert()
  110. end
  111. print("CG_ASK_LOGIN", msg.account)
  112. --如果在线人数大于最大可容纳在线人数时,断开链接
  113. local onlineCnt = ObjHuman.getOnlineCnt()
  114. if onlineCnt >= CommonDefine.MAX_ONLINE_COUNT then
  115. return sendDisconnect(fd, CommonDefine.DISCONNECT_MAX_ONLINE)
  116. end
  117. local retAuth = AuthCheck.authCheck(msg.account, msg.authkey, msg.timestamp, msg.ip)
  118. if retAuth ~= true then
  119. return sendDisconnect(fd, CommonDefine.DISCONNECT_AUTH_FAIL)
  120. end
  121. local account = msg.account
  122. local params = Json.Decode(msg.params)
  123. --如果是已经登录的,也断开连接
  124. local human_old = ObjHuman.onlineAccount[account]
  125. if human_old then
  126. ObjHuman.doDisconnect(human_old, CommonDefine.DISCONNECT_DUPLICATE)
  127. end
  128. --创建新角色
  129. local human = ObjHuman.create(fd, account, human_old and human_old.db, nil)
  130. setLoginParams(human, msg, params) -- 设置登录参数
  131. if human.db == nil then
  132. -- 新号
  133. local ip,time = CommonDB.getBanIp(msg.ip)
  134. if (time and time > os.time()) then
  135. ObjHuman.doDisconnect(human, CommonDefine.DISCONNECT_BANIP)
  136. return
  137. else
  138. CommonDB.delBanIp(msg.ip)
  139. end
  140. Log.write(Log.LOGID_OSS_CREATELOSS,account, "", LogDefine.HUMAN_LOST.ENTRANCE, human.ip, human.pf, human.appid, human.phpChanelID)
  141. CreateRole.createNewRole(human)
  142. else
  143. -- 封号
  144. if human.db.banUserTime == -1 or
  145. (human.db.banUserTime and human.db.banUserTime > os.time()) then
  146. ObjHuman.doDisconnect(human, CommonDefine.DISCONNECT_BANUSER)
  147. return
  148. end
  149. local ip,time = CommonDB.getBanIp(msg.ip)
  150. if (time and time > os.time()) then
  151. ObjHuman.doDisconnect(human, CommonDefine.DISCONNECT_BANIP)
  152. return
  153. else
  154. CommonDB.delBanIp(msg.ip)
  155. end
  156. ObjHuman.onLogin(human, nil)
  157. end
  158. end
  159. function CG_HEART_BEAT(human, msg)
  160. local msgRet = Msg.gc.GC_HEART_BEAT
  161. msgRet.timeStamp = os.time()
  162. Msg.send(msgRet, human.fd)
  163. end
  164. -- 记录fps
  165. local FPS_TB = {["guaji"]=1, ["zhandou"]=1, ["zhucheng"]=1, ["buzhen"]=1}
  166. function CG_PHONE_FPS(human, msg)
  167. if FPS_TB[msg.fpsType] == nil then return end
  168. human.db.fpsTb = human.db.fpsTb or {}
  169. human.db.fpsTb[msg.fpsType] = { lv = human.db.lv, startFps = msg.startFps, endFps = msg.endFps}
  170. end
  171. function CG_HEART_BEAT_M(human)
  172. end
  173. function CG_ASK_DISCONNECT(human)
  174. ObjHuman.doDisconnect(human, CommonDefine.DISCONNECT_NORMAL)
  175. end
  176. function CG_CLIENT_ERROR(human, msg)
  177. 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)
  178. end
  179. function CG_CLIENT_LOAD_ERROR(human, msg)
  180. 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)
  181. end
  182. IOS_FLAG_CHARGECLOSE = 0 -- 提示关闭
  183. IOS_FLAG_CHARGEOPENTIP = 1 -- 提示开放
  184. IOS_FLAG_CHARGEOPEN = 2 -- 充值开放
  185. function getIosChargeOpenFlag(human)
  186. if PfLogic.isFkwTishen() == true then
  187. if human.isIOS == 1 then
  188. return IOS_FLAG_CHARGECLOSE
  189. end
  190. end
  191. if PfLogic.isKunTangTishen() == true then
  192. return IOS_FLAG_CHARGECLOSE
  193. end
  194. return IOS_FLAG_CHARGEOPEN
  195. end
  196. function canCharge(human)
  197. if getIosChargeOpenFlag(human) == IOS_FLAG_CHARGECLOSE then
  198. return
  199. end
  200. return true
  201. end