As the subject says. The patch should apply to client trunk rev 19091.
The fix is in three parts: * If no character name is given (is NULL), don't load or save character-specific keys file. * Load key bindings directly on startup, when name is NULL. * If playing on a server with a login process, set the character name and load key bindings again. Also, please do not modify the patches when applying them since it messes up any patches that I have queued. If something should be changed, tell me what and I'll generate a new one. Thanks, Arvid
>From 72b2d4af20da13b00753119ada19016c9209f6fa Mon Sep 17 00:00:00 2001 From: Arvid Brodin <arv...@kth.se> Date: Tue, 5 Nov 2013 00:15:14 +0100 Subject: [PATCH] Fix keybinding bug when connected to server-1.12. Signed-off-by: Arvid Brodin <arv...@kth.se> --- gtk-v2/src/account.c | 6 +----- gtk-v2/src/create_char.c | 6 +----- gtk-v2/src/gtk2proto.h | 2 +- gtk-v2/src/keys.c | 38 ++++++++++++++++++++++++++++++++------ 4 files changed, 35 insertions(+), 17 deletions(-) diff --git a/gtk-v2/src/account.c b/gtk-v2/src/account.c index 4b1b598..02930ed 100644 --- a/gtk-v2/src/account.c +++ b/gtk-v2/src/account.c @@ -503,11 +503,7 @@ static void play_character(const char *name) SockList_AddString(&sl, name); SockList_Send(&sl, csocket.fd); - if (cpl.name) { - free(cpl.name); - } - cpl.name = strdup(name); - keybindings_init(); + keybindings_init(name); } /** diff --git a/gtk-v2/src/create_char.c b/gtk-v2/src/create_char.c index ebca675..735107b 100644 --- a/gtk-v2/src/create_char.c +++ b/gtk-v2/src/create_char.c @@ -357,11 +357,7 @@ static void send_create_player_to_server() SockList_Send(&sl, csocket.fd); - if (cpl.name) { - free(cpl.name); - } - cpl.name = strdup(char_name); - keybindings_init(); + keybindings_init(char_name); } diff --git a/gtk-v2/src/gtk2proto.h b/gtk-v2/src/gtk2proto.h index 0e894a5..e87c54f 100644 --- a/gtk-v2/src/gtk2proto.h +++ b/gtk-v2/src/gtk2proto.h @@ -112,7 +112,7 @@ extern void animate_inventory(void); extern void animate_look(void); extern void inventory_tick(void); /* keys.c */ -extern void keybindings_init(); +extern void keybindings_init(const char *character_name); extern void keys_init(GtkWidget *window_root); extern void bind_key(char *params); extern void unbind_key(const char *params); diff --git a/gtk-v2/src/keys.c b/gtk-v2/src/keys.c index 3fdcd9b..200d69d 100644 --- a/gtk-v2/src/keys.c +++ b/gtk-v2/src/keys.c @@ -501,7 +501,7 @@ static int parse_keys_file(char *filename) * from main() as part of the client start up. The function is common to both * the x11 and gdk clients. */ -void keybindings_init() +void keybindings_init(const char *character_name) { int i; char buf[BIG_BUF]; @@ -540,6 +540,18 @@ void keybindings_init() } /* + * If we were supplied with a character name, store it so that we + * can load and save a character-specific keys file. + */ + if (cpl.name) { + free(cpl.name); + cpl.name = NULL; + } + if (character_name) { + cpl.name = strdup(character_name); + } + + /* * We now try to load the keybindings. First place to look is the users * home directory, "~/.crossfire/keys". Using a directory seems like a * good idea, in the future, additional stuff may be stored. @@ -549,10 +561,12 @@ void keybindings_init() * in character files to this format, all that needs to be done is remove * the 'key ' at the start of each line. */ - - /* Try the character-specific keys file */ - snprintf(buf, sizeof(buf), "%s/.crossfire/%s.keys", getenv("HOME"), cpl.name); - res = parse_keys_file(buf); + res = -1; + if (cpl.name) { + /* Try the character-specific keys file */ + snprintf(buf, sizeof(buf), "%s/.crossfire/%s.keys", getenv("HOME"), cpl.name); + res = parse_keys_file(buf); + } if (res < 0) { /* Try the user-specific keys file */ snprintf(buf, sizeof(buf), "%s/.crossfire/keys", getenv("HOME")); @@ -696,6 +710,14 @@ void keys_init(GtkWidget *window_root) for (i = 0; i < KEYHASH; i++) { keys[i] = NULL; } + + /* + * Old servers (e.g. 1.12) starts game play without a login + * process. We can't get the character name on such a server, so + * load default (or user-specific) key bindings here in case we + * don't get the character-specific one later. + */ + keybindings_init(NULL); } /** @@ -1197,7 +1219,11 @@ static void save_keys(void) int i; FILE *fp; - snprintf(buf, sizeof(buf), "%s/.crossfire/%s.keys", getenv("HOME"), cpl.name); + if (cpl.name) { + snprintf(buf, sizeof(buf), "%s/.crossfire/%s.keys", getenv("HOME"), cpl.name); + } else { + snprintf(buf, sizeof(buf), "%s/.crossfire/keys", getenv("HOME")); + } CONVERT_FILESPEC_TO_OS_FORMAT(buf); LOG(LOG_WARNING, "gtk-v2::save_keys", "Saving keybindings to %s", buf); -- 1.8.1.5
_______________________________________________ crossfire mailing list crossfire@metalforge.org http://mailman.metalforge.org/mailman/listinfo/crossfire