OpenTTD Source
12.0-beta2
|
Go to the documentation of this file.
10 #ifndef NETWORK_CONTENT_H
11 #define NETWORK_CONTENT_H
103 static constexpr std::chrono::seconds
IDLE_TIMEOUT = std::chrono::seconds(60);
130 uint
Length()
const {
return (uint)this->infos.size(); }
Callbacks for notifying others about incoming data.
void OnConnect(bool success) override
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.
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.
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.
virtual void OnConnect(bool success)
Callback for when the connection has finished.
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.
bool include(std::vector< T > &vec, const T &item)
Helper function to append an item to a vector if it is not already contained Consider using std::set,...
void CheckDependencyState(ContentInfo *ci)
Check the dependencies (recursively) of this content info.
Socket handler for the content server connection.
virtual void OnDownloadComplete(ContentID cid)
We have finished downloading a file.
@ 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.
virtual void OnReceiveContentInfo(const ContentInfo *ci)
We received a content info.
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 OnReceiveData(const char *data, size_t length) override
We're receiving data.
void Unselect(ContentID cid)
Unselect a specific content id.
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.
FILE * curFile
Currently downloaded file.
void OnDownloadComplete(ContentID cid) override
We have finished downloading a file.
void OnDownloadProgress(const ContentInfo *ci, int bytes) override
We have progress in the download of a file.
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.
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 CDECL error(const char *s,...)
Error handling for fatal non-user errors.
void OnReceiveContentInfo(const ContentInfo *ci) override
We received a content info.
void SelectAll()
Select everything we can select.
ConstContentIterator Get(uint32 index) const
Get the nth position of the content inf iterator.
bool BeforeDownload()
Handle the opening of the file before downloading.
bool Receive_SERVER_INFO(Packet *p) override
Server sending list of content info: byte type (invalid ID == does not exist) uint32 id uint32 file_s...
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.
ContentInfo * GetContent(ContentID cid)
Get the content info based on a ContentID.
virtual ~ContentCallback()
Silentium.
std::vector< const ContentInfo * > ConstContentVector
Vector with constant content info.
bool Receive_SERVER_CONTENT(Packet *p) override
Server sending list of content info: uint32 unique id uint32 file size (0 == does not exist) string f...
ConstContentIterator Begin() const
Get the begin of the content inf iterator.
virtual void OnDownloadProgress(const ContentInfo *ci, int bytes)
We have progress in the download of a file.