From 1b6048819730b9fa5c48cb1e4c59fbb0545e49aa Mon Sep 17 00:00:00 2001 From: The Dude Date: Tue, 15 Oct 2019 11:46:15 +0200 Subject: [PATCH] Add: inform clients what game-script a server is running --- src/lang/english.txt | 1 + src/network/core/config.h | 2 +- src/network/core/game_info.cpp | 15 ++++++++++++++- src/network/core/game_info.h | 2 ++ src/network/network_gui.cpp | 9 ++++++++- 5 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/lang/english.txt b/src/lang/english.txt index 94a1bf7442a7e..0ee52d2f8d375 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -2033,6 +2033,7 @@ STR_NETWORK_SERVER_LIST_SERVER_VERSION :{SILVER}Server STR_NETWORK_SERVER_LIST_SERVER_ADDRESS :{SILVER}Server address: {WHITE}{RAW_STRING} STR_NETWORK_SERVER_LIST_START_DATE :{SILVER}Start date: {WHITE}{DATE_SHORT} STR_NETWORK_SERVER_LIST_CURRENT_DATE :{SILVER}Current date: {WHITE}{DATE_SHORT} +STR_NETWORK_SERVER_LIST_GAMESCRIPT :{SILVER}Gamescript: {WHITE}{RAW_STRING} (v{NUM}) STR_NETWORK_SERVER_LIST_PASSWORD :{SILVER}Password protected! STR_NETWORK_SERVER_LIST_SERVER_OFFLINE :{SILVER}SERVER OFFLINE STR_NETWORK_SERVER_LIST_SERVER_FULL :{SILVER}SERVER FULL diff --git a/src/network/core/config.h b/src/network/core/config.h index fee969b6d4720..8c3ccdd7a9e61 100644 --- a/src/network/core/config.h +++ b/src/network/core/config.h @@ -55,7 +55,7 @@ static const uint16 TCP_MTU = 32767; ///< Number of static const uint16 COMPAT_MTU = 1460; ///< Number of bytes we can pack in a single packet for backward compatibility static const byte NETWORK_GAME_ADMIN_VERSION = 1; ///< What version of the admin network do we use? -static const byte NETWORK_GAME_INFO_VERSION = 5; ///< What version of game-info do we use? +static const byte NETWORK_GAME_INFO_VERSION = 6; ///< What version of game-info do we use? static const byte NETWORK_COMPANY_INFO_VERSION = 6; ///< What version of company info is this? static const byte NETWORK_MASTER_SERVER_VERSION = 2; ///< What version of master-server-protocol do we use? static const byte NETWORK_COORDINATOR_VERSION = 1; ///< What version of game-coordinator-protocol do we use? diff --git a/src/network/core/game_info.cpp b/src/network/core/game_info.cpp index 1637610bcaed1..e7e028d689349 100644 --- a/src/network/core/game_info.cpp +++ b/src/network/core/game_info.cpp @@ -22,6 +22,8 @@ #include "../network_func.h" #include "../network.h" #include "packet.h" +#include "../../game/game.hpp" +#include "../../game/game_info.hpp" #include "../../safeguards.h" @@ -190,11 +192,16 @@ static void HandleIncomingNetworkGameInfoGRFConfig(GRFConfig *config, std::strin */ void SerializeNetworkGameInfo(Packet *p, const NetworkServerGameInfo *info, GameInfoNewGRFMode newgrf_mode) { - p->Send_uint8 (NETWORK_GAME_INFO_VERSION); + p->Send_uint8(NETWORK_GAME_INFO_VERSION); /* Update the documentation in game_info.h on changes * to the NetworkGameInfo wire-protocol! */ + /* NETWORK_GAME_INFO_VERSION = 6 */ + GameInfo *game_info = Game::GetInfo(); + p->Send_uint32(game_info == nullptr ? -1 : (uint32)game_info->GetVersion()); + p->Send_string(game_info == nullptr ? "" : game_info->GetName()); + /* NETWORK_GAME_INFO_VERSION = 5 */ assert(info->join_key.empty() || info->join_key[0] == '+'); p->Send_string(info->join_key.empty() ? "" : info->join_key.substr(1)); @@ -269,6 +276,12 @@ void DeserializeNetworkGameInfo(Packet *p, NetworkGameInfo *info) GameInfoNewGRFMode newgrf_mode = GAME_INFO_NEWGRF_MODE_SHORT; switch (game_info_version) { + case 6: { + info->gamescript_version = (int)p->Recv_uint32(); + info->gamescript_name = p->Recv_string(NETWORK_NAME_LENGTH); + FALLTHROUGH; + } + case 5: { std::string join_key = p->Recv_string(NETWORK_JOIN_KEY_LENGTH); info->join_key = join_key.empty() ? "" : "+" + join_key; diff --git a/src/network/core/game_info.h b/src/network/core/game_info.h index edd9145478b56..5423676b570bb 100644 --- a/src/network/core/game_info.h +++ b/src/network/core/game_info.h @@ -80,6 +80,8 @@ struct NetworkServerGameInfo { byte spectators_on; ///< How many spectators do we have? byte spectators_max; ///< Max spectators allowed on server byte landscape; ///< The used landscape + int gamescript_version; ///< Version of the gamescript. + std::string gamescript_name; ///< Name of the gamescript. }; /** diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index 965a6d1b8769d..8b3d6d64cff73 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -675,6 +675,13 @@ class NetworkGameWindow : public Window { DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_SERVER_LIST_CURRENT_DATE); // current date y += FONT_HEIGHT_NORMAL; + if (sel->info.gamescript_version != -1) { + SetDParamStr(0, sel->info.gamescript_name); + SetDParam(1, sel->info.gamescript_version); + DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_SERVER_LIST_GAMESCRIPT); // gamescript name and version + y += FONT_HEIGHT_NORMAL; + } + y += WD_PAR_VSEP_NORMAL; if (!sel->info.compatible) { @@ -933,7 +940,7 @@ static const NWidgetPart _nested_network_game_widgets[] = { EndContainer(), NWidget(WWT_PANEL, COLOUR_LIGHT_BLUE, WID_NG_DETAILS), NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(5, 5, 5), - NWidget(WWT_EMPTY, INVALID_COLOUR, WID_NG_DETAILS_SPACER), SetMinimalSize(140, 0), SetMinimalTextLines(15, 24 + WD_PAR_VSEP_NORMAL), SetResize(0, 1), SetFill(1, 1), // Make sure it's at least this wide + NWidget(WWT_EMPTY, INVALID_COLOUR, WID_NG_DETAILS_SPACER), SetMinimalSize(270, 0), SetMinimalTextLines(15, 24 + WD_PAR_VSEP_NORMAL), SetResize(0, 1), SetFill(1, 1), // Make sure it's at least this wide NWidget(NWID_HORIZONTAL, NC_NONE), SetPIP(5, 5, 5), NWidget(NWID_SELECTION, INVALID_COLOUR, WID_NG_NEWGRF_MISSING_SEL), NWidget(WWT_PUSHTXTBTN, COLOUR_WHITE, WID_NG_NEWGRF_MISSING), SetFill(1, 0), SetDataTip(STR_NEWGRF_SETTINGS_FIND_MISSING_CONTENT_BUTTON, STR_NEWGRF_SETTINGS_FIND_MISSING_CONTENT_TOOLTIP),