LCOV - code coverage report
Current view: top level - source/network - NetHost.h (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 0 1 0.0 %
Date: 2023-01-19 00:18:29 Functions: 0 3 0.0 %

          Line data    Source code
       1             : /* Copyright (C) 2019 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 NETHOST_H
      19             : #define NETHOST_H
      20             : 
      21             : #include "ps/CStr.h"
      22             : 
      23             : #include <map>
      24             : 
      25             : /**
      26             :  * @file
      27             :  * Various declarations shared by networking code.
      28             :  */
      29             : 
      30             : typedef struct _ENetPeer ENetPeer;
      31             : typedef struct _ENetPacket ENetPacket;
      32             : typedef struct _ENetHost ENetHost;
      33             : class CNetMessage;
      34             : 
      35           0 : struct PlayerAssignment
      36             : {
      37             :     /**
      38             :      * Whether the player is currently connected and active.
      39             :      * (We retain information on disconnected players to support rejoining,
      40             :      * but don't transmit these to other clients.)
      41             :      */
      42             :     bool m_Enabled;
      43             : 
      44             :     /// Player name
      45             :     CStrW m_Name;
      46             : 
      47             :     /// The player that the given host controls, or -1 if none (observer)
      48             :     i32 m_PlayerID;
      49             : 
      50             :     /// Status - Ready or not: 0 for not ready, 1 for ready, 2 to stay ready
      51             :     u8 m_Status;
      52             : };
      53             : 
      54             : typedef std::map<CStr, PlayerAssignment> PlayerAssignmentMap; // map from GUID -> assignment
      55             : 
      56             : /**
      57             :  * Reasons sent by server to clients in disconnection messages.
      58             :  * Must be kept in sync with binaries/data/mods/public/gui/common/network.js
      59             :  * To avoid ambiguity, use a distinct reason for each callstack leading to a disconnect.
      60             :  * NDR_UNKNOWN should remain reserved to the case where it is actually not a known disconnect by the server.
      61             :  */
      62             : enum NetDisconnectReason
      63             : {
      64             :     NDR_UNKNOWN = 0,
      65             :     NDR_SERVER_SHUTDOWN,
      66             :     NDR_INCORRECT_PROTOCOL_VERSION,
      67             :     NDR_SERVER_LOADING,
      68             :     NDR_SERVER_ALREADY_IN_GAME,
      69             :     NDR_KICKED,
      70             :     NDR_BANNED,
      71             :     NDR_PLAYERNAME_IN_USE,
      72             :     NDR_SERVER_FULL,
      73             :     NDR_LOBBY_AUTH_FAILED,
      74             :     NDR_GUID_FAILED,
      75             :     NDR_INCORRECT_READY_TURN_COMMANDS,
      76             :     NDR_INCORRECT_READY_TURN_SIMULATED,
      77             :     NDR_SERVER_REFUSED,
      78             :     NDR_STUN_PORT_FAILED,
      79             :     NDR_STUN_ENDPOINT_FAILED
      80             : };
      81             : 
      82             : class CNetHost
      83             : {
      84             : public:
      85             :     static const int DEFAULT_CHANNEL = 0;
      86             : 
      87             :     /**
      88             :      * Transmit a message to the given peer.
      89             :      * @param message message to send
      90             :      * @param peer peer to send to
      91             :      * @param peerName name of peer for debug logs
      92             :      * @return true on success, false on failure
      93             :      */
      94             :     static bool SendMessage(const CNetMessage* message, ENetPeer* peer, const char* peerName);
      95             : 
      96             :     /**
      97             :      * Construct an ENet packet by serialising the given message.
      98             :      * @return NULL on failure
      99             :      */
     100             :     static ENetPacket* CreatePacket(const CNetMessage* message);
     101             : 
     102             :     /**
     103             :      * Initialize ENet.
     104             :      * This must be called before any other networking code.
     105             :      */
     106             :     static void Initialize();
     107             : 
     108             :     /**
     109             :      * Deinitialize ENet.
     110             :      */
     111             :     static void Deinitialize();
     112             : };
     113             : 
     114             : #endif  // NETHOST_H

Generated by: LCOV version 1.13