diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/server.lua | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/server/server.lua b/server/server.lua index 85112c9..f78bdd0 100644 --- a/server/server.lua +++ b/server/server.lua @@ -60,6 +60,9 @@ end local function player_move_packet(player,x,y) return json.encode{t="move",id=player.id,x=x,y=y} end +local function chat_packet(fromplayer,msg) + return json.encode{t="chat",from=fromplayer.id,msg=msg} +end local map = MapS:make() @@ -121,6 +124,11 @@ local function handle_ev(ev) local cp = coords.ChunkPos:make(j.u,j.v) local ch = map:obtain(cp) player.peer:send(ch:data_packet()) + elseif op == "chat" then + print("chat ["..player.id.."] "..j.msg) + for i,otherplayer in ipairs(playerlist) do + otherplayer.peer:send(chat_packet(player,j.msg)) + end end end end @@ -160,7 +168,7 @@ local ntick = 0 local function player_near_chunk(cp) -- true: chunk at cp should stay loaded (because of a nearby player), -- false: no players nearby, can be unloaded - -- this is kind of inefficient at the moment + -- this is maybe not as efficient as it possibly could be for _,player in ipairs(playerlist) do local pcp = player.pos:to_hex():containing_chunk() for _,neighb in ipairs(pcp:neighborhood()) do |