re-add love-gltf for now; use local IPs for now.

This commit is contained in:
wan-may 2023-09-22 01:15:06 -03:00
parent 6d623dec28
commit 42aa39423f
6 changed files with 23 additions and 11 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "love-gltf"]
path = love-gltf
url = https://gitlab.com/Alloyed/love-gltf.git

1
love-gltf Submodule

@ -0,0 +1 @@
Subproject commit b9084c4dd27057d0e72b569c2da806cabc1a84f7

View File

@ -18,12 +18,18 @@ local tick = 0
local handlers = setmetatable({ local handlers = setmetatable({
serverInfo = function( svInfo, ip, port ) serverInfo = function( svInfo, ip, port )
print( "Received server info from:", ip, port ) print( "Server:", ip, port )
if ip ~= tostring( svInfo.ip ) then return print("Server IP mismatch:", ip, svInfo.ip) end
local t = socket.gettime() local t = socket.gettime()
if not servers[ip] then servers[ip] = { ip = ip, port = port, info = svInfo } end if not servers[ip..port] then
servers[ip].time = t servers[ip..port] = { ip = ip, port = port, info = svInfo }
packet.advertised{ time = t } --NAT punch: the server doesn't know its own external IP
--so it contacts a third party (the metaserver) to discover it.
--This external IP gets advertised to prospective clients.
svInfo.ip = shared.ip.fromString( ip )
svInfo.port = port
end
servers[ip..port].time = t
packet.advertised{ time = t, ip = svInfo.ip, port = svInfo.port }
return udp:sendto( packet.get(), ip, port ) return udp:sendto( packet.get(), ip, port )
end, end,

View File

@ -3,7 +3,9 @@ package.path = "..\\?.lua;..\\lualib\\?.lua;"..package.path
local shared = assert( require 'shared.shared' ) local shared = assert( require 'shared.shared' )
local packet = shared.packet local packet = shared.packet
local socket = assert( require 'socket' ) local socket = assert( require 'socket' )
local ms = shared.metaserver local mscxn = assert( socket.udp() )
mscxn:settimeout( 0 )
assert( mscxn:setpeername( shared.metaserver.ip, shared.metaserver.port ), "Could not connect to metaserver!" )
local udp local udp
local io = assert( io ) local io = assert( io )
@ -36,7 +38,7 @@ function server.Advertise()
packet.get() packet.get()
packet.metaServer() packet.metaServer()
packet.serverInfo( svInfo ) packet.serverInfo( svInfo )
udp:sendto( packet.get() , ms.ip, ms.port ) mscxn:send( packet.get() )
end end
function server.serverInfo( serverInfo ) function server.serverInfo( serverInfo )
@ -106,7 +108,7 @@ server.Start()
function love.update( dt ) function love.update( dt )
server.Parse( udp:receivefrom() ) server.Parse( udp:receivefrom() )
server.Advance() server.Advance()
if server.tick % 50 == 0 then if server.tick % 250 == 0 then
server.Advertise() server.Advertise()
end end
end end

View File

@ -1 +1 @@
return { ip = '142.162.167.92', port = 42069 } return { ip = '192.168.2.15', port = 42069 }

View File

@ -1,13 +1,13 @@
print( "Loading Shared." ) print( "Loading Shared." )
local shared = {} local shared = {}
do --[[do
local rq = require local rq = require
require = function( ... ) require = function( ... )
print( "Require:", ... ) print( "Require:", ... )
return rq( ... ) return rq( ... )
end end
end end]]
shared.ip = assert( require 'shared.ipstring' ) shared.ip = assert( require 'shared.ipstring' )
shared.packet = assert( require 'shared.packet' ) shared.packet = assert( require 'shared.packet' )
shared.print = assert( require 'shared.print' ) shared.print = assert( require 'shared.print' )