NULLCONN.H 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. ** Command & Conquer Red Alert(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. /* $Header: /CounterStrike/NULLCONN.H 1 3/03/97 10:25a Joe_bostic $ */
  19. /***************************************************************************
  20. ** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S **
  21. ***************************************************************************
  22. * *
  23. * Project Name : Command & Conquer *
  24. * *
  25. * File Name : NULLCONN.H *
  26. * *
  27. * Programmer : Bill Randolph *
  28. * *
  29. * Start Date : December 19, 1994 *
  30. * *
  31. * Last Update : April 3, 1995 [BR] *
  32. * *
  33. *-------------------------------------------------------------------------*
  34. * *
  35. * This is the Connection Class for a NULL-Modem connection. It inherits *
  36. * a Queue, PacketBuf, timeout variables from ConnectionClass. It *
  37. * inherits its Send_/Receive_/Get_Packet functions, and the non-sequenced *
  38. * ACK/Retry logic in Service_Send_Queue & Service_Receive_Queue from *
  39. * ConnectionClass. *
  40. * *
  41. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  42. #ifndef NULLCONN_H
  43. #define NULLCONN_H
  44. /*
  45. ********************************* Includes **********************************
  46. */
  47. #include "connect.h"
  48. #include "commlib.h"
  49. /*
  50. ********************************** Defines **********************************
  51. */
  52. #define PACKET_SERIAL_START 0xDABD
  53. #define PACKET_SERIAL_VERIFY 0xDEAF
  54. #define PACKET_SERIAL_OVERHEAD_SIZE (sizeof( SerialHeaderType ) + sizeof( SerialCRCType ))
  55. typedef struct {
  56. unsigned short MagicNumber;
  57. unsigned short Length;
  58. unsigned short MagicNumber2;
  59. } SerialHeaderType;
  60. typedef struct {
  61. int SerialCRC;
  62. } SerialCRCType;
  63. /*
  64. ***************************** Class Declaration *****************************
  65. */
  66. class NullModemConnClass : public ConnectionClass
  67. {
  68. /*
  69. ---------------------------- Public Interface ----------------------------
  70. */
  71. public:
  72. /*.....................................................................
  73. Constructor/destructor.
  74. .....................................................................*/
  75. NullModemConnClass (int numsend, int numrecieve, int maxlen,
  76. unsigned short magicnum);
  77. virtual ~NullModemConnClass ();
  78. /*.....................................................................
  79. Initialization.
  80. .....................................................................*/
  81. #ifdef WIN32
  82. void Init (HANDLE port_handle);
  83. #else //WIN32
  84. void Init (PORT *port);
  85. #endif //WIN32
  86. /*.....................................................................
  87. Utility routines.
  88. .....................................................................*/
  89. unsigned long Actual_Max_Packet (void) { return (MaxPacketLen +
  90. (sizeof(SerialHeaderType)) + sizeof(int) + sizeof (char)); }
  91. /*.....................................................................
  92. This routine computes a CRC value for the given buffer.
  93. .....................................................................*/
  94. static int Compute_CRC(char *buf, int buflen);
  95. /*.....................................................................
  96. This routine returns the number of bytes extra added the packet
  97. for communication.
  98. .....................................................................*/
  99. static int Packet_Overhead_Size( void );
  100. /*
  101. --------------------------- Private Interface ----------------------------
  102. */
  103. protected:
  104. /*.....................................................................
  105. This routine actually performs a hardware-dependent data send.
  106. .....................................................................*/
  107. virtual int Send (char *buf, int buflen, void *extrabuf, int extralen);
  108. #ifdef WIN32
  109. /*
  110. ** This is the winsoze port handle
  111. */
  112. HANDLE PortHandle;
  113. #else //WIN32
  114. /*.....................................................................
  115. This is the PORT value used by the GreenLeaf calls.
  116. .....................................................................*/
  117. PORT *Port;
  118. #endif //WIN32
  119. /*.....................................................................
  120. This buffer is a staging area for data sent out; it includes the
  121. packet sent by the parent class (which includes the application's
  122. packet, plus the CommHeaderType header), plus:
  123. - 2-byte buffer start ID
  124. - 2-byte length
  125. - 4-byte CRC value (at the end of the buffer)
  126. This is the actual packet that gets sent across the serial line.
  127. .....................................................................*/
  128. char *SendBuf;
  129. };
  130. #endif
  131. /************************** end of nullconn.h ******************************/