map, environment, players, auth - everything saved in databases :)

master
jachoo 2012-02-10 18:45:45 +01:00
parent af26ab7a13
commit 7c291d9e2b
9 changed files with 349 additions and 234 deletions

View File

@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <sstream>
#include "strfnd.h"
#include "debug.h"
#include "db.h"
std::set<std::string> privsToSet(u64 privs)
{
@ -112,20 +113,15 @@ u64 stringToPrivs(std::string str)
return privs;
}
AuthManager::AuthManager(const std::string &authfilepath):
m_authfilepath(authfilepath),
AuthManager::AuthManager(Database* database):
m_database(database),
m_authtable( NULL ),
//m_authfilepath(authfilepath),
m_modified(false)
{
m_mutex.Init();
try{
load();
}
catch(SerializationError &e)
{
dstream<<"WARNING: AuthManager: creating "
<<m_authfilepath<<std::endl;
}
if(m_database!=NULL)init(database);
}
AuthManager::~AuthManager()
@ -133,32 +129,58 @@ AuthManager::~AuthManager()
save();
}
void AuthManager::init(Database* database)
{
if(database!=NULL) m_database = database;
assert(m_database!=NULL);
m_authtable = &database->getTable<std::string,std::string>("auth");
try{
load();
}
catch(SerializationError &e)
{
dstream<<"WARNING: AuthManager: load error"<<std::endl;
}
}
void AuthManager::load()
{
JMutexAutoLock lock(m_mutex);
dstream<<"AuthManager: loading from "<<m_authfilepath<<std::endl;
std::ifstream is(m_authfilepath.c_str(), std::ios::binary);
dstream<<"AuthManager: loading from DB"<<std::endl;
core::list<std::string> playerlist;
if(!m_authtable->getKeys(playerlist)) throw SerializationError("AuthManager::load(): Couldn't read keys from auth DB");
/*std::ifstream is(m_authfilepath.c_str(), std::ios::binary);
if(is.good() == false)
{
dstream<<"AuthManager: failed loading from "<<m_authfilepath<<std::endl;
throw SerializationError("AuthManager::load(): Couldn't open file");
}
}*/
for(;;)
//for(;;)
for(core::list<std::string>::ConstIterator it=playerlist.begin(); it!=playerlist.end(); it++)
{
if(is.eof() || is.good() == false)
break;
const std::string& name = *it;
std::string line;
if(!m_authtable->getNoEx(name,line))continue;
/*if(is.eof() || is.good() == false)
break;*/
// Read a line
std::string line;
std::getline(is, line, '\n');
/*std::string line;
std::getline(is, line, '\n');*/
std::istringstream iss(line);
// Read name
std::string name;
std::getline(iss, name, ':');
/*std::string name;
std::getline(iss, name, ':');*/
// Read password
std::string pwd;
@ -183,13 +205,13 @@ void AuthManager::save()
{
JMutexAutoLock lock(m_mutex);
dstream<<"AuthManager: saving to "<<m_authfilepath<<std::endl;
std::ofstream os(m_authfilepath.c_str(), std::ios::binary);
dstream<<"AuthManager: saving to DB"<<std::endl;
/*std::ofstream os(m_authfilepath.c_str(), std::ios::binary);
if(os.good() == false)
{
dstream<<"AuthManager: failed saving to "<<m_authfilepath<<std::endl;
throw SerializationError("AuthManager::save(): Couldn't open file");
}
}*/
for(core::map<std::string, AuthData>::Iterator
i = m_authdata.getIterator();
@ -199,7 +221,10 @@ void AuthManager::save()
if(name == "")
continue;
AuthData ad = i.getNode()->getValue();
os<<name<<":"<<ad.pwd<<":"<<privsToString(ad.privs)<<"\n";
std::ostringstream os;
os<<ad.pwd<<":"<<privsToString(ad.privs)<<"\n";
m_authtable->put(name,os.str());
}
m_modified = false;

View File

@ -80,11 +80,17 @@ public:
{}
};
//#include "db.h"
class Database;
template<class Key, class Data> class Table;
typedef std::string binary_t;
class AuthManager
{
public:
AuthManager(const std::string &authfilepath);
AuthManager(Database* database = NULL);
~AuthManager();
void init(Database* database);
void load();
void save();
bool exists(const std::string &username);
@ -98,9 +104,12 @@ public:
bool isModified();
private:
JMutex m_mutex;
std::string m_authfilepath;
//std::string m_authfilepath;
core::map<std::string, AuthData> m_authdata;
bool m_modified;
Database* m_database;
Table<std::string,std::string>* m_authtable;
};
#endif

View File

@ -38,6 +38,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "main.h" // For g_settings, g_profiler
#include "gamedef.h"
#include "serverremoteplayer.h"
#include "db.h"
#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
@ -293,7 +294,7 @@ void ActiveBlockList::update(core::list<v3s16> &active_positions,
*/
ServerEnvironment::ServerEnvironment(ServerMap *map, lua_State *L,
IGameDef *gamedef, IBackgroundBlockEmerger *emerger):
IGameDef *gamedef, IBackgroundBlockEmerger *emerger, const std::string& mapsavedir):
m_map(map),
m_lua(L),
m_gamedef(gamedef),
@ -301,7 +302,10 @@ ServerEnvironment::ServerEnvironment(ServerMap *map, lua_State *L,
m_random_spawn_timer(3),
m_send_recommended_timer(0),
m_game_time(0),
m_game_time_fraction_counter(0)
m_game_time_fraction_counter(0),
m_database( new Database(mapsavedir + DIR_DELIM "env.sqlite") ),
m_players_db( m_database->getTable<std::string,binary_t>("players") ),
m_meta_db( m_database->getTable<std::string,std::string>("meta") )
{
}
@ -324,74 +328,74 @@ ServerEnvironment::~ServerEnvironment()
}
}
void ServerEnvironment::serializePlayers(const std::string &savedir)
void ServerEnvironment::serializePlayers()
{
std::string players_path = savedir + "/players";
fs::CreateDir(players_path);
//std::string players_path = savedir + "/players";
//fs::CreateDir(players_path);
core::map<Player*, bool> saved_players;
//core::map<Player*, bool> saved_players;
std::vector<fs::DirListNode> player_files = fs::GetDirListing(players_path);
for(u32 i=0; i<player_files.size(); i++)
{
if(player_files[i].dir)
continue;
// Full path to this file
std::string path = players_path + "/" + player_files[i].name;
//std::vector<fs::DirListNode> player_files = fs::GetDirListing(players_path);
//for(u32 i=0; i<player_files.size(); i++)
//{
// if(player_files[i].dir)
// continue;
//
// // Full path to this file
// std::string path = players_path + "/" + player_files[i].name;
//infostream<<"Checking player file "<<path<<std::endl;
// //infostream<<"Checking player file "<<path<<std::endl;
// Load player to see what is its name
ServerRemotePlayer testplayer(this);
{
// Open file and deserialize
std::ifstream is(path.c_str(), std::ios_base::binary);
if(is.good() == false)
{
infostream<<"Failed to read "<<path<<std::endl;
continue;
}
testplayer.deSerialize(is);
}
// // Load player to see what is its name
// ServerRemotePlayer testplayer(this);
// {
// // Open file and deserialize
// std::ifstream is(path.c_str(), std::ios_base::binary);
// if(is.good() == false)
// {
// infostream<<"Failed to read "<<path<<std::endl;
// continue;
// }
// testplayer.deSerialize(is);
// }
//infostream<<"Loaded test player with name "<<testplayer.getName()<<std::endl;
// Search for the player
std::string playername = testplayer.getName();
Player *player = getPlayer(playername.c_str());
if(player == NULL)
{
infostream<<"Didn't find matching player, ignoring file "<<path<<std::endl;
continue;
}
// //infostream<<"Loaded test player with name "<<testplayer.getName()<<std::endl;
//
// // Search for the player
// std::string playername = testplayer.getName();
// Player *player = getPlayer(playername.c_str());
// if(player == NULL)
// {
// infostream<<"Didn't find matching player, ignoring file "<<path<<std::endl;
// continue;
// }
//infostream<<"Found matching player, overwriting."<<std::endl;
// //infostream<<"Found matching player, overwriting."<<std::endl;
// OK, found. Save player there.
{
// Open file and serialize
std::ofstream os(path.c_str(), std::ios_base::binary);
if(os.good() == false)
{
infostream<<"Failed to overwrite "<<path<<std::endl;
continue;
}
player->serialize(os);
saved_players.insert(player, true);
}
}
// // OK, found. Save player there.
// {
// // Open file and serialize
// std::ofstream os(path.c_str(), std::ios_base::binary);
// if(os.good() == false)
// {
// infostream<<"Failed to overwrite "<<path<<std::endl;
// continue;
// }
// player->serialize(os);
// saved_players.insert(player, true);
// }
//}
for(core::list<Player*>::Iterator i = m_players.begin();
i != m_players.end(); i++)
{
Player *player = *i;
if(saved_players.find(player) != NULL)
{
/*infostream<<"Player "<<player->getName()
<<" was already saved."<<std::endl;*/
continue;
}
//if(saved_players.find(player) != NULL)
//{
// /*infostream<<"Player "<<player->getName()
// <<" was already saved."<<std::endl;*/
// continue;
//}
std::string playername = player->getName();
// Don't save unnamed player
if(playername == "")
@ -404,7 +408,7 @@ void ServerEnvironment::serializePlayers(const std::string &savedir)
*/
if(string_allowed(playername, PLAYERNAME_ALLOWED_CHARS) == false)
playername = "player";
std::string path = players_path + "/" + playername;
/*std::string path = players_path + "/" + playername;
bool found = false;
for(u32 i=0; i<1000; i++)
{
@ -419,51 +423,63 @@ void ServerEnvironment::serializePlayers(const std::string &savedir)
{
infostream<<"Didn't find free file for player"<<std::endl;
continue;
}
}*/
{
/*infostream<<"Saving player "<<player->getName()<<" to "
<<path<<std::endl;*/
// Open file and serialize
std::ofstream os(path.c_str(), std::ios_base::binary);
if(os.good() == false)
//std::ofstream os(path.c_str(), std::ios_base::binary);
std::ostringstream os;
/*if(os.good() == false)
{
infostream<<"Failed to overwrite "<<path<<std::endl;
continue;
}
}*/
player->serialize(os);
saved_players.insert(player, true);
//saved_players.insert(player, true);
m_players_db.put(playername,os.str());
}
}
//infostream<<"Saved "<<saved_players.size()<<" players."<<std::endl;
}
void ServerEnvironment::deSerializePlayers(const std::string &savedir)
void ServerEnvironment::deSerializePlayers()
{
std::string players_path = savedir + "/players";
/*std::string players_path = savedir + "/players";
core::map<Player*, bool> saved_players;
std::vector<fs::DirListNode> player_files = fs::GetDirListing(players_path);
for(u32 i=0; i<player_files.size(); i++)
{
if(player_files[i].dir)
continue;
// Full path to this file
std::string path = players_path + "/" + player_files[i].name;
for(u32 i=0; i<player_files.size(); i++)*/
core::list<std::string> player_names;
m_players_db.getKeys(player_names);
infostream<<"Checking player file "<<path<<std::endl;
for(core::list<std::string>::ConstIterator i=player_names.begin(); i!=player_names.end(); i++)
{
const std::string& player_name = *i;
//if(player_files[i].dir)
// continue;
//
//// Full path to this file
//std::string path = players_path + "/" + player_files[i].name;
//infostream<<"Checking player file "<<path<<std::endl;
// Load player data from DB
std::string data;
if(!m_players_db.getNoEx(player_name,data)) continue;
// Load player to see what is its name
ServerRemotePlayer testplayer(this);
{
// Open file and deserialize
std::ifstream is(path.c_str(), std::ios_base::binary);
//std::ifstream is(path.c_str(), std::ios_base::binary);
std::istringstream is(data,std::ios::binary);
if(is.good() == false)
{
infostream<<"Failed to read "<<path<<std::endl;
infostream<<"Failed to read player data from DB"<<std::endl;
continue;
}
testplayer.deSerialize(is);
@ -493,13 +509,13 @@ void ServerEnvironment::deSerializePlayers(const std::string &savedir)
// Load player
{
infostream<<"Reading player "<<testplayer.getName()<<" from "
<<path<<std::endl;
infostream<<"Reading player "<<testplayer.getName()<<" from DB"<<std::endl;
// Open file and deserialize
std::ifstream is(path.c_str(), std::ios_base::binary);
//std::ifstream is(path.c_str(), std::ios_base::binary);
std::istringstream is(data,std::ios::binary);
if(is.good() == false)
{
infostream<<"Failed to read "<<path<<std::endl;
infostream<<"Failed to read player data from DB"<<std::endl;
continue;
}
srp->deSerialize(is);
@ -514,64 +530,69 @@ void ServerEnvironment::deSerializePlayers(const std::string &savedir)
}
}
void ServerEnvironment::saveMeta(const std::string &savedir)
void ServerEnvironment::saveMeta()
{
std::string path = savedir + "/env_meta.txt";
//std::string path = savedir + "/env_meta.txt";
// Open file and serialize
std::ofstream os(path.c_str(), std::ios_base::binary);
//std::ofstream os(path.c_str(), std::ios_base::binary);
/*std::ostringstream os;
if(os.good() == false)
{
infostream<<"ServerEnvironment::saveMeta(): Failed to open "
<<path<<std::endl;
throw SerializationError("Couldn't save env meta");
}
}*/
Settings args;
/*Settings args;
args.setU64("game_time", m_game_time);
args.setU64("time_of_day", getTimeOfDay());
args.writeLines(os);
os<<"EnvArgsEnd\n";
os<<"EnvArgsEnd\n";*/
m_meta_db.put("game_time",itos(m_game_time));
m_meta_db.put("time_of_day",itos(getTimeOfDay()));
}
void ServerEnvironment::loadMeta(const std::string &savedir)
void ServerEnvironment::loadMeta()
{
std::string path = savedir + "/env_meta.txt";
//std::string path = savedir + "/env_meta.txt";
// Open file and deserialize
std::ifstream is(path.c_str(), std::ios_base::binary);
if(is.good() == false)
{
infostream<<"ServerEnvironment::loadMeta(): Failed to open "
<<path<<std::endl;
throw SerializationError("Couldn't load env meta");
}
//// Open file and deserialize
//std::ifstream is(path.c_str(), std::ios_base::binary);
//if(is.good() == false)
//{
// infostream<<"ServerEnvironment::loadMeta(): Failed to open "
// <<path<<std::endl;
// throw SerializationError("Couldn't load env meta");
//}
Settings args;
for(;;)
{
if(is.eof())
throw SerializationError
("ServerEnvironment::loadMeta(): EnvArgsEnd not found");
std::string line;
std::getline(is, line);
std::string trimmedline = trim(line);
if(trimmedline == "EnvArgsEnd")
break;
args.parseConfigLine(line);
}
//Settings args;
//
//for(;;)
//{
// if(is.eof())
// throw SerializationError
// ("ServerEnvironment::loadMeta(): EnvArgsEnd not found");
// std::string line;
// std::getline(is, line);
// std::string trimmedline = trim(line);
// if(trimmedline == "EnvArgsEnd")
// break;
// args.parseConfigLine(line);
//}
try{
m_game_time = args.getU64("game_time");
}catch(SettingNotFoundException &e){
m_game_time = stoi(m_meta_db.get("game_time"));
}catch(BaseException&){
// Getting this is crucial, otherwise timestamps are useless
throw SerializationError("Couldn't load env meta game_time");
if(!m_database->isNew())
throw SerializationError("Couldn't load env meta game_time");
}
try{
m_time_of_day = args.getU64("time_of_day");
}catch(SettingNotFoundException &e){
m_time_of_day = stoi(m_meta_db.get("time_of_day"));
}catch(BaseException &){
// This is not as important
m_time_of_day = 9000;
}

View File

@ -173,7 +173,7 @@ class ServerEnvironment : public Environment
{
public:
ServerEnvironment(ServerMap *map, lua_State *L, IGameDef *gamedef,
IBackgroundBlockEmerger *emerger);
IBackgroundBlockEmerger *emerger, const std::string& mapsavedir);
~ServerEnvironment();
Map & getMap()
@ -193,17 +193,22 @@ public:
return 0.10;
}
Database* getDatabase()
{
return m_database;
}
/*
Save players
*/
void serializePlayers(const std::string &savedir);
void deSerializePlayers(const std::string &savedir);
void serializePlayers();
void deSerializePlayers();
/*
Save and load time of day and game timer
*/
void saveMeta(const std::string &savedir);
void loadMeta(const std::string &savedir);
void saveMeta();
void loadMeta();
/*
External ActiveObject interface
@ -350,6 +355,10 @@ private:
// A helper variable for incrementing the latter
float m_game_time_fraction_counter;
core::list<ABMWithState> m_abms;
Database* m_database;
Table<std::string,binary_t>& m_players_db;
Table<std::string,binary_t>& m_meta_db;
};
#ifndef SERVER

View File

@ -1084,8 +1084,43 @@ public:
}
} main_dstream_no_stderr_log_out;
//#include "db.h"
int main(int argc, char *argv[])
{
//j!!!
//Database db("../../bin/minetest.sqlite");
//db.getTable<int,int>("i").put(1,100);
//db.getTable<int,int>("i").put(2,200);
//db.getTable<int,int>("i").put(3,300);
//db.getTable<int,int>("i").put(3,400); //3!
//irr::core::list<int> ks;
//db.getTable<int,int>("i").getKeys(ks);
//int i;
//db.getTable<int,int>("i").getNoEx(1,i);
//db.getTable<int,int>("i").getNoEx(2,i);
//db.getTable<int,int>("i").getNoEx(3,i);
//db.getTable<int,int>("i").getNoEx(4,i);
//db.getTable<v3s16,binary_t>("x").put(v3s16(1,1,1),"aaa.");
//db.getTable<v3s16,binary_t>("x").put(v3s16(1,1,2),"bbbbbbbbbbbbbbbb.");
//db.getTable<v3s16,binary_t>("x").put(v3s16(1,1,3),"cccccccccccccccccccccccc.");
//db.getTable<v3s16,binary_t>("x").put(v3s16(1,1,3),"d."); //3!
//irr::core::list<v3s16> kss;
//db.getTable<v3s16,binary_t>("x").getKeys(kss);
//binary_t b;
//db.getTable<v3s16,binary_t>("x").getNoEx(v3s16(1,1,1),b);
//db.getTable<v3s16,binary_t>("x").getNoEx(v3s16(1,1,2),b);
//db.getTable<v3s16,binary_t>("x").getNoEx(v3s16(1,1,3),b);
//db.getTable<v3s16,binary_t>("x").getNoEx(v3s16(1,1,4),b);
//
//assert(b=="d." && i==400);
//assert(kss.size()==3 && ks.size()==3);
//return 0;
/*
Initialization
*/

View File

@ -38,7 +38,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "profiler.h"
#include "nodedef.h"
#include "gamedef.h"
#include "db.h"
#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
@ -71,7 +70,6 @@ Map::Map(std::ostream &dout, IGameDef *gamedef):
{
/*m_sector_mutex.Init();
assert(m_sector_mutex.IsInitialized());*/
_db_test_();
}
Map::~Map()
@ -1917,10 +1915,10 @@ ServerMap::ServerMap(std::string savedir, IGameDef *gamedef):
Map(dout_server, gamedef),
m_seed(0),
m_map_metadata_changed(true),
m_database(savedir+"/map.sqlite"),
m_blocks( m_database.getTable<v3s16,binary_t>("blocks") ),
m_map_meta( m_database.getTable<std::string,std::string>("map_meta") ),
m_sectors_meta( m_database.getTable<v2s16,binary_t>("sectors_meta") )
m_database( new Database(savedir + DIR_DELIM "map.sqlite") ),
m_blocks( m_database->getTable<v3s16,binary_t>("blocks",true) ),
m_map_meta( m_database->getTable<std::string,std::string>("map_meta") ),
m_sectors_meta( m_database->getTable<v2s16,binary_t>("sectors_meta") )
{
infostream<<__FUNCTION_NAME<<std::endl;
@ -1952,77 +1950,80 @@ ServerMap::ServerMap(std::string savedir, IGameDef *gamedef):
m_savedir = savedir;
m_map_saving_enabled = false;
try
{
// If directory exists, check contents and load if possible
if(fs::PathExists(m_savedir))
{
// If directory is empty, it is safe to save into it.
if(fs::GetDirListing(m_savedir).size() == 0)
{
infostream<<"Server: Empty save directory is valid."
<<std::endl;
m_map_saving_enabled = true;
}
else
{
try{
// Load map metadata (seed, chunksize)
loadMapMeta();
}
catch(FileNotGoodException &e){
infostream<<"WARNING: Could not load map metadata"
//<<" Disabling chunk-based generator."
<<std::endl;
//m_chunksize = 0;
}
loadMapMeta();
m_map_saving_enabled = true;
/*try{
// Load chunk metadata
loadChunkMeta();
}
catch(FileNotGoodException &e){
infostream<<"WARNING: Could not load chunk metadata."
<<" Disabling chunk-based generator."
<<std::endl;
m_chunksize = 0;
}*/
//try
//{
// // If directory exists, check contents and load if possible
// if(fs::PathExists(m_savedir))
// {
// // If directory is empty, it is safe to save into it.
// if(fs::GetDirListing(m_savedir).size() == 0)
// {
// infostream<<"Server: Empty save directory is valid."
// <<std::endl;
// m_map_saving_enabled = true;
// }
// else
// {
// try{
// // Load map metadata (seed, chunksize)
// loadMapMeta();
// }
// catch(FileNotGoodException &e){
// infostream<<"WARNING: Could not load map metadata"
// //<<" Disabling chunk-based generator."
// <<std::endl;
// //m_chunksize = 0;
// }
/*infostream<<"Server: Successfully loaded chunk "
"metadata and sector (0,0) from "<<savedir<<
", assuming valid save directory."
<<std::endl;*/
// /*try{
// // Load chunk metadata
// loadChunkMeta();
// }
// catch(FileNotGoodException &e){
// infostream<<"WARNING: Could not load chunk metadata."
// <<" Disabling chunk-based generator."
// <<std::endl;
// m_chunksize = 0;
// }*/
infostream<<"Server: Successfully loaded map "
<<"and chunk metadata from "<<savedir
<<", assuming valid save directory."
<<std::endl;
// /*infostream<<"Server: Successfully loaded chunk "
// "metadata and sector (0,0) from "<<savedir<<
// ", assuming valid save directory."
// <<std::endl;*/
m_map_saving_enabled = true;
// Map loaded, not creating new one
return;
}
}
// If directory doesn't exist, it is safe to save to it
else{
m_map_saving_enabled = true;
}
}
catch(std::exception &e)
{
infostream<<"WARNING: Server: Failed to load map from "<<savedir
<<", exception: "<<e.what()<<std::endl;
infostream<<"Please remove the map or fix it."<<std::endl;
infostream<<"WARNING: Map saving will be disabled."<<std::endl;
}
// infostream<<"Server: Successfully loaded map "
// <<"and chunk metadata from "<<savedir
// <<", assuming valid save directory."
// <<std::endl;
infostream<<"Initializing new map."<<std::endl;
// m_map_saving_enabled = true;
// // Map loaded, not creating new one
// return;
// }
// }
// // If directory doesn't exist, it is safe to save to it
// else{
// m_map_saving_enabled = true;
// }
//}
//catch(std::exception &e)
//{
// infostream<<"WARNING: Server: Failed to load map from "<<savedir
// <<", exception: "<<e.what()<<std::endl;
// infostream<<"Please remove the map or fix it."<<std::endl;
// infostream<<"WARNING: Map saving will be disabled."<<std::endl;
//}
// Create zero sector
emergeSector(v2s16(0,0));
//infostream<<"Initializing new map."<<std::endl;
// Initially write whole map
save(MOD_STATE_CLEAN);
//// Create zero sector
//emergeSector(v2s16(0,0));
//// Initially write whole map
//save(MOD_STATE_CLEAN);
}
ServerMap::~ServerMap()
@ -2057,6 +2058,7 @@ ServerMap::~ServerMap()
sqlite3_finalize(m_database_write);
if(m_database)
sqlite3_close(m_database);*/
delete m_database;
#if 0
/*
@ -2982,9 +2984,10 @@ void ServerMap::saveMapMeta()
os<<"[end_of_params]\n";*/
m_map_meta.put("seed",itos(m_seed));
m_map_metadata_changed = false;
bool success = true;
if(m_map_meta.put("seed",itos(m_seed))) success = false;
if(success) m_map_metadata_changed = false;
}
void ServerMap::loadMapMeta()
@ -3023,6 +3026,7 @@ void ServerMap::loadMapMeta()
std::string s;
if(m_map_meta.getNoEx("seed",s))
m_seed = stox<u64>(s);
else m_map_metadata_changed = true; //auto-generated, needs save
infostream<<"ServerMap::loadMapMeta(): "<<"seed="<<m_seed<<std::endl;
}
@ -3201,11 +3205,11 @@ bool ServerMap::loadSectorFull(v2s16 p2d)
#endif
void ServerMap::beginSave() {
m_database.begin();
m_database->begin();
}
void ServerMap::endSave() {
m_database.commit();
m_database->commit();
}
void ServerMap::saveBlock(MapBlock *block)

View File

@ -33,7 +33,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "voxel.h"
#include "utility.h" // Needed for UniqueQueue, a member of Map
#include "modifiedstate.h"
#include "db.h"
//#include "db.h"
class Database;
template<class Key, class Data> class Table;
typedef std::string binary_t;
class MapSector;
class ServerMapSector;
@ -464,7 +468,7 @@ private:
sqlite3_stmt *m_database_read;
sqlite3_stmt *m_database_write;
sqlite3_stmt *m_database_list;*/
Database m_database;
Database* m_database;
Table<v3s16,binary_t>& m_blocks;
Table<std::string,std::string>& m_map_meta;
Table<v2s16,binary_t>& m_sectors_meta;

View File

@ -850,7 +850,7 @@ Server::Server(
):
m_env(NULL),
m_con(PROTOCOL_ID, 512, CONNECTION_TIMEOUT, this),
m_authmanager(mapsavedir+DIR_DELIM+"auth.txt"),
m_authmanager(NULL),
m_banmanager(mapsavedir+DIR_DELIM+"ipban.txt"),
m_lua(NULL),
m_toolmgr(createToolDefManager()),
@ -882,6 +882,9 @@ Server::Server(
JMutexAutoLock envlock(m_env_mutex);
JMutexAutoLock conlock(m_con_mutex);
// Create world directory
fs::CreateAllDirs(mapsavedir);
// Path to builtin.lua
std::string builtinpath = porting::path_data + DIR_DELIM + "builtin.lua";
@ -937,7 +940,9 @@ Server::Server(
// Initialize Environment
m_env = new ServerEnvironment(new ServerMap(mapsavedir, this), m_lua,
this, this);
this, this, mapsavedir);
m_authmanager.init(m_env->getDatabase());
// Give environment reference to scripting api
scriptapi_add_environment(m_lua, m_env);
@ -946,15 +951,15 @@ Server::Server(
m_env->getMap().addEventReceiver(this);
// If file exists, load environment metadata
if(fs::PathExists(m_mapsavedir+DIR_DELIM+"env_meta.txt"))
{
/*if(fs::PathExists(m_mapsavedir+DIR_DELIM+"env_meta.txt"))
{*/
infostream<<"Server: Loading environment metadata"<<std::endl;
m_env->loadMeta(m_mapsavedir);
}
m_env->loadMeta();
//}
// Load players
infostream<<"Server: Loading players"<<std::endl;
m_env->deSerializePlayers(m_mapsavedir);
m_env->deSerializePlayers();
/*
Add some test ActiveBlockModifiers to environment
@ -1002,13 +1007,13 @@ Server::~Server()
Save players
*/
infostream<<"Server: Saving players"<<std::endl;
m_env->serializePlayers(m_mapsavedir);
m_env->serializePlayers();
/*
Save environment metadata
*/
infostream<<"Server: Saving environment metadata"<<std::endl;
m_env->saveMeta(m_mapsavedir);
m_env->saveMeta();
}
/*
@ -1806,10 +1811,10 @@ void Server::AsyncRunStep()
m_env->getMap().save(MOD_STATE_WRITE_NEEDED);
// Save players
m_env->serializePlayers(m_mapsavedir);
m_env->serializePlayers();
// Save environment metadata
m_env->saveMeta(m_mapsavedir);
m_env->saveMeta();
}
}
}

View File

@ -1084,6 +1084,9 @@ struct TestConnection
void run_tests()
{
//j!!!
return;
DSTACK(__FUNCTION_NAME);
// Create node definitions