#include "itemdef.h"
#include "craftdef.h"
#include "emerge.h"
-#include "mapgen.h"
-#include "mg_biome.h"
+#include "mapgen/mapgen.h"
+#include "mapgen/mg_biome.h"
#include "content_mapnode.h"
#include "content_nodemeta.h"
#include "content_sao.h"
#include "util/base64.h"
#include "util/sha1.h"
#include "util/hex.h"
-#include "database.h"
+#include "database/database.h"
#include "chatmessage.h"
#include "chat_interface.h"
#include "remoteplayer.h"
const std::string &path_world,
const SubgameSpec &gamespec,
bool simple_singleplayer_mode,
- bool ipv6,
+ Address bind_addr,
bool dedicated,
ChatInterface *iface
):
+ m_bind_addr(bind_addr),
m_path_world(path_world),
m_gamespec(gamespec),
m_simple_singleplayer_mode(simple_singleplayer_mode),
m_con(std::make_shared<con::Connection>(PROTOCOL_ID,
512,
CONNECTION_TIMEOUT,
- ipv6,
+ m_bind_addr.isIPv6(),
this)),
m_itemdef(createItemDefManager()),
m_nodedef(createNodeDefManager()),
m_nodedef->updateAliases(m_itemdef);
// Apply texture overrides from texturepack/override.txt
- std::string texture_path = g_settings->get("texture_path");
- if (!texture_path.empty() && fs::IsDir(texture_path))
- m_nodedef->applyTextureOverrides(texture_path + DIR_DELIM + "override.txt");
+ for (const auto &path : fs::GetRecursiveDirs(g_settings->get("texture_path")))
+ m_nodedef->applyTextureOverrides(path + DIR_DELIM + "override.txt");
m_nodedef->setNodeRegistrationStatus(true);
}
}
-void Server::start(Address bind_addr)
+void Server::start()
{
- m_bind_addr = bind_addr;
-
- infostream<<"Starting server on "
- << bind_addr.serializeString() <<"..."<<std::endl;
+ infostream << "Starting server on " << m_bind_addr.serializeString()
+ << "..." << std::endl;
// Stop thread if already running
m_thread->stop();
// Initialize connection
m_con->SetTimeoutMs(30);
- m_con->Serve(bind_addr);
+ m_con->Serve(m_bind_addr);
// Start thread
m_thread->start();
// ASCII art for the win!
actionstream
- <<" .__ __ __ "<<std::endl
- <<" _____ |__| ____ _____/ |_ ____ _______/ |_ "<<std::endl
- <<" / \\| |/ \\_/ __ \\ __\\/ __ \\ / ___/\\ __\\"<<std::endl
- <<"| Y Y \\ | | \\ ___/| | \\ ___/ \\___ \\ | | "<<std::endl
- <<"|__|_| /__|___| /\\___ >__| \\___ >____ > |__| "<<std::endl
- <<" \\/ \\/ \\/ \\/ \\/ "<<std::endl;
- actionstream<<"World at ["<<m_path_world<<"]"<<std::endl;
- actionstream<<"Server for gameid=\""<<m_gamespec.id
- <<"\" listening on "<<bind_addr.serializeString()<<":"
- <<bind_addr.getPort() << "."<<std::endl;
+ << " .__ __ __ " << std::endl
+ << " _____ |__| ____ _____/ |_ ____ _______/ |_ " << std::endl
+ << " / \\| |/ \\_/ __ \\ __\\/ __ \\ / ___/\\ __\\" << std::endl
+ << "| Y Y \\ | | \\ ___/| | \\ ___/ \\___ \\ | | " << std::endl
+ << "|__|_| /__|___| /\\___ >__| \\___ >____ > |__| " << std::endl
+ << " \\/ \\/ \\/ \\/ \\/ " << std::endl;
+ actionstream << "World at [" << m_path_world << "]" << std::endl;
+ actionstream << "Server for gameid=\"" << m_gamespec.id
+ << "\" listening on " << m_bind_addr.serializeString() << ":"
+ << m_bind_addr.getPort() << "." << std::endl;
}
void Server::stop()
// If failed, cancel
if (!playersao || !player) {
- if (player && player->peer_id != 0) {
+ if (player && player->getPeerId() != PEER_ID_INEXISTENT) {
actionstream << "Server: Failed to emerge player \"" << playername
<< "\" (player allocated to an another client)" << std::endl;
DenyAccess_Legacy(peer_id, L"Another client is connected with this "
// Send information about server to player in chat
SendChatMessage(peer_id, ChatMessage(CHATMESSAGE_TYPE_SYSTEM, getStatusString()));
}
- Address addr = getPeerAddress(player->peer_id);
+ Address addr = getPeerAddress(player->getPeerId());
std::string ip_str = addr.serializeString();
actionstream<<player->getName() <<" [" << ip_str << "] joins game. " << std::endl;
/*
void Server::SetBlocksNotSent(std::map<v3s16, MapBlock *>& block)
{
- std::vector<u16> clients = m_clients.getClientIDs();
+ std::vector<session_t> clients = m_clients.getClientIDs();
m_clients.lock();
// Set the modified blocks unsent for all the clients
- for (const u16 client_id : clients) {
+ for (const session_t client_id : clients) {
if (RemoteClient *client = m_clients.lockedGetClientNoEx(client_id))
client->SetBlocksNotSent(block);
}
g_settings->getS16("max_block_send_distance") * MAP_BLOCKSIZE * BS;
if (peer_id == PEER_ID_INEXISTENT) {
- std::vector<u16> clients = m_clients.getClientIDs();
+ std::vector<session_t> clients = m_clients.getClientIDs();
- for (const u16 client_id : clients) {
+ for (const session_t client_id : clients) {
RemotePlayer *player = m_env->getPlayer(client_id);
if (!player)
continue;
{
if (peer_id == PEER_ID_INEXISTENT) {
// This sucks and should be replaced:
- std::vector<u16> clients = m_clients.getClientIDs();
- for (const u16 client_id : clients) {
+ std::vector<session_t> clients = m_clients.getClientIDs();
+ for (const session_t client_id : clients) {
RemotePlayer *player = m_env->getPlayer(client_id);
if (!player)
continue;
{
RemotePlayer *player = m_env->getPlayer(peer_id);
assert(player);
- if(player->peer_id == PEER_ID_INEXISTENT)
+ if(player->getPeerId() == PEER_ID_INEXISTENT)
return;
std::set<std::string> privs;
{
RemotePlayer *player = m_env->getPlayer(peer_id);
assert(player);
- if(player->peer_id == PEER_ID_INEXISTENT)
+ if(player->getPeerId() == PEER_ID_INEXISTENT)
return;
NetworkPacket pkt(TOCLIENT_INVENTORY_FORMSPEC, 0, peer_id);
return -1;
// Filter destination clients
- std::vector<u16> dst_clients;
+ std::vector<session_t> dst_clients;
if(!params.to_player.empty()) {
RemotePlayer *player = m_env->getPlayer(params.to_player.c_str());
if(!player){
<<"\" not found"<<std::endl;
return -1;
}
- if(player->peer_id == PEER_ID_INEXISTENT){
+ if (player->getPeerId() == PEER_ID_INEXISTENT) {
infostream<<"Server::playSound: Player \""<<params.to_player
<<"\" not connected"<<std::endl;
return -1;
}
- dst_clients.push_back(player->peer_id);
+ dst_clients.push_back(player->getPeerId());
} else {
- std::vector<u16> clients = m_clients.getClientIDs();
+ std::vector<session_t> clients = m_clients.getClientIDs();
- for (const u16 client_id : clients) {
+ for (const session_t client_id : clients) {
RemotePlayer *player = m_env->getPlayer(client_id);
if (!player)
continue;
NetworkPacket pkt(TOCLIENT_STOP_SOUND, 4);
pkt << handle;
- for (std::unordered_set<u16>::const_iterator si = psound.clients.begin();
+ for (std::unordered_set<session_t>::const_iterator si = psound.clients.begin();
si != psound.clients.end(); ++si) {
// Send as reliable
m_clients.send(*si, 0, &pkt, true);
NetworkPacket pkt(TOCLIENT_REMOVENODE, 6);
pkt << p;
- std::vector<u16> clients = m_clients.getClientIDs();
- for (u16 client_id : clients) {
+ std::vector<session_t> clients = m_clients.getClientIDs();
+ for (session_t client_id : clients) {
if (far_players) {
// Get player
if (RemotePlayer *player = m_env->getPlayer(client_id)) {
float maxd = far_d_nodes*BS;
v3f p_f = intToFloat(p, BS);
- std::vector<u16> clients = m_clients.getClientIDs();
- for (const u16 client_id : clients) {
+ std::vector<session_t> clients = m_clients.getClientIDs();
+ for (const session_t client_id : clients) {
if (far_players) {
// Get player
if (RemotePlayer *player = m_env->getPlayer(client_id)) {
void Server::setBlockNotSent(v3s16 p)
{
- std::vector<u16> clients = m_clients.getClientIDs();
+ std::vector<session_t> clients = m_clients.getClientIDs();
m_clients.lock();
- for (const u16 i : clients) {
+ for (const session_t i : clients) {
RemoteClient *client = m_clients.lockedGetClientNoEx(i);
client->SetBlockNotSent(p);
}
{
ScopeProfiler sp2(g_profiler, "Server: selecting blocks for sending");
- std::vector<u16> clients = m_clients.getClientIDs();
+ std::vector<session_t> clients = m_clients.getClientIDs();
m_clients.lock();
- for (const u16 client_id : clients) {
+ for (const session_t client_id : clients) {
RemoteClient *client = m_clients.lockedGetClientNoEx(client_id, CS_Active);
if (!client)
paths.push_back(mod.path + DIR_DELIM + "models");
paths.push_back(mod.path + DIR_DELIM + "locale");
}
- paths.push_back(porting::path_user + DIR_DELIM + "textures" + DIR_DELIM + "server");
-
+ fs::GetRecursiveDirs(paths, porting::path_user + DIR_DELIM +
+ "textures" + DIR_DELIM + "server");
// Collect media file information from paths into cache
for (const std::string &mediapath : paths) {
std::vector<fs::DirListNode> dirlist = fs::GetDirListing(mediapath);
return m_clients.sendToAll(&pkt);
RemotePlayer *p = m_env->getPlayer(check.c_str());
if (p)
- m_clients.send(p->peer_id, 0, &pkt, true);
+ m_clients.send(p->getPeerId(), 0, &pkt, true);
} else {
if (check.empty() || getPlayerName(peer_id) == check)
Send(&pkt);
{
if (player && reason != CDR_DENY) {
std::ostringstream os(std::ios_base::binary);
- std::vector<u16> clients = m_clients.getClientIDs();
+ std::vector<session_t> clients = m_clients.getClientIDs();
- for (const u16 client_id : clients) {
+ for (const session_t client_id : clients) {
// Get player
RemotePlayer *player = m_env->getPlayer(client_id);
if (!player)
return ws.str();
}
case RPLAYER_CHATRESULT_KICK:
- DenyAccess_Legacy(player->peer_id,
+ DenyAccess_Legacy(player->getPeerId(),
L"You have been kicked due to message flooding.");
return L"";
case RPLAYER_CHATRESULT_OK:
*/
actionstream << "CHAT: " << wide_to_narrow(unescape_enriched(line)) << std::endl;
- std::vector<u16> clients = m_clients.getClientIDs();
+ std::vector<session_t> clients = m_clients.getClientIDs();
/*
Send the message back to the inital sender
if they are using protocol version >= 29
*/
- session_t peer_id_to_avoid_sending = (player ? player->peer_id : PEER_ID_INEXISTENT);
+ session_t peer_id_to_avoid_sending =
+ (player ? player->getPeerId() : PEER_ID_INEXISTENT);
+
if (player && player->protocol_version >= 29)
peer_id_to_avoid_sending = PEER_ID_INEXISTENT;
// Information about clients
bool first = true;
os<<L", clients={";
- std::vector<u16> clients = m_clients.getClientIDs();
- for (u16 client_id : clients) {
+ std::vector<session_t> clients = m_clients.getClientIDs();
+ for (session_t client_id : clients) {
// Get player
RemotePlayer *player = m_env->getPlayer(client_id);
// Get name of player
void Server::reportPrivsModified(const std::string &name)
{
if (name.empty()) {
- std::vector<u16> clients = m_clients.getClientIDs();
- for (const u16 client_id : clients) {
+ std::vector<session_t> clients = m_clients.getClientIDs();
+ for (const session_t client_id : clients) {
RemotePlayer *player = m_env->getPlayer(client_id);
reportPrivsModified(player->getName());
}
RemotePlayer *player = m_env->getPlayer(name.c_str());
if (!player)
return;
- SendPlayerPrivileges(player->peer_id);
+ SendPlayerPrivileges(player->getPeerId());
PlayerSAO *sao = player->getPlayerSAO();
if(!sao)
return;
RemotePlayer *player = m_env->getPlayer(name.c_str());
if (!player)
return;
- SendPlayerInventoryFormspec(player->peer_id);
+ SendPlayerInventoryFormspec(player->getPeerId());
}
void Server::setIpBanned(const std::string &ip, const std::string &name)
return;
}
- if (player->peer_id == PEER_ID_INEXISTENT)
+ if (player->getPeerId() == PEER_ID_INEXISTENT)
return;
- SendChatMessage(player->peer_id, ChatMessage(msg));
+ SendChatMessage(player->getPeerId(), ChatMessage(msg));
}
bool Server::showFormspec(const char *playername, const std::string &formspec,
if (!player)
return false;
- SendShowFormspecMessage(player->peer_id, formspec, formname);
+ SendShowFormspecMessage(player->getPeerId(), formspec, formname);
return true;
}
u32 id = player->addHud(form);
- SendHUDAdd(player->peer_id, id, form);
+ SendHUDAdd(player->getPeerId(), id, form);
return id;
}
delete todel;
- SendHUDRemove(player->peer_id, id);
+ SendHUDRemove(player->getPeerId(), id);
return true;
}
if (!player)
return false;
- SendHUDChange(player->peer_id, id, stat, data);
+ SendHUDChange(player->getPeerId(), id, stat, data);
return true;
}
if (!player)
return false;
- SendHUDSetFlags(player->peer_id, flags, mask);
+ SendHUDSetFlags(player->getPeerId(), flags, mask);
player->hud_flags &= ~mask;
player->hud_flags |= flags;
player->setHotbarItemcount(hotbar_itemcount);
std::ostringstream os(std::ios::binary);
writeS32(os, hotbar_itemcount);
- SendHUDSetParam(player->peer_id, HUD_PARAM_HOTBAR_ITEMCOUNT, os.str());
+ SendHUDSetParam(player->getPeerId(), HUD_PARAM_HOTBAR_ITEMCOUNT, os.str());
return true;
}
return;
player->setHotbarImage(name);
- SendHUDSetParam(player->peer_id, HUD_PARAM_HOTBAR_IMAGE, name);
+ SendHUDSetParam(player->getPeerId(), HUD_PARAM_HOTBAR_IMAGE, name);
}
std::string Server::hudGetHotbarImage(RemotePlayer *player)
return;
player->setHotbarSelectedImage(name);
- SendHUDSetParam(player->peer_id, HUD_PARAM_HOTBAR_SELECTED_IMAGE, name);
+ SendHUDSetParam(player->getPeerId(), HUD_PARAM_HOTBAR_SELECTED_IMAGE, name);
}
const std::string& Server::hudGetHotbarSelectedImage(RemotePlayer *player) const
return false;
player->setLocalAnimations(animation_frames, frame_speed);
- SendLocalPlayerAnimations(player->peer_id, animation_frames, frame_speed);
+ SendLocalPlayerAnimations(player->getPeerId(), animation_frames, frame_speed);
return true;
}
player->eye_offset_first = first;
player->eye_offset_third = third;
- SendEyeOffset(player->peer_id, first, third);
+ SendEyeOffset(player->getPeerId(), first, third);
return true;
}
return false;
player->setSky(bgcolor, type, params, clouds);
- SendSetSky(player->peer_id, bgcolor, type, params, clouds);
+ SendSetSky(player->getPeerId(), bgcolor, type, params, clouds);
return true;
}
if (!player)
return false;
- SendCloudParams(player->peer_id, density,
+ SendCloudParams(player->getPeerId(), density,
color_bright, color_ambient, height,
thickness, speed);
return true;
return false;
player->overrideDayNightRatio(do_override, ratio);
- SendOverrideDayNightRatio(player->peer_id, do_override, ratio);
+ SendOverrideDayNightRatio(player->getPeerId(), do_override, ratio);
return true;
}
RemotePlayer *player = m_env->getPlayer(playername.c_str());
if (!player)
return;
- peer_id = player->peer_id;
+ peer_id = player->getPeerId();
proto_ver = player->protocol_version;
}
RemotePlayer *player = m_env->getPlayer(playername.c_str());
if (!player)
return -1;
- peer_id = player->peer_id;
+ peer_id = player->getPeerId();
proto_ver = player->protocol_version;
}
RemotePlayer *player = m_env->getPlayer(playername.c_str());
if (!player)
return;
- peer_id = player->peer_id;
+ peer_id = player->getPeerId();
}
m_env->deleteParticleSpawner(id);
RemotePlayer *player = m_env->getPlayer(name);
// If player is already connected, cancel
- if (player && player->peer_id != 0) {
+ if (player && player->getPeerId() != PEER_ID_INEXISTENT) {
infostream<<"emergePlayer(): Player already connected"<<std::endl;
return NULL;
}
}
void Server::broadcastModChannelMessage(const std::string &channel,
- const std::string &message, u16 from_peer)
+ const std::string &message, session_t from_peer)
{
const std::vector<u16> &peers = m_modchannel_mgr->getChannelPeers(channel);
if (peers.empty())