summaryrefslogtreecommitdiff
path: root/src/client.cpp
diff options
context:
space:
mode:
authorLoïc Blot <nerzhul@users.noreply.github.com>2017-03-16 07:53:39 +0100
committerGitHub <noreply@github.com>2017-03-16 07:53:39 +0100
commiteb88e5dd4b181a90b382c036cf6c4f42e63e8cc2 (patch)
tree2ba995e0a2f15c0bc50212169f0b5af8addd3f86 /src/client.cpp
parent46276414ed51d61dc29879ac85e861dc770d90da (diff)
downloadminetest-eb88e5dd4b181a90b382c036cf6c4f42e63e8cc2.tar.gz
minetest-eb88e5dd4b181a90b382c036cf6c4f42e63e8cc2.tar.bz2
minetest-eb88e5dd4b181a90b382c036cf6c4f42e63e8cc2.zip
Add ModStorageAPI to client side modding (#5396)
mod storage is located into user_path / client / mod_storage
Diffstat (limited to 'src/client.cpp')
-rw-r--r--src/client.cpp43
1 files changed, 42 insertions, 1 deletions
diff --git a/src/client.cpp b/src/client.cpp
index 4ddabd814..567ee6dd7 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -249,7 +249,8 @@ Client::Client(
m_removed_sounds_check_timer(0),
m_state(LC_Created),
m_localdb(NULL),
- m_script(NULL)
+ m_script(NULL),
+ m_mod_storage_save_timer(10.0f)
{
// Add local player
m_env.setLocalPlayer(new LocalPlayer(this, playername));
@@ -730,6 +731,18 @@ void Client::step(float dtime)
}
}
+ m_mod_storage_save_timer -= dtime;
+ if (m_mod_storage_save_timer <= 0.0f) {
+ verbosestream << "Saving registered mod storages." << std::endl;
+ m_mod_storage_save_timer = g_settings->getFloat("server_map_save_interval");
+ for (UNORDERED_MAP<std::string, ModMetadata *>::const_iterator
+ it = m_mod_storages.begin(); it != m_mod_storages.end(); ++it) {
+ if (it->second->isModified()) {
+ it->second->save(getModStoragePath());
+ }
+ }
+ }
+
// Write server map
if (m_localdb && m_localdb_save_interval.step(dtime,
m_cache_save_interval)) {
@@ -1998,3 +2011,31 @@ scene::IAnimatedMesh* Client::getMesh(const std::string &filename)
smgr->getMeshCache()->removeMesh(mesh);
return mesh;
}
+
+bool Client::registerModStorage(ModMetadata *storage)
+{
+ if (m_mod_storages.find(storage->getModName()) != m_mod_storages.end()) {
+ errorstream << "Unable to register same mod storage twice. Storage name: "
+ << storage->getModName() << std::endl;
+ return false;
+ }
+
+ m_mod_storages[storage->getModName()] = storage;
+ return true;
+}
+
+void Client::unregisterModStorage(const std::string &name)
+{
+ UNORDERED_MAP<std::string, ModMetadata *>::const_iterator it = m_mod_storages.find(name);
+ if (it != m_mod_storages.end()) {
+ // Save unconditionaly on unregistration
+ it->second->save(getModStoragePath());
+ m_mod_storages.erase(name);
+ }
+}
+
+std::string Client::getModStoragePath() const
+{
+ return porting::path_user + DIR_DELIM + "client" + DIR_DELIM + "mod_storage";
+}
+