LCOV - code coverage report
Current view: top level - source/network - NetServerSession.h (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 0 8 0.0 %
Date: 2026-12-03 01:19:39 Functions: 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 NET_SERVER_SESSION_H
      19             : #define NET_SERVER_SESSION_H
      20             : 
      21             : #include "network/FSM.h"
      22             : #include "network/NetFileTransfer.h"
      23             : #include "network/NetHost.h"
      24             : #include "ps/CStr.h"
      25             : 
      26             : class CNetServerWorker;
      27             : 
      28             : typedef struct _ENetPeer ENetPeer;
      29             : 
      30             : /**
      31             :  * The server's end of a network session.
      32             :  * Represents an abstraction of the state of the client, storing all the per-client data
      33             :  * needed by the server.
      34             :  *
      35             :  * Thread-safety:
      36             :  * - This is constructed and used by CNetServerWorker in the network server thread.
      37             :  */
      38             : class CNetServerSession : public CFsm<CNetServerSession, CNetMessage*>
      39             : {
      40             :     NONCOPYABLE(CNetServerSession);
      41             : 
      42             : public:
      43             :     CNetServerSession(CNetServerWorker& server, ENetPeer* peer);
      44             : 
      45           0 :     CNetServerWorker& GetServer() { return m_Server; }
      46             : 
      47           0 :     const CStr& GetGUID() const { return m_GUID; }
      48           0 :     void SetGUID(const CStr& guid) { m_GUID = guid; }
      49             : 
      50           0 :     const CStrW& GetUserName() const { return m_UserName; }
      51           0 :     void SetUserName(const CStrW& name) { m_UserName = name; }
      52             : 
      53           0 :     std::uint32_t GetHostID() const { return m_HostID; }
      54           0 :     void SetHostID(std::uint32_t id) { m_HostID = id; }
      55             : 
      56             :     std::uint32_t GetIPAddress() const;
      57             : 
      58             :     /**
      59             :      * Number of milliseconds since the latest packet of that client was received.
      60             :      */
      61             :     std::uint32_t GetLastReceivedTime() const;
      62             : 
      63             :     /**
      64             :      * Average round trip time to the client.
      65             :      */
      66             :     std::uint32_t GetMeanRTT() const;
      67             : 
      68             :     /**
      69             :      * Sends a disconnection notification to the client,
      70             :      * and sends a NMT_CONNECTION_LOST message to the session FSM.
      71             :      * The server will receive a disconnection notification after a while.
      72             :      * The server will not receive any further messages sent via this session.
      73             :      */
      74             :     void Disconnect(NetDisconnectReason reason);
      75             : 
      76             :     /**
      77             :      * Sends an unreliable disconnection notification to the client.
      78             :      * The server will not receive any disconnection notification.
      79             :      * The server will not receive any further messages sent via this session.
      80             :      */
      81             :     void DisconnectNow(NetDisconnectReason reason);
      82             : 
      83             :     /**
      84             :      * Send a message to the client.
      85             :      */
      86             :     bool SendMessage(const CNetMessage* message);
      87             : 
      88           0 :     CNetFileTransferer& GetFileTransferer() { return m_FileTransferer; }
      89             : 
      90             : private:
      91             :     CNetServerWorker& m_Server;
      92             : 
      93             :     CNetFileTransferer m_FileTransferer;
      94             : 
      95             :     ENetPeer* m_Peer;
      96             : 
      97             :     CStr m_GUID;
      98             :     CStrW m_UserName;
      99             :     std::uint32_t m_HostID{0};
     100             :     CStr m_Password;
     101             : };
     102             : 
     103             : #endif // NET_SERVER_SESSION_H

Generated by: LCOV version 1.16