diff options
author | Perttu Ahola <celeron55@gmail.com> | 2012-03-11 04:15:45 +0200 |
---|---|---|
committer | Perttu Ahola <celeron55@gmail.com> | 2012-03-11 04:15:45 +0200 |
commit | f1d9880006cf713597c1fc573f83db75062712c9 (patch) | |
tree | c5b056acf05ce408964b79b32e3e84a3619b2cdd /src | |
parent | 6ec447a1aa3678371af31aad4e186885ca4b8f27 (diff) | |
download | minetest-f1d9880006cf713597c1fc573f83db75062712c9.tar.gz minetest-f1d9880006cf713597c1fc573f83db75062712c9.tar.bz2 minetest-f1d9880006cf713597c1fc573f83db75062712c9.zip |
Clean up log messages everywhere
Diffstat (limited to 'src')
-rw-r--r-- | src/clouds.cpp | 3 | ||||
-rw-r--r-- | src/content_sao.cpp | 4 | ||||
-rw-r--r-- | src/craftdef.cpp | 2 | ||||
-rw-r--r-- | src/debug.cpp | 4 | ||||
-rw-r--r-- | src/environment.cpp | 12 | ||||
-rw-r--r-- | src/gettext.h | 6 | ||||
-rw-r--r-- | src/itemdef.cpp | 4 | ||||
-rw-r--r-- | src/main.cpp | 14 | ||||
-rw-r--r-- | src/map.cpp | 49 | ||||
-rw-r--r-- | src/nodedef.cpp | 2 | ||||
-rw-r--r-- | src/porting.cpp | 5 | ||||
-rw-r--r-- | src/script.cpp | 2 | ||||
-rw-r--r-- | src/scriptapi.cpp | 30 | ||||
-rw-r--r-- | src/server.cpp | 321 | ||||
-rw-r--r-- | src/server.h | 21 | ||||
-rw-r--r-- | src/settings.h | 2 |
16 files changed, 240 insertions, 241 deletions
diff --git a/src/clouds.cpp b/src/clouds.cpp index 232436597..784d611f2 100644 --- a/src/clouds.cpp +++ b/src/clouds.cpp @@ -38,8 +38,6 @@ Clouds::Clouds( m_camera_pos(0,0), m_time(0) { - dstream<<__FUNCTION_NAME<<std::endl; - m_material.setFlag(video::EMF_LIGHTING, false); m_material.setFlag(video::EMF_BACK_FACE_CULLING, false); m_material.setFlag(video::EMF_BILINEAR_FILTER, false); @@ -54,7 +52,6 @@ Clouds::Clouds( Clouds::~Clouds() { - dstream<<__FUNCTION_NAME<<std::endl; } void Clouds::OnRegisterSceneNode() diff --git a/src/content_sao.cpp b/src/content_sao.cpp index b04f03f26..85340981d 100644 --- a/src/content_sao.cpp +++ b/src/content_sao.cpp @@ -517,7 +517,7 @@ std::string LuaEntitySAO::getClientInitializationData() std::string LuaEntitySAO::getStaticData() { - infostream<<__FUNCTION_NAME<<std::endl; + verbosestream<<__FUNCTION_NAME<<std::endl; std::ostringstream os(std::ios::binary); // version writeU8(os, 1); @@ -641,7 +641,7 @@ std::string LuaEntitySAO::getDescription() os<<(m_base_position.Y/BS)<<","; os<<(m_base_position.Z/BS); os<<")"; - return std::string("LuaEntitySAO"); + return os.str(); } void LuaEntitySAO::setVelocity(v3f velocity) diff --git a/src/craftdef.cpp b/src/craftdef.cpp index 5bcbf6f94..d21a1b5e7 100644 --- a/src/craftdef.cpp +++ b/src/craftdef.cpp @@ -827,7 +827,7 @@ public: } virtual void registerCraft(CraftDefinition *def) { - infostream<<"registerCraft: registering craft definition: " + verbosestream<<"registerCraft: registering craft definition: " <<def->dump()<<std::endl; m_craft_definitions.push_back(def); } diff --git a/src/debug.cpp b/src/debug.cpp index ad02c5110..fb04ba952 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -45,8 +45,8 @@ void debugstreams_init(bool disable_stderr, const char *filename) fprintf(g_debugstreams[1], "-------------\n\n"); } - DEBUGPRINT("Debug streams initialized, disable_stderr=%d\n", - disable_stderr); + DEBUGPRINT("Debug streams initialized, %s\n", + disable_stderr?"not printing on stderr":"using stderr"); } void debugstreams_deinit() diff --git a/src/environment.cpp b/src/environment.cpp index 6a8943d12..cfe82fb8b 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -454,7 +454,7 @@ void ServerEnvironment::deSerializePlayers(const std::string &savedir) // 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); @@ -475,8 +475,8 @@ void ServerEnvironment::deSerializePlayers(const std::string &savedir) <<testplayer.getName()<<std::endl; } - infostream<<"Loaded test player with name "<<testplayer.getName() - <<std::endl; + /*infostream<<"Loaded test player with name "<<testplayer.getName() + <<std::endl;*/ // Search for the player std::string playername = testplayer.getName(); @@ -484,7 +484,7 @@ void ServerEnvironment::deSerializePlayers(const std::string &savedir) bool newplayer = false; if(player == NULL) { - infostream<<"Is a new player"<<std::endl; + //infostream<<"Is a new player"<<std::endl; player = new ServerRemotePlayer(this); newplayer = true; } @@ -493,7 +493,7 @@ void ServerEnvironment::deSerializePlayers(const std::string &savedir) // Load player { - infostream<<"Reading player "<<testplayer.getName()<<" from " + verbosestream<<"Reading player "<<testplayer.getName()<<" from " <<path<<std::endl; // Open file and deserialize std::ifstream is(path.c_str(), std::ios_base::binary); @@ -2254,7 +2254,7 @@ void ClientEnvironment::addActiveObject(u16 id, u8 type, void ClientEnvironment::removeActiveObject(u16 id) { - infostream<<"ClientEnvironment::removeActiveObject(): " + verbosestream<<"ClientEnvironment::removeActiveObject(): " <<"id="<<id<<std::endl; ClientActiveObject* obj = getActiveObject(id); if(obj == NULL) diff --git a/src/gettext.h b/src/gettext.h index 0e6ee0fd5..54470cb0d 100644 --- a/src/gettext.h +++ b/src/gettext.h @@ -1,6 +1,6 @@ #ifndef GETTEXT_HEADER #include "config.h" // for USE_GETTEXT -#include <iostream> +#include "log.h" #if USE_GETTEXT #include <libintl.h> @@ -41,9 +41,9 @@ inline void changeCtype(const char *l) char *ret = NULL; ret = setlocale(LC_CTYPE, l); if(ret == NULL) - std::cout<<"locale could not be set"<<std::endl; + infostream<<"locale could not be set"<<std::endl; else - std::cout<<"locale has been set to:"<<ret<<std::endl; + infostream<<"locale has been set to:"<<ret<<std::endl; } #define GETTEXT_HEADER #endif diff --git a/src/itemdef.cpp b/src/itemdef.cpp index 98232c6d5..ace9c253f 100644 --- a/src/itemdef.cpp +++ b/src/itemdef.cpp @@ -286,7 +286,7 @@ public: } virtual void registerItem(const ItemDefinition &def) { - infostream<<"ItemDefManager: registering \""<<def.name<<"\""<<std::endl; + verbosestream<<"ItemDefManager: registering \""<<def.name<<"\""<<std::endl; // Ensure that the "" item (the hand) always has ToolCapabilities if(def.name == "") assert(def.tool_capabilities != NULL); @@ -304,7 +304,7 @@ public: { if(m_item_definitions.find(name) == m_item_definitions.end()) { - infostream<<"ItemDefManager: setting alias "<<name + verbosestream<<"ItemDefManager: setting alias "<<name <<" -> "<<convert_to<<std::endl; m_aliases[name] = convert_to; } diff --git a/src/main.cpp b/src/main.cpp index 83bca7c44..3f75391d8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1188,8 +1188,8 @@ int main(int argc, char *argv[]) DSTACK(__FUNCTION_NAME); - // Init material properties table - //initializeMaterialProperties(); + dstream<<"path_share = "<<porting::path_share<<std::endl; + dstream<<"path_user = "<<porting::path_user<<std::endl; // Debug handler BEGIN_DEBUG_EXCEPTION_HANDLER @@ -1323,16 +1323,6 @@ int main(int argc, char *argv[]) Server server(map_dir, configpath, "mesetint"); server.start(port); - // ASCII art for the win! - actionstream - <<" .__ __ __ "<<std::endl - <<" _____ |__| ____ _____/ |_ ____ _______/ |_ "<<std::endl - <<" / \\| |/ \\_/ __ \\ __\\/ __ \\ / ___/\\ __\\"<<std::endl - <<"| Y Y \\ | | \\ ___/| | \\ ___/ \\___ \\ | | "<<std::endl - <<"|__|_| /__|___| /\\___ >__| \\___ >____ > |__| "<<std::endl - <<" \\/ \\/ \\/ \\/ \\/ "<<std::endl; - actionstream<<"Listening at port "<<port<<"."<<std::endl; - // Run server dedicated_server_loop(server, kill); diff --git a/src/map.cpp b/src/map.cpp index c245242e8..e0175a4ab 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -1916,7 +1916,7 @@ ServerMap::ServerMap(std::string savedir, IGameDef *gamedef): m_database_read(NULL), m_database_write(NULL) { - infostream<<__FUNCTION_NAME<<std::endl; + verbosestream<<__FUNCTION_NAME<<std::endl; //m_chunksize = 8; // Takes a few seconds @@ -1954,7 +1954,7 @@ ServerMap::ServerMap(std::string savedir, IGameDef *gamedef): // 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." + infostream<<"ServerMap: Empty save directory is valid." <<std::endl; m_map_saving_enabled = true; } @@ -1971,25 +1971,10 @@ ServerMap::ServerMap(std::string savedir, IGameDef *gamedef): //m_chunksize = 0; } - /*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 chunk " - "metadata and sector (0,0) from "<<savedir<< - ", assuming valid save directory." - <<std::endl;*/ - - infostream<<"Server: Successfully loaded map " - <<"and chunk metadata from "<<savedir + infostream<<"ServerMap: Successfully loaded map " + <<"metadata from "<<savedir <<", assuming valid save directory." + <<" seed="<<m_seed<<"." <<std::endl; m_map_saving_enabled = true; @@ -2004,7 +1989,7 @@ ServerMap::ServerMap(std::string savedir, IGameDef *gamedef): } catch(std::exception &e) { - infostream<<"WARNING: Server: Failed to load map from "<<savedir + infostream<<"WARNING: ServerMap: 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; @@ -2021,7 +2006,7 @@ ServerMap::ServerMap(std::string savedir, IGameDef *gamedef): ServerMap::~ServerMap() { - infostream<<__FUNCTION_NAME<<std::endl; + verbosestream<<__FUNCTION_NAME<<std::endl; try { @@ -2029,16 +2014,16 @@ ServerMap::~ServerMap() { // Save only changed parts save(MOD_STATE_WRITE_AT_UNLOAD); - infostream<<"Server: saved map to "<<m_savedir<<std::endl; + infostream<<"ServerMap: Saved map to "<<m_savedir<<std::endl; } else { - infostream<<"Server: map not saved"<<std::endl; + infostream<<"ServerMap: Map not saved"<<std::endl; } } catch(std::exception &e) { - infostream<<"Server: Failed to save map to "<<m_savedir + infostream<<"ServerMap: Failed to save map to "<<m_savedir <<", exception: "<<e.what()<<std::endl; } @@ -2693,7 +2678,7 @@ void ServerMap::createDatabase() { if(e == SQLITE_ABORT) throw FileNotGoodException("Could not create database structure"); else - infostream<<"Server: Database structure was created"; + infostream<<"ServerMap: Database structure was created"; } void ServerMap::verifyDatabase() { @@ -2741,7 +2726,7 @@ void ServerMap::verifyDatabase() { throw FileNotGoodException("Cannot prepare read statement"); } - infostream<<"Server: Database opened"<<std::endl; + infostream<<"ServerMap: Database opened"<<std::endl; } } @@ -2977,9 +2962,9 @@ void ServerMap::saveMapMeta() { DSTACK(__FUNCTION_NAME); - infostream<<"ServerMap::saveMapMeta(): " + /*infostream<<"ServerMap::saveMapMeta(): " <<"seed="<<m_seed - <<std::endl; + <<std::endl;*/ createDirs(m_savedir); @@ -3006,8 +2991,8 @@ void ServerMap::loadMapMeta() { DSTACK(__FUNCTION_NAME); - infostream<<"ServerMap::loadMapMeta(): Loading map metadata" - <<std::endl; + /*infostream<<"ServerMap::loadMapMeta(): Loading map metadata" + <<std::endl;*/ std::string fullpath = m_savedir + DIR_DELIM + "map_meta.txt"; std::ifstream is(fullpath.c_str(), std::ios_base::binary); @@ -3035,7 +3020,7 @@ void ServerMap::loadMapMeta() m_seed = params.getU64("seed"); - infostream<<"ServerMap::loadMapMeta(): "<<"seed="<<m_seed<<std::endl; + verbosestream<<"ServerMap::loadMapMeta(): "<<"seed="<<m_seed<<std::endl; } void ServerMap::saveSectorMeta(ServerMapSector *sector) diff --git a/src/nodedef.cpp b/src/nodedef.cpp index cc8009ab7..f24497dd8 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -368,7 +368,7 @@ public: // IWritableNodeDefManager virtual void set(content_t c, const ContentFeatures &def) { - infostream<<"registerNode: registering content id \""<<c + verbosestream<<"registerNode: registering content id \""<<c <<"\": name=\""<<def.name<<"\""<<std::endl; assert(c <= MAX_CONTENT); // Don't allow redefining CONTENT_IGNORE (but allow air) diff --git a/src/porting.cpp b/src/porting.cpp index edf950635..57da69e82 100644 --- a/src/porting.cpp +++ b/src/porting.cpp @@ -71,7 +71,6 @@ void sigint_handler(int sig) void signal_handler_init(void) { - dstream<<"signal_handler_init()"<<std::endl; (void)signal(SIGINT, sigint_handler); } @@ -114,7 +113,6 @@ void signal_handler_init(void) void signal_handler_init(void) { - dstream<<"signal_handler_init()"<<std::endl; SetConsoleCtrlHandler( (PHANDLER_ROUTINE)event_handler,TRUE); } @@ -288,9 +286,6 @@ void initializePaths() #endif #endif // RUN_IN_PLACE - - dstream<<"path_share = "<<path_share<<std::endl; - dstream<<"path_user = "<<path_user<<std::endl; } } //namespace porting diff --git a/src/script.cpp b/src/script.cpp index f91b22896..1925ea701 100644 --- a/src/script.cpp +++ b/src/script.cpp @@ -89,7 +89,7 @@ int luaErrorHandler(lua_State *L) { bool script_load(lua_State *L, const char *path) { - infostream<<"Loading and running script from "<<path<<std::endl; + verbosestream<<"Loading and running script from "<<path<<std::endl; lua_pushcfunction(L, luaErrorHandler); int errorhandler = lua_gettop(L); diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp index 7bdf7a9f4..99c3767ae 100644 --- a/src/scriptapi.cpp +++ b/src/scriptapi.cpp @@ -2240,7 +2240,7 @@ private: ObjectRef *ref = checkobject(L, 1); ServerActiveObject *co = getobject(ref); if(co == NULL) return 0; - infostream<<"ObjectRef::l_remove(): id="<<co->getId()<<std::endl; + verbosestream<<"ObjectRef::l_remove(): id="<<co->getId()<<std::endl; co->m_removed = true; return 0; } @@ -2340,8 +2340,8 @@ private: ServerActiveObject *co = getobject(ref); if(co == NULL) return 0; int hp = lua_tonumber(L, 2); - infostream<<"ObjectRef::l_set_hp(): id="<<co->getId() - <<" hp="<<hp<<std::endl; + /*infostream<<"ObjectRef::l_set_hp(): id="<<co->getId() + <<" hp="<<hp<<std::endl;*/ // Do it co->setHP(hp); // Return @@ -2357,8 +2357,8 @@ private: ServerActiveObject *co = getobject(ref); if(co == NULL) return 0; int hp = co->getHP(); - infostream<<"ObjectRef::l_get_hp(): id="<<co->getId() - <<" hp="<<hp<<std::endl; + /*infostream<<"ObjectRef::l_get_hp(): id="<<co->getId() + <<" hp="<<hp<<std::endl;*/ // Return lua_pushnumber(L, hp); return 1; @@ -3029,12 +3029,12 @@ public: EnvRef(ServerEnvironment *env): m_env(env) { - infostream<<"EnvRef created"<<std::endl; + //infostream<<"EnvRef created"<<std::endl; } ~EnvRef() { - infostream<<"EnvRef destructing"<<std::endl; + //infostream<<"EnvRef destructing"<<std::endl; } // Creates an EnvRef and leaves it on top of stack @@ -3230,7 +3230,7 @@ static int l_register_item_raw(lua_State *L) lua_getfield(L, table, "name"); if(lua_isstring(L, -1)){ std::string name = lua_tostring(L, -1); - infostream<<"register_item_raw: "<<name<<std::endl; + verbosestream<<"register_item_raw: "<<name<<std::endl; } else { throw LuaError(L, "register_item_raw: name is not defined or not a string"); } @@ -3672,7 +3672,7 @@ void scriptapi_export(lua_State *L, Server *server) { realitycheck(L); assert(lua_checkstack(L, 20)); - infostream<<"scriptapi_export"<<std::endl; + verbosestream<<"scriptapi_export()"<<std::endl; StackUnroller stack_unroller(L); // Store server as light userdata in registry @@ -3732,7 +3732,7 @@ void scriptapi_add_environment(lua_State *L, ServerEnvironment *env) { realitycheck(L); assert(lua_checkstack(L, 20)); - infostream<<"scriptapi_add_environment"<<std::endl; + verbosestream<<"scriptapi_add_environment"<<std::endl; StackUnroller stack_unroller(L); // Create EnvRef on stack @@ -4230,7 +4230,7 @@ bool scriptapi_luaentity_add(lua_State *L, u16 id, const char *name) { realitycheck(L); assert(lua_checkstack(L, 20)); - infostream<<"scriptapi_luaentity_add: id="<<id<<" name=\"" + verbosestream<<"scriptapi_luaentity_add: id="<<id<<" name=\"" <<name<<"\""<<std::endl; StackUnroller stack_unroller(L); @@ -4281,7 +4281,7 @@ void scriptapi_luaentity_activate(lua_State *L, u16 id, { realitycheck(L); assert(lua_checkstack(L, 20)); - infostream<<"scriptapi_luaentity_activate: id="<<id<<std::endl; + verbosestream<<"scriptapi_luaentity_activate: id="<<id<<std::endl; StackUnroller stack_unroller(L); // Get minetest.luaentities[id] @@ -4306,7 +4306,7 @@ void scriptapi_luaentity_rm(lua_State *L, u16 id) { realitycheck(L); assert(lua_checkstack(L, 20)); - infostream<<"scriptapi_luaentity_rm: id="<<id<<std::endl; + verbosestream<<"scriptapi_luaentity_rm: id="<<id<<std::endl; // Get minetest.luaentities table lua_getglobal(L, "minetest"); @@ -4326,7 +4326,7 @@ std::string scriptapi_luaentity_get_staticdata(lua_State *L, u16 id) { realitycheck(L); assert(lua_checkstack(L, 20)); - infostream<<"scriptapi_luaentity_get_staticdata: id="<<id<<std::endl; + //infostream<<"scriptapi_luaentity_get_staticdata: id="<<id<<std::endl; StackUnroller stack_unroller(L); // Get minetest.luaentities[id] @@ -4356,7 +4356,7 @@ void scriptapi_luaentity_get_properties(lua_State *L, u16 id, { realitycheck(L); assert(lua_checkstack(L, 20)); - infostream<<"scriptapi_luaentity_get_properties: id="<<id<<std::endl; + //infostream<<"scriptapi_luaentity_get_properties: id="<<id<<std::endl; StackUnroller stack_unroller(L); // Get minetest.luaentities[id] diff --git a/src/server.cpp b/src/server.cpp index ad4524901..1eb618f7c 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -824,18 +824,11 @@ void PlayerInfo::PrintLine(std::ostream *s) (*s)<<std::endl; } -u32 PIChecksum(core::list<PlayerInfo> &l) +static std::string padStringRight(std::string s, size_t len) { - core::list<PlayerInfo>::Iterator i; - u32 checksum = 1; - u32 a = 10; - for(i=l.begin(); i!=l.end(); i++) - { - checksum += a * (i->id+1); - checksum ^= 0x435aafcd; - a *= 10; - } - return checksum; + if(len > s.size()) + s.insert(s.end(), len - s.size(), ' '); + return s; } /* @@ -867,11 +860,6 @@ Server::Server( m_ignore_map_edit_events(false), m_ignore_map_edit_events_peer_id(0) { - infostream<<"Server created."<<std::endl; - infostream<<"- path_world = "<<path_world<<std::endl; - infostream<<"- path_config = "<<path_config<<std::endl; - infostream<<"- gamename = "<<gamename<<std::endl; - m_liquid_transform_timer = 0.0; m_print_info_timer = 0.0; m_objectdata_timer = 0.0; @@ -884,13 +872,36 @@ Server::Server( m_step_dtime = 0.0; // Figure out some paths + // share/server m_path_share = porting::path_share + DIR_DELIM + "server"; - m_path_game = m_path_share + DIR_DELIM + "games" + DIR_DELIM + m_gamename; - m_path_addons.insert(m_path_share + DIR_DELIM + "addons" - + DIR_DELIM + m_gamename); + // game + m_path_game = porting::path_user + DIR_DELIM + "server" + DIR_DELIM + + "games" + DIR_DELIM + m_gamename; + bool user_game = true; // Game is in user's directory + if(!fs::PathExists(m_path_game)){ + m_path_game = m_path_share + DIR_DELIM + "games" + DIR_DELIM + + m_gamename; + user_game = false; + } + if(!fs::PathExists(m_path_game)){ + throw ServerError("Could not find game files for game \"" + +gamename+"\""); + } + // addons + if(!user_game) + m_path_addons.insert(m_path_share + DIR_DELIM + "addons" + + DIR_DELIM + m_gamename); m_path_addons.insert(porting::path_user + DIR_DELIM + "server" + DIR_DELIM + "addons" + DIR_DELIM + m_gamename); + infostream<<"Server created for gamename=\""<<gamename<<"\""<<std::endl; + infostream<<"- path_world = "<<m_path_world<<std::endl; + infostream<<"- path_config = "<<m_path_config<<std::endl; + infostream<<"- path_game = "<<m_path_game<<std::endl; + for(std::set<std::string>::const_iterator i = m_path_addons.begin(); + i != m_path_addons.end(); i++) + infostream<<"- path_addons+= "<<(*i)<<std::endl; + // Path to builtin.lua std::string builtinpath = m_path_share + DIR_DELIM + "builtin.lua"; @@ -903,13 +914,12 @@ Server::Server( i != m_path_addons.end(); i++){ m_modspaths.push_front((*i) + DIR_DELIM + "mods"); } - + // Print out mod search paths - infostream<<"- mod search paths:"<<std::endl; for(core::list<std::string>::Iterator i = m_modspaths.begin(); i != m_modspaths.end(); i++){ std::string modspath = *i; - infostream<<" "<<modspath<<std::endl; + infostream<<"- modspath += "<<modspath<<std::endl; } // Lock environment @@ -918,27 +928,37 @@ Server::Server( // Initialize scripting - infostream<<"Server: Initializing scripting"<<std::endl; + infostream<<"Server: Initializing Lua"<<std::endl; m_lua = script_init(); assert(m_lua); // Export API scriptapi_export(m_lua, this); // Load and run builtin.lua - infostream<<"Server: Loading builtin Lua stuff from \""<<builtinpath - <<"\""<<std::endl; + infostream<<"Server: Loading builtin.lua [\"" + <<builtinpath<<"\"]"<<std::endl; bool success = scriptapi_loadmod(m_lua, builtinpath, "__builtin"); if(!success){ errorstream<<"Server: Failed to load and run " <<builtinpath<<std::endl; throw ModError("Failed to load and run "+builtinpath); } - // Load and run "mod" scripts + // Find mods in mod search paths m_mods = getMods(m_modspaths); + // Print 'em + infostream<<"Server: Loading mods: "; + for(core::list<ModSpec>::Iterator i = m_mods.begin(); + i != m_mods.end(); i++){ + const ModSpec &mod = *i; + infostream<<mod.name<<" "; + } + infostream<<std::endl; + // Load and run "mod" scripts for(core::list<ModSpec>::Iterator i = m_mods.begin(); i != m_mods.end(); i++){ const ModSpec &mod = *i; - infostream<<"Server: Loading mod \""<<mod.name<<"\""<<std::endl; std::string scriptpath = mod.path + DIR_DELIM + "init.lua"; + infostream<<" ["<<padStringRight(mod.name, 12)<<"] [\"" + <<scriptpath<<"\"]"<<std::endl; bool success = scriptapi_loadmod(m_lua, scriptpath, mod.name); if(!success){ errorstream<<"Server: Failed to load and run " @@ -983,7 +1003,7 @@ Server::Server( Server::~Server() { - infostream<<"Server::~Server()"<<std::endl; + infostream<<"Server destructing"<<std::endl; /* Send shutdown message @@ -1084,7 +1104,15 @@ void Server::start(unsigned short port) m_thread.setRun(true); m_thread.Start(); - infostream<<"Server started on port "<<port<<"."<<std::endl; + // ASCII art for the win! + actionstream + <<" .__ __ __ "<<std::endl + <<" _____ |__| ____ _____/ |_ ____ _______/ |_ "<<std::endl + <<" / \\| |/ \\_/ __ \\ __\\/ __ \\ / ___/\\ __\\"<<std::endl + <<"| Y Y \\ | | \\ ___/| | \\ ___/ \\___ \\ | | "<<std::endl + <<"|__|_| /__|___| /\\___ >__| \\___ >____ > |__| "<<std::endl + <<" \\/ \\/ \\/ \\/ \\/ "<<std::endl; + actionstream<<"Server listening on port "<<port<<"."<<std::endl; } void Server::stop() @@ -1514,7 +1542,7 @@ void Server::AsyncRunStep() // Send as reliable m_con.Send(client->peer_id, 0, reply, true); - infostream<<"Server: Sent object remove/add: " + verbosestream<<"Server: Sent object remove/add: " <<removed_objects.size()<<" removed, " <<added_objects.size()<<" added, " <<"packet size is "<<reply.getSize()<<std::endl; @@ -1677,15 +1705,13 @@ void Server::AsyncRunStep() if(m_unsent_map_edit_queue.size() >= 4) disable_single_change_sending = true; - bool got_any_events = false; + int event_count = m_unsent_map_edit_queue.size(); // We'll log the amount of each Profiler prof; while(m_unsent_map_edit_queue.size() != 0) { - got_any_events = true; - MapEditEvent* event = m_unsent_map_edit_queue.pop_front(); // Players far away from the change are stored here. @@ -1776,10 +1802,12 @@ void Server::AsyncRunStep() break;*/ } - if(got_any_events) - { + if(event_count >= 5){ infostream<<"Server: MapEditEvents:"<<std::endl; prof.print(infostream); + } else if(event_count != 0){ + verbosestream<<"Server: MapEditEvents:"<<std::endl; + prof.print(verbosestream); } } @@ -1899,6 +1927,8 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) <<peer_id<<" not found"<<std::endl; return; } + + std::string addr_s = m_con.GetPeerAddress(peer_id).serializeString(); u8 peer_ser_ver = getClient(peer_id)->serialization_version; @@ -1920,7 +1950,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) if(datasize < 2+1+PLAYERNAME_SIZE) return; - infostream<<"Server: Got TOSERVER_INIT from " + verbosestream<<"Server: Got TOSERVER_INIT from " <<peer_id<<std::endl; // First byte after command is maximum supported @@ -1938,8 +1968,8 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) if(deployed == SER_FMT_VER_INVALID) { - actionstream<<"Server: A mismatched client tried to connect." - <<std::endl; + actionstream<<"Server: A mismatched client tried to connect from " + <<addr_s<<std::endl; infostream<<"Server: Cannot negotiate " "serialization version with peer " <<peer_id<<std::endl; @@ -1965,7 +1995,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) if(net_proto_version == 0) { - actionstream<<"Server: An old tried to connect." + actionstream<<"Server: An old tried to connect from "<<addr_s <<std::endl; SendAccessDenied(m_con, peer_id, std::wstring( L"Your client's version is not supported.\n" @@ -1979,8 +2009,8 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) { if(net_proto_version != PROTOCOL_VERSION) { - actionstream<<"Server: A mismatched client tried to connect." - <<std::endl; + actionstream<<"Server: A mismatched client tried to connect" + <<" from "<<addr_s<<std::endl; SendAccessDenied(m_con, peer_id, std::wstring( L"Your client's version is not supported.\n" L"Server version is ") @@ -2009,7 +2039,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) if(playername[0]=='\0') { actionstream<<"Server: Player with an empty name " - <<"tried to connect."<<std::endl; + <<"tried to connect from "<<addr_s<<std::endl; SendAccessDenied(m_con, peer_id, L"Empty name"); return; @@ -2018,12 +2048,15 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) if(string_allowed(playername, PLAYERNAME_ALLOWED_CHARS)==false) { actionstream<<"Server: Player with an invalid name " - <<"tried to connect."<<std::endl; + <<"tried to connect from "<<addr_s<<std::endl; SendAccessDenied(m_con, peer_id, L"Name contains unallowed characters"); return; } + infostream<<"Server: New connection: \""<<playername<<"\" from " + <<m_con.GetPeerAddress(peer_id).serializeString()<<std::endl; + // Get password char password[PASSWORD_SIZE]; if(datasize < 2+1+PLAYERNAME_SIZE+PASSWORD_SIZE) @@ -2124,7 +2157,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) if(command == TOSERVER_INIT2) { - infostream<<"Server: Got TOSERVER_INIT2 from " + verbosestream<<"Server: Got TOSERVER_INIT2 from " <<peer_id<<std::endl; @@ -2135,6 +2168,9 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) Send some initialization data */ + infostream<<"Server: Sending content to " + <<getPlayerName(peer_id)<<std::endl; + // Send item definitions SendItemDef(m_con, peer_id, m_itemdef); @@ -2389,7 +2425,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) { // Strip command and create a stream std::string datastring((char*)&data[2], datasize-2); - infostream<<"TOSERVER_INVENTORY_ACTION: data="<<datastring<<std::endl; + verbosestream<<"TOSERVER_INVENTORY_ACTION: data="<<datastring<<std::endl; std::istringstream is(datastring, std::ios_base::binary); // Create an action InventoryAction *a = InventoryAction::deSerialize(is); @@ -2800,19 +2836,20 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) else if(command == TOSERVER_REQUEST_TEXTURES) { std::string datastring((char*)&data[2], datasize-2); std::istringstream is(datastring, std::ios_base::binary); - - infostream<<"TOSERVER_REQUEST_TEXTURES: "<<std::endl; - + + core::list<TextureRequest> tosend; - u16 numtextures = readU16(is); - for(int i = 0; i < numtextures; i++) { + infostream<<"Sending "<<numtextures<<" textures to " + <<getPlayerName(peer_id)<<std::endl; + verbosestream<<"TOSERVER_REQUEST_TEXTURES: "<<std::endl; + for(int i = 0; i < numtextures; i++) { std::string name = deSerializeString(is); - tosend.push_back(TextureRequest(name)); - infostream<<"TOSERVER_REQUEST_TEXTURES: requested texture " << name <<std::endl; + verbosestream<<"TOSERVER_REQUEST_TEXTURES: requested texture " + <<name<<std::endl; } SendTexturesRequested(peer_id, tosend); @@ -2845,11 +2882,12 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) PointedThing pointed; pointed.deSerialize(tmp_is); - infostream<<"TOSERVER_INTERACT: action="<<(int)action<<", item="<<item_i<<", pointed="<<pointed.dump()<<std::endl; + verbosestream<<"TOSERVER_INTERACT: action="<<(int)action<<", item=" + <<item_i<<", pointed="<<pointed.dump()<<std::endl; if(player->hp == 0) { - infostream<<"TOSERVER_INTERACT: "<<srp->getName() + verbosestream<<"TOSERVER_INTERACT: "<<srp->getName() <<" tried to interact, but is dead!"<<std::endl; return; } @@ -2874,7 +2912,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) pointed_object = m_env->getActiveObject(pointed.object_id); if(pointed_object == NULL) { - infostream<<"TOSERVER_INTERACT: " + verbosestream<<"TOSERVER_INTERACT: " "pointed object is NULL"<<std::endl; return; } @@ -2962,7 +3000,8 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) return; actionstream<<player->getName()<<" punches object " - <<pointed.object_id<<std::endl; + <<pointed.object_id<<": " + <<pointed_object->getDescription()<<std::endl; ItemStack punchitem = srp->getWieldedItem(); ToolCapabilities toolcap = @@ -3031,7 +3070,8 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) return; actionstream<<player->getName()<<" right-clicks object " - <<pointed.object_id<<std::endl; + <<pointed.object_id<<": " + <<pointed_object->getDescription()<<std::endl; // Do stuff pointed_object->rightClick(srp); @@ -3238,7 +3278,7 @@ core::list<PlayerInfo> Server::getPlayerInfo() void Server::peerAdded(con::Peer *peer) { DSTACK(__FUNCTION_NAME); - infostream<<"Server::peerAdded(): peer->id=" + verbosestream<<"Server::peerAdded(): peer->id=" <<peer->id<<std::endl; PeerChange c; @@ -3251,7 +3291,7 @@ void Server::peerAdded(con::Peer *peer) void Server::deletingPeer(con::Peer *peer, bool timeout) { DSTACK(__FUNCTION_NAME); - infostream<<"Server::deletingPeer(): peer->id=" + verbosestream<<"Server::deletingPeer(): peer->id=" <<peer->id<<", timeout="<<timeout<<std::endl; PeerChange c; @@ -3333,8 +3373,8 @@ void Server::SendItemDef(con::Connection &con, u16 peer_id, // Make data buffer std::string s = os.str(); - infostream<<"Server::SendItemDef(): Sending item definitions: size=" - <<s.size()<<std::endl; + verbosestream<<"Server: Sending item definitions to id("<<peer_id + <<"): size="<<s.size()<<std::endl; SharedBuffer<u8> data((u8*)s.c_str(), s.size()); // Send as reliable con.Send(peer_id, 0, data, true); @@ -3360,8 +3400,8 @@ void Server::SendNodeDef(con::Connection &con, u16 peer_id, // Make data buffer std::string s = os.str(); - infostream<<"Server::SendNodeDef(): Sending node definitions: size=" - <<s.size()<<std::endl; + verbosestream<<"Server: Sending node definitions to id("<<peer_id + <<"): size="<<s.size()<<std::endl; SharedBuffer<u8> data((u8*)s.c_str(), s.size()); // Send as reliable con.Send(peer_id, 0, data, true); @@ -3512,7 +3552,7 @@ void Server::SendMovePlayer(Player *player) v3f pos = player->getPosition(); f32 pitch = player->getPitch(); f32 yaw = player->getYaw(); - infostream<<"Server sending TOCLIENT_MOVE_PLAYER" + verbosestream<<"Server: Sending TOCLIENT_MOVE_PLAYER" <<" pos=("<<pos.X<<","<<pos.Y<<","<<pos.Z<<")" <<" pitch="<<pitch <<" yaw="<<yaw @@ -3760,71 +3800,72 @@ void Server::SendBlocks(float dtime) } } -void Server::PrepareTextures() { +void Server::PrepareTextures() +{ DSTACK(__FUNCTION_NAME); - infostream<<"Server::PrepareTextures(): Calculate sha1 sums of textures"<<std::endl; + infostream<<"Server: Calculating texture checksums"<<std::endl; for(core::list<ModSpec>::Iterator i = m_mods.begin(); - i != m_mods.end(); i++){ - const ModSpec &mod = *i; - std::string texturepath = mod.path + DIR_DELIM + "textures"; - std::vector<fs::DirListNode> dirlist = fs::GetDirListing(texturepath); - for(u32 j=0; j<dirlist.size(); j++){ - if(dirlist[j].dir) // Ignode dirs - continue; - std::string tname = dirlist[j].name; - // if name contains illegal characters, ignore the texture - if(!string_allowed(tname, TEXTURENAME_ALLOWED_CHARS)){ - errorstream<<"Server: ignoring illegal texture name: \"" - <<tname<<"\""<<std::endl; - continue; - } - std::string tpath = texturepath + DIR_DELIM + tname; - // Read data - std::ifstream fis(tpath.c_str(), std::ios_base::binary); - if(fis.good() == false){ - errorstream<<"Server::PrepareTextures(): Could not open \"" - <<tname<<"\" for reading"<<std::endl; - continue; - } - std::ostringstream tmp_os(std::ios_base::binary); - bool bad = false; - for(;;){ - char buf[1024]; - fis.read(buf, 1024); - std::streamsize len = fis.gcount(); - tmp_os.write(buf, len); - if(fis.eof()) - break; - if(!fis.good()){ - bad = true; - break; - } - } - if(bad){ - errorstream<<"Server::PrepareTextures(): Failed to read \"" - <<tname<<"\""<<std::endl; - continue; - } - if(tmp_os.str().length() == 0){ - errorstream<<"Server::PrepareTextures(): Empty file \"" - <<tpath<<"\""<<std::endl; - continue; + i != m_mods.end(); i++){ + const ModSpec &mod = *i; + std::string texturepath = mod.path + DIR_DELIM + "textures"; + std::vector<fs::DirListNode> dirlist = fs::GetDirListing(texturepath); + for(u32 j=0; j<dirlist.size(); j++){ + if(dirlist[j].dir) // Ignode dirs + continue; + std::string tname = dirlist[j].name; + // if name contains illegal characters, ignore the texture + if(!string_allowed(tname, TEXTURENAME_ALLOWED_CHARS)){ + errorstream<<"Server: ignoring illegal texture name: \"" + <<tname<<"\""<<std::endl; + continue; + } + std::string tpath = texturepath + DIR_DELIM + tname; + // Read data + std::ifstream fis(tpath.c_str(), std::ios_base::binary); + if(fis.good() == false){ + errorstream<<"Server::PrepareTextures(): Could not open \"" + <<tname<<"\" for reading"<<std::endl; + continue; + } + std::ostringstream tmp_os(std::ios_base::binary); + bool bad = false; + for(;;){ + char buf[1024]; + fis.read(buf, 1024); + std::streamsize len = fis.gcount(); + tmp_os.write(buf, len); + if(fis.eof()) + break; + if(!fis.good()){ + bad = true; + break; } + } + if(bad){ + errorstream<<"Server::PrepareTextures(): Failed to read \"" + <<tname<<"\""<<std::endl; + continue; + } + if(tmp_os.str().length() == 0){ + errorstream<<"Server::PrepareTextures(): Empty file \"" + <<tpath<<"\""<<std::endl; + continue; + } - SHA1 sha1; - sha1.addBytes(tmp_os.str().c_str(), tmp_os.str().length()); + SHA1 sha1; + sha1.addBytes(tmp_os.str().c_str(), tmp_os.str().length()); - unsigned char *digest = sha1.getDigest(); - std::string digest_string = base64_encode(digest, 20); + unsigned char *digest = sha1.getDigest(); + std::string digest_string = base64_encode(digest, 20); - free(digest); + free(digest); - // Put in list - this->m_Textures[tname] = TextureInformation(tpath,digest_string); - infostream<<"Server::PrepareTextures(): added sha1 for "<< tname <<std::endl; - } + // Put in list + this->m_Textures[tname] = TextureInformation(tpath,digest_string); + verbosestream<<"Server: sha1 for "<<tname<<"\tis "<<std::endl; + } } } @@ -3844,7 +3885,8 @@ struct SendableTextureAnnouncement void Server::SendTextureAnnouncement(u16 peer_id){ DSTACK(__FUNCTION_NAME); - infostream<<"Server::SendTextureAnnouncement()"<<std::endl; + verbosestream<<"Server: Announcing textures to id("<<peer_id<<")" + <<std::endl; core::list<SendableTextureAnnouncement> texture_announcements; @@ -3881,7 +3923,6 @@ void Server::SendTextureAnnouncement(u16 peer_id){ // Make data buffer std::string s = os.str(); - infostream<<"Server::SendTextureAnnouncement(): Send to client"<<std::endl; SharedBuffer<u8> data((u8*)s.c_str(), s.size()); // Send as reliable @@ -3906,7 +3947,8 @@ struct SendableTexture void Server::SendTexturesRequested(u16 peer_id,core::list<TextureRequest> tosend) { DSTACK(__FUNCTION_NAME); - infostream<<"Server::SendTexturesRequested(): Sending textures to client"<<std::endl; + verbosestream<<"Server::SendTexturesRequested(): " + <<"Sending textures to client"<<std::endl; /* Read textures */ @@ -4002,7 +4044,8 @@ void Server::SendTexturesRequested(u16 peer_id,core::list<TextureRequest> tosend // Make data buffer std::string s = os.str(); - infostream<<"Server::SendTexturesRequested(): bunch "<<i<<"/"<<num_bunches + verbosestream<<"Server::SendTexturesRequested(): bunch " + <<i<<"/"<<num_bunches <<" textures="<<texture_bunches[i].size() <<" size=" <<s.size()<<std::endl; SharedBuffer<u8> data((u8*)s.c_str(), s.size()); @@ -4496,7 +4539,7 @@ void Server::handlePeerChanges() { PeerChange c = m_peer_change_queue.pop_front(); - infostream<<"Server: Handling peer change: " + verbosestream<<"Server: Handling peer change: " <<"id="<<c.peer_id<<", timeout="<<c.timeout <<std::endl; @@ -4525,7 +4568,7 @@ void dedicated_server_loop(Server &server, bool &kill) { DSTACK(__FUNCTION_NAME); - infostream<<"dedicated_server_loop()"<<std::endl; + verbosestream<<"dedicated_server_loop()"<<std::endl; IntervalLimiter m_profiler_interval; @@ -4542,7 +4585,7 @@ void dedicated_server_loop(Server &server, bool &kill) if(server.getShutdownRequested() || kill) { - infostream<<DTIME<<" dedicated_server_loop(): Quitting."<<std::endl; + infostream<<"Dedicated server quitting"<<std::endl; break; } @@ -4560,30 +4603,6 @@ void dedicated_server_loop(Server &server, bool &kill) g_profiler->clear(); } } - - /* - Player info - */ - static int counter = 0; - counter--; - if(counter <= 0) - { - counter = 10; - - core::list<PlayerInfo> list = server.getPlayerInfo(); - core::list<PlayerInfo>::Iterator i; - static u32 sum_old = 0; - u32 sum = PIChecksum(list); - if(sum != sum_old) - { - infostream<<DTIME<<"Player info:"<<std::endl; - for(i=list.begin(); i!=list.end(); i++) - { - i->PrintLine(&infostream); - } - } - sum_old = sum; - } } } diff --git a/src/server.h b/src/server.h index 50cd5b285..a1d7e5df7 100644 --- a/src/server.h +++ b/src/server.h @@ -40,6 +40,23 @@ class IWritableItemDefManager; class IWritableNodeDefManager; class IWritableCraftDefManager; +class ServerError : public std::exception +{ +public: + ServerError(const std::string &s) + { + m_s = "ServerError: "; + m_s += s; + } + virtual ~ServerError() throw() + {} + virtual const char * what() const throw() + { + return m_s.c_str(); + } + std::string m_s; +}; + /* Some random functions */ @@ -211,8 +228,6 @@ struct PlayerInfo void PrintLine(std::ostream *s); }; -u32 PIChecksum(core::list<PlayerInfo> &l); - /* Used for queueing and sorting block transfers in containers @@ -608,7 +623,7 @@ private: { Player *player = m_env->getPlayer(peer_id); if(player == NULL) - return "[id="+itos(peer_id); + return "[id="+itos(peer_id)+"]"; return player->getName(); } diff --git a/src/settings.h b/src/settings.h index 9eb2254f0..0b828e2a5 100644 --- a/src/settings.h +++ b/src/settings.h @@ -425,8 +425,6 @@ public: n = m_defaults.find(name); if(n == NULL) { - infostream<<"Settings: Setting not found: \"" - <<name<<"\""<<std::endl; throw SettingNotFoundException("Setting not found"); } } |