1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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
|