OpenTTD Source  1.11.0-beta2
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 <http://www.gnu.org/licenses/>.
6  */
7 
12 #ifndef NETWORK_CORE_TCP_CONTENT_H
13 #define NETWORK_CORE_TCP_CONTENT_H
14 
15 #include "os_abstraction.h"
16 #include "tcp.h"
17 #include "packet.h"
18 #include "../../debug.h"
19 
34 };
35 
46 };
47 
49 enum ContentID {
50  INVALID_CONTENT_ID = UINT32_MAX,
51 };
52 
54 struct ContentInfo {
56  enum State {
63  };
64 
67  uint32 filesize;
68  char filename[48];
69  char name[32];
70  char version[16];
71  char url[96];
72  char description[512];
73  uint32 unique_id;
74  byte md5sum[16];
77  uint8 tag_count;
78  char (*tags)[32];
80  bool upgrade;
81 
82  ContentInfo();
83  ~ContentInfo();
84 
85  void TransferFrom(ContentInfo *other);
86 
87  size_t Size() const;
88  bool IsSelected() const;
89  bool IsValid() const;
90 #ifndef OPENTTD_MSU
91  const char *GetTextfile(TextfileType type) const;
92 #endif /* OPENTTD_MSU */
93 };
94 
97 protected:
99  void Close() override;
100 
102 
110  virtual bool Receive_CLIENT_INFO_LIST(Packet *p);
111 
119  virtual bool Receive_CLIENT_INFO_ID(Packet *p);
120 
133  virtual bool Receive_CLIENT_INFO_EXTID(Packet *p);
134 
148  virtual bool Receive_CLIENT_INFO_EXTID_MD5(Packet *p);
149 
166  virtual bool Receive_SERVER_INFO(Packet *p);
167 
175  virtual bool Receive_CLIENT_CONTENT(Packet *p);
176 
187  virtual bool Receive_SERVER_CONTENT(Packet *p);
188 
189  bool HandlePacket(Packet *p);
190 public:
196  NetworkContentSocketHandler(SOCKET s = INVALID_SOCKET, const NetworkAddress &address = NetworkAddress()) :
198  client_addr(address)
199  {
200  }
201 
203  virtual ~NetworkContentSocketHandler() { this->Close(); }
204 
205  bool ReceivePackets();
206 };
207 
208 #ifndef OPENTTD_MSU
210 #endif /* OPENTTD_MSU */
211 
212 #endif /* NETWORK_CORE_TCP_CONTENT_H */
ContentInfo::IsSelected
bool IsSelected() const
Is the state either selected or autoselected?
Definition: tcp_content.cpp:73
INVALID_CONTENT_ID
@ INVALID_CONTENT_ID
Sentinel for invalid content.
Definition: tcp_content.h:50
ContentInfo::tag_count
uint8 tag_count
Number of tags.
Definition: tcp_content.h:77
ContentInfo::~ContentInfo
~ContentInfo()
Free everything allocated.
Definition: tcp_content.cpp:32
ContentInfo::GetTextfile
const char * GetTextfile(TextfileType type) const
Search a textfile file next to this file in the content list.
Definition: tcp_content.cpp:101
ContentInfo::type
ContentType type
Type of content.
Definition: tcp_content.h:65
NetworkContentSocketHandler
Base socket handler for all Content TCP sockets.
Definition: tcp_content.h:96
NetworkContentSocketHandler::Receive_SERVER_CONTENT
virtual bool Receive_SERVER_CONTENT(Packet *p)
Server sending list of content info: uint32 unique id uint32 file size (0 == does not exist) string f...
Definition: tcp_content.cpp:237
ContentType
ContentType
The values in the enum are important; they are used as database 'keys'.
Definition: tcp_content.h:21
ContentInfo::upgrade
bool upgrade
This item is an upgrade.
Definition: tcp_content.h:80
ContentInfo::DOES_NOT_EXIST
@ DOES_NOT_EXIST
The content does not exist in the content system.
Definition: tcp_content.h:61
PacketContentType
PacketContentType
Enum with all types of TCP content packets.
Definition: tcp_content.h:37
CONTENT_TYPE_BASE_SOUNDS
@ CONTENT_TYPE_BASE_SOUNDS
The content consists of base sounds.
Definition: tcp_content.h:29
CONTENT_TYPE_AI
@ CONTENT_TYPE_AI
The content consists of an AI.
Definition: tcp_content.h:25
ContentInfo::tags
char(* tags)[32]
Malloced array of tags (strings)
Definition: tcp_content.h:78
PACKET_CONTENT_END
@ PACKET_CONTENT_END
Must ALWAYS be on the end of this list!! (period)
Definition: tcp_content.h:45
CONTENT_TYPE_BASE_GRAPHICS
@ CONTENT_TYPE_BASE_GRAPHICS
The content consists of base graphics.
Definition: tcp_content.h:23
PACKET_CONTENT_CLIENT_CONTENT
@ PACKET_CONTENT_CLIENT_CONTENT
Request a content file given an internal ID.
Definition: tcp_content.h:43
NetworkContentSocketHandler::ReceivePackets
bool ReceivePackets()
Receive a packet at TCP level.
Definition: tcp_content.cpp:186
PACKET_CONTENT_SERVER_CONTENT
@ PACKET_CONTENT_SERVER_CONTENT
Reply with the content of the given ID.
Definition: tcp_content.h:44
ContentInfo::State
State
The state the content can be in.
Definition: tcp_content.h:56
ContentInfo::filename
char filename[48]
Filename (for the .tar.gz; only valid on download)
Definition: tcp_content.h:68
NetworkContentSocketHandler::Receive_CLIENT_INFO_EXTID_MD5
virtual bool Receive_CLIENT_INFO_EXTID_MD5(Packet *p)
Client requesting a list of content info based on an external 'unique' id; GRF ID + MD5 checksum for ...
Definition: tcp_content.cpp:234
ContentInfo::IsValid
bool IsValid() const
Is the information from this content info valid?
Definition: tcp_content.cpp:90
CONTENT_TYPE_BASE_MUSIC
@ CONTENT_TYPE_BASE_MUSIC
The content consists of base music.
Definition: tcp_content.h:30
ContentInfo::TransferFrom
void TransferFrom(ContentInfo *other)
Copy data from other ContentInfo and take ownership of allocated stuff.
Definition: tcp_content.cpp:42
NetworkContentSocketHandler::Receive_CLIENT_INFO_EXTID
virtual bool Receive_CLIENT_INFO_EXTID(Packet *p)
Client requesting a list of content info based on an external 'unique' id; GRF ID for NewGRFS,...
Definition: tcp_content.cpp:233
NetworkContentSocketHandler::client_addr
NetworkAddress client_addr
The address we're connected to.
Definition: tcp_content.h:98
ContentInfo::UNSELECTED
@ UNSELECTED
The content has not been selected.
Definition: tcp_content.h:57
NetworkContentSocketHandler::~NetworkContentSocketHandler
virtual ~NetworkContentSocketHandler()
On destructing of this class, the socket needs to be closed.
Definition: tcp_content.h:203
CONTENT_TYPE_HEIGHTMAP
@ CONTENT_TYPE_HEIGHTMAP
The content consists of a heightmap.
Definition: tcp_content.h:28
ContentInfo
Container for all important information about a piece of content.
Definition: tcp_content.h:54
ContentInfo::md5sum
byte md5sum[16]
The MD5 checksum.
Definition: tcp_content.h:74
CONTENT_TYPE_GAME
@ CONTENT_TYPE_GAME
The content consists of a game script.
Definition: tcp_content.h:31
CONTENT_TYPE_SCENARIO
@ CONTENT_TYPE_SCENARIO
The content consists of a scenario.
Definition: tcp_content.h:27
ContentInfo::SELECTED
@ SELECTED
The content has been manually selected.
Definition: tcp_content.h:58
CONTENT_TYPE_AI_LIBRARY
@ CONTENT_TYPE_AI_LIBRARY
The content consists of an AI library.
Definition: tcp_content.h:26
PACKET_CONTENT_CLIENT_INFO_ID
@ PACKET_CONTENT_CLIENT_INFO_ID
Queries the content server for information about a list of internal IDs.
Definition: tcp_content.h:39
ContentInfo::url
char url[96]
URL related to the content.
Definition: tcp_content.h:71
Packet
Internal entity of a packet.
Definition: packet.h:40
CONTENT_TYPE_GAME_LIBRARY
@ CONTENT_TYPE_GAME_LIBRARY
The content consists of a GS library.
Definition: tcp_content.h:32
CONTENT_TYPE_NEWGRF
@ CONTENT_TYPE_NEWGRF
The content consists of a NewGRF.
Definition: tcp_content.h:24
NetworkContentSocketHandler::ReceiveInvalidPacket
bool ReceiveInvalidPacket(PacketContentType type)
Helper for logging receiving invalid packets.
Definition: tcp_content.cpp:225
ContentInfo::description
char description[512]
Description of the content.
Definition: tcp_content.h:72
PACKET_CONTENT_CLIENT_INFO_LIST
@ PACKET_CONTENT_CLIENT_INFO_LIST
Queries the content server for a list of info of a given content type.
Definition: tcp_content.h:38
NetworkAddress
Wrapper for (un)resolved network addresses; there's no reason to transform a numeric IP to a string a...
Definition: address.h:29
ContentInfo::ALREADY_HERE
@ ALREADY_HERE
The content is already at the client side.
Definition: tcp_content.h:60
NetworkContentSocketHandler::Receive_CLIENT_CONTENT
virtual bool Receive_CLIENT_CONTENT(Packet *p)
Client requesting the actual content: uint16 count of unique ids uint32 unique id (count times)
Definition: tcp_content.cpp:236
ContentInfo::AUTOSELECTED
@ AUTOSELECTED
The content has been selected as dependency.
Definition: tcp_content.h:59
packet.h
ContentInfo::Size
size_t Size() const
Get the size of the data as send over the network.
Definition: tcp_content.cpp:57
NetworkContentSocketHandler::Receive_CLIENT_INFO_LIST
virtual bool Receive_CLIENT_INFO_LIST(Packet *p)
Client requesting a list of content info: byte type uint32 openttd version.
Definition: tcp_content.cpp:231
NetworkContentSocketHandler::Receive_CLIENT_INFO_ID
virtual bool Receive_CLIENT_INFO_ID(Packet *p)
Client requesting a list of content info: uint16 count of ids uint32 id (count times)
Definition: tcp_content.cpp:232
tcp.h
PACKET_CONTENT_CLIENT_INFO_EXTID
@ PACKET_CONTENT_CLIENT_INFO_EXTID
Queries the content server for information about a list of external IDs.
Definition: tcp_content.h:40
NetworkContentSocketHandler::NetworkContentSocketHandler
NetworkContentSocketHandler(SOCKET s=INVALID_SOCKET, const NetworkAddress &address=NetworkAddress())
Create a new cs socket handler for a given cs.
Definition: tcp_content.h:196
ContentInfo::ContentInfo
ContentInfo()
Clear everything in the struct.
Definition: tcp_content.cpp:26
ContentInfo::dependency_count
uint8 dependency_count
Number of dependencies.
Definition: tcp_content.h:75
Subdirectory
Subdirectory
The different kinds of subdirectories OpenTTD uses.
Definition: fileio_type.h:108
ContentInfo::version
char version[16]
Version of the content.
Definition: tcp_content.h:70
ContentInfo::state
State state
Whether the content info is selected (for download)
Definition: tcp_content.h:79
ContentInfo::unique_id
uint32 unique_id
Unique ID; either GRF ID or shortname.
Definition: tcp_content.h:73
CONTENT_TYPE_BEGIN
@ CONTENT_TYPE_BEGIN
Helper to mark the begin of the types.
Definition: tcp_content.h:22
os_abstraction.h
ContentID
ContentID
Unique identifier for the content.
Definition: tcp_content.h:49
TextfileType
TextfileType
Additional text files accompanying Tar archives.
Definition: textfile_type.h:14
GetContentInfoSubDir
Subdirectory GetContentInfoSubDir(ContentType type)
Helper to get the subdirectory a ContentInfo is located in.
Definition: tcp_content.cpp:245
NetworkContentSocketHandler::HandlePacket
bool HandlePacket(Packet *p)
Handle the given packet, i.e.
Definition: tcp_content.cpp:159
NetworkContentSocketHandler::Close
void Close() override
Really close the socket.
Definition: tcp_content.cpp:144
ContentInfo::name
char name[32]
Name of the content.
Definition: tcp_content.h:69
ContentInfo::INVALID
@ INVALID
The content's invalid.
Definition: tcp_content.h:62
ContentInfo::dependencies
ContentID * dependencies
Malloced array of dependencies (unique server side ids)
Definition: tcp_content.h:76
ContentInfo::id
ContentID id
Unique (server side) ID for the content.
Definition: tcp_content.h:66
NetworkContentSocketHandler::Receive_SERVER_INFO
virtual bool Receive_SERVER_INFO(Packet *p)
Server sending list of content info: byte type (invalid ID == does not exist) uint32 id uint32 file_s...
Definition: tcp_content.cpp:235
PACKET_CONTENT_SERVER_INFO
@ PACKET_CONTENT_SERVER_INFO
Reply of content server with information about content.
Definition: tcp_content.h:42
CONTENT_TYPE_END
@ CONTENT_TYPE_END
Helper to mark the end of the types.
Definition: tcp_content.h:33
ContentInfo::filesize
uint32 filesize
Size of the file.
Definition: tcp_content.h:67
NetworkTCPSocketHandler
Base socket handler for all TCP sockets.
Definition: tcp.h:29
PACKET_CONTENT_CLIENT_INFO_EXTID_MD5
@ PACKET_CONTENT_CLIENT_INFO_EXTID_MD5
Queries the content server for information about a list of external IDs and MD5.
Definition: tcp_content.h:41