aboutsummaryrefslogtreecommitdiff
path: root/src/content/subgames.cpp
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2021-09-12 14:35:52 +0200
committersfan5 <sfan5@live.de>2021-09-12 14:42:01 +0200
commitb480a3e9fd7036208068c4fad410f0cae8fc9c4f (patch)
tree895d49291027262a47a85cc55bb4d9260ca85389 /src/content/subgames.cpp
parent75bf9b75caba5fc876f20eabea3fabc142d1b51e (diff)
downloadminetest-b480a3e9fd7036208068c4fad410f0cae8fc9c4f.tar.gz
minetest-b480a3e9fd7036208068c4fad410f0cae8fc9c4f.tar.bz2
minetest-b480a3e9fd7036208068c4fad410f0cae8fc9c4f.zip
Fix broken handling of NodemetaChanged packets
fixes #11610
Diffstat (limited to 'src/content/subgames.cpp')
0 files changed, 0 insertions, 0 deletions
' href='#n126'>126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
/*
Minetest-c55
Copyright (C) 2011 celeron55, Perttu Ahola <celeron55@gmail.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include "ban.h"
#include <fstream>
#include <jmutexautolock.h>
#include <sstream>
#include <set>
#include "strfnd.h"
#include "log.h"

BanManager::BanManager(const std::string &banfilepath):
		m_banfilepath(banfilepath),
		m_modified(false)
{
	m_mutex.Init();
	try{
		load();
	}
	catch(SerializationError &e)
	{
		infostream<<"WARNING: BanManager: creating "
				<<m_banfilepath<<std::endl;
	}
}

BanManager::~BanManager()
{
	save();
}

void BanManager::load()
{
	JMutexAutoLock lock(m_mutex);
	infostream<<"BanManager: loading from "<<m_banfilepath<<std::endl;
	std::ifstream is(m_banfilepath.c_str(), std::ios::binary);
	if(is.good() == false)
	{
		infostream<<"BanManager: failed loading from "<<m_banfilepath<<std::endl;
		throw SerializationError("BanManager::load(): Couldn't open file");
	}
	
	for(;;)
	{
		if(is.eof() || is.good() == false)
			break;
		std::string line;
		std::getline(is, line, '\n');
		Strfnd f(line);
		std::string ip = trim(f.next("|"));
		std::string name = trim(f.next("|"));
		if(ip.empty())
			continue;
		m_ips[ip] = name;
	}
	m_modified = false;
}

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");
	}

	for(std::map<std::string, std::string>::iterator
			i = m_ips.begin();
			i != m_ips.end(); i++)
	{