Changeset - r25881:988fc42507a5
[Not reviewed]
master
0 4 0
Patric Stout - 3 years ago 2021-08-14 08:19:40
truebrain@openttd.org
Add: synchronize server name to clients and display in Online Players GUI (#9472)
4 files changed with 17 insertions and 9 deletions:
0 comments (0 inline, 0 general)
src/network/network_client.cpp
Show inline comments
 
@@ -311,12 +311,14 @@ static uint32 last_ack_frame;
 
static uint32 _password_game_seed;
 
/** The other bit of 'entropy' used to generate a salt for the company passwords. */
 
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;
 

	
 
/** Make sure the server ID length is the same as a md5 hash. */
 
static_assert(NETWORK_SERVER_ID_LENGTH == 16 * 2 + 1);
 
@@ -1184,12 +1186,13 @@ NetworkRecvStatus ClientNetworkGameSocke
 

	
 
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CONFIG_UPDATE(Packet *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;
 
}
 

	
 
NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_COMPANY_UPDATE(Packet *p)
 
{
src/network/network_gui.cpp
Show inline comments
 
@@ -1598,20 +1598,20 @@ static const NWidgetPart _nested_client_
 
		NWidget(WWT_CLOSEBOX, COLOUR_GREY),
 
		NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_NETWORK_CLIENT_LIST_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
 
		NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
 
		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),
 
					NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_CL_SERVER_VISIBILITY), SetDataTip(STR_BLACK_STRING, STR_NETWORK_CLIENT_LIST_SERVER_VISIBILITY_TOOLTIP),
 
				EndContainer(),
 
				NWidget(NWID_HORIZONTAL), SetPIP(0, 3, 0),
 
@@ -2014,12 +2014,13 @@ public:
 
	void OnInvalidateData(int data = 0, bool gui_scope = true) override
 
	{
 
		this->RebuildList();
 

	
 
		/* 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
 
	{
 
		switch (widget) {
 
			case WID_CL_SERVER_VISIBILITY:
 
@@ -2048,13 +2049,13 @@ public:
 
	}
 

	
 
	void SetStringParameters(int widget) const override
 
	{
 
		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:
 
				SetDParam(0, STR_NETWORK_SERVER_VISIBILITY_LOCAL + _settings_client.network.server_game_type);
 
				break;
 

	
src/network/network_internal.h
Show inline comments
 
@@ -83,12 +83,15 @@ extern NetworkJoinStatus _network_join_s
 
extern uint8 _network_join_waiting;
 
extern uint32 _network_join_bytes;
 
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;
 

	
 
void NetworkQueryServer(const std::string &connection_string);
 
void NetworkQueryLobbyServer(const std::string &connection_string);
src/network/network_server.cpp
Show inline comments
 
@@ -817,12 +817,13 @@ NetworkRecvStatus ServerNetworkGameSocke
 
/** Send an update about the max company/spectator counts. */
 
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;
 
}
 

	
 
/***********
 
 * Receiving functions
0 comments (0 inline, 0 general)