Crossfire Client, Trunk  R20507
Data Structures | Macros | Typedefs | Functions | Variables
client.c File Reference

Client interface main routine. More...

#include "client.h"
#include <ctype.h>
#include <errno.h>
#include <gio/gio.h>
#include "external.h"
#include "mapdata.h"
#include "metaserver.h"
#include "script.h"
Include dependency graph for client.c:

Go to the source code of this file.

Data Structures

struct  CmdMapping
 Links server commands to client functions that implement them, and gives a rough indication of the type of data that the server supplies with the command. More...
 

Macros

#define NCOMMANDS   ((int)(sizeof(commands)/sizeof(struct CmdMapping)))
 The number of entries in commands. More...
 

Typedefs

typedef void(* CmdProc) (unsigned char *, int len)
 

Functions

void client_connect (const char hostname[static 1])
 
void client_disconnect ()
 Closes the connection to the server. More...
 
GQuark client_error_quark ()
 
GSource * client_get_source ()
 Return a source triggered when input from the server is available. More...
 
bool client_is_connected ()
 
void client_mapsize (int width, int height)
 Ask the server for the given map size. More...
 
void client_negotiate (int sound)
 This function negotiates the characteriistics of a connection to the server. More...
 
void client_run ()
 Read available packets from the server and handle commands until there are no more, or if a socket error occurs. More...
 

Variables

const char * cache_dir
 
struct CmdMapping commands []
 The list of server commands that this client supports along with pointers to the function that handles the command. More...
 
const char * config_dir
 
Client_Player cpl
 Player object. More...
 
ClientSocket csocket
 
guint64 * exp_table =NULL
 
guint16 exp_table_max =0
 
static GInputStream * in
 
int last_used_skills [MAX_SKILL+1]
 maps position to skill id with trailing zero as stop mark. More...
 
int maxfd
 
int replyinfo_last_face = 0
 
int replyinfo_status = 0
 
int requestinfo_sent = 0
 
NameMapping resist_mapping [NUM_RESISTS]
 
const char *const resists_name [NUM_RESISTS]
 
int serverloginmethod = 0
 
NameMapping skill_mapping [MAX_SKILL]
 
char * skill_names [MAX_SKILL]
 
char * sound_server = BINDIR "/cfsndserv"
 
guint32 tick =0
 
char VERSION_INFO [MAX_BUF]
 
int want_skill_exp = 0
 
int wantloginmethod = 0
 

Detailed Description

Client interface main routine.

Sets up a few global variables, connects to the server, tells it what kind of pictures it wants, adds the client and enters the main dispatch loop.

The main event loop (event_loop()) checks the TCP socket for input and then polls for x events. This should be fixed since you can just block on both filedescriptors.

The DoClient function receives a message (an ArgList), unpacks it, and in a slow for loop dispatches the command to the right function through the commands table. ArgLists are essentially like RPC things, only they don't require going through RPCgen, and it's easy to get variable length lists. They are just lists of longs, strings, characters, and byte arrays that can be converted to a machine independent format

Definition in file client.c.

Macro Definition Documentation

#define NCOMMANDS   ((int)(sizeof(commands)/sizeof(struct CmdMapping)))

The number of entries in commands.

Definition at line 166 of file client.c.

Referenced by client_run().

Typedef Documentation

typedef void(* CmdProc) (unsigned char *, int len)

Definition at line 80 of file client.c.

Function Documentation

void client_connect ( const char  hostname[static 1])

Definition at line 258 of file client.c.

References CONFIG_FASTTCP, CONFIG_PORT, ClientSocket::fd, in, ClientSocket::servername, SOL_TCP, and use_config.

Referenced by metaserver_connect_to().

Here is the caller graph for this function:

void client_disconnect ( void  )

Closes the connection to the server.

It seems better to have it one place here than the same logic sprinkled about in half a dozen locations. It is also useful in that if this logic does change, there is just one place to update it.

Definition at line 180 of file client.c.

References ClientSocket::fd, LOG(), and LOG_DEBUG.

Referenced by client_negotiate(), client_run(), do_disconnect(), keyfunc(), on_button_go_metaserver_clicked(), on_disconnect_activate(), and SetupCmd().

Here is the call graph for this function:

Here is the caller graph for this function:

GQuark client_error_quark ( )
inline

Definition at line 640 of file client.h.

GSource* client_get_source ( void  )

Return a source triggered when input from the server is available.

Definition at line 293 of file client.c.

References in.

Referenced by event_loop().

Here is the caller graph for this function:

bool client_is_connected ( void  )

Definition at line 289 of file client.c.

References ClientSocket::fd.

Referenced by do_network(), and on_disconnect_activate().

Here is the caller graph for this function:

void client_mapsize ( int  width,
int  height 
)

Ask the server for the given map size.

Definition at line 170 of file client.c.

References CONFIG_MAPHEIGHT, CONFIG_MAPWIDTH, cs_print_string(), ClientSocket::fd, height, mapdata_set_size(), use_config, and width.

Referenced by client_negotiate(), and map_check_resize().

Here is the call graph for this function:

Here is the caller graph for this function:

void client_negotiate ( int  sound)

This function negotiates the characteriistics of a connection to the server.

Negotiation consists of asking the server for commands it wants, and checking protocol version for compatibility. Serious incompatibilities abort the connection.

Parameters
soundNon-zero to ask for sound and music commands.

Definition at line 298 of file client.c.

References Face_Information_struct::cache_hits, Face_Information_struct::cache_misses, client_disconnect(), client_mapsize(), client_run(), CONFIG_CACHE, CONFIG_DOWNLOAD, CONFIG_LIGHTING, CONFIG_MAPHEIGHT, CONFIG_MAPWIDTH, CONFIG_SMOOTH, cs_print_string(), ClientSocket::cs_version, draw_ext_info(), face_info, Face_Information_struct::faceset, ClientSocket::fd, image_update_download_status(), LOG(), LOG_ERROR, LOG_WARNING, MAX_BUF, MSG_TYPE_CLIENT, MSG_TYPE_CLIENT_CONFIG, NDI_GOLD, Face_Information_struct::num_images, replyinfo_last_face, replyinfo_status, requestinfo_sent, RI_IMAGE_INFO, RI_IMAGE_SUMS, ClientSocket::sc_version, SendAddMe(), SendVersion(), serverloginmethod, use_config, want_config, Face_Information_struct::want_faceset, and wantloginmethod.

Referenced by main().

Here is the call graph for this function:

Here is the caller graph for this function:

void client_run ( void  )

Read available packets from the server and handle commands until there are no more, or if a socket error occurs.

Definition at line 187 of file client.c.

References SockList::buf, client_disconnect(), CmdMapping::cmdformat, CmdMapping::cmdname, CmdMapping::cmdproc, ClientSocket::fd, SockList::len, LOG(), LOG_ERROR, MAXSOCKBUF, NCOMMANDS, script_watch(), and SockList_ReadPacket().

Referenced by client_negotiate(), and do_network().

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

const char* cache_dir

Definition at line 53 of file client.c.

Referenced by cache_newpng(), finish_face_cmd(), init_common_cache_data(), and init_paths().

struct CmdMapping commands[]

The list of server commands that this client supports along with pointers to the function that handles the command.

The table also gives a rough indication of the type of data that the server should send with each command. If the client receives a command not listed in the table, a complaint is output on stdout.

Definition at line 100 of file client.c.

const char* config_dir
ClientSocket csocket
guint64* exp_table =NULL

Definition at line 64 of file client.c.

Referenced by client_init(), draw_message_window(), get_exp_info(), and update_skill_information().

guint16 exp_table_max =0

Definition at line 63 of file client.c.

Referenced by client_init(), draw_message_window(), get_exp_info(), and update_skill_information().

GInputStream* in
static

Definition at line 70 of file client.c.

Referenced by client_connect(), client_get_source(), and SockList_ReadPacket().

int last_used_skills[MAX_SKILL+1]

maps position to skill id with trailing zero as stop mark.

Definition at line 55 of file client.c.

Referenced by client_init(), and use_skill().

int maxfd

Definition at line 58 of file client.c.

Referenced by do_network(), and init_sockets().

int replyinfo_last_face = 0

Definition at line 58 of file client.c.

Referenced by client_negotiate(), and get_image_sums().

int replyinfo_status = 0

Definition at line 57 of file client.c.

Referenced by client_negotiate(), and get_image_info().

int requestinfo_sent = 0

Definition at line 57 of file client.c.

Referenced by client_negotiate().

NameMapping resist_mapping[NUM_RESISTS]

Definition at line 66 of file client.c.

Referenced by draw_stats(), and update_stat_mapping().

const char* const resists_name[NUM_RESISTS]
Initial value:
= {
"armor", "magic", "fire", "elec",
"cold", "conf", "acid", "drain",
"ghit", "pois", "slow", "para",
"t undead", "fear", "depl","death",
"hword", "blind"
}

Definition at line 72 of file client.c.

Referenced by update_stat_mapping().

int serverloginmethod = 0
NameMapping skill_mapping[MAX_SKILL]

Definition at line 66 of file client.c.

Referenced by draw_stats(), update_skill_information(), and update_stat_mapping().

char* skill_names[MAX_SKILL]
char* sound_server = BINDIR "/cfsndserv"

Definition at line 51 of file client.c.

Referenced by init_sounds().

guint32 tick =0

Definition at line 61 of file client.c.

Referenced by animate_inventory(), animate_look(), do_timeout(), and TickCmd().

char VERSION_INFO[MAX_BUF]

Definition at line 48 of file client.c.

Referenced by main(), parse_args(), and SendVersion().

int want_skill_exp = 0

Definition at line 57 of file client.c.

int wantloginmethod = 0

Definition at line 59 of file client.c.

Referenced by client_negotiate(), and init_sockets().