aboutsummaryrefslogtreecommitdiff
path: root/src/serverlist.h
Commit message (Expand)AuthorAge
* Fixes for compiling with a newer (system) jsoncpp (#4429)Rogier-52016-08-10
* Send real port to server listShadowNinja2015-01-23
* Serverlist: announce mg_name from map_meta.txt instead of minetest.confKahrl2014-11-10
* Fix serverlist code style, const-correctness, and typesShadowNinja2014-06-30
* Remove a lot of superfluous ifndef USE_CURL checkssapier2014-06-19
* Send long announce as POST, show OS in useragentproller2014-01-07
* Masterserver updateproller2013-10-18
* Masterserver mods announse, ipv6, better curl errorsproller2013-07-13
* Masterserver: report gameid, uptime, cosmetic fixes on server web pageproller2013-03-30
* Update Copyright YearsSfan52013-02-24
* Change Minetest-c55 to MinetestPilzAdam2013-02-24
* new auto masterserverproller2013-02-22
* Add a list of servers to the "Multiplayer" tabJeija2013-01-21
> 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 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
/*
Minetest
Copyright (C) 2010-2013 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 "content_nodemeta.h"
#include "nodemetadata.h"
#include "nodetimer.h"
#include "inventory.h"
#include "log.h"
#include "serialization.h"
#include "util/serialize.h"
#include "util/string.h"
#include "constants.h" // MAP_BLOCKSIZE
#include <sstream>

#define NODEMETA_GENERIC 1
#define NODEMETA_SIGN 14
#define NODEMETA_CHEST 15
#define NODEMETA_FURNACE 16
#define NODEMETA_LOCKABLE_CHEST 17

// Returns true if node timer must be set
static bool content_nodemeta_deserialize_legacy_body(
		std::istream &is, s16 id, NodeMetadata *meta)
{
	meta->clear();

	if(id == NODEMETA_GENERIC) // GenericNodeMetadata (0.4-dev)
	{
		meta->getInventory()->deSerialize(is);
		deSerializeLongString(is);  // m_text
		deSerializeString(is);  // m_owner

		meta->setString("infotext",deSerializeString(is));
		meta->setString("formspec",deSerializeString(is));
		readU8(is);  // m_allow_text_input
		readU8(is);  // m_allow_removal
		readU8(is);  // m_enforce_owner

		int num_vars = readU32(is);
		for(int i=0; i<num_vars; i++){
			std::string name = deSerializeString(is);
			std::string var = deSerializeLongString(is);
			meta->setString(name, var);
		}
		return false;
	}
	else if(id == NODEMETA_SIGN) // SignNodeMetadata
	{
		meta->setString("text", deSerializeString(is));
		//meta->setString("infotext","\"${text}\"");
		meta->setString("infotext",
				std::string("\"") + meta->getString("text") + "\"");
		meta->setString("formspec","field[text;;${text}]");
		return false;
	}
	else if(id == NODEMETA_CHEST) // ChestNodeMetadata
	{
		meta->getInventory()->deSerialize(is);

		// Rename inventory list "0" to "main"
		Inventory *inv = meta->getInventory();
		if(!inv->getList("main") && inv->getList("0")){
			inv->getList("0")->setName("main");
		}
		assert(inv->getList("main") && !inv->getList("0"));

		meta->setString("formspec","size[8,9]"
				"list[current_name;main;0,0;8,4;]"
				"list[current_player;main;0,5;8,4;]");
		return false;
	}
	else if(id == NODEMETA_LOCKABLE_CHEST) // LockingChestNodeMetadata
	{
		meta->setString("owner", deSerializeString(is));
		meta->getInventory()->deSerialize(is);

		// Rename inventory list "0" to "main"
		Inventory *inv = meta->getInventory();
		if(!inv->getList("main") && inv->getList("0")){
			inv->getList("0")->setName("main");
		}
		assert(inv->getList("main") && !inv->getList("0"));

		meta->setString("formspec","size[8,9]"
				"list[current_name;main;0,0;8,4;]"
				"list[current_player;main;0,5;8,4;]");
		return false;
	}
	else if(id == NODEMETA_FURNACE) // FurnaceNodeMetadata
	{
		meta->getInventory()->deSerialize(is);
		int temp = 0;
		is>>temp;
		meta->setString("fuel_totaltime", ftos((float)temp/10));
		temp = 0;
		is>>temp;
		meta->setString("fuel_time", ftos((float)temp/10));
		temp = 0;
		is>>temp;
		//meta->setString("src_totaltime", ftos((float)temp/10));
		temp = 0;
		is>>temp;
		meta->setString("src_time", ftos((float)temp/10));

		meta->setString("formspec","size[8,9]"
			"list[current_name;fuel;2,3;1,1;]"
			"list[current_name;src;2,1;1,1;]"
			"list[current_name;dst;5,1;2,2;]"
			"list[current_player;main;0,5;8,4;]");
		return true;
	}
	else
	{
		throw SerializationError("Unknown legacy node metadata");
	}
}

static bool content_nodemeta_deserialize_legacy_meta(
		std::istream &is, NodeMetadata *meta)
{
	// Read id
	s16 id = readS16(is);

	// Read data
	std::string data = deSerializeString(is);
	std::istringstream tmp_is(data, std::ios::binary);
	return content_nodemeta_deserialize_legacy_body(tmp_is, id, meta);
}

void content_nodemeta_deserialize_legacy(std::istream &is,
		NodeMetadataList *meta, NodeTimerList *timers,
		IItemDefManager *item_def_mgr)
{
	meta->clear();
	timers->clear();

	u16 version = readU16(is);

	if(version > 1)
	{
		infostream<<FUNCTION_NAME<<": version "<<version<<" not supported"
				<<std::endl;
		throw SerializationError(FUNCTION_NAME);
	}

	u16 count = readU16(is);

	for(u16 i=0; i<count; i++)
	{
		u16 p16 = readU16(is);

		v3s16 p(0,0,0);
		p.Z += p16 / MAP_BLOCKSIZE / MAP_BLOCKSIZE;
		p16 -= p.Z * MAP_BLOCKSIZE * MAP_BLOCKSIZE;
		p.Y += p16 / MAP_BLOCKSIZE;
		p16 -= p.Y * MAP_BLOCKSIZE;
		p.X += p16;

		if(meta->get(p) != NULL)
		{
			warningstream<<FUNCTION_NAME<<": "
					<<"already set data at position"
					<<"("<<p.X<<","<<p.Y<<","<<p.Z<<"): Ignoring."
					<<std::endl;
			continue;
		}

		NodeMetadata *data = new NodeMetadata(item_def_mgr);
		bool need_timer = content_nodemeta_deserialize_legacy_meta(is, data);
		meta->set(p, data);

		if(need_timer)
			timers->set(NodeTimer(1., 0., p));
	}
}