Compare commits

...

2 Commits

7 changed files with 96 additions and 22 deletions

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

@ -1 +0,0 @@
Subproject commit 88246d621abf7b6fba9332f49229d507f020e450

@ -1 +0,0 @@
Subproject commit 8c2ff7217e2a205eb107a6f48b04ff1b2b3090a1

View File

@ -20,7 +20,8 @@ function connecting.update(dt)
end end
function connecting:onLoad( params ) 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 ) return server.connect( ip, port )
end end

View File

@ -2,21 +2,93 @@ local lg = assert( love.graphics )
local scene = assert( require 'client.scene' ) local scene = assert( require 'client.scene' )
local textInput = assert( require 'client.ui.textinput' ) 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 ipString = assert( require 'shared.ipstring' )
local browser = {} local browser = {}
local serverList = { local font = lg.newFont( "client/assets/fonts/Montserrat-Bold.ttf", 20 )
selected = false,
x = 25, local function populateTestServers()
y = 160, packet.get()
h = 24, packet.serverInfo{
{ name = "test", ip = "192.168.2.150", port = 51312, players = 1, capacity = 64, map = "testMap" }, players = 24,
{ name = "best", ip = "142.154.3.212", port = 21345, players = 2, capacity = 64, map = "nestMap" }, capacity = 255,
{ name = "aest", ip = "123.45.67.89", port = 21253, players = 3, capacity = 32, map = "aestMap" }, 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() 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 end
function serverList.select() function serverList.select()
@ -42,6 +114,7 @@ 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 )
ti:draw() ti:draw()
serverList.draw()
end end
function browser.update( dt ) function browser.update( dt )

View File

@ -1,16 +1,20 @@
package.path = package.path .. ";lib/"
package.cpath = package.path .. ";lib/"
local shared = assert( require 'shared' ) local shared = assert( require 'shared' )
local packet = shared.packet local packet = shared.packet
local socket = assert( require 'socket' ) local socket = assert( require 'socket' )
local udp local udp
local io = assert( io ) local io = assert( io )
local svInfo = { version = 13, local svInfo = packet.serverInfo{ version = 13,
players = 0, players = 0,
capacity = 255, capacity = 255,
ip = shared.ip.fromString( socket.dns.toip(socket.dns.gethostname()) ), ip = shared.ip.fromString( socket.dns.toip(socket.dns.gethostname()) ),
port = 51312, port = 51312,
svname = "New Server", svname = "New Server",
map = "Test Map"} map = "Test Map"
}
local server = { tick = 0 } local server = { tick = 0 }
@ -36,7 +40,7 @@ end
function server.Advertise() function server.Advertise()
print( socket.gettime(), "Advertise." ) print( socket.gettime(), "Advertise." )
packet.metaServer{ padding = "" } packet.metaServer()
packet.serverInfo( svInfo ) packet.serverInfo( svInfo )
udp:sendto( packet.get() , msIP, msPort ) udp:sendto( packet.get() , msIP, msPort )
end end

View File

@ -44,7 +44,6 @@ newStruct{
newStruct{ newStruct{
name = "heartbeat", name = "heartbeat",
netname = 69, netname = 69,
"uint16_t protocol",
"uint32_t tick", "uint32_t tick",
"uint32_t hash", "uint32_t hash",
} }
@ -133,7 +132,7 @@ function packet.add( struct, data )
local str = ffi.new( struct.ct, data or 0 ) local str = ffi.new( struct.ct, data or 0 )
str.netname = assert( struct.netname ) str.netname = assert( struct.netname )
writeBuffer:putcdata( str, struct.size ) writeBuffer:putcdata( str, struct.size )
return writeBuffer return str
end end
function packet.get() function packet.get()