Implemented the chat logic in the server