chatclient.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #ifndef __CHATCLIENT_H
  2. #define __CHATCLIENT_H
  3. #include "biglist.h"
  4. #include "message.h"
  5. #include "concurrent_queue.h"
  6. #include <libwebsockets.h>
  7. //#include "simplechatgame.h"
  8. //#include <queue>
  9. class user;
  10. class chatroom;
  11. class simplechatgame;
  12. class chatclient
  13. {
  14. public:
  15. int64_t chatclientid; // Unuqie number assigned as connections come in.
  16. user *logged_in_user; // Optional. The user this client is logged in as.
  17. biglist<chatroom *> *chatrooms; // What chatrooms this client is using.
  18. concurrent_queue<message *> *messages_to_send;
  19. bool should_disconnect;
  20. struct lws *wsi; // From libwebsockets callback.
  21. void add_chatroom(chatroom *room); // Add a chatroom to the list of chatrooms above.
  22. void remove_chatroom(chatroom *room); // Remove a chatroom from the list of chatrooms above.
  23. void push_message(message **message_to_add); // Adds a message to messages_to_send. Sets *message_to_add to nullptr. Also calls callback_on_writable.
  24. void add_message(message *message_to_add); // Adds a message to messages_to_send. Increments message_to_add->usage.
  25. void add_message(datastring message_to_add);
  26. void add_message(datastring *message_to_add);
  27. void add_message(const char *message_to_add);
  28. void disconnect();
  29. message *get_next_message(); // Returns a message if it's available. Delete the returned message with message::dereference.
  30. void initialize(struct lws *opened_wsi,int64_t chat_client_id); // Call this when the connection is opened.
  31. void clear(); // Call this when the connection is closed.
  32. void send_yourchatclientid();
  33. int callback_on_writable(); // Signal libwebsockets that there's data to send. This can be called from a different thread.
  34. // Send a message to a list of clients.
  35. static void send_message_to_clients(biglist<chatclient *> *clients,message *message);
  36. };
  37. #endif