From e97b8e844c931c9daff036805ea18d087429d472 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Tue, 24 Jan 2023 15:28:43 +0000 Subject: things and stuff and things --- server/server.lua | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'server') diff --git a/server/server.lua b/server/server.lua index 4db0207..c518222 100644 --- a/server/server.lua +++ b/server/server.lua @@ -9,6 +9,7 @@ print(host) -- sequential list of all players local playerlist = {} +local nextid = 1 -- this is maybe suboptimal -- but it is simplest for now @@ -25,17 +26,13 @@ local function player_by_peer(peer) return nil end - -local function gen_id() - local x = math.random(100000) - -- if players[x] then error("cough") end - return x -end local function random_color() return {math.random(),math.random(),math.random()} end local function make_player(peer) - return {pos={100,100},color=random_color(),peer=peer} + local p = {pos={100,100},color=random_color(),peer=peer,id=nextid} + nextid = nextid + 1 + return p end -- maybe json could be used for this @@ -68,7 +65,6 @@ while true do if ev.type == "connect" then local player = make_player(ev.peer) table.insert(playerlist,player) - player.id = #playerlist print("connect",player.peer,player.id) player.peer:send(player_you_packet(player)) -- cgit v1.2.3