2010-11-29 19:13:04 +01:00
|
|
|
/*
|
2013-02-24 18:40:43 +01:00
|
|
|
Minetest
|
2013-02-24 19:38:45 +01:00
|
|
|
Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
|
2010-11-29 19:13:04 +01:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
2012-06-05 16:56:56 +02:00
|
|
|
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
|
2010-11-29 19:13:04 +01:00
|
|
|
(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
|
2012-06-05 16:56:56 +02:00
|
|
|
GNU Lesser General Public License for more details.
|
2010-11-29 19:13:04 +01:00
|
|
|
|
2012-06-05 16:56:56 +02:00
|
|
|
You should have received a copy of the GNU Lesser General Public License along
|
2010-11-29 19:13:04 +01:00
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2017-08-17 22:19:39 +02:00
|
|
|
#pragma once
|
2010-11-27 00:02:21 +01:00
|
|
|
|
2013-08-11 04:09:45 +02:00
|
|
|
#include "irr_v3d.h"
|
2011-02-23 01:49:57 +01:00
|
|
|
#include "map.h"
|
2013-04-14 00:20:22 +02:00
|
|
|
#include "hud.h"
|
2011-11-13 23:19:48 +01:00
|
|
|
#include "gamedef.h"
|
2011-11-15 20:00:39 +01:00
|
|
|
#include "serialization.h" // For SER_FMT_VER_INVALID
|
2018-04-17 15:54:50 +02:00
|
|
|
#include "content/mods.h"
|
2011-12-06 14:21:56 +01:00
|
|
|
#include "inventorymanager.h"
|
2018-04-17 15:54:50 +02:00
|
|
|
#include "content/subgames.h"
|
2020-05-22 13:23:25 +02:00
|
|
|
#include "tileanimation.h" // TileAnimationParams
|
|
|
|
#include "particles.h" // ParticleParams
|
2017-08-24 08:28:54 +02:00
|
|
|
#include "network/peerhandler.h"
|
|
|
|
#include "network/address.h"
|
2013-08-11 04:09:45 +02:00
|
|
|
#include "util/numeric.h"
|
|
|
|
#include "util/thread.h"
|
2016-12-13 23:16:26 +01:00
|
|
|
#include "util/basic_macros.h"
|
2020-04-27 08:31:37 +02:00
|
|
|
#include "util/metricsbackend.h"
|
2017-01-08 11:01:35 +01:00
|
|
|
#include "serverenvironment.h"
|
2014-01-31 00:24:00 +01:00
|
|
|
#include "clientiface.h"
|
2017-07-16 10:47:31 +02:00
|
|
|
#include "chatmessage.h"
|
2020-09-16 15:51:11 +02:00
|
|
|
#include "translation.h"
|
2013-08-11 04:09:45 +02:00
|
|
|
#include <string>
|
|
|
|
#include <list>
|
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
2021-09-09 16:51:35 +02:00
|
|
|
#include <unordered_set>
|
2012-06-17 01:40:36 +02:00
|
|
|
|
2017-08-16 22:11:45 +02:00
|
|
|
class ChatEvent;
|
|
|
|
struct ChatEventChat;
|
|
|
|
struct ChatInterface;
|
2012-01-12 06:10:39 +01:00
|
|
|
class IWritableItemDefManager;
|
2018-02-10 21:04:16 +01:00
|
|
|
class NodeDefManager;
|
2011-11-17 01:28:46 +01:00
|
|
|
class IWritableCraftDefManager;
|
2013-08-11 04:09:45 +02:00
|
|
|
class BanManager;
|
2012-03-23 19:23:03 +01:00
|
|
|
class EventManager;
|
2013-08-11 04:09:45 +02:00
|
|
|
class Inventory;
|
2017-09-26 00:11:20 +02:00
|
|
|
class ModChannelMgr;
|
2017-08-18 19:25:07 +02:00
|
|
|
class RemotePlayer;
|
2012-03-19 03:04:16 +01:00
|
|
|
class PlayerSAO;
|
2018-03-28 17:05:18 +02:00
|
|
|
struct PlayerHPChangeReason;
|
2012-07-26 21:06:45 +02:00
|
|
|
class IRollbackManager;
|
2014-12-08 09:06:31 +01:00
|
|
|
struct RollbackAction;
|
2013-02-14 04:43:15 +01:00
|
|
|
class EmergeManager;
|
2017-01-21 15:02:08 +01:00
|
|
|
class ServerScripting;
|
2013-08-11 04:09:45 +02:00
|
|
|
class ServerEnvironment;
|
|
|
|
struct SimpleSoundSpec;
|
2018-03-08 22:19:25 +01:00
|
|
|
struct CloudParams;
|
2019-08-21 22:47:45 +02:00
|
|
|
struct SkyboxParams;
|
|
|
|
struct SunParams;
|
|
|
|
struct MoonParams;
|
|
|
|
struct StarParams;
|
2022-03-26 16:58:26 +01:00
|
|
|
struct Lighting;
|
2014-01-31 00:24:00 +01:00
|
|
|
class ServerThread;
|
2018-03-16 08:41:33 +01:00
|
|
|
class ServerModManager;
|
2020-05-07 22:38:41 +02:00
|
|
|
class ServerInventoryManager;
|
2022-05-09 18:20:10 +02:00
|
|
|
struct PackedValue;
|
2013-05-25 00:51:02 +02:00
|
|
|
|
2014-01-31 00:24:00 +01:00
|
|
|
enum ClientDeletionReason {
|
|
|
|
CDR_LEAVE,
|
|
|
|
CDR_TIMEOUT,
|
|
|
|
CDR_DENY
|
|
|
|
};
|
2010-11-27 00:02:21 +01:00
|
|
|
|
2012-03-25 10:50:29 +02:00
|
|
|
struct MediaInfo
|
2012-01-02 12:31:50 +01:00
|
|
|
{
|
|
|
|
std::string path;
|
2021-09-09 16:51:35 +02:00
|
|
|
std::string sha1_digest; // base64-encoded
|
|
|
|
bool no_announce; // true: not announced in TOCLIENT_ANNOUNCE_MEDIA (at player join)
|
2012-01-02 12:31:50 +01:00
|
|
|
|
2014-02-27 21:12:59 +01:00
|
|
|
MediaInfo(const std::string &path_="",
|
|
|
|
const std::string &sha1_digest_=""):
|
2012-01-02 12:31:50 +01:00
|
|
|
path(path_),
|
2021-09-09 16:51:35 +02:00
|
|
|
sha1_digest(sha1_digest_),
|
|
|
|
no_announce(false)
|
2012-01-02 12:31:50 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-06-20 21:56:12 +02:00
|
|
|
// Combines the pure sound (SimpleSoundSpec) with positional information
|
|
|
|
struct ServerPlayingSound
|
2012-03-24 18:01:26 +01:00
|
|
|
{
|
2022-07-09 22:32:24 +02:00
|
|
|
SoundLocation type = SoundLocation::Local;
|
2022-06-20 21:56:12 +02:00
|
|
|
|
|
|
|
float gain = 1.0f; // for amplification of the base sound
|
2017-06-18 19:55:15 +02:00
|
|
|
float max_hear_distance = 32 * BS;
|
|
|
|
v3f pos;
|
2017-06-11 13:58:26 +02:00
|
|
|
u16 object = 0;
|
2022-06-20 21:56:12 +02:00
|
|
|
std::string to_player;
|
|
|
|
std::string exclude_player;
|
2012-12-18 19:23:16 +01:00
|
|
|
|
2012-03-19 03:04:16 +01:00
|
|
|
v3f getPos(ServerEnvironment *env, bool *pos_exists) const;
|
2012-03-24 18:01:26 +01:00
|
|
|
|
2016-07-10 07:08:26 +02:00
|
|
|
SimpleSoundSpec spec;
|
2022-06-20 21:56:12 +02:00
|
|
|
|
2017-09-27 19:47:36 +02:00
|
|
|
std::unordered_set<session_t> clients; // peer ids
|
2012-03-24 18:01:26 +01:00
|
|
|
};
|
|
|
|
|
2020-10-04 15:24:29 +02:00
|
|
|
struct MinimapMode {
|
|
|
|
MinimapType type = MINIMAP_TYPE_OFF;
|
|
|
|
std::string label;
|
|
|
|
u16 size = 0;
|
|
|
|
std::string texture;
|
|
|
|
u16 scale = 1;
|
|
|
|
};
|
|
|
|
|
2021-01-31 20:36:47 +01:00
|
|
|
// structure for everything getClientInfo returns, for convenience
|
|
|
|
struct ClientInfo {
|
|
|
|
ClientState state;
|
|
|
|
Address addr;
|
|
|
|
u32 uptime;
|
|
|
|
u8 ser_vers;
|
|
|
|
u16 prot_vers;
|
|
|
|
u8 major, minor, patch;
|
|
|
|
std::string vers_string, lang_code;
|
|
|
|
};
|
|
|
|
|
2011-04-04 14:13:19 +02:00
|
|
|
class Server : public con::PeerHandler, public MapEventReceiver,
|
2020-05-07 22:38:41 +02:00
|
|
|
public IGameDef
|
2010-11-27 00:02:21 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/*
|
|
|
|
NOTE: Every public method should be thread-safe
|
|
|
|
*/
|
2012-12-18 19:23:16 +01:00
|
|
|
|
2010-11-27 00:02:21 +01:00
|
|
|
Server(
|
2012-03-11 13:54:23 +01:00
|
|
|
const std::string &path_world,
|
2012-03-15 14:20:20 +01:00
|
|
|
const SubgameSpec &gamespec,
|
2014-03-07 01:00:03 +01:00
|
|
|
bool simple_singleplayer_mode,
|
2017-09-28 13:47:30 +02:00
|
|
|
Address bind_addr,
|
2015-10-15 19:04:15 +02:00
|
|
|
bool dedicated,
|
2020-08-23 19:44:25 +02:00
|
|
|
ChatInterface *iface = nullptr,
|
|
|
|
std::string *on_shutdown_errmsg = nullptr
|
2010-11-29 09:52:07 +01:00
|
|
|
);
|
2010-11-27 00:02:21 +01:00
|
|
|
~Server();
|
2017-06-10 13:49:15 +02:00
|
|
|
DISABLE_CLASS_COPY(Server);
|
|
|
|
|
2017-09-28 13:47:30 +02:00
|
|
|
void start();
|
2010-11-27 00:02:21 +01:00
|
|
|
void stop();
|
2010-11-29 09:52:07 +01:00
|
|
|
// This is mainly a way to pass the time to the server.
|
|
|
|
// Actual processing is done in an another thread.
|
2010-11-27 00:02:21 +01:00
|
|
|
void step(float dtime);
|
2010-11-29 09:52:07 +01:00
|
|
|
// This is run by ServerThread and does the actual processing
|
2014-01-06 20:05:28 +01:00
|
|
|
void AsyncRunStep(bool initial_step=false);
|
2010-11-27 00:02:21 +01:00
|
|
|
void Receive();
|
2017-09-27 19:47:36 +02:00
|
|
|
PlayerSAO* StageTwoClientInit(session_t peer_id);
|
2015-01-12 17:01:41 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Command Handlers
|
|
|
|
*/
|
|
|
|
|
[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
|
|
|
void handleCommand(NetworkPacket* pkt);
|
|
|
|
|
|
|
|
void handleCommand_Null(NetworkPacket* pkt) {};
|
|
|
|
void handleCommand_Deprecated(NetworkPacket* pkt);
|
2015-03-13 16:35:21 +01:00
|
|
|
void handleCommand_Init(NetworkPacket* pkt);
|
[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
|
|
|
void handleCommand_Init2(NetworkPacket* pkt);
|
2017-09-26 00:11:20 +02:00
|
|
|
void handleCommand_ModChannelJoin(NetworkPacket *pkt);
|
|
|
|
void handleCommand_ModChannelLeave(NetworkPacket *pkt);
|
|
|
|
void handleCommand_ModChannelMsg(NetworkPacket *pkt);
|
[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
|
|
|
void handleCommand_RequestMedia(NetworkPacket* pkt);
|
|
|
|
void handleCommand_ClientReady(NetworkPacket* pkt);
|
|
|
|
void handleCommand_GotBlocks(NetworkPacket* pkt);
|
|
|
|
void handleCommand_PlayerPos(NetworkPacket* pkt);
|
|
|
|
void handleCommand_DeletedBlocks(NetworkPacket* pkt);
|
|
|
|
void handleCommand_InventoryAction(NetworkPacket* pkt);
|
|
|
|
void handleCommand_ChatMessage(NetworkPacket* pkt);
|
|
|
|
void handleCommand_Damage(NetworkPacket* pkt);
|
|
|
|
void handleCommand_PlayerItem(NetworkPacket* pkt);
|
|
|
|
void handleCommand_Respawn(NetworkPacket* pkt);
|
|
|
|
void handleCommand_Interact(NetworkPacket* pkt);
|
|
|
|
void handleCommand_RemovedSounds(NetworkPacket* pkt);
|
|
|
|
void handleCommand_NodeMetaFields(NetworkPacket* pkt);
|
|
|
|
void handleCommand_InventoryFields(NetworkPacket* pkt);
|
2015-04-12 04:49:13 +02:00
|
|
|
void handleCommand_FirstSrp(NetworkPacket* pkt);
|
|
|
|
void handleCommand_SrpBytesA(NetworkPacket* pkt);
|
|
|
|
void handleCommand_SrpBytesM(NetworkPacket* pkt);
|
2021-09-09 16:51:35 +02:00
|
|
|
void handleCommand_HaveMedia(NetworkPacket *pkt);
|
2015-01-12 17:01:41 +01:00
|
|
|
|
2015-03-31 10:35:51 +02:00
|
|
|
void ProcessData(NetworkPacket *pkt);
|
2010-11-27 00:02:21 +01:00
|
|
|
|
2017-09-26 00:11:20 +02:00
|
|
|
void Send(NetworkPacket *pkt);
|
2017-09-27 19:47:36 +02:00
|
|
|
void Send(session_t peer_id, NetworkPacket *pkt);
|
[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
|
|
|
|
2016-11-12 08:22:39 +01:00
|
|
|
// Helper for handleCommand_PlayerPos and handleCommand_Interact
|
|
|
|
void process_PlayerPos(RemotePlayer *player, PlayerSAO *playersao,
|
|
|
|
NetworkPacket *pkt);
|
|
|
|
|
2015-10-27 21:03:59 +01:00
|
|
|
// Both setter and getter need no envlock,
|
|
|
|
// can be called freely from threads
|
2013-08-11 04:09:45 +02:00
|
|
|
void setTimeOfDay(u32 time);
|
2011-05-16 11:41:19 +02:00
|
|
|
|
2011-02-23 01:49:57 +01:00
|
|
|
/*
|
|
|
|
Shall be called with the environment locked.
|
|
|
|
This is accessed by the map, which is inside the environment,
|
|
|
|
so it shouldn't be a problem.
|
|
|
|
*/
|
2019-09-24 19:05:28 +02:00
|
|
|
void onMapEditEvent(const MapEditEvent &event);
|
2011-02-15 15:11:24 +01:00
|
|
|
|
2011-05-16 11:41:19 +02:00
|
|
|
// Connection must be locked when called
|
2021-01-29 14:03:27 +01:00
|
|
|
std::string getStatusString();
|
2020-04-27 08:31:37 +02:00
|
|
|
inline double getUptime() const { return m_uptime_counter->get(); }
|
2011-05-16 11:41:19 +02:00
|
|
|
|
2014-01-31 00:24:00 +01:00
|
|
|
// read shutdown state
|
2018-06-13 21:58:34 +02:00
|
|
|
inline bool isShutdownRequested() const { return m_shutdown_state.is_requested; }
|
2014-01-31 00:24:00 +01:00
|
|
|
|
|
|
|
// request server to shutdown
|
2017-04-15 23:19:18 +02:00
|
|
|
void requestShutdown(const std::string &msg, bool reconnect, float delay = 0.0f);
|
2011-05-16 11:41:19 +02:00
|
|
|
|
2012-03-24 18:01:26 +01:00
|
|
|
// Returns -1 if failed, sound handle on success
|
2014-01-31 00:24:00 +01:00
|
|
|
// Envlock
|
2022-06-20 21:56:12 +02:00
|
|
|
s32 playSound(ServerPlayingSound ¶ms, bool ephemeral=false);
|
2012-03-24 18:01:26 +01:00
|
|
|
void stopSound(s32 handle);
|
2016-07-10 07:08:26 +02:00
|
|
|
void fadeSound(s32 handle, float step, float gain);
|
2012-12-18 19:23:16 +01:00
|
|
|
|
2014-01-31 00:24:00 +01:00
|
|
|
// Envlock
|
2012-03-30 17:42:18 +02:00
|
|
|
std::set<std::string> getPlayerEffectivePrivs(const std::string &name);
|
|
|
|
bool checkPriv(const std::string &name, const std::string &priv);
|
2012-03-31 15:23:26 +02:00
|
|
|
void reportPrivsModified(const std::string &name=""); // ""=all
|
2012-07-19 13:09:16 +02:00
|
|
|
void reportInventoryFormspecModified(const std::string &name);
|
2018-03-28 17:04:41 +02:00
|
|
|
void reportFormspecPrependModified(const std::string &name);
|
2011-11-20 20:16:15 +01:00
|
|
|
|
2013-08-11 04:09:45 +02:00
|
|
|
void setIpBanned(const std::string &ip, const std::string &name);
|
|
|
|
void unsetIpBanned(const std::string &ip_or_name);
|
|
|
|
std::string getBanDescription(const std::string &ip_or_name);
|
2011-08-12 12:11:27 +02:00
|
|
|
|
2014-02-27 21:12:59 +01:00
|
|
|
void notifyPlayer(const char *name, const std::wstring &msg);
|
|
|
|
void notifyPlayers(const std::wstring &msg);
|
2020-05-22 13:23:25 +02:00
|
|
|
|
2015-07-25 11:56:24 +02:00
|
|
|
void spawnParticle(const std::string &playername,
|
2020-05-22 13:23:25 +02:00
|
|
|
const ParticleParameters &p);
|
|
|
|
|
|
|
|
u32 addParticleSpawner(const ParticleSpawnerParameters &p,
|
|
|
|
ServerActiveObject *attached, const std::string &playername);
|
2013-01-23 18:32:02 +01:00
|
|
|
|
2015-07-25 11:56:24 +02:00
|
|
|
void deleteParticleSpawner(const std::string &playername, u32 id);
|
2013-01-23 18:32:02 +01:00
|
|
|
|
2021-09-09 16:51:35 +02:00
|
|
|
bool dynamicAddMedia(std::string filepath, u32 token,
|
|
|
|
const std::string &to_player, bool ephemeral);
|
2020-06-13 19:03:26 +02:00
|
|
|
|
2020-05-07 22:38:41 +02:00
|
|
|
ServerInventoryManager *getInventoryMgr() const { return m_inventory_mgr.get(); }
|
|
|
|
void sendDetachedInventory(Inventory *inventory, const std::string &name, session_t peer_id);
|
2012-12-18 19:23:16 +01:00
|
|
|
|
2013-05-25 00:51:02 +02:00
|
|
|
// Envlock and conlock should be locked when using scriptapi
|
2017-01-21 15:02:08 +01:00
|
|
|
ServerScripting *getScriptIface(){ return m_script; }
|
2012-07-26 21:06:45 +02:00
|
|
|
|
|
|
|
// actions: time-reversed list
|
|
|
|
// Return value: success/failure
|
|
|
|
bool rollbackRevertActions(const std::list<RollbackAction> &actions,
|
|
|
|
std::list<std::string> *log);
|
2012-12-18 19:23:16 +01:00
|
|
|
|
2011-11-13 23:19:48 +01:00
|
|
|
// IGameDef interface
|
|
|
|
// Under envlock
|
2012-01-12 06:10:39 +01:00
|
|
|
virtual IItemDefManager* getItemDefManager();
|
2018-02-10 21:04:16 +01:00
|
|
|
virtual const NodeDefManager* getNodeDefManager();
|
2011-11-17 01:28:46 +01:00
|
|
|
virtual ICraftDefManager* getCraftDefManager();
|
2011-11-16 12:03:28 +01:00
|
|
|
virtual u16 allocateUnknownNodeId(const std::string &name);
|
2017-01-09 20:39:22 +01:00
|
|
|
IRollbackManager *getRollbackManager() { return m_rollback; }
|
2015-04-17 05:37:50 +02:00
|
|
|
virtual EmergeManager *getEmergeManager() { return m_emerge; }
|
2022-01-07 19:28:49 +01:00
|
|
|
virtual ModMetadataDatabase *getModStorageDatabase() { return m_mod_storage_database; }
|
2014-06-26 02:28:41 +02:00
|
|
|
|
2012-01-12 06:10:39 +01:00
|
|
|
IWritableItemDefManager* getWritableItemDefManager();
|
2018-02-10 21:04:16 +01:00
|
|
|
NodeDefManager* getWritableNodeDefManager();
|
2011-11-17 01:28:46 +01:00
|
|
|
IWritableCraftDefManager* getWritableCraftDefManager();
|
2011-08-12 01:13:42 +02:00
|
|
|
|
2018-03-16 08:41:33 +01:00
|
|
|
virtual const std::vector<ModSpec> &getMods() const;
|
2017-01-21 15:02:08 +01:00
|
|
|
virtual const ModSpec* getModSpec(const std::string &modname) const;
|
2022-05-02 20:55:04 +02:00
|
|
|
static std::string getBuiltinLuaPath();
|
2017-03-16 07:53:39 +01:00
|
|
|
virtual std::string getWorldPath() const { return m_path_world; }
|
2012-12-18 19:23:16 +01:00
|
|
|
|
2022-04-09 14:47:59 +02:00
|
|
|
inline bool isSingleplayer() const
|
2014-01-31 00:24:00 +01:00
|
|
|
{ return m_simple_singleplayer_mode; }
|
2012-03-28 12:22:48 +02:00
|
|
|
|
2014-01-31 00:24:00 +01:00
|
|
|
inline void setAsyncFatalError(const std::string &error)
|
|
|
|
{ m_async_fatal_error.set(error); }
|
2021-09-10 23:16:46 +02:00
|
|
|
inline void setAsyncFatalError(const LuaError &e)
|
|
|
|
{
|
|
|
|
setAsyncFatalError(std::string("Lua: ") + e.what());
|
|
|
|
}
|
2012-03-11 19:45:43 +01:00
|
|
|
|
2013-01-03 18:59:28 +01:00
|
|
|
bool showFormspec(const char *name, const std::string &formspec, const std::string &formname);
|
2012-10-22 23:18:44 +02:00
|
|
|
Map & getMap() { return m_env->getMap(); }
|
2013-09-17 04:52:24 +02:00
|
|
|
ServerEnvironment & getEnv() { return *m_env; }
|
2017-04-23 14:35:08 +02:00
|
|
|
v3f findSpawnPos();
|
2015-01-12 17:01:41 +01:00
|
|
|
|
2016-10-08 12:21:41 +02:00
|
|
|
u32 hudAdd(RemotePlayer *player, HudElement *element);
|
|
|
|
bool hudRemove(RemotePlayer *player, u32 id);
|
|
|
|
bool hudChange(RemotePlayer *player, u32 id, HudElementStat stat, void *value);
|
2016-10-08 10:38:04 +02:00
|
|
|
bool hudSetFlags(RemotePlayer *player, u32 flags, u32 mask);
|
|
|
|
bool hudSetHotbarItemcount(RemotePlayer *player, s32 hotbar_itemcount);
|
Optimize string (mis)handling (#8128)
* Optimize statbar drawing
The texture name of the statbar is a string passed by value.
That slows down the client and creates litter in the heap
as the content of the string is allocated there. Convert the
offending parameter to a const reference to avoid the
performance hit.
* Optimize texture cache
There is an unnecessary temporary created when the texture
path is being generated. This slows down the cache each time
a new texture is encountered and it needs to be loaded into
the cache. Additionally, the heap litter created by this
unnecessary temporary is particularly troublesome here as
the following code then piles another string (the resulting
full path of the texture) on top of it, followed by the
texture itself, which both are quite long term objects as
they are subsequently inserted into the cache where they can
remain for quite a while (especially if the texture turns
out to be a common one like dirt, grass or stone).
Use std::string.append to get rid of the temporary which
solves both issues (speed and heap fragmentation).
* Optimize animations in client
Each time an animated node is updated, an unnecessary copy of
the texture name is created, littering the heap with lots of
fragments. This can be specifically troublesome when looking
at oceans or large lava lakes as both of these nodes are
usually animated (the lava animation is pretty visible).
Convert the parameter of GenericCAO::updateTextures to a
const reference to get rid of the unnecessary copy.
There is a comment stating "std::string copy is mandatory as
mod can be a class member and there is a swap on those class
members ... do NOT pass by reference", reinforcing the
belief that the unnecessary copy is in fact necessary.
However one of the first things the code of the method does
is to assign the parameter to its class member, creating
another copy. By rearranging the code a little bit this
"another copy" can then be used by the subsequent code,
getting rid of the need to pass the parameter by value and
thus saving that copying effort.
* Optimize chat console history handling
The GUIChatConsole::replaceAndAddToHistory was getting the
line to work on by value which turns out to be unnecessary.
Get rid of that unnecessary copy by converting the parameter
to a const reference.
* Optimize gui texture setting
The code used to set the texture for GUI components was
getting the name of the texture by value, creating
unnecessary performance bottleneck for mods/games with
heavily textured GUIs. Get rid of the bottleneck by passing
the texture name as a const reference.
* Optimize sound playing code in GUIEngine
The GUIEngine's code receives the specification of the sound
to be played by value, which turns out to be most likely a
mistake as the underlying sound manager interface receives
the same thing by reference. Convert the offending parameter
to a const reference to get rid of the rather bulky copying
effort and the associated performance hit.
* Silence CLANG TIDY warnings for unit tests
Change "std::string" to "const std::string &" to avoid an
unnecessary local value copy, silencing the CLANG TIDY
process.
* Optimize formspec handling
The "formspec prepend" parameter was passed to the formspec
handling code by value, creating unnecessary copy of
std::string and slowing down the game if mods add things like
textured backgrounds for the player inventory and/or other
forms. Get rid of that performance bottleneck by converting
the parameter to a const reference.
* Optimize hotbar image handling
The code that sets the background images for the hotbar is
getting the name of the image by value, creating an
unnecessary std::string copying effort. Fix that by
converting the relevant parameters to const references.
* Optimize inventory deserialization
The inventory manager deserialization code gets the
serialized version of the inventory by value, slowing the
server and the client down when there are inventory updates.
This can get particularly troublesome with pipeworks which
adds nodes that can mess around with inventories
automatically or with mods that have mobs with inventories
that actively use them.
* Optimize texture scaling cache
There is an io::path parameter passed by value in the
procedure used to add images converted from textures,
leading to slowdown when the image is not yet created and
the conversion is thus needed. The performance hit is
quite significant as io::path is similar to std::string
so convert the parameter to a const reference to get rid of
it.
* Optimize translation file loader
Use "std::string::append" when calculating the final index
for the translation table to avoid unnecessary temporary
strings. This speeds the translation file loader up
significantly as std::string uses heap allocation which
tends to be rather slow. Additionally, the heap is no
longer being littered by these unnecessary string
temporaries, increasing performance of code that gets
executed after the translation file loader finishes.
* Optimize server map saving
When the directory structure for the world data is created
during server map saving, an unnecessary value passing of
the directory name slows things down. Remove that overhead
by converting the offending parameter to a const reference.
2019-05-18 17:19:13 +02:00
|
|
|
void hudSetHotbarImage(RemotePlayer *player, const std::string &name);
|
|
|
|
void hudSetHotbarSelectedImage(RemotePlayer *player, const std::string &name);
|
2013-09-03 19:51:40 +02:00
|
|
|
|
2017-09-27 19:47:36 +02:00
|
|
|
Address getPeerAddress(session_t peer_id);
|
2015-01-12 17:01:41 +01:00
|
|
|
|
2018-03-08 22:19:25 +01:00
|
|
|
void setLocalPlayerAnimations(RemotePlayer *player, v2s32 animation_frames[4],
|
2016-10-08 12:21:41 +02:00
|
|
|
f32 frame_speed);
|
2018-03-08 22:19:25 +01:00
|
|
|
void setPlayerEyeOffset(RemotePlayer *player, const v3f &first, const v3f &third);
|
2014-01-08 13:47:53 +01:00
|
|
|
|
2019-08-21 22:47:45 +02:00
|
|
|
void setSky(RemotePlayer *player, const SkyboxParams ¶ms);
|
|
|
|
void setSun(RemotePlayer *player, const SunParams ¶ms);
|
|
|
|
void setMoon(RemotePlayer *player, const MoonParams ¶ms);
|
|
|
|
void setStars(RemotePlayer *player, const StarParams ¶ms);
|
|
|
|
|
2018-03-08 22:19:25 +01:00
|
|
|
void setClouds(RemotePlayer *player, const CloudParams ¶ms);
|
2015-01-12 17:01:41 +01:00
|
|
|
|
2020-05-07 22:38:41 +02:00
|
|
|
void overrideDayNightRatio(RemotePlayer *player, bool do_override, float brightness);
|
2010-11-27 00:02:21 +01:00
|
|
|
|
2022-03-26 16:58:26 +01:00
|
|
|
void setLighting(RemotePlayer *player, const Lighting &lighting);
|
|
|
|
|
2022-05-25 19:29:11 +02:00
|
|
|
void RespawnPlayer(session_t peer_id);
|
|
|
|
|
2014-01-31 00:24:00 +01:00
|
|
|
/* con::PeerHandler implementation. */
|
2010-11-27 00:02:21 +01:00
|
|
|
void peerAdded(con::Peer *peer);
|
|
|
|
void deletingPeer(con::Peer *peer, bool timeout);
|
2012-12-18 19:23:16 +01:00
|
|
|
|
2017-09-27 19:47:36 +02:00
|
|
|
void DenySudoAccess(session_t peer_id);
|
|
|
|
void DenyAccess(session_t peer_id, AccessDeniedCode reason,
|
2022-04-27 19:55:13 +02:00
|
|
|
const std::string &custom_reason = "", bool reconnect = false);
|
2017-09-27 19:47:36 +02:00
|
|
|
void acceptAuth(session_t peer_id, bool forSudoMode);
|
|
|
|
void DisconnectPeer(session_t peer_id);
|
|
|
|
bool getClientConInfo(session_t peer_id, con::rtt_stat_type type, float *retval);
|
2021-01-31 20:36:47 +01:00
|
|
|
bool getClientInfo(session_t peer_id, ClientInfo &ret);
|
2014-01-26 18:40:25 +01:00
|
|
|
|
2015-07-25 07:43:32 +02:00
|
|
|
void printToConsoleOnly(const std::string &text);
|
|
|
|
|
2022-01-15 17:44:55 +01:00
|
|
|
void HandlePlayerHPChange(PlayerSAO *sao, const PlayerHPChangeReason &reason);
|
2022-06-11 20:00:40 +02:00
|
|
|
void SendPlayerHP(PlayerSAO *sao, bool effect);
|
2017-01-01 16:13:01 +01:00
|
|
|
void SendPlayerBreath(PlayerSAO *sao);
|
2019-08-24 19:07:38 +02:00
|
|
|
void SendInventory(PlayerSAO *playerSAO, bool incremental);
|
2017-09-27 19:47:36 +02:00
|
|
|
void SendMovePlayer(session_t peer_id);
|
2019-07-16 14:00:42 +02:00
|
|
|
void SendPlayerSpeed(session_t peer_id, const v3f &added_vel);
|
2018-07-15 02:26:30 +02:00
|
|
|
void SendPlayerFov(session_t peer_id);
|
2015-03-04 11:29:34 +01:00
|
|
|
|
2020-10-04 15:24:29 +02:00
|
|
|
void SendMinimapModes(session_t peer_id,
|
|
|
|
std::vector<MinimapMode> &modes,
|
|
|
|
size_t wanted_mode);
|
|
|
|
|
2019-08-25 10:55:27 +02:00
|
|
|
void sendDetachedInventories(session_t peer_id, bool incremental);
|
|
|
|
|
2017-09-26 00:11:20 +02:00
|
|
|
bool joinModChannel(const std::string &channel);
|
|
|
|
bool leaveModChannel(const std::string &channel);
|
|
|
|
bool sendModChannelMessage(const std::string &channel, const std::string &message);
|
|
|
|
ModChannel *getModChannel(const std::string &channel);
|
|
|
|
|
Force send a mapblock to a player (#8140)
* Force send a mapblock to a player.
Send a single mapblock to a specific remote player.
This is badly needed for mods and games where players are teleported
into terrain which may be not generated, loaded, or modified
significantly since the last player visit.
In all these cases, the player currently ends up in void, air, or
inside blocks which not only looks bad, but has the effect that the
player might end up falling and then the server needs to correct for
the player position again later, which is a hack.
The best solution is to send at least the single mapblock that the
player will be teleported to. I've tested this with ITB which does this
all the time, and I can see it functioning as expected (it even shows
a half loaded entry hallway, as the further blocks aren't loaded yet).
The parameter is a blockpos (table of x, y, z), not a regular pos.
The function may return false if the call failed. This is most likely
due to the target position not being generated or emerged yet, or
another internal failure, such as the player not being initialized.
* Always send mapblock on teleport or respawn.
This avoids the need for mods to send a mapblock on teleport or
respawn, since any call to `player:set_pos()` will pass this code.
2019-04-28 01:42:13 +02:00
|
|
|
// Send block to specific player only
|
|
|
|
bool SendBlock(session_t peer_id, const v3s16 &blockpos);
|
|
|
|
|
2020-09-16 15:51:11 +02:00
|
|
|
// Get or load translations for a language
|
|
|
|
Translations *getTranslationLanguage(const std::string &lang_code);
|
2020-04-25 07:20:00 +02:00
|
|
|
|
2022-01-07 19:28:49 +01:00
|
|
|
static ModMetadataDatabase *openModStorageDatabase(const std::string &world_path);
|
|
|
|
|
|
|
|
static ModMetadataDatabase *openModStorageDatabase(const std::string &backend,
|
|
|
|
const std::string &world_path, const Settings &world_mt);
|
|
|
|
|
|
|
|
static bool migrateModStorageDatabase(const GameParams &game_params,
|
|
|
|
const Settings &cmd_args);
|
|
|
|
|
2022-05-02 20:55:04 +02:00
|
|
|
// Lua files registered for init of async env, pair of modname + path
|
|
|
|
std::vector<std::pair<std::string, std::string>> m_async_init_files;
|
|
|
|
|
2022-05-09 18:20:10 +02:00
|
|
|
// Data transferred into async envs at init time
|
|
|
|
std::unique_ptr<PackedValue> m_async_globals_data;
|
2022-05-02 20:55:04 +02:00
|
|
|
|
2015-01-21 20:32:12 +01:00
|
|
|
// Bind address
|
|
|
|
Address m_bind_addr;
|
|
|
|
|
2015-10-30 07:48:37 +01:00
|
|
|
// Environment mutex (envlock)
|
2017-06-06 16:29:28 +02:00
|
|
|
std::mutex m_env_mutex;
|
2015-10-30 07:48:37 +01:00
|
|
|
|
2014-01-31 00:24:00 +01:00
|
|
|
private:
|
|
|
|
friend class EmergeThread;
|
|
|
|
friend class RemoteClient;
|
2018-06-13 21:58:34 +02:00
|
|
|
friend class TestServerShutdownState;
|
|
|
|
|
|
|
|
struct ShutdownState {
|
|
|
|
friend class TestServerShutdownState;
|
|
|
|
public:
|
|
|
|
bool is_requested = false;
|
|
|
|
bool should_reconnect = false;
|
|
|
|
std::string message;
|
|
|
|
|
|
|
|
void reset();
|
|
|
|
void trigger(float delay, const std::string &msg, bool reconnect);
|
|
|
|
void tick(float dtime, Server *server);
|
|
|
|
std::wstring getShutdownTimerMessage() const;
|
|
|
|
bool isTimerRunning() const { return m_timer > 0.0f; }
|
|
|
|
private:
|
|
|
|
float m_timer = 0.0f;
|
|
|
|
};
|
2012-12-18 19:23:16 +01:00
|
|
|
|
2021-09-09 16:51:35 +02:00
|
|
|
struct PendingDynamicMediaCallback {
|
|
|
|
std::string filename; // only set if media entry and file is to be deleted
|
|
|
|
float expiry_timer;
|
|
|
|
std::unordered_set<session_t> waiting_players;
|
|
|
|
};
|
|
|
|
|
2022-05-22 00:37:58 +02:00
|
|
|
// The standard library does not implement std::hash for pairs so we have this:
|
2022-05-05 22:03:49 +02:00
|
|
|
struct SBCHash {
|
|
|
|
size_t operator() (const std::pair<v3s16, u16> &p) const {
|
2022-05-22 00:37:58 +02:00
|
|
|
return std::hash<v3s16>()(p.first) ^ p.second;
|
2022-05-05 22:03:49 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::unordered_map<std::pair<v3s16, u16>, std::string, SBCHash> SerializedBlockCache;
|
|
|
|
|
2020-05-07 22:38:41 +02:00
|
|
|
void init();
|
|
|
|
|
2017-09-27 19:47:36 +02:00
|
|
|
void SendMovement(session_t peer_id);
|
2022-06-11 20:00:40 +02:00
|
|
|
void SendHP(session_t peer_id, u16 hp, bool effect);
|
2017-09-27 19:47:36 +02:00
|
|
|
void SendBreath(session_t peer_id, u16 breath);
|
|
|
|
void SendAccessDenied(session_t peer_id, AccessDeniedCode reason,
|
2015-07-17 16:40:41 +02:00
|
|
|
const std::string &custom_reason, bool reconnect = false);
|
2017-09-27 19:47:36 +02:00
|
|
|
void SendAccessDenied_Legacy(session_t peer_id, const std::wstring &reason);
|
|
|
|
void SendDeathscreen(session_t peer_id, bool set_camera_point_target,
|
|
|
|
v3f camera_point_target);
|
|
|
|
void SendItemDef(session_t peer_id, IItemDefManager *itemdef, u16 protocol_version);
|
2018-02-10 21:04:16 +01:00
|
|
|
void SendNodeDef(session_t peer_id, const NodeDefManager *nodedef,
|
|
|
|
u16 protocol_version);
|
2014-01-31 00:24:00 +01:00
|
|
|
|
|
|
|
/* mark blocks not sent for all clients */
|
|
|
|
void SetBlocksNotSent(std::map<v3s16, MapBlock *>& block);
|
2011-04-21 18:35:17 +02:00
|
|
|
|
2015-03-04 11:29:34 +01:00
|
|
|
|
2018-06-13 21:58:34 +02:00
|
|
|
virtual void SendChatMessage(session_t peer_id, const ChatMessage &message);
|
2017-09-27 19:47:36 +02:00
|
|
|
void SendTimeOfDay(session_t peer_id, u16 time, f32 time_speed);
|
|
|
|
|
|
|
|
void SendLocalPlayerAnimations(session_t peer_id, v2s32 animation_frames[4],
|
|
|
|
f32 animation_speed);
|
|
|
|
void SendEyeOffset(session_t peer_id, v3f first, v3f third);
|
|
|
|
void SendPlayerPrivileges(session_t peer_id);
|
|
|
|
void SendPlayerInventoryFormspec(session_t peer_id);
|
2018-03-28 17:04:41 +02:00
|
|
|
void SendPlayerFormspecPrepend(session_t peer_id);
|
2017-09-27 19:47:36 +02:00
|
|
|
void SendShowFormspecMessage(session_t peer_id, const std::string &formspec,
|
|
|
|
const std::string &formname);
|
|
|
|
void SendHUDAdd(session_t peer_id, u32 id, HudElement *form);
|
|
|
|
void SendHUDRemove(session_t peer_id, u32 id);
|
|
|
|
void SendHUDChange(session_t peer_id, u32 id, HudElementStat stat, void *value);
|
|
|
|
void SendHUDSetFlags(session_t peer_id, u32 flags, u32 mask);
|
|
|
|
void SendHUDSetParam(session_t peer_id, u16 param, const std::string &value);
|
2019-08-21 22:47:45 +02:00
|
|
|
void SendSetSky(session_t peer_id, const SkyboxParams ¶ms);
|
|
|
|
void SendSetSun(session_t peer_id, const SunParams ¶ms);
|
|
|
|
void SendSetMoon(session_t peer_id, const MoonParams ¶ms);
|
|
|
|
void SendSetStars(session_t peer_id, const StarParams ¶ms);
|
2018-03-08 22:19:25 +01:00
|
|
|
void SendCloudParams(session_t peer_id, const CloudParams ¶ms);
|
2017-09-27 19:47:36 +02:00
|
|
|
void SendOverrideDayNightRatio(session_t peer_id, bool do_override, float ratio);
|
2022-03-26 16:58:26 +01:00
|
|
|
void SendSetLighting(session_t peer_id, const Lighting &lighting);
|
2017-09-26 00:11:20 +02:00
|
|
|
void broadcastModChannelMessage(const std::string &channel,
|
2017-09-27 19:47:36 +02:00
|
|
|
const std::string &message, session_t from_peer);
|
2015-01-12 17:01:41 +01:00
|
|
|
|
2011-04-06 10:02:39 +02:00
|
|
|
/*
|
|
|
|
Send a node removal/addition event to all clients except ignore_id.
|
|
|
|
Additionally, if far_players!=NULL, players further away than
|
|
|
|
far_d_nodes are ignored and their peer_ids are added to far_players
|
|
|
|
*/
|
2011-05-31 19:02:55 +02:00
|
|
|
// Envlock and conlock should be locked when calling these
|
2018-08-16 20:10:34 +02:00
|
|
|
void sendRemoveNode(v3s16 p, std::unordered_set<u16> *far_players = nullptr,
|
|
|
|
float far_d_nodes = 100);
|
|
|
|
void sendAddNode(v3s16 p, MapNode n,
|
|
|
|
std::unordered_set<u16> *far_players = nullptr,
|
|
|
|
float far_d_nodes = 100, bool remove_metadata = true);
|
2012-12-18 19:23:16 +01:00
|
|
|
|
2022-05-26 14:40:00 +02:00
|
|
|
void sendMetadataChanged(const std::unordered_set<v3s16> &positions,
|
2018-12-04 20:37:48 +01:00
|
|
|
float far_d_nodes = 100);
|
|
|
|
|
2011-05-22 16:00:09 +02:00
|
|
|
// Environment and Connection must be locked when called
|
2022-05-05 22:03:49 +02:00
|
|
|
// `cache` may only be very short lived! (invalidation not handeled)
|
|
|
|
void SendBlockNoLock(session_t peer_id, MapBlock *block, u8 ver,
|
|
|
|
u16 net_proto_version, SerializedBlockCache *cache = nullptr);
|
2012-12-18 19:23:16 +01:00
|
|
|
|
2011-05-31 19:02:55 +02:00
|
|
|
// Sends blocks to clients (locks env and con on its own)
|
2010-11-27 00:02:21 +01:00
|
|
|
void SendBlocks(float dtime);
|
2012-12-18 19:23:16 +01:00
|
|
|
|
2020-06-13 19:03:26 +02:00
|
|
|
bool addMediaFile(const std::string &filename, const std::string &filepath,
|
|
|
|
std::string *filedata = nullptr, std::string *digest = nullptr);
|
2012-03-25 10:50:29 +02:00
|
|
|
void fillMediaCache();
|
2017-09-27 19:47:36 +02:00
|
|
|
void sendMediaAnnouncement(session_t peer_id, const std::string &lang_code);
|
|
|
|
void sendRequestedMedia(session_t peer_id,
|
2015-03-05 11:39:05 +01:00
|
|
|
const std::vector<std::string> &tosend);
|
2021-09-09 16:51:35 +02:00
|
|
|
void stepPendingDynMediaCallbacks(float dtime);
|
2012-12-18 19:23:16 +01:00
|
|
|
|
2014-01-31 00:24:00 +01:00
|
|
|
// Adds a ParticleSpawner on peer with peer_id (PEER_ID_INEXISTENT == all)
|
2017-09-27 19:47:36 +02:00
|
|
|
void SendAddParticleSpawner(session_t peer_id, u16 protocol_version,
|
2020-05-22 13:23:25 +02:00
|
|
|
const ParticleSpawnerParameters &p, u16 attached_id, u32 id);
|
2013-01-23 18:32:02 +01:00
|
|
|
|
2017-09-27 19:47:36 +02:00
|
|
|
void SendDeleteParticleSpawner(session_t peer_id, u32 id);
|
2013-01-23 18:32:02 +01:00
|
|
|
|
2014-01-31 00:24:00 +01:00
|
|
|
// Spawns particle on peer with peer_id (PEER_ID_INEXISTENT == all)
|
2017-09-27 19:47:36 +02:00
|
|
|
void SendSpawnParticle(session_t peer_id, u16 protocol_version,
|
2020-05-22 13:23:25 +02:00
|
|
|
const ParticleParameters &p);
|
2013-01-23 18:32:02 +01:00
|
|
|
|
2019-08-25 02:54:21 +02:00
|
|
|
void SendActiveObjectRemoveAdd(RemoteClient *client, PlayerSAO *playersao);
|
2017-09-27 19:47:36 +02:00
|
|
|
void SendActiveObjectMessages(session_t peer_id, const std::string &datas,
|
|
|
|
bool reliable = true);
|
2018-06-20 22:36:08 +02:00
|
|
|
void SendCSMRestrictionFlags(session_t peer_id);
|
2017-07-18 21:39:55 +02:00
|
|
|
|
2011-04-21 18:35:17 +02:00
|
|
|
/*
|
|
|
|
Something random
|
|
|
|
*/
|
2012-12-18 19:23:16 +01:00
|
|
|
|
2022-01-15 17:44:55 +01:00
|
|
|
void HandlePlayerDeath(PlayerSAO* sao, const PlayerHPChangeReason &reason);
|
2017-09-27 19:47:36 +02:00
|
|
|
void DeleteClient(session_t peer_id, ClientDeletionReason reason);
|
2016-10-08 10:38:04 +02:00
|
|
|
void UpdateCrafting(RemotePlayer *player);
|
2019-03-07 08:19:13 +01:00
|
|
|
bool checkInteractDistance(RemotePlayer *player, const f32 d, const std::string &what);
|
2012-12-18 19:23:16 +01:00
|
|
|
|
2015-11-09 06:04:24 +01:00
|
|
|
void handleChatInterfaceEvent(ChatEvent *evt);
|
|
|
|
|
2015-07-25 07:43:32 +02:00
|
|
|
// This returns the answer to the sender of wmessage, or "" if there is none
|
2021-01-29 14:03:27 +01:00
|
|
|
std::wstring handleChat(const std::string &name, std::wstring wmessage_input,
|
|
|
|
bool check_shout_priv = false, RemotePlayer *player = nullptr);
|
2015-07-25 07:43:32 +02:00
|
|
|
void handleAdminChat(const ChatEventChat *evt);
|
|
|
|
|
2010-11-27 00:02:21 +01:00
|
|
|
// When called, connection mutex should be locked
|
2017-09-27 19:47:36 +02:00
|
|
|
RemoteClient* getClient(session_t peer_id, ClientState state_min = CS_Active);
|
|
|
|
RemoteClient* getClientNoEx(session_t peer_id, ClientState state_min = CS_Active);
|
2012-12-18 19:23:16 +01:00
|
|
|
|
2011-05-30 23:15:43 +02:00
|
|
|
// When called, environment mutex should be locked
|
2017-09-27 19:47:36 +02:00
|
|
|
std::string getPlayerName(session_t peer_id);
|
|
|
|
PlayerSAO *getPlayerSAO(session_t peer_id);
|
2012-03-19 03:04:16 +01:00
|
|
|
|
2011-01-17 23:26:09 +01:00
|
|
|
/*
|
|
|
|
Get a player from memory or creates one.
|
|
|
|
If player is already connected, return NULL
|
2011-11-20 20:16:15 +01:00
|
|
|
Does not verify/modify auth info and password.
|
2011-01-17 23:26:09 +01:00
|
|
|
|
|
|
|
Call with env and con locked.
|
|
|
|
*/
|
2017-09-27 19:47:36 +02:00
|
|
|
PlayerSAO *emergePlayer(const char *name, session_t peer_id, u16 proto_version);
|
2012-12-18 19:23:16 +01:00
|
|
|
|
2010-12-24 16:08:50 +01:00
|
|
|
void handlePeerChanges();
|
2011-05-22 16:00:09 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Variables
|
|
|
|
*/
|
2012-03-10 14:56:24 +01:00
|
|
|
// World directory
|
|
|
|
std::string m_path_world;
|
2012-03-11 13:54:23 +01:00
|
|
|
// Subgame specification
|
|
|
|
SubgameSpec m_gamespec;
|
2012-03-15 14:20:20 +01:00
|
|
|
// If true, do not allow multiple players and hide some multiplayer
|
|
|
|
// functionality
|
|
|
|
bool m_simple_singleplayer_mode;
|
2016-10-04 18:17:12 +02:00
|
|
|
u16 m_max_chatmessage_length;
|
2015-10-15 19:04:15 +02:00
|
|
|
// For "dedicated" server list flag
|
|
|
|
bool m_dedicated;
|
2020-11-22 17:49:30 +01:00
|
|
|
Settings *m_game_settings = nullptr;
|
2012-03-10 14:56:24 +01:00
|
|
|
|
2012-03-11 19:45:43 +01:00
|
|
|
// Thread can set; step() will throw as ServerError
|
|
|
|
MutexedVariable<std::string> m_async_fatal_error;
|
2012-12-18 19:23:16 +01:00
|
|
|
|
2011-05-22 16:00:09 +02:00
|
|
|
// Some timers
|
2017-06-18 19:55:15 +02:00
|
|
|
float m_liquid_transform_timer = 0.0f;
|
|
|
|
float m_liquid_transform_every = 1.0f;
|
|
|
|
float m_masterserver_timer = 0.0f;
|
|
|
|
float m_emergethread_trigger_timer = 0.0f;
|
|
|
|
float m_savemap_timer = 0.0f;
|
2011-06-26 23:27:17 +02:00
|
|
|
IntervalLimiter m_map_timer_and_unload_interval;
|
2012-12-18 19:23:16 +01:00
|
|
|
|
2011-05-22 16:00:09 +02:00
|
|
|
// Environment
|
2017-06-18 19:55:15 +02:00
|
|
|
ServerEnvironment *m_env = nullptr;
|
2012-12-18 19:23:16 +01:00
|
|
|
|
2021-02-05 18:34:25 +01:00
|
|
|
// Reference to the server map until ServerEnvironment is initialized
|
|
|
|
// after that this variable must be a nullptr
|
|
|
|
ServerMap *m_startup_server_map = nullptr;
|
|
|
|
|
2014-01-31 00:24:00 +01:00
|
|
|
// server connection
|
2017-08-24 08:28:54 +02:00
|
|
|
std::shared_ptr<con::Connection> m_con;
|
2011-05-29 20:11:16 +02:00
|
|
|
|
2013-08-04 07:17:07 +02:00
|
|
|
// Ban checking
|
2017-06-18 19:55:15 +02:00
|
|
|
BanManager *m_banmanager = nullptr;
|
2011-11-11 18:33:17 +01:00
|
|
|
|
2012-07-26 21:06:45 +02:00
|
|
|
// Rollback manager (behind m_env_mutex)
|
2017-06-18 19:55:15 +02:00
|
|
|
IRollbackManager *m_rollback = nullptr;
|
2012-07-26 21:06:45 +02:00
|
|
|
|
2012-11-26 03:16:48 +01:00
|
|
|
// Emerge manager
|
2017-06-18 19:55:15 +02:00
|
|
|
EmergeManager *m_emerge = nullptr;
|
2012-11-26 03:16:48 +01:00
|
|
|
|
2011-11-11 18:33:17 +01:00
|
|
|
// Scripting
|
|
|
|
// Envlock and conlock should be locked when using Lua
|
2017-06-18 19:55:15 +02:00
|
|
|
ServerScripting *m_script = nullptr;
|
2011-11-13 23:19:48 +01:00
|
|
|
|
2012-01-12 06:10:39 +01:00
|
|
|
// Item definition manager
|
|
|
|
IWritableItemDefManager *m_itemdef;
|
2012-12-18 19:23:16 +01:00
|
|
|
|
2011-11-14 20:41:30 +01:00
|
|
|
// Node definition manager
|
2018-02-10 21:04:16 +01:00
|
|
|
NodeDefManager *m_nodedef;
|
2012-12-18 19:23:16 +01:00
|
|
|
|
2011-11-17 01:28:46 +01:00
|
|
|
// Craft definition manager
|
|
|
|
IWritableCraftDefManager *m_craftdef;
|
2012-12-18 19:23:16 +01:00
|
|
|
|
2011-12-11 15:49:40 +01:00
|
|
|
// Mods
|
2018-03-16 08:41:33 +01:00
|
|
|
std::unique_ptr<ServerModManager> m_modmgr;
|
2012-12-18 19:23:16 +01:00
|
|
|
|
2020-09-16 15:51:11 +02:00
|
|
|
std::unordered_map<std::string, Translations> server_translations;
|
|
|
|
|
2011-05-22 16:00:09 +02:00
|
|
|
/*
|
|
|
|
Threads
|
|
|
|
*/
|
|
|
|
// A buffer for time steps
|
|
|
|
// step() increments and AsyncRunStep() run by m_thread reads it.
|
2017-06-18 19:55:15 +02:00
|
|
|
float m_step_dtime = 0.0f;
|
2017-06-06 16:29:28 +02:00
|
|
|
std::mutex m_step_dtime_mutex;
|
2010-11-27 00:02:21 +01:00
|
|
|
|
2011-05-22 16:00:09 +02:00
|
|
|
// The server mainly operates in this thread
|
2017-06-18 19:55:15 +02:00
|
|
|
ServerThread *m_thread = nullptr;
|
2012-12-18 19:23:16 +01:00
|
|
|
|
2011-05-22 16:00:09 +02:00
|
|
|
/*
|
|
|
|
Time related stuff
|
|
|
|
*/
|
|
|
|
// Timer for sending time of day over network
|
2017-06-18 19:55:15 +02:00
|
|
|
float m_time_of_day_send_timer = 0.0f;
|
2018-07-15 02:26:30 +02:00
|
|
|
|
2014-01-31 00:24:00 +01:00
|
|
|
/*
|
2018-07-15 02:26:30 +02:00
|
|
|
Client interface
|
|
|
|
*/
|
2014-01-31 00:24:00 +01:00
|
|
|
ClientInterface m_clients;
|
|
|
|
|
2011-05-22 16:00:09 +02:00
|
|
|
/*
|
|
|
|
Peer change queue.
|
|
|
|
Queues stuff from peerAdded() and deletingPeer() to
|
|
|
|
handlePeerChanges()
|
|
|
|
*/
|
2015-03-04 17:48:07 +01:00
|
|
|
std::queue<con::PeerChange> m_peer_change_queue;
|
2010-12-24 16:08:50 +01:00
|
|
|
|
2018-02-18 22:33:42 +01:00
|
|
|
std::unordered_map<session_t, std::string> m_formspec_state_data;
|
|
|
|
|
2011-05-22 16:00:09 +02:00
|
|
|
/*
|
|
|
|
Random stuff
|
|
|
|
*/
|
2012-12-18 19:23:16 +01:00
|
|
|
|
2018-06-13 21:58:34 +02:00
|
|
|
ShutdownState m_shutdown_state;
|
2012-01-12 06:10:39 +01:00
|
|
|
|
2015-07-25 07:43:32 +02:00
|
|
|
ChatInterface *m_admin_chat;
|
|
|
|
std::string m_admin_nick;
|
|
|
|
|
2020-08-23 19:44:25 +02:00
|
|
|
// if a mod-error occurs in the on_shutdown callback, the error message will
|
|
|
|
// be written into this
|
|
|
|
std::string *const m_on_shutdown_errmsg;
|
|
|
|
|
2011-05-22 16:00:09 +02:00
|
|
|
/*
|
|
|
|
Map edit event queue. Automatically receives all map edits.
|
|
|
|
The constructor of this class registers us to receive them through
|
|
|
|
onMapEditEvent
|
|
|
|
|
|
|
|
NOTE: Should these be moved to actually be members of
|
|
|
|
ServerEnvironment?
|
|
|
|
*/
|
|
|
|
|
2011-02-23 01:49:57 +01:00
|
|
|
/*
|
|
|
|
Queue of map edits from the environment for sending to the clients
|
|
|
|
This is behind m_env_mutex
|
|
|
|
*/
|
2015-03-04 17:48:07 +01:00
|
|
|
std::queue<MapEditEvent*> m_unsent_map_edit_queue;
|
2012-03-29 00:22:08 +02:00
|
|
|
/*
|
|
|
|
If a non-empty area, map edit events contained within are left
|
|
|
|
unsent. Done at map generation time to speed up editing of the
|
|
|
|
generated area, as it will be sent anyway.
|
|
|
|
This is behind m_env_mutex
|
|
|
|
*/
|
|
|
|
VoxelArea m_ignore_map_edit_events_area;
|
2011-02-15 15:11:24 +01:00
|
|
|
|
2014-01-31 00:24:00 +01:00
|
|
|
// media files known to server
|
2017-06-04 21:00:04 +02:00
|
|
|
std::unordered_map<std::string, MediaInfo> m_media;
|
2012-03-24 18:01:26 +01:00
|
|
|
|
2021-09-09 16:51:35 +02:00
|
|
|
// pending dynamic media callbacks, clients inform the server when they have a file fetched
|
|
|
|
std::unordered_map<u32, PendingDynamicMediaCallback> m_pending_dyn_media;
|
|
|
|
float m_step_pending_dyn_media_timer = 0.0f;
|
|
|
|
|
2012-03-24 18:01:26 +01:00
|
|
|
/*
|
|
|
|
Sounds
|
|
|
|
*/
|
2017-06-04 21:00:04 +02:00
|
|
|
std::unordered_map<s32, ServerPlayingSound> m_playing_sounds;
|
2020-01-25 21:19:29 +01:00
|
|
|
s32 m_next_sound_id = 0; // positive values only
|
|
|
|
s32 nextSoundId();
|
2012-07-24 19:57:17 +02:00
|
|
|
|
2022-01-07 19:28:49 +01:00
|
|
|
ModMetadataDatabase *m_mod_storage_database = nullptr;
|
2017-06-18 19:55:15 +02:00
|
|
|
float m_mod_storage_save_timer = 10.0f;
|
2017-07-18 21:39:55 +02:00
|
|
|
|
2018-06-20 22:36:08 +02:00
|
|
|
// CSM restrictions byteflag
|
|
|
|
u64 m_csm_restriction_flags = CSMRestrictionFlags::CSM_RF_NONE;
|
|
|
|
u32 m_csm_restriction_noderange = 8;
|
2017-09-26 00:11:20 +02:00
|
|
|
|
|
|
|
// ModChannel manager
|
|
|
|
std::unique_ptr<ModChannelMgr> m_modchannel_mgr;
|
2020-04-27 08:31:37 +02:00
|
|
|
|
2020-05-07 22:38:41 +02:00
|
|
|
// Inventory manager
|
|
|
|
std::unique_ptr<ServerInventoryManager> m_inventory_mgr;
|
|
|
|
|
2020-04-27 08:31:37 +02:00
|
|
|
// Global server metrics backend
|
|
|
|
std::unique_ptr<MetricsBackend> m_metrics_backend;
|
|
|
|
|
|
|
|
// Server metrics
|
|
|
|
MetricCounterPtr m_uptime_counter;
|
|
|
|
MetricGaugePtr m_player_gauge;
|
|
|
|
MetricGaugePtr m_timeofday_gauge;
|
|
|
|
MetricGaugePtr m_lag_gauge;
|
2022-05-09 21:20:58 +02:00
|
|
|
MetricCounterPtr m_aom_buffer_counter[2]; // [0] = rel, [1] = unrel
|
2020-04-27 08:31:37 +02:00
|
|
|
MetricCounterPtr m_packet_recv_counter;
|
|
|
|
MetricCounterPtr m_packet_recv_processed_counter;
|
2022-05-09 21:20:58 +02:00
|
|
|
MetricCounterPtr m_map_edit_event_counter;
|
2010-11-27 00:02:21 +01:00
|
|
|
};
|
|
|
|
|
2011-01-23 16:29:15 +01:00
|
|
|
/*
|
2011-02-15 15:11:24 +01:00
|
|
|
Runs a simple dedicated server loop.
|
|
|
|
|
2015-07-24 23:11:19 +02:00
|
|
|
Shuts down when kill is set to true.
|
2011-01-23 16:29:15 +01:00
|
|
|
*/
|
2015-07-24 23:11:19 +02:00
|
|
|
void dedicated_server_loop(Server &server, bool &kill);
|