forked from github/server
commit
208ed4c74a
45 changed files with 300 additions and 411 deletions
|
@ -19,7 +19,7 @@ fi
|
||||||
rm -f "orders.$TURN"
|
rm -f "orders.$TURN"
|
||||||
find "orders.dir.$TURN" -maxdepth 1 -type f -printf "%T+\t%p\n" | sort | cut -f2 | while read -r
|
find "orders.dir.$TURN" -maxdepth 1 -type f -printf "%T+\t%p\n" | sort | cut -f2 | while read -r
|
||||||
do
|
do
|
||||||
cat "$REPLY" >> "orders.$TURN"
|
tr -d '\r' < "$REPLY" >> "orders.$TURN"
|
||||||
done
|
done
|
||||||
|
|
||||||
lockfile -r3 -l120 orders.queue.lock
|
lockfile -r3 -l120 orders.queue.lock
|
||||||
|
|
|
@ -52,6 +52,9 @@ messages = {
|
||||||
"validate-en": "Validating",
|
"validate-en": "Validating",
|
||||||
"validate-de": "Verarbeite",
|
"validate-de": "Verarbeite",
|
||||||
|
|
||||||
|
"noorders-en": "The email contained no recognizable orders.",
|
||||||
|
"noorders-de": "Es konnten keine Befehle gefunden werden.",
|
||||||
|
|
||||||
"faction-en": "Faction",
|
"faction-en": "Faction",
|
||||||
"faction-de": "Partei",
|
"faction-de": "Partei",
|
||||||
|
|
||||||
|
@ -183,6 +186,8 @@ for line in lines:
|
||||||
logfile = open(os.path.join(game_dir, "zug.log"), "a")
|
logfile = open(os.path.join(game_dir, "zug.log"), "a")
|
||||||
dirname, filename = split_filename(infile)
|
dirname, filename = split_filename(infile)
|
||||||
msg = messages["validate-"+locale] + " " + infile + "\n\n"
|
msg = messages["validate-"+locale] + " " + infile + "\n\n"
|
||||||
|
if len(results)==0:
|
||||||
|
msg = msg + messages["noorders-"+locale]
|
||||||
for faction, game_email, success, pwd in results:
|
for faction, game_email, success, pwd in results:
|
||||||
msg = msg + messages["faction-"+locale] + " " + faction + "\n"
|
msg = msg + messages["faction-"+locale] + " " + faction + "\n"
|
||||||
if success: failed = False
|
if success: failed = False
|
||||||
|
|
|
@ -2429,6 +2429,9 @@ msgstr "\"$unit($unit) konnte nur $int($ships) von $int($maxships) Schiffen verz
|
||||||
msgid "error283"
|
msgid "error283"
|
||||||
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Das Passwort darf nur Buchstaben und Ziffern enthalten.\""
|
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Das Passwort darf nur Buchstaben und Ziffern enthalten.\""
|
||||||
|
|
||||||
|
msgid "error321"
|
||||||
|
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Das gewählte Passwort war zu lang.\""
|
||||||
|
|
||||||
msgid "rust_effect"
|
msgid "rust_effect"
|
||||||
msgstr "\"$unit($mage) legt einen Rosthauch auf $unit($target). $int($amount) Waffen wurden vom Rost zerfressen.\""
|
msgstr "\"$unit($mage) legt einen Rosthauch auf $unit($target). $int($amount) Waffen wurden vom Rost zerfressen.\""
|
||||||
|
|
||||||
|
|
|
@ -2426,6 +2426,9 @@ msgstr "\"$unit($unit) in $region($region): '$order($command)' - No luxury items
|
||||||
msgid "stormwinds_reduced"
|
msgid "stormwinds_reduced"
|
||||||
msgstr "\"$unit($unit) could only enchant $int($ships) of $int($maxships) ships.\""
|
msgstr "\"$unit($unit) could only enchant $int($ships) of $int($maxships) ships.\""
|
||||||
|
|
||||||
|
msgid "error321"
|
||||||
|
msgstr "\"$unit($unit) in $region($region): '$order($command)' - The chosen password was too long.\""
|
||||||
|
|
||||||
msgid "error283"
|
msgid "error283"
|
||||||
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Your password may only contain alphanumeric symbols.\""
|
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Your password may only contain alphanumeric symbols.\""
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
IGNORE=$(find src -name "*.test.c" | awk '{ print "-i"$1 }')
|
IGNORE=$(find src -name "*.test.c" | awk '{ print "-i"$1 }')
|
||||||
|
|
||||||
cppcheck $IGNORE -isrc/tests.c \
|
#cppcheck $IGNORE -isrc/tests.c \
|
||||||
--quiet --enable=all -U_MSC_VER -UCLEANUP_CODE -UTODO \
|
cppcheck --quiet --enable=warning,style,performance,portability -U_MSC_VER -UCLEANUP_CODE -UTODO \
|
||||||
-UERESSEA_BUILDNO -UERESSEA_VERSION \
|
-UERESSEA_BUILDNO -UERESSEA_VERSION -UTEST_THREADS \
|
||||||
-IcJSON -Isrc -Iclibs -Istorage src
|
-IcJSON -Isrc -Iclibs -Istorage src
|
||||||
|
|
||||||
|
|
|
@ -121,7 +121,7 @@ static int read_keyval_orig(gamedata *data, int *keys, int n) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int a_readkeys(variant *var, void *owner, gamedata *data) {
|
static int a_readkeys(variant *var, void *owner, gamedata *data) {
|
||||||
int i, n, ksn, *keys;
|
int n, ksn, *keys;
|
||||||
|
|
||||||
READ_INT(data->store, &n);
|
READ_INT(data->store, &n);
|
||||||
assert(n < 4096 && n >= 0);
|
assert(n < 4096 && n >= 0);
|
||||||
|
@ -155,7 +155,7 @@ static int a_readkeys(variant *var, void *owner, gamedata *data) {
|
||||||
}
|
}
|
||||||
keys[0] = n;
|
keys[0] = n;
|
||||||
if (data->version < SORTKEYS_VERSION) {
|
if (data->version < SORTKEYS_VERSION) {
|
||||||
int e = 1;
|
int i, e = 1;
|
||||||
for (i = 1; i != n; ++i) {
|
for (i = 1; i != n; ++i) {
|
||||||
int k = keys[i * 2 + 1];
|
int k = keys[i * 2 + 1];
|
||||||
int v = keys[i * 2 + 2];
|
int v = keys[i * 2 + 2];
|
||||||
|
|
|
@ -48,13 +48,12 @@ static int read_seenspells(variant *var, void *owner, struct gamedata *data)
|
||||||
{
|
{
|
||||||
selist *ql = NULL;
|
selist *ql = NULL;
|
||||||
storage *store = data->store;
|
storage *store = data->store;
|
||||||
spell *sp = 0;
|
|
||||||
char token[32];
|
char token[32];
|
||||||
|
|
||||||
UNUSED_ARG(owner);
|
UNUSED_ARG(owner);
|
||||||
READ_TOK(store, token, sizeof(token));
|
READ_TOK(store, token, sizeof(token));
|
||||||
while (token[0]) {
|
while (token[0]) {
|
||||||
sp = find_spell(token);
|
spell *sp = find_spell(token);
|
||||||
if (!sp) {
|
if (!sp) {
|
||||||
log_info("read_seenspells: could not find spell '%s'\n", token);
|
log_info("read_seenspells: could not find spell '%s'\n", token);
|
||||||
return AT_READ_FAIL;
|
return AT_READ_FAIL;
|
||||||
|
|
|
@ -82,7 +82,7 @@ void autostudy_run(scholar scholars[], int nscholars)
|
||||||
int ti = 0;
|
int ti = 0;
|
||||||
while (ti != nscholars) {
|
while (ti != nscholars) {
|
||||||
skill_t sk = scholars[ti].sk;
|
skill_t sk = scholars[ti].sk;
|
||||||
int t, s, se, ts = 0, tt = 0, si = ti;
|
int t, se, ts = 0, tt = 0, si = ti;
|
||||||
for (se = ti; se != nscholars && scholars[se].sk == sk; ++se) {
|
for (se = ti; se != nscholars && scholars[se].sk == sk; ++se) {
|
||||||
int mint;
|
int mint;
|
||||||
ts += scholars[se].u->number; /* count total scholars */
|
ts += scholars[se].u->number; /* count total scholars */
|
||||||
|
@ -110,7 +110,7 @@ void autostudy_run(scholar scholars[], int nscholars)
|
||||||
/* invariant: unit ti can still teach i students */
|
/* invariant: unit ti can still teach i students */
|
||||||
int i = scholars[ti].u->number * STUDENTS_PER_TEACHER;
|
int i = scholars[ti].u->number * STUDENTS_PER_TEACHER;
|
||||||
/* invariant: unit si has n students that can still be taught */
|
/* invariant: unit si has n students that can still be taught */
|
||||||
int n = scholars[si].u->number;
|
int s, n = scholars[si].u->number;
|
||||||
for (t = ti, s = si; t != si && s != se; ) {
|
for (t = ti, s = si; t != si && s != se; ) {
|
||||||
if (i >= n) {
|
if (i >= n) {
|
||||||
/* t has more than enough teaching capacity for s */
|
/* t has more than enough teaching capacity for s */
|
||||||
|
|
83
src/battle.c
83
src/battle.c
|
@ -697,23 +697,20 @@ static int CavalryBonus(const unit * u, troop enemy, int type)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Effektiver Waffenskill waehrend des Kampfes.
|
||||||
|
*/
|
||||||
static int
|
static int
|
||||||
weapon_effskill(troop t, troop enemy, const weapon * w, bool attacking,
|
weapon_effskill(troop t, troop enemy, const weapon * w,
|
||||||
bool missile)
|
bool attacking, bool missile)
|
||||||
/* effektiver Waffenskill w<>hrend des Kampfes */
|
|
||||||
{
|
{
|
||||||
/* In dieser Runde alle die Modifier berechnen, die fig durch die
|
|
||||||
* Waffen bekommt. */
|
|
||||||
fighter *tf = t.fighter;
|
fighter *tf = t.fighter;
|
||||||
unit *tu = t.fighter->unit;
|
unit *tu = t.fighter->unit;
|
||||||
int skill;
|
/* Alle Modifier berechnen, die fig durch die Waffen bekommt. */
|
||||||
const weapon_type *wtype = w ? w->type : NULL;
|
if (w) {
|
||||||
|
int skill = 0;
|
||||||
|
const weapon_type *wtype = w->type;
|
||||||
|
|
||||||
if (wtype == NULL) {
|
|
||||||
/* Ohne Waffe: Waffenlose Angriffe */
|
|
||||||
skill = weapon_skill(NULL, tu, attacking);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (attacking) {
|
if (attacking) {
|
||||||
skill = w->attackskill;
|
skill = w->attackskill;
|
||||||
}
|
}
|
||||||
|
@ -745,30 +742,31 @@ bool missile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
/* Burgenbonus, Pferdebonus */
|
||||||
|
if (is_riding(t) && (wtype == NULL || (fval(wtype, WTF_HORSEBONUS)
|
||||||
|
&& !fval(wtype, WTF_MISSILE)))) {
|
||||||
|
skill += CavalryBonus(tu, enemy, BONUS_SKILL);
|
||||||
|
}
|
||||||
|
|
||||||
/* Burgenbonus, Pferdebonus */
|
if (t.index < tf->elvenhorses) {
|
||||||
if (is_riding(t) && (wtype == NULL || (fval(wtype, WTF_HORSEBONUS)
|
/* Elfenpferde: Helfen dem Reiter, egal ob und welche Waffe. Das ist
|
||||||
&& !fval(wtype, WTF_MISSILE)))) {
|
* eleganter, und vor allem einfacher, sonst mu<EFBFBD> man noch ein
|
||||||
skill += CavalryBonus(tu, enemy, BONUS_SKILL);
|
* WMF_ELVENHORSE einbauen. */
|
||||||
}
|
skill += 2;
|
||||||
|
}
|
||||||
|
|
||||||
if (t.index < tf->elvenhorses) {
|
if (skill > 0 && !attacking && missile) {
|
||||||
/* Elfenpferde: Helfen dem Reiter, egal ob und welche Waffe. Das ist
|
/*
|
||||||
* eleganter, und vor allem einfacher, sonst mu<EFBFBD> man noch ein
|
* Wenn ich verteidige, und nicht direkt meinem Feind gegen<EFBFBD>berstehe,
|
||||||
* WMF_ELVENHORSE einbauen. */
|
* halbiert sich mein Skill: (z.B. gegen Fernk<EFBFBD>mpfer. Nahk<EFBFBD>mpfer
|
||||||
skill += 2;
|
* k<EFBFBD>nnen mich eh nicht treffen)
|
||||||
|
*/
|
||||||
|
skill /= 2;
|
||||||
|
}
|
||||||
|
return skill;
|
||||||
}
|
}
|
||||||
|
/* no weapon: fight weaponless */
|
||||||
if (skill > 0 && !attacking && missile) {
|
return weapon_skill(NULL, tu, attacking);
|
||||||
/*
|
|
||||||
* Wenn ich verteidige, und nicht direkt meinem Feind gegen<EFBFBD>berstehe,
|
|
||||||
* halbiert sich mein Skill: (z.B. gegen Fernk<EFBFBD>mpfer. Nahk<EFBFBD>mpfer
|
|
||||||
* k<EFBFBD>nnen mich eh nicht treffen)
|
|
||||||
*/
|
|
||||||
skill /= 2;
|
|
||||||
}
|
|
||||||
return skill;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const armor_type *select_armor(troop t, bool shield)
|
const armor_type *select_armor(troop t, bool shield)
|
||||||
|
@ -1318,7 +1316,7 @@ terminate(troop dt, troop at, int type, const char *damage_formula, bool missile
|
||||||
++at.fighter->hits;
|
++at.fighter->hits;
|
||||||
|
|
||||||
calculate_attack_type(at, dt, type, missile, &awtype, &attskill, &magic);
|
calculate_attack_type(at, dt, type, missile, &awtype, &attskill, &magic);
|
||||||
calculate_defense_type(at, dt, type, missile, &awtype, &attskill);
|
calculate_defense_type(at, dt, type, missile, &dwtype, &defskill);
|
||||||
|
|
||||||
if (is_riding(at) && (awtype == NULL || (fval(awtype, WTF_HORSEBONUS)
|
if (is_riding(at) && (awtype == NULL || (fval(awtype, WTF_HORSEBONUS)
|
||||||
&& !fval(awtype, WTF_MISSILE)))) {
|
&& !fval(awtype, WTF_MISSILE)))) {
|
||||||
|
@ -3383,23 +3381,6 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack)
|
||||||
return fig;
|
return fig;
|
||||||
}
|
}
|
||||||
|
|
||||||
fighter * get_fighter(battle * b, const struct unit * u)
|
|
||||||
{
|
|
||||||
side * s;
|
|
||||||
|
|
||||||
for (s = b->sides; s != b->sides + b->nsides; ++s) {
|
|
||||||
fighter *fig;
|
|
||||||
if (s->faction == u->faction) {
|
|
||||||
for (fig = s->fighters; fig; fig = fig->next) {
|
|
||||||
if (fig->unit == u) {
|
|
||||||
return fig;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int join_battle(battle * b, unit * u, bool attack, fighter ** cp)
|
int join_battle(battle * b, unit * u, bool attack, fighter ** cp)
|
||||||
{
|
{
|
||||||
side *s;
|
side *s;
|
||||||
|
|
|
@ -213,7 +213,6 @@ extern "C" {
|
||||||
/* BEGIN battle interface */
|
/* BEGIN battle interface */
|
||||||
side * find_side(battle * b, const struct faction * f, const struct group * g, unsigned int flags, const struct faction * stealthfaction);
|
side * find_side(battle * b, const struct faction * f, const struct group * g, unsigned int flags, const struct faction * stealthfaction);
|
||||||
side * get_side(battle * b, const struct unit * u);
|
side * get_side(battle * b, const struct unit * u);
|
||||||
fighter * get_fighter(battle * b, const struct unit * u);
|
|
||||||
/* END battle interface */
|
/* END battle interface */
|
||||||
|
|
||||||
void do_battles(void);
|
void do_battles(void);
|
||||||
|
|
|
@ -123,6 +123,16 @@ static void test_select_weapon_restricted(CuTest *tc) {
|
||||||
CuAssertIntEquals(tc, 0, af->weapons[0].count);
|
CuAssertIntEquals(tc, 0, af->weapons[0].count);
|
||||||
free_battle(b);
|
free_battle(b);
|
||||||
|
|
||||||
|
itype->mask_deny = 0;
|
||||||
|
itype->mask_allow = rc_mask(au->_race);
|
||||||
|
b = make_battle(au->region);
|
||||||
|
af = make_fighter(b, au, make_side(b, au->faction, 0, 0, 0), false);
|
||||||
|
CuAssertPtrNotNull(tc, af->weapons);
|
||||||
|
CuAssertIntEquals(tc, 1, af->weapons[0].count);
|
||||||
|
CuAssertPtrEquals(tc, itype->rtype->wtype, (void *)af->weapons[0].type);
|
||||||
|
CuAssertIntEquals(tc, 0, af->weapons[1].count);
|
||||||
|
free_battle(b);
|
||||||
|
|
||||||
itype->mask_deny = 0;
|
itype->mask_deny = 0;
|
||||||
itype->mask_allow = rc_mask(rc);
|
itype->mask_allow = rc_mask(rc);
|
||||||
b = make_battle(au->region);
|
b = make_battle(au->region);
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
#include "kernel/skills.h"
|
#include "kernel/skills.h"
|
||||||
#include "kernel/types.h"
|
#include "kernel/types.h"
|
||||||
#include <kernel/building.h>
|
#include <kernel/building.h>
|
||||||
#include <kernel/config.h>
|
|
||||||
#include <kernel/curse.h>
|
#include <kernel/curse.h>
|
||||||
#include "kernel/equipment.h"
|
#include "kernel/equipment.h"
|
||||||
#include <kernel/faction.h>
|
#include <kernel/faction.h>
|
||||||
|
@ -432,38 +431,11 @@ static int tolua_unit_effskill(lua_State * L)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct fctr_data {
|
|
||||||
unit *target;
|
|
||||||
int fhandle;
|
|
||||||
} fctr_data;
|
|
||||||
|
|
||||||
typedef struct event {
|
typedef struct event {
|
||||||
struct event_arg *args;
|
struct event_arg *args;
|
||||||
char *msg;
|
char *msg;
|
||||||
} event;
|
} event;
|
||||||
|
|
||||||
int fctr_handle(struct trigger *tp, void *data)
|
|
||||||
{
|
|
||||||
trigger *t = tp;
|
|
||||||
event evt = { 0 };
|
|
||||||
fctr_data *fd = (fctr_data *)t->data.v;
|
|
||||||
lua_State *L = (lua_State *)global.vm_state;
|
|
||||||
unit *u = fd->target;
|
|
||||||
|
|
||||||
evt.args = (event_arg *)data;
|
|
||||||
lua_rawgeti(L, LUA_REGISTRYINDEX, fd->fhandle);
|
|
||||||
tolua_pushusertype(L, u, TOLUA_CAST "unit");
|
|
||||||
tolua_pushusertype(L, &evt, TOLUA_CAST "event");
|
|
||||||
if (lua_pcall(L, 2, 0, 0) != 0) {
|
|
||||||
const char *error = lua_tostring(L, -1);
|
|
||||||
log_error("event (%s): %s\n", unitname(u), error);
|
|
||||||
lua_pop(L, 1);
|
|
||||||
tolua_error(L, TOLUA_CAST "event handler call failed", NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int tolua_unit_addnotice(lua_State * L)
|
static int tolua_unit_addnotice(lua_State * L)
|
||||||
{
|
{
|
||||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include "creport.h"
|
#include "creport.h"
|
||||||
#include "report.h"
|
#include "report.h"
|
||||||
#include "names.h"
|
#include "names.h"
|
||||||
|
#include "prefix.h"
|
||||||
#include "reports.h"
|
#include "reports.h"
|
||||||
#include "spells.h"
|
#include "spells.h"
|
||||||
#include "vortex.h"
|
#include "vortex.h"
|
||||||
|
@ -50,9 +51,10 @@ void game_done(void)
|
||||||
calendar_cleanup();
|
calendar_cleanup();
|
||||||
free_functions();
|
free_functions();
|
||||||
free_config();
|
free_config();
|
||||||
free_special_directions();
|
|
||||||
free_locales();
|
free_locales();
|
||||||
#endif
|
#endif
|
||||||
|
free_prefixes();
|
||||||
|
free_special_directions();
|
||||||
kernel_done();
|
kernel_done();
|
||||||
swapdb_close();
|
swapdb_close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,90 +0,0 @@
|
||||||
#include "reports.h"
|
|
||||||
#include "jsreport.h"
|
|
||||||
#include <kernel/faction.h>
|
|
||||||
#include <kernel/region.h>
|
|
||||||
#include <kernel/terrain.h>
|
|
||||||
#include <kernel/terrainid.h>
|
|
||||||
#include <kernel/config.h>
|
|
||||||
|
|
||||||
#include <util/log.h>
|
|
||||||
|
|
||||||
#include <limits.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
static void coor_to_tiled(int *x, int *y) {
|
|
||||||
*y = -*y;
|
|
||||||
*x = *x - (*y + 1) / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void coor_from_tiled(int *x, int *y) {
|
|
||||||
*x = *x + (*y + 1) / 2;
|
|
||||||
*y = -*y;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int report_json(const char *filename, report_context * ctx, const char *charset)
|
|
||||||
{
|
|
||||||
if (config_get_int("jsreport.enabled", 0) != 0) {
|
|
||||||
FILE * F = fopen(filename, "w");
|
|
||||||
if (F) {
|
|
||||||
int minx = INT_MAX, maxx = INT_MIN, miny = INT_MAX, maxy = INT_MIN;
|
|
||||||
seen_region *sr;
|
|
||||||
region *r;
|
|
||||||
/* traverse all regions */
|
|
||||||
for (sr = NULL, r = ctx->first; sr == NULL && r != ctx->last; r = r->next) {
|
|
||||||
sr = find_seen(ctx->f->seen, r);
|
|
||||||
}
|
|
||||||
for (; sr != NULL; sr = sr->next) {
|
|
||||||
int tx = sr->r->x;
|
|
||||||
int ty = sr->r->y;
|
|
||||||
coor_to_tiled(&tx, &ty);
|
|
||||||
if (ty < miny) miny = ty;
|
|
||||||
else if (ty > maxy) maxy = ty;
|
|
||||||
if (tx < minx) minx = tx;
|
|
||||||
else if (tx > maxx) maxx = tx;
|
|
||||||
}
|
|
||||||
if (maxx >= minx && maxy >= miny) {
|
|
||||||
int y, w = maxx - minx + 1, h = maxy - miny + 1;
|
|
||||||
fputs("{ \"orientation\":\"hexagonal\",\"staggeraxis\":\"y\",", F);
|
|
||||||
fprintf(F, "\"staggerindex\":\"%s\", \"height\":%d, \"width\":%d, \"layers\":[", (miny & 1) ? "odd" : "even", h, w);
|
|
||||||
fprintf(F, "{ \"height\":%d, \"width\":%d, ", h, w);
|
|
||||||
fputs("\"visible\":true, \"opacity\":1, \"type\":\"tilelayer\", \"name\":\"terrain\", \"x\":0, \"y\":0, \"data\":[", F);
|
|
||||||
for (y = miny; y <= maxy; ++y) {
|
|
||||||
int x;
|
|
||||||
for (x = minx; x <= maxx; ++x) {
|
|
||||||
int data = 0;
|
|
||||||
int tx = x, ty = y;
|
|
||||||
coor_from_tiled(&tx, &ty);
|
|
||||||
r = findregion(tx, ty);
|
|
||||||
if (r) {
|
|
||||||
sr = find_seen(ctx->f->seen, r);
|
|
||||||
if (sr) {
|
|
||||||
terrain_t ter = oldterrain(r->terrain);
|
|
||||||
if (ter == NOTERRAIN) {
|
|
||||||
data = 1 + r->terrain->_name[0];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
data = 1 + (int)ter;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fprintf(F, "%d", data);
|
|
||||||
if (x != maxx || y != maxy) fputs(", ", F);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fputs("]}], \"tilesets\": [{\"firstgid\": 1, \"image\": \"magellan.png\", \"imageheight\": 192, \"imagewidth\": 256,"
|
|
||||||
"\"margin\": 0, \"name\": \"hextiles\", \"properties\": { }, \"spacing\": 0, "
|
|
||||||
"\"tileheight\" : 64, \"tilewidth\" : 64 }], \"tilewidth\": 64, \"tileheight\": 96}", F);
|
|
||||||
}
|
|
||||||
fclose(F);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void register_jsreport(void)
|
|
||||||
{
|
|
||||||
register_reporttype("json", &report_json, 1 << O_JSON);
|
|
||||||
}
|
|
|
@ -1,24 +0,0 @@
|
||||||
#pragma once
|
|
||||||
/*
|
|
||||||
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
|
|
||||||
| | Enno Rehling <enno@eressea.de>
|
|
||||||
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
|
|
||||||
| (c) 1998 - 2003 | Henning Peters <faroul@beyond.kn-bremen.de>
|
|
||||||
| | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de>
|
|
||||||
+-------------------+ Stefan Reich <reich@halbling.de>
|
|
||||||
|
|
||||||
This program may not be used, modified or distributed
|
|
||||||
without prior permission by the authors of Eressea.
|
|
||||||
*/
|
|
||||||
#ifndef H_GC_JSREPORT
|
|
||||||
#define H_GC_JSREPORT
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void register_jsreport(void);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#endif
|
|
|
@ -106,27 +106,31 @@ int findoption(const char *s, const struct locale *lang)
|
||||||
|
|
||||||
/* -- Erschaffung neuer Einheiten ------------------------------ */
|
/* -- Erschaffung neuer Einheiten ------------------------------ */
|
||||||
|
|
||||||
static const char *forbidden[] = { "t", "te", "tem", "temp", NULL };
|
|
||||||
static int *forbidden_ids;
|
static int *forbidden_ids;
|
||||||
|
|
||||||
int forbiddenid(int id)
|
bool forbiddenid(int id)
|
||||||
{
|
{
|
||||||
|
static const char *forbidden[] = { "t", "te", "tem", "temp", NULL };
|
||||||
static size_t len;
|
static size_t len;
|
||||||
size_t i;
|
size_t i;
|
||||||
if (id <= 0)
|
if (id <= 0) {
|
||||||
return 1;
|
return true;
|
||||||
|
}
|
||||||
if (!forbidden_ids) {
|
if (!forbidden_ids) {
|
||||||
while (forbidden[len])
|
while (forbidden[len])
|
||||||
++len;
|
++len;
|
||||||
forbidden_ids = calloc(len, sizeof(int));
|
forbidden_ids = malloc(len * sizeof(int));
|
||||||
|
if (!forbidden_ids) abort();
|
||||||
for (i = 0; i != len; ++i) {
|
for (i = 0; i != len; ++i) {
|
||||||
forbidden_ids[i] = atoi36(forbidden[i]);
|
forbidden_ids[i] = atoi36(forbidden[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (i = 0; i != len; ++i)
|
for (i = 0; i != len; ++i) {
|
||||||
if (id == forbidden_ids[i])
|
if (id == forbidden_ids[i]) {
|
||||||
return 1;
|
return true;
|
||||||
return 0;
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int newcontainerid(void)
|
int newcontainerid(void)
|
||||||
|
@ -274,6 +278,7 @@ void set_param(struct param **p, const char *key, const char *value)
|
||||||
par = *p;
|
par = *p;
|
||||||
if (!par && value) {
|
if (!par && value) {
|
||||||
*p = par = calloc(1, sizeof(param));
|
*p = par = calloc(1, sizeof(param));
|
||||||
|
if (!par) abort();
|
||||||
}
|
}
|
||||||
if (par) {
|
if (par) {
|
||||||
void *match;
|
void *match;
|
||||||
|
@ -509,7 +514,6 @@ order *default_order(const struct locale *lang)
|
||||||
int i = locale_index(lang);
|
int i = locale_index(lang);
|
||||||
keyword_t kwd;
|
keyword_t kwd;
|
||||||
const char * str;
|
const char * str;
|
||||||
order *result = 0;
|
|
||||||
|
|
||||||
assert(i < MAXLOCALES);
|
assert(i < MAXLOCALES);
|
||||||
kwd = keyword_disabled(K_WORK) ? NOKEYWORD : K_WORK;
|
kwd = keyword_disabled(K_WORK) ? NOKEYWORD : K_WORK;
|
||||||
|
@ -518,7 +522,8 @@ order *default_order(const struct locale *lang)
|
||||||
kwd = findkeyword(str);
|
kwd = findkeyword(str);
|
||||||
}
|
}
|
||||||
if (kwd != NOKEYWORD) {
|
if (kwd != NOKEYWORD) {
|
||||||
result = create_order(kwd, lang, NULL);
|
/* TODO: why is there a copy_order made here? */
|
||||||
|
order *result = create_order(kwd, lang, NULL);
|
||||||
return copy_order(result);
|
return copy_order(result);
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -52,7 +52,7 @@ extern "C" {
|
||||||
void init_locale(struct locale *lang);
|
void init_locale(struct locale *lang);
|
||||||
void init_races(struct locale *lang);
|
void init_races(struct locale *lang);
|
||||||
|
|
||||||
int forbiddenid(int id);
|
bool forbiddenid(int id);
|
||||||
int newcontainerid(void);
|
int newcontainerid(void);
|
||||||
|
|
||||||
bool rule_region_owners(void);
|
bool rule_region_owners(void);
|
||||||
|
|
|
@ -672,16 +672,6 @@ bool curse_active(const curse * c)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_cursed_internal(attrib * ap, const curse_type * ct)
|
|
||||||
{
|
|
||||||
curse *c = get_curse(ap, ct);
|
|
||||||
|
|
||||||
if (!c)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool is_cursed_with(const attrib * ap, const curse * c)
|
bool is_cursed_with(const attrib * ap, const curse * c)
|
||||||
{
|
{
|
||||||
const attrib *a = ap;
|
const attrib *a = ap;
|
||||||
|
|
|
@ -168,28 +168,6 @@ void set_show_item(faction * f, const struct item_type *itype)
|
||||||
a->data.v = (void *)itype;
|
a->data.v = (void *)itype;
|
||||||
}
|
}
|
||||||
|
|
||||||
const unit *random_unit_in_faction(const faction * f)
|
|
||||||
{
|
|
||||||
unit *u;
|
|
||||||
int c = 0, u_nr;
|
|
||||||
|
|
||||||
if (!f->units) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
for (u = f->units; u; u = u->next)
|
|
||||||
c++;
|
|
||||||
|
|
||||||
u_nr = rng_int() % c;
|
|
||||||
c = 0;
|
|
||||||
|
|
||||||
for (u = f->units; u; u = u->next)
|
|
||||||
if (u_nr == c)
|
|
||||||
return u;
|
|
||||||
|
|
||||||
/* Hier sollte er nie ankommen */
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *factionname(const faction * f)
|
const char *factionname(const faction * f)
|
||||||
{
|
{
|
||||||
typedef char name[OBJECTIDSIZE + 1];
|
typedef char name[OBJECTIDSIZE + 1];
|
||||||
|
|
|
@ -117,7 +117,6 @@ extern "C" {
|
||||||
int max_magicians(const faction * f);
|
int max_magicians(const faction * f);
|
||||||
void set_show_item(faction * f, const struct item_type *itype);
|
void set_show_item(faction * f, const struct item_type *itype);
|
||||||
|
|
||||||
const struct unit *random_unit_in_faction(const struct faction *f);
|
|
||||||
const char *factionname(const struct faction *f);
|
const char *factionname(const struct faction *f);
|
||||||
struct unit *addplayer(struct region *r, faction * f);
|
struct unit *addplayer(struct region *r, faction * f);
|
||||||
struct faction *addfaction(const char *email, const char *password,
|
struct faction *addfaction(const char *email, const char *password,
|
||||||
|
|
|
@ -194,12 +194,10 @@ resource_type *rt_get_or_create(const char *name) {
|
||||||
if (!rtype) {
|
if (!rtype) {
|
||||||
rtype = calloc(1, sizeof(resource_type));
|
rtype = calloc(1, sizeof(resource_type));
|
||||||
if (!rtype) {
|
if (!rtype) {
|
||||||
perror("resource_type allocation failed");
|
abort();
|
||||||
}
|
|
||||||
else {
|
|
||||||
rtype->_name = str_strdup(name);
|
|
||||||
rt_register(rtype);
|
|
||||||
}
|
}
|
||||||
|
rtype->_name = str_strdup(name);
|
||||||
|
rt_register(rtype);
|
||||||
}
|
}
|
||||||
return rtype;
|
return rtype;
|
||||||
}
|
}
|
||||||
|
@ -247,6 +245,7 @@ item_type *it_get_or_create(resource_type *rtype) {
|
||||||
if (!rtype->itype) {
|
if (!rtype->itype) {
|
||||||
item_type * itype;
|
item_type * itype;
|
||||||
itype = (item_type *)calloc(sizeof(item_type), 1);
|
itype = (item_type *)calloc(sizeof(item_type), 1);
|
||||||
|
if (!itype) abort();
|
||||||
itype->rtype = rtype;
|
itype->rtype = rtype;
|
||||||
rtype->uchange = res_changeitem;
|
rtype->uchange = res_changeitem;
|
||||||
rtype->itype = itype;
|
rtype->itype = itype;
|
||||||
|
@ -269,6 +268,7 @@ luxury_type *new_luxurytype(item_type * itype, int price)
|
||||||
assert(resource2luxury(itype->rtype) == NULL);
|
assert(resource2luxury(itype->rtype) == NULL);
|
||||||
|
|
||||||
ltype = calloc(sizeof(luxury_type), 1);
|
ltype = calloc(sizeof(luxury_type), 1);
|
||||||
|
if (!ltype) abort();
|
||||||
ltype->itype = itype;
|
ltype->itype = itype;
|
||||||
ltype->price = price;
|
ltype->price = price;
|
||||||
lt_register(ltype);
|
lt_register(ltype);
|
||||||
|
@ -285,6 +285,7 @@ weapon_type *new_weapontype(item_type * itype,
|
||||||
assert(itype && (!itype->rtype || !resource2weapon(itype->rtype)));
|
assert(itype && (!itype->rtype || !resource2weapon(itype->rtype)));
|
||||||
|
|
||||||
wtype = calloc(sizeof(weapon_type), 1);
|
wtype = calloc(sizeof(weapon_type), 1);
|
||||||
|
if (!wtype) abort();
|
||||||
if (damage) {
|
if (damage) {
|
||||||
wtype->damage[0] = str_strdup(damage[0]);
|
wtype->damage[0] = str_strdup(damage[0]);
|
||||||
wtype->damage[1] = str_strdup(damage[1]);
|
wtype->damage[1] = str_strdup(damage[1]);
|
||||||
|
@ -309,6 +310,7 @@ armor_type *new_armortype(item_type * itype, double penalty, variant magres,
|
||||||
assert(itype->rtype->atype == NULL);
|
assert(itype->rtype->atype == NULL);
|
||||||
|
|
||||||
atype = calloc(sizeof(armor_type), 1);
|
atype = calloc(sizeof(armor_type), 1);
|
||||||
|
if (!atype) abort();
|
||||||
|
|
||||||
atype->itype = itype;
|
atype->itype = itype;
|
||||||
atype->penalty = penalty;
|
atype->penalty = penalty;
|
||||||
|
@ -530,6 +532,7 @@ item *i_new(const item_type * itype, int size)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
i = malloc(sizeof(item));
|
i = malloc(sizeof(item));
|
||||||
|
if (!i) abort();
|
||||||
}
|
}
|
||||||
assert(itype);
|
assert(itype);
|
||||||
i->next = NULL;
|
i->next = NULL;
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include "messages.h"
|
#include "messages.h"
|
||||||
|
|
||||||
#include "unit.h"
|
#include "unit.h"
|
||||||
|
#include "faction.h"
|
||||||
#include "order.h"
|
#include "order.h"
|
||||||
|
|
||||||
#include <CuTest.h>
|
#include <CuTest.h>
|
||||||
|
@ -25,10 +26,13 @@ void test_missing_message(CuTest *tc) {
|
||||||
|
|
||||||
void test_missing_feedback(CuTest *tc) {
|
void test_missing_feedback(CuTest *tc) {
|
||||||
message *msg;
|
message *msg;
|
||||||
|
unit *u;
|
||||||
|
|
||||||
test_setup();
|
test_setup();
|
||||||
|
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||||
|
u->thisorder = create_order(K_ENTERTAIN, u->faction->locale, NULL);
|
||||||
message_handle_missing(MESSAGE_MISSING_REPLACE);
|
message_handle_missing(MESSAGE_MISSING_REPLACE);
|
||||||
msg = msg_error(NULL, NULL, 77);
|
msg = msg_error(u, NULL, 77);
|
||||||
CuAssertPtrNotNull(tc, msg);
|
CuAssertPtrNotNull(tc, msg);
|
||||||
CuAssertPtrNotNull(tc, msg->type);
|
CuAssertPtrNotNull(tc, msg->type);
|
||||||
CuAssertStrEquals(tc, msg->type->name, "missing_feedback");
|
CuAssertStrEquals(tc, msg->type->name, "missing_feedback");
|
||||||
|
@ -113,6 +117,7 @@ static void test_noerror(CuTest *tc) {
|
||||||
CuSuite *get_messages_suite(void) {
|
CuSuite *get_messages_suite(void) {
|
||||||
CuSuite *suite = CuSuiteNew();
|
CuSuite *suite = CuSuiteNew();
|
||||||
SUITE_ADD_TEST(suite, test_missing_message);
|
SUITE_ADD_TEST(suite, test_missing_message);
|
||||||
|
SUITE_ADD_TEST(suite, test_missing_feedback);
|
||||||
SUITE_ADD_TEST(suite, test_merge_split);
|
SUITE_ADD_TEST(suite, test_merge_split);
|
||||||
SUITE_ADD_TEST(suite, test_message);
|
SUITE_ADD_TEST(suite, test_message);
|
||||||
SUITE_ADD_TEST(suite, test_noerror);
|
SUITE_ADD_TEST(suite, test_noerror);
|
||||||
|
|
|
@ -240,15 +240,6 @@ race_list *get_familiarraces(void)
|
||||||
return familiarraces;
|
return familiarraces;
|
||||||
}
|
}
|
||||||
|
|
||||||
void racelist_clear(struct race_list **rl)
|
|
||||||
{
|
|
||||||
while (*rl) {
|
|
||||||
race_list *rl2 = (*rl)->next;
|
|
||||||
free(*rl);
|
|
||||||
*rl = rl2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void racelist_insert(struct race_list **rl, const struct race *r)
|
void racelist_insert(struct race_list **rl, const struct race *r)
|
||||||
{
|
{
|
||||||
race_list *rl2 = (race_list *)malloc(sizeof(race_list));
|
race_list *rl2 = (race_list *)malloc(sizeof(race_list));
|
||||||
|
|
|
@ -67,7 +67,6 @@ bool terrain_changed(int *cache) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void free_terrains(void)
|
void free_terrains(void)
|
||||||
{
|
{
|
||||||
while (registered_terrains) {
|
while (registered_terrains) {
|
||||||
|
|
43
src/laws.c
43
src/laws.c
|
@ -2088,34 +2088,33 @@ int email_cmd(unit * u, struct order *ord)
|
||||||
|
|
||||||
int password_cmd(unit * u, struct order *ord)
|
int password_cmd(unit * u, struct order *ord)
|
||||||
{
|
{
|
||||||
char pwbuf[32];
|
char pwbuf[PASSWORD_MAXSIZE + 1];
|
||||||
const char *s;
|
const char *s;
|
||||||
bool pwok = true;
|
|
||||||
|
|
||||||
init_order_depr(ord);
|
init_order_depr(ord);
|
||||||
|
pwbuf[PASSWORD_MAXSIZE] = '\n';
|
||||||
s = gettoken(pwbuf, sizeof(pwbuf));
|
s = gettoken(pwbuf, sizeof(pwbuf));
|
||||||
|
if (pwbuf[PASSWORD_MAXSIZE] == '\0') {
|
||||||
if (!s || !*s) {
|
cmistake(u, ord, 321, MSG_EVENT);
|
||||||
int i;
|
pwbuf[PASSWORD_MAXSIZE - 1] = '\0';
|
||||||
for (i = 0; i < 6; i++)
|
|
||||||
pwbuf[i] = (char)(97 + rng_int() % 26);
|
|
||||||
pwbuf[6] = 0;
|
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
char *c;
|
if (s && *s) {
|
||||||
for (c = pwbuf; *c && pwok; ++c) {
|
unsigned char *c = (unsigned char *)pwbuf;
|
||||||
if (!isalnum(*(unsigned char *)c)) {
|
int i, r = 0;
|
||||||
pwok = false;
|
|
||||||
|
for (i = 0; c[i] && i != PASSWORD_MAXSIZE; ++i) {
|
||||||
|
if (!isalnum(c[i])) {
|
||||||
|
c[i] = 'X';
|
||||||
|
++r;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if (r != 0) {
|
||||||
if (!pwok) {
|
cmistake(u, ord, 283, MSG_EVENT);
|
||||||
cmistake(u, ord, 283, MSG_EVENT);
|
}
|
||||||
str_strlcpy(pwbuf, itoa36(rng_int()), sizeof(pwbuf));
|
|
||||||
}
|
}
|
||||||
faction_setpassword(u->faction, password_hash(pwbuf, PASSWORD_DEFAULT));
|
faction_setpassword(u->faction, password_hash(pwbuf, PASSWORD_DEFAULT));
|
||||||
ADDMSG(&u->faction->msgs, msg_message("changepasswd",
|
ADDMSG(&u->faction->msgs, msg_message("changepasswd", "value", pwbuf));
|
||||||
"value", pwbuf));
|
|
||||||
u->faction->flags |= FFL_PWMSG;
|
u->faction->flags |= FFL_PWMSG;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -3339,7 +3338,6 @@ int pay_cmd(unit * u, struct order *ord)
|
||||||
cmistake(u, ord, 6, MSG_EVENT);
|
cmistake(u, ord, 6, MSG_EVENT);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
building *b = NULL;
|
|
||||||
param_t p;
|
param_t p;
|
||||||
int id;
|
int id;
|
||||||
|
|
||||||
|
@ -3355,13 +3353,12 @@ int pay_cmd(unit * u, struct order *ord)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* If no building id is given or it is the id of our building, just set the do-not-pay flag */
|
/* If no building id is given or it is the id of our building, just set the do-not-pay flag */
|
||||||
if (id == 0 || id == u->building->no)
|
if (id == 0 || id == u->building->no) {
|
||||||
{
|
|
||||||
u->building->flags |= BLD_DONTPAY;
|
u->building->flags |= BLD_DONTPAY;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* Find the building that matches to the given id*/
|
/* Find the building that matches to the given id*/
|
||||||
b = findbuilding(id);
|
building *b = findbuilding(id);
|
||||||
/* If there is a building and it is in the same region as the unit continue, else: error */
|
/* If there is a building and it is in the same region as the unit continue, else: error */
|
||||||
if (b && b->region == u->region)
|
if (b && b->region == u->region)
|
||||||
{
|
{
|
||||||
|
|
|
@ -48,6 +48,37 @@ static void test_new_building_can_be_renamed(CuTest * tc)
|
||||||
test_teardown();
|
test_teardown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_password_cmd(CuTest * tc)
|
||||||
|
{
|
||||||
|
unit *u;
|
||||||
|
faction * f;
|
||||||
|
test_setup();
|
||||||
|
u = test_create_unit(f = test_create_faction(NULL), test_create_plain(0, 0));
|
||||||
|
|
||||||
|
u->thisorder = create_order(K_PASSWORD, f->locale, "abcdefgh");
|
||||||
|
password_cmd(u, u->thisorder);
|
||||||
|
CuAssertPtrNotNull(tc, faction_getpassword(f));
|
||||||
|
CuAssertTrue(tc, checkpasswd(f, "abcdefgh"));
|
||||||
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "changepasswd"));
|
||||||
|
free_order(u->thisorder);
|
||||||
|
|
||||||
|
u->thisorder = create_order(K_PASSWORD, f->locale, "abc*de*");
|
||||||
|
password_cmd(u, u->thisorder);
|
||||||
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error283"));
|
||||||
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "changepasswd"));
|
||||||
|
CuAssertTrue(tc, !checkpasswd(f, "abc*de*"));
|
||||||
|
CuAssertTrue(tc, checkpasswd(f, "abcXdeX"));
|
||||||
|
free_order(u->thisorder);
|
||||||
|
|
||||||
|
u->thisorder = create_order(K_PASSWORD, f->locale, "1234567890123456789012345678901234567890");
|
||||||
|
password_cmd(u, u->thisorder);
|
||||||
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error321"));
|
||||||
|
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "changepasswd"));
|
||||||
|
CuAssertTrue(tc, checkpasswd(f, "1234567890123456789012345678901"));
|
||||||
|
|
||||||
|
test_teardown();
|
||||||
|
}
|
||||||
|
|
||||||
static void test_rename_building(CuTest * tc)
|
static void test_rename_building(CuTest * tc)
|
||||||
{
|
{
|
||||||
region *r;
|
region *r;
|
||||||
|
@ -1831,6 +1862,7 @@ CuSuite *get_laws_suite(void)
|
||||||
SUITE_ADD_TEST(suite, test_long_order_buy_cast);
|
SUITE_ADD_TEST(suite, test_long_order_buy_cast);
|
||||||
SUITE_ADD_TEST(suite, test_long_order_hungry);
|
SUITE_ADD_TEST(suite, test_long_order_hungry);
|
||||||
SUITE_ADD_TEST(suite, test_new_building_can_be_renamed);
|
SUITE_ADD_TEST(suite, test_new_building_can_be_renamed);
|
||||||
|
SUITE_ADD_TEST(suite, test_password_cmd);
|
||||||
SUITE_ADD_TEST(suite, test_rename_building);
|
SUITE_ADD_TEST(suite, test_rename_building);
|
||||||
SUITE_ADD_TEST(suite, test_rename_building_twice);
|
SUITE_ADD_TEST(suite, test_rename_building_twice);
|
||||||
SUITE_ADD_TEST(suite, test_fishing_feeds_2_people);
|
SUITE_ADD_TEST(suite, test_fishing_feeds_2_people);
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include "util/filereader.h"
|
#include "util/filereader.h"
|
||||||
#include "util/param.h"
|
#include "util/param.h"
|
||||||
#include "util/parser.h"
|
#include "util/parser.h"
|
||||||
|
#include "util/password.h"
|
||||||
#include "util/order_parser.h"
|
#include "util/order_parser.h"
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
@ -22,7 +23,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
static void begin_orders(unit *u) {
|
static void begin_orders(unit *u) {
|
||||||
if (u->flags & UFL_ORDERS) {
|
if ((u->flags & UFL_ORDERS) == 0) {
|
||||||
order **ordp;
|
order **ordp;
|
||||||
/* alle wiederholbaren, langen befehle werden gesichert: */
|
/* alle wiederholbaren, langen befehle werden gesichert: */
|
||||||
u->flags |= UFL_ORDERS;
|
u->flags |= UFL_ORDERS;
|
||||||
|
@ -47,13 +48,12 @@ static void begin_orders(unit *u) {
|
||||||
u->orders = NULL;
|
u->orders = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unit *unitorders(input *in, faction *f)
|
static void unitorders(input *in, faction *f)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
unit *u;
|
unit *u;
|
||||||
|
|
||||||
if (!f)
|
assert(f);
|
||||||
return NULL;
|
|
||||||
|
|
||||||
i = getid();
|
i = getid();
|
||||||
u = findunit(i);
|
u = findunit(i);
|
||||||
|
@ -120,10 +120,6 @@ static unit *unitorders(input *in, faction *f)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return u;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static faction *factionorders(void)
|
static faction *factionorders(void)
|
||||||
|
@ -132,7 +128,7 @@ static faction *factionorders(void)
|
||||||
faction *f = findfaction(fid);
|
faction *f = findfaction(fid);
|
||||||
|
|
||||||
if (f != NULL && (f->flags & FFL_NPC) == 0) {
|
if (f != NULL && (f->flags & FFL_NPC) == 0) {
|
||||||
char token[128];
|
char token[PASSWORD_MAXSIZE];
|
||||||
const char *pass = gettoken(token, sizeof(token));
|
const char *pass = gettoken(token, sizeof(token));
|
||||||
|
|
||||||
if (!checkpasswd(f, (const char *)pass)) {
|
if (!checkpasswd(f, (const char *)pass)) {
|
||||||
|
@ -189,7 +185,8 @@ int read_orders(input *in)
|
||||||
* vermerkt. */
|
* vermerkt. */
|
||||||
|
|
||||||
case P_UNIT:
|
case P_UNIT:
|
||||||
if (!f || !unitorders(in, f)) {
|
if (f) {
|
||||||
|
unitorders(in, f);
|
||||||
do {
|
do {
|
||||||
b = in->getbuf(in->data);
|
b = in->getbuf(in->data);
|
||||||
if (!b) {
|
if (!b) {
|
||||||
|
@ -278,7 +275,7 @@ static void handle_unit(void *userData, int no) {
|
||||||
static void handle_order(void *userData, const char *str) {
|
static void handle_order(void *userData, const char *str) {
|
||||||
parser_state *state = (parser_state *)userData;
|
parser_state *state = (parser_state *)userData;
|
||||||
const char * tok, *input = str;
|
const char * tok, *input = str;
|
||||||
char buffer[16];
|
char buffer[64];
|
||||||
const struct locale *lang;
|
const struct locale *lang;
|
||||||
param_t p;
|
param_t p;
|
||||||
faction * f = state->f;
|
faction * f = state->f;
|
||||||
|
|
|
@ -3,9 +3,20 @@
|
||||||
|
|
||||||
#include "orderfile.h"
|
#include "orderfile.h"
|
||||||
|
|
||||||
|
#include "direction.h"
|
||||||
|
|
||||||
#include <kernel/calendar.h>
|
#include <kernel/calendar.h>
|
||||||
#include <kernel/faction.h>
|
#include <kernel/faction.h>
|
||||||
|
#include <kernel/order.h>
|
||||||
|
#include <kernel/unit.h>
|
||||||
|
|
||||||
|
#include <util/base36.h>
|
||||||
|
#include <util/keyword.h>
|
||||||
|
#include <util/language.h>
|
||||||
|
#include <util/lists.h>
|
||||||
#include <util/message.h>
|
#include <util/message.h>
|
||||||
|
#include <util/param.h>
|
||||||
|
#include <util/password.h>
|
||||||
|
|
||||||
#include <CuTest.h>
|
#include <CuTest.h>
|
||||||
#include <tests.h>
|
#include <tests.h>
|
||||||
|
@ -24,6 +35,52 @@ static void test_read_orders(CuTest *tc) {
|
||||||
test_teardown();
|
test_teardown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char *getbuf_strings(void *data)
|
||||||
|
{
|
||||||
|
strlist **listp = (strlist **)data;
|
||||||
|
if (listp && *listp) {
|
||||||
|
strlist *list = *listp;
|
||||||
|
*listp = list->next;
|
||||||
|
return list->s;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_unit_orders(CuTest *tc) {
|
||||||
|
input in;
|
||||||
|
unit *u;
|
||||||
|
faction *f;
|
||||||
|
strlist *orders = NULL, *backup;
|
||||||
|
char buf[64];
|
||||||
|
|
||||||
|
test_setup();
|
||||||
|
u = test_create_unit(f = test_create_faction(NULL), test_create_plain(0, 0));
|
||||||
|
f->locale = test_create_locale();
|
||||||
|
u->orders = create_order(K_ENTERTAIN, f->locale, NULL);
|
||||||
|
faction_setpassword(f, password_hash("password", PASSWORD_DEFAULT));
|
||||||
|
snprintf(buf, sizeof(buf), "%s %s %s",
|
||||||
|
LOC(f->locale, parameters[P_FACTION]), itoa36(f->no), "password");
|
||||||
|
addstrlist(&orders, buf);
|
||||||
|
snprintf(buf, sizeof(buf), "%s %s",
|
||||||
|
LOC(f->locale, parameters[P_UNIT]), itoa36(u->no));
|
||||||
|
addstrlist(&orders, buf);
|
||||||
|
snprintf(buf, sizeof(buf), "%s %s", keyword_name(K_MOVE, f->locale),
|
||||||
|
LOC(f->locale, shortdirections[D_WEST]));
|
||||||
|
backup = orders;
|
||||||
|
addstrlist(&orders, buf);
|
||||||
|
in.data = &orders;
|
||||||
|
in.getbuf = getbuf_strings;
|
||||||
|
CuAssertIntEquals(tc, 0, read_orders(&in));
|
||||||
|
CuAssertPtrNotNull(tc, u->old_orders);
|
||||||
|
CuAssertPtrNotNull(tc, u->orders);
|
||||||
|
CuAssertPtrEquals(tc, NULL, orders);
|
||||||
|
CuAssertIntEquals(tc, K_MOVE, getkeyword(u->orders));
|
||||||
|
CuAssertIntEquals(tc, K_ENTERTAIN, getkeyword(u->old_orders));
|
||||||
|
CuAssertIntEquals(tc, UFL_ORDERS, u->flags & UFL_ORDERS);
|
||||||
|
freestrlist(backup);
|
||||||
|
test_teardown();
|
||||||
|
}
|
||||||
|
|
||||||
typedef struct order_list {
|
typedef struct order_list {
|
||||||
const char **orders;
|
const char **orders;
|
||||||
int next;
|
int next;
|
||||||
|
@ -85,6 +142,7 @@ CuSuite *get_orderfile_suite(void)
|
||||||
{
|
{
|
||||||
CuSuite *suite = CuSuiteNew();
|
CuSuite *suite = CuSuiteNew();
|
||||||
SUITE_ADD_TEST(suite, test_read_orders);
|
SUITE_ADD_TEST(suite, test_read_orders);
|
||||||
|
SUITE_ADD_TEST(suite, test_unit_orders);
|
||||||
SUITE_ADD_TEST(suite, test_faction_password_okay);
|
SUITE_ADD_TEST(suite, test_faction_password_okay);
|
||||||
SUITE_ADD_TEST(suite, test_faction_password_bad);
|
SUITE_ADD_TEST(suite, test_faction_password_bad);
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include "kernel/building.h"
|
#include "kernel/building.h"
|
||||||
#include "kernel/faction.h"
|
#include "kernel/faction.h"
|
||||||
#include "kernel/item.h"
|
#include "kernel/item.h"
|
||||||
|
#include "kernel/messages.h"
|
||||||
#include "kernel/race.h"
|
#include "kernel/race.h"
|
||||||
#include "kernel/region.h"
|
#include "kernel/region.h"
|
||||||
#include "kernel/ship.h"
|
#include "kernel/ship.h"
|
||||||
|
@ -29,6 +30,7 @@
|
||||||
#include "util/language.h"
|
#include "util/language.h"
|
||||||
#include "util/lists.h"
|
#include "util/lists.h"
|
||||||
#include "util/message.h"
|
#include "util/message.h"
|
||||||
|
#include "util/nrmessage.h"
|
||||||
|
|
||||||
#include "attributes/attributes.h"
|
#include "attributes/attributes.h"
|
||||||
#include "attributes/key.h"
|
#include "attributes/key.h"
|
||||||
|
@ -906,6 +908,46 @@ static void test_visible_unit(CuTest *tc) {
|
||||||
test_teardown();
|
test_teardown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_eval_functions(CuTest *tc)
|
||||||
|
{
|
||||||
|
message *msg;
|
||||||
|
message_type *mtype;
|
||||||
|
item *items = NULL;
|
||||||
|
char buf[1024];
|
||||||
|
struct locale * lang;
|
||||||
|
|
||||||
|
test_setup();
|
||||||
|
init_resources();
|
||||||
|
test_create_itemtype("stone");
|
||||||
|
test_create_itemtype("iron");
|
||||||
|
|
||||||
|
lang = test_create_locale();
|
||||||
|
locale_setstring(lang, "nr_claims", "$resources($items)");
|
||||||
|
register_reports();
|
||||||
|
mtype = mt_create_va(mt_new("nr_claims", NULL), "items:items", MT_NEW_END);
|
||||||
|
nrt_register(mtype);
|
||||||
|
|
||||||
|
msg = msg_message("nr_claims", "items", items);
|
||||||
|
nr_render(msg, lang, buf, sizeof(buf), NULL);
|
||||||
|
CuAssertStrEquals(tc, "", buf);
|
||||||
|
msg_release(msg);
|
||||||
|
|
||||||
|
i_change(&items, get_resourcetype(R_IRON)->itype, 1);
|
||||||
|
msg = msg_message("nr_claims", "items", items);
|
||||||
|
nr_render(msg, lang, buf, sizeof(buf), NULL);
|
||||||
|
CuAssertStrEquals(tc, "1 Eisen", buf);
|
||||||
|
msg_release(msg);
|
||||||
|
|
||||||
|
i_change(&items, get_resourcetype(R_STONE)->itype, 2);
|
||||||
|
msg = msg_message("nr_claims", "items", items);
|
||||||
|
nr_render(msg, lang, buf, sizeof(buf), NULL);
|
||||||
|
CuAssertStrEquals(tc, "1 Eisen, 2 Steine", buf);
|
||||||
|
msg_release(msg);
|
||||||
|
i_freeall(&items);
|
||||||
|
|
||||||
|
test_teardown();
|
||||||
|
}
|
||||||
|
|
||||||
CuSuite *get_reports_suite(void)
|
CuSuite *get_reports_suite(void)
|
||||||
{
|
{
|
||||||
CuSuite *suite = CuSuiteNew();
|
CuSuite *suite = CuSuiteNew();
|
||||||
|
@ -936,5 +978,6 @@ CuSuite *get_reports_suite(void)
|
||||||
SUITE_ADD_TEST(suite, test_insect_warnings);
|
SUITE_ADD_TEST(suite, test_insect_warnings);
|
||||||
SUITE_ADD_TEST(suite, test_newbie_warning);
|
SUITE_ADD_TEST(suite, test_newbie_warning);
|
||||||
SUITE_ADD_TEST(suite, test_visible_unit);
|
SUITE_ADD_TEST(suite, test_visible_unit);
|
||||||
|
SUITE_ADD_TEST(suite, test_eval_functions);
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
29
src/tests.c
29
src/tests.c
|
@ -1,6 +1,8 @@
|
||||||
#include <platform.h>
|
#include <platform.h>
|
||||||
#include "tests.h"
|
#include "tests.h"
|
||||||
#include "prefix.h"
|
#include "prefix.h"
|
||||||
|
#include "creport.h"
|
||||||
|
#include "report.h"
|
||||||
#include "reports.h"
|
#include "reports.h"
|
||||||
#include "vortex.h"
|
#include "vortex.h"
|
||||||
|
|
||||||
|
@ -230,9 +232,12 @@ static void test_reset(void) {
|
||||||
free_gamedata();
|
free_gamedata();
|
||||||
free_terrains();
|
free_terrains();
|
||||||
free_resources();
|
free_resources();
|
||||||
|
free_functions();
|
||||||
free_config();
|
free_config();
|
||||||
default_locale = 0;
|
default_locale = 0;
|
||||||
calendar_cleanup();
|
calendar_cleanup();
|
||||||
|
creport_cleanup();
|
||||||
|
report_cleanup();
|
||||||
close_orders();
|
close_orders();
|
||||||
log_close();
|
log_close();
|
||||||
stats_close();
|
stats_close();
|
||||||
|
@ -245,29 +250,7 @@ static void test_reset(void) {
|
||||||
free_spellbooks();
|
free_spellbooks();
|
||||||
free_prefixes();
|
free_prefixes();
|
||||||
mt_clear();
|
mt_clear();
|
||||||
/*
|
|
||||||
for (i = 0; i != MAXTERRAINS; ++i) {
|
|
||||||
int flags = 0;
|
|
||||||
if (i == T_FIREWALL) {
|
|
||||||
flags |= FORBIDDEN_REGION;
|
|
||||||
} else {
|
|
||||||
flags = FLY_INTO | WALK_INTO;
|
|
||||||
if (i == T_OCEAN) {
|
|
||||||
flags |= SEA_REGION | SWIM_INTO;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
flags |= LAND_REGION;
|
|
||||||
if (i == T_PLAIN) {
|
|
||||||
flags |= CAVALRY_REGION | FOREST_REGION;
|
|
||||||
}
|
|
||||||
else if (i == T_GLACIER || i == T_ICEBERG || i == T_ICEBERG_SLEEP) {
|
|
||||||
flags |= ARCTIC_REGION;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
test_create_terrain(terrainnames[i], flags);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
for (i = 0; i != MAXSKILLS; ++i) {
|
for (i = 0; i != MAXSKILLS; ++i) {
|
||||||
enable_skill(i, true);
|
enable_skill(i, true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,13 +125,3 @@ const char *itoa10(int i)
|
||||||
{
|
{
|
||||||
return itoab(i, 10);
|
return itoab(i, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
int i10toi36(int i)
|
|
||||||
{
|
|
||||||
int r = 0;
|
|
||||||
while (i) {
|
|
||||||
r = r * 36 + i % 10;
|
|
||||||
i = i / 10;
|
|
||||||
}
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
|
@ -25,14 +25,13 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
const char *itoa36(int i);
|
||||||
|
int atoi36(const char *s);
|
||||||
|
|
||||||
const char *itoa36_r(int i, char *result, size_t len);
|
const char *itoa36_r(int i, char *result, size_t len);
|
||||||
const char *itoab_r(int i, int base, char *result, size_t len);
|
const char *itoab_r(int i, int base, char *result, size_t len);
|
||||||
const char *itoab(int i, int base);
|
const char *itoab(int i, int base);
|
||||||
const char *itoa36(int i);
|
|
||||||
const char *itoa10(int i);
|
const char *itoa10(int i);
|
||||||
extern int atoi36(const char *s);
|
|
||||||
extern int atoi10(const char *s);
|
|
||||||
int i10toi36(int i);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,14 +131,14 @@ int bcrypt_gensalt(int factor, char salt[BCRYPT_HASHSIZE])
|
||||||
return (aux == NULL)?5:0;
|
return (aux == NULL)?5:0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int bcrypt_hashpw(const char *passwd, const char salt[BCRYPT_HASHSIZE], char hash[BCRYPT_HASHSIZE])
|
int bcrypt_hashpw(const char *passwd, const char salt[], char hash[BCRYPT_HASHSIZE])
|
||||||
{
|
{
|
||||||
char *aux;
|
char *aux;
|
||||||
aux = crypt_rn(passwd, salt, hash, BCRYPT_HASHSIZE);
|
aux = crypt_rn(passwd, salt, hash, BCRYPT_HASHSIZE);
|
||||||
return (aux == NULL)?1:0;
|
return (aux == NULL)?1:0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int bcrypt_checkpw(const char *passwd, const char hash[BCRYPT_HASHSIZE])
|
int bcrypt_checkpw(const char *passwd, const char hash[])
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
char outhash[BCRYPT_HASHSIZE];
|
char outhash[BCRYPT_HASHSIZE];
|
||||||
|
|
|
@ -45,7 +45,7 @@ int bcrypt_gensalt(int workfactor, char salt[BCRYPT_HASHSIZE]);
|
||||||
* The return value is zero if the password could be hashed and nonzero
|
* The return value is zero if the password could be hashed and nonzero
|
||||||
* otherwise.
|
* otherwise.
|
||||||
*/
|
*/
|
||||||
int bcrypt_hashpw(const char *passwd, const char salt[BCRYPT_HASHSIZE],
|
int bcrypt_hashpw(const char *passwd, const char salt[],
|
||||||
char hash[BCRYPT_HASHSIZE]);
|
char hash[BCRYPT_HASHSIZE]);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -57,7 +57,7 @@ int bcrypt_hashpw(const char *passwd, const char salt[BCRYPT_HASHSIZE],
|
||||||
* passwords don't match.
|
* passwords don't match.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
int bcrypt_checkpw(const char *passwd, const char hash[BCRYPT_HASHSIZE]);
|
int bcrypt_checkpw(const char *passwd, const char hash[]);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Brief Example
|
* Brief Example
|
||||||
|
|
|
@ -88,6 +88,11 @@ bool keyword_disabled(keyword_t kwd) {
|
||||||
return disabled_kwd[kwd];
|
return disabled_kwd[kwd];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *keyword_name(keyword_t kwd, const struct locale *lang)
|
||||||
|
{
|
||||||
|
return LOC(lang, mkname("keyword", keywords[kwd]));
|
||||||
|
}
|
||||||
|
|
||||||
const char *keywords[MAXKEYWORDS] = {
|
const char *keywords[MAXKEYWORDS] = {
|
||||||
"//",
|
"//",
|
||||||
"banner",
|
"banner",
|
||||||
|
|
|
@ -83,6 +83,7 @@ extern "C"
|
||||||
void init_keywords(const struct locale *lang);
|
void init_keywords(const struct locale *lang);
|
||||||
void init_keyword(const struct locale *lang, keyword_t kwd, const char *str);
|
void init_keyword(const struct locale *lang, keyword_t kwd, const char *str);
|
||||||
bool keyword_disabled(keyword_t kwd);
|
bool keyword_disabled(keyword_t kwd);
|
||||||
|
const char *keyword_name(keyword_t kwd, const struct locale *lang);
|
||||||
void enable_keyword(keyword_t kwd, bool enabled);
|
void enable_keyword(keyword_t kwd, bool enabled);
|
||||||
const char *keyword(keyword_t kwd);
|
const char *keyword(keyword_t kwd);
|
||||||
|
|
||||||
|
|
|
@ -80,15 +80,6 @@ void translist(void *l1, void *l2, void *p)
|
||||||
addlist(l2, p);
|
addlist(l2, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
void removelist(void *l, void *p)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* remove entry p from list l; free p */
|
|
||||||
|
|
||||||
choplist(l, p);
|
|
||||||
free(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
void freelist(void *p1)
|
void freelist(void *p1)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,6 @@ extern "C" {
|
||||||
void addlist(void *l1, void *p1);
|
void addlist(void *l1, void *p1);
|
||||||
void translist(void *l1, void *l2, void *p);
|
void translist(void *l1, void *l2, void *p);
|
||||||
void freelist(void *p1);
|
void freelist(void *p1);
|
||||||
void removelist(void *l, void *p);
|
|
||||||
unsigned int listlen(void *l);
|
unsigned int listlen(void *l);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -325,10 +325,10 @@ int log_level(log_t * log, int flags)
|
||||||
static critbit_tree stats = CRITBIT_TREE();
|
static critbit_tree stats = CRITBIT_TREE();
|
||||||
|
|
||||||
int stats_count(const char *stat, int delta) {
|
int stats_count(const char *stat, int delta) {
|
||||||
size_t len;
|
|
||||||
char data[128];
|
|
||||||
void * match;
|
void * match;
|
||||||
if (cb_find_prefix_str(&stats, stat, &match, 1, 0) == 0) {
|
if (cb_find_prefix_str(&stats, stat, &match, 1, 0) == 0) {
|
||||||
|
size_t len;
|
||||||
|
char data[128];
|
||||||
len = cb_new_kv(stat, strlen(stat), &delta, sizeof(delta), data);
|
len = cb_new_kv(stat, strlen(stat), &delta, sizeof(delta), data);
|
||||||
cb_insert(&stats, data, len);
|
cb_insert(&stats, data, len);
|
||||||
return delta;
|
return delta;
|
||||||
|
|
|
@ -148,6 +148,9 @@ const char *section_add(const char *name) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert(i < MAXSECTIONS);
|
assert(i < MAXSECTIONS);
|
||||||
|
if (i == MAXSECTIONS) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
assert(sections[i] == NULL);
|
assert(sections[i] == NULL);
|
||||||
if (i + 1 < MAXSECTIONS) {
|
if (i + 1 < MAXSECTIONS) {
|
||||||
sections[i + 1] = NULL;
|
sections[i + 1] = NULL;
|
||||||
|
|
|
@ -6,6 +6,7 @@ typedef enum cryptalgo_t {
|
||||||
PASSWORD_BCRYPT
|
PASSWORD_BCRYPT
|
||||||
} cryptalgo_t;
|
} cryptalgo_t;
|
||||||
#define PASSWORD_DEFAULT PASSWORD_BCRYPT
|
#define PASSWORD_DEFAULT PASSWORD_BCRYPT
|
||||||
|
#define PASSWORD_MAXSIZE 32
|
||||||
|
|
||||||
extern int bcrypt_workfactor;
|
extern int bcrypt_workfactor;
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#include <platform.h>
|
#include <platform.h>
|
||||||
#define HAVE__ITOA
|
#undef HAVE__ITOA
|
||||||
#endif
|
#endif
|
||||||
#include "strings.h"
|
#include "strings.h"
|
||||||
|
|
||||||
|
@ -35,27 +35,23 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const char* str_itoab(int val, int base)
|
const char* str_itoa_r(int val, char *buf)
|
||||||
{
|
{
|
||||||
static char buf[32] = { 0 };
|
#ifdef HAVE__ITOA
|
||||||
#ifdef HAVE__ITOAB
|
return _itoa(val, buf, 10);
|
||||||
return _itoa(val, buf, base);
|
|
||||||
#else
|
#else
|
||||||
int i = 30;
|
snprintf(buf, 12, "%d", val);
|
||||||
for (; val && i; --i, val /= base) {
|
return buf;
|
||||||
buf[i] = "0123456789abcdefghijklmnopqrstuvwxyz"[val % base];
|
|
||||||
}
|
|
||||||
return &buf[i + 1];
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *str_itoa(int n)
|
const char *str_itoa(int n)
|
||||||
{
|
{
|
||||||
|
static char buf[12];
|
||||||
#ifdef HAVE__ITOA
|
#ifdef HAVE__ITOA
|
||||||
static char buf[32] = { 0 };
|
|
||||||
return _itoa(n, buf, 10);
|
return _itoa(n, buf, 10);
|
||||||
#else
|
#else
|
||||||
return str_itoab(n, 10);
|
return str_itoa_r(n, buf);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,49 +177,6 @@ int str_hash(const char *s)
|
||||||
return key & 0x7FFFFFFF;
|
return key & 0x7FFFFFFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *str_escape_wrong(const char *str, char *buffer, size_t len)
|
|
||||||
{
|
|
||||||
const char *handle_start = strchr(str, '\"');
|
|
||||||
if (!handle_start) handle_start = strchr(str, '\\');
|
|
||||||
assert(buffer);
|
|
||||||
if (handle_start) {
|
|
||||||
const char *p = str;
|
|
||||||
char *o = buffer;
|
|
||||||
size_t skip = handle_start - str;
|
|
||||||
|
|
||||||
if (skip > len) {
|
|
||||||
skip = len;
|
|
||||||
}
|
|
||||||
if (skip > 0) {
|
|
||||||
memcpy(buffer, str, skip);
|
|
||||||
o += skip;
|
|
||||||
p += skip;
|
|
||||||
len -= skip;
|
|
||||||
}
|
|
||||||
do {
|
|
||||||
if (*p == '\"' || *p == '\\') {
|
|
||||||
if (len < 2) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
(*o++) = '\\';
|
|
||||||
len -= 2;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (len < 1) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
--len;
|
|
||||||
}
|
|
||||||
if (len > 0) {
|
|
||||||
(*o++) = (*p);
|
|
||||||
}
|
|
||||||
} while (len > 0 && *p++);
|
|
||||||
*o = '\0';
|
|
||||||
return buffer;
|
|
||||||
}
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int jenkins_hash(unsigned int a)
|
unsigned int jenkins_hash(unsigned int a)
|
||||||
{
|
{
|
||||||
a = (a + 0x7ed55d16) + (a << 12);
|
a = (a + 0x7ed55d16) + (a << 12);
|
||||||
|
|
|
@ -29,7 +29,6 @@ extern "C" {
|
||||||
void str_replace(char *buffer, size_t size, const char *tmpl, const char *var, const char *value);
|
void str_replace(char *buffer, size_t size, const char *tmpl, const char *var, const char *value);
|
||||||
int str_hash(const char *s);
|
int str_hash(const char *s);
|
||||||
const char *str_itoa(int i);
|
const char *str_itoa(int i);
|
||||||
const char *str_itoab(int i, int base);
|
|
||||||
size_t str_slprintf(char * dst, size_t size, const char * format, ...);
|
size_t str_slprintf(char * dst, size_t size, const char * format, ...);
|
||||||
size_t str_strlcpy(char *dst, const char *src, size_t len);
|
size_t str_strlcpy(char *dst, const char *src, size_t len);
|
||||||
size_t str_strlcat(char *dst, const char *src, size_t len);
|
size_t str_strlcat(char *dst, const char *src, size_t len);
|
||||||
|
|
|
@ -133,6 +133,14 @@ static void test_str_strlcpy(CuTest * tc)
|
||||||
errno = 0;
|
errno = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_str_itoa(CuTest * tc)
|
||||||
|
{
|
||||||
|
CuAssertStrEquals(tc, "1234", str_itoa(1234));
|
||||||
|
CuAssertStrEquals(tc, "0", str_itoa(0));
|
||||||
|
CuAssertStrEquals(tc, "1234567890", str_itoa(1234567890));
|
||||||
|
CuAssertStrEquals(tc, "-1234567890", str_itoa(-1234567890));
|
||||||
|
}
|
||||||
|
|
||||||
static void test_sbstring(CuTest * tc)
|
static void test_sbstring(CuTest * tc)
|
||||||
{
|
{
|
||||||
char buffer[16];
|
char buffer[16];
|
||||||
|
@ -274,6 +282,7 @@ CuSuite *get_strings_suite(void)
|
||||||
SUITE_ADD_TEST(suite, test_str_slprintf);
|
SUITE_ADD_TEST(suite, test_str_slprintf);
|
||||||
SUITE_ADD_TEST(suite, test_str_strlcat);
|
SUITE_ADD_TEST(suite, test_str_strlcat);
|
||||||
SUITE_ADD_TEST(suite, test_str_strlcpy);
|
SUITE_ADD_TEST(suite, test_str_strlcpy);
|
||||||
|
SUITE_ADD_TEST(suite, test_str_itoa);
|
||||||
SUITE_ADD_TEST(suite, test_sbstring);
|
SUITE_ADD_TEST(suite, test_sbstring);
|
||||||
SUITE_ADD_TEST(suite, test_sbs_strcat);
|
SUITE_ADD_TEST(suite, test_sbs_strcat);
|
||||||
SUITE_ADD_TEST(suite, test_sbs_substr);
|
SUITE_ADD_TEST(suite, test_sbs_substr);
|
||||||
|
|
|
@ -129,13 +129,12 @@ attrib_type at_direction = {
|
||||||
region *find_special_direction(const region * r, const char *token)
|
region *find_special_direction(const region * r, const char *token)
|
||||||
{
|
{
|
||||||
attrib *a;
|
attrib *a;
|
||||||
spec_direction *d;
|
|
||||||
|
|
||||||
if (strlen(token) == 0)
|
if (strlen(token) == 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
for (a = a_find(r->attribs, &at_direction); a && a->type == &at_direction;
|
for (a = a_find(r->attribs, &at_direction); a && a->type == &at_direction;
|
||||||
a = a->next) {
|
a = a->next) {
|
||||||
d = (spec_direction *)(a->data.v);
|
spec_direction *d = (spec_direction *)(a->data.v);
|
||||||
|
|
||||||
if (d->active && strcmp(token, d->keyword) == 0) {
|
if (d->active && strcmp(token, d->keyword) == 0) {
|
||||||
return findregion(d->x, d->y);
|
return findregion(d->x, d->y);
|
||||||
|
|
Loading…
Reference in a new issue