Add: maximum number of companies allowed to the client list

This commit is contained in:
Zachary
2022-10-03 10:52:38 -04:00
committed by rubidium42
parent 6f9b3fa964
commit e17c82e32b
5 changed files with 21 additions and 4 deletions

View File

@@ -1111,6 +1111,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CONFIG_UPDATE(P
_network_server_max_companies = p->Recv_uint8();
_network_server_name = p->Recv_string(NETWORK_NAME_LENGTH);
SetWindowClassesDirty(WC_CLIENT_LIST);
return NETWORK_RECV_STATUS_OKAY;
}
@@ -1319,11 +1320,20 @@ bool NetworkClientPreferTeamChat(const NetworkClientInfo *cio)
return false;
}
/**
* Get the maximum number of companies that are allowed by the server.
* @return The number of companies allowed.
*/
uint NetworkMaxCompaniesAllowed()
{
return _network_server ? _settings_client.network.max_companies : _network_server_max_companies;
}
/**
* Check if max_companies has been reached on the server (local check only).
* @return true if the max value has been reached or exceeded, false otherwise.
*/
bool NetworkMaxCompaniesReached()
{
return Company::GetNumItems() >= (_network_server ? _settings_client.network.max_companies : _network_server_max_companies);
return Company::GetNumItems() >= NetworkMaxCompaniesAllowed();
}

View File

@@ -59,6 +59,7 @@ void NetworkClientSendRcon(const std::string &password, const std::string &comma
void NetworkClientSendChat(NetworkAction action, DestType type, int dest, const std::string &msg, int64 data = 0);
bool NetworkClientPreferTeamChat(const NetworkClientInfo *cio);
bool NetworkCompanyIsPassworded(CompanyID company_id);
uint NetworkMaxCompaniesAllowed();
bool NetworkMaxCompaniesReached();
void NetworkPrintClients();
void NetworkHandlePauseChange(PauseMode prev_mode, PauseMode changed_mode);

View File

@@ -1352,7 +1352,7 @@ static const NWidgetPart _nested_client_list_widgets[] = {
NWidget(NWID_VERTICAL),
NWidget(WWT_MATRIX, COLOUR_GREY, WID_CL_MATRIX), SetMinimalSize(180, 0), SetResize(1, 1), SetFill(1, 1), SetMatrixDataTip(1, 0, STR_NULL), SetScrollbar(WID_CL_SCROLLBAR),
NWidget(WWT_PANEL, COLOUR_GREY),
NWidget(WWT_TEXT, COLOUR_GREY, WID_CL_CLIENT_COMPANY_COUNT), SetFill(1, 0), SetMinimalTextLines(1, 0), SetResize(1, 0), SetPadding(2, 1, 2, 1), SetAlignment(SA_CENTER), SetDataTip(STR_NETWORK_CLIENT_LIST_CLIENT_COMPANY_COUNT, STR_NULL),
NWidget(WWT_TEXT, COLOUR_GREY, WID_CL_CLIENT_COMPANY_COUNT), SetFill(1, 0), SetMinimalTextLines(1, 0), SetResize(1, 0), SetPadding(2, 1, 2, 1), SetAlignment(SA_CENTER), SetDataTip(STR_NETWORK_CLIENT_LIST_CLIENT_COMPANY_COUNT, STR_NETWORK_CLIENT_LIST_CLIENT_COMPANY_COUNT_TOOLTIP),
EndContainer(),
EndContainer(),
NWidget(NWID_VERTICAL),
@@ -1797,6 +1797,7 @@ public:
case WID_CL_CLIENT_COMPANY_COUNT:
SetDParam(0, NetworkClientInfo::GetNumItems());
SetDParam(1, Company::GetNumItems());
SetDParam(2, NetworkMaxCompaniesAllowed());
break;
}
}