Handler.lua 8.2 KB

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