home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / games / volume15 / xtb / part02 / comms.h next >
Text File  |  1993-01-27  |  3KB  |  149 lines

  1. /* comms and common data structures */
  2.  
  3. /*
  4.  * $Header: /morpork/home/bmh/xtest2/RCS/comms.h,v 1.18 92/10/19 15:34:38 bmh Exp Locker: bmh $
  5.  *
  6.  * Bernard Hatt
  7.  * Camtec Electronics (Ericsson), Leicester, England, LE1 4SA
  8.  * bmh@terminus.ericsson.se
  9.  *
  10.  */
  11.  
  12.     /* types of message */
  13. #define    T_SIGNON    1    /* signon request to server */
  14. #define    T_ACCEPT    2    /* accept of signon from server */
  15. #define T_REJECT    3    /* rejection of signon from server */
  16. #define T_MOVE        4    /* move made sent to server */
  17. #define    T_REPLY        5    /* reply from server (once moves have been made) */
  18. #define    T_SIGNOFF    6    /* signoff to server */
  19. #define T_FIELDDATA    7    /* battlefield data (from server) */
  20. #define    T_DATAREQ    8    /* request for battlefield data (to server) */
  21. #define T_EXPLOSION    9    /* explosion on battlefield */
  22. #define T_MESSAGE    10    /* message from server */
  23. #define T_ALIVE        11    /* check if client is alive */
  24.  
  25.     /* match byte orders of differing machines */
  26. #define INSWAP(x)    ((int)(htonl((long)(x))))
  27. #define OUTSWAP(x)    ((int)(ntohl((long)(x))))
  28.  
  29.  
  30. typedef struct struct_userinfo
  31. {
  32.     int id;    
  33.     char username[NAMELEN];
  34.     char hostname[HOSTLEN];        /* sending hostname */
  35. } USER;
  36.  
  37. typedef struct struct_position
  38. {
  39.     int x;        /* x position on battlefield */
  40.     int y;        /* y */
  41.     int rot;    /* rotation */
  42.     int scx;    /* x distance scrolled */
  43.     int scy;    /* y */
  44. } POSITION;
  45.  
  46. typedef struct signon_struct
  47. {
  48.     int port;    /* callback port no. */
  49.     int version;    /* program version */
  50.     char hostname[HOSTLEN];    /* sending hostname */
  51.     char username[NAMELEN];
  52. } SIGNON;
  53.  
  54. typedef struct accept_struct
  55. {
  56.     int id;        /* your player id. */
  57.     USER players[MAXUSERS];
  58.     int kills[MAXUSERS];    /* no. of kills made */
  59.     int killed[MAXUSERS];    /* no of times killed */
  60. } ACCEPT;
  61.  
  62. typedef struct reject_struct
  63. {
  64.     int reason;        /* unused */
  65.     char text[BUFLEN];    /* textual reason for rejection */
  66. } REJECT;
  67.  
  68. typedef struct move_struct
  69. {
  70.     int rot;    /* rotation */
  71.     int linear;    /* linear movement */
  72.     int fire;    /* file button */
  73. } MOVE;
  74.  
  75. typedef struct reply_struct
  76. {
  77.     POSITION    pos[MAXUSERS];    /* positions of players */
  78. } REPLY;
  79.  
  80. typedef struct field_struct
  81. {
  82.     int lineno;        /* line no of field */
  83.     char object[OBJECTSIZE];    /* data */
  84. } FIELD;
  85.  
  86. typedef struct datareq_struct
  87. {
  88.     int lineno;        /* requested reason */
  89. } DATAREQ;
  90.  
  91. typedef struct signoff_struct
  92. {
  93.     int reason;
  94. } SIGNOFF;
  95.  
  96. typedef struct explosion_struct
  97. {
  98.     int x;    /* x and y of explosion */
  99.     int y;
  100.     int damage[MAXUSERS];    /* damage sustained by players */
  101. } EXPLOSION;
  102.  
  103. typedef struct message_struct
  104. {
  105.     char text[BUFLEN];
  106. } MESSAGE;
  107.  
  108. typedef union extra_union
  109. {
  110.     SIGNON    signon;
  111.     ACCEPT    accept;
  112.     REJECT    reject;
  113.     MOVE    move;
  114.     REPLY    reply;
  115.     FIELD    field;
  116.     DATAREQ    datareq;
  117.     EXPLOSION explosion;
  118.     MESSAGE    message;
  119.     SIGNOFF    signoff;
  120. } EXTRA;
  121.  
  122. typedef struct data_struct
  123. {
  124.     int type;    /* type of message */
  125.     int id;        /* id of sending machine */
  126.     EXTRA extra;
  127. } DATA;
  128.  
  129. typedef struct player_struct
  130. {
  131.     int ssd;    /* socket descripter */
  132.     int t;        /* last time a move was made */
  133.     int restime;    /* time of last response */
  134.     int firetime;    /* last time the player fired */
  135.     int damage;    /* damage a player has sustained */
  136.     int kills;    /* kills made by a player */
  137.     int killed;    /* times killed */
  138.     USER    user;    /* data about user */
  139.     POSITION pos;    /* current position */
  140.     MOVE    move;    /* status */
  141. } PLAYER;
  142.  
  143. typedef struct score_struct
  144. {
  145.     int kills;    /* kills made by a player */
  146.     int killed;    /* times killed */
  147.     USER    user;    /* data about user */
  148. } SCORE;
  149.