Codechange: use enum class for CompanyAllowListCtrlAction

This commit is contained in:
Peter Nelson
2026-02-15 09:30:32 +00:00
committed by Peter Nelson
parent d09b91cd92
commit 1c095ba464
5 changed files with 19 additions and 21 deletions
+8 -8
View File
@@ -1008,18 +1008,18 @@ CommandCost CmdCompanyCtrl(DoCommandFlags flags, CompanyCtrlAction cca, CompanyI
static bool ExecuteAllowListCtrlAction(CompanyAllowListCtrlAction action, Company *c, const std::string &public_key)
{
switch (action) {
case CALCA_ADD:
case CompanyAllowListCtrlAction::AddKey:
return c->allow_list.Add(public_key);
case CALCA_REMOVE:
case CompanyAllowListCtrlAction::RemoveKey:
return c->allow_list.Remove(public_key);
case CALCA_ALLOW_ANY:
case CompanyAllowListCtrlAction::AllowAny:
if (c->allow_any) return false;
c->allow_any = true;
return true;
case CALCA_ALLOW_LISTED:
case CompanyAllowListCtrlAction::AllowListed:
if (!c->allow_any) return false;
c->allow_any = false;
return true;
@@ -1042,14 +1042,14 @@ CommandCost CmdCompanyAllowListCtrl(DoCommandFlags flags, CompanyAllowListCtrlAc
if (c == nullptr) return CMD_ERROR;
switch (action) {
case CALCA_ADD:
case CALCA_REMOVE:
case CompanyAllowListCtrlAction::AddKey:
case CompanyAllowListCtrlAction::RemoveKey:
/* The public key length includes the '\0'. */
if (public_key.size() != NETWORK_PUBLIC_KEY_LENGTH - 1) return CMD_ERROR;
break;
case CALCA_ALLOW_ANY:
case CALCA_ALLOW_LISTED:
case CompanyAllowListCtrlAction::AllowAny:
case CompanyAllowListCtrlAction::AllowListed:
if (public_key.size() != 0) return CMD_ERROR;
break;
+5 -7
View File
@@ -75,13 +75,11 @@ enum class CompanyCtrlAction : uint8_t {
};
/** The action to do with Commands::CompanyAllowListControl. */
enum CompanyAllowListCtrlAction : uint8_t {
CALCA_ADD, ///< Create a public key.
CALCA_REMOVE, ///< Remove a public key.
CALCA_ALLOW_ANY, ///< Allow joining the company without a key.
CALCA_ALLOW_LISTED, ///< Allow only listed keys to join the company.
CALCA_END, ///< Sentinel for end.
enum class CompanyAllowListCtrlAction : uint8_t {
AddKey, ///< Create a public key.
RemoveKey, ///< Remove a public key.
AllowAny, ///< Allow joining the company without a key.
AllowListed, ///< Allow only listed keys to join the company.
};
#endif /* COMPANY_TYPE_H */
+2 -2
View File
@@ -2146,7 +2146,7 @@ static void PerformNetworkAuthorizedKeyAction(std::string_view name, NetworkAuth
authorized_keys->Add(authorized_key);
} else {
AutoRestoreBackup backup(_current_company, company);
Command<Commands::CompanyAllowListControl>::Post(CALCA_ADD, authorized_key);
Command<Commands::CompanyAllowListControl>::Post(CompanyAllowListCtrlAction::AddKey, authorized_key);
}
IConsolePrint(CC_INFO, "Added {} to {}.", authorized_key, name);
return;
@@ -2161,7 +2161,7 @@ static void PerformNetworkAuthorizedKeyAction(std::string_view name, NetworkAuth
authorized_keys->Remove(authorized_key);
} else {
AutoRestoreBackup backup(_current_company, company);
Command<Commands::CompanyAllowListControl>::Post(CALCA_REMOVE, authorized_key);
Command<Commands::CompanyAllowListControl>::Post(CompanyAllowListCtrlAction::RemoveKey, authorized_key);
}
IConsolePrint(CC_INFO, "Removed {} from {}.", authorized_key, name);
return;
+3 -3
View File
@@ -1654,7 +1654,7 @@ private:
static void OnClickClientAuthorize([[maybe_unused]] NetworkClientListWindow *w, [[maybe_unused]] Point pt, ClientID client_id)
{
AutoRestoreBackup<CompanyID> cur_company(_current_company, NetworkClientInfo::GetByClientID(_network_own_client_id)->client_playas);
Command<Commands::CompanyAllowListControl>::Post(CALCA_ADD, NetworkClientInfo::GetByClientID(client_id)->public_key);
Command<Commands::CompanyAllowListControl>::Post(CompanyAllowListCtrlAction::AddKey, NetworkClientInfo::GetByClientID(client_id)->public_key);
}
/**
@@ -1910,13 +1910,13 @@ public:
case DropDownAction::CompanyAllowAny: {
AutoRestoreBackup cur_company(_current_company, this->dd_company_id);
Command<Commands::CompanyAllowListControl>::Post(CALCA_ALLOW_ANY, {});
Command<Commands::CompanyAllowListControl>::Post(CompanyAllowListCtrlAction::AllowAny, {});
return;
}
case DropDownAction::CompanyAllowListed: {
AutoRestoreBackup cur_company(_current_company, this->dd_company_id);
Command<Commands::CompanyAllowListControl>::Post(CALCA_ALLOW_LISTED, {});
Command<Commands::CompanyAllowListControl>::Post(CompanyAllowListCtrlAction::AllowListed, {});
return;
}
+1 -1
View File
@@ -2215,7 +2215,7 @@ void NetworkServerNewCompany(const Company *c, NetworkClientInfo *ci)
* different state/president/company name in the different clients, we need to
* circumvent the normal ::Post logic and go directly to sending the command.
*/
Command<Commands::CompanyAllowListControl>::SendNet(STR_NULL, c->index, CALCA_ADD, ci->public_key);
Command<Commands::CompanyAllowListControl>::SendNet(STR_NULL, c->index, CompanyAllowListCtrlAction::AddKey, ci->public_key);
Command<Commands::RenamePresident>::SendNet(STR_NULL, c->index, ci->client_name);
NetworkServerSendChat(NETWORK_ACTION_COMPANY_NEW, DESTTYPE_BROADCAST, 0, "", ci->client_id, c->index + 1);