Crossfire Client, Trunk
main.c File Reference
#include "client.h"
#include <errno.h>
#include <gtk/gtk.h>
#include <stdbool.h>
#include <signal.h>
#include "client-vala.h"
#include "image.h"
#include "main.h"
#include "mapdata.h"
#include "metaserver.h"
#include "script.h"
#include "sound.h"
#include "gtk2proto.h"
+ Include dependency graph for main.c:

Go to the source code of this file.

Functions

static void auto_afk ()
 
void client_tick (guint32 tick)
 
static gboolean do_network (GObject *stream, gpointer data)
 
void error_dialog (char *error, char *message)
 
static void event_loop ()
 
void get_window_coord (GtkWidget *win, int *x, int *y, int *wx, int *wy, int *w, int *h)
 
void hide_main_client ()
 
static void init_sockets ()
 
static void init_ui ()
 
static char * init_ui_layout (const char *name)
 
int main (int argc, char *argv[])
 
void my_log_handler (const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer user_data)
 
static void on_auto_afk_response (GtkDialog *self, gint response_id, gpointer user_data)
 
void on_window_destroy_event (GtkWidget *object, gpointer user_data)
 
static void parse_args (int argc, char *argv[])
 
static gboolean redraw (gpointer data)
 
static gboolean script_launch (const gchar *option_name, const gchar *value, gpointer data, GError **error)
 
void show_main_client ()
 

Variables

static const char *const colorname [NUM_COLORS]
 
static char * connect_server = NULL
 
GtkWidget * connect_window
 
bool debug_protocol
 
GtkBuilder * dialog_xml
 
bool is_afk
 
time_t last_command_sent
 
GtkWidget * magic_map
 
GtkNotebook * main_notebook
 
int MINLOG
 
static GOptionEntry options []
 
bool profile_latency
 
GdkColor root_color [NUM_COLORS]
 
bool time_map_redraw
 
static gboolean updatekeycodes = FALSE
 
GtkWidget * window_root
 
GtkBuilder * window_xml
 
char window_xml_file [MAX_BUF]
 

Detailed Description

Client startup and main loop.

Definition in file main.c.

Function Documentation

◆ auto_afk()

static void auto_afk ( )
static

Definition at line 171 of file main.c.

References on_auto_afk_response(), send_command(), and window_root.

Referenced by client_tick().

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

◆ client_tick()

void client_tick ( guint32  tick)

Called whenever the server sends a tick command.

Definition at line 186 of file main.c.

References auto_afk(), CONFIG_AUTO_AFK, cpl, info_buffer_tick(), inventory_tick(), is_afk, last_command_sent, magic_map_flash_pos(), MAGIC_MAP_PAGE, map_notebook, mapdata_animation(), redraw(), Player_Struct::showmagic, Player_Struct::spells_updated, update_spell_information(), and use_config.

Referenced by TickCmd().

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

◆ do_network()

static gboolean do_network ( GObject *  stream,
gpointer  data 
)
static

Callback from the event loop triggered when server input is available.

Definition at line 222 of file main.c.

References client_is_connected(), client_run(), LOG(), LOG_ERROR, LOG_INFO, maxfd, script_fdset(), and script_process().

Referenced by event_loop().

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

◆ error_dialog()

void error_dialog ( char *  error,
char *  message 
)

Display an error message dialog. The dialog contains a multi-line, bolded heading that includes the client version information, an error description, and information relevant to the error condition.

Definition at line 314 of file main.c.

Referenced by client_run(), event_loop(), and init_ui().

+ Here is the caller graph for this function:

◆ event_loop()

static void event_loop ( )
static

Set up, enter, and exit event loop. Blocks until event loop returns.

Definition at line 254 of file main.c.

References client_disconnect(), client_get_source(), do_network(), error_dialog(), LOG(), and LOG_DEBUG.

Referenced by main().

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

◆ get_window_coord()

void get_window_coord ( GtkWidget *  win,
int *  x,
int *  y,
int *  wx,
int *  wy,
int *  w,
int *  h 
)

Gets the coordinates of a specified window.

Parameters
winPass in a GtkWidget pointer to get its coordinates.
xParent-relative window x coordinate
yParent-relative window y coordinate
wx?
wy?
wWindow width
hWindow height

Definition at line 579 of file main.c.

Referenced by image_update_download_status(), and save_winpos().

+ Here is the caller graph for this function:

◆ hide_main_client()

void hide_main_client ( )

Called if event_loop() exits, or whenever the character selection window comes up (before logging in, or after having applied a bed).

Definition at line 477 of file main.c.

References cf_play_music(), connect_window, cpl, locate_item(), Player_Struct::ob, remove_item_inventory(), and window_root.

Referenced by choose_character_init(), create_new_character_failure(), and main().

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

◆ init_sockets()

static void init_sockets ( )
static

Definition at line 342 of file main.c.

Referenced by main().

+ Here is the caller graph for this function:

◆ init_ui()

◆ init_ui_layout()

static char* init_ui_layout ( const char *  name)
static

Load the UI from the given path. On success, store path in window_xml_file.

Definition at line 351 of file main.c.

References window_xml, and window_xml_file.

Referenced by init_ui().

+ Here is the caller graph for this function:

◆ main()

◆ my_log_handler()

void my_log_handler ( const gchar *  log_domain,
GLogLevelFlags  log_level,
const gchar *  message,
gpointer  user_data 
)

This goes with the g_log_set_handler below in main(). I leave it here since it may be useful - basically, it can prove handy to try and track down error messages like:

file gtklabel.c: line 1845: assertion ‘GTK_IS_LABEL (label)’ failed

In the debugger, you can set a breakpoint in this function, and then see the stacktrace on what is trying to access a widget that isn't set or otherwise having issues.

Definition at line 337 of file main.c.

◆ on_auto_afk_response()

static void on_auto_afk_response ( GtkDialog *  self,
gint  response_id,
gpointer  user_data 
)
static

Definition at line 146 of file main.c.

References CONFIG_AUTO_AFK, config_check(), is_afk, save_defaults(), send_command(), and want_config.

Referenced by auto_afk().

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

◆ on_window_destroy_event()

void on_window_destroy_event ( GtkWidget *  object,
gpointer  user_data 
)

Handles client shutdown.

Definition at line 213 of file main.c.

References LOG(), LOG_DEBUG, and script_killall().

Referenced by init_ui(), and on_button_metaserver_quit_pressed().

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

◆ parse_args()

static void parse_args ( int  argc,
char *  argv[] 
)
static

parse_args: Parses command line options, and does variable initialization.

Parameters
argc
argvParse command-line arguments and store settings in want_config.

This function should be called after config_load().

Definition at line 284 of file main.c.

References LOG(), LOG_DEBUG, MINLOG, options, and VERSION_INFO.

Referenced by main().

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

◆ redraw()

static gboolean redraw ( gpointer  data)
static

Redraw the map. Do a full redraw if there are new images to show. Return false to unregister this event source after one redraw.

Definition at line 129 of file main.c.

References client_is_connected(), Player_Struct::container, cpl, draw_lists(), draw_map(), have_new_image, item_struct::inv_updated, and Player_Struct::ob.

Referenced by client_tick(), display_map_doneupdate(), draw_stats(), and StatsCmd().

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

◆ script_launch()

static gboolean script_launch ( const gchar *  option_name,
const gchar *  value,
gpointer  data,
GError **  error 
)
static

Definition at line 116 of file main.c.

References script_init().

+ Here is the call graph for this function:

◆ show_main_client()

void show_main_client ( )

Show main client window. Called after connect if server does not support new loginmethod, or after character is selected.

Definition at line 466 of file main.c.

References clear_stat_mapping(), hide_all_login_windows(), map_init(), and window_root.

Referenced by AddMeSuccess(), main(), on_button_cc_done(), and on_button_play_character_clicked().

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

Variable Documentation

◆ colorname

const char* const colorname[NUM_COLORS]
static
Initial value:
= {
"Black",
"White",
"Navy",
"Red",
"Orange",
"DodgerBlue",
"DarkOrange2",
"SeaGreen",
"DarkSeaGreen",
"Grey50",
"Sienna",
"Gold",
"Khaki"
}

Definition at line 39 of file main.c.

Referenced by init_ui().

◆ connect_server

char* connect_server = NULL
static

Definition at line 63 of file main.c.

Referenced by main().

◆ connect_window

GtkWidget * connect_window

◆ debug_protocol

bool debug_protocol

Definition at line 61 of file main.c.

Referenced by client_run(), and SockList_Send().

◆ dialog_xml

◆ is_afk

bool is_afk

Best guess whether or not we are currently AFK or not.

Definition at line 46 of file player.c.

Referenced by client_tick(), new_player(), on_auto_afk_response(), and send_command().

◆ last_command_sent

time_t last_command_sent

Time when last command was sent. Used to keep track of auto-AFK.

Definition at line 49 of file player.c.

Referenced by client_tick(), new_player(), and send_command().

◆ magic_map

GtkWidget * magic_map

Definition at line 103 of file main.c.

Referenced by draw_magic_map(), init_ui(), and magic_map_flash_pos().

◆ main_notebook

◆ MINLOG

int MINLOG

Log level, or the threshold below which messages are suppressed.

Definition at line 34 of file misc.c.

Referenced by LOG(), and parse_args().

◆ options

GOptionEntry options[]
static
Initial value:
= {
{ "server", 's', 0, G_OPTION_ARG_STRING, &connect_server,
"Connect to the given server", "SERVER[:PORT]" },
{ "cache", 0, 0, G_OPTION_ARG_NONE, &want_config[CONFIG_CACHE],
"Cache images", NULL },
{ "prefetch", 0, 0, G_OPTION_ARG_NONE, &want_config[CONFIG_DOWNLOAD],
"Download images before playing", NULL },
{ "faceset", 0, 0, G_OPTION_ARG_STRING, &face_info.want_faceset,
"Use the given faceset (if available)", "FACESET" },
{ "sound_server", 0, 0, G_OPTION_ARG_FILENAME, &sound_server,
"Path to the sound server", "PATH" },
{ "updatekeycodes", 0, 0, G_OPTION_ARG_NONE, &updatekeycodes,
"Update the saved bindings for this keyboard", NULL },
{ "loginmethod", 0, 0, G_OPTION_ARG_INT, &wantloginmethod,
"Login method to request from server", NULL },
{ "profile-latency", 0, 0, G_OPTION_ARG_NONE, &profile_latency,
"Log command acknowledgement latency to stdout", NULL },
{ "profile-redraw", 0, 0, G_OPTION_ARG_NONE, &time_map_redraw,
"Print map redraw times to stdout", NULL },
{ "verbose", 'v', 0, G_OPTION_ARG_INT, &MINLOG,
"Set verbosity (0 is the most verbose)", "LEVEL" },
{ "debug-protocol", 0, 0, G_OPTION_ARG_NONE, &debug_protocol,
"Print commands to and from the server", NULL },
{ "script", 0, 0, G_OPTION_ARG_CALLBACK, &script_launch,
"Launch client script at start (can be used multiple times)", "SCRIPT_NAME" },
{ NULL }
}

Command line options, descriptions, and parameters.

Definition at line 68 of file main.c.

Referenced by on_spell_cast_clicked(), on_spell_invoke_clicked(), and parse_args().

◆ profile_latency

bool profile_latency

Definition at line 36 of file player.c.

Referenced by CompleteCmd(), and send_command().

◆ root_color

GdkColor root_color[NUM_COLORS]

Definition at line 100 of file main.c.

Referenced by draw_magic_map(), init_ui(), and magic_map_flash_pos().

◆ time_map_redraw

bool time_map_redraw

Definition at line 51 of file config.c.

◆ updatekeycodes

gboolean updatekeycodes = FALSE
static

Definition at line 55 of file main.c.

◆ window_root

◆ window_xml

◆ window_xml_file

char window_xml_file[MAX_BUF]

Path to the current UI file.

Definition at line 98 of file main.c.

Referenced by config_load(), config_load_legacy(), init_ui(), init_ui_layout(), main(), read_config_dialog(), save_defaults(), setup_config_dialog(), and ui_name().

updatekeycodes
static gboolean updatekeycodes
Definition: main.c:55
CONFIG_DOWNLOAD
#define CONFIG_DOWNLOAD
Definition: client.h:183
face_info
Face_Information face_info
Definition: image.c:169
wantloginmethod
int wantloginmethod
Definition: client.c:61
CONFIG_CACHE
#define CONFIG_CACHE
Definition: client.h:187
MINLOG
int MINLOG
Definition: misc.c:34
Face_Information_struct::want_faceset
char * want_faceset
Definition: client.h:407
want_config
gint16 want_config[CONFIG_NUMS]
Definition: init.c:41
time_map_redraw
bool time_map_redraw
Definition: config.c:51
connect_server
static char * connect_server
Definition: main.c:63
debug_protocol
bool debug_protocol
Definition: main.c:61
sound_server
char * sound_server
Definition: client.c:51
script_launch
static gboolean script_launch(const gchar *option_name, const gchar *value, gpointer data, GError **error)
Definition: main.c:116
profile_latency
bool profile_latency
Definition: player.c:36