aboutsummaryrefslogtreecommitdiffstats
path: root/Gamestates/Multiplayer/Protocol.lua
diff options
context:
space:
mode:
authorpiernov <piernov@piernov.org>2014-05-12 13:00:01 +0200
committerpiernov <piernov@piernov.org>2014-05-12 13:00:01 +0200
commite72226dbf8f61dacc2fe4d18297807faa27b207f (patch)
tree82fe32b0e1b594c5c7241353ba1685d1f50818ee /Gamestates/Multiplayer/Protocol.lua
parent344b536979556aa2cfec0f9b16d6140e8fed9fe5 (diff)
downloadMastermind-e72226dbf8f61dacc2fe4d18297807faa27b207f.tar.gz
Mastermind-e72226dbf8f61dacc2fe4d18297807faa27b207f.tar.bz2
Mastermind-e72226dbf8f61dacc2fe4d18297807faa27b207f.tar.xz
Mastermind-e72226dbf8f61dacc2fe4d18297807faa27b207f.zip
Multiplayer mode + various improvement
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