]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/ban.cpp
Omnicleanup: header cleanup, add ModApiUtil shared between game and mainmenu
[dragonfireclient.git] / src / ban.cpp
index 75bae746f9455131705a27763d382014ca6a7a7e..5bb470a676f5e6c3a010e50f26cb83990a65614b 100644 (file)
@@ -23,7 +23,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include <sstream>
 #include <set>
 #include "strfnd.h"
+#include "util/string.h"
 #include "log.h"
+#include "filesys.h"
 
 BanManager::BanManager(const std::string &banfilepath):
                m_banfilepath(banfilepath),
@@ -76,20 +78,20 @@ void BanManager::save()
 {
        JMutexAutoLock lock(m_mutex);
        infostream<<"BanManager: saving to "<<m_banfilepath<<std::endl;
-       std::ofstream os(m_banfilepath.c_str(), std::ios::binary);
-       
-       if(os.good() == false)
-       {
-               infostream<<"BanManager: failed saving to "<<m_banfilepath<<std::endl;
-               throw SerializationError("BanManager::load(): Couldn't open file");
-       }
+       std::ostringstream ss(std::ios_base::binary);
 
        for(std::map<std::string, std::string>::iterator
                        i = m_ips.begin();
                        i != m_ips.end(); i++)
        {
-               os<<i->first<<"|"<<i->second<<"\n";
+               ss << i->first << "|" << i->second << "\n";
        }
+
+       if(!fs::safeWriteToFile(m_banfilepath, ss.str())) {
+               infostream<<"BanManager: failed saving to "<<m_banfilepath<<std::endl;
+               throw SerializationError("BanManager::save(): Couldn't write file");
+       }
+
        m_modified = false;
 }