CnC_Remastered_Collection

Command and Conquer: Red Alert
Log | Files | Refs | README | LICENSE

PACKET.H (4408B)


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