1 /**
2  * @file client.h
3  * Includes various dependencies header files needed by most everything.  It
4  * also declares structures and other variables that the GUI portion needs.
5  */
6 
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;
49     ExtTextManager callback;
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 
72 /**
73  * Do not send more than this many outstanding commands to the server this is
74  * only a default value.
75  */
76 #define COMMAND_WINDOW 10
77 
78 #define STRINGCOMMAND 0
79 
80 /**
81  * How many skill types server supports/client will get sent to it.  If more
82  * skills are added to server, this needs to get increased.
83  */
84 #define MAX_SKILL CS_NUM_SKILLS
85 
86 #define MAXANIM 2000
87 
88 /**
89  * @defgroup SC_xxx SC_xxx send_command options.
90  * Values assigned to send_command option.
91  */
92 /*@{*/
93 #define SC_NORMAL  0
94 #define SC_FIRERUN 1
95 #define SC_ALWAYS  2
96 /*@}*/
97 
98 typedef struct Animations {
99     guint16  flags;
100     guint8   num_animations;             /**< Number of animations.  Value of 2
101                                          *   means only faces[0],[1] have
102                                          *   meaningful values.
103                                          */
104     guint8   speed;
105     guint8   speed_left;
106     guint8   phase;
107     guint16  *faces;
108 
109 } Animations;
110 
111 extern Animations animations[MAXANIM];
112 
113 /** Largest ncom command number to send before wrapping. */
114 #define COMMAND_MAX 255
115 
116 /**
117  * Basic support for socket communications, including the file descriptor,
118  * input buffer, server, server, version, etc. ClientSocket could probably
119  * hold more of the global values - it could probably hold most all
120  * socket/communication related values instead of globals.
121  */
122 typedef struct {
123     GSocketConnection* fd;
124     int cs_version, sc_version;         /**< Server versions of these
125                                          */
126     guint16 command_sent, command_received; /**< These are used for the newer
127                                          *   'windowing' method of commands -
128                                          *   number of last command sent,
129                                          *   number of received confirmation
130                                          */
131     int command_time;                   /**< Time (in ms) players commands
132                                          *   currently take to execute
133                                          */
134     char* servername;
135     gint8 dir[COMMAND_MAX];    //< Direction of sent movement command (or -1) for local prediction
136 } ClientSocket;
137 
138 extern ClientSocket csocket;
139 
140 extern char *sound_server;
141 extern const char *cache_dir, *config_dir;
142 
143 typedef enum {
144     Playing,            //< including account login, character selection
145     Reply_One, Reply_Many, Configure_Keys, Command_Mode,
146     Metaserver_Select   //< only when metaserver window is up
147 } Input_State;
148 
149 typedef enum {
150   range_bottom = -1, range_none = 0, range_bow = 1, range_magic = 2,
151   range_wand = 3, range_rod = 4, range_scroll = 5, range_horn = 6,
152   range_steal = 7,
153   range_size = 8
154 } rangetype;
155 
156 /**
157  * @defgroup CONFIG_xxx CONFIG_xxx want_config array indices.
158  * Definitions to index into an array of most of the configuration options.
159  *
160  * Instead of having a whole mess of variables of different names, instead use
161  * a common 16 bit signed array, and index into these - this makes processing
162  * in the GUI aspect of the GTK client much easier.
163  *
164  * There are also 2 elements - want_options, and use_options.  The former is
165  * what the player wants to use, the latter is what is currently in use.
166  * There are many options that can not be switched between during actual play,
167  * but we want to record what the player has changed them to so that when we
168  * save them out, we save what the player wants, and not what is currently
169  * being used.
170  *
171  * Note that all the GUI interfaces may not use all these values, but making
172  * them available here makes it easy for the GUI to present a nice interface.
173  *
174  * 0 is intentially skipped so the index into this doesn't get a default if a
175  * table has a blank value
176  *
177  * CONFIG_NUMS is the number of configuration options; don't forget to add to
178  * some of:
179  *
180  *   common/init.c config_names,
181  *                 init_client_vars,
182  *   x11/x11.c load_defaults
183  *             save_defaults
184  *   gtk/config.c load_defaults
185  *                save_defaults
186  *
187  * and probably other places, if you add a new option.
188  */
189 /*@{*/
190 #define CONFIG_DOWNLOAD         1
191 #define CONFIG_ECHO             2
192 #define CONFIG_FASTTCP          3
193 #define CONFIG_CWINDOW          4
194 #define CONFIG_CACHE            5
195 #define CONFIG_FOGWAR           6
196 #define CONFIG_ICONSCALE        7
197 #define CONFIG_MAPSCALE         8
198 #define CONFIG_POPUPS           9
199 #define CONFIG_DISPLAYMODE      10     /**< @sa CFG_DM_xxx */
200 #define CONFIG_SHOWICON         11
201 #define CONFIG_TOOLTIPS         12
202 #define CONFIG_SOUND            13
203 #define CONFIG_SPLITINFO        14
204 #define CONFIG_SPLITWIN         15
205 #define CONFIG_SHOWGRID         16
206 #define CONFIG_LIGHTING         17      /**< @sa CFG_LT_xxx */
207 #define CONFIG_TRIMINFO         18
208 #define CONFIG_MAPWIDTH         19
209 #define CONFIG_MAPHEIGHT        20
210 #define CONFIG_FOODBEEP         21
211 #define CONFIG_DARKNESS         22
212 #define CONFIG_PORT             23      /**< Is this useful any more? */
213 #define CONFIG_GRAD_COLOR       24
214 #define CONFIG_RESISTS          25
215 #define CONFIG_SMOOTH           26
216 #define CONFIG_SPLASH           27
217 #define CONFIG_APPLY_CONTAINER  28      /**< Reapply container */
218 #define CONFIG_MAPSCROLL        29      /**< Use bitmap operations for map
219                                              scrolling */
220 #define CONFIG_SIGNPOPUP        30
221 #define CONFIG_TIMESTAMP        31
222 #define CONFIG_NUMS             32      /**< This should always be the last
223                                              value in the CONFIG_xxx list. */
224 /*@}*/
225 
226 /**
227  * @defgroup CFG_LT_xxx CONFIG_LIGHTING values.
228  * Values that may be assigned to want_config[CONFIG_LIGHTING].
229  */
230 /*@{*/
231 #define CFG_LT_NONE         0
232 #define CFG_LT_TILE         1
233 #define CFG_LT_PIXEL        2
234 #define CFG_LT_PIXEL_BEST   3
235 /*@}*/
236 
237 /**
238  * @defgroup CFG_DM_xxx CONFIG_DISPLAYMODE values.
239  * Values that may be assigned to want_config[CONFIG_DISPLAYMODE].
240  */
241 /*@{*/
242 #define CFG_DM_PIXMAP       0
243 #define CFG_DM_SDL          1
244 #define CFG_DM_OPENGL       2
245 /*@}*/
246 
247 extern gint16 want_config[CONFIG_NUMS], use_config[CONFIG_NUMS];
248 
249 extern const char *const config_names[CONFIG_NUMS]; /**< See common/init.c -
250                                                      *   number mapping used
251                                                      *   when loading/saving
252                                                      *   the values.
253                                                      */
254 typedef struct Stat_struct {
255     gint8 Str;                          /**< Strength */
256     gint8 Dex;                          /**< Dexterity */
257     gint8 Con;                          /**< Constitution */
258     gint8 Wis;                          /**< Wisdom */
259     gint8 Cha;                          /**< Charisma */
260     gint8 Int;                          /**< Intelligence */
261     gint8 Pow;                          /**< Power */
262     gint8 wc;                           /**< Weapon Class */
263     gint8 ac;                           /**< Armour Class */
264     gint8 level;                        /**< Experience level */
265     gint16 hp;                          /**< Hit Points */
266     gint16 maxhp;                       /**< Maximum hit points */
267     gint16 sp;                          /**< Spell points for casting spells */
268     gint16 maxsp;                       /**< Maximum spell points. */
269     gint16 grace;                       /**< Spell points for using prayers. */
270     gint16 maxgrace;                    /**< Maximum spell points. */
271     gint64 exp;                         /**< Experience.  Killers gain 1/10. */
272     gint16 food;                        /**< Quantity food in stomach.
273                                          *   0 = starved.
274                                          */
275     gint16 dam;                         /**< How much damage this object does
276                                          *   for each hit
277                                          */
278     gint32 speed;                       /**< Speed (is displayed as a float) */
279     gint32 weapon_sp;                   /**< Weapon speed (displayed in client
280                                          *   as a float)
281                                          */
282     guint32 attuned;                     /**< Spell paths to which the player is
283                                          *   attuned
284                                          */
285     guint32 repelled;                    /**< Spell paths to which the player is
286                                          *   repelled
287                                          */
288     guint32 denied;                      /**< Spell paths denied to the player*/
289     guint16 flags;                       /**< Contains fire on/run on flags */
290     gint16 resists[30];                 /**< Resistant values */
291     guint32 resist_change:1;             /**< Resistant value change flag */
292     gint16 skill_level[MAX_SKILL];      /**< Level of known skills */
293     gint64 skill_exp[MAX_SKILL];        /**< Experience points for skills */
294     guint32 weight_limit;                /**< Carrying weight limit */
295 } Stats;
296 
297 typedef struct Spell_struct {
298     struct Spell_struct *next;
299     char name[256];                     /**< One length byte plus data       */
300     char message[10000];                /**< This is huge, the packets can't
301                                          *   be much bigger than this anyway */
302     guint32 tag;                         /**< Unique ID number for a spell so
303                                          *   updspell etc can operate on it. */
304     guint16 level;                       /**< The casting level of the spell. */
305     guint16 time;                        /**< Casting time in server ticks.   */
306     guint16 sp;                          /**< Mana per cast; may be zero.     */
307     guint16 grace;                       /**< Grace per cast; may be zero.    */
308     guint16 dam;                         /**< Damage done by spell though the
309                                          *   meaning is spell dependent and
310                                          *   actual damage may depend on how
311                                          *   the spell works.                */
312     guint8 skill_number;                 /**< The index in the skill arrays,
313                                          *   plus CS_STAT_SKILLINFO. 0: no
314                                          *   skill used for cast.  See also:
315                                          *   request_info skill_info         */
316     char *skill;                        /**< Pointer to the skill name,
317                                          *   derived from the skill number.  */
318     guint32 path;                        /**< The bitmask of paths this spell
319                                          *   belongs to.  See request_info
320                                          *   spell_paths and stats about
321                                          *   attunement, repulsion, etc.     */
322     gint32 face;                        /**< A face ID that may be used to
323                                          *   show a graphic representation
324                                          *   of the spell.                   */
325     guint8 usage;                        /**< Spellmon 2 data.  Values are:
326                                          *   0: No argument required.
327                                          *   1: Requires other spell name.
328                                          *   2: Freeform string is optional.
329                                          *   3: Freeform string is required. */
330     char requirements[256];             /**< Spellmon 2 data. One length byte
331                                          *   plus data. If the spell requires
332                                          *   items to be cast, this is a list
333                                          *   of req'd items. Comma-separated,
334                                          *   number of items, singular names
335                                          *   (like ingredients for alchemy). */
336 } Spell;
337 
338 typedef struct Player_Struct {
339     item        *ob;                    /**< Player object */
340     item        *below;                 /**< Items below the player
341                                          *   (pl.below->inv) */
342     item        *container;             /**< open container */
343     guint16      count_left;             /**< count for commands */
344     Input_State input_state;            /**< What the input state is */
345     char        last_command[MAX_BUF];  /**< Last command entered */
346     char        input_text[MAX_BUF];    /**< keys typed (for long commands) */
347     item        *ranges[range_size];    /**< Object that is used for that */
348                                         /**< range type */
349     guint8       ready_spell;            /**< Index to spell that is readied */
350     char        spells[255][40];        /**< List of all the spells the */
351                                         /**< player knows */
352     Stats       stats;                  /**< Player stats */
353     Spell       *spelldata;             /**< List of spells known */
354     char        title[MAX_BUF];         /**< Title of character */
355     char        range[MAX_BUF];         /**< Range attack chosen */
356     guint32      spells_updated;         /**< Whether or not spells updated */
357     guint32      fire_on:1;              /**< True if fire key is pressed */
358     guint32      run_on:1;               /**< True if run key is on */
359     guint32      meta_on:1;              /**< True if fire key is pressed */
360     guint32      alt_on:1;               /**< True if fire key is pressed */
361     guint32      no_echo:1;              /**< If TRUE, don't echo keystrokes */
362     guint32      count;                  /**< Repeat count on command */
363     guint16      mmapx, mmapy;           /**< size of magic map */
364     guint16      pmapx, pmapy;           /**< Where the player is on the magic
365                                          *   map */
366     guint8       *magicmap;              /**< Magic map data */
367     guint8       showmagic;              /**< If 0, show the normal map,
368                                          *   otherwise show the magic map. */
369     guint16      mapxres,mapyres;        /**< Resolution to draw on the magic
370                                          *   map. Only used in client-specific
371                                          *   code, so it should move there. */
372     char        *name;                  /**< Name of PC, set and freed in account.c
373                                          *   play_character() (using data returned
374                                          *   from server to AccountPlayersCmd, via
375                                          *   character_choose window,
376                                          *   OR in
377                                          *   send_create_player_to_server() when
378                                          *   new character created. */
379 } Client_Player;
380 
381 /**
382  * @defgroup MAX_xxx_xxx MAX_xxx_xxx Face and image constants.
383  * Faceset information pretty much grabbed right from server/socket/image.c.
384  */
385 /*@{*/
386 #define MAX_FACE_SETS   20
387 #define MAX_IMAGE_SIZE 320              /**< Maximum size of image in each
388                                          *   direction.  Needed for the X11
389                                          *   client, which wants to initialize
390                                          *   some data once.  Increasing this
391                                          *   would likely only need a bigger
392                                          *   footprint.
393                                          */
394 /*@}*/
395 
396 typedef struct FaceSets_struct {
397     guint8   setnum;                     /**<  */
398     guint8   fallback;                   /**<  */
399     char    *prefix;                    /**<  */
400     char    *fullname;                  /**<  */
401     char    *size;                      /**<  */
402     char    *extension;                 /**<  */
403     char    *comment;                   /**<  */
404 } FaceSets;
405 
406 /**
407  * One struct that holds most of the image related data to reduce danger of
408  * namespace collision.
409  */
410 typedef struct Face_Information_struct {
411     guint8   faceset;
412     char    *want_faceset;
413     gint16  num_images;
414     guint32  bmaps_checksum, old_bmaps_checksum;
415     /**
416      * Just for debugging/logging purposes.  This is cleared on each new
417      * server connection.  This may not be 100% precise (as we increment
418      * cache_hits when we find a suitable image to load - if the data is bad,
419      * that would count as both a hit and miss.
420      */
421     gint16  cache_hits, cache_misses;
422     guint8   have_faceset_info;          /**< Simple value to know if there is
423                                          *   data in facesets[].
424                                          */
425     FaceSets    facesets[MAX_FACE_SETS];
426 } Face_Information;
427 
428 extern Face_Information face_info;
429 
430 extern Client_Player cpl;               /**< Player object. */
431 extern char *skill_names[MAX_SKILL];
432 
433 extern int last_used_skills[MAX_SKILL+1]; /**< maps position to skill id with
434                                            *  trailing zero as stop mark.
435                                            */
436 
437 typedef enum {
438     LOG_DEBUG = 0,      ///< Useful debugging information
439     LOG_INFO = 1,       ///< Minor, non-harmful issues
440     LOG_WARNING = 2,    ///< Warning that something might not work
441     LOG_ERROR = 3,      ///< Warning that something definitely didn't work
442     LOG_CRITICAL = 4    ///< Fatal crash-worthy error
443 } LogLevel;
444 
445 /**
446  * Translation of the STAT_RES names into printable names, in matching order.
447  */
448 #define NUM_RESISTS 18
449 
450 extern const char *const resists_name[NUM_RESISTS];
451 extern char *meta_server;
452 extern int serverloginmethod, wantloginmethod;
453 
454 /**
455  * Holds the names that correspond to skill and resistance numbers.
456  */
457 typedef struct {
458     const char *name;
459     int         value;
460 } NameMapping;
461 
462 extern NameMapping skill_mapping[MAX_SKILL], resist_mapping[NUM_RESISTS];
463 
464 extern guint64   *exp_table;
465 extern guint16   exp_table_max;
466 
467 /**
468  * Map size the client will request the map to be.  The bigger it is, more
469  * memory it will use.
470  */
471 #define MAP_MAX_SIZE 25
472 
473 /**
474  * This is the smallest the map structure used for the client can be.  It
475  * needs to be bigger than the MAP_MAX_SIZE simply because we have to deal
476  * with off map big images, Also, the center point is moved around within this
477  * map, so that if the player moves one space, we don't have to move around
478  * all the data.
479  */
480 #define MIN_ALLOCATED_MAP_SIZE  MAP_MAX_SIZE * 2
481 
482 /**
483  * How many spaces an object might extend off the map.  E.g. For bigimage
484  * stuff, the head of the image may be off the the map edge.  This is the most
485  * it may be off.  This is needed To cover case of need_recenter_map routines.
486  */
487 #define MAX_MAP_OFFSET  8
488 
489 /* Start of map handling code.
490  *
491  * For the most part, this actually is not window system specific, but
492  * certainly how the client wants to store this may vary.
493  */
494 
495 #define MAXPIXMAPNUM 10000
496 
497 /**
498  * Used mostly in the cache.c file, however, it can be returned to the graphic
499  * side of things so that they can update the image_data field.  Since the
500  * common side has no idea what data the graphic side will point to, we use a
501  * void pointer for that - it is completely up to the graphic side to
502  * allocate/deallocate and cast that pointer as needed.
503  */
504 typedef struct Cache_Entry {
505     char    *filename;
506     guint32  checksum;
507     guint32  ispublic:1;
508     void    *image_data;
509     struct Cache_Entry  *next;
510 } Cache_Entry;
511 
512 /**
513  * @defgroup RI_IMAGE_xxx RI_IMAGE_xxx RequestInfo values.
514  * Values used for various aspects of the library to hold state on what
515  * requestinfo's we have gotten replyinfo for and what data was received.  In
516  * this way, common/client.c can loop until it has gotten replies for all the
517  * requestinfos it has sent.  This can be useful - we don't want the addme
518  * command sent for example if we are going to use a different image set.  The
519  * GUI stuff should really never change these variables, but I suppose I could
520  * look at them for debugging/ status information.
521  */
522 /*@{*/
523 #define RI_IMAGE_INFO 0x1
524 #define RI_IMAGE_SUMS 0x2
525 /*@}*/
526 
527 extern int  replyinfo_status, requestinfo_sent, replyinfo_last_face;
528 
529 typedef struct PlayerPosition {
530   int x;
531   int y;
532 } PlayerPosition;
533 
534 extern PlayerPosition pl_pos;
535 
536 typedef struct Msg_Type_Names {
537     int        type;                    /**< Type of message */
538     int        subtype;                 /**< Subtype of message */
539     const char *style_name;             /**< Name of this message in the
540                                          *   configfile.
541                                          */
542 } Msg_Type_Names;
543 
544 extern TextManager* firstTextManager;
545 
546 /* declared/handled in commands.c .  These variables are documented
547  * in that file - the data they present is created by the command
548  * code, but consumed by the GUI code.
549  */
550 extern char *motd, *news, *rules;
551 extern char *motd, *news, *rules;       /* Declared/handled in commands.c */
552 extern int num_races, used_races, num_classes, used_classes;
553 extern int stat_points, stat_min, stat_maximum;
554 
555 
556 
557 /*
558  * This structure is used to hold race/class adjustment info, as
559  * received by the requestinfo command.  We get the same info
560  * for both races and class, so it simplifies code to share a structure.
561  */
562 /* This is how many stats (str, dex, con, etc) that are present
563  * in the create character window.
564  */
565 #define NUM_NEW_CHAR_STATS  7
566 
567 /**
568  * The usage of the stat_mapping is to simplify the code and make it easier
569  * to expand.  Within the character creation, the different stats really
570  * do not have any meaning - the handling is pretty basic - value user
571  * has selected + race adjust + class adjustment = total stat.
572  */
573 struct Stat_Mapping {
574     const char  *widget_suffix; /* within the glade file, suffix used on widget */
575     guint8       cs_value;       /* within the protocol, the CS_STAT value */
576     guint8       rc_offset;      /* Offset into the stat_adj array */
577 };
578 
579 extern struct Stat_Mapping stat_mapping[NUM_NEW_CHAR_STATS];
580 
581 /**
582  * For classes & races, the server can present some number of
583  * choices, eg, the character gets to choose 1 skill from a
584  * choice of many.  Eg RC_Choice entry represents one of these
585  * choices.  However, each race/class may have multiple choices.
586  * For example, if the class had the character make 2 choices -
587  * one for a skill, and one for an item, 2 RC_Choice structures
588  * would be used.
589  */
590 struct RC_Choice {
591     char *choice_name;                  /* name to respond, eg, race_choice_1 */
592     char *choice_desc;                  /* Longer description of choice */
593     int num_values;                     /* How many values we have */
594     char **value_arch;    /* Array arch names */
595     char **value_desc;    /* Array of description */
596 };
597 
598 typedef struct Race_Class_Info {
599     char    *arch_name;     /* Name of the archetype this correponds to */
600     char    *public_name;   /* Public (human readadable) name */
601     char    *description;   /* Description of the race/class */
602     gint8   stat_adj[NUM_NEW_CHAR_STATS];   /* Adjustment values */
603     int     num_rc_choice;                  /* Size of following array */
604     struct RC_Choice    *rc_choice;         /* array of choices */
605 } Race_Class_Info;
606 
607 typedef struct Starting_Map_Info {
608     char    *arch_name;     /* Name of archetype for this map */
609     char    *public_name;   /* Name of the human readable name */
610     char    *description;   /* Description of this map */
611 } Starting_Map_Info;
612 
613 extern Race_Class_Info *races, *classes;
614 extern Starting_Map_Info *starting_map_info;
615 extern int starting_map_number;
616 extern int maxfd;
617 
618 /* End of commands.c data, start of other declarations */
619 #ifndef MIN
620 #define MIN(X__,Y__) ( (X__)<(Y__)?(X__):(Y__) )
621 #endif
622 
623 /**
624  * @defgroup INFO_xxx INFO_xxx login information constants.
625  * Used for passing in to update_login_info() used instead of passing in the
626  * strings.
627  */
628 /*@{*/
629 #define INFO_NEWS  1
630 #define INFO_MOTD  2
631 #define INFO_RULES 3
632 /*@}*/
633 
634 #define CLIENT_ERROR client_error_quark()
635 
client_error_quark()636 inline GQuark client_error_quark() {
637     return g_quark_from_static_string("client-error-quark");
638 }
639 
640 enum ClientError {
641     CLIENT_ERROR_TOOBIG
642 };
643 
644 /* We need to declare most of the structs before we can include this */
645 #include "proto.h"
646 
647 /**
648  * Open a socket to the given hostname and store connection information.
649  *
650  * @param hostname Host name or address of the server
651  */
652 extern void client_connect(const char *hostname);
653 
654 /**
655  * Closes the connection to the server.  It seems better to have it one place
656  * here than the same logic sprinkled about in half a dozen locations.  It is
657  * also useful in that if this logic does change, there is just one place to
658  * update it.
659  */
660 extern void client_disconnect(void);
661 
662 /**
663  * This function negotiates the characteriistics of a connection to the
664  * server.  Negotiation consists of asking the server for commands it wants,
665  * and checking protocol version for compatibility.  Serious incompatibilities
666  * abort the connection.
667  *
668  * @param sound Non-zero to ask for sound and music commands.
669  */
670 extern void client_negotiate(int sound);
671 
672 /**
673  * Ask the server for the given map size.
674  */
675 extern void client_mapsize(int width, int height);
676 
677 /**
678  * Read available packets from the server and handle commands until there are
679  * no more, or if a socket error occurs.
680  */
681 extern void client_run(void);
682 
683 /**
684  * Write the given data to the server.
685  */
686 extern bool client_write(const void *buf, int len);
687 
688 extern bool client_is_connected(void);
689 
690 /**
691  * Return a source triggered when input from the server is available.
692  */
693 extern GSource *client_get_source(void);
694 
695 extern GTimer* global_time;
696 
697 extern bool debug_protocol;
698 
699 #endif
700