-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.lua
127 lines (95 loc) · 2.34 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
if castle then
cs = require("https://raw.githubusercontent.com/castle-games/share.lua/master/cs.lua")
else
cs = require("cs")
end
server = cs.server
server.maxClients = 4
if USE_CASTLE_CONFIG then
server.useCastleConfig()
else
function start_server()
server.enabled = true
server.start('22122') -- Port of server
love.update = server.update
server.load()
ROLE = server
end
end
server.changed = server_input
server.connect = server_new_client
server.disconnect = server_lost_client
-- 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
if USE_CASTLE_CONFIG then
local syss = {"audio", "graphics", "video", "window"}
--local syss = {}
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
else
if not castle then
init_graphics(400,300)
init_audio()
init_shader_mgr()
init_input_mgr()
font("big")
pal()
end
predraw()
_init()
afterdraw()
love.keyboard.setKeyRepeat(true)
love.keyboard.setTextInput(false)
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)
dt = dt or love.timer.getDelta()
-- if not castle then
-- love.timer.sleep(1/30-dt)
-- dt = 1/30
-- end
if ROLE then server.preupdate() end
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 syss = {}
-- local syssav = {}
-- for sys in all(syss) do
-- syssav[sys], love[sys] = love[sys], nil
-- end
--update_game()
_update(dt)
-- for sys in all(syss) do
-- love[sys] = syssav[sys]
-- end
-- server_only = false
if ROLE then server.postupdate() end
end