Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions doc/luanti.6
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,17 @@ Display an interactive terminal over ncurses during execution.

.SH ENVIRONMENT VARIABLES
.TP
.B MINETEST_GAME_PATH
Colon delimited list of directories to search for games
.B LUANTI_GAME_PATH
Colon delimited list of directories to search for games. This should
be used instead of \fBMINETEST_GAME_PATH\fP, which is deprecated.

.TP
.B MINETEST_MOD_PATH
Colon delimited list of directories to search for mods
.B LUANTI_MOD_PATH
Colon delimited list of directories to search for mods. This should be
used instead of \fBMINETEST_MOD_PATH\fP, which is deprecated.

.TP
.B MINETEST_USER_PATH
.B LUANTI_USER_PATH
Path to Luanti user data directory (only on RUN_IN_PLACE=0 build)
.TP
.B LOG_TIMESTAMP
Expand Down
2 changes: 1 addition & 1 deletion doc/world_format.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ For `load_mod_<mod>`, the possible values are:
* Must be one of the following:
* `mods/`: mods in the user path's mods folder (ex. `/home/user/.minetest/mods`)
* `share/`: mods in the share's mods folder (ex. `/usr/share/minetest/mods`)
* `/path/to/env`: you can use absolute paths to mods inside folders specified with the `MINETEST_MOD_PATH` `env` variable.
* `/path/to/env`: you can use absolute paths to mods inside folders specified with the `LUANTI_MOD_PATH` `env` variable.
* Other locations and absolute paths are not supported.
* Note that `moddir` is the directory name, not the mod name specified in mod.conf.

Expand Down
67 changes: 50 additions & 17 deletions src/content/subgames.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,26 @@ struct GameFindPath
std::string getSubgamePathEnv()
{
static bool has_warned = false;
char *subgame_path = getenv("MINETEST_SUBGAME_PATH");
if (subgame_path && !has_warned) {
warningstream << "MINETEST_SUBGAME_PATH is deprecated, use MINETEST_GAME_PATH instead."
<< std::endl;
has_warned = true;
}

char *game_path = getenv("MINETEST_GAME_PATH");
if (const char *path = getenv("LUANTI_GAME_PATH"))
return std::string(path);

if (game_path)
return std::string(game_path);
else if (subgame_path)
return std::string(subgame_path);
if (const char *path = getenv("MINETEST_GAME_PATH")) {
if (!has_warned) {
warningstream << "MINETEST_GAME_PATH is deprecated, use LUANTI_GAME_PATH instead."
<< std::endl;
has_warned = true;
}
return std::string(path);
}
if (const char *path = getenv("MINETEST_SUBGAME_PATH")) {
if (!has_warned) {
warningstream << "MINETEST_SUBGAME_PATH is deprecated, use LUANTI_GAME_PATH instead."
<< std::endl;
has_warned = true;
}
return std::string(path);
}
return "";
}

Expand Down Expand Up @@ -279,8 +286,20 @@ std::string getWorldGameId(const std::string &world_path, bool can_be_legacy)

std::string getWorldPathEnv()
{
char *world_path = getenv("MINETEST_WORLD_PATH");
return world_path ? std::string(world_path) : "";
static bool has_warned = false;

if (const char *path = getenv("LUANTI_WORLD_PATH"))
return std::string(path);

if (const char *path = getenv("MINETEST_WORLD_PATH")) {
if (!has_warned) {
warningstream << "MINETEST_WORLD_PATH is deprecated, use LUANTI_WORLD_PATH instead."
<< std::endl;
has_warned = true;
}
return std::string(path);
}
return "";
}

std::vector<WorldSpec> getAvailableWorlds()
Expand Down Expand Up @@ -413,10 +432,24 @@ void loadGameConfAndInitWorld(const std::string &path, const std::string &name,

std::vector<std::string> getEnvModPaths()
{
const char *c_mod_path = getenv("MINETEST_MOD_PATH");
static bool has_warned = false;

std::vector<std::string> paths;
Strfnd search_paths(c_mod_path ? c_mod_path : "");
while (!search_paths.at_end())
paths.push_back(search_paths.next(PATH_DELIM));
const char *c_mod_path = nullptr;
if ((c_mod_path = getenv("LUANTI_MOD_PATH"))) {
// no-op
} else if ((c_mod_path = getenv("MINETEST_MOD_PATH"))) {
if (!has_warned) {
warningstream << "MINETEST_MOD_PATH is deprecated, use LUANTI_MOD_PATH instead."
<< std::endl;
has_warned = true;
}
}

if (c_mod_path) {
Strfnd search_paths(c_mod_path);
while (!search_paths.at_end())
paths.push_back(search_paths.next(PATH_DELIM));
}
return paths;
}
2 changes: 1 addition & 1 deletion src/content/subgames.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ SubgameSpec findWorldSubgame(const std::string &world_path);

std::set<std::string> getAvailableGameIds();
std::vector<SubgameSpec> getAvailableGames();
// Get the list of paths to mods in the environment variable $MINETEST_MOD_PATH
// Get the list of paths to mods in the environment variable LUANTI_MOD_PATH
std::vector<std::string> getEnvModPaths();

bool getWorldExists(const std::string &world_path);
Expand Down
53 changes: 41 additions & 12 deletions src/porting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#include <csignal>
#include <cstdarg>
#include <cstdio>
#include <optional>
#include <signal.h>
#include <atomic>

Expand Down Expand Up @@ -153,6 +154,24 @@ void signal_handler_init(void)

#endif

/*
Environment variables
*/

static std::optional<std::string> getUserPathEnvVar()
{
if (const char *user_path = getenv("LUANTI_USER_PATH");
user_path && *user_path) {
return user_path;
}
if (const char *user_path = getenv("MINETEST_USER_PATH");
user_path && *user_path) {
warningstream << "MINETEST_USER_PATH is deprecated, "
<< "use LUANTI_USER_PATH instead." << std::endl;
return user_path;
}
return std::nullopt;
}

/*
Path mangler
Expand Down Expand Up @@ -464,9 +483,17 @@ bool setSystemPaths()
path_share += DIR_DELIM "..";
}

// Use %MINETEST_USER_PATH%
DWORD len = GetEnvironmentVariable("MINETEST_USER_PATH", buf, sizeof(buf));
FATAL_ERROR_IF(len > sizeof(buf), "Failed to get MINETEST_USER_PATH (too large for buffer)");
// Use %LUANTI_USER_PATH%
DWORD len = GetEnvironmentVariable("LUANTI_USER_PATH", buf, sizeof(buf));
if (!len) {
len = GetEnvironmentVariable("MINETEST_USER_PATH", buf, sizeof(buf));
if (len) {
warningstream << "MINETEST_USER_PATH is deprecated, "
<< "use LUANTI_USER_PATH instead." << std::endl;
}
}

FATAL_ERROR_IF(len >= sizeof(buf), "Failed to get LUANTI_USER_PATH (too large for buffer)");
if (len == 0) {
// Use "C:\Users\<user>\AppData\Roaming\<PROJECT_NAME_C>"
len = GetEnvironmentVariable("APPDATA", buf, sizeof(buf));
Expand Down Expand Up @@ -532,9 +559,9 @@ bool setSystemPaths()
break;
}

const char *const env_user_path = getenv("MINETEST_USER_PATH");
if (env_user_path && env_user_path[0] != '\0') {
path_user = std::string(env_user_path);
auto user_path_env = getUserPathEnvVar();
if (user_path_env) {
path_user = std::move(user_path_env.value());
} else {
// TODO: luanti with migration
path_user = std::string(getHomeOrFail()) + DIR_DELIM "." "minetest";
Expand All @@ -552,6 +579,7 @@ bool setSystemPaths()
CFBundleRef main_bundle = CFBundleGetMainBundle();
CFURLRef resources_url = CFBundleCopyResourcesDirectoryURL(main_bundle);
char path[PATH_MAX];

if (CFURLGetFileSystemRepresentation(resources_url,
TRUE, (UInt8 *)path, PATH_MAX)) {
path_share = std::string(path);
Expand All @@ -560,9 +588,9 @@ bool setSystemPaths()
}
CFRelease(resources_url);

const char *const env_user_path = getenv("MINETEST_USER_PATH");
if (env_user_path && env_user_path[0] != '\0') {
path_user = std::string(env_user_path);
auto user_path_env = getUserPathEnvVar();
if (user_path_env) {
path_user = std::move(user_path_env.value());
} else {
// TODO: luanti with migration
path_user = std::string(getHomeOrFail())
Expand All @@ -577,9 +605,10 @@ bool setSystemPaths()
bool setSystemPaths()
{
path_share = STATIC_SHAREDIR;
const char *const env_user_path = getenv("MINETEST_USER_PATH");
if (env_user_path && env_user_path[0] != '\0') {
path_user = std::string(env_user_path);

auto user_path_env = getUserPathEnvVar();
if (user_path_env) {
path_user = std::move(user_path_env.value());
} else {
// TODO: luanti with migration
path_user = std::string(getHomeOrFail()) + DIR_DELIM "." "minetest";
Expand Down
6 changes: 3 additions & 3 deletions src/unittest/test_servermodmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void TestServerModManager::runTests(IGameDef *gamedef)
ofs2 << "-- intentionally empty\n";
}

setenv("MINETEST_MOD_PATH", test_mods.c_str(), 1);
setenv("LUANTI_MOD_PATH", test_mods.c_str(), 1);

m_worlddir = getTestTempDirectory().append(DIR_DELIM "world");
fs::CreateDir(m_worlddir);
Expand All @@ -71,9 +71,9 @@ void TestServerModManager::runTests(IGameDef *gamedef)
TEST(testGetModNames);
TEST(testGetModMediaPathsWrongDir);
TEST(testGetModMediaPaths);
// TODO: test MINETEST_GAME_PATH
// TODO: test LUANTI_GAME_PATH

unsetenv("MINETEST_MOD_PATH");
unsetenv("LUANTI_MOD_PATH");
}

void TestServerModManager::testCreation()
Expand Down
Loading