From c779be0c96f406489111203620f1a977aff5ffe8 Mon Sep 17 00:00:00 2001 From: zhouhaihai Date: Fri, 27 Mar 2020 17:14:05 +0800 Subject: [PATCH] pvp 中心服务 --- src/nodenames.lua | 3 ++- src/services/pvpd.lua | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 src/services/pvpd.lua diff --git a/src/nodenames.lua b/src/nodenames.lua index 5eb8678..214c253 100644 --- a/src/nodenames.lua +++ b/src/nodenames.lua @@ -1,3 +1,4 @@ center = "127.0.0.1:9000" -node_01 = "127.0.0.1:9898" \ No newline at end of file +server1 = "127.0.0.1:8101" +server2 = "127.0.0.1:8102" \ No newline at end of file diff --git a/src/services/pvpd.lua b/src/services/pvpd.lua new file mode 100644 index 0000000..90c3a57 --- /dev/null +++ b/src/services/pvpd.lua @@ -0,0 +1,126 @@ +local skynet = require "skynet" +local json = require("shared.json") +local redisproxy = require("shared.redisproxy") +local cluster = require "skynet.cluster" + +require "shared.init" +require "utils.init" +require "RedisKeys" +require "skynet.manager" +globalCsv = require "csvdata/GlobalDefine" +require "GlobalVar" + + + + + +function rpcRole(roleId, funcName, ...) + local fields = ... + local agent = datacenter.get("agent", roleId) + if agent and agent.serv then + if funcName == "getProperties" then + return skynet.call(agent.serv, "role", funcName, fields) + else + return skynet.call(agent.serv, "role", funcName, ...) + end + else + local roleCross = require("models.RoleCross") + if funcName == "getProperties" then + return roleCross.handle(funcName, roleId, fields) + else + return roleCross.handle(funcName, roleId, ...) + end + end +end + +local function upLoadTeams() + local chatd = cluster.query("center", "chatd") + if not chatd then + return + end + return pcall(cluster.call, "center", chatd, "test", {serverId = 123, hehe = "asd"}) +end + + + + +local function update() + local now = skynet.timex() + local resetData = csvdb["time_resetCsv"][TimeReset.PvpCross] + + local oldRound = tonum(redisproxy:hget("pvp_cross", "round"), -100) + + local startTime = START_RESET_TIME + curRound * resetData.interval + resetData.start + local endTime = startTime + (resetData.duration == 0 and resetData.interval or math.min(resetData.interval, resetData.duration)) + local nextStartTime = startTime + resetData.interval + + local updateTime = math.max((nextStartTime - now) / 2, CHECK_PVP_STATUS_INTERVAL) + -- 已经 上传过阵容了 + if curRound ~= oldRound then + -- 跨服竞技场已经结束了 + if now >= endTime then + redisproxy:hset("pvp_cross", "round", curRound) + else + -- 上传信息 + local status, back = upLoadTeams() + if status and back == "success" then --上传成功 + redisproxy:hset("pvp_cross", "round", curRound) + else + updateTime = CHECK_PVP_STATUS_INTERVAL + end + end + end + return updateTime +end + + +local CMD = {} + +function CMD.start() + -- check_pvp_update() +end + +local function getDBKey() + local resetData = csvdb["time_resetCsv"][TimeReset.PvpCross] + local curRound = math.floor((skynet.timex() - START_RESET_TIME - resetData.start) / resetData.interval) + local idx = 1 + if curRound % 2 == 1 then + idx = 2 + end + return RANK_PVP_HIGHT_KEY[idx] +end + +function CMD.loadRoleInfo(roleIds) + roleIds = roleIds or {} + local infos = {} + for _, roleId in ipairs(roleIds) do + infos[roleId] = rpcRole(roleId, "pvpHInfo") + end + return infos +end + +function CMD.loadTeams() + local dbKey = getDBKey() + local redret = redisproxy:zrevrange(dbKey, 0, 15) + local roleIds = {} + for _, roleId in ipairs(redret) do + table.insert(roleIds, tonumber(roleId)) + end + + local infos = CMD.loadRoleInfo(roleIds) + + return {roleIds = roleIds, infos = infos} +end + +local function __init__() + skynet.dispatch("lua", function(_, _, command, ...) + local f = CMD[command] + if f then + skynet.ret(skynet.pack(f(...))) + end + end) + redisd = skynet.localname(".REDIS") + skynet.register(".PVPCROSS") +end + +skynet.start(__init__) -- libgit2 0.21.2