Crossfire Client, Trunk  R20612
init.c
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 1999-2013 Mark Wedel and the Crossfire Development Team
5  * Copyright (c) 1992 Frank Tore Johansen
6  *
7  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
8  * welcome to redistribute it under certain conditions. For details, please
9  * see COPYING and LICENSE.
10  *
11  * The authors can be reached via e-mail at <crossfire@metalforge.org>.
12  */
13 
19 #include "client.h"
20 #include "mapdata.h"
21 #include "metaserver.h"
22 #include "p_cmd.h"
23 
24 /* Makes the load/save code trivial - basically, the
25  * entries here match the same numbers as the CONFIG_ values defined
26  * in common/client.h - this means the load and save just does
27  * something like a fprintf(outifle, "%s: %d", config_names[i],
28  * want_config[i]);
29  */
30 const char *const config_names[CONFIG_NUMS] = {
31  NULL, "download_all_images", "echo_bindings",
32  "fasttcpsend", "command_window", "cacheimages", "fog_of_war", "iconscale",
33  "mapscale", "popups", "displaymode", "showicon", "tooltips", "sound", "splitinfo",
34  "split", "show_grid", "lighting", "trim_info_window",
35  "map_width", "map_height", "foodbeep", "darkness", "port",
36  "grad_color_bars", "resistances", "smoothing", "nosplash",
37  "auto_apply_container", "mapscroll", "sign_popups", "message_timestamping"
38 };
39 
41 
42 #define FREE_AND_CLEAR(xyz) { free(xyz); xyz=NULL; }
43 
44 void VersionCmd(char *data, int len) {
45  char *cp;
46 
47  csocket.cs_version = atoi(data);
48  /* set sc_version in case it is an old server supplying only one version */
50  if (csocket.cs_version != VERSION_CS) {
51  LOG(LOG_WARNING, "common::VersionCmd", "Differing C->S version numbers (%d,%d)",
53  /* exit(1);*/
54  }
55  cp = strchr(data, ' ');
56  if (!cp) {
57  return;
58  }
59  csocket.sc_version = atoi(cp);
60  if (csocket.sc_version != VERSION_SC) {
61  LOG(LOG_WARNING, "common::VersionCmd", "Differing S->C version numbers (%d,%d)",
63  }
64  cp = strchr(cp + 1, ' ');
65  if (cp) {
66  LOG(LOG_DEBUG, "common::VersionCmd", "Playing on server type %s", cp);
67  }
68 }
69 
71  cs_print_string(csock.fd, "version %d %d %s",
73 }
74 
75 void SendAddMe(ClientSocket csock) {
76  cs_print_string(csock.fd, "addme");
77 }
78 
79 static void init_paths() {
80  // Set and create configuration and cache directories.
81  GString *app_config_dir = g_string_new(g_get_user_config_dir());
82  g_string_append(app_config_dir, "/crossfire");
83  config_dir = g_string_free(app_config_dir, FALSE);
84  g_mkdir_with_parents(config_dir, 0755);
85 
86  GString *app_cache_dir = g_string_new(g_get_user_cache_dir());
87  g_string_append(app_cache_dir, "/crossfire");
88  cache_dir = g_string_free(app_cache_dir, FALSE);
89  g_mkdir_with_parents(cache_dir, 0755);
90 }
91 
96 static void reset_vars_common() {
97  cpl.count_left = 0;
98  cpl.container = NULL;
99  memset(&cpl.stats, 0, sizeof(Stats));
100  cpl.stats.maxsp = 1; /* avoid div by 0 errors */
101  cpl.stats.maxhp = 1; /* ditto */
102  cpl.stats.maxgrace = 1; /* ditto */
103 
104  /* ditto - displayed weapon speed is weapon speed/speed */
105  cpl.stats.speed = 1;
106  cpl.input_text[0] = '\0';
107  cpl.title[0] = '\0';
108  cpl.range[0] = '\0';
109  cpl.last_command[0] = '\0';
110 
111  for (int i = 0; i < range_size; i++) {
112  cpl.ranges[i] = NULL;
113  }
114 
115  csocket.command_sent = 0;
117  csocket.command_time = 0;
118 
119  cpl.magicmap = NULL;
120  cpl.showmagic = 0;
121 
123  face_info.cache_hits = 0;
125  face_info.faceset = 0;
127  face_info.num_images = 0;
128 
129  stat_points = 0;
130  stat_min = 0;
131  stat_maximum = 0;
132 
133  mapdata_init();
135 }
136 
140 static void init_config() {
142  want_config[CONFIG_CACHE] = FALSE;
146  want_config[CONFIG_DOWNLOAD] = FALSE;
147  want_config[CONFIG_ECHO] = FALSE;
148  want_config[CONFIG_FASTTCP] = TRUE;
149  want_config[CONFIG_FOGWAR] = TRUE;
150  want_config[CONFIG_FOODBEEP] = FALSE;
158  want_config[CONFIG_POPUPS] = FALSE;
162  want_config[CONFIG_SHOWGRID] = FALSE;
163  want_config[CONFIG_SHOWICON] = FALSE;
166  want_config[CONFIG_SOUND] = TRUE;
167  want_config[CONFIG_SPLASH] = TRUE;
168  want_config[CONFIG_SPLITINFO] = FALSE;
169  want_config[CONFIG_SPLITWIN] = FALSE;
170  want_config[CONFIG_TIMESTAMP] = FALSE;
172  want_config[CONFIG_TRIMINFO] = FALSE;
173 
174  for (int i = 0; i < CONFIG_NUMS; i++) {
175  use_config[i] = want_config[i];
176  }
177 }
178 
184 void client_init() {
185  // Initialize experience tables.
186  exp_table = NULL;
187  exp_table_max = 0;
188 
190 
191  // Clear out variables related to image face caching.
193  face_info.want_faceset = NULL;
194 
195  for (int i = 0; i < MAX_FACE_SETS; i++) {
196  face_info.facesets[i].prefix = NULL;
197  face_info.facesets[i].fullname = NULL;
198  face_info.facesets[i].fallback = 0;
199  face_info.facesets[i].size = NULL;
200  face_info.facesets[i].extension = NULL;
201  face_info.facesets[i].comment = NULL;
202  }
203 
204  // Allocate memory for player-related objects.
205  cpl.ob = player_item();
206  cpl.below = map_item();
207 
209 
210  for (int i = 0; i < MAX_SKILL; i++) {
211  skill_names[i] = NULL;
212  last_used_skills[i] = -1;
213  }
214 
215  init_commands();
216  init_config();
217  init_paths();
218 
219  // Paths must be set before metaserver can be initialized.
220  ms_init();
221 }
222 
227  int i;
228 
229  for (i = 0; i < MAX_SKILL; i++) {
230  cpl.stats.skill_exp[i] = 0;
231  cpl.stats.skill_level[i] = 0;
232  }
233 }
234 
239 void client_reset() {
240  int i;
241 
242  /* Keep old checksum to compare it with the next server's checksum. */
244 
245  for (i = 0; i < MAX_FACE_SETS; i++) {
248  face_info.facesets[i].fallback = 0;
252  }
253 
255 
256  for (i = 0; i < MAX_SKILL; i++) {
258  }
259 
260  if (motd) {
262  }
263 
264  if (news) {
266  }
267 
268  if (rules) {
270  }
271 
272  if (races) {
274  num_races = 0;
275  used_races = 0;
276  races = NULL;
277  }
278 
279  if (classes) {
281  num_classes = 0;
282  used_classes = 0;
283  classes = NULL;
284  }
285 
286  serverloginmethod = 0;
287 }
#define VERSION_CS
Definition: client.h:67
void free_all_race_class_info(Race_Class_Info *data, int num_entries)
Definition: commands.c:420
char * comment
Definition: client.h:406
char * news
Definition: client.h:555
#define CONFIG_FASTTCP
Definition: client.h:187
#define COMMAND_WINDOW
Definition: client.h:76
static void init_paths()
Definition: init.c:79
int command_time
Definition: client.h:128
GSocketConnection * fd
Definition: client.h:120
int used_classes
Definition: commands.c:91
#define CONFIG_TOOLTIPS
Definition: client.h:196
int stat_points
Definition: commands.c:93
#define CONFIG_RESISTS
Definition: client.h:209
#define CONFIG_SHOWGRID
Definition: client.h:200
void ms_init()
Definition: metaserver.c:257
guint8 fallback
Definition: client.h:401
gint64 skill_exp[MAX_SKILL]
Definition: client.h:290
void client_init()
Definition: init.c:184
Race_Class_Info * races
Definition: commands.c:98
void reset_player_data()
Definition: init.c:226
int sc_version
Definition: client.h:121
guint8 have_faceset_info
Definition: client.h:425
gint16 want_config[CONFIG_NUMS]
Definition: init.c:40
#define CONFIG_LIGHTING
Definition: client.h:201
#define MAX_SKILL
Definition: client.h:84
#define CONFIG_POPUPS
Definition: client.h:193
char * rules
Definition: client.h:555
gint16 maxsp
Definition: client.h:265
item * ob
Definition: client.h:336
#define CONFIG_DISPLAYMODE
Definition: client.h:194
int num_classes
Definition: commands.c:90
Warning that something might not work.
Definition: client.h:443
gint32 speed
Definition: client.h:275
ClientSocket csocket
Definition: client.c:69
FaceSets facesets[MAX_FACE_SETS]
Definition: client.h:428
#define CONFIG_FOODBEEP
Definition: client.h:205
Face_Information face_info
Definition: image.c:169
Stats stats
Definition: client.h:349
#define CONFIG_SHOWICON
Definition: client.h:195
const char * cache_dir
Definition: client.c:53
#define CONFIG_SPLITINFO
Definition: client.h:198
static void reset_vars_common()
Definition: init.c:96
guint32 bmaps_checksum
Definition: client.h:417
char * prefix
Definition: client.h:402
int serverloginmethod
Definition: client.c:59
guint8 * magicmap
Definition: client.h:363
char VERSION_INFO[MAX_BUF]
Definition: client.c:48
char * skill_names[MAX_SKILL]
Definition: client.c:50
#define EPORT
Definition: client.h:62
guint64 * exp_table
Definition: client.c:64
#define CONFIG_MAPSCROLL
Definition: client.h:213
void LOG(LogLevel level, const char *origin, const char *format,...)
Definition: misc.c:109
char * size
Definition: client.h:404
#define CONFIG_SPLASH
Definition: client.h:211
#define CFG_DM_PIXMAP
Definition: client.h:239
int stat_maximum
Definition: commands.c:95
void init_commands()
Definition: p_cmd.c:376
item * below
Definition: client.h:337
Client_Player cpl
Definition: client.c:68
#define CONFIG_GRAD_COLOR
Definition: client.h:208
#define CONFIG_SIGNPOPUP
Definition: client.h:216
item * container
Definition: client.h:339
#define CONFIG_APPLY_CONTAINER
Definition: client.h:212
#define CONFIG_DARKNESS
Definition: client.h:206
int stat_min
Definition: commands.c:94
#define CONFIG_MAPHEIGHT
Definition: client.h:204
void mapdata_init(void)
Definition: mapdata.c:556
#define CONFIG_PORT
Definition: client.h:207
#define CONFIG_CWINDOW
Definition: client.h:188
gint16 use_config[CONFIG_NUMS]
Definition: init.c:40
#define CONFIG_CACHE
Definition: client.h:189
const char *const config_names[CONFIG_NUMS]
Definition: init.c:30
char last_command[MAX_BUF]
Definition: client.h:342
const char * config_dir
Definition: client.c:52
#define CONFIG_NUMS
Definition: client.h:218
guint16 count_left
Definition: client.h:340
int num_races
Definition: commands.c:87
#define MAX_FACE_SETS
Definition: client.h:383
#define CONFIG_DOWNLOAD
Definition: client.h:185
int last_used_skills[MAX_SKILL+1]
Definition: client.c:55
char * extension
Definition: client.h:405
void SendAddMe(ClientSocket csock)
Definition: init.c:75
void VersionCmd(char *data, int len)
Definition: init.c:44
#define CONFIG_TRIMINFO
Definition: client.h:202
#define CFG_LT_TILE
Definition: client.h:229
gint16 skill_level[MAX_SKILL]
Definition: client.h:289
guint8 showmagic
Definition: client.h:364
guint32 old_bmaps_checksum
Definition: client.h:417
#define CONFIG_ICONSCALE
Definition: client.h:191
void client_reset()
Definition: init.c:239
#define CONFIG_TIMESTAMP
Definition: client.h:217
item * ranges[range_size]
Definition: client.h:344
#define CONFIG_SMOOTH
Definition: client.h:210
int used_races
Definition: commands.c:88
#define VERSION_SC
Definition: client.h:68
char * fullname
Definition: client.h:403
int command_sent
Definition: client.h:123
item * map_item(void)
Definition: item.c:637
char range[MAX_BUF]
Definition: client.h:352
int command_received
Definition: client.h:123
gint16 maxhp
Definition: client.h:263
#define CONFIG_SOUND
Definition: client.h:197
char title[MAX_BUF]
Definition: client.h:351
int cs_print_string(GSocketConnection *fd, const char *str,...)
Definition: newsocket.c:245
char input_text[MAX_BUF]
Definition: client.h:343
item * player_item(void)
Definition: item.c:631
static void init_config()
Definition: init.c:140
#define CONFIG_ECHO
Definition: client.h:186
#define FREE_AND_CLEAR(xyz)
Definition: init.c:42
void SendVersion(ClientSocket csock)
Definition: init.c:70
Useful debugging information.
Definition: client.h:441
#define CONFIG_FOGWAR
Definition: client.h:190
char * motd
Definition: client.h:555
guint16 exp_table_max
Definition: client.c:63
#define CONFIG_SPLITWIN
Definition: client.h:199
Race_Class_Info * classes
Definition: commands.c:98
#define CONFIG_MAPSCALE
Definition: client.h:192
#define CONFIG_MAPWIDTH
Definition: client.h:203
int cs_version
Definition: client.h:121
gint16 maxgrace
Definition: client.h:267