2003-11-10 00:36:11 +01:00
|
|
|
|
/* vi: set ts=2:
|
2004-04-10 21:21:02 +02:00
|
|
|
|
*
|
|
|
|
|
*
|
2004-04-12 01:56:47 +02:00
|
|
|
|
* Eressea PB(E)M host Copyright (C) 1998-2003
|
|
|
|
|
* Christian Schlittchen (corwin@amber.kn-bremen.de)
|
|
|
|
|
* Katja Zedel (katze@felidae.kn-bremen.de)
|
|
|
|
|
* Henning Peters (faroul@beyond.kn-bremen.de)
|
2007-09-02 20:11:17 +02:00
|
|
|
|
* Enno Rehling (enno@eressea.de)
|
2004-04-12 01:56:47 +02:00
|
|
|
|
* Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de)
|
2004-04-10 21:21:02 +02:00
|
|
|
|
*
|
|
|
|
|
* based on:
|
|
|
|
|
*
|
|
|
|
|
* Atlantis v1.0 13 September 1993 Copyright 1993 by Russell Wallace
|
|
|
|
|
* Atlantis v1.7 Copyright 1996 by Alex Schr<EFBFBD>der
|
|
|
|
|
*
|
|
|
|
|
* This program may not be used, modified or distributed without
|
|
|
|
|
* prior permission by the authors of Eressea.
|
|
|
|
|
* This program may not be sold or used commercially without prior written
|
|
|
|
|
* permission from the authors.
|
|
|
|
|
*/
|
2003-11-10 00:36:11 +01:00
|
|
|
|
|
2003-12-14 11:10:30 +01:00
|
|
|
|
/* config includes */
|
2003-11-10 00:36:11 +01:00
|
|
|
|
#include <config.h>
|
2008-04-19 18:12:13 +02:00
|
|
|
|
#include <kernel/eressea.h>
|
2003-11-10 00:36:11 +01:00
|
|
|
|
|
2004-04-10 21:21:02 +02:00
|
|
|
|
#include "console.h"
|
2008-04-19 18:56:15 +02:00
|
|
|
|
#include "gmtool.h"
|
2003-11-10 00:36:11 +01:00
|
|
|
|
|
|
|
|
|
/* initialization - TODO: init in separate module */
|
|
|
|
|
#include <attributes/attributes.h>
|
2003-12-14 11:10:30 +01:00
|
|
|
|
#include <spells/spells.h>
|
2007-07-17 17:33:48 +02:00
|
|
|
|
#include <gamecode/spells.h>
|
2003-11-10 00:36:11 +01:00
|
|
|
|
#include <triggers/triggers.h>
|
2005-01-30 09:57:16 +01:00
|
|
|
|
#include <items/itemtypes.h>
|
2007-08-05 14:19:56 +02:00
|
|
|
|
#include <races/races.h>
|
2003-11-10 00:36:11 +01:00
|
|
|
|
|
|
|
|
|
/* modules includes */
|
2003-12-14 11:10:30 +01:00
|
|
|
|
#include <modules/xmas.h>
|
2003-11-10 00:36:11 +01:00
|
|
|
|
#include <modules/gmcmd.h>
|
2003-12-14 11:10:30 +01:00
|
|
|
|
#include <modules/infocmd.h>
|
2008-04-20 17:18:43 +02:00
|
|
|
|
#if MUSEUM_MODULE
|
2003-12-14 11:10:30 +01:00
|
|
|
|
#include <modules/museum.h>
|
|
|
|
|
#endif
|
2004-02-21 23:25:00 +01:00
|
|
|
|
#include <modules/wormhole.h>
|
2008-04-20 17:18:43 +02:00
|
|
|
|
#if ARENA_MODULE
|
2003-12-14 11:10:30 +01:00
|
|
|
|
#include <modules/arena.h>
|
2003-11-10 00:36:11 +01:00
|
|
|
|
#endif
|
2008-04-20 17:18:43 +02:00
|
|
|
|
#if DUNGEON_MODULE
|
2004-03-28 22:53:47 +02:00
|
|
|
|
#include <modules/dungeon.h>
|
|
|
|
|
#endif
|
2003-11-10 00:36:11 +01:00
|
|
|
|
|
|
|
|
|
/* gamecode includes */
|
2007-05-28 18:03:48 +02:00
|
|
|
|
#include <gamecode/archetype.h>
|
2004-03-28 22:53:47 +02:00
|
|
|
|
#include <gamecode/economy.h>
|
2005-01-30 09:57:16 +01:00
|
|
|
|
#include <gamecode/items.h>
|
2004-03-28 22:53:47 +02:00
|
|
|
|
#include <gamecode/laws.h>
|
2006-02-09 20:39:17 +01:00
|
|
|
|
#include <gamecode/creport.h>
|
|
|
|
|
#include <gamecode/report.h>
|
|
|
|
|
#include <gamecode/xmlreport.h>
|
2003-11-10 00:36:11 +01:00
|
|
|
|
|
|
|
|
|
/* kernel includes */
|
2004-03-28 22:53:47 +02:00
|
|
|
|
#include <kernel/border.h>
|
|
|
|
|
#include <kernel/building.h>
|
2005-06-11 10:09:55 +02:00
|
|
|
|
#include <kernel/calendar.h>
|
2004-03-28 22:53:47 +02:00
|
|
|
|
#include <kernel/faction.h>
|
|
|
|
|
#include <kernel/item.h>
|
|
|
|
|
#include <kernel/message.h>
|
2007-06-25 03:50:34 +02:00
|
|
|
|
#include <kernel/names.h>
|
2004-03-28 22:53:47 +02:00
|
|
|
|
#include <kernel/plane.h>
|
|
|
|
|
#include <kernel/race.h>
|
|
|
|
|
#include <kernel/region.h>
|
|
|
|
|
#include <kernel/reports.h>
|
|
|
|
|
#include <kernel/resources.h>
|
|
|
|
|
#include <kernel/save.h>
|
|
|
|
|
#include <kernel/ship.h>
|
|
|
|
|
#include <kernel/skill.h>
|
2004-04-12 01:56:47 +02:00
|
|
|
|
#include <kernel/spell.h>
|
2004-03-28 22:53:47 +02:00
|
|
|
|
#include <kernel/teleport.h>
|
|
|
|
|
#include <kernel/unit.h>
|
|
|
|
|
#include <kernel/xmlreader.h>
|
2007-06-20 02:34:02 +02:00
|
|
|
|
#include <kernel/version.h>
|
2003-11-10 00:36:11 +01:00
|
|
|
|
|
2004-04-12 01:56:47 +02:00
|
|
|
|
|
2003-11-10 00:36:11 +01:00
|
|
|
|
/* util includes */
|
2004-03-28 22:53:47 +02:00
|
|
|
|
#include <util/base36.h>
|
|
|
|
|
#include <util/goodies.h>
|
2003-12-15 23:59:15 +01:00
|
|
|
|
#include <util/log.h>
|
2004-03-28 22:53:47 +02:00
|
|
|
|
#include <util/rand.h>
|
2006-02-19 23:43:56 +01:00
|
|
|
|
#include <util/rng.h>
|
2003-12-15 23:59:15 +01:00
|
|
|
|
#include <util/sql.h>
|
2005-06-12 12:56:18 +02:00
|
|
|
|
#ifdef MSPACES
|
|
|
|
|
# include <util/dl/malloc.h>
|
|
|
|
|
#endif
|
2003-11-10 00:36:11 +01:00
|
|
|
|
|
2006-11-22 22:07:48 +01:00
|
|
|
|
/* external iniparser */
|
|
|
|
|
#include <iniparser/iniparser.h>
|
|
|
|
|
|
2003-11-10 00:36:11 +01:00
|
|
|
|
/* lua includes */
|
|
|
|
|
#include "lua/bindings.h"
|
2005-11-25 23:09:59 +01:00
|
|
|
|
#include "lua/script.h"
|
2005-11-01 21:49:58 +01:00
|
|
|
|
#include <boost/version.hpp>
|
2008-04-20 16:48:15 +02:00
|
|
|
|
#ifdef _MSC_VER
|
2007-10-27 17:09:36 +02:00
|
|
|
|
#pragma warning (push)
|
|
|
|
|
#pragma warning (disable: 4127)
|
2008-04-20 16:48:15 +02:00
|
|
|
|
#endif
|
2003-11-10 00:36:11 +01:00
|
|
|
|
#include <lua.hpp>
|
|
|
|
|
#include <luabind/luabind.hpp>
|
2008-04-20 16:48:15 +02:00
|
|
|
|
#ifdef _MSC_VER
|
2007-10-27 17:09:36 +02:00
|
|
|
|
#pragma warning (pop)
|
2008-04-20 16:48:15 +02:00
|
|
|
|
#endif
|
2003-11-10 00:36:11 +01:00
|
|
|
|
|
2007-08-12 11:51:26 +02:00
|
|
|
|
#include <libxml/encoding.h>
|
|
|
|
|
|
2004-09-26 20:49:57 +02:00
|
|
|
|
/* stdc++ includes */
|
|
|
|
|
#include <stdexcept>
|
2006-01-15 12:05:23 +01:00
|
|
|
|
#include <string>
|
|
|
|
|
#include <sstream>
|
2004-09-26 20:49:57 +02:00
|
|
|
|
|
2003-11-10 00:36:11 +01:00
|
|
|
|
/* libc includes */
|
|
|
|
|
#include <cstdio>
|
|
|
|
|
#include <cctype>
|
2006-07-29 00:08:00 +02:00
|
|
|
|
#include <climits>
|
|
|
|
|
#include <clocale>
|
2003-11-10 00:36:11 +01:00
|
|
|
|
#include <cstring>
|
|
|
|
|
#include <ctime>
|
2004-04-12 01:56:47 +02:00
|
|
|
|
|
2007-09-03 21:52:51 +02:00
|
|
|
|
#if defined(_MSC_VER)
|
|
|
|
|
# include <crtdbg.h>
|
|
|
|
|
#endif
|
2005-05-07 12:31:25 +02:00
|
|
|
|
|
2003-11-10 00:36:11 +01:00
|
|
|
|
/**
|
2004-04-10 21:21:02 +02:00
|
|
|
|
** global variables we are importing from other modules
|
|
|
|
|
**/
|
2003-11-10 00:36:11 +01:00
|
|
|
|
extern "C" {
|
2006-11-22 22:59:24 +01:00
|
|
|
|
extern const char * g_reportdir;
|
|
|
|
|
extern const char * g_datadir;
|
|
|
|
|
extern const char * g_basedir;
|
|
|
|
|
extern const char * g_resourcedir;
|
2004-04-10 21:21:02 +02:00
|
|
|
|
|
|
|
|
|
extern boolean nobattle;
|
|
|
|
|
extern boolean nomonsters;
|
2007-05-27 23:20:06 +02:00
|
|
|
|
extern boolean battledebug;
|
2004-04-10 21:21:02 +02:00
|
|
|
|
|
|
|
|
|
extern int loadplane;
|
|
|
|
|
extern boolean opt_cr_absolute_coords;
|
2003-11-10 00:36:11 +01:00
|
|
|
|
|
2003-12-14 11:10:30 +01:00
|
|
|
|
}
|
2003-11-10 00:36:11 +01:00
|
|
|
|
|
|
|
|
|
/**
|
2004-04-10 21:21:02 +02:00
|
|
|
|
** global variables that we are exporting
|
|
|
|
|
**/
|
2003-11-10 00:36:11 +01:00
|
|
|
|
static char * orders = NULL;
|
|
|
|
|
static int nowrite = 0;
|
|
|
|
|
static boolean g_writemap = false;
|
2006-02-05 16:48:52 +01:00
|
|
|
|
static boolean g_ignore_errors = false;
|
2003-12-14 11:10:30 +01:00
|
|
|
|
static boolean opt_reportonly = false;
|
2007-08-08 09:43:24 +02:00
|
|
|
|
static const char * luafile = NULL;
|
2004-12-22 23:02:31 +01:00
|
|
|
|
static const char * script_path = "scripts";
|
2007-08-15 08:27:40 +02:00
|
|
|
|
static int memdebug = 0;
|
2003-11-10 00:36:11 +01:00
|
|
|
|
|
2008-04-20 16:48:15 +02:00
|
|
|
|
#if defined(HAVE_SIGACTION) && defined(HAVE_EXECINFO)
|
2005-05-01 00:03:47 +02:00
|
|
|
|
#include <execinfo.h>
|
|
|
|
|
#include <signal.h>
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
report_segfault(int signo, siginfo_t * sinf, void * arg)
|
|
|
|
|
{
|
|
|
|
|
void * btrace[50];
|
|
|
|
|
size_t size;
|
|
|
|
|
int fd = fileno(stderr);
|
|
|
|
|
|
2005-05-01 02:26:15 +02:00
|
|
|
|
fflush(stdout);
|
2005-05-01 00:03:47 +02:00
|
|
|
|
fputs("\n\nProgram received SIGSEGV, backtrace follows.\n", stderr);
|
|
|
|
|
size = backtrace(btrace, 50);
|
|
|
|
|
backtrace_symbols_fd(btrace, size, fd);
|
|
|
|
|
abort();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
setup_signal_handler(void)
|
|
|
|
|
{
|
|
|
|
|
struct sigaction act;
|
|
|
|
|
|
|
|
|
|
act.sa_flags = SA_ONESHOT | SA_SIGINFO;
|
|
|
|
|
act.sa_sigaction = report_segfault;
|
|
|
|
|
sigfillset(&act.sa_mask);
|
|
|
|
|
return sigaction(SIGSEGV, &act, NULL);
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
static int
|
|
|
|
|
setup_signal_handler(void)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2003-11-10 00:36:11 +01:00
|
|
|
|
static void
|
|
|
|
|
game_init(void)
|
|
|
|
|
{
|
2004-03-28 22:53:47 +02:00
|
|
|
|
init_triggers();
|
|
|
|
|
init_xmas();
|
2005-11-02 22:10:40 +01:00
|
|
|
|
|
|
|
|
|
reports_init();
|
2004-03-28 22:53:47 +02:00
|
|
|
|
report_init();
|
|
|
|
|
creport_init();
|
2005-11-19 00:23:47 +01:00
|
|
|
|
xmlreport_init();
|
2004-03-28 22:53:47 +02:00
|
|
|
|
|
|
|
|
|
debug_language("locales.log");
|
|
|
|
|
register_races();
|
2007-06-25 03:50:34 +02:00
|
|
|
|
register_names();
|
2004-03-28 22:53:47 +02:00
|
|
|
|
register_resources();
|
|
|
|
|
register_buildings();
|
|
|
|
|
register_ships();
|
2005-10-26 21:02:45 +02:00
|
|
|
|
register_itemfunctions();
|
2004-03-28 22:53:47 +02:00
|
|
|
|
register_spells();
|
2007-07-17 17:33:48 +02:00
|
|
|
|
register_gcspells();
|
2008-04-20 17:18:43 +02:00
|
|
|
|
#if DUNGEON_MODULE
|
2004-03-28 22:53:47 +02:00
|
|
|
|
register_dungeon();
|
2003-12-14 11:10:30 +01:00
|
|
|
|
#endif
|
2008-04-20 17:18:43 +02:00
|
|
|
|
#if MUSEUM_MODULE
|
2004-03-28 22:53:47 +02:00
|
|
|
|
register_museum();
|
2003-12-14 11:10:30 +01:00
|
|
|
|
#endif
|
2008-04-20 17:18:43 +02:00
|
|
|
|
#if ARENA_MODULE
|
2004-03-28 22:53:47 +02:00
|
|
|
|
register_arena();
|
2003-12-14 11:10:30 +01:00
|
|
|
|
#endif
|
2004-02-21 23:25:00 +01:00
|
|
|
|
register_wormholes();
|
|
|
|
|
|
2005-10-29 18:28:10 +02:00
|
|
|
|
register_itemtypes();
|
2004-03-28 22:53:47 +02:00
|
|
|
|
register_xmlreader();
|
2007-05-28 21:45:08 +02:00
|
|
|
|
register_archetypes();
|
2005-01-31 00:33:28 +01:00
|
|
|
|
enable_xml_gamecode();
|
2006-02-09 20:39:17 +01:00
|
|
|
|
|
2004-03-28 22:53:47 +02:00
|
|
|
|
init_data(xmlfile);
|
|
|
|
|
|
|
|
|
|
init_locales();
|
2007-05-28 18:03:48 +02:00
|
|
|
|
init_archetypes();
|
2004-03-28 22:53:47 +02:00
|
|
|
|
init_attributes();
|
2005-01-30 09:57:16 +01:00
|
|
|
|
init_itemtypes();
|
2004-03-28 22:53:47 +02:00
|
|
|
|
init_rawmaterials();
|
|
|
|
|
|
|
|
|
|
init_gmcmd();
|
2008-04-20 17:18:43 +02:00
|
|
|
|
#if INFOCMD_MODULE
|
2004-03-28 22:53:47 +02:00
|
|
|
|
init_info();
|
2004-06-21 18:45:27 +02:00
|
|
|
|
#endif
|
2003-11-10 00:36:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
2007-06-12 01:56:04 +02:00
|
|
|
|
static const struct {
|
|
|
|
|
const char * name;
|
|
|
|
|
int (*func)(lua_State *);
|
|
|
|
|
} lualibs[] = {
|
|
|
|
|
{"", luaopen_base},
|
|
|
|
|
{LUA_TABLIBNAME, luaopen_table},
|
|
|
|
|
{LUA_IOLIBNAME, luaopen_io},
|
|
|
|
|
{LUA_STRLIBNAME, luaopen_string},
|
|
|
|
|
{LUA_MATHLIBNAME, luaopen_math},
|
2008-04-26 18:46:05 +02:00
|
|
|
|
#if LUA_VERSION_NUM>=501
|
|
|
|
|
{LUA_OSLIBNAME, luaopen_os},
|
|
|
|
|
#endif
|
2007-06-12 01:56:04 +02:00
|
|
|
|
{ NULL, NULL }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
openlibs(lua_State * L)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
for (i=0;lualibs[i].func;++i) {
|
|
|
|
|
lua_pushcfunction(L, lualibs[i].func);
|
|
|
|
|
lua_pushstring(L, lualibs[i].name);
|
|
|
|
|
lua_call(L, 1, 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-16 14:48:55 +02:00
|
|
|
|
static lua_State *
|
2003-11-10 00:36:11 +01:00
|
|
|
|
lua_init(void)
|
|
|
|
|
{
|
2008-04-19 18:12:13 +02:00
|
|
|
|
lua_State * L = lua_open();
|
|
|
|
|
|
|
|
|
|
openlibs(L);
|
|
|
|
|
luabind::open(L);
|
|
|
|
|
|
|
|
|
|
bind_objects(L);
|
|
|
|
|
bind_eressea(L);
|
|
|
|
|
bind_script(L);
|
|
|
|
|
bind_spell(L);
|
|
|
|
|
bind_alliance(L);
|
|
|
|
|
bind_region(L);
|
|
|
|
|
bind_item(L);
|
|
|
|
|
bind_faction(L);
|
|
|
|
|
bind_unit(L);
|
|
|
|
|
bind_ship(L);
|
|
|
|
|
bind_building(L);
|
|
|
|
|
bind_event(L);
|
|
|
|
|
bind_message(L);
|
|
|
|
|
bind_gamecode(L);
|
2008-04-25 16:31:38 +02:00
|
|
|
|
|
2008-04-19 18:12:13 +02:00
|
|
|
|
bind_gmtool(L);
|
2008-04-25 16:31:38 +02:00
|
|
|
|
bind_test(L);
|
2008-04-19 18:12:13 +02:00
|
|
|
|
return L;
|
2003-11-10 00:36:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
2006-04-16 14:48:55 +02:00
|
|
|
|
static void
|
2003-12-14 17:34:00 +01:00
|
|
|
|
lua_done(lua_State * luaState)
|
2003-11-10 00:36:11 +01:00
|
|
|
|
{
|
2005-11-25 23:09:59 +01:00
|
|
|
|
reset_scripts();
|
2003-11-10 00:36:11 +01:00
|
|
|
|
lua_close(luaState);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
game_done(void)
|
|
|
|
|
{
|
2008-05-22 12:46:02 +02:00
|
|
|
|
#ifdef CLEANUP_CODE
|
2004-04-10 21:21:02 +02:00
|
|
|
|
/* Diese Routine enfernt allen allokierten Speicher wieder. Das ist nur
|
2007-12-17 00:18:22 +01:00
|
|
|
|
* zum Debugging interessant, wenn man Leak Detection hat, und nach
|
|
|
|
|
* nicht freigegebenem Speicher sucht, der nicht bis zum Ende ben<EFBFBD>tigt
|
|
|
|
|
* wird (tempor<EFBFBD>re Hilsstrukturen) */
|
|
|
|
|
|
2008-05-22 12:46:02 +02:00
|
|
|
|
free_game();
|
2005-05-07 12:31:25 +02:00
|
|
|
|
|
|
|
|
|
creport_cleanup();
|
2007-08-08 09:43:24 +02:00
|
|
|
|
#ifdef REPORT_FORMAT_NR
|
2005-05-07 12:31:25 +02:00
|
|
|
|
report_cleanup();
|
2007-08-08 09:43:24 +02:00
|
|
|
|
#endif
|
2005-06-11 10:09:55 +02:00
|
|
|
|
calendar_cleanup();
|
2003-11-10 00:36:11 +01:00
|
|
|
|
#endif
|
2008-05-22 12:46:02 +02:00
|
|
|
|
}
|
2003-11-10 00:36:11 +01:00
|
|
|
|
|
2007-08-12 11:51:26 +02:00
|
|
|
|
#define CRTDBG
|
2005-05-07 12:07:06 +02:00
|
|
|
|
#ifdef CRTDBG
|
2003-12-14 11:10:30 +01:00
|
|
|
|
void
|
2005-05-07 12:07:06 +02:00
|
|
|
|
init_crtdbg(void)
|
2003-11-10 00:36:11 +01:00
|
|
|
|
{
|
|
|
|
|
#if (defined(_MSC_VER))
|
2007-08-12 11:51:26 +02:00
|
|
|
|
int flags = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
|
2007-08-15 08:27:40 +02:00
|
|
|
|
if (memdebug==1) {
|
|
|
|
|
flags |= _CRTDBG_CHECK_ALWAYS_DF; /* expensive */
|
|
|
|
|
} else if (memdebug==2) {
|
|
|
|
|
flags = (flags&0x0000FFFF) | _CRTDBG_CHECK_EVERY_16_DF;
|
|
|
|
|
} else if (memdebug==3) {
|
|
|
|
|
flags = (flags&0x0000FFFF) | _CRTDBG_CHECK_EVERY_128_DF;
|
|
|
|
|
} else if (memdebug==4) {
|
|
|
|
|
flags = (flags&0x0000FFFF) | _CRTDBG_CHECK_EVERY_1024_DF;
|
|
|
|
|
}
|
2007-08-12 11:51:26 +02:00
|
|
|
|
_CrtSetDbgFlag(flags);
|
2003-11-10 00:36:11 +01:00
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
usage(const char * prog, const char * arg)
|
|
|
|
|
{
|
2004-04-10 21:21:02 +02:00
|
|
|
|
if (arg) {
|
|
|
|
|
fprintf(stderr, "unknown argument: %s\n\n", arg);
|
|
|
|
|
}
|
|
|
|
|
fprintf(stderr, "Usage: %s [options]\n"
|
|
|
|
|
"-v befehlsdatei : verarbeitet automatisch die angegebene Befehlsdatei\n"
|
2006-03-24 08:35:51 +01:00
|
|
|
|
"-q : be less verbose\n"
|
2004-04-10 21:21:02 +02:00
|
|
|
|
"-d datadir : gibt das datenverzeichnis an\n"
|
|
|
|
|
"-b basedir : gibt das basisverzeichnis an\n"
|
|
|
|
|
"-r resdir : gibt das resourceverzeichnis an\n"
|
|
|
|
|
"-t turn : read this datafile, not the most current one\n"
|
|
|
|
|
"-o reportdir : gibt das reportverzeichnis an\n"
|
2004-07-02 07:41:47 +02:00
|
|
|
|
"-l path : specify the base script directory\n"
|
|
|
|
|
"-C : run in interactive mode\n"
|
2007-08-08 09:43:24 +02:00
|
|
|
|
"-e script : main lua script\n"
|
2004-04-10 21:21:02 +02:00
|
|
|
|
"-R : erstellt nur die Reports neu\n"
|
2005-04-23 11:47:03 +02:00
|
|
|
|
"--lomem : keine Messages (RAM sparen)\n"
|
2004-04-10 21:21:02 +02:00
|
|
|
|
"--nobattle : keine K<>mpfe\n"
|
2006-02-05 16:48:52 +01:00
|
|
|
|
"--ignore-errors : ignore errors in scripts (please don\'t)\n"
|
2004-04-10 21:21:02 +02:00
|
|
|
|
"--nomonsters : keine monster KI\n"
|
|
|
|
|
"--nodebug : keine Logfiles f<>r K<>mpfe\n"
|
2005-09-03 11:13:36 +02:00
|
|
|
|
"--noreports : absolut keine Reporte schreiben\n"
|
2004-04-10 21:21:02 +02:00
|
|
|
|
"--debug : schreibt Debug-Ausgaben in die Datei debug\n"
|
2008-04-19 18:56:15 +02:00
|
|
|
|
"--color : force curses to use colors even when not detected\n"
|
2004-04-10 21:21:02 +02:00
|
|
|
|
"--nocr : keine CRs\n"
|
|
|
|
|
"--nonr : keine Reports\n"
|
|
|
|
|
"--crabsolute : absolute Koordinaten im CR\n"
|
|
|
|
|
"--help : help\n", prog);
|
|
|
|
|
return -1;
|
2003-11-10 00:36:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
2003-12-14 17:34:00 +01:00
|
|
|
|
static void
|
|
|
|
|
setLuaString(lua_State * luaState, const char * name, const char * value)
|
|
|
|
|
{
|
2006-01-02 21:24:33 +01:00
|
|
|
|
#if LUABIND_BETA<7 || (LUABIND_BETA==7 && LUABIND_DEVEL<2)
|
2005-11-26 00:52:53 +01:00
|
|
|
|
luabind::object g = luabind::get_globals(luaState);
|
2005-11-25 23:25:13 +01:00
|
|
|
|
#else
|
2005-11-26 00:52:53 +01:00
|
|
|
|
luabind::object g = luabind::globals(luaState);
|
2005-11-01 21:33:21 +01:00
|
|
|
|
#endif
|
2005-11-26 00:52:53 +01:00
|
|
|
|
g[name] = value;
|
2003-12-14 17:34:00 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
setLuaNumber(lua_State * luaState, const char * name, double value)
|
|
|
|
|
{
|
2006-01-02 21:24:33 +01:00
|
|
|
|
#if LUABIND_BETA<7 || (LUABIND_BETA==7 && LUABIND_DEVEL<2)
|
2005-11-26 00:52:53 +01:00
|
|
|
|
luabind::object g = luabind::get_globals(luaState);
|
2005-11-01 21:33:21 +01:00
|
|
|
|
#else
|
2005-11-26 00:52:53 +01:00
|
|
|
|
luabind::object g = luabind::globals(luaState);
|
2005-11-01 21:33:21 +01:00
|
|
|
|
#endif
|
2005-11-26 00:52:53 +01:00
|
|
|
|
g[name] = value;
|
2003-12-14 17:34:00 +01:00
|
|
|
|
}
|
|
|
|
|
|
2003-11-10 00:36:11 +01:00
|
|
|
|
static int
|
2003-12-14 17:34:00 +01:00
|
|
|
|
read_args(int argc, char **argv, lua_State * luaState)
|
2003-11-10 00:36:11 +01:00
|
|
|
|
{
|
2004-04-10 21:21:02 +02:00
|
|
|
|
int i;
|
2003-12-14 17:34:00 +01:00
|
|
|
|
char * c;
|
2004-04-10 21:21:02 +02:00
|
|
|
|
for (i=1;i!=argc;++i) {
|
|
|
|
|
if (argv[i][0]!='-') {
|
|
|
|
|
return usage(argv[0], argv[i]);
|
|
|
|
|
} else if (argv[i][1]=='-') { /* long format */
|
|
|
|
|
if (strcmp(argv[i]+2, "nocr")==0) nocr = true;
|
|
|
|
|
else if (strcmp(argv[i]+2, "nosave")==0) nowrite = true;
|
|
|
|
|
else if (strcmp(argv[i]+2, "noreports")==0) {
|
|
|
|
|
noreports = true;
|
|
|
|
|
nocr = true;
|
|
|
|
|
nocr = true;
|
|
|
|
|
}
|
|
|
|
|
else if (strcmp(argv[i]+2, "xml")==0) xmlfile = argv[++i];
|
2006-02-05 16:48:52 +01:00
|
|
|
|
else if (strcmp(argv[i]+2, "ignore-errors")==0) g_ignore_errors = true;
|
2004-04-10 21:21:02 +02:00
|
|
|
|
else if (strcmp(argv[i]+2, "nonr")==0) nonr = true;
|
2005-04-23 11:47:03 +02:00
|
|
|
|
else if (strcmp(argv[i]+2, "lomem")==0) lomem = true;
|
2004-04-10 21:21:02 +02:00
|
|
|
|
else if (strcmp(argv[i]+2, "nobattle")==0) nobattle = true;
|
|
|
|
|
else if (strcmp(argv[i]+2, "nomonsters")==0) nomonsters = true;
|
2007-05-27 23:20:06 +02:00
|
|
|
|
else if (strcmp(argv[i]+2, "nodebug")==0) battledebug = false;
|
2004-04-10 21:21:02 +02:00
|
|
|
|
else if (strcmp(argv[i]+2, "console")==0) luafile=NULL;
|
|
|
|
|
else if (strcmp(argv[i]+2, "crabsolute")==0) opt_cr_absolute_coords = true;
|
2008-04-19 18:56:15 +02:00
|
|
|
|
else if (strcmp(argv[i]+2, "color")==0) {
|
|
|
|
|
/* force the editor to have colors */
|
|
|
|
|
force_color = 1;
|
|
|
|
|
} else if (strcmp(argv[i]+2, "current")==0) {
|
|
|
|
|
turn = -1;
|
|
|
|
|
}
|
2004-04-10 21:21:02 +02:00
|
|
|
|
else if (strcmp(argv[i]+2, "help")==0)
|
|
|
|
|
return usage(argv[0], NULL);
|
|
|
|
|
else
|
|
|
|
|
return usage(argv[0], argv[i]);
|
|
|
|
|
} else switch(argv[i][1]) {
|
|
|
|
|
case 'C':
|
|
|
|
|
luafile=NULL;
|
|
|
|
|
break;
|
|
|
|
|
case 'o':
|
|
|
|
|
g_reportdir = argv[++i];
|
|
|
|
|
break;
|
2003-12-14 17:34:00 +01:00
|
|
|
|
case 'e':
|
|
|
|
|
luafile = argv[++i];
|
|
|
|
|
break;
|
2004-04-10 21:21:02 +02:00
|
|
|
|
case 'd':
|
|
|
|
|
g_datadir = argv[++i];
|
|
|
|
|
break;
|
|
|
|
|
case 'r':
|
|
|
|
|
g_resourcedir = argv[++i];
|
|
|
|
|
break;
|
|
|
|
|
case 'b':
|
|
|
|
|
g_basedir = argv[++i];
|
|
|
|
|
break;
|
|
|
|
|
case 'i':
|
|
|
|
|
xmlfile = argv[++i];
|
|
|
|
|
break;
|
|
|
|
|
case 't':
|
|
|
|
|
turn = atoi(argv[++i]);
|
|
|
|
|
break;
|
|
|
|
|
case 'q':
|
|
|
|
|
quiet = 1;
|
|
|
|
|
break;
|
|
|
|
|
case 'v':
|
2003-12-14 17:34:00 +01:00
|
|
|
|
if (i<argc) {
|
|
|
|
|
orders = argv[++i];
|
|
|
|
|
} else {
|
|
|
|
|
return usage(argv[0], argv[i]);
|
|
|
|
|
}
|
2004-04-10 21:21:02 +02:00
|
|
|
|
break;
|
|
|
|
|
case 'p':
|
|
|
|
|
loadplane = atoi(argv[++i]);
|
|
|
|
|
break;
|
2003-12-14 17:34:00 +01:00
|
|
|
|
case 's':
|
|
|
|
|
c = argv[++i];
|
|
|
|
|
while (*c && (*c!='=')) ++c;
|
|
|
|
|
if (*c) {
|
|
|
|
|
*c++ = 0;
|
|
|
|
|
setLuaString(luaState, argv[i], c);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'n':
|
|
|
|
|
c = argv[++i];
|
|
|
|
|
while (*c && (*c!='=')) ++c;
|
|
|
|
|
if (*c) {
|
|
|
|
|
*c++ = 0;
|
|
|
|
|
setLuaNumber(luaState, argv[i], atof(c));
|
|
|
|
|
}
|
|
|
|
|
break;
|
2004-04-10 21:21:02 +02:00
|
|
|
|
case 'l':
|
2004-06-26 22:51:19 +02:00
|
|
|
|
script_path = argv[++i];
|
2004-04-10 21:21:02 +02:00
|
|
|
|
break;
|
|
|
|
|
case 'w':
|
|
|
|
|
g_writemap = true;
|
|
|
|
|
break;
|
|
|
|
|
case 'R':
|
|
|
|
|
opt_reportonly = true;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
usage(argv[0], argv[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-12-15 23:59:15 +01:00
|
|
|
|
|
2006-07-29 00:08:00 +02:00
|
|
|
|
if (orders==NULL) {
|
|
|
|
|
static char orderfile[MAX_PATH];
|
|
|
|
|
sprintf(orderfile, "%s/orders.%d", basepath(), turn);
|
|
|
|
|
orders = orderfile;
|
|
|
|
|
}
|
|
|
|
|
|
2003-12-15 23:59:15 +01:00
|
|
|
|
/* add some more variables to the lua globals */
|
|
|
|
|
setLuaString(luaState, "datapath", datapath());
|
2004-06-26 22:51:19 +02:00
|
|
|
|
setLuaString(luaState, "scriptpath", script_path);
|
2003-12-15 23:59:15 +01:00
|
|
|
|
setLuaString(luaState, "basepath", basepath());
|
|
|
|
|
setLuaString(luaState, "reportpath", reportpath());
|
|
|
|
|
setLuaString(luaState, "resourcepath", resourcepath());
|
|
|
|
|
setLuaString(luaState, "orderfile", orders);
|
|
|
|
|
|
|
|
|
|
return 0;
|
2003-11-10 00:36:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
2006-01-15 12:05:23 +01:00
|
|
|
|
static int
|
2004-08-29 01:06:15 +02:00
|
|
|
|
my_lua_error(lua_State * L)
|
|
|
|
|
{
|
|
|
|
|
const char* error = lua_tostring(L, -1);
|
|
|
|
|
|
2005-10-08 13:02:10 +02:00
|
|
|
|
log_error(("A LUA error occured: %s\n", error));
|
2004-08-29 01:06:15 +02:00
|
|
|
|
lua_pop(L, 1);
|
2006-02-05 16:48:52 +01:00
|
|
|
|
if (!g_ignore_errors) std::terminate();
|
2006-01-15 12:05:23 +01:00
|
|
|
|
return 1;
|
2004-08-29 01:06:15 +02:00
|
|
|
|
}
|
|
|
|
|
|
2006-11-22 22:07:48 +01:00
|
|
|
|
static dictionary * inifile;
|
|
|
|
|
static void
|
|
|
|
|
load_inifile(const char * filename)
|
|
|
|
|
{
|
|
|
|
|
dictionary * d = iniparser_new(filename);
|
|
|
|
|
if (d) {
|
2007-08-12 11:51:26 +02:00
|
|
|
|
const char * str;
|
2007-08-10 09:03:23 +02:00
|
|
|
|
g_basedir = iniparser_getstring(d, "common:base", g_basedir);
|
|
|
|
|
g_resourcedir = iniparser_getstring(d, "common:res", g_resourcedir);
|
|
|
|
|
xmlfile = iniparser_getstring(d, "common:xml", xmlfile);
|
|
|
|
|
script_path = iniparser_getstring(d, "common:scripts", script_path);
|
2007-02-25 12:10:13 +01:00
|
|
|
|
lomem = iniparser_getint(d, "common:lomem", lomem)?1:0;
|
2007-08-15 08:27:40 +02:00
|
|
|
|
memdebug = iniparser_getint(d, "common:memcheck", memdebug);
|
2007-02-25 12:10:13 +01:00
|
|
|
|
|
2007-08-16 08:53:00 +02:00
|
|
|
|
str = iniparser_getstring(d, "common:encoding", NULL);
|
2007-08-12 11:51:26 +02:00
|
|
|
|
if (str) enc_gamedata = xmlParseCharEncoding(str);
|
2007-08-10 09:03:23 +02:00
|
|
|
|
|
2007-02-25 12:10:13 +01:00
|
|
|
|
quiet = iniparser_getint(d, "eressea:verbose", 0)?0:1;
|
2007-05-27 23:20:06 +02:00
|
|
|
|
battledebug = iniparser_getint(d, "eressea:debug", battledebug)?1:0;
|
|
|
|
|
|
2007-08-10 09:03:23 +02:00
|
|
|
|
luafile = iniparser_getstring(d, "eressea:run", luafile);
|
|
|
|
|
g_reportdir = iniparser_getstring(d, "eressea:report", g_reportdir);
|
2007-08-12 15:02:24 +02:00
|
|
|
|
|
2008-04-19 18:56:15 +02:00
|
|
|
|
/* editor settings */
|
|
|
|
|
force_color = iniparser_getint(d, "editor:color", force_color);
|
|
|
|
|
|
2007-08-19 22:40:42 +02:00
|
|
|
|
str = iniparser_getstring(d, "common:locales", "de,en");
|
2007-08-12 15:02:24 +02:00
|
|
|
|
make_locales(str);
|
2006-11-22 22:07:48 +01:00
|
|
|
|
}
|
|
|
|
|
inifile = d;
|
|
|
|
|
}
|
|
|
|
|
|
2003-11-10 00:36:11 +01:00
|
|
|
|
int
|
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
|
{
|
2004-04-10 21:21:02 +02:00
|
|
|
|
int i;
|
2005-05-07 12:07:06 +02:00
|
|
|
|
char * lc_ctype;
|
|
|
|
|
char * lc_numeric;
|
2004-04-10 21:21:02 +02:00
|
|
|
|
|
2005-05-01 00:03:47 +02:00
|
|
|
|
setup_signal_handler();
|
|
|
|
|
|
2004-04-10 21:21:02 +02:00
|
|
|
|
sqlpatch = true;
|
|
|
|
|
log_open("eressea.log");
|
|
|
|
|
printf("\n%s PBEM host\n"
|
2005-01-03 22:28:21 +01:00
|
|
|
|
"Copyright (C) 1996-2005 C. Schlittchen, K. Zedel, E. Rehling, H. Peters.\n\n"
|
2004-04-10 21:21:02 +02:00
|
|
|
|
"Compilation: " __DATE__ " at " __TIME__ "\nVersion: %f\n\n", global.gamename, version());
|
|
|
|
|
|
2005-05-07 12:07:06 +02:00
|
|
|
|
lc_ctype = setlocale(LC_CTYPE, "");
|
|
|
|
|
lc_numeric = setlocale(LC_NUMERIC, "C");
|
|
|
|
|
if (lc_ctype) lc_ctype = strdup(lc_ctype);
|
|
|
|
|
if (lc_numeric) lc_numeric = strdup(lc_numeric);
|
2006-11-22 22:07:48 +01:00
|
|
|
|
|
2003-12-14 17:34:00 +01:00
|
|
|
|
lua_State * luaState = lua_init();
|
2004-06-07 06:53:28 +02:00
|
|
|
|
global.vm_state = luaState;
|
2006-11-22 22:07:48 +01:00
|
|
|
|
load_inifile("eressea.ini");
|
2003-12-14 17:34:00 +01:00
|
|
|
|
if ((i=read_args(argc, argv, luaState))!=0) return i;
|
2003-11-10 00:36:11 +01:00
|
|
|
|
|
2007-08-15 08:27:40 +02:00
|
|
|
|
#ifdef CRTDBG
|
|
|
|
|
init_crtdbg();
|
|
|
|
|
#endif
|
|
|
|
|
|
2004-04-10 21:21:02 +02:00
|
|
|
|
kernel_init();
|
|
|
|
|
game_init();
|
2003-11-10 00:36:11 +01:00
|
|
|
|
|
2003-12-14 17:34:00 +01:00
|
|
|
|
// run the main script
|
2004-04-10 21:21:02 +02:00
|
|
|
|
if (luafile==NULL) lua_console(luaState);
|
2004-06-26 22:51:19 +02:00
|
|
|
|
else {
|
2007-07-22 11:31:39 +02:00
|
|
|
|
char buf[MAX_PATH];
|
2004-08-29 01:06:15 +02:00
|
|
|
|
if (script_path) sprintf(buf, "%s/%s", script_path, luafile);
|
|
|
|
|
else strcpy(buf, luafile);
|
|
|
|
|
#ifdef LUABIND_NO_EXCEPTIONS
|
|
|
|
|
luabind::set_error_callback(my_lua_error);
|
2006-01-15 12:05:23 +01:00
|
|
|
|
luabind::set_pcall_callback(my_lua_error);
|
2004-08-29 01:06:15 +02:00
|
|
|
|
#else
|
2004-06-26 22:51:19 +02:00
|
|
|
|
try {
|
2004-08-29 01:06:15 +02:00
|
|
|
|
#endif
|
2004-09-26 21:15:36 +02:00
|
|
|
|
luabind::call_function<int>(luaState, "dofile", buf);
|
2004-08-29 01:06:15 +02:00
|
|
|
|
#ifndef LUABIND_NO_EXCEPTIONS
|
2004-06-26 22:51:19 +02:00
|
|
|
|
}
|
2004-09-26 20:49:57 +02:00
|
|
|
|
catch (std::runtime_error& rte) {
|
|
|
|
|
log_error(("%s.\n", rte.what()));
|
|
|
|
|
}
|
2004-06-26 22:51:19 +02:00
|
|
|
|
catch (luabind::error& e) {
|
|
|
|
|
lua_State* L = e.state();
|
2004-08-29 01:06:15 +02:00
|
|
|
|
my_lua_error(L);
|
2004-06-26 22:51:19 +02:00
|
|
|
|
}
|
2004-08-29 01:06:15 +02:00
|
|
|
|
#endif
|
2004-06-26 22:51:19 +02:00
|
|
|
|
}
|
2005-06-12 12:56:18 +02:00
|
|
|
|
#ifdef MSPACES
|
2005-06-12 01:10:06 +02:00
|
|
|
|
malloc_stats();
|
2005-06-12 12:56:18 +02:00
|
|
|
|
#endif
|
2004-04-10 21:21:02 +02:00
|
|
|
|
game_done();
|
|
|
|
|
kernel_done();
|
2003-12-14 17:34:00 +01:00
|
|
|
|
lua_done(luaState);
|
2004-04-10 21:21:02 +02:00
|
|
|
|
log_close();
|
2005-05-07 12:07:06 +02:00
|
|
|
|
|
|
|
|
|
setlocale(LC_CTYPE, lc_ctype);
|
|
|
|
|
setlocale(LC_NUMERIC, lc_numeric);
|
|
|
|
|
free(lc_ctype);
|
|
|
|
|
free(lc_numeric);
|
|
|
|
|
|
2006-11-22 22:07:48 +01:00
|
|
|
|
if (inifile) iniparser_free(inifile);
|
|
|
|
|
|
2004-04-10 21:21:02 +02:00
|
|
|
|
return 0;
|
2003-11-10 00:36:11 +01:00
|
|
|
|
}
|