diff options
-rw-r--r-- | client/main.lua | 6 | ||||
-rw-r--r-- | server/server.lua | 12 |
2 files changed, 7 insertions, 11 deletions
diff --git a/client/main.lua b/client/main.lua index 4375ed3..9ee18ea 100644 --- a/client/main.lua +++ b/client/main.lua @@ -1,10 +1,10 @@ local enet = require"enet" local words = require"common.words" - +local SERVER_HOSTNAME = "192.168.1.112" local PLAYER_SIZE = 30 -local local_player = false +local local_player = nil -- { -- pos={100,100}, @@ -113,7 +113,7 @@ end function love.load() host = enet.host_create() - peer = host:connect("localhost:8473") + peer = host:connect(SERVER_HOSTNAME..":8473") end function love.quit() 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)) |