Crossfire Server, Branches 1.12  R18729
loop.c File Reference
#include <global.h>
#include <sproto.h>
#include <sockproto.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <loader.h>
#include <newserver.h>
+ Include dependency graph for loop.c:

Go to the source code of this file.

Data Structures

struct  client_cmd_mapping
 
struct  player_cmd_mapping
 

Typedefs

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

Functions

static void block_until_new_connection (void)
 
void do_server (void)
 
void handle_client (socket_struct *ns, player *pl)
 
static int is_fd_valid (int fd)
 
void request_info_cmd (char *buf, int len, socket_struct *ns)
 

Variables

static const struct
client_cmd_mapping 
client_commands []
 
static const struct
player_cmd_mapping 
player_commands []
 
unsigned long todtick
 

Detailed Description

Main client/server loops.

Date
2003-12-02

Mainly deals with initialization and higher level socket maintenance (checking for lost connections and if data has arrived.) The reading of data is handled in lowlevel.c

Definition in 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 80 of file loop.c.

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

Prototype for functions used to handle player actions.

Definition at line 89 of file loop.c.

Function Documentation

static void block_until_new_connection ( void  )
static

Waits for new connection

Definition at line 309 of file loop.c.

References Settings::fastclock, flush_old_maps(), init_sockets, llevInfo, LOG(), Socket_Info::max_filedescriptor, metaserver_update(), reset_sleep(), settings, socket_info, tick_the_clock(), and watchdog().

Referenced by do_server().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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. Will be set to Ns_Dead if read error.
plplayer associated to the socket. If NULL, only commands in client_cmd_mapping will be checked.

Definition at line 200 of file loop.c.

References SockList::buf, client_cmd_mapping::cmdname, player_cmd_mapping::cmdname, client_cmd_mapping::cmdproc, player_cmd_mapping::cmdproc, socket_struct::fd, player_cmd_mapping::flag, socket_struct::inbuf, SockList::len, llevDebug, LOG(), obj::name, Ns_Dead, pl::ob, SockList_NullTerminate(), SockList_ReadPacket(), SockList_ResetRead(), obj::speed_left, ST_PLAYING, pl::state, and socket_struct::status.

Referenced by do_server(), and handle_newcs_player().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 368 of file loop.c.

Referenced by do_server().

+ Here is the caller graph for this function:

void request_info_cmd ( char *  buf,
int  len,
socket_struct ns 
)

request_info_cmd is sort of a meta command. There is some specific request of information, but we call other functions to provide that information.

Definition at line 146 of file loop.c.

References send_class_info(), send_class_list(), send_exp_table(), send_image_info(), send_image_sums(), send_race_info(), send_race_list(), send_skill_info(), send_spell_paths(), Send_With_Handling(), SockList_AddString(), SockList_Init(), and SockList_Term().

+ Here is the call graph for this function:

Variable Documentation

const struct client_cmd_mapping client_commands[]
static
Initial value:
= {
{ "addme", add_me_cmd },
{ "askface", send_face_cmd },
{ "requestinfo", request_info_cmd },
{ "setfacemode", set_face_mode_cmd },
{ "setsound", set_sound_cmd },
{ "setup", set_up_cmd },
{ "version", version_cmd },
{ "toggleextendedinfos", toggle_extended_infos_cmd },
{ "toggleextendedtext", toggle_extended_text_cmd },
{ "asksmooth", ask_smooth_cmd },
{ NULL, NULL }
}
void set_face_mode_cmd(char *buf, int len, socket_struct *ns)
Definition: image.c:53
void version_cmd(char *buf, int len, socket_struct *ns)
Definition: request.c:621
void set_sound_cmd(char *buf, int len, socket_struct *ns)
Definition: request.c:656
void set_up_cmd(char *buf, int len, socket_struct *ns)
Definition: request.c:116
void toggle_extended_infos_cmd(char *buf, int len, socket_struct *ns)
Definition: request.c:359
void request_info_cmd(char *buf, int len, socket_struct *ns)
Definition: loop.c:146
void ask_smooth_cmd(char *buf, int len, socket_struct *ns)
Definition: request.c:473
void toggle_extended_text_cmd(char *buf, int len, socket_struct *ns)
Definition: request.c:398
void add_me_cmd(char *buf, int len, socket_struct *ns)
Definition: request.c:320
void send_face_cmd(char *buff, int len, socket_struct *ns)
Definition: image.c:80

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

Definition at line 127 of file loop.c.

const struct player_cmd_mapping player_commands[]
static
Initial value:
= {
{ "examine", examine_cmd, 1 },
{ "apply", apply_cmd, 1 },
{ "move", move_cmd, 1 },
{ "reply", reply_cmd, 0 },
{ "lookat", look_at_cmd, 1 },
{ "mapredraw", map_redraw_cmd, 0 },
{ "inscribe", inscribe_scroll_cmd, 0 },
{ NULL, NULL, 0 }
}
void map_redraw_cmd(char *buf, int len, player *pl)
Definition: request.c:662
void(* func_uint8_int_pl)(char *, int, player *)
Definition: loop.c:89
void look_at_cmd(char *buf, int len, player *pl)
Definition: item.c:754
void inscribe_scroll_cmd(char *buf, int len, player *pl)
Definition: item.c:841
void new_player_cmd(uint8 *buf, int len, player *pl)
Definition: request.c:492
void mark_item_cmd(uint8 *data, int len, player *pl)
Definition: item.c:655
void lock_item_cmd(uint8 *data, int len, player *pl)
Definition: item.c:615
void examine_cmd(char *buf, int len, player *pl)
Definition: item.c:562
void apply_cmd(char *buf, int len, player *pl)
Definition: item.c:581
void reply_cmd(char *buf, int len, player *pl)
Definition: request.c:555
void move_cmd(char *buf, int len, player *pl)
Definition: request.c:694

Dispatch tables for the server.

CmdMapping is the dispatch table for the server, used in handle_client, which gets called when the client has input. All commands called here use the same parameter form (char *data, int len, int clientnum. We do implicit casts, because the data that is being passed is unsigned (pretty much needs to be for binary data), however, most of these treat it only as strings, so it makes things easier to cast it here instead of a bunch of times in the function itself. flag is 1 if the player must be in the playing state to issue the command, 0 if they can issue it at any time.Commands sent by the client reacting to player's actions.

Definition at line 112 of file loop.c.

unsigned long todtick

Ingame time

Definition at line 418 of file init.c.

Referenced by init_clocks(), and write_todclock().