Compare commits

...

2 Commits

Author SHA1 Message Date
Pascal Abresch 0f3c555149 Tell other clients about leaving clients 2022-01-04 18:54:59 +01:00
Pascal Abresch 1cbe3a1c64 remove some logging 2022-01-04 18:54:39 +01:00
2 changed files with 13 additions and 7 deletions

View File

@ -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

View File

@ -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