-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathS95servers.lua
40 lines (36 loc) · 851 Bytes
/
S95servers.lua
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
if (tcp_servers == nil) then
tcp_servers={}
end
if (tcp_modules == nil) then
tcp_modules={}
setmetatable(tcp_modules, { __mode = "v" })
end
function server_connect(c,name)
local mod=tcp_modules[name]
if (not mod) then
-- print("loading",name)
mod=require(name)
tcp_modules[name]=mod
package.loaded[name]=nil
else
-- print(name,"already loaded")
end
mod(c)
end
function server_activate(name)
local port=name:match("TCP_(%d*).*%.lua")
if (port) then
print("Activating",name)
local s=net.createServer(net.TCP)
tcp_servers[name]=s
s:listen(port,function(c) server_connect(c,name:sub(1,-5)) end, true)
end
end
function server_deactivate(name)
local s=tcp_servers[name]
pcall(s.close,s)
tcp_servers[name]=nil
end
for key,value in pairs(file.list()) do
server_activate(key)
end