Crossfire Client, Trunk  R20789
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 "gtk2proto.h"
+ Include dependency graph for main.c:

Go to the source code of this file.

Functions

void client_tick (guint32 tick)
 
static gboolean do_network (GObject *stream, gpointer data)
 
static gboolean do_timeout (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)
 
void on_window_destroy_event (GtkObject *object, gpointer user_data)
 
static void parse_args (int argc, char *argv[])
 
static gboolean redraw (gpointer data)
 
void show_main_client ()
 

Variables

static const char *const colorname [NUM_COLORS]
 
static char * connect_server = NULL
 
GtkWidget * connect_window
 
GtkBuilder * dialog_xml
 
GtkWidget * magic_map
 
GtkNotebook * main_notebook
 
int MINLOG
 
bool next_tick = false
 
static GOptionEntry options []
 
bool profile_latency
 
GdkColor root_color [NUM_COLORS]
 
SoundServer * server
 
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

◆ client_tick()

void client_tick ( guint32  tick)

X11 client doesn't care about this

Definition at line 164 of file main.c.

References info_buffer_tick(), inventory_tick(), mapdata_animation(), and next_tick.

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 185 of file main.c.

References client_is_connected(), client_run(), draw_lists(), 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:

◆ do_timeout()

static gboolean do_timeout ( gpointer  data)
static

Map, spell, and inventory maintenance.

Returns
TRUE

Definition at line 111 of file main.c.

References cpl, inventory_tick(), magic_map_flash_pos(), MAGIC_MAP_PAGE, map_notebook, mapdata_animation(), Player_Struct::showmagic, Player_Struct::spells_updated, tick, and update_spell_information().

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 271 of file main.c.

Referenced by 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 211 of file main.c.

References client_get_source(), do_network(), do_timeout(), LOG(), LOG_DEBUG, and redraw().

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 534 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 ( void  )

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 437 of file main.c.

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

Referenced by choose_character_init(), 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 299 of file main.c.

References maxfd, and wantloginmethod.

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 318 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 294 of file main.c.

◆ on_window_destroy_event()

void on_window_destroy_event ( GtkObject *  object,
gpointer  user_data 
)

Handles client shutdown.

Definition at line 173 of file main.c.

References LOG(), and LOG_DEBUG.

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 241 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.

Definition at line 136 of file main.c.

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

Referenced by event_loop(), and StatsCmd().

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

◆ show_main_client()

void show_main_client ( void  )

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

Definition at line 426 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 38 of file main.c.

Referenced by init_ui().

◆ connect_server

char* connect_server = NULL
static

Definition at line 62 of file main.c.

Referenced by main().

◆ connect_window

GtkWidget * connect_window

◆ dialog_xml

◆ magic_map

GtkWidget * magic_map

Definition at line 94 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 32 of file misc.c.

Referenced by LOG(), and parse_args().

◆ next_tick

bool next_tick = false

Track whether the client has received a trick since the last redraw.

Definition at line 98 of file main.c.

Referenced by client_tick(), and redraw().

◆ 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 },
{ "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" },
{ NULL }
}
int MINLOG
Definition: misc.c:32
static char * connect_server
Definition: main.c:62
Face_Information face_info
Definition: image.c:169
bool time_map_redraw
Definition: map.c:50
bool profile_latency
Definition: player.c:33
#define CONFIG_CACHE
Definition: client.h:189
gint16 want_config[CONFIG_NUMS]
Definition: init.c:40
#define CONFIG_DOWNLOAD
Definition: client.h:185
char * sound_server
Definition: client.c:51
static gboolean updatekeycodes
Definition: main.c:54

Command line options, descriptions, and parameters.

Definition at line 65 of file main.c.

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

◆ profile_latency

bool profile_latency

Definition at line 33 of file player.c.

Referenced by CompleteCmd(), and send_command().

◆ root_color

GdkColor root_color[NUM_COLORS]

Definition at line 91 of file main.c.

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

◆ server

SoundServer* server

Definition at line 25 of file sound.c.

Referenced by hide_main_client(), init_sounds(), MusicCmd(), and Sound2Cmd().

◆ time_map_redraw

bool time_map_redraw

Definition at line 50 of file map.c.

Referenced by draw_map().

◆ updatekeycodes

gboolean updatekeycodes = FALSE
static

Definition at line 54 of file main.c.

◆ window_root

◆ window_xml

◆ window_xml_file