LCOV - code coverage report
Current view: top level - source/network - NetMessages.h (source / functions) Hit Total Coverage
Test: 0 A.D. test coverage report Lines: 0 549 0.0 %
Date: 2021-09-24 14:46:47 Functions: 0 130 0.0 %

          Line data    Source code
       1             : /* Copyright (C) 2021 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             : /**
      19             :  * @file
      20             :  * The list of messages used by the network subsystem.
      21             :  */
      22             : 
      23             : #ifndef NETMESSAGES_H
      24             : #define NETMESSAGES_H
      25             : 
      26             : #include "ps/CStr.h"
      27             : #include "scriptinterface/ScriptTypes.h"
      28             : 
      29             : #define PS_PROTOCOL_MAGIC                         0x5073013f    // 'P', 's', 0x01, '?'
      30             : #define PS_PROTOCOL_MAGIC_RESPONSE                0x50630121    // 'P', 'c', 0x01, '!'
      31             : #define PS_PROTOCOL_VERSION                       0x01010018    // Arbitrary protocol
      32             : #define PS_DEFAULT_PORT                           0x5073        // 'P', 's'
      33             : 
      34             : // Set when lobby authentication is required. Used in the SrvHandshakeResponseMessage.
      35             : #define PS_NETWORK_FLAG_REQUIRE_LOBBYAUTH         0x1
      36             : 
      37             : // Defines the list of message types. The order of the list must not change.
      38             : // The message types having a negative value are used internally and not sent
      39             : // over the network. The message types used for network communication have
      40             : // positive values.
      41             : enum NetMessageType
      42             : {
      43             :     NMT_CONNECT_COMPLETE = -256,
      44             :     NMT_CONNECTION_LOST,
      45             :     NMT_INVALID = 0,
      46             : 
      47             :     NMT_SERVER_HANDSHAKE,
      48             :     NMT_CLIENT_HANDSHAKE,
      49             :     NMT_SERVER_HANDSHAKE_RESPONSE,
      50             : 
      51             :     NMT_AUTHENTICATE,
      52             :     NMT_AUTHENTICATE_RESULT,
      53             : 
      54             :     NMT_CHAT,
      55             :     NMT_READY,
      56             :     NMT_CLEAR_ALL_READY,
      57             :     NMT_GAME_SETUP,
      58             :     NMT_ASSIGN_PLAYER,
      59             :     NMT_PLAYER_ASSIGNMENT,
      60             : 
      61             :     NMT_FILE_TRANSFER_REQUEST,
      62             :     NMT_FILE_TRANSFER_RESPONSE,
      63             :     NMT_FILE_TRANSFER_DATA,
      64             :     NMT_FILE_TRANSFER_ACK,
      65             : 
      66             :     NMT_JOIN_SYNC_START,
      67             : 
      68             :     NMT_REJOINED,
      69             :     NMT_KICKED,
      70             : 
      71             :     NMT_CLIENT_TIMEOUT,
      72             :     NMT_CLIENT_PERFORMANCE,
      73             :     NMT_CLIENTS_LOADING,
      74             :     NMT_CLIENT_PAUSED,
      75             : 
      76             :     NMT_LOADED_GAME,
      77             :     NMT_GAME_START,
      78             :     NMT_END_COMMAND_BATCH,
      79             : 
      80             :     NMT_SYNC_CHECK, // OOS-detection hash checking
      81             :     NMT_SYNC_ERROR, // OOS-detection error
      82             : 
      83             :     NMT_SIMULATION_COMMAND
      84             : };
      85             : 
      86             : // Authentication result codes
      87             : enum AuthenticateResultCode
      88             : {
      89             :     ARC_OK,
      90             :     ARC_OK_REJOINING,
      91             :     ARC_PASSWORD_INVALID,
      92             : };
      93             : 
      94             : #endif //   NETMESSAGES_H
      95             : 
      96             : #ifdef CREATING_NMT
      97             : 
      98             : #define ALLNETMSGS_DONT_CREATE_NMTS
      99             : #define START_NMT_CLASS_(_nm, _message) START_NMT_CLASS(C##_nm##Message, _message)
     100             : #define DERIVE_NMT_CLASS_(_base, _nm, _message) START_NMT_CLASS_DERIVED(C ## _base ## Message, C ## _nm ## Message, _message)
     101             : 
     102             : START_NMTS()
     103             : 
     104           0 : START_NMT_CLASS_(SrvHandshake, NMT_SERVER_HANDSHAKE)
     105           0 :     NMT_FIELD_INT(m_Magic, u32, 4)
     106           0 :     NMT_FIELD_INT(m_ProtocolVersion, u32, 4)
     107           0 :     NMT_FIELD_INT(m_SoftwareVersion, u32, 4)
     108           0 : END_NMT_CLASS()
     109           0 : 
     110           0 : START_NMT_CLASS_(CliHandshake, NMT_CLIENT_HANDSHAKE)
     111           0 :     NMT_FIELD_INT(m_MagicResponse, u32, 4)
     112           0 :     NMT_FIELD_INT(m_ProtocolVersion, u32, 4)
     113           0 :     NMT_FIELD_INT(m_SoftwareVersion, u32, 4)
     114           0 : END_NMT_CLASS()
     115           0 : 
     116           0 : START_NMT_CLASS_(SrvHandshakeResponse, NMT_SERVER_HANDSHAKE_RESPONSE)
     117           0 :     NMT_FIELD_INT(m_UseProtocolVersion, u32, 4)
     118           0 :     NMT_FIELD_INT(m_Flags, u32, 4)
     119           0 :     NMT_FIELD(CStr, m_GUID)
     120           0 : END_NMT_CLASS()
     121           0 : 
     122           0 : START_NMT_CLASS_(Authenticate, NMT_AUTHENTICATE)
     123           0 :     NMT_FIELD(CStrW, m_Name)
     124           0 :     NMT_FIELD_SECRET(CStr, m_Password)
     125           0 :     NMT_FIELD_SECRET(CStr, m_ControllerSecret)
     126           0 : END_NMT_CLASS()
     127           0 : 
     128           0 : START_NMT_CLASS_(AuthenticateResult, NMT_AUTHENTICATE_RESULT)
     129             :     NMT_FIELD_INT(m_Code, u32, 4)
     130           0 :     NMT_FIELD_INT(m_HostID, u32, 2)
     131           0 :     NMT_FIELD_INT(m_IsController, u8, 1)
     132           0 :     NMT_FIELD(CStrW, m_Message)
     133           0 : END_NMT_CLASS()
     134           0 : 
     135           0 : START_NMT_CLASS_(Chat, NMT_CHAT)
     136           0 :     NMT_FIELD(CStr, m_GUID) // ignored when client->server, valid when server->client
     137           0 :     NMT_FIELD(CStrW, m_Message)
     138           0 : END_NMT_CLASS()
     139           0 : 
     140           0 : START_NMT_CLASS_(Ready, NMT_READY)
     141           0 :     NMT_FIELD(CStr, m_GUID)
     142           0 :     NMT_FIELD_INT(m_Status, u8, 1)
     143           0 : END_NMT_CLASS()
     144           0 : 
     145           0 : START_NMT_CLASS_(ClearAllReady, NMT_CLEAR_ALL_READY)
     146           0 : END_NMT_CLASS()
     147           0 : 
     148           0 : START_NMT_CLASS_(PlayerAssignment, NMT_PLAYER_ASSIGNMENT)
     149           0 :     NMT_START_ARRAY(m_Hosts)
     150           0 :         NMT_FIELD(CStr, m_GUID)
     151           0 :         NMT_FIELD(CStrW, m_Name)
     152           0 :         NMT_FIELD_INT(m_PlayerID, i8, 1)
     153           0 :         NMT_FIELD_INT(m_Status, u8, 1)
     154           0 :     NMT_END_ARRAY()
     155             : END_NMT_CLASS()
     156           0 : 
     157           0 : START_NMT_CLASS_(FileTransferRequest, NMT_FILE_TRANSFER_REQUEST)
     158           0 :     NMT_FIELD_INT(m_RequestID, u32, 4)
     159           0 : END_NMT_CLASS()
     160           0 : 
     161           0 : START_NMT_CLASS_(FileTransferResponse, NMT_FILE_TRANSFER_RESPONSE)
     162           0 :     NMT_FIELD_INT(m_RequestID, u32, 4)
     163           0 :     NMT_FIELD_INT(m_Length, u32, 4)
     164           0 : END_NMT_CLASS()
     165           0 : 
     166           0 : START_NMT_CLASS_(FileTransferData, NMT_FILE_TRANSFER_DATA)
     167           0 :     NMT_FIELD_INT(m_RequestID, u32, 4)
     168           0 :     NMT_FIELD(CStr, m_Data)
     169           0 : END_NMT_CLASS()
     170             : 
     171           0 : START_NMT_CLASS_(FileTransferAck, NMT_FILE_TRANSFER_ACK)
     172           0 :     NMT_FIELD_INT(m_RequestID, u32, 4)
     173           0 :     NMT_FIELD_INT(m_NumPackets, u32, 4)
     174           0 : END_NMT_CLASS()
     175           0 : 
     176           0 : START_NMT_CLASS_(JoinSyncStart, NMT_JOIN_SYNC_START)
     177           0 :     NMT_FIELD(CStr, m_InitAttributes)
     178           0 : END_NMT_CLASS()
     179           0 : 
     180           0 : START_NMT_CLASS_(Rejoined, NMT_REJOINED)
     181             :     NMT_FIELD(CStr, m_GUID)
     182           0 : END_NMT_CLASS()
     183           0 : 
     184           0 : START_NMT_CLASS_(Kicked, NMT_KICKED)
     185           0 :     NMT_FIELD(CStrW, m_Name)
     186           0 :     NMT_FIELD_INT(m_Ban, u8, 1)
     187           0 : END_NMT_CLASS()
     188           0 : 
     189           0 : START_NMT_CLASS_(ClientTimeout, NMT_CLIENT_TIMEOUT)
     190           0 :     NMT_FIELD(CStr, m_GUID)
     191           0 :     NMT_FIELD_INT(m_LastReceivedTime, u32, 4)
     192           0 : END_NMT_CLASS()
     193           0 : 
     194           0 : START_NMT_CLASS_(ClientPerformance, NMT_CLIENT_PERFORMANCE)
     195           0 :     NMT_START_ARRAY(m_Clients)
     196             :         NMT_FIELD(CStr, m_GUID)
     197           0 :         NMT_FIELD_INT(m_MeanRTT, u32, 4)
     198           0 :     NMT_END_ARRAY()
     199           0 : END_NMT_CLASS()
     200           0 : 
     201           0 : START_NMT_CLASS_(ClientsLoading, NMT_CLIENTS_LOADING)
     202           0 :     NMT_START_ARRAY(m_Clients)
     203           0 :         NMT_FIELD(CStr, m_GUID)
     204           0 :     NMT_END_ARRAY()
     205           0 : END_NMT_CLASS()
     206           0 : 
     207           0 : START_NMT_CLASS_(ClientPaused, NMT_CLIENT_PAUSED)
     208           0 :     NMT_FIELD(CStr, m_GUID)
     209           0 :     NMT_FIELD_INT(m_Pause, u8, 1)
     210           0 : END_NMT_CLASS()
     211           0 : 
     212           0 : START_NMT_CLASS_(LoadedGame, NMT_LOADED_GAME)
     213           0 :     NMT_FIELD_INT(m_CurrentTurn, u32, 4)
     214           0 : END_NMT_CLASS()
     215           0 : 
     216           0 : START_NMT_CLASS_(GameStart, NMT_GAME_START)
     217           0 :     NMT_FIELD(CStr, m_InitAttributes)
     218           0 : END_NMT_CLASS()
     219           0 : 
     220           0 : START_NMT_CLASS_(EndCommandBatch, NMT_END_COMMAND_BATCH)
     221           0 :     NMT_FIELD_INT(m_Turn, u32, 4)
     222           0 :     NMT_FIELD_INT(m_TurnLength, u32, 2)
     223           0 : END_NMT_CLASS()
     224           0 : 
     225           0 : START_NMT_CLASS_(SyncCheck, NMT_SYNC_CHECK)
     226           0 :     NMT_FIELD_INT(m_Turn, u32, 4)
     227           0 :     NMT_FIELD(CStr, m_Hash)
     228           0 : END_NMT_CLASS()
     229           0 : 
     230           0 : START_NMT_CLASS_(SyncError, NMT_SYNC_ERROR)
     231           0 :     NMT_FIELD_INT(m_Turn, u32, 4)
     232           0 :     NMT_FIELD(CStr, m_HashExpected)
     233           0 :     NMT_START_ARRAY(m_PlayerNames)
     234           0 :         NMT_FIELD(CStrW, m_Name)
     235           0 :     NMT_END_ARRAY()
     236           0 : END_NMT_CLASS()
     237           0 : 
     238           0 : START_NMT_CLASS_(AssignPlayer, NMT_ASSIGN_PLAYER)
     239           0 :     NMT_FIELD_INT(m_PlayerID, i8, 1)
     240           0 :     NMT_FIELD(CStr, m_GUID)
     241           0 : END_NMT_CLASS()
     242           0 : 
     243           0 : END_NMTS()
     244           0 : 
     245           0 : #else
     246           0 : #ifndef ALLNETMSGS_DONT_CREATE_NMTS
     247           0 : 
     248           0 : # ifdef ALLNETMSGS_IMPLEMENT
     249           0 : #  define NMT_CREATOR_IMPLEMENT
     250             : # endif
     251           0 : 
     252           0 : # define NMT_CREATE_HEADER_NAME "NetMessages.h"
     253           0 : # include "NMTCreator.h"
     254           0 : 
     255           0 : #endif // #ifndef ALLNETMSGS_DONT_CREATE_NMTS
     256           0 : #endif // #ifdef CREATING_NMT

Generated by: LCOV version 1.13