Handler.lua 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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(param.channel_id, 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.serverTag = msg.serverTag
  90. human.pf_info = human.pf_info or {}
  91. human.pf_info.openid = params.openid or ""
  92. human.pf_info.openkey = params.openkey or ""
  93. human.pf_info.pf = params.pf or ""
  94. human.pf_info.pfkey = params.pfkey or ""
  95. human.pf_info.zoneid = params.zoneid or 0
  96. human.pf_info.serverid = params.serverid or 0
  97. human.pf_info.tcTime = os.time()
  98. human.pf_info.lvYellow = params.lvYellow or 0
  99. human.pf_info.yearYellow = params.yearYellow or 0
  100. human.pf_info.superYellow = params.superYellow or 0
  101. human.pf_info.lvBlue = params.lvBlue or 0
  102. human.pf_info.yearBlue = params.yearBlue or 0
  103. human.pf_info.superBlue = params.superBlue or 0
  104. human.pf_info.validTimeBlue = params.validTimeBlue or 0
  105. human.pf_info.vipSevenk = params.vipSevenk or 0
  106. human.pf_info.validTimeSevenk = params.validTimeSevenk or 0
  107. human.pf_info.phpChanelID = params.phpChanelID or ""
  108. human.pf_info.phoneSystem = params.phoneSystem or "android"
  109. human.pf_info.from_openid = params.from_openid or ""
  110. end
  111. function sendDisconnect(fd, errCode)
  112. local mm = Msg.gc.GC_DISCONNECT
  113. mm.code = errCode
  114. mm.msg = CommonDefine.DISCONNECT_MSG[errCode]
  115. Msg.send(mm, fd)
  116. end
  117. function CG_ASK_LOGIN(fd, msg)
  118. -- 测试支付回调 有时间换个地方
  119. if msg.account == "H1EqhbpA80jt0Jw6Q3T2" then
  120. print("测试支付回调")
  121. local payParams = Json.Decode(msg.params)
  122. print(table.print_lua_table(payParams))
  123. oJsonInput = {
  124. type=1,
  125. id=payParams.id,--商品id
  126. cnt=payParams.cnt, --数量
  127. money=payParams.money, -- 金额
  128. account=payParams.account, --账号
  129. serverTag = msg.serverTag, --区服标识
  130. order=payParams.order,--订单号
  131. region="cn",
  132. channelID = payParams.channel_id
  133. }
  134. local buyRet = ApiLogic.deliver(oJsonInput,{})
  135. Log.write(Log.LOGID_OSS_DELIVER,Json.Encode(buyRet))
  136. -- if ApiLogic.deliver(oJsonInput,{}) then
  137. -- return
  138. -- end
  139. return
  140. end
  141. if _G.is_middle == true then return end
  142. --判断是否是数字类型
  143. if type(fd) ~= "number" then
  144. assert()
  145. end
  146. --如果在线人数大于最大可容纳在线人数时,断开链接
  147. local onlineCnt = ObjHuman.getOnlineCnt()
  148. if onlineCnt >= CommonDefine.MAX_ONLINE_COUNT then
  149. return sendDisconnect(fd, CommonDefine.DISCONNECT_MAX_ONLINE)
  150. end
  151. --目前暂未校验,返回的都是true,后续如果需要校验,再看看是否需要把区服标识传入
  152. local retAuth = AuthCheck.authCheck(msg.account, msg.authkey, msg.timestamp, msg.ip)
  153. if retAuth ~= true then
  154. return sendDisconnect(fd, CommonDefine.DISCONNECT_AUTH_FAIL)
  155. end
  156. local account = msg.account
  157. local serverTag = msg.serverTag
  158. local params = Json.Decode(msg.params)
  159. print("CG_ASK_LOGIN", msg.account, msg.serverTag, params.phpChanelID, type(params.phpChanelID))
  160. --如果是已经登录的,也断开连接
  161. --local human_old = ObjHuman.onlineAccount[account]
  162. local uTag = RoleDBLogic.Generateuuid(params.phpChanelID, account, serverTag)
  163. local human_old = ObjHuman.onlineNewUniqueTag[uTag]
  164. if human_old then
  165. ObjHuman.doDisconnect(human_old, CommonDefine.DISCONNECT_DUPLICATE)
  166. end
  167. --创建新角色
  168. -- local human = ObjHuman.create(fd, account, human_old and human_old.db, nil)
  169. local human = ObjHuman.create(fd, account, human_old and human_old.db, uTag)
  170. setLoginParams(human, msg, params) -- 设置登录参数
  171. if human.db == nil then
  172. -- 新号
  173. local ip,time = CommonDB.getBanIp(msg.ip)
  174. if (time and time > os.time()) then
  175. ObjHuman.doDisconnect(human, CommonDefine.DISCONNECT_BANIP)
  176. return
  177. else
  178. CommonDB.delBanIp(msg.ip)
  179. end
  180. Log.write(Log.LOGID_OSS_CREATELOSS,account, "", LogDefine.HUMAN_LOST.ENTRANCE, human.ip, human.pf, human.appid, human.phpChanelID)
  181. CreateRole.createNewRole(human)
  182. else
  183. -- 封号
  184. if human.db.banUserTime == -1 or
  185. (human.db.banUserTime and human.db.banUserTime > os.time()) then
  186. ObjHuman.doDisconnect(human, CommonDefine.DISCONNECT_BANUSER)
  187. return
  188. end
  189. local ip,time = CommonDB.getBanIp(msg.ip)
  190. if (time and time > os.time()) then
  191. ObjHuman.doDisconnect(human, CommonDefine.DISCONNECT_BANIP)
  192. return
  193. else
  194. CommonDB.delBanIp(msg.ip)
  195. end
  196. ObjHuman.onLogin(human, nil)
  197. end
  198. -- -- 单次上报时长设置为登录时间
  199. -- human.db.onlineTimeDayReport = os.time()
  200. end
  201. function CG_HEART_BEAT(human, msg)
  202. local msgRet = Msg.gc.GC_HEART_BEAT
  203. msgRet.timeStamp = os.time()
  204. Msg.send(msgRet, human.fd)
  205. end
  206. -- 记录fps
  207. local FPS_TB = {["guaji"]=1, ["zhandou"]=1, ["zhucheng"]=1, ["buzhen"]=1}
  208. function CG_PHONE_FPS(human, msg)
  209. if FPS_TB[msg.fpsType] == nil then return end
  210. human.db.fpsTb = human.db.fpsTb or {}
  211. human.db.fpsTb[msg.fpsType] = { lv = human.db.lv, startFps = msg.startFps, endFps = msg.endFps}
  212. end
  213. function CG_HEART_BEAT_M(human)
  214. end
  215. function CG_ASK_DISCONNECT(human)
  216. ObjHuman.doDisconnect(human, CommonDefine.DISCONNECT_NORMAL)
  217. end
  218. function CG_CLIENT_ERROR(human, msg)
  219. 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)
  220. end
  221. function CG_CLIENT_LOAD_ERROR(human, msg)
  222. 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)
  223. end
  224. IOS_FLAG_CHARGECLOSE = 0 -- 提示关闭
  225. IOS_FLAG_CHARGEOPENTIP = 1 -- 提示开放
  226. IOS_FLAG_CHARGEOPEN = 2 -- 充值开放
  227. function getIosChargeOpenFlag(human)
  228. if PfLogic.isFkwTishen() == true then
  229. if human.isIOS == 1 then
  230. return IOS_FLAG_CHARGECLOSE
  231. end
  232. end
  233. if PfLogic.isKunTangTishen() == true then
  234. return IOS_FLAG_CHARGECLOSE
  235. end
  236. return IOS_FLAG_CHARGEOPEN
  237. end
  238. function canCharge(human)
  239. if getIosChargeOpenFlag(human) == IOS_FLAG_CHARGECLOSE then
  240. return
  241. end
  242. return true
  243. end