Crossfire Client, Trunk  R20507
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 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 
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 #endif
Animations animations[MAXANIM]
Definition: commands.c:1127
struct Stat_struct Stats
struct Spell_struct Spell
char * news
Definition: client.h:555
guint32 width
Definition: image.c:42
Fatal crash-worthy error.
Definition: client.h:445
int command_time
Time (in ms) players commands currently take to execute.
Definition: client.h:128
GSocketConnection * fd
Definition: client.h:120
int used_classes
Definition: commands.c:91
guint16 level
The casting level of the spell.
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)
Ask the server for the given map size.
Definition: client.c:170
Defines various flags that both the new client and new server use.
const char *const resists_name[NUM_RESISTS]
Definition: client.c:72
guint8 num_animations
Number of animations.
Definition: client.h:100
Race_Class_Info * races
Definition: commands.c:98
int sc_version
Server versions of these.
Definition: client.h:121
#define MAX_SKILL
How many skill types server supports/client will get sent to it.
Definition: client.h:84
char * rules
Definition: client.h:555
int num_classes
Definition: commands.c:90
guint16 dam
Damage done by spell though the meaning is spell dependent and actual damage may depend on how the sp...
Definition: client.h:305
Warning that something might not work.
Definition: client.h:443
guint16 sp
Mana per cast; may be zero.
Definition: client.h:303
struct Animations Animations
Face_Information face_info
Definition: image.c:169
guint16 time
Casting time in server ticks.
Definition: client.h:302
#define NUM_NEW_CHAR_STATS
Definition: client.h:569
struct Cache_Entry Cache_Entry
Used mostly in the cache.c file, however, it can be returned to the graphic side of things so that th...
LogLevel
Definition: client.h:440
const char * config_dir
Definition: client.c:52
guint8 usage
Spellmon 2 data.
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:66
One struct that holds most of the image related data to reduce danger of namespace collision...
Definition: client.h:413
For classes & races, the server can present some number of choices, eg, the character gets to choose ...
Definition: client.h:594
Basic support for socket communications, including the file descriptor, input buffer, server, server, version, etc.
Definition: client.h:119
guint32 path
The bitmask of paths this spell belongs to.
Definition: client.h:315
int stat_maximum
Definition: commands.c:95
guint16 grace
Grace per cast; may be zero.
Definition: client.h:304
void client_disconnect(void)
Closes the connection to the server.
Definition: client.c:180
#define NUM_RESISTS
Translation of the STAT_RES names into printable names, in matching order.
Definition: client.h:451
char * servername
Definition: client.h:131
Holds the names that correspond to skill and resistance numbers.
Definition: client.h:461
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
Player object.
Definition: client.c:68
guint16 exp_table_max
Definition: client.c:63
ClientError
Definition: client.h:644
struct Face_Information_struct Face_Information
One struct that holds most of the image related data to reduce danger of namespace collision...
Starting_Map_Info * starting_map_info
Definition: commands.c:99
NameMapping skill_mapping[MAX_SKILL]
Definition: client.c:66
int stat_min
Definition: commands.c:94
guint32 height
Definition: image.c:42
void client_connect(const char *hostname)
Open a socket to the given hostname and store connection information.
char * meta_server
int maxfd
Definition: client.c:58
char message[10000]
This is huge, the packets can&#39;t be much bigger than this anyway.
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
The index in the skill arrays, plus CS_STAT_SKILLINFO.
Definition: client.h:309
struct Starting_Map_Info Starting_Map_Info
guint32 tag
Unique ID number for a spell so updspell etc can operate on it.
Definition: client.h:299
guint32 checksum
Definition: image.c:40
#define CONFIG_NUMS
This should always be the last value in the CONFIG_xxx list.
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:640
gint32 face
A face ID that may be used to show a graphic representation of the spell.
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)
Write the given data to the server.
struct TextManager TextManager
The usage of the stat_mapping is to simplify the code and make it easier to expand.
Definition: client.h:577
ClientSocket csocket
Definition: client.c:69
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
guint32 tick
Definition: client.c:61
Used mostly in the cache.c file, however, it can be returned to the graphic side of things so that th...
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
int command_sent
Definition: client.h:123
char VERSION_INFO[256]
Definition: client.c:48
GSource * client_get_source(void)
Return a source triggered when input from the server is available.
Definition: client.c:293
guint64 * exp_table
Definition: client.c:64
struct PlayerPosition PlayerPosition
char * name
Definition: image.c:39
char requirements[256]
Spellmon 2 data.
Definition: client.h:327
#define MAXANIM
Definition: client.h:86
Useful debugging information.
Definition: client.h:441
void client_run(void)
Read available packets from the server and handle commands until there are no more, or if a socket error occurs.
Definition: client.c:187
char * motd
Definition: client.h:555
const char *const config_names[CONFIG_NUMS]
See common/init.c - number mapping used when loading/saving the values.
Definition: init.c:30
Minor, non-harmful issues.
Definition: client.h:442
int last_used_skills[MAX_SKILL+1]
maps position to skill id with trailing zero as stop mark.
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)
This function negotiates the characteriistics of a connection to the server.
Definition: client.c:298
char * skill
Pointer to the skill name, derived from the skill number.
Definition: client.h:313
char * skill_names[MAX_SKILL]
Definition: client.c:50
TextManager * firstTextManager
Definition: commands.c:1216