]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/clientmedia.cpp
Fix #5617 - respect message and reconnect parameters when shutting down immediately...
[dragonfireclient.git] / src / clientmedia.cpp
index e2679ed46301e4902d36b997a7274d5f15750a7c..14a38ca66439dbacfe065b3da3d274251a50b9dd 100644 (file)
@@ -20,21 +20,21 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "clientmedia.h"
 #include "httpfetch.h"
 #include "client.h"
-#include "clientserver.h"
 #include "filecache.h"
-#include "hex.h"
-#include "sha1.h"
+#include "filesys.h"
 #include "debug.h"
 #include "log.h"
 #include "porting.h"
 #include "settings.h"
-#include "main.h"
+#include "network/networkprotocol.h"
+#include "util/hex.h"
 #include "util/serialize.h"
+#include "util/sha1.h"
 #include "util/string.h"
 
 static std::string getMediaCacheDir()
 {
-       return porting::path_user + DIR_DELIM + "cache" + DIR_DELIM + "media";
+       return porting::path_cache + DIR_DELIM + "media";
 }
 
 /*
@@ -42,12 +42,12 @@ static std::string getMediaCacheDir()
 */
 
 ClientMediaDownloader::ClientMediaDownloader():
-       m_media_cache(getMediaCacheDir())
+       m_media_cache(getMediaCacheDir()),
+       m_initial_step_done(false),
+       m_uncached_count(0),
+       m_uncached_received_count(0),
+       m_name_bound("")
 {
-       m_initial_step_done = false;
-       m_name_bound = "";  // works because "" is an invalid file name
-       m_uncached_count = 0;
-       m_uncached_received_count = 0;
        m_httpfetch_caller = HTTPFETCH_DISCARD;
        m_httpfetch_active = 0;
        m_httpfetch_active_limit = 0;
@@ -69,9 +69,9 @@ ClientMediaDownloader::~ClientMediaDownloader()
                delete m_remotes[i];
 }
 
-void ClientMediaDownloader::addFile(std::string name, std::string sha1)
+void ClientMediaDownloader::addFile(const std::string &name, const std::string &sha1)
 {
-       assert(!m_initial_step_done);
+       assert(!m_initial_step_done); // pre-condition
 
        // if name was already announced, ignore the new announcement
        if (m_files.count(name) != 0) {
@@ -104,9 +104,9 @@ void ClientMediaDownloader::addFile(std::string name, std::string sha1)
        m_files.insert(std::make_pair(name, filestatus));
 }
 
-void ClientMediaDownloader::addRemoteServer(std::string baseurl)
+void ClientMediaDownloader::addRemoteServer(const std::string &baseurl)
 {
-       assert(!m_initial_step_done);
+       assert(!m_initial_step_done);   // pre-condition
 
        #ifdef USE_CURL
 
@@ -355,11 +355,11 @@ void ClientMediaDownloader::remoteMediaReceived(
                m_remote_file_transfers.erase(it);
        }
 
-       assert(m_files.count(name) != 0);
+       sanity_check(m_files.count(name) != 0);
 
        FileStatus *filestatus = m_files[name];
-       assert(!filestatus->received);
-       assert(filestatus->current_remote >= 0);
+       sanity_check(!filestatus->received);
+       sanity_check(filestatus->current_remote >= 0);
 
        RemoteServerStatus *remote = m_remotes[filestatus->current_remote];
 
@@ -381,6 +381,7 @@ void ClientMediaDownloader::remoteMediaReceived(
 
 s32 ClientMediaDownloader::selectRemoteServer(FileStatus *filestatus)
 {
+       // Pre-conditions
        assert(filestatus != NULL);
        assert(!filestatus->received);
        assert(filestatus->current_remote < 0);
@@ -482,12 +483,12 @@ void ClientMediaDownloader::startRemoteMediaTransfers()
 
 void ClientMediaDownloader::startConventionalTransfers(Client *client)
 {
-       assert(m_httpfetch_active == 0);
+       assert(m_httpfetch_active == 0);        // pre-condition
 
        if (m_uncached_received_count != m_uncached_count) {
                // Some media files have not been received yet, use the
                // conventional slow method (minetest protocol) to get them
-               std::list<std::string> file_requests;
+               std::vector<std::string> file_requests;
                for (std::map<std::string, FileStatus*>::iterator
                                it = m_files.begin();
                                it != m_files.end(); ++it) {
@@ -615,7 +616,7 @@ std::string ClientMediaDownloader::serializeRequiredHashSet()
                        it = m_files.begin();
                        it != m_files.end(); ++it) {
                if (!it->second->received) {
-                       assert(it->second->sha1.size() == 20);
+                       FATAL_ERROR_IF(it->second->sha1.size() != 20, "Invalid SHA1 size");
                        os << it->second->sha1;
                }
        }