-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.lua
More file actions
53 lines (41 loc) · 1.1 KB
/
server.lua
File metadata and controls
53 lines (41 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
47
48
49
50
51
52
53
require 'common'
local server = clientServer.server
if USE_LOCAL_SERVER then
server.enabled = true
server.start('22122')
else
server.useCastleConfig()
end
local share = server.share
local homes = server.homes
function server.load()
share.players = {}
end
function server.connect(clientId)
print('server: client ' .. clientId .. ' connected')
share.players[clientId] = {
x = math.random(40, 800 - 40),
y = math.random(40, 450 - 40),
}
end
function server.disconnect(clientId)
print('server: client ' .. clientId .. ' disconnected')
share.players[clientId] = nil
end
function server.receive(clientId, message, ...)
if message == 'pressedKey' then
local key = ...
server.send('all', 'otherClientPressedKey', clientId, key)
end
end
function server.update(dt)
for clientId, player in pairs(share.players) do
local home = homes[clientId]
if home.x and home.y then
player.x, player.y = home.x, home.y
end
if home.me and not player.me then
player.me = home.me
end
end
end