From ad0a2dc909fbb772d42ab6faf13bba74fbc2483d Mon Sep 17 00:00:00 2001 From: Joursoir Date: Wed, 2 Dec 2020 12:46:42 +0000 Subject: try to make the code is easier; start work with db --- src/server/ChatServer.hpp | 63 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/server/ChatServer.hpp (limited to 'src/server/ChatServer.hpp') diff --git a/src/server/ChatServer.hpp b/src/server/ChatServer.hpp new file mode 100644 index 0000000..e2ef154 --- /dev/null +++ b/src/server/ChatServer.hpp @@ -0,0 +1,63 @@ +#ifndef WC_CHATSERVER_H +#define WC_CHATSERVER_H + +#include "sockets.hpp" +#include "database.hpp" +#include "../const_vars.hpp" + +#define CONSOLE_LOG(f_, ...) printf((f_), ##__VA_ARGS__) + +enum handle_room_enter { + enter_noexist, + enter_private, + enter_uncorrect_pass, + enter_success +}; + +class ChatRoom; +class UserInfo; + +class ChatServer : public FdHandler { + EventSelector *the_selector; + DatabaseManager *dbase; + + ChatRoom **room; + int room_len; + ChatRoom *lobby; + + ChatServer(EventSelector *sel, DatabaseManager *db, int fd); +public: + ~ChatServer(); + static ChatServer *Start(EventSelector *sel, + DatabaseManager *db, int fd); + + int AddRoom(char *password); + bool DeleteRoom(int id); // call only if room is empty + bool RoomExist(int id) const; + + void GotoLobby(ChatRoom *cur_room, UserInfo *u); + handle_room_enter ChangeSessionRoom(ChatRoom *cur_room, + UserInfo *u, int id, char *pass); + + void CloseConnection(UserInfo *u); + + // work with database: + AnswerDB *QuerySelect(const char *sql) + { return dbase->QuerySelect(sql); } + +private: + virtual void Handle(bool r, bool w); +}; + +/*class StorageOfUsers { + struct item { + ChatSession *s; + item *next; + } + item *first; +public: + AddSession(ChatSession *s); + RemoveSession(ChatSession *s); +};*/ + +#endif \ No newline at end of file -- cgit v1.2.3-18-g5258