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);
|
||||
bool check_status(Maze& maze);
|
||||
public:
|
||||
Server(const std::string& host, const unsigned short port, bool service_flag);
|
||||
void start(int steps = 10);
|
||||
Server(const std::string& host, const unsigned short port);
|
||||
void start(int steps, bool service_flag);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -4,12 +4,7 @@ bool Server::check_status(Maze &maze) {
|
||||
return (!maze.test_mode && maze.get_moves_left() > 0);
|
||||
}
|
||||
|
||||
Server::Server(const std::string& h, const unsigned short p, bool _service){
|
||||
service_mode = _service;
|
||||
if (service_mode) {
|
||||
std::cout << "Service mode is ON" << std::endl;
|
||||
}
|
||||
|
||||
Server::Server(const std::string& h, const unsigned short p){
|
||||
sockaddr_in server_address;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if (listen(server_socket, MAX_CLIENTS) < 0) {
|
||||
|
||||
@@ -31,8 +31,8 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
|
||||
try {
|
||||
Server server(host, port, service_mode);
|
||||
server.start(steps);
|
||||
Server server(host, port);
|
||||
server.start(steps, service_mode);
|
||||
} catch (const std::runtime_error& e){
|
||||
std::cerr << "Server application error: " << e.what() << std::endl;
|
||||
return 1;
|
||||
|
||||
Reference in New Issue
Block a user