Merge branch 'master' into jgrpp

# Conflicts:
#	cmake/CompileFlags.cmake
#	src/crashlog.cpp
#	src/fileio.cpp
#	src/fileio_func.h
#	src/fios_gui.cpp
#	src/ini_load.cpp
#	src/ini_type.h
#	src/lang/english.txt
#	src/lang/german.txt
#	src/lang/korean.txt
#	src/network/network_client.cpp
#	src/order_base.h
#	src/order_cmd.cpp
#	src/os/windows/win32.cpp
#	src/road_cmd.cpp
#	src/saveload/saveload.cpp
#	src/saveload/saveload.h
#	src/settings.cpp
#	src/station_cmd.cpp
#	src/stdafx.h
#	src/table/settings.ini
#	src/tree_cmd.cpp
#	src/tree_gui.cpp
#	src/vehicle_base.h
#	src/video/cocoa/cocoa_v.mm
#	src/video/cocoa/event.mm
#	src/video/cocoa/wnd_quartz.mm
#	src/viewport.cpp
#	src/widgets/tree_widget.h
This commit is contained in:
Jonathan G Rennison
2021-01-30 23:24:40 +00:00
235 changed files with 3537 additions and 3063 deletions

View File

@@ -270,7 +270,7 @@ static inline bool ShutdownSocket(SOCKET d, bool read, bool write, uint linger_t
}
/* Make sure these structures have the size we expect them to be */
assert_compile(sizeof(in_addr) == 4); ///< IPv4 addresses should be 4 bytes.
assert_compile(sizeof(in6_addr) == 16); ///< IPv6 addresses should be 16 bytes.
static_assert(sizeof(in_addr) == 4); ///< IPv4 addresses should be 4 bytes.
static_assert(sizeof(in6_addr) == 16); ///< IPv6 addresses should be 16 bytes.
#endif /* NETWORK_CORE_OS_ABSTRACTION_H */

View File

@@ -18,10 +18,10 @@
#include "../../safeguards.h"
/* Make sure that these enums match. */
assert_compile((int)CRR_MANUAL == (int)ADMIN_CRR_MANUAL);
assert_compile((int)CRR_AUTOCLEAN == (int)ADMIN_CRR_AUTOCLEAN);
assert_compile((int)CRR_BANKRUPT == (int)ADMIN_CRR_BANKRUPT);
assert_compile((int)CRR_END == (int)ADMIN_CRR_END);
static_assert((int)CRR_MANUAL == (int)ADMIN_CRR_MANUAL);
static_assert((int)CRR_AUTOCLEAN == (int)ADMIN_CRR_AUTOCLEAN);
static_assert((int)CRR_BANKRUPT == (int)ADMIN_CRR_BANKRUPT);
static_assert((int)CRR_END == (int)ADMIN_CRR_END);
/**
* Create the admin handler for the given socket.

View File

@@ -44,7 +44,7 @@ bool _ddc_fastforward = true;
#endif /* DEBUG_DUMP_COMMANDS */
/** Make sure both pools have the same size. */
assert_compile(NetworkClientInfoPool::MAX_SIZE == NetworkClientSocketPool::MAX_SIZE);
static_assert(NetworkClientInfoPool::MAX_SIZE == NetworkClientSocketPool::MAX_SIZE);
/** The pool with client information. */
NetworkClientInfoPool _networkclientinfo_pool("NetworkClientInfo");
@@ -83,8 +83,8 @@ uint8 _network_advertise_retries; ///< The number of advertisement retries w
CompanyMask _network_company_passworded; ///< Bitmask of the password status of all companies.
/* Check whether NETWORK_NUM_LANDSCAPES is still in sync with NUM_LANDSCAPE */
assert_compile((int)NETWORK_NUM_LANDSCAPES == (int)NUM_LANDSCAPE);
assert_compile((int)NETWORK_COMPANY_NAME_LENGTH == MAX_LENGTH_COMPANY_NAME_CHARS * MAX_CHAR_LENGTH);
static_assert((int)NETWORK_NUM_LANDSCAPES == (int)NUM_LANDSCAPE);
static_assert((int)NETWORK_COMPANY_NAME_LENGTH == MAX_LENGTH_COMPANY_NAME_CHARS * MAX_CHAR_LENGTH);
extern NetworkUDPSocketHandler *_udp_client_socket; ///< udp client socket
extern NetworkUDPSocketHandler *_udp_server_socket; ///< udp server socket
@@ -341,7 +341,7 @@ StringID GetNetworkErrorMsg(NetworkErrorCode err)
STR_NETWORK_ERROR_CLIENT_TIMEOUT_MAP,
STR_NETWORK_ERROR_CLIENT_TIMEOUT_JOIN,
};
assert_compile(lengthof(network_error_strings) == NETWORK_ERROR_END);
static_assert(lengthof(network_error_strings) == NETWORK_ERROR_END);
if (err >= (ptrdiff_t)lengthof(network_error_strings)) err = NETWORK_ERROR_GENERAL;
@@ -940,7 +940,7 @@ void NetworkGameLoop()
cp.reset(new CommandPacket());
int company;
cp->text.resize(MAX_CMD_TEXT_LENGTH);
assert_compile(MAX_CMD_TEXT_LENGTH > 8192);
static_assert(MAX_CMD_TEXT_LENGTH > 8192);
int ret = sscanf(p, "date{%x; %x; %x}; company: %x; tile: %x (%*u x %*u); p1: %x; p2: %x; p3: " OTTD_PRINTFHEX64 "; cmd: %x; \"%8192[^\"]\"",
&next_date, &next_date_fract, &next_tick_skip_counter, &company, &cp->tile, &cp->p1, &cp->p2, &cp->p3, &cp->cmd, const_cast<char *>(cp->text.c_str()));
/* There are 10 pieces of data to read, however the last is a

View File

@@ -54,7 +54,7 @@ static const AdminUpdateFrequency _admin_update_type_frequencies[] = {
ADMIN_FREQUENCY_AUTOMATIC, ///< ADMIN_UPDATE_GAMESCRIPT
};
/** Sanity check. */
assert_compile(lengthof(_admin_update_type_frequencies) == ADMIN_UPDATE_END);
static_assert(lengthof(_admin_update_type_frequencies) == ADMIN_UPDATE_END);
/**
* Create a new socket for the server side of the admin network.
@@ -86,7 +86,7 @@ ServerNetworkAdminSocketHandler::~ServerNetworkAdminSocketHandler()
bool accept = !StrEmpty(_settings_client.network.admin_password) && _network_admins_connected < MAX_ADMINS;
/* We can't go over the MAX_ADMINS limit here. However, if we accept
* the connection, there has to be space in the pool. */
assert_compile(NetworkAdminSocketPool::MAX_SIZE == MAX_ADMINS);
static_assert(NetworkAdminSocketPool::MAX_SIZE == MAX_ADMINS);
assert(!accept || ServerNetworkAdminSocketHandler::CanAllocateItem());
return accept;
}

View File

@@ -31,7 +31,7 @@
/** The draw buffer must be able to contain the chat message, client name and the "[All]" message,
* some spaces and possible translations of [All] to other languages. */
assert_compile((int)DRAW_STRING_BUFFER >= (int)NETWORK_CHAT_LENGTH + NETWORK_NAME_LENGTH + 40);
static_assert((int)DRAW_STRING_BUFFER >= (int)NETWORK_CHAT_LENGTH + NETWORK_NAME_LENGTH + 40);
/** Spacing between chat lines. */
static const uint NETWORK_CHAT_LINE_SPACING = 3;

View File

@@ -242,17 +242,25 @@ void ClientNetworkGameSocketHandler::ClientError(NetworkRecvStatus res)
default: errorno = NETWORK_ERROR_GENERAL; break;
}
/* This means we fucked up and the server closed the connection */
if (res != NETWORK_RECV_STATUS_SERVER_ERROR && res != NETWORK_RECV_STATUS_SERVER_FULL &&
res != NETWORK_RECV_STATUS_SERVER_BANNED) {
if (res == NETWORK_RECV_STATUS_SERVER_ERROR || res == NETWORK_RECV_STATUS_SERVER_FULL ||
res == NETWORK_RECV_STATUS_SERVER_BANNED) {
/* This means the server closed the connection. Emergency save is
* already created if this was appropriate during handling of the
* disconnect. */
this->SendPackets();
this->CloseConnection(res);
} else {
/* This means we as client made a boo-boo. */
SendError(errorno);
/* Close connection before we make an emergency save, as the save can
* take a bit of time; better that the server doesn't stall while we
* are doing the save, and already disconnects us. */
this->SendPackets();
this->CloseConnection(res);
ClientNetworkEmergencySave();
}
this->SendPackets();
this->CloseConnection(res);
ClientNetworkEmergencySave();
_switch_mode = SM_MENU;
_networking = false;
}
@@ -384,7 +392,7 @@ const char *_network_join_server_password = nullptr;
const char *_network_join_company_password = nullptr;
/** Make sure the server ID length is the same as a md5 hash. */
assert_compile(NETWORK_SERVER_ID_LENGTH == 16 * 2 + 1);
static_assert(NETWORK_SERVER_ID_LENGTH == 16 * 2 + 1);
/***********
* Sending functions
@@ -633,7 +641,7 @@ bool ClientNetworkGameSocketHandler::IsConnected()
* DEF_CLIENT_RECEIVE_COMMAND has parameter: Packet *p
************/
extern bool SafeLoad(const char *filename, SaveLoadOperation fop, DetailedFileType dft, GameMode newgm, Subdirectory subdir, struct LoadFilter *lf = nullptr);
extern bool SafeLoad(const std::string &filename, SaveLoadOperation fop, DetailedFileType dft, GameMode newgm, Subdirectory subdir, struct LoadFilter *lf = nullptr);
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_FULL(Packet *p)
{
@@ -774,7 +782,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_ERROR(Packet *p
STR_NETWORK_ERROR_TIMEOUT_MAP, // NETWORK_ERROR_TIMEOUT_MAP
STR_NETWORK_ERROR_TIMEOUT_JOIN, // NETWORK_ERROR_TIMEOUT_JOIN
};
assert_compile(lengthof(network_error_strings) == NETWORK_ERROR_END);
static_assert(lengthof(network_error_strings) == NETWORK_ERROR_END);
NetworkErrorCode error = (NetworkErrorCode)p->Recv_uint8();
@@ -967,7 +975,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE(Packet
/* The map is done downloading, load it */
ClearErrorMessages();
bool load_success = SafeLoad(nullptr, SLO_LOAD, DFT_GAME_FILE, GM_NORMAL, NO_DIRECTORY, lf);
bool load_success = SafeLoad({}, SLO_LOAD, DFT_GAME_FILE, GM_NORMAL, NO_DIRECTORY, lf);
/* Long savegame loads shouldn't affect the lag calculation! */
this->last_packet = _realtime_tick;

View File

@@ -392,14 +392,14 @@ void ClientNetworkContentSocketHandler::DownloadSelectedContentFallback(const Co
* @return a statically allocated buffer with the filename or
* nullptr when no filename could be made.
*/
static char *GetFullFilename(const ContentInfo *ci, bool compressed)
static std::string GetFullFilename(const ContentInfo *ci, bool compressed)
{
Subdirectory dir = GetContentInfoSubDir(ci->type);
if (dir == NO_DIRECTORY) return nullptr;
if (dir == NO_DIRECTORY) return {};
static char buf[MAX_PATH];
FioGetFullPath(buf, lastof(buf), SP_AUTODOWNLOAD_DIR, dir, ci->filename);
strecat(buf, compressed ? ".tar.gz" : ".tar", lastof(buf));
std::string buf = FioGetDirectory(SP_AUTODOWNLOAD_DIR, dir);
buf += ci->filename;
buf += compressed ? ".tar.gz" : ".tar";
return buf;
}
@@ -415,13 +415,13 @@ static bool GunzipFile(const ContentInfo *ci)
bool ret = true;
/* Need to open the file with fopen() to support non-ASCII on Windows. */
FILE *ftmp = fopen(GetFullFilename(ci, true), "rb");
FILE *ftmp = fopen(GetFullFilename(ci, true).c_str(), "rb");
if (ftmp == nullptr) return false;
/* Duplicate the handle, and close the FILE*, to avoid double-closing the handle later. */
gzFile fin = gzdopen(dup(fileno(ftmp)), "rb");
fclose(ftmp);
FILE *fout = fopen(GetFullFilename(ci, false), "wb");
FILE *fout = fopen(GetFullFilename(ci, false).c_str(), "wb");
if (fin == nullptr || fout == nullptr) {
ret = false;
@@ -516,8 +516,8 @@ bool ClientNetworkContentSocketHandler::BeforeDownload()
if (this->curInfo->filesize != 0) {
/* The filesize is > 0, so we are going to download it */
const char *filename = GetFullFilename(this->curInfo, true);
if (filename == nullptr || (this->curFile = fopen(filename, "wb")) == nullptr) {
std::string filename = GetFullFilename(this->curInfo, true);
if (filename.empty() || (this->curFile = fopen(filename.c_str(), "wb")) == nullptr) {
/* Unless that fails of course... */
DeleteWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_CONTENT_DOWNLOAD);
ShowErrorMessage(STR_CONTENT_ERROR_COULD_NOT_DOWNLOAD, STR_CONTENT_ERROR_COULD_NOT_DOWNLOAD_FILE_NOT_WRITABLE, WL_ERROR);
@@ -539,18 +539,19 @@ void ClientNetworkContentSocketHandler::AfterDownload()
this->curFile = nullptr;
if (GunzipFile(this->curInfo)) {
unlink(GetFullFilename(this->curInfo, true));
unlink(GetFullFilename(this->curInfo, true).c_str());
Subdirectory sd = GetContentInfoSubDir(this->curInfo->type);
if (sd == NO_DIRECTORY) NOT_REACHED();
TarScanner ts;
ts.AddFile(sd, GetFullFilename(this->curInfo, false));
std::string fname = GetFullFilename(this->curInfo, false);
ts.AddFile(sd, fname);
if (this->curInfo->type == CONTENT_TYPE_BASE_MUSIC) {
/* Music can't be in a tar. So extract the tar! */
ExtractTar(GetFullFilename(this->curInfo, false), BASESET_DIR);
unlink(GetFullFilename(this->curInfo, false));
ExtractTar(fname, BASESET_DIR);
unlink(fname.c_str());
}
#ifdef __EMSCRIPTEN__

View File

@@ -46,9 +46,9 @@ DECLARE_POSTFIX_INCREMENT(ClientID)
static ClientID _network_client_id = CLIENT_ID_FIRST;
/** Make very sure the preconditions given in network_type.h are actually followed */
assert_compile(MAX_CLIENT_SLOTS > MAX_CLIENTS);
static_assert(MAX_CLIENT_SLOTS > MAX_CLIENTS);
/** Yes... */
assert_compile(NetworkClientSocketPool::MAX_SIZE == MAX_CLIENT_SLOTS);
static_assert(NetworkClientSocketPool::MAX_SIZE == MAX_CLIENT_SLOTS);
/** The pool with clients. */
NetworkClientSocketPool _networkclientsocket_pool("NetworkClientSocket");
@@ -219,7 +219,7 @@ ServerNetworkGameSocketHandler::ServerNetworkGameSocketHandler(SOCKET s) : Netwo
/* The Socket and Info pools need to be the same in size. After all,
* each Socket will be associated with at most one Info object. As
* such if the Socket was allocated the Info object can as well. */
assert_compile(NetworkClientSocketPool::MAX_SIZE == NetworkClientInfoPool::MAX_SIZE);
static_assert(NetworkClientSocketPool::MAX_SIZE == NetworkClientInfoPool::MAX_SIZE);
}
/**
@@ -310,7 +310,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::CloseConnection(NetworkRecvSta
/* We can't go over the MAX_CLIENTS limit here. However, the
* pool must have place for all clients and ourself. */
assert_compile(NetworkClientSocketPool::MAX_SIZE == MAX_CLIENTS + 1);
static_assert(NetworkClientSocketPool::MAX_SIZE == MAX_CLIENTS + 1);
assert(!accept || ServerNetworkGameSocketHandler::CanAllocateItem());
return accept;
}
@@ -2060,7 +2060,7 @@ void NetworkServerShowStatusToConsole()
"active",
"close pending"
};
assert_compile(lengthof(stat_str) == NetworkClientSocket::STATUS_END);
static_assert(lengthof(stat_str) == NetworkClientSocket::STATUS_END);
for (NetworkClientSocket *cs : NetworkClientSocket::Iterate()) {
NetworkClientInfo *ci = cs->GetInfo();