2014-01-31 00:24:00 +01:00
|
|
|
/*
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
#ifndef _CLIENTIFACE_H_
|
|
|
|
#define _CLIENTIFACE_H_
|
|
|
|
|
|
|
|
#include "irr_v3d.h" // for irrlicht datatypes
|
|
|
|
|
|
|
|
#include "constants.h"
|
|
|
|
#include "serialization.h" // for SER_FMT_VER_INVALID
|
[Patch 2/4] Network rework: packet writing, sending and cleanups
NetworkPacket.cpp:
* Remove some deprecated functions, we must use streaming interface
* m_data converted from u8* to std::vector<u8>
* Add an exporter to forge packet to Connection object
* implement operator << std::wstring. n
* implement operator << std::string
* dynamic resize when write packet content.
* fix string writing and performances.
* create ServerCommandFactory, used by client to get useful informations about packet processing (sending).
* Reliability
* Transmit channel
* Implement putRawString for some ugly char (_INIT packet), and use it.
* Many packet read and write migrated
* Implement oldForgePacket to interface writing with current connection
* fix U8/char/bool writing
* fix string writing and performances.
* add some missing functions
* Use v3s16 read instead of reading x,y,z separately
* Add irr::video::SColor support into packets
* Add some missing handlers
* Add a template function to increase offset
* Throw a serialization error on packet reading (must be improved)
PacketFactories:
* Create ServerCommandFactory, used by client to get useful informations about packet processing (sending).
* Create ClientCommandFactory, used by server to get useful informations about packet processing (sending).
Client.cpp:
* implement NetworkPacket ::Send interface.
* Move packet handlers to a dedicated file
* Remove Client::Send(SharedBuffer)
Server.cpp:
* implement NetworkPacket ::Send interface.
* Rewrite all packets using NetworkPacket
* Move packet handlers to a dedicated file
* Remove Server::Send(SharedBuffer)
ClientIface.cpp:
* Remove sendToAll(SharedBuffer<u8>)
Connection.hpp rework:
* Remove duplicate include
* Remove duplicate negation
* Remove a useless variable
* Improve code performance by using a m_peers_list instead of scanning m_peers map
* Remove Connection::Send(SharedBuffer)
* Fix useafterfree into NetworkPacket Sending
* Remove unused Connection::sendToAll
Test.cpp:
* Remove dead code
* Update tests to use NetworkPackets
Misc:
* add new wrappers to Send packets in client, using NetworkPacket
* Add NetworkPacket methods for Connection
* coding style fix
* dead code since changes cleanup
* Use v3s16 read instead of reading x,y,z separately in some packets
* Use different files to handle packets received by client and server
* Cleanup: Remove useless includes
ok @Zeno-
Tested by @Zeno- @VanessaE and @nerzhul on running servers
2015-01-16 11:37:49 +01:00
|
|
|
#include "network/networkpacket.h"
|
2016-03-06 20:31:16 +01:00
|
|
|
#include "porting.h"
|
2014-01-31 00:24:00 +01:00
|
|
|
|
|
|
|
#include <list>
|
|
|
|
#include <vector>
|
|
|
|
#include <set>
|
2017-06-06 16:29:28 +02:00
|
|
|
#include <mutex>
|
2014-01-31 00:24:00 +01:00
|
|
|
|
|
|
|
class MapBlock;
|
|
|
|
class ServerEnvironment;
|
|
|
|
class EmergeManager;
|
|
|
|
|
2014-02-13 20:17:42 +01:00
|
|
|
/*
|
|
|
|
* State Transitions
|
|
|
|
|
|
|
|
Start
|
|
|
|
(peer connect)
|
|
|
|
|
|
|
|
|
v
|
|
|
|
/-----------------\
|
|
|
|
| |
|
|
|
|
| Created |
|
|
|
|
| |
|
|
|
|
\-----------------/
|
2015-04-12 04:49:13 +02:00
|
|
|
| depending of the incoming packet
|
|
|
|
+---------------------------------------
|
2015-05-24 16:33:22 +02:00
|
|
|
v v
|
2015-04-12 04:49:13 +02:00
|
|
|
+-----------------------------+ +-----------------------------+
|
|
|
|
|IN: | |IN: |
|
|
|
|
| TOSERVER_INIT_LEGACY |----- | TOSERVER_INIT | invalid playername,
|
|
|
|
+-----------------------------+ | +-----------------------------+ password (for _LEGACY),
|
|
|
|
| | | or denied by mod
|
|
|
|
| Auth ok -------------------+---------------------------------
|
2015-05-24 16:33:22 +02:00
|
|
|
v v |
|
2015-04-12 04:49:13 +02:00
|
|
|
+-----------------------------+ +-----------------------------+ |
|
|
|
|
|OUT: | |OUT: | |
|
|
|
|
| TOCLIENT_INIT_LEGACY | | TOCLIENT_HELLO | |
|
|
|
|
+-----------------------------+ +-----------------------------+ |
|
|
|
|
| | |
|
|
|
|
| | |
|
|
|
|
v v |
|
|
|
|
/-----------------\ /-----------------\ |
|
|
|
|
| | | | |
|
|
|
|
| AwaitingInit2 |<--------- | HelloSent | |
|
|
|
|
| | | | | |
|
|
|
|
\-----------------/ | \-----------------/ |
|
|
|
|
| | | |
|
|
|
|
+-----------------------------+ | *-----------------------------* Auth fails |
|
|
|
|
|IN: | | |Authentication, depending on |-----------------+
|
|
|
|
| TOSERVER_INIT2 | | | packet sent by client | |
|
|
|
|
+-----------------------------+ | *-----------------------------* |
|
|
|
|
| | | |
|
|
|
|
| | | Authentication |
|
|
|
|
v | | successful |
|
|
|
|
/-----------------\ | v |
|
|
|
|
| | | +-----------------------------+ |
|
|
|
|
| InitDone | | |OUT: | |
|
|
|
|
| | | | TOCLIENT_AUTH_ACCEPT | |
|
|
|
|
\-----------------/ | +-----------------------------+ |
|
|
|
|
| | | |
|
|
|
|
+-----------------------------+ --------------------- |
|
|
|
|
|OUT: | |
|
|
|
|
| TOCLIENT_MOVEMENT | |
|
|
|
|
| TOCLIENT_ITEMDEF | |
|
|
|
|
| TOCLIENT_NODEDEF | |
|
|
|
|
| TOCLIENT_ANNOUNCE_MEDIA | |
|
|
|
|
| TOCLIENT_DETACHED_INVENTORY | |
|
|
|
|
| TOCLIENT_TIME_OF_DAY | |
|
|
|
|
+-----------------------------+ |
|
|
|
|
| |
|
|
|
|
| |
|
|
|
|
| ----------------------------- |
|
|
|
|
v | | |
|
|
|
|
/-----------------\ v |
|
|
|
|
| | +-----------------------------+ |
|
|
|
|
| DefinitionsSent | |IN: | |
|
|
|
|
| | | TOSERVER_REQUEST_MEDIA | |
|
|
|
|
\-----------------/ | TOSERVER_RECEIVED_MEDIA | |
|
|
|
|
| +-----------------------------+ |
|
|
|
|
| ^ | |
|
|
|
|
| ----------------------------- |
|
2015-05-24 16:33:22 +02:00
|
|
|
v |
|
2015-04-12 04:49:13 +02:00
|
|
|
+-----------------------------+ --------------------------------+
|
|
|
|
|IN: | | |
|
|
|
|
| TOSERVER_CLIENT_READY | v |
|
|
|
|
+-----------------------------+ +-------------------------------+ |
|
|
|
|
| |OUT: | |
|
|
|
|
v | TOCLIENT_ACCESS_DENIED_LEGAGY | |
|
|
|
|
+-----------------------------+ +-------------------------------+ |
|
|
|
|
|OUT: | | |
|
|
|
|
| TOCLIENT_MOVE_PLAYER | v |
|
|
|
|
| TOCLIENT_PRIVILEGES | /-----------------\ |
|
|
|
|
| TOCLIENT_INVENTORY_FORMSPEC | | | |
|
|
|
|
| UpdateCrafting | | Denied | |
|
|
|
|
| TOCLIENT_INVENTORY | | | |
|
|
|
|
| TOCLIENT_HP (opt) | \-----------------/ |
|
|
|
|
| TOCLIENT_BREATH | |
|
|
|
|
| TOCLIENT_DEATHSCREEN | |
|
|
|
|
+-----------------------------+ |
|
|
|
|
| |
|
|
|
|
v |
|
|
|
|
/-----------------\ async mod action (ban, kick) |
|
|
|
|
| |---------------------------------------------------------------
|
|
|
|
---->| Active |
|
|
|
|
| | |----------------------------------------------
|
2015-05-24 16:33:22 +02:00
|
|
|
| \-----------------/ timeout v
|
2015-04-12 04:49:13 +02:00
|
|
|
| | | +-----------------------------+
|
|
|
|
| | | |OUT: |
|
|
|
|
| | | | TOCLIENT_DISCONNECT |
|
|
|
|
| | | +-----------------------------+
|
|
|
|
| | | |
|
2015-05-24 16:33:22 +02:00
|
|
|
| | v v
|
2015-04-12 04:49:13 +02:00
|
|
|
| | +-----------------------------+ /-----------------\
|
|
|
|
| | |IN: | | |
|
|
|
|
| | | TOSERVER_DISCONNECT |------------------->| Disconnecting |
|
|
|
|
| | +-----------------------------+ | |
|
|
|
|
| | \-----------------/
|
|
|
|
| | any auth packet which was
|
|
|
|
| | allowed in TOCLIENT_AUTH_ACCEPT
|
|
|
|
| v
|
|
|
|
| *-----------------------------* Auth +-------------------------------+
|
|
|
|
| |Authentication, depending on | succeeds |OUT: |
|
|
|
|
| | packet sent by client |---------->| TOCLIENT_ACCEPT_SUDO_MODE |
|
|
|
|
| *-----------------------------* +-------------------------------+
|
|
|
|
| | |
|
|
|
|
| | Auth fails /-----------------\
|
|
|
|
| v | |
|
|
|
|
| +-------------------------------+ | SudoMode |
|
|
|
|
| |OUT: | | |
|
|
|
|
| | TOCLIENT_DENY_SUDO_MODE | \-----------------/
|
|
|
|
| +-------------------------------+ |
|
|
|
|
| | v
|
|
|
|
| | +-----------------------------+
|
|
|
|
| | sets password accordingly |IN: |
|
|
|
|
-------------------+-------------------------------| TOSERVER_FIRST_SRP |
|
2015-05-24 16:33:22 +02:00
|
|
|
+-----------------------------+
|
2015-04-12 04:49:13 +02:00
|
|
|
|
2014-02-13 20:17:42 +01:00
|
|
|
*/
|
2014-01-31 00:24:00 +01:00
|
|
|
namespace con {
|
|
|
|
class Connection;
|
|
|
|
}
|
|
|
|
|
2014-04-15 19:49:32 +02:00
|
|
|
|
2015-08-31 13:26:40 +02:00
|
|
|
// Also make sure to update the ClientInterface::statenames
|
|
|
|
// array when modifying these enums
|
|
|
|
|
2014-01-31 00:24:00 +01:00
|
|
|
enum ClientState
|
|
|
|
{
|
2014-06-28 08:02:38 +02:00
|
|
|
CS_Invalid,
|
|
|
|
CS_Disconnecting,
|
|
|
|
CS_Denied,
|
|
|
|
CS_Created,
|
2015-04-12 04:49:13 +02:00
|
|
|
CS_AwaitingInit2,
|
|
|
|
CS_HelloSent,
|
2014-06-28 08:02:38 +02:00
|
|
|
CS_InitDone,
|
|
|
|
CS_DefinitionsSent,
|
2015-04-12 04:49:13 +02:00
|
|
|
CS_Active,
|
|
|
|
CS_SudoMode
|
2014-02-13 20:17:42 +01:00
|
|
|
};
|
|
|
|
|
2014-01-31 00:24:00 +01:00
|
|
|
enum ClientStateEvent
|
|
|
|
{
|
2015-04-12 04:49:13 +02:00
|
|
|
CSE_Hello,
|
|
|
|
CSE_AuthAccept,
|
|
|
|
CSE_InitLegacy,
|
2014-06-28 08:02:38 +02:00
|
|
|
CSE_GotInit2,
|
|
|
|
CSE_SetDenied,
|
|
|
|
CSE_SetDefinitionsSent,
|
|
|
|
CSE_SetClientReady,
|
2015-04-12 04:49:13 +02:00
|
|
|
CSE_SudoSuccess,
|
|
|
|
CSE_SudoLeave,
|
2014-06-28 08:02:38 +02:00
|
|
|
CSE_Disconnect
|
2014-01-31 00:24:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
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;
|
|
|
|
|
2015-04-12 04:49:13 +02:00
|
|
|
/* Authentication information */
|
|
|
|
std::string enc_pwd;
|
2015-07-21 17:57:57 +02:00
|
|
|
bool create_player_on_auth_success;
|
2015-04-12 04:49:13 +02:00
|
|
|
AuthMechanism chosen_mech;
|
|
|
|
void * auth_data;
|
|
|
|
u32 allowed_auth_mechs;
|
|
|
|
u32 allowed_sudo_mechs;
|
|
|
|
|
|
|
|
bool isSudoMechAllowed(AuthMechanism mech)
|
|
|
|
{ return allowed_sudo_mechs & mech; }
|
|
|
|
bool isMechAllowed(AuthMechanism mech)
|
|
|
|
{ return allowed_auth_mechs & mech; }
|
|
|
|
|
2014-01-31 00:24:00 +01:00
|
|
|
RemoteClient():
|
|
|
|
peer_id(PEER_ID_INEXISTENT),
|
|
|
|
serialization_version(SER_FMT_VER_INVALID),
|
|
|
|
net_proto_version(0),
|
2015-07-21 17:57:57 +02:00
|
|
|
create_player_on_auth_success(false),
|
2015-04-12 04:49:13 +02:00
|
|
|
chosen_mech(AUTH_MECHANISM_NONE),
|
|
|
|
auth_data(NULL),
|
2014-01-31 00:24:00 +01:00
|
|
|
m_time_from_building(9999),
|
|
|
|
m_pending_serialization_version(SER_FMT_VER_INVALID),
|
2014-06-28 08:02:38 +02:00
|
|
|
m_state(CS_Created),
|
2014-01-31 00:24:00 +01:00
|
|
|
m_nearest_unsent_d(0),
|
|
|
|
m_nearest_unsent_reset_timer(0.0),
|
|
|
|
m_excess_gotblocks(0),
|
|
|
|
m_nothing_to_send_pause_timer(0.0),
|
2014-02-13 20:17:42 +01:00
|
|
|
m_name(""),
|
|
|
|
m_version_major(0),
|
|
|
|
m_version_minor(0),
|
|
|
|
m_version_patch(0),
|
|
|
|
m_full_version("unknown"),
|
2015-05-16 22:14:15 +02:00
|
|
|
m_deployed_compression(0),
|
2017-05-26 14:03:36 +02:00
|
|
|
m_connection_time(porting::getTimeS())
|
2014-01-31 00:24:00 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
~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<PrioritySortedBlockTransfer> &dest);
|
|
|
|
|
|
|
|
void GotBlock(v3s16 p);
|
|
|
|
|
|
|
|
void SentBlock(v3s16 p);
|
|
|
|
|
|
|
|
void SetBlockNotSent(v3s16 p);
|
|
|
|
void SetBlocksNotSent(std::map<v3s16, MapBlock*> &blocks);
|
|
|
|
|
2014-07-12 20:20:11 +02:00
|
|
|
/**
|
|
|
|
* tell client about this block being modified right now.
|
|
|
|
* this information is required to requeue the block in case it's "on wire"
|
|
|
|
* while modification is processed by server
|
|
|
|
* @param p position of modified block
|
|
|
|
*/
|
|
|
|
void ResendBlockIfOnWire(v3s16 p);
|
|
|
|
|
2014-01-31 00:24:00 +01:00
|
|
|
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 "<<peer_id<<": "
|
|
|
|
<<"m_blocks_sent.size()="<<m_blocks_sent.size()
|
|
|
|
<<", m_blocks_sending.size()="<<m_blocks_sending.size()
|
|
|
|
<<", m_nearest_unsent_d="<<m_nearest_unsent_d
|
|
|
|
<<", m_excess_gotblocks="<<m_excess_gotblocks
|
|
|
|
<<std::endl;
|
|
|
|
m_excess_gotblocks = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Time from last placing or removing blocks
|
|
|
|
float m_time_from_building;
|
|
|
|
|
|
|
|
/*
|
|
|
|
List of active objects that the client knows of.
|
|
|
|
*/
|
|
|
|
std::set<u16> m_known_objects;
|
|
|
|
|
2017-04-20 00:12:52 +02:00
|
|
|
ClientState getState() const { return m_state; }
|
2014-01-31 00:24:00 +01:00
|
|
|
|
2017-04-20 00:12:52 +02:00
|
|
|
std::string getName() const { return m_name; }
|
2014-01-31 00:24:00 +01:00
|
|
|
|
2017-04-20 00:12:52 +02:00
|
|
|
void setName(const std::string &name) { m_name = name; }
|
2014-01-31 00:24:00 +01:00
|
|
|
|
|
|
|
/* update internal client state */
|
|
|
|
void notifyEvent(ClientStateEvent event);
|
|
|
|
|
|
|
|
/* set expected serialization version */
|
|
|
|
void setPendingSerializationVersion(u8 version)
|
|
|
|
{ m_pending_serialization_version = version; }
|
|
|
|
|
2015-05-16 22:14:15 +02:00
|
|
|
void setDeployedCompressionMode(u16 byteFlag)
|
|
|
|
{ m_deployed_compression = byteFlag; }
|
2015-03-13 16:35:21 +01:00
|
|
|
|
2014-01-31 00:24:00 +01:00
|
|
|
void confirmSerializationVersion()
|
|
|
|
{ serialization_version = m_pending_serialization_version; }
|
|
|
|
|
2014-02-13 20:17:42 +01:00
|
|
|
/* get uptime */
|
2017-05-26 14:03:36 +02:00
|
|
|
u64 uptime() const;
|
2014-02-13 20:17:42 +01:00
|
|
|
|
|
|
|
/* set version information */
|
2017-04-20 00:12:52 +02:00
|
|
|
void setVersionInfo(u8 major, u8 minor, u8 patch, const std::string &full)
|
|
|
|
{
|
2014-02-13 20:17:42 +01:00
|
|
|
m_version_major = major;
|
|
|
|
m_version_minor = minor;
|
|
|
|
m_version_patch = patch;
|
|
|
|
m_full_version = full;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read version information */
|
2017-04-20 00:12:52 +02:00
|
|
|
u8 getMajor() const { return m_version_major; }
|
|
|
|
u8 getMinor() const { return m_version_minor; }
|
|
|
|
u8 getPatch() const { return m_version_patch; }
|
2014-01-31 00:24:00 +01:00
|
|
|
private:
|
|
|
|
// Version is stored in here after INIT before INIT2
|
|
|
|
u8 m_pending_serialization_version;
|
|
|
|
|
|
|
|
/* current state of client */
|
|
|
|
ClientState m_state;
|
|
|
|
|
|
|
|
/*
|
|
|
|
Blocks that have been sent to client.
|
|
|
|
- These don't have to be sent again.
|
|
|
|
- A block is cleared from here when client says it has
|
|
|
|
deleted it from it's memory
|
|
|
|
|
2016-02-16 23:58:30 +01:00
|
|
|
List of block positions.
|
2014-01-31 00:24:00 +01:00
|
|
|
No MapBlock* is stored here because the blocks can get deleted.
|
|
|
|
*/
|
|
|
|
std::set<v3s16> m_blocks_sent;
|
|
|
|
s16 m_nearest_unsent_d;
|
|
|
|
v3s16 m_last_center;
|
|
|
|
float m_nearest_unsent_reset_timer;
|
|
|
|
|
|
|
|
/*
|
|
|
|
Blocks that are currently on the line.
|
|
|
|
This is used for throttling the sending of blocks.
|
|
|
|
- The size of this list is limited to some value
|
|
|
|
Block is added when it is sent with BLOCKDATA.
|
|
|
|
Block is removed when GOTBLOCKS is received.
|
|
|
|
Value is time from sending. (not used at the moment)
|
|
|
|
*/
|
|
|
|
std::map<v3s16, float> m_blocks_sending;
|
|
|
|
|
2016-02-15 16:05:40 +01:00
|
|
|
/*
|
|
|
|
Blocks that have been modified since last sending them.
|
|
|
|
These blocks will not be marked as sent, even if the
|
|
|
|
client reports it has received them to account for blocks
|
|
|
|
that are being modified while on the line.
|
|
|
|
|
|
|
|
List of block positions.
|
|
|
|
*/
|
|
|
|
std::set<v3s16> m_blocks_modified;
|
|
|
|
|
2014-01-31 00:24:00 +01:00
|
|
|
/*
|
|
|
|
Count of excess GotBlocks().
|
|
|
|
There is an excess amount because the client sometimes
|
|
|
|
gets a block so late that the server sends it again,
|
|
|
|
and the client then sends two GOTBLOCKs.
|
|
|
|
This is resetted by PrintInfo()
|
|
|
|
*/
|
|
|
|
u32 m_excess_gotblocks;
|
|
|
|
|
|
|
|
// CPU usage optimization
|
|
|
|
float m_nothing_to_send_pause_timer;
|
2014-02-13 20:17:42 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
name of player using this client
|
|
|
|
*/
|
2014-01-31 00:24:00 +01:00
|
|
|
std::string m_name;
|
2014-02-13 20:17:42 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
client information
|
|
|
|
*/
|
|
|
|
u8 m_version_major;
|
|
|
|
u8 m_version_minor;
|
|
|
|
u8 m_version_patch;
|
|
|
|
|
|
|
|
std::string m_full_version;
|
|
|
|
|
2015-05-16 22:14:15 +02:00
|
|
|
u16 m_deployed_compression;
|
2015-03-13 16:35:21 +01:00
|
|
|
|
2014-02-13 20:17:42 +01:00
|
|
|
/*
|
|
|
|
time this client was created
|
|
|
|
*/
|
2017-05-26 14:03:36 +02:00
|
|
|
const u64 m_connection_time;
|
2014-01-31 00:24:00 +01:00
|
|
|
};
|
|
|
|
|
2017-06-04 21:00:04 +02:00
|
|
|
typedef std::unordered_map<u16, RemoteClient*> RemoteClientMap;
|
|
|
|
|
2014-01-31 00:24:00 +01:00
|
|
|
class ClientInterface {
|
|
|
|
public:
|
|
|
|
|
|
|
|
friend class Server;
|
|
|
|
|
|
|
|
ClientInterface(con::Connection* con);
|
|
|
|
~ClientInterface();
|
|
|
|
|
|
|
|
/* run sync step */
|
|
|
|
void step(float dtime);
|
|
|
|
|
|
|
|
/* get list of active client id's */
|
2015-03-04 16:30:24 +01:00
|
|
|
std::vector<u16> getClientIDs(ClientState min_state=CS_Active);
|
2014-01-31 00:24:00 +01:00
|
|
|
|
|
|
|
/* get list of client player names */
|
2016-10-08 16:42:09 +02:00
|
|
|
const std::vector<std::string> &getPlayerNames() const { return m_clients_names; }
|
2014-01-31 00:24:00 +01:00
|
|
|
|
|
|
|
/* send message to client */
|
2015-03-13 22:01:49 +01:00
|
|
|
void send(u16 peer_id, u8 channelnum, NetworkPacket* pkt, bool reliable);
|
2014-01-31 00:24:00 +01:00
|
|
|
|
|
|
|
/* send to all clients */
|
2017-04-14 15:34:01 +02:00
|
|
|
void sendToAll(NetworkPacket *pkt);
|
2014-01-31 00:24:00 +01:00
|
|
|
|
|
|
|
/* delete a client */
|
|
|
|
void DeleteClient(u16 peer_id);
|
|
|
|
|
|
|
|
/* create client */
|
|
|
|
void CreateClient(u16 peer_id);
|
|
|
|
|
|
|
|
/* get a client by peer_id */
|
2014-06-28 08:02:38 +02:00
|
|
|
RemoteClient* getClientNoEx(u16 peer_id, ClientState state_min=CS_Active);
|
2014-01-31 00:24:00 +01:00
|
|
|
|
|
|
|
/* get client by peer_id (make sure you have list lock before!*/
|
2014-06-28 08:02:38 +02:00
|
|
|
RemoteClient* lockedGetClientNoEx(u16 peer_id, ClientState state_min=CS_Active);
|
2014-01-31 00:24:00 +01:00
|
|
|
|
|
|
|
/* get state of client by id*/
|
|
|
|
ClientState getClientState(u16 peer_id);
|
|
|
|
|
|
|
|
/* set client playername */
|
|
|
|
void setPlayerName(u16 peer_id,std::string name);
|
|
|
|
|
|
|
|
/* get protocol version of client */
|
|
|
|
u16 getProtocolVersion(u16 peer_id);
|
|
|
|
|
2014-02-13 20:17:42 +01:00
|
|
|
/* set client version */
|
|
|
|
void setClientVersion(u16 peer_id, u8 major, u8 minor, u8 patch, std::string full);
|
|
|
|
|
2014-01-31 00:24:00 +01:00
|
|
|
/* event to update client state */
|
|
|
|
void event(u16 peer_id, ClientStateEvent event);
|
|
|
|
|
2015-03-06 11:21:51 +01:00
|
|
|
/* Set environment. Do not call this function if environment is already set */
|
|
|
|
void setEnv(ServerEnvironment *env)
|
|
|
|
{
|
|
|
|
assert(m_env == NULL); // pre-condition
|
|
|
|
m_env = env;
|
|
|
|
}
|
2014-01-31 00:24:00 +01:00
|
|
|
|
2014-06-28 08:02:38 +02:00
|
|
|
static std::string state2Name(ClientState state);
|
2014-02-13 20:17:42 +01:00
|
|
|
|
2014-01-31 00:24:00 +01:00
|
|
|
protected:
|
|
|
|
//TODO find way to avoid this functions
|
2015-04-07 12:13:12 +02:00
|
|
|
void lock() { m_clients_mutex.lock(); }
|
|
|
|
void unlock() { m_clients_mutex.unlock(); }
|
2014-01-31 00:24:00 +01:00
|
|
|
|
2017-06-04 21:00:04 +02:00
|
|
|
RemoteClientMap& getClientList() { return m_clients; }
|
2014-01-31 00:24:00 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
/* update internal player list */
|
|
|
|
void UpdatePlayerList();
|
|
|
|
|
|
|
|
// Connection
|
|
|
|
con::Connection* m_con;
|
2017-06-06 16:29:28 +02:00
|
|
|
std::mutex m_clients_mutex;
|
2014-01-31 00:24:00 +01:00
|
|
|
// Connected clients (behind the con mutex)
|
2017-06-04 21:00:04 +02:00
|
|
|
RemoteClientMap m_clients;
|
2014-01-31 00:24:00 +01:00
|
|
|
std::vector<std::string> m_clients_names; //for announcing masterserver
|
|
|
|
|
|
|
|
// Environment
|
|
|
|
ServerEnvironment *m_env;
|
2017-06-06 16:29:28 +02:00
|
|
|
std::mutex m_env_mutex;
|
2014-01-31 00:24:00 +01:00
|
|
|
|
|
|
|
float m_print_info_timer;
|
[Patch 2/4] Network rework: packet writing, sending and cleanups
NetworkPacket.cpp:
* Remove some deprecated functions, we must use streaming interface
* m_data converted from u8* to std::vector<u8>
* Add an exporter to forge packet to Connection object
* implement operator << std::wstring. n
* implement operator << std::string
* dynamic resize when write packet content.
* fix string writing and performances.
* create ServerCommandFactory, used by client to get useful informations about packet processing (sending).
* Reliability
* Transmit channel
* Implement putRawString for some ugly char (_INIT packet), and use it.
* Many packet read and write migrated
* Implement oldForgePacket to interface writing with current connection
* fix U8/char/bool writing
* fix string writing and performances.
* add some missing functions
* Use v3s16 read instead of reading x,y,z separately
* Add irr::video::SColor support into packets
* Add some missing handlers
* Add a template function to increase offset
* Throw a serialization error on packet reading (must be improved)
PacketFactories:
* Create ServerCommandFactory, used by client to get useful informations about packet processing (sending).
* Create ClientCommandFactory, used by server to get useful informations about packet processing (sending).
Client.cpp:
* implement NetworkPacket ::Send interface.
* Move packet handlers to a dedicated file
* Remove Client::Send(SharedBuffer)
Server.cpp:
* implement NetworkPacket ::Send interface.
* Rewrite all packets using NetworkPacket
* Move packet handlers to a dedicated file
* Remove Server::Send(SharedBuffer)
ClientIface.cpp:
* Remove sendToAll(SharedBuffer<u8>)
Connection.hpp rework:
* Remove duplicate include
* Remove duplicate negation
* Remove a useless variable
* Improve code performance by using a m_peers_list instead of scanning m_peers map
* Remove Connection::Send(SharedBuffer)
* Fix useafterfree into NetworkPacket Sending
* Remove unused Connection::sendToAll
Test.cpp:
* Remove dead code
* Update tests to use NetworkPackets
Misc:
* add new wrappers to Send packets in client, using NetworkPacket
* Add NetworkPacket methods for Connection
* coding style fix
* dead code since changes cleanup
* Use v3s16 read instead of reading x,y,z separately in some packets
* Use different files to handle packets received by client and server
* Cleanup: Remove useless includes
ok @Zeno-
Tested by @Zeno- @VanessaE and @nerzhul on running servers
2015-01-16 11:37:49 +01:00
|
|
|
|
2014-06-28 08:02:38 +02:00
|
|
|
static const char *statenames[];
|
2014-01-31 00:24:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|