ngxd.lua
2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
skynet = require "skynet"
redisproxy = require "shared.redisproxy"
netpack = require "skynet.netpack"
datacenter = require "skynet.datacenter"
sharedata = require "skynet.sharedata"
mcast_util = require "services/mcast_util"
globalCsv = require "csvdata/GlobalDefine"
local socket = require "skynet.socket"
local harbor = require "skynet.harbor"
require "shared.init"
require "utils.init"
require "ProtocolCode"
require "skynet.manager"
require "RedisKeys"
require "GlobalVar"
local port = tonumber(...)
local SEP = "$end$"
local actions = {}
SendPacket = function(...) end
rpcAgent = function(...) end
rpcParter = function(...) end
rpcRole = function(...) end
rpcUnion = function(...) end
rpcOtherUnion = function(...) end
skynet.register_protocol {
name = "role",
id = 13,
pack = skynet.pack,
unpack = skynet.unpack,
}
local function process(request)
local req = json.decode(request)
if req["handle"] == "checkStatus" then
return "success"
end
local modName, funcName = req["handle"]:match("([%w_]+)%.([%w_]+)")
if not modName or not funcName then
return table.concat({"handle格式错误", modName, funcName}, "\t")
end
local action = require("actions." .. modName .. "Action")
return action[funcName](req)
end
local function main_loop(stdin, send)
socket.lock(stdin)
while true do
local request = socket.readline(stdin, SEP)
if not request then
break
end
local response = process(request)
if response then send(response) end
end
socket.unlock(stdin)
end
local function start()
local listen_socket = socket.listen("0.0.0.0", port)
print("Start nginx proxy at port: ", port)
redisd = harbor.queryname("REDIS")
csvdb = sharedata.query("csvdata")
socket.start(listen_socket, function(id, addr)
local function send(...)
local t = { ... }
socket.write(id, table.concat(t, "\t"))
socket.write(id, SEP)
end
socket.start(id)
skynet.fork(main_loop, id, send)
end)
-- 注册全服广播
local channels = {}
for i = 1, 10 do
local channel = datacenter.get("MC_W_CHANNEL" .. i)
if channel then
table.insert(channels, channel)
end
end
if #channels > 0 then
mcast_util.sub_worlds(channels)
end
end
local CMD = {}
function CMD.reloadCsvdb(globalData)
if globalData then
for k, v in pairs(globalData) do
globalCsv[k] = v
end
else
csvdb = sharedata.query("csvdata")
end
end
local function __init__()
skynet.dispatch("lua", function(_,_, command, ...)
if command == "start" then
skynet.ret(skynet.pack(start(...)))
else
local f = CMD[command]
skynet.ret(skynet.pack(f(...)))
end
end)
skynet.register "NGXD"
end
skynet.start(__init__)