home *** CD-ROM | disk | FTP | other *** search
- /* @(#)netio.h 1.1 92/05/28 SMI */
- /* from netio.h 1.4 90/07/23 */
-
-
- #ifndef DSTAR_NETIO
- #define DSTAR_NETIO
-
- #include <netinet/in.h>
-
- #ifndef OBJECT_TYPES
- #include "object_types.h"
- #endif OBJECT_TYPES
-
-
- /* if there's more than this many players in the game, use broadcast
- messages instead of point-to-point */
-
- #define BROADCAST_THRESH 5
-
- #define MESSAGE_LENGTH 1024 /* maximum datagram length */
-
- #define MAX_DAEMONS 10 /* max # nets in game */
-
-
- /*
- * this constant determine the port addresses that the game and
- * the daemon will try to contact each other on. The exact values are
- * not important as long as they are greater than 1024 and are unique
- * within the local network
- */
-
- #define DSTAR_PORT 3314
-
-
-
-
- /*
- * datagram headers. Multiple messages may be packed into a single
- * datagram. All headers contain their length so that they may be
- * skipped over by software that doesn't recognize them. All
- * messages (player->player, player->daemon, daemon->player) fit
- * these categories.
- */
-
- /*
- * KLUDGE ALERT! WHOOP WHOOP WHOOP!
- *
- * This communications protocol assumes that all the machines on the
- * net have the same byte ordering and data padding. This is an
- * unreasonable assumption, and it's already caused trouble porting
- * to sun-4. To do this right would require using the XDR protocol
- * which I'm too lazy to adapt to.
- */
-
-
- typedef enum header_type {
- NET_NULL, /* no message */
- NET_JOINING, /* I'm joining game */
- NET_WELCOME, /* acknowledgement */
- NET_ARE_YOU_THERE, /* check to see if still alive */
- NET_JUST_SCORED, /* I just shot someone */
- NET_NEW_SCORES, /* update score info */
- NET_CURRENT_STATUS, /* here's a new status block */
- NET_REQUEST_MISSILE, /* want new missile id */
- NET_MISSILE, /* response to above */
- NET_DIED, /* some player has timed out */
- NET_BROADCAST, /* request to rebroadcast a message */
- NET_RENAME, /* move player from slot to slot */
- } Header_Type ;
-
-
-
-
-
- /*
- * null message
- */
-
- typedef struct net_null {
- Header_Type type ; /* identifier = NET_NULL */
- int len ; /* sizeof(Net_null) */
- int id ; /* sender's id */
- int sequence ; /* sender's sequence # */
- } Net_null ;
-
-
- /*
- * message to submaster from new player
- */
- typedef struct net_joining {
- Header_Type type ; /* identifier = NET_JOINING */
- int len ; /* sizeof(Net_joining) */
- int id ; /* assigned by submaster */
- int sequence ;
- char name[NAMELEN] ; /* player's name */
- Object_Class class ; /* player's class */
- struct sockaddr_in address ; /* player's address */
- } Net_joining ;
-
-
- /*
- * message to new player from daemon
- */
- typedef struct net_welcome {
- Header_Type type ; /* identifier = NET_WELCOME */
- int len ; /* sizeof(Net_welcome) */
- int id ; /* master id */
- int sequence ;
- int player_id ; /* player's id number */
- int team ; /* player's team number */
- Game_Type game_type ; /* scenario */
- } Net_welcome ;
-
-
- /*
- * message to player from submaster if timing out
- */
- typedef struct net_are_you_there {
- Header_Type type ; /* identifier = NET_ARE_YOU_THERE */
- int len ; /* sizeof(Net_are_you_there) */
- int id ;
- int sequence ;
- int his_id ;
- } Net_are_you_there ;
-
-
-
-
-
- /*
- * message to all players from player that shot someone
- */
- typedef struct net_just_scored {
- Header_Type type ; /* identifier = NET_JUST_SCORED */
- int len ; /* sizeof(Net_just_scored) */
- int id ; /* player's id */
- int sequence ;
- int weapon_id ; /* weapon's (me or missile) id */
- int his_id ; /* victim's id */
- } Net_just_scored ;
-
-
- /*
- * message to all players from daemon keeping score
- */
- typedef struct net_new_scores {
- Header_Type type ; /* identifier = NET_NEW_SCORES */
- int len ; /* length of this message */
- int id ;
- int sequence ;
- int nscores ; /* total # of scores in array */
- int scores[2] ; /* this is an array, player:score */
- } Net_new_scores ;
-
-
- /*
- * message from player to player with current status
- */
- typedef struct net_current_status {
- Header_Type type ; /* identifier = NET_CURRENT_STATUS */
- int len ; /* sizeof(Net_current_status) */
- int id ;
- int sequence ;
- int obj_id ;
- char name[NAMELEN] ; /* pilot's name */
- int team ; /* player's team or object's owner */
- int score ; /* player's score */
- Object_Class class ; /* ship type */
- Object_State status ; /* ship status */
- u_int flags ; /* radar, laser etc. */
- Pt3d Posn, /* ship position & orientation */
- Forward,
- Up,
- Right ;
- Pt3d Delta ; /* amount object is turning */
- Pt3d Pointing ; /* direction player is looking */
- float Speed ; /* velocity along Forward vector */
- int target ; /* id of target if radar locked */
- int description ; /* index into object table */
- struct sockaddr_in address ; /* net address */
- long net_addr ; /* what local net are we? */
- } Net_current_status ;
-
-
-
- /*
- * message from player to master asking for a missile assignment
- */
- typedef struct net_request_missile {
- Header_Type type ; /* identifier = NET_REQUEST_MISSILE */
- int len ; /* sizeof(Net_request_missile) */
- int id ;
- int sequence ;
- } Net_request_missile ;
-
-
-
-
- /*
- * message from master to player making assignment
- */
- typedef struct net_missile {
- Header_Type type ; /* identifier = NET_MISSILE */
- int len ; /* sizeof(Net_missile) */
- int id ;
- int sequence ;
- int missile_id ; /* returned missile id */
- } Net_missile ;
-
-
-
-
- /*
- * message to all players about a player that timed out or quit
- */
- typedef struct net_died {
- Header_Type type ; /* identifier = NET_DIED */
- int len ; /* sizeof(Net_died) */
- int id ; /* master's id */
- int sequence ;
- int his_id ; /* dead player's id */
- } Net_died ;
-
-
-
- /*
- * message to all players from master that changed id
- */
- typedef struct net_rename {
- Header_Type type ; /* identifier = NET_RENAME */
- int len ; /* sizeof(Net_rename) */
- int id ; /* master's id */
- int sequence ;
- int new_id ; /* new id */
- } Net_rename ;
-
-
-
- /*
- * request to rebroadcast a message
- */
- typedef struct net_broadcast {
- Header_Type type ; /* identifier = NET_BROADCAST */
- int len ; /* size of total packet */
- int id ; /* id */
- int sequence ;
- } Net_broadcast ;
-
-
-
-
-
- int sequence_number ;
- int status_display ;
- int poll_master ;
- int need_rehash ;
- int master_id ;
-
-
-
- #endif DSTAR_NETIO
-