OpenTTD Source: src/network/network_content.cpp File Reference

OpenTTD Source 15.0-RC2

Data Structures | Typedefs | Functions | Variables
network_content.cpp File Reference

Content sending/receiving part of the network protocol. More...

`#include "../stdafx.h"`
`#include "../rev.h"`
`#include "../ai/ai.hpp"`
`#include "../game/game.hpp"`
`#include "../window_func.h"`
`#include "../error.h"`
`#include "../fileio_func.h"`
`#include "../base_media_base.h"`
`#include "../base_media_graphics.h"`
`#include "../base_media_music.h"`
`#include "../base_media_sounds.h"`
`#include "../settings_type.h"`
`#include "../strings_func.h"`
`#include "../timer/timer.h"`
`#include "../timer/timer_window.h"`
`#include "../core/string_consumer.hpp"`
`#include "network_content.h"`
`#include "table/strings.h"`
`#include <zlib.h>`
`#include "../safeguards.h"`

Go to the source code of this file.

## Data Structures
class | NetworkContentConnecter
| Connect to the content server. More...

## Typedefs
using | HasContentProc = bool(const ContentInfo &ci, bool md5sum)
| Check whether a function piece of content is locally known.

## Functions
bool | HasScenario (const ContentInfo &ci, bool md5sum)
| Check whether we've got a given scenario based on its unique ID.
static bool | HasGRFConfig (const ContentInfo &ci, bool md5sum)
| Wrapper function for the HasProc.
static HasContentProc * | GetHasContentProcforContentType (ContentType type)
| Get the has-content check function for the given content type.
static std::string | GetFullFilename (const ContentInfo &ci, bool compressed)
| Determine the full filename of a piece of content information.
static bool | GunzipFile (const ContentInfo &ci)
| Gunzip a given file and remove the .gz if successful.

## Variables
ClientNetworkContentSocketHandler | _network_content_client
| The client we use to connect to the server.
static constexpr auto | CONTENT_QUEUE_TIMEOUT = std::chrono::milliseconds(100)
| Timeout after queueing content for it to try to be requested.
static TimeoutTimer< TimerWindow > | _request_queue_timeout

## Detailed Description

Content sending/receiving part of the network protocol.

Definition in file network_content.cpp.

## Typedef Documentation

## ◆ HasContentProc

using HasContentProc = bool(const ContentInfo &ci, bool md5sum)

Check whether a function piece of content is locally known.

Matches on the unique ID and possibly the MD5 checksum.

Parameters

  ci | the content info to search for
  md5sum | also match the MD5 checksum?

Returns
  true iff it's known

Definition at line 62 of file network_content.cpp.

## Function Documentation

## ◆ GetFullFilename()

static std::string GetFullFilename | ( | const ContentInfo & | ci,
|  | bool | compressed
| ) |  |
| static

Determine the full filename of a piece of content information.

Parameters

  ci | the information to get the filename from
  compressed | should the filename end with .gz?

Returns
  a statically allocated buffer with the filename or nullptr when no filename could be made.

Definition at line 371 of file network_content.cpp.

References ContentInfo::filename, GetContentInfoSubDir(), NO_DIRECTORY, SP_AUTODOWNLOAD_DIR, and ContentInfo::type.

Referenced by ClientNetworkContentSocketHandler::AfterDownload(), ClientNetworkContentSocketHandler::BeforeDownload(), and GunzipFile().

## ◆ GetHasContentProcforContentType()

static HasContentProc * GetHasContentProcforContentType | ( | ContentType | type | ) |
| static

Get the has-content check function for the given content type.

Parameters

  type | Content type to get check function for.

Returns
  Check function pointer.

Definition at line 69 of file network_content.cpp.

References CONTENT_TYPE_AI, CONTENT_TYPE_AI_LIBRARY, CONTENT_TYPE_BASE_GRAPHICS, CONTENT_TYPE_BASE_MUSIC, CONTENT_TYPE_BASE_SOUNDS, CONTENT_TYPE_GAME, CONTENT_TYPE_GAME_LIBRARY, CONTENT_TYPE_HEIGHTMAP, CONTENT_TYPE_NEWGRF, CONTENT_TYPE_SCENARIO, AI::HasAI(), Game::HasGame(), HasGRFConfig(), HasScenario(), BaseMedia< SoundsSet >::HasSet(), BaseMedia< MusicSet >::HasSet(), and BaseMedia< GraphicsSet >::HasSet().

Referenced by ClientNetworkContentSocketHandler::Receive_SERVER_INFO().

## ◆ GunzipFile()

static bool GunzipFile | ( | const ContentInfo & | ci | ) |
| static

Gunzip a given file and remove the .gz if successful.

Parameters

  ci | container with filename

Returns
  true if the gunzip completed

Definition at line 388 of file network_content.cpp.

References GetFullFilename(), and FileHandle::Open().

Referenced by ClientNetworkContentSocketHandler::AfterDownload().

## ◆ HasGRFConfig()

static bool HasGRFConfig | ( | const ContentInfo & | ci,
|  | bool | md5sum
| ) |  |
| static

Wrapper function for the HasProc.

Definition at line 50 of file network_content.cpp.

References FGCM_ANY, FGCM_EXACT, FindGRFConfig(), ContentInfo::md5sum, and ContentInfo::unique_id.

Referenced by GetHasContentProcforContentType().

## ◆ HasScenario()

bool HasScenario | ( | const ContentInfo & | ci,
|  | bool | md5sum
| ) |  |
| extern

Check whether we've got a given scenario based on its unique ID.

Parameters

  ci | The content info to compare it to.
  md5sum | Whether to look at the md5sum or the id.

Returns
  True iff we've got the scenario.

Definition at line 684 of file fios.cpp.

References FindScenario().

Referenced by GetHasContentProcforContentType().

## Variable Documentation

## ◆ _network_content_client

ClientNetworkContentSocketHandler _network_content_client

The client we use to connect to the server.

Definition at line 47 of file network_content.cpp.

Referenced by BaseNetworkContentDownloadStatusWindow::BaseNetworkContentDownloadStatusWindow(), BootstrapAskForDownloadWindow::BootstrapAskForDownloadWindow(), NetworkContentListWindow::BuildContentList(), BootstrapAskForDownloadWindow::Close(), NetworkContentListWindow::Close(), BaseNetworkContentDownloadStatusWindow::Close(), NetworkContentListWindow::DrawDetails(), NetworkBackgroundLoop(), NetworkContentListWindow::NetworkContentListWindow(), BootstrapAskForDownloadWindow::OnClick(), NetworkContentDownloadStatusWindow::OnClick(), NetworkContentListWindow::OnClick(), BootstrapAskForDownloadWindow::OnConnect(), NetworkContentConnecter::OnConnect(), NetworkContentConnecter::OnFailure(), NetworkContentListWindow::OnKeyPress(), BootstrapAskForDownloadWindow::OnReceiveContentInfo(), NetworkContentListWindow::OnReceiveContentInfo(), and ShowNetworkContentListWindow().

## ◆ _request_queue_timeout

TimeoutTimer<TimerWindow> _request_queue_timeout
| static

Initial value:
= {CONTENT_QUEUE_TIMEOUT, []() {
_network_content_client.RequestQueuedContentInfo();
}}
ClientNetworkContentSocketHandler::RequestQueuedContentInfo
void RequestQueuedContentInfo()
Send a content request for queued content info download.
Definition network_content.cpp:805
_network_content_client
ClientNetworkContentSocketHandler _network_content_client
The client we use to connect to the server.
Definition network_content.cpp:47
CONTENT_QUEUE_TIMEOUT
static constexpr auto CONTENT_QUEUE_TIMEOUT
Timeout after queueing content for it to try to be requested.
Definition network_content.cpp:782

Definition at line 784 of file network_content.cpp.

## ◆ CONTENT_QUEUE_TIMEOUT

constexpr auto CONTENT_QUEUE_TIMEOUT = std::chrono::milliseconds(100)
| staticconstexpr

Timeout after queueing content for it to try to be requested.

Definition at line 782 of file network_content.cpp.

Referenced by ClientNetworkContentSocketHandler::RequestQueuedContentInfo().