Handler.lua 7.8 KB

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