Crossfire Server, Branch 1.12  R12190
Data Structures | Typedefs | Functions | Variables
loop.c File Reference

Main client/server loops. More...

#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
 Definition of a function the client sends without player interaction. More...
struct  player_cmd_mapping
 Definition of a function called in reaction to player's action. More...

Typedefs

typedef void(* func_uint8_int_ns )(char *, int, socket_struct *)
 Prototype for functions the client sends without player interaction.
typedef void(* func_uint8_int_pl )(char *, int, player *)
 Prototype for functions used to handle player actions.

Functions

static void block_until_new_connection (void)
 Waits for new connection.
void do_server (void)
 This checks the sockets for input and exceptions, does the right thing.
void handle_client (socket_struct *ns, player *pl)
 Handle client commands.
static int is_fd_valid (int fd)
 Checks if file descriptor is valid.
void request_info_cmd (char *buf, int len, socket_struct *ns)
 request_info_cmd is sort of a meta command.

Variables

static struct client_cmd_mapping client_commands []
 Commands sent directly by client, when connecting or when needed.
static struct player_cmd_mapping player_commands []
 Dispatch tables for the server.
unsigned long todtick
 Ingame time.

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 do_server ( void  )
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(), Ns_Dead, pl::ob, SockList_NullTerminate(), SockList_ReadPacket(), SockList_ResetRead(), 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

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 }                       
}

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

Definition at line 127 of file loop.c.

Initial value:
 {
    { "examine",    examine_cmd,                       1 },
    { "apply",      apply_cmd,                         1 },
    { "move",       move_cmd,                          1 },
    { "reply",      reply_cmd,                         0 },
    { "ncom",       (func_uint8_int_pl)new_player_cmd, 1 },
    { "lookat",     look_at_cmd,                       1 },
    { "lock",       (func_uint8_int_pl)lock_item_cmd,  1 },
    { "mark",       (func_uint8_int_pl)mark_item_cmd,  1 },
    { "mapredraw",  map_redraw_cmd,                    0 },  
    { "inscribe",   inscribe_scroll_cmd,               0 },
    { NULL,         NULL,                              0 }   
}

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 get_tod(), init_clocks(), tick_the_clock(), and write_todclock().