-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserverinit.lua
More file actions
46 lines (38 loc) · 1.1 KB
/
Copy pathserverinit.lua
File metadata and controls
46 lines (38 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
local nl = require("NetworkLib")
local socket = require("socket")
local server_ready = false
local connection_attempts = 0
local max_attempts = 50
local function open_server()
local is_windows = os.getenv("COMSPEC") or os.getenv("OS") == "Windows_NT"
if is_windows then
os.execute('start "" "network.exe"')
else
os.execute('./network.exe &')
end
end
function love.load()
open_server()
socket.sleep(1.0)
end
function love.update(dt)
if not server_ready and connection_attempts < max_attempts then
local success, msg = nl:init("127.0.0.1", 8080)
if success then
server_ready = true
dofile("multiplayer.lua")
if love.load then
love.load()
end
else
connection_attempts = connection_attempts + 1
socket.sleep(0.2)
end
end
end
function love.draw()
if not server_ready then
love.graphics.setColor(1, 1, 1)
love.graphics.print("Starting server... (attempt " .. connection_attempts .. "/" .. max_attempts .. ")", 50, 50)
end
end