00001 /* $Id$ */ 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 00043 struct Packet { 00045 Packet *next; 00051 PacketSize size; 00053 PacketSize pos; 00055 byte *buffer; 00056 00057 private: 00059 NetworkSocketHandler *cs; 00060 00061 public: 00062 Packet(NetworkSocketHandler *cs); 00063 Packet(PacketType type); 00064 ~Packet(); 00065 00066 /* Sending/writing of packets */ 00067 void PrepareToSend(); 00068 00069 void Send_bool (bool data); 00070 void Send_uint8 (uint8 data); 00071 void Send_uint16(uint16 data); 00072 void Send_uint32(uint32 data); 00073 void Send_uint64(uint64 data); 00074 void Send_string(const char *data); 00075 00076 /* Reading/receiving of packets */ 00077 void ReadRawPacketSize(); 00078 void PrepareToRead(); 00079 00080 bool CanReadFromPacket (uint bytes_to_read); 00081 bool Recv_bool (); 00082 uint8 Recv_uint8 (); 00083 uint16 Recv_uint16(); 00084 uint32 Recv_uint32(); 00085 uint64 Recv_uint64(); 00086 void Recv_string(char *buffer, size_t size, bool allow_newlines = false); 00087 }; 00088 00089 #endif /* ENABLE_NETWORK */ 00090 00091 #endif /* NETWORK_CORE_PACKET_H */