Server browser functionality.
This commit is contained in:
parent
dc6cdf123e
commit
e6b9e7aa13
27
build.sh
27
build.sh
|
@ -1,10 +1,33 @@
|
||||||
|
#get locations of scripts, libraries, engine
|
||||||
SRC_DIR="src"
|
SRC_DIR="src"
|
||||||
|
LIB_DIR="lib"
|
||||||
LOVE_DIR="../../love"
|
LOVE_DIR="../../love"
|
||||||
BUILD_DIR="build"
|
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/
|
cp -r $SRC_DIR/ $BUILD_DIR/
|
||||||
cd $BUILD_DIR/
|
cd $BUILD_DIR/
|
||||||
zip -9 -r vision.love
|
zip -9 -r vision.love
|
||||||
|
|
||||||
cat ../../love/love.exe vision.love > vision.exe
|
#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
|
|
@ -11,7 +11,7 @@ return {
|
||||||
chat = "t",
|
chat = "t",
|
||||||
love = "q",
|
love = "q",
|
||||||
hate = "e",
|
hate = "e",
|
||||||
}
|
},
|
||||||
serverIP = "192.168.2.15",
|
serverIP = "192.168.2.15",
|
||||||
serverPort = 51312,
|
serverPort = 51312,
|
||||||
}
|
}
|
|
@ -6,7 +6,7 @@ local connecting = {}
|
||||||
local time, ip, port = 0
|
local time, ip, port = 0
|
||||||
|
|
||||||
function connecting.draw()
|
function connecting.draw()
|
||||||
lg.print( "Connecting to server:\t"..time, 0, 0, 0 )
|
lg.print( ("CONNECTING:\nTIME: %1.1fs\nADDRESS: %s:%d"):format(time, ip, port), 0, 0, 0 )
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -20,8 +20,10 @@ function connecting.update(dt)
|
||||||
end
|
end
|
||||||
|
|
||||||
function connecting:onLoad( params )
|
function connecting:onLoad( params )
|
||||||
params = params or { ip = "127.0.0.0", port = 8 }
|
print( "connecting:", params, self.ip, self.port )
|
||||||
local ip, port = params.ip, params.port
|
for k, v in pairs( self ) do print( k,v ) end
|
||||||
|
params = params or { ip = "8.8.8.8", port = 8 }
|
||||||
|
ip, port = params.ip, params.port
|
||||||
return server.connect( ip, port )
|
return server.connect( ip, port )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,6 @@ function game.disconnect( )
|
||||||
end
|
end
|
||||||
|
|
||||||
function game.onLoad( params )
|
function game.onLoad( params )
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function game.keypressed( key, code, isRepeat )
|
function game.keypressed( key, code, isRepeat )
|
||||||
|
|
|
@ -4,6 +4,7 @@ local textInput = assert( require 'client.ui.textinput' )
|
||||||
local button = assert( require 'client.ui.button' )
|
local button = assert( require 'client.ui.button' )
|
||||||
local packet = assert( require 'shared.packet' )
|
local packet = assert( require 'shared.packet' )
|
||||||
local ipString = assert( require 'shared.ipstring' )
|
local ipString = assert( require 'shared.ipstring' )
|
||||||
|
local menu = assert( require 'client.ui.menu' )
|
||||||
local browser = {}
|
local browser = {}
|
||||||
|
|
||||||
local font = lg.newFont( "client/assets/fonts/Montserrat-Bold.ttf", 20 )
|
local font = lg.newFont( "client/assets/fonts/Montserrat-Bold.ttf", 20 )
|
||||||
|
@ -20,7 +21,7 @@ local function populateTestServers()
|
||||||
map = "testMap_01",
|
map = "testMap_01",
|
||||||
}
|
}
|
||||||
packet.serverInfo{
|
packet.serverInfo{
|
||||||
players = 24,
|
players = 8,
|
||||||
capacity = 255,
|
capacity = 255,
|
||||||
ip = ipString.new{ 123, 456, 789, 101 },
|
ip = ipString.new{ 123, 456, 789, 101 },
|
||||||
port = 51312,
|
port = 51312,
|
||||||
|
@ -29,8 +30,8 @@ local function populateTestServers()
|
||||||
map = "testMap_02",
|
map = "testMap_02",
|
||||||
}
|
}
|
||||||
packet.serverInfo{
|
packet.serverInfo{
|
||||||
players = 24,
|
players = 14,
|
||||||
capacity = 255,
|
capacity = 64,
|
||||||
ip = ipString.new{ 150, 645, 151, 67 },
|
ip = ipString.new{ 150, 645, 151, 67 },
|
||||||
port = 51312,
|
port = 51312,
|
||||||
version = 25,
|
version = 25,
|
||||||
|
@ -48,7 +49,24 @@ local function populateTestServers()
|
||||||
}
|
}
|
||||||
return packet.deserialise( packet.get() )
|
return packet.deserialise( packet.get() )
|
||||||
end
|
end
|
||||||
local serverList = {}
|
local function joinServerCallback( button )
|
||||||
|
if button.ip and button.port then return browser.joinIP( button.ip, button.port ) end
|
||||||
|
end
|
||||||
|
|
||||||
|
local serverButtons = populateTestServers()
|
||||||
|
for i, server in ipairs( serverButtons ) do
|
||||||
|
serverButtons[i] = button{
|
||||||
|
ip = tostring( server.ip ),
|
||||||
|
port = server.port,
|
||||||
|
text = tostring( server.ip ),
|
||||||
|
callback = joinServerCallback}
|
||||||
|
end
|
||||||
|
local serverList = menu.new( "serverList",
|
||||||
|
serverButtons,
|
||||||
|
nil,
|
||||||
|
nil,
|
||||||
|
nil,
|
||||||
|
true )
|
||||||
serverList.servers = populateTestServers()
|
serverList.servers = populateTestServers()
|
||||||
serverList.offsets = {
|
serverList.offsets = {
|
||||||
15,
|
15,
|
||||||
|
@ -65,7 +83,7 @@ serverList.x = 25
|
||||||
serverList.y = 220
|
serverList.y = 220
|
||||||
serverList.h = 36
|
serverList.h = 36
|
||||||
|
|
||||||
function serverList.draw()
|
--[[function serverList.draw()
|
||||||
local gs = packet.getString
|
local gs = packet.getString
|
||||||
local x, y, h = serverList.x, serverList.y, serverList.h
|
local x, y, h = serverList.x, serverList.y, serverList.h
|
||||||
local oldFont = lg.getFont()
|
local oldFont = lg.getFont()
|
||||||
|
@ -89,7 +107,7 @@ function serverList.draw()
|
||||||
y = y + h + 5
|
y = y + h + 5
|
||||||
end
|
end
|
||||||
lg.setFont( oldFont )
|
lg.setFont( oldFont )
|
||||||
end
|
end]]
|
||||||
|
|
||||||
function serverList.select()
|
function serverList.select()
|
||||||
|
|
||||||
|
@ -110,6 +128,8 @@ local ti = textInput.new{
|
||||||
y = 175
|
y = 175
|
||||||
}
|
}
|
||||||
|
|
||||||
|
browser.selected = false
|
||||||
|
|
||||||
function browser.draw()
|
function browser.draw()
|
||||||
lg.setColor( 1, 1, 1, 1 )
|
lg.setColor( 1, 1, 1, 1 )
|
||||||
lg.print( "Server Browser", 15, 115 )
|
lg.print( "Server Browser", 15, 115 )
|
||||||
|
@ -122,26 +142,29 @@ function browser.update( dt )
|
||||||
end
|
end
|
||||||
|
|
||||||
function browser.onLoad( )
|
function browser.onLoad( )
|
||||||
|
serverList:onLoad()
|
||||||
lg.setColor( 1, 1, 1, 1 )
|
lg.setColor( 1, 1, 1, 1 )
|
||||||
end
|
end
|
||||||
|
|
||||||
function browser.mousepressed(x, y, button, istouch, pressed)
|
function browser.mousepressed(x, y, button, istouch, pressed)
|
||||||
if ti:contains( x, y ) then return ti:enterText( browser.joinIPString ) end
|
if ti:contains( x, y ) then return ti:enterText( browser.joinIPString ) end
|
||||||
|
return serverList.mousepressed( x, y, button, istouch, pressed )
|
||||||
end
|
end
|
||||||
|
|
||||||
function browser.joinIPString( s )
|
function browser.joinIPString( s )
|
||||||
--Parse IP address and port from string. If it's valid, join the server.
|
--Parse IP address and port from string. If it's valid, join the server.
|
||||||
print( "browser: Attempting to join server", s )
|
print( "browser: entered IP and port", s )
|
||||||
if not s then return end
|
if not s then return end
|
||||||
ti:clear()
|
ti:clear()
|
||||||
local valid, ip, port
|
local ip, port = s:match '(%d+%.%d+%.%d+%.%d+)', s:match ':(%d+)'
|
||||||
|
print( "browser:", "ip:", ip, port )
|
||||||
|
|
||||||
if valid then return browser.joinIP( ip, port ) end
|
if ip and port then return browser.joinIP( ip, port ) end
|
||||||
end
|
end
|
||||||
|
|
||||||
function browser.joinIP( ip, port )
|
function browser.joinIP( ip, port )
|
||||||
print( "Joining server:", ip, port )
|
print( "Joining server:", ip, port )
|
||||||
return scene.game{ serverIP = ip, serverPort = port }
|
return scene.loadScene( scene.connecting, { ip = ip, port = port } )
|
||||||
end
|
end
|
||||||
|
|
||||||
function browser.keypressed( key, code, isRepeat )
|
function browser.keypressed( key, code, isRepeat )
|
||||||
|
|
|
@ -14,7 +14,7 @@ return menu.new(
|
||||||
x = 15, w = lg.getWidth(), y = 115, h = 72,
|
x = 15, w = lg.getWidth(), y = 115, h = 72,
|
||||||
text = strings.newgame_button,
|
text = strings.newgame_button,
|
||||||
color = { 0.6, 0.6, 0.6, 0.9 },
|
color = { 0.6, 0.6, 0.6, 0.9 },
|
||||||
callback = function() return scene.connecting() end },
|
callback = function() return scene.connecting{ip = "127.0.0.0", port = 8} end },
|
||||||
|
|
||||||
button{
|
button{
|
||||||
text = strings.join_button,
|
text = strings.join_button,
|
||||||
|
|
|
@ -10,10 +10,13 @@ local canvas
|
||||||
local wWidth, wHeight
|
local wWidth, wHeight
|
||||||
local currentMenu
|
local currentMenu
|
||||||
|
|
||||||
function menu.new( name, buttons, fg, bg, font )
|
function menu.new( name, buttons, fg, bg, font, subScene )
|
||||||
local t = { buttons = buttons, fg = fg, bg = bg, font = font or lg.getFont() }
|
local t = { buttons = buttons, fg = fg, bg = bg, font = font or lg.getFont() }
|
||||||
scene[name] = t
|
if subScene then setmetatable( t, t )
|
||||||
print( 'scene', scene )
|
else
|
||||||
|
scene[name] = t
|
||||||
|
print( 'scene', scene )
|
||||||
|
end
|
||||||
getmetatable( t ).__index = menu
|
getmetatable( t ).__index = menu
|
||||||
return t
|
return t
|
||||||
end
|
end
|
||||||
|
@ -21,7 +24,7 @@ end
|
||||||
function menu:onLoad()
|
function menu:onLoad()
|
||||||
print( 'loading:', self.name )
|
print( 'loading:', self.name )
|
||||||
currentMenu = self
|
currentMenu = self
|
||||||
lg.setFont( self.font )
|
if self.font then lg.setFont( self.font ) end
|
||||||
return menu.resize( lg.getDimensions() )
|
return menu.resize( lg.getDimensions() )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -42,7 +45,7 @@ end
|
||||||
function menu.mousemoved( x, y, dx, dy, istouch )
|
function menu.mousemoved( x, y, dx, dy, istouch )
|
||||||
if not currentMenu then return end
|
if not currentMenu then return end
|
||||||
local buttons = currentMenu.buttons
|
local buttons = currentMenu.buttons
|
||||||
|
|
||||||
local selectedButton = buttons[selectedButtonIdx or 0]
|
local selectedButton = buttons[selectedButtonIdx or 0]
|
||||||
for id, menuButton in ipairs( buttons ) do
|
for id, menuButton in ipairs( buttons ) do
|
||||||
if menuButton:contains( x, y ) then
|
if menuButton:contains( x, y ) then
|
||||||
|
@ -77,13 +80,13 @@ function menu.mousepressed( x, y, button, istouch, presses )
|
||||||
end
|
end
|
||||||
|
|
||||||
function menu.keypressed( key, code, isrepeat )
|
function menu.keypressed( key, code, isrepeat )
|
||||||
|
|
||||||
assert( currentMenu )
|
assert( currentMenu )
|
||||||
|
|
||||||
if code == "escape" then
|
if code == "escape" then
|
||||||
return love.event.quit()
|
return love.event.quit()
|
||||||
end
|
end
|
||||||
|
|
||||||
local buttons = currentMenu.buttons
|
local buttons = currentMenu.buttons
|
||||||
|
|
||||||
if code == "return" and selectedButtonIdx then
|
if code == "return" and selectedButtonIdx then
|
||||||
|
@ -117,7 +120,9 @@ function menu:paint()
|
||||||
|
|
||||||
--bg
|
--bg
|
||||||
lg.setColor( 1, 1, 1, 1 )
|
lg.setColor( 1, 1, 1, 1 )
|
||||||
lg.draw( self.bg, 0, 0, 0, wWidth, wHeight )
|
if self.bg then
|
||||||
|
lg.draw( self.bg, 0, 0, 0, wWidth, wHeight )
|
||||||
|
end
|
||||||
|
|
||||||
--buttons
|
--buttons
|
||||||
for i = #self.buttons, 1, -1 do self.buttons[i]:draw( ) end
|
for i = #self.buttons, 1, -1 do self.buttons[i]:draw( ) end
|
||||||
|
@ -127,12 +132,14 @@ function menu:paint()
|
||||||
local r = math.random
|
local r = math.random
|
||||||
local v = r() * 0.4 + 0.6
|
local v = r() * 0.4 + 0.6
|
||||||
|
|
||||||
local fg = self.fg
|
if self.fg then
|
||||||
fg:setVertexAttribute( 2, 3, v * (0.7 + 0.2 * r()), v * (0.1 + 0.4 * r()), v * (0.1 * r()), 1 )
|
local fg = self.fg
|
||||||
fg:setVertexAttribute( 1, 3, 0.3 * ( 1 - v ), 0, 0, 0.4 * (1 - v) )
|
fg:setVertexAttribute( 2, 3, v * (0.7 + 0.2 * r()), v * (0.1 + 0.4 * r()), v * (0.1 * r()), 1 )
|
||||||
fg:setVertexAttribute( 4, 3, 0.3 * ( 1 - v ), 0, 0, 0.4 * (1 - v) )
|
fg:setVertexAttribute( 1, 3, 0.3 * ( 1 - v ), 0, 0, 0.4 * (1 - v) )
|
||||||
fg:setVertexAttribute( 3, 3, v * (0.7 + 0.2 * r()), v * (0.1 + 0.4 * r()), v * (0.1 * r()), 1 )
|
fg:setVertexAttribute( 4, 3, 0.3 * ( 1 - v ), 0, 0, 0.4 * (1 - v) )
|
||||||
lg.draw( fg, 0, 0, 0, wWidth, wHeight )
|
fg:setVertexAttribute( 3, 3, v * (0.7 + 0.2 * r()), v * (0.1 + 0.4 * r()), v * (0.1 * r()), 1 )
|
||||||
|
lg.draw( fg, 0, 0, 0, wWidth, wHeight )
|
||||||
|
end
|
||||||
lg.setCanvas()
|
lg.setCanvas()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,6 @@ function server.Start()
|
||||||
udp:settimeout(0)
|
udp:settimeout(0)
|
||||||
server.SetIP( socket.dns.toip(socket.dns.gethostname()), 51312 )
|
server.SetIP( socket.dns.toip(socket.dns.gethostname()), 51312 )
|
||||||
assert( udp:setsockname( tostring( svInfo.ip ), svInfo.port ))
|
assert( udp:setsockname( tostring( svInfo.ip ), svInfo.port ))
|
||||||
server.StartLocalClient()
|
|
||||||
print( socket.gettime(), "Start." )
|
print( socket.gettime(), "Start." )
|
||||||
repeat
|
repeat
|
||||||
server.Parse( udp:receivefrom() )
|
server.Parse( udp:receivefrom() )
|
||||||
|
|
Loading…
Reference in New Issue