Atrinik Server  4.0
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
server.c File Reference
#include <global.h>
#include <toolkit/string.h>
#include <toolkit/packet.h>
#include <toolkit/socket_crypto.h>
#include <server.h>
#include <player.h>
#include <object.h>
#include <ban.h>

Go to the source code of this file.

Data Structures

struct  csocket_entry
 
struct  socket_command
 

Macros

#define SOCKET_COMMAND_PLAYER_ONLY   1
 
#define SOCKET_SERVER_PLAYER_MAX_COMMANDS   15
 

Typedefs

typedef enum socket_server_id socket_server_id_t
 
typedef struct csocket_entry csocket_entry_t
 
typedef struct socket_command socket_command_t
 

Enumerations

enum  socket_server_id {
  SOCKET_SERVER_ID_CLASSIC_V4, SOCKET_SERVER_ID_SECURE_V4, SOCKET_SERVER_ID_CLASSIC_V6, SOCKET_SERVER_ID_SECURE_V6,
  SOCKET_SERVER_ID_NUM
}
 

Functions

 TOOLKIT_API (DEPENDS(socket), IMPORTS(logger))
 
 CASSERT_ARRAY (socket_commands, SERVER_CMD_NROF)
 
static bool server_socket_id_is_secure (socket_server_id_t id)
 
static bool server_socket_id_is_v6 (socket_server_id_t id)
 
static bool server_socket_id_is_v4 (socket_server_id_t id)
 
 TOOLKIT_INIT_FUNC (socket_server)
 
TOOLKIT_INIT_FUNC_FINISH TOOLKIT_DEINIT_FUNC (socket_server)
 
static
TOOLKIT_DEINIT_FUNC_FINISH
bool 
socket_server_handle_command (socket_struct *cs, player *pl, uint8_t *data, size_t len)
 
static void socket_server_csocket_create (socket_t *server_socket)
 
static void socket_server_csocket_free (csocket_entry_t *entry)
 
static void socket_server_csocket_drop (csocket_entry_t *entry)
 
void socket_server_handle_client (player *pl)
 
bool socket_server_remove (socket_struct *cs)
 
static bool server_socket_csocket_is_zombie (socket_struct *cs)
 
static void socket_server_csocket_read (socket_struct *cs)
 
static void socket_server_csocket_write (socket_struct *cs)
 
void socket_server_process (void)
 
void socket_server_post_process (void)
 

Variables

static fd_set fds_read
 
static fd_set fds_write
 
static fd_set fds_error
 
static socket_t * server_sockets [SOCKET_SERVER_ID_NUM]
 
static csocket_entry_tclient_sockets
 
static const socket_command_t socket_commands []
 

Detailed Description

Socket server implementation.

Author
Alex Tokar

Definition in file server.c.

Macro Definition Documentation

#define SOCKET_SERVER_PLAYER_MAX_COMMANDS   15

Maximum number of commands a player is able to issue in a single iteration.

Definition at line 58 of file server.c.

Typedef Documentation

Structure to provide link linkage for client socket entries.

Structure that defines a single socket command type.

Function Documentation

static bool server_socket_csocket_is_zombie ( socket_struct cs)
inlinestatic

Checks if the specified client socket is in zombie state and takes care of increasing the zombie tick counter until the socket is marked as dead.

Parameters
csClient socket.
Returns
True if the client socket is in zombie state, false otherwise.

Definition at line 580 of file server.c.

static bool server_socket_id_is_secure ( socket_server_id_t  id)
inlinestatic

Checks if the specified socket ID is for a secure connection.

Parameters
idID to check.
Returns
Whether the ID is for a secure connection.

Definition at line 154 of file server.c.

static bool server_socket_id_is_v4 ( socket_server_id_t  id)
inlinestatic

Checks if the specified socket ID is for an IPv4 connection.

Parameters
idID to check.
Returns
Whether the ID is for an IPv4 connection.

Definition at line 191 of file server.c.

static bool server_socket_id_is_v6 ( socket_server_id_t  id)
inlinestatic

Checks if the specified socket ID is for an IPv6 connection.

Parameters
idID to check.
Returns
Whether the ID is for an IPv6 connection.

Definition at line 172 of file server.c.

static void socket_server_csocket_drop ( csocket_entry_t entry)
static

Drops the specified client socket entry connection.

Essentially the same as socket_server_csocket_free(), but logs a message.

Parameters
entryEntry to drop.

Definition at line 485 of file server.c.

static void socket_server_csocket_free ( csocket_entry_t entry)
static

Frees the specified client socket entry.

Parameters
entryEntry to free.

Definition at line 468 of file server.c.

static void socket_server_csocket_read ( socket_struct cs)
inlinestatic

Read data from the specified client socket and handle complete commands.

Parameters
csClient socket.

Definition at line 602 of file server.c.

static void socket_server_csocket_write ( socket_struct cs)
inlinestatic

Write out the packet queue to the specified client socket.

Parameters
csClient socket.

Definition at line 677 of file server.c.

void socket_server_handle_client ( player pl)

Handle client commands.

We only get here once there is input, and only do basic connection checking.

Parameters
plPlayer to handle commands for.

Definition at line 503 of file server.c.

static TOOLKIT_DEINIT_FUNC_FINISH bool socket_server_handle_command ( socket_struct cs,
player pl,
uint8_t *  data,
size_t  len 
)
static

Attempt to handle a command from the client.

Parameters
csClient socket.
plPlayer associated with the client. Can be NULL if the client is not playing yet.
dataNetwork data buffer containing the command to handle.
lenLength of the command.
Returns
True if the command was handled, false otherwise.

Definition at line 383 of file server.c.

void socket_server_post_process ( void  )

Update player socket-related data, render the map for them, etc. Afterwards, attempt to write to the players' clients.

Definition at line 902 of file server.c.

void socket_server_process ( void  )

Accept incoming connections, read data from clients and write data to clients.

Definition at line 722 of file server.c.

bool socket_server_remove ( socket_struct cs)

Removes the specified client socket from the server's managed list of clients that haven't logged in yet. The client socket remains valid afterwards.

This is used from the login routine, because as soon as the client logs in, they go to the player list, which is also walked through in the server socket code, thus, it needs to be removed from the other list.

Parameters
csClient socket to remove.
Returns
True on success, false on failure (no such client socket).

Definition at line 556 of file server.c.

TOOLKIT_INIT_FUNC_FINISH TOOLKIT_DEINIT_FUNC ( socket_server  )

Deinitialize the socket server API.

Definition at line 355 of file server.c.

TOOLKIT_INIT_FUNC ( socket_server  )

Initialize the socket server API.

Definition at line 204 of file server.c.

Variable Documentation

csocket_entry_t* client_sockets
static

List of client sockets that are not yet playing.

Definition at line 112 of file server.c.

fd_set fds_error
static

File descriptors with errors.

Definition at line 104 of file server.c.

fd_set fds_read
static

File descriptors that have data available.

Definition at line 96 of file server.c.

fd_set fds_write
static

File descriptors that are ready to receive data.

Definition at line 100 of file server.c.

socket_t* server_sockets[SOCKET_SERVER_ID_NUM]
static

The server's listening sockets.

Definition at line 108 of file server.c.

const socket_command_t socket_commands[]
static
Initial value:
= {
{socket_command_control, 0},
{socket_command_ask_face, 0},
{socket_command_setup, 0},
{socket_command_version, 0},
{socket_command_clear, 0},
{socket_command_request_update, 0},
{socket_command_keepalive, 0},
{socket_command_account, 0},
{socket_command_item_examine, SOCKET_COMMAND_PLAYER_ONLY},
{socket_command_item_apply, SOCKET_COMMAND_PLAYER_ONLY},
{socket_command_item_move, SOCKET_COMMAND_PLAYER_ONLY},
{socket_command_player_cmd, SOCKET_COMMAND_PLAYER_ONLY},
{socket_command_item_lock, SOCKET_COMMAND_PLAYER_ONLY},
{socket_command_item_mark, SOCKET_COMMAND_PLAYER_ONLY},
{socket_command_fire, SOCKET_COMMAND_PLAYER_ONLY},
{socket_command_quickslot, SOCKET_COMMAND_PLAYER_ONLY},
{socket_command_quest_list, SOCKET_COMMAND_PLAYER_ONLY},
{socket_command_move_path, SOCKET_COMMAND_PLAYER_ONLY},
{socket_command_combat, SOCKET_COMMAND_PLAYER_ONLY},
{socket_command_talk, SOCKET_COMMAND_PLAYER_ONLY},
{socket_command_move, SOCKET_COMMAND_PLAYER_ONLY},
{socket_command_target, SOCKET_COMMAND_PLAYER_ONLY},
}
#define SOCKET_COMMAND_PLAYER_ONLY
Definition: server.c:51
void socket_command_ask_resource(socket_struct *ns, player *pl, uint8_t *data, size_t len, size_t pos)
Definition: request.c:3108
void socket_command_crypto(socket_struct *ns, player *pl, uint8_t *data, size_t len, size_t pos)
Definition: request.c:3046

Defines all the possible socket commands.

Definition at line 117 of file server.c.