Merge remote-tracking branch 'upstream/release/14' into 14
This commit is contained in:
@@ -48,7 +48,7 @@ static const size_t COMPAT_MTU = 1460; ///< Number of bytes we can pack in a sin
|
||||
static const byte NETWORK_GAME_ADMIN_VERSION = 3; ///< What version of the admin network do we use?
|
||||
static const byte NETWORK_GAME_INFO_VERSION = 7; ///< What version of game-info do we use?
|
||||
static const byte NETWORK_COORDINATOR_VERSION = 6; ///< What version of game-coordinator-protocol do we use?
|
||||
static const byte NETWORK_SURVEY_VERSION = 1; ///< What version of the survey do we use?
|
||||
static const byte NETWORK_SURVEY_VERSION = 2; ///< What version of the survey do we use?
|
||||
|
||||
static const uint NETWORK_NAME_LENGTH = 80; ///< The maximum length of the server name and map name, in bytes including '\0'
|
||||
static const uint NETWORK_COMPANY_NAME_LENGTH = 128; ///< The maximum length of the company name, in bytes including '\0'
|
||||
|
||||
@@ -24,10 +24,9 @@
|
||||
*/
|
||||
enum PacketGameType : uint8_t {
|
||||
/*
|
||||
* These first four pair of packets (thus eight in
|
||||
* total) must remain in this order for backward
|
||||
* and forward compatibility between clients that
|
||||
* are trying to join directly.
|
||||
* These first ten packets must remain in this order for backward and forward compatibility
|
||||
* between clients that are trying to join directly. These packets can be received and/or sent
|
||||
* by the server before the server has processed the 'join' packet from the client.
|
||||
*/
|
||||
|
||||
/* Packets sent by socket accepting code without ever constructing a client socket instance. */
|
||||
@@ -46,6 +45,10 @@ enum PacketGameType : uint8_t {
|
||||
PACKET_SERVER_GAME_INFO, ///< Information about the server.
|
||||
PACKET_CLIENT_GAME_INFO, ///< Request information about the server.
|
||||
|
||||
/* A server quitting this game. */
|
||||
PACKET_SERVER_NEWGAME, ///< The server is preparing to start a new game.
|
||||
PACKET_SERVER_SHUTDOWN, ///< The server is shutting down.
|
||||
|
||||
/*
|
||||
* Packets after here assume that the client
|
||||
* and server are running the same version. As
|
||||
@@ -115,10 +118,6 @@ enum PacketGameType : uint8_t {
|
||||
PACKET_SERVER_COMPANY_UPDATE, ///< Information (password) of a company changed.
|
||||
PACKET_SERVER_CONFIG_UPDATE, ///< Some network configuration important to the client changed.
|
||||
|
||||
/* A server quitting this game. */
|
||||
PACKET_SERVER_NEWGAME, ///< The server is preparing to start a new game.
|
||||
PACKET_SERVER_SHUTDOWN, ///< The server is shutting down.
|
||||
|
||||
/* A client quitting. */
|
||||
PACKET_CLIENT_QUIT, ///< A client tells the server it is going to quit.
|
||||
PACKET_SERVER_QUIT, ///< A server tells that a client has quit.
|
||||
|
||||
@@ -746,6 +746,7 @@ public:
|
||||
Debug(net, 9, "Client::OnConnect(): connection_string={}", this->connection_string);
|
||||
|
||||
_networking = true;
|
||||
_network_own_client_id = ClientID{};
|
||||
new ClientNetworkGameSocketHandler(s, this->connection_string);
|
||||
IConsoleCmdExec("exec scripts/on_client.scr 0");
|
||||
NetworkClient_Connected();
|
||||
|
||||
@@ -882,7 +882,8 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE(Packet
|
||||
SendMapOk();
|
||||
|
||||
/* As we skipped switch-mode, update the time we "switched". */
|
||||
_switch_mode_time = std::chrono::steady_clock::now();
|
||||
_game_session_stats.start_time = std::chrono::steady_clock::now();
|
||||
_game_session_stats.savegame_size = std::nullopt;
|
||||
|
||||
ShowClientList();
|
||||
|
||||
|
||||
@@ -327,15 +327,15 @@ static void DistributeQueue(CommandQueue &queue, const NetworkClientSocket *owne
|
||||
|
||||
/* Not technically the most performant way, but consider clients rarely click more than once per tick. */
|
||||
for (auto cp = queue.begin(); cp != queue.end(); /* removing some items */) {
|
||||
/* Limit the number of commands per client per tick. */
|
||||
if (--to_go < 0) break;
|
||||
|
||||
/* Do not distribute commands when paused and the command is not allowed while paused. */
|
||||
if (_pause_mode != PM_UNPAUSED && !IsCommandAllowedWhilePaused(cp->cmd)) {
|
||||
++cp;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Limit the number of commands per client per tick. */
|
||||
if (--to_go < 0) break;
|
||||
|
||||
DistributeCommandPacket(*cp, owner);
|
||||
NetworkAdminCmdLogging(owner, *cp);
|
||||
cp = queue.erase(cp);
|
||||
|
||||
@@ -466,6 +466,8 @@ class NetworkContentListWindow : public Window, ContentCallback {
|
||||
/** Filter content by tags/name */
|
||||
static bool CDECL TagNameFilter(const ContentInfo * const *a, ContentListFilterData &filter)
|
||||
{
|
||||
if ((*a)->state == ContentInfo::SELECTED || (*a)->state == ContentInfo::AUTOSELECTED) return true;
|
||||
|
||||
filter.string_filter.ResetState();
|
||||
for (auto &tag : (*a)->tags) filter.string_filter.AddLine(tag);
|
||||
|
||||
@@ -811,6 +813,7 @@ public:
|
||||
if (click_count > 1 || IsInsideBS(pt.x, checkbox->pos_x, checkbox->current_x)) {
|
||||
_network_content_client.ToggleSelectedState(this->selected);
|
||||
this->content.ForceResort();
|
||||
this->content.ForceRebuild();
|
||||
}
|
||||
|
||||
if (this->filter_data.types.any()) {
|
||||
@@ -997,7 +1000,7 @@ public:
|
||||
this->SetWidgetDisabledState(WID_NCL_DOWNLOAD, this->filesize_sum == 0 || (FindWindowById(WC_NETWORK_STATUS_WINDOW, WN_NETWORK_STATUS_WINDOW_CONTENT_DOWNLOAD) != nullptr && data != 2));
|
||||
this->SetWidgetDisabledState(WID_NCL_UNSELECT, this->filesize_sum == 0);
|
||||
this->SetWidgetDisabledState(WID_NCL_SELECT_ALL, !show_select_all);
|
||||
this->SetWidgetDisabledState(WID_NCL_SELECT_UPDATE, !show_select_upgrade);
|
||||
this->SetWidgetDisabledState(WID_NCL_SELECT_UPDATE, !show_select_upgrade || !this->filter_data.string_filter.IsEmpty());
|
||||
this->SetWidgetDisabledState(WID_NCL_OPEN_URL, this->selected == nullptr || this->selected->url.empty());
|
||||
for (TextfileType tft = TFT_CONTENT_BEGIN; tft < TFT_CONTENT_END; tft++) {
|
||||
this->SetWidgetDisabledState(WID_NCL_TEXTFILE + tft, this->selected == nullptr || this->selected->state != ContentInfo::ALREADY_HERE || !this->selected->GetTextfile(tft).has_value());
|
||||
|
||||
@@ -248,7 +248,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::CloseConnection(NetworkRecvSta
|
||||
|
||||
/* Inform other clients of this... strange leaving ;) */
|
||||
for (NetworkClientSocket *new_cs : NetworkClientSocket::Iterate()) {
|
||||
if (new_cs->status > STATUS_AUTHORIZED && this != new_cs) {
|
||||
if (new_cs->status >= STATUS_AUTHORIZED && this != new_cs) {
|
||||
new_cs->SendErrorQuit(this->client_id, NETWORK_ERROR_CONNECTION_LOST);
|
||||
}
|
||||
}
|
||||
@@ -366,7 +366,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendError(NetworkErrorCode err
|
||||
StringID strid = GetNetworkErrorMsg(error);
|
||||
|
||||
/* Only send when the current client was in game */
|
||||
if (this->status > STATUS_AUTHORIZED) {
|
||||
if (this->status >= STATUS_AUTHORIZED) {
|
||||
std::string client_name = this->GetClientName();
|
||||
|
||||
Debug(net, 1, "'{}' made an error and has been disconnected: {}", client_name, GetString(strid));
|
||||
@@ -1252,7 +1252,7 @@ void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, co
|
||||
} else {
|
||||
/* Else find the client to send the message to */
|
||||
for (NetworkClientSocket *cs : NetworkClientSocket::Iterate()) {
|
||||
if (cs->client_id == (ClientID)dest) {
|
||||
if (cs->client_id == (ClientID)dest && cs->status >= ServerNetworkGameSocketHandler::STATUS_AUTHORIZED) {
|
||||
cs->SendChat(action, from_id, false, msg, data);
|
||||
break;
|
||||
}
|
||||
@@ -1269,7 +1269,7 @@ void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, co
|
||||
}
|
||||
} else {
|
||||
for (NetworkClientSocket *cs : NetworkClientSocket::Iterate()) {
|
||||
if (cs->client_id == from_id) {
|
||||
if (cs->client_id == from_id && cs->status >= ServerNetworkGameSocketHandler::STATUS_AUTHORIZED) {
|
||||
cs->SendChat(action, (ClientID)dest, true, msg, data);
|
||||
break;
|
||||
}
|
||||
@@ -1284,7 +1284,7 @@ void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, co
|
||||
ci_to = nullptr;
|
||||
for (NetworkClientSocket *cs : NetworkClientSocket::Iterate()) {
|
||||
ci = cs->GetInfo();
|
||||
if (ci != nullptr && ci->client_playas == (CompanyID)dest) {
|
||||
if (ci != nullptr && ci->client_playas == (CompanyID)dest && cs->status >= ServerNetworkGameSocketHandler::STATUS_AUTHORIZED) {
|
||||
cs->SendChat(action, from_id, false, msg, data);
|
||||
if (cs->client_id == from_id) show_local = false;
|
||||
ci_to = ci; // Remember a client that is in the company for company-name
|
||||
@@ -1316,7 +1316,7 @@ void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, co
|
||||
NetworkTextMessage(action, GetDrawStringCompanyColour(ci_own->client_playas), true, name, msg, data);
|
||||
} else {
|
||||
for (NetworkClientSocket *cs : NetworkClientSocket::Iterate()) {
|
||||
if (cs->client_id == from_id) {
|
||||
if (cs->client_id == from_id && cs->status >= ServerNetworkGameSocketHandler::STATUS_AUTHORIZED) {
|
||||
cs->SendChat(action, ci_to->client_id, true, msg, data);
|
||||
}
|
||||
}
|
||||
@@ -1330,7 +1330,7 @@ void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, co
|
||||
|
||||
case DESTTYPE_BROADCAST:
|
||||
for (NetworkClientSocket *cs : NetworkClientSocket::Iterate()) {
|
||||
cs->SendChat(action, from_id, false, msg, data);
|
||||
if (cs->status >= ServerNetworkGameSocketHandler::STATUS_AUTHORIZED) cs->SendChat(action, from_id, false, msg, data);
|
||||
}
|
||||
|
||||
NetworkAdminChat(action, desttype, from_id, msg, data, from_admin);
|
||||
@@ -1353,7 +1353,7 @@ void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, co
|
||||
void NetworkServerSendExternalChat(const std::string &source, TextColour colour, const std::string &user, const std::string &msg)
|
||||
{
|
||||
for (NetworkClientSocket *cs : NetworkClientSocket::Iterate()) {
|
||||
cs->SendExternalChat(source, colour, user, msg);
|
||||
if (cs->status >= ServerNetworkGameSocketHandler::STATUS_AUTHORIZED) cs->SendExternalChat(source, colour, user, msg);
|
||||
}
|
||||
NetworkTextMessage(NETWORK_ACTION_EXTERNAL_CHAT, colour, false, user, msg, 0, source);
|
||||
}
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
|
||||
#include "../safeguards.h"
|
||||
|
||||
extern std::string _savegame_id;
|
||||
|
||||
NetworkSurveyHandler _survey = {};
|
||||
|
||||
NLOHMANN_JSON_SERIALIZE_ENUM(NetworkSurveyHandler::Reason, {
|
||||
@@ -43,7 +41,6 @@ std::string NetworkSurveyHandler::CreatePayload(Reason reason, bool for_preview)
|
||||
|
||||
survey["schema"] = NETWORK_SURVEY_VERSION;
|
||||
survey["reason"] = reason;
|
||||
survey["id"] = _savegame_id;
|
||||
survey["date"] = fmt::format("{:%Y-%m-%d %H:%M:%S} (UTC)", fmt::gmtime(time(nullptr)));
|
||||
|
||||
#ifdef SURVEY_KEY
|
||||
@@ -53,6 +50,8 @@ std::string NetworkSurveyHandler::CreatePayload(Reason reason, bool for_preview)
|
||||
survey["key"] = "";
|
||||
#endif
|
||||
|
||||
SurveyGameSession(survey["session"]);
|
||||
|
||||
{
|
||||
auto &info = survey["info"];
|
||||
SurveyOS(info["os"]);
|
||||
|
||||
Reference in New Issue
Block a user