Annotation of quake2/server/server.h, revision 1.1.1.3

1.1       root        1: // server.h
                      2: 
                      3: 
                      4: //define       PARANOID                        // speed sapping error checking
                      5: 
                      6: #include "../qcommon/qcommon.h"
                      7: #include "../game/game.h"
                      8: 
                      9: //=============================================================================
                     10: 
                     11: #define        MAX_MASTERS     8                               // max recipients for heartbeat packets
                     12: 
                     13: typedef enum {
                     14:        ss_dead,                        // no map loaded
                     15:        ss_loading,                     // spawning level edicts
                     16:        ss_game,                        // actively running
                     17:        ss_cinematic,
                     18:        ss_demo,
                     19:        ss_pic
                     20: } server_state_t;
                     21: // some qc commands are only valid before the server has finished
                     22: // initializing (precache commands, static sounds / objects, etc)
                     23: 
                     24: typedef struct
                     25: {
                     26:        server_state_t  state;                  // precache commands are only valid during load
                     27: 
                     28:        qboolean        attractloop;            // running cinematics and demos for the local system only
                     29:        qboolean        loadgame;                       // client begins should reuse existing entity
                     30: 
1.1.1.2   root       31:        unsigned        time;                           // always sv.framenum * 100 msec
1.1       root       32:        int                     framenum;
                     33: 
                     34:        char            name[MAX_QPATH];                        // map name, or cinematic name
                     35:        struct cmodel_s         *models[MAX_MODELS];
                     36: 
                     37:        char            configstrings[MAX_CONFIGSTRINGS][MAX_QPATH];
                     38:        entity_state_t  baselines[MAX_EDICTS];
                     39: 
                     40:        // the multicast buffer is used to send a message to a set of clients
                     41:        // it is only used to marshall data until SV_Multicast is called
                     42:        sizebuf_t       multicast;
                     43:        byte            multicast_buf[MAX_MSGLEN];
                     44: 
                     45:        // demo server information
                     46:        FILE            *demofile;
                     47:        qboolean        timedemo;               // don't time sync
                     48: } server_t;
                     49: 
                     50: #define EDICT_NUM(n) ((edict_t *)((byte *)ge->edicts + ge->edict_size*(n)))
                     51: #define NUM_FOR_EDICT(e) ( ((byte *)(e)-(byte *)ge->edicts ) / ge->edict_size)
                     52: 
                     53: 
                     54: typedef enum
                     55: {
                     56:        cs_free,                // can be reused for a new connection
                     57:        cs_zombie,              // client has been disconnected, but don't reuse
                     58:                                        // connection for a couple seconds
                     59:        cs_connected,   // has been assigned to a client_t, but not in game yet
                     60:        cs_spawned              // client is fully in game
                     61: } client_state_t;
                     62: 
                     63: typedef struct
                     64: {
                     65:        int                                     areabytes;
                     66:        byte                            areabits[MAX_MAP_AREAS/8];              // portalarea visibility bits
                     67:        player_state_t          ps;
                     68:        int                                     num_entities;
                     69:        int                                     first_entity;           // into the circular sv_packet_entities[]
1.1.1.2   root       70:        int                                     senttime;                       // for ping calculations
1.1       root       71: } client_frame_t;
                     72: 
                     73: #define        LATENCY_COUNTS  16
                     74: #define        RATE_MESSAGES   10
                     75: 
                     76: typedef struct client_s
                     77: {
                     78:        client_state_t  state;
                     79: 
                     80:        char                    userinfo[MAX_INFO_STRING];              // name, etc
                     81: 
                     82:        int                             lastframe;                      // for delta compression
                     83:        usercmd_t               lastcmd;                        // for filling in big drops
                     84: 
                     85:        int                             commandMsec;            // every seconds this is reset, if user
                     86:                                                                                // commands exhaust it, assume time cheating
                     87: 
                     88:        int                             frame_latency[LATENCY_COUNTS];
                     89:        int                             ping;
                     90: 
                     91:        int                             message_size[RATE_MESSAGES];    // used to rate drop packets
                     92:        int                             rate;
                     93:        int                             surpressCount;          // number of messages rate supressed
                     94: 
                     95:        edict_t                 *edict;                         // EDICT_NUM(clientnum+1)
                     96:        char                    name[32];                       // extracted from userinfo, high bits masked
                     97:        int                             messagelevel;           // for filtering printed messages
                     98: 
                     99:        // The datagram is written to by sound calls, prints, temp ents, etc.
                    100:        // It can be harmlessly overflowed.
                    101:        sizebuf_t               datagram;
                    102:        byte                    datagram_buf[MAX_MSGLEN];
                    103: 
                    104:        client_frame_t  frames[UPDATE_BACKUP];  // updates can be delta'd from here
                    105: 
                    106:        byte                    *download;                      // file being downloaded
                    107:        int                             downloadsize;           // total bytes (can't use EOF because of paks)
                    108:        int                             downloadcount;          // bytes sent
                    109: 
                    110:        int                             lastmessage;            // sv.framenum when packet was last received
                    111:        int                             lastconnect;
                    112: 
1.1.1.2   root      113:        int                             challenge;                      // challenge of this user, randomly generated
                    114: 
1.1       root      115:        netchan_t               netchan;
                    116: } client_t;
                    117: 
                    118: // a client can leave the server in one of four ways:
                    119: // dropping properly by quiting or disconnecting
                    120: // timing out if no valid messages are received for timeout.value seconds
                    121: // getting kicked off by the server operator
                    122: // a program error, like an overflowed reliable buffer
                    123: 
                    124: //=============================================================================
                    125: 
                    126: // MAX_CHALLENGES is made large to prevent a denial
                    127: // of service attack that could cycle all of them
                    128: // out before legitimate users connected
                    129: #define        MAX_CHALLENGES  1024
                    130: 
                    131: typedef struct
                    132: {
                    133:        netadr_t        adr;
                    134:        int                     challenge;
                    135:        int                     time;
                    136: } challenge_t;
                    137: 
                    138: 
                    139: typedef struct
                    140: {
                    141:        qboolean        initialized;                            // sv_init has completed
1.1.1.2   root      142:        int                     realtime;                                       // always increasing, no clamping, etc
1.1       root      143: 
                    144:        char            mapcmd[MAX_TOKEN_CHARS];        // ie: *intro.cin+base 
                    145: 
                    146:        int                     spawncount;                                     // incremented each server start
                    147:                                                                                        // used to check late spawns
                    148: 
                    149:        client_t        *clients;                                       // [maxclients->value];
                    150:        int                     num_client_entities;            // maxclients->value*UPDATE_BACKUP*MAX_PACKET_ENTITIES
                    151:        int                     next_client_entities;           // next client_entity to use
                    152:        entity_state_t  *client_entities;               // [num_client_entities]
                    153: 
                    154:        int                     last_heartbeat;
                    155: 
                    156:        challenge_t     challenges[MAX_CHALLENGES];     // to prevent invalid IPs from connecting
                    157: 
                    158:        // serverrecord values
                    159:        FILE            *demofile;
                    160:        sizebuf_t       demo_multicast;
                    161:        byte            demo_multicast_buf[MAX_MSGLEN];
                    162: } server_static_t;
                    163: 
                    164: //=============================================================================
                    165: 
                    166: extern netadr_t        net_from;
                    167: extern sizebuf_t       net_message;
                    168: 
                    169: extern netadr_t        master_adr[MAX_MASTERS];        // address of the master server
                    170: 
                    171: extern server_static_t svs;                            // persistant server info
                    172: extern server_t                sv;                                     // local server
                    173: 
                    174: extern cvar_t          *sv_paused;
                    175: extern cvar_t          *maxclients;
                    176: extern cvar_t          *sv_noreload;                   // don't reload level state when reentering
1.1.1.3 ! root      177: extern cvar_t          *sv_airaccelerate;              // don't reload level state when reentering
1.1       root      178:                                                                                        // development tool
                    179: extern cvar_t          *sv_enforcetime;
                    180: 
                    181: extern client_t        *sv_client;
                    182: extern edict_t         *sv_player;
                    183: 
                    184: //===========================================================
                    185: 
                    186: //
                    187: // sv_main.c
                    188: //
                    189: void SV_FinalMessage (char *message, qboolean reconnect);
                    190: void SV_DropClient (client_t *drop);
                    191: 
                    192: int SV_ModelIndex (char *name);
                    193: int SV_SoundIndex (char *name);
                    194: int SV_ImageIndex (char *name);
                    195: 
                    196: void SV_WriteClientdataToMessage (client_t *client, sizebuf_t *msg);
                    197: 
                    198: void SV_ExecuteUserCommand (char *s);
                    199: void SV_InitOperatorCommands (void);
                    200: 
                    201: void SV_SendServerinfo (client_t *client);
                    202: void SV_UserinfoChanged (client_t *cl);
                    203: 
                    204: 
                    205: void Master_Heartbeat (void);
                    206: void Master_Packet (void);
                    207: 
                    208: //
                    209: // sv_init.c
                    210: //
                    211: void SV_InitGame (void);
                    212: void SV_Map (qboolean attractloop, char *levelstring, qboolean loadgame);
                    213: 
                    214: 
                    215: //
                    216: // sv_phys.c
                    217: //
                    218: void SV_PrepWorldFrame (void);
                    219: 
                    220: //
                    221: // sv_send.c
                    222: //
                    223: typedef enum {RD_NONE, RD_CLIENT, RD_PACKET} redirect_t;
                    224: #define        SV_OUTPUTBUF_LENGTH     (MAX_MSGLEN - 16)
                    225: 
                    226: extern char    sv_outputbuf[SV_OUTPUTBUF_LENGTH];
                    227: 
                    228: void SV_FlushRedirect (int sv_redirected, char *outputbuf);
                    229: 
                    230: void SV_DemoCompleted (void);
                    231: void SV_SendClientMessages (void);
                    232: 
                    233: void SV_Multicast (vec3_t origin, multicast_t to);
                    234: void SV_StartSound (vec3_t origin, edict_t *entity, int channel,
                    235:                                        int soundindex, float volume,
                    236:                                        float attenuation, float timeofs);
                    237: void SV_ClientPrintf (client_t *cl, int level, char *fmt, ...);
                    238: void SV_BroadcastPrintf (int level, char *fmt, ...);
                    239: void SV_BroadcastCommand (char *fmt, ...);
                    240: 
                    241: //
                    242: // sv_user.c
                    243: //
                    244: void SV_Nextserver (void);
                    245: void SV_ExecuteClientMessage (client_t *cl);
                    246: 
                    247: //
                    248: // sv_ccmds.c
                    249: //
                    250: void SV_ReadLevelFile (void);
                    251: void SV_Status_f (void);
                    252: 
                    253: //
                    254: // sv_ents.c
                    255: //
                    256: void SV_WriteFrameToClient (client_t *client, sizebuf_t *msg);
                    257: void SV_RecordDemoMessage (void);
                    258: void SV_BuildClientFrame (client_t *client);
                    259: 
                    260: 
                    261: void SV_Error (char *error, ...);
                    262: 
                    263: //
                    264: // sv_game.c
                    265: //
                    266: extern game_export_t   *ge;
                    267: 
                    268: void SV_InitGameProgs (void);
                    269: void SV_ShutdownGameProgs (void);
                    270: void SV_InitEdict (edict_t *e);
                    271: 
                    272: 
                    273: 
                    274: //============================================================
                    275: 
                    276: //
                    277: // high level object sorting to reduce interaction tests
                    278: //
                    279: 
                    280: void SV_ClearWorld (void);
                    281: // called after the world model has been loaded, before linking any entities
                    282: 
                    283: void SV_UnlinkEdict (edict_t *ent);
                    284: // call before removing an entity, and before trying to move one,
                    285: // so it doesn't clip against itself
                    286: 
                    287: void SV_LinkEdict (edict_t *ent);
                    288: // Needs to be called any time an entity changes origin, mins, maxs,
                    289: // or solid.  Automatically unlinks if needed.
                    290: // sets ent->v.absmin and ent->v.absmax
                    291: // sets ent->leafnums[] for pvs determination even if the entity
                    292: // is not solid
                    293: 
                    294: int SV_AreaEdicts (vec3_t mins, vec3_t maxs, edict_t **list, int maxcount, int areatype);
                    295: // fills in a table of edict pointers with edicts that have bounding boxes
                    296: // that intersect the given area.  It is possible for a non-axial bmodel
                    297: // to be returned that doesn't actually intersect the area on an exact
                    298: // test.
                    299: // returns the number of pointers filled in
1.1.1.2   root      300: // ??? does this always return the world?
1.1       root      301: 
                    302: //===================================================================
                    303: 
                    304: //
                    305: // functions that interact with everything apropriate
                    306: //
                    307: int SV_PointContents (vec3_t p);
                    308: // returns the CONTENTS_* value from the world at the given point.
                    309: // Quake 2 extends this to also check entities, to allow moving liquids
                    310: 
                    311: 
                    312: trace_t SV_Trace (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, edict_t *passedict, int contentmask);
                    313: // mins and maxs are relative
                    314: 
                    315: // if the entire move stays in a solid volume, trace.allsolid will be set,
                    316: // trace.startsolid will be set, and trace.fraction will be 0
                    317: 
                    318: // if the starting point is in a solid, it will be allowed to move out
                    319: // to an open area
                    320: 
                    321: // passedict is explicitly excluded from clipping checks (normally NULL)
                    322: 

unix.superglobalmegacorp.com

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