From e258675eabc874d31bc9c6cf49e4bbc1f7f3f417 Mon Sep 17 00:00:00 2001 From: sapier Date: Fri, 31 Jan 2014 00:24:00 +0100 Subject: Add propper client initialization -add client states to avoid server sending data to uninitialized clients -don't show uninitialized clients to other players -propper client disconnect handling Minor comment fixes in server Minor bugfixes in connection -improved peer id calculation -honor NDEBUG flag -improved disconnect handling -increased initial send window Remove some dead code --- src/clientiface.h | 306 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 306 insertions(+) create mode 100644 src/clientiface.h (limited to 'src/clientiface.h') diff --git a/src/clientiface.h b/src/clientiface.h new file mode 100644 index 000000000..a2315b3bd --- /dev/null +++ b/src/clientiface.h @@ -0,0 +1,306 @@ +/* +Minetest +Copyright (C) 2010-2014 celeron55, Perttu Ahola + +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. +*/ +#ifndef _CLIENTIFACE_H_ +#define _CLIENTIFACE_H_ + +#include "irr_v3d.h" // for irrlicht datatypes + +#include "constants.h" +#include "serialization.h" // for SER_FMT_VER_INVALID +#include "jthread/jmutex.h" + +#include +#include +#include +#include + +class MapBlock; +class ServerEnvironment; +class EmergeManager; + +namespace con { + class Connection; +} + +enum ClientState +{ + Invalid, + Disconnecting, + Denied, + Created, + InitSent, + InitDone, + DefinitionsSent, + Active +}; + +enum ClientStateEvent +{ + Init, + GotInit2, + SetDenied, + SetDefinitionsSent, + SetMediaSent, + Disconnect +}; + +/* + Used for queueing and sorting block transfers in containers + + Lower priority number means higher priority. +*/ +struct PrioritySortedBlockTransfer +{ + PrioritySortedBlockTransfer(float a_priority, v3s16 a_pos, u16 a_peer_id) + { + priority = a_priority; + pos = a_pos; + peer_id = a_peer_id; + } + bool operator < (const PrioritySortedBlockTransfer &other) const + { + return priority < other.priority; + } + float priority; + v3s16 pos; + u16 peer_id; +}; + +class RemoteClient +{ +public: + // peer_id=0 means this client has no associated peer + // NOTE: If client is made allowed to exist while peer doesn't, + // this has to be set to 0 when there is no peer. + // Also, the client must be moved to some other container. + u16 peer_id; + // The serialization version to use with the client + u8 serialization_version; + // + u16 net_proto_version; + + RemoteClient(): + peer_id(PEER_ID_INEXISTENT), + serialization_version(SER_FMT_VER_INVALID), + net_proto_version(0), + m_time_from_building(9999), + m_pending_serialization_version(SER_FMT_VER_INVALID), + m_state(Created), + m_nearest_unsent_d(0), + m_nearest_unsent_reset_timer(0.0), + m_excess_gotblocks(0), + m_nothing_to_send_counter(0), + m_nothing_to_send_pause_timer(0.0), + m_name("") + { + } + ~RemoteClient() + { + } + + /* + Finds block that should be sent next to the client. + Environment should be locked when this is called. + dtime is used for resetting send radius at slow interval + */ + void GetNextBlocks(ServerEnvironment *env, EmergeManager* emerge, + float dtime, std::vector &dest); + + void GotBlock(v3s16 p); + + void SentBlock(v3s16 p); + + void SetBlockNotSent(v3s16 p); + void SetBlocksNotSent(std::map &blocks); + + s32 SendingCount() + { + return m_blocks_sending.size(); + } + + // Increments timeouts and removes timed-out blocks from list + // NOTE: This doesn't fix the server-not-sending-block bug + // because it is related to emerging, not sending. + //void RunSendingTimeouts(float dtime, float timeout); + + void PrintInfo(std::ostream &o) + { + o<<"RemoteClient "<