From 7077b617bebfb6575448d0e68d154f315619c851 Mon Sep 17 00:00:00 2001 From: MarcEricMartel Date: Wed, 6 Dec 2023 15:37:08 -0500 Subject: [PATCH] Rollover Beethoven --- SQCSim-common/netprotocol.cpp | 12 +++++++++++- SQCSim-common/netprotocol.h | 2 +- SQCSim-srv/server.cpp | 16 +++++++++++----- SQCSim2021/engine.cpp | 24 ++++++++++++------------ 4 files changed, 35 insertions(+), 19 deletions(-) diff --git a/SQCSim-common/netprotocol.cpp b/SQCSim-common/netprotocol.cpp index 33a4533..a1e2b77 100644 --- a/SQCSim-common/netprotocol.cpp +++ b/SQCSim-common/netprotocol.cpp @@ -405,7 +405,14 @@ void netprot::Serialize(Chat* chat, char* buf[], uint32_t* buflen) { size_t messize = std::strlen(chat->mess) + 1; - memcpy(*buf + 1 + sizeof(uint64_t) * 3, &chat->mess, messize); + std::cout << chat->mess << ": "; + + strcpy(*buf + 1 + sizeof(uint64_t) * 3, messize, chat->mess); + + //memcpy(*buf + 1 + sizeof(uint64_t) * 3, &chat->mess, messize); + + for (int x = 0; x < sizeof(Chat); ++x) + std::cout << *(*buf + x); *buflen = messize + sizeof(uint64_t) * 3 + 2; } @@ -928,6 +935,9 @@ bool netprot::Deserialize(Chat* chat, char* buf, uint32_t *buflen) { if (messsize > 140) return false; + for (int x = 0; x < 140; ++x) + std::cout << buf[sizeof(uint64_t) * 3 + x]; + memcpy(&chat->mess, &buf[1 + sizeof(uint64_t) * 3], messsize); *buflen = messsize + sizeof(uint64_t) * 3 + 2; diff --git a/SQCSim-common/netprotocol.h b/SQCSim-common/netprotocol.h index 7fb8c94..f724226 100644 --- a/SQCSim-common/netprotocol.h +++ b/SQCSim-common/netprotocol.h @@ -129,7 +129,7 @@ namespace netprot { Chat() {} Chat(Chat* cha) : src_id(cha->src_id), dest_id(cha->dest_id), dest_team_id(cha->dest_team_id) { strcpy(mess, 140, cha->mess); } - ~Chat() { delete[] mess; } + ~Chat() {/* delete[] mess; */} }; struct ChunkMod { diff --git a/SQCSim-srv/server.cpp b/SQCSim-srv/server.cpp index c68fd90..0e5221d 100644 --- a/SQCSim-srv/server.cpp +++ b/SQCSim-srv/server.cpp @@ -83,17 +83,18 @@ int Server::Ready() { m_game.countdown = 0; } } while (m_game.countdown < 1); - do { + m_game.seed = 9370707; + /*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); + std::stoi(m_buf.ptr); } catch (const std::exception& e) { Log(e.what(), true, false); m_game.seed = 0; } - } while (m_game.seed < 1); + } while (m_game.seed < 1);*/ do { Log("Entrez le nombre de joueurs: ", false, false); std::cin.getline(m_buf.ptr, BUFFER_LENGTH); @@ -312,10 +313,12 @@ void Server::Run() { endgame = true; } - for (auto& bull : netbull) + for (auto& bull : netbull) { for (auto& [key, conn] : m_conns) if (bull->id != conn->GetHash(false)) // Pour pas repitcher au joueur sa propre balle. sendPackTo(m_sock_udp, bull, &m_buf, conn->getAddr()); + delete bull; + } for (auto& bull : bullets) { @@ -327,6 +330,10 @@ void Server::Run() { } } + //for (auto& bull : outbox_bullets) + // delete bull; + //outbox_bullets.clear(); + for (auto& chat : chatlog) { Log(chat->mess, false, false); for (auto& [key, conn] : m_conns) @@ -340,7 +347,6 @@ void Server::Run() { delete chmo; } - outbox_bullets.clear(); netbull.clear(); chunkdiffs.clear(); chatlog.clear(); diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp index de2e9af..f405712 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -90,7 +90,7 @@ void Engine::Init() { RemotePlayer* rt = (RemotePlayer*)m_players[key]; rt->SetPosition(Vector3f(555, 555, 555)); } - + m_player.m_username = playname; seed = 9370707;//m_conn.getSeed(); m_networkgame = true; } @@ -659,17 +659,17 @@ void Engine::PrintText(float x, float y, const std::string& t, float charSizeMul int Engine::GetFps(float elapsedTime) const { return 1 / elapsedTime; } int Engine::GetCountdown(float elapsedTime) { - if (m_resetcountdown) { - m_nbReductionChunk = 4; - m_timerReductionChunk = 30; - m_countdown = m_time + COUNTDOWN; - m_resetcountdown = false; - } - if (m_countdown < m_time) {} - //Stop(); - if (!m_stopcountdown) - m_time += elapsedTime; - return m_countdown - (int)m_time; + //if (m_resetcountdown) { +// m_nbReductionChunk = 4; +// m_timerReductionChunk = 30; + // m_countdown = m_time + COUNTDOWN; +// m_resetcountdown = false; +// } +// if (m_countdown < m_time) {} + // Stop(); + //if (!m_stopcountdown) + // m_time += elapsedTime; + return m_countdown;// -(int)m_time; } int Engine::GetOptionsChoice() {