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

          Line data    Source code
       1             : /* Copyright (C) 2025 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             : #include "precompiled.h"
      19             : 
      20             : #include "NetProtocol.h"
      21             : 
      22             : #include "ps/CStr.h"
      23             : 
      24             : #include <algorithm>
      25             : #include <cstdint>
      26             : 
      27             : namespace
      28             : {
      29             : template <typename ModType>
      30           0 : std::string GetModName(const ModType& mod)
      31             : {
      32           0 :     return mod.m_Name + "-" + mod.m_Version;
      33             : }
      34             : }
      35             : 
      36           0 : std::optional<HandshakeError> CheckHandshake(const CSrvHandshakeMessage& serverMessage, const CCliHandshakeMessage& clientMessage)
      37             : {
      38           0 :     if (serverMessage.m_EngineVersion != clientMessage.m_EngineVersion)
      39           0 :         return HandshakeError{"engine", clientMessage.m_EngineVersion, serverMessage.m_EngineVersion};
      40             : 
      41             :     const auto& serverMods = serverMessage.m_EnabledMods;
      42             :     const auto& clientMods = clientMessage.m_EnabledMods;
      43             : 
      44           0 :     for (uint32_t i = 0; i < std::max(clientMods.size(), serverMods.size()); ++i)
      45             :     {
      46           0 :         if (i >= serverMods.size())
      47           0 :             return HandshakeError{"mod", GetModName(clientMods[i]), ""};
      48             : 
      49           0 :         if (i >= clientMods.size())
      50           0 :             return HandshakeError{"mod", "", GetModName(serverMods[i])};
      51             : 
      52           0 :         const std::string serverMod = GetModName(serverMods[i]);
      53           0 :         const std::string clientMod = GetModName(clientMods[i]);
      54             : 
      55             :         // Client and server have different mods enabled, or mods enabled in a different order
      56           0 :         if (clientMod != serverMod)
      57           0 :             return HandshakeError{"mod", clientMod, serverMod};
      58           0 :     }
      59             : 
      60           0 :     return {};
      61           0 : }

Generated by: LCOV version 1.16