forked from github/server
commit
208ed4c74a
|
@ -19,7 +19,7 @@ fi
|
|||
rm -f "orders.$TURN"
|
||||
find "orders.dir.$TURN" -maxdepth 1 -type f -printf "%T+\t%p\n" | sort | cut -f2 | while read -r
|
||||
do
|
||||
cat "$REPLY" >> "orders.$TURN"
|
||||
tr -d '\r' < "$REPLY" >> "orders.$TURN"
|
||||
done
|
||||
|
||||
lockfile -r3 -l120 orders.queue.lock
|
||||
|
|
|
@ -52,6 +52,9 @@ messages = {
|
|||
"validate-en": "Validating",
|
||||
"validate-de": "Verarbeite",
|
||||
|
||||
"noorders-en": "The email contained no recognizable orders.",
|
||||
"noorders-de": "Es konnten keine Befehle gefunden werden.",
|
||||
|
||||
"faction-en": "Faction",
|
||||
"faction-de": "Partei",
|
||||
|
||||
|
@ -183,6 +186,8 @@ for line in lines:
|
|||
logfile = open(os.path.join(game_dir, "zug.log"), "a")
|
||||
dirname, filename = split_filename(infile)
|
||||
msg = messages["validate-"+locale] + " " + infile + "\n\n"
|
||||
if len(results)==0:
|
||||
msg = msg + messages["noorders-"+locale]
|
||||
for faction, game_email, success, pwd in results:
|
||||
msg = msg + messages["faction-"+locale] + " " + faction + "\n"
|
||||
if success: failed = False
|
||||
|
|
|
@ -2429,6 +2429,9 @@ msgstr "\"$unit($unit) konnte nur $int($ships) von $int($maxships) Schiffen verz
|
|||
msgid "error283"
|
||||
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"
|
||||
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"
|
||||
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"
|
||||
msgstr "\"$unit($unit) in $region($region): '$order($command)' - Your password may only contain alphanumeric symbols.\""
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
#!/bin/sh
|
||||
IGNORE=$(find src -name "*.test.c" | awk '{ print "-i"$1 }')
|
||||
|
||||
cppcheck $IGNORE -isrc/tests.c \
|
||||
--quiet --enable=all -U_MSC_VER -UCLEANUP_CODE -UTODO \
|
||||
-UERESSEA_BUILDNO -UERESSEA_VERSION \
|
||||
#cppcheck $IGNORE -isrc/tests.c \
|
||||
cppcheck --quiet --enable=warning,style,performance,portability -U_MSC_VER -UCLEANUP_CODE -UTODO \
|
||||
-UERESSEA_BUILDNO -UERESSEA_VERSION -UTEST_THREADS \
|
||||
-IcJSON -Isrc -Iclibs -Istorage src
|
||||
|
||||
|
|
|
@ -121,7 +121,7 @@ static int read_keyval_orig(gamedata *data, int *keys, int n) {
|
|||
#endif
|
||||
|
||||
static int a_readkeys(variant *var, void *owner, gamedata *data) {
|
||||
int i, n, ksn, *keys;
|
||||
int n, ksn, *keys;
|
||||
|
||||
READ_INT(data->store, &n);
|
||||
assert(n < 4096 && n >= 0);
|
||||
|
@ -155,7 +155,7 @@ static int a_readkeys(variant *var, void *owner, gamedata *data) {
|
|||
}
|
||||
keys[0] = n;
|
||||
if (data->version < SORTKEYS_VERSION) {
|
||||
int e = 1;
|
||||
int i, e = 1;
|
||||
for (i = 1; i != n; ++i) {
|
||||
int k = keys[i * 2 + 1];
|
||||
int v = keys[i * 2 + 2];
|
||||
|
|
|
@ -48,13 +48,12 @@ static int read_seenspells(variant *var, void *owner, struct gamedata *data)
|
|||
{
|
||||
selist *ql = NULL;
|
||||
storage *store = data->store;
|
||||
spell *sp = 0;
|
||||
char token[32];
|
||||
|
||||
UNUSED_ARG(owner);
|
||||
READ_TOK(store, token, sizeof(token));
|
||||
while (token[0]) {
|
||||
sp = find_spell(token);
|
||||
spell *sp = find_spell(token);
|
||||
if (!sp) {
|
||||
log_info("read_seenspells: could not find spell '%s'\n", token);
|
||||
return AT_READ_FAIL;
|
||||
|
|
|
@ -82,7 +82,7 @@ void autostudy_run(scholar scholars[], int nscholars)
|
|||
int ti = 0;
|
||||
while (ti != nscholars) {
|
||||
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) {
|
||||
int mint;
|
||||
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 */
|
||||
int i = scholars[ti].u->number * STUDENTS_PER_TEACHER;
|
||||
/* 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; ) {
|
||||
if (i >= n) {
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Effektiver Waffenskill waehrend des Kampfes.
|
||||
*/
|
||||
static int
|
||||
weapon_effskill(troop t, troop enemy, const weapon * w, bool attacking,
|
||||
bool missile)
|
||||
/* effektiver Waffenskill w<>hrend des Kampfes */
|
||||
weapon_effskill(troop t, troop enemy, const weapon * w,
|
||||
bool attacking, bool missile)
|
||||
{
|
||||
/* In dieser Runde alle die Modifier berechnen, die fig durch die
|
||||
* Waffen bekommt. */
|
||||
fighter *tf = t.fighter;
|
||||
unit *tu = t.fighter->unit;
|
||||
int skill;
|
||||
const weapon_type *wtype = w ? w->type : NULL;
|
||||
/* Alle Modifier berechnen, die fig durch die Waffen bekommt. */
|
||||
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) {
|
||||
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 (is_riding(t) && (wtype == NULL || (fval(wtype, WTF_HORSEBONUS)
|
||||
&& !fval(wtype, WTF_MISSILE)))) {
|
||||
skill += CavalryBonus(tu, enemy, BONUS_SKILL);
|
||||
}
|
||||
if (t.index < tf->elvenhorses) {
|
||||
/* Elfenpferde: Helfen dem Reiter, egal ob und welche Waffe. Das ist
|
||||
* eleganter, und vor allem einfacher, sonst mu<EFBFBD> man noch ein
|
||||
* WMF_ELVENHORSE einbauen. */
|
||||
skill += 2;
|
||||
}
|
||||
|
||||
if (t.index < tf->elvenhorses) {
|
||||
/* Elfenpferde: Helfen dem Reiter, egal ob und welche Waffe. Das ist
|
||||
* eleganter, und vor allem einfacher, sonst mu<EFBFBD> man noch ein
|
||||
* WMF_ELVENHORSE einbauen. */
|
||||
skill += 2;
|
||||
if (skill > 0 && !attacking && missile) {
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
if (skill > 0 && !attacking && missile) {
|
||||
/*
|
||||
* 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;
|
||||
/* no weapon: fight weaponless */
|
||||
return weapon_skill(NULL, tu, attacking);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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)
|
||||
&& !fval(awtype, WTF_MISSILE)))) {
|
||||
|
@ -3383,23 +3381,6 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack)
|
|||
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)
|
||||
{
|
||||
side *s;
|
||||
|
|
|
@ -213,7 +213,6 @@ extern "C" {
|
|||
/* BEGIN battle interface */
|
||||
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);
|
||||
fighter * get_fighter(battle * b, const struct unit * u);
|
||||
/* END battle interface */
|
||||
|
||||
void do_battles(void);
|
||||
|
|
|
@ -123,6 +123,16 @@ static void test_select_weapon_restricted(CuTest *tc) {
|
|||
CuAssertIntEquals(tc, 0, af->weapons[0].count);
|
||||
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_allow = rc_mask(rc);
|
||||
b = make_battle(au->region);
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
#include "kernel/skills.h"
|
||||
#include "kernel/types.h"
|
||||
#include <kernel/building.h>
|
||||
#include <kernel/config.h>
|
||||
#include <kernel/curse.h>
|
||||
#include "kernel/equipment.h"
|
||||
#include <kernel/faction.h>
|
||||
|
@ -432,38 +431,11 @@ static int tolua_unit_effskill(lua_State * L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
typedef struct fctr_data {
|
||||
unit *target;
|
||||
int fhandle;
|
||||
} fctr_data;
|
||||
|
||||
typedef struct event {
|
||||
struct event_arg *args;
|
||||
char *msg;
|
||||
} 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)
|
||||
{
|
||||
unit *self = (unit *)tolua_tousertype(L, 1, 0);
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "creport.h"
|
||||
#include "report.h"
|
||||
#include "names.h"
|
||||
#include "prefix.h"
|
||||
#include "reports.h"
|
||||
#include "spells.h"
|
||||
#include "vortex.h"
|
||||
|
@ -50,9 +51,10 @@ void game_done(void)
|
|||
calendar_cleanup();
|
||||
free_functions();
|
||||
free_config();
|
||||
free_special_directions();
|
||||
free_locales();
|
||||
#endif
|
||||
free_prefixes();
|
||||
free_special_directions();
|
||||
kernel_done();
|
||||
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 ------------------------------ */
|
||||
|
||||
static const char *forbidden[] = { "t", "te", "tem", "temp", NULL };
|
||||
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;
|
||||
size_t i;
|
||||
if (id <= 0)
|
||||
return 1;
|
||||
if (id <= 0) {
|
||||
return true;
|
||||
}
|
||||
if (!forbidden_ids) {
|
||||
while (forbidden[len])
|
||||
++len;
|
||||
forbidden_ids = calloc(len, sizeof(int));
|
||||
forbidden_ids = malloc(len * sizeof(int));
|
||||
if (!forbidden_ids) abort();
|
||||
for (i = 0; i != len; ++i) {
|
||||
forbidden_ids[i] = atoi36(forbidden[i]);
|
||||
}
|
||||
}
|
||||
for (i = 0; i != len; ++i)
|
||||
if (id == forbidden_ids[i])
|
||||
return 1;
|
||||
return 0;
|
||||
for (i = 0; i != len; ++i) {
|
||||
if (id == forbidden_ids[i]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int newcontainerid(void)
|
||||
|
@ -274,6 +278,7 @@ void set_param(struct param **p, const char *key, const char *value)
|
|||
par = *p;
|
||||
if (!par && value) {
|
||||
*p = par = calloc(1, sizeof(param));
|
||||
if (!par) abort();
|
||||
}
|
||||
if (par) {
|
||||
void *match;
|
||||
|
@ -509,7 +514,6 @@ order *default_order(const struct locale *lang)
|
|||
int i = locale_index(lang);
|
||||
keyword_t kwd;
|
||||
const char * str;
|
||||
order *result = 0;
|
||||
|
||||
assert(i < MAXLOCALES);
|
||||
kwd = keyword_disabled(K_WORK) ? NOKEYWORD : K_WORK;
|
||||
|
@ -518,7 +522,8 @@ order *default_order(const struct locale *lang)
|
|||
kwd = findkeyword(str);
|
||||
}
|
||||
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 NULL;
|
||||
|
|
|
@ -52,7 +52,7 @@ extern "C" {
|
|||
void init_locale(struct locale *lang);
|
||||
void init_races(struct locale *lang);
|
||||
|
||||
int forbiddenid(int id);
|
||||
bool forbiddenid(int id);
|
||||
int newcontainerid(void);
|
||||
|
||||
bool rule_region_owners(void);
|
||||
|
|
|
@ -672,16 +672,6 @@ bool curse_active(const curse * c)
|
|||
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)
|
||||
{
|
||||
const attrib *a = ap;
|
||||
|
|
|
@ -168,28 +168,6 @@ void set_show_item(faction * f, const struct item_type *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)
|
||||
{
|
||||
typedef char name[OBJECTIDSIZE + 1];
|
||||
|
|
|
@ -117,7 +117,6 @@ extern "C" {
|
|||
int max_magicians(const faction * f);
|
||||
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);
|
||||
struct unit *addplayer(struct region *r, faction * f);
|
||||
struct faction *addfaction(const char *email, const char *password,
|
||||
|
|
|
@ -194,12 +194,10 @@ resource_type *rt_get_or_create(const char *name) {
|
|||
if (!rtype) {
|
||||
rtype = calloc(1, sizeof(resource_type));
|
||||
if (!rtype) {
|
||||
perror("resource_type allocation failed");
|
||||
}
|
||||
else {
|
||||
rtype->_name = str_strdup(name);
|
||||
rt_register(rtype);
|
||||
abort();
|
||||
}
|
||||
rtype->_name = str_strdup(name);
|
||||
rt_register(rtype);
|
||||
}
|
||||
return rtype;
|
||||
}
|
||||
|
@ -247,6 +245,7 @@ item_type *it_get_or_create(resource_type *rtype) {
|
|||
if (!rtype->itype) {
|
||||
item_type * itype;
|
||||
itype = (item_type *)calloc(sizeof(item_type), 1);
|
||||
if (!itype) abort();
|
||||
itype->rtype = rtype;
|
||||
rtype->uchange = res_changeitem;
|
||||
rtype->itype = itype;
|
||||
|
@ -269,6 +268,7 @@ luxury_type *new_luxurytype(item_type * itype, int price)
|
|||
assert(resource2luxury(itype->rtype) == NULL);
|
||||
|
||||
ltype = calloc(sizeof(luxury_type), 1);
|
||||
if (!ltype) abort();
|
||||
ltype->itype = itype;
|
||||
ltype->price = price;
|
||||
lt_register(ltype);
|
||||
|
@ -285,6 +285,7 @@ weapon_type *new_weapontype(item_type * itype,
|
|||
assert(itype && (!itype->rtype || !resource2weapon(itype->rtype)));
|
||||
|
||||
wtype = calloc(sizeof(weapon_type), 1);
|
||||
if (!wtype) abort();
|
||||
if (damage) {
|
||||
wtype->damage[0] = str_strdup(damage[0]);
|
||||
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);
|
||||
|
||||
atype = calloc(sizeof(armor_type), 1);
|
||||
if (!atype) abort();
|
||||
|
||||
atype->itype = itype;
|
||||
atype->penalty = penalty;
|
||||
|
@ -530,6 +532,7 @@ item *i_new(const item_type * itype, int size)
|
|||
}
|
||||
else {
|
||||
i = malloc(sizeof(item));
|
||||
if (!i) abort();
|
||||
}
|
||||
assert(itype);
|
||||
i->next = NULL;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "messages.h"
|
||||
|
||||
#include "unit.h"
|
||||
#include "faction.h"
|
||||
#include "order.h"
|
||||
|
||||
#include <CuTest.h>
|
||||
|
@ -25,10 +26,13 @@ void test_missing_message(CuTest *tc) {
|
|||
|
||||
void test_missing_feedback(CuTest *tc) {
|
||||
message *msg;
|
||||
unit *u;
|
||||
|
||||
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);
|
||||
msg = msg_error(NULL, NULL, 77);
|
||||
msg = msg_error(u, NULL, 77);
|
||||
CuAssertPtrNotNull(tc, msg);
|
||||
CuAssertPtrNotNull(tc, msg->type);
|
||||
CuAssertStrEquals(tc, msg->type->name, "missing_feedback");
|
||||
|
@ -113,6 +117,7 @@ static void test_noerror(CuTest *tc) {
|
|||
CuSuite *get_messages_suite(void) {
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
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_message);
|
||||
SUITE_ADD_TEST(suite, test_noerror);
|
||||
|
|
|
@ -240,15 +240,6 @@ race_list *get_familiarraces(void)
|
|||
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)
|
||||
{
|
||||
race_list *rl2 = (race_list *)malloc(sizeof(race_list));
|
||||
|
|
|
@ -67,7 +67,6 @@ bool terrain_changed(int *cache) {
|
|||
return false;
|
||||
}
|
||||
|
||||
|
||||
void free_terrains(void)
|
||||
{
|
||||
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)
|
||||
{
|
||||
char pwbuf[32];
|
||||
char pwbuf[PASSWORD_MAXSIZE + 1];
|
||||
const char *s;
|
||||
bool pwok = true;
|
||||
|
||||
init_order_depr(ord);
|
||||
pwbuf[PASSWORD_MAXSIZE] = '\n';
|
||||
s = gettoken(pwbuf, sizeof(pwbuf));
|
||||
|
||||
if (!s || !*s) {
|
||||
int i;
|
||||
for (i = 0; i < 6; i++)
|
||||
pwbuf[i] = (char)(97 + rng_int() % 26);
|
||||
pwbuf[6] = 0;
|
||||
if (pwbuf[PASSWORD_MAXSIZE] == '\0') {
|
||||
cmistake(u, ord, 321, MSG_EVENT);
|
||||
pwbuf[PASSWORD_MAXSIZE - 1] = '\0';
|
||||
}
|
||||
else {
|
||||
char *c;
|
||||
for (c = pwbuf; *c && pwok; ++c) {
|
||||
if (!isalnum(*(unsigned char *)c)) {
|
||||
pwok = false;
|
||||
|
||||
if (s && *s) {
|
||||
unsigned char *c = (unsigned char *)pwbuf;
|
||||
int i, r = 0;
|
||||
|
||||
for (i = 0; c[i] && i != PASSWORD_MAXSIZE; ++i) {
|
||||
if (!isalnum(c[i])) {
|
||||
c[i] = 'X';
|
||||
++r;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!pwok) {
|
||||
cmistake(u, ord, 283, MSG_EVENT);
|
||||
str_strlcpy(pwbuf, itoa36(rng_int()), sizeof(pwbuf));
|
||||
if (r != 0) {
|
||||
cmistake(u, ord, 283, MSG_EVENT);
|
||||
}
|
||||
}
|
||||
faction_setpassword(u->faction, password_hash(pwbuf, PASSWORD_DEFAULT));
|
||||
ADDMSG(&u->faction->msgs, msg_message("changepasswd",
|
||||
"value", pwbuf));
|
||||
ADDMSG(&u->faction->msgs, msg_message("changepasswd", "value", pwbuf));
|
||||
u->faction->flags |= FFL_PWMSG;
|
||||
return 0;
|
||||
}
|
||||
|
@ -3339,7 +3338,6 @@ int pay_cmd(unit * u, struct order *ord)
|
|||
cmistake(u, ord, 6, MSG_EVENT);
|
||||
}
|
||||
else {
|
||||
building *b = NULL;
|
||||
param_t p;
|
||||
int id;
|
||||
|
||||
|
@ -3355,13 +3353,12 @@ int pay_cmd(unit * u, struct order *ord)
|
|||
}
|
||||
else {
|
||||
/* 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;
|
||||
}
|
||||
else {
|
||||
/* 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 (b && b->region == u->region)
|
||||
{
|
||||
|
|
|
@ -48,6 +48,37 @@ static void test_new_building_can_be_renamed(CuTest * tc)
|
|||
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)
|
||||
{
|
||||
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_hungry);
|
||||
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_twice);
|
||||
SUITE_ADD_TEST(suite, test_fishing_feeds_2_people);
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "util/filereader.h"
|
||||
#include "util/param.h"
|
||||
#include "util/parser.h"
|
||||
#include "util/password.h"
|
||||
#include "util/order_parser.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
@ -22,7 +23,7 @@
|
|||
#include <string.h>
|
||||
|
||||
static void begin_orders(unit *u) {
|
||||
if (u->flags & UFL_ORDERS) {
|
||||
if ((u->flags & UFL_ORDERS) == 0) {
|
||||
order **ordp;
|
||||
/* alle wiederholbaren, langen befehle werden gesichert: */
|
||||
u->flags |= UFL_ORDERS;
|
||||
|
@ -47,13 +48,12 @@ static void begin_orders(unit *u) {
|
|||
u->orders = NULL;
|
||||
}
|
||||
|
||||
static unit *unitorders(input *in, faction *f)
|
||||
static void unitorders(input *in, faction *f)
|
||||
{
|
||||
int i;
|
||||
unit *u;
|
||||
|
||||
if (!f)
|
||||
return NULL;
|
||||
assert(f);
|
||||
|
||||
i = getid();
|
||||
u = findunit(i);
|
||||
|
@ -120,10 +120,6 @@ static unit *unitorders(input *in, faction *f)
|
|||
}
|
||||
|
||||
}
|
||||
else {
|
||||
return NULL;
|
||||
}
|
||||
return u;
|
||||
}
|
||||
|
||||
static faction *factionorders(void)
|
||||
|
@ -132,7 +128,7 @@ static faction *factionorders(void)
|
|||
faction *f = findfaction(fid);
|
||||
|
||||
if (f != NULL && (f->flags & FFL_NPC) == 0) {
|
||||
char token[128];
|
||||
char token[PASSWORD_MAXSIZE];
|
||||
const char *pass = gettoken(token, sizeof(token));
|
||||
|
||||
if (!checkpasswd(f, (const char *)pass)) {
|
||||
|
@ -189,7 +185,8 @@ int read_orders(input *in)
|
|||
* vermerkt. */
|
||||
|
||||
case P_UNIT:
|
||||
if (!f || !unitorders(in, f)) {
|
||||
if (f) {
|
||||
unitorders(in, f);
|
||||
do {
|
||||
b = in->getbuf(in->data);
|
||||
if (!b) {
|
||||
|
@ -278,7 +275,7 @@ static void handle_unit(void *userData, int no) {
|
|||
static void handle_order(void *userData, const char *str) {
|
||||
parser_state *state = (parser_state *)userData;
|
||||
const char * tok, *input = str;
|
||||
char buffer[16];
|
||||
char buffer[64];
|
||||
const struct locale *lang;
|
||||
param_t p;
|
||||
faction * f = state->f;
|
||||
|
|
|
@ -3,9 +3,20 @@
|
|||
|
||||
#include "orderfile.h"
|
||||
|
||||
#include "direction.h"
|
||||
|
||||
#include <kernel/calendar.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/param.h>
|
||||
#include <util/password.h>
|
||||
|
||||
#include <CuTest.h>
|
||||
#include <tests.h>
|
||||
|
@ -24,6 +35,52 @@ static void test_read_orders(CuTest *tc) {
|
|||
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 {
|
||||
const char **orders;
|
||||
int next;
|
||||
|
@ -85,6 +142,7 @@ CuSuite *get_orderfile_suite(void)
|
|||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
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_bad);
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "kernel/building.h"
|
||||
#include "kernel/faction.h"
|
||||
#include "kernel/item.h"
|
||||
#include "kernel/messages.h"
|
||||
#include "kernel/race.h"
|
||||
#include "kernel/region.h"
|
||||
#include "kernel/ship.h"
|
||||
|
@ -29,6 +30,7 @@
|
|||
#include "util/language.h"
|
||||
#include "util/lists.h"
|
||||
#include "util/message.h"
|
||||
#include "util/nrmessage.h"
|
||||
|
||||
#include "attributes/attributes.h"
|
||||
#include "attributes/key.h"
|
||||
|
@ -906,6 +908,46 @@ static void test_visible_unit(CuTest *tc) {
|
|||
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 *suite = CuSuiteNew();
|
||||
|
@ -936,5 +978,6 @@ CuSuite *get_reports_suite(void)
|
|||
SUITE_ADD_TEST(suite, test_insect_warnings);
|
||||
SUITE_ADD_TEST(suite, test_newbie_warning);
|
||||
SUITE_ADD_TEST(suite, test_visible_unit);
|
||||
SUITE_ADD_TEST(suite, test_eval_functions);
|
||||
return suite;
|
||||
}
|
||||
|
|
29
src/tests.c
29
src/tests.c
|
@ -1,6 +1,8 @@
|
|||
#include <platform.h>
|
||||
#include "tests.h"
|
||||
#include "prefix.h"
|
||||
#include "creport.h"
|
||||
#include "report.h"
|
||||
#include "reports.h"
|
||||
#include "vortex.h"
|
||||
|
||||
|
@ -230,9 +232,12 @@ static void test_reset(void) {
|
|||
free_gamedata();
|
||||
free_terrains();
|
||||
free_resources();
|
||||
free_functions();
|
||||
free_config();
|
||||
default_locale = 0;
|
||||
calendar_cleanup();
|
||||
creport_cleanup();
|
||||
report_cleanup();
|
||||
close_orders();
|
||||
log_close();
|
||||
stats_close();
|
||||
|
@ -245,29 +250,7 @@ static void test_reset(void) {
|
|||
free_spellbooks();
|
||||
free_prefixes();
|
||||
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) {
|
||||
enable_skill(i, true);
|
||||
}
|
||||
|
|
|
@ -125,13 +125,3 @@ const char *itoa10(int i)
|
|||
{
|
||||
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" {
|
||||
#endif
|
||||
|
||||
const char *itoa36(int i);
|
||||
int atoi36(const char *s);
|
||||
|
||||
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(int i, int base);
|
||||
const char *itoa36(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
|
||||
}
|
||||
|
|
|
@ -131,14 +131,14 @@ int bcrypt_gensalt(int factor, char salt[BCRYPT_HASHSIZE])
|
|||
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;
|
||||
aux = crypt_rn(passwd, salt, hash, BCRYPT_HASHSIZE);
|
||||
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;
|
||||
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
|
||||
* 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]);
|
||||
|
||||
/*
|
||||
|
@ -57,7 +57,7 @@ int bcrypt_hashpw(const char *passwd, const char salt[BCRYPT_HASHSIZE],
|
|||
* 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
|
||||
|
|
|
@ -88,6 +88,11 @@ bool keyword_disabled(keyword_t 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] = {
|
||||
"//",
|
||||
"banner",
|
||||
|
|
|
@ -83,6 +83,7 @@ extern "C"
|
|||
void init_keywords(const struct locale *lang);
|
||||
void init_keyword(const struct locale *lang, keyword_t kwd, const char *str);
|
||||
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);
|
||||
const char *keyword(keyword_t kwd);
|
||||
|
||||
|
|
|
@ -80,15 +80,6 @@ void translist(void *l1, void *l2, void *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)
|
||||
{
|
||||
|
||||
|
|
|
@ -32,7 +32,6 @@ extern "C" {
|
|||
void addlist(void *l1, void *p1);
|
||||
void translist(void *l1, void *l2, void *p);
|
||||
void freelist(void *p1);
|
||||
void removelist(void *l, void *p);
|
||||
unsigned int listlen(void *l);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -325,10 +325,10 @@ int log_level(log_t * log, int flags)
|
|||
static critbit_tree stats = CRITBIT_TREE();
|
||||
|
||||
int stats_count(const char *stat, int delta) {
|
||||
size_t len;
|
||||
char data[128];
|
||||
void * match;
|
||||
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);
|
||||
cb_insert(&stats, data, len);
|
||||
return delta;
|
||||
|
|
|
@ -148,6 +148,9 @@ const char *section_add(const char *name) {
|
|||
}
|
||||
}
|
||||
assert(i < MAXSECTIONS);
|
||||
if (i == MAXSECTIONS) {
|
||||
return NULL;
|
||||
}
|
||||
assert(sections[i] == NULL);
|
||||
if (i + 1 < MAXSECTIONS) {
|
||||
sections[i + 1] = NULL;
|
||||
|
|
|
@ -6,6 +6,7 @@ typedef enum cryptalgo_t {
|
|||
PASSWORD_BCRYPT
|
||||
} cryptalgo_t;
|
||||
#define PASSWORD_DEFAULT PASSWORD_BCRYPT
|
||||
#define PASSWORD_MAXSIZE 32
|
||||
|
||||
extern int bcrypt_workfactor;
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
|
||||
#ifdef _MSC_VER
|
||||
#include <platform.h>
|
||||
#define HAVE__ITOA
|
||||
#undef HAVE__ITOA
|
||||
#endif
|
||||
#include "strings.h"
|
||||
|
||||
|
@ -35,27 +35,23 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <string.h>
|
||||
#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__ITOAB
|
||||
return _itoa(val, buf, base);
|
||||
#ifdef HAVE__ITOA
|
||||
return _itoa(val, buf, 10);
|
||||
#else
|
||||
int i = 30;
|
||||
for (; val && i; --i, val /= base) {
|
||||
buf[i] = "0123456789abcdefghijklmnopqrstuvwxyz"[val % base];
|
||||
}
|
||||
return &buf[i + 1];
|
||||
snprintf(buf, 12, "%d", val);
|
||||
return buf;
|
||||
#endif
|
||||
}
|
||||
|
||||
const char *str_itoa(int n)
|
||||
{
|
||||
static char buf[12];
|
||||
#ifdef HAVE__ITOA
|
||||
static char buf[32] = { 0 };
|
||||
return _itoa(n, buf, 10);
|
||||
#else
|
||||
return str_itoab(n, 10);
|
||||
return str_itoa_r(n, buf);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -181,49 +177,6 @@ int str_hash(const char *s)
|
|||
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)
|
||||
{
|
||||
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);
|
||||
int str_hash(const char *s);
|
||||
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_strlcpy(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;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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_strlcat);
|
||||
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_sbs_strcat);
|
||||
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)
|
||||
{
|
||||
attrib *a;
|
||||
spec_direction *d;
|
||||
|
||||
if (strlen(token) == 0)
|
||||
return NULL;
|
||||
for (a = a_find(r->attribs, &at_direction); a && a->type == &at_direction;
|
||||
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) {
|
||||
return findregion(d->x, d->y);
|
||||
|
|
Loading…
Reference in New Issue