12 #include "../../stdafx.h"
13 #include "../../textfile_gui.h"
14 #include "../../newgrf_config.h"
15 #include "../../base_media_base.h"
16 #include "../../ai/ai.hpp"
17 #include "../../game/game.hpp"
18 #include "../../fios.h"
21 #include "../../safeguards.h"
29 switch (this->
state) {
59 default: NOT_REACHED();
74 tmp = gc !=
nullptr ? gc->
filename.c_str() :
nullptr;
91 if (tmp ==
nullptr)
return std::nullopt;
116 Debug(net, 0,
"[tcp/content] Received invalid packet type {}", type);
118 Debug(net, 0,
"[tcp/content] Received illegal packet");
149 std::unique_ptr<Packet> p;
150 static const int MAX_PACKETS_TO_RECEIVE = 42;
151 int i = MAX_PACKETS_TO_RECEIVE;
154 if (!cont)
return true;
157 return i != MAX_PACKETS_TO_RECEIVE - 1;
168 Debug(net, 0,
"[tcp/content] Received illegal packet type {}", type);
static uint32_t BSWAP32(uint32_t x)
Perform a 32 bits endianness bitswap on x.
static AIScannerLibrary * GetScannerLibrary()
Gets the ScriptScanner instance that is used to find AI Libraries.
static AIScannerInfo * GetScannerInfo()
Gets the ScriptScanner instance that is used to find AIs.
static GameScannerLibrary * GetScannerLibrary()
Gets the ScriptScanner instance that is used to find Game Libraries.
static GameScannerInfo * GetScannerInfo()
Gets the ScriptScanner instance that is used to find Game scripts.
virtual bool Receive_CLIENT_CONTENT(Packet &p)
Client requesting the actual content: uint16_t count of unique ids uint32_t unique id (count times)
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,...
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 ...
virtual bool Receive_SERVER_INFO(Packet &p)
Server sending list of content info: uint8_t type (invalid ID == does not exist) uint32_t id uint32_t...
virtual bool Receive_CLIENT_INFO_ID(Packet &p)
Client requesting a list of content info: uint16_t count of ids uint32_t id (count times)
virtual bool Receive_SERVER_CONTENT(Packet &p)
Server sending list of content info: uint32_t unique id uint32_t file size (0 == does not exist) stri...
bool ReceivePackets()
Receive a packet at TCP level.
virtual bool Receive_CLIENT_INFO_LIST(Packet &p)
Client requesting a list of content info: uint8_t type uint32_t openttd version (or 0xFFFFFFFF if usi...
bool ReceiveInvalidPacket(PacketContentType type)
Helper for logging receiving invalid packets.
bool HandlePacket(Packet &p)
Handle the given packet, i.e.
bool HasClientQuit() const
Whether the current client connected to the socket has quit.
virtual std::unique_ptr< Packet > ReceivePacket()
Receives a packet for the given client.
const char * FindMainScript(const ContentInfo *ci, bool md5sum)
Find a script of a ContentInfo.
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
Subdirectory
The different kinds of subdirectories OpenTTD uses.
@ NO_DIRECTORY
A path without any base directory.
@ AI_LIBRARY_DIR
Subdirectory for all AI libraries.
@ GAME_LIBRARY_DIR
Subdirectory for all GS libraries.
@ AI_DIR
Subdirectory for all AI files.
@ SCENARIO_DIR
Base directory for all scenarios.
@ HEIGHTMAP_DIR
Subdirectory of scenario for heightmaps.
@ NEWGRF_DIR
Subdirectory for all NewGRFs.
@ BASESET_DIR
Subdirectory for all base data (base sets, intro game)
@ GAME_DIR
Subdirectory for all game scripts.
const char * FindScenario(const ContentInfo *ci, bool md5sum)
Find a given scenario based on its unique ID.
const GRFConfig * FindGRFConfig(uint32_t grfid, FindGRFConfigMode mode, const MD5Hash *md5sum, uint32_t desired_version)
Find a NewGRF in the scanned list.
@ FGCM_EXACT
Only find Grfs matching md5sum.
uint32_t unique_id
Unique ID; either GRF ID or shortname.
bool IsValid() const
Is the information from this content info valid?
MD5Hash md5sum
The MD5 checksum.
State state
Whether the content info is selected (for download)
std::optional< std::string > GetTextfile(TextfileType type) const
Search a textfile file next to this file in the content list.
@ ALREADY_HERE
The content is already at the client side.
@ AUTOSELECTED
The content has been selected as dependency.
@ INVALID
The content's invalid.
@ SELECTED
The content has been manually selected.
bool IsSelected() const
Is the state either selected or autoselected?
ContentType type
Type of content.
Information about GRF, used in the game and (part of it) in savegames.
std::string filename
Filename - either with or without full path.
Internal entity of a packet.
uint8_t Recv_uint8()
Read a 8 bits integer from the packet.
Subdirectory GetContentInfoSubDir(ContentType type)
Helper to get the subdirectory a ContentInfo is located in.
Basic functions to receive and send TCP packets to/from the content server.
ContentType
The values in the enum are important; they are used as database 'keys'.
@ CONTENT_TYPE_AI_LIBRARY
The content consists of an AI library.
@ CONTENT_TYPE_BASE_SOUNDS
The content consists of base sounds.
@ CONTENT_TYPE_GAME_LIBRARY
The content consists of a GS library.
@ CONTENT_TYPE_BASE_GRAPHICS
The content consists of base graphics.
@ CONTENT_TYPE_AI
The content consists of an AI.
@ CONTENT_TYPE_SCENARIO
The content consists of a scenario.
@ CONTENT_TYPE_NEWGRF
The content consists of a NewGRF.
@ CONTENT_TYPE_BEGIN
Helper to mark the begin of the types.
@ CONTENT_TYPE_BASE_MUSIC
The content consists of base music.
@ CONTENT_TYPE_GAME
The content consists of a game script.
@ CONTENT_TYPE_END
Helper to mark the end of the types.
@ CONTENT_TYPE_HEIGHTMAP
The content consists of a heightmap.
PacketContentType
Enum with all types of TCP content packets.
@ PACKET_CONTENT_CLIENT_CONTENT
Request a content file given an internal ID.
@ PACKET_CONTENT_END
Must ALWAYS be on the end of this list!! (period)
@ PACKET_CONTENT_CLIENT_INFO_LIST
Queries the content server for a list of info of a given content type.
@ PACKET_CONTENT_CLIENT_INFO_EXTID_MD5
Queries the content server for information about a list of external IDs and MD5.
@ PACKET_CONTENT_SERVER_INFO
Reply of content server with information about content.
@ PACKET_CONTENT_SERVER_CONTENT
Reply with the content of the given ID.
@ PACKET_CONTENT_CLIENT_INFO_ID
Queries the content server for information about a list of internal IDs.
@ PACKET_CONTENT_CLIENT_INFO_EXTID
Queries the content server for information about a list of external IDs.
std::optional< std::string > GetTextfile(TextfileType type, Subdirectory dir, const std::string &filename)
Search a textfile file next to the given content.
TextfileType
Additional text files accompanying Tar archives.