Merge branch 'master' of github.com:eressea/server

This commit is contained in:
Enno Rehling 2014-11-09 00:25:06 +01:00
commit 7bebea4f67
17 changed files with 50 additions and 160 deletions

@ -1 +1 @@
Subproject commit 2a7af5e2347217ea4efcf7fb3f0bc9c2681d1a17
Subproject commit c267f95e4170c40809effa61af418fbe63d43e48

View File

@ -12,5 +12,6 @@ return {
require('eressea.tunnels'),
require('eressea.ponnuki'),
require('eressea.astral'),
require('eressea.locales'),
require('eressea.ents')
}

View File

@ -0,0 +1,20 @@
local function change_locales(localechange)
for loc, flist in pairs(localechange) do
for index, name in pairs(flist) do
f = get_faction(atoi36(name))
if f ~= nil and f.locale ~= loc then
print("LOCALECHANGE ", f, f.locale, loc)
f.locale = loc
end
end
end
end
local pkg = {}
function pkg.update()
local localechange = { de = { 'ii' } }
change_locales(localechange)
end
return pkg

View File

@ -45,6 +45,7 @@ function test_flags()
eressea.write_game("test.dat")
eressea.free_game()
eressea.read_game("test.dat")
os.remove('test.dat')
f = get_faction(no)
assert_equal(flags, f.flags)
end

View File

@ -105,6 +105,7 @@ function test_process_quit()
eressea.write_game('test.dat')
eressea.free_game()
eressea.read_game('test.dat')
os.remove('test.dat')
assert_equal(nil, _G.get_faction(fno))
end

View File

@ -26,18 +26,6 @@ function callbacks(rules, name, ...)
end
end
local function change_locales(localechange)
for loc, flist in pairs(localechange) do
for index, name in pairs(flist) do
f = get_faction(atoi36(name))
if f ~= nil and f.locale ~= loc then
print("LOCALECHANGE ", f, f.locale, loc)
f.locale = loc
end
end
end
end
local function dbupdate()
update_scores()
dbname = config.dbname or 'eressea.db'
@ -153,9 +141,6 @@ function process(rules, orders)
process_orders()
callbacks(rules, 'update')
local localechange = { de = { 'ii' } }
change_locales(localechange)
write_files(config.locales)
file = '' .. get_turn() .. '.dat'

View File

@ -77,7 +77,6 @@ set (ERESSEA_SRC
keyword.c
skill.c
json.c
creation.c
creport.c
economy.c
give.c

View File

@ -1,71 +0,0 @@
/*
Copyright (c) 1998-2014, Enno Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de>
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 <platform.h>
#include <kernel/config.h>
#include "creation.h"
#include "monster.h"
#include "alchemy.h"
/* kernel includes */
#include <kernel/build.h>
#include <kernel/faction.h>
#include <kernel/item.h>
#include <kernel/plane.h>
#include <kernel/race.h>
#include <kernel/region.h>
#include <kernel/save.h>
#include <kernel/ship.h>
#include <kernel/terrain.h>
#include <kernel/unit.h>
/* util includes */
#include <util/goodies.h>
#include <util/lists.h>
/* libc includes */
#include <assert.h>
#include <ctype.h>
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
faction *createmonsters(int no)
{
faction *f = findfaction(no);
if (f) {
puts("* Fehler! Die Monster Partei gibt es schon.");
return f;
}
f = (faction *) calloc(1, sizeof(faction));
f->no = no;
/* alles ist auf null gesetzt, ausser dem folgenden. achtung - partei
* no 0 muss keine orders einreichen! */
f->email = _strdup("monsters@eressea.de");
f->name = _strdup("Monster");
f->alive = 1;
f->options = (char)(1 << O_REPORT);
addlist(&factions, f);
fhash(f);
return f;
}

View File

@ -1,30 +0,0 @@
/*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de>
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.
**/
#ifndef H_GC_CREATION
#define H_GC_CREATION
#ifdef __cplusplus
extern "C" {
#endif
struct faction *createmonsters(int no);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -35,12 +35,14 @@ static void test_export_no_regions(CuTest * tc) {
char buf[1024];
stream out = { 0 };
int err;
size_t len;
mstream_init(&out);
err = json_export(&out, EXPORT_REGIONS);
CuAssertIntEquals(tc, 0, err);
out.api->rewind(out.handle);
out.api->read(out.handle, buf, sizeof(buf));
len = out.api->read(out.handle, buf, sizeof(buf));
buf[len] = '\0';
CuAssertStrEquals(tc, "{}", strip(buf));
mstream_done(&out);
}

View File

@ -68,6 +68,7 @@ faction *factions;
*/
void free_faction(faction * f)
{
funhash(f);
if (f->msgs)
free_messagelist(f->msgs);
while (f->battles) {
@ -113,9 +114,12 @@ void funhash(faction * f)
{
int index = f->no % FMAXHASH;
faction **fp = factionhash + index;
while (*fp && (*fp) != f)
while (*fp && (*fp) != f) {
fp = &(*fp)->nexthash;
}
if (*fp == f) {
*fp = f->nexthash;
}
}
static faction *ffindhash(int no)
@ -139,44 +143,24 @@ void set_show_item(faction * f, const struct item_type *itype)
a->data.v = (void *)itype;
}
faction *get_monsters(void) {
faction *f;
for (f = factions; f; f = f->next) {
if ((f->flags & FFL_NPC) && !(f->flags & FFL_DEFENDER)) {
return f;
}
}
return 0;
}
faction *get_or_create_monsters(void)
{
faction *f = get_monsters();
faction *f = findfaction(666);
if (!f) {
/* shit! */
f = findfaction(666);
}
if (!f) {
const race *rc = rc_find("dragon");
const race *rc = rc_get_or_create("dragon");
const char *email = get_param(global.parameters, "monster.email");
if (email) {
f = addfaction(email, NULL, rc, NULL, 0);
}
else {
f = addfaction("noreply@eressea.de", NULL, rc, NULL, 0);
}
f = addfaction(email ? email : "noreply@eressea.de", NULL, rc, NULL, 0);
renumber_faction(f, 666);
faction_setname(f, "Monster");
f->options = 0;
}
if (f) {
fset(f, FFL_NPC | FFL_NOIDLEOUT);
}
return f;
}
faction *get_monsters(void) {
return get_or_create_monsters();
}
const unit *random_unit_in_faction(const faction * f)
{
unit *u;

View File

@ -54,7 +54,7 @@ extern "C" {
#define FFL_SAVEMASK (FFL_DEFENDER|FFL_NEWID|FFL_GM|FFL_NPC|FFL_DBENTRY|FFL_NOIDLEOUT)
#define is_monsters(f) ((f)->flags&FFL_NPC)
#define is_monsters(f) (f && fval(f, FFL_NPC) && f==get_monsters())
typedef struct faction {
struct faction *next;

View File

@ -91,20 +91,18 @@ static void test_addfaction(CuTest *tc) {
CuAssertIntEquals(tc, M_GRAY, f->magiegebiet);
CuAssertIntEquals(tc, turn, f->lastorders);
CuAssertPtrEquals(tc, f, findfaction(f->no));
test_cleanup();
}
static void test_get_monsters(CuTest *tc) {
faction *f;
CuAssertPtrEquals(tc, NULL, get_monsters());
f = get_or_create_monsters();
free_gamedata();
CuAssertPtrNotNull(tc, (f = get_monsters()));
CuAssertPtrEquals(tc, f, get_monsters());
CuAssertIntEquals(tc, 666, f->no);
CuAssertStrEquals(tc, "Monster", f->name);
free_gamedata();
CuAssertPtrEquals(tc, NULL, get_monsters());
f = get_or_create_monsters();
CuAssertPtrEquals(tc, f, get_monsters());
CuAssertIntEquals(tc, 666, f->no);
test_cleanup();
}
CuSuite *get_faction_suite(void)

View File

@ -50,6 +50,7 @@ static void test_group_readwrite(CuTest * tc)
CuAssertPtrEquals(tc, 0, f->groups->allies->next);
CuAssertPtrEquals(tc, f, f->groups->allies->faction);
CuAssertIntEquals(tc, HELP_GIVE, f->groups->allies->status);
remove("test.dat");
test_cleanup();
}

View File

@ -733,7 +733,7 @@ void set_level(unit * u, skill_t sk, int value)
{
skill *sv = u->skills;
assert(sk != SK_MAGIC || !u->faction || is_monsters(u->faction) || u->number == 1);
assert(sk != SK_MAGIC || !u->faction || u->number == 1 || is_monsters(u->faction));
if (!skill_enabled(sk))
return;

View File

@ -268,7 +268,7 @@ int main(int argc, char **argv)
bind_monsters(L);
err = eressea_run(L, luafile);
if (err) {
log_error("server execution failed with code %d\n", err);
log_error("script %s failed with code %d\n", luafile, err);
return err;
}
#ifdef MSPACES

View File

@ -2337,14 +2337,13 @@ static void eval_int36(struct opstack **stack, const void *userdata)
static void log_orders(const struct message *msg)
{
faction *f = get_monsters();
char buffer[4096];
int i;
for (i = 0; i != msg->type->nparameters; ++i) {
if (msg->type->types[i]->copy == &var_copy_order) {
const char *section = nr_section(msg);
nr_render(msg, f ? f->locale : default_locale, buffer, sizeof(buffer), f);
nr_render(msg, default_locale, buffer, sizeof(buffer), NULL);
log_debug("MESSAGE [%s]: %s\n", section, buffer);
break;
}