62 lines
1.8 KiB
C++
Executable File
62 lines
1.8 KiB
C++
Executable File
#ifndef YC_LIB_USER_H
|
|
#define YC_LIB_USER_H
|
|
|
|
#include <string>
|
|
#include <json/json.h>
|
|
#include <thread>
|
|
#include "base.h"
|
|
|
|
namespace Yc {
|
|
namespace Lib {
|
|
|
|
class Room;
|
|
|
|
class User: public Base {
|
|
public:
|
|
enum MsgType {
|
|
error = -1,
|
|
token = 1,
|
|
userListe = 2,
|
|
roomList = 3,
|
|
message = 4,
|
|
system = 5,
|
|
scream = 6,
|
|
dosomething = 7,
|
|
dice = 8,
|
|
result = 9
|
|
};
|
|
|
|
User(Room *parent, std::string name, std::string color, int socket);
|
|
~User();
|
|
std::string name() const;
|
|
bool validateToken(std::string token);
|
|
bool isUser(User *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 stop();
|
|
std::string color() const;
|
|
void setParent(Room *parent);
|
|
private:
|
|
Room *_parent;
|
|
std::string _name;
|
|
std::string _color;
|
|
int _socket;
|
|
std::string _token;
|
|
bool _stop;
|
|
std::thread *thread;
|
|
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_USER_H
|