updated some code
This commit is contained in:
parent
1eeb654a32
commit
b0ce79defd
15
net/init.lua
15
net/init.lua
@ -164,9 +164,9 @@ function net:newCastedClients(name) -- connects to the broadcasted server
|
|||||||
local timer=multi:newTimer()
|
local timer=multi:newTimer()
|
||||||
multi:newTLoop(function(self)
|
multi:newTLoop(function(self)
|
||||||
local data, ip, port = listen:receivefrom()
|
local data, ip, port = listen:receivefrom()
|
||||||
if data and not net.ClientCache[data] then
|
if data then
|
||||||
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) and not net.ClientCache[n] then
|
||||||
local capture = n:match(name)
|
local capture = n:match(name)
|
||||||
local client = {}
|
local client = {}
|
||||||
if tp=="tcp" then
|
if tp=="tcp" then
|
||||||
@ -174,8 +174,8 @@ function net:newCastedClients(name) -- connects to the broadcasted server
|
|||||||
else
|
else
|
||||||
client=net:newUDPClient(ip,tonumber(port))
|
client=net:newUDPClient(ip,tonumber(port))
|
||||||
end
|
end
|
||||||
|
net.ClientCache[n]=client
|
||||||
net.OnCastedClientInfo:Fire(client,n,ip,port)
|
net.OnCastedClientInfo:Fire(client,n,ip,port)
|
||||||
net.ClientCache[data]=client -- we only want this to trigger once so lets add it to our list of clients
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,.1)
|
end,.1)
|
||||||
@ -188,7 +188,9 @@ function net:newUDPServer(port,servercode,nonluaServer)
|
|||||||
c.udp:setsockname("*", port)
|
c.udp:setsockname("*", port)
|
||||||
c.ips={}
|
c.ips={}
|
||||||
c.Type="udp"
|
c.Type="udp"
|
||||||
c.port=port
|
if port == 0 then
|
||||||
|
_, c.port = c.udp:getsockname()
|
||||||
|
end
|
||||||
c.ids={}
|
c.ids={}
|
||||||
c.servercode=servercode
|
c.servercode=servercode
|
||||||
c.bannedIPs={}
|
c.bannedIPs={}
|
||||||
@ -474,7 +476,9 @@ function net:newTCPServer(port)
|
|||||||
c.tcp:settimeout(0)
|
c.tcp:settimeout(0)
|
||||||
c.ip,c.port=c.tcp:getsockname()
|
c.ip,c.port=c.tcp:getsockname()
|
||||||
c.ips={}
|
c.ips={}
|
||||||
c.port=port
|
if port == 0 then
|
||||||
|
_, c.port = c.udp:getsockname()
|
||||||
|
end
|
||||||
c.ids={}
|
c.ids={}
|
||||||
c.bannedIPs={}
|
c.bannedIPs={}
|
||||||
c.Type="tcp"
|
c.Type="tcp"
|
||||||
@ -619,7 +623,6 @@ end
|
|||||||
function net:newTCPClient(host,port)
|
function net:newTCPClient(host,port)
|
||||||
local c={}
|
local c={}
|
||||||
c.ip=assert(socket.dns.toip(host))
|
c.ip=assert(socket.dns.toip(host))
|
||||||
c.port=port
|
|
||||||
c.tcp=socket.connect(c.ip,port)
|
c.tcp=socket.connect(c.ip,port)
|
||||||
if not c.tcp then
|
if not c.tcp then
|
||||||
print("Can't connect to the server: no response from server")
|
print("Can't connect to the server: no response from server")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user