# packet.h

Go to the documentation of this file.

    00001 /* $Id: packet.h 23590 2011-12-18 18:37:54Z 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 #include "../../string_type.h"
    00020
    00021 #ifdef ENABLE_NETWORK
    00022
    00023 typedef uint16 PacketSize;
    00024 typedef uint8  PacketType;
    00025
    00044 struct Packet {
    00046   Packet *next;
    00052   PacketSize size;
    00054   PacketSize pos;
    00056   byte *buffer;
    00057
    00058 private:
    00060   NetworkSocketHandler *cs;
    00061
    00062 public:
    00063   Packet(NetworkSocketHandler *cs);
    00064   Packet(PacketType type);
    00065   ~Packet();
    00066
    00067   /* Sending/writing of packets */
    00068   void PrepareToSend();
    00069
    00070   void Send_bool  (bool   data);
    00071   void Send_uint8 (uint8  data);
    00072   void Send_uint16(uint16 data);
    00073   void Send_uint32(uint32 data);
    00074   void Send_uint64(uint64 data);
    00075   void Send_string(const char *data);
    00076
    00077   /* Reading/receiving of packets */
    00078   void ReadRawPacketSize();
    00079   void PrepareToRead();
    00080
    00081   bool   CanReadFromPacket (uint bytes_to_read);
    00082   bool   Recv_bool  ();
    00083   uint8  Recv_uint8 ();
    00084   uint16 Recv_uint16();
    00085   uint32 Recv_uint32();
    00086   uint64 Recv_uint64();
    00087   void   Recv_string(char *buffer, size_t size, StringValidationSettings settings = SVS_REPLACE_WITH_QUESTION_MARK);
    00088 };
    00089
    00090 #endif /* ENABLE_NETWORK */
    00091
    00092 #endif /* NETWORK_CORE_PACKET_H */