Merge branch 'master' into SQC-15_online

This commit is contained in:
MarcEricMartel
2023-12-05 06:34:51 -05:00
69 changed files with 172 additions and 329 deletions

View File

@@ -69,16 +69,15 @@ int Server::Init() {
}
int Server::Ready() {
int nbrjoueurs = 0,
int nbrjoueurs = 0,
nbrconn = 0;
bool readystart = false;
do {
Log("Entrez la duree de la partie: ", false, false);
std::cin.getline(m_buf.ptr, BUFFER_LENGTH);
try {
try {
m_game.countdown = std::stoi(m_buf.ptr);
}
catch (const std::exception& e) {
} catch(const std::exception& e) {
Log(e.what(), true, false);
m_game.countdown = 0;
}
@@ -86,10 +85,9 @@ int Server::Ready() {
do {
Log("Entrez le seed de la partie: ", false, false);
std::cin.getline(m_buf.ptr, BUFFER_LENGTH);
try {
m_game.seed = 9370707;//std::stoi(m_buf.ptr);
}
catch (const std::exception& e) {
try {
m_game.seed = std::stoi(m_buf.ptr);
} catch(const std::exception& e) {
Log(e.what(), true, false);
m_game.seed = 0;
}
@@ -97,10 +95,9 @@ int Server::Ready() {
do {
Log("Entrez le nombre de joueurs: ", false, false);
std::cin.getline(m_buf.ptr, BUFFER_LENGTH);
try {
try {
nbrjoueurs = std::stoi(m_buf.ptr);
}
catch (const std::exception& e) {
} catch(const std::exception& e) {
Log(e.what(), true, false);
nbrjoueurs = 0;
}
@@ -116,9 +113,9 @@ int Server::Ready() {
}
buildIdList(ID_LIST_SIZE);
Log("A l'ecoute sur le port: " + std::to_string(SRV_PORT), false, false);
while (!readystart) {
sockaddr_in sockad;
addrlen_t addrlen = sizeof(sockad);
@@ -138,7 +135,7 @@ int Server::Ready() {
if (pck.type != PACKET_TYPE::LOGINF) {
Log("Paquet invalide.", true, false);
if (pck.type != PACKET_TYPE::ERR)
netprot::emptyPack(pck);
netprot::emptyPack(pck);
continue; // Passer au prochain appel si c'est pas un LoginInfo ou un LoginInfo invalide qui rentre.
}
LoginInfo* log = (LoginInfo*)pck.ptr;
@@ -148,21 +145,17 @@ int Server::Ready() {
Log(str.append(" Nom: ").append(log->name), false, false);
str.clear();
Log(str.append(log->name).append(" SID: [").append(std::to_string(log->sid).append("]")), false, false);
sendPackTo<LoginInfo>(m_sock_udp, log, &m_buf, &sockad);
sendPack<LoginInfo>(sock, log, &m_buf);
play.id = getUniqueId();
play.tid = log->tid;
strcpy(play.name, log->name);
Log(str.append(play.name).append(" SID: [").append(std::to_string(log->sid)).append("]")
.append(" ID: [").append(std::to_string(play.id)).append("]")
.append(" TID: [").append(std::to_string(play.tid)).append("]"), false, false);
play.tid = log->tid;
sendPackTo<GameInfo>(m_sock_udp, &m_game, &m_buf, &sockad);
std::cout << m_game.seed << std::endl;
sendPack<GameInfo>(sock, &m_game, &m_buf);
Connection* conn = new Connection(sock, sockad, *log, play);
m_conns[log->sid] = conn;
@@ -189,7 +182,7 @@ void Server::Run() {
Input in;
sockaddr_in sockad;
addrlen_t socklen = sizeof(sockad);
Log("Debut de la partie...", false, false);
int players = m_conns.size();
@@ -205,13 +198,13 @@ void Server::Run() {
conn->player = new Player(Vector3f(x + .5f, CHUNK_SIZE_Y + 1.8f, y + .5f));
m_players[key] = conn->player;
Sync sync;
sync.position = conn->player->GetPositionAbs();
sync.position = conn->player->GetPosition();
sync.hp = conn->player->GetHP();
sync.sid = key;
sync.ammo = 0;
sync.timestamp = 0;
sync.timer = m_game.countdown;
sendPackTo<Sync>(m_sock_udp, &sync, &m_buf, conn->getAddr());
sendPack<Sync>(conn->getSock(), &sync, &m_buf);
}
int timer = m_game.countdown, sync_acc = 0;
@@ -369,13 +362,13 @@ inline std::string Server::LogTimestamp() {
void Server::Log(std::string str, bool is_error = false, bool is_fatal = false) {
switch (m_log) {
using enum LOG_DEST; // C++20!
case LOGFILE:
m_logfile << LogTimestamp() << (is_fatal ? "FATAL " : "") << (is_error ? "ERROR " : "") << str << std::endl;
break;
case CONSOLE: [[fallthrough]]; // Pour dire que c'est voulu que ça traverse vers le case en dessous (C++17!)
default:
std::cout << LogTimestamp() << (is_fatal ? "FATAL " : "") << (is_error ? "ERROR " : "") << str << std::endl;
break;
case LOGFILE:
m_logfile << LogTimestamp() << (is_fatal ? "FATAL " : "") << (is_error ? "ERROR " : "") << str << std::endl;
break;
case CONSOLE: [[fallthrough]]; // Pour dire que c'est voulu que ça traverse vers le case en dessous (C++17!)
default:
std::cout << LogTimestamp() << (is_fatal ? "FATAL " : "") << (is_error ? "ERROR " : "") << str << std::endl;
break;
}
if (is_fatal) {
@@ -403,7 +396,7 @@ void Server::buildIdList(size_t size) {
srand(time(NULL));
do lst.insert(((uint64_t)rand() << 32 | rand()));
while (lst.size() < size);
m_ids = std::vector<uint64_t>(lst.begin(), lst.end());
}