Crossfire Client, Branches  R11627
client.h
Go to the documentation of this file.
1 /*
2  * static char *rcsid_client_h =
3  * "$Id: client.h 9197 2008-06-01 16:32:15Z anmaster $";
4  */
5 /*
6  Crossfire client, a client program for the crossfire program.
7 
8  Copyright (C) 2001,2007 Mark Wedel & Crossfire Development Team
9 
10  This program is free software; you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation; either version 2 of the License, or
13  (at your option) any later version.
14 
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with this program; if not, write to the Free Software
22  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 
24  The author can be reached via e-mail to crossfire-devel@real-time.com
25 */
26 
34 #include <config.h>
35 #include <version.h>
36 #include <client-types.h>
37 #include <newclient.h>
38 #include <item.h>
39 
40 #ifdef HAVE_DMALLOC_H
41 # include <dmalloc.h>
42 #endif
43 
44 #define MULTKEYS
45 
46 #define VERSION_CS 1023
47 #define VERSION_SC 1029
48 
49 extern char VERSION_INFO[256];
50 
51 /* Don't send more than this many outstanding commands to the server
52  * this is only a default value.
53  */
54 #define COMMAND_WINDOW 10
55 
56 #define STRINGCOMMAND 0
57 
58 /* How many skill types server supports/client will get sent to it.
59  * If more skills are added to server, this needs to get increased.
60  */
61 #define MAX_SKILL CS_NUM_SKILLS
62 
63 #define MAXANIM 2000
64 
65 /* Values for send_command option */
66 
67 #define SC_NORMAL 0
68 #define SC_FIRERUN 1
69 #define SC_ALWAYS 2
70 
71 typedef struct Animations {
73  uint8 num_animations; /* number of animations. Value of 2 means
74  * only faces[0],[1] have meaningfull values.
75  */
80 
81 } Animations;
82 
84 
85 #define CAN_SMOOTH(__SQUARE,__LEVEL) ( ( \
86  (__SQUARE.heads[__LEVEL].face==0) \
87  && (__LEVEL >0) \
88  ) \
89  || (__SQUARE.smooth[layer]) \
90  )
91 
92 /* ClientSocket could probably hold more of the global values - it could
93  * probably hold most all socket/communication related values instead
94  * of globals.
95  */
96 typedef struct ClientSocket {
97  int fd;
99  int cs_version, sc_version; /* Server versions of these */
100  /* These are used for the newer 'windowing' method of commands -
101  * number of last command sent, number of received confirmation
102  */
104  /* Time (in ms) players commands currently take to execute */
106  char* servername;
107 } ClientSocket;
108 
109 extern ClientSocket csocket;
110 
111 extern char *server, *client_libdir,*image_file, *sound_server;
112 
115 
116 typedef enum rangetype {
121 } rangetype;
122 
123 /* This is a structure that contains most all of the
124  * configuration options. Instead of having a
125  * whole mess of variables of different names, instead use
126  * a common 16 bit signed array, and index into these -
127  * this makes processing in the gui aspect of the GTK
128  * client much easier. There are also 2 elements -
129  * want options, and use_options. The former is what the
130  * player wants to use, the later is what is currently
131  * in use. There are many options that can not be
132  * switched between during actual play, but we want to
133  * record what the player has changed them to so that
134  * when we save them out, we save what the player wants,
135  * and not what is currently being used. Note that all the gui
136  * interfaces may not use all these values, but making them
137  * available here makes it easy for the GUI to present a
138  * nice interface.
139  * 0 is intentially skipped so the index into this doesn't
140  * get a default if a table has a blank value
141  *
142  * CONFIG_NUMS is the number of configuration options; don't
143  * forget to add to some of
144  * common/init.c config_names,
145  * init_client_vars,
146  * x11/x11.c load_defaults
147  * save_defaults
148  * gtk/config.c load_defaults
149  * save_defaults
150  * probably among other places, if you add a new option.
151  */
152 #define CONFIG_DOWNLOAD 1
153 #define CONFIG_ECHO 2
154 #define CONFIG_FASTTCP 3
155 #define CONFIG_CWINDOW 4
156 #define CONFIG_CACHE 5
157 #define CONFIG_FOGWAR 6
158 #define CONFIG_ICONSCALE 7
159 #define CONFIG_MAPSCALE 8
160 #define CONFIG_POPUPS 9
161 #define CONFIG_DISPLAYMODE 10
162 #define CONFIG_SHOWICON 11
163 #define CONFIG_TOOLTIPS 12
164 #define CONFIG_SOUND 13
165 #define CONFIG_SPLITINFO 14
166 #define CONFIG_SPLITWIN 15
167 #define CONFIG_SHOWGRID 16
168 #define CONFIG_LIGHTING 17
169 #define CONFIG_TRIMINFO 18
170 #define CONFIG_MAPWIDTH 19
171 #define CONFIG_MAPHEIGHT 20
172 #define CONFIG_FOODBEEP 21
173 #define CONFIG_DARKNESS 22
174 #define CONFIG_PORT 23 /* Not sure if useful at all anymore */
175 #define CONFIG_GRAD_COLOR 24
176 #define CONFIG_RESISTS 25
177 #define CONFIG_SMOOTH 26
178 #define CONFIG_SPLASH 27
179 #define CONFIG_APPLY_CONTAINER 28 /* Reapply container */
180 #define CONFIG_MAPSCROLL 29 /* Use bitmap operations for map scrolling */
181 #define CONFIG_SIGNPOPUP 30
182 #define CONFIG_TIMESTAMP 31
183 #define CONFIG_NUMS 32 /* This should always be the last value in the list */
184 
185 /* CONFIG_LIGHTING can have several possible values - set them accordingly */
186 #define CFG_LT_NONE 0
187 #define CFG_LT_TILE 1
188 #define CFG_LT_PIXEL 2
189 #define CFG_LT_PIXEL_BEST 3
190 
191 /* CONFIG_DISPLAYMODE can have several possible values. Give
192  * defines for the possibilities.
193  */
194 #define CFG_DM_PIXMAP 0
195 #define CFG_DM_SDL 1
196 #define CFG_DM_OPENGL 2
197 
199 
200 extern const char *const config_names[CONFIG_NUMS];
205 typedef struct Stat_struct {
222  sint64 exp;
246 } Stats;
247 
248 typedef struct Spell_struct {
250  char name[256];
253  char message[10000];
264  char *skill;
269 } Spell;
270 
271 typedef struct Player_Struct {
272  item *ob;
283  char spells[255][40];
287  char title[MAX_BUF];
288  char range[MAX_BUF];
305 #ifdef MULTKEYS
306  char name[ 40 ];
308 #endif
309 } Client_Player;
310 
311 /* This faceset information is pretty much grabbed right from
312  * server/socket/image.c
313  */
314 
315 #define MAX_FACE_SETS 20
316 #define MAX_IMAGE_SIZE 320
323 typedef struct FaceSets_struct {
324  uint8 setnum;
325  uint8 fallback;
326  char *prefix;
327  char *fullname;
328  char *size;
329  char *extension;
330  char *comment;
333 /* Make one struct that holds most of the image related data.
334  * reduces danger of namespace collision.
335  */
336 typedef struct Face_Information_struct {
337  uint8 faceset;
338  char *want_faceset;
341  /* Just for debugging/logging purposes. This is cleared
342  * on each new server connection. This may not be
343  * 100% precise (as we increment cache_hits when we
344  * find a suitable image to load - if the data is bad,
345  * that would count as both a hit and miss
346  */
348  uint8 have_faceset_info; /* Simple value to know if there is data in facesets[] */
351 
355 extern Client_Player cpl; /* Player object. */
356 extern char *skill_names[MAX_SKILL];
357 
358 extern int last_used_skills[MAX_SKILL+1]; // maps position to skill id with trailing zero as stop mark
359 
360 
361 typedef enum LogLevel {
362  LOG_DEBUG = 0, LOG_INFO = 1, LOG_WARNING = 2, LOG_ERROR = 3, LOG_CRITICAL = 4
363 } LogLevel;
364 
365 typedef struct LogEntry {
366  char* message;
367  char* origin;
369  struct LogEntry* next;
370 } LogEntry;
373 extern int logcount;
374 typedef void (*LogListener)(LogEntry*);
375 #define MAX_LOGS 200
376 #define LOG_APPEND(_Entry) if (LogLast) {\
377  LogLast->next=_Entry;\
378  } else {\
379  LogFirst=_Entry;\
380  };\
381  LogLast=_Entry;_Entry->next=NULL;\
382  if (++logcount > MAX_LOGS)\
383  {\
384  LogEntry* old = LogFirst;\
385  LogFirst = LogFirst -> next;\
386  if (old->message) free (old->message);\
387  if (old->origin) free (old->origin);\
388  }
389 #define LOG_NEW_ENTRY (LogEntry*)calloc(1,sizeof(LogEntry))
390 #define LOG_SETMESSAGE(_Entry,_msg) free(_Entry->message);_Entry->message=strdup(_msg)
391 #define LOG_SETORIGIN(_Entry,_orig) free(_Entry->origin);_Entry->origin=strdup(_orig)
392 
393 typedef struct PipeLog {
394  char* name;
396  int log; /*yes or no to log*/
398 
399 #define CHILD_STDIN 1
400 #define CHILD_STDOUT 2
401 #define CHILD_STDERR 4
402 #define CHILD_SILENTFAIL 8
403 #define CHILD_TUBE (CHILD_STDIN|CHILD_STDOUT|CHILD_STDERR)
404 typedef struct ChildProcess{
405  char* name;
406  int flag;
407  int pid;
408  int tube[3];
413 #define CHILD_PIPEIN(__child) (__child->tube[0])
414 #define CHILD_PIPEOUT(__child) (__child->tube[1])
415 #define CHILD_PIPEERR(__child) (__child->tube[2])
417 
418 #ifndef CPROTO
419 /* We need to declare most of the structs before we can include this */
420 #include <proto.h>
421 #endif
422 
423 /* translation of the STAT_RES names into printable names,
424  * in matching order.
425  */
426 #define NUM_RESISTS 18
427 extern const char *const resists_name[NUM_RESISTS];
428 extern char *meta_server;
429 extern int meta_port,want_skill_exp;
430 extern int metaserver_on, metaserver2_on;
431 extern uint32 tick;
433 extern uint64 *exp_table;
434 extern uint16 exp_table_max;
435 
436 extern int command_inscribe;
437 
438 /* Map size the client will request the map to be. Bigger it is,
439  * more memory it will use
440  */
441 #define MAP_MAX_SIZE 31
442 
443 /* This is basically the smallest the map structure
444  * used for the client can be. It needs to be bigger than
445  * the min map size above simply because we have to deal with
446  * off map big images, Also, we move the center point
447  * around within this map, so that if the player moves one space,
448  * we don't have to move around all the data.
449  */
450 #define MIN_ALLOCATED_MAP_SIZE MAP_MAX_SIZE * 2
451 
452 /* This is how many spaces an object might extend off the map.
453  * Eg, for bigimage stuff, the head of the image may be off the
454  * the map edge. This is the most it may be off. This is needed
455  * To cover case of need_recenter_map routines.
456  */
457 #define MAX_MAP_OFFSET 8
458 
459 /* Start of map handling code.
460  * For the most part, this actually is not window system specific,
461  * but certainly how the client wants to store this may vary.
462  */
464 #define MAXPIXMAPNUM 10000
465 
466 /* This is used mostly in the cache.c file, however, it
467  * can be returned to the graphic side of things so that they
468  * can update the image_data field. Since the common side
469  * has no idea what data the graphic side will point to,
470  * we use a void pointer for that - it is completely up to
471  * the graphic side to allocate/deallocate and cast that
472  * pointer as needed.
473  */
474 typedef struct Cache_Entry {
475  char *filename;
477  uint32 ispublic:1;
478  void *image_data;
479  struct Cache_Entry *next;
482 /* These values are used for various aspects of the library to
483  * hold state on what requestinfo's we have gotten replyinfo
484  * for and what data was received. In this way, common/client.c
485  * can loop until it has gotten replies for all the requestinfos
486  * it has sent. This can be useful - we don't want the addme
487  * command sent for example if we are going to use a different
488  * image set. The GUI stuff should really never chnage these
489  * variables, but could I suppose look at them for debugging/
490  * status information.
491  */
492 
493 #define RI_IMAGE_INFO 0x1
494 #define RI_IMAGE_SUMS 0x2
496 
497 typedef struct PlayerPosition {
498  int x;
499  int y;
501 
502 extern PlayerPosition pl_pos;
505 typedef struct Msg_Type_Names {
506  int type; /* type of message */
507  int subtype; /* subtype of message */
508  const char *style_name; /* name of this message in the configfile */
510 
513 #ifndef MIN
514 #define MIN(X__,Y__) ( (X__)<(Y__)?(X__):(Y__) )
515 #endif
uint16 pmapx
Definition: client.h:297
Animations animations[MAXANIM]
Definition: commands.c:419
struct Stat_struct Stats
struct Spell_struct Spell
PipeLog logger[3]
Definition: client.h:415
uint32 spells_updated
Definition: client.h:289
signed short sint16
Definition: client-types.h:80
const char * style_name
Definition: client.h:514
uint8 skill_number
Definition: client.h:262
uint32 count
Definition: client.h:295
sint8 level
Definition: client.h:215
int command_time
Definition: client.h:105
uint16 grace
Definition: client.h:260
sint32 face
Definition: client.h:268
sint16 hp
Definition: client.h:216
sint8 Int
Definition: client.h:211
sint32 speed
Definition: client.h:229
const char *const resists_name[NUM_RESISTS]
Definition: client.c:80
int sc_version
Definition: client.h:99
sint8 Str
Definition: client.h:206
#define MAX_SKILL
Definition: client.h:61
item * ob
Definition: client.h:272
sint16 food
Definition: client.h:223
int command_inscribe
Definition: client.c:75
uint8 * magicmap
Definition: client.h:299
sint16 maxhp
Definition: client.h:217
struct Animations Animations
FaceSets facesets[MAX_FACE_SETS]
Definition: client.h:355
Face_Information face_info
Definition: image.c:167
sint8 ac
Definition: client.h:214
uint32 repelled
Definition: client.h:236
char * name
Definition: client.h:411
Stats stats
Definition: client.h:285
uint32 ispublic
Definition: client.h:483
sint16 want_config[CONFIG_NUMS]
Definition: init.c:50
struct Cache_Entry Cache_Entry
LogLevel
Definition: client.h:367
uint32 resist_change
Definition: client.h:242
uint32 no_echo
Definition: client.h:294
sint64 skill_exp[MAX_SKILL]
Definition: client.h:244
sint8 Con
Definition: client.h:208
char * client_libdir
Definition: client.c:61
sint8 Cha
Definition: client.h:210
uint16 pmapy
Definition: client.h:297
LogLevel level
Definition: client.h:401
Input_State
Definition: client.h:113
void * image_data
Definition: client.h:484
int requestinfo_sent
Definition: client.c:68
int metaserver2_on
Definition: client.c:69
uint32 checksum
Definition: client.h:482
uint32 tag
Definition: client.h:255
rangetype
Definition: client.h:116
char * filename
Definition: client.h:481
sint8 Pow
Definition: client.h:212
struct PipeLog PipeLog
uint16 flags
Definition: client.h:72
uint32 denied
Definition: client.h:239
uint8 phase
Definition: client.h:78
struct ChildProcess ChildProcess
uint8 speed
Definition: client.h:76
sint16 grace
Definition: client.h:220
int meta_port
Definition: client.c:67
#define NUM_RESISTS
Definition: client.h:432
char * servername
Definition: client.h:106
uint8 speed_left
Definition: client.h:77
sint16 resists[30]
Definition: client.h:241
#define CONFIG_NUMS
Definition: client.h:183
int replyinfo_last_face
Definition: client.c:68
sint8 Dex
Definition: client.h:207
Client_Player cpl
Definition: client.c:77
sint16 use_config[CONFIG_NUMS]
Definition: init.c:50
struct Face_Information_struct Face_Information
int metaserver_on
Definition: client.c:69
uint16 time
Definition: client.h:258
item * below
Definition: client.h:273
struct Cache_Entry * next
Definition: client.h:485
uint16 flags
Definition: client.h:240
char * name
Definition: client.h:400
item * container
Definition: client.h:275
char * image_file
struct ClientSocket ClientSocket
uint16 mapxres
Definition: client.h:302
char * meta_server
Definition: client.c:61
int fd
Definition: client.h:97
char message[10000]
Definition: client.h:253
char name[40]
Definition: client.h:306
int logcount
Definition: misc.c:135
struct ChildProcess * next
Definition: client.h:416
char last_command[MAX_BUF]
Definition: client.h:278
unsigned short uint16
Definition: client-types.h:79
uint16 count_left
Definition: client.h:276
char * message
Definition: client.h:372
uint16 mmapy
Definition: client.h:296
uint8 ready_spell
Definition: client.h:282
uint32 run_on
Definition: client.h:291
sint16 maxgrace
Definition: client.h:221
LogEntry * LogFirst
Definition: misc.c:133
uint32 fire_on
Definition: client.h:290
struct Spell_struct * next
Definition: client.h:249
sint16 maxsp
Definition: client.h:219
uint16 dam
Definition: client.h:261
#define MAX_BUF
Definition: client-types.h:128
uint32 old_bmaps_checksum
Definition: client.h:346
int want_skill_exp
Definition: client.c:67
int flag
Definition: client.h:412
struct Player_Struct Client_Player
int tube[3]
Definition: client.h:414
sint16 dam
Definition: client.h:226
struct LogEntry LogEntry
Spell * spelldata
Definition: client.h:286
unsigned int uint32
Definition: client-types.h:77
#define MAX_FACE_SETS
Definition: client.h:315
char name[256]
Definition: client.h:250
ClientSocket csocket
Definition: client.c:78
char * origin
Definition: client.h:373
void(* LogListener)(LogEntry *)
Definition: client.h:380
int log
Definition: client.h:402
sint32 weapon_sp
Definition: client.h:230
signed int sint32
Definition: client-types.h:78
char * sound_server
Definition: client.c:62
uint8 showmagic
Definition: client.h:300
struct Msg_Type_Names Msg_Type_Names
item * ranges[range_size]
Definition: client.h:280
signed char sint8
Definition: client-types.h:82
Definition: client.h:480
uint32 attuned
Definition: client.h:233
uint32 meta_on
Definition: client.h:292
sint16 sp
Definition: client.h:218
char * server
Definition: client.c:56
uint16 sp
Definition: client.h:259
int replyinfo_status
Definition: client.c:68
int command_sent
Definition: client.h:103
SockList inbuf
Definition: client.h:98
char VERSION_INFO[256]
Definition: client.c:59
uint16 level
Definition: client.h:257
uint64 * exp_table
Definition: client.c:73
Input_State input_state
Definition: client.h:277
char range[MAX_BUF]
Definition: client.h:288
uint16 mapyres
Definition: client.h:302
int command_received
Definition: client.h:103
uint32 alt_on
Definition: client.h:293
char title[MAX_BUF]
Definition: client.h:287
struct PlayerPosition PlayerPosition
char input_text[MAX_BUF]
Definition: client.h:279
char spells[255][40]
Definition: client.h:283
uint32 tick
Definition: client.c:70
LogEntry * LogLast
Definition: misc.c:134
unsigned char uint8
Definition: client-types.h:81
#define MAXANIM
Definition: client.h:63
uint16 mmapx
Definition: client.h:296
sint8 wc
Definition: client.h:213
sint16 skill_level[MAX_SKILL]
Definition: client.h:243
uint8 num_animations
Definition: client.h:73
sint8 Wis
Definition: client.h:209
struct LogEntry * next
Definition: client.h:375
sint64 exp
Definition: client.h:222
uint32 weight_limit
Definition: client.h:245
LogLevel level
Definition: client.h:374
uint32 path
Definition: client.h:266
const char *const config_names[CONFIG_NUMS]
Definition: init.c:40
uint16 exp_table_max
Definition: client.c:72
int last_used_skills[MAX_SKILL+1]
Definition: client.c:65
PlayerPosition pl_pos
Definition: map.c:69
struct FaceSets_struct FaceSets
uint16 * faces
Definition: client.h:79
char * skill
Definition: client.h:264
char * skill_names[MAX_SKILL]
Definition: client.c:63
int cs_version
Definition: client.h:99
TextManager * firstTextManager
Definition: commands.c:495