Annotation of quake1/net.h, revision 1.1.1.2

1.1       root        1: // net.h -- quake's interface to the networking layer
                      2: 
                      3: struct qsockaddr
                      4: {
                      5:        short sa_family;
                      6:        unsigned char sa_data[14];
                      7: };
                      8: 
                      9: 
                     10: #define        NET_NAMELEN                     64
                     11: 
                     12: #define NET_MAXMESSAGE         8192
                     13: #define NET_HEADERSIZE         (2 * sizeof(unsigned int))
                     14: #define NET_DATAGRAMSIZE       (MAX_DATAGRAM + NET_HEADERSIZE)
                     15: 
1.1.1.2 ! root       16: 
1.1       root       17: // NetHeader flags
                     18: #define NETFLAG_LENGTH_MASK    0x0000ffff
                     19: #define NETFLAG_DATA           0x00010000
                     20: #define NETFLAG_ACK                    0x00020000
                     21: #define NETFLAG_NAK                    0x00040000
                     22: #define NETFLAG_EOM                    0x00080000
                     23: #define NETFLAG_UNRELIABLE     0x00100000
                     24: #define NETFLAG_CTL                    0x80000000
                     25: 
                     26: 
                     27: #define NET_PROTOCOL_VERSION   3
                     28: 
                     29: // This is the network info/connection protocol.  It is used to find Quake
                     30: // servers, get info about them, and connect to them.  Once connected, the
                     31: // Quake game protocol (documented elsewhere) is used.
                     32: //
                     33: //
                     34: // General notes:
                     35: //     game_name is currently always "QUAKE", but is there so this same protocol
                     36: //             can be used for future games as well; can you say Quake2?
                     37: //
                     38: // CCREQ_CONNECT
                     39: //             string  game_name                               "QUAKE"
                     40: //             byte    net_protocol_version    NET_PROTOCOL_VERSION
1.1.1.2 ! root       41: //             byte    game_protocol_version   PROTOCOL_VERSION
1.1       root       42: //
                     43: // CCREQ_SERVER_INFO
                     44: //             string  game_name                               "QUAKE"
                     45: //             byte    net_protocol_version    NET_PROTOCOL_VERSION
1.1.1.2 ! root       46: //             byte    game_protocol_version   PROTOCOL_VERSION
1.1       root       47: //
                     48: // CCREQ_PLAYER_INFO
                     49: //             byte    player_number
                     50: //
                     51: // CCREQ_RULE_INFO
                     52: //             string  rule
                     53: //
1.1.1.2 ! root       54: // CCREQ_RULE_NEXT_INFO
        !            55: //             string  previous_rule
        !            56: //
        !            57: // CCREQ_PING
        !            58: //             byte    data[64]
        !            59: //
1.1       root       60: //
                     61: //
                     62: // CCREP_ACCEPT
                     63: //             long    port
                     64: //
                     65: // CCREP_REJECT
                     66: //             string  reason
                     67: //
                     68: // CCREP_SERVER_INFO
1.1.1.2 ! root       69: //             byte    protocol_version        NET_PROTOCOL_VERSION
        !            70: //             byte    address_form            ;0 short form, 1 long form
        !            71: //                     long    port
        !            72: //             OR
        !            73: //                     string  server_address
1.1       root       74: //             string  host_name
                     75: //             string  level_name
                     76: //             byte    current_players
                     77: //             byte    max_players
                     78: //
                     79: // CCREP_PLAYER_INFO
                     80: //             byte    player_number
                     81: //             string  name
                     82: //             long    colors
                     83: //             long    frags
                     84: //             long    connect_time
                     85: //             string  address
                     86: //
                     87: // CCREP_RULE_INFO
                     88: //             string  rule
                     89: //             string  value
1.1.1.2 ! root       90: //
        !            91: // CCREP_PING
        !            92: //             byte    data[64]
1.1       root       93: 
                     94: //     note:
                     95: //             There are two address forms used above.  The short form is just a
                     96: //             port number.  The address that goes along with the port is defined as
                     97: //             "whatever address you receive this reponse from".  This lets us use
                     98: //             the host OS to solve the problem of multiple host addresses (possibly
                     99: //             with no routing between them); the host will use the right address
                    100: //             when we reply to the inbound connection request.  The long from is
                    101: //             a full address and port in a string.  It is used for returning the
                    102: //             address of a server that is not running locally.
                    103: 
                    104: #define CCREQ_CONNECT          0x01
                    105: #define CCREQ_SERVER_INFO      0x02
                    106: #define CCREQ_PLAYER_INFO      0x03
                    107: #define CCREQ_RULE_INFO                0x04
1.1.1.2 ! root      108: #define CCREQ_PING                     0x05
1.1       root      109: 
                    110: #define CCREP_ACCEPT           0x81
                    111: #define CCREP_REJECT           0x82
                    112: #define CCREP_SERVER_INFO      0x83
                    113: #define CCREP_PLAYER_INFO      0x84
                    114: #define CCREP_RULE_INFO                0x85
1.1.1.2 ! root      115: #define CCREP_PING                     0x86
1.1       root      116: 
                    117: typedef struct qsocket_s
                    118: {
                    119:        struct qsocket_s        *next;
                    120:        double                  connecttime;
                    121:        double                  lastMessageTime;
                    122:        double                  lastSendTime;
                    123: 
                    124:        qboolean                disconnected;
                    125:        qboolean                canSend;
                    126:        qboolean                sendNext;
                    127:        
                    128:        int                             driver;
                    129:        int                             landriver;
                    130:        int                             socket;
                    131:        void                    *driverdata;
                    132: 
                    133:        unsigned int    sendSequence;
                    134:        unsigned int    unreliableSendSequence;
                    135:        int                             sendMessageLength;
                    136:        byte                    sendMessage [NET_MAXMESSAGE];
                    137: 
                    138:        unsigned int    receiveSequence;
                    139:        unsigned int    unreliableReceiveSequence;
                    140:        int                             receiveMessageLength;
                    141:        byte                    receiveMessage [NET_MAXMESSAGE];
                    142: 
                    143:        struct qsockaddr        addr;
                    144:        char                            address[NET_NAMELEN];
                    145: 
                    146: } qsocket_t;
                    147: 
                    148: extern qsocket_t       *net_activeSockets;
                    149: extern qsocket_t       *net_freeSockets;
                    150: extern int                     net_numsockets;
                    151: 
                    152: typedef struct
                    153: {
                    154:        char            *name;
                    155:        qboolean        initialized;
                    156:        int                     controlSock;
                    157:        int                     (*Init) (void);
                    158:        void            (*Shutdown) (void);
                    159:        void            (*Listen) (qboolean state);
                    160:        int             (*OpenSocket) (int port);
                    161:        int             (*CloseSocket) (int socket);
                    162:        int             (*Connect) (int socket, struct qsockaddr *addr);
                    163:        int             (*CheckNewConnections) (void);
                    164:        int             (*Read) (int socket, byte *buf, int len, struct qsockaddr *addr);
                    165:        int             (*Write) (int socket, byte *buf, int len, struct qsockaddr *addr);
                    166:        int             (*Broadcast) (int socket, byte *buf, int len);
                    167:        char *          (*AddrToString) (struct qsockaddr *addr);
                    168:        int             (*StringToAddr) (char *string, struct qsockaddr *addr);
                    169:        int             (*GetSocketAddr) (int socket, struct qsockaddr *addr);
                    170:        int             (*GetNameFromAddr) (struct qsockaddr *addr, char *name);
                    171:        int             (*GetAddrFromName) (char *name, struct qsockaddr *addr);
                    172:        int                     (*AddrCompare) (struct qsockaddr *addr1, struct qsockaddr *addr2);
                    173:        int                     (*GetSocketPort) (struct qsockaddr *addr);
                    174:        int                     (*SetSocketPort) (struct qsockaddr *addr, int port);
                    175: } net_landriver_t;
                    176: 
                    177: #define        MAX_NET_DRIVERS         8
                    178: extern int                             net_numlandrivers;
                    179: extern net_landriver_t net_landrivers[MAX_NET_DRIVERS];
                    180: 
                    181: typedef struct
                    182: {
                    183:        char            *name;
                    184:        qboolean        initialized;
                    185:        int                     (*Init) (void);
                    186:        void            (*Listen) (qboolean state);
                    187:        void            (*SearchForHosts) (qboolean xmit);
                    188:        qsocket_t       *(*Connect) (char *host);
                    189:        qsocket_t       *(*CheckNewConnections) (void);
                    190:        int                     (*GetMessage) (qsocket_t *sock);
                    191:        int                     (*SendMessage) (qsocket_t *sock, sizebuf_t *data);
                    192:        int                     (*SendUnreliableMessage) (qsocket_t *sock, sizebuf_t *data);
                    193:        qboolean        (*CanSendMessage) (qsocket_t *sock);
                    194:        qboolean        (*CanSendUnreliableMessage) (qsocket_t *sock);
                    195:        void            (*Close) (qsocket_t *sock);
                    196:        void            (*Shutdown) (void);
                    197:        int                     controlSock;
                    198: } net_driver_t;
                    199: 
                    200: extern int                     net_numdrivers;
                    201: extern net_driver_t    net_drivers[MAX_NET_DRIVERS];
                    202: 
                    203: extern int net_driverlevel;
                    204: extern cvar_t          hostname;
                    205: extern char                    playername[];
                    206: extern int                     playercolor;
                    207: 
                    208: extern int             messagesSent;
                    209: extern int             messagesReceived;
                    210: extern int             unreliableMessagesSent;
                    211: extern int             unreliableMessagesReceived;
                    212: 
                    213: qsocket_t *NET_NewQSocket (void);
                    214: void NET_FreeQSocket(qsocket_t *);
                    215: double SetNetTime(void);
                    216: 
                    217: 
                    218: #define HOSTCACHESIZE  8
                    219: 
                    220: typedef struct
                    221: {
                    222:        char    name[16];
                    223:        char    map[16];
                    224:        char    cname[32];
                    225:        int             users;
                    226:        int             maxusers;
                    227:        int             driver;
                    228:        int             ldriver;
                    229:        struct qsockaddr addr;
                    230: } hostcache_t;
                    231: 
                    232: extern int hostCacheCount;
                    233: extern hostcache_t hostcache[HOSTCACHESIZE];
                    234: 
                    235: #ifndef _WIN32
                    236: #ifndef htonl
                    237: extern unsigned long htonl (unsigned long hostlong);
                    238: #endif
                    239: #ifndef htons
                    240: extern unsigned short htons (unsigned short hostshort);
                    241: #endif
                    242: #ifndef ntohl
                    243: extern unsigned long ntohl (unsigned long netlong);
                    244: #endif
                    245: #ifndef ntohs
                    246: extern unsigned short ntohs (unsigned short netshort);
                    247: #endif
                    248: #endif
                    249: 
                    250: #ifdef IDGODS
                    251: qboolean IsID(struct qsockaddr *addr);
                    252: #endif
                    253: 
                    254: //============================================================================
                    255: //
                    256: // public network functions
                    257: //
                    258: //============================================================================
                    259: 
                    260: extern double          net_time;
                    261: extern sizebuf_t       net_message;
                    262: extern int                     net_activeconnections;
                    263: 
                    264: void           NET_Init (void);
                    265: void           NET_Shutdown (void);
                    266: 
                    267: struct qsocket_s       *NET_CheckNewConnections (void);
                    268: // returns a new connection number if there is one pending, else -1
                    269: 
                    270: struct qsocket_s       *NET_Connect (char *host);
                    271: // called by client to connect to a host.  Returns -1 if not able to
                    272: 
                    273: qboolean NET_CanSendMessage (qsocket_t *sock);
                    274: // Returns true or false if the given qsocket can currently accept a
                    275: // message to be transmitted.
                    276: 
                    277: int                    NET_GetMessage (struct qsocket_s *sock);
                    278: // returns data in net_message sizebuf
                    279: // returns 0 if no data is waiting
                    280: // returns 1 if a message was received
                    281: // returns 2 if an unreliable message was received
                    282: // returns -1 if the connection died
                    283: 
                    284: int                    NET_SendMessage (struct qsocket_s *sock, sizebuf_t *data);
                    285: int                    NET_SendUnreliableMessage (struct qsocket_s *sock, sizebuf_t *data);
                    286: // returns 0 if the message connot be delivered reliably, but the connection
                    287: //             is still considered valid
                    288: // returns 1 if the message was sent properly
                    289: // returns -1 if the connection died
                    290: 
                    291: int                    NET_SendToAll(sizebuf_t *data, int blocktime);
                    292: // This is a reliable *blocking* send to all attached clients.
                    293: 
                    294: 
                    295: void           NET_Close (struct qsocket_s *sock);
                    296: // if a dead connection is returned by a get or send function, this function
                    297: // should be called when it is convenient
                    298: 
                    299: // Server calls when a client is kicked off for a game related misbehavior
                    300: // like an illegal protocal conversation.  Client calls when disconnecting
                    301: // from a server.
                    302: // A netcon_t number will not be reused until this function is called for it
                    303: 
                    304: void NET_Poll(void);
                    305: 
                    306: 
                    307: typedef struct _PollProcedure
                    308: {
                    309:        struct _PollProcedure   *next;
                    310:        double                                  nextTime;
                    311:        void                                    (*procedure)();
                    312:        void                                    *arg;
                    313: } PollProcedure;
                    314: 
                    315: void SchedulePollProcedure(PollProcedure *pp, double timeOffset);
                    316: 
                    317: extern qboolean        serialAvailable;
                    318: extern qboolean        ipxAvailable;
                    319: extern qboolean        tcpipAvailable;
                    320: extern char            my_ipx_address[NET_NAMELEN];
                    321: extern char            my_tcpip_address[NET_NAMELEN];
                    322: extern void (*GetComPortConfig) (int portNumber, int *port, int *irq, int *baud, qboolean *useModem);
                    323: extern void (*SetComPortConfig) (int portNumber, int port, int irq, int baud, qboolean useModem);
                    324: extern void (*GetModemConfig) (int portNumber, char *dialType, char *clear, char *init, char *hangup);
                    325: extern void (*SetModemConfig) (int portNumber, char *dialType, char *clear, char *init, char *hangup);
                    326: 
                    327: extern qboolean        slistInProgress;
                    328: extern qboolean        slistSilent;
                    329: extern qboolean        slistLocal;
                    330: 
                    331: void NET_Slist_f (void);

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.