Crossfire Server, Trunk  R20513
Data Structures | Typedefs | Functions | Variables
hiscore.c File Reference

Hiscore handling functions. More...

#include "global.h"
#include <errno.h>
#include <string.h>
#include "sproto.h"
#include "output_file.h"
Include dependency graph for hiscore.c:

Go to the source code of this file.

Data Structures

struct  score_table
 A highscore table. More...
 
struct  scr
 The score structure is used when treating new high-scores. More...
 

Typedefs

typedef struct scr score
 The score structure is used when treating new high-scores. More...
 

Functions

static void add_score (score_table *table, score *new_score, score *old_score)
 Adds the given score-structure to the high-score list, but only if it was good enough to deserve a place. More...
 
static char * draw_one_high_score (const score *sc, char *buf, size_t size)
 Formats one score to display to a player. More...
 
static int get_score (char *bp, score *sc)
 The opposite of put_score(), get_score reads from the given buffer into a static score structure, and returns a pointer to it. More...
 
void hiscore_check (object *op, int quiet)
 Checks if player should enter the hiscore, and if so writes her into the list. More...
 
void hiscore_display (object *op, int max, const char *match)
 Displays the high score file. More...
 
void hiscore_init (void)
 Initializes the module. More...
 
static void hiscore_load (score_table *table)
 Loads the hiscore_table from the highscore file. More...
 
static void hiscore_save (const score_table *table)
 Saves the highscore_table into the highscore file. More...
 
static void put_score (const score *sc, char *buf, size_t size)
 Writes the given score structure to specified buffer. More...
 

Variables

static score_table hiscore_table
 The highscore table. More...
 

Detailed Description

Hiscore handling functions.

Definition in file hiscore.c.

Typedef Documentation

typedef struct scr score

The score structure is used when treating new high-scores.

Function Documentation

static void add_score ( score_table table,
score new_score,
score old_score 
)
static

Adds the given score-structure to the high-score list, but only if it was good enough to deserve a place.

Parameters
tablethe highscore table to add to.
new_scorescore to add.
old_scorereturns the old player score.

Definition at line 181 of file hiscore.c.

References score_table::entry, scr::exp, HIGHSCORE_LENGTH, hiscore_save(), scr::name, and scr::position.

Referenced by hiscore_check().

Here is the call graph for this function:

Here is the caller graph for this function:

static char* draw_one_high_score ( const score sc,
char *  buf,
size_t  size 
)
static

Formats one score to display to a player.

Parameters
scscore to format.
bufbuffer to write to. Will contain suitably formatted score.
sizelength of buf.
Returns
buf.

Definition at line 154 of file hiscore.c.

References scr::exp, FMT64, scr::killer, scr::maplevel, scr::maxgrace, scr::maxhp, scr::maxsp, scr::name, scr::position, snprintf, and scr::title.

Referenced by hiscore_check(), and hiscore_display().

Here is the caller graph for this function:

static int get_score ( char *  bp,
score sc 
)
static

The opposite of put_score(), get_score reads from the given buffer into a static score structure, and returns a pointer to it.

Parameters
bpstring to parse.
screturns the parsed score.
Returns
whether parsing was successful

Definition at line 109 of file hiscore.c.

References BIG_NAME, scr::exp, FMT64, scr::killer, scr::maplevel, scr::maxgrace, scr::maxhp, scr::maxsp, scr::name, split_string(), and scr::title.

Referenced by hiscore_load().

Here is the call graph for this function:

Here is the caller graph for this function:

void hiscore_check ( object op,
int  quiet 
)

Checks if player should enter the hiscore, and if so writes her into the list.

Parameters
opplayer to check.
quietIf set, don't print anything out - used for periodic updates during game play or when player unexpected quits - don't need to print anything in those cases
Note
check_score() has been renamed to hiscore_check()

Definition at line 302 of file hiscore.c.

References add_score(), BIG_NAME, obj::contr, draw_ext_info(), draw_one_high_score(), scr::exp, liv::exp, FLAG_WAS_WIZ, HIGHSCORE_LENGTH, scr::killer, pl::killer, obj::map, scr::maplevel, MAX_BUF, scr::maxgrace, liv::maxgrace, scr::maxhp, liv::maxhp, scr::maxsp, liv::maxsp, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_HISCORE, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_ERROR, scr::name, obj::name, mapdef::name, pl::name_changed, NDI_UNIQUE, mapdef::path, player_get_title(), scr::position, QUERY_FLAG, obj::stats, and scr::title.

Referenced by apply_savebed(), command_kick2(), emergency_save(), key_confirm_quit(), kill_player_permadeath(), leave(), and process_players1().

Here is the call graph for this function:

Here is the caller graph for this function:

void hiscore_display ( object op,
int  max,
const char *  match 
)

Displays the high score file.

Parameters
opplayer asking for the score file.
maxmaximum number of scores to display.
matchif non-empty, will only print players with name or title containing the string (non case-sensitive).
Note
display_high_score() has been renamed to hiscore_display()

Definition at line 386 of file hiscore.c.

References draw_ext_info(), draw_one_high_score(), score_table::entry, HIGHSCORE_LENGTH, llevDebug, LOG(), MAX_BUF, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_HISCORE, scr::name, NDI_UNIQUE, strcasestr_local, and scr::title.

Referenced by command_hiscore().

Here is the call graph for this function:

Here is the caller graph for this function:

void hiscore_init ( void  )

Initializes the module.

Definition at line 284 of file hiscore.c.

References score_table::fname, HIGHSCORE, hiscore_load(), Settings::localdir, settings, and snprintf.

Referenced by init().

Here is the call graph for this function:

Here is the caller graph for this function:

static void hiscore_load ( score_table table)
static

Loads the hiscore_table from the highscore file.

Parameters
tablethe highscore table to load.

Definition at line 243 of file hiscore.c.

References score_table::entry, score_table::fname, get_score(), HIGHSCORE_LENGTH, llevDebug, llevError, llevInfo, LOG(), MAX_BUF, and scr::position.

Referenced by hiscore_init().

Here is the call graph for this function:

Here is the caller graph for this function:

static void hiscore_save ( const score_table table)
static

Saves the highscore_table into the highscore file.

Parameters
tablethe highscore table to save.

Definition at line 75 of file hiscore.c.

References score_table::entry, score_table::fname, HIGHSCORE_LENGTH, llevDebug, LOG(), MAX_BUF, scr::name, of_close(), of_open(), and put_score().

Referenced by add_score().

Here is the call graph for this function:

Here is the caller graph for this function:

static void put_score ( const score sc,
char *  buf,
size_t  size 
)
static

Writes the given score structure to specified buffer.

Parameters
scscore to write.
bufbuffer to write to.
sizebuf's size.

Definition at line 65 of file hiscore.c.

References scr::exp, FMT64, scr::killer, scr::maplevel, scr::maxgrace, scr::maxhp, scr::maxsp, scr::name, snprintf, and scr::title.

Referenced by hiscore_save().

Here is the caller graph for this function:

Variable Documentation

score_table hiscore_table
static

The highscore table.

Unused entries are set to zero (except for position).

Definition at line 53 of file hiscore.c.