diff options
author | Patric Stout <truebrain@openttd.org> | 2021-08-14 10:19:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-14 10:19:40 +0200 |
commit | 508e465b590c28113ceac472cb73112dbe58435a (patch) | |
tree | 4644eaad4beb402165837efd246facd67132ab82 /src | |
parent | 65b8614d2640a0cfa5472689f5ddcb5fbefc06d2 (diff) | |
download | openttd-508e465b590c28113ceac472cb73112dbe58435a.tar.xz |
Add: synchronize server name to clients and display in Online Players GUI (#9472)
Diffstat (limited to 'src')
-rw-r--r-- | src/network/network_client.cpp | 3 | ||||
-rw-r--r-- | src/network/network_gui.cpp | 19 | ||||
-rw-r--r-- | src/network/network_internal.h | 3 | ||||
-rw-r--r-- | src/network/network_server.cpp | 1 |
4 files changed, 17 insertions, 9 deletions
diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp index 16fd31cfe..a1a86c8de 100644 --- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -314,6 +314,8 @@ static std::string _password_server_id; /** Maximum number of companies of the currently joined server. */ static uint8 _network_server_max_companies; +/** The current name of the server you are on. */ +std::string _network_server_name; /** Information about the game to join to. */ NetworkJoinInfo _network_join; @@ -1187,6 +1189,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CONFIG_UPDATE(P if (this->status < STATUS_ACTIVE) return NETWORK_RECV_STATUS_MALFORMED_PACKET; _network_server_max_companies = p->Recv_uint8(); + _network_server_name = p->Recv_string(NETWORK_NAME_LENGTH); return NETWORK_RECV_STATUS_OKAY; } diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index 076b3d46e..34e06712c 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -1601,14 +1601,14 @@ static const NWidgetPart _nested_client_list_widgets[] = { NWidget(WWT_STICKYBOX, COLOUR_GREY), EndContainer(), NWidget(WWT_PANEL, COLOUR_GREY), - NWidget(NWID_SELECTION, INVALID_COLOUR, WID_CL_SERVER_SELECTOR), - NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_NETWORK_CLIENT_LIST_SERVER, STR_NULL), SetPadding(4, 4, 0, 4), SetPIP(0, 2, 0), - NWidget(NWID_HORIZONTAL), SetPIP(0, 3, 0), - NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalTextLines(1, 0), SetDataTip(STR_NETWORK_CLIENT_LIST_SERVER_NAME, STR_NULL), - NWidget(NWID_SPACER), SetMinimalSize(10, 0), - NWidget(WWT_TEXT, COLOUR_GREY, WID_CL_SERVER_NAME), SetFill(1, 0), SetMinimalTextLines(1, 0), SetResize(1, 0), SetDataTip(STR_BLACK_RAW_STRING, STR_NETWORK_CLIENT_LIST_SERVER_NAME_TOOLTIP), SetAlignment(SA_VERT_CENTER | SA_RIGHT), - NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_CL_SERVER_NAME_EDIT), SetMinimalSize(12, 14), SetDataTip(SPR_RENAME, STR_NETWORK_CLIENT_LIST_SERVER_NAME_EDIT_TOOLTIP), - EndContainer(), + NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_NETWORK_CLIENT_LIST_SERVER, STR_NULL), SetPadding(4, 4, 0, 4), SetPIP(0, 2, 0), + NWidget(NWID_HORIZONTAL), SetPIP(0, 3, 0), + NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalTextLines(1, 0), SetDataTip(STR_NETWORK_CLIENT_LIST_SERVER_NAME, STR_NULL), + NWidget(NWID_SPACER), SetMinimalSize(10, 0), + NWidget(WWT_TEXT, COLOUR_GREY, WID_CL_SERVER_NAME), SetFill(1, 0), SetMinimalTextLines(1, 0), SetResize(1, 0), SetDataTip(STR_BLACK_RAW_STRING, STR_NETWORK_CLIENT_LIST_SERVER_NAME_TOOLTIP), SetAlignment(SA_VERT_CENTER | SA_RIGHT), + NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_CL_SERVER_NAME_EDIT), SetMinimalSize(12, 14), SetDataTip(SPR_RENAME, STR_NETWORK_CLIENT_LIST_SERVER_NAME_EDIT_TOOLTIP), + EndContainer(), + NWidget(NWID_SELECTION, INVALID_COLOUR, WID_CL_SERVER_SELECTOR), NWidget(NWID_HORIZONTAL), SetPIP(0, 3, 0), NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalTextLines(1, 0), SetDataTip(STR_NETWORK_CLIENT_LIST_SERVER_VISIBILITY, STR_NULL), NWidget(NWID_SPACER), SetMinimalSize(10, 0), SetFill(1, 0), SetResize(1, 0), @@ -2017,6 +2017,7 @@ public: /* Currently server information is not sync'd to clients, so we cannot show it on clients. */ this->GetWidget<NWidgetStacked>(WID_CL_SERVER_SELECTOR)->SetDisplayedPlane(_network_server ? 0 : SZSP_HORIZONTAL); + this->SetWidgetDisabledState(WID_CL_SERVER_NAME_EDIT, !_network_server); } void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override @@ -2051,7 +2052,7 @@ public: { switch (widget) { case WID_CL_SERVER_NAME: - SetDParamStr(0, _settings_client.network.server_name); + SetDParamStr(0, _network_server ? _settings_client.network.server_name : _network_server_name); break; case WID_CL_SERVER_VISIBILITY: diff --git a/src/network/network_internal.h b/src/network/network_internal.h index 2c6639961..5f04088f4 100644 --- a/src/network/network_internal.h +++ b/src/network/network_internal.h @@ -86,6 +86,9 @@ extern uint32 _network_join_bytes_total; extern ConnectionType _network_server_connection_type; extern std::string _network_server_invite_code; +/* Variable available for clients. */ +extern std::string _network_server_name; + extern uint8 _network_reconnect; extern CompanyMask _network_company_passworded; diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp index e4e1de906..c817acc90 100644 --- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -820,6 +820,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::SendConfigUpdate() Packet *p = new Packet(PACKET_SERVER_CONFIG_UPDATE); p->Send_uint8(_settings_client.network.max_companies); + p->Send_string(_settings_client.network.server_name); this->SendPacket(p); return NETWORK_RECV_STATUS_OKAY; } |