packet.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
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;
00040 PacketSize size;
00042 PacketSize pos;
00044 byte buffer[SEND_MTU];
00045 private:
00046 NetworkSocketHandler *cs;
00047
00048 public:
00049 Packet(NetworkSocketHandler *cs);
00050 Packet(PacketType type);
00051
00052
00053 void PrepareToSend();
00054
00055 void Send_bool (bool data);
00056 void Send_uint8 (uint8 data);
00057 void Send_uint16(uint16 data);
00058 void Send_uint32(uint32 data);
00059 void Send_uint64(uint64 data);
00060 void Send_string(const char *data);
00061
00062
00063 void ReadRawPacketSize();
00064 void PrepareToRead();
00065
00066 bool CanReadFromPacket (uint bytes_to_read);
00067 bool Recv_bool ();
00068 uint8 Recv_uint8 ();
00069 uint16 Recv_uint16();
00070 uint32 Recv_uint32();
00071 uint64 Recv_uint64();
00072 void Recv_string(char *buffer, size_t size, bool allow_newlines = false);
00073 };
00074
00075 #endif
00076
00077 #endif