OpenTTD Source
20240919-master-gdf0233f4c2
|
Go to the documentation of this file.
10 #ifndef NETWORK_CONTENT_H
11 #define NETWORK_CONTENT_H
15 #include <unordered_map>
16 #include "../core/container_func.hpp"
34 virtual void OnConnect([[maybe_unused]]
bool success) {}
91 void OnConnect(
bool success)
override;
93 void OnReceiveContentInfo(
const ContentInfo *ci)
override;
94 void OnDownloadProgress(
const ContentInfo *ci,
int bytes)
override;
95 void OnDownloadComplete(
ContentID cid)
override;
98 void OnReceiveData(std::unique_ptr<
char[]> data,
size_t length)
override;
108 static constexpr std::chrono::seconds
IDLE_TIMEOUT = std::chrono::seconds(60);
136 uint
Length()
const {
return (uint)this->infos.size(); }
virtual void OnDownloadProgress([[maybe_unused]] const ContentInfo *ci, [[maybe_unused]] int bytes)
We have progress in the download of a file.
Callbacks for notifying others about incoming data.
virtual void OnReceiveContentInfo([[maybe_unused]] const ContentInfo *ci)
We received a content info.
virtual void OnConnect([[maybe_unused]] bool success)
Callback for when the connection has finished.
Base socket handler for all Content TCP sockets.
void ReverseLookupDependency(ConstContentVector &parents, const ContentInfo *child) const
Reverse lookup the dependencies of (direct) parents over a given child.
ConstContentIterator End() const
Get the end of the content inf iterator.
void SendReceive()
Check whether we received/can send some data from/to the content server and when that's the case hand...
Callback for when the HTTP handler has something to tell us.
void OnReceiveData(std::unique_ptr< char[]> data, size_t length) override
We're receiving data.
std::optional< FileHandle > curFile
Currently downloaded file.
uint Length() const
Get the number of content items we know locally.
std::chrono::steady_clock::time_point lastActivity
The last time there was network activity.
int http_response_index
Where we are, in the response, with handling it.
bool Receive_SERVER_CONTENT(Packet &p) override
Server sending list of content info: uint32_t unique id uint32_t file size (0 == does not exist) stri...
ClientNetworkContentSocketHandler _network_content_client
The client we use to connect to the server.
void ShowNetworkContentListWindow(ContentVector *cv=nullptr, ContentType type1=CONTENT_TYPE_END, ContentType type2=CONTENT_TYPE_END)
Show the content list window with a given set of content.
std::vector< ContentInfo * > ContentVector
Vector with content info.
void ShowMissingContentWindow(const GRFConfig *list)
Show the content list window with all missing grfs from the given list.
void CheckDependencyState(ContentInfo *ci)
Check the dependencies (recursively) of this content info.
Socket handler for the content server connection.
std::unordered_multimap< ContentID, ContentID > reverse_dependency_map
Content reverse dependency map.
@ CONTENT_TYPE_END
Helper to mark the end of the types.
void Clear()
Clear all downloaded content information.
bool isConnecting
Whether we're connecting.
const typedef ContentInfo *const * ConstContentIterator
Iterator for the constant content vector.
ContentType
The values in the enum are important; they are used as database 'keys'.
ContentInfo * curInfo
Information about the currently downloaded file.
void DownloadSelectedContentHTTP(const ContentIDList &content)
Initiate downloading the content over HTTP.
void RequestContentList(ContentType type)
Request the content list for the given type.
bool include(Container &container, typename Container::const_reference &item)
Helper function to append an item to a container if it is not already contained.
void OnDisconnect() override
Callback for when the connection got disconnected.
Information about GRF, used in the game and (part of it) in savegames.
ContentVector infos
All content info we received.
void DownloadContentInfo(ContentID cid)
Download information of a given Content ID if not already tried.
~ClientNetworkContentSocketHandler()
Clear up the mess ;)
void UnselectAll()
Unselect everything that we've not downloaded so far.
Container for all important information about a piece of content.
void Unselect(ContentID cid)
Unselect a specific content id.
bool isCancelled
Whether the download has been cancelled.
virtual void OnDownloadComplete([[maybe_unused]] ContentID cid)
We have finished downloading a file.
ContentInfo ** ContentIterator
Iterator for the content vector.
void OnFailure() override
An error has occurred and the connection has been closed.
static constexpr std::chrono::seconds IDLE_TIMEOUT
The idle timeout; when to close the connection because it's idle.
ContentInfo * GetContent(ContentID cid) const
Get the content info based on a ContentID.
void RemoveCallback(ContentCallback *cb)
Remove a callback.
Internal entity of a packet.
void DownloadSelectedContent(uint &files, uint &bytes, bool fallback=false)
Actually begin downloading the content we selected.
std::vector< char > http_response
The HTTP response to the requests we've been doing.
bool Receive_SERVER_INFO(Packet &p) override
Server sending list of content info: uint8_t type (invalid ID == does not exist) uint32_t id uint32_t...
bool IsCancelled() const override
Check if there is a request to cancel the transfer.
std::vector< ContentID > ContentIDList
List of content IDs to (possibly) select.
void ReverseLookupTreeDependency(ConstContentVector &tree, const ContentInfo *child) const
Reverse lookup the dependencies of all parents over a given child.
void Connect()
Connect with the content server.
void ToggleSelectedState(const ContentInfo *ci)
Toggle the state of a content info and check its dependencies.
NetworkRecvStatus
Status of a network client; reasons why a client has quit.
ContentID
Unique identifier for the content.
std::vector< ContentCallback * > callbacks
Callbacks to notify "the world".
void Select(ContentID cid)
Select a specific content id.
ContentIDList requested
ContentIDs we already requested (so we don't do it again)
Connect to the content server.
void DownloadSelectedContentFallback(const ContentIDList &content)
Initiate downloading the content over the fallback protocol.
void AddCallback(ContentCallback *cb)
Add a callback to this class.
void SelectAll()
Select everything we can select.
void Cancel()
Cancel the current download.
bool BeforeDownload()
Handle the opening of the file before downloading.
NetworkRecvStatus CloseConnection(bool error=true) override
Disconnect from the content server.
void SelectUpgrade()
Select everything that's an update for something we've got.
void AfterDownload()
Handle the closing and extracting of a file after downloading it has been done.
ClientNetworkContentSocketHandler()
Create a socket handler to handle the connection.
virtual void OnDisconnect()
Callback for when the connection got disconnected.
std::vector< const ContentInfo * > ConstContentVector
Vector with constant content info.
ConstContentIterator Begin() const
Get the begin of the content inf iterator.
ConstContentIterator Get(uint32_t index) const
Get the nth position of the content inf iterator.
virtual ~ContentCallback()=default
Silentium.