MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / PerformNetworkAuthorizedKeyAction

Function PerformNetworkAuthorizedKeyAction

src/console_cmds.cpp:2059–2097  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2057};
2058
2059static void PerformNetworkAuthorizedKeyAction(std::string_view name, NetworkAuthorizedKeys *authorized_keys, ConNetworkAuthorizedKeyAction action, const std::string &authorized_key, CompanyID company = CompanyID::Invalid())
2060{
2061 switch (action) {
2062 case CNAKA_LIST:
2063 IConsolePrint(CC_WHITE, "The authorized keys for {} are:", name);
2064 for (auto &ak : *authorized_keys) IConsolePrint(CC_INFO, " {}", ak);
2065 return;
2066
2067 case CNAKA_ADD:
2068 if (authorized_keys->Contains(authorized_key)) {
2069 IConsolePrint(CC_WARNING, "Not added {} to {} as it already exists.", authorized_key, name);
2070 return;
2071 }
2072
2073 if (company == CompanyID::Invalid()) {
2074 authorized_keys->Add(authorized_key);
2075 } else {
2076 AutoRestoreBackup backup(_current_company, company);
2077 Command<CMD_COMPANY_ALLOW_LIST_CTRL>::Post(CALCA_ADD, authorized_key);
2078 }
2079 IConsolePrint(CC_INFO, "Added {} to {}.", authorized_key, name);
2080 return;
2081
2082 case CNAKA_REMOVE:
2083 if (!authorized_keys->Contains(authorized_key)) {
2084 IConsolePrint(CC_WARNING, "Not removed {} from {} as it does not exist.", authorized_key, name);
2085 return;
2086 }
2087
2088 if (company == CompanyID::Invalid()) {
2089 authorized_keys->Remove(authorized_key);
2090 } else {
2091 AutoRestoreBackup backup(_current_company, company);
2092 Command<CMD_COMPANY_ALLOW_LIST_CTRL>::Post(CALCA_REMOVE, authorized_key);
2093 }
2094 IConsolePrint(CC_INFO, "Removed {} from {}.", authorized_key, name);
2095 return;
2096 }
2097}
2098
2099static bool ConNetworkAuthorizedKey(std::span<std::string_view> argv)
2100{

Callers 1

ConNetworkAuthorizedKeyFunction · 0.85

Calls 5

InvalidFunction · 0.85
IConsolePrintFunction · 0.70
ContainsMethod · 0.45
AddMethod · 0.45
RemoveMethod · 0.45

Tested by

no test coverage detected