Skip to content

Commit

Permalink
Typo & masterserver.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
bartbes committed May 4, 2009
1 parent 6c8aad8 commit a72a142
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
Binary file added Netris.love
Binary file not shown.
39 changes: 39 additions & 0 deletions masterserver.lua
@@ -0,0 +1,39 @@
require "socket"

searchstring = "SERVBROWSER_MASTERSEARCH"
responsestring = "MASTERSERVER_RESULT"
identifystring = "MASTERSERVER_IDENTIFY"
checkstring = "MASTERSERVER_CHECK"
checkpassstring = "MASTERSERVER_CHECKPASS"

servers = {}

sock = socket.udp()
sock:settimeout(0)
sock:setsockname("*", 8189)
while true do
local data, ip, port = sock:receivefrom()
if data == searchstring then
for i, v in pairs(servers) do
local sip, sport = i:gmatch("([0-9%.]*):([0-9]*)")()
sock:sendto(string.format("%s %s %s\n", responsestring, sip, sport), ip, port)
end
elseif data == identifystring then
sock:sendto(checkstring, ip, port)
elseif data == checkpassstring then
servers[ip .. ":" .. port] = os.time()
elseif not data then
local t = os.time()
for i, v in pairs(servers) do
local dt = os.difftime(t, v)
if dt > 60 then
servers[i] = nil
elseif dt > 30 then
local ip, port = i:gmatch("([0-9%.]*):([0-9]*)")()
sock:sendto(checkstring, ip, port)
end
end
end
socket.sleep(0.1)
end

2 changes: 1 addition & 1 deletion protocol.lua
Expand Up @@ -188,6 +188,6 @@ function identifyatmaster(server, port)
if not host then
return nil, "DNS failed"
end
conn.socket:sendto("MASTERSERVER_IDENTIFY", host, ip)
conn.socket:sendto("MASTERSERVER_IDENTIFY", host, port)
end

0 comments on commit a72a142

Please sign in to comment.