summaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
Diffstat (limited to 'src/client')
-rw-r--r--src/client/client.cpp12
-rw-r--r--src/client/client.h9
-rw-r--r--src/client/clientmedia.cpp10
-rw-r--r--src/client/clientmedia.h5
-rw-r--r--src/client/filecache.cpp8
-rw-r--r--src/client/filecache.h1
6 files changed, 37 insertions, 8 deletions
diff --git a/src/client/client.cpp b/src/client/client.cpp
index c03c062c6..34f97a9de 100644
--- a/src/client/client.cpp
+++ b/src/client/client.cpp
@@ -670,11 +670,9 @@ void Client::step(float dtime)
}
}
-bool Client::loadMedia(const std::string &data, const std::string &filename)
+bool Client::loadMedia(const std::string &data, const std::string &filename,
+ bool from_media_push)
{
- // Silly irrlicht's const-incorrectness
- Buffer<char> data_rw(data.c_str(), data.size());
-
std::string name;
const char *image_ext[] = {
@@ -690,6 +688,9 @@ bool Client::loadMedia(const std::string &data, const std::string &filename)
io::IFileSystem *irrfs = RenderingEngine::get_filesystem();
video::IVideoDriver *vdrv = RenderingEngine::get_video_driver();
+ // Silly irrlicht's const-incorrectness
+ Buffer<char> data_rw(data.c_str(), data.size());
+
// Create an irrlicht memory file
io::IReadFile *rfile = irrfs->createMemoryReadFile(
*data_rw, data_rw.getSize(), "_tempreadfile");
@@ -727,7 +728,6 @@ bool Client::loadMedia(const std::string &data, const std::string &filename)
".x", ".b3d", ".md2", ".obj",
NULL
};
-
name = removeStringEnd(filename, model_ext);
if (!name.empty()) {
verbosestream<<"Client: Storing model into memory: "
@@ -744,6 +744,8 @@ bool Client::loadMedia(const std::string &data, const std::string &filename)
};
name = removeStringEnd(filename, translate_ext);
if (!name.empty()) {
+ if (from_media_push)
+ return false;
TRACESTREAM(<< "Client: Loading translation: "
<< "\"" << filename << "\"" << std::endl);
g_client_translations->loadTranslation(data);
diff --git a/src/client/client.h b/src/client/client.h
index 3b1095ac2..733634db1 100644
--- a/src/client/client.h
+++ b/src/client/client.h
@@ -222,6 +222,7 @@ public:
void handleCommand_FormspecPrepend(NetworkPacket *pkt);
void handleCommand_CSMRestrictionFlags(NetworkPacket *pkt);
void handleCommand_PlayerSpeed(NetworkPacket *pkt);
+ void handleCommand_MediaPush(NetworkPacket *pkt);
void ProcessData(NetworkPacket *pkt);
@@ -376,7 +377,8 @@ public:
// The following set of functions is used by ClientMediaDownloader
// Insert a media file appropriately into the appropriate manager
- bool loadMedia(const std::string &data, const std::string &filename);
+ bool loadMedia(const std::string &data, const std::string &filename,
+ bool from_media_push = false);
// Send a request for conventional media transfer
void request_media(const std::vector<std::string> &file_requests);
@@ -488,6 +490,7 @@ private:
Camera *m_camera = nullptr;
Minimap *m_minimap = nullptr;
bool m_minimap_disabled_by_server = false;
+
// Server serialization version
u8 m_server_ser_ver;
@@ -529,7 +532,6 @@ private:
AuthMechanism m_chosen_auth_mech;
void *m_auth_data = nullptr;
-
bool m_access_denied = false;
bool m_access_denied_reconnect = false;
std::string m_access_denied_reason = "";
@@ -538,7 +540,10 @@ private:
bool m_nodedef_received = false;
bool m_activeobjects_received = false;
bool m_mods_loaded = false;
+
ClientMediaDownloader *m_media_downloader;
+ // Set of media filenames pushed by server at runtime
+ std::unordered_set<std::string> m_media_pushed_files;
// time_of_day speed approximation for old protocol
bool m_time_of_day_set = false;
diff --git a/src/client/clientmedia.cpp b/src/client/clientmedia.cpp
index 6da99bbbf..8cd3b6bcc 100644
--- a/src/client/clientmedia.cpp
+++ b/src/client/clientmedia.cpp
@@ -35,6 +35,15 @@ static std::string getMediaCacheDir()
return porting::path_cache + DIR_DELIM + "media";
}
+bool clientMediaUpdateCache(const std::string &raw_hash, const std::string &filedata)
+{
+ FileCache media_cache(getMediaCacheDir());
+ std::string sha1_hex = hex_encode(raw_hash);
+ if (!media_cache.exists(sha1_hex))
+ return media_cache.update(sha1_hex, filedata);
+ return true;
+}
+
/*
ClientMediaDownloader
*/
@@ -559,7 +568,6 @@ bool ClientMediaDownloader::checkAndLoad(
return true;
}
-
/*
Minetest Hashset File Format
diff --git a/src/client/clientmedia.h b/src/client/clientmedia.h
index 92831082c..5a918535b 100644
--- a/src/client/clientmedia.h
+++ b/src/client/clientmedia.h
@@ -33,6 +33,11 @@ struct HTTPFetchResult;
#define MTHASHSET_FILE_SIGNATURE 0x4d544853 // 'MTHS'
#define MTHASHSET_FILE_NAME "index.mth"
+// Store file into media cache (unless it exists already)
+// Validating the hash is responsibility of the caller
+bool clientMediaUpdateCache(const std::string &raw_hash,
+ const std::string &filedata);
+
class ClientMediaDownloader
{
public:
diff --git a/src/client/filecache.cpp b/src/client/filecache.cpp
index 3d1b302a8..46bbe4059 100644
--- a/src/client/filecache.cpp
+++ b/src/client/filecache.cpp
@@ -82,8 +82,16 @@ bool FileCache::update(const std::string &name, const std::string &data)
std::string path = m_dir + DIR_DELIM + name;
return updateByPath(path, data);
}
+
bool FileCache::load(const std::string &name, std::ostream &os)
{
std::string path = m_dir + DIR_DELIM + name;
return loadByPath(path, os);
}
+
+bool FileCache::exists(const std::string &name)
+{
+ std::string path = m_dir + DIR_DELIM + name;
+ std::ifstream fis(path.c_str(), std::ios_base::binary);
+ return fis.good();
+}
diff --git a/src/client/filecache.h b/src/client/filecache.h
index 96e4c8ba1..ea6afc4b2 100644
--- a/src/client/filecache.h
+++ b/src/client/filecache.h
@@ -33,6 +33,7 @@ public:
bool update(const std::string &name, const std::string &data);
bool load(const std::string &name, std::ostream &os);
+ bool exists(const std::string &name);
private:
std::string m_dir;