aboutsummaryrefslogtreecommitdiffstats
path: root/Gamestates/Multiplayer/Protocol.lua
diff options
context:
space:
mode:
Diffstat (limited to 'Gamestates/Multiplayer/Protocol.lua')
-rw-r--r--Gamestates/Multiplayer/Protocol.lua35
1 files changed, 35 insertions, 0 deletions
diff --git a/Gamestates/Multiplayer/Protocol.lua b/Gamestates/Multiplayer/Protocol.lua
new file mode 100644
index 0000000..6f3b739
--- /dev/null
+++ b/Gamestates/Multiplayer/Protocol.lua
@@ -0,0 +1,35 @@
+--[[
+ Gamestates/Multiplayer/Protocol.lua
+ Some functions involved in talking between 2 clients
+ by piernov
+
+ Comment: maybe useless.
+]]--
+local Protocol = {}
+
+function Protocol.acceptGame(host, peer_id, accept) -- Send an answer to a connection from another player
+ local peer = host:get_peer(peer_id)
+ if accept then
+ peer:send("ACCEPT: YES", 0, "reliable")
+ else
+ peer:send("ACCEPT: NO", 0, "reliable")
+ peer:disconnect_later()
+ end
+end
+
+function Protocol.parseGlobalEvents(event) -- Shared function between local menu and game which disallow multiple connections and handle disconnect
+ if event.type == "connect" then
+ if event.peer:index() > 1 then
+ print("Already connected")
+ event.peer:disconnect(2)
+ end
+ elseif event.type == "disconnect" then
+ print("Disconnect " .. tostring(event.peer))
+ if event.data == 2 then
+ print("Peer is busy")
+ event.peer:disconnect()
+ end
+ end
+end
+
+return Protocol