123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- -- 遗迹战令
- local skynet = require "skynet"
- require "skynet.manager"
- local logger = require "logger"
- local skynet_retpack = skynet.retpack
- local asset = require "model.asset"
- local redisdriver = require "skynet.db.redis"
- local util = require "util"
- local common_fun = require "model.common_fun"
- local redis
- local cjson = require "cjson"
- local cjson_decode = cjson.decode -- 解码
- local cjson_encode = cjson.encode -- 编码
- local INIT_FLAG = false
- local data_list = {
- -- round = 1, -- 版本
- -- start_time = 0, -- 开始时间
- -- end_time = 0, -- 结束时间
- }
- local CMD = {}
- local function save_data()
- local temp = {}
- temp.round = data_list.round
- temp.start_time = common_fun.time_str(data_list.start_time)
- redis:hset(OTHER_REDIS_KEY, "relic_manual", cjson_encode(temp))
- end
- local function init_data()
- local activitytime = skynet.localname(".activitytime")
- local open_time = util.today(skynet.call(activitytime, "lua", "query"))
- local data_conf = asset.DataConfig_proto[22]
- local today = util.today()
- if open_time > today then
- return
- end
- local round_time = DAY_SEC*data_conf.data2
- local round = math.floor((today - open_time)/(round_time))+1
- local start_time = open_time + (round-1)*round_time
- local end_time = start_time + round_time
- data_list.round = round
- data_list.start_time = start_time
- data_list.end_time = end_time
- save_data()
- INIT_FLAG = true
- end
- local function check_data()
- local now = os.time()
- -- 提前2s,与玩家时间做差异处理
- if now > data_list.end_time-2 then
- local data_conf = asset.DataConfig_proto[22]
- local round_time = DAY_SEC*data_conf.data2
- data_list.round = data_list.round + 1
- data_list.start_time = data_list.end_time
- data_list.end_time = data_list.start_time + round_time
- save_data()
- end
- end
- local function optimize()
- local res = redis:hget(OTHER_REDIS_KEY, "relic_manual")
- if res then
- local temp = cjson_decode(res)
- if not temp then
- return
- end
- data_list.round = temp.round
- data_list.start_time = common_fun.split(temp.start_time)
- local data_conf = asset.DataConfig_proto[22]
- local round_time = DAY_SEC*data_conf.data2
- data_list.end_time = data_list.start_time + round_time
- if data_list.round and data_list.start_time then
- INIT_FLAG = true
- end
- end
- end
- local function watchtime()
- skynet.fork(function()
- while true do
- if not INIT_FLAG then
- init_data()
- else
- check_data()
- end
- skynet.sleep(50)
- end
- end)
- end
- function CMD.start()
- local conf = assert(option.redis)
- redis = redisdriver.connect(conf)
- redis:select(15)
- optimize()
- watchtime()
- end
- function CMD.relic_manual_data()
- if not INIT_FLAG then
- return
- else
- return {
- round = data_list.round,
- start_time = data_list.start_time + 12*3600 -- //防止冬夏令时的问题
- }
- end
- end
- skynet.init(function()
- skynet.register(".relic_manual")
- end)
-
- skynet.start(function()
- logger.label("<Relic_manual>,")
- skynet.dispatch("lua", function(session,_, cmd, ...)
- local f = assert(CMD[cmd])
- if session == 0 then
- f(...)
- else
- skynet_retpack(f(...))
- end
- end)
- end)
|