get_server_uid.lua 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. --[[
  2. luaide 模板位置位于 Template/FunTemplate/NewFileTemplate.lua 其中 Template 为配置路径 与luaide.luaTemplatesDir
  3. luaide.luaTemplatesDir 配置 https://www.showdoc.cc/web/#/luaide?page_id=713062580213505
  4. author:{zlf}
  5. time:2019-10-21 16:33:17
  6. jira: PK3-987
  7. note: 确定玩家在本服务器是否有角色
  8. ]]
  9. --查询是否建号
  10. local logger = require "logger"
  11. local redisdriver = require "skynet.db.redis"
  12. local stringify = require "stringify"
  13. local skynet = require "skynet"
  14. local queue = require "skynet.queue"
  15. local synchronized = queue()
  16. local trace = logger.trace
  17. --local trace = function(...) end
  18. local redis
  19. local redis_recharge
  20. local start
  21. local rechargeser
  22. local REBATE = "rebate:"
  23. local KEYGEN_PAY = "%s:%s"
  24. local authz = {
  25. lee = "yytx-Games-9527"
  26. }
  27. local function start_pay()
  28. local conf = assert(option.redis)
  29. redis = redisdriver.connect(conf)
  30. redis_recharge = redisdriver.connect(conf)
  31. redis:select(0)--切换到数据库db1
  32. redis_recharge:select(3)--切换到数据库db1
  33. rechargeser = rechargeser or skynet.localname(".recharge")
  34. return 1
  35. end
  36. local facebook = nil -- 云账号登陆废弃
  37. local function retrieve_facebook_account(account, sid, channel)
  38. facebook = facebook or skynet.localname(".facebook")
  39. local errno, fb = skynet.call(facebook, "lua", "retrieve", account, channel)
  40. local uid = nil
  41. if errno == 200 then
  42. uid = redis:get(string.format("account:%s:%s:%s", channel, sid, fb))
  43. end
  44. return errno, uid
  45. end
  46. --192.168.1.44:9001/get_server_uid?uid=9999&&channel=185sy&account=1232123
  47. local get_server_uid = function(args, ipaddr)
  48. return synchronized(function()
  49. start = start or start_pay()
  50. trace("处理来自主机 %s 的uid检测请求", ipaddr)
  51. local channel = args.channel
  52. local account = args.account
  53. local serverid = tonumber(args.serverid)
  54. trace("开始处理uid检测信息:%s",stringify(args))
  55. -- 验证gm账号
  56. local user = args.user or ""
  57. local pwd = args.pwd or ""
  58. if authz[user] ~= pwd then
  59. return { code=2 }
  60. end
  61. if not account or not channel then
  62. return { code=1 }--数据不足
  63. end
  64. local uid
  65. if account then
  66. local k = string.format("account:%s:%s:%s", channel, serverid, account)
  67. uid = redis:get(k)
  68. end
  69. if not uid then -- 云账号登陆废弃
  70. local errno, val = retrieve_facebook_account(account, serverid, channel)
  71. if errno == 200 then
  72. uid = val
  73. end
  74. end
  75. if not uid then
  76. trace("验证玩家建号数据错误:setuid:%s, uid:%s",setuid, uid)
  77. return { code=3 }--未在该服务器创建玩家
  78. end
  79. local name
  80. local level
  81. if uid then
  82. local k = string.format("character:%s", uid)
  83. if redis:hget(k,"sex") then
  84. name = redis:hget(k,"nickname")
  85. level = redis:hget(k,"level")
  86. else
  87. return { code=3 }--未在该服务器创建玩家
  88. end
  89. end
  90. return { code=0,uid=uid,name=name,level=level }
  91. end)
  92. end
  93. return get_server_uid