Handler.lua 9.1 KB

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