TinyMUSH 3.3
TinyMUSH Server
Loading...
Searching...
No Matches
Functions | Variables
db_rw.c File Reference

flatfile implementation More...

#include "config.h"
#include "constants.h"
#include "typedefs.h"
#include "macros.h"
#include "externs.h"
#include "prototypes.h"
#include <stdbool.h>
#include <ctype.h>
#include <fcntl.h>
#include <string.h>
Include dependency graph for db_rw.c:

Functions

BOOLEXPgetboolexp1 (FILE *f)
 Get boolean subexpression from file. More...
 
BOOLEXPgetboolexp (FILE *f)
 Read a boolean expression from the flat file. More...
 
int unscramble_attrnum (int attrnum)
 Fix up attribute numbers from foreign muds. More...
 
void get_list (FILE *f, dbref i, int new_strings)
 Read attribute list from flat file. More...
 
void putbool_subexp (FILE *f, BOOLEXP *b)
 Write a boolean sub-expression to the flat file. More...
 
void putboolexp (FILE *f, BOOLEXP *b)
 Write boolean expression to the flat file. More...
 
void upgrade_flags (FLAG *flags1, FLAG *flags2, FLAG *flags3, dbref thing, int db_format, int db_version)
 Convert foreign flags to MUSH format. More...
 
void efo_convert (void)
 Fix things up for Exits-From-Objects. More...
 
void fix_mux_zones (void)
 Convert MUX-style zones to 3.0-style zones. More...
 
void fix_typed_quotas (void)
 Explode standard quotas into typed quotas. More...
 
dbref db_read_flatfile (FILE *f, int *db_format, int *db_version, int *db_flags)
 Read a flatfile. More...
 
int db_read (void)
 Read a DB. More...
 
int db_write_object_out (FILE *f, dbref i, int db_format __attribute__((unused)), int flags, int *n_atrt)
 Write an object to a DB. More...
 
dbref db_write_flatfile (FILE *f, int format, int version)
 Write a db to Flat File. More...
 
dbref db_write (void)
 Write DB to file. More...
 
FILE * db_module_flatfile (char *filename, bool wrflag)
 Open a file pointer for a module to use when writing a flatfile. More...
 

Variables

struct objectdb
 
int g_version
 
int g_format
 
int g_flags
 
int anum_alc_top
 
int * used_attrs_table
 

Detailed Description

flatfile implementation

Author
TinyMUSH development team (https://github.com/TinyMUSH)
Version
3.3
Date
2020-12-28

Function Documentation

◆ db_module_flatfile()

FILE * db_module_flatfile ( char *  filename,
bool  wrflag 
)

Open a file pointer for a module to use when writing a flatfile.

Parameters
filenameFilename
wrflagOpen for write or read access.
Returns
FILE*

◆ db_read()

int db_read ( void  )

Read a DB.

Returns
int

Fetch the database info

Unroll the data returned

Load the attribute numbers

Unroll the data into flags and name

Houston, we have a problem

Load the object structures

Unroll the data into objnum and object

We read the entire object structure in and copy it into place

Check to see if it's a player

◆ db_read_flatfile()

dbref db_read_flatfile ( FILE *  f,
int *  db_format,
int *  db_version,
int *  db_flags 
)

Read a flatfile.

Parameters
fFile
db_formatDB Format
db_versionDB Version
db_flagsDB Flags
Returns
dbref

Misc tag

Record number of players

MUX and MUSH header, 2nd char selects type

The following things are common across 2.x, MUX, and 3.0.

Otherwise extract feature flags

More generic switch.

3.0 VERSION

2.0 VERSION

MUX VERSION

SIZE

USER-NAMED ATTRIBUTE

< skip ':'

If not AF_ODARK, is AF_VISUAL. Strip AF_ODARK.

OPEN USER ATTRIBUTE SLOT

NEXT ATTR TO ALLOC WHEN NO FREELIST

MUX and MUSH entries

CONTENTS and EXITS

EXITS

LINK

NEXT

LOCK

OWNER

PARENT

PENNIES

FLAGS

ATTRIBUTES

check to see if it's a player

EOF marker

◆ db_write()

dbref db_write ( void  )

Write DB to file.

Returns
dbref

Lock the database

Write database information

Roll up various paramaters needed for startup into one record. This should be the only data record of its type

"TM3" is our unique key

Dump user-named attribute info

First, calculate the number of attribute entries we can fit in a block, allowing for some minor DBM key overhead. This should not change unless the size of VNAME_SIZE or LBUF_SIZE changes, in which case you'd have to reload anyway

Step through the attribute number array, writing stuff in 'num' sized chunks

Only write the dirty attribute numbers and clear the flag

No valid attributes in this block, delete it

Something is dirty in this block, write all of the attribute numbers in this block

j is an offset of attribute numbers into the current block

Write the block: Block number is our key

Dump object structures using the same block-based method we use to dump attribute numbers

Step through the object structure array, writing stuff in 'num' sized chunks

We assume you always do a dbck before dump, and Going objects are really destroyed!

Only write the dirty objects and clear the flag

No valid objects in this block, delete it

Something is dirty in this block, write all of the objects in this block

j is an offset of object numbers into the current block

Write the block: Block number is our key

Unlock the database

◆ db_write_flatfile()

dbref db_write_flatfile ( FILE *  f,
int  format,
int  version 
)

Write a db to Flat File.

Parameters
fFile
formatFormat of the flatfile
versionVersion of the flatfile
Returns
dbref

Attribute cleaning, if standalone.

Non-user defined attributes are always considered used.

Walk the database. Mark all the attribute numbers in use.

Count up how many attributes we're deleting.

Walk the table we've created of used statuses. When we find free slots, walk backwards to the first used slot at the end of the table. Write the number of the free slot into that used slot. Keep a mapping of what things used to be.

Count up our renumbers.

The new end of the attribute table is the first thing we've renumbered.

Write database information. TinyMUSH 2 wrote '+V', MUX wrote '+X', 3.0 writes '+T'.

Dump user-named attribute info

Dump object and attribute info

◆ db_write_object_out()

int db_write_object_out ( FILE *  f,
dbref  i,
int db_format   __attribute__(unused),
int  flags,
int *  n_atrt 
)

Write an object to a DB.

Parameters
fFile
iDBref of object
db_formatDB Format
flagsFlags
n_atrtNumber of attributes
Returns
int

write the attribute list

◆ efo_convert()

void efo_convert ( void  )

Fix things up for Exits-From-Objects.

swap Exits and Link

◆ fix_mux_zones()

void fix_mux_zones ( void  )

Convert MUX-style zones to 3.0-style zones.

For all objects in the database where Zone(thing) != NOTHING, set the CONTROL_OK flag on them.

For all objects in the database that are ZMOs (that have other objects zoned to them), copy the EnterLock of those objects to the ControlLock.

◆ fix_typed_quotas()

void fix_typed_quotas ( void  )

Explode standard quotas into typed quotas.

If we have a pre-2.2 or MUX database, only the QUOTA and RQUOTA attributes exist. For simplicity's sake, we assume that players will have the same quotas for all types, equal to the current value. This is going to produce incorrect values for RQUOTA; this is easily fixed by a @quota/fix done from within-game.

If we have a early beta 2.2 release, we have quotas which are spread out over ten attributes. We're going to have to grab those, make the new quotas, and then delete the old attributes.

◆ get_list()

void get_list ( FILE *  f,
dbref  i,
int  new_strings 
)

Read attribute list from flat file.

Parameters
fFile
iDBref
new_stringsNew string

read # then string

Store the attr

Silently discard

ignore newlines. They're due to v(r).

end of list

We've found a bad spot. I hope things aren't too bad.

◆ getboolexp()

BOOLEXP * getboolexp ( FILE *  f)

Read a boolean expression from the flat file.

Parameters
fFile
Returns
BOOLEXP*

parse error, we lose

◆ getboolexp1()

BOOLEXP * getboolexp1 ( FILE *  f)

Get boolean subexpression from file.

Parameters
fFile
Returns
BOOLEXP*

obsolete NOTHING key, eat it

if last character is : then this is an attribute lock. A last character of / means an eval lock

dbref or attribute

This is either an attribute, eval, or constant lock. Constant locks are of the form <num>, while attribute and eval locks are of the form <anam-or-anum>:<string> or <aname-or-anum>/<string> respectively. The characters <nl>, |, and & terminate the string.

Look the name up as an attribute. If not found, create a new attribute.

if last character is : then this is an attribute lock. A last character of / means an eval lock

bomb out

◆ putbool_subexp()

void putbool_subexp ( FILE *  f,
BOOLEXP b 
)

Write a boolean sub-expression to the flat file.

Parameters
fFile
bBoolean sub-expression

◆ putboolexp()

void putboolexp ( FILE *  f,
BOOLEXP b 
)

Write boolean expression to the flat file.

Parameters
fFile
bBoolean expression

◆ unscramble_attrnum()

int unscramble_attrnum ( int  attrnum)

Fix up attribute numbers from foreign muds.

Parameters
attrnumattribute numbers
Returns
int

TinyMUSH 2.2: Deal with different attribute numbers.

◆ upgrade_flags()

void upgrade_flags ( FLAG *  flags1,
FLAG *  flags2,
FLAG *  flags3,
dbref  thing,
int  db_format,
int  db_version 
)

Convert foreign flags to MUSH format.

Parameters
flags1Flag
flags2Flag
flags3Flag
thingDBref of thing
db_formatDB Format
db_versionDB Version

TinyMUSH 2.2 to 3.0 flag conversion

This is the unimplemented TICKLER flag.

TinyMUX to 3.0 flag conversion

This used to be an object set NO_COMMAND. We unset the flag.

And if it wasn't NO_COMMAND, then it should be COMMANDS.

This used to be the COMPRESS flag, which didn't do anything.

Players set MONITOR should be set WATCHER as well.

Native TinyMUSH 3.0 database. The only thing we have to do is clear the redirection flag, as nothing is ever redirected at startup.

< this flag is now obsolete

Variable Documentation

◆ db

struct object* db
extern

Restart definitions struct database