Crossfire Client, Branch  R11627
client.h
Go to the documentation of this file.
00001 /*
00002  * static char *rcsid_client_h =
00003  *   "$Id: client.h 9197 2008-06-01 16:32:15Z anmaster $";
00004  */
00005 /*
00006     Crossfire client, a client program for the crossfire program.
00007 
00008     Copyright (C) 2001,2007 Mark Wedel & Crossfire Development Team
00009 
00010     This program is free software; you can redistribute it and/or modify
00011     it under the terms of the GNU General Public License as published by
00012     the Free Software Foundation; either version 2 of the License, or
00013     (at your option) any later version.
00014 
00015     This program is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018     GNU General Public License for more details.
00019 
00020     You should have received a copy of the GNU General Public License
00021     along with this program; if not, write to the Free Software
00022     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00023 
00024     The author can be reached via e-mail to crossfire-devel@real-time.com
00025 */
00026 
00034 #include <config.h>
00035 #include <version.h>
00036 #include <client-types.h>
00037 #include <newclient.h>
00038 #include <item.h>
00039 
00040 #ifdef HAVE_DMALLOC_H
00041 #  include <dmalloc.h>
00042 #endif
00043 
00044 #define MULTKEYS
00045 
00046 #define VERSION_CS 1023
00047 #define VERSION_SC 1029
00048 
00049 extern char VERSION_INFO[256];
00050 
00051 /* Don't send more than this many outstanding commands to the server
00052  * this is only a default value.
00053  */
00054 #define COMMAND_WINDOW 10
00055 
00056 #define STRINGCOMMAND 0
00057 
00058 /* How many skill types server supports/client will get sent to it.
00059  * If more skills are added to server, this needs to get increased.
00060  */
00061 #define MAX_SKILL   CS_NUM_SKILLS
00062 
00063 #define MAXANIM 2000
00064 
00065 /* Values for send_command option */
00066 
00067 #define SC_NORMAL 0
00068 #define SC_FIRERUN 1
00069 #define SC_ALWAYS 2
00070 
00071 typedef struct Animations {
00072     uint16  flags;
00073     uint8   num_animations; /* number of animations.  Value of 2 means
00074                              * only faces[0],[1] have meaningfull values.
00075                              */
00076     uint8   speed;
00077     uint8   speed_left;
00078     uint8   phase;
00079     uint16  *faces;
00080 
00081 } Animations;
00082 
00083 extern Animations animations[MAXANIM];
00084 
00085 #define CAN_SMOOTH(__SQUARE,__LEVEL) ( (                                       \
00086                                             (__SQUARE.heads[__LEVEL].face==0)  \
00087                                             && (__LEVEL >0)                    \
00088                                         )                                      \
00089                                         || (__SQUARE.smooth[layer])            \
00090                                      )
00091 
00092 /* ClientSocket could probably hold more of the global values - it could
00093  * probably hold most all socket/communication related values instead
00094  * of globals.
00095  */
00096 typedef struct ClientSocket {
00097     int fd;
00098     SockList    inbuf;
00099     int cs_version, sc_version; /* Server versions of these */
00100     /* These are used for the newer 'windowing' method of commands -
00101      * number of last command sent, number of received confirmation
00102      */
00103     int command_sent, command_received;
00104     /* Time (in ms) players commands currently take to execute */
00105     int command_time;
00106     char* servername;
00107 } ClientSocket;
00108 
00109 extern ClientSocket csocket;
00110 
00111 extern char *server, *client_libdir,*image_file, *sound_server;
00112 
00113 typedef enum Input_State {Playing, Reply_One, Reply_Many,
00114         Configure_Keys, Command_Mode, Metaserver_Select} Input_State;
00115 
00116 typedef enum rangetype {
00117   range_bottom = -1, range_none = 0, range_bow = 1, range_magic = 2,
00118   range_wand = 3, range_rod = 4, range_scroll = 5, range_horn = 6,
00119   range_steal = 7,
00120   range_size = 8
00121 } rangetype;
00122 
00123 /* This is a structure that contains most all of the
00124  * configuration options.  Instead of having a
00125  * whole mess of variables of different names, instead use
00126  * a common 16 bit signed array, and index into these -
00127  * this makes processing in the gui aspect of the GTK
00128  * client much easier.  There are also 2 elements -
00129  * want options, and use_options.  The former is what the
00130  * player wants to use, the later is what is currently
00131  * in use.  There are many options that can not be
00132  * switched between during actual play, but we want to
00133  * record what the player has changed them to so that
00134  * when we save them out, we save what the player wants,
00135  * and not what is currently being used.  Note that all the gui
00136  * interfaces may not use all these values, but making them
00137  * available here makes it easy for the GUI to present a
00138  * nice interface.
00139  * 0 is intentially skipped so the index into this doesn't
00140  * get a default if a table has a blank value
00141  *
00142  * CONFIG_NUMS is the number of configuration options; don't
00143  * forget to add to some of
00144  *   common/init.c config_names,
00145  *                 init_client_vars,
00146  *   x11/x11.c load_defaults
00147  *             save_defaults
00148  *   gtk/config.c load_defaults
00149  *                save_defaults
00150  * probably among other places, if you add a new option.
00151  */
00152 #define CONFIG_DOWNLOAD     1
00153 #define CONFIG_ECHO         2
00154 #define CONFIG_FASTTCP      3
00155 #define CONFIG_CWINDOW      4
00156 #define CONFIG_CACHE        5
00157 #define CONFIG_FOGWAR       6
00158 #define CONFIG_ICONSCALE    7
00159 #define CONFIG_MAPSCALE     8
00160 #define CONFIG_POPUPS       9
00161 #define CONFIG_DISPLAYMODE  10
00162 #define CONFIG_SHOWICON     11
00163 #define CONFIG_TOOLTIPS     12
00164 #define CONFIG_SOUND        13
00165 #define CONFIG_SPLITINFO    14
00166 #define CONFIG_SPLITWIN     15
00167 #define CONFIG_SHOWGRID     16
00168 #define CONFIG_LIGHTING     17
00169 #define CONFIG_TRIMINFO     18
00170 #define CONFIG_MAPWIDTH     19
00171 #define CONFIG_MAPHEIGHT    20
00172 #define CONFIG_FOODBEEP     21
00173 #define CONFIG_DARKNESS     22
00174 #define CONFIG_PORT         23          /* Not sure if useful at all anymore */
00175 #define CONFIG_GRAD_COLOR   24
00176 #define CONFIG_RESISTS      25
00177 #define CONFIG_SMOOTH       26
00178 #define CONFIG_SPLASH       27
00179 #define CONFIG_APPLY_CONTAINER  28      /* Reapply container */
00180 #define CONFIG_MAPSCROLL    29          /* Use bitmap operations for map scrolling */
00181 #define CONFIG_SIGNPOPUP    30
00182 #define CONFIG_TIMESTAMP    31
00183 #define CONFIG_NUMS         32          /* This should always be the last value in the list */
00184 
00185 /* CONFIG_LIGHTING can have several possible values - set them accordingly */
00186 #define CFG_LT_NONE         0
00187 #define CFG_LT_TILE         1
00188 #define CFG_LT_PIXEL        2
00189 #define CFG_LT_PIXEL_BEST   3
00190 
00191 /* CONFIG_DISPLAYMODE can have several possible values.  Give
00192  * defines for the possibilities.
00193  */
00194 #define CFG_DM_PIXMAP       0
00195 #define CFG_DM_SDL          1
00196 #define CFG_DM_OPENGL       2
00197 
00198 extern sint16 want_config[CONFIG_NUMS], use_config[CONFIG_NUMS];
00199 
00200 extern const char *const config_names[CONFIG_NUMS]; 
00205 typedef struct Stat_struct {
00206     sint8 Str;                          
00207     sint8 Dex;                          
00208     sint8 Con;                          
00209     sint8 Wis;                          
00210     sint8 Cha;                          
00211     sint8 Int;                          
00212     sint8 Pow;                          
00213     sint8 wc;                           
00214     sint8 ac;                           
00215     sint8 level;                        
00216     sint16 hp;                          
00217     sint16 maxhp;                       
00218     sint16 sp;                          
00219     sint16 maxsp;                       
00220     sint16 grace;                       
00221     sint16 maxgrace;                    
00222     sint64 exp;                         
00223     sint16 food;                        
00226     sint16 dam;                         
00229     sint32 speed;                       
00230     sint32 weapon_sp;                   
00233     uint32 attuned;                     
00236     uint32 repelled;                    
00239     uint32 denied;                      
00240     uint16 flags;                       
00241     sint16 resists[30];                 
00242     uint32 resist_change:1;             
00243     sint16 skill_level[MAX_SKILL];      
00244     sint64 skill_exp[MAX_SKILL];        
00245     uint32 weight_limit;                
00246 } Stats;
00247 
00248 typedef struct Spell_struct {
00249     struct Spell_struct *next;
00250     char name[256];                     
00253     char message[10000];                
00255     uint32 tag;                         
00257     uint16 level;                       
00258     uint16 time;                        
00259     uint16 sp;                          
00260     uint16 grace;                       
00261     uint16 dam;                         
00262     uint8 skill_number;                 
00264     char *skill;                        
00266     uint32 path;                        
00268     sint32 face;                        
00269 } Spell;
00270 
00271 typedef struct Player_Struct {
00272     item        *ob;                    
00273     item        *below;                 
00275     item        *container;             
00276     uint16      count_left;             
00277     Input_State input_state;            
00278     char        last_command[MAX_BUF];  
00279     char        input_text[MAX_BUF];    
00280     item        *ranges[range_size];    
00282     uint8       ready_spell;            
00283     char        spells[255][40];        
00285     Stats       stats;                  
00286     Spell       *spelldata;             
00287     char        title[MAX_BUF];         
00288     char        range[MAX_BUF];         
00289     uint32      spells_updated;         
00290     uint32      fire_on:1;              
00291     uint32      run_on:1;               
00292     uint32      meta_on:1;              
00293     uint32      alt_on:1;               
00294     uint32      no_echo:1;              
00295     uint32      count;                  
00296     uint16      mmapx, mmapy;           
00297     uint16      pmapx, pmapy;           
00299     uint8       *magicmap;              
00300     uint8       showmagic;              
00302     uint16      mapxres,mapyres;        
00305 #ifdef MULTKEYS
00306     char    name[ 40 ];                 
00308 #endif
00309 } Client_Player;
00310 
00311 /* This faceset information is pretty much grabbed right from
00312  * server/socket/image.c
00313  */
00314 
00315 #define MAX_FACE_SETS   20
00316 #define MAX_IMAGE_SIZE 320              
00323 typedef struct FaceSets_struct {
00324     uint8   setnum;                     
00325     uint8   fallback;                   
00326     char    *prefix;                    
00327     char    *fullname;                  
00328     char    *size;                      
00329     char    *extension;                 
00330     char    *comment;                   
00331 } FaceSets;
00332 
00333 /* Make one struct that holds most of the image related data.
00334  * reduces danger of namespace collision.
00335  */
00336 typedef struct Face_Information_struct {
00337     uint8   faceset;
00338     char    *want_faceset;
00339     sint16  num_images;
00340     uint32  bmaps_checksum, old_bmaps_checksum;
00341     /* Just for debugging/logging purposes.  This is cleared
00342      * on each new server connection.  This may not be
00343      * 100% precise (as we increment cache_hits when we
00344      * find a suitable image to load - if the data is bad,
00345      * that would count as both a hit and miss
00346      */
00347     sint16  cache_hits, cache_misses;
00348     uint8       have_faceset_info;      /* Simple value to know if there is data in facesets[] */
00349     FaceSets    facesets[MAX_FACE_SETS];
00350 } Face_Information;
00351 
00352 extern Face_Information face_info;
00353 
00354 
00355 extern Client_Player cpl;               /* Player object. */
00356 extern char *skill_names[MAX_SKILL];
00357 
00358 extern int last_used_skills[MAX_SKILL+1]; // maps position to skill id with trailing zero as stop mark
00359 
00360 
00361 typedef enum LogLevel {
00362   LOG_DEBUG = 0, LOG_INFO = 1, LOG_WARNING = 2, LOG_ERROR = 3, LOG_CRITICAL = 4
00363 } LogLevel;
00364 
00365 typedef struct LogEntry {
00366     char* message;
00367     char* origin;
00368     LogLevel level;
00369     struct LogEntry* next;
00370 } LogEntry;
00371 extern LogEntry* LogFirst;
00372 extern LogEntry* LogLast;
00373 extern int logcount;
00374 typedef void (*LogListener)(LogEntry*);
00375 #define MAX_LOGS 200
00376 #define LOG_APPEND(_Entry) if (LogLast) {\
00377     LogLast->next=_Entry;\
00378   } else {\
00379     LogFirst=_Entry;\
00380   };\
00381   LogLast=_Entry;_Entry->next=NULL;\
00382   if (++logcount > MAX_LOGS)\
00383   {\
00384       LogEntry* old = LogFirst;\
00385       LogFirst = LogFirst -> next;\
00386       if (old->message) free (old->message);\
00387       if (old->origin) free (old->origin);\
00388   }
00389 #define LOG_NEW_ENTRY (LogEntry*)calloc(1,sizeof(LogEntry))
00390 #define LOG_SETMESSAGE(_Entry,_msg) free(_Entry->message);_Entry->message=strdup(_msg)
00391 #define LOG_SETORIGIN(_Entry,_orig) free(_Entry->origin);_Entry->origin=strdup(_orig)
00392 
00393 typedef struct PipeLog {
00394     char* name;
00395     LogLevel level;
00396     int log; /*yes or no to log*/
00397 }PipeLog;
00398 
00399 #define CHILD_STDIN 1
00400 #define CHILD_STDOUT 2
00401 #define CHILD_STDERR 4
00402 #define CHILD_SILENTFAIL 8
00403 #define CHILD_TUBE (CHILD_STDIN|CHILD_STDOUT|CHILD_STDERR)
00404 typedef struct ChildProcess{
00405     char* name;
00406     int flag;
00407     int pid;
00408     int tube[3];
00409     PipeLog logger[3];
00410     struct ChildProcess* next;
00411 }ChildProcess;
00412 
00413 #define CHILD_PIPEIN(__child) (__child->tube[0])
00414 #define CHILD_PIPEOUT(__child) (__child->tube[1])
00415 #define CHILD_PIPEERR(__child) (__child->tube[2])
00416 
00417 
00418 #ifndef CPROTO
00419 /* We need to declare most of the structs before we can include this */
00420 #include <proto.h>
00421 #endif
00422 
00423 /* translation of the STAT_RES names into printable names,
00424  * in matching order.
00425  */
00426 #define NUM_RESISTS 18
00427 extern const char *const resists_name[NUM_RESISTS];
00428 extern char *meta_server;
00429 extern int meta_port,want_skill_exp;
00430 extern int metaserver_on, metaserver2_on;
00431 extern uint32   tick;
00432 
00433 extern uint64   *exp_table;
00434 extern uint16   exp_table_max;
00435 
00436 extern int command_inscribe;
00437 
00438 /* Map size the client will request the map to be.  Bigger it is,
00439  * more memory it will use
00440  */
00441 #define MAP_MAX_SIZE    31
00442 
00443 /* This is basically the smallest the map structure
00444  * used for the client can be.  It needs to be bigger than
00445  * the min map size above simply because we have to deal with
00446  * off map big images, Also, we move the center point
00447  * around within this map, so that if the player moves one space,
00448  * we don't have to move around all the data.
00449  */
00450 #define MIN_ALLOCATED_MAP_SIZE  MAP_MAX_SIZE * 2
00451 
00452 /* This is how many spaces an object might extend off the map.
00453  * Eg, for bigimage stuff, the head of the image may be off the
00454  * the map edge.  This is the most it may be off.  This is needed
00455  * To cover case of need_recenter_map routines.
00456  */
00457 #define MAX_MAP_OFFSET  8
00458 
00459 /* Start of map handling code.
00460  * For the most part, this actually is not window system specific,
00461  * but certainly how the client wants to store this may vary.
00462  */
00463 
00464 #define MAXPIXMAPNUM 10000
00465 
00466 /* This is used mostly in the cache.c file, however, it
00467  * can be returned to the graphic side of things so that they
00468  * can update the image_data field.  Since the common side
00469  * has no idea what data the graphic side will point to,
00470  * we use a void pointer for that - it is completely up to
00471  * the graphic side to allocate/deallocate and cast that
00472  * pointer as needed.
00473  */
00474 typedef struct Cache_Entry {
00475     char    *filename;
00476     uint32  checksum;
00477     uint32  ispublic:1;
00478     void    *image_data;
00479     struct Cache_Entry  *next;
00480 } Cache_Entry;
00481 
00482 /* These values are used for various aspects of the library to
00483  * hold state on what requestinfo's we have gotten replyinfo
00484  * for and what data was received.  In this way, common/client.c
00485  * can loop until it has gotten replies for all the requestinfos
00486  * it has sent.  This can be useful - we don't want the addme
00487  * command sent for example if we are going to use a different
00488  * image set.  The GUI stuff should really never chnage these
00489  * variables, but could I suppose look at them for debugging/
00490  * status information.
00491  */
00492 
00493 #define RI_IMAGE_INFO       0x1
00494 #define RI_IMAGE_SUMS       0x2
00495 extern int  replyinfo_status, requestinfo_sent, replyinfo_last_face;
00496 
00497 typedef struct PlayerPosition {
00498   int x;
00499   int y;
00500 } PlayerPosition;
00501 
00502 extern PlayerPosition pl_pos;
00503 
00504 
00505 typedef struct Msg_Type_Names {
00506     int        type;           /* type of message */
00507     int        subtype;        /* subtype of message */
00508     const char *style_name;    /* name of this message in the configfile */
00509 } Msg_Type_Names;
00510 
00511 extern TextManager* firstTextManager;
00512 
00513 #ifndef MIN
00514 #define MIN(X__,Y__) ( (X__)<(Y__)?(X__):(Y__) )
00515 #endif