-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.lua
More file actions
33 lines (28 loc) · 798 Bytes
/
server.lua
File metadata and controls
33 lines (28 loc) · 798 Bytes
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
-- server.lua
local SharedNet = require("SharedNet")
local Server = class("Server", SharedNet)
function Server:initialize(toconnect)
SharedNet.initialize(self)
self.target = toconnect
self.host = enet.host_create(self.target)
self.peers = {}
end
function Server:update(dt)
self.timeout = dt
local event = self.host:service(self.timeout)
if event then
if event.type == "connect" then
table.insert(self.peers, event.peer)
self:onConnect(event)
elseif event.type == "receive" then
self:onReceive(event.data, event.peer)
elseif event.type == "disconnect" then
self:onDisconnect(event)
end
end
end
function Server:send(command, args, peer)
local ndata = binser.serialize({command=command, args=args})
peer:send(ndata)
end
return Server