Breaking update
This commit is contained in:
@@ -49,6 +49,10 @@ void Client::run(const std::string& h, const unsigned short p) {
|
||||
std::string player_name;
|
||||
std::getline(std::cin, player_name);
|
||||
|
||||
if (player_name.empty() || player_name.size() > BUFFER_SIZE) {
|
||||
throw std::runtime_error("Incorrect name!");
|
||||
}
|
||||
|
||||
if (!ping(serv_addr)) {
|
||||
throw std::runtime_error("Connection lost!");
|
||||
}
|
||||
@@ -61,25 +65,30 @@ void Client::game(){
|
||||
std::cout << "Игра началась!" << std::endl;
|
||||
//print_instructions();
|
||||
|
||||
char buffer[1024] = {0};
|
||||
char buffer[BUFFER_SIZE] = {0};
|
||||
while (true) {
|
||||
std::cout << "Введите команду: ";
|
||||
std::string command;
|
||||
std::getline(std::cin, command);
|
||||
|
||||
if (command.empty() || command.size() > BUFFER_SIZE) {
|
||||
std::cout << "Некорректная команда" << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Отправка команды на сервер
|
||||
send(sock, command.c_str(), command.size(), 0);
|
||||
|
||||
// Получение ответа от сервера
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
int bytes_received = recv(sock, buffer, sizeof(buffer), 0);
|
||||
if (bytes_received <= 0) {
|
||||
if (bytes_received == 0 || bytes_received > BUFFER_SIZE) {
|
||||
throw std::runtime_error("Connection lost!");
|
||||
//break;
|
||||
}
|
||||
|
||||
std::string response(buffer);
|
||||
std::cout << "Ответ сервера: " << response;
|
||||
std::cout << "Ответ сервера: " << response << std::endl;
|
||||
|
||||
// Проверка завершения игры
|
||||
if (response.find("вы выиграли") != std::string::npos ||
|
||||
|
||||
Reference in New Issue
Block a user