Updated some files
This commit is contained in:
parent
a7ce660e3b
commit
36ae77e98a
@ -1,7 +1,7 @@
|
|||||||
package.path = "./?/init.lua;./?.lua;"..package.path
|
package.path = "./?/init.lua;./?.lua;"..package.path
|
||||||
local net = require("lnet.tcp")
|
local net = require("lnet.tcp")
|
||||||
local multi, thread = require("multi"):init()
|
local multi, thread = require("multi"):init()
|
||||||
local client = net:newCastedClient("Test")--net:newTCPClient("localhost",12345)
|
local client = net.newCastedClient("Test")--net:newTCPClient("localhost",12345)
|
||||||
|
|
||||||
client:send("Test!")
|
client:send("Test!")
|
||||||
|
|
||||||
|
|||||||
@ -5,6 +5,7 @@ client.updaterRate = 1
|
|||||||
client.sMode = "*l"
|
client.sMode = "*l"
|
||||||
client.rMode = "*l"
|
client.rMode = "*l"
|
||||||
function client:init(type)
|
function client:init(type)
|
||||||
|
self.Type = type
|
||||||
self.OnDataRecieved = multi:newConnection()
|
self.OnDataRecieved = multi:newConnection()
|
||||||
self.OnServerNotAvailable = multi:newConnection()
|
self.OnServerNotAvailable = multi:newConnection()
|
||||||
self.OnClientReady = multi:newConnection()
|
self.OnClientReady = multi:newConnection()
|
||||||
@ -13,7 +14,6 @@ function client:init(type)
|
|||||||
self.OnPreSend = multi:newConnection()
|
self.OnPreSend = multi:newConnection()
|
||||||
self.OnPreRecieved = multi:newConnection()
|
self.OnPreRecieved = multi:newConnection()
|
||||||
self.OnError = multi:newConnection()
|
self.OnError = multi:newConnection()
|
||||||
self.Type = type
|
|
||||||
self.process = multi:newProcessor()
|
self.process = multi:newProcessor()
|
||||||
self.process.Start()
|
self.process.Start()
|
||||||
end
|
end
|
||||||
@ -8,6 +8,7 @@ server.updaterRate = 1
|
|||||||
server.rMode = "*l"
|
server.rMode = "*l"
|
||||||
server.sMode = "*l"
|
server.sMode = "*l"
|
||||||
function server:init(type)
|
function server:init(type)
|
||||||
|
self.Type = type
|
||||||
self.OnClientsModulesList = multi:newConnection()
|
self.OnClientsModulesList = multi:newConnection()
|
||||||
self.OnPreRecieved = multi:newConnection()
|
self.OnPreRecieved = multi:newConnection()
|
||||||
self.OnDataRecieved = multi:newConnection()
|
self.OnDataRecieved = multi:newConnection()
|
||||||
@ -15,11 +16,11 @@ function server:init(type)
|
|||||||
self.OnClientConnected = multi:newConnection()
|
self.OnClientConnected = multi:newConnection()
|
||||||
self.OnPreSend = multi:newConnection()
|
self.OnPreSend = multi:newConnection()
|
||||||
self.idleRate = 5
|
self.idleRate = 5
|
||||||
|
self.clientHandlers = {}
|
||||||
self.bannedCIDs = {}
|
self.bannedCIDs = {}
|
||||||
self.bannedIPs = {}
|
self.bannedIPs = {}
|
||||||
self.broad = socket.udp()
|
self.broad = socket.udp()
|
||||||
self.localIP = net.getLocalIP()
|
self.localIP = net.getLocalIP()
|
||||||
self.Type = type
|
|
||||||
self.ips = {}
|
self.ips = {}
|
||||||
self.links = {}
|
self.links = {}
|
||||||
self.cids = {}
|
self.cids = {}
|
||||||
@ -49,11 +50,12 @@ function server:broadcast(name)
|
|||||||
bCaster = bCaster + 1
|
bCaster = bCaster + 1
|
||||||
self.isBroadcasting = true
|
self.isBroadcasting = true
|
||||||
self.process:newThread("Broadcast Handler<"..bCaster..">",function()
|
self.process:newThread("Broadcast Handler<"..bCaster..">",function()
|
||||||
print(table.concat({name,self.Type,self.localIP},"|")..":"..self.port)
|
|
||||||
while true do
|
while true do
|
||||||
thread.yield()
|
thread.yield()
|
||||||
self.broad:setoption("broadcast",true)
|
self.broad:setoption("broadcast",true)
|
||||||
self.broad:sendto(table.concat({name,self.Type,self.localIP},"|")..":"..self.port, "255.255.255.255", 11111)
|
self.broad:sendto(table.concat({name,self.Type,self.localIP},"|")..":"..self.port, "255.255.255.255", 11111)
|
||||||
|
-- Send to localhost as well
|
||||||
|
self.broad:sendto(table.concat({name,self.Type,self.localIP},"|")..":"..self.port, self.localIP, 11111)
|
||||||
self.broad:setoption("broadcast", false)
|
self.broad:setoption("broadcast", false)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
@ -38,7 +38,7 @@ end
|
|||||||
for i = 97, 122 do
|
for i = 97, 122 do
|
||||||
char[#char + 1] = string.char(i)
|
char[#char + 1] = string.char(i)
|
||||||
end
|
end
|
||||||
local isHyphen = {[9] = 1, [14] = 1, [19] = 1, [24] = 1}
|
|
||||||
math.random()
|
math.random()
|
||||||
math.random()
|
math.random()
|
||||||
math.random()
|
math.random()
|
||||||
@ -48,8 +48,8 @@ local http = require("socket.http")
|
|||||||
--ssl=require("ssl")
|
--ssl=require("ssl")
|
||||||
--https=require("ssl.https")
|
--https=require("ssl.https")
|
||||||
local net = {}
|
local net = {}
|
||||||
net.Version = {4, 0, 0} -- This will probably stay this version for quite a while... The modules on the otherhand will change more often
|
net.Version = {5, 0, 0} -- This will probably stay this version for quite a while... The modules on the otherhand will change more often
|
||||||
net._VERSION = "4.0.0"
|
net._VERSION = "5.0.0"
|
||||||
net.ClientCache = {}
|
net.ClientCache = {}
|
||||||
net.OnServerCreated = multi:newConnection()
|
net.OnServerCreated = multi:newConnection()
|
||||||
net.OnClientCreated = multi:newConnection()
|
net.OnClientCreated = multi:newConnection()
|
||||||
@ -59,6 +59,7 @@ net.autoInit = true
|
|||||||
net.ConnectionDriver = {}
|
net.ConnectionDriver = {}
|
||||||
net.BroadcastDriver = {}
|
net.BroadcastDriver = {}
|
||||||
math.randomseed(math.ceil(os.time()+(os.clock()*1000)))
|
math.randomseed(math.ceil(os.time()+(os.clock()*1000)))
|
||||||
|
local isHyphen = {[9] = 1, [14] = 1, [19] = 1, [24] = 1}
|
||||||
net.generateGUID = function(t)
|
net.generateGUID = function(t)
|
||||||
local pass = {}
|
local pass = {}
|
||||||
local a = 0
|
local a = 0
|
||||||
@ -102,23 +103,20 @@ function net.getExternalIP()
|
|||||||
local data = http.request("http://www.myipnumber.com/my-ip-address.asp")
|
local data = http.request("http://www.myipnumber.com/my-ip-address.asp")
|
||||||
return data:match("(%d+%.%d+%.%d+%.%d+)")
|
return data:match("(%d+%.%d+%.%d+%.%d+)")
|
||||||
end
|
end
|
||||||
function net:registerModule(mod, version)
|
function net.registerModule(mod, version)
|
||||||
if net[mod] then
|
if net[mod] then
|
||||||
error(
|
error("Module by the name: " .. mod .. " has already been registered! Remember some modules are internal and use certain names!")
|
||||||
"Module by the name: " ..
|
|
||||||
mod .. " has already been registered! Remember some modules are internal and use certain names!"
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
table.insert(self.loadedModules, mod)
|
table.insert(net.loadedModules, mod)
|
||||||
net[mod] = {}
|
net[mod] = {}
|
||||||
if version then
|
if version then
|
||||||
net[mod].Version = version
|
net[mod].Version = version
|
||||||
net[mod]._VERSION = version[1] .. "." .. version[2] .. "." .. version[3]
|
net[mod]._VERSION = table.concat(version,".")
|
||||||
else
|
else
|
||||||
net[mod].Version = {1, 0, 0}
|
net[mod].Version = {1, 0, 0}
|
||||||
net[mod]._VERSION = {1, 0, 0}
|
net[mod]._VERSION = {1, 0, 0}
|
||||||
end
|
end
|
||||||
return {Version = version, _VERSION = version[1] .. "." .. version[2] .. "." .. version[3]}
|
return {Version = version, _VERSION = table.concat(version,".")}
|
||||||
end
|
end
|
||||||
function net.getModuleVersion(ext)
|
function net.getModuleVersion(ext)
|
||||||
if not ext then
|
if not ext then
|
||||||
@ -145,33 +143,31 @@ end
|
|||||||
function net.setTrigger(funcW, funcE)
|
function net.setTrigger(funcW, funcE)
|
||||||
multi:newTrigger(func)
|
multi:newTrigger(func)
|
||||||
end
|
end
|
||||||
net:registerModule("net", net.Version)
|
net.registerModule("net", net.Version)
|
||||||
-- Client broadcast
|
-- Client broadcast
|
||||||
function net:newCastedClient(name) -- connects to the broadcasted server
|
function net.newCastedClient(name) -- connects to the broadcasted server
|
||||||
local listen = socket.udp() -- make a new socket
|
local listen = socket.udp() -- make a new socket
|
||||||
listen:setsockname(net.getLocalIP(), 11111)
|
listen:setsockname(net.getLocalIP(), 11111)
|
||||||
listen:settimeout(0)
|
listen:settimeout(0)
|
||||||
local timer = multi:newTimer()
|
local timer = multi:newTimer()
|
||||||
while true do
|
while true do
|
||||||
local data, ip, port = listen:receivefrom()
|
local data, ip, port = listen:receivefrom()
|
||||||
-- if timer:Get() > 3 then
|
if timer:Get() > 3 then
|
||||||
-- error("Timeout! Server by the name: " .. name .. " has not been found!")
|
error("Timeout! Server by the name: " .. name .. " has not been found!")
|
||||||
-- end
|
end
|
||||||
if data then
|
if data then
|
||||||
print("Found:", data)
|
|
||||||
local n, tp, ip, port = data:match("(%S-)|(%S-)|(%S-):(%d+)")
|
local n, tp, ip, port = data:match("(%S-)|(%S-)|(%S-):(%d+)")
|
||||||
if n:match(name) then
|
if n:match(name) then
|
||||||
--print("Found Server!", n, tp, ip, port)
|
|
||||||
if tp == "tcp" then
|
if tp == "tcp" then
|
||||||
return net:newTCPClient(ip, tonumber(port))
|
return net.newTCPClient(ip, tonumber(port))
|
||||||
else
|
else
|
||||||
return net:newClient(ip, tonumber(port))
|
return net.newClient(ip, tonumber(port))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function net:newCastedClients(name) -- connects to the broadcasted server
|
function net.newCastedClients(name) -- connects to the broadcasted server
|
||||||
local listen = socket.udp() -- make a new socket
|
local listen = socket.udp() -- make a new socket
|
||||||
listen:setsockname(net.getLocalIP(), 11111)
|
listen:setsockname(net.getLocalIP(), 11111)
|
||||||
listen:settimeout(0)
|
listen:settimeout(0)
|
||||||
|
|||||||
@ -1,9 +1,10 @@
|
|||||||
local net = require("lnet")
|
local net = require("lnet")
|
||||||
local clientbase = require("net.core.clientbase")
|
local clientbase = require("lnet.base.client")
|
||||||
local serverbase = require("net.core.serverbase")
|
local serverbase = require("lnet.base.server")
|
||||||
local multi, thread = require("multi"):init()
|
local multi, thread = require("multi"):init()
|
||||||
|
local socket = require("socket")
|
||||||
local tcpcount = 0
|
local tcpcount = 0
|
||||||
function net:newTCPServer(port)
|
net.newTCPServer = thread:newFunction(function(port)
|
||||||
local c = {}
|
local c = {}
|
||||||
setmetatable(c,serverbase)
|
setmetatable(c,serverbase)
|
||||||
c:init("tcp")
|
c:init("tcp")
|
||||||
@ -35,7 +36,8 @@ function net:newTCPServer(port)
|
|||||||
ip, port = client:getpeername()
|
ip, port = client:getpeername()
|
||||||
if ip and port then
|
if ip and port then
|
||||||
c.OnClientConnected:Fire(c, client, ip, port)
|
c.OnClientConnected:Fire(c, client, ip, port)
|
||||||
multi:newThread("ServerClientHandler",function()
|
-- We need to cache the client handler so we can work with it
|
||||||
|
c.clientHandlers[client] = multi:newThread("ServerClientHandler<".. tostring(client):match(": (.+)") ..">",function()
|
||||||
local cli = client
|
local cli = client
|
||||||
while true do
|
while true do
|
||||||
thread.yield()
|
thread.yield()
|
||||||
@ -66,8 +68,6 @@ function net:newTCPServer(port)
|
|||||||
c.OnDataRecieved:Fire(c, data, cli, ip, port)
|
c.OnDataRecieved:Fire(c, data, cli, ip, port)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end).OnError(function(...)
|
|
||||||
print(...)
|
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -75,10 +75,11 @@ function net:newTCPServer(port)
|
|||||||
end).OnError(function(...)
|
end).OnError(function(...)
|
||||||
print(...)
|
print(...)
|
||||||
end)
|
end)
|
||||||
|
net.OnServerCreated:Fire(c)
|
||||||
return c
|
return c
|
||||||
end
|
end,true)
|
||||||
|
|
||||||
function net:newTCPClient(host, port)
|
net.newTCPClient = thread:newFunction(function(host, port)
|
||||||
local c = {}
|
local c = {}
|
||||||
setmetatable(c,clientbase)
|
setmetatable(c,clientbase)
|
||||||
c:init("tcp")
|
c:init("tcp")
|
||||||
@ -128,6 +129,7 @@ function net:newTCPClient(host, port)
|
|||||||
end).OnError(function(...)
|
end).OnError(function(...)
|
||||||
print(...)
|
print(...)
|
||||||
end)
|
end)
|
||||||
|
net.OnClientCreated:Fire(c)
|
||||||
return c
|
return c
|
||||||
end
|
end,true)
|
||||||
return net
|
return net
|
||||||
@ -1,13 +1,13 @@
|
|||||||
local net = require("lnet")
|
local net = require("lnet")
|
||||||
local clientbase = require("net.core.clientbase")
|
local clientbase = require("lnet.base.client")
|
||||||
local serverbase = require("net.core.serverbase")
|
local serverbase = require("lnet.base.server")
|
||||||
local multi, thread = require("multi"):init()
|
local multi, thread = require("multi"):init()
|
||||||
local CID = {}
|
local CID = {}
|
||||||
CID.__index = cid
|
CID.__index = cid
|
||||||
local udpcount = 0
|
local udpcount = 0
|
||||||
CID.ip = "0.0.0.0"
|
CID.ip = "0.0.0.0"
|
||||||
CID.port = 0
|
CID.port = 0
|
||||||
function net:newUDPServer(port)
|
net.newUDPServer = thread:newFunction(function(port)
|
||||||
local c = {}
|
local c = {}
|
||||||
setmetatable(c,serverbase)
|
setmetatable(c,serverbase)
|
||||||
c:init("udp")
|
c:init("udp")
|
||||||
@ -27,6 +27,7 @@ function net:newUDPServer(port)
|
|||||||
self.udp:sendto(dat.data,dat.cid.ip,dat.cid.port)
|
self.udp:sendto(dat.data,dat.cid.ip,dat.cid.port)
|
||||||
end
|
end
|
||||||
c.updateThread = c.process:newThread("UDPServer Thread<"..udpcount..">",function()
|
c.updateThread = c.process:newThread("UDPServer Thread<"..udpcount..">",function()
|
||||||
|
-- Every now and then we are going to check to see if a client has been inactive
|
||||||
local sideJob = thread:newFunction(function()
|
local sideJob = thread:newFunction(function()
|
||||||
thread.sleep(60*c.idleRate)
|
thread.sleep(60*c.idleRate)
|
||||||
for i,v in pairs(c.cids) do
|
for i,v in pairs(c.cids) do
|
||||||
@ -41,7 +42,7 @@ function net:newUDPServer(port)
|
|||||||
while true do
|
while true do
|
||||||
thread.skip(c.updaterRate)
|
thread.skip(c.updaterRate)
|
||||||
local data, ip, port = c.udp:receivefrom()
|
local data, ip, port = c.udp:receivefrom()
|
||||||
sideJob().connect(function(yes,a,b,c)
|
sideJob().connect(function(yes)
|
||||||
if yes then
|
if yes then
|
||||||
sideJob:Resume()
|
sideJob:Resume()
|
||||||
end
|
end
|
||||||
@ -59,7 +60,6 @@ function net:newUDPServer(port)
|
|||||||
cid = cd
|
cid = cd
|
||||||
c.OnClientConnected:Fire(c, cd, ip, port)
|
c.OnClientConnected:Fire(c, cd, ip, port)
|
||||||
end
|
end
|
||||||
print("Refreshing CID: ",cid," Activity!")
|
|
||||||
cid.activity = os.clock()
|
cid.activity = os.clock()
|
||||||
local dat = {data = data,cid = cid}
|
local dat = {data = data,cid = cid}
|
||||||
c.OnPreRecieved:Fire(dat)
|
c.OnPreRecieved:Fire(dat)
|
||||||
@ -69,9 +69,10 @@ function net:newUDPServer(port)
|
|||||||
end).OnError(function(...)
|
end).OnError(function(...)
|
||||||
print(...)
|
print(...)
|
||||||
end)
|
end)
|
||||||
|
net.OnServerCreated:Fire(c)
|
||||||
return c
|
return c
|
||||||
end
|
end,true)
|
||||||
function net:newUDPClient(host, port)
|
net.newUDPClient = thread:newFunction(function(host, port)
|
||||||
local c = {}
|
local c = {}
|
||||||
setmetatable(c,clientbase)
|
setmetatable(c,clientbase)
|
||||||
c:init("udp")
|
c:init("udp")
|
||||||
@ -95,6 +96,7 @@ function net:newUDPClient(host, port)
|
|||||||
c.OnDataRecieved:Fire(c,dat.data)
|
c.OnDataRecieved:Fire(c,dat.data)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
net.OnClientCreated:Fire(c)
|
||||||
return c
|
return c
|
||||||
end
|
end,true)
|
||||||
return net
|
return net
|
||||||
@ -18,7 +18,7 @@ net.OnServerCreated:connect(function(s)
|
|||||||
local cmd,arg1,arg2=data:match("!version! ")
|
local cmd,arg1,arg2=data:match("!version! ")
|
||||||
end,"version")
|
end,"version")
|
||||||
s.OnClientConnected(function(self,CID_OR_HANDLE,IP_OR_HANDLE,PORT_OR_IP)
|
s.OnClientConnected(function(self,CID_OR_HANDLE,IP_OR_HANDLE,PORT_OR_IP)
|
||||||
multi:newFunction(function(func) -- anom func, allows for fancy multitasking
|
multi:newFunction(function(func) -- anon func, allows for fancy multitasking
|
||||||
multi:newFunction(function(self)
|
multi:newFunction(function(self)
|
||||||
local range=self:newRange()
|
local range=self:newRange()
|
||||||
for i in range(1,#self.loadedModules) do
|
for i in range(1,#self.loadedModules) do
|
||||||
|
|||||||
@ -15,6 +15,7 @@ description = {
|
|||||||
dependencies = {
|
dependencies = {
|
||||||
"lua >= 5.1",
|
"lua >= 5.1",
|
||||||
"luasocket",
|
"luasocket",
|
||||||
|
"luasec",
|
||||||
"multi",
|
"multi",
|
||||||
}
|
}
|
||||||
build = {
|
build = {
|
||||||
@ -23,8 +24,8 @@ build = {
|
|||||||
["lnet.init"] = "lnet/init.lua",
|
["lnet.init"] = "lnet/init.lua",
|
||||||
["lnet.tcp.init"] = "lnet/tcp/init.lua",
|
["lnet.tcp.init"] = "lnet/tcp/init.lua",
|
||||||
["lnet.udp.init"] = "lnet/udp/init.lua",
|
["lnet.udp.init"] = "lnet/udp/init.lua",
|
||||||
["lnet.core.clientbase"] = "lnet/core/clientbase.lua",
|
["lnet.base.client"] = "lnet/base/client.lua",
|
||||||
["lnet.core.serverbase"] = "lnet/core/serverbase.lua",
|
["lnet.base.server"] = "lnet/base/server.lua",
|
||||||
["lnet.http"] = "lnet/http.lua",
|
["lnet.http"] = "lnet/http.lua",
|
||||||
["lnet.https"] = "lnet/https.lua"
|
["lnet.https"] = "lnet/https.lua"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
package.path = "./?/init.lua;./?.lua;"..package.path
|
package.path = "./?/init.lua;./?.lua;"..package.path
|
||||||
local net = require("lnet.tcp")
|
local net = require("lnet.tcp")
|
||||||
local multi, thread = require("multi"):init()
|
local multi, thread = require("multi"):init()
|
||||||
local server = net:newTCPServer(12345)
|
server = net.newTCPServer(12345)
|
||||||
server:broadcast("Test")
|
server:broadcast("Test")
|
||||||
print("Server has been broadcasted!")
|
print("Server has been broadcasted!")
|
||||||
server.OnDataRecieved(function(serv, data,cid)
|
server.OnDataRecieved(function(serv, data,cid)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user