OpenTTD: src/network/core/packet.h Source File

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

packet.h
Go to the documentation of this file.
1 /* $Id: packet.h 23590 2011-12-18 18:37:54Z rubidium $ */
2
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
9
14 #ifndef NETWORK_CORE_PACKET_H
15 #define NETWORK_CORE_PACKET_H
16
17 #include "config.h"
18 #include "core.h"
19 #include "../../string_type.h"
20
21 #ifdef ENABLE_NETWORK
22
23 typedef uint16 PacketSize;
24 typedef uint8 PacketType;
25
44 struct Packet {
46 Packet *next;
52 PacketSize size;
54 PacketSize pos;
56 byte *buffer;
57
58 private:
60 NetworkSocketHandler *cs;
61
62 public:
63 Packet(NetworkSocketHandler *cs);
64 Packet(PacketType type);
65 ~Packet();
66
67 /* Sending/writing of packets */
68 void PrepareToSend();
69
70 void Send_bool (bool data);
71 void Send_uint8 (uint8 data);
72 void Send_uint16(uint16 data);
73 void Send_uint32(uint32 data);
74 void Send_uint64(uint64 data);
75 void Send_string(const char *data);
76
77 /* Reading/receiving of packets */
78 void ReadRawPacketSize();
79 void PrepareToRead();
80
81 bool CanReadFromPacket (uint bytes_to_read);
82 bool Recv_bool ();
83 uint8 Recv_uint8 ();
84 uint16 Recv_uint16();
85 uint32 Recv_uint32();
86 uint64 Recv_uint64();
87 void Recv_string(char *buffer, size_t size, StringValidationSettings settings = SVS_REPLACE_WITH_QUESTION_MARK);
88 };
89
90 #endif /* ENABLE_NETWORK */
91
92 #endif /* NETWORK_CORE_PACKET_H */