function lobby.send(name, msg)
   local map = lobby.game[name]
   for _, player in pairs(minetest.get_connected_players()) do
      local rname  = player:get_player_name()
      if lobby.game[rname] == map then
         minetest.chat_send_player(rname, "<"..name.."> "..msg)
      end
   end
   minetest.log("action", "CHAT: ".."<"..name.."> "..msg)
   -- Prevent from sending normally
   return true
end

function lobby.message_to_level(map_id, message)
   for _, player in pairs(minetest.get_connected_players()) do
      local rname  = player:get_player_name()
      if lobby.game[rname] == map_id then
         minetest.chat_send_player(rname, message)
      end
   end
end

minetest.register_on_chat_message(function(name, msg)
   return lobby.send(name, msg)
end)
