home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / alt / sources / 2608 / netio.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-23  |  6.3 KB  |  262 lines

  1. /*    @(#)netio.h 1.1 92/05/28 SMI    */
  2. /*    from netio.h 1.4 90/07/23        */
  3.  
  4.  
  5. #ifndef    DSTAR_NETIO
  6. #define    DSTAR_NETIO
  7.  
  8. #include <netinet/in.h>
  9.  
  10. #ifndef    OBJECT_TYPES
  11. #include "object_types.h"
  12. #endif    OBJECT_TYPES
  13.  
  14.  
  15. /* if there's more than this many players in the game, use broadcast
  16.    messages instead of point-to-point */
  17.  
  18. #define    BROADCAST_THRESH 5
  19.  
  20. #define    MESSAGE_LENGTH    1024        /* maximum datagram length */
  21.  
  22. #define    MAX_DAEMONS    10        /* max # nets in game */
  23.  
  24.  
  25. /*
  26.  * this constant determine the port addresses that the game and
  27.  * the daemon will try to contact each other on.  The exact values are
  28.  * not important as long as they are greater than 1024 and are unique
  29.  * within the local network
  30.  */
  31.  
  32. #define    DSTAR_PORT    3314
  33.  
  34.  
  35.  
  36.  
  37. /*
  38.  * datagram headers.  Multiple messages may be packed into a single
  39.  * datagram.  All headers contain their length so that they may be
  40.  * skipped over by software that doesn't recognize them.  All
  41.  * messages (player->player, player->daemon, daemon->player) fit
  42.  * these categories.
  43.  */
  44.  
  45. /*
  46.  * KLUDGE ALERT!  WHOOP WHOOP WHOOP!
  47.  *
  48.  * This communications protocol assumes that all the machines on the
  49.  * net have the same byte ordering and data padding.  This is an
  50.  * unreasonable assumption, and it's already caused trouble porting
  51.  * to sun-4.  To do this right would require using the XDR protocol
  52.  * which I'm too lazy to adapt to.
  53.  */
  54.  
  55.  
  56. typedef enum header_type {
  57.       NET_NULL,            /* no message            */
  58.       NET_JOINING,            /* I'm joining game        */
  59.       NET_WELCOME,            /* acknowledgement        */
  60.       NET_ARE_YOU_THERE,        /* check to see if still alive    */
  61.       NET_JUST_SCORED,        /* I just shot someone        */
  62.       NET_NEW_SCORES,        /* update score info        */
  63.       NET_CURRENT_STATUS,        /* here's a new status block    */
  64.       NET_REQUEST_MISSILE,        /* want new missile id        */
  65.       NET_MISSILE,            /* response to above        */
  66.       NET_DIED,            /* some player has timed out    */
  67.       NET_BROADCAST,        /* request to rebroadcast a message */
  68.       NET_RENAME,            /* move player from slot to slot */
  69.     } Header_Type ;
  70.  
  71.  
  72.  
  73.  
  74.  
  75. /*
  76.  * null message
  77.  */
  78.  
  79. typedef    struct net_null {
  80.       Header_Type    type ;        /* identifier = NET_NULL */
  81.       int        len ;        /* sizeof(Net_null) */
  82.       int        id ;        /* sender's id */
  83.       int        sequence ;    /* sender's sequence # */
  84.     } Net_null ;
  85.  
  86.  
  87. /*
  88.  * message to submaster from new player
  89.  */
  90. typedef    struct net_joining {
  91.       Header_Type    type ;        /* identifier = NET_JOINING */
  92.       int        len ;        /* sizeof(Net_joining)    */
  93.       int        id ;        /* assigned by submaster */
  94.       int        sequence ;
  95.       char        name[NAMELEN] ;    /* player's name    */
  96.       Object_Class    class ;        /* player's class    */
  97.       struct sockaddr_in address ;    /* player's address    */
  98.     } Net_joining ;
  99.  
  100.  
  101. /*
  102.  * message to new player from daemon
  103.  */
  104. typedef    struct net_welcome {
  105.       Header_Type    type ;        /* identifier = NET_WELCOME */
  106.       int        len ;        /* sizeof(Net_welcome) */
  107.       int        id ;        /* master id */
  108.       int        sequence ;
  109.       int        player_id ;    /* player's id number */
  110.       int        team ;        /* player's team number */
  111.       Game_Type    game_type ;    /* scenario */
  112.     } Net_welcome ;
  113.  
  114.  
  115. /*
  116.  * message to player from submaster if timing out
  117.  */
  118. typedef    struct net_are_you_there {
  119.       Header_Type    type ;        /* identifier = NET_ARE_YOU_THERE */
  120.       int        len ;        /* sizeof(Net_are_you_there) */
  121.       int        id ;
  122.       int        sequence ;
  123.       int        his_id ;
  124.     } Net_are_you_there ;
  125.  
  126.  
  127.  
  128.  
  129.  
  130. /*
  131.  * message to all players from player that shot someone
  132.  */
  133. typedef    struct net_just_scored {
  134.       Header_Type    type ;        /* identifier = NET_JUST_SCORED */
  135.       int        len ;        /* sizeof(Net_just_scored) */
  136.       int        id ;        /* player's id */
  137.       int        sequence ;
  138.       int        weapon_id ;    /* weapon's (me or missile) id */
  139.       int        his_id ;    /* victim's id */
  140.     } Net_just_scored ;
  141.  
  142.  
  143. /*
  144.  * message to all players from daemon keeping score
  145.  */
  146. typedef    struct net_new_scores {
  147.       Header_Type    type ;        /* identifier = NET_NEW_SCORES */
  148.       int        len ;        /* length of this message */
  149.       int        id ;
  150.       int        sequence ;
  151.       int        nscores ;    /* total # of scores in array */
  152.       int        scores[2] ;    /* this is an array, player:score */
  153.     } Net_new_scores ;
  154.  
  155.  
  156. /*
  157.  * message from player to player with current status
  158.  */
  159. typedef    struct net_current_status {
  160.       Header_Type    type ;        /* identifier = NET_CURRENT_STATUS */
  161.       int        len ;        /* sizeof(Net_current_status)    */
  162.       int        id ;
  163.       int        sequence ;
  164.       int        obj_id ;
  165.       char        name[NAMELEN] ;    /* pilot's name            */
  166.       int        team ;        /* player's team or object's owner */
  167.       int        score ;        /* player's score        */
  168.       Object_Class    class ;        /* ship type            */
  169.       Object_State    status ;    /* ship status            */
  170.       u_int        flags ;        /* radar, laser etc.        */
  171.       Pt3d        Posn,        /* ship position & orientation    */
  172.             Forward,
  173.             Up,
  174.             Right ;
  175.       Pt3d        Delta ;        /* amount object is turning    */
  176.       Pt3d        Pointing ;    /* direction player is looking    */
  177.       float        Speed ;        /* velocity along Forward vector */
  178.       int        target ;    /* id of target if radar locked    */
  179.       int        description ;    /* index into object table    */
  180.       struct sockaddr_in address ;    /* net address            */
  181.       long        net_addr ;    /* what local net are we?    */
  182.     } Net_current_status ;
  183.  
  184.  
  185.  
  186. /*
  187.  * message from player to master asking for a missile assignment
  188.  */
  189. typedef    struct net_request_missile {
  190.       Header_Type    type ;        /* identifier = NET_REQUEST_MISSILE */
  191.       int        len ;        /* sizeof(Net_request_missile) */
  192.       int        id ;
  193.       int        sequence ;
  194.     } Net_request_missile ;
  195.  
  196.  
  197.  
  198.  
  199. /*
  200.  * message from master to player making assignment
  201.  */
  202. typedef    struct net_missile {
  203.       Header_Type    type ;        /* identifier = NET_MISSILE */
  204.       int        len ;        /* sizeof(Net_missile) */
  205.       int        id ;
  206.       int        sequence ;
  207.       int        missile_id ;    /* returned missile id */
  208.     } Net_missile ;
  209.  
  210.  
  211.  
  212.  
  213. /*
  214.  * message to all players about a player that timed out or quit
  215.  */
  216. typedef    struct net_died {
  217.       Header_Type    type ;        /* identifier = NET_DIED */
  218.       int        len ;        /* sizeof(Net_died) */
  219.       int        id ;        /* master's id */
  220.       int        sequence ;
  221.       int        his_id ;    /* dead player's id */
  222.     } Net_died ;
  223.  
  224.  
  225.  
  226. /*
  227.  * message to all players from master that changed id
  228.  */
  229. typedef    struct net_rename {
  230.       Header_Type    type ;        /* identifier = NET_RENAME */
  231.       int        len ;        /* sizeof(Net_rename) */
  232.       int        id ;        /* master's id */
  233.       int        sequence ;
  234.       int        new_id ;    /* new id */
  235.     } Net_rename ;
  236.  
  237.  
  238.  
  239. /*
  240.  * request to rebroadcast a message
  241.  */
  242. typedef    struct net_broadcast {
  243.       Header_Type    type ;        /* identifier = NET_BROADCAST */
  244.       int        len ;        /* size of total packet */
  245.       int        id ;        /* id */
  246.       int        sequence ;
  247.     } Net_broadcast ;
  248.  
  249.  
  250.  
  251.  
  252.  
  253.     int    sequence_number ;
  254.     int    status_display ;
  255.     int    poll_master ;
  256.     int    need_rehash ;
  257.     int    master_id ;
  258.  
  259.  
  260.  
  261. #endif    DSTAR_NETIO
  262.