summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2023-08-27 00:31:54 +0100
committerubq323 <ubq323@ubq323.website>2023-08-27 00:31:54 +0100
commitef0b7de7745c8932ff76fef2dd267c1d7a0d4b69 (patch)
treee5876c15da3bd013ce13bc41e8ff4514268f771a /server
parent00d6c715e8d71056274e22b3a7eae2e55d3840c1 (diff)
move chat formatting to serverside, and make chat messages include username
Diffstat (limited to 'server')
-rw-r--r--server/server.lua10
1 files changed, 7 insertions, 3 deletions
diff --git a/server/server.lua b/server/server.lua
index a3c8f60..1c637bc 100644
--- a/server/server.lua
+++ b/server/server.lua
@@ -45,8 +45,8 @@ 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}
+local function chat_packet(msg)
+ return json.encode{t="chat",msg=msg}
end
local function settile_packet(h,tile)
return json.encode{t='settile',q=h.q,r=h.r,tile=tile}
@@ -77,6 +77,8 @@ local function create_player(...)
if otherplayer ~= player then
player.peer:send(player_join_packet(otherplayer))
otherplayer.peer:send(player_join_packet(player))
+ otherplayer.peer:send(
+ chat_packet(player.username .. " joined"))
end
end
@@ -113,6 +115,7 @@ local function on_peer_disconnect(peer)
table.remove(playerlist, idx)
for i,otherplayer in ipairs(playerlist) do
otherplayer.peer:send(player_leave_packet(player))
+ otherplayer.peer:send(chat_packet(player.username..' left'))
end
print("disconnect", player.id, player.peer)
end
@@ -176,7 +179,8 @@ local function handle_player_packet(player,ev)
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))
+ otherplayer.peer:send(
+ chat_packet('['..player.username..'] '..j.msg))
end
end
end