PACKET.H 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. ** Command & Conquer(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. * Project Name : Westwood Auto Registration App *
  21. * *
  22. * File Name : PACKET.H *
  23. * *
  24. * Programmer : Philip W. Gorrow *
  25. * *
  26. * Start Date : 04/19/96 *
  27. * *
  28. * Last Update : April 19, 1996 [PWG] *
  29. * *
  30. * This header defines the functions for the PacketClass. The packet *
  31. * class is used to create a linked list of field entries which can be *
  32. * converted to a linear packet in a COMMS API compatible format. *
  33. * *
  34. * Packets can be created empty and then have fields added to them or can *
  35. * be created from an existing linear packet. *
  36. * *
  37. *-------------------------------------------------------------------------*
  38. * Functions: *
  39. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  40. #ifndef __PACKET_H
  41. #define __PACKET_H
  42. #include "field.h"
  43. class PacketClass {
  44. public:
  45. PacketClass(short id = 0)
  46. {
  47. Size = 0;
  48. ID = id;
  49. Head = 0;
  50. }
  51. PacketClass(char *cur_buf);
  52. ~PacketClass(void);
  53. //
  54. // This function allows us to add a field to the start of the list. As the field is just
  55. // a big linked list it makes no difference which end we add a member to.
  56. //
  57. void Add_Field(FieldClass *field);
  58. //
  59. // These conveniance functions allow us to add a field directly to the list without
  60. // having to worry about newing one first.
  61. //
  62. void Add_Field(char *field, char data) {Add_Field(new FieldClass(field, data));};
  63. void Add_Field(char *field, unsigned char data) {Add_Field(new FieldClass(field, data));};
  64. void Add_Field(char *field, short data) {Add_Field(new FieldClass(field, data));};
  65. void Add_Field(char *field, unsigned short data) {Add_Field(new FieldClass(field, data));};
  66. void Add_Field(char *field, long data) {Add_Field(new FieldClass(field, data));};
  67. void Add_Field(char *field, unsigned long data) {Add_Field(new FieldClass(field, data));};
  68. void Add_Field(char *field, char *data) {Add_Field(new FieldClass(field, data));};
  69. void Add_Field(char *field, void *data, int length) {Add_Field(new FieldClass(field, data, length));};
  70. //
  71. // These functions search for a field of a given name in the list and
  72. // return the data via a reference value.
  73. //
  74. FieldClass *Find_Field(char *id);
  75. bool Get_Field(char *id, char &data);
  76. bool Get_Field(char *id, unsigned char &data);
  77. bool Get_Field(char *id, short &data);
  78. bool Get_Field(char *id, unsigned short &data);
  79. bool Get_Field(char *id, long &data);
  80. bool Get_Field(char *id, unsigned long &data);
  81. bool Get_Field(char *id, char *data);
  82. bool Get_Field(char *id, void *data, int &length);
  83. char *Create_Comms_Packet(int &size);
  84. private:
  85. unsigned short Size;
  86. short ID;
  87. FieldClass *Head;
  88. FieldClass *Current;
  89. };
  90. #endif