LANGameInfo.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. ** Command & Conquer Generals Zero Hour(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. // FILE: LANGameInfo.h //////////////////////////////////////////////////////
  24. // Generals LAN game setup information
  25. // Author: Matthew D. Campbell, December 2001
  26. #pragma once
  27. #ifndef __LANGAMEINFO_H__
  28. #define __LANGAMEINFO_H__
  29. #include "GameNetwork/GameInfo.h"
  30. #include "GameNetwork/LANPlayer.h"
  31. class GameWindow;
  32. /**
  33. * LANGameSlot class - maintains information about the contents of a
  34. * game slot. This persists throughout the game.
  35. */
  36. class LANGameSlot : public GameSlot
  37. {
  38. public:
  39. LANGameSlot();
  40. LANPlayer *getUser( void ); ///< Get the User structure associated with the slot (NULL for non-humans)
  41. // Various tests
  42. Bool isUser( LANPlayer *user ); ///< Does this slot contain the given user? Based off user->name
  43. Bool isUser( UnicodeString userName ); ///< Does this slot contain the given user?
  44. Bool isLocalPlayer( void ) const; ///< Is this slot me?
  45. inline void setLogin( UnicodeString name ) { m_user.setLogin(name); }
  46. inline void setLogin( AsciiString name ) { m_user.setLogin(name); }
  47. inline void setHost( UnicodeString name ) { m_user.setHost(name); }
  48. inline void setHost( AsciiString name ) { m_user.setHost(name); }
  49. inline void setSerial( AsciiString serial ) { m_serial = serial; }
  50. inline AsciiString getSerial( void ) { return m_serial; }
  51. inline void setLastHeard( UnsignedInt t ) { m_lastHeard = t; }
  52. inline UnsignedInt getLastHeard( void ) { return m_lastHeard; }
  53. //LANGameSlot& operator=(const LANGameSlot& src);
  54. private:
  55. LANPlayer m_user; ///< filled in for each getUser() call
  56. AsciiString m_serial;
  57. UnsignedInt m_lastHeard;
  58. };
  59. /**
  60. * LANGameInfo class - maintains information about the LAN game and
  61. * the contents of its slot list hroughout the game.
  62. */
  63. class LANGameInfo : public GameInfo
  64. {
  65. private:
  66. LANGameSlot m_LANSlot[MAX_SLOTS]; ///< The Lan Games Slot List
  67. public:
  68. LANGameInfo();
  69. void setSlot( Int slotNum, LANGameSlot slotInfo ); ///< Set the slot state (human, open, AI, etc)
  70. LANGameSlot* getLANSlot( Int slotNum ); ///< Get the slot
  71. const LANGameSlot* getConstLANSlot( Int slotNum ) const; ///< Get the slot
  72. virtual Int getLocalSlotNum( void ) const; ///< Get the local slot number, or -1 if we're not present
  73. Int getSlotNum( UnicodeString userName ); ///< Get the slot number corresponding to a specific user, or -1 if he's not present
  74. inline UnsignedInt getLastHeard( void ) { return m_lastHeard; }
  75. inline void setLastHeard( UnsignedInt lastHeard ) { m_lastHeard = lastHeard; }
  76. inline LANGameInfo *getNext( void ) { return m_next; }
  77. inline void setNext( LANGameInfo *next ) { m_next = next; }
  78. // Game options
  79. void setMap( AsciiString mapName ); ///< Set the map to play on
  80. void setSeed( Int seed ); ///< Set the random seed for the game
  81. inline void setName( UnicodeString name ) { m_gameName = name; } ///< Set the Name of the Game
  82. inline UnicodeString getName( void ) { return m_gameName; } ///< Get the Name of the Game
  83. // Convinience functions that interface with the LANPlayer held in the slot list
  84. virtual void resetAccepted(void); ///< Reset the accepted flag on all players
  85. Bool amIHost( void ); ///< Convenience function - is the local player the game host?
  86. /// Get the IP of selected player or return 0
  87. inline UnsignedInt getIP( int who )
  88. {
  89. return m_LANSlot[who].getIP();
  90. }
  91. /// Set the IP of the Selected Player
  92. inline void setIP( int who, UnsignedInt IP )
  93. {
  94. m_LANSlot[who].setIP(IP);
  95. }
  96. /// set whether or not this is a direct connect game or not.
  97. inline void setIsDirectConnect(Bool isDirectConnect)
  98. {
  99. m_isDirectConnect = isDirectConnect;
  100. }
  101. /// returns whether or not this is a direct connect game or not.
  102. inline Bool getIsDirectConnect()
  103. {
  104. return m_isDirectConnect;
  105. }
  106. /// Set the Player Name
  107. inline void setPlayerName( int who, UnicodeString name )
  108. {
  109. m_LANSlot[who].setName(name);
  110. }
  111. /// Return the Player name or TheEmptyString
  112. inline UnicodeString getPlayerName(int who)
  113. {
  114. return m_LANSlot[who].getName();
  115. }
  116. /// Return the time the player was heard from last, or 0
  117. inline UnsignedInt getPlayerLastHeard( int who )
  118. {
  119. if (m_LANSlot[who].isHuman())
  120. return m_LANSlot[who].getLastHeard();
  121. return 0;
  122. }
  123. /// Set the last time we heard from the player
  124. inline void setPlayerLastHeard( int who, UnsignedInt lastHeard )
  125. {
  126. DEBUG_LOG(("LANGameInfo::setPlayerLastHeard - changing player %d last heard from %d to %d\n", who, getPlayerLastHeard(who), lastHeard));
  127. if (m_LANSlot[who].isHuman())
  128. m_LANSlot[who].setLastHeard(lastHeard);
  129. }
  130. /// Return the hosts IP or 0
  131. UnsignedInt getHostIP(void)
  132. {
  133. if (m_LANSlot[0].isHuman())
  134. return m_LANSlot[0].getIP();
  135. return 0;
  136. }
  137. private:
  138. LANGameInfo *m_next; ///< Pointer for linked list
  139. UnsignedInt m_lastHeard; ///< The last time we heard from this game (for timeout purposes)
  140. UnicodeString m_gameName; ///< Game name. @todo: are game names based off of host player names?
  141. Bool m_isDirectConnect; ///< Is this game a direct connect game, or a LAN game?
  142. };
  143. void LANDisplayGameList( GameWindow *gameListbox, LANGameInfo *gameList ); ///< Displays the list of games in a listbox, preserving selections
  144. void LANEnableStartButton(Bool enabled);
  145. void LANDisplaySlotList( void ); ///< Displays the slot list according to TheLANGameInfo
  146. void LANDisplayGameOptions( void ); ///< Displays the game options according to TheLANGameInfo
  147. AsciiString GenerateGameOptionsString( void );
  148. Bool ParseGameOptionsString(LANGameInfo *game, AsciiString options);
  149. #endif // __LANGAMEINFO_H__