Atrinik Server 2.5
Data Structures | Defines | Typedefs | Functions | Variables
socket/loop.c File Reference
#include <global.h>

Go to the source code of this file.

Data Structures

struct  client_cmd_mapping
struct  player_cmd_mapping

Defines

#define FREE_SOCKET(i)

Typedefs

typedef void(* func_uint8_int_ns )(char *, int, socket_struct *)
typedef void(* func_uint8_int_pl )(char *, int, player *)

Functions

static int check_client_command (socket_struct *ns)
static void fill_command_buffer (socket_struct *ns)
static int check_command (socket_struct *ns, player *pl)
void handle_client (socket_struct *ns, player *pl)
void watchdog ()
void remove_ns_dead_player (player *pl)
static int is_fd_valid (int fd)
void doeric_server ()
void doeric_server_write ()

Variables

static fd_set tmp_read
static fd_set tmp_exceptions
static fd_set tmp_write
static struct player_cmd_mapping player_commands []
static struct client_cmd_mapping client_commands []

Detailed Description

Mainly deals with initialization and higher level socket maintenance (checking for lost connections and if data has arrived).

Definition in file loop.c.


Define Documentation

#define FREE_SOCKET (   i)
Value:
free_newsocket(&init_sockets[(i)]); \
    init_sockets[(i)].status = Ns_Avail; \
    socket_info.nconns--;

Common way to free a socket. Frees the socket from init_sockets, sets its status to Ns_Avail and decrements number of connections.

Definition at line 386 of file loop.c.


Typedef Documentation

typedef void(* func_uint8_int_ns)(char *, int, socket_struct *)

Prototype for functions the client sends without player interaction.

Definition at line 36 of file loop.c.

typedef void(* func_uint8_int_pl)(char *, int, player *)

Prototype for functions used to handle player actions.

Definition at line 49 of file loop.c.


Function Documentation

static int check_client_command ( socket_struct ns) [static]

Used to check whether read data is a client command in fill_command_buffer().

Parameters:
nsSocket.
Returns:
1 if the read data is a client command, 0 otherwise.

Definition at line 105 of file loop.c.

static int check_command ( socket_struct ns,
player pl 
) [static]

Used to check whether parsed data is valid client or player command in handle_client().

Parameters:
nsSocket.
plPlayer. Can be NULL, in which case player commands are not considered.
Returns:
1 if the parsed data is a valid command, 0 otherwise.

Definition at line 179 of file loop.c.

void doeric_server ( )

This checks the sockets for input and exceptions, does the right thing.

There are 2 lists we need to look through - init_sockets is a list

Definition at line 396 of file loop.c.

void doeric_server_write ( )

Write to players' sockets.

Definition at line 664 of file loop.c.

static void fill_command_buffer ( socket_struct ns) [static]

Fill a command buffer with data we read from socket.

Parameters:
nsSocket.

Definition at line 146 of file loop.c.

void handle_client ( socket_struct ns,
player pl 
)

Handle client commands.

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

Parameters:
nsSocket sending the command.
plPlayer associated to the socket. If NULL, only commands in client_commands will be checked.

Definition at line 247 of file loop.c.

static int is_fd_valid ( int  fd) [static]

Checks if file descriptor is valid.

Parameters:
fdFile descriptor to check.
Returns:
1 if fd is valid, 0 else.

Definition at line 374 of file loop.c.

void remove_ns_dead_player ( player pl)

Remove a player from the game that has been disconnected by logging out, the socket connection was interrupted, etc.

Parameters:
plThe player to remove.

Definition at line 315 of file loop.c.

void watchdog ( )

Tell the Atrinik watchdog program that we are still alive by sending datagrams to port 13325 on localhost.

See also:
atrinik_watchdog

Definition at line 289 of file loop.c.


Variable Documentation

Initial value:
{
    {"addme",       AddMeCmd},
    {"askface",     SendFaceCmd},
    {"setup",       SetUp},
    {"version",     VersionCmd},
    {"rf",          RequestFileCmd},
    {"clr", command_clear_cmds},
    {"setsound", SetSound},
    {"upf", cmd_request_update},
    {"ka", cmd_keepalive},
    {NULL, NULL}
}

Commands sent directly by the client, when connecting or needed.

Definition at line 87 of file loop.c.

Initial value:
{
    {"ex",          ExamineCmd, 0},
    {"ap",          ApplyCmd, 0},
    {"mv",          MoveCmd, 0},
    {"reply",       ReplyCmd, 0},
    {"cm",          PlayerCmd, 0},
    {"lock",        (func_uint8_int_pl) LockItem, 0},
    {"mark",        (func_uint8_int_pl) MarkItem, 0},
    {"/fire", command_fire_old, 0},
    {"fire", (func_uint8_int_pl) command_fire, 0},
    {"nc",          command_new_char, 0},
    {"qs",          (func_uint8_int_pl) QuickSlotCmd, 0},
    {"shop",        ShopCmd, 0},
    {"qlist",       QuestListCmd, 0},
    {"mp", (func_uint8_int_pl) command_move_path, 0},
    {"rd", (func_uint8_int_pl) cmd_ready, 0},
    {"pc", (func_uint8_int_pl) cmd_password_change, 0},
    {NULL, NULL, 0}
}

Commands sent by the client, based on player's actions.

Definition at line 65 of file loop.c.