-
Notifications
You must be signed in to change notification settings - Fork 1
/
serverTCP.h
75 lines (72 loc) · 2.21 KB
/
serverTCP.h
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
64
65
66
67
68
69
70
71
72
73
74
75
#ifndef serverTCP_h
#define serverTCP_h
#include "header.h"
#include "elementTCP.h"
class sqlServer;
class serverTCP{
friend class sqlServer;
public:
//share
serverTCP();
static void sig_chld(int signo);
void TCP_connect(int port);
bool accept_client();
//login server
void login_mainloop();
void login_handle(sqlServer& sqlserver);
//game server
void game_mainloop();
void turnOnNonBlock();
void new_game_handle(sqlServer& sqlServer);
void game_handle(sqlServer& sqlServer);
void sendData(Packet& packet, int sockfd);
void broadcast_xy(Packet& packet, int sockfd);
void broadcast_chatroom(Packet& packet, int sockfd);
Packet receiveData_login(int sockfd);
Packet receiveData_game(int sockfd);
Packet deserialize(std::string& json_string);
std::string serialize(Packet packet);
std::string get_player_name(int sockfd);
void remove_player(int sockfd);
void getNewRoom(Player& player1, Player& player2);
void broadcastMaxTime(sqlServer& sqlServer);
void sendSelfTotalTime(sqlServer& sqlServer, char* name, int sockfd);
private:
int n, listenfd, connfd, sockfd;
socklen_t clilen;
struct sockaddr_in cliaddr, servaddr;
int maxfd;
fd_set rset, allset;
std::unordered_map<std::string, struct Player> players;
std::unordered_map<int, std::string> disconnect_list; //name, sockfd
std::vector<std::vector<Player>> roomList;
};
class sqlServer{
friend class serverTCP;
public:
sqlServer();
~sqlServer();
int db_register();
bool login_check();
bool register_check();
void addtimelen(std::string name, char* msg);
void db_information(std::string new_user_name, std::string new_user_password);
void db_query();
void db_clear();
void db_pswd_select();
void db_user_select();
void db_user_insert();
void db_time_insert();
float getSelfTotalTime();
std::pair<std::string, float> getUserMaxTime();
private:
int affectedRows;
sql::ResultSet *res;
std::string user_name;
std::string user_password;
std::string timelen;
sql::Connection *con;
sql::mysql::MySQL_Driver *driver;
sql::PreparedStatement *prep_stmt;
};
#endif