1 /* XQF - Quake server browser and launcher
2  * Copyright (C) 1998-2000 Roman Pozlevich <roma@botik.ru>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
17  */
18 
19 #ifndef __GAME_H__
20 #define __GAME_H__
21 
22 #include <sys/types.h>
23 #include <stdio.h>
24 
25 #include <gtk/gtk.h>
26 
27 #include "xqf.h"
28 #include "launch.h"
29 #include "pixmaps.h"
30 
31 
32 // game->flags
33 enum {
34 	GAME_CONNECT                = 0x0001,
35 	GAME_RECORD                 = 0x0002,
36 	GAME_SPECTATE               = 0x0004,
37 	GAME_PASSWORD               = 0x0008,
38 	GAME_RCON                   = 0x0010,
39 	GAME_ADMIN                  = 0x0020,
40 	GAME_QUAKE1_PLAYER_COLORS   = 0x0100,
41 	GAME_QUAKE1_SKIN            = 0x0200,
42 	GAME_QUAKE3_MASTERPROTOCOL  = 0x0400, // master server protocol version is in games_data["masterprotocol"]
43 	GAME_LAUNCH_HOSTPORT        = 0x0800, // use hostport rule as port when launching
44 	GAME_MASTER_CDKEY           = 0x1000, // master server requires CD key
45 	GAME_Q3COLORS               = 0x2000, // Q3 color codes
46 	GAME_MASTER_STEAM           = 0x4000, // server side filter
47 };
48 
49 struct game {
50 	enum server_type type;
51 	unsigned long flags;
52 
53 	char *name;
54 	unsigned short default_port;
55 	unsigned short default_master_port;
56 
57 	char *id;
58 	char *qstat_str;
59 	char *qstat_option;
60 	char *qstat_master_option;
61 	const char* icon; // xpm symbol name
62 	struct pixmap *pix;
63 
64 	struct player * (*parse_player) (char *tokens[], int num, struct server *s);
65 	void (*parse_server) (char *tokens[], int num, struct server *s);
66 	void (*analyze_serverinfo) (struct server *s);
67 	int (*config_is_valid) (struct server *s);
68 	int (*write_config) (const struct condef *con);
69 	int (*exec_client) (const struct condef *con, int forkit);
70 	/** \brief find a list of custom config files
71 	 *
72 	 * this->main_mods as well as mod directories inside
73 	 * this->real_home and dir will be scanned
74 	 * @param this pointer to game
75 	 * @param dir full path to game directory or NULL to use this->real_dir
76 	 * @param mod which mod
77 	 * @return list of found config files
78 	 */
79 	GList * (*custom_cfgs) (struct game* this, const char *dir, const char *mod);
80 	void (*save_info) (FILE *f, struct server *s);
81 
82 	/* map functions */
83 	/** determine installed maps, destroys previous data */
84 	void (*init_maps)(enum server_type);
85 	/** return true if s->map is installed, false otherwise */
86 	gboolean (*has_map)(struct server* s);
87 	/** acquire image data, function allocates space in buf, returns size. buf
88 	 * must be freed by caller */
89 	size_t (*get_mapshot)(struct server* s, guchar** buf);
90 
91 	char *arch_identifier;
92 	enum CPU (*identify_cpu) (struct server *s, const char *versionstr);
93 	enum OS (*identify_os) (struct server *s, char *versionstr);
94 
95 	char *cmd;
96 	char *dir;
97 	char *real_dir;
98 
99 	/** called when either cmd or dir have changed. Also on xqf startup */
100 	void (*cmd_or_dir_changed)(struct game* g);
101 
102 	/** load preferences from config */
103 	void (*prefs_load)(struct game* g);
104 
105 	/** sync preference dialog to config */
106 	void (*update_prefs)(struct game* g);
107 
108 	/** built in default game specific home directory */
109 	char *default_home;
110 
111 	/** tilde expanded game specific home directory */
112 	char *real_home;
113 
114 	/** NULL terminated list of main mods (eg baseq3 for q3)*/
115 	char** main_mod;
116 
117 	/** NULL terminated list of commands to search in $PATH for suggestion */
118 	char** command;
119 
120 	/** NULL terminated list attributes and keys. used for filling games_data  */
121 	char** attributes;
122 
123 	char *game_cfg;
124 	GData *games_data;
125 	GSList *custom_args;
126 	/** game specific private data */
127 	void *pd;
128 };
129 
130 extern struct game games[];
131 
132 extern enum server_type id2type (const char *id);
133 extern const char *type2id (enum server_type type);
134 extern GtkWidget *game_pixmap_with_label (enum server_type type);
135 
136 // retreive game specific value that belongs to key, do not free return value!
137 const char* game_get_attribute(enum server_type type, const char* key);
138 // set game specific key/value pair, value is _not_ copied but will be freed internally
139 const char* game_set_attribute(enum server_type type, const char* key, char* value);
140 
141 // set game specific key/value pair, value is _not_ copied and will not be freed internally
142 const char* game_set_attribute_const(enum server_type type, const char* attr, const char* value);
143 
144 void init_games(void);
145 void games_done(void);
146 
147 #endif /* __GAME_H__ */
148