Service mode flag as argument in start function of Server
This commit is contained in:
@@ -22,8 +22,8 @@ private:
|
|||||||
void handle_client(int socket, bool flag, int steps);
|
void handle_client(int socket, bool flag, int steps);
|
||||||
bool check_status(Maze& maze);
|
bool check_status(Maze& maze);
|
||||||
public:
|
public:
|
||||||
Server(const std::string& host, const unsigned short port, bool service_flag);
|
Server(const std::string& host, const unsigned short port);
|
||||||
void start(int steps = 10);
|
void start(int steps, bool service_flag);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -4,12 +4,7 @@ bool Server::check_status(Maze &maze) {
|
|||||||
return (!maze.test_mode && maze.get_moves_left() > 0);
|
return (!maze.test_mode && maze.get_moves_left() > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Server::Server(const std::string& h, const unsigned short p, bool _service){
|
Server::Server(const std::string& h, const unsigned short p){
|
||||||
service_mode = _service;
|
|
||||||
if (service_mode) {
|
|
||||||
std::cout << "Service mode is ON" << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
sockaddr_in server_address;
|
sockaddr_in server_address;
|
||||||
|
|
||||||
if ((server_socket = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
|
if ((server_socket = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
|
||||||
@@ -134,7 +129,11 @@ void Server::handle_client(int client_socket, bool mode, int steps) {
|
|||||||
std::cout << "Игрок " << player_name << " отключился" << std::endl;
|
std::cout << "Игрок " << player_name << " отключился" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::start(int steps) {
|
void Server::start(int steps, bool service_mode) {
|
||||||
|
if (service_mode) {
|
||||||
|
std::cout << "Service mode is ON" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
int new_socket;
|
int new_socket;
|
||||||
|
|
||||||
if (listen(server_socket, MAX_CLIENTS) < 0) {
|
if (listen(server_socket, MAX_CLIENTS) < 0) {
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Server server(host, port, service_mode);
|
Server server(host, port);
|
||||||
server.start(steps);
|
server.start(steps, service_mode);
|
||||||
} catch (const std::runtime_error& e){
|
} catch (const std::runtime_error& e){
|
||||||
std::cerr << "Server application error: " << e.what() << std::endl;
|
std::cerr << "Server application error: " << e.what() << std::endl;
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user