![]() |
Crossfire Client, Trunk
|
#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... | |
| bool | 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... | |
| char * | printable (void *data, int len) |
| Replace the non-printable characters in 'data' with a dot ('. 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 = -1 |
| NameMapping | skill_mapping [MAX_SKILL] |
| char * | skill_names [MAX_SKILL] |
| char | VERSION_INFO [MAX_BUF] |
| int | want_skill_exp = 0 |
| int | wantloginmethod = 2 |
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.
| #define NCOMMANDS ((int)(sizeof(commands)/sizeof(struct CmdMapping))) |
| 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:| 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 174 of file client.c.
References csocket, 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:| GSource* client_get_source | ( | ) |
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:| 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:| void client_mapsize | ( | int | width, |
| int | height | ||
| ) |
Ask the server for the given map size.
Definition at line 170 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:| bool 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.
| sound | Non-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_SERVER_TICKS, 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:| void client_run | ( | ) |
Read available packets from the server and handle commands until there are no more, or if a socket error occurs.
Definition at line 201 of file client.c.
References SockList::buf, client_disconnect(), CmdMapping::cmdformat, CmdMapping::cmdname, CmdMapping::cmdproc, commands, debug_protocol, error_dialog(), in, 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:| 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 185 of file client.c.
Referenced by client_run(), and SockList_Send().
Here is the caller graph for this function:| const char* cache_dir |
Definition at line 52 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.
Referenced by client_run().
| const char* config_dir |
Definition at line 51 of file client.c.
Referenced by config_load(), init_paths(), init_theme(), keybindings_init(), load_msgctrl_configuration(), save_keys(), and save_msgctrl_configuration().
| Client_Player cpl |
Player object.
Definition at line 68 of file client.c.
Referenced by AddspellCmd(), animate_objects(), bind_key(), client_init(), client_tick(), command_take(), configure_keys(), DeleteSpell(), do_inv(), draw_inv(), draw_inv_list(), draw_inv_table(), draw_lists(), draw_look_list(), draw_magic_map(), draw_message_window(), draw_stats(), drawingarea_inventory_table_expose_event(), extended_command(), fire_dir(), focusoutfunc(), get_item_env(), gtk_command_history(), handle_query(), hide_main_client(), item_actions(), item_event_item_deleting(), keybindings_init(), keyfunc(), list_item_drop(), load_theme(), locate_item(), magic_map_flash_pos(), MagicMapCmd(), main(), metaserver_connect_to(), metaserver_show_prompt(), new_player(), on_count_changed(), on_entry_commands_activate(), on_switch_page(), parse_key(), parse_key_release(), redraw(), remove_item(), reset_player_data(), reset_vars_common(), save_keys(), script_init(), script_process_cmd(), send_command(), send_reply(), show_item_menu(), StatsCmd(), stop_fire(), toggle_keybind_scope(), update_skill_information(), update_spell_information(), UpdspellCmd(), and x_set_echo().
| ClientSocket csocket |
Definition at line 69 of file client.c.
Referenced by add_character_to_account(), client_connect(), client_disconnect(), client_is_connected(), client_mapsize(), client_negotiate(), client_send_apply(), client_send_examine(), client_send_move(), cmd_raw(), command_take(), CompleteCmd(), config_check(), create_character_window_show(), create_new_character(), do_account_change(), do_account_create(), do_account_login(), draw_stats(), get_image_info(), get_new_char_info(), inscribe_magical_scroll(), keybindings_init(), keyfunc(), look_at(), main(), map_check_resize(), mapdata_newmap(), metaserver_connect_to(), play_character(), ReplyInfoCmd(), requestface(), reset_vars_common(), save_keys(), script_init(), script_process_cmd(), send_command(), send_create_player_to_server(), send_mark_obj(), send_reply(), set_item_values(), SetupCmd(), toggle_locked(), and VersionCmd().
| 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().
|
static |
Definition at line 70 of file client.c.
Referenced by client_connect(), client_get_source(), client_run(), init_default_keybindings(), keybindings_init(), parse_keys_file(), and SockList_ReadPacket().
| int last_used_skills[MAX_SKILL+1] |
maps position to skill id with trailing zero as stop mark.
Definition at line 54 of file client.c.
Referenced by client_init(), and use_skill().
| int maxfd |
Definition at line 57 of file client.c.
Referenced by do_network(), and script_fdset().
| int replyinfo_last_face = 0 |
Definition at line 57 of file client.c.
Referenced by client_negotiate(), and get_image_sums().
| int replyinfo_status = 0 |
Definition at line 56 of file client.c.
Referenced by client_negotiate(), and get_image_info().
| int requestinfo_sent = 0 |
Definition at line 56 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] |
Definition at line 72 of file client.c.
Referenced by update_stat_mapping().
| int serverloginmethod = -1 |
Definition at line 61 of file client.c.
Referenced by client_negotiate(), client_reset(), main(), on_button_create_character_clicked(), SetupCmd(), and start_login().
| 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] |
Definition at line 50 of file client.c.
Referenced by AddspellCmd(), client_init(), client_reset(), draw_stats(), get_skill_info(), script_process_cmd(), and update_stat_mapping().
| char VERSION_INFO[MAX_BUF] |
Definition at line 48 of file client.c.
Referenced by main(), parse_args(), and SendVersion().
| int wantloginmethod = 2 |
Definition at line 60 of file client.c.
Referenced by client_negotiate().