Crossfire Client, Trunk
Classes | Macros | Typedefs | Functions | Variables
client.c File Reference
#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.

Classes

struct  CmdMapping
 

Macros

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

Typedefs

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

Functions

void client_connect (const char hostname[static 1])
 
void client_disconnect ()
 
GQuark client_error_quark ()
 
GSource * client_get_source ()
 
bool client_is_connected ()
 
void client_mapsize (int width, int height)
 
void client_negotiate (int sound)
 
void client_run ()
 
char * printable (void *data, int len)
 

Variables

const char * cache_dir
 
struct CmdMapping commands []
 
const char * config_dir
 
Client_Player cpl
 
ClientSocket csocket
 
guint64 * exp_table =NULL
 
guint16 exp_table_max =0
 
static GInputStream * in
 
int last_used_skills [MAX_SKILL+1]
 
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"
 
char VERSION_INFO [MAX_BUF]
 
int want_skill_exp = 0
 
int wantloginmethod = 2
 

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

◆ NCOMMANDS

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

The number of entries in commands.

Definition at line 167 of file client.c.

Typedef Documentation

◆ CmdProc

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

Definition at line 81 of file client.c.

Function Documentation

◆ client_connect()

void client_connect ( const char  hostname[static 1])

Definition at line 289 of file client.c.

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

Referenced by main(), and metaserver_connect_to().

Here is the caller graph for this function:

◆ client_disconnect()

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 175 of file client.c.

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

Referenced by client_negotiate(), client_run(), do_disconnect(), event_loop(), 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:

◆ client_error_quark()

GQuark client_error_quark ( )
inline

Definition at line 631 of file client.h.

◆ client_get_source()

GSource* client_get_source ( void  )

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

Definition at line 324 of file client.c.

References in.

Referenced by event_loop().

Here is the caller graph for this function:

◆ client_is_connected()

bool client_is_connected ( )

Definition at line 320 of file client.c.

References csocket, and ClientSocket::fd.

Referenced by do_network(), on_disconnect_activate(), and redraw().

Here is the caller graph for this function:

◆ client_mapsize()

void client_mapsize ( int  width,
int  height 
)

Ask the server for the given map size.

Definition at line 171 of file client.c.

References cs_print_string(), csocket, ClientSocket::fd, height, and width.

Referenced by client_negotiate(), map_check_resize(), and SetupCmd().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ client_negotiate()

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 329 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, csocket, 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:

◆ client_run()

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 202 of file client.c.

References SockList::buf, client_disconnect(), CmdMapping::cmdformat, CmdMapping::cmdname, CmdMapping::cmdproc, commands, csocket, debug_protocol, error_dialog(), ClientSocket::fd, SockList::len, LOG(), LOG_ERROR, LOG_INFO, MAXSOCKBUF, NCOMMANDS, printable(), 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:

◆ printable()

char* printable ( void *  data,
int  len 
)

Replace the non-printable characters in 'data' with a dot ('.') in a newly allocated, NUL-terminated string. Caller must free the result.

Definition at line 186 of file client.c.

Referenced by client_run(), and SockList_Send().

Here is the caller graph for this function:

Variable Documentation

◆ cache_dir

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().

◆ commands

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 101 of file client.c.

Referenced by client_run().

◆ config_dir

const char* config_dir

◆ cpl

◆ csocket

ClientSocket csocket

◆ exp_table

guint64* exp_table =NULL

Definition at line 65 of file client.c.

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

◆ exp_table_max

guint16 exp_table_max =0

Definition at line 64 of file client.c.

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

◆ in

GInputStream* in
static

◆ last_used_skills

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().

◆ maxfd

int maxfd

Definition at line 58 of file client.c.

Referenced by do_network(), and script_fdset().

◆ replyinfo_last_face

int replyinfo_last_face = 0

Definition at line 58 of file client.c.

Referenced by client_negotiate(), and get_image_sums().

◆ replyinfo_status

int replyinfo_status = 0

Definition at line 57 of file client.c.

Referenced by client_negotiate(), and get_image_info().

◆ requestinfo_sent

int requestinfo_sent = 0

Definition at line 57 of file client.c.

Referenced by client_negotiate().

◆ resist_mapping

NameMapping resist_mapping[NUM_RESISTS]

Definition at line 67 of file client.c.

Referenced by draw_stats(), and update_stat_mapping().

◆ resists_name

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 73 of file client.c.

Referenced by update_stat_mapping().

◆ serverloginmethod

int serverloginmethod = 0

◆ skill_mapping

NameMapping skill_mapping[MAX_SKILL]

Definition at line 67 of file client.c.

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

◆ skill_names

char* skill_names[MAX_SKILL]

◆ sound_server

char* sound_server = BINDIR "/cfsndserv"

Definition at line 51 of file client.c.

◆ VERSION_INFO

char VERSION_INFO[MAX_BUF]

Definition at line 48 of file client.c.

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

◆ want_skill_exp

int want_skill_exp = 0

Definition at line 57 of file client.c.

◆ wantloginmethod

int wantloginmethod = 2

Definition at line 61 of file client.c.

Referenced by client_negotiate().