From 04664ee48de5fc8b06a584e20a4b75c41dafa558 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Tue, 31 Jan 2023 23:51:25 +0000 Subject: add sending of tile changes, between players. server remembers all changes made. also add better debug screen --- server/server.lua | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'server/server.lua') diff --git a/server/server.lua b/server/server.lua index 42ed41d..ff3c3eb 100644 --- a/server/server.lua +++ b/server/server.lua @@ -2,6 +2,7 @@ local enet = require"enet" local json = require"common.dkjson" local Chunk = require"common.chunk".Chunk local unpack = unpack or table.unpack +local coords = require"common.coords" math.randomseed(os.time()) @@ -94,12 +95,24 @@ while true do local x,y = j.x,j.y player.pos[1] = x player.pos[2] = y - print(player.id,"-->",player.pos[1],player.pos[2]) + -- print(player.id,"-->",player.pos[1],player.pos[2]) for i,otherplayer in ipairs(playerlist) do if otherplayer ~= player then otherplayer.peer:send(player_move_packet(player,x,y)) end end + elseif op == "settile" then + local h = coords.Hex.make(j.q,j.r) + the_chunk:set_at(h,j.tile) + print(player.id,"settile",h,j.tile) + for i,otherplayer in ipairs(playerlist) do + if otherplayer ~= player then + -- same packet structure s2c as c2s + -- when multiple chunks exist and players only get info + -- about stuff near to them, that won't be the case any more + otherplayer.peer:send(ev.data) + end + end end end -- cgit v1.2.3