Crossfire Client, Trunk  R20612
client.h
Go to the documentation of this file.
1 
7 #ifndef _CLIENT_H
8 #define _CLIENT_H
9 
10 #include "config.h"
11 
12 // This is required for 'newclient.h' to expose client variables.
13 #define CLIENT_TYPES_H
14 
15 #include <fcntl.h>
16 #include <glib.h>
17 #include <stdbool.h>
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <sys/time.h>
22 #include <sys/types.h>
23 #include <time.h>
24 #include <unistd.h>
25 
26 #include <gio/gio.h>
27 
28 #ifdef WIN32
29 # include <winsock2.h>
30 #endif
31 
32 #include "item.h"
33 #include "shared/newclient.h"
34 #include "version.h"
35 
36 #ifndef SOL_TCP
37 #define SOL_TCP IPPROTO_TCP
38 #endif
39 
40 #define MAX_BUF 256
41 #define BIG_BUF 1024
42 
43 /* used to register gui callbacks to extended texts
44  * (which are supposed to be handled more friendly than raw text)*/
45 typedef void (*ExtTextManager)(int flag, int type, int subtype, char* message);
46 
47 typedef struct TextManager{
48  int type;
50  struct TextManager* next;
51 } TextManager;
52 
53 /* This is how often the client checks for X events, as well as how often
54  * it performs animations (or will). This value can be most anything.
55  * IT is only configurable because the exact value it needs to be set to
56  * has to be figured out. This value is in microseconds (100,000 microseconds=
57  * 0.1 seconds
58  */
59 #define MAX_TIME 100000
60 
61 /* This is the default port to connect to the server with. */
62 #define EPORT 13327
63 
64 /* This is the default port to connect to the server with in string form. */
65 #define DEFPORT "13327"
66 
67 #define VERSION_CS 1023
68 #define VERSION_SC 1029
69 
70 extern char VERSION_INFO[256];
71 
76 #define COMMAND_WINDOW 10
77 
78 #define STRINGCOMMAND 0
79 
84 #define MAX_SKILL CS_NUM_SKILLS
85 
86 #define MAXANIM 2000
87 
93 #define SC_NORMAL 0
94 #define SC_FIRERUN 1
95 #define SC_ALWAYS 2
96 
98 typedef struct Animations {
99  guint16 flags;
100  guint8 num_animations;
104  guint8 speed;
105  guint8 speed_left;
106  guint8 phase;
107  guint16 *faces;
108 
109 } Animations;
110 
112 
119 typedef struct {
120  GSocketConnection* fd;
121  int cs_version, sc_version;
123  int command_sent, command_received;
131  char* servername;
132 } ClientSocket;
133 
134 extern ClientSocket csocket;
135 
136 extern char *sound_server;
137 extern const char *cache_dir, *config_dir;
138 
139 typedef enum {
142 } Input_State;
143 
144 typedef enum {
149 } rangetype;
150 
185 #define CONFIG_DOWNLOAD 1
186 #define CONFIG_ECHO 2
187 #define CONFIG_FASTTCP 3
188 #define CONFIG_CWINDOW 4
189 #define CONFIG_CACHE 5
190 #define CONFIG_FOGWAR 6
191 #define CONFIG_ICONSCALE 7
192 #define CONFIG_MAPSCALE 8
193 #define CONFIG_POPUPS 9
194 #define CONFIG_DISPLAYMODE 10
195 #define CONFIG_SHOWICON 11
196 #define CONFIG_TOOLTIPS 12
197 #define CONFIG_SOUND 13
198 #define CONFIG_SPLITINFO 14
199 #define CONFIG_SPLITWIN 15
200 #define CONFIG_SHOWGRID 16
201 #define CONFIG_LIGHTING 17
202 #define CONFIG_TRIMINFO 18
203 #define CONFIG_MAPWIDTH 19
204 #define CONFIG_MAPHEIGHT 20
205 #define CONFIG_FOODBEEP 21
206 #define CONFIG_DARKNESS 22
207 #define CONFIG_PORT 23
208 #define CONFIG_GRAD_COLOR 24
209 #define CONFIG_RESISTS 25
210 #define CONFIG_SMOOTH 26
211 #define CONFIG_SPLASH 27
212 #define CONFIG_APPLY_CONTAINER 28
213 #define CONFIG_MAPSCROLL 29
215 #define CONFIG_SIGNPOPUP 30
216 #define CONFIG_TIMESTAMP 31
217 #define CONFIG_NUMS 32
220 
221 
226 #define CFG_LT_NONE 0
227 #define CFG_LT_TILE 1
228 #define CFG_LT_PIXEL 2
229 #define CFG_LT_PIXEL_BEST 3
237 #define CFG_DM_PIXMAP 0
238 #define CFG_DM_SDL 1
239 #define CFG_DM_OPENGL 2
243 
244 extern const char *const config_names[CONFIG_NUMS];
249 typedef struct Stat_struct {
250  gint8 Str;
251  gint8 Dex;
252  gint8 Con;
253  gint8 Wis;
254  gint8 Cha;
255  gint8 Int;
256  gint8 Pow;
257  gint8 wc;
258  gint8 ac;
259  gint8 level;
260  gint16 hp;
261  gint16 maxhp;
262  gint16 sp;
263  gint16 maxsp;
264  gint16 grace;
265  gint16 maxgrace;
266  gint64 exp;
267  gint16 food;
270  gint16 dam;
273  gint32 speed;
274  gint32 weapon_sp;
277  guint32 attuned;
280  guint32 repelled;
283  guint32 denied;
284  guint16 flags;
285  gint16 resists[30];
286  guint32 resist_change:1;
289  guint32 weight_limit;
292 typedef struct Spell_struct {
293  struct Spell_struct *next;
294  char name[256];
295  char message[10000];
297  guint32 tag;
299  guint16 level;
300  guint16 time;
301  guint16 sp;
302  guint16 grace;
303  guint16 dam;
307  guint8 skill_number;
311  char *skill;
313  guint32 path;
317  gint32 face;
320  guint8 usage;
325  char requirements[256];
331 } Spell;
332 
333 typedef struct Player_Struct {
334  item *ob;
338  guint16 count_left;
344  guint8 ready_spell;
345  char spells[255][40];
348  Spell *spelldata;
349  char title[MAX_BUF];
350  char range[MAX_BUF];
351  guint32 spells_updated;
352  guint32 fire_on:1;
353  guint32 run_on:1;
354  guint32 meta_on:1;
355  guint32 alt_on:1;
356  guint32 no_echo:1;
357  guint32 count;
358  guint16 mmapx, mmapy;
359  guint16 pmapx, pmapy;
361  guint8 *magicmap;
362  guint8 showmagic;
364  guint16 mapxres,mapyres;
367  char *name;
374 } Client_Player;
375 
381 #define MAX_FACE_SETS 20
382 #define MAX_IMAGE_SIZE 320
390 
391 typedef struct FaceSets_struct {
392  guint8 setnum;
393  guint8 fallback;
394  char *prefix;
395  char *fullname;
396  char *size;
397  char *extension;
398  char *comment;
405 typedef struct Face_Information_struct {
406  guint8 faceset;
407  char *want_faceset;
408  gint16 num_images;
422 
426 extern char *skill_names[MAX_SKILL];
427 
432 typedef enum {
433  LOG_DEBUG = 0,
434  LOG_INFO = 1,
435  LOG_WARNING = 2,
436  LOG_ERROR = 3,
437  LOG_CRITICAL = 4
438 } LogLevel;
439 
443 #define NUM_RESISTS 18
445 extern const char *const resists_name[NUM_RESISTS];
446 extern char *meta_server;
448 extern guint32 tick;
449 
453 typedef struct {
454  const char *name;
455  int value;
456 } NameMapping;
457 
459 
460 extern guint64 *exp_table;
461 extern guint16 exp_table_max;
467 #define MAP_MAX_SIZE 31
468 
476 #define MIN_ALLOCATED_MAP_SIZE MAP_MAX_SIZE * 2
477 
483 #define MAX_MAP_OFFSET 8
485 /* Start of map handling code.
486  *
487  * For the most part, this actually is not window system specific, but
488  * certainly how the client wants to store this may vary.
489  */
490 
491 #define MAXPIXMAPNUM 10000
492 
500 typedef struct Cache_Entry {
501  char *filename;
502  guint32 checksum;
503  guint32 ispublic:1;
504  void *image_data;
505  struct Cache_Entry *next;
506 } Cache_Entry;
507 
519 #define RI_IMAGE_INFO 0x1
520 #define RI_IMAGE_SUMS 0x2
521 
524 
525 typedef struct PlayerPosition {
526  int x;
527  int y;
529 
530 extern PlayerPosition pl_pos;
531 
532 typedef struct Msg_Type_Names {
533  int type;
534  int subtype;
535  const char *style_name;
539 
542 /* declared/handled in commands.c . These variables are documented
543  * in that file - the data they present is created by the command
544  * code, but consumed by the GUI code.
545  */
546 extern char *motd, *news, *rules;
547 extern char *motd, *news, *rules; /* Declared/handled in commands.c */
549 extern int stat_points, stat_min, stat_maximum;
550 
551 
552 
553 /*
554  * This structure is used to hold race/class adjustment info, as
555  * received by the requestinfo command. We get the same info
556  * for both races and class, so it simplifies code to share a structure.
557  */
558 /* This is how many stats (str, dex, con, etc) that are present
559  * in the create character window.
560  */
561 #define NUM_NEW_CHAR_STATS 7
562 
569 struct Stat_Mapping {
570  const char *widget_suffix; /* within the glade file, suffix used on widget */
571  guint8 cs_value; /* within the protocol, the CS_STAT value */
572  guint8 rc_offset; /* Offset into the stat_adj array */
573 };
574 
576 
586 struct RC_Choice {
587  char *choice_name; /* name to respond, eg, race_choice_1 */
588  char *choice_desc; /* Longer description of choice */
589  int num_values; /* How many values we have */
590  char **value_arch; /* Array arch names */
591  char **value_desc; /* Array of description */
592 };
593 
594 typedef struct Race_Class_Info {
595  char *arch_name; /* Name of the archetype this correponds to */
596  char *public_name; /* Public (human readadable) name */
597  char *description; /* Description of the race/class */
598  gint8 stat_adj[NUM_NEW_CHAR_STATS]; /* Adjustment values */
599  int num_rc_choice; /* Size of following array */
600  struct RC_Choice *rc_choice; /* array of choices */
603 typedef struct Starting_Map_Info {
604  char *arch_name; /* Name of archetype for this map */
605  char *public_name; /* Name of the human readable name */
606  char *description; /* Description of this map */
609 extern Race_Class_Info *races, *classes;
612 extern int maxfd;
614 /* End of commands.c data, start of other declarations */
615 #ifndef MIN
616 #define MIN(X__,Y__) ( (X__)<(Y__)?(X__):(Y__) )
617 #endif
618 
625 #define INFO_NEWS 1
626 #define INFO_MOTD 2
627 #define INFO_RULES 3
628 
630 #define CLIENT_ERROR client_error_quark()
631 
632 inline GQuark client_error_quark() {
633  return g_quark_from_static_string("client-error-quark");
634 }
636 enum ClientError {
638 };
639 
640 /* We need to declare most of the structs before we can include this */
641 #include "proto.h"
642 
648 extern void client_connect(const char *hostname);
649 
656 extern void client_disconnect(void);
657 
666 extern void client_negotiate(int sound);
667 
671 extern void client_mapsize(int width, int height);
672 
677 extern void client_run(void);
678 
682 extern bool client_write(const void *buf, int len);
683 
684 extern bool client_is_connected(void);
685 
689 extern GSource *client_get_source(void);
690 
691 #endif
Animations animations[MAXANIM]
Definition: commands.c:1127
struct Stat_struct Stats
struct Spell_struct Spell
gint16 grace
Definition: client.h:266
char * comment
Definition: client.h:406
gint8 wc
Definition: client.h:259
char * news
Definition: client.h:555
guint32 width
Definition: image.c:42
const char * style_name
Definition: client.h:543
Fatal crash-worthy error.
Definition: client.h:445
int command_time
Definition: client.h:128
gint32 weapon_sp
Definition: client.h:276
GSocketConnection * fd
Definition: client.h:120
char ** value_arch
Definition: client.h:598
int used_classes
Definition: commands.c:91
char * choice_desc
Definition: client.h:596
guint16 level
Definition: client.h:301
int num_values
Definition: client.h:597
gint16 use_config[CONFIG_NUMS]
Definition: init.c:40
int stat_points
Definition: commands.c:93
char * description
Definition: client.h:614
void client_mapsize(int width, int height)
Definition: client.c:170
guint8 fallback
Definition: client.h:401
const char *const resists_name[NUM_RESISTS]
Definition: client.c:72
gint64 skill_exp[MAX_SKILL]
Definition: client.h:290
guint8 num_animations
Definition: client.h:100
Race_Class_Info * races
Definition: commands.c:98
int sc_version
Definition: client.h:121
guint8 have_faceset_info
Definition: client.h:425
#define MAX_SKILL
Definition: client.h:84
char * rules
Definition: client.h:555
gint16 maxsp
Definition: client.h:265
item * ob
Definition: client.h:336
int num_classes
Definition: commands.c:90
guint16 dam
Definition: client.h:305
const char * widget_suffix
Definition: client.h:578
Warning that something might not work.
Definition: client.h:443
guint16 sp
Definition: client.h:303
gint32 speed
Definition: client.h:275
guint16 mmapy
Definition: client.h:360
struct Animations Animations
FaceSets facesets[MAX_FACE_SETS]
Definition: client.h:428
char * description
Definition: client.h:605
Face_Information face_info
Definition: image.c:169
guint16 time
Definition: client.h:302
Stats stats
Definition: client.h:349
#define NUM_NEW_CHAR_STATS
Definition: client.h:569
struct Cache_Entry Cache_Entry
LogLevel
Definition: client.h:440
guint16 pmapx
Definition: client.h:361
char ** value_desc
Definition: client.h:599
guint8 ready_spell
Definition: client.h:346
guint32 bmaps_checksum
Definition: client.h:417
const char * config_dir
Definition: client.c:52
char * prefix
Definition: client.h:402
guint8 usage
Definition: client.h:322
gint8 Con
Definition: client.h:254
int type
Definition: client.h:48
Input_State
Definition: client.h:139
void * image_data
Definition: client.h:512
int requestinfo_sent
Definition: client.c:57
guint8 * magicmap
Definition: client.h:363
guint32 meta_on
Definition: client.h:356
rangetype
Definition: client.h:144
char * filename
Definition: client.h:509
NameMapping resist_mapping[NUM_RESISTS]
Definition: client.c:66
guint32 path
Definition: client.h:315
guint32 alt_on
Definition: client.h:357
guint16 mapyres
Definition: client.h:366
guint32 ispublic
Definition: client.h:511
char * size
Definition: client.h:404
char * public_name
Definition: client.h:613
guint32 resist_change
Definition: client.h:288
guint32 repelled
Definition: client.h:282
int stat_maximum
Definition: commands.c:95
guint16 grace
Definition: client.h:304
void client_disconnect(void)
Definition: client.c:180
gint8 ac
Definition: client.h:260
#define NUM_RESISTS
Definition: client.h:451
char * servername
Definition: client.h:131
guint8 cs_value
Definition: client.h:579
ExtTextManager callback
Definition: client.h:49
gint8 Str
Definition: client.h:252
guint8 speed
Definition: client.h:104
int num_rc_choice
Definition: client.h:607
int replyinfo_last_face
Definition: client.c:58
Client_Player cpl
Definition: client.c:68
guint16 exp_table_max
Definition: client.c:63
guint8 rc_offset
Definition: client.h:580
guint32 checksum
Definition: client.h:510
gint8 Wis
Definition: client.h:255
ClientError
Definition: client.h:644
struct Face_Information_struct Face_Information
guint16 mmapx
Definition: client.h:360
item * below
Definition: client.h:337
struct Cache_Entry * next
Definition: client.h:513
gint8 level
Definition: client.h:261
Starting_Map_Info * starting_map_info
Definition: commands.c:99
item * container
Definition: client.h:339
NameMapping skill_mapping[MAX_SKILL]
Definition: client.c:66
char * choice_name
Definition: client.h:595
int stat_min
Definition: commands.c:94
guint32 height
Definition: image.c:42
void client_connect(const char *hostname)
char * meta_server
void(* ExtTextManager)(int flag, int type, int subtype, char *message)
Definition: client.h:45
int maxfd
Definition: client.c:58
gint8 Pow
Definition: client.h:258
char message[10000]
Definition: client.h:297
bool client_is_connected(void)
Definition: client.c:289
#define MAX_BUF
Definition: client.h:40
int starting_map_number
Definition: commands.c:96
guint8 skill_number
Definition: client.h:309
guint8 setnum
Definition: client.h:400
struct Starting_Map_Info Starting_Map_Info
gint16 food
Definition: client.h:269
gint8 Dex
Definition: client.h:253
guint32 tag
Definition: client.h:299
char last_command[MAX_BUF]
Definition: client.h:342
#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
gint16 want_config[CONFIG_NUMS]
Definition: init.c:40
char * sound_server
Definition: client.c:51
int serverloginmethod
Definition: client.c:59
guint16 pmapy
Definition: client.h:361
struct RC_Choice * rc_choice
Definition: client.h:608
char * arch_name
Definition: client.h:603
gint16 resists[30]
Definition: client.h:287
guint32 count
Definition: client.h:359
struct Spell_struct * next
Definition: client.h:295
GQuark client_error_quark()
Definition: client.h:640
char * extension
Definition: client.h:405
guint16 flags
Definition: client.h:286
gint64 exp
Definition: client.h:268
gint32 face
Definition: client.h:319
struct Race_Class_Info Race_Class_Info
gint16 skill_level[MAX_SKILL]
Definition: client.h:289
struct Player_Struct Client_Player
struct Stat_Mapping stat_mapping[NUM_NEW_CHAR_STATS]
Definition: commands.c:118
guint8 showmagic
Definition: client.h:364
Warning that something definitely didn't work.
Definition: client.h:444
guint32 weight_limit
Definition: client.h:291
bool client_write(const void *buf, int len)
struct TextManager TextManager
Spell * spelldata
Definition: client.h:350
gint16 dam
Definition: client.h:272
guint32 spells_updated
Definition: client.h:353
guint32 run_on
Definition: client.h:355
char name[256]
Definition: client.h:296
ClientSocket csocket
Definition: client.c:69
guint32 old_bmaps_checksum
Definition: client.h:417
guint16 flags
Definition: client.h:99
int wantloginmethod
Definition: client.c:59
gint8 stat_adj[NUM_NEW_CHAR_STATS]
Definition: client.h:606
const char * cache_dir
Definition: client.c:53
struct Msg_Type_Names Msg_Type_Names
gint8 Int
Definition: client.h:257
struct TextManager * next
Definition: client.h:50
gint16 sp
Definition: client.h:264
char * arch_name
Definition: client.h:612
item * ranges[range_size]
Definition: client.h:344
guint32 tick
Definition: client.c:61
Definition: client.h:508
int used_races
Definition: commands.c:88
guint16 * faces
Definition: client.h:107
guint8 speed_left
Definition: client.h:105
int replyinfo_status
Definition: client.c:57
char * fullname
Definition: client.h:403
int command_sent
Definition: client.h:123
char VERSION_INFO[256]
Definition: client.c:48
GSource * client_get_source(void)
Definition: client.c:293
guint16 mapxres
Definition: client.h:366
char * public_name
Definition: client.h:604
Input_State input_state
Definition: client.h:341
char range[MAX_BUF]
Definition: client.h:352
guint64 * exp_table
Definition: client.c:64
gint16 maxhp
Definition: client.h:263
char title[MAX_BUF]
Definition: client.h:351
struct PlayerPosition PlayerPosition
char input_text[MAX_BUF]
Definition: client.h:343
char * name
Definition: image.c:39
gint16 hp
Definition: client.h:262
char spells[255][40]
Definition: client.h:347
char requirements[256]
Definition: client.h:327
guint32 no_echo
Definition: client.h:358
#define MAXANIM
Definition: client.h:86
Useful debugging information.
Definition: client.h:441
void client_run(void)
Definition: client.c:187
gint8 Cha
Definition: client.h:256
char * name
Definition: client.h:369
char * motd
Definition: client.h:555
const char *const config_names[CONFIG_NUMS]
Definition: init.c:30
guint32 fire_on
Definition: client.h:354
Minor, non-harmful issues.
Definition: client.h:442
int last_used_skills[MAX_SKILL+1]
Definition: client.c:55
Race_Class_Info * classes
Definition: commands.c:98
PlayerPosition pl_pos
Definition: map.c:37
struct FaceSets_struct FaceSets
guint32 attuned
Definition: client.h:279
guint8 phase
Definition: client.h:106
void client_negotiate(int sound)
Definition: client.c:298
char * skill
Definition: client.h:313
char * skill_names[MAX_SKILL]
Definition: client.c:50
gint16 maxgrace
Definition: client.h:267
guint32 denied
Definition: client.h:285
TextManager * firstTextManager
Definition: commands.c:1216