Atrinik Server  4.0
Data Structures | Typedefs | Functions | Variables
ban.c File Reference
#include <global.h>
#include <toolkit/string.h>
#include <ban.h>

Go to the source code of this file.

Data Structures

struct  ban
 

Typedefs

typedef struct ban ban_t
 

Functions

static void ban_save (void)
 
static void ban_free (void)
 
static void ban_entry_free (ban_t *ban)
 
static const char * ban_entry_save (const ban_t *ban, char *buf, size_t len)
 
 TOOLKIT_API (DEPENDS(socket), IMPORTS(shstr), IMPORTS(string))
 
 TOOLKIT_INIT_FUNC (ban)
 
TOOLKIT_INIT_FUNC_FINISH TOOLKIT_DEINIT_FUNC (ban)
 
static void ban_entry_new (const char *name, const char *account, const struct sockaddr_storage *addr, unsigned short plen)
 
static ban_tban_entry_find (const char *name, const char *account, const struct sockaddr_storage *addr, unsigned short plen)
 
static ban_error_t ban_parse (const char *str, char *name, size_t name_len, char *account, size_t account_len, struct sockaddr_storage *addr, unsigned short *plen)
 
ban_error_t ban_add (const char *str)
 
ban_error_t ban_remove (const char *str)
 
bool ban_check (socket_struct *ns, const char *name)
 
void ban_list (object *op)
 
void ban_reset (void)
 
const char * ban_strerror (ban_error_t errnum)
 

Variables

static ban_tbans = NULL
 
static size_t bans_num = 0
 

Detailed Description

Banning related functions.

It is possible to use the /ban operator command to ban a specified player, account or IP from the game.

Syntax for banning is: "player account[ address/plen]", where player is name of the player to ban (or * to match any player), account name to match (or * to match any account), address is an IP address (IPv4, or IPv6 if the server supports it) and plen is the subnet to match.

Author
Alex Tokar

Definition in file ban.c.

Typedef Documentation

typedef struct ban ban_t

The ban structure.

Function Documentation

ban_error_t ban_add ( const char *  str)

Adds a new ban.

Parameters
strBan command parameters.
Returns
BAN_OK on success, one of the errors defined in ban_error_t on failure.

Definition at line 363 of file ban.c.

bool ban_check ( socket_struct ns,
const char *  name 
)

Checks if the specified connection is banned from the game.

Parameters
nsThe connection.
namePlayer name to check. Can be NULL.
Returns
True if the connection is banned, false otherwise.

Definition at line 441 of file ban.c.

static ban_t* ban_entry_find ( const char *  name,
const char *  account,
const struct sockaddr_storage *  addr,
unsigned short  plen 
)
static

Find an existing ban entry.

Parameters
namePlayer name, * for any match.
accountAccount name, * for any match.
addrBinary representation of an IP address.
plenPrefix length (the subnet).
Returns
Pointer to the found ban structure, NULL otherwise.

Definition at line 208 of file ban.c.

static void ban_entry_free ( ban_t ban)
static

Frees the specified ban entry.

Parameters
banBan entry to free.

Definition at line 248 of file ban.c.

static void ban_entry_new ( const char *  name,
const char *  account,
const struct sockaddr_storage *  addr,
unsigned short  plen 
)
static

Creates a new ban entry.

Parameters
namePlayer name. Can be NULL.
accountAccount name. Can be NULL.
addrBinary representation of an IP address.
plenPrefix length (the subnet).

Definition at line 181 of file ban.c.

static const char * ban_entry_save ( const ban_t ban,
char *  buf,
size_t  len 
)
static

Create a text representation of a single ban entry.

Parameters
banPointer to the ban entry.
bufWhere to store the text representation.
lenSize of 'buf'.
Returns
'buf' on success, NULL on failure.

Definition at line 272 of file ban.c.

static void ban_free ( void  )
static

Frees all the bans.

Definition at line 153 of file ban.c.

void ban_list ( object op)

List existing bans to the specified player.

Parameters
opPlayer.

Definition at line 479 of file ban.c.

static ban_error_t ban_parse ( const char *  str,
char *  name,
size_t  name_len,
char *  account,
size_t  account_len,
struct sockaddr_storage *  addr,
unsigned short *  plen 
)
static

Parse ban command parameters into supported components.

Parameters
strThe command parameters.
[out]nameWhere to store player name.
name_lenSize of 'name'.
[out]accountWhere to store account name.
account_lenSize of 'account'.
[out]addrWhere to store binary representation of an IP address.
[out]plenPrefix length (the subnet).
Returns
BAN_OK on success, one of the errors defined in ban_error_t on failure.

Definition at line 313 of file ban.c.

ban_error_t ban_remove ( const char *  str)

Remove an existing ban.

Parameters
strBan command parameters.
Returns
BAN_OK on success, one of the errors defined in ban_error_t on failure.

Definition at line 393 of file ban.c.

void ban_reset ( void  )

Removes all existing bans.

Definition at line 502 of file ban.c.

static TOOLKIT_DEINIT_FUNC_FINISH void ban_save ( void  )
static

Saves all the bans to the bans file.

Definition at line 122 of file ban.c.

const char* ban_strerror ( ban_error_t  errnum)

Create string representation of an error code.

Parameters
errnumError code. Cannot be BAN_OK.
Returns
String representation, never NULL.

Definition at line 515 of file ban.c.

Variable Documentation

ban_t* bans = NULL
static

Array of all the bans.

Definition at line 64 of file ban.c.

size_t bans_num = 0
static

Number of bans.

Definition at line 69 of file ban.c.