aboutsummaryrefslogtreecommitdiff
path: root/src/mapgen_singlenode.cpp
diff options
context:
space:
mode:
authorCraig Robbins <kde.psych@gmail.com>2015-01-05 22:39:08 +1000
committerCraig Robbins <kde.psych@gmail.com>2015-01-05 22:55:02 +1000
commitbeb6b3e5937160fab583f5dda2be53a651f0ec71 (patch)
tree09b0f12eb8762866bc8fb52ecae76a579423ff49 /src/mapgen_singlenode.cpp
parent2d849b0a19af03913e564e2b6dbc36eecdd5ae0c (diff)
downloadminetest-beb6b3e5937160fab583f5dda2be53a651f0ec71.tar.gz
minetest-beb6b3e5937160fab583f5dda2be53a651f0ec71.tar.bz2
minetest-beb6b3e5937160fab583f5dda2be53a651f0ec71.zip
Prevent client crashing if an NDT_AIRLIKE node is dropped
The player dropping the node can either be themselves or another player (i.e. without this fix you can crash other people's clients) Thanks CWz for reporting the issue
Diffstat (limited to 'src/mapgen_singlenode.cpp')
0 files changed, 0 insertions, 0 deletions
130' href='#n130'>130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
/*
Minetest
Copyright (C) 2017 nerzhul, Loic Blot <loic.blot@unix-experience.fr>

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 "modchannels.h"
#include <algorithm>
#include <cassert>
#include "util/basic_macros.h"

bool ModChannel::registerConsumer(session_t peer_id)
{

	// ignore if peer_id already joined
	if (CONTAINS(m_client_consumers, peer_id))
		return false;

	m_client_consumers.push_back(peer_id);
	return true;
}

bool ModChannel::removeConsumer(session_t peer_id)
{
	bool found = false;
	auto peer_removal_fct = [peer_id, &found](u16 p) {
		if (p == peer_id)
			found = true;

		return p == peer_id;
	};

	m_client_consumers.erase(
			std::remove_if(m_client_consumers.begin(),
					m_client_consumers.end(), peer_removal_fct),
			m_client_consumers.end());

	return found;
}

bool ModChannel::canWrite() const
{
	return m_state == MODCHANNEL_STATE_READ_WRITE;
}

void ModChannel::setState(ModChannelState state)
{
	assert(state != MODCHANNEL_STATE_INIT);

	m_state = state;
}

bool ModChannelMgr::channelRegistered(const std::string &channel) const
{
	return m_registered_channels.find(channel) != m_registered_channels.end();
}

ModChannel *ModChannelMgr::getModChannel(const std::string &channel)
{
	if (!channelRegistered(channel))
		return nullptr;

	return m_registered_channels[channel].get();
}

bool ModChannelMgr::canWriteOnChannel(const std::string &channel) const
{