Zigonnage dans le srv.

This commit is contained in:
MarcEricMartel
2023-09-24 11:07:03 -04:00
parent 51b0795c62
commit 2bb55e5bf6
5 changed files with 101 additions and 34 deletions

View File

@@ -1,10 +1,11 @@
#include "server.h"
Server::Server(LogDest log) : m_log(log) {
if (log == LogDest::LOGFILE) {
Server::Server(LogDest log) {
m_log = log;
if (log == LOG_DEST::LOGFILE) {
m_logfile = std::ofstream("server.log", std::ofstream::out);
if (!m_logfile.is_open()) {
m_log = LogDest::CONSOLE; // Fallback console.
m_log = LOG_DEST::CONSOLE; // Fallback console.
Log("Ouverture fichier log: repli vers console.", true, false);
}
}
@@ -60,11 +61,28 @@ int Server::Init() {
return 5;
}
for (auto& conn : m_conn)
conn = nullptr;
return 0;
}
int Server::Ready() {
Log("Pr<EFBFBD>t <20> d<>marrer...", false, false);
if (listen(m_sock_tcp, MAX_CONNECTIONS) < 0) {
Log("<EFBFBD>coute sur le port TCP.", true, true);
return 1;
}
char buffer[2048];
bool readystart = false;
Log("<EFBFBD> l'<27>coute sur le port: " + std::to_string(SRV_PORT), false, false);
while (!readystart) {
Log("trololo", false, false);
readystart = true;
}
return 0;
}
@@ -93,10 +111,10 @@ inline std::string Server::Timestamp() {
void Server::Log(std::string str, bool is_error = false, bool is_fatal = false) {
switch (m_log) {
case LogDest::LOGFILE:
case LOG_DEST::LOGFILE:
m_logfile << Timestamp() << (is_fatal ? "FATAL " : "") << (is_error ? "ERROR " : "") << str << std::endl;
break;
case LogDest::CONSOLE:
case LOG_DEST::CONSOLE:
default:
std::cout << Timestamp() << (is_fatal? "FATAL ": "") << (is_error ? "ERROR ": "") << str << std::endl;
break;