Commit c779be0c96f406489111203620f1a977aff5ffe8

Authored by zhouhaihai
1 parent da898074

pvp 中心服务

Showing 2 changed files with 128 additions and 1 deletions   Show diff stats
src/nodenames.lua
1 1 center = "127.0.0.1:9000"
2 2  
3   -node_01 = "127.0.0.1:9898"
4 3 \ No newline at end of file
  4 +server1 = "127.0.0.1:8101"
  5 +server2 = "127.0.0.1:8102"
5 6 \ No newline at end of file
... ...
src/services/pvpd.lua 0 → 100644
... ... @@ -0,0 +1,126 @@
  1 +local skynet = require "skynet"
  2 +local json = require("shared.json")
  3 +local redisproxy = require("shared.redisproxy")
  4 +local cluster = require "skynet.cluster"
  5 +
  6 +require "shared.init"
  7 +require "utils.init"
  8 +require "RedisKeys"
  9 +require "skynet.manager"
  10 +globalCsv = require "csvdata/GlobalDefine"
  11 +require "GlobalVar"
  12 +
  13 +
  14 +
  15 +
  16 +
  17 +function rpcRole(roleId, funcName, ...)
  18 + local fields = ...
  19 + local agent = datacenter.get("agent", roleId)
  20 + if agent and agent.serv then
  21 + if funcName == "getProperties" then
  22 + return skynet.call(agent.serv, "role", funcName, fields)
  23 + else
  24 + return skynet.call(agent.serv, "role", funcName, ...)
  25 + end
  26 + else
  27 + local roleCross = require("models.RoleCross")
  28 + if funcName == "getProperties" then
  29 + return roleCross.handle(funcName, roleId, fields)
  30 + else
  31 + return roleCross.handle(funcName, roleId, ...)
  32 + end
  33 + end
  34 +end
  35 +
  36 +local function upLoadTeams()
  37 + local chatd = cluster.query("center", "chatd")
  38 + if not chatd then
  39 + return
  40 + end
  41 + return pcall(cluster.call, "center", chatd, "test", {serverId = 123, hehe = "asd"})
  42 +end
  43 +
  44 +
  45 +
  46 +
  47 +local function update()
  48 + local now = skynet.timex()
  49 + local resetData = csvdb["time_resetCsv"][TimeReset.PvpCross]
  50 +
  51 + local oldRound = tonum(redisproxy:hget("pvp_cross", "round"), -100)
  52 +
  53 + local startTime = START_RESET_TIME + curRound * resetData.interval + resetData.start
  54 + local endTime = startTime + (resetData.duration == 0 and resetData.interval or math.min(resetData.interval, resetData.duration))
  55 + local nextStartTime = startTime + resetData.interval
  56 +
  57 + local updateTime = math.max((nextStartTime - now) / 2, CHECK_PVP_STATUS_INTERVAL)
  58 + -- 已经 上传过阵容了
  59 + if curRound ~= oldRound then
  60 + -- 跨服竞技场已经结束了
  61 + if now >= endTime then
  62 + redisproxy:hset("pvp_cross", "round", curRound)
  63 + else
  64 + -- 上传信息
  65 + local status, back = upLoadTeams()
  66 + if status and back == "success" then --上传成功
  67 + redisproxy:hset("pvp_cross", "round", curRound)
  68 + else
  69 + updateTime = CHECK_PVP_STATUS_INTERVAL
  70 + end
  71 + end
  72 + end
  73 + return updateTime
  74 +end
  75 +
  76 +
  77 +local CMD = {}
  78 +
  79 +function CMD.start()
  80 + -- check_pvp_update()
  81 +end
  82 +
  83 +local function getDBKey()
  84 + local resetData = csvdb["time_resetCsv"][TimeReset.PvpCross]
  85 + local curRound = math.floor((skynet.timex() - START_RESET_TIME - resetData.start) / resetData.interval)
  86 + local idx = 1
  87 + if curRound % 2 == 1 then
  88 + idx = 2
  89 + end
  90 + return RANK_PVP_HIGHT_KEY[idx]
  91 +end
  92 +
  93 +function CMD.loadRoleInfo(roleIds)
  94 + roleIds = roleIds or {}
  95 + local infos = {}
  96 + for _, roleId in ipairs(roleIds) do
  97 + infos[roleId] = rpcRole(roleId, "pvpHInfo")
  98 + end
  99 + return infos
  100 +end
  101 +
  102 +function CMD.loadTeams()
  103 + local dbKey = getDBKey()
  104 + local redret = redisproxy:zrevrange(dbKey, 0, 15)
  105 + local roleIds = {}
  106 + for _, roleId in ipairs(redret) do
  107 + table.insert(roleIds, tonumber(roleId))
  108 + end
  109 +
  110 + local infos = CMD.loadRoleInfo(roleIds)
  111 +
  112 + return {roleIds = roleIds, infos = infos}
  113 +end
  114 +
  115 +local function __init__()
  116 + skynet.dispatch("lua", function(_, _, command, ...)
  117 + local f = CMD[command]
  118 + if f then
  119 + skynet.ret(skynet.pack(f(...)))
  120 + end
  121 + end)
  122 + redisd = skynet.localname(".REDIS")
  123 + skynet.register(".PVPCROSS")
  124 +end
  125 +
  126 +skynet.start(__init__)
... ...