@@ -48,14 +48,12 @@ void BanManager::load()
48
48
MutexAutoLock lock (m_mutex);
49
49
infostream<<" BanManager: loading from " <<m_banfilepath<<std::endl;
50
50
std::ifstream is (m_banfilepath.c_str (), std::ios::binary);
51
- if (is.good () == false )
52
- {
51
+ if (!is.good ()) {
53
52
infostream<<" BanManager: failed loading from " <<m_banfilepath<<std::endl;
54
53
throw SerializationError (" BanManager::load(): Couldn't open file" );
55
54
}
56
55
57
- while (!is.eof () && is.good ())
58
- {
56
+ while (!is.eof () && is.good ()) {
59
57
std::string line;
60
58
std::getline (is, line, ' \n ' );
61
59
Strfnd f (line);
@@ -74,8 +72,8 @@ void BanManager::save()
74
72
infostream << " BanManager: saving to " << m_banfilepath << std::endl;
75
73
std::ostringstream ss (std::ios_base::binary);
76
74
77
- for (StringMap::iterator it = m_ips. begin (); it != m_ips. end (); ++it )
78
- ss << it-> first << " |" << it-> second << " \n " ;
75
+ for (const auto &ip : m_ips)
76
+ ss << ip. first << " |" << ip. second << " \n " ;
79
77
80
78
if (!fs::safeWriteToFile (m_banfilepath, ss.str ())) {
81
79
infostream << " BanManager: failed saving to " << m_banfilepath << std::endl;
@@ -94,11 +92,11 @@ bool BanManager::isIpBanned(const std::string &ip)
94
92
std::string BanManager::getBanDescription (const std::string &ip_or_name)
95
93
{
96
94
MutexAutoLock lock (m_mutex);
97
- std::string s = " " ;
98
- for (StringMap::iterator it = m_ips. begin (); it != m_ips. end (); ++it ) {
99
- if (it-> first == ip_or_name || it-> second == ip_or_name
100
- || ip_or_name == " " ) {
101
- s += it-> first + " |" + it-> second + " , " ;
95
+ std::string s;
96
+ for (const auto &ip : m_ips) {
97
+ if (ip. first == ip_or_name || ip. second == ip_or_name
98
+ || ip_or_name. empty () ) {
99
+ s += ip. first + " |" + ip. second + " , " ;
102
100
}
103
101
}
104
102
s = s.substr (0 , s.size () - 2 );
0 commit comments