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

OpenTTD

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

- File List
- Globals

tcp_content.h
Go to the documentation of this file.
1 /* $Id: tcp_content.h 25597 2013-07-13 09:26:11Z 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_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
22 #ifdef ENABLE_NETWORK
23
25 enum ContentType {
26 CONTENT_TYPE_BEGIN = 1,
27 CONTENT_TYPE_BASE_GRAPHICS = 1,
28 CONTENT_TYPE_NEWGRF = 2,
29 CONTENT_TYPE_AI = 3,
30 CONTENT_TYPE_AI_LIBRARY = 4,
31 CONTENT_TYPE_SCENARIO = 5,
32 CONTENT_TYPE_HEIGHTMAP = 6,
33 CONTENT_TYPE_BASE_SOUNDS = 7,
34 CONTENT_TYPE_BASE_MUSIC = 8,
35 CONTENT_TYPE_GAME = 9,
36 CONTENT_TYPE_GAME_LIBRARY = 10,
37 CONTENT_TYPE_END,
38 };
39
41 enum PacketContentType {
42 PACKET_CONTENT_CLIENT_INFO_LIST,
43 PACKET_CONTENT_CLIENT_INFO_ID,
44 PACKET_CONTENT_CLIENT_INFO_EXTID,
45 PACKET_CONTENT_CLIENT_INFO_EXTID_MD5,
46 PACKET_CONTENT_SERVER_INFO,
47 PACKET_CONTENT_CLIENT_CONTENT,
48 PACKET_CONTENT_SERVER_CONTENT,
49 PACKET_CONTENT_END,
50 };
51
53 enum ContentID {
54 INVALID_CONTENT_ID = UINT32_MAX,
55 };
56
58 struct ContentInfo {
60 enum State {
61 UNSELECTED,
62 SELECTED,
63 AUTOSELECTED,
64 ALREADY_HERE,
65 DOES_NOT_EXIST,
66 INVALID,
67 };
68
69 ContentType type;
70 ContentID id;
71 uint32 filesize;
72 char filename[48];
73 char name[32];
74 char version[16];
75 char url[96];
76 char description[512];
77 uint32 unique_id;
78 byte md5sum[16];
79 uint8 dependency_count;
80 ContentID *dependencies;
81 uint8 tag_count;
82 char (*tags)[32];
83 State state;
84 bool upgrade;
85
86 ContentInfo();
87 ~ContentInfo();
88
89 void TransferFrom(ContentInfo *other);
90
91 size_t Size() const;
92 bool IsSelected() const;
93 bool IsValid() const;
94 #ifndef OPENTTD_MSU
95 const char *GetTextfile(TextfileType type) const;
96 #endif /* OPENTTD_MSU */
97 };
98
100 class NetworkContentSocketHandler : public NetworkTCPSocketHandler {
101 protected:
102 NetworkAddress client_addr;
103 virtual void Close();
104
105 bool ReceiveInvalidPacket(PacketContentType type);
106
114 virtual bool Receive_CLIENT_INFO_LIST(Packet *p);
115
123 virtual bool Receive_CLIENT_INFO_ID(Packet *p);
124
137 virtual bool Receive_CLIENT_INFO_EXTID(Packet *p);
138
152 virtual bool Receive_CLIENT_INFO_EXTID_MD5(Packet *p);
153
170 virtual bool Receive_SERVER_INFO(Packet *p);
171
179 virtual bool Receive_CLIENT_CONTENT(Packet *p);
180
191 virtual bool Receive_SERVER_CONTENT(Packet *p);
192
193 bool HandlePacket(Packet *p);
194 public:
200 NetworkContentSocketHandler(SOCKET s = INVALID_SOCKET, const NetworkAddress &address = NetworkAddress()) :
201 NetworkTCPSocketHandler(s),
202 client_addr(address)
203 {
204 }
205
207 virtual ~NetworkContentSocketHandler() { this->Close(); }
208
209 bool ReceivePackets();
210 };
211
212 #ifndef OPENTTD_MSU
213 Subdirectory GetContentInfoSubDir(ContentType type);
214 #endif /* OPENTTD_MSU */
215
216 #endif /* ENABLE_NETWORK */
217
218 #endif /* NETWORK_CORE_TCP_CONTENT_H */