diff options
Diffstat (limited to 'src/database')
0 files changed, 0 insertions, 0 deletions
/*
Minetest
Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "irrlichttypes.h" // must be included before anything irrlicht, see comment in the file
#include "irrlicht.h" // createDevice
#include "irrlichttypes_extrabloated.h"
#include "chat_interface.h"
#include "debug.h"
#include "unittest/test.h"
#include "server.h"
#include "filesys.h"
#include "version.h"
#include "client/game.h"
#include "defaultsettings.h"
#include "gettext.h"
#include "log.h"
#include "util/quicktune.h"
#include "httpfetch.h"
#include "gameparams.h"
#include "database/database.h"
#include "config.h"
#include "player.h"
#include "porting.h"
#include "network/socket.h"
#if USE_CURSES
#include "terminal_chat_console.h"
#endif
#ifndef SERVER
#include "gui/guiMainMenu.h"
#include "client/clientlauncher.h"
#include "gui/guiEngine.h"
#include "gui/mainmenumanager.h"
#endif
#ifdef HAVE_TOUCHSCREENGUI
#include "gui/touchscreengui.h"
#endif
#if !defined(SERVER) && \
(IRRLICHT_VERSION_MAJOR == 1) && \
(IRRLICHT_VERSION_MINOR == 8) && \
(IRRLICHT_VERSION_REVISION == 2)
#error "Irrlicht 1.8.2 is known to be broken - please update Irrlicht to version >= 1.8.3"
#endif
#define DEBUGFILE "debug.txt"
#define DEFAULT_SERVER_PORT 30000
typedef std::map<std::string, ValueSpec> OptionList;
/**********************************************************************
* Private functions
**********************************************************************/
static bool get_cmdline_opts(int argc, char *argv[], Settings *cmd_args);
static void set_allowed_options(OptionList *allowed_options);
static void print_help(const OptionList &allowed_options);
static void print_allowed_options(const OptionList &allowed_options);
static void print_version();
static void print_worldspecs(const std::vector<WorldSpec> &worldspecs,
std::ostream &os, bool print_name = true, bool print_path = true);
static void print_modified_quicktune_values();
static void list_game_ids();
static void list_worlds(bool print_name, bool print_path);
static bool setup_log_params(const Settings &cmd_args);
static bool create_userdata_path();
static bool init_common(const Settings &cmd_args, int argc, char *argv[]);
static void startup_message();
static bool read_config_file(const Settings &cmd_args);
static void init_log_streams(const Settings &cmd_args);
static bool game_configure(GameParams *game_params, const Settings &cmd_args);
static void game_configure_port(GameParams *game_params, const Settings &cmd_args);
static bool game_configure_world(GameParams *game_params, const Settings &cmd_args);
static bool get_world_from_cmdline(GameParams *game_params, const Settings &cmd_args);
static bool get_world_from_config(GameParams *game_params, const Settings &cmd_args);
static bool auto_select_world(GameParams *game_params);
static std::string get_clean_world_path(const std::string &path);
static bool game_configure_subgame(GameParams *game_params, const Settings &cmd_args);
static bool get_game_from_cmdline(GameParams *game_params, const Settings &cmd_args);
static bool determine_subgame(GameParams *game_params);
static bool run_dedicated_server(const GameParams &game_params, const Settings &cmd_args);
static bool migrate_map_database(const GameParams &game_params, const Settings &cmd_args);
/**********************************************************************/
FileLogOutput file_log_output;
static OptionList allowed_options;
int main(int argc, char *argv[])
{
int retval;
debug_set_exception_handler();
g_logger.registerThread("Main");
g_logger.addOutputMaxLevel(&stderr_output, LL_ACTION);
Settings cmd_args;
bool cmd_args_ok = get_cmdline_opts(argc, argv, &cmd_args);
if (!cmd_args_ok
|| cmd_args.getFlag("help")
|| cmd_args.exists("nonopt1")) {
porting::attachOrCreateConsole();
print_help(allowed_options);
return cmd_args_ok ? 0 : 1;
}
if (cmd_args.getFlag("console"))
porting::attachOrCreateConsole();
if (cmd_args.getFlag("version")) {
porting::attachOrCreateConsole();
print_version();
return 0;
}
if (!setup_log_params(cmd_args))
return 1;
porting::signal_handler_init();
#ifdef __ANDROID__
porting::initAndroid();
porting::initializePathsAndroid();
#else
porting::initializePaths();
#endif
if (!create_userdata_path()) {
errorstream << "Cannot create user data directory" << std::endl;
return 1;
}
// Debug handler
BEGIN_DEBUG_EXCEPTION_HANDLER
// List gameids if requested
if (cmd_args.exists("gameid") && cmd_args.get("gameid") == "list") {
list_game_ids();
return 0;
}
// List worlds, world names, and world paths if requested
if (cmd_args.exists("worldlist")) {
if (cmd_args.get("worldlist") == "name") {
list_worlds(true, false);
} else if (cmd_args.get("worldlist") == "path") {
list_worlds(false, true);
} else if (cmd_args.get("worldlist") == "both") {
list_worlds(true, true);
} else {
errorstream << "Invalid --worldlist value: "
<< cmd_args.get("worldlist") << std::endl;
return 1;
}
return 0;
}
if (!init_common(cmd_args, argc, argv))
return 1;
if (g_settings->getBool("enable_console"))
porting::attachOrCreateConsole();
#ifndef __ANDROID__
// Run unit tests
if (cmd_args.getFlag("run-unittests")) {
#if BUILD_UNITTESTS
return run_tests();
#else
errorstream << "Unittest support is not enabled in this binary. "
<< "If you want to enable it, compile project with BUILD_UNITTESTS=1 flag."
<< std::endl;
#endif
}
#endif
GameStartData game_params;
#ifdef SERVER
porting::attachOrCreateConsole();
game_params.is_dedicated_server = true;
#else
const bool isServer = cmd_args.getFlag("server");
if (isServer)
porting::attachOrCreateConsole();
game_params.is_dedicated_server = isServer;
#endif
if (!game_configure(&game_params, cmd_args))
return 1;
sanity_check(!game_params.world_path.empty());
if (game_params.is_dedicated_server)
return run_dedicated_server(game_params, cmd_args) ? 0 : 1;
#ifndef SERVER
ClientLauncher launcher;
retval = launcher.run(game_params, cmd_args) ? 0 : 1;
#else
retval = 0;
#endif
// Update configuration file
if (!g_settings_path.empty())
g_settings->updateConfigFile(g_settings_path.c_str());
print_modified_quicktune_values();
// Stop httpfetch thread (if started)
httpfetch_cleanup();
END_DEBUG_EXCEPTION_HANDLER
return retval;
}
/*****************************************************************************
* Startup / Init
*****************************************************************************/