commit e608d40e7a045c6cd3826f4ddeb45ba2cff3d89b Author: Enno Rehling Date: Sat Aug 7 22:17:11 2010 -0700 moving to a new repository layout. step 3: the example server that anyone can use diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..fdd287910 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,33 @@ +cmake_minimum_required(VERSION 2.4) +project (example C) + +if (WIN32) + add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE) +else (WIN32) + include_directories (/usr/include/lua5.1/ /usr/include/libxml2) + set(CMAKE_C_FLAGS "-g -Wall -Werror -Wno-unknown-pragmas -Wstrict-prototypes -Wpointer-arith -Wno-char-subscripts") +endif (WIN32) +include_directories (../external ../shared/src) + +set (LIB_SRCS + ../external/sqlite3.c + ../external/md5.c + ../external/bson/bson.c + ../external/bson/numbers.c + ../external/dlmalloc/malloc.c + ../external/cutest/CuTest.c + ../shared/src/build/gamecode.c + ../shared/src/build/kernel.c + ../shared/src/build/lib.c + ../shared/src/build/util.c +) + +set (EXE_SRCS + src/server.c +) + +add_executable (example ${LIB_SRCS} ${EXE_SRCS}) +if (WIN32) +else (WIN32) + target_link_libraries (example tolua xml2 ncurses lua5.1 pthread) +endif (WIN32) diff --git a/example.sln b/example.sln new file mode 100644 index 000000000..e1d9e7116 --- /dev/null +++ b/example.sln @@ -0,0 +1,53 @@ +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "kernel", "..\server\src\kernel.vcproj", "{6F104C0A-DDF5-A34B-A89C-0DC278DCEF6D}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gamecode", "..\server\src\gamecode.vcproj", "{1E8BFF9E-3044-0742-992F-C5765B80FE65}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "util", "..\server\src\util.vcproj", "{F70CFB27-8A2F-E447-B452-4E1C590EDA6D}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lua-bindings", "..\server\src\lua-bindings.vcproj", "{75501170-51C2-E641-BA8B-EDC008184192}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "external", "..\external\external.vcproj", "{F9AE4586-8F65-486B-9666-744839E40A54}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "amalgamation-example", "src\example.vcproj", "{4A17DAEE-2261-4E2C-96F6-BA4132A09551}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tests", "..\server\src\tests.vcproj", "{228B8781-480F-4608-BA14-1EB82581EADE}" +EndProject +Global + GlobalSection(SubversionScc) = preSolution + Svn-Managed = True + Manager = AnkhSVN - Subversion Support for Visual Studio + EndGlobalSection + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6F104C0A-DDF5-A34B-A89C-0DC278DCEF6D}.Debug|Win32.ActiveCfg = Debug|Win32 + {6F104C0A-DDF5-A34B-A89C-0DC278DCEF6D}.Release|Win32.ActiveCfg = Release|Win32 + {6F104C0A-DDF5-A34B-A89C-0DC278DCEF6D}.Release|Win32.Build.0 = Release|Win32 + {1E8BFF9E-3044-0742-992F-C5765B80FE65}.Debug|Win32.ActiveCfg = Debug|Win32 + {1E8BFF9E-3044-0742-992F-C5765B80FE65}.Release|Win32.ActiveCfg = Release|Win32 + {1E8BFF9E-3044-0742-992F-C5765B80FE65}.Release|Win32.Build.0 = Release|Win32 + {F70CFB27-8A2F-E447-B452-4E1C590EDA6D}.Debug|Win32.ActiveCfg = Debug|Win32 + {F70CFB27-8A2F-E447-B452-4E1C590EDA6D}.Release|Win32.ActiveCfg = Release|Win32 + {F70CFB27-8A2F-E447-B452-4E1C590EDA6D}.Release|Win32.Build.0 = Release|Win32 + {75501170-51C2-E641-BA8B-EDC008184192}.Debug|Win32.ActiveCfg = Debug|Win32 + {75501170-51C2-E641-BA8B-EDC008184192}.Release|Win32.ActiveCfg = Release|Win32 + {75501170-51C2-E641-BA8B-EDC008184192}.Release|Win32.Build.0 = Release|Win32 + {F9AE4586-8F65-486B-9666-744839E40A54}.Debug|Win32.ActiveCfg = Debug|Win32 + {F9AE4586-8F65-486B-9666-744839E40A54}.Release|Win32.ActiveCfg = Release|Win32 + {F9AE4586-8F65-486B-9666-744839E40A54}.Release|Win32.Build.0 = Release|Win32 + {4A17DAEE-2261-4E2C-96F6-BA4132A09551}.Debug|Win32.ActiveCfg = Debug|Win32 + {4A17DAEE-2261-4E2C-96F6-BA4132A09551}.Debug|Win32.Build.0 = Debug|Win32 + {4A17DAEE-2261-4E2C-96F6-BA4132A09551}.Release|Win32.ActiveCfg = Release|Win32 + {228B8781-480F-4608-BA14-1EB82581EADE}.Debug|Win32.ActiveCfg = Debug|Win32 + {228B8781-480F-4608-BA14-1EB82581EADE}.Debug|Win32.Build.0 = Debug|Win32 + {228B8781-480F-4608-BA14-1EB82581EADE}.Release|Win32.ActiveCfg = Release|Win32 + {228B8781-480F-4608-BA14-1EB82581EADE}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/example_10.sln b/example_10.sln new file mode 100644 index 000000000..621a3769c --- /dev/null +++ b/example_10.sln @@ -0,0 +1,47 @@ +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual C++ Express 2010 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "kernel", "..\server\src\kernel.vcxproj", "{6F104C0A-DDF5-A34B-A89C-0DC278DCEF6D}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gamecode", "..\server\src\gamecode.vcxproj", "{1E8BFF9E-3044-0742-992F-C5765B80FE65}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "util", "..\server\src\util.vcxproj", "{F70CFB27-8A2F-E447-B452-4E1C590EDA6D}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lua-bindings", "..\server\src\lua-bindings.vcxproj", "{75501170-51C2-E641-BA8B-EDC008184192}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "external", "..\external\external.vcxproj", "{F9AE4586-8F65-486B-9666-744839E40A54}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "amalgamation-example", "src\example.vcxproj", "{4A17DAEE-2261-4E2C-96F6-BA4132A09551}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6F104C0A-DDF5-A34B-A89C-0DC278DCEF6D}.Debug|Win32.ActiveCfg = Debug|Win32 + {6F104C0A-DDF5-A34B-A89C-0DC278DCEF6D}.Release|Win32.ActiveCfg = Release|Win32 + {6F104C0A-DDF5-A34B-A89C-0DC278DCEF6D}.Release|Win32.Build.0 = Release|Win32 + {1E8BFF9E-3044-0742-992F-C5765B80FE65}.Debug|Win32.ActiveCfg = Debug|Win32 + {1E8BFF9E-3044-0742-992F-C5765B80FE65}.Release|Win32.ActiveCfg = Release|Win32 + {1E8BFF9E-3044-0742-992F-C5765B80FE65}.Release|Win32.Build.0 = Release|Win32 + {F70CFB27-8A2F-E447-B452-4E1C590EDA6D}.Debug|Win32.ActiveCfg = Debug|Win32 + {F70CFB27-8A2F-E447-B452-4E1C590EDA6D}.Release|Win32.ActiveCfg = Release|Win32 + {F70CFB27-8A2F-E447-B452-4E1C590EDA6D}.Release|Win32.Build.0 = Release|Win32 + {75501170-51C2-E641-BA8B-EDC008184192}.Debug|Win32.ActiveCfg = Debug|Win32 + {75501170-51C2-E641-BA8B-EDC008184192}.Release|Win32.ActiveCfg = Release|Win32 + {75501170-51C2-E641-BA8B-EDC008184192}.Release|Win32.Build.0 = Release|Win32 + {F9AE4586-8F65-486B-9666-744839E40A54}.Debug|Win32.ActiveCfg = Debug|Win32 + {F9AE4586-8F65-486B-9666-744839E40A54}.Release|Win32.ActiveCfg = Release|Win32 + {F9AE4586-8F65-486B-9666-744839E40A54}.Release|Win32.Build.0 = Release|Win32 + {4A17DAEE-2261-4E2C-96F6-BA4132A09551}.Debug|Win32.ActiveCfg = Debug|Win32 + {4A17DAEE-2261-4E2C-96F6-BA4132A09551}.Debug|Win32.Build.0 = Debug|Win32 + {4A17DAEE-2261-4E2C-96F6-BA4132A09551}.Release|Win32.ActiveCfg = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(SubversionScc) = preSolution + Svn-Managed = True + Manager = AnkhSVN - Subversion Support for Visual Studio + EndGlobalSection +EndGlobal diff --git a/game/eressea.ini b/game/eressea.ini new file mode 100644 index 000000000..e9a95cb15 --- /dev/null +++ b/game/eressea.ini @@ -0,0 +1,17 @@ +[eressea] +base = . +load = setup.lua +report = reports +verbose = 0 +lomem = 0 +debug = 0 +memcheck = 0 +locales = de,en + +[config] +game = example +source_dir = ../.. +maxnmrs = 10 + +[editor] +color = 1 diff --git a/game/setup.lua b/game/setup.lua new file mode 100644 index 000000000..0c9f0ca3d --- /dev/null +++ b/game/setup.lua @@ -0,0 +1,15 @@ +local srcpath = config.source_dir +local respath = srcpath .. '/example/res' +local paths = { + 'example/scripts/?.lua', + 'server/scripts/?.lua', + 'external/lunit/?.lua' +} + +for idx, path in pairs(paths) do + package.path = srcpath .. '/' .. path .. ';' .. package.path +end + +read_xml(respath..'/config-example.xml', respath..'/catalog-example.xml') + +require "init" diff --git a/res/armor.xml b/res/armor.xml new file mode 100644 index 000000000..bfd1b851a --- /dev/null +++ b/res/armor.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/res/buildings.xml b/res/buildings.xml new file mode 100644 index 000000000..eddaf42bc --- /dev/null +++ b/res/buildings.xml @@ -0,0 +1,4 @@ + + + + diff --git a/res/buildings/castle.xml b/res/buildings/castle.xml new file mode 100644 index 000000000..071fb13fc --- /dev/null +++ b/res/buildings/castle.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/res/catalog-example.xml b/res/catalog-example.xml new file mode 100644 index 000000000..2b16bf737 --- /dev/null +++ b/res/catalog-example.xml @@ -0,0 +1,10 @@ + + + + + + diff --git a/res/config-example.xml b/res/config-example.xml new file mode 100644 index 000000000..4ff416112 --- /dev/null +++ b/res/config-example.xml @@ -0,0 +1,106 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + eressea-server@example.com + eressea-server@example.com + + + Bitte denke daran, deine Befehle mit dem Betreff + ERESSEA BEFEHLE an eressea-server@example.com zu senden. + Remember to send your orders to + eressea-server@example.com with the subject ERESSEA ORDERS. + + + ERESSEA BEFEHLE + ERESSEA ORDERS + + + ARBEITEN + WORK + + + diff --git a/res/items.xml b/res/items.xml new file mode 100644 index 000000000..c526081c0 --- /dev/null +++ b/res/items.xml @@ -0,0 +1,3 @@ + + + diff --git a/res/races.xml b/res/races.xml new file mode 100644 index 000000000..c79f3d002 --- /dev/null +++ b/res/races.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/res/races/aquarian.xml b/res/races/aquarian.xml new file mode 100644 index 000000000..0b53b588c --- /dev/null +++ b/res/races/aquarian.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/res/races/cat.xml b/res/races/cat.xml new file mode 100644 index 000000000..f1ac0f5ee --- /dev/null +++ b/res/races/cat.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/res/races/demon.xml b/res/races/demon.xml new file mode 100644 index 000000000..9b5802450 --- /dev/null +++ b/res/races/demon.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/res/races/dwarf.xml b/res/races/dwarf.xml new file mode 100644 index 000000000..d1efbfc21 --- /dev/null +++ b/res/races/dwarf.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/races/elf.xml b/res/races/elf.xml new file mode 100644 index 000000000..07e6cd3c0 --- /dev/null +++ b/res/races/elf.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/races/goblin.xml b/res/races/goblin.xml new file mode 100644 index 000000000..50f15b5e0 --- /dev/null +++ b/res/races/goblin.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/res/races/halfling.xml b/res/races/halfling.xml new file mode 100644 index 000000000..4104c7199 --- /dev/null +++ b/res/races/halfling.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/res/races/human.xml b/res/races/human.xml new file mode 100644 index 000000000..d8fea87f4 --- /dev/null +++ b/res/races/human.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/res/races/insect.xml b/res/races/insect.xml new file mode 100644 index 000000000..42617ce9b --- /dev/null +++ b/res/races/insect.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/races/orc.xml b/res/races/orc.xml new file mode 100644 index 000000000..bf23a4e7f --- /dev/null +++ b/res/races/orc.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/res/races/troll.xml b/res/races/troll.xml new file mode 100644 index 000000000..b75169f15 --- /dev/null +++ b/res/races/troll.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/res/ships.xml b/res/ships.xml new file mode 100644 index 000000000..c25b573de --- /dev/null +++ b/res/ships.xml @@ -0,0 +1,4 @@ + + + + diff --git a/res/ships/boat.xml b/res/ships/boat.xml new file mode 100644 index 000000000..bbcdcb1f3 --- /dev/null +++ b/res/ships/boat.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/res/spells.xml b/res/spells.xml new file mode 100644 index 000000000..4883fce74 --- /dev/null +++ b/res/spells.xml @@ -0,0 +1,166 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/res/terrains.xml b/res/terrains.xml new file mode 100644 index 000000000..5cc812a9a --- /dev/null +++ b/res/terrains.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/res/weapons.xml b/res/weapons.xml new file mode 100644 index 000000000..5efef2831 --- /dev/null +++ b/res/weapons.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/scripts/example/main.lua b/scripts/example/main.lua new file mode 100644 index 000000000..5601ee47d --- /dev/null +++ b/scripts/example/main.lua @@ -0,0 +1,50 @@ +-- Enno was here +require "multis" + +function process(orders) + local confirmed_multis = { } + local suspected_multis = { } + + if open_game(get_turn())~=0 then + print("could not read game") + return -1 + end + init_summary() + + -- kill multi-players (external script) + kill_multis(confirmed_multis, false) + mark_multis(suspected_multis, false) + + -- run the turn: + if read_orders(orders) ~= 0 then + print("could not read " .. orders) + return -1 + end + + -- plan_monsters() + + if nmr_check(config.maxnmrs or 80)~=0 then + return -1 + end + + process_orders() + + -- create new monsters: + spawn_braineaters(0.25) + + -- post-turn updates: + update_guards() + update_scores() + + local localechange = { de = { "ii" } } + change_locales(localechange) + + write_files(config.locales) + + file = "" .. get_turn() .. ".dat" + if write_game(file, "binary")~=0 then + print("could not write game") + return -1 + end + return 0 +end diff --git a/scripts/example/modules.lua b/scripts/example/modules.lua new file mode 100644 index 000000000..8f08dcbe5 --- /dev/null +++ b/scripts/example/modules.lua @@ -0,0 +1,6 @@ +require "example.rules" + +local srcpath = config.source_dir +tests = { + srcpath .. '/server/scripts/tests/common.lua', +} diff --git a/scripts/example/rules.lua b/scripts/example/rules.lua new file mode 100644 index 000000000..9b3706a55 --- /dev/null +++ b/scripts/example/rules.lua @@ -0,0 +1,8 @@ +function item_canuse(u, iname) + local race = u.race + if iname=="greatbow" then + -- only elves use greatbow + return race=="elf" + end + return true +end diff --git a/src/example.vcproj b/src/example.vcproj new file mode 100644 index 000000000..6e23045ae --- /dev/null +++ b/src/example.vcproj @@ -0,0 +1,276 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/example.vcxproj b/src/example.vcxproj new file mode 100644 index 000000000..b6f693d22 --- /dev/null +++ b/src/example.vcxproj @@ -0,0 +1,114 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + amalgamation-example + {4A17DAEE-2261-4E2C-96F6-BA4132A09551} + build + Win32Proj + + + + Application + Unicode + true + + + Application + Unicode + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30319.1 + $(ProjectDir)$(Configuration)\ + $(ProjectDir)$(Configuration)\ + true + $(ProjectDir)$(Configuration)\ + $(ProjectDir)$(Configuration)\ + false + + + + /MP %(AdditionalOptions) + Disabled + ../../server/src;../../external;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + EnableFastChecks + MultiThreadedDebugDLL + Use + stdafx.h + Level4 + EditAndContinue + + + libxml2.lib;pdcurses.lib;lua5.1_d.lib;tolua.lib;%(AdditionalDependencies) + $(OutDir)eressea.exe + true + Console + MachineX86 + + + + + ../../server/src;../../external;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + MultiThreadedDLL + Use + Level3 + ProgramDatabase + + + libxml2.lib;pdcurses.lib;lua5.1.lib;tolua.lib;%(AdditionalDependencies) + $(OutDir)eressea.exe + true + Console + true + true + MachineX86 + + + + + true + true + + + + + + + + Create + stdafx.h + Create + + + src/util;%(AdditionalIncludeDirectories) + + + + + + + + + \ No newline at end of file diff --git a/src/example.vcxproj.filters b/src/example.vcxproj.filters new file mode 100644 index 000000000..ae1f12b67 --- /dev/null +++ b/src/example.vcxproj.filters @@ -0,0 +1,47 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {28903f02-8887-4f37-9579-228fe73a2dcd} + + + + + Source Files + + + Unity Build + + + Unity Build + + + Unity Build + + + Unity Build + + + Unity Build + + + Unity Build + + + Unity Build + + + + + Header Files + + + \ No newline at end of file diff --git a/src/main.c b/src/main.c new file mode 100644 index 000000000..1ecdece18 --- /dev/null +++ b/src/main.c @@ -0,0 +1,171 @@ +/* +Copyright (c) 1998-2010, Enno Rehling + Katja Zedel + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +**/ + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +static const char * luafile = "setup.lua"; +static const char * entry_point = NULL; +static const char * inifile = "eressea.ini"; +static int memdebug = 0; + +static void parse_config(const char * filename) +{ + dictionary * d = iniparser_new(filename); + if (d) { + load_inifile(d); + + memdebug = iniparser_getint(d, "eressea:memcheck", memdebug); + entry_point = iniparser_getstring(d, "eressea:run", entry_point); + luafile = iniparser_getstring(d, "eressea:load", luafile); + + /* only one value in the [editor] section */ + force_color = iniparser_getint(d, "editor:color", force_color); + } + global.inifile = d; +} + +static int +usage(const char * prog, const char * arg) +{ + if (arg) { + fprintf(stderr, "unknown argument: %s\n\n", arg); + } + fprintf(stderr, "Usage: %s [options]\n" + "-t : read this datafile, not the most current one\n" + "-q : be quite (same as -v 0)\n" + "-v : verbosity level\n" + "-C : run in interactive mode\n" + "--color : force curses to use colors even when not detected\n" + "--tests : run test suite\n" + "--help : help\n", prog); + return -1; +} + +static int +parse_args(int argc, char **argv, int * exitcode) +{ + int i, run_tests = 0; + + 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, "version")==0) { + printf("\n%s PBEM host\n" + "Copyright (C) 1996-2005 C. Schlittchen, K. Zedel, E. Rehling, H. Peters.\n\n" + "Compilation: " __DATE__ " at " __TIME__ "\nVersion: %f\n\n", global.gamename, version()); + } + else if (strcmp(argv[i]+2, "color")==0) { + /* force the editor to have colors */ + force_color = 1; + } + else if (strcmp(argv[i]+2, "help")==0) { + return usage(argv[0], NULL); + } + else if (strcmp(argv[i]+2, "tests")==0) { + run_tests = 1; + } + else { + return usage(argv[0], argv[i]); + } + } else switch(argv[i][1]) { + case 'C': + entry_point = NULL; + break; + case 'e': + entry_point = argv[++i]; + break; + case 't': + turn = atoi(argv[++i]); + break; + case 'q': + verbosity = 0; + break; + case 'v': + verbosity = atoi(argv[++i]); + break; + case 'h': + usage(argv[0], NULL); + return 1; + default: + *exitcode = -1; + usage(argv[0], argv[i]); + return 1; + } + } + + if (run_tests) { + *exitcode = RunAllTests(); + return 1; + } + + return 0; +} + + +void locale_init(void) +{ + setlocale(LC_CTYPE, ""); + setlocale(LC_NUMERIC, "C"); + assert(towlower(0xC4)==0xE4); /* Ä => ä */ +} + +int main(int argc, char ** argv) +{ + int err, result = 0; + + parse_config(inifile); + + log_open("eressea.log"); + locale_init(); + + err = parse_args(argc, argv, &result); + if (err) { + return result; + } + + err = eressea_init(); + if (err) { + log_error(("initialization failed with code %d\n", err)); + return err; + } + + err = eressea_run(luafile, entry_point); + if (err) { + log_error(("server execution failed with code %d\n", err)); + return err; + } + + eressea_done(); + log_close(); + return 0; +} diff --git a/src/server.c b/src/server.c new file mode 100644 index 000000000..ce69a67a3 --- /dev/null +++ b/src/server.c @@ -0,0 +1,3 @@ +#include "stdafx.h" +#include "main.c" +#include "tests.c"