-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.lua
86 lines (60 loc) · 1.51 KB
/
server.lua
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
local cs = require 'cs'
server = cs.server
server.maxClients = 16
if USE_CASTLE_CONFIG then
server.useCastleConfig()
else
server.enabled = true
server.start('22122') -- Port of server
end
server.changed = read_server
server.disconnect = server_client_disconnected
-- Server only gets `.load`, `.update`, `.quit` Love events (also `.lowmemory` and `.threaderror`
-- which are less commonly used)
local server_init
function server.load()
if server_init then
castle_print("Attempt to 2nd server init?")
return
end
castle_print("Starting server init...")
server_only = true
local syss = {"audio", "graphics", "video", "window"}
local syssav = {}
for sys in all(syss) do
syssav[sys], love[sys] = love[sys], nil
end
_init()
for sys in all(syss) do
love[sys] = syssav[sys]
end
server_only = false
server_init = true
castle_print("Server init done!")
end
local server_load_sav = server.load
delta_time = 0
dt30f = 0
function server.update(dt)
if not server_init then
castle_print("Calling server.load from update.")
server.load = server_load_sav
server.load()
return
end
-- castle_print("server update")
server_only = true
delta_time = dt
dt30f = dt*30
local syss = {"audio", "graphics", "video", "window"}
local syssav = {}
for sys in all(syss) do
syssav[sys], love[sys] = love[sys], nil
end
--update_game()
_update()
for sys in all(syss) do
love[sys] = syssav[sys]
end
server_only = false
end