Changeset - r27007:15588a7af43e
[Not reviewed]
master
0 8 0
Rubidium - 21 months ago 2023-03-02 20:22:37
rubidium@openttd.org
Add: deity mode enforcement checks to functions with command or company access

Command functions are those that call ScriptObject::Command, and functions
with company access are any that call ScriptObject::GetCompany. This is a bit
over-protective, but having the check everywhere makes it easier to validate
that no check is missing automatically instead of by review.
8 files changed with 18 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/script/api/script_industry.cpp
Show inline comments
 
@@ -53,6 +53,7 @@
 
{
 
	CCountedPtr<Text> counter(text);
 

	
 
	EnforceDeityMode(false);
 
	EnforcePrecondition(false, IsValidIndustry(industry_id));
 

	
 
	return ScriptObject::Command<CMD_INDUSTRY_SET_TEXT>::Do(industry_id, text != nullptr ? text->GetEncodedText() : std::string{});
 
@@ -268,6 +269,7 @@
 

	
 
/* static */ bool ScriptIndustry::SetExclusiveSupplier(IndustryID industry_id, ScriptCompany::CompanyID company_id)
 
{
 
	EnforceDeityMode(false);
 
	EnforcePrecondition(false, IsValidIndustry(industry_id));
 

	
 
	auto company = ScriptCompany::ResolveCompanyID(company_id);
 
@@ -287,6 +289,7 @@
 

	
 
/* static */ bool ScriptIndustry::SetExclusiveConsumer(IndustryID industry_id, ScriptCompany::CompanyID company_id)
 
{
 
	EnforceDeityMode(false);
 
	EnforcePrecondition(false, IsValidIndustry(industry_id));
 

	
 
	auto company = ScriptCompany::ResolveCompanyID(company_id);
src/script/api/script_industry.hpp
Show inline comments
 
@@ -85,6 +85,7 @@ public:
 
	 * Set the custom text of an industry, shown in the GUI.
 
	 * @param industry_id The industry to set the custom text of.
 
	 * @param text The text to set it to (can be either a raw string, or a ScriptText object). If null, or an empty string, is passed, the text will be removed.
 
	 * @pre ScriptCompanyMode::IsDeity().
 
	 * @pre IsValidIndustry(industry_id).
 
	 * @return True if the action succeeded.
 
	 * @api -ai
 
@@ -286,6 +287,7 @@ public:
 
	 * @param industry_id The index of the industry.
 
	 * @param company_id The company to set (ScriptCompany::COMPANY_INVALID to reset).
 
	 * @pre IsValidIndustry(industry_id).
 
	 * @pre ScriptCompanyMode::IsDeity().
 
	 * @return True if the action succeeded.
 
	 * @api -ai
 
	 */
 
@@ -306,6 +308,7 @@ public:
 
	 * @param industry_id The index of the industry.
 
	 * @param company_id The company to set (ScriptCompany::COMPANY_INVALID to reset).
 
	 * @pre IsValidIndustry(industry_id).
 
	 * @pre ScriptCompanyMode::IsDeity().
 
	 * @return True if the action succeeded.
 
	 * @api -ai
 
	 */
src/script/api/script_news.cpp
Show inline comments
 
@@ -24,6 +24,7 @@
 
{
 
	CCountedPtr<Text> counter(text);
 

	
 
	EnforceDeityMode(false);
 
	EnforcePrecondition(false, text != nullptr);
 
	const std::string &encoded = text->GetEncodedText();
 
	EnforcePreconditionEncodedText(false, encoded);
src/script/api/script_news.hpp
Show inline comments
 
@@ -62,6 +62,7 @@ public:
 
	 * @pre text != null.
 
	 * @pre company == COMPANY_INVALID || ResolveCompanyID(company) != COMPANY_INVALID.
 
	 * @pre The \a reference condition must be fulfilled.
 
	 * @pre ScriptCompanyMode::IsDeity().
 
	 */
 
	static bool Create(NewsType type, Text *text, ScriptCompany::CompanyID company, NewsReferenceType ref_type, SQInteger reference);
 
};
src/script/api/script_subsidy.cpp
Show inline comments
 
@@ -33,6 +33,7 @@
 

	
 
/* static */ bool ScriptSubsidy::Create(CargoID cargo_type, SubsidyParticipantType from_type, SQInteger from_id, SubsidyParticipantType to_type, SQInteger to_id)
 
{
 
	EnforceDeityMode(false);
 
	EnforcePrecondition(false, ScriptCargo::IsValidCargo(cargo_type));
 
	EnforcePrecondition(false, from_type == SPT_INDUSTRY || from_type == SPT_TOWN);
 
	EnforcePrecondition(false, to_type == SPT_INDUSTRY || to_type == SPT_TOWN);
src/script/api/script_subsidy.hpp
Show inline comments
 
@@ -55,6 +55,7 @@ public:
 
	 * @param to_type The type of the subsidy on the 'to' side.
 
	 * @param to_id The ID of the 'to' side.
 
	 * @return True if the action succeeded.
 
	 * @pre ScriptCompanyMode::IsDeity().
 
	 * @pre ScriptCargo::IsValidCargo(cargo_type)
 
	 * @pre from_type == SPT_INDUSTRY || from_type == SPT_TOWN.
 
	 * @pre to_type   == SPT_INDUSTRY || to_type   == SPT_TOWN.
src/script/api/script_town.cpp
Show inline comments
 
@@ -44,6 +44,7 @@
 
{
 
	CCountedPtr<Text> counter(name);
 

	
 
	EnforceDeityMode(false);
 
	EnforcePrecondition(false, IsValidTown(town_id));
 
	std::string text;
 
	if (name != nullptr) {
 
@@ -58,6 +59,7 @@
 
{
 
	CCountedPtr<Text> counter(text);
 

	
 
	EnforceDeityMode(false);
 
	EnforcePrecondition(false, IsValidTown(town_id));
 

	
 
	return ScriptObject::Command<CMD_TOWN_SET_TEXT>::Do(town_id, text != nullptr ? text->GetEncodedText() : std::string{});
 
@@ -125,6 +127,7 @@
 

	
 
/* static */ bool ScriptTown::SetCargoGoal(TownID town_id, ScriptCargo::TownEffect towneffect_id, SQInteger goal)
 
{
 
	EnforceDeityMode(false);
 
	EnforcePrecondition(false, IsValidTown(town_id));
 
	EnforcePrecondition(false, ScriptCargo::IsValidTownEffect(towneffect_id));
 

	
 
@@ -155,6 +158,7 @@
 

	
 
/* static */ bool ScriptTown::SetGrowthRate(TownID town_id, SQInteger days_between_town_growth)
 
{
 
	EnforceDeityMode(false);
 
	EnforcePrecondition(false, IsValidTown(town_id));
 
	uint16 growth_rate;
 
	switch (days_between_town_growth) {
src/script/api/script_town.hpp
Show inline comments
 
@@ -149,6 +149,7 @@ public:
 
	 * @param town_id The town to rename
 
	 * @param name The new name of the town. If null, or an empty string, is passed, the town name will be reset to the default name.
 
	 * @pre IsValidTown(town_id).
 
	 * @pre ScriptCompanyMode::IsDeity().
 
	 * @return True if the action succeeded.
 
	 * @api -ai
 
	 */
 
@@ -159,6 +160,7 @@ public:
 
	 * @param town_id The town to set the custom text of.
 
	 * @param text The text to set it to (can be either a raw string, or a ScriptText object). If null, or an empty string, is passed, the text will be removed.
 
	 * @pre IsValidTown(town_id).
 
	 * @pre ScriptCompanyMode::IsDeity().
 
	 * @return True if the action succeeded.
 
	 * @api -ai
 
	 */
 
@@ -236,6 +238,7 @@ public:
 
	 *             The value will be clamped to 0 .. MAX(uint32).
 
	 * @pre IsValidTown(town_id).
 
	 * @pre ScriptCargo::IsValidTownEffect(towneffect_id).
 
	 * @pre ScriptCompanyMode::IsDeity().
 
	 * @return True if the action succeeded.
 
	 * @api -ai
 
	 */
 
@@ -392,6 +395,7 @@ public:
 
	 *               The value will be clamped to 0 .. MAX(uint32).
 
	 * @pre IsValidTown(town_id).
 
	 * @pre houses > 0.
 
	 * @pre ScriptCompanyMode::IsDeity().
 
	 * @return True if the action succeeded.
 
	 * @api -ai
 
	 */
0 comments (0 inline, 0 general)