mirror of
https://github.com/luanti-org/luanti.git
synced 2025-10-13 00:25:19 +02:00
Server pushing media at runtime (#9961)
This commit is contained in:
@@ -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);
|
||||
|
@@ -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;
|
||||
|
@@ -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
|
||||
|
||||
|
@@ -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:
|
||||
|
@@ -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();
|
||||
}
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user