Compare commits
2 Commits
1d4e5a49aa
...
0f3c555149
Author | SHA1 | Date |
---|---|---|
Pascal Abresch | 0f3c555149 | |
Pascal Abresch | 1cbe3a1c64 |
8
main.lua
8
main.lua
|
@ -22,10 +22,8 @@ if not server or not socket then error("failed to listen on socket") end
|
|||
|
||||
while true do
|
||||
::nw_next::
|
||||
--print("iteration start")
|
||||
local data
|
||||
data, ip, port = server:receivefrom()
|
||||
--print("received data from " .. ip)
|
||||
if not data then
|
||||
local err_code = ip
|
||||
print(err_code)
|
||||
|
@ -44,16 +42,12 @@ while true do
|
|||
clients[clientCount ..""] = { ip = ip, port = port }
|
||||
print("New client connected. Granting id: [" .. clientCount .. "] IP: " .. ip .. " Port:" .. port)
|
||||
for i, client in pairs(clients) do
|
||||
print("Iter : ".. i .. " client is " .. client.ip .. " : " .. client.port)
|
||||
if i ~= clientCount .."" then
|
||||
print("Introducing client[" .. i .. "] and client[" .. clientCount.."]")
|
||||
local payload = util.unit("poppyV001", clientCount, "player", "join")
|
||||
server:sendto(payload, client.ip, client.port)
|
||||
print("Telling client " .. i .. " about " .. clientCount)
|
||||
print(payload)
|
||||
local payload = util.unit("poppyV001", i, "player", "join")
|
||||
server:sendto(payload, ip, port)
|
||||
print("Telling client " .. clientCount .. " about " .. i)
|
||||
print(payload)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
12
players.lua
12
players.lua
|
@ -1,6 +1,18 @@
|
|||
local util = require("utils")
|
||||
|
||||
return function(commands)
|
||||
commands.rq = commands.rq or {}
|
||||
|
||||
function commands.rq.cid() return "granted" end
|
||||
commands.player = {}
|
||||
|
||||
function commands.player.leave(clientID)
|
||||
clients[clientID] = nil
|
||||
for i, player in pairs(clients) do
|
||||
local payload = util.unit("poppyV001", clientID,
|
||||
"player", "leave")
|
||||
server:sendto(payload, player.ip, player.port)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue