OpenTTD
tcp_content.h
Go to the documentation of this file.
1 /* $Id$ */
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_TCP_CONTENT_H
15 #define NETWORK_CORE_TCP_CONTENT_H
16 
17 #include "os_abstraction.h"
18 #include "tcp.h"
19 #include "packet.h"
20 #include "../../debug.h"
21 
36 };
37 
48 };
49 
51 enum ContentID {
52  INVALID_CONTENT_ID = UINT32_MAX,
53 };
54 
56 struct ContentInfo {
58  enum State {
65  };
66 
69  uint32 filesize;
70  char filename[48];
71  char name[32];
72  char version[16];
73  char url[96];
74  char description[512];
75  uint32 unique_id;
76  byte md5sum[16];
79  uint8 tag_count;
80  char (*tags)[32];
82  bool upgrade;
83 
84  ContentInfo();
85  ~ContentInfo();
86 
87  void TransferFrom(ContentInfo *other);
88 
89  size_t Size() const;
90  bool IsSelected() const;
91  bool IsValid() const;
92 #ifndef OPENTTD_MSU
93  const char *GetTextfile(TextfileType type) const;
94 #endif /* OPENTTD_MSU */
95 };
96 
99 protected:
101  void Close() override;
102 
103  bool ReceiveInvalidPacket(PacketContentType type);
104 
112  virtual bool Receive_CLIENT_INFO_LIST(Packet *p);
113 
121  virtual bool Receive_CLIENT_INFO_ID(Packet *p);
122 
135  virtual bool Receive_CLIENT_INFO_EXTID(Packet *p);
136 
150  virtual bool Receive_CLIENT_INFO_EXTID_MD5(Packet *p);
151 
168  virtual bool Receive_SERVER_INFO(Packet *p);
169 
177  virtual bool Receive_CLIENT_CONTENT(Packet *p);
178 
189  virtual bool Receive_SERVER_CONTENT(Packet *p);
190 
191  bool HandlePacket(Packet *p);
192 public:
198  NetworkContentSocketHandler(SOCKET s = INVALID_SOCKET, const NetworkAddress &address = NetworkAddress()) :
200  client_addr(address)
201  {
202  }
203 
205  virtual ~NetworkContentSocketHandler() { this->Close(); }
206 
207  bool ReceivePackets();
208 };
209 
210 #ifndef OPENTTD_MSU
212 #endif /* OPENTTD_MSU */
213 
214 #endif /* NETWORK_CORE_TCP_CONTENT_H */
Helper to mark the end of the types.
Definition: tcp_content.h:35
The content consists of base graphics.
Definition: tcp_content.h:25
bool IsSelected() const
Is the state either selected or autoselected?
Definition: tcp_content.cpp:75
char filename[48]
Filename (for the .tar.gz; only valid on download)
Definition: tcp_content.h:70
uint32 unique_id
Unique ID; either GRF ID or shortname.
Definition: tcp_content.h:75
Internal entity of a packet.
Definition: packet.h:42
Queries the content server for information about a list of external IDs.
Definition: tcp_content.h:42
Network stuff has many things that needs to be included and/or implemented by default.
State
The state the content can be in.
Definition: tcp_content.h:58
Subdirectory
The different kinds of subdirectories OpenTTD uses.
Definition: fileio_type.h:110
Base socket handler for all Content TCP sockets.
Definition: tcp_content.h:98
uint32 filesize
Size of the file.
Definition: tcp_content.h:69
The content consists of a scenario.
Definition: tcp_content.h:29
Base socket handler for all TCP sockets.
Definition: tcp.h:29
uint8 dependency_count
Number of dependencies.
Definition: tcp_content.h:77
char(* tags)[32]
Malloced array of tags (strings)
Definition: tcp_content.h:80
Wrapper for (un)resolved network addresses; there&#39;s no reason to transform a numeric IP to a string a...
Definition: address.h:29
ContentID * dependencies
Malloced array of dependencies (unique server side ids)
Definition: tcp_content.h:78
The content has been selected as dependency.
Definition: tcp_content.h:61
virtual ~NetworkContentSocketHandler()
On destructing of this class, the socket needs to be closed.
Definition: tcp_content.h:205
ContentID
Unique identifier for the content.
Definition: tcp_content.h:51
The content has not been selected.
Definition: tcp_content.h:59
Queries the content server for information about a list of internal IDs.
Definition: tcp_content.h:41
The content does not exist in the content system.
Definition: tcp_content.h:63
char name[32]
Name of the content.
Definition: tcp_content.h:71
The content consists of a game script.
Definition: tcp_content.h:33
The content&#39;s invalid.
Definition: tcp_content.h:64
uint8 tag_count
Number of tags.
Definition: tcp_content.h:79
char version[16]
Version of the content.
Definition: tcp_content.h:72
Subdirectory GetContentInfoSubDir(ContentType type)
Helper to get the subdirectory a ContentInfo is located in.
Reply of content server with information about content.
Definition: tcp_content.h:44
size_t Size() const
Get the size of the data as send over the network.
Definition: tcp_content.cpp:59
The content is already at the client side.
Definition: tcp_content.h:62
ContentID id
Unique (server side) ID for the content.
Definition: tcp_content.h:68
ContentInfo()
Clear everything in the struct.
Definition: tcp_content.cpp:28
State state
Whether the content info is selected (for download)
Definition: tcp_content.h:81
void TransferFrom(ContentInfo *other)
Copy data from other ContentInfo and take ownership of allocated stuff.
Definition: tcp_content.cpp:44
TextfileType
Additional text files accompanying Tar archives.
Definition: textfile_type.h:16
Queries the content server for a list of info of a given content type.
Definition: tcp_content.h:40
byte md5sum[16]
The MD5 checksum.
Definition: tcp_content.h:76
The content consists of a GS library.
Definition: tcp_content.h:34
The content consists of a NewGRF.
Definition: tcp_content.h:26
ContentType
The values in the enum are important; they are used as database &#39;keys&#39;.
Definition: tcp_content.h:23
PacketContentType
Enum with all types of TCP content packets.
Definition: tcp_content.h:39
NetworkAddress client_addr
The address we&#39;re connected to.
Definition: tcp_content.h:100
Queries the content server for information about a list of external IDs and MD5.
Definition: tcp_content.h:43
The content consists of an AI library.
Definition: tcp_content.h:28
Sentinel for invalid content.
Definition: tcp_content.h:52
Request a content file given an internal ID.
Definition: tcp_content.h:45
~ContentInfo()
Free everything allocated.
Definition: tcp_content.cpp:34
The content consists of a heightmap.
Definition: tcp_content.h:30
The content consists of an AI.
Definition: tcp_content.h:27
const char * GetTextfile(TextfileType type) const
Search a textfile file next to this file in the content list.
ContentType type
Type of content.
Definition: tcp_content.h:67
bool upgrade
This item is an upgrade.
Definition: tcp_content.h:82
Helper to mark the begin of the types.
Definition: tcp_content.h:24
The content consists of base music.
Definition: tcp_content.h:32
Basic functions to create, fill and read packets.
The content has been manually selected.
Definition: tcp_content.h:60
NetworkContentSocketHandler(SOCKET s=INVALID_SOCKET, const NetworkAddress &address=NetworkAddress())
Create a new cs socket handler for a given cs.
Definition: tcp_content.h:198
Basic functions to receive and send TCP packets.
char url[96]
URL related to the content.
Definition: tcp_content.h:73
Must ALWAYS be on the end of this list!! (period)
Definition: tcp_content.h:47
char description[512]
Description of the content.
Definition: tcp_content.h:74
Container for all important information about a piece of content.
Definition: tcp_content.h:56
bool IsValid() const
Is the information from this content info valid?
Definition: tcp_content.cpp:92
Reply with the content of the given ID.
Definition: tcp_content.h:46
The content consists of base sounds.
Definition: tcp_content.h:31