Crossfire Client, Branches  R11627
init.c
Go to the documentation of this file.
1 const char * const rcsid_common_init_c =
2  "$Id: init.c 10973 2008-12-14 08:51:26Z ryo_saeba $";
3 /*
4  Crossfire client, a client program for the crossfire program.
5 
6  Copyright (C) 2001 Mark Wedel & Crossfire Development Team
7 
8  This program is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 
22  The author can be reached via e-mail to crossfire-devel@real-time.com
23 */
24 
25 /* This handles the initialization of the client. This includes making
26  * the I_IMAGE and I_ARCH commands.
27  */
28 
29 #include <client.h>
30 #include "p_cmd.h" /* init_commands() */
31 
32 /* XXX Does the x11 client *use* these? */
33 
34 /* Makes the load/save code trivial - basically, the
35  * entries here match the same numbers as the CONFIG_ values defined
36  * in common/client.h - this means the load and save just does
37  * something like a fprintf(outifle, "%s: %d", config_names[i],
38  * want_config[i]);
39  */
40 const char *const config_names[CONFIG_NUMS] = {
41 NULL, "download_all_images", "echo_bindings",
42 "fasttcpsend", "command_window", "cacheimages", "fog_of_war", "iconscale",
43 "mapscale", "popups", "displaymode", "showicon", "tooltips", "sound", "splitinfo",
44 "split", "show_grid", "lighting", "trim_info_window",
45 "map_width", "map_height", "foodbeep", "darkness", "port",
46 "grad_color_bars", "resistances", "smoothing", "nosplash",
47 "auto_apply_container", "mapscroll", "sign_popups", "message_timestamping"
48 };
49 
51 
52 #define FREE_AND_CLEAR(xyz) { free(xyz); xyz=NULL; }
53 
54 void VersionCmd(char *data, int len)
55 {
56  char *cp;
57 
58  csocket.cs_version = atoi(data);
59  /* set sc_version in case it is an old server supplying only one version */
61  if (csocket.cs_version != VERSION_CS) {
62  LOG(LOG_WARNING,"common::VersionCmd","Differing C->S version numbers (%d,%d)",
64 /* exit(1);*/
65  }
66  cp = strchr(data,' ');
67  if (!cp) return;
68  csocket.sc_version = atoi(cp);
69  if (csocket.sc_version != VERSION_SC) {
70  LOG(LOG_WARNING,"common::VersionCmd","Differing S->C version numbers (%d,%d)",
72  }
73  cp = strchr(cp+1, ' ');
74  if (cp)
75  LOG(LOG_INFO,"common::VersionCmd","Playing on server type %s", cp);
76 }
77 
79 {
80  cs_print_string(csock.fd,
81  "version %d %d %s", VERSION_CS, VERSION_SC, VERSION_INFO);
82 }
83 
84 
86 {
87  cs_print_string(csock.fd, "addme");
88 }
89 
90 
91 void SendSetFaceMode(ClientSocket csock,int mode)
92 {
93  cs_print_string(csock.fd, "setfacemode %d", mode);
94 }
95 
96 
97 void init_client_vars(void)
98 {
99  int i;
100 
101  /* I think environment variables should be more important than
102  * compiled in defaults, so these probably should be reversed.
103  */
104  client_libdir=getenv("CFCLIENT_LIBDIR");
105 #ifdef CLIENT_LIBDIR
106  if (client_libdir==NULL)
107  client_libdir=CLIENT_LIBDIR;
108 #endif
109 
110  if (exp_table) {
111  free(exp_table);
112  exp_table=NULL;
113  }
114  exp_table_max=0;
115 
116  cpl.count_left = 0;
117  cpl.container = NULL;
118  memset(&cpl.stats,0, sizeof(Stats));
119  cpl.stats.maxsp=1; /* avoid div by 0 errors */
120  cpl.stats.maxhp=1; /* ditto */
121  cpl.stats.maxgrace=1; /* ditto */
122  /* ditto - displayed weapon speed is weapon speed/speed */
123  cpl.stats.speed=1;
124  cpl.input_text[0]='\0';
125  cpl.title[0] = '\0';
126  cpl.range[0] = '\0';
127  cpl.last_command[0] = '\0';
128 
129  for (i=0; i<range_size; i++)
130  cpl.ranges[i]=NULL;
131 
132  for (i=0; i<MAX_SKILL; i++) {
133  cpl.stats.skill_exp[i]=0;
134  cpl.stats.skill_level[i] = 0;
135  skill_names[i] = NULL;
136  last_used_skills[i] = -1;
137  }
139 
140  cpl.ob = player_item();
141  cpl.below = map_item();
142  cpl.magicmap=NULL;
143  cpl.showmagic=0;
144 
145 
149 
150  face_info.faceset = 0;
151  face_info.num_images = 0;
154  face_info.want_faceset = NULL;
158  for (i=0; i<MAX_FACE_SETS; i++) {
159  face_info.facesets[i].prefix = NULL;
160  face_info.facesets[i].fullname = NULL;
161  face_info.facesets[i].fallback = 0;
162  face_info.facesets[i].size = NULL;
163  face_info.facesets[i].extension = NULL;
164  face_info.facesets[i].comment = NULL;
165  }
166  /* Makes just as much sense to initialize the arrays
167  * where they are declared, but I did this so I could
168  * keep track of everything as I was updating
169  * the code. Plus, the performance difference is virtually
170  * nothing.
171  */
200  want_config[CONFIG_APPLY_CONTAINER] = TRUE; /* Same behavior before this option was put in */
204  for (i=0; i<CONFIG_NUMS; i++)
205  use_config[i] = want_config[i];
206 
207 #ifdef WIN32
208  /* If HOME is not set, let's set it to . to avoid things like (null)/.crossfire paths */
209  if ( !getenv( "HOME" ) )
210  {
211  if ( getenv( "APPDATA" ) )
212  {
213  char env[ MAX_BUF ];
214  _snprintf( env, MAX_BUF, "HOME=%s", getenv( "APPDATA" ) );
215  LOG( LOG_INFO, "common::init.c", "init_client_vars: HOME set to %APPDATA%.\n" );
216  putenv( env );
217  }
218  else
219  {
220  LOG( LOG_INFO, "common::init.c", "init_client_vars: HOME not set, setting it to .\n" );
221  putenv( "HOME=." );
222  }
223  }
224 #endif
225  init_commands(); /* pcmd.c */
226  init_metaserver(); /* metaserver.c */
227  /* Any reasonable seed really works */
228  srandom(time(NULL));
229 }
230 
231 /* This is basically called each time a new player logs
232  * on - reset all the player data
233  */
235 {
236  int i;
237 
238  for (i=0; i<MAX_SKILL; i++) {
239  cpl.stats.skill_exp[i]=0;
240  cpl.stats.skill_level[i] = 0;
241  }
242 }
243 
244 /* This is used to clear values between connections to different
245  * servers. This needs to be called after init_client_vars has
246  * been called because it does not re-allocated some values.
247  */
248 
250 {
251  int i;
252 
253  cpl.count_left = 0;
254  cpl.container = NULL;
255  memset(&cpl.stats,0, sizeof(Stats));
256  cpl.stats.maxsp=1; /* avoid div by 0 errors */
257  cpl.stats.maxhp=1; /* ditto */
258  cpl.stats.maxgrace=1; /* ditto */
259  /* ditto - displayed weapon speed is weapon speed/speed */
260  cpl.stats.speed=1;
261  cpl.input_text[0]='\0';
262  cpl.title[0] = '\0';
263  cpl.range[0] = '\0';
264  cpl.last_command[0] = '\0';
265 
266  for (i=0; i<range_size; i++)
267  cpl.ranges[i]=NULL;
268 
269  cpl.magicmap=NULL;
270  cpl.showmagic=0;
271 
275 
276  face_info.faceset = 0;
277  face_info.num_images = 0;
278  /* Preserve the old one - this can be used to see if the next
279  * server has the same name -> number mapping so that we don't
280  * need to rebuild all the images.
281  */
287  for (i=0; i<MAX_FACE_SETS; i++) {
290  face_info.facesets[i].fallback = 0;
294  }
296  for (i=0; i<MAX_SKILL; i++)
298 
299 }
#define VERSION_CS
Definition: client.h:46
char * comment
Definition: client.h:336
char * client_libdir
Definition: client.c:61
signed short sint16
Definition: client-types.h:80
sint16 want_config[CONFIG_NUMS]
Definition: init.c:50
#define COMMAND_WINDOW
Definition: client.h:54
int command_time
Definition: client.h:105
uint16 exp_table_max
Definition: client.c:72
void init_client_vars(void)
Definition: init.c:97
sint32 speed
Definition: client.h:229
#define CONFIG_POPUPS
Definition: client.h:160
void init_metaserver(void)
Definition: metaserver.c:459
#define CONFIG_ECHO
Definition: client.h:153
int sc_version
Definition: client.h:99
#define MAX_SKILL
Definition: client.h:61
item * ob
Definition: client.h:272
#define CONFIG_TIMESTAMP
Definition: client.h:182
#define CONFIG_APPLY_CONTAINER
Definition: client.h:179
uint8 * magicmap
Definition: client.h:299
ClientSocket csocket
Definition: client.c:78
sint16 maxhp
Definition: client.h:217
FaceSets facesets[MAX_FACE_SETS]
Definition: client.h:355
Face_Information face_info
Definition: image.c:167
void init_commands(void)
Definition: p_cmd.c:755
uint8 fallback
Definition: client.h:331
#define CONFIG_SIGNPOPUP
Definition: client.h:181
#define CONFIG_SPLASH
Definition: client.h:178
Stats stats
Definition: client.h:285
#define CONFIG_FOGWAR
Definition: client.h:157
#define CONFIG_MAPSCALE
Definition: client.h:159
void reset_player_data(void)
Definition: init.c:234
sint64 skill_exp[MAX_SKILL]
Definition: client.h:244
char * prefix
Definition: client.h:332
#define CONFIG_SPLITINFO
Definition: client.h:165
char * skill_names[MAX_SKILL]
Definition: client.c:63
void LOG(LogLevel level, const char *origin, const char *format,...)
Definition: misc.c:178
void reset_client_vars(void)
Definition: init.c:249
char * size
Definition: client.h:334
#define TRUE
Definition: client-types.h:71
#define CONFIG_CWINDOW
Definition: client.h:155
#define CONFIG_FOODBEEP
Definition: client.h:172
#define CONFIG_NUMS
Definition: client.h:183
#define CONFIG_PORT
Definition: client.h:174
int cs_print_string(int fd, const char *str,...)
Definition: newsocket.c:259
#define CFG_LT_TILE
Definition: client.h:187
sint16 use_config[CONFIG_NUMS]
Definition: init.c:50
item * below
Definition: client.h:273
Client_Player cpl
Definition: client.c:77
item * container
Definition: client.h:275
#define CONFIG_GRAD_COLOR
Definition: client.h:175
#define CONFIG_CACHE
Definition: client.h:156
#define CONFIG_MAPSCROLL
Definition: client.h:180
#define CONFIG_FASTTCP
Definition: client.h:154
int fd
Definition: client.h:97
const char *const config_names[CONFIG_NUMS]
Definition: init.c:40
char last_command[MAX_BUF]
Definition: client.h:278
uint16 count_left
Definition: client.h:276
sint16 maxgrace
Definition: client.h:221
#define CONFIG_SMOOTH
Definition: client.h:177
int last_used_skills[MAX_SKILL+1]
Definition: client.c:65
sint16 maxsp
Definition: client.h:219
char * extension
Definition: client.h:335
void SendAddMe(ClientSocket csock)
Definition: init.c:85
void SendSetFaceMode(ClientSocket csock, int mode)
Definition: init.c:91
#define MAX_BUF
Definition: client-types.h:128
void VersionCmd(char *data, int len)
Definition: init.c:54
#define CFG_DM_PIXMAP
Definition: client.h:194
uint32 old_bmaps_checksum
Definition: client.h:346
#define EPORT
Definition: cconfig.h:43
#define CONFIG_MAPWIDTH
Definition: client.h:170
#define CONFIG_SHOWICON
Definition: client.h:162
#define MAX_FACE_SETS
Definition: client.h:315
#define CONFIG_SHOWGRID
Definition: client.h:167
#define CONFIG_TRIMINFO
Definition: client.h:169
#define CONFIG_ICONSCALE
Definition: client.h:158
uint8 showmagic
Definition: client.h:300
item * ranges[range_size]
Definition: client.h:280
#define CONFIG_MAPHEIGHT
Definition: client.h:171
#define CONFIG_DOWNLOAD
Definition: client.h:152
#define VERSION_SC
Definition: client.h:47
#define CONFIG_RESISTS
Definition: client.h:176
char * fullname
Definition: client.h:333
int command_sent
Definition: client.h:103
item * map_item(void)
Definition: item.c:611
char range[MAX_BUF]
Definition: client.h:288
const char *const rcsid_common_init_c
Definition: init.c:1
int command_received
Definition: client.h:103
char title[MAX_BUF]
Definition: client.h:287
char VERSION_INFO[256]
Definition: client.c:59
char input_text[MAX_BUF]
Definition: client.h:279
#define CONFIG_DISPLAYMODE
Definition: client.h:161
item * player_item(void)
Definition: item.c:606
#define CONFIG_LIGHTING
Definition: client.h:168
#define FREE_AND_CLEAR(xyz)
Definition: init.c:52
sint16 skill_level[MAX_SKILL]
Definition: client.h:243
#define FALSE
Definition: client-types.h:68
void SendVersion(ClientSocket csock)
Definition: init.c:78
#define CONFIG_SPLITWIN
Definition: client.h:166
#define CONFIG_DARKNESS
Definition: client.h:173
#define CONFIG_TOOLTIPS
Definition: client.h:163
uint64 * exp_table
Definition: client.c:73
#define CONFIG_SOUND
Definition: client.h:164
int cs_version
Definition: client.h:99