diff options
author | Perttu Ahola <celeron55@gmail.com> | 2012-03-10 15:56:24 +0200 |
---|---|---|
committer | Perttu Ahola <celeron55@gmail.com> | 2012-03-10 17:10:10 +0200 |
commit | c89d1cf072f4ac34cfb35eadd8c9890b3de1b922 (patch) | |
tree | 710e2764b126d6de0c528d531d24ad1653a682d2 /src | |
parent | 9c5e422d3a5fc3784d261a1effdb94a44b84a41c (diff) | |
download | minetest-c89d1cf072f4ac34cfb35eadd8c9890b3de1b922.tar.gz minetest-c89d1cf072f4ac34cfb35eadd8c9890b3de1b922.tar.bz2 minetest-c89d1cf072f4ac34cfb35eadd8c9890b3de1b922.zip |
Initial directory structure rework
Diffstat (limited to 'src')
-rw-r--r-- | src/client.cpp | 2 | ||||
-rw-r--r-- | src/game.cpp | 2 | ||||
-rw-r--r-- | src/guiPauseMenu.cpp | 4 | ||||
-rw-r--r-- | src/main.cpp | 28 | ||||
-rw-r--r-- | src/porting.cpp | 61 | ||||
-rw-r--r-- | src/porting.h | 6 | ||||
-rw-r--r-- | src/server.cpp | 65 | ||||
-rw-r--r-- | src/server.h | 24 | ||||
-rw-r--r-- | src/servermain.cpp | 38 | ||||
-rw-r--r-- | src/tile.cpp | 7 |
10 files changed, 136 insertions, 101 deletions
diff --git a/src/client.cpp b/src/client.cpp index bc303bc4b..72cd28b18 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -40,7 +40,7 @@ with this program; if not, write to the Free Software Foundation, Inc., static std::string getTextureCacheDir() { - return porting::path_userdata + DIR_DELIM + "cache" + DIR_DELIM + "texture"; + return porting::path_user + DIR_DELIM + "cache" + DIR_DELIM + "textures"; } struct TextureRequest diff --git a/src/game.cpp b/src/game.cpp index a69942e61..0d09e335e 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -726,7 +726,7 @@ void the_game( if(address == ""){ draw_load_screen(L"Creating server...", driver, font); infostream<<"Creating server"<<std::endl; - server = new Server(map_dir, configpath); + server = new Server(map_dir, configpath, "mesetint"); server->start(port); } diff --git a/src/guiPauseMenu.cpp b/src/guiPauseMenu.cpp index 3cd572387..3b1861b3d 100644 --- a/src/guiPauseMenu.cpp +++ b/src/guiPauseMenu.cpp @@ -174,7 +174,7 @@ void GUIPauseMenu::regenerateGui(v2u32 screensize) SWPRINTF_CHARSTRING
,
BUILD_INFO,
- porting::path_userdata.c_str()
+ porting::path_user.c_str()
);*/
std::ostringstream os;
@@ -182,7 +182,7 @@ void GUIPauseMenu::regenerateGui(v2u32 screensize) os<<"by Perttu Ahola and contributors\n";
os<<"celeron55@gmail.com\n";
os<<BUILD_INFO<<"\n";
- os<<"ud_path = "<<wrap_rows(porting::path_userdata, 20)<<"\n";
+ os<<"path_user = "<<wrap_rows(porting::path_user, 20)<<"\n";
Environment->addStaticText(narrow_to_wide(os.str()).c_str(), rect, false, true, this, 259);
}
diff --git a/src/main.cpp b/src/main.cpp index ec999c530..322d84e9e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1157,19 +1157,18 @@ int main(int argc, char *argv[]) porting::signal_handler_init(); bool &kill = *porting::signal_handler_killstatus(); - // Initialize porting::path_data and porting::path_userdata porting::initializePaths(); // Create user data directory - fs::CreateDir(porting::path_userdata); + fs::CreateDir(porting::path_user); - init_gettext((porting::path_data+DIR_DELIM+".."+DIR_DELIM+"locale").c_str()); + init_gettext((porting::path_share+DIR_DELIM+".."+DIR_DELIM+"locale").c_str()); // Initialize debug streams #ifdef RUN_IN_PLACE std::string debugfile = DEBUGFILE; #else - std::string debugfile = porting::path_userdata+DIR_DELIM+DEBUGFILE; + std::string debugfile = porting::path_user+DIR_DELIM+DEBUGFILE; #endif debugstreams_init(disable_stderr, debugfile.c_str()); // Initialize debug stacks @@ -1221,10 +1220,12 @@ int main(int argc, char *argv[]) else { core::array<std::string> filenames; - filenames.push_back(porting::path_userdata + + filenames.push_back(porting::path_user + DIR_DELIM + "minetest.conf"); #ifdef RUN_IN_PLACE - filenames.push_back(porting::path_userdata + + // Try also from a lower level (to aid having the same configuration + // for many RUN_IN_PLACE installs) + filenames.push_back(porting::path_user + DIR_DELIM + ".." + DIR_DELIM + "minetest.conf"); #endif @@ -1278,11 +1279,22 @@ int main(int argc, char *argv[]) port = 30000; // Map directory - std::string map_dir = porting::path_userdata+DIR_DELIM+"world"; + std::string map_dir = porting::path_user + DIR_DELIM + "server" + DIR_DELIM + "worlds" + DIR_DELIM + "world"; if(cmd_args.exists("map-dir")) map_dir = cmd_args.get("map-dir"); else if(g_settings->exists("map-dir")) map_dir = g_settings->get("map-dir"); + else{ + // No map-dir option was specified. + // Check if the world is found from the default directory, and if + // not, see if the legacy world directory exists. + std::string legacy_map_dir = porting::path_user+DIR_DELIM+".."+DIR_DELIM+"world"; + if(!fs::PathExists(map_dir) && fs::PathExists(legacy_map_dir)){ + errorstream<<"Warning: Using legacy world directory \"" + <<legacy_map_dir<<"\""<<std::endl; + map_dir = legacy_map_dir; + } + } // Run dedicated server if asked to if(cmd_args.getFlag("server")) @@ -1293,7 +1305,7 @@ int main(int argc, char *argv[]) g_timegetter = new SimpleTimeGetter(); // Create server - Server server(map_dir.c_str(), configpath); + Server server(map_dir, configpath, "mesetint"); server.start(port); // Run server diff --git a/src/porting.cpp b/src/porting.cpp index 0adc955a9..edf950635 100644 --- a/src/porting.cpp +++ b/src/porting.cpp @@ -124,12 +124,12 @@ void signal_handler_init(void) Path mangler */ -std::string path_data = ".." DIR_DELIM "data"; -std::string path_userdata = ".."; +std::string path_share = ".." DIR_DELIM "share"; +std::string path_user = ".." DIR_DELIM "user"; std::string getDataPath(const char *subpath) { - return path_data + DIR_DELIM + subpath; + return path_share + DIR_DELIM + subpath; } void pathRemoveFile(char *path, char delim) @@ -163,16 +163,13 @@ void initializePaths() char buf[buflen]; DWORD len; - // Find path of executable and set path_data relative to it + // Find path of executable and set path_share relative to it len = GetModuleFileName(GetModuleHandle(NULL), buf, buflen); assert(len < buflen); pathRemoveFile(buf, '\\'); - // Use "./bin/../data" - path_data = std::string(buf) + DIR_DELIM ".." DIR_DELIM "data"; - - // Use "./bin/.." - path_userdata = std::string(buf) + DIR_DELIM ".."; + path_share = std::string(buf) + "\\..\\share"; + path_user = std::string(buf) + "\\..\\user"; /* Linux @@ -187,11 +184,8 @@ void initializePaths() pathRemoveFile(buf, '/'); - // Use "./bin/../data" - path_data = std::string(buf) + "/../data"; - - // Use "./bin/../" - path_userdata = std::string(buf) + "/.."; + path_share = std::string(buf) + "/../share"; + path_user = std::string(buf) + "/../user"; /* OS X @@ -201,8 +195,8 @@ void initializePaths() //TODO: Get path of executable. This assumes working directory is bin/ dstream<<"WARNING: Relative path not properly supported on OS X and FreeBSD" <<std::endl; - path_data = std::string("../data"); - path_userdata = std::string(".."); + path_share = std::string("../share"); + path_user = std::string("../user"); #endif @@ -224,19 +218,18 @@ void initializePaths() char buf[buflen]; DWORD len; - // Find path of executable and set path_data relative to it + // Find path of executable and set path_share relative to it len = GetModuleFileName(GetModuleHandle(NULL), buf, buflen); assert(len < buflen); pathRemoveFile(buf, '\\'); - // Use "./bin/../data" - path_data = std::string(buf) + DIR_DELIM ".." DIR_DELIM "data"; - //path_data = std::string(buf) + "/../share/" + PROJECT_NAME; + // Use ".\bin\..\share" + path_share = std::string(buf) + "\\..\\share"; // Use "C:\Documents and Settings\user\Application Data\<PROJECT_NAME>" len = GetEnvironmentVariable("APPDATA", buf, buflen); assert(len < buflen); - path_userdata = std::string(buf) + DIR_DELIM + PROJECT_NAME; + path_user = std::string(buf) + DIR_DELIM + PROJECT_NAME; /* Linux @@ -251,15 +244,15 @@ void initializePaths() pathRemoveFile(buf, '/'); - path_data = std::string(buf) + "/../share/" + PROJECT_NAME; - //path_data = std::string(INSTALL_PREFIX) + "/share/" + PROJECT_NAME; - if (!fs::PathExists(path_data)) { - dstream<<"WARNING: data path " << path_data << " not found!"; - path_data = std::string(buf) + "/../data"; - dstream<<" Trying " << path_data << std::endl; + path_share = std::string(buf) + "/../share/" + PROJECT_NAME; + //path_share = std::string(INSTALL_PREFIX) + "/share/" + PROJECT_NAME; + if (!fs::PathExists(path_share)) { + dstream<<"WARNING: data path " << path_share << " not found!"; + path_share = std::string(buf) + "/../data"; + dstream<<" Trying " << path_share << std::endl; } - path_userdata = std::string(getenv("HOME")) + "/." + PROJECT_NAME; + path_user = std::string(getenv("HOME")) + "/." + PROJECT_NAME; /* OS X @@ -276,7 +269,7 @@ void initializePaths() { dstream<<"Bundle resource path: "<<path<<std::endl; //chdir(path); - path_data = std::string(path) + "/data"; + path_share = std::string(path) + "/share"; } else { @@ -285,19 +278,19 @@ void initializePaths() } CFRelease(resources_url); - path_userdata = std::string(getenv("HOME")) + "/Library/Application Support/" + PROJECT_NAME; + path_user = std::string(getenv("HOME")) + "/Library/Application Support/" + PROJECT_NAME; #elif defined(__FreeBSD__) - path_data = std::string(INSTALL_PREFIX) + "/share/" + PROJECT_NAME; - path_userdata = std::string(getenv("HOME")) + "/." + PROJECT_NAME; + path_share = std::string(INSTALL_PREFIX) + "/share/" + PROJECT_NAME; + path_user = std::string(getenv("HOME")) + "/." + PROJECT_NAME; #endif #endif // RUN_IN_PLACE - dstream<<"path_data = "<<path_data<<std::endl; - dstream<<"path_userdata = "<<path_userdata<<std::endl; + dstream<<"path_share = "<<path_share<<std::endl; + dstream<<"path_user = "<<path_user<<std::endl; } } //namespace porting diff --git a/src/porting.h b/src/porting.h index 4970a8478..05a6ae0c4 100644 --- a/src/porting.h +++ b/src/porting.h @@ -59,7 +59,7 @@ bool * signal_handler_killstatus(void); /* Path of static data directory. */ -extern std::string path_data; +extern std::string path_share; /* Directory for storing user data. Examples: @@ -67,7 +67,7 @@ extern std::string path_data; Linux: "~/.<PROJECT_NAME>" Mac: "~/Library/Application Support/<PROJECT_NAME>" */ -extern std::string path_userdata; +extern std::string path_user; /* Get full path of stuff in data directory. @@ -76,7 +76,7 @@ extern std::string path_userdata; std::string getDataPath(const char *subpath); /* - Initialize path_data and path_userdata. + Initialize path_share and path_user. */ void initializePaths(); diff --git a/src/server.cpp b/src/server.cpp index 899624633..69f655e6a 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -843,13 +843,17 @@ u32 PIChecksum(core::list<PlayerInfo> &l) */ Server::Server( - std::string mapsavedir, - std::string configpath + std::string path_world, + std::string path_config, + std::string gamename ): + m_gamename(gamename), + m_path_world(path_world), + m_path_config(path_config), m_env(NULL), m_con(PROTOCOL_ID, 512, CONNECTION_TIMEOUT, this), - m_authmanager(mapsavedir+DIR_DELIM+"auth.txt"), - m_banmanager(mapsavedir+DIR_DELIM+"ipban.txt"), + m_authmanager(path_world+DIR_DELIM+"auth.txt"), + m_banmanager(path_world+DIR_DELIM+"ipban.txt"), m_lua(NULL), m_itemdef(createItemDefManager()), m_nodedef(createNodeDefManager()), @@ -859,12 +863,15 @@ Server::Server( m_time_counter(0), m_time_of_day_send_timer(0), m_uptime(0), - m_mapsavedir(mapsavedir), - m_configpath(configpath), m_shutdown_requested(false), m_ignore_map_edit_events(false), m_ignore_map_edit_events_peer_id(0) { + infostream<<"Server created."<<std::endl; + infostream<<"- path_world = "<<path_world<<std::endl; + infostream<<"- path_config = "<<path_config<<std::endl; + infostream<<"- gamename = "<<gamename<<std::endl; + m_liquid_transform_timer = 0.0; m_print_info_timer = 0.0; m_objectdata_timer = 0.0; @@ -876,27 +883,35 @@ Server::Server( m_step_dtime_mutex.Init(); m_step_dtime = 0.0; - JMutexAutoLock envlock(m_env_mutex); - JMutexAutoLock conlock(m_con_mutex); + // Figure out some paths + m_path_share = porting::path_share + DIR_DELIM + "server"; + m_path_game = m_path_share + DIR_DELIM + "games" + DIR_DELIM + m_gamename; // Path to builtin.lua - std::string builtinpath = porting::path_data + DIR_DELIM + "builtin.lua"; + std::string builtinpath = m_path_share + DIR_DELIM + "builtin.lua"; // Add default global mod search path - m_modspaths.push_front(porting::path_data + DIR_DELIM + "mods"); + m_modspaths.push_front(m_path_game + DIR_DELIM "mods"); // Add world mod search path - m_modspaths.push_front(mapsavedir + DIR_DELIM + "worldmods"); - // Add user mod search path - m_modspaths.push_front(porting::path_userdata + DIR_DELIM + "usermods"); + m_modspaths.push_front(m_path_world + DIR_DELIM + "worldmods"); + // Add addon mod search path + for(std::set<std::string>::const_iterator i = m_path_addons.begin(); + i != m_path_addons.end(); i++){ + m_modspaths.push_front((*i) + DIR_DELIM + "mods"); + } // Print out mod search paths - infostream<<"Mod search paths:"<<std::endl; + infostream<<"- mod search paths:"<<std::endl; for(core::list<std::string>::Iterator i = m_modspaths.begin(); i != m_modspaths.end(); i++){ std::string modspath = *i; infostream<<" "<<modspath<<std::endl; } + // Lock environment + JMutexAutoLock envlock(m_env_mutex); + JMutexAutoLock conlock(m_con_mutex); + // Initialize scripting infostream<<"Server: Initializing scripting"<<std::endl; @@ -936,7 +951,7 @@ Server::Server( // Initialize Environment - m_env = new ServerEnvironment(new ServerMap(mapsavedir, this), m_lua, + m_env = new ServerEnvironment(new ServerMap(path_world, this), m_lua, this, this); // Give environment reference to scripting api @@ -946,15 +961,15 @@ Server::Server( m_env->getMap().addEventReceiver(this); // If file exists, load environment metadata - if(fs::PathExists(m_mapsavedir+DIR_DELIM+"env_meta.txt")) + if(fs::PathExists(m_path_world+DIR_DELIM+"env_meta.txt")) { infostream<<"Server: Loading environment metadata"<<std::endl; - m_env->loadMeta(m_mapsavedir); + m_env->loadMeta(m_path_world); } // Load players infostream<<"Server: Loading players"<<std::endl; - m_env->deSerializePlayers(m_mapsavedir); + m_env->deSerializePlayers(m_path_world); /* Add some test ActiveBlockModifiers to environment @@ -1002,13 +1017,13 @@ Server::~Server() Save players */ infostream<<"Server: Saving players"<<std::endl; - m_env->serializePlayers(m_mapsavedir); + m_env->serializePlayers(m_path_world); /* Save environment metadata */ infostream<<"Server: Saving environment metadata"<<std::endl; - m_env->saveMeta(m_mapsavedir); + m_env->saveMeta(m_path_world); } /* @@ -1065,7 +1080,7 @@ void Server::start(unsigned short port) m_thread.setRun(true); m_thread.Start(); - infostream<<"Server: Started on port "<<port<<std::endl; + infostream<<"Server started on port "<<port<<"."<<std::endl; } void Server::stop() @@ -1803,10 +1818,10 @@ void Server::AsyncRunStep() m_env->getMap().save(MOD_STATE_WRITE_NEEDED); // Save players - m_env->serializePlayers(m_mapsavedir); + m_env->serializePlayers(m_path_world); // Save environment metadata - m_env->saveMeta(m_mapsavedir); + m_env->saveMeta(m_path_world); } } } @@ -4110,8 +4125,8 @@ void Server::setPlayerPassword(const std::string &name, const std::wstring &pass // Saves g_settings to configpath given at initialization void Server::saveConfig() { - if(m_configpath != "") - g_settings->updateConfigFile(m_configpath.c_str()); + if(m_path_config != "") + g_settings->updateConfigFile(m_path_config.c_str()); } void Server::notifyPlayer(const char *name, const std::wstring msg) diff --git a/src/server.h b/src/server.h index 04bd61a87..50cd5b285 100644 --- a/src/server.h +++ b/src/server.h @@ -392,6 +392,7 @@ public: */ Server( + std::string gamename, std::string mapsavedir, std::string configpath ); @@ -526,7 +527,7 @@ public: const ModSpec* getModSpec(const std::string &modname); - std::string getWorldPath(){ return m_mapsavedir; } + std::string getWorldPath(){ return m_path_world; } private: @@ -631,6 +632,21 @@ private: Variables */ + // Game name + std::string m_gamename; + // World directory + std::string m_path_world; + // Path to user's configuration file ("" = no configuration file) + std::string m_path_config; + + // Equivalent of /usr/share/minetest/server + std::string m_path_share; + // Equivalent of /usr/share/minetest/server/games/gamename + std::string m_path_game; + // Equivalent of /usr/share/minetest/server/addons/gamename + // and ~/.minetest/server/addons/gamename + std::set<std::string> m_path_addons; + // Some timers float m_liquid_transform_timer; float m_print_info_timer; @@ -724,12 +740,6 @@ private: /* Random stuff */ - - // Map directory - std::string m_mapsavedir; - - // Configuration path ("" = no configuration file) - std::string m_configpath; // Mod parent directory paths core::list<std::string> m_modspaths; diff --git a/src/servermain.cpp b/src/servermain.cpp index 4194faaaa..5eb5162ae 100644 --- a/src/servermain.cpp +++ b/src/servermain.cpp @@ -163,17 +163,16 @@ int main(int argc, char *argv[]) porting::signal_handler_init(); bool &kill = *porting::signal_handler_killstatus(); - // Initialize porting::path_data and porting::path_userdata porting::initializePaths(); // Create user data directory - fs::CreateDir(porting::path_userdata); + fs::CreateDir(porting::path_user); // Initialize debug streams #ifdef RUN_IN_PLACE std::string debugfile = DEBUGFILE; #else - std::string debugfile = porting::path_userdata+DIR_DELIM+DEBUGFILE; + std::string debugfile = porting::path_user+DIR_DELIM+DEBUGFILE; #endif debugstreams_init(disable_stderr, debugfile.c_str()); // Initialize debug stacks @@ -283,10 +282,12 @@ int main(int argc, char *argv[]) else { core::array<std::string> filenames; - filenames.push_back(porting::path_userdata + + filenames.push_back(porting::path_user + DIR_DELIM + "minetest.conf"); #ifdef RUN_IN_PLACE - filenames.push_back(porting::path_userdata + + // Try also from a lower level (to aid having the same configuration + // for many RUN_IN_PLACE installs) + filenames.push_back(porting::path_user + DIR_DELIM + ".." + DIR_DELIM + "minetest.conf"); #endif @@ -334,28 +335,31 @@ int main(int argc, char *argv[]) // Port? u16 port = 30000; if(cmd_args.exists("port") && cmd_args.getU16("port") != 0) - { port = cmd_args.getU16("port"); - } else if(g_settings->exists("port") && g_settings->getU16("port") != 0) - { port = g_settings->getU16("port"); - } - else - { - dstream<<"Please specify port (in config or on command line)" - <<std::endl; - } - // Figure out path to map - std::string map_dir = porting::path_userdata+DIR_DELIM+"world"; + // Map directory + std::string map_dir = porting::path_user + DIR_DELIM + "server" + DIR_DELIM + "worlds" + DIR_DELIM + "world"; if(cmd_args.exists("map-dir")) map_dir = cmd_args.get("map-dir"); else if(g_settings->exists("map-dir")) map_dir = g_settings->get("map-dir"); + else{ + // No map-dir option was specified. + // Check if the world is found from the default directory, and if + // not, see if the legacy world directory exists. + std::string legacy_map_dir = porting::path_user+DIR_DELIM+".."+DIR_DELIM+"world"; + if(!fs::PathExists(map_dir) && fs::PathExists(legacy_map_dir)){ + errorstream<<"Warning: Using legacy world directory \"" + <<legacy_map_dir<<"\""<<std::endl; + map_dir = legacy_map_dir; + } + } + // Create server - Server server(map_dir.c_str(), configpath); + Server server(map_dir, configpath, "mesetint"); server.start(port); // Run server diff --git a/src/tile.cpp b/src/tile.cpp index c39a65511..5ef469944 100644 --- a/src/tile.cpp +++ b/src/tile.cpp @@ -132,8 +132,9 @@ std::string getTexturePath(const std::string &filename) */ if(fullpath == "") { - std::string rel_path = std::string("clienttextures")+DIR_DELIM+filename; - std::string testpath = porting::path_data + DIR_DELIM + rel_path; + std::string rel_path = std::string("client") + + DIR_DELIM + "textures" + DIR_DELIM + filename; + std::string testpath = porting::path_share + DIR_DELIM + rel_path; // Check all filename extensions. Returns "" if not found. fullpath = getImagePath(testpath); } @@ -997,7 +998,7 @@ void TextureSource::buildMainAtlas(class IGameDef *gamedef) /* Write image to file so that it can be inspected */ - /*std::string atlaspath = porting::path_userdata + /*std::string atlaspath = porting::path_user + DIR_DELIM + "generated_texture_atlas.png"; infostream<<"Removing and writing texture atlas for inspection to " <<atlaspath<<std::endl; |