packet.h

Go to the documentation of this file.
00001 /* $Id: packet.h 21357 2010-11-30 13:22:29Z rubidium $ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
00008  */
00009 
00014 #ifndef NETWORK_CORE_PACKET_H
00015 #define NETWORK_CORE_PACKET_H
00016 
00017 #include "config.h"
00018 #include "core.h"
00019 
00020 #ifdef ENABLE_NETWORK
00021 
00022 typedef uint16 PacketSize; 
00023 typedef uint8  PacketType; 
00024 
00034 struct Packet {
00036   Packet *next;
00042   PacketSize size;
00044   PacketSize pos;
00046   byte *buffer;
00047 
00048 private:
00050   NetworkSocketHandler *cs;
00051 
00052 public:
00053   Packet(NetworkSocketHandler *cs);
00054   Packet(PacketType type);
00055   ~Packet();
00056 
00057   /* Sending/writing of packets */
00058   void PrepareToSend();
00059 
00060   void Send_bool  (bool   data);
00061   void Send_uint8 (uint8  data);
00062   void Send_uint16(uint16 data);
00063   void Send_uint32(uint32 data);
00064   void Send_uint64(uint64 data);
00065   void Send_string(const char *data);
00066 
00067   /* Reading/receiving of packets */
00068   void ReadRawPacketSize();
00069   void PrepareToRead();
00070 
00071   bool   CanReadFromPacket (uint bytes_to_read);
00072   bool   Recv_bool  ();
00073   uint8  Recv_uint8 ();
00074   uint16 Recv_uint16();
00075   uint32 Recv_uint32();
00076   uint64 Recv_uint64();
00077   void   Recv_string(char *buffer, size_t size, bool allow_newlines = false);
00078 };
00079 
00080 #endif /* ENABLE_NETWORK */
00081 
00082 #endif /* NETWORK_CORE_PACKET_H */

Generated on Sun May 15 19:20:09 2011 for OpenTTD by  doxygen 1.6.1