Handler.lua 9.8 KB

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