forked from github/server
Potential buffer overruns galore.
This commit is contained in:
parent
23ab322ee1
commit
0b8c2c94ef
|
@ -72,6 +72,7 @@
|
||||||
|
|
||||||
/* util includes */
|
/* util includes */
|
||||||
#include <util/base36.h>
|
#include <util/base36.h>
|
||||||
|
#include <util/bsdstring.h>
|
||||||
#include <util/event.h>
|
#include <util/event.h>
|
||||||
#include <util/goodies.h>
|
#include <util/goodies.h>
|
||||||
#include <util/log.h>
|
#include <util/log.h>
|
||||||
|
@ -2264,6 +2265,8 @@ display_item(faction *f, unit *u, const item_type * itype)
|
||||||
const char *name;
|
const char *name;
|
||||||
const char *info;
|
const char *info;
|
||||||
const char *key;
|
const char *key;
|
||||||
|
char * bufp = buf;
|
||||||
|
size_t size = sizeof(buf), rsize;
|
||||||
|
|
||||||
if (u && *i_find(&u->items, itype) == NULL) return false;
|
if (u && *i_find(&u->items, itype) == NULL) return false;
|
||||||
|
|
||||||
|
@ -2287,10 +2290,14 @@ display_item(faction *f, unit *u, const item_type * itype)
|
||||||
if (fp!=NULL) {
|
if (fp!=NULL) {
|
||||||
buf[0]='\0';
|
buf[0]='\0';
|
||||||
while (fgets(t, NAMESIZE, fp) != NULL) {
|
while (fgets(t, NAMESIZE, fp) != NULL) {
|
||||||
if (t[strlen(t) - 1] == '\n') {
|
size_t len = strlen(t);
|
||||||
t[strlen(t) - 1] = 0;
|
if (len>0 && t[len - 1] == '\n') {
|
||||||
|
t[len - 1] = 0;
|
||||||
}
|
}
|
||||||
strcat(buf, t);
|
rsize = strlcpy(bufp, t, size);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
info = buf;
|
info = buf;
|
||||||
|
@ -2336,11 +2343,16 @@ display_race(faction *f, unit *u, const race * rc)
|
||||||
const char *name;
|
const char *name;
|
||||||
int a, at_count;
|
int a, at_count;
|
||||||
char buf2[2048];
|
char buf2[2048];
|
||||||
|
char * bufp = buf;
|
||||||
|
size_t size = sizeof(buf), rsize;
|
||||||
|
|
||||||
if (u && u->race != rc) return false;
|
if (u && u->race != rc) return false;
|
||||||
name = rc_name(rc, 0);
|
name = rc_name(rc, 0);
|
||||||
|
|
||||||
sprintf(buf, "%s: ", LOC(f->locale, name));
|
rsize = slprintf(bufp, size, "%s: ", LOC(f->locale, name));
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
|
|
||||||
sprintf(filename, "showdata/%s", LOC(default_locale, name));
|
sprintf(filename, "showdata/%s", LOC(default_locale, name));
|
||||||
fp = fopen(filename, "r");
|
fp = fopen(filename, "r");
|
||||||
|
@ -2349,29 +2361,52 @@ display_race(faction *f, unit *u, const race * rc)
|
||||||
if (t[strlen(t) - 1] == '\n') {
|
if (t[strlen(t) - 1] == '\n') {
|
||||||
t[strlen(t) - 1] = 0;
|
t[strlen(t) - 1] = 0;
|
||||||
}
|
}
|
||||||
strcat(buf, t);
|
rsize = strlcpy(bufp, t, size);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
strcat(buf, ". ");
|
rsize = strlcpy(bufp, ". ", size);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* hp_p : Trefferpunkte */
|
/* hp_p : Trefferpunkte */
|
||||||
sprintf(buf2, "Trefferpunkte: %d", rc->hitpoints);
|
sprintf(buf2, "Trefferpunkte: %d", rc->hitpoints);
|
||||||
strcat(buf, buf2);
|
|
||||||
|
rsize = strlcpy(bufp, buf2, size);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
|
|
||||||
/* b_armor : Rüstung */
|
/* b_armor : Rüstung */
|
||||||
if (rc->armor > 0){
|
if (rc->armor > 0){
|
||||||
sprintf(buf2, ", Rüstung: %d", rc->armor);
|
sprintf(buf2, ", Rüstung: %d", rc->armor);
|
||||||
strcat(buf, buf2);
|
rsize += strlcpy(bufp, buf2, size);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
}
|
}
|
||||||
/* b_attacke : Angriff */
|
/* b_attacke : Angriff */
|
||||||
sprintf(buf2, ", Angriff: %d", (rc->at_default+rc->at_bonus));
|
sprintf(buf2, ", Angriff: %d", (rc->at_default+rc->at_bonus));
|
||||||
strcat(buf, buf2);
|
rsize = strlcpy(bufp, buf2, size);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
|
|
||||||
/* b_defense : Verteidigung */
|
/* b_defense : Verteidigung */
|
||||||
sprintf(buf2, ", Verteidigung: %d", (rc->df_default+rc->df_bonus));
|
sprintf(buf2, ", Verteidigung: %d", (rc->df_default+rc->df_bonus));
|
||||||
strcat(buf, buf2);
|
rsize = strlcpy(bufp, buf2, size);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
|
|
||||||
strcat(buf, ".");
|
if (size>1) {
|
||||||
|
strcpy(bufp++, ".");
|
||||||
|
--size;
|
||||||
|
}
|
||||||
|
|
||||||
/* b_damage : Schaden */
|
/* b_damage : Schaden */
|
||||||
at_count=0;
|
at_count=0;
|
||||||
|
@ -2381,26 +2416,43 @@ display_race(faction *f, unit *u, const race * rc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (rc->battle_flags & BF_EQUIPMENT) {
|
if (rc->battle_flags & BF_EQUIPMENT) {
|
||||||
strcat(buf, " Kann Waffen benutzen.");
|
rsize = strlcpy(bufp, " Kann Waffen benutzen.", size);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
}
|
}
|
||||||
if (rc->battle_flags & BF_RES_PIERCE) {
|
if (rc->battle_flags & BF_RES_PIERCE) {
|
||||||
strcat(buf, " Ist durch Stichwaffen, Bögen und Armbrüste schwer zu verwunden.");
|
rsize = strlcpy(bufp, " Ist durch Stichwaffen, Bögen und Armbrüste schwer zu verwunden.", size);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
}
|
}
|
||||||
if (rc->battle_flags & BF_RES_CUT) {
|
if (rc->battle_flags & BF_RES_CUT) {
|
||||||
strcat(buf, " Ist durch Hiebwaffen schwer zu verwunden.");
|
rsize = strlcpy(bufp, " Ist durch Hiebwaffen schwer zu verwunden.", size);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
}
|
}
|
||||||
if (rc->battle_flags & BF_RES_BASH) {
|
if (rc->battle_flags & BF_RES_BASH) {
|
||||||
strcat(buf, " Ist durch Schlagwaffen und Katapulte schwer zu verwunden.");
|
rsize = strlcpy(bufp, " Ist durch Schlagwaffen und Katapulte schwer zu verwunden.", size);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
sprintf(buf2, " Hat %d Angriff%s", at_count, (at_count>1)?"e":"");
|
sprintf(buf2, " Hat %d Angriff%s", at_count, (at_count>1)?"e":"");
|
||||||
strcat(buf, buf2);
|
rsize = strlcpy(bufp, buf2, size);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
|
|
||||||
for (a = 0; a < 6; a++) {
|
for (a = 0; a < 6; a++) {
|
||||||
if (rc->attack[a].type != AT_NONE){
|
if (rc->attack[a].type != AT_NONE){
|
||||||
if (a!=0){
|
if (size>2) {
|
||||||
strcat(buf, ", ");
|
if (a!=0) strcat(bufp, ", ");
|
||||||
} else {
|
else strcat(bufp, ": ");
|
||||||
strcat(buf, ": ");
|
size -= 2;
|
||||||
|
bufp += 2;
|
||||||
}
|
}
|
||||||
switch(rc->attack[a].type) {
|
switch(rc->attack[a].type) {
|
||||||
case AT_STANDARD:
|
case AT_STANDARD:
|
||||||
|
@ -2418,11 +2470,17 @@ display_race(faction *f, unit *u, const race * rc)
|
||||||
case AT_STRUCTURAL:
|
case AT_STRUCTURAL:
|
||||||
sprintf(buf2, "ein Angriff, der %s Gebäudeschaden verursacht", rc->attack[a].data.dice);
|
sprintf(buf2, "ein Angriff, der %s Gebäudeschaden verursacht", rc->attack[a].data.dice);
|
||||||
}
|
}
|
||||||
strcat(buf, buf2);
|
rsize = strlcpy(bufp, buf2, size);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
strcat(buf, ".");
|
if (size>1) {
|
||||||
|
strcat(bufp++, ".");
|
||||||
|
--size;
|
||||||
|
}
|
||||||
|
|
||||||
addmessage(0, f, buf, MSG_EVENT, ML_IMPORTANT);
|
addmessage(0, f, buf, MSG_EVENT, ML_IMPORTANT);
|
||||||
|
|
||||||
|
|
|
@ -2749,7 +2749,7 @@ print_stats(battle * b)
|
||||||
faction * f = bf->faction;
|
faction * f = bf->faction;
|
||||||
const char * loc_army = LOC(f->locale, "battle_army");
|
const char * loc_army = LOC(f->locale, "battle_army");
|
||||||
fbattlerecord(b, f, " ");
|
fbattlerecord(b, f, " ");
|
||||||
sprintf(buf, "%s %d: %s", loc_army, side->index,
|
slprintf(buf, sizeof(buf), "%s %d: %s", loc_army, side->index,
|
||||||
seematrix(f, side)
|
seematrix(f, side)
|
||||||
? sidename(side,false) : LOC(f->locale, "unknown_faction"));
|
? sidename(side,false) : LOC(f->locale, "unknown_faction"));
|
||||||
fbattlerecord(b, f, buf);
|
fbattlerecord(b, f, buf);
|
||||||
|
@ -2758,7 +2758,7 @@ print_stats(battle * b)
|
||||||
cv_foreach(s2, b->sides) {
|
cv_foreach(s2, b->sides) {
|
||||||
if (enemy(s2, side)) {
|
if (enemy(s2, side)) {
|
||||||
const char * abbrev = seematrix(f, s2)?sideabkz(s2, false):"-?-";
|
const char * abbrev = seematrix(f, s2)?sideabkz(s2, false):"-?-";
|
||||||
sprintf(buf, "%s%s %s %d(%s)", buf, komma++ ? "," : "", loc_army,
|
slprintf(buf, sizeof(buf), "%s%s %s %d(%s)", buf, komma++ ? "," : "", loc_army,
|
||||||
s2->index, abbrev);
|
s2->index, abbrev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2769,7 +2769,7 @@ print_stats(battle * b)
|
||||||
cv_foreach(s2, b->sides) {
|
cv_foreach(s2, b->sides) {
|
||||||
if (side->enemy[s2->index] & E_ATTACKING) {
|
if (side->enemy[s2->index] & E_ATTACKING) {
|
||||||
const char * abbrev = seematrix(f, s2)?sideabkz(s2, false):"-?-";
|
const char * abbrev = seematrix(f, s2)?sideabkz(s2, false):"-?-";
|
||||||
sprintf(buf, "%s%s %s %d(%s)", buf, komma++ ? "," : "", loc_army,
|
slprintf(buf, sizeof(buf), "%s%s %s %d(%s)", buf, komma++ ? "," : "", loc_army,
|
||||||
s2->index, abbrev);
|
s2->index, abbrev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2781,10 +2781,10 @@ print_stats(battle * b)
|
||||||
battlerecord(b, buf);
|
battlerecord(b, buf);
|
||||||
if (side->bf->faction) {
|
if (side->bf->faction) {
|
||||||
if (side->bf->faction->alliance) {
|
if (side->bf->faction->alliance) {
|
||||||
sprintf(buf, "##### %s (%s/%d)", side->bf->faction->name, itoa36(side->bf->faction->no),
|
slprintf(buf, sizeof(buf), "##### %s (%s/%d)", side->bf->faction->name, itoa36(side->bf->faction->no),
|
||||||
side->bf->faction->alliance?side->bf->faction->alliance->id:0);
|
side->bf->faction->alliance?side->bf->faction->alliance->id:0);
|
||||||
} else {
|
} else {
|
||||||
sprintf(buf, "##### %s (%s)", side->bf->faction->name, itoa36(side->bf->faction->no));
|
slprintf(buf, sizeof(buf), "##### %s (%s)", side->bf->faction->name, itoa36(side->bf->faction->no));
|
||||||
}
|
}
|
||||||
battledebug(buf);
|
battledebug(buf);
|
||||||
}
|
}
|
||||||
|
@ -3037,7 +3037,7 @@ make_fighter(battle * b, unit * u, side * s1, boolean attack)
|
||||||
while (*s) *c++ = (char)toupper(*s++);
|
while (*s) *c++ = (char)toupper(*s++);
|
||||||
*c = 0;
|
*c = 0;
|
||||||
fig->person[0].hp = unit_max_hp(u) * 3;
|
fig->person[0].hp = unit_max_hp(u) * 3;
|
||||||
sprintf(buf, "Eine Stimme ertönt über dem Schlachtfeld. 'DIESES %sKIND IST MEIN. IHR SOLLT ES NICHT HABEN.'. Eine leuchtende Aura umgibt %s", lbuf, unitname(u));
|
slprintf(buf, sizeof(buf), "Eine Stimme ertönt über dem Schlachtfeld. 'DIESES %sKIND IST MEIN. IHR SOLLT ES NICHT HABEN.'. Eine leuchtende Aura umgibt %s", lbuf, unitname(u));
|
||||||
battlerecord(b, buf);
|
battlerecord(b, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3305,6 +3305,7 @@ battle_report(battle * b)
|
||||||
for (bf=b->factions;bf;bf=bf->next) {
|
for (bf=b->factions;bf;bf=bf->next) {
|
||||||
faction * fac = bf->faction;
|
faction * fac = bf->faction;
|
||||||
char * bufp = buf;
|
char * bufp = buf;
|
||||||
|
size_t size = sizeof(buf), rsize;
|
||||||
message * m;
|
message * m;
|
||||||
|
|
||||||
fbattlerecord(b, fac, " ");
|
fbattlerecord(b, fac, " ");
|
||||||
|
@ -3323,24 +3324,43 @@ battle_report(battle * b)
|
||||||
const char * loc_army = LOC(fac->locale, "battle_army");
|
const char * loc_army = LOC(fac->locale, "battle_army");
|
||||||
char buffer[32];
|
char buffer[32];
|
||||||
|
|
||||||
if (komma) bufp += strlcpy(bufp, ", ", sizeof(buf) - (bufp - buf));
|
if (komma) {
|
||||||
|
rsize = strlcpy(bufp, ", ", size);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
|
}
|
||||||
snprintf(buffer, sizeof(buffer), "%s %2d(%s): ",
|
snprintf(buffer, sizeof(buffer), "%s %2d(%s): ",
|
||||||
loc_army, s->index, abbrev);
|
loc_army, s->index, abbrev);
|
||||||
buffer[sizeof(buffer)-1] = 0;
|
buffer[sizeof(buffer)-1] = 0;
|
||||||
|
|
||||||
bufp += strlcpy(bufp, buffer, sizeof(buf) - (bufp - buf));
|
rsize = strlcpy(bufp, buffer, size);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
|
|
||||||
for (r=FIGHT_ROW;r!=NUMROWS;++r) {
|
for (r=FIGHT_ROW;r!=NUMROWS;++r) {
|
||||||
if (alive[r]) {
|
if (alive[r]) {
|
||||||
if (l!=FIGHT_ROW) {
|
if (l!=FIGHT_ROW) {
|
||||||
bufp += strlcpy(bufp, "+", sizeof(buf) - (bufp - buf));
|
rsize = strlcpy(bufp, "+", size);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
}
|
}
|
||||||
while (k--) {
|
while (k--) {
|
||||||
bufp += strlcpy(bufp, "0+", sizeof(buf) - (bufp - buf));
|
rsize = strlcpy(bufp, "0+", size);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
}
|
}
|
||||||
sprintf(buffer, "%d", alive[r]);
|
sprintf(buffer, "%d", alive[r]);
|
||||||
bufp += strlcpy(bufp, buffer, sizeof(buf) - (bufp - buf));
|
|
||||||
k = 0;
|
rsize = strlcpy(bufp, buffer, size);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
|
|
||||||
|
k = 0;
|
||||||
l = r+1;
|
l = r+1;
|
||||||
} else ++k;
|
} else ++k;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3339,7 +3339,9 @@ freadstr(FILE * F, char * start, size_t size)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
*str++ = (char)c;
|
if ((size_t)(str-start+1)<size) {
|
||||||
|
*str++ = (char)c;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,8 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* util includes */
|
/* util includes */
|
||||||
#include <base36.h>
|
#include <util/base36.h>
|
||||||
|
#include <util/bsdstring.h>
|
||||||
|
|
||||||
/* Untote */
|
/* Untote */
|
||||||
|
|
||||||
|
@ -293,15 +294,15 @@ zombie_name(const unit * u)
|
||||||
/* nur 50% aller Namen haben "Nach-Teil", wenn kein Vor-Teil */
|
/* nur 50% aller Namen haben "Nach-Teil", wenn kein Vor-Teil */
|
||||||
|
|
||||||
if (uv < ZOM_VOR) {
|
if (uv < ZOM_VOR) {
|
||||||
strcpy(name, zombie_vor[uv]);
|
strlcpy(name, zombie_vor[uv], sizeof(name));
|
||||||
} else {
|
} else {
|
||||||
name[0] = 0;
|
name[0] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
strcat(name, zombie[uu]);
|
strlcat(name, zombie[uu], sizeof(name));
|
||||||
|
|
||||||
if (un < ZOM_NACH)
|
if (un < ZOM_NACH)
|
||||||
strcat(name, zombie_nach[un]);
|
strlcat(name, zombie_nach[un], sizeof(name));
|
||||||
|
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
#include "order.h"
|
#include "order.h"
|
||||||
#include "skill.h"
|
#include "skill.h"
|
||||||
|
|
||||||
|
#include <util/bsdstring.h>
|
||||||
|
|
||||||
/* libc includes */
|
/* libc includes */
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
@ -107,15 +109,18 @@ getcommand(const order * ord)
|
||||||
#ifdef SHORT_STRINGS
|
#ifdef SHORT_STRINGS
|
||||||
if (kwd!=NOKEYWORD) {
|
if (kwd!=NOKEYWORD) {
|
||||||
const struct locale * lang = ORD_LOCALE(ord);
|
const struct locale * lang = ORD_LOCALE(ord);
|
||||||
strcpy(str, LOC(lang, keywords[kwd]));
|
size_t size = sizeof(sbuffer)-(str-sbuffer);
|
||||||
str += strlen(str);
|
if (text) --size;
|
||||||
|
str += strlcpy(str, LOC(lang, keywords[kwd]), size);
|
||||||
if (text) {
|
if (text) {
|
||||||
*str++ = ' ';
|
*str++ = ' ';
|
||||||
*str = 0;
|
*str = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (text) strcpy(str, text);
|
if (text) {
|
||||||
|
str += strlcpy(str, text, sizeof(sbuffer)-(str-sbuffer));
|
||||||
|
}
|
||||||
return strdup(sbuffer);
|
return strdup(sbuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,8 +43,9 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* util includes */
|
/* util includes */
|
||||||
#include <base36.h>
|
#include <util/bsdstring.h>
|
||||||
#include <goodies.h>
|
#include <util/base36.h>
|
||||||
|
#include <util/goodies.h>
|
||||||
|
|
||||||
/* libc includes */
|
/* libc includes */
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
@ -56,8 +57,6 @@
|
||||||
#include <attributes/otherfaction.h>
|
#include <attributes/otherfaction.h>
|
||||||
#include <attributes/racename.h>
|
#include <attributes/racename.h>
|
||||||
|
|
||||||
#include <util/bsdstring.h>
|
|
||||||
|
|
||||||
const char * g_reportdir;
|
const char * g_reportdir;
|
||||||
|
|
||||||
const char *neue_gebiete[] = {
|
const char *neue_gebiete[] = {
|
||||||
|
@ -166,19 +165,30 @@ report_item(const unit * owner, const item * i, const faction * viewer, const ch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
size_t
|
static size_t
|
||||||
buforder(char * bufp, size_t size, const order * ord)
|
buforder(char * bufp, size_t size, const order * ord)
|
||||||
{
|
{
|
||||||
char * cmd = getcommand(ord);
|
char * cmd = getcommand(ord);
|
||||||
size_t len = 0;
|
size_t tsize = 0, rsize;
|
||||||
len += strlcpy(bufp+len, ", \"", size);
|
|
||||||
len += strlcpy(bufp+len, cmd, size-len);
|
rsize = strlcpy(bufp, ", \"", size);
|
||||||
if (len>=2) {
|
tsize += rsize;
|
||||||
strcpy(bufp+len, "\"");
|
if (rsize>size) rsize = size-1;
|
||||||
++len;
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
|
|
||||||
|
rsize = strlcpy(bufp, cmd, size);
|
||||||
|
tsize += rsize;
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
|
|
||||||
|
if (size>1) {
|
||||||
|
strcpy(bufp, "\"");
|
||||||
|
++tsize;
|
||||||
}
|
}
|
||||||
free(cmd);
|
free(cmd);
|
||||||
return len;
|
return tsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -200,6 +210,7 @@ bufunit(const faction * f, const unit * u, int indent, int mode)
|
||||||
boolean itemcloak = false;
|
boolean itemcloak = false;
|
||||||
static const curse_type * itemcloak_ct = 0;
|
static const curse_type * itemcloak_ct = 0;
|
||||||
static boolean init = false;
|
static boolean init = false;
|
||||||
|
size_t size = sizeof(buf), rsize;
|
||||||
|
|
||||||
if (!init) {
|
if (!init) {
|
||||||
init = true;
|
init = true;
|
||||||
|
@ -212,7 +223,10 @@ bufunit(const faction * f, const unit * u, int indent, int mode)
|
||||||
if (fspecial(u->faction, FS_HIDDEN))
|
if (fspecial(u->faction, FS_HIDDEN))
|
||||||
a_fshidden = a_find(u->attribs, &at_fshidden);
|
a_fshidden = a_find(u->attribs, &at_fshidden);
|
||||||
|
|
||||||
bufp += strlcpy(bufp, unitname(u), sizeof(buf));
|
rsize = strlcpy(bufp, unitname(u), size);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
|
|
||||||
if (!isbattle) {
|
if (!isbattle) {
|
||||||
attrib *a_otherfaction = a_find(u->attribs, &at_otherfaction);
|
attrib *a_otherfaction = a_find(u->attribs, &at_otherfaction);
|
||||||
|
@ -221,31 +235,62 @@ bufunit(const faction * f, const unit * u, int indent, int mode)
|
||||||
attrib *a = a_find(u->attribs, &at_group);
|
attrib *a = a_find(u->attribs, &at_group);
|
||||||
if (a) {
|
if (a) {
|
||||||
group * g = (group*)a->data.v;
|
group * g = (group*)a->data.v;
|
||||||
bufp += strlcpy(bufp, ", ", sizeof(buf)-(bufp-buf));
|
rsize = strlcpy(bufp, ", ", size);
|
||||||
bufp += strlcpy(bufp, groupid(g, f), sizeof(buf)-(bufp-buf));
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
|
rsize = strlcpy(bufp, groupid(g, f), size);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (getarnt) {
|
if (getarnt) {
|
||||||
bufp += strlcpy(bufp, ", ", sizeof(buf)-(bufp-buf));
|
rsize = strlcpy(bufp, ", ", size);
|
||||||
bufp += strlcpy(bufp, LOC(f->locale, "anonymous"), sizeof(buf)-(bufp-buf));
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
|
rsize = strlcpy(bufp, LOC(f->locale, "anonymous"), size);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
} else if (a_otherfaction) {
|
} else if (a_otherfaction) {
|
||||||
faction * otherfaction = get_otherfaction(a_otherfaction);
|
faction * otherfaction = get_otherfaction(a_otherfaction);
|
||||||
if (otherfaction) {
|
if (otherfaction) {
|
||||||
bufp += strlcpy(bufp, ", ", sizeof(buf)-(bufp-buf));
|
rsize = strlcpy(bufp, ", ", size);
|
||||||
bufp += strlcpy(bufp, factionname(otherfaction), sizeof(buf)-(bufp-buf));
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
|
rsize = strlcpy(bufp, factionname(otherfaction), size);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (getarnt) {
|
if (getarnt) {
|
||||||
bufp += strlcpy(bufp, ", ", sizeof(buf)-(bufp-buf));
|
rsize = strlcpy(bufp, ", ", size);
|
||||||
bufp += strlcpy(bufp, LOC(f->locale, "anonymous"), sizeof(buf)-(bufp-buf));
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
|
rsize = strlcpy(bufp, LOC(f->locale, "anonymous"), size);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
} else {
|
} else {
|
||||||
if (a_otherfaction && alliedunit(u, f, HELP_FSTEALTH)) {
|
if (a_otherfaction && alliedunit(u, f, HELP_FSTEALTH)) {
|
||||||
faction * f = get_otherfaction(a_otherfaction);
|
faction * f = get_otherfaction(a_otherfaction);
|
||||||
bufp += sprintf(bufp, ", %s (%s)", factionname(f), factionname(u->faction));
|
bufp += snprintf(bufp, size, ", %s (%s)", factionname(f), factionname(u->faction));
|
||||||
|
size = sizeof(buf)-(bufp-buf);
|
||||||
} else {
|
} else {
|
||||||
bufp += strlcpy(bufp, ", ", sizeof(buf)-(bufp-buf));
|
rsize = strlcpy(bufp, ", ", size);
|
||||||
bufp += strlcpy(bufp, factionname(fv), sizeof(buf)-(bufp-buf));
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
|
rsize = strlcpy(bufp, factionname(fv), size);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -256,81 +301,164 @@ bufunit(const faction * f, const unit * u, int indent, int mode)
|
||||||
if (a) {
|
if (a) {
|
||||||
ugroup *ug = findugroupid(u->faction, a->data.i);
|
ugroup *ug = findugroupid(u->faction, a->data.i);
|
||||||
if (is_ugroupleader(u, ug)) {
|
if (is_ugroupleader(u, ug)) {
|
||||||
strcpy(bufp++, "*");
|
if (size>1) {
|
||||||
|
strcpy(bufp++, "*");
|
||||||
|
--size;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
bufp += strlcpy(bufp, itoa36(ug->id), sizeof(buf)-(bufp-buf));
|
rsize = strlcpy(bufp, itoa36(ug->id), size);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bufp += strlcpy(bufp, ", ", sizeof(buf)-(bufp-buf));
|
rsize = strlcpy(bufp, ", ", size);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
|
|
||||||
if (u->faction != f && a_fshidden && a_fshidden->data.ca[0] == 1 && effskill(u, SK_STEALTH) >= 6) {
|
if (u->faction != f && a_fshidden && a_fshidden->data.ca[0] == 1 && effskill(u, SK_STEALTH) >= 6) {
|
||||||
bufp += strlcpy(bufp, "? ", sizeof(buf)-(bufp-buf));
|
rsize = strlcpy(bufp, "? ", size);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
} else {
|
} else {
|
||||||
bufp += sprintf(bufp, "%d ", u->number);
|
bufp += snprintf(bufp, size, "%d ", u->number);
|
||||||
|
size = sizeof(buf)-(bufp-buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
pzTmp = get_racename(u->attribs);
|
pzTmp = get_racename(u->attribs);
|
||||||
if (pzTmp) {
|
if (pzTmp) {
|
||||||
bufp += strlcpy(bufp, pzTmp, sizeof(buf)-(bufp-buf));
|
rsize = strlcpy(bufp, pzTmp, size);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
if (u->faction==f && fval(u->race, RCF_SHAPESHIFTANY)) {
|
if (u->faction==f && fval(u->race, RCF_SHAPESHIFTANY)) {
|
||||||
bufp += strlcpy(bufp, " (", sizeof(buf)-(bufp-buf));
|
rsize = strlcpy(bufp, " (", size);
|
||||||
bufp += strlcpy(bufp, racename(f->locale, u, u->race), sizeof(buf)-(bufp-buf));
|
if (rsize>size) rsize = size-1;
|
||||||
strcpy(bufp++, ")");
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
|
rsize = strlcpy(bufp, racename(f->locale, u, u->race), size);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
|
if (size>1) {
|
||||||
|
strcpy(bufp++, ")");
|
||||||
|
--size;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
bufp += strlcpy(bufp, racename(f->locale, u, u->irace), sizeof(buf)-(bufp-buf));
|
rsize = strlcpy(bufp, racename(f->locale, u, u->irace), size);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
if (u->faction==f && u->irace!=u->race) {
|
if (u->faction==f && u->irace!=u->race) {
|
||||||
bufp += strlcpy(bufp, " (", sizeof(buf)-(bufp-buf));
|
rsize = strlcpy(bufp, " (", size);
|
||||||
bufp += strlcpy(bufp, racename(f->locale, u, u->race), sizeof(buf)-(bufp-buf));
|
if (rsize>size) rsize = size-1;
|
||||||
strcpy(bufp++, ")");
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
|
rsize = strlcpy(bufp, racename(f->locale, u, u->race), size);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
|
if (size>1) {
|
||||||
|
strcpy(bufp++, ")");
|
||||||
|
--size;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HEROES
|
#ifdef HEROES
|
||||||
if (fval(u, UFL_HERO) && (u->faction == f || omniscient(f))) {
|
if (fval(u, UFL_HERO) && (u->faction == f || omniscient(f))) {
|
||||||
bufp += strlcpy(bufp, ", ", sizeof(buf)-(bufp-buf));
|
rsize = strlcpy(bufp, ", ", size);
|
||||||
bufp += strlcpy(bufp, LOC(f->locale, "hero"), sizeof(buf)-(bufp-buf));
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
|
rsize = strlcpy(bufp, LOC(f->locale, "hero"), size);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
/* status */
|
/* status */
|
||||||
|
|
||||||
if (u->number && (u->faction == f || telepath_see || isbattle)) {
|
if (u->number && (u->faction == f || telepath_see || isbattle)) {
|
||||||
const char * c = locale_string(f->locale, hp_status(u));
|
const char * c = locale_string(f->locale, hp_status(u));
|
||||||
bufp += strlcpy(bufp, ", ", sizeof(buf)-(bufp-buf));
|
rsize = strlcpy(bufp, ", ", size);
|
||||||
bufp += strlcpy(bufp, report_kampfstatus(u, f->locale), sizeof(buf)-(bufp-buf));
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
|
rsize = strlcpy(bufp, report_kampfstatus(u, f->locale), size);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
if (c || fval(u, UFL_HUNGER)) {
|
if (c || fval(u, UFL_HUNGER)) {
|
||||||
bufp += strlcpy(bufp, " (", sizeof(buf)-(bufp-buf));
|
rsize = strlcpy(bufp, " (", size);
|
||||||
if (c) bufp += strlcpy(bufp, c, sizeof(buf)-(bufp-buf));
|
if (rsize>size) rsize = size-1;
|
||||||
if (fval(u, UFL_HUNGER)) {
|
size -= rsize;
|
||||||
if (c) bufp += strlcpy(bufp, ", hungert", sizeof(buf)-(bufp-buf));
|
bufp += rsize;
|
||||||
else bufp += strlcpy(bufp, "hungert", sizeof(buf)-(bufp-buf));
|
if (c) {
|
||||||
|
rsize = strlcpy(bufp, c, size);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
|
}
|
||||||
|
if (fval(u, UFL_HUNGER)) {
|
||||||
|
if (c) rsize = strlcpy(bufp, ", hungert", size);
|
||||||
|
else rsize = strlcpy(bufp, "hungert", size);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
|
}
|
||||||
|
if (size>1) {
|
||||||
|
strcpy(bufp++, ")");
|
||||||
|
--size;
|
||||||
}
|
}
|
||||||
strcpy(bufp++, ")");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (getguard(u)) bufp += strlcpy(bufp, ", bewacht die Region", sizeof(buf)-(bufp-buf));
|
if (getguard(u)) {
|
||||||
|
rsize = strlcpy(bufp, ", bewacht die Region", size);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
|
}
|
||||||
|
|
||||||
if (u->faction==f || telepath_see) {
|
if (u->faction==f || telepath_see) {
|
||||||
attrib * a = a_find(u->attribs, &at_follow);
|
attrib * a = a_find(u->attribs, &at_follow);
|
||||||
if (a) {
|
if (a) {
|
||||||
unit * uf = (unit*)a->data.v;
|
unit * uf = (unit*)a->data.v;
|
||||||
if (uf) {
|
if (uf) {
|
||||||
bufp += strlcpy(bufp, ", folgt ", sizeof(buf)-(bufp-buf));
|
rsize = strlcpy(bufp, ", folgt ", size);
|
||||||
bufp += strlcpy(bufp, itoa36(uf->no), sizeof(buf)-(bufp-buf));
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
|
rsize = strlcpy(bufp, itoa36(uf->no), size);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((b = usiege(u))!=NULL) {
|
if ((b = usiege(u))!=NULL) {
|
||||||
bufp += strlcpy(bufp, ", belagert ", sizeof(buf)-(bufp-buf));
|
rsize = strlcpy(bufp, ", belagert ", size);
|
||||||
bufp += strlcpy(bufp, buildingname(b), sizeof(buf)-(bufp-buf));
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
|
rsize = strlcpy(bufp, buildingname(b), size);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
dh = 0;
|
dh = 0;
|
||||||
if (u->faction == f || telepath_see) {
|
if (u->faction == f || telepath_see) {
|
||||||
for (sk = 0; sk != MAXSKILLS; sk++) {
|
for (sk = 0; sk != MAXSKILLS; sk++) {
|
||||||
bufp += spskill(bufp, sizeof(buf)-(bufp-buf), f->locale, u, sk, &dh, 1);
|
rsize = spskill(bufp, size, f->locale, u, sk, &dh, 1);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -370,17 +498,24 @@ bufunit(const faction * f, const unit * u, int indent, int mode)
|
||||||
int in;
|
int in;
|
||||||
report_item(u, itm, f, &ic, NULL, &in, false);
|
report_item(u, itm, f, &ic, NULL, &in, false);
|
||||||
if (in==0 || ic==NULL) continue;
|
if (in==0 || ic==NULL) continue;
|
||||||
bufp += strlcpy(bufp, ", ", sizeof(buf)-(bufp-buf));
|
rsize = strlcpy(bufp, ", ", size);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
|
|
||||||
if (!dh) {
|
if (!dh) {
|
||||||
bufp += sprintf(bufp, "%s: ", LOC(f->locale, "nr_inventory"));
|
bufp += snprintf(bufp, size, "%s: ", LOC(f->locale, "nr_inventory"));
|
||||||
|
size = sizeof(buf)-(bufp-buf);
|
||||||
dh = 1;
|
dh = 1;
|
||||||
}
|
}
|
||||||
if (in == 1) {
|
if (in == 1) {
|
||||||
bufp += strlcpy(bufp, ic, sizeof(buf)-(bufp-buf));
|
rsize = strlcpy(bufp, ic, size);
|
||||||
} else {
|
} else {
|
||||||
bufp += sprintf(bufp, "%d %s", in, ic);
|
rsize = snprintf(bufp, size, "%d %s", in, ic);
|
||||||
}
|
}
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
}
|
}
|
||||||
if (show!=u->items) while (show) i_free(i_remove(&show, show));
|
if (show!=u->items) while (show) i_free(i_remove(&show, show));
|
||||||
|
|
||||||
|
@ -388,23 +523,29 @@ bufunit(const faction * f, const unit * u, int indent, int mode)
|
||||||
dh = 0;
|
dh = 0;
|
||||||
|
|
||||||
if (is_mage(u) == true) {
|
if (is_mage(u) == true) {
|
||||||
bufp += sprintf(bufp, ". Aura %d/%d", get_spellpoints(u), max_spellpoints(u->region,u));
|
spell_ptr *spt;
|
||||||
{
|
int t = effskill(u, SK_MAGIC);
|
||||||
spell_ptr *spt;
|
bufp += snprintf(bufp, size, ". Aura %d/%d", get_spellpoints(u), max_spellpoints(u->region,u));
|
||||||
int t = effskill(u, SK_MAGIC);
|
size = sizeof(buf)-(bufp-buf);
|
||||||
|
|
||||||
for (spt = get_mage(u)->spellptr;spt; spt = spt->next){
|
for (spt = get_mage(u)->spellptr;spt; spt = spt->next) {
|
||||||
sp = find_spellbyid(spt->spellid);
|
sp = find_spellbyid(spt->spellid);
|
||||||
if (sp->level > t) continue;
|
if (sp->level > t) continue;
|
||||||
if (!dh) {
|
if (!dh) {
|
||||||
bufp += sprintf(bufp, ", %s: ", LOC(f->locale, "nr_spells"));
|
rsize = snprintf(bufp, size, ", %s: ", LOC(f->locale, "nr_spells"));
|
||||||
dh = 1;
|
dh = 1;
|
||||||
} else {
|
} else {
|
||||||
bufp += strlcpy(bufp, ", ", sizeof(buf)-(bufp-buf));
|
rsize = strlcpy(bufp, ", ", size);
|
||||||
}
|
|
||||||
bufp += strlcpy(bufp, spell_name(sp, f->locale), sizeof(buf)-(bufp-buf));
|
|
||||||
}
|
}
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
|
rsize = strlcpy(bufp, spell_name(sp, f->locale), size);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
dh = 0;
|
dh = 0;
|
||||||
for (i = 0; i < MAXCOMBATSPELLS; i++){
|
for (i = 0; i < MAXCOMBATSPELLS; i++){
|
||||||
sp = get_combatspell(u,i);
|
sp = get_combatspell(u,i);
|
||||||
|
@ -412,31 +553,46 @@ bufunit(const faction * f, const unit * u, int indent, int mode)
|
||||||
dh = 1;
|
dh = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(dh){
|
if (dh) {
|
||||||
dh = 0;
|
dh = 0;
|
||||||
bufp += sprintf(bufp, ", %s: ", LOC(f->locale, "nr_combatspells"));
|
bufp += snprintf(bufp, size, ", %s: ", LOC(f->locale, "nr_combatspells"));
|
||||||
|
size = sizeof(buf)-(bufp-buf);
|
||||||
for (i = 0; i < MAXCOMBATSPELLS; i++){
|
for (i = 0; i < MAXCOMBATSPELLS; i++){
|
||||||
if (!dh){
|
if (!dh){
|
||||||
dh = 1;
|
dh = 1;
|
||||||
} else {
|
} else {
|
||||||
bufp += strlcpy(bufp, ", ", sizeof(buf)-(bufp-buf));
|
rsize = strlcpy(bufp, ", ", size);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
}
|
}
|
||||||
sp = get_combatspell(u,i);
|
sp = get_combatspell(u,i);
|
||||||
if (sp) {
|
if (sp) {
|
||||||
int sl;
|
int sl = get_combatspelllevel(u, i);
|
||||||
bufp += strlcpy(bufp, spell_name(sp, u->faction->locale), sizeof(buf)-(bufp-buf));
|
rsize = strlcpy(bufp, spell_name(sp, u->faction->locale), size);
|
||||||
if ((sl = get_combatspelllevel(u,i)) > 0) {
|
if (rsize>size) rsize = size-1;
|
||||||
bufp += sprintf(bufp, " (%d)", sl);
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
|
|
||||||
|
if (sl > 0) {
|
||||||
|
bufp += snprintf(bufp, size, " (%d)", sl);
|
||||||
|
size = sizeof(buf)-(bufp-buf);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
bufp += strlcpy(bufp, LOC(f->locale, "nr_nospells"), sizeof(buf)-(bufp-buf));
|
rsize = strlcpy(bufp, LOC(f->locale, "nr_nospells"), size);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef LASTORDER
|
#ifdef LASTORDER
|
||||||
if (!isbattle && u->lastorder) {
|
if (!isbattle && u->lastorder) {
|
||||||
bufp += buforder(bufp, sizeof(buf)-(bufp-buf), u->lastorder);
|
rsize = buforder(bufp, size, u->lastorder);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (!isbattle) {
|
if (!isbattle) {
|
||||||
|
@ -447,10 +603,13 @@ bufunit(const faction * f, const unit * u, int indent, int mode)
|
||||||
while (ord) {
|
while (ord) {
|
||||||
if (is_repeated(ord)) {
|
if (is_repeated(ord)) {
|
||||||
if (printed==0) {
|
if (printed==0) {
|
||||||
bufp += buforder(bufp, sizeof(buf)-(bufp-buf), ord);
|
rsize = buforder(bufp, size, ord);
|
||||||
} else if (printed==1) {
|
} else if (printed==1) {
|
||||||
bufp += strlcpy(bufp, ", ...", sizeof(buf)-(bufp-buf));
|
rsize = strlcpy(bufp, ", ...", size);
|
||||||
}
|
}
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
++printed;
|
++printed;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -464,19 +623,38 @@ bufunit(const faction * f, const unit * u, int indent, int mode)
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|
||||||
if (u->display && u->display[0]) {
|
if (u->display && u->display[0]) {
|
||||||
bufp += strlcpy(bufp, "; ", sizeof(buf)-(bufp-buf));
|
rsize = strlcpy(bufp, "; ", size);
|
||||||
bufp += strlcpy(bufp, u->display, sizeof(buf)-(bufp-buf));
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
|
|
||||||
|
rsize = strlcpy(bufp, u->display, size);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
|
|
||||||
i = u->display[strlen(u->display) - 1];
|
i = u->display[strlen(u->display) - 1];
|
||||||
}
|
}
|
||||||
if (i != '!' && i != '?' && i != '.')
|
if (i != '!' && i != '?' && i != '.') {
|
||||||
strcpy(bufp++, ".");
|
if (size>1) {
|
||||||
|
strcpy(bufp++, ".");
|
||||||
|
--size;
|
||||||
|
}
|
||||||
|
}
|
||||||
pzTmp = uprivate(u);
|
pzTmp = uprivate(u);
|
||||||
if (u->faction == f && pzTmp) {
|
if (u->faction == f && pzTmp) {
|
||||||
bufp += strlcpy(bufp, " (Bem: ", sizeof(buf)-(bufp-buf));
|
rsize = strlcpy(bufp, " (Bem: ", size);
|
||||||
bufp += strlcpy(bufp, pzTmp, sizeof(buf)-(bufp-buf));
|
if (rsize>size) rsize = size-1;
|
||||||
bufp += strlcpy(bufp, ")", sizeof(buf)-(bufp-buf));
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
|
rsize = strlcpy(bufp, pzTmp, size);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
|
rsize = strlcpy(bufp, ")", size);
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
dh=0;
|
dh=0;
|
||||||
|
@ -652,41 +830,83 @@ bufunit_ugroupleader(const faction * f, const unit * u, int indent, int mode)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
spskill(char * buffer, size_t siz, const struct locale * lang, const struct unit * u, skill_t sk, int *dh, int days)
|
spskill(char * buffer, size_t size, const struct locale * lang, const struct unit * u, skill_t sk, int *dh, int days)
|
||||||
{
|
{
|
||||||
char * bufp = buffer;
|
char * bufp = buffer;
|
||||||
int i, effsk;
|
int i, effsk;
|
||||||
|
size_t rsize;
|
||||||
|
size_t tsize = 0;
|
||||||
|
|
||||||
if (!u->number) return 0;
|
if (!u->number) return 0;
|
||||||
|
|
||||||
if (!has_skill(u, sk)) return 0;
|
if (!has_skill(u, sk)) return 0;
|
||||||
|
|
||||||
bufp += strlcpy(bufp, ", ", siz);
|
rsize = strlcpy(bufp, ", ", size);
|
||||||
|
tsize += rsize;
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
|
|
||||||
if (!*dh) {
|
if (!*dh) {
|
||||||
bufp += strlcpy(bufp, LOC(lang, "nr_skills"), siz-(bufp-buffer));
|
rsize = strlcpy(bufp, LOC(lang, "nr_skills"), size);
|
||||||
bufp += strlcpy(bufp, ": ", sizeof(buf)-(bufp-buf));
|
tsize += rsize;
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
|
|
||||||
|
rsize = strlcpy(bufp, ": ", size);
|
||||||
|
tsize += rsize;
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
|
|
||||||
*dh = 1;
|
*dh = 1;
|
||||||
}
|
}
|
||||||
bufp += strlcpy(bufp, skillname(sk, lang), siz-(bufp-buffer));
|
rsize = strlcpy(bufp, skillname(sk, lang), size);
|
||||||
strcpy(bufp++, " ");
|
tsize += rsize;
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
|
|
||||||
|
rsize = strlcpy(bufp, " ", size);
|
||||||
|
tsize += rsize;
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
|
|
||||||
if (sk == SK_MAGIC){
|
if (sk == SK_MAGIC){
|
||||||
if (find_magetype(u) != M_GRAU){
|
if (find_magetype(u) != M_GRAU){
|
||||||
bufp += strlcpy(bufp, LOC(lang, mkname("school", magietypen[find_magetype(u)])), siz-(bufp-buffer));
|
rsize = strlcpy(bufp, LOC(lang, mkname("school", magietypen[find_magetype(u)])), size);
|
||||||
strcpy(bufp++, " ");
|
tsize += rsize;
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
|
|
||||||
|
rsize = strlcpy(bufp, " ", size);
|
||||||
|
tsize += rsize;
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sk == SK_STEALTH && fval(u, UFL_STEALTH)) {
|
if (sk == SK_STEALTH && fval(u, UFL_STEALTH)) {
|
||||||
i = u_geteffstealth(u);
|
i = u_geteffstealth(u);
|
||||||
if(i>=0) {
|
if (i>=0) {
|
||||||
bufp += sprintf(bufp, "%d/", i);
|
rsize = slprintf(bufp, size, "%d/", i);
|
||||||
|
tsize += rsize;
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
effsk = effskill(u, sk);
|
effsk = effskill(u, sk);
|
||||||
bufp += sprintf(bufp, "%d", effsk);
|
rsize = slprintf(bufp, size, "%d", effsk);
|
||||||
|
tsize += rsize;
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
|
|
||||||
if(u->faction->options & Pow(O_SHOWSKCHANGE)) {
|
if(u->faction->options & Pow(O_SHOWSKCHANGE)) {
|
||||||
skill *skill = get_skill(u, sk);
|
skill *skill = get_skill(u, sk);
|
||||||
|
@ -700,11 +920,15 @@ spskill(char * buffer, size_t siz, const struct locale * lang, const struct unit
|
||||||
oldeff = max(0, oldeff);
|
oldeff = max(0, oldeff);
|
||||||
diff = effsk - oldeff;
|
diff = effsk - oldeff;
|
||||||
|
|
||||||
if(diff != 0) {
|
if (diff != 0) {
|
||||||
bufp += sprintf(bufp, " (%s%d)", (diff>0)?"+":"", diff);
|
rsize = slprintf(bufp, size, " (%s%d)", (diff>0)?"+":"", diff);
|
||||||
|
tsize += rsize;
|
||||||
|
if (rsize>size) rsize = size-1;
|
||||||
|
size -= rsize;
|
||||||
|
bufp += rsize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return bufp-buffer;
|
return tsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -223,7 +223,6 @@ rds(FILE * F, char **ds)
|
||||||
fprintf(stderr, "Die Datei bricht vorzeitig ab.\n");
|
fprintf(stderr, "Die Datei bricht vorzeitig ab.\n");
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
assert(s <= buffer + DISPLAYSIZE + 1);
|
|
||||||
rc(F);
|
rc(F);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,26 +230,20 @@ rds(FILE * F, char **ds)
|
||||||
|
|
||||||
while (nextc != '"') {
|
while (nextc != '"') {
|
||||||
if (nextc == EOF) {
|
if (nextc == EOF) {
|
||||||
assert(s <= buffer + DISPLAYSIZE + 1);
|
|
||||||
*s = 0;
|
*s = 0;
|
||||||
fprintf(stderr, "Die Datei bricht vorzeitig ab.\n");
|
fprintf(stderr, "Die Datei bricht vorzeitig ab.\n");
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
*s++ = (char)nextc;
|
if (s - buffer < DISPLAYSIZE) {
|
||||||
if (s - buffer > DISPLAYSIZE) {
|
*s++ = (char)nextc;
|
||||||
assert(s <= buffer + DISPLAYSIZE + 1);
|
}
|
||||||
*s = 0;
|
|
||||||
log_error(("\nDer String %s wurde nicht terminiert.\n", s));
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
rc(F);
|
rc(F);
|
||||||
}
|
}
|
||||||
|
|
||||||
rc(F);
|
rc(F);
|
||||||
assert(s <= buffer + DISPLAYSIZE + 1);
|
|
||||||
*s = 0;
|
*s = 0;
|
||||||
if (ds) {
|
if (ds) {
|
||||||
(*ds) = realloc(*ds, sizeof(char) * (strlen(buffer) + 1));
|
*ds = realloc(*ds, sizeof(char) * (strlen(buffer) + 1));
|
||||||
strcpy(*ds, buffer);
|
strcpy(*ds, buffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,12 @@
|
||||||
extern size_t strlcpy(char *dst, const char *src, size_t siz);
|
extern size_t strlcpy(char *dst, const char *src, size_t siz);
|
||||||
extern size_t strlcat(char * dst, const char * src, size_t siz);
|
extern size_t strlcat(char * dst, const char * src, size_t siz);
|
||||||
# endif
|
# endif
|
||||||
|
# define HAVE_STRLCPY
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !defined(HAVE_STRLPRINTF)
|
||||||
|
# define HAVE_STRLPRINTF
|
||||||
|
# define slprintf snprintf
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue