Use PubNub's Anti-Spam Function to restrict users from publishing messages based-on the incoming IP address that is used when publishing messages.
The function rate limits the publish rate from any IP address. The limit is configurable. The function keeps track of the times of published messages and allows a message to get published only if the IP address does not cross the maximum number of messages allowed.
Note: Refer to PubNub Access Manager to manage permissions restrict read/write access to chat rooms for users.