LCOV - code coverage report
Current view: top level - source/network - NetProtocol.h (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 0 15 0.0 %
Date: 2026-12-03 01:19:39 Functions: 0 2 0.0 %

          Line data    Source code
       1             : /* Copyright (C) 2026 Wildfire Games.
       2             :  * This file is part of 0 A.D.
       3             :  *
       4             :  * 0 A.D. is free software: you can redistribute it and/or modify
       5             :  * it under the terms of the GNU General Public License as published by
       6             :  * the Free Software Foundation, either version 2 of the License, or
       7             :  * (at your option) any later version.
       8             :  *
       9             :  * 0 A.D. is distributed in the hope that it will be useful,
      10             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12             :  * GNU General Public License for more details.
      13             :  *
      14             :  * You should have received a copy of the GNU General Public License
      15             :  * along with 0 A.D.  If not, see <http://www.gnu.org/licenses/>.
      16             :  */
      17             : 
      18             : #ifndef NETPROTOCOL_H
      19             : #define NETPROTOCOL_H
      20             : 
      21             : #include "network/NetMessage.h"
      22             : #include "ps/Mod.h"
      23             : #include "ps/Pyrogenesis.h"
      24             : 
      25             : #include <optional>
      26             : #include <string>
      27             : #include <type_traits>
      28             : #include <vector>
      29             : 
      30             : /**
      31             :  * Report the peer if we didn't receive a packet after this time (milliseconds).
      32             :  */
      33             : inline constexpr std::uint32_t NETWORK_WARNING_TIMEOUT{2000};
      34             : 
      35             : struct HandshakeError
      36             : {
      37             :     std::string componentType;
      38             :     std::string clientComponent;
      39             :     std::string serverComponent;
      40             : };
      41             : 
      42             : template <typename Message>
      43           0 : Message CreateHandshake() {
      44           0 :     Message handshake;
      45             : 
      46             :     if constexpr (std::is_same_v<Message, CCliHandshakeMessage>)
      47           0 :         handshake.m_MagicResponse = PS_PROTOCOL_MAGIC_RESPONSE;
      48             :     else
      49           0 :         handshake.m_Magic = PS_PROTOCOL_MAGIC;
      50             : 
      51           0 :     handshake.m_ProtocolVersion = PS_PROTOCOL_VERSION;
      52           0 :     handshake.m_EngineVersion = PS_SERIALIZATION_VERSION;
      53             : 
      54           0 :     for (const Mod::ModData* mod : Mod::Instance().GetEnabledModsData())
      55             :     {
      56           0 :         if (mod->m_IgnoreInCompatibilityChecks)
      57           0 :             continue;
      58             : 
      59           0 :         typename Message::S_m_EnabledMods enabledMod;
      60           0 :         enabledMod.m_Name = mod->m_Name;
      61           0 :         enabledMod.m_Version = mod->m_Version;
      62           0 :         handshake.m_EnabledMods.push_back(enabledMod);
      63             :     }
      64             : 
      65           0 :     return handshake;
      66           0 : }
      67             : 
      68             : std::optional<HandshakeError> CheckHandshake(const CSrvHandshakeMessage& serverMessage, const CCliHandshakeMessage& clientMessage);
      69             : 
      70             : #endif

Generated by: LCOV version 1.16