aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api
ModeNameSize
-rw-r--r--CMakeLists.txt1250logplain
-rw-r--r--l_areastore.cpp9071logplain
-rw-r--r--l_areastore.h1816logplain
-rw-r--r--l_base.cpp2208logplain
-rw-r--r--l_base.h2108logplain
-rw-r--r--l_client.cpp6333logplain
-rw-r--r--l_client.h2089logplain
-rw-r--r--l_craft.cpp14132logplain
-rw-r--r--l_craft.h1633logplain
-rw-r--r--l_env.cpp27948logplain
-rw-r--r--l_env.h6939logplain
-rw-r--r--l_http.cpp5682logplain
-rw-r--r--l_http.h1533logplain
-rw-r--r--l_internal.h1997logplain
-rw-r--r--l_inventory.cpp13558logplain
-rw-r--r--l_inventory.h3776logplain
-rw-r--r--l_item.cpp16115logplain
-rw-r--r--l_item.h4477logplain
-rw-r--r--l_itemstackmeta.cpp3337logplain
-rw-r--r--l_itemstackmeta.h1686logplain
-rw-r--r--l_localplayer.cpp9973logplain
-rw-r--r--l_localplayer.h2740logplain
-rw-r--r--l_mainmenu.cpp30332logplain
-rw-r--r--l_mainmenu.h3882logplain
-rw-r--r--l_mapgen.cpp38949logplain
-rw-r--r--l_mapgen.h3897logplain
-rw-r--r--l_metadata.cpp6209logplain
-rw-r--r--l_metadata.h1978logplain
-rw-r--r--l_minimap.cpp4900logplain
-rw-r--r--l_minimap.h1672logplain
-rw-r--r--l_nodemeta.cpp6518logplain
-rw-r--r--l_nodemeta.h2959logplain
-rw-r--r--l_nodetimer.cpp4461logplain
-rw-r--r--l_nodetimer.h1771logplain
-rw-r--r--l_noise.cpp15532logplain
-rw-r--r--l_noise.h4583logplain
-rw-r--r--l_object.cpp47834logplain
-rw-r--r--l_object.h8807logplain
-rw-r--r--l_particles.cpp8429logplain
-rw-r--r--l_particles.h1148logplain
-rw-r--r--l_rollback.cpp3552logplain
-rw-r--r--l_rollback.h1278logplain
-rw-r--r--l_server.cpp14014logplain
-rw-r--r--l_server.h2975logplain
-rw-r--r--l_settings.cpp5569logplain
-rw-r--r--l_settings.h1910logplain
-rw-r--r--l_sound.cpp1428logplain
-rw-r--r--l_sound.h1119logplain
-rw-r--r--l_storage.cpp3829logplain
-rw-r--r--l_storage.h1704logplain
-rw-r--r--l_util.cpp13502logplain
-rw-r--r--l_util.h3178logplain
-rw-r--r--l_vmanip.cpp10510logplain
-rw-r--r--l_vmanip.h2274logplain
45' href='#n845'>845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910
/*
Minetest
Copyright (C) 2010-2014 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 <sstream>
#include "clientiface.h"
#include "network/connection.h"
#include "network/serveropcodes.h"
#include "remoteplayer.h"
#include "settings.h"
#include "mapblock.h"
#include "serverenvironment.h"
#include "map.h"
#include "emerge.h"
#include "server/luaentity_sao.h"
#include "server/player_sao.h"
#include "log.h"
#include "util/srp.h"
#include "face_position_cache.h"

const char *ClientInterface::statenames[] = {
	"Invalid",
	"Disconnecting",
	"Denied",
	"Created",
	"AwaitingInit2",
	"HelloSent",
	"InitDone",
	"DefinitionsSent",
	"Active",
	"SudoMode",
};



std::string ClientInterface::state2Name(ClientState state)
{
	return statenames[state];
}

RemoteClient::RemoteClient() :
	m_max_simul_sends(g_settings->getU16("max_simultaneous_block_sends_per_client")),
	m_min_time_from_building(
		g_settings->getFloat("full_block_send_enable_min_time_from_building")),
	m_max_send_distance(g_settings->getS16("max_block_send_distance")),
	m_block_optimize_distance(g_settings->getS16("block_send_optimize_distance")),
	m_max_gen_distance(g_settings->getS16("max_block_generate_distance")),
	m_occ_cull(g_settings->getBool("server_side_occlusion_culling"))
{
}

void RemoteClient::ResendBlockIfOnWire(v3s16 p)
{
	// if this block is on wire, mark it for sending again as soon as possible
	if (m_blocks_sending.find(p) != m_blocks_sending.end()) {
		SetBlockNotSent(p);
	}
}

LuaEntitySAO *getAttachedObject(PlayerSAO *sao, ServerEnvironment *env)
{
	if (!sao->isAttached())
		return nullptr;

	int id;
	std::string bone;
	v3f dummy;
	sao->getAttachment(&id, &bone, &dummy, &dummy);
	ServerActiveObject *ao = env->getActiveObject(id);
	while (id && ao) {
		ao->getAttachment(&id, &bone, &dummy, &dummy);
		if (id)
			ao = env->getActiveObject(id);
	}
	return dynamic_cast<LuaEntitySAO *>(ao);
}

void RemoteClient::GetNextBlocks (
		ServerEnvironment *env,
		EmergeManager * emerge,
		float dtime,
		std::vector<PrioritySortedBlockTransfer> &dest)
{
	// Increment timers
	m_nothing_to_send_pause_timer -= dtime;
	m_nearest_unsent_reset_timer += dtime;

	if (m_nothing_to_send_pause_timer >= 0)
		return;

	RemotePlayer *player = env->getPlayer(peer_id);
	// This can happen sometimes; clients and players are not in perfect sync.
	if (!player)
		return;

	PlayerSAO *sao = player->getPlayerSAO();
	if (!sao)
		return;

	// Won't send anything if already sending
	if (m_blocks_sending.size() >= m_max_simul_sends) {
		//infostream<<"Not sending any blocks, Queue full."<<std::endl;
		return;
	}

	v3f playerpos = sao->getBasePosition();
	// if the player is attached, get the velocity from the attached object
	LuaEntitySAO *lsao = getAttachedObject(sao, env);
	const v3f &playerspeed = lsao? lsao->getVelocity() : player->getSpeed();
	v3f playerspeeddir(0,0,0);
	if (playerspeed.getLength() > 1.0f * BS)
		playerspeeddir = playerspeed / playerspeed.getLength();
	// Predict to next block
	v3f playerpos_predicted = playerpos + playerspeeddir * (MAP_BLOCKSIZE * BS);

	v3s16 center_nodepos = floatToInt(playerpos_predicted, BS);

	v3s16 center = getNodeBlockPos(center_nodepos);

	// Camera position and direction
	v3f camera_pos = sao->getEyePosition();
	v3f camera_dir = v3f(0,0,1);
	camera_dir.rotateYZBy(sao->getLookPitch());
	camera_dir.rotateXZBy(sao->getRotation().Y);

	/*infostream<<"camera_dir=("<<camera_dir.X<<","<<camera_dir.Y<<","
			<<camera_dir.Z<<")"<<std::endl;*/

	/*
		Get the starting value of the block finder radius.
	*/