OpenTTD Source 20260311-master-g511d3794ce
tcp_content.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#ifndef NETWORK_CORE_TCP_CONTENT_H
11#define NETWORK_CORE_TCP_CONTENT_H
12
13#include "os_abstraction.h"
14#include "tcp.h"
15#include "packet.h"
16#include "../../debug.h"
17#include "tcp_content_type.h"
18
32
34 static constexpr bool value = true;
35};
36
39protected:
41
53 virtual bool ReceiveClientInfoList(Packet &p);
54
62 virtual bool ReceiveClientInfoID(Packet &p);
63
76 virtual bool ReceiveClientInfoExternalID(Packet &p);
77
91 virtual bool ReceiveClientInfoExternalIDMD5(Packet &p);
92
109 virtual bool ReceiveServerInfo(Packet &p);
110
118 virtual bool ReceiveClientContent(Packet &p);
119
130 virtual bool ReceiveServerContent(Packet &p);
131
132 bool HandlePacket(Packet &p);
133public:
138 NetworkContentSocketHandler(SOCKET s = INVALID_SOCKET) :
140 {
141 }
142
145 {
146 /* Virtual functions get called statically in destructors, so make it explicit to remove any confusion. */
147 this->CloseSocket();
148 }
149
150 bool ReceivePackets();
151};
152
154
155#endif /* NETWORK_CORE_TCP_CONTENT_H */
virtual bool ReceiveClientContent(Packet &p)
Client requesting the actual content: uint16_t count of unique ids uint32_t unique id (count times).
virtual bool ReceiveClientInfoID(Packet &p)
Client requesting a list of content info: uint16_t count of ids uint32_t id (count times).
NetworkContentSocketHandler(SOCKET s=INVALID_SOCKET)
Create a new cs socket handler for a given cs.
bool ReceivePackets()
Receive a packet at TCP level.
virtual bool ReceiveServerInfo(Packet &p)
Server sending list of content info: uint8_t type (invalid ID == does not exist) uint32_t id uint32_t...
virtual bool ReceiveClientInfoList(Packet &p)
Client requesting a list of content info: uint8_t type uint32_t openttd version (or 0xFFFFFFFF if usi...
virtual bool ReceiveServerContent(Packet &p)
Server sending list of content info: uint32_t unique id uint32_t file size (0 == does not exist) stri...
virtual bool ReceiveClientInfoExternalIDMD5(Packet &p)
Client requesting a list of content info based on an external 'unique' id; GRF ID + MD5 checksum for ...
virtual bool ReceiveClientInfoExternalID(Packet &p)
Client requesting a list of content info based on an external 'unique' id; GRF ID for NewGRFS,...
~NetworkContentSocketHandler() override
On destructing of this class, the socket needs to be closed.
bool ReceiveInvalidPacket(PacketContentType type)
Helper for logging receiving invalid packets.
bool HandlePacket(Packet &p)
Handle the given packet, i.e.
NetworkTCPSocketHandler(SOCKET s=INVALID_SOCKET)
Construct a socket handler for a TCP connection.
Definition tcp.h:64
void CloseSocket()
Close the actual socket of the connection.
Definition tcp.cpp:28
Functions related to debugging.
Subdirectory
The different kinds of subdirectories OpenTTD uses.
Definition fileio_type.h:88
Includes and/or implementations for the network stuff.
Basic functions to create, fill and read packets.
static constexpr bool value
This is an enumeration of a PacketType.
Definition tcp_content.h:34
Trait to mark an enumeration as a PacketType.
Definition packet.h:24
Basic functions to receive and send TCP packets.
Subdirectory GetContentInfoSubDir(ContentType type)
Helper to get the subdirectory a ContentInfo is located in.
PacketContentType
Enum with all types of TCP content packets.
Definition tcp_content.h:23
@ ClientContent
Request a content file given an internal ID.
Definition tcp_content.h:29
@ ClientInfoExternalID
Queries the content server for information about a list of external IDs.
Definition tcp_content.h:26
@ ClientInfoID
Queries the content server for information about a list of internal IDs.
Definition tcp_content.h:25
@ ClientInfoExternalIDMD5
Queries the content server for information about a list of external IDs and MD5.
Definition tcp_content.h:27
@ ServerInfo
Reply of content server with information about content.
Definition tcp_content.h:28
@ ServerContent
Reply with the content of the given ID.
Definition tcp_content.h:30
@ ClientInfoList
Queries the content server for a list of info of a given content type.
Definition tcp_content.h:24
Basic types related to the content on the content server.
ContentType
The values in the enum are important; they are used as database 'keys'.