diff --git a/.gitignore b/.gitignore index 656301a..6ac74d2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .vscode/ +.fleet/ \ No newline at end of file diff --git a/src/global.hpp b/src/global.hpp index d7d4be9..2966983 100644 --- a/src/global.hpp +++ b/src/global.hpp @@ -1,2 +1,3 @@ extern int board_size; -extern bool ishost; \ No newline at end of file +extern bool ishost; +extern unsigned short port; \ No newline at end of file diff --git a/src/input.cpp b/src/input.cpp index f15b1c4..5b5efff 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -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"; + } + } + } } \ No newline at end of file diff --git a/src/input.hpp b/src/input.hpp index 4bcc794..9f9f207 100644 --- a/src/input.hpp +++ b/src/input.hpp @@ -1,2 +1,3 @@ void ishost_check(); -void board_size_check(); \ No newline at end of file +void board_size_check(); +void port_check(); \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index b7182fc..1f01950 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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; } } diff --git a/src/net.cpp b/src/net.cpp index 5ad834f..3478c71 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1,8 +1,29 @@ -#include"net.hpp" +#include "global.hpp" +#include "net.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + int init_net() { + if(ishost) { + + } return 0; }