diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/server.lua | 10 |
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 |