AuthCheck.lua 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. local lua_mongo = _G.lua_mongo
  2. local Config = require("Config")
  3. local Log = require("common.Log")
  4. local Util = require("common.Util")
  5. local PfLogic = require("platform.PfLogic")
  6. -- 是否需要检验账号
  7. local function isNeedCheck(account)
  8. if Config.IS_USE_GM_CMD == true then
  9. return
  10. end
  11. --[[if PfLogic.isKunTang() or
  12. PfLogic.isShouQ() or
  13. PfLogic.isFKW() or
  14. PfLogic.isQQ() or
  15. PfLogic.isAug() or
  16. PfLogic.is9377() or
  17. PfLogic.isTaptap() or
  18. PfLogic.isYingHe() then
  19. return -- 某些平台,不开校验
  20. end
  21. return true]]
  22. return
  23. end
  24. local function getReallyAccout(account)
  25. if not account then return end
  26. local tb = Util.split(account, "-")
  27. if #tb < 2 then return end
  28. local svrIndex = tonumber(tb[1])
  29. if math.abs(Config.SVR_INDEX - svrIndex) >= 100000 then
  30. return -- 账号服务器应该一致
  31. end
  32. local index = #tb
  33. local realAccount = ""
  34. for i = 2, index do
  35. if i > 2 then
  36. realAccount = realAccount .. "-"
  37. end
  38. realAccount = realAccount .. tb[i]
  39. end
  40. return realAccount
  41. end
  42. function getCalckey(account, timestamp, ip)
  43. return lua_mongo.md5(account .. timestamp .. ip .. Config.AUTH_KEY)
  44. end
  45. function authCheck(account, authkey, timestamp, ip)
  46. if isNeedCheck(account) ~= true then
  47. return true
  48. end
  49. local realAccount = getReallyAccout(account)
  50. if not realAccount then
  51. Log.write(Log.LOGID_TEST, "auth check fail no realaccount", account, authkey, timestamp, os.time())
  52. return
  53. end
  54. local sec = os.time() - timestamp
  55. if math.abs(sec) > 86400 then
  56. Log.write(Log.LOGID_TEST, "auth check fail ts err", account, authkey, timestamp, os.time())
  57. return
  58. end
  59. local calckey = getCalckey(realAccount, timestamp, ip)
  60. if calckey ~= authkey then
  61. Log.write(Log.LOGID_TEST, "auth check fail calckey", account, authkey, timestamp, os.time(), calckey)
  62. return
  63. end
  64. return true
  65. end