 |
Crossfire Client, Trunk
|
Go to the documentation of this file.
29 #include "client-vala.h"
67 static gboolean
script_launch(
const gchar *option_name,
const gchar *value, gpointer data, GError **error);
72 "Connect to the given server",
"SERVER[:PORT]" },
74 "Cache images", NULL },
76 "Download images before playing", NULL },
78 "Use the given faceset (if available)",
"FACESET" },
80 {
"sound_server", 0, 0, G_OPTION_ARG_FILENAME, &
sound_server,
81 "Path to the sound server",
"PATH" },
83 "Update the saved bindings for this keyboard", NULL },
86 "Login method to request from server", NULL },
88 "Log command acknowledgement latency to stdout", NULL },
90 "Print map redraw times to stdout", NULL },
91 {
"verbose",
'v', 0, G_OPTION_ARG_INT, &
MINLOG,
92 "Set verbosity (0 is the most verbose)",
"LEVEL" },
94 "Print commands to and from the server", NULL },
96 "Launch client script at start (can be used multiple times)",
"SCRIPT_NAME" },
112 static int do_scriptout() {
118 static gboolean
script_launch(
const gchar *option_name,
const gchar *value, gpointer data, GError **error)
150 switch (response_id) {
152 gtk_widget_destroy(GTK_WIDGET(
self));
161 gtk_widget_destroy(GTK_WIDGET(
self));
168 gtk_widget_destroy(GTK_WIDGET(
self));
175 GtkWidget *dialog = gtk_dialog_new_with_buttons(
"Auto-AFK", GTK_WINDOW(
window_root), GTK_DIALOG_DESTROY_WITH_PARENT,
176 "Return to game", 0,
"Return to game, but stay AFK", 1,
"Return to game, disable auto-AFK", 2, NULL);
177 GtkWidget *label, *content_area;
178 content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
179 label = gtk_label_new(
"You have been automatically marked as being away.");
180 gtk_container_add(GTK_CONTAINER(content_area), label);
182 gtk_widget_show_all(dialog);
190 if (gtk_notebook_get_current_page(GTK_NOTEBOOK(
map_notebook)) !=
212 LOG(
LOG_DEBUG,
"main.c::client_exit",
"Exiting with return value 0.");
220 struct timeval timeout = {0, 0};
226 LOG(
LOG_INFO,
"main.c::do_network",
"Trying to do network when not connected.");
235 pollret = select(
maxfd, &tmp_read, NULL, NULL, &timeout);
239 LOG(
LOG_ERROR,
"do_network",
"script select() failed: %s", strerror(errno));
241 }
else if (pollret > 0) {
268 g_timeout_add(250, G_SOURCE_FUNC(do_scriptout), NULL);
272 if (net_source == NULL) {
274 "The server unexpectedly disconnected.");
278 g_source_set_callback(net_source, (GSourceFunc)
do_network, NULL, NULL);
279 g_source_attach(net_source, NULL);
297 GOptionContext *context = g_option_context_new(
"- Crossfire GTKv2 Client");
298 GError *error = NULL;
300 g_option_context_add_main_entries(context,
options, NULL);
301 g_option_context_add_group(context, gtk_get_option_group(TRUE));
303 if (!g_option_context_parse(context, &argc, &argv, &error)) {
304 g_print(
"%s\n", error->message);
309 g_option_context_free(context);
317 g_setenv(
"CF_SOUND_DEBUG",
"yes",
false);
327 GtkWidget *dialog = gtk_message_dialog_new(
328 NULL, GTK_DIALOG_DESTROY_WITH_PARENT,
329 GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
"%s", error);
330 gtk_window_set_title(GTK_WINDOW(dialog),
"Crossfire Client");
331 gtk_message_dialog_format_secondary_markup(
332 GTK_MESSAGE_DIALOG(dialog),
"%s", message);
333 gtk_dialog_run(GTK_DIALOG(dialog));
334 gtk_widget_destroy(dialog);
350 const gchar *message, gpointer user_data) {
356 signal(SIGPIPE, SIG_IGN);
364 guint retval = gtk_builder_add_from_file(
window_xml, name, NULL);
365 if (retval > 0 && strlen(name) > 0) {
376 GError *error = NULL;
377 GdkGeometry geometry;
383 error_dialog(
"Couldn't load UI dialogs.", error->message);
384 g_warning(
"Couldn't load UI dialogs: %s", error->message);
395 g_error(
"Could not load default layout!");
406 GTK_NOTEBOOK(gtk_builder_get_object(
dialog_xml,
"main_notebook"));
412 "Check that your layout files are not corrupt.");
417 gtk_widget_add_events((gpointer)
window_root, GDK_FOCUS_CHANGE_MASK);
418 g_signal_connect((gpointer)
window_root,
"focus-out-event",
421 g_signal_connect_swapped((gpointer)
window_root,
"key_press_event",
423 g_signal_connect_swapped((gpointer)
window_root,
"key_release_event",
425 g_signal_connect((gpointer)
window_root,
"destroy",
429 geometry.min_width=640;
430 geometry.min_height=480;
433 &geometry, GDK_HINT_MIN_SIZE);
436 "drawingarea_magic_map"));
438 g_signal_connect((gpointer)
magic_map,
"expose_event",
444 fprintf(stderr,
"gdk_color_parse failed (%s)\n",
colorname[i]);
446 if (!gdk_colormap_alloc_color(gtk_widget_get_colormap(
window_root),
448 fprintf(stderr,
"gdk_color_alloc failed\n");
481 g_timeout_add(1000/8, G_SOURCE_FUNC(
self_tick), NULL);
515 int main(
int argc,
char *argv[]) {
518 bind_textdomain_codeset(GETTEXT_PACKAGE,
"UTF-8");
519 bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
520 textdomain(GETTEXT_PACKAGE);
524 gtk_init(&argc, &argv);
604 gdk_window_get_geometry(gtk_widget_get_window(win), x, y, w, h, NULL);
606 gdk_window_get_origin(gtk_widget_get_window(win), wx, wy);
time_t last_command_sent
Time when last command was sent.
@ LOG_INFO
Minor, non-harmful issues.
static gboolean updatekeycodes
static gboolean redraw(gpointer data)
Redraw the map.
void init_menu_items()
Initialize menu bar items and connect their signals to their handlers.
void script_killall(void)
void keyfunc(GtkWidget *widget, GdkEventKey *event, GtkWidget *window)
GTK Callback function used to handle client key press events.
#define CONFIG_SERVER_TICKS
void load_window_positions(GtkWidget *window_root)
Resize the client window and its panels using saved window positions.
Input_State input_state
What the input state is.
void client_disconnect()
Closes the connection to the server.
static void parse_args(int argc, char *argv[])
parse_args: Parses command line options, and does variable initialization.
void client_reset()
Clear client variables between connections to different servers.
void show_main_client()
Show main client window.
GtkNotebook * main_notebook
void remove_item_inventory(item *op)
void client_tick(guint32 tick)
Called whenever the server sends a tick command.
void map_init(GtkWidget *window_root)
This initializes the stuff we need for the map.
void hide_all_login_windows(void)
Hides all the login related windows.
Face_Information face_info
void msgctrl_init(GtkWidget *window_root)
Initialize the message control panel by populating it with descriptions of each message type along wi...
void save_defaults(void)
This function saves user settings chosen using the configuration popup dialog.
static GOptionEntry options[]
Command line options, descriptions, and parameters.
void script_process(fd_set *set)
bool client_is_connected()
void client_connect(const char hostname[static 1])
#define MAGIC_MAP_PAGE
Notebook page of the magic map.
char VERSION_INFO[MAX_BUF]
static void event_loop()
Set up, enter, and exit event loop.
static void on_auto_afk_response(GtkDialog *self, gint response_id, gpointer user_data)
GSource * client_get_source()
Return a source triggered when input from the server is available.
item * container
open container
void pickup_init(GtkWidget *window_root)
Maps the menuitem lists into pickup values.
void info_init(GtkWidget *window_root)
Initialize the information panels in the client.
void reset_image_data(void)
Connecting to different servers, try to clear out any old images.
static char * init_ui_layout(const char *name)
Load the UI from the given path.
void focusoutfunc(GtkWidget *widget, GdkEventKey *event, GtkWidget *window)
When the main window looses its focus, act as if all keys have been released.
int MINLOG
Log level, or the threshold below which messages are suppressed.
void hide_main_client()
Called if event_loop() exits, or whenever the character selection window comes up (before logging in,...
void clear_stat_mapping(void)
void init_image_cache_data(void)
Initializes the data for image caching Create question mark to display in each supported rendering mo...
void client_run()
Read available packets from the server and handle commands until there are no more,...
void draw_lists(void)
Redraws inventory and look windows when necessary.
GdkColor root_color[NUM_COLORS]
void LOG(LogLevel level, const char *origin, const char *format,...)
Log messages of a certain importance to stderr.
void inventory_init(GtkWidget *window_root)
Set up the inventory viewer.
void load_theme(int reload)
char window_xml_file[MAX_BUF]
Path to the current UI file.
gint16 want_config[CONFIG_NUMS]
void metaserver_show_prompt(void)
Constructs the metaserver dialog and handles metaserver selection.
void metaserver_ui_init()
Initialize the metaserver user interface.
static void init_sockets()
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().
void magic_map_flash_pos(void)
Flash the player's position on the magic map.
void keys_init(GtkWidget *window_root)
One-time initialization of windows and signals for the keybindings dialog.
void error_dialog(char *error, char *message)
Display an error message dialog.
int main(int argc, char *argv[])
Main client entry point.
void keyrelfunc(GtkWidget *widget, GdkEventKey *event, GtkWidget *window)
GTK callback function used to handle client key release events.
guint8 showmagic
If 0, show the normal map, otherwise show the magic map.
bool is_afk
Best guess whether or not we are currently AFK or not.
int send_command(const char *command, int repeat, int must_send)
void init_create_character_window()
Initializes the create character window.
gboolean on_drawingarea_magic_map_expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer user_data)
@ LOG_ERROR
Warning that something definitely didn't work.
void update_spell_information(void)
When spell information updates, the treeview is cleared and re-populated.
item * locate_item(gint32 tag)
Client_Player cpl
Player object.
static char * connect_server
void inventory_tick(void)
This is called periodically from main.c - basically a timeout, used to animate the inventory.
static gboolean do_network(GObject *stream, gpointer data)
Callback from the event loop triggered when server input is available.
void config_init(GtkWidget *window_root)
static gboolean self_tick(gpointer data)
void account_show_login()
gint16 use_config[CONFIG_NUMS]
static const char *const colorname[NUM_COLORS]
void info_buffer_tick(void)
Output count/sync buffer maintainer adds buffer time and output messages.
void client_init()
Called ONCE during client startup to initialize configuration and other variables to reasonable defau...
void script_fdset(int *maxfd, fd_set *set)
GtkWidget * window_root
In main.c.
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.
void script_init(const char *cparams)
void on_window_destroy_event(GtkWidget *object, gpointer user_data)
Handles client shutdown.
void mapdata_animation(void)
static gboolean script_launch(const gchar *option_name, const gchar *value, gpointer data, GError **error)
void draw_map(void)
Draw the map window using the appropriate backend.
guint32 spells_updated
Whether or not spells updated.
GtkWidget * connect_window
@ LOG_DEBUG
Useful debugging information.
void config_load()
Load settings from the user's configuration file into want_config.
void stats_init(GtkWidget *window_root)
Associate the XML-defined widgets with pointers by name reference.
void cf_play_music(const char *music_name)
Play a music file.
void config_check(void)
Check that want_config is valid, copy the new configuration to use_config, and apply the new configur...
void client_negotiate(int sound)
This function negotiates the characteriistics of a connection to the server.