server.h

Go to the documentation of this file.
00001 
00006 /*
00007 All original material Copyright (C) 2002-2010 UFO: Alien Invasion.
00008 
00009 Original file from Quake 2 v3.21: quake2-2.31/server/server.h
00010 Copyright (C) 1997-2001 Id Software, Inc.
00011 
00012 This program is free software; you can redistribute it and/or
00013 modify it under the terms of the GNU General Public License
00014 as published by the Free Software Foundation; either version 2
00015 of the License, or (at your option) any later version.
00016 
00017 This program is distributed in the hope that it will be useful,
00018 but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00020 
00021 See the GNU General Public License for more details.
00022 
00023 You should have received a copy of the GNU General Public License
00024 along with this program; if not, write to the Free Software
00025 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00026 
00027 */
00028 
00029 #ifndef SERVER_SERVER_H
00030 #define SERVER_SERVER_H
00031 
00032 #include "../common/common.h"
00033 #include "../shared/infostring.h"
00034 #include "../game/game.h"
00035 #include <SDL_thread.h>
00036 
00037 extern memPool_t *sv_genericPool;
00038 
00039 typedef struct sv_edict_s {
00040     struct worldSector_s *worldSector;  
00041     struct sv_edict_s *nextEntityInWorldSector;
00042     qboolean linked;        
00043     edict_t *ent;
00044 } sv_edict_t;
00045 
00047 typedef struct sv_model_s {
00048     vec3_t mins, maxs;  
00049     int frame;          
00050     char *name;         
00051 } sv_model_t;
00052 
00057 typedef struct worldSector_s {
00058     int axis;                   
00059     float dist;
00060     struct worldSector_s *children[2];
00061     sv_edict_t *entities;
00062 } worldSector_t;
00063 
00064 #define AREA_NODES  32
00065 
00066 typedef struct pending_event_s {
00068     qboolean pending;
00070     int playerMask;
00071     int type;
00072     struct dbuffer *buf;
00073 } pending_event_t;
00074 
00075 typedef struct {
00076     qboolean initialized;       
00077     int realtime;               
00078     struct datagram_socket *netDatagramSocket;
00079     struct client_s *clients;           
00080     int lastHeartbeat;          
00082     qboolean abandon;       
00083     qboolean killserver;        
00084     SDL_mutex *serverMutex;
00085     SDL_Thread *gameThread;
00086     void *gameLibrary;
00087     game_export_t *ge;
00088 } serverInstanceStatic_t;
00089 
00090 typedef enum {
00091     ss_dead,                    
00092     ss_restart,                 
00093     ss_loading,                 
00094     ss_game                     
00095 } server_state_t;
00096 
00100 typedef struct {
00101     server_state_t state;       
00103     char name[MAX_QPATH];       
00104     char assembly[MAX_QPATH];       
00105     struct cBspModel_s *models[MAX_MODELS];
00106 
00107     qboolean endgame;
00108     qboolean started;           
00110     char configstrings[MAX_CONFIGSTRINGS][MAX_TOKEN_CHARS];
00111 
00112     struct dbuffer *messageBuffer;
00113     pending_event_t pendingEvent;
00114 
00115     mapData_t mapData;
00116 
00117     mapTiles_t mapTiles;
00118 
00119     sv_model_t svModels[MAX_MOD_KNOWN];
00120     unsigned int numSVModels;
00121     sv_edict_t edicts[MAX_EDICTS];
00122     worldSector_t worldSectors[AREA_NODES];
00123     unsigned int numWorldSectors;
00124 
00125     memPool_t *gameSysPool; 
00126 } serverInstanceGame_t;
00127 
00128 #define EDICT_NUM(n) ((edict_t *)((byte *)svs.ge->edicts + svs.ge->edict_size * (n)))
00129 #define NUM_FOR_EDICT(e) (((byte *)(e) - (byte *)svs.ge->edicts) / svs.ge->edict_size)
00130 
00131 #define PLAYER_NUM(n) ((player_t *)((byte *)svs.ge->players + svs.ge->player_size * (n)))
00132 #define NUM_FOR_PLAYER(e) (((byte *)(e) - (byte *)svs.ge->players) / svs.ge->player_size)
00133 
00134 typedef enum {
00135     cs_free,                    
00136     cs_connected,               
00137     cs_spawning,                
00138     cs_began,                   
00140     cs_spawned                  
00141 } client_state_t;
00142 
00150 typedef struct client_s {
00151     client_state_t state;
00152     char userinfo[MAX_INFO_STRING];
00153     player_t *player;           
00154     char name[32];              
00155     int messagelevel;           
00156     int lastconnect;
00157     char peername[256];
00158     struct net_stream *stream;
00159 } client_t;
00160 
00161 extern serverInstanceStatic_t svs;      
00162 extern serverInstanceGame_t sv;         
00164 extern cvar_t *sv_mapname;
00165 extern cvar_t *sv_public;           
00166 extern cvar_t *sv_dumpmapassembly;
00167 extern cvar_t *sv_threads;  
00169 /* sv_main.c */
00170 void SV_DropClient(client_t *drop, const char *message);
00171 int SV_CountPlayers(void);
00172 void SV_InitOperatorCommands(void);
00173 void SV_UserinfoChanged(client_t *cl);
00174 void SV_ReadPacket(struct net_stream *s);
00175 char *SV_GetConfigString(int index);
00176 int SV_GetConfigStringInteger(int index);
00177 char *SV_SetConfigString(int index, ...);
00178 /* ensure that always two parameters are used */
00179 #define SV_SetConfigString(index, value) SV_SetConfigString(index, value)
00180 client_t* SV_GetNextClient(client_t *lastClient);
00181 client_t *SV_GetClient(int index);
00182 
00183 /* sv_mapcycle.c */
00184 void SV_MapcycleInit(void);
00185 void SV_NextMapcycle(void);
00186 void SV_MapcycleClear(void);
00187 
00188 /* sv_init.c */
00189 void SV_Map(qboolean day, const char *levelstring, const char *assembly);
00190 
00191 void SV_Multicast(int mask, struct dbuffer *msg);
00192 void SV_StartSound(int mask, const vec3_t origin, const edict_t *entity, const char* sound);
00193 void SV_ClientCommand(client_t *client, const char *fmt, ...) __attribute__((format(printf,2,3)));
00194 void SV_ClientPrintf(client_t * cl, int level, const char *fmt, ...) __attribute__((format(printf,3,4)));
00195 void SV_BroadcastPrintf(int level, const char *fmt, ...) __attribute__((format(printf,2,3)));
00196 
00197 /* sv_user.c */
00198 void SV_ExecuteClientMessage(client_t * cl, int cmd, struct dbuffer *msg);
00199 void SV_SetClientState(client_t* client, int state);
00200 
00201 /* sv_ccmds.c */
00202 void SV_SetMaster_f(void);
00203 void SV_Heartbeat_f(void);
00204 qboolean SV_CheckMap(const char *map, const char *assembly);
00205 
00206 /* sv_game.c */
00207 int SV_RunGameFrameThread(void *data);
00208 void SV_RunGameFrame(void);
00209 void SV_InitGameProgs(void);
00210 void SV_ShutdownGameProgs(void);
00211 
00212 /*============================================================ */
00213 
00214 void SV_ClearWorld(void);
00215 
00216 void SV_UnlinkEdict(edict_t * ent);
00217 void SV_LinkEdict(edict_t * ent);
00218 int SV_AreaEdicts(const vec3_t mins, const vec3_t maxs, edict_t ** list, int maxcount);
00219 int SV_TouchEdicts(const vec3_t mins, const vec3_t maxs, edict_t **list, int maxCount, edict_t *skip);
00220 
00221 /*=================================================================== */
00222 
00223 /* returns the CONTENTS_* value from the world at the given point. */
00224 int SV_PointContents(vec3_t p);
00225 const char *SV_GetFootstepSound(const char *texture);
00226 float SV_GetBounceFraction(const char *texture);
00227 qboolean SV_LoadModelMinsMaxs(const char *model, int frame, vec3_t mins, vec3_t maxs);
00228 trace_t SV_Trace(const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, const edict_t * passedict, int contentmask);
00229 
00230 #endif /* SERVER_SERVER_H */

Generated by  doxygen 1.6.2