Handler.lua 10 KB

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