 |
Crossfire Client, Trunk
|
Go to the documentation of this file.
30 #include <sys/capsicum.h>
33 #include "client-vala.h"
71 static gboolean
script_launch(
const gchar *option_name,
const gchar *value, gpointer data, GError **error);
76 "Connect to the given server",
"SERVER[:PORT]" },
78 "Cache images", NULL },
80 "Download images before playing", NULL },
82 "Use the given faceset (if available)",
"FACESET" },
84 {
"sound_server", 0, 0, G_OPTION_ARG_FILENAME, &
sound_server,
85 "Path to the sound server",
"PATH" },
87 "Update the saved bindings for this keyboard", NULL },
90 "Login method to request from server", NULL },
92 "Log command acknowledgement latency to stdout", NULL },
94 "Print map redraw times to stdout", NULL },
95 {
"verbose",
'v', 0, G_OPTION_ARG_INT, &
MINLOG,
96 "Set verbosity (0 is the most verbose)",
"LEVEL" },
98 "Print commands to and from the server", NULL },
100 "Launch client script at start (can be used multiple times)",
"SCRIPT_NAME" },
118 static int do_scriptout() {
124 static gboolean
script_launch(
const gchar *option_name,
const gchar *value, gpointer data, GError **error)
156 switch (response_id) {
158 gtk_widget_destroy(GTK_WIDGET(
self));
167 gtk_widget_destroy(GTK_WIDGET(
self));
174 gtk_widget_destroy(GTK_WIDGET(
self));
181 GtkWidget *dialog = gtk_dialog_new_with_buttons(
"Auto-AFK", GTK_WINDOW(
window_root), GTK_DIALOG_DESTROY_WITH_PARENT,
182 "Return to game", 0,
"Return to game, but stay AFK", 1,
"Return to game, disable auto-AFK", 2, NULL);
183 GtkWidget *label, *content_area;
184 content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
185 label = gtk_label_new(
"You have been automatically marked as being away.");
186 gtk_container_add(GTK_CONTAINER(content_area), label);
188 gtk_widget_show_all(dialog);
196 if (gtk_notebook_get_current_page(GTK_NOTEBOOK(
map_notebook)) !=
218 LOG(
LOG_DEBUG,
"main.c::client_exit",
"Exiting with return value 0.");
226 struct timeval timeout = {0, 0};
242 pollret = select(
maxfd, &tmp_read, NULL, NULL, &timeout);
246 LOG(
LOG_ERROR,
"do_network",
"script select() failed: %s", strerror(errno));
248 }
else if (pollret > 0) {
275 g_timeout_add(250, G_SOURCE_FUNC(do_scriptout), NULL);
280 g_assert(net_source != NULL);
281 g_source_set_callback(net_source, (GSourceFunc)
do_network, NULL, NULL);
282 g_source_attach(net_source, NULL);
299 GOptionContext *context = g_option_context_new(
"- Crossfire GTKv2 Client");
300 GError *error = NULL;
302 g_option_context_add_main_entries(context,
options, NULL);
303 g_option_context_add_group(context, gtk_get_option_group(TRUE));
305 if (!g_option_context_parse(context, &argc, &argv, &error)) {
306 g_print(
"%s\n", error->message);
311 g_option_context_free(context);
319 g_setenv(
"CF_SOUND_DEBUG",
"yes",
false);
330 GtkWidget *dialog = gtk_message_dialog_new(
331 NULL, GTK_DIALOG_DESTROY_WITH_PARENT,
332 GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
"%s", error);
333 gtk_window_set_title(GTK_WINDOW(dialog),
"Crossfire Client");
334 gtk_message_dialog_format_secondary_markup(
335 GTK_MESSAGE_DIALOG(dialog),
"%s", message);
336 gtk_dialog_run(GTK_DIALOG(dialog));
337 gtk_widget_destroy(dialog);
353 const gchar *message, gpointer user_data) {
359 signal(SIGPIPE, SIG_IGN);
367 guint retval = gtk_builder_add_from_file(
window_xml, name, NULL);
368 if (retval > 0 && strlen(name) > 0) {
379 GError *error = NULL;
380 GdkGeometry geometry;
386 error_dialog(
"Couldn't load UI dialogs.", error->message);
397 g_error(
"Could not load default layout!");
408 GTK_NOTEBOOK(gtk_builder_get_object(
dialog_xml,
"main_notebook"));
414 "Check that your layout files are not corrupt.");
419 gtk_widget_add_events((gpointer)
window_root, GDK_FOCUS_CHANGE_MASK);
420 g_signal_connect((gpointer)
window_root,
"focus-out-event",
423 g_signal_connect_swapped((gpointer)
window_root,
"key_press_event",
425 g_signal_connect_swapped((gpointer)
window_root,
"key_release_event",
427 g_signal_connect((gpointer)
window_root,
"destroy",
431 geometry.min_width=640;
432 geometry.min_height=480;
435 &geometry, GDK_HINT_MIN_SIZE);
438 "drawingarea_magic_map"));
440 g_signal_connect((gpointer)
magic_map,
"expose_event",
446 fprintf(stderr,
"gdk_color_parse failed (%s)\n",
colorname[i]);
448 if (!gdk_colormap_alloc_color(gtk_widget_get_colormap(
window_root),
450 fprintf(stderr,
"gdk_color_alloc failed\n");
489 g_timeout_add(1000/8, G_SOURCE_FUNC(
self_tick), NULL);
523 int main(
int argc,
char *argv[]) {
526 bind_textdomain_codeset(GETTEXT_PACKAGE,
"UTF-8");
527 bindtextdomain(GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
528 textdomain(GETTEXT_PACKAGE);
532 gtk_init(&argc, &argv);
562 bool sandbox_enabled =
false;
578 sandbox_enabled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
sandbox_enable));
579 if (sandbox_enabled) {
581 if (cap_enter() != 0) {
582 error_dialog(
"Failed to enter sandbox",
"Sandboxing was enabled, but the running kernel does not support sandboxing.");
599 LOG(
LOG_ERROR,
"main",
"Failed to negotiate connection with server");
631 gdk_window_get_geometry(gtk_widget_get_window(win), x, y, w, h, NULL);
633 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.
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])
GtkCheckButton * sandbox_enable
#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.
bool client_negotiate(int sound)
This function negotiates the characteriistics of a connection to the server.
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...