Add helper functions for network settings admin state
This commit is contained in:
@@ -2105,10 +2105,7 @@ struct BuildVehicleWindow : BuildVehicleWindowBase {
|
|||||||
this->SetWidgetsDisabledState(this->sel_engine == INVALID_ENGINE, WID_BV_SHOW_HIDE, WID_BV_BUILD);
|
this->SetWidgetsDisabledState(this->sel_engine == INVALID_ENGINE, WID_BV_SHOW_HIDE, WID_BV_BUILD);
|
||||||
|
|
||||||
/* Disable renaming engines in network games if you are not the server. */
|
/* Disable renaming engines in network games if you are not the server. */
|
||||||
this->SetWidgetDisabledState(WID_BV_RENAME, this->sel_engine == INVALID_ENGINE || (_networking && !_network_server));
|
this->SetWidgetDisabledState(WID_BV_RENAME, this->sel_engine == INVALID_ENGINE || IsNonAdminNetworkClient());
|
||||||
|
|
||||||
/* disable renaming engines in network games if you are not the server */
|
|
||||||
this->SetWidgetDisabledState(WID_BV_RENAME, _networking && !(_network_server || _network_settings_access));
|
|
||||||
|
|
||||||
this->DrawWidgets();
|
this->DrawWidgets();
|
||||||
|
|
||||||
|
@@ -58,7 +58,7 @@ static int32_t _money_cheat_amount = 10000000;
|
|||||||
*/
|
*/
|
||||||
static int32_t ClickMoneyCheat(int32_t p1, int32_t p2)
|
static int32_t ClickMoneyCheat(int32_t p1, int32_t p2)
|
||||||
{
|
{
|
||||||
DoCommandPEx(0, 0, 0, (uint64_t)(p2 * _money_cheat_amount), _network_server || _network_settings_access ? CMD_MONEY_CHEAT_ADMIN : CMD_MONEY_CHEAT);
|
DoCommandPEx(0, 0, 0, (uint64_t)(p2 * _money_cheat_amount), IsNetworkSettingsAdmin() ? CMD_MONEY_CHEAT_ADMIN : CMD_MONEY_CHEAT);
|
||||||
return _money_cheat_amount;
|
return _money_cheat_amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,13 +212,13 @@ static bool IsCheatAllowed(CheatNetworkMode mode)
|
|||||||
{
|
{
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case CNM_ALL:
|
case CNM_ALL:
|
||||||
return !_networking || _network_server || _network_settings_access;
|
return !IsNonAdminNetworkClient();
|
||||||
|
|
||||||
case CNM_LOCAL_ONLY:
|
case CNM_LOCAL_ONLY:
|
||||||
return !_networking;
|
return !_networking;
|
||||||
|
|
||||||
case CNM_MONEY:
|
case CNM_MONEY:
|
||||||
return !_networking || _network_server || _network_settings_access || _settings_game.difficulty.money_cheat_in_multiplayer;
|
return !IsNonAdminNetworkClient() || _settings_game.difficulty.money_cheat_in_multiplayer;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -507,7 +507,7 @@ struct CheatWindow : Window {
|
|||||||
}
|
}
|
||||||
if (ce->mode == CNM_MONEY) {
|
if (ce->mode == CNM_MONEY) {
|
||||||
if (!_networking) *ce->been_used = true;
|
if (!_networking) *ce->been_used = true;
|
||||||
DoCommandPEx(0, 0, 0, (std::strtoll(str, nullptr, 10) / _currency->rate), _network_server || _network_settings_access ? CMD_MONEY_CHEAT_ADMIN : CMD_MONEY_CHEAT);
|
DoCommandPEx(0, 0, 0, (std::strtoll(str, nullptr, 10) / _currency->rate), IsNetworkSettingsAdmin() ? CMD_MONEY_CHEAT_ADMIN : CMD_MONEY_CHEAT);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -532,7 +532,7 @@ static WindowDesc _cheats_desc(__FILE__, __LINE__,
|
|||||||
|
|
||||||
bool CheatWindowMayBeShown()
|
bool CheatWindowMayBeShown()
|
||||||
{
|
{
|
||||||
return _game_mode != GM_EDITOR && (!_networking || _network_server || _network_settings_access || _settings_game.difficulty.money_cheat_in_multiplayer);
|
return _game_mode != GM_EDITOR && (!IsNonAdminNetworkClient() || _settings_game.difficulty.money_cheat_in_multiplayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Open cheat window. */
|
/** Open cheat window. */
|
||||||
|
@@ -368,7 +368,7 @@ struct MainWindow : Window
|
|||||||
/* You can only cheat for money in single player or when otherwise suitably authorised. */
|
/* You can only cheat for money in single player or when otherwise suitably authorised. */
|
||||||
if (!_networking || _settings_game.difficulty.money_cheat_in_multiplayer) {
|
if (!_networking || _settings_game.difficulty.money_cheat_in_multiplayer) {
|
||||||
DoCommandP(0, 10000000, 0, CMD_MONEY_CHEAT);
|
DoCommandP(0, 10000000, 0, CMD_MONEY_CHEAT);
|
||||||
} else if (_network_server || _network_settings_access) {
|
} else if (IsNetworkSettingsAdmin()) {
|
||||||
DoCommandP(0, 10000000, 0, CMD_MONEY_CHEAT_ADMIN);
|
DoCommandP(0, 10000000, 0, CMD_MONEY_CHEAT_ADMIN);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@@ -22,4 +22,14 @@ extern bool _network_dedicated; ///< are we a dedicated server?
|
|||||||
extern bool _is_network_server; ///< Does this client wants to be a network-server?
|
extern bool _is_network_server; ///< Does this client wants to be a network-server?
|
||||||
extern bool _network_settings_access; ///< Can this client change server settings?
|
extern bool _network_settings_access; ///< Can this client change server settings?
|
||||||
|
|
||||||
|
inline bool IsNetworkSettingsAdmin()
|
||||||
|
{
|
||||||
|
return _network_server || _network_settings_access;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool IsNonAdminNetworkClient()
|
||||||
|
{
|
||||||
|
return _networking && !(_network_server || _network_settings_access);
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* NETWORK_H */
|
#endif /* NETWORK_H */
|
||||||
|
@@ -1024,7 +1024,7 @@ void IniSaveWindowSettings(IniFile &ini, const char *grpname, void *desc)
|
|||||||
*/
|
*/
|
||||||
bool SettingDesc::IsEditable(bool do_command) const
|
bool SettingDesc::IsEditable(bool do_command) const
|
||||||
{
|
{
|
||||||
if (!do_command && !(this->flags & SF_NO_NETWORK_SYNC) && _networking && !(_network_server || _network_settings_access) && !(this->flags & SF_PER_COMPANY)) return false;
|
if (!do_command && !(this->flags & SF_NO_NETWORK_SYNC) && IsNonAdminNetworkClient() && !(this->flags & SF_PER_COMPANY)) return false;
|
||||||
if (do_command && (this->flags & SF_NO_NETWORK_SYNC)) return false;
|
if (do_command && (this->flags & SF_NO_NETWORK_SYNC)) return false;
|
||||||
if ((this->flags & SF_NETWORK_ONLY) && !_networking && _game_mode != GM_MENU) return false;
|
if ((this->flags & SF_NETWORK_ONLY) && !_networking && _game_mode != GM_MENU) return false;
|
||||||
if ((this->flags & SF_NO_NETWORK) && _networking) return false;
|
if ((this->flags & SF_NO_NETWORK) && _networking) return false;
|
||||||
@@ -1772,7 +1772,7 @@ static void MaxNoAIsChange(int32_t new_value)
|
|||||||
{
|
{
|
||||||
if (GetGameSettings().difficulty.max_no_competitors != 0 &&
|
if (GetGameSettings().difficulty.max_no_competitors != 0 &&
|
||||||
AI::GetInfoList()->size() == 0 &&
|
AI::GetInfoList()->size() == 0 &&
|
||||||
(!_networking || (_network_server || _network_settings_access))) {
|
!IsNonAdminNetworkClient()) {
|
||||||
ShowErrorMessage(STR_WARNING_NO_SUITABLE_AI, INVALID_STRING_ID, WL_CRITICAL);
|
ShowErrorMessage(STR_WARNING_NO_SUITABLE_AI, INVALID_STRING_ID, WL_CRITICAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3296,7 +3296,7 @@ bool SetSettingValue(const IntSettingDesc *sd, int32_t value, bool force_newgame
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* send non-company-based settings over the network */
|
/* send non-company-based settings over the network */
|
||||||
if (!_networking || (_networking && (_network_server || _network_settings_access))) {
|
if (!IsNonAdminNetworkClient()) {
|
||||||
return DoCommandP(0, 0, value, CMD_CHANGE_SETTING, nullptr, setting->name);
|
return DoCommandP(0, 0, value, CMD_CHANGE_SETTING, nullptr, setting->name);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -3411,7 +3411,7 @@ void IConsoleSetSetting(const char *name, const char *value, bool force_newgame)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!success) {
|
if (!success) {
|
||||||
if ((_network_server || _network_settings_access)) {
|
if (IsNetworkSettingsAdmin()) {
|
||||||
IConsoleError("This command/variable is not available during network games.");
|
IConsoleError("This command/variable is not available during network games.");
|
||||||
} else {
|
} else {
|
||||||
IConsoleError("This command/variable is only available to a network server.");
|
IConsoleError("This command/variable is only available to a network server.");
|
||||||
|
@@ -208,7 +208,7 @@ static CallBackFunction SelectSignTool()
|
|||||||
|
|
||||||
static CallBackFunction ToolbarPauseClick(Window *)
|
static CallBackFunction ToolbarPauseClick(Window *)
|
||||||
{
|
{
|
||||||
if (_networking && !(_network_server || _network_settings_access)) return CBF_NONE; // only server can pause the game
|
if (IsNonAdminNetworkClient()) return CBF_NONE; // only server can pause the game
|
||||||
|
|
||||||
if (DoCommandP(0, PM_PAUSED_NORMAL, _pause_mode == PM_UNPAUSED, CMD_PAUSE)) {
|
if (DoCommandP(0, PM_PAUSED_NORMAL, _pause_mode == PM_UNPAUSED, CMD_PAUSE)) {
|
||||||
if (_settings_client.sound.confirm) SndPlayFx(SND_15_BEEP);
|
if (_settings_client.sound.confirm) SndPlayFx(SND_15_BEEP);
|
||||||
@@ -2140,7 +2140,7 @@ struct MainToolbarWindow : Window {
|
|||||||
this->SetWidgetDisabledState(WID_TN_GOAL, Goal::GetNumItems() == 0);
|
this->SetWidgetDisabledState(WID_TN_GOAL, Goal::GetNumItems() == 0);
|
||||||
this->SetWidgetDisabledState(WID_TN_STORY, StoryPage::GetNumItems() == 0);
|
this->SetWidgetDisabledState(WID_TN_STORY, StoryPage::GetNumItems() == 0);
|
||||||
|
|
||||||
this->SetWidgetDisabledState(WID_TN_PAUSE, _networking && !(_network_server || _network_settings_access)); // if not server, disable pause button
|
this->SetWidgetDisabledState(WID_TN_PAUSE, IsNonAdminNetworkClient()); // if not server, disable pause button
|
||||||
|
|
||||||
this->DrawWidgets();
|
this->DrawWidgets();
|
||||||
}
|
}
|
||||||
|
@@ -110,7 +110,7 @@ private:
|
|||||||
|
|
||||||
static bool ChangeSettingsDisabled()
|
static bool ChangeSettingsDisabled()
|
||||||
{
|
{
|
||||||
return _networking && !(_network_server || _network_settings_access) &&
|
return IsNonAdminNetworkClient() &&
|
||||||
!(_local_company != COMPANY_SPECTATOR && _settings_game.difficulty.override_town_settings_in_multiplayer);
|
!(_local_company != COMPANY_SPECTATOR && _settings_game.difficulty.override_town_settings_in_multiplayer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -508,7 +508,7 @@ public:
|
|||||||
SetBit(p2, 16);
|
SetBit(p2, 16);
|
||||||
p2 |= (index - 1) << 8;
|
p2 |= (index - 1) << 8;
|
||||||
}
|
}
|
||||||
Commands cmd = (_networking && !(_network_server || _network_settings_access)) ? CMD_TOWN_SETTING_OVERRIDE_NON_ADMIN : CMD_TOWN_SETTING_OVERRIDE;
|
Commands cmd = IsNonAdminNetworkClient() ? CMD_TOWN_SETTING_OVERRIDE_NON_ADMIN : CMD_TOWN_SETTING_OVERRIDE;
|
||||||
DoCommandP(this->town->xy, this->window_number, p2, cmd | CMD_MSG(STR_ERROR_CAN_T_DO_THIS));
|
DoCommandP(this->town->xy, this->window_number, p2, cmd | CMD_MSG(STR_ERROR_CAN_T_DO_THIS));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -575,7 +575,7 @@ public:
|
|||||||
{
|
{
|
||||||
extern const Town *_viewport_highlight_town;
|
extern const Town *_viewport_highlight_town;
|
||||||
this->SetWidgetLoweredState(WID_TV_CATCHMENT, _viewport_highlight_town == this->town);
|
this->SetWidgetLoweredState(WID_TV_CATCHMENT, _viewport_highlight_town == this->town);
|
||||||
this->SetWidgetDisabledState(WID_TV_CHANGE_NAME, _networking && !(_network_server || _network_settings_access) &&
|
this->SetWidgetDisabledState(WID_TV_CHANGE_NAME, IsNonAdminNetworkClient() &&
|
||||||
!(_local_company != COMPANY_SPECTATOR && _settings_game.difficulty.rename_towns_in_multiplayer));
|
!(_local_company != COMPANY_SPECTATOR && _settings_game.difficulty.rename_towns_in_multiplayer));
|
||||||
|
|
||||||
this->DrawWidgets();
|
this->DrawWidgets();
|
||||||
@@ -786,7 +786,7 @@ public:
|
|||||||
{
|
{
|
||||||
if (str == nullptr) return;
|
if (str == nullptr) return;
|
||||||
|
|
||||||
DoCommandP(0, this->window_number, 0, ((_networking && !(_network_server || _network_settings_access)) ? CMD_RENAME_TOWN_NON_ADMIN : CMD_RENAME_TOWN) | CMD_MSG(STR_ERROR_CAN_T_RENAME_TOWN), nullptr, str);
|
DoCommandP(0, this->window_number, 0, (IsNonAdminNetworkClient() ? CMD_RENAME_TOWN_NON_ADMIN : CMD_RENAME_TOWN) | CMD_MSG(STR_ERROR_CAN_T_RENAME_TOWN), nullptr, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsNewGRFInspectable() const override
|
bool IsNewGRFInspectable() const override
|
||||||
|
Reference in New Issue
Block a user