Crossfire Client, Trunk  R20922
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;
287  gint16 skill_level[MAX_SKILL];
288  gint64 skill_exp[MAX_SKILL];
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;
335  item *below;
337  item *container;
338  guint16 count_left;
339  Input_State input_state;
340  char last_command[MAX_BUF];
341  char input_text[MAX_BUF];
342  item *ranges[range_size];
344  guint8 ready_spell;
345  char spells[255][40];
347  Stats stats;
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;
409  guint32 bmaps_checksum, old_bmaps_checksum;
416  gint16 cache_hits, cache_misses;
417  guint8 have_faceset_info;
420  FaceSets facesets[MAX_FACE_SETS];
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 
452 typedef struct {
453  const char *name;
454  int value;
455 } NameMapping;
456 
458 
459 extern guint64 *exp_table;
460 extern guint16 exp_table_max;
466 #define MAP_MAX_SIZE 31
467 
475 #define MIN_ALLOCATED_MAP_SIZE MAP_MAX_SIZE * 2
476 
482 #define MAX_MAP_OFFSET 8
484 /* Start of map handling code.
485  *
486  * For the most part, this actually is not window system specific, but
487  * certainly how the client wants to store this may vary.
488  */
489 
490 #define MAXPIXMAPNUM 10000
491 
499 typedef struct Cache_Entry {
500  char *filename;
501  guint32 checksum;
502  guint32 ispublic:1;
503  void *image_data;
504  struct Cache_Entry *next;
505 } Cache_Entry;
506 
518 #define RI_IMAGE_INFO 0x1
519 #define RI_IMAGE_SUMS 0x2
520 
523 
524 typedef struct PlayerPosition {
525  int x;
526  int y;
528 
529 extern PlayerPosition pl_pos;
530 
531 typedef struct Msg_Type_Names {
532  int type;
533  int subtype;
534  const char *style_name;
538 
541 /* declared/handled in commands.c . These variables are documented
542  * in that file - the data they present is created by the command
543  * code, but consumed by the GUI code.
544  */
545 extern char *motd, *news, *rules;
546 extern char *motd, *news, *rules; /* Declared/handled in commands.c */
548 extern int stat_points, stat_min, stat_maximum;
549 
550 
551 
552 /*
553  * This structure is used to hold race/class adjustment info, as
554  * received by the requestinfo command. We get the same info
555  * for both races and class, so it simplifies code to share a structure.
556  */
557 /* This is how many stats (str, dex, con, etc) that are present
558  * in the create character window.
559  */
560 #define NUM_NEW_CHAR_STATS 7
561 
568 struct Stat_Mapping {
569  const char *widget_suffix; /* within the glade file, suffix used on widget */
570  guint8 cs_value; /* within the protocol, the CS_STAT value */
571  guint8 rc_offset; /* Offset into the stat_adj array */
572 };
573 
574 extern struct Stat_Mapping stat_mapping[NUM_NEW_CHAR_STATS];
575 
585 struct RC_Choice {
586  char *choice_name; /* name to respond, eg, race_choice_1 */
587  char *choice_desc; /* Longer description of choice */
588  int num_values; /* How many values we have */
589  char **value_arch; /* Array arch names */
590  char **value_desc; /* Array of description */
591 };
592 
593 typedef struct Race_Class_Info {
594  char *arch_name; /* Name of the archetype this correponds to */
595  char *public_name; /* Public (human readadable) name */
596  char *description; /* Description of the race/class */
597  gint8 stat_adj[NUM_NEW_CHAR_STATS]; /* Adjustment values */
598  int num_rc_choice; /* Size of following array */
599  struct RC_Choice *rc_choice; /* array of choices */
602 typedef struct Starting_Map_Info {
603  char *arch_name; /* Name of archetype for this map */
604  char *public_name; /* Name of the human readable name */
605  char *description; /* Description of this map */
608 extern Race_Class_Info *races, *classes;
611 extern int maxfd;
613 /* End of commands.c data, start of other declarations */
614 #ifndef MIN
615 #define MIN(X__,Y__) ( (X__)<(Y__)?(X__):(Y__) )
616 #endif
617 
624 #define INFO_NEWS 1
625 #define INFO_MOTD 2
626 #define INFO_RULES 3
627 
629 #define CLIENT_ERROR client_error_quark()
630 
631 inline GQuark client_error_quark() {
632  return g_quark_from_static_string("client-error-quark");
633 }
635 enum ClientError {
637 };
638 
639 /* We need to declare most of the structs before we can include this */
640 #include "proto.h"
641 
647 extern void client_connect(const char *hostname);
648 
655 extern void client_disconnect(void);
656 
665 extern void client_negotiate(int sound);
666 
670 extern void client_mapsize(int width, int height);
671 
676 extern void client_run(void);
677 
681 extern bool client_write(const void *buf, int len);
682 
683 extern bool client_is_connected(void);
684 
688 extern GSource *client_get_source(void);
689 
690 #endif
Animations animations[MAXANIM]
Definition: commands.c:1141
struct Stat_struct Stats
struct Spell_struct Spell
char * news
Definition: client.h:554
static int height
Definition: mapdata.c:80
Fatal crash-worthy error.
Definition: client.h:445
int command_time
Definition: client.h:128
GSocketConnection * fd
Definition: client.h:120
int used_classes
Definition: commands.c:91
guint16 level
Definition: client.h:301
gint16 use_config[CONFIG_NUMS]
Definition: init.c:40
int stat_points
Definition: commands.c:93
void client_mapsize(int width, int height)
Definition: client.c:168
const char *const resists_name[NUM_RESISTS]
Definition: client.c:70
guint8 num_animations
Definition: client.h:100
Race_Class_Info * races
Definition: commands.c:98
int sc_version
Definition: client.h:121
#define MAX_SKILL
Definition: client.h:84
char * rules
Definition: client.h:554
int num_classes
Definition: commands.c:90
guint16 dam
Definition: client.h:305
Warning that something might not work.
Definition: client.h:443
guint16 sp
Definition: client.h:303
struct Animations Animations
Face_Information face_info
Definition: image.c:169
guint16 time
Definition: client.h:302
#define NUM_NEW_CHAR_STATS
Definition: client.h:568
struct Cache_Entry Cache_Entry
LogLevel
Definition: client.h:440
const char * config_dir
Definition: client.c:52
guint8 usage
Definition: client.h:322
int type
Definition: client.h:48
Input_State
Definition: client.h:139
int requestinfo_sent
Definition: client.c:57
rangetype
Definition: client.h:144
NameMapping resist_mapping[NUM_RESISTS]
Definition: client.c:64
guint32 path
Definition: client.h:315
static int width
Definition: mapdata.c:79
int stat_maximum
Definition: commands.c:95
guint16 grace
Definition: client.h:304
void client_disconnect(void)
Definition: client.c:178
#define NUM_RESISTS
Definition: client.h:451
char * servername
Definition: client.h:131
ExtTextManager callback
Definition: client.h:49
guint8 speed
Definition: client.h:104
void(* ExtTextManager)(int flag, int type, int subtype, char *message)
Definition: client.h:45
int replyinfo_last_face
Definition: client.c:58
Client_Player cpl
Definition: client.c:66
guint16 exp_table_max
Definition: client.c:61
ClientError
Definition: client.h:643
struct Face_Information_struct Face_Information
Starting_Map_Info * starting_map_info
Definition: commands.c:99
NameMapping skill_mapping[MAX_SKILL]
Definition: client.c:64
int stat_min
Definition: commands.c:94
void client_connect(const char *hostname)
char * meta_server
int maxfd
Definition: client.c:58
char message[10000]
Definition: client.h:297
bool client_is_connected(void)
Definition: client.c:287
#define MAX_BUF
Definition: client.h:40
int starting_map_number
Definition: commands.c:96
guint8 skill_number
Definition: client.h:309
struct Starting_Map_Info Starting_Map_Info
guint32 tag
Definition: client.h:299
#define CONFIG_NUMS
Definition: client.h:218
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
static double weight_limit
Definition: inventory.c:49
GQuark client_error_quark()
Definition: client.h:639
gint32 face
Definition: client.h:319
struct Race_Class_Info Race_Class_Info
struct Player_Struct Client_Player
Warning that something definitely didn&#39;t work.
Definition: client.h:444
bool client_write(const void *buf, int len)
struct TextManager TextManager
char name[256]
Definition: client.h:296
ClientSocket csocket
Definition: client.c:67
guint16 flags
Definition: client.h:99
int wantloginmethod
Definition: client.c:59
const char * cache_dir
Definition: client.c:53
struct Msg_Type_Names Msg_Type_Names
struct TextManager * next
Definition: client.h:50
Definition: client.h:507
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
int command_sent
Definition: client.h:123
char VERSION_INFO[256]
Definition: client.c:48
GSource * client_get_source(void)
Definition: client.c:291
guint64 * exp_table
Definition: client.c:62
struct PlayerPosition PlayerPosition
char requirements[256]
Definition: client.h:327
#define MAXANIM
Definition: client.h:86
Useful debugging information.
Definition: client.h:441
void client_run(void)
Definition: client.c:185
char * motd
Definition: client.h:554
const char *const config_names[CONFIG_NUMS]
Definition: init.c:30
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
guint8 phase
Definition: client.h:106
void client_negotiate(int sound)
Definition: client.c:296
char * skill
Definition: client.h:313
char * skill_names[MAX_SKILL]
Definition: client.c:50
TextManager * firstTextManager
Definition: commands.c:1230