diff --git a/lib/lua54 b/lib/lua54 deleted file mode 160000 index 88246d6..0000000 --- a/lib/lua54 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 88246d621abf7b6fba9332f49229d507f020e450 diff --git a/lib/luasocket b/lib/luasocket deleted file mode 160000 index 8c2ff72..0000000 --- a/lib/luasocket +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 8c2ff7217e2a205eb107a6f48b04ff1b2b3090a1 diff --git a/src/client/connecting.lua b/src/client/connecting.lua index 562524e..7ec58c4 100644 --- a/src/client/connecting.lua +++ b/src/client/connecting.lua @@ -20,7 +20,8 @@ function connecting.update(dt) end function connecting:onLoad( params ) - local ip, port = assert( params, "No IP address specified!" ).ip, params.port + params = params or { ip = "127.0.0.0", port = 8 } + local ip, port = params.ip, params.port return server.connect( ip, port ) end diff --git a/src/client/ui/browser.lua b/src/client/ui/browser.lua index d6093c3..49708a7 100644 --- a/src/client/ui/browser.lua +++ b/src/client/ui/browser.lua @@ -2,25 +2,97 @@ local lg = assert( love.graphics ) local scene = assert( require 'client.scene' ) local textInput = assert( require 'client.ui.textinput' ) local button = assert( require 'client.ui.button' ) +local packet = assert( require 'shared.packet' ) +local ipString = assert( require 'shared.ipstring' ) local browser = {} -local serverList = { - selected = false, - x = 25, - y = 160, - h = 24, - { name = "test", ip = "192.168.2.150", port = 51312, players = 1, capacity = 64, map = "testMap" }, - { name = "best", ip = "142.154.3.212", port = 21345, players = 2, capacity = 64, map = "nestMap" }, - { name = "aest", ip = "123.45.67.89", port = 21253, players = 3, capacity = 32, map = "aestMap" }, +local font = lg.newFont( "client/assets/fonts/Montserrat-Bold.ttf", 20 ) + +local function populateTestServers() + packet.get() + packet.serverInfo{ + players = 24, + capacity = 255, + ip = ipString.new{ 123, 456, 789, 101 }, + port = 51312, + version = 25, + svname = "test server", + map = "testMap_01", + } + packet.serverInfo{ + players = 24, + capacity = 255, + ip = ipString.new{ 123, 456, 789, 101 }, + port = 51312, + version = 25, + svname = "test server", + map = "testMap_02", + } + packet.serverInfo{ + players = 24, + capacity = 255, + ip = ipString.new{ 150, 645, 151, 67 }, + port = 51312, + version = 25, + svname = "test server", + map = "testMap_03", + } + packet.serverInfo{ + players = 24, + capacity = 255, + ip = ipString.new{ 123, 456, 789, 101 }, + port = 51312, + version = 25, + svname = "test server", + map = "testMap_01", + } + return packet.deserialise( packet.get() ) +end +local serverList = {} +serverList.servers = populateTestServers() +serverList.offsets = { + 15, + 50, + 150, + 100, + 100, + 50, + 50 } +serverList.selected = false +serverList.x = 25 +serverList.y = 220 +serverList.h = 36 + function serverList.draw() - - + local gs = packet.getString + local x, y, h = serverList.x, serverList.y, serverList.h + local oldFont = lg.getFont() + lg.setFont( font ) + for i, svInfo in ipairs( serverList.servers ) do + lg.setColor( 0.7, 0.7, 0.7, 0.7 ) + lg.rectangle( "fill", x, y, 800, h, 5, 5 ) + + x = x + 15 + y = y + 9 + lg.setColor( 0, 0, 0, 0.7 ) + lg.print( svInfo.version, x, y ) + lg.print( gs( svInfo.svname ), 50 + x, y ) + lg.print( tostring( svInfo.ip ), 200 + x, y ) + lg.print( svInfo.port, 300 + x, y ) + lg.print( svInfo.players, 400 + x, y ) + lg.print( svInfo.capacity, 450 + x, y ) + lg.print( gs( svInfo.map ), 500 + x, y ) + y = y - 12 + x = x - 15 + y = y + h + 5 + end + lg.setFont( oldFont ) end function serverList.select() - + end function serverList.up() @@ -42,10 +114,11 @@ function browser.draw() lg.setColor( 1, 1, 1, 1 ) lg.print( "Server Browser", 15, 115 ) ti:draw() + serverList.draw() end function browser.update( dt ) - + end function browser.onLoad( ) @@ -62,7 +135,7 @@ function browser.joinIPString( s ) if not s then return end ti:clear() local valid, ip, port - + if valid then return browser.joinIP( ip, port ) end end diff --git a/src/server.lua b/src/server.lua index 6913ba7..a3f87c3 100644 --- a/src/server.lua +++ b/src/server.lua @@ -1,16 +1,20 @@ +package.path = package.path .. ";lib/" +package.cpath = package.path .. ";lib/" + local shared = assert( require 'shared' ) local packet = shared.packet local socket = assert( require 'socket' ) local udp local io = assert( io ) -local svInfo = { version = 13, +local svInfo = packet.serverInfo{ version = 13, players = 0, capacity = 255, ip = shared.ip.fromString( socket.dns.toip(socket.dns.gethostname()) ), port = 51312, svname = "New Server", - map = "Test Map"} + map = "Test Map" +} local server = { tick = 0 } @@ -36,7 +40,7 @@ end function server.Advertise() print( socket.gettime(), "Advertise." ) - packet.metaServer{ padding = "" } + packet.metaServer() packet.serverInfo( svInfo ) udp:sendto( packet.get() , msIP, msPort ) end diff --git a/src/shared/packet.lua b/src/shared/packet.lua index 67f6d4e..408a7aa 100644 --- a/src/shared/packet.lua +++ b/src/shared/packet.lua @@ -44,7 +44,6 @@ newStruct{ newStruct{ name = "heartbeat", netname = 69, - "uint16_t protocol", "uint32_t tick", "uint32_t hash", } @@ -133,7 +132,7 @@ function packet.add( struct, data ) local str = ffi.new( struct.ct, data or 0 ) str.netname = assert( struct.netname ) writeBuffer:putcdata( str, struct.size ) - return writeBuffer + return str end function packet.get()