AuthCheck.lua 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. local SdkLogic = require("platform.SdkLogic")
  7. -- 是否需要检验账号
  8. local function isNeedCheck(account)
  9. if Config.IS_USE_GM_CMD == true then
  10. return
  11. end
  12. --[[if PfLogic.isKunTang() or
  13. PfLogic.isShouQ() or
  14. PfLogic.isFKW() or
  15. PfLogic.isQQ() or
  16. PfLogic.isAug() or
  17. PfLogic.is9377() or
  18. PfLogic.isTaptap() or
  19. PfLogic.isYingHe() then
  20. return -- 某些平台,不开校验
  21. end
  22. return true]]
  23. return
  24. end
  25. local function getReallyAccout(account)
  26. if not account then return end
  27. local tb = Util.split(account, "-")
  28. if #tb < 2 then return end
  29. local svrIndex = tonumber(tb[1])
  30. if math.abs(Config.SVR_INDEX - svrIndex) >= 100000 then
  31. return -- 账号服务器应该一致
  32. end
  33. local index = #tb
  34. local realAccount = ""
  35. for i = 2, index do
  36. if i > 2 then
  37. realAccount = realAccount .. "-"
  38. end
  39. realAccount = realAccount .. tb[i]
  40. end
  41. return realAccount
  42. end
  43. function getCalckey(account, timestamp, ip)
  44. return lua_mongo.md5(account .. timestamp .. ip .. Config.AUTH_KEY)
  45. end
  46. -- 这里做账号验证
  47. function authCheck(account, authkey, timestamp, ip,sign)
  48. if isNeedCheck(account) ~= true then
  49. return true
  50. end
  51. local realAccount = getReallyAccout(account)
  52. if not realAccount then
  53. Log.write(Log.LOGID_TEST, "auth check fail no realaccount", account, authkey, timestamp, os.time())
  54. return
  55. end
  56. local sec = os.time() - timestamp
  57. if math.abs(sec) > 86400 then
  58. Log.write(Log.LOGID_TEST, "auth check fail ts err", account, authkey, timestamp, os.time())
  59. return
  60. end
  61. local signStr = lua_mongo.md5("app_id=12&mem_id="..account.."&user_token="..authkey.."app_key=64ba80a7e327f3f334425d8a8d897117")
  62. if signStr ~= sign then
  63. return
  64. end
  65. return true
  66. -- local sdkRet = SdkLogic.CheckUserToken(account,authkey)
  67. -- if sdkRet == true then
  68. -- return true
  69. -- end
  70. -- return false
  71. local calckey = getCalckey(realAccount, timestamp, ip)
  72. if calckey ~= authkey then
  73. Log.write(Log.LOGID_TEST, "auth check fail calckey", account, authkey, timestamp, os.time(), calckey)
  74. return
  75. end
  76. return true
  77. end