Moving metaserver and server to LOVE (since it's got a working LuaSocket installation OOTB
This commit is contained in:
parent
ea5b39ebb7
commit
1e144775a5
|
@ -0,0 +1,6 @@
|
|||
call build.bat
|
||||
pushd "%~dp0\build\"
|
||||
start server.bat
|
||||
start client.bat
|
||||
start metaserver.bat
|
||||
popd
|
33
build.sh
33
build.sh
|
@ -1,33 +0,0 @@
|
|||
#get locations of scripts, libraries, engine
|
||||
SRC_DIR="src"
|
||||
LIB_DIR="lib"
|
||||
LOVE_DIR="../../love"
|
||||
BUILD_DIR="build"
|
||||
|
||||
#build LuaJIT for target platform
|
||||
|
||||
|
||||
#build LuaSocket shared library for target platform
|
||||
|
||||
|
||||
#get appropriate copy of love
|
||||
|
||||
|
||||
#zip client scripts into .love file
|
||||
cp -r $SRC_DIR/ $BUILD_DIR/
|
||||
cd $BUILD_DIR/
|
||||
zip -9 -r vision.love
|
||||
|
||||
#zip .love file with LOVE and dependencies (and license!)
|
||||
|
||||
|
||||
#zip server scripts with LuaJIT and dependencies
|
||||
|
||||
|
||||
#zip metaserver with LuaJIT and dependencies
|
||||
|
||||
|
||||
#WINDOWS: make fused client executable
|
||||
cat ../../love/love.exe vision.love > vision.exe
|
||||
|
||||
#LINUX: get official LOVE AppImage
|
|
@ -5,7 +5,7 @@ local love = assert( love )
|
|||
function love.load()
|
||||
print( "Client Started." )
|
||||
assert( require 'client.config' )
|
||||
|
||||
|
||||
--Crash unless coconut present and running luajit 2.1
|
||||
loadstring( love.data.decode( "string", "base64","G0xKAgrbAQAACgALABY2AAAAOQABADkAAgAnAgMAJwMEADYEAAA5BAEEOQQFBCcGBgA2BwAAOQcHBzkHCAcnCQkAQgcCAEEEAQBBAAICBgAKAFgAAoArAAEAWAEBgCsAAgBMAAIALWQ4MmY3M2RkNjQ1MDcxNDZiNTkwNTMwYjg0NDcwMWZlMmJmYjdjZTkeY2xpZW50L2Fzc2V0cy9jb2NvbnV0LnBuZxFuZXdJbWFnZURhdGEKaW1hZ2UJc2hhMQloYXNoCGhleAtzdHJpbmcLZW5jb2RlCWRhdGEJbG92ZV0BAAUABQAONgAAADMCAQBCAAICDgAAAFgBB4A2AAIANAIAADUDAwA2BAAAPQQEA0IAAwJCAAECMgAAgEwAAgALX19jYWxsAQAAEXNldG1ldGF0YWJsZQAKcGNhbGwA" ))()
|
||||
|
|
@ -67,17 +67,17 @@ serverList.ips = {}
|
|||
local serverButtons = serverList.buttons
|
||||
local color = { 1, 0.6, 0.6, 0.1 }
|
||||
local ti = textInput.new{
|
||||
width = lg.getWidth(),
|
||||
length = 20,
|
||||
x = cw,
|
||||
y = 35,
|
||||
h = 55,
|
||||
str = strings.ip_button,
|
||||
font = fonts.midFont,
|
||||
}
|
||||
width = lg.getWidth(),
|
||||
length = 20,
|
||||
x = cw,
|
||||
y = 35,
|
||||
h = 55,
|
||||
str = strings.ip_button,
|
||||
font = fonts.midFont,
|
||||
}
|
||||
function ti:callback() return self:enterText( browser.joinIPString ) end
|
||||
local headerButtons = {
|
||||
|
||||
|
||||
button{
|
||||
callback = function() return serverList.requestServers() end,
|
||||
text = lg.newText( fonts.midFont, strings.refresh_button ) ,
|
||||
|
@ -113,7 +113,7 @@ for j, headerButton in ipairs( headerButtons ) do
|
|||
end
|
||||
|
||||
function serverList.requestServers()
|
||||
for i = 1, 5 do metaserver.requestServerList() end
|
||||
return metaserver.requestServerList()
|
||||
end
|
||||
|
||||
function serverList.clear( )
|
||||
|
@ -152,14 +152,16 @@ local metaServerHandlers = setmetatable(
|
|||
function serverList.scroll( up )
|
||||
local minY = 170
|
||||
local maxY = lg.getHeight() + 40
|
||||
if up and serverButtons[ #headerButtons + 1 ].y > minY then return end
|
||||
if ( not up ) and serverButtons[ #serverButtons ].y < maxY then return end
|
||||
|
||||
up = ( 27 / 3 ) * ( up and 1 or -1 )
|
||||
for i = #headerButtons + 1, #serverButtons do
|
||||
local sb = serverButtons[i]
|
||||
sb.y = sb.y + up
|
||||
sb.active = ( sb.y > minY ) and ( sb.y < maxY )
|
||||
if #serverButtons > #headerButtons then
|
||||
if up and serverButtons[ #headerButtons + 1 ].y > minY then return end
|
||||
if ( not up ) and serverButtons[ #serverButtons ].y < maxY then return end
|
||||
|
||||
up = ( 27 / 3 ) * ( up and 1 or -1 )
|
||||
for i = #headerButtons + 1, #serverButtons do
|
||||
local sb = serverButtons[i]
|
||||
sb.y = sb.y + up
|
||||
sb.active = ( sb.y > minY ) and ( sb.y < maxY )
|
||||
end
|
||||
end
|
||||
return serverList:paint()
|
||||
end
|
||||
|
@ -195,7 +197,7 @@ end
|
|||
|
||||
function browser.resize( x, y )
|
||||
serverList.resize( x, y )
|
||||
|
||||
|
||||
for i, button in ipairs( serverButtons ) do
|
||||
button.w = x
|
||||
end
|
||||
|
@ -223,21 +225,21 @@ function browser.joinIP( ip, port )
|
|||
end
|
||||
|
||||
function browser.keypressed( key, code, isRepeat )
|
||||
|
||||
|
||||
local y = serverList.getSelectedButton()
|
||||
|
||||
|
||||
if code == "escape" then return scene.mainmenu() end
|
||||
|
||||
|
||||
if y and code == "down" and y.y > lg.getHeight() - 100 then
|
||||
for i = 1, 3 do serverList.scroll( false ) end
|
||||
end
|
||||
|
||||
|
||||
if y and code == "up" and y.y > 180 and y.y < 250 then
|
||||
for i = 1, 3 do serverList.scroll( true ) end
|
||||
end
|
||||
|
||||
|
||||
return serverList.keypressed( key, code, isRepeat )
|
||||
|
||||
|
||||
end
|
||||
|
||||
scene.browser = browser
|
||||
|
|
|
@ -42,11 +42,13 @@ return menu.new{
|
|||
},
|
||||
|
||||
bg = lg.newMesh{
|
||||
{ 0, 0, 0, 0, 0.4, 0.05, 0.0, 0.1 },
|
||||
{ 1, 0, 1, 0, 0.8, 0.3, 0.1, 0.8 },
|
||||
{ 1, 1, 1, 1, 0.7, 0.4, 0.1, 0.8 },
|
||||
{ 0, 1, 0, 1, 0.4, 0.05, 0.05, 0.1 },
|
||||
{ 0, 0, 0, 0, 1, 1, 1, 0.01 },
|
||||
{ 1, 0, 1, 0, 1, 1, 1, 0.1 },
|
||||
{ 1, 1, 1, 1, 0, 0, 0, 0.1 },
|
||||
{ 0, 1, 0, 1, 0, 0, 0, 0.01 },
|
||||
},
|
||||
|
||||
font = lg.newFont( "client/assets/fonts/Montserrat-Bold.ttf", 48 )
|
||||
font = font,
|
||||
|
||||
wheelmoved = function( x, y ) return ( y ~= 0 ) and love.keypressed( nil, (y > 0) and "up" or "down" ) end
|
||||
}
|
|
@ -62,7 +62,6 @@ local optionsMenu = menu.new{
|
|||
{ 0, 1, 0, 1, 0.4, 0.1, 0.03, 0.0 },
|
||||
},
|
||||
|
||||
|
||||
bg = lg.newMesh{
|
||||
{ 0, 0, 0, 0, 1, 1, 1, 0.01 },
|
||||
{ 1, 0, 1, 0, 1, 1, 1, 0.1 },
|
||||
|
|
|
@ -24,9 +24,7 @@ local handlers = setmetatable({
|
|||
if not servers[ip] then servers[ip] = { ip = ip, port = port, info = svInfo } end
|
||||
servers[ip].time = t
|
||||
packet.advertised{ time = t }
|
||||
|
||||
local p = packet.get()
|
||||
for i = 1, 10 do udp:sendto( p, ip, port ) end
|
||||
return udp:sendto( packet.get(), ip, port )
|
||||
end,
|
||||
|
||||
default = function( s, ip, port )
|
||||
|
@ -42,7 +40,7 @@ local handlers = setmetatable({
|
|||
return print( ip, port, "Client IP mismatch:", clientInfo.ip )
|
||||
end]]
|
||||
|
||||
print( "Client requested server list: ", ip, port )
|
||||
print( "Server List:", ip, port )
|
||||
|
||||
clients[ip] = clients[ip] or {}
|
||||
|
||||
|
@ -50,12 +48,12 @@ local handlers = setmetatable({
|
|||
clients[ip].time = t
|
||||
|
||||
packet.heartbeat{ tick = tick }
|
||||
for ip, server in pairs( servers ) do
|
||||
for svIP, server in pairs( servers ) do
|
||||
print( "", svIP, packet.getString( server.info.svname ))
|
||||
packet.serverInfo( server.info )
|
||||
end
|
||||
|
||||
local p = packet.get()
|
||||
for i = 1, 10 do udp:sendto( p, ip, port ) end
|
||||
return udp:sendto( packet.get(), ip, port )
|
||||
end
|
||||
},
|
||||
|
|
@ -16,6 +16,10 @@ local svInfo = packet.serverInfo{ version = 13,
|
|||
|
||||
local server = {
|
||||
tick = 0,
|
||||
|
||||
advertised = function()
|
||||
print( "Advertised." )
|
||||
end,
|
||||
}
|
||||
|
||||
local clients = {}
|
||||
|
@ -27,6 +31,7 @@ end
|
|||
|
||||
function server.Advertise()
|
||||
print( "Advertise." )
|
||||
packet.get()
|
||||
packet.metaServer()
|
||||
packet.serverInfo( svInfo )
|
||||
udp:sendto( packet.get() , ms.ip, ms.port )
|
||||
|
@ -59,18 +64,26 @@ end
|
|||
function server.SetIP( ipString, port )
|
||||
svInfo.ip = shared.ip.fromString( ipString )
|
||||
svInfo.port = port
|
||||
if udp:setsockname( ipString, port ) then
|
||||
print( ipString, port )
|
||||
--Find another port.
|
||||
elseif port < 65536 then
|
||||
return server.SetIP( ipString, port + 1 )
|
||||
else
|
||||
print( "Could not use IP: "..ipString )
|
||||
return error( "Connection failed." )
|
||||
end
|
||||
end
|
||||
|
||||
function server.Start()
|
||||
udp = assert( socket.udp() )
|
||||
udp:settimeout(0)
|
||||
server.SetIP( socket.dns.toip(socket.dns.gethostname()), 51312 )
|
||||
assert( udp:setsockname( tostring( svInfo.ip ), svInfo.port ))
|
||||
server.SetIP( shared.myip, 51312 )
|
||||
print( "Server started:", udp:getsockname() )
|
||||
repeat
|
||||
server.Parse( udp:receivefrom() )
|
||||
server.Advance()
|
||||
if server.tick % 20 == 0 then
|
||||
if server.tick % 50 == 0 then
|
||||
server.Advertise()
|
||||
end
|
||||
until socket.sleep( 0.1 )
|
|
@ -0,0 +1 @@
|
|||
return assert(assert( require 'socket.http' ).request 'https://api.ipify.org' )
|
|
@ -6,10 +6,11 @@ shared.ip = assert( require 'shared.ipstring' )
|
|||
shared.packet = assert( require 'shared.packet' )
|
||||
shared.print = assert( require 'shared.print' )
|
||||
shared.metaserver = assert( require 'shared.metaserver' )
|
||||
shared.myip = assert( require 'shared.getip' )
|
||||
|
||||
--Turn on logging?
|
||||
print = shared.print
|
||||
|
||||
print( "My IP: ", shared.myip )
|
||||
|
||||
--World state.
|
||||
local world = {}
|
Loading…
Reference in New Issue