Compare commits

...

2 Commits

24 changed files with 313 additions and 168 deletions

6
all.bat Normal file
View File

@ -0,0 +1,6 @@
call build.bat
pushd "%~dp0\build\"
start server.bat
start client.bat
start metaserver.bat
popd

3
build.bat Normal file
View File

@ -0,0 +1,3 @@
@echo on
robocopy src build /E
pause

View File

@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

View File

@ -11,7 +11,7 @@ function love.conf(t)
t.audio.mixwithsystem = true -- Keep background music playing when opening LOVE (boolean, iOS and Android only)
t.window.title = "vision-dajjal" -- The window title (string)
t.window.icon = "client/assets/client-icon.png" -- Filepath to an image to use as the window's icon (string)
t.window.icon = "assets/client-icon.png" -- Filepath to an image to use as the window's icon (string)
t.window.width = 800 -- The window width (number)
t.window.height = 600 -- The window height (number)
t.window.borderless = false -- Remove all border visuals from the window (boolean)

View File

@ -1,31 +1,58 @@
local config = {}
local config
local lfs = assert( love ).filesystem
local cfg = lfs.newFile "cfg.lua"
local mt = { __tostring = function( t )
local arr = { "tblOption{\n ",}
for k, v in pairs( t ) do
arr[#arr + 1] = k
arr[#arr + 1] = " = "
arr[#arr + 1] = tostring( v )
arr[#arr + 1] = ",\n "
end
arr[#arr + 1] = "}"
return table.concat( arr )
end }
local function tblOption(t)
return setmetatable( t, mt )
end
local defaultConfig = {
plName = "Player Name",
plPronoun = "they/them/their",
plR = 0.8,
plG = 0.4,
plB = 0.4,
plPronoun = tblOption{
subject = "they",
object = "them",
possessive = "their",
},
plColour = tblOption{ 0.5, 0.6, 0.7, 0.5 },
gamma = 0.5,
keyForward = "w",
keyBack = "s",
keyLeft = "a",
keyRight = "d",
keyChat = "t",
keyLove = "q",
keyHate = "e",
keybinds = tblOption{
Forward = "w",
Back = "s",
Left = "a",
Right = "d",
Chat = "t",
Love = "q",
Hate = "e",
},
serverIP = "192.168.2.15",
serverPort = 51312,
logFile = "../logs/log.txt",
logFile = "log.txt",
}
local function readConfigFile()
return dofile( "./cfg.lua" ) or defaultConfig
local ok, cfgTbl, err = pcall( lfs.load, 'cfg.lua' )
if ok and cfgTbl then
local ok, err = pcall( cfgTbl )
if err then print( "Failed to load settings file: ", err ) end
return
end
return defaultConfig
end
local function dumpConfigFile()
print( "Saving Settings." )
local cfg = assert(io.open( "./cfg.lua", "w" ))
assert( cfg:open 'w' )
cfg:write( "return {\n " )
for k, v in pairs( config ) do
cfg:write( k )
@ -36,4 +63,6 @@ local function dumpConfigFile()
cfg:write( "}" )
end
config = readConfigFile()
return config

View File

@ -1,8 +1,8 @@
local scene = assert( require 'client.scene' )
local scene = assert( require 'scene' )
local lg = assert( love.graphics )
local server = assert( require 'client.udp' )
local button = assert( require 'client.ui.button' )
local strings = assert( require 'client.strings' )
local server = assert( require 'udp' )
local button = assert( require 'ui.button' )
local strings = assert( require 'strings' )
local connecting = {}
local time, ip, port, attempts = 0, 0, 0, 0

View File

@ -1,7 +1,7 @@
local crepuscular = {}
local lg = assert( love.graphics )
local shader = assert( lg.newShader( 'client/assets/glsl/crepuscular' ))
local scene = assert( require( 'client.scene' ) )
local shader = assert( lg.newShader( 'assets/glsl/crepuscular' ))
local scene = assert( require( 'scene' ) )
local rectanglePosition = { }
function crepuscular.draw()

View File

@ -1,9 +1,9 @@
local lg = assert( love.graphics )
local scene = assert( require 'client.scene' )
local shared = assert( require 'shared' )
local server = assert( require 'client.udp' )
local scene = assert( require 'scene' )
local shared = assert( require 'shared.shared' )
local server = assert( require 'udp' )
local packet = shared.packet
local crepuscular = assert( require 'client.crepuscular' )
local crepuscular = assert( require 'crepuscular' )
local game = {}
local t = 0

28
src/client/main.lua Normal file
View File

@ -0,0 +1,28 @@
package.cpath = "..\\?.dll;..\\clib\\?.dll;"..package.cpath
package.path = "..\\?.lua;..\\lualib\\?.lua;"..package.path
local shared = assert( require 'shared.shared' )
local love = assert( love )
function love.load()
print( "Client Started." )
assert( require 'config' )
--Crash if running luajit 2.1 and coconut missing
--[[loadstring( love.data.decode( "string", "base64","G0xKAgrbAQAACgALABY2AAAAOQABADkAAgAnAgMAJwMEADYEAAA5BAEEOQQFBCcGBgA2BwAAOQcHBzkHCAcnCQkAQgcCAEEEAQBBAAICBgAKAFgAAoArAAEAWAEBgCsAAgBMAAIALWQ4MmY3M2RkNjQ1MDcxNDZiNTkwNTMwYjg0NDcwMWZlMmJmYjdjZTkeY2xpZW50L2Fzc2V0cy9jb2NvbnV0LnBuZxFuZXdJbWFnZURhdGEKaW1hZ2UJc2hhMQloYXNoCGhleAtzdHJpbmcLZW5jb2RlCWRhdGEJbG92ZV0BAAUABQAONgAAADMCAQBCAAICDgAAAFgBB4A2AAIANAIAADUDAwA2BAAAPQQEA0IAAwJCAAECMgAAgEwAAgALX19jYWxsAQAAEXNldG1ldGF0YWJsZQAKcGNhbGwA" ))()]]
love.window.setIcon( assert( love.image.newImageData( "assets/client-icon.png" ) ) )
love.graphics.setNewFont( "assets/fonts/Montserrat-Bold.ttf", 48 )
local scenes = assert( require 'scene' )
assert( require 'ui.options' )
assert( require 'ui.browser' )
assert( require 'game' )
assert( require 'ui.mainmenu' )
assert( require 'connecting' )
scenes.loadScene( scenes.mainmenu )
end
function love.quit()
print( "Client Quit." )
end

View File

@ -1,17 +1,17 @@
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 scene = assert( require 'scene' )
local textInput = assert( require 'ui.textinput' )
local button = assert( require 'ui.button' )
local packet = assert( require 'shared.packet' )
local menu = assert( require 'client.ui.menu' )
local strings = assert( require 'client.strings' )
local fonts = assert( require 'client.ui.fonts' )
local metaserver = assert ( require 'client.udp' )
local menu = assert( require 'ui.menu' )
local strings = assert( require 'strings' )
local fonts = assert( require 'ui.fonts' )
local metaserver = assert ( require 'udp' )
local utf8 = assert( require 'utf8' )
local browser = { latest = 0, }
local test = assert( require 'client.test.browser' )
local test = assert( require 'test.browser' )
local font = fonts.font
local cw = fonts.font:getWidth( "w" )
@ -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

View File

@ -3,7 +3,7 @@ local lgnf = love.graphics.newFont
return {
font = lgnf( "client/assets/fonts/Montserrat-Bold.ttf", 14 ),
midFont = lgnf( "client/assets/fonts/Montserrat-Bold.ttf", 24 ),
headerFont = lgnf( "client/assets/fonts/Montserrat-Bold.ttf", 48 )
font = lgnf( "assets/fonts/Montserrat-Bold.ttf", 14 ),
midFont = lgnf( "assets/fonts/Montserrat-Bold.ttf", 24 ),
headerFont = lgnf( "assets/fonts/Montserrat-Bold.ttf", 48 )
}

View File

@ -1,10 +1,10 @@
local lg = assert( love.graphics )
local love = assert( love )
local scene = assert( require 'client.scene' )
local strings = strings or assert( require 'client.assets.strings.english' )
local button = assert( require 'client.ui.button' )
local menu = assert( require 'client.ui.menu' )
local font = assert( require 'client.ui.fonts').headerFont
local scene = assert( require 'scene' )
local strings = strings or assert( require 'strings' )
local button = assert( require 'ui.button' )
local menu = assert( require 'ui.menu' )
local font = assert( require 'ui.fonts').headerFont
return menu.new{
name = "mainmenu",
@ -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
}

View File

@ -1,6 +1,6 @@
local love = assert( love )
local lg = assert( love.graphics )
local scene = assert( require 'client.scene' )
local scene = assert( require 'scene' )
local menu = {}
--Static variables.

View File

@ -1,11 +1,11 @@
local lg = assert( love.graphics )
local love = assert( love )
local scene = assert( require 'client.scene' )
local strings = strings or assert( require 'client.assets.strings.english' )
local button = assert( require 'client.ui.button' )
local menu = assert( require 'client.ui.menu' )
local config = assert( require 'client.config' )
local font = assert( require 'client.ui.fonts' ).midFont
local scene = assert( require 'scene' )
local strings = strings or assert( require 'strings' )
local button = assert( require 'ui.button' )
local menu = assert( require 'ui.menu' )
local config = assert( require 'config' )
local font = assert( require 'ui.fonts' ).midFont
local function editSelectedOption( button )
@ -29,19 +29,19 @@ local optionsMenu = menu.new{
callback = function() return scene.mainmenu() end },
button{
option = 'name',
option = 'plName',
text = lg.newText( font, strings.option_name ),
color = { 0.6, 0.6, 0.6, 0.8 },
callback = editSelectedOption },
button{
option = 'pronoun',
option = 'plPronoun',
text = lg.newText( font, strings.option_pron ),
color = { 0.6, 0.6, 0.6, 0.8 },
callback = editSelectedOption },
button{
option = 'colour',
option = 'plColour',
text = lg.newText( font, strings.option_tint ),
color = { 0.6, 0.6, 0.6, 0.8 },
callback = editSelectedOption },
@ -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 },
@ -77,7 +76,7 @@ do
function optionsMenu:paint()
local selected = self.getSelectedButton()
local optionName = selected and selected.option
if optionName then self.buttons[1].text:set( optionName ) end
self.buttons[1].text:set( optionName and tostring( config[optionName] ) or "")
return op( self )
end
end

View File

@ -1,26 +0,0 @@
local shared = assert( require 'shared' )
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" ))()
love.window.setIcon( assert( love.image.newImageData( "client/assets/client-icon.png" ) ) )
love.graphics.setNewFont( "client/assets/fonts/Montserrat-Bold.ttf", 48 )
local scenes = assert( require 'client.scene' )
assert( require 'client.ui.options' )
assert( require 'client.ui.browser' )
assert( require 'client.game' )
assert( require 'client.ui.mainmenu' )
assert( require 'client.connecting' )
scenes.loadScene( scenes.mainmenu )
end
function love.quit()
print( "Client Quit." )
end

51
src/metaserver/conf.lua Normal file
View File

@ -0,0 +1,51 @@
function love.conf(t)
t.identity = "metaserver" -- The name of the save directory (string)
t.appendidentity = false -- Search files in source directory before save directory (boolean)
t.version = "11.4" -- The LÖVE version this game was made for (string)
t.console = true -- Attach a console (boolean, Windows only)
t.accelerometerjoystick = false -- Enable the accelerometer on iOS and Android by exposing it as a Joystick (boolean)
t.externalstorage = false -- True to save files (and read from the save directory) in external storage on Android (boolean)
t.gammacorrect = false -- Enable gamma-correct rendering, when supported by the system (boolean)
t.audio.mic = false -- Request and use microphone capabilities in Android (boolean)
t.audio.mixwithsystem = true -- Keep background music playing when opening LOVE (boolean, iOS and Android only)
t.window.title = "metaserver" -- The window title (string)
t.window.icon = false -- Filepath to an image to use as the window's icon (string)
t.window.width = 800 -- The window width (number)
t.window.height = 600 -- The window height (number)
t.window.borderless = false -- Remove all border visuals from the window (boolean)
t.window.resizable = true -- Let the window be user-resizable (boolean)
t.window.minwidth = 400 -- Minimum window width if the window is resizable (number)
t.window.minheight = 400 -- Minimum window height if the window is resizable (number)
t.window.fullscreen = false -- Enable fullscreen (boolean)
t.window.fullscreentype = "desktop" -- Choose between "desktop" fullscreen or "exclusive" fullscreen mode (string)
t.window.vsync = 1 -- Vertical sync mode (number)
t.window.msaa = 3 -- The number of samples to use with multi-sampled antialiasing (number)
t.window.depth = nil -- The number of bits per sample in the depth buffer
t.window.stencil = nil -- The number of bits per sample in the stencil buffer
t.window.display = 1 -- Index of the monitor to show the window in (number)
t.window.highdpi = false -- Enable high-dpi mode for the window on a Retina display (boolean)
t.window.usedpiscale = true -- Enable automatic DPI scaling when highdpi is set to true as well (boolean)
t.window.x = nil -- The x-coordinate of the window's position in the specified display (number)
t.window.y = nil -- The y-coordinate of the window's position in the specified display (number)
t.modules.audio = false -- Enable the audio module (boolean)
t.modules.data = true -- Enable the data module (boolean)
t.modules.event = true -- Enable the event module (boolean)
t.modules.font = false -- Enable the font module (boolean)
t.modules.graphics = true -- Enable the graphics module (boolean)
t.modules.image = true -- Enable the image module (boolean)
t.modules.joystick = false -- Enable the joystick module (boolean)
t.modules.keyboard = true -- Enable the keyboard module (boolean)
t.modules.math = true -- Enable the math module (boolean)
t.modules.mouse = true -- Enable the mouse module (boolean)
t.modules.physics = false -- Enable the physics module (boolean)
t.modules.sound = false -- Enable the sound module (boolean)
t.modules.system = true -- Enable the system module (boolean)
t.modules.thread = true -- Enable the thread module (boolean)
t.modules.timer = true -- Enable the timer module (boolean), Disabling it will result 0 delta time in love.update
t.modules.touch = false -- Enable the touch module (boolean)
t.modules.video = false -- Enable the video module (boolean)
t.modules.window = true -- Enable the window module (boolean)
end

3
src/metaserver/getip.lua Normal file
View File

@ -0,0 +1,3 @@
local http = assert( require 'socket.http' )
print( "Retrieving IP: " )
return assert( http.request 'https://api.ipify.org' )

View File

@ -1,7 +1,7 @@
local SERVERTIMEOUT = 30
local CLIENTTIMEOUT = 1
local shared = assert( require 'shared' )
local shared = assert( require '../shared.shared' )
local socket = assert( require 'socket' )
local packet = assert( shared.packet )
local udp = assert( socket.udp() )
@ -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
},
@ -86,9 +84,9 @@ local function prune( t )
end
print( "Starting Metaserver", socket.gettime() )
repeat
function love.update()
read( udp:receivefrom() )
prune( socket.gettime() )
io.flush()
tick = tick + 1
until socket.sleep( 2.0 )
end

51
src/server/conf.lua Normal file
View File

@ -0,0 +1,51 @@
function love.conf(t)
t.identity = "vision-server" -- The name of the save directory (string)
t.appendidentity = false -- Search files in source directory before save directory (boolean)
t.version = "11.4" -- The LÖVE version this game was made for (string)
t.console = true -- Attach a console (boolean, Windows only)
t.accelerometerjoystick = true -- Enable the accelerometer on iOS and Android by exposing it as a Joystick (boolean)
t.externalstorage = false -- True to save files (and read from the save directory) in external storage on Android (boolean)
t.gammacorrect = false -- Enable gamma-correct rendering, when supported by the system (boolean)
t.audio.mic = false -- Request and use microphone capabilities in Android (boolean)
t.audio.mixwithsystem = true -- Keep background music playing when opening LOVE (boolean, iOS and Android only)
t.window.title = "vision-server" -- The window title (string)
t.window.icon = false -- Filepath to an image to use as the window's icon (string)
t.window.width = 800 -- The window width (number)
t.window.height = 600 -- The window height (number)
t.window.borderless = false -- Remove all border visuals from the window (boolean)
t.window.resizable = true -- Let the window be user-resizable (boolean)
t.window.minwidth = 400 -- Minimum window width if the window is resizable (number)
t.window.minheight = 400 -- Minimum window height if the window is resizable (number)
t.window.fullscreen = false -- Enable fullscreen (boolean)
t.window.fullscreentype = "desktop" -- Choose between "desktop" fullscreen or "exclusive" fullscreen mode (string)
t.window.vsync = 1 -- Vertical sync mode (number)
t.window.msaa = 3 -- The number of samples to use with multi-sampled antialiasing (number)
t.window.depth = nil -- The number of bits per sample in the depth buffer
t.window.stencil = nil -- The number of bits per sample in the stencil buffer
t.window.display = 1 -- Index of the monitor to show the window in (number)
t.window.highdpi = false -- Enable high-dpi mode for the window on a Retina display (boolean)
t.window.usedpiscale = true -- Enable automatic DPI scaling when highdpi is set to true as well (boolean)
t.window.x = nil -- The x-coordinate of the window's position in the specified display (number)
t.window.y = nil -- The y-coordinate of the window's position in the specified display (number)
t.modules.audio = true -- Enable the audio module (boolean)
t.modules.data = true -- Enable the data module (boolean)
t.modules.event = true -- Enable the event module (boolean)
t.modules.font = true -- Enable the font module (boolean)
t.modules.graphics = true -- Enable the graphics module (boolean)
t.modules.image = true -- Enable the image module (boolean)
t.modules.joystick = false -- Enable the joystick module (boolean)
t.modules.keyboard = true -- Enable the keyboard module (boolean)
t.modules.math = true -- Enable the math module (boolean)
t.modules.mouse = true -- Enable the mouse module (boolean)
t.modules.physics = true -- Enable the physics module (boolean)
t.modules.sound = true -- Enable the sound module (boolean)
t.modules.system = true -- Enable the system module (boolean)
t.modules.thread = true -- Enable the thread module (boolean)
t.modules.timer = true -- Enable the timer module (boolean), Disabling it will result 0 delta time in love.update
t.modules.touch = false -- Enable the touch module (boolean)
t.modules.video = false -- Enable the video module (boolean)
t.modules.window = true -- Enable the window module (boolean)
end

View File

@ -1,4 +1,6 @@
local shared = assert( require 'shared' )
package.cpath = "..\\?.dll;..\\clib\\?.dll;"..package.cpath
package.path = "..\\?.lua;..\\lualib\\?.lua;"..package.path
local shared = assert( require 'shared.shared' )
local packet = shared.packet
local socket = assert( require 'socket' )
local ms = shared.metaserver
@ -16,6 +18,10 @@ local svInfo = packet.serverInfo{ version = 13,
local server = {
tick = 0,
advertised = function()
print( "Advertised." )
end,
}
local clients = {}
@ -27,6 +33,7 @@ end
function server.Advertise()
print( "Advertise." )
packet.get()
packet.metaServer()
packet.serverInfo( svInfo )
udp:sendto( packet.get() , ms.ip, ms.port )
@ -59,21 +66,24 @@ 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
print( "Trying IP:", ipString, port )
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 ))
print( "Server started:", udp:getsockname() )
repeat
server.Parse( udp:receivefrom() )
server.Advance()
if server.tick % 20 == 0 then
server.Advertise()
end
until socket.sleep( 0.1 )
end
function server.Advance()
@ -91,4 +101,14 @@ function server.Quit()
end
return server.Start()
server.Start()
function love.update( dt )
server.Parse( udp:receivefrom() )
server.Advance()
if server.tick % 50 == 0 then
server.Advertise()
end
end
function love.draw() end

3
src/shared/getip.lua Normal file
View File

@ -0,0 +1,3 @@
local dns = assert( require 'socket' ).dns
--Get your own local IP address via DNS.
return dns.toip( dns.gethostname() )

View File

@ -1,8 +1,10 @@
local _print = print
local log = assert( io.open( ("../logs/log_%04d.txt"):format( os.time() % 1000 ), "a" ))
local lfs = assert( love.filesystem )
local log = assert( lfs.newFile( ("log_%04d.txt"):format( os.time() % 1000 )))
assert( log:open 'a', "Could not open log file!" )
return function( ... )
log:write( os.date("!%S") )
log:write( os.date("!%M%S") )
for i, v in ipairs{...} do
log:write("\t")
log:write(tostring(v))

View File

@ -1,15 +1,22 @@
package.cpath = ".\\?.dll;..\\build\\clib\\?.dll;"..package.cpath
package.path = ".\\?.lua;..\\build\\lualib\\?.lua;"..package.path
print( "Loading Shared." )
local shared = {}
do
local rq = require
require = function( ... )
print( "Require:", ... )
return rq( ... )
end
end
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 = {}