From a3af144dec34adf9e8ac047dd368bb102de40821 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Mon, 20 Feb 2023 03:55:51 +0000 Subject: chat system, some controls changes --- server/server.lua | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'server') 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 -- cgit v1.2.3