Commit 6a009043c8e6527f0e340b457dc5b71e9a3fac01

Authored by zhouhaihai
2 parents 445aae2c 3f604f2e

Merge branch 'develop' into tr/ob

* develop:
  扩容 redis 和 log服务
  监听再前
  增加池子
  拆分网关
  清除引导功能顺便也清除关卡解锁触发的强制引导
1 root = "./" 1 root = "./"
2 -thread = 8 2 +thread = 4
3 logger = nil 3 logger = nil
4 harbor = 0 4 harbor = 0
5 -start = "start" -- main script 5 +start = "robot_main" -- main script
6 bootstrap = "snlua bootstrap" -- The service for bootstrap 6 bootstrap = "snlua bootstrap" -- The service for bootstrap
7 7
8 lua_path = root .."skynet/lualib/?.lua;"..root.."robot/?.lua;"..root.."src/?.lua" 8 lua_path = root .."skynet/lualib/?.lua;"..root.."robot/?.lua;"..root.."src/?.lua"
@@ -16,6 +16,7 @@ local eventListener = {} @@ -16,6 +16,7 @@ local eventListener = {}
16 16
17 local ignoreListener = { 17 local ignoreListener = {
18 ["Role.updateProperty"] = function(data) 18 ["Role.updateProperty"] = function(data)
  19 + if not client.role then return end
19 local msg = MsgPack.unpack(data) 20 local msg = MsgPack.unpack(data)
20 for _, one in pairs(msg) do 21 for _, one in pairs(msg) do
21 client.role[one.key] = one.newValue 22 client.role[one.key] = one.newValue
@@ -80,7 +81,7 @@ function triggerListener(listener, data) @@ -80,7 +81,7 @@ function triggerListener(listener, data)
80 ignoreListener[listener](data) 81 ignoreListener[listener](data)
81 end 82 end
82 else 83 else
83 - log(listener .. " no handle!!!") 84 + -- log(listener .. " no handle!!!")
84 end 85 end
85 end 86 end
86 87
@@ -103,8 +104,8 @@ function sendServer(actionCode, bin) @@ -103,8 +104,8 @@ function sendServer(actionCode, bin)
103 end 104 end
104 105
105 function requestServer(actionCode, bin, callback, isKeep) 106 function requestServer(actionCode, bin, callback, isKeep)
106 - sendServer(actionCode, bin)  
107 addListener(actionCode, callback, isKeep) 107 addListener(actionCode, callback, isKeep)
  108 + sendServer(actionCode, bin)
108 end 109 end
109 110
110 local function heartBeat() 111 local function heartBeat()
robot/robot_main.lua 0 → 100644
@@ -0,0 +1,21 @@ @@ -0,0 +1,21 @@
  1 +local skynet = require "skynet"
  2 +local config = require "robot_config"
  3 +
  4 +local preOnlineCount = 10
  5 +
  6 +
  7 +skynet.start(function()
  8 + local need = math.ceil(config.online / preOnlineCount)
  9 + local inpre = math.ceil(config.inpre / need)
  10 + local idRange = math.ceil(config.max / need)
  11 + local curId = 1
  12 + local poold = skynet.newservice("robot_pool")
  13 + local pooldObj = skynet.call(poold, "lua", "start", config.online + preOnlineCount)
  14 +
  15 + for i = 1, need do
  16 + local start = skynet.newservice("start")
  17 + skynet.send(start, "lua", "start", poold, pooldObj, preOnlineCount, curId, curId + idRange - 1, inpre)
  18 + curId = curId + idRange
  19 + end
  20 + skynet.exit()
  21 +end)
0 \ No newline at end of file 22 \ No newline at end of file
robot/robot_pool.lua 0 → 100644
@@ -0,0 +1,46 @@ @@ -0,0 +1,46 @@
  1 +--[[
  2 + deque 为了减少锁竞争,尽量保证 a服务 push;b服务 pop
  3 +]]
  4 +local skynet = require "skynet"
  5 +local deque = require "deque"
  6 +
  7 +local CMD = {}
  8 +local factory
  9 +
  10 +local PRE_FEED_COUNT = 5
  11 +local dead = 0
  12 +-- agent死亡,通知poold补充,当累计到5个agent时,马上生成5个agent放入poold中
  13 +-- 当然这里也可以写得更复杂,参考redis落地规则
  14 +function CMD.feed()
  15 + dead = dead + 1
  16 + if dead == PRE_FEED_COUNT then
  17 + dead = 0
  18 + for i=1, PRE_FEED_COUNT do
  19 + factory:push(skynet.newservice("robot"))
  20 + end
  21 + end
  22 +end
  23 +
  24 +-- 系统启动,生成count个agent放入双端队列中
  25 +function CMD.start(count)
  26 + factory, addr = deque.new(count)
  27 +
  28 + for i = 1, count do
  29 + factory:push(skynet.newservice("robot"))
  30 + end
  31 +
  32 + return addr
  33 +end
  34 +
  35 +local function __init__()
  36 + skynet.dispatch("lua", function (_, _, command, ...)
  37 + local f = CMD[command]
  38 + if command == "start" then
  39 + skynet.ret(skynet.pack(f(...)))
  40 + return
  41 + end
  42 + f(...)
  43 + end)
  44 +end
  45 +
  46 +skynet.start(__init__)
@@ -5,13 +5,17 @@ local config = require "robot_config" @@ -5,13 +5,17 @@ local config = require "robot_config"
5 local skynet = require "skynet" 5 local skynet = require "skynet"
6 local netpack = require "skynet.netpack" 6 local netpack = require "skynet.netpack"
7 local socketdriver = require "skynet.socketdriver" 7 local socketdriver = require "skynet.socketdriver"
  8 +local deque = require "deque"
8 local string_format = string.format 9 local string_format = string.format
9 10
  11 +local poold, pooldObj, onlineCount, startId, endId, inpre
  12 +local factory
  13 +
10 local queue = {} 14 local queue = {}
11 local fd2serv = {} 15 local fd2serv = {}
12 local id2fd = {} 16 local id2fd = {}
13 local MSG = {} 17 local MSG = {}
14 -local id_max = 0 -- robot id 18 +local id_max
15 19
16 20
17 function MSG.open( ... ) 21 function MSG.open( ... )
@@ -21,9 +25,11 @@ end @@ -21,9 +25,11 @@ end
21 function MSG.close(fd) 25 function MSG.close(fd)
22 if fd2serv[fd] and not fd2serv[fd].closing then 26 if fd2serv[fd] and not fd2serv[fd].closing then
23 fd2serv[fd].closing = true 27 fd2serv[fd].closing = true
  28 + print(fd2serv[fd].agent)
24 skynet.call(fd2serv[fd].agent, "lua", "exit") 29 skynet.call(fd2serv[fd].agent, "lua", "exit")
25 - log(string_format("logout %s", fd2serv[fd].id)) 30 + pcall(skynet.send, poold, "lua", "feed")
26 31
  32 + log(string_format("logout %s", fd2serv[fd].id))
27 id2fd[fd2serv[fd].id] = nil 33 id2fd[fd2serv[fd].id] = nil
28 fd2serv[fd] = nil 34 fd2serv[fd] = nil
29 end 35 end
@@ -72,13 +78,14 @@ skynet.register_protocol { @@ -72,13 +78,14 @@ skynet.register_protocol {
72 } 78 }
73 79
74 local function add_robot() 80 local function add_robot()
75 - local robot = skynet.newservice("robot") 81 + local time = skynet.time()
  82 + local robot = factory:pop()
76 local fd = socketdriver.connect(config.host, config.port) 83 local fd = socketdriver.connect(config.host, config.port)
77 socketdriver.start(fd) 84 socketdriver.start(fd)
78 local id 85 local id
79 - if id_max >= config.max then 86 + if id_max >= endId then
80 while true do 87 while true do
81 - id = math.randomInt(1, config.max) 88 + id = math.randomInt(startId, endId)
82 if not id2fd[id] then 89 if not id2fd[id] then
83 break 90 break
84 end 91 end
@@ -89,9 +96,8 @@ local function add_robot() @@ -89,9 +96,8 @@ local function add_robot()
89 end 96 end
90 fd2serv[fd] = {agent = robot, id = id} 97 fd2serv[fd] = {agent = robot, id = id}
91 id2fd[id] = fd 98 id2fd[id] = fd
92 - pcall(skynet.call, robot, "lua", "start", fd, id) 99 + pcall(skynet.call, robot, "lua", "start", fd, id, prefix)
93 log(string_format("login %s", fd2serv[fd].id)) 100 log(string_format("login %s", fd2serv[fd].id))
94 -  
95 -- 定时下线 101 -- 定时下线
96 skynet.timeout(math.randomInt(config.online_time[1], config.online_time[2]) * 100, function() 102 skynet.timeout(math.randomInt(config.online_time[1], config.online_time[2]) * 100, function()
97 MSG.close(fd) 103 MSG.close(fd)
@@ -106,8 +112,8 @@ local function online() @@ -106,8 +112,8 @@ local function online()
106 end 112 end
107 113
108 -- 及时补充人数 114 -- 及时补充人数
109 - if curCount < config.online then  
110 - for i = curCount + 1, config.online do 115 + if curCount < onlineCount then
  116 + for i = curCount + 1, onlineCount do
111 add_robot() 117 add_robot()
112 end 118 end
113 end 119 end
@@ -116,11 +122,15 @@ local function online() @@ -116,11 +122,15 @@ local function online()
116 skynet.timeout(100, online) 122 skynet.timeout(100, online)
117 end 123 end
118 124
119 -local function start() 125 +local function start(pooldp, pooldObj, onlineCountp, startIdp, endIdp, inprep)
120 log("start testing ...") 126 log("start testing ...")
121 127
122 - for i = 1, config.online, config.inpre do  
123 - for j = 1, config.inpre do 128 + factory = deque.clone(pooldObj)
  129 + poold, onlineCount, startId, endId, inpre = pooldp, onlineCountp, startIdp, endIdp, inprep
  130 + id_max = startId - 1
  131 +
  132 + for i = 1, onlineCount, inpre do
  133 + for j = 1, inpre do
124 add_robot() 134 add_robot()
125 end 135 end
126 skynet.sleep(100) 136 skynet.sleep(100)
@@ -131,5 +141,10 @@ local function start() @@ -131,5 +141,10 @@ local function start()
131 end 141 end
132 142
133 skynet.start(function() 143 skynet.start(function()
134 - skynet.fork(start) 144 + skynet.dispatch("lua", function (_, _, command, ...)
  145 + if command == "start" then
  146 + start(...)
  147 + return
  148 + end
  149 + end)
135 end) 150 end)
136 \ No newline at end of file 151 \ No newline at end of file
robot/unitTest/item.lua
@@ -14,7 +14,7 @@ end @@ -14,7 +14,7 @@ end
14 local taskMap = { 14 local taskMap = {
15 saleItem = {100}, 15 saleItem = {100},
16 openItem = {100}, 16 openItem = {100},
17 - openTimeBox = {100}, 17 + -- openTimeBox = {100},
18 } 18 }
19 19
20 function _M:task() 20 function _M:task()
src/actions/GmAction.lua
@@ -502,6 +502,11 @@ function _M.guide(role, pms) @@ -502,6 +502,11 @@ function _M.guide(role, pms)
502 end 502 end
503 end 503 end
504 end 504 end
  505 + for _, data in pairs(csvdb["guide_unlockCsv"]) do
  506 + if data.type == 0 or data.type == 3 then
  507 + str = str:setv(data.id,1)
  508 + end
  509 + end
505 role:updateProperty({field = "funcGuide", value = str}) 510 role:updateProperty({field = "funcGuide", value = str})
506 role:mylog("gm_action", {desc = "sguide", key1 = pms.sender}) 511 role:mylog("gm_action", {desc = "sguide", key1 = pms.sender})
507 512
@@ -356,11 +356,6 @@ skynet.start(function() @@ -356,11 +356,6 @@ skynet.start(function()
356 return info 356 return info
357 end) 357 end)
358 358
359 - redisd = skynet.localname(".redis")  
360 - if tonumber(skynet.getenv "logd") == 1 then  
361 - logd = skynet.localname(".log")  
362 - end  
363 -  
364 cs = queue() 359 cs = queue()
365 360
366 pvpd = skynet.localname(".pvpcross") 361 pvpd = skynet.localname(".pvpcross")
@@ -2,23 +2,41 @@ local skynet = require &quot;skynet&quot; @@ -2,23 +2,41 @@ local skynet = require &quot;skynet&quot;
2 2
3 local max_client = tonumber(skynet.getenv("max_client")) 3 local max_client = tonumber(skynet.getenv("max_client"))
4 local max_queue = tonumber(skynet.getenv("max_queue")) 4 local max_queue = tonumber(skynet.getenv("max_queue"))
  5 +local work_count = tonumber(skynet.getenv("thread"))
  6 +local use_logd = tonumber(skynet.getenv("logd"))
5 7
6 skynet.start(function() 8 skynet.start(function()
7 print("Server start") 9 print("Server start")
8 skynet.newservice("debug_console", tonumber(skynet.getenv("debug_port"))) 10 skynet.newservice("debug_console", tonumber(skynet.getenv("debug_port")))
9 11
  12 +
  13 + -- 启动redis
  14 + for i = 1, work_count do
  15 + local redisd = skynet.newservice("services/redisd", i)
  16 + skynet.call(redisd, "lua", "open", {
  17 + redishost = skynet.getenv("redis_host"),
  18 + redisport = tonumber(skynet.getenv("redis_port")),
  19 + redisdb = tonumber(skynet.getenv("redis_db")),
  20 + auth = skynet.getenv("redis_auth")
  21 + })
  22 + end
  23 +
  24 + --启动log
  25 + if use_logd == 1 then
  26 + for i = 1, work_count do
  27 + local logd = skynet.newservice("services/logd", i)
  28 + skynet.call(logd, "lua", "open")
  29 + end
  30 + end
  31 +
10 local httpd = skynet.newservice("services/httpweb", tonumber(skynet.getenv("httpweb_port"))) 32 local httpd = skynet.newservice("services/httpweb", tonumber(skynet.getenv("httpweb_port")))
11 local watchdog = skynet.newservice("services/watchdog", max_client) 33 local watchdog = skynet.newservice("services/watchdog", max_client)
12 34
  35 +
13 skynet.call(watchdog, "lua", "start", { 36 skynet.call(watchdog, "lua", "start", {
14 port = tonumber(skynet.getenv("server_port")), 37 port = tonumber(skynet.getenv("server_port")),
15 maxclient = max_client + max_queue + 10, 38 maxclient = max_client + max_queue + 10,
16 httpd = httpd, 39 httpd = httpd,
17 -  
18 - redishost = skynet.getenv("redis_host"),  
19 - redisport = tonumber(skynet.getenv("redis_port")),  
20 - redisdb = tonumber(skynet.getenv("redis_db")),  
21 - auth = skynet.getenv("redis_auth"),  
22 }) 40 })
23 41
24 skynet.exit() 42 skynet.exit()
src/models/RoleLog.lua
1 local serverId = skynet.getenv("servId") 1 local serverId = skynet.getenv("servId")
2 local server_id = (skynet.getenv("serverType") or "localtest") .. "_" .. serverId 2 local server_id = (skynet.getenv("serverType") or "localtest") .. "_" .. serverId
  3 +local logproxy = require "shared.logproxy"
3 4
4 --[[ 5 --[[
5 100 购买/兑换行为 6 100 购买/兑换行为
@@ -765,8 +766,7 @@ function RoleLog.bind(Role) @@ -765,8 +766,7 @@ function RoleLog.bind(Role)
765 end 766 end
766 end 767 end
767 end 768 end
768 - if not logd then return end  
769 - pcall(skynet.send, logd, "lua", "log", doc, "bi") 769 + logproxy:log(doc, "bi")
770 end 770 end
771 771
772 function Role:logItems(itemId, before, after, log) 772 function Role:logItems(itemId, before, after, log)
@@ -825,8 +825,7 @@ function RoleLog.bind(Role) @@ -825,8 +825,7 @@ function RoleLog.bind(Role)
825 end 825 end
826 end 826 end
827 doc["@type"] = logType 827 doc["@type"] = logType
828 - if not logd then return end  
829 - pcall(skynet.send, logd, "lua", "log", doc, "log") 828 + logproxy:log(doc, "log")
830 end 829 end
831 830
832 831
src/services/agent_ctrl.lua
@@ -6,6 +6,7 @@ local xxtea = require &quot;xxtea&quot; @@ -6,6 +6,7 @@ local xxtea = require &quot;xxtea&quot;
6 local deque = require "deque" 6 local deque = require "deque"
7 local datacenter = require "skynet.datacenter" 7 local datacenter = require "skynet.datacenter"
8 local agent_queued = require "services.agent_queued" 8 local agent_queued = require "services.agent_queued"
  9 +local logproxy = require "shared.logproxy"
9 10
10 local pcall = pcall 11 local pcall = pcall
11 local string_format = string.format 12 local string_format = string.format
@@ -139,11 +140,11 @@ function _M:check_agent_status() @@ -139,11 +140,11 @@ function _M:check_agent_status()
139 end 140 end
140 end 141 end
141 142
142 - if now >= next_log_time and now % 60 == 0 and logd then 143 + if now >= next_log_time and now % 60 == 0 then
143 next_log_time = now + 60 144 next_log_time = now + 60
144 local count = table_nums(self.u2f) 145 local count = table_nums(self.u2f)
145 datacenter.set("onlineCount", count) 146 datacenter.set("onlineCount", count)
146 - pcall(skynet.send, logd, "lua", "log", {["@type"] = "online", count = count}, "log") 147 + logproxy:log({["@type"] = "online", count = count}, "log")
147 end 148 end
148 end 149 end
149 150
src/services/dbseed.lua
@@ -34,8 +34,6 @@ local steps = { @@ -34,8 +34,6 @@ local steps = {
34 } 34 }
35 35
36 skynet.start(function () 36 skynet.start(function ()
37 - redisd = skynet.localname(".redis")  
38 -  
39 redisproxy = require("shared.redisproxy") 37 redisproxy = require("shared.redisproxy")
40 38
41 local new = redisproxy:hsetnx("autoincrement_set", "server_start", os.date("%Y%m%d", skynet.timex())) == 1 39 local new = redisproxy:hsetnx("autoincrement_set", "server_start", os.date("%Y%m%d", skynet.timex())) == 1
src/services/globald.lua
@@ -190,7 +190,6 @@ local function __init__() @@ -190,7 +190,6 @@ local function __init__()
190 end 190 end
191 end 191 end
192 end) 192 end)
193 - redisd = skynet.localname(".redis")  
194 skynet.register(".globald") 193 skynet.register(".globald")
195 194
196 end 195 end
src/services/httpweb.lua
@@ -53,12 +53,8 @@ end @@ -53,12 +53,8 @@ end
53 local CMD = require "actions.HttpAction" 53 local CMD = require "actions.HttpAction"
54 54
55 local function start() 55 local function start()
56 - redisd = skynet.localname(".redis")  
57 globalCsv = csvdb["GlobalDefineCsv"] 56 globalCsv = csvdb["GlobalDefineCsv"]
58 57
59 - if tonumber(skynet.getenv "logd") == 1 then  
60 - logd = skynet.localname(".log")  
61 - end  
62 58
63 local listen_socket = socket.listen("0.0.0.0", port) 59 local listen_socket = socket.listen("0.0.0.0", port)
64 print("Listen web port " .. port) 60 print("Listen web port " .. port)
src/services/logd.lua
@@ -2,12 +2,12 @@ local skynet = require &quot;skynet&quot; @@ -2,12 +2,12 @@ local skynet = require &quot;skynet&quot;
2 local queue = require "skynet.queue" 2 local queue = require "skynet.queue"
3 local bson = require "bson" 3 local bson = require "bson"
4 local socketdriver = require "skynet.socketdriver" 4 local socketdriver = require "skynet.socketdriver"
5 -  
6 local serverId = tonumber(skynet.getenv("servId")) 5 local serverId = tonumber(skynet.getenv("servId"))
7 6
8 require "shared.init" 7 require "shared.init"
9 require "skynet.manager" 8 require "skynet.manager"
10 9
  10 +local logdIdx = ...
11 local table_insert = table.insert 11 local table_insert = table.insert
12 local pairs = pairs 12 local pairs = pairs
13 local ipairs = ipairs 13 local ipairs = ipairs
@@ -15,6 +15,7 @@ local string_format = string.format @@ -15,6 +15,7 @@ local string_format = string.format
15 15
16 local logId = 0 16 local logId = 0
17 local CMD, cs = {} 17 local CMD, cs = {}
  18 +local prefix = "wasteland" .. logdIdx .. "S" .. serverId .. "C"
18 19
19 local logHandle = { 20 local logHandle = {
20 bi = { 21 bi = {
@@ -33,7 +34,7 @@ local logHandle = { @@ -33,7 +34,7 @@ local logHandle = {
33 doc["game_name"] = "wasteland" 34 doc["game_name"] = "wasteland"
34 doc["env"] = "cb" 35 doc["env"] = "cb"
35 doc["game_name_type"] = "guaji" 36 doc["game_name_type"] = "guaji"
36 - doc["log_id"] = "wastelandC" .. logId .. "S" .. serverId .. "T" .. now 37 + doc["log_id"] = prefix .. logId .. "T" .. now
37 logId = (logId + 1) % 10000000 38 logId = (logId + 1) % 10000000
38 end 39 end
39 }, 40 },
@@ -135,7 +136,7 @@ local function __init__() @@ -135,7 +136,7 @@ local function __init__()
135 end) 136 end)
136 cs = queue() 137 cs = queue()
137 138
138 - skynet.register(".log") 139 + skynet.register(".logd" .. logdIdx)
139 end 140 end
140 141
141 skynet.start(__init__) 142 skynet.start(__init__)
src/services/pvpd.lua
@@ -289,7 +289,6 @@ end @@ -289,7 +289,6 @@ end
289 289
290 ------------------------------------------------------ 290 ------------------------------------------------------
291 function CMD.start() 291 function CMD.start()
292 - redisd = skynet.localname(".redis")  
293 globalCsv = csvdb["GlobalDefineCsv"] 292 globalCsv = csvdb["GlobalDefineCsv"]
294 293
295 pvpInfo = require("models.Pvpd").new({key = "cross:pvpInfo"}) 294 pvpInfo = require("models.Pvpd").new({key = "cross:pvpInfo"})
src/services/redisd.lua
@@ -3,7 +3,7 @@ require &quot;skynet.manager&quot; @@ -3,7 +3,7 @@ require &quot;skynet.manager&quot;
3 local redis = require "skynet.db.redis" 3 local redis = require "skynet.db.redis"
4 4
5 local db 5 local db
6 - 6 +local idx = ...
7 local command = {} 7 local command = {}
8 8
9 function command.open(conf) 9 function command.open(conf)
@@ -27,5 +27,5 @@ skynet.start(function() @@ -27,5 +27,5 @@ skynet.start(function()
27 skynet.info_func(function() 27 skynet.info_func(function()
28 return skynet.stat("mqlen") 28 return skynet.stat("mqlen")
29 end) 29 end)
30 - skynet.register ".redis" 30 + skynet.register(".redis" .. idx)
31 end) 31 end)
32 \ No newline at end of file 32 \ No newline at end of file
src/services/watchdog.lua
1 local skynet = require "skynet" 1 local skynet = require "skynet"
2 require "skynet.manager" 2 require "skynet.manager"
3 -local redisproxy = require "shared.redisproxy"  
4 local socket = require "skynet.socket" 3 local socket = require "skynet.socket"
5 local netpack = require "skynet.netpack" 4 local netpack = require "skynet.netpack"
6 local datacenter = require "skynet.datacenter" 5 local datacenter = require "skynet.datacenter"
@@ -47,7 +46,7 @@ function SOCKET.data(fd, msg) @@ -47,7 +46,7 @@ function SOCKET.data(fd, msg)
47 end 46 end
48 end 47 end
49 48
50 -local use_logd = tonumber(skynet.getenv "logd") 49 +
51 50
52 -- @desc: agent状态定时检测 51 -- @desc: agent状态定时检测
53 function check_agent_status() 52 function check_agent_status()
@@ -65,11 +64,7 @@ end @@ -65,11 +64,7 @@ end
65 64
66 function CMD.start(conf) 65 function CMD.start(conf)
67 skynet.call(gate_serv, "lua", "open" , conf) 66 skynet.call(gate_serv, "lua", "open" , conf)
68 - skynet.call(redisd, "lua", "open", conf)  
69 -  
70 - if use_logd == 1 then  
71 - skynet.call(logd, "lua", "open")  
72 - end 67 +
73 skynet.call(pvpd, "lua", "start") 68 skynet.call(pvpd, "lua", "start")
74 -- 开启agent状态检测定时器 69 -- 开启agent状态检测定时器
75 check_agent_status() 70 check_agent_status()
@@ -110,17 +105,11 @@ skynet.start(function() @@ -110,17 +105,11 @@ skynet.start(function()
110 end 105 end
111 end) 106 end)
112 skynet.register ".watchdog" 107 skynet.register ".watchdog"
113 - -- 数据库服务  
114 - redisd = skynet.newservice("services/redisd")  
115 108
116 -- 提前加载好 109 -- 提前加载好
117 csvdata.init() 110 csvdata.init()
118 print("launch csvdatad ...") 111 print("launch csvdatad ...")
119 112
120 - -- 日志服务  
121 - if use_logd == 1 then  
122 - logd = skynet.newservice("services/logd")  
123 - end  
124 -- pvp 服务 113 -- pvp 服务
125 pvpd = skynet.newservice("services/pvpd") 114 pvpd = skynet.newservice("services/pvpd")
126 cluster.register("pvpd", pvpd) 115 cluster.register("pvpd", pvpd)
src/shared/logproxy.lua 0 → 100644
@@ -0,0 +1,23 @@ @@ -0,0 +1,23 @@
  1 +
  2 +local skynet = require "skynet"
  3 +local logd_count = tonumber(skynet.getenv("thread"))
  4 +local use_logd = tonumber(skynet.getenv("logd"))
  5 +
  6 +
  7 +local logd
  8 +skynet.init(function()
  9 + if use_logd then
  10 + local idx = math.randomInt(1, logd_count)
  11 + logd = skynet.localname(".logd" .. idx)
  12 + end
  13 +end)
  14 +
  15 +local logproxy = {}
  16 +
  17 +function logproxy:log(doc, logTo)
  18 + if use_logd and logd then
  19 + pcall(skynet.send, logd, "lua", "log", doc, logTo)
  20 + end
  21 +end
  22 +
  23 +return logproxy
0 \ No newline at end of file 24 \ No newline at end of file
src/shared/redisproxy.lua
1 local skynet = require "skynet" 1 local skynet = require "skynet"
2 -local harbor = require "skynet.harbor" 2 +require "utils.init"
  3 +
  4 +local redisd_count = tonumber(skynet.getenv("thread"))
  5 +local redisd
  6 +skynet.init(function()
  7 + local idx = math.randomInt(1, redisd_count)
  8 + redisd = skynet.localname(".redis" .. idx)
  9 +end)
3 10
4 local table_insert = table.insert 11 local table_insert = table.insert
5 12
6 local redisproxy = {} 13 local redisproxy = {}
7 14
8 -  
9 local isUsePika = false 15 local isUsePika = false
10 16
11 17