Crossfire Client, Trunk  R21435
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  guint16 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 {
140  Playing, //< including account login, character selection
142  Metaserver_Select //< only when metaserver window is up
143 } Input_State;
144 
145 typedef enum {
150 } rangetype;
151 
186 #define CONFIG_DOWNLOAD 1
187 #define CONFIG_ECHO 2
188 #define CONFIG_FASTTCP 3
189 #define CONFIG_CWINDOW 4
190 #define CONFIG_CACHE 5
191 #define CONFIG_FOGWAR 6
192 #define CONFIG_ICONSCALE 7
193 #define CONFIG_MAPSCALE 8
194 #define CONFIG_POPUPS 9
195 #define CONFIG_DISPLAYMODE 10
196 #define CONFIG_SHOWICON 11
197 #define CONFIG_TOOLTIPS 12
198 #define CONFIG_SOUND 13
199 #define CONFIG_SPLITINFO 14
200 #define CONFIG_SPLITWIN 15
201 #define CONFIG_SHOWGRID 16
202 #define CONFIG_LIGHTING 17
203 #define CONFIG_TRIMINFO 18
204 #define CONFIG_MAPWIDTH 19
205 #define CONFIG_MAPHEIGHT 20
206 #define CONFIG_FOODBEEP 21
207 #define CONFIG_DARKNESS 22
208 #define CONFIG_PORT 23
209 #define CONFIG_GRAD_COLOR 24
210 #define CONFIG_RESISTS 25
211 #define CONFIG_SMOOTH 26
212 #define CONFIG_SPLASH 27
213 #define CONFIG_APPLY_CONTAINER 28
214 #define CONFIG_MAPSCROLL 29
216 #define CONFIG_SIGNPOPUP 30
217 #define CONFIG_TIMESTAMP 31
218 #define CONFIG_NUMS 32
221 
222 
227 #define CFG_LT_NONE 0
228 #define CFG_LT_TILE 1
229 #define CFG_LT_PIXEL 2
230 #define CFG_LT_PIXEL_BEST 3
238 #define CFG_DM_PIXMAP 0
239 #define CFG_DM_SDL 1
240 #define CFG_DM_OPENGL 2
244 
245 extern const char *const config_names[CONFIG_NUMS];
250 typedef struct Stat_struct {
251  gint8 Str;
252  gint8 Dex;
253  gint8 Con;
254  gint8 Wis;
255  gint8 Cha;
256  gint8 Int;
257  gint8 Pow;
258  gint8 wc;
259  gint8 ac;
260  gint8 level;
261  gint16 hp;
262  gint16 maxhp;
263  gint16 sp;
264  gint16 maxsp;
265  gint16 grace;
266  gint16 maxgrace;
267  gint64 exp;
268  gint16 food;
271  gint16 dam;
274  gint32 speed;
275  gint32 weapon_sp;
278  guint32 attuned;
281  guint32 repelled;
284  guint32 denied;
285  guint16 flags;
286  gint16 resists[30];
287  guint32 resist_change:1;
288  gint16 skill_level[MAX_SKILL];
289  gint64 skill_exp[MAX_SKILL];
290  guint32 weight_limit;
293 typedef struct Spell_struct {
294  struct Spell_struct *next;
295  char name[256];
296  char message[10000];
298  guint32 tag;
300  guint16 level;
301  guint16 time;
302  guint16 sp;
303  guint16 grace;
304  guint16 dam;
308  guint8 skill_number;
312  char *skill;
314  guint32 path;
318  gint32 face;
321  guint8 usage;
326  char requirements[256];
332 } Spell;
333 
334 typedef struct Player_Struct {
335  item *ob;
336  item *below;
338  item *container;
339  guint16 count_left;
340  Input_State input_state;
341  char last_command[MAX_BUF];
342  char input_text[MAX_BUF];
343  item *ranges[range_size];
345  guint8 ready_spell;
346  char spells[255][40];
348  Stats stats;
349  Spell *spelldata;
350  char title[MAX_BUF];
351  char range[MAX_BUF];
352  guint32 spells_updated;
353  guint32 fire_on:1;
354  guint32 run_on:1;
355  guint32 meta_on:1;
356  guint32 alt_on:1;
357  guint32 no_echo:1;
358  guint32 count;
359  guint16 mmapx, mmapy;
360  guint16 pmapx, pmapy;
362  guint8 *magicmap;
363  guint8 showmagic;
365  guint16 mapxres,mapyres;
368  char *name;
375 } Client_Player;
376 
382 #define MAX_FACE_SETS 20
383 #define MAX_IMAGE_SIZE 320
391 
392 typedef struct FaceSets_struct {
393  guint8 setnum;
394  guint8 fallback;
395  char *prefix;
396  char *fullname;
397  char *size;
398  char *extension;
399  char *comment;
406 typedef struct Face_Information_struct {
407  guint8 faceset;
408  char *want_faceset;
409  gint16 num_images;
410  guint32 bmaps_checksum, old_bmaps_checksum;
417  gint16 cache_hits, cache_misses;
418  guint8 have_faceset_info;
421  FaceSets facesets[MAX_FACE_SETS];
423 
427 extern char *skill_names[MAX_SKILL];
428 
433 typedef enum {
434  LOG_DEBUG = 0,
435  LOG_INFO = 1,
436  LOG_WARNING = 2,
437  LOG_ERROR = 3,
438  LOG_CRITICAL = 4
439 } LogLevel;
440 
444 #define NUM_RESISTS 18
446 extern const char *const resists_name[NUM_RESISTS];
447 extern char *meta_server;
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 
575 extern struct Stat_Mapping stat_mapping[NUM_NEW_CHAR_STATS];
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 extern GTimer* global_time;
692 
693 extern bool debug_protocol;
694 
695 #endif
Animations animations[MAXANIM]
Definition: commands.c:1141
struct Stat_struct Stats
struct Spell_struct Spell
char * news
Definition: client.h:555
static int height
Definition: mapdata.c:80
Fatal crash-worthy error.
Definition: client.h:446
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:302
gint16 use_config[CONFIG_NUMS]
Definition: init.c:40
bool debug_protocol
Definition: main.c:61
int stat_points
Definition: commands.c:93
guint16 command_sent
Definition: client.h:123
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:555
int num_classes
Definition: commands.c:90
guint16 dam
Definition: client.h:306
Warning that something might not work.
Definition: client.h:444
guint16 sp
Definition: client.h:304
struct Animations Animations
Face_Information face_info
Definition: image.c:169
guint16 time
Definition: client.h:303
#define NUM_NEW_CHAR_STATS
Definition: client.h:569
struct Cache_Entry Cache_Entry
LogLevel
Definition: client.h:441
const char * config_dir
Definition: client.c:52
guint8 usage
Definition: client.h:323
int type
Definition: client.h:48
Input_State
Definition: client.h:139
int requestinfo_sent
Definition: client.c:57
rangetype
Definition: client.h:145
NameMapping resist_mapping[NUM_RESISTS]
Definition: client.c:64
guint32 path
Definition: client.h:316
static int width
Definition: mapdata.c:79
int stat_maximum
Definition: commands.c:95
guint16 grace
Definition: client.h:305
void client_disconnect(void)
Definition: client.c:178
#define NUM_RESISTS
Definition: client.h:452
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:644
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:298
bool client_is_connected(void)
Definition: client.c:300
#define MAX_BUF
Definition: client.h:40
int starting_map_number
Definition: commands.c:96
guint8 skill_number
Definition: client.h:310
struct Starting_Map_Info Starting_Map_Info
guint32 tag
Definition: client.h:300
#define CONFIG_NUMS
Definition: client.h:219
int num_races
Definition: commands.c:87
#define MAX_FACE_SETS
Definition: client.h:384
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:640
gint32 face
Definition: client.h:320
struct Race_Class_Info Race_Class_Info
struct Player_Struct Client_Player
Warning that something definitely didn&#39;t work.
Definition: client.h:445
bool client_write(const void *buf, int len)
struct TextManager TextManager
char name[256]
Definition: client.h:297
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
GTimer * global_time
Definition: misc.c:31
struct Msg_Type_Names Msg_Type_Names
struct TextManager * next
Definition: client.h:50
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 VERSION_INFO[256]
Definition: client.c:48
GSource * client_get_source(void)
Definition: client.c:304
guint64 * exp_table
Definition: client.c:62
struct PlayerPosition PlayerPosition
char requirements[256]
Definition: client.h:328
#define MAXANIM
Definition: client.h:86
Useful debugging information.
Definition: client.h:442
void client_run(void)
Definition: client.c:185
char * motd
Definition: client.h:555
const char *const config_names[CONFIG_NUMS]
Definition: init.c:30
Minor, non-harmful issues.
Definition: client.h:443
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:309
char * skill
Definition: client.h:314
char * skill_names[MAX_SKILL]
Definition: client.c:50
TextManager * firstTextManager
Definition: commands.c:1230