Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

Commit a847e64e authored by deuce's avatar deuce

Map all of the files, allow passing SIZE_T_MAX as the length to request the

map to covewr the entire file.
parent 1d802152
#include <sys/limits.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <string.h>
#include <errno.h>
#include <stdbool.h>
......@@ -24,12 +27,63 @@ struct map_file onliner_map;
struct onliner *onliner;
struct onliner *onliners;
struct map_file object_map;
struct object *objects;
struct map_file king_map;
struct king *king;
struct map_file abody_map;
struct object *abody;
struct map_file armor_map;
struct armor *armor;
struct map_file arms_map;
struct object *arms;
struct map_file body_map;
struct object *body;
struct map_file drink_map;
struct object *drink;
struct map_file face_map;
struct object *face;
struct map_file feets_map;
struct object *feets;
struct map_file food_map;
struct object *food;
struct map_file hands_map;
struct object *hands;
struct map_file head_map;
struct object *head;
struct map_file legs_map;
struct object *legs;
struct map_file neck_map;
struct object *neck;
struct map_file rings_map;
struct object *rings;
struct map_file shields_map;
struct object *shields;
struct map_file waist_map;
struct object *waist;
struct map_file weapons_map;
struct object *weapons;
struct map_file weapon_map;
struct weapon *weapon;
struct map_file monster_map;
struct monster *monster;
static size_t align(size_t val)
{
int pagesize=getpagesize();
......@@ -41,7 +95,14 @@ static size_t align(size_t val)
void map_file(char *name, struct map_file *map, size_t len)
{
struct stat st;
map->fd=open(name, O_RDWR);
if(len==SIZE_T_MAX) {
if(fstat(map->fd, &st)!=0)
CRASH;
len=st.st_size;
}
if(map->fd == -1)
CRASHF("Error opening map \"%s\"\n", name);
map->len=align(len);
......@@ -59,16 +120,72 @@ void unmap_file(struct map_file *map)
void open_files(void)
{
map_file("poison.dat", &poison_map, MAX_POISON * sizeof(struct poison));
poison=poison_map.data;
map_file("players.dat", &player_map, MAX_PLAYERS * sizeof(struct player));
players=player_map.data;
map_file("npcs.dat", &npc_map, MAX_NPCS * sizeof(struct player));
map_file("abody.dat", &abody_map, SIZE_T_MAX);
abody=abody_map.data;
map_file("armor.dat", &armor_map, SIZE_T_MAX);
armor=armor_map.data;
map_file("arms.dat", &arms_map, SIZE_T_MAX);
arms=arms_map.data;
map_file("body.dat", &body_map, SIZE_T_MAX);
body=body_map.data;
map_file("drink.dat", &drink_map, SIZE_T_MAX);
drink=drink_map.data;
map_file("face.dat", &face_map, SIZE_T_MAX);
face=face_map.data;
map_file("feets.dat", &feets_map, SIZE_T_MAX);
feets=feets_map.data;
map_file("food.dat", &food_map, SIZE_T_MAX);
food=food_map.data;
map_file("hands.dat", &hands_map, SIZE_T_MAX);
hands=hands_map.data;
map_file("head.dat", &head_map, SIZE_T_MAX);
head=head_map.data;
map_file("king.dat", &king_map, SIZE_T_MAX);
king=king_map.data;
map_file("legs.dat", &legs_map, SIZE_T_MAX);
legs=legs_map.data;
map_file("monsters.dat", &monster_map, SIZE_T_MAX);
monster=monster_map.data;
map_file("neck.dat", &neck_map, SIZE_T_MAX);
neck=neck_map.data;
map_file("npcs.dat", &npc_map, SIZE_T_MAX);
npcs=npc_map.data;
map_file("objects.dat", &object_map, MAX_OBJECTS * sizeof(struct object));
objects=object_map.data;
map_file("onliner.dat", &onliner_map, MAX_OBJECTS * sizeof(struct onliner));
map_file("onliner.dat", &onliner_map, SIZE_T_MAX);
onliners=onliner_map.data;
map_file("king.dat", &king_map, MAX_OBJECTS * sizeof(struct king));
king=king_map.data;
map_file("players.dat", &player_map, SIZE_T_MAX);
players=player_map.data;
map_file("poison.dat", &poison_map, SIZE_T_MAX);
poison=poison_map.data;
map_file("rings.dat", &rings_map, SIZE_T_MAX);
rings=rings_map.data;
map_file("shields.dat", &shields_map, SIZE_T_MAX);
shields=shields_map.data;
map_file("waist.dat", &waist_map, SIZE_T_MAX);
waist=waist_map.data;
map_file("weapon.dat", &weapon_map, SIZE_T_MAX);
weapon=weapon_map.data;
map_file("weapons.dat", &weapons_map, SIZE_T_MAX);
weapons=weapons_map.data;
}
......@@ -341,11 +341,65 @@ extern struct player *npcs;
extern struct map_file onliner_map;
extern struct onliner *onliner;
extern struct onliner *onliners;
extern struct map_file object_map;
extern struct object *objects;
extern struct map_file king_map;
extern struct king *king;
extern struct map_file abody_map;
extern struct object *abody;
extern struct map_file armor_map;
extern struct armor *armor;
extern struct map_file arms_map;
extern struct object *arms;
extern struct map_file body_map;
extern struct object *body;
extern struct map_file drink_map;
extern struct object *drink;
extern struct map_file face_map;
extern struct object *face;
extern struct map_file feets_map;
extern struct object *feets;
extern struct map_file food_map;
extern struct object *food;
extern struct map_file hands_map;
extern struct object *hands;
extern struct map_file head_map;
extern struct object *head;
extern struct map_file legs_map;
extern struct object *legs;
extern struct map_file neck_map;
extern struct object *neck;
extern struct map_file rings_map;
extern struct object *rings;
extern struct map_file shields_map;
extern struct object *shields;
extern struct map_file waist_map;
extern struct object *waist;
extern struct map_file weapons_map;
extern struct object *weapons;
extern struct map_file weapon_map;
extern struct weapon *weapon;
extern struct map_file monster_map;
extern struct monster *monster;
void open_files(void);
void map_file(char *name, struct map_file *map, size_t len);
void unmap_file(struct map_file *map);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment