Crossfire Server  1.75.0
hiscore.cpp File Reference

Hiscore handling functions. More...

#include "global.h"
#include <errno.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "sproto.h"
#include "output_file.h"

Go to the source code of this file.

Data Structures

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

Macros

#define _GNU_SOURCE
 

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_tables [MAX_SKILLS+1]
 The highscore table. More...
 

Detailed Description

Hiscore handling functions.

Definition in file hiscore.cpp.

Macro Definition Documentation

◆ _GNU_SOURCE

#define _GNU_SOURCE

Definition at line 19 of file hiscore.cpp.

Function Documentation

◆ add_score()

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 188 of file hiscore.cpp.

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

Referenced by hiscore_check().

◆ draw_one_high_score()

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 158 of file hiscore.cpp.

References buf, score::exp, FMT64, score::killer, score::maplevel, score::maxgrace, score::maxhp, score::maxsp, score::name, score::position, and score::title.

Referenced by hiscore_check(), and hiscore_display().

◆ get_score()

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 113 of file hiscore.cpp.

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

Referenced by hiscore_load().

◆ hiscore_check()

◆ hiscore_display()

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). Other options: -s:[name] – show the table for the skill 'name' instead of overall -s – show a short list for each skill

Definition at line 451 of file hiscore.cpp.

References draw_ext_info(), draw_ext_info_format(), draw_one_high_score(), score_table::entry, score::exp, HIGHSCORE_LENGTH, llevDebug, LOG(), MAX_BUF, MAX_SKILLS, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_HISCORE, score::name, NDI_UNIQUE, and strcasestr_local.

Referenced by command_hiscore().

◆ hiscore_init()

void hiscore_init ( void  )

Initializes the module.

Note
There is one table per skill, as well as the "Overall" table, each saved in a file in .../var/crossfire/hiscores/[skill_name] or as configured in config.h.

Definition at line 296 of file hiscore.cpp.

References c, score::exp, get_skill_client_code(), HIGHSCORE_DIR, hiscore_load(), Settings::localdir, MAX_BUF, MAX_SKILLS, score::name, OLD_HIGHSCORE, settings, and skill_names.

Referenced by init().

◆ hiscore_load()

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 250 of file hiscore.cpp.

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

Referenced by hiscore_init().

◆ hiscore_save()

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 81 of file hiscore.cpp.

References buf, score_table::entry, score_table::fname, HIGHSCORE_LENGTH, MAX_BUF, score::name, of_close(), of_open(), and put_score().

Referenced by add_score().

◆ put_score()

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 71 of file hiscore.cpp.

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

Referenced by hiscore_save().

Variable Documentation

◆ hiscore_tables

score_table hiscore_tables[MAX_SKILLS+1]
static

The highscore table.

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

Definition at line 59 of file hiscore.cpp.