51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-/*
-(c) 2010 Perttu Ahola <celeron55@gmail.com>
-*/
-
#ifndef SERVER_HEADER
#define SERVER_HEADER
#include "environment.h"
#include "common_irrlicht.h"
#include <string>
-#include "utility.h"
#include "porting.h"
#include "map.h"
#include "inventory.h"
#include "auth.h"
+#include "ban.h"
+#include "gamedef.h"
+#include "serialization.h" // For SER_FMT_VER_INVALID
+struct LuaState;
+typedef struct lua_State lua_State;
+class IWritableToolDefManager;
+class IWritableNodeDefManager;
+class IWritableCraftDefManager;
/*
Some random functions
u16 peer_id;
// The serialization version to use with the client
u8 serialization_version;
+ //
+ u16 net_proto_version;
// Version is stored in here after INIT before INIT2
u8 pending_serialization_version;
{
peer_id = 0;
serialization_version = SER_FMT_VER_INVALID;
+ net_proto_version = 0;
pending_serialization_version = SER_FMT_VER_INVALID;
m_nearest_unsent_d = 0;
m_nearest_unsent_reset_timer = 0.0;
};
class Server : public con::PeerHandler, public MapEventReceiver,
- public InventoryManager
+ public InventoryManager, public IGameDef
{
public:
/*
*/
Server(
- std::string mapsavedir
+ std::string mapsavedir,
+ std::string configpath
);
~Server();
void start(unsigned short port);
// Environment must be locked when called
void setTimeOfDay(u32 time)
{
- m_env.setTimeOfDay(time);
+ m_env->setTimeOfDay(time);
m_time_of_day_send_timer = 0;
}
dstream<<"WARNING: Auth not found for "<<name<<std::endl;
}
}
+
+ // Saves g_settings to configpath given at initialization
+ void saveConfig();
+
+ void setIpBanned(const std::string &ip, const std::string &name)
+ {
+ m_banmanager.add(ip, name);
+ return;
+ }
+
+ void unsetIpBanned(const std::string &ip_or_name)
+ {
+ m_banmanager.remove(ip_or_name);
+ return;
+ }
+
+ std::string getBanDescription(const std::string &ip_or_name)
+ {
+ return m_banmanager.getBanDescription(ip_or_name);
+ }
+
+ Address getPeerAddress(u16 peer_id)
+ {
+ return m_con.GetPeerAddress(peer_id);
+ }
+
+ // Envlock and conlock should be locked when calling this
+ void notifyPlayer(const char *name, const std::wstring msg);
+ void notifyPlayers(const std::wstring msg);
+
+ // Envlock and conlock should be locked when using Lua
+ lua_State *getLua(){ return m_lua; }
+
+ // IGameDef interface
+ // Under envlock
+ virtual IToolDefManager* getToolDefManager();
+ virtual INodeDefManager* getNodeDefManager();
+ virtual ICraftDefManager* getCraftDefManager();
+ virtual ITextureSource* getTextureSource();
+ virtual u16 allocateUnknownNodeId(const std::string &name);
+
+ IWritableToolDefManager* getWritableToolDefManager();
+ IWritableNodeDefManager* getWritableNodeDefManager();
+ IWritableCraftDefManager* getWritableCraftDefManager();
private:
static void SendHP(con::Connection &con, u16 peer_id, u8 hp);
static void SendAccessDenied(con::Connection &con, u16 peer_id,
const std::wstring &reason);
+ static void SendDeathscreen(con::Connection &con, u16 peer_id,
+ bool set_camera_point_target, v3f camera_point_target);
+ static void SendToolDef(con::Connection &con, u16 peer_id,
+ IToolDefManager *tooldef);
+ static void SendNodeDef(con::Connection &con, u16 peer_id,
+ INodeDefManager *nodedef);
/*
- Non-static send methods
+ Non-static send methods.
+ Conlock should be always used.
+ Envlock usage is documented badly but it's easy to figure out
+ which ones access the environment.
*/
// Envlock and conlock should be locked when calling these
void SendObjectData(float dtime);
void SendPlayerInfos();
void SendInventory(u16 peer_id);
+ // send wielded item info about player to all
+ void SendWieldedItem(const Player *player);
+ // send wielded item info about all players to all players
+ void SendPlayerItems();
void SendChatMessage(u16 peer_id, const std::wstring &message);
void BroadcastChatMessage(const std::wstring &message);
void SendPlayerHP(Player *player);
Additionally, if far_players!=NULL, players further away than
far_d_nodes are ignored and their peer_ids are added to far_players
*/
+ // Envlock and conlock should be locked when calling these
void sendRemoveNode(v3s16 p, u16 ignore_id=0,
core::list<u16> *far_players=NULL, float far_d_nodes=100);
void sendAddNode(v3s16 p, MapNode n, u16 ignore_id=0,
core::list<u16> *far_players=NULL, float far_d_nodes=100);
+ void setBlockNotSent(v3s16 p);
// Environment and Connection must be locked when called
void SendBlockNoLock(u16 peer_id, MapBlock *block, u8 ver);
- // Sends blocks to clients
+ // Sends blocks to clients (locks env and con on its own)
void SendBlocks(float dtime);
+
+ void SendTextures(u16 peer_id);
/*
Something random
*/
+ void HandlePlayerHP(Player *player, s16 damage);
+ void RespawnPlayer(Player *player);
+
void UpdateCrafting(u16 peer_id);
// When called, connection mutex should be locked
RemoteClient* getClient(u16 peer_id);
+ // When called, environment mutex should be locked
+ std::string getPlayerName(u16 peer_id)
+ {
+ Player *player = m_env->getPlayer(peer_id);
+ if(player == NULL)
+ return "[id="+itos(peer_id);
+ return player->getName();
+ }
+
/*
Get a player from memory or creates one.
If player is already connected, return NULL
float m_objectdata_timer;
float m_emergethread_trigger_timer;
float m_savemap_timer;
+ IntervalLimiter m_map_timer_and_unload_interval;
// NOTE: If connection and environment are both to be locked,
// environment shall be locked first.
// Environment
- ServerEnvironment m_env;
+ ServerEnvironment *m_env;
JMutex m_env_mutex;
// Connection
// User authentication
AuthManager m_authmanager;
+
+ // Bann checking
+ BanManager m_banmanager;
+
+ // Scripting
+ // Envlock and conlock should be locked when using Lua
+ lua_State *m_lua;
+
+ // Tool definition manager
+ IWritableToolDefManager *m_toolmgr;
+
+ // Node definition manager
+ IWritableNodeDefManager *m_nodedef;
+
+ // Craft definition manager
+ IWritableCraftDefManager *m_craftdef;
/*
Threads
// Map directory
std::string m_mapsavedir;
+ // Configuration path ("" = no configuration file)
+ std::string m_configpath;
+
+ // Mod parent directory paths
+ core::list<std::string> m_modspaths;
+
bool m_shutdown_requested;
/*