This commit is contained in:
MarcEricMartel
2023-10-18 09:33:56 -04:00
parent 793da52871
commit 2cb7d4c776
4 changed files with 65 additions and 22 deletions

View File

@@ -10,6 +10,7 @@
#define MAX_CONNECTIONS 16
#define ID_LIST_SIZE 127
#define BUFFER_LENGTH 150
#define SRV_MANUAL_SETUP true
typedef unsigned char LogDest;
enum LOG_DEST { CONSOLE, LOGFILE, LOG_LAST };

View File

@@ -65,6 +65,31 @@ int Server::Init() {
}
int Server::Ready() {
int nbrjoueurs = 0,
nbrconn = 0;
#ifdef SRV_MANUAL_SETUP
do {
Log("Entrez la dur<75>e de la partie: ", false, false);
std::cin >> m_game.countdown;
std::cout << std::endl;
} while (m_game.countdown < 1);
do {
Log("Entrez le seed de la partie: ", false, false);
std::cin >> m_game.seed;
std::cout << std::endl;
} while (m_game.seed < 1);
do {
Log("Entrez le nombre de joueurs: ", false, false);
std::cin >> nbrjoueurs;
std::cout << std::endl;
} while (nbrjoueurs > 0 && nbrjoueurs >= MAX_CONNECTIONS);
#else // setup preconfigur<75>
m_game.countdown = 360;
m_game.seed = 9370707;
nbrjoueurs = 1;
#endif
m_game.gameType = 1;
if (listen(m_sock_tcp, MAX_CONNECTIONS) < 0) {
Log("<EFBFBD>coute sur le port TCP.", true, true);
return 1;
@@ -79,13 +104,17 @@ int Server::Ready() {
buildIdList(ID_LIST_SIZE);
m_game.countdown = 360;
m_game.gameType = 1;
m_game.seed = 9370707;
while (!readystart) {
sockaddr_in sockad;
#ifdef _WIN32
int addrlen = sizeof(sockad);
#else // maudit que c'est con, <20>a.
unsigned int addrlen = sizeof(sockad);
#endif
SOCKET sock = accept(m_sock_tcp, (sockaddr*)&sockad, &addrlen);
if (sock < 0)
@@ -127,7 +156,8 @@ int Server::Ready() {
Connection* conn = new Connection(sock, sockad, log, play);
m_players[log.sid] = conn;
readystart = true;
if (++nbrconn >= nbrjoueurs)
readystart = true;
}
}
}

View File

@@ -34,6 +34,7 @@ private:
netprot::GameInfo m_game;
World* m_world = nullptr;
const bool m_manual_setup = SRV_MANUAL_SETUP;
std::string LogTimestamp();
void Log(std::string str, bool is_error, bool is_fatal);