From 20eb410b082adf6c2a7a27877f422c04ffd3e56c Mon Sep 17 00:00:00 2001 From: MarcEricMartel Date: Sat, 2 Dec 2023 10:04:18 -0500 Subject: [PATCH] Hahaha il manquait les ChunkMods dans netprot :finnadie: --- SQCSim-common/netprotocol.cpp | 56 +++++++++++++++++++++++++++++++++++ SQCSim-common/netprotocol.h | 7 +++++ SQCSim-srv/connection.cpp | 3 -- SQCSim-srv/connection.h | 5 ++++ SQCSim-srv/server.cpp | 8 +++++ 5 files changed, 76 insertions(+), 3 deletions(-) diff --git a/SQCSim-common/netprotocol.cpp b/SQCSim-common/netprotocol.cpp index 8f05c06..5441a5b 100644 --- a/SQCSim-common/netprotocol.cpp +++ b/SQCSim-common/netprotocol.cpp @@ -402,6 +402,33 @@ void netprot::Serialize(Chat* chat, char* buf[], uint32_t* buflen) { *buflen = messize + sizeof(uint64_t) * 3 + 2; } +void netprot::Serialize(ChunkMod* chmod, char* buf[], uint32_t* buflen) { + *buf[0] = (char)netprot::PACKET_TYPE::CHUNKMOD; + + uint32_t vec[3]; + memcpy(vec, &chmod->pos, sizeof(Vector3f)); // Pour d�naturer les floats. + + uint8_t vec8[3 * sizeof(uint32_t)] = { + (uint8_t)((vec[0] >> 24) & 0xFF), + (uint8_t)((vec[0] >> 16) & 0xFF), + (uint8_t)((vec[0] >> 8) & 0xFF), + (uint8_t)(vec[0] & 0xFF), + (uint8_t)((vec[1] >> 24) & 0xFF), + (uint8_t)((vec[1] >> 16) & 0xFF), + (uint8_t)((vec[1] >> 8) & 0xFF), + (uint8_t)(vec[1] & 0xFF), + (uint8_t)((vec[2] >> 24) & 0xFF), + (uint8_t)((vec[2] >> 16) & 0xFF), + (uint8_t)((vec[2] >> 8) & 0xFF), + (uint8_t)(vec[2] & 0xFF) }; + + memcpy(*buf + 1, vec8, sizeof(uint32_t) * 3); + + memcpy(*buf + sizeof(uint32_t) * 3 + 1, &chmod->b_type, sizeof(BlockType)); + + *buflen = sizeof(uint32_t) * 3 + 2; +} + void netprot::Serialize(ErrorLog* errlog, char* buf[], uint32_t* buflen) { *buf[0] = (char)netprot::PACKET_TYPE::ERRLOG; @@ -818,6 +845,35 @@ bool netprot::Deserialize(Chat* chat, char* buf, uint32_t *buflen) { return true; } +bool netprot::Deserialize(ChunkMod* chmod, char* buf, uint32_t* buflen) { + if (*buflen <= sizeof(ChunkMod)) + return false; + + uint8_t subvec[3 * sizeof(uint32_t)] = { 0,0,0,0,0,0,0,0,0,0,0,0 }; + memcpy(subvec, &buf[1], sizeof(uint8_t) * 12); + uint32_t vec[3] = { + (uint32_t)subvec[0] << 24 | + (uint32_t)subvec[1] << 16 | + (uint32_t)subvec[2] << 8 | + (uint32_t)subvec[3], + (uint32_t)subvec[4] << 24 | + (uint32_t)subvec[5] << 16 | + (uint32_t)subvec[6] << 8 | + (uint32_t)subvec[7], + (uint32_t)subvec[8] << 24 | + (uint32_t)subvec[9] << 16 | + (uint32_t)subvec[10] << 8 | + (uint32_t)subvec[11] }; + + memcpy(&chmod->pos, vec, sizeof(uint32_t) * 3); + + memcpy(&chmod->b_type, &buf[1 + sizeof(uint8_t) * 12], sizeof(BlockType)); + + *buflen = sizeof(uint32_t) * 3 + 2; + + return true; +} + bool netprot::Deserialize(ErrorLog* errlog, char* buf, uint32_t *buflen) { if (*buflen <= sizeof(ErrorLog)) return false; diff --git a/SQCSim-common/netprotocol.h b/SQCSim-common/netprotocol.h index b6f78c9..c7223dd 100644 --- a/SQCSim-common/netprotocol.h +++ b/SQCSim-common/netprotocol.h @@ -130,6 +130,11 @@ namespace netprot { Chat(Chat* cha) : src_id(cha->src_id), dest_id(cha->dest_id), dest_team_id(cha->dest_team_id) { strcpy(cha->mess, mess); } }; + struct ChunkMod { + Vector3f pos; + BlockType b_type; + }; + struct ErrorLog { // srv -> cli TCP event char mess[140]; bool is_fatal; @@ -147,6 +152,7 @@ namespace netprot { void Serialize(PlayerInfo* pinfo, char* buf[], uint32_t* buflen); // srv void Serialize(GameInfo* ginfo, char* buf[], uint32_t* buflen); // cli/srv void Serialize(Chat* chat, char* buf[], uint32_t* buflen); // cli/srv + void Serialize(ChunkMod* chmod, char* buf[], uint32_t* buflen); // srv void Serialize(ErrorLog* errlog, char* buf[], uint32_t* buflen); // srv bool Deserialize(Input* in, char* buf, uint32_t* buflen); // srv @@ -157,6 +163,7 @@ namespace netprot { bool Deserialize(PlayerInfo* pinfo, char* buf, uint32_t* buflen); // cli bool Deserialize(GameInfo* ginfo, char* buf, uint32_t* buflen); // cli bool Deserialize(Chat* chat, char* buf, uint32_t* buflen); // srv/cli + bool Deserialize(ChunkMod* chmod, char* buf, uint32_t* buflen); // cli bool Deserialize(ErrorLog* errlog, char* buf, uint32_t* buflen); // srv PACKET_TYPE getType(char* buf, uint32_t buflen); diff --git a/SQCSim-srv/connection.cpp b/SQCSim-srv/connection.cpp index ac01b5f..74e0506 100644 --- a/SQCSim-srv/connection.cpp +++ b/SQCSim-srv/connection.cpp @@ -122,9 +122,7 @@ void Connection::Run(World* world) { last = m_input_vector.at(m_last_in); el = (double)(in.timestamp - last.timestamp) / 1000.; - std::cout << 1. / el << std::endl; player.get()->SetDirection(in.direction); - std::cout << in.direction << std::endl; player.get()->ApplyPhysics(player.get()->GetInput(in.keys.forward, in.keys.backward, in.keys.left, @@ -132,7 +130,6 @@ void Connection::Run(World* world) { in.keys.jump, false, el), world, el); out.position = player.get()->GetPositionAbs(); - player.get()->GetPositionAbs().Afficher(); out.direction = in.direction; out.timestamp = in.timestamp; out.id = m_playinfo.id; diff --git a/SQCSim-srv/connection.h b/SQCSim-srv/connection.h index a9d171a..4af3596 100644 --- a/SQCSim-srv/connection.h +++ b/SQCSim-srv/connection.h @@ -41,6 +41,10 @@ public: void CleanInputManifest(Timestamp time); bool m_nsync = true; + + std::vector m_bullet_vector; + std::vector m_diff_vector; + private: std::unordered_map m_input_manifest; std::vector m_input_vector; @@ -48,6 +52,7 @@ private: std::deque m_output_vector; std::unordered_map m_chatlog; + SOCKET m_sock; sockaddr_in m_addr; LoginInfo m_loginfo; diff --git a/SQCSim-srv/server.cpp b/SQCSim-srv/server.cpp index 77f31e8..7b1f0e7 100644 --- a/SQCSim-srv/server.cpp +++ b/SQCSim-srv/server.cpp @@ -230,6 +230,9 @@ void Server::Run() { } for (auto& [key, conn] : m_players) { + + /* In */ + int deadplayers = 0; std::vector lsPck; Input in; Chat chat; Sync sync; @@ -254,6 +257,8 @@ void Server::Run() { } lsPck.clear(); + /* Process */ + if (conn->m_nsync) { if (conn->player->AmIDead()) { ++deadplayers; @@ -261,6 +266,9 @@ void Server::Run() { continue; } conn->Run(m_world); + + /* Out */ + conn->sendPacks(m_sock_udp, m_players, timer); }