- Implementiere eine neue Methode `addUser`, die einen Token als Parameter akzeptiert, um die Benutzeranmeldung über WebSockets zu verbessern. - Aktualisiere den Konstruktor von `ChatUser`, um den Token zu verarbeiten und sicherzustellen, dass Benutzer korrekt initialisiert werden. - Ergänze Debug-Ausgaben, um den Ablauf beim Hinzufügen von Benutzern und beim Senden von Nachrichten zu protokollieren, um die Nachverfolgbarkeit zu erhöhen.
81 lines
2.7 KiB
C++
81 lines
2.7 KiB
C++
#ifndef YC_LIB_CHAT_USER_H
|
|
#define YC_LIB_CHAT_USER_H
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
#include <set>
|
|
#include <json/json.h>
|
|
#include <thread>
|
|
#include "lib/base.h"
|
|
#include "object/user.h"
|
|
#include "lib/database.h"
|
|
|
|
namespace Yc
|
|
{
|
|
namespace Lib
|
|
{
|
|
|
|
class ChatRoom;
|
|
|
|
class ChatUser : public Base, public std::enable_shared_from_this<ChatUser>
|
|
{
|
|
public:
|
|
enum MsgType
|
|
{
|
|
error = -1,
|
|
token = 1,
|
|
userListe = 2,
|
|
roomList = 3,
|
|
message = 4,
|
|
system = 5,
|
|
scream = 6,
|
|
dosomething = 7,
|
|
dice = 8,
|
|
result = 9
|
|
};
|
|
|
|
ChatUser(std::shared_ptr<ChatRoom> parent, std::string name, std::string color, int socket);
|
|
ChatUser(std::shared_ptr<ChatRoom> parent, std::string name, std::string color, int socket, std::shared_ptr<Database> database);
|
|
ChatUser(std::shared_ptr<ChatRoom> parent, std::string name, std::string color, void* wsi, std::shared_ptr<Database> database);
|
|
ChatUser(std::shared_ptr<ChatRoom> parent, std::string name, std::string color, void* wsi, std::shared_ptr<Database> database, std::string token);
|
|
~ChatUser();
|
|
std::string name() const;
|
|
std::string getToken() const;
|
|
bool validateToken(std::string token);
|
|
bool isUser(std::shared_ptr<ChatUser> toValidate);
|
|
void sendMsg(MsgType type, std::string message, std::string userName, std::string color);
|
|
void sendMsg(MsgType type, const char *message, std::string userName, std::string color);
|
|
void sendMsg(MsgType type, Json::Value message, std::string userName, std::string color);
|
|
void checkerTask();
|
|
void start();
|
|
void stop();
|
|
std::string color() const;
|
|
void setParent(std::shared_ptr<ChatRoom> parent);
|
|
|
|
public:
|
|
std::thread thread;
|
|
|
|
private:
|
|
std::shared_ptr<ChatRoom> _parent;
|
|
Yc::Object::User _user;
|
|
std::string _name;
|
|
std::string _color;
|
|
int _socket;
|
|
void* _wsi; // WebSocket pointer for libwebsockets
|
|
std::string _token;
|
|
bool _stop;
|
|
|
|
void send(std::string out);
|
|
void send(Json::Value out);
|
|
void handleMessage(std::string message);
|
|
void doDice();
|
|
void changeRoom(std::string newRoom, std::string password);
|
|
void checkString(std::string message);
|
|
void sendUserList();
|
|
};
|
|
|
|
} // namespace Lib
|
|
} // namespace Yc
|
|
|
|
#endif // YC_LIB_CHAT_USER_H
|