PACKET.H 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //
  2. // Copyright 2020 Electronic Arts Inc.
  3. //
  4. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
  5. // software: you can redistribute it and/or modify it under the terms of
  6. // the GNU General Public License as published by the Free Software Foundation,
  7. // either version 3 of the License, or (at your option) any later version.
  8. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
  9. // in the hope that it will be useful, but with permitted additional restrictions
  10. // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. // distributed with this program. You should have received a copy of the
  12. // GNU General Public License along with permitted additional restrictions
  13. // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
  14. /***************************************************************************
  15. * *
  16. * Project Name : Westwood Auto Registration App *
  17. * *
  18. * File Name : PACKET.H *
  19. * *
  20. * Programmer : Philip W. Gorrow *
  21. * *
  22. * Start Date : 04/19/96 *
  23. * *
  24. * Last Update : April 19, 1996 [PWG] *
  25. * *
  26. * This header defines the functions for the PacketClass. The packet *
  27. * class is used to create a linked list of field entries which can be *
  28. * converted to a linear packet in a COMMS API compatible format. *
  29. * *
  30. * Packets can be created empty and then have fields added to them or can *
  31. * be created from an existing linear packet. *
  32. * *
  33. *-------------------------------------------------------------------------*
  34. * Functions: *
  35. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  36. #ifndef __PACKET_H
  37. #define __PACKET_H
  38. #include "field.h"
  39. class PacketClass {
  40. public:
  41. PacketClass(short id = 0)
  42. {
  43. Size = 0;
  44. ID = id;
  45. Head = 0;
  46. }
  47. PacketClass(char *cur_buf);
  48. ~PacketClass(void);
  49. //
  50. // This function allows us to add a field to the start of the list. As the field is just
  51. // a big linked list it makes no difference which end we add a member to.
  52. //
  53. void Add_Field(FieldClass *field);
  54. //
  55. // These conveniance functions allow us to add a field directly to the list without
  56. // having to worry about newing one first.
  57. //
  58. void Add_Field(char *field, char data) {Add_Field(new FieldClass(field, data));};
  59. void Add_Field(char *field, unsigned char data) {Add_Field(new FieldClass(field, data));};
  60. void Add_Field(char *field, short data) {Add_Field(new FieldClass(field, data));};
  61. void Add_Field(char *field, unsigned short data) {Add_Field(new FieldClass(field, data));};
  62. void Add_Field(char *field, long data) {Add_Field(new FieldClass(field, data));};
  63. void Add_Field(char *field, unsigned long data) {Add_Field(new FieldClass(field, data));};
  64. void Add_Field(char *field, char *data) {Add_Field(new FieldClass(field, data));};
  65. void Add_Field(char *field, void *data, int length) {Add_Field(new FieldClass(field, data, length));};
  66. //
  67. // These functions search for a field of a given name in the list and
  68. // return the data via a reference value.
  69. //
  70. FieldClass *Find_Field(char *id);
  71. bool Get_Field(char *id, char &data);
  72. bool Get_Field(char *id, unsigned char &data);
  73. bool Get_Field(char *id, short &data);
  74. bool Get_Field(char *id, unsigned short &data);
  75. bool Get_Field(char *id, long &data);
  76. bool Get_Field(char *id, unsigned long &data);
  77. bool Get_Field(char *id, char *data);
  78. bool Get_Field(char *id, void *data, int &length);
  79. char *Create_Comms_Packet(int &size);
  80. private:
  81. unsigned short Size;
  82. short ID;
  83. FieldClass *Head;
  84. FieldClass *Current;
  85. };
  86. #endif