- split get_new_defaults into game specific functions

- fix doom3 protocol detection (#1092165)


git-svn-id: http://svn.code.sf.net/p/xqf/code/trunk@702 d2ac09be-c843-0410-8b1f-f8a84130e0ec
This commit is contained in:
Ludwig Nussel 2005-01-12 21:23:11 +00:00 committed by l-n
parent c7e085b5f9
commit 1c3d173975
8 changed files with 183 additions and 149 deletions

View File

@ -1,3 +1,7 @@
Jan 12, 2005: Ludwig Nussel <l-n@users.sourceforge.net>
- split get_new_defaults into game specific functions
- fix doom3 protocol detection (#1092165)
Jan 11, 2005: Ludwig Nussel <l-n@users.sourceforge.net>
- Fix crashes due to wrong return type of callbacks (#1098910, patch by Jochen
Baier)

View File

@ -119,7 +119,6 @@ static gboolean quake_has_map(struct server* s);
static void q3_init_maps(enum server_type);
static size_t q3_get_mapshot(struct server* s, guchar** buf);
static void doom3_cmd_or_dir_changed(struct game* g);
static void doom3_init_maps(enum server_type);
static size_t doom3_get_mapshot(struct server* s, guchar** buf);
static gboolean doom3_has_map(struct server* s);
@ -154,8 +153,6 @@ static struct quake_private cod_private;
static struct quake_private jk3_private;
static struct quake_private doom3_private;
static void ut2004_cmd_or_dir_changed(struct game* g);
#include "games.c"
struct gsname2type_s
@ -3553,74 +3550,4 @@ static gboolean unreal_has_map(struct server* s)
return ut_lookup_map(hash,s->map);
}
static void doom3_cmd_or_dir_changed(struct game* g)
{
FILE* f;
char* verinfo;
const char* attrproto;
char line[64];
debug(3, "cmd: %s, dir: %s", g->cmd, g->real_dir);
attrproto = game_get_attribute(g->type,"masterprotocol");
verinfo = file_in_dir (g->real_dir, "version.info");
f = fopen(verinfo, "r");
if(!f)
goto out;
if(!fgets(line, sizeof(line), f))
goto out;
if(!fgets(line, sizeof(line), f))
goto out;
debug(3, "detected doom3 protocol version %s", line);
game_set_attribute(g->type, "_masterprotocol", g_strdup(line));
out:
if(f) fclose(f);
g_free(verinfo);
}
static void ut2004_cmd_or_dir_changed(struct game* g)
{
FILE* f;
char* keyfile = NULL;
debug(2, "cmd: %s, dir: %s, home: %s", g->cmd, g->real_dir, g->real_home);
keyfile = file_in_dir (g->real_home, "System/cdkey");
if(keyfile)
{
f = fopen(keyfile, "r");
if(!f)
{
g_free(keyfile);
keyfile = NULL;
}
}
if(!keyfile)
{
if(f) fclose(f);
keyfile = file_in_dir (g->real_dir, "System/cdkey");
if(keyfile)
{
f = fopen(keyfile, "r");
if(!f)
{
g_free(keyfile);
keyfile = NULL;
}
}
}
if(keyfile || (!keyfile && game_get_attribute(g->type,"cdkey")))
game_set_attribute(g->type, "cdkey", keyfile);
if(f) fclose(f);
}
// vim: sw=2

View File

@ -97,6 +97,9 @@ struct game {
/** called when either cmd or dir have changed. Also on xqf startup */
void (*cmd_or_dir_changed)(struct game* g);
/** sync preference dialog to config */
void (*update_prefs)(struct game* g);
/** built in default game specific home directory */
char *default_home;

View File

@ -54,6 +54,7 @@ struct game games[] = {
init_maps : quake_init_maps,
has_map : quake_has_map,
cmd_or_dir_changed : q1_cmd_or_dir_changed,
update_prefs : q1_update_prefs,
pd : &q1_private,
main_mod : stringlist000,
command : stringlist001,
@ -81,6 +82,7 @@ struct game games[] = {
init_maps : quake_init_maps,
has_map : quake_has_map,
cmd_or_dir_changed : qw_cmd_or_dir_changed,
update_prefs : qw_update_prefs,
pd : &qw_private,
main_mod : stringlist002,
command : stringlist003,
@ -110,6 +112,7 @@ struct game games[] = {
identify_cpu : identify_cpu,
identify_os : identify_os,
cmd_or_dir_changed : q2_cmd_or_dir_changed,
update_prefs : q2_update_prefs,
pd : &q2_private,
main_mod : stringlist004,
command : stringlist005,
@ -138,6 +141,7 @@ struct game games[] = {
arch_identifier : "version",
identify_cpu : identify_cpu,
identify_os : identify_os,
update_prefs : q3_update_prefs,
default_home : "~/.q3a",
pd : &q3_private,
main_mod : stringlist006,
@ -167,6 +171,7 @@ struct game games[] = {
arch_identifier : "version",
identify_cpu : identify_cpu,
identify_os : identify_os,
update_prefs : wo_update_prefs,
default_home : "~/.wolf",
pd : &wolf_private,
main_mod : stringlist008,
@ -196,6 +201,7 @@ struct game games[] = {
arch_identifier : "version",
identify_cpu : identify_cpu,
identify_os : identify_os,
update_prefs : et_update_prefs,
default_home : "~/.etwolf",
pd : &wolfet_private,
main_mod : stringlist010,
@ -225,7 +231,7 @@ struct game games[] = {
arch_identifier : "si_version",
identify_cpu : identify_cpu,
identify_os : identify_os,
cmd_or_dir_changed : doom3_cmd_or_dir_changed,
update_prefs : doom3_update_prefs,
default_home : "~/.doom3",
pd : &doom3_private,
main_mod : stringlist012,
@ -252,6 +258,7 @@ struct game games[] = {
arch_identifier : "version",
identify_cpu : identify_cpu,
identify_os : identify_os,
update_prefs : ef_update_prefs,
main_mod : stringlist014,
},
{
@ -402,6 +409,7 @@ struct game games[] = {
save_info : quake_save_info,
arch_identifier : "linux",
identify_os : t2_identify_os,
update_prefs : tribes2_update_prefs,
command : stringlist017,
},
{
@ -480,7 +488,7 @@ struct game games[] = {
save_info : quake_save_info,
init_maps : unreal_init_maps,
has_map : unreal_has_map,
cmd_or_dir_changed : ut2004_cmd_or_dir_changed,
update_prefs : ut2004_update_prefs,
default_home : "~/.ut2004",
pd : &ut2004_private,
command : stringlist020,
@ -648,6 +656,7 @@ struct game games[] = {
get_mapshot : q3_get_mapshot,
identify_cpu : identify_cpu,
identify_os : identify_os,
update_prefs : cod_update_prefs,
pd : &cod_private,
main_mod : stringlist029,
command : stringlist030,
@ -708,6 +717,7 @@ struct game games[] = {
get_mapshot : q3_get_mapshot,
identify_cpu : identify_cpu,
identify_os : identify_os,
update_prefs : jk3_update_prefs,
pd : &jk3_private,
main_mod : stringlist032,
command : stringlist033,

View File

@ -26,6 +26,7 @@
<identify_os/>
<command/>
<cmd_or_dir_changed/>
<update_prefs/>
<default_home/>
<main_mod/>
<pd/>
@ -52,6 +53,7 @@
<command>nq-sgl</command>
<command>twilight-nq</command>
<cmd_or_dir_changed>q1_cmd_or_dir_changed</cmd_or_dir_changed>
<update_prefs>q1_update_prefs</update_prefs>
<main_mod>id1</main_mod>
<pd>q1_private</pd>
</game>
@ -81,6 +83,7 @@
<command>qw-client-sgl</command>
<command>twilight-qw</command>
<cmd_or_dir_changed>qw_cmd_or_dir_changed</cmd_or_dir_changed>
<update_prefs>qw_update_prefs</update_prefs>
<main_mod>qw</main_mod>
<main_mod>id1</main_mod>
<pd>qw_private</pd>
@ -109,6 +112,7 @@
<identify_os>identify_os</identify_os>
<command>quake2</command>
<cmd_or_dir_changed>q2_cmd_or_dir_changed</cmd_or_dir_changed>
<update_prefs>q2_update_prefs</update_prefs>
<main_mod>baseq2</main_mod>
<pd>q2_private</pd>
</game>
@ -137,6 +141,7 @@
<command>quake3</command>
<command>q3</command>
<default_home>~/.q3a</default_home>
<update_prefs>q3_update_prefs</update_prefs>
<main_mod>demoq3</main_mod>
<main_mod>baseq3</main_mod>
<pd>q3_private</pd>
@ -153,6 +158,7 @@
<config_is_valid>config_is_valid_generic</config_is_valid>
<command>wolf</command>
<default_home>~/.wolf</default_home>
<update_prefs>wo_update_prefs</update_prefs>
<main_mod>demomain</main_mod>
<main_mod>main</main_mod>
<main_mod>wolfmp</main_mod>
@ -170,6 +176,7 @@
<config_is_valid>config_is_valid_generic</config_is_valid>
<command>et</command>
<default_home>~/.etwolf</default_home>
<update_prefs>et_update_prefs</update_prefs>
<main_mod>etmain</main_mod>
<pd>wolfet_private</pd>
</game>
@ -192,7 +199,7 @@
<get_mapshot>doom3_get_mapshot</get_mapshot>
<arch_identifier>si_version</arch_identifier>
<command>doom3</command>
<cmd_or_dir_changed>doom3_cmd_or_dir_changed</cmd_or_dir_changed>
<update_prefs>doom3_update_prefs</update_prefs>
<default_home>~/.doom3</default_home>
<main_mod>base</main_mod>
<pd>doom3_private</pd>
@ -210,6 +217,7 @@
<init_maps>NULL</init_maps>
<has_map>NULL</has_map>
<get_mapshot>NULL</get_mapshot>
<update_prefs>ef_update_prefs</update_prefs>
<main_mod>BaseEF</main_mod>
</game>
<game>
@ -331,6 +339,7 @@
<arch_identifier>linux</arch_identifier>
<identify_os>t2_identify_os</identify_os>
<command>tribes2</command>
<update_prefs>tribes2_update_prefs</update_prefs>
</game>
<game>
<type>HR_SERVER</type>
@ -389,7 +398,7 @@
<icon>ut2004_xpm</icon>
<command>ut2004demo</command>
<command>ut2004</command>
<cmd_or_dir_changed>ut2004_cmd_or_dir_changed</cmd_or_dir_changed>
<update_prefs>ut2004_update_prefs</update_prefs>
<default_home>~/.ut2004</default_home>
<pd>ut2004_private</pd>
</game>
@ -493,6 +502,7 @@
<config_is_valid>config_is_valid_generic</config_is_valid>
<arch_identifier>NULL</arch_identifier>
<command>codmp</command>
<update_prefs>cod_update_prefs</update_prefs>
<main_mod>main</main_mod>
<pd>cod_private</pd>
</game>
@ -537,6 +547,7 @@
<config_is_valid>config_is_valid_generic</config_is_valid>
<arch_identifier>NULL</arch_identifier>
<command>jamp</command>
<update_prefs>jk3_update_prefs</update_prefs>
<main_mod>base</main_mod>
<pd>jk3_private</pd>
</game>

View File

@ -53,6 +53,7 @@ typedef enum
TAG_identify_cpu,
TAG_identify_os,
TAG_cmd_or_dir_changed,
TAG_update_prefs,
TAG_default_home,
TAG_pd,
TAG_end_basic = TAG_pd,
@ -126,6 +127,7 @@ static void tags_init()
add_tag(TAG_identify_cpu, Tag_do_inherit, Tag_type_literal, "identify_cpu");
add_tag(TAG_identify_os, Tag_do_inherit, Tag_type_literal, "identify_os");
add_tag(TAG_cmd_or_dir_changed, Tag_do_inherit, Tag_type_literal, "cmd_or_dir_changed");
add_tag(TAG_update_prefs, Tag_no_inherit, Tag_type_literal, "update_prefs");
add_tag(TAG_default_home, Tag_no_inherit, Tag_type_string, "default_home");
add_tag(TAG_pd, Tag_no_inherit, Tag_type_address, "pd");
add_tag(TAG_data, Tag_no_inherit, Tag_type_literal, "data");

View File

@ -484,6 +484,10 @@ static void get_new_defaults_for_game (enum server_type type) {
str = config_get_string_with_default (buf,&isdefault);
}
}
if(g->update_prefs)
g->update_prefs(g);
config_pop_prefix ();
}
@ -530,7 +534,7 @@ static void load_game_defaults (enum server_type type) {
}
// verify Quake3 settings, return false if something's not ok
static int verify_q3_settings (void)
int verify_q3_settings (void)
{
int com_hunkmegs = 0;
int com_zonemegs = 0;
@ -550,15 +554,9 @@ static int verify_q3_settings (void)
return TRUE;
}
static void get_new_defaults (void) {
int i;
char *str,*str1;
debug (5, "get_new_defaults()");
/* Quake */
config_push_prefix ("/" CONFIG_FILE "/Game: QS");
void q1_update_prefs (struct game* g)
{
char* str;
if (pref_q1_top_color != default_q1_top_color)
config_set_int ("top", default_q1_top_color = pref_q1_top_color);
@ -574,12 +572,13 @@ static void get_new_defaults (void) {
config_set_string ("player name", (str)? str : "");
}
str=NULL;
}
config_pop_prefix ();
/* QuakeWorld (some network settings are used by Q2) */
config_push_prefix ("/" CONFIG_FILE "/Game: QWS");
/* QuakeWorld (some network settings are used by Q2) */
void qw_update_prefs (struct game* g)
{
char* str;
int i;
str = strdup_strip (gtk_entry_get_text (GTK_ENTRY (name_qw_entry)));
if (str == NULL || default_qw_name == NULL ||
@ -654,12 +653,12 @@ static void get_new_defaults (void) {
i = GTK_TOGGLE_BUTTON (qw_is_quakeforge_button)->active;
if (i != default_qw_is_quakeforge)
config_set_int ("is quakeforge", default_qw_is_quakeforge = i);
}
config_pop_prefix ();
/* Quake2 */
config_push_prefix ("/" CONFIG_FILE "/Game: Q2S");
void q2_update_prefs (struct game* g)
{
char* str;
int i;
if (pref_q2_skin == NULL ||
(default_q2_skin && strcmp (pref_q2_skin, default_q2_skin))) {
@ -692,12 +691,12 @@ static void get_new_defaults (void) {
if (pref_q2_noskins != default_q2_noskins)
config_set_int ("noskins", default_q2_noskins = pref_q2_noskins);
}
config_pop_prefix ();
/* Quake 3 */
config_push_prefix ("/" CONFIG_FILE "/Game: Q3S");
void q3_update_prefs (struct game* g)
{
char* str, *str1;
int i;
str = strdup_strip (gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (q3proto_entry)->entry)));
// locate first space and mark it as str's end
@ -751,12 +750,12 @@ static void get_new_defaults (void) {
i = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(cg_precachedmodels_spinner));
config_set_int ("cg_precachedmodels", i);
game_set_attribute(Q3_SERVER,"cg_precachedmodels",g_strdup_printf("%d",i));
}
config_pop_prefix ();
/* Wolfenstein */
config_push_prefix ("/" CONFIG_FILE "/Game: WOS");
void wo_update_prefs (struct game* g)
{
char* str, *str1;
int i;
str = strdup_strip (gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (wo_proto_entry)->entry)));
// locate first space and mark it as str's end
@ -775,12 +774,12 @@ static void get_new_defaults (void) {
i = GTK_TOGGLE_BUTTON (wo_set_punkbusterbutton)->active;
config_set_bool ("set_punkbuster", i);
game_set_attribute(WO_SERVER,"set_punkbuster",g_strdup(bool2str(i)));
config_pop_prefix ();
}
/* Enemy Territory */
config_push_prefix ("/" CONFIG_FILE "/Game: WOETS");
void et_update_prefs (struct game* g)
{
char* str, *str1;
int i;
str = strdup_strip (gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (woet_proto_entry)->entry)));
// locate first space and mark it as str's end
@ -795,12 +794,42 @@ static void get_new_defaults (void) {
i = GTK_TOGGLE_BUTTON (woet_setfs_gamebutton)->active;
config_set_bool ("setfs_game", i);
game_set_attribute(WOET_SERVER,"setfs_game",g_strdup(bool2str(i)));
}
config_pop_prefix ();
static void doom3_detect_version(struct game* g)
{
FILE* f;
char* verinfo;
const char* attrproto;
char line[64];
/* doom3 */
debug(3, "cmd: %s, dir: %s", g->cmd, g->real_dir);
config_push_prefix ("/" CONFIG_FILE "/Game: DOOM3");
attrproto = game_get_attribute(g->type,"masterprotocol");
verinfo = file_in_dir (g->real_dir, "version.info");
f = fopen(verinfo, "r");
if(!f)
goto out;
if(!fgets(line, sizeof(line), f))
goto out;
if(!fgets(line, sizeof(line), f))
goto out;
debug(3, "detected doom3 protocol version %s", line);
game_set_attribute(g->type, "_masterprotocol", g_strdup(line));
out:
if(f) fclose(f);
g_free(verinfo);
}
void doom3_update_prefs (struct game* g)
{
char* str, *str1;
str = strdup_strip (gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (doom3_proto_entry)->entry)));
// locate first space and mark it as str's end
@ -812,11 +841,13 @@ static void get_new_defaults (void) {
g_free(str);
str=NULL;
config_pop_prefix ();
doom3_detect_version(g);
}
/* Voyager Elite Force */
config_push_prefix ("/" CONFIG_FILE "/Game: EFS");
void ef_update_prefs (struct game* g)
{
char* str, *str1;
int i;
str = strdup_strip (gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (ef_proto_entry)->entry)));
// locate first space and mark it as str's end
@ -831,12 +862,11 @@ static void get_new_defaults (void) {
i = GTK_TOGGLE_BUTTON (ef_setfs_gamebutton)->active;
config_set_bool ("setfs_game", i);
game_set_attribute(EF_SERVER,"setfs_game",g_strdup(bool2str(i)));
}
config_pop_prefix ();
/* Call of Duty */
config_push_prefix ("/" CONFIG_FILE "/Game: CODS");
void cod_update_prefs (struct game* g)
{
char* str, *str1;
str = strdup_strip (gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (cod_proto_entry)->entry)));
// locate first space and mark it as str's end
@ -847,12 +877,11 @@ static void get_new_defaults (void) {
config_set_string ("protocol", (str)? str : "");
g_free(str);
str=NULL;
}
config_pop_prefix ();
/* Jedi Academy */
config_push_prefix ("/" CONFIG_FILE "/Game: JK3S");
void jk3_update_prefs (struct game* g)
{
char* str, *str1;
str = strdup_strip (gtk_entry_get_text (GTK_ENTRY (GTK_COMBO (jk3_proto_entry)->entry)));
// locate first space and mark it as str's end
@ -863,12 +892,11 @@ static void get_new_defaults (void) {
config_set_string ("protocol", (str)? str : "");
g_free(str);
str=NULL;
}
config_pop_prefix ();
/* Tribes 2 */
config_push_prefix ("/" CONFIG_FILE "/Game: T2S");
void tribes2_update_prefs (struct game* g)
{
char* str;
str = strdup_strip (gtk_entry_get_text (GTK_ENTRY (name_t2_entry)));
if (str == NULL || default_t2_name == NULL ||
@ -878,8 +906,57 @@ static void get_new_defaults (void) {
config_set_string ("player name", (str)? str : "");
}
str=NULL;
}
config_pop_prefix ();
static void ut2004_detect_cdkey(struct game* g)
{
FILE* f;
char* keyfile = NULL;
debug(2, "cmd: %s, dir: %s, home: %s", g->cmd, g->real_dir, g->real_home);
keyfile = file_in_dir (g->real_home, "System/cdkey");
if(keyfile)
{
f = fopen(keyfile, "r");
if(!f)
{
g_free(keyfile);
keyfile = NULL;
}
}
if(!keyfile)
{
if(f) fclose(f);
keyfile = file_in_dir (g->real_dir, "System/cdkey");
if(keyfile)
{
f = fopen(keyfile, "r");
if(!f)
{
g_free(keyfile);
keyfile = NULL;
}
}
}
if(keyfile || (!keyfile && game_get_attribute(g->type,"cdkey")))
game_set_attribute(g->type, "cdkey", keyfile);
if(f) fclose(f);
}
void ut2004_update_prefs (struct game* g)
{
ut2004_detect_cdkey(g);
}
static void get_new_defaults (void) {
int i;
static const char form[] = "/" CONFIG_FILE "/Game: %s";
debug (5, "get_new_defaults()");
/* Common part of games config */
@ -3294,14 +3371,6 @@ static GtkWidget *woet_options_page (void) {
return page_vbox;
}
static gboolean doom3_proto_entry_activate_callback (GtkWidget *widget, gpointer data)
{
games[DOOM3_SERVER].cmd_or_dir_changed(&games[DOOM3_SERVER]);
return FALSE;
}
// additional options for doom3
static GtkWidget *doom3_options_page (void) {
GtkWidget *page_vbox;
@ -3328,12 +3397,6 @@ static GtkWidget *doom3_options_page (void) {
gtk_entry_set_text (GTK_ENTRY (GTK_COMBO (doom3_proto_entry)->entry),
game_get_attribute(DOOM3_SERVER,"masterprotocol"));
gtk_signal_connect (GTK_OBJECT (GTK_COMBO (doom3_proto_entry)->entry),
"activate", GTK_SIGNAL_FUNC (doom3_proto_entry_activate_callback), NULL);
gtk_signal_connect (GTK_OBJECT (GTK_COMBO (doom3_proto_entry)->entry),
"focus_out_event", GTK_SIGNAL_FUNC (doom3_proto_entry_activate_callback), NULL);
gtk_box_pack_start (GTK_BOX (hbox), doom3_proto_entry, FALSE, FALSE, 0);
gtk_widget_show (doom3_proto_entry);

View File

@ -21,6 +21,7 @@
#include <gtk/gtk.h>
#include "game.h"
#ifndef PATH_MAX
@ -120,6 +121,19 @@ extern char *sound_redial_success;
// Any other game with Q3 engine
//extern struct q3engineopts generic_q3_opts;
void q1_update_prefs (struct game* g);
void qw_update_prefs (struct game* g);
void q2_update_prefs (struct game* g);
void q3_update_prefs (struct game* g);
void wo_update_prefs (struct game* g);
void et_update_prefs (struct game* g);
void doom3_update_prefs (struct game* g);
void ef_update_prefs (struct game* g);
void cod_update_prefs (struct game* g);
void jk3_update_prefs (struct game* g);
void tribes2_update_prefs (struct game* g);
void ut2004_update_prefs (struct game* g);
extern int set_working_dir (char *dir);
extern void preferences_dialog (int page_num);
extern int fix_qw_player_color (int color);