They were
on paper
vassal states of the Ottoman Empire, and also claimed by Morocco.
In effect, the Ottomans had no hold on them, and those cities were operating independantly and insubordinately. They were for all intents and purposes independant city-states governed locally by gangs who made a living off of looting ships, similar to some cities in Somalia around 2005-2010.
Also you know Ottoman doesn't equal Morocco I suppose, so your first comment is still mostly wrong. Morocco was not
the first country to wage war against it [USA]