1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-23 15:52:55 +01:00

Close #11614: Require plugins to specify their license

This commit is contained in:
Tulio Leao
2020-06-19 11:14:33 -03:00
committed by GitHub
parent d66c61ca08
commit 6a8d9007e2
4 changed files with 13 additions and 0 deletions

View File

@@ -108,6 +108,7 @@ declare global {
version: string;
authors: string | string[];
type: PluginType;
licence: string;
minApiVersion?: number;
main: () => void;
}

View File

@@ -18,6 +18,8 @@ Local scripts can **not** alter the game state. This allows each player to enabl
Remote scripts on the other hand can alter the game state in certain contexts, thus must be enabled for every player in a multiplayer game. Players **cannot** enable or disable remote scripts for multiplayer servers they join. Instead the server will upload any remote scripts that have been enabled on the server to each player. This allows servers to enable scripts without players needing to manually download or enable the same script on their end.
The authors must also define a licence for the plug-in, making it clear to the community whether that plug-in can be altered, copied, etc. A good reference material is listed on [ChooseALlicense](https://choosealicense.com/appendix/), try to pick one of them and use its corresponding identifier, as listed on [SPDX](https://spdx.org/licenses/).
## Writing Scripts
Scripts are written in ECMAScript 5 compatible JavaScript. OpenRCT2 currently uses the [duktape](https://duktape.org) library to execute scripts. This however does not mean you need to write your plug-in in JavaScript, there are many transpilers that allow you to write in a language of your choice and then compile it to JavaScript allowing it to be executed by OpenRCT2. JavaScript or [TypeScript](https://www.typescriptlang.org) is recommended however, as that will allow you to utilise the type definition file we supply (`openrct2.d.ts`). If you would like to use ECMAScript 6 or later which contain features such as the `let` keyword or classes, then you will need to use a transpiler such as [Babel](https://babeljs.io) or [TypeScript](https://www.typescriptlang.org).
@@ -38,6 +40,7 @@ registerPlugin({
version: '1.0',
authors: ['Your Name'],
type: 'remote',
licence: 'MIT',
main: main
});
```

View File

@@ -11,6 +11,7 @@
# include "Plugin.h"
# include "../Diagnostic.h"
# include "../OpenRCT2.h"
# include "Duktape.hpp"
@@ -127,6 +128,7 @@ PluginMetadata Plugin::GetMetadata(const DukValue& dukMetadata)
metadata.Name = TryGetString(dukMetadata["name"], "Plugin name not specified.");
metadata.Version = TryGetString(dukMetadata["version"], "Plugin version not specified.");
metadata.Type = ParsePluginType(TryGetString(dukMetadata["type"], "Plugin type not specified."));
CheckForLicence(dukMetadata["licence"], metadata.Name);
auto dukMinApiVersion = dukMetadata["minApiVersion"];
if (dukMinApiVersion.type() == DukValue::Type::NUMBER)
@@ -161,4 +163,10 @@ PluginType Plugin::ParsePluginType(const std::string_view& type)
throw std::invalid_argument("Unknown plugin type.");
}
void Plugin::CheckForLicence(const DukValue& dukLicence, const std::string_view& pluginName)
{
if (dukLicence.type() != DukValue::Type::STRING || dukLicence.as_string().empty())
log_error("Plugin %s does not specify a licence", pluginName.data());
}
#endif

View File

@@ -95,6 +95,7 @@ namespace OpenRCT2::Scripting
static PluginMetadata GetMetadata(const DukValue& dukMetadata);
static PluginType ParsePluginType(const std::string_view& type);
static void CheckForLicence(const DukValue& dukLicence, const std::string_view& pluginName);
};
} // namespace OpenRCT2::Scripting