#include "profiler.h"
#include "raycast.h"
#include "remoteplayer.h"
-#include "scripting_game.h"
+#include "serverscripting.h"
#include "server.h"
#include "voxelalgorithms.h"
#include "util/serialize.h"
*/
ServerEnvironment::ServerEnvironment(ServerMap *map,
- GameScripting *scriptIface, IGameDef *gamedef,
- const std::string &path_world) :
+ ServerScripting *scriptIface, Server *server,
+ const std::string &path_world):
+ Environment(server),
m_map(map),
m_script(scriptIface),
- m_gamedef(gamedef),
+ m_server(server),
m_path_world(path_world),
m_send_recommended_timer(0),
m_active_block_interval_overload_skip(0),
for (std::vector<RemotePlayer *>::iterator it = m_players.begin();
it != m_players.end(); ++it) {
RemotePlayer *player = dynamic_cast<RemotePlayer *>(*it);
- ((Server*)m_gamedef)->DenyAccessVerCompliant(player->peer_id,
+ m_server->DenyAccessVerCompliant(player->peer_id,
player->protocol_version, reason, str_reason, reconnect);
}
}
for (std::vector<RemotePlayer *>::iterator it = m_players.begin();
it != m_players.end();
++it) {
- if ((*it)->checkModified()) {
- (*it)->save(players_path, m_gamedef);
+ if ((*it)->checkModified() ||
+ ((*it)->getPlayerSAO() && (*it)->getPlayerSAO()->extendedAttributesModified())) {
+ (*it)->save(players_path, m_server);
}
}
}
std::string players_path = m_path_world + DIR_DELIM "players";
fs::CreateDir(players_path);
- player->save(players_path, m_gamedef);
+ player->save(players_path, m_server);
}
RemotePlayer *ServerEnvironment::loadPlayer(const std::string &playername, PlayerSAO *sao)
RemotePlayer *player = getPlayer(playername.c_str());
if (!player) {
- player = new RemotePlayer("", m_gamedef->idef());
+ player = new RemotePlayer("", m_server->idef());
newplayer = true;
}
} catch (SettingNotFoundException &e) {
// No problem, this is expected. Just continue with an empty string
}
- m_lbm_mgr.loadIntroductionTimes(lbm_introduction_times, m_gamedef, m_game_time);
+ m_lbm_mgr.loadIntroductionTimes(lbm_introduction_times, m_server, m_game_time);
m_day_count = args.exists("day_count") ?
args.getU64("day_count") : 0;
void ServerEnvironment::loadDefaultMeta()
{
- m_lbm_mgr.loadIntroductionTimes("", m_gamedef, m_game_time);
+ m_lbm_mgr.loadIntroductionTimes("", m_server, m_game_time);
}
struct ActiveABM
v3s16 p0;
for(p0.X=0; p0.X<MAP_BLOCKSIZE; p0.X++)
- for(p0.Y=0; p0.Y<MAP_BLOCKSIZE; p0.Y++)
- for(p0.Z=0; p0.Z<MAP_BLOCKSIZE; p0.Z++)
- {
- const MapNode &n = block->getNodeUnsafe(p0);
- content_t c = n.getContent();
+ for(p0.Y=0; p0.Y<MAP_BLOCKSIZE; p0.Y++)
+ for(p0.Z=0; p0.Z<MAP_BLOCKSIZE; p0.Z++)
+ {
+ const MapNode &n = block->getNodeUnsafe(p0);
+ content_t c = n.getContent();
- if (c >= m_aabms.size() || !m_aabms[c])
- continue;
+ if (c >= m_aabms.size() || !m_aabms[c])
+ continue;
- v3s16 p = p0 + block->getPosRelative();
- for(std::vector<ActiveABM>::iterator
- i = m_aabms[c]->begin(); i != m_aabms[c]->end(); ++i) {
- if(myrand() % i->chance != 0)
- continue;
+ v3s16 p = p0 + block->getPosRelative();
+ for(std::vector<ActiveABM>::iterator
+ i = m_aabms[c]->begin(); i != m_aabms[c]->end(); ++i) {
+ if(myrand() % i->chance != 0)
+ continue;
- // Check neighbors
- if(!i->required_neighbors.empty())
- {
- v3s16 p1;
- for(p1.X = p0.X-1; p1.X <= p0.X+1; p1.X++)
- for(p1.Y = p0.Y-1; p1.Y <= p0.Y+1; p1.Y++)
- for(p1.Z = p0.Z-1; p1.Z <= p0.Z+1; p1.Z++)
- {
- if(p1 == p0)
- continue;
- content_t c;
- if (block->isValidPosition(p1)) {
- // if the neighbor is found on the same map block
- // get it straight from there
- const MapNode &n = block->getNodeUnsafe(p1);
- c = n.getContent();
- } else {
- // otherwise consult the map
- MapNode n = map->getNodeNoEx(p1 + block->getPosRelative());
- c = n.getContent();
- }
- std::set<content_t>::const_iterator k;
- k = i->required_neighbors.find(c);
- if(k != i->required_neighbors.end()){
- goto neighbor_found;
- }
- }
- // No required neighbor found
+ // Check neighbors
+ if(!i->required_neighbors.empty())
+ {
+ v3s16 p1;
+ for(p1.X = p0.X-1; p1.X <= p0.X+1; p1.X++)
+ for(p1.Y = p0.Y-1; p1.Y <= p0.Y+1; p1.Y++)
+ for(p1.Z = p0.Z-1; p1.Z <= p0.Z+1; p1.Z++)
+ {
+ if(p1 == p0)
continue;
+ content_t c;
+ if (block->isValidPosition(p1)) {
+ // if the neighbor is found on the same map block
+ // get it straight from there
+ const MapNode &n = block->getNodeUnsafe(p1);
+ c = n.getContent();
+ } else {
+ // otherwise consult the map
+ MapNode n = map->getNodeNoEx(p1 + block->getPosRelative());
+ c = n.getContent();
}
- neighbor_found:
-
- // Call all the trigger variations
- i->abm->trigger(m_env, p, n);
- i->abm->trigger(m_env, p, n,
- active_object_count, active_object_count_wider);
-
- // Count surrounding objects again if the abms added any
- if(m_env->m_added_objects > 0) {
- active_object_count = countObjects(block, map, active_object_count_wider);
- m_env->m_added_objects = 0;
+ std::set<content_t>::const_iterator k;
+ k = i->required_neighbors.find(c);
+ if(k != i->required_neighbors.end()){
+ goto neighbor_found;
}
}
+ // No required neighbor found
+ continue;
+ }
+ neighbor_found:
+
+ // Call all the trigger variations
+ i->abm->trigger(m_env, p, n);
+ i->abm->trigger(m_env, p, n,
+ active_object_count, active_object_count_wider);
+
+ // Count surrounding objects again if the abms added any
+ if(m_env->m_added_objects > 0) {
+ active_object_count = countObjects(block, map, active_object_count_wider);
+ m_env->m_added_objects = 0;
}
+ }
+ }
}
};
bool ServerEnvironment::setNode(v3s16 p, const MapNode &n)
{
- INodeDefManager *ndef = m_gamedef->ndef();
+ INodeDefManager *ndef = m_server->ndef();
MapNode n_old = m_map->getNodeNoEx(p);
// Call destructor
bool ServerEnvironment::removeNode(v3s16 p)
{
- INodeDefManager *ndef = m_gamedef->ndef();
+ INodeDefManager *ndef = m_server->ndef();
MapNode n_old = m_map->getNodeNoEx(p);
// Call destructor
if (objectpos_over_limit(object->getBasePosition())) {
v3f p = object->getBasePosition();
- errorstream << "ServerEnvironment::addActiveObjectRaw(): "
+ warningstream << "ServerEnvironment::addActiveObjectRaw(): "
<< "object position (" << p.X << "," << p.Y << "," << p.Z
<< ") outside maximum range" << std::endl;
if (object->environmentDeletes())
{
// Add static object to active static list of the block
v3f objectpos = object->getBasePosition();
- std::string staticdata = object->getStaticData();
+ std::string staticdata = "";
+ object->getStaticData(&staticdata);
StaticObject s_obj(object->getType(), objectpos, staticdata);
// Add to the block where the object is located in
v3s16 blockpos = getNodeBlockPos(floatToInt(objectpos, BS));
If block wasn't generated (not in memory or on disk),
*/
-void ServerEnvironment::deactivateFarObjects(bool force_delete)
+void ServerEnvironment::deactivateFarObjects(bool _force_delete)
{
std::vector<u16> objects_to_remove;
for(ActiveObjectMap::iterator i = m_active_objects.begin();
i != m_active_objects.end(); ++i) {
+ // force_delete might be overriden per object
+ bool force_delete = _force_delete;
+
ServerActiveObject* obj = i->second;
assert(obj);
<<std::endl;
continue;
}
- std::string staticdata_new = obj->getStaticData();
+ std::string staticdata_new = "";
+ obj->getStaticData(&staticdata_new);
StaticObject s_obj(obj->getType(), objectpos, staticdata_new);
block->m_static_objects.insert(id, s_obj);
obj->m_static_block = blockpos_o;
if(obj->isStaticAllowed())
{
// Create new static object
- std::string staticdata_new = obj->getStaticData();
+ std::string staticdata_new = "";
+ obj->getStaticData(&staticdata_new);
StaticObject s_obj(obj->getType(), objectpos, staticdata_new);
bool stays_in_same_block = false;