summaryrefslogtreecommitdiff
path: root/server/server.lua
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2023-02-20 03:55:51 +0000
committerubq323 <ubq323@ubq323.website>2023-02-20 03:55:51 +0000
commita3af144dec34adf9e8ac047dd368bb102de40821 (patch)
tree23f84d753dd3158d65f58004686687977f6f5496 /server/server.lua
parent12972093a8eb1853c4bbe32750e43ec390cfe8c5 (diff)
chat system, some controls changes
Diffstat (limited to 'server/server.lua')
-rw-r--r--server/server.lua10
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