From 573316682b4be1778ae591281bd468f6a8fb4bc4 Mon Sep 17 00:00:00 2001 From: MarcEricMartel Date: Fri, 24 Nov 2023 14:15:40 -0500 Subject: [PATCH] Jim Babwe --- SQCSim-common/netprotocol.cpp | 2 -- SQCSim-srv/connection.cpp | 17 ++++++++++------- SQCSim-srv/connection.h | 2 ++ SQCSim-srv/server.cpp | 2 ++ 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/SQCSim-common/netprotocol.cpp b/SQCSim-common/netprotocol.cpp index 40a535c..8f05c06 100644 --- a/SQCSim-common/netprotocol.cpp +++ b/SQCSim-common/netprotocol.cpp @@ -471,8 +471,6 @@ bool netprot::Deserialize(Input* in, char* buf, uint32_t *buflen) { memcpy(&in->direction, vec, sizeof(uint32_t) * 3); - in->direction.Afficher(); - *buflen = sizeof(uint64_t) * 2 + 2 + sizeof(uint32_t) * 3; return true; diff --git a/SQCSim-srv/connection.cpp b/SQCSim-srv/connection.cpp index 3d0d79f..110b325 100644 --- a/SQCSim-srv/connection.cpp +++ b/SQCSim-srv/connection.cpp @@ -52,6 +52,10 @@ void Connection::getPacks(SOCKET sock) { Input in; while (true) { lsPck = recvPacksFrom(sock, &m_buf, m_addr); + + if (lsPck.empty() && !m_buf.tmp) + break; + for (auto& pck : lsPck) { uint32_t bsize = m_buf.len - (pck - m_buf.ptr); switch (netprot::getType(pck, 1)) { @@ -59,8 +63,7 @@ void Connection::getPacks(SOCKET sock) { case INPUT: if (Deserialize(&in, pck, &bsize)) { m_input_manifest[in.timestamp] = in; - if (in.keys.forward == true) - std::cout << "!!!!"; + m_input_vector.push_back(in); } break; default: break; @@ -72,8 +75,7 @@ void Connection::getPacks(SOCKET sock) { void Connection::sendPacks(SOCKET sock, std::unordered_map conns) { while (m_last_out < m_output_manifest.size()) { - Output out = m_output_manifest.at(m_last_out++); - std::cout << "bip"; + Output out = m_output_vector.at(m_last_out++); for (auto& [key, conn] : conns) { if (m_playinfo.id == conn->GetHash(true)) continue; @@ -90,9 +92,9 @@ void Connection::Run(World* world) { if (m_input_manifest.size() < 2) return; - while (m_last_in < m_input_manifest.size()) { - in = m_input_manifest.at(m_last_in + 1); - last = m_input_manifest.at(m_last_in); + while (m_last_in < m_input_vector.size() - 1) { + in = m_input_vector.at(m_last_in + 1); + last = m_input_vector.at(m_last_in); el = (float)(in.timestamp - last.timestamp) / 1000.; player.get()->SetDirection(in.direction); @@ -108,6 +110,7 @@ void Connection::Run(World* world) { out.id = m_playinfo.id; m_output_manifest[out.timestamp] = out; + m_output_vector.push_back(out); ++m_last_in; } diff --git a/SQCSim-srv/connection.h b/SQCSim-srv/connection.h index af9c2df..27f351c 100644 --- a/SQCSim-srv/connection.h +++ b/SQCSim-srv/connection.h @@ -41,7 +41,9 @@ public: void CleanInputManifest(Timestamp time); private: std::unordered_map m_input_manifest; + std::vector m_input_vector; std::unordered_map m_output_manifest; + std::vector m_output_vector; std::unordered_map m_chatlog; SOCKET m_sock; diff --git a/SQCSim-srv/server.cpp b/SQCSim-srv/server.cpp index 17945e2..9dd0f00 100644 --- a/SQCSim-srv/server.cpp +++ b/SQCSim-srv/server.cpp @@ -201,6 +201,8 @@ void Server::Run() { sendPack(conn->getSock(), &sync, &m_buf); } + std::cout << players << " players." << std::endl; + while (!endgame) { for (auto& [key, conn] : m_players) { conn->getPacks(m_sock_udp);