polishing

This commit is contained in:
PoliEcho 2024-06-02 12:42:49 +02:00
parent 304f3e2293
commit 15691e3094
6 changed files with 69 additions and 20 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
.vscode/
.fleet/

View File

@ -1,2 +1,3 @@
extern int board_size;
extern bool ishost;
extern bool ishost;
extern unsigned short port;

View File

@ -4,9 +4,11 @@
using std::cout;
using std::cin;
using std::cerr;
int board_size;
bool ishost;
unsigned short port;
bool repeat = true;
void ishost_check() {
@ -34,22 +36,40 @@ void board_size_check() {
repeat = true;
while (repeat) {
cout << "\nplease enter board size(for example: 3 for 3x3): ";
cout << "\nplease enter board size(for example: 3 for 3x3): ";
cin >> board_size;
if(cin.fail()) {
cout << "integer please\n";
cin.clear();
cin.ignore(256,'\n');
} else {
if(board_size > 0) {
repeat = false;
} else {
cout << "positive integer please\n";
cin >> board_size;
if(cin.fail()) {
cerr << "integer please\n";
cin.clear();
cin.ignore(256,'\n');
} else {
if(board_size > 0) {
repeat = false;
} else {
cerr << "positive integer please\n";
}
}
}
}
}
void port_check() {
repeat = true;
while (repeat) {
cout << "\nplease enter port you want to host on: ";
cin >> port;
if(cin.fail()) {
cerr << "integer please (range: 1-65535)\n";
cin.clear();
cin.ignore(256,'\n');
} else {
if(board_size > 0) {
repeat = false;
} else {
cerr << "positive integer please\n";
}
}
}
}

View File

@ -1,2 +1,3 @@
void ishost_check();
void board_size_check();
void board_size_check();
void port_check();

View File

@ -6,6 +6,7 @@
using std::cout;
using std::cin;
using std::cerr;
int main() {
@ -41,12 +42,16 @@ cout << R"( ___ __ _______ ___ ________ ________ _____ ______
int board_size;
ishost_check();
board_size_check();
if(ishost) {
board_size_check();
port_check();
}
{
int init_net_status = init_net();
if(init_net_status != 0){
cout << "failed to initialize network\n";
cerr << "failed to initialize network\n";
return 2;
}
}

View File

@ -1,8 +1,29 @@
#include"net.hpp"
#include "global.hpp"
#include "net.hpp"
#include <iostream>
#include <string>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <netdb.h>
#include <sys/uio.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <fstream>
int init_net() {
if(ishost) {
}
return 0;
}