From e72226dbf8f61dacc2fe4d18297807faa27b207f Mon Sep 17 00:00:00 2001 From: piernov Date: Mon, 12 May 2014 13:00:01 +0200 Subject: Multiplayer mode + various improvement --- Gamestates/Multiplayer/Protocol.lua | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Gamestates/Multiplayer/Protocol.lua (limited to 'Gamestates/Multiplayer/Protocol.lua') 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 -- cgit v1.2.3-54-g00ecf