X-Git-Url: http://git.pond.sub.org/?p=empserver;a=blobdiff_plain;f=include%2Ffile.h;h=07dae38dadfd23f50ca81d75c2abe0aac98cdd0b;hp=a4e2a7e390e866e01313b50b3082badf91c258f8;hb=HEAD;hpb=6eec00105048eb50617b366eecfa40c664200595 diff --git a/include/file.h b/include/file.h index a4e2a7e39..07dae38da 100644 --- a/include/file.h +++ b/include/file.h @@ -1,6 +1,6 @@ /* * Empire - A multi-player, client/server Internet based war game. - * Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak, + * Copyright (C) 1986-2021, Dave Pare, Jeff Bailey, Thomas Ruschak, * Ken Stevens, Steve McClure, Markus Armbruster * * Empire is free software: you can redistribute it and/or modify @@ -27,7 +27,7 @@ * file.h: Describes Empire tables (`files' for historical reasons) * * Known contributors to this file: - * Markus Armbruster, 2005-2010 + * Markus Armbruster, 2005-2016 */ #ifndef FILE_H @@ -38,7 +38,8 @@ struct empfile { /* Members with immutable values */ int uid; /* Table ID */ - char *name; /* Empire name (e.g., "treaty") */ + char *name; /* Empire name (e.g., "land") */ + char *pretty_name; /* prettier name, e.g. "land unit" */ char *file; /* file name, relative to gamedir for game state, to builtindir for config */ struct castr *cadef; /* table column selectors (column meta-data) */ @@ -54,7 +55,7 @@ struct empfile { /* flags bits EFF_MEM, EFF_PRIVATE, EFF_NOTIME also fixed then */ /* Members whose values may vary throughout operation */ - int baseid; /* id of first entry in cache */ + int baseid; /* ID of first entry in cache */ int cids; /* # entries in cache */ int fids; /* # entries in table */ int fd; /* file descriptor, -1 if not open */ @@ -62,21 +63,22 @@ struct empfile { /* User callbacks, may all be null */ /* - * Called after element initialization. ELT is the element. + * Called after element initialization. @elt is the element. * May modify the element. */ void (*oninit)(void *elt); /* - * Called after read. ID is the element id, and ELT is the + * Called after read. @id is the element ID, and @elt is the * element read. May modify the element. Modifications are * visible to caller of ef_read(), but have no effect on the file. */ void (*postread)(int id, void *elt); /* - * Called before write. ID is the element id, OLD is the element - * being updated (null unless it is cached) and ELT is the element - * being written. May modify the element. Modifications will be - * visible to caller of ef_write() and are written to the file. + * Called before write. @id is the element ID, @old is the + * element being updated (null unless it is cached) and @elt is + * the element being written. May modify the element. + * Modifications will be visible to caller of ef_write() and are + * written to the file. */ void (*prewrite)(int id, void *old, void *elt); /* @@ -85,7 +87,7 @@ struct empfile { void (*onresize)(int type); }; -struct emptypedstr { +struct ef_typedstr { signed ef_type: 8; unsigned seqno: 12; unsigned generation: 12; @@ -99,7 +101,7 @@ struct emptypedstr { * The remaining flags record how the table is being used. */ /* Immutable flags, fixed at compile-time */ -/* Dereferencing entry address cast to struct emptypedstr * is safe */ +/* Dereferencing entry address cast to struct ef_typedstr * is safe */ #define EFF_TYPED bit(0) /* * EFF_XY / EFF_OWNER / EFF_GROUP assert that coordinates / owner / @@ -129,6 +131,12 @@ struct emptypedstr { /* Create table file, clobbering any existing file */ #define EFF_CREATE bit(16) +/* + * A value larger than any struct empfile member size where member + * cadef is not null. + */ +#define EF_WITH_CADEF_MAX_ENTRY_SIZE 1024 + /* * Empire `file types' * These are really table IDs. Some tables are backed by files, some @@ -145,10 +153,12 @@ enum { EF_LAND, EF_NUKE, EF_NEWS, - EF_TREATY, EF_TRADE, EF_POWER, EF_NATION, + EF_RELAT, + EF_CONTACT, + EF_REJECT, EF_LOAN, EF_MAP, EF_BMAP, @@ -192,8 +202,8 @@ enum { EF_RESOURCES, EF_RETREAT_FLAGS, EF_SECTOR_NAVIGATION, + EF_SECTOR_CHR_FLAGS, EF_SHIP_CHR_FLAGS, - EF_TREATY_FLAGS, /* Views */ EF_COUNTRY, /* Number of types: */ @@ -209,6 +219,7 @@ extern void ef_make_stale(void); extern void ef_mark_fresh(int, void *); extern void *ef_ptr(int, int); extern char *ef_nameof(int); +extern char *ef_nameof_pretty(int); extern time_t ef_mtime(int); extern int ef_open(int, int); extern int ef_open_view(int); @@ -217,6 +228,7 @@ extern int ef_flush(int); extern void ef_blank(int, int, void *); extern int ef_write(int, int, void *); extern void ef_set_uid(int, void *, int); +extern int ef_typedstr_eq(struct ef_typedstr *, struct ef_typedstr *); extern int ef_extend(int, int); extern int ef_ensure_space(int, int, int); extern int ef_id_limit(int); @@ -225,7 +237,8 @@ extern int ef_nelem(int); extern int ef_flags(int); extern int ef_byname(char *); extern int ef_byname_from(char *, int *); -extern int ef_verify(int); +extern int ef_verify_config(void); +extern int ef_verify_state(int); extern int ef_elt_byname(int, char *); extern struct empfile empfile[EF_MAX + 1];