summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/server.lua12
1 files changed, 4 insertions, 8 deletions
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))