NetworkInterface.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. ** Command & Conquer Generals(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // NetworkInterface.h ///////////////////////////////////////////////////////////////
  24. // Network singleton class - defines interface to Network methods
  25. // Author: Matthew D. Campbell, July 2001
  26. #pragma once
  27. #ifndef _NETWORK_INTERFACE_H_
  28. #define _NETWORK_INTERFACE_H_
  29. #include "Common/MessageStream.h"
  30. #include "GameNetwork/ConnectionManager.h"
  31. #include "GameNetwork/User.h"
  32. #include "GameNetwork/NetworkDefs.h"
  33. // forward declarations
  34. struct CommandPacket;
  35. class GameMessage;
  36. class GameInfo;
  37. void ClearCommandPacket(UnsignedInt frame); ///< ClearCommandPacket clears the command packet at the start of the frame.
  38. CommandPacket *GetCommandPacket(void); ///< TheNetwork calls GetCommandPacket to get commands to send.
  39. /**
  40. * Interface definition for the Network.
  41. */
  42. class NetworkInterface : public SubsystemInterface
  43. {
  44. protected:
  45. public:
  46. virtual ~NetworkInterface() { };
  47. static NetworkInterface * createNetwork( void );
  48. //---------------------------------------------------------------------------------------
  49. // SubsystemInterface functions
  50. virtual void init( void ) = 0; ///< Initialize the network
  51. virtual void reset( void ) = 0; ///< Re-initialize the network
  52. virtual void update( void ) = 0; ///< Updates the network
  53. virtual void liteupdate( void ) = 0; ///< does a lightweight update for passing messages around.
  54. virtual void setLocalAddress(UnsignedInt ip, UnsignedInt port) = 0; ///< Tell the network what local ip and port to bind to.
  55. virtual Bool isFrameDataReady( void ) = 0; ///< Are the commands for the next frame available?
  56. virtual void parseUserList( const GameInfo *game ) = 0; ///< Parse a userlist, creating connections
  57. virtual void startGame(void) = 0; ///< Sets the network game frame counter to -1
  58. virtual UnsignedInt getRunAhead(void) = 0; ///< Get the current RunAhead value
  59. virtual UnsignedInt getFrameRate(void) = 0; ///< Get the current allowed frame rate.
  60. virtual UnsignedInt getPacketArrivalCushion(void) = 0; ///< Get the smallest packet arrival cushion since this was last called.
  61. // Chat functions
  62. virtual void sendChat(UnicodeString text, Int playerMask) = 0; ///< Send a chat line using the normal system.
  63. virtual void sendDisconnectChat(UnicodeString text) = 0; ///< Send a chat line using the disconnect manager.
  64. virtual void sendFile(AsciiString path, UnsignedByte playerMask, UnsignedShort commandID) = 0;
  65. virtual UnsignedShort sendFileAnnounce(AsciiString path, UnsignedByte playerMask) = 0;
  66. virtual Int getFileTransferProgress(Int playerID, AsciiString path) = 0;
  67. virtual Bool areAllQueuesEmpty(void) = 0;
  68. virtual void quitGame() = 0; ///< Quit the game right now.
  69. virtual void selfDestructPlayer(Int index) = 0;
  70. virtual void voteForPlayerDisconnect(Int slot) = 0; ///< register a vote towards this player's disconnect.
  71. virtual Bool isPacketRouter( void ) = 0;
  72. // Bandwidth metrics
  73. virtual Real getIncomingBytesPerSecond( void ) = 0;
  74. virtual Real getIncomingPacketsPerSecond( void ) = 0;
  75. virtual Real getOutgoingBytesPerSecond( void ) = 0;
  76. virtual Real getOutgoingPacketsPerSecond( void ) = 0;
  77. virtual Real getUnknownBytesPerSecond( void ) = 0;
  78. virtual Real getUnknownPacketsPerSecond( void ) = 0;
  79. virtual void updateLoadProgress( Int percent ) = 0;
  80. virtual void loadProgressComplete( void ) = 0;
  81. virtual void sendTimeOutGameStart( void ) = 0;
  82. virtual UnsignedInt getLocalPlayerID()= 0;
  83. virtual UnicodeString getPlayerName(Int playerNum)= 0;
  84. virtual Int getNumPlayers() = 0;
  85. virtual Int getAverageFPS() = 0;
  86. virtual Int getSlotAverageFPS(Int slot) = 0;
  87. virtual void attachTransport(Transport *transport) = 0;
  88. virtual void initTransport() = 0;
  89. virtual Bool sawCRCMismatch() = 0;
  90. virtual void setSawCRCMismatch() = 0;
  91. virtual Bool isPlayerConnected(Int playerID) = 0;
  92. virtual void notifyOthersOfCurrentFrame() = 0; ///< Tells all the other players what frame we are on.
  93. virtual void notifyOthersOfNewFrame(UnsignedInt frame) = 0; ///< Tells all the other players that we are on a new frame.
  94. virtual Int getExecutionFrame() = 0; ///< Returns the next valid frame for simultaneous command execution.
  95. #if defined(_DEBUG) || defined(_INTERNAL)
  96. virtual void toggleNetworkOn( void ) = 0; ///< toggle whether or not to send network traffic.
  97. #endif
  98. // For disconnect blame assignment
  99. virtual UnsignedInt getPingFrame() = 0;
  100. virtual Int getPingsSent() = 0;
  101. virtual Int getPingsRecieved() = 0;
  102. };
  103. /**
  104. * ResolveIP turns a string ("games2.westwood.com", or "192.168.0.1") into
  105. * a 32-bit unsigned integer.
  106. */
  107. UnsignedInt ResolveIP(AsciiString host);
  108. #endif // _NETWORK_INTERFACE_H_