Handler.lua 7.9 KB

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