void SV_WriteLevelFile(void) { char name[MAX_OSPATH]; FILE *f; Com_DPrintf("SV_WriteLevelFile()\n"); Com_sprintf(name, sizeof(name), "%s/save/current/%s.sv2", FS_Gamedir(), sv.name); f = fopen(name, "wb"); if (!f) { Com_Printf("Failed to open %s\n", name); return; } fwrite(sv.configstrings, sizeof(sv.configstrings), 1, f); CM_WritePortalState(f); fclose(f); Com_sprintf(name, sizeof(name), "%s/save/current/%s.sav", FS_Gamedir(), sv.name); ge->WriteLevel(name); }
/* ===================== SV_WipeSavegame Delete save/<XXX>/ ===================== */ static void SV_WipeSavegame (const char *savename) { char name[MAX_OSPATH]; char *s; Com_DPrintf("SV_WipeSaveGame(%s)\n", savename); Com_sprintf (name, sizeof(name), "%s/save/%s/server.ssv", FS_Gamedir (), savename); FS_RemoveFile(name); Com_sprintf (name, sizeof(name), "%s/save/%s/game.ssv", FS_Gamedir (), savename); FS_RemoveFile(name); Com_sprintf (name, sizeof(name), "%s/save/%s/*.sav", FS_Gamedir (), savename); s = Sys_FindFirst( name, 0, 0 ); while (s) { FS_RemoveFile(s); s = Sys_FindNext( 0, 0 ); } Sys_FindClose (); Com_sprintf (name, sizeof(name), "%s/save/%s/*.sv2", FS_Gamedir (), savename); s = Sys_FindFirst(name, 0, 0 ); while (s) { FS_RemoveFile(s); s = Sys_FindNext( 0, 0 ); } Sys_FindClose (); }
int binaryWrite(char *file, char *data, int bytenum) { char tmpfile[512]; char tmpfile2[512]; FILE *fh = NULL; sprintf(tmpfile,"%s/%s.tmp2",FS_Gamedir(),file); sprintf(tmpfile2,"%s/%s",FS_Gamedir(),file); //Com_Printf("[mio] try to write %d bytes to %s..\n", bytenum, tmpfile); fh = fopen(tmpfile,"wb"); if (!fh) return 1; fwrite(data,1,bytenum,fh); fclose(fh); //CL_RestartFilesystem( false ); //Com_Printf("fetched 100 ok, rename time...\n"); //Com_Printf("rename %s to %s ..\n", tmpfile,tmpfile2); if (rename(tmpfile,tmpfile2) == 0) remove(tmpfile); return 0; }
/* ===================== SV_WipeSavegame Delete save/<XXX>/ ===================== */ void SV_WipeSavegame (char *savename) { char name[MAX_OSPATH]; char *s; Com_DPrintf("SV_WipeSaveGame(%s)\n", savename); Com_sprintf (name, sizeof(name), "%s/save/%s/server.ssv", FS_Gamedir (), savename); remove (name); Com_sprintf (name, sizeof(name), "%s/save/%s/game.ssv", FS_Gamedir (), savename); remove (name); // Knightmare- delete screenshot Com_sprintf (name, sizeof(name), "%s/save/%s/shot.png", FS_Gamedir (), savename); remove (name); Com_sprintf (name, sizeof(name), "%s/save/%s/*.sav", FS_Gamedir (), savename); s = Sys_FindFirst( name, 0, 0 ); while (s) { remove (s); s = Sys_FindNext( 0, 0 ); } Sys_FindClose (); Com_sprintf (name, sizeof(name), "%s/save/%s/*.sv2", FS_Gamedir (), savename); s = Sys_FindFirst(name, 0, 0 ); while (s) { remove (s); s = Sys_FindNext( 0, 0 ); } Sys_FindClose (); }
void CDAudio_Play2(int track, qboolean looping) { HANDLE playingThread; char filename[MAX_PATH]; struct ThreadArgList_t *tal; if (!enabled) return; if (!cdValid) { CDAudio_GetAudioDiskInfo(); if (!cdValid) return; } track = remap[track]; if (track < 1 || track > maxTrack) { Com_DPrintf("CDAudio: Bad track number %u.\n", track); return; } if (playing) { if (playTrack == track) return; CDAudio_Stop(); } tal = malloc(sizeof(struct ThreadArgList_t)); tal->playLooping = looping; tal->playTrack = track; sprintf(filename, "%s\\Track%03d.ogg", FS_Gamedir(), track); if (!OpenOGG(filename, tal)) { sprintf(filename, "%s\\Track%02d.ogg", FS_Gamedir(), track); if (!OpenOGG(filename, tal)) { Com_DPrintf("CDAudio: Cannot open Vorbis file \"%s\"", filename); return; } } playLooping = looping; playTrack = track; playing = true; // force volume update cdvolume = -1; playingThread = (HANDLE)_beginthreadex(NULL, 0, PlayingThreadProc, tal, CREATE_SUSPENDED, NULL); SetThreadPriority(playingThread, THREAD_PRIORITY_TIME_CRITICAL); ResumeThread(playingThread); }
/* ----------------------------------------------------------------------------- Function: Parameters: Returns: Notes: ----------------------------------------------------------------------------- */ PRIVATE void R_ScreenShot_f( void ) { W8 *buffer; char picname[ 80 ]; char checkname[ MAX_OSPATH ]; int i; FILE *f; // create the scrnshots directory if it doesn't exist my_snprintf( checkname, sizeof( checkname ), "%s/scrnshot", FS_Gamedir() ); FS_CreateDirectory( checkname ); // // find a file name to save it to // my_strlcpy( picname, "scrn00.tga", sizeof( picname ) ); for( i = 0 ; i <= 99 ; ++i ) { picname[ 4 ] = i / 10 + '0'; picname[ 5 ] = i % 10 + '0'; my_snprintf( checkname, sizeof( checkname ), "%s/scrnshot/%s", FS_Gamedir(), picname ); f = fopen( checkname, "rb" ); if( ! f ) { break; // file doesn't exist } fclose( f ); } if( i == 100 ) { Com_Printf( "R_ScreenShot_f: Couldn't create a file\n" ); return; } buffer = MM_MALLOC( viddef.width * viddef.height * 3 ); pfglReadPixels( 0, 0, viddef.width, viddef.height, GL_RGB, GL_UNSIGNED_BYTE, buffer ); WriteTGA( checkname, 24, viddef.width, viddef.height, buffer, 1, 1 ); MM_FREE( buffer ); Com_Printf( "Wrote %s\n", picname ); }
void SV_ReadLevelFile(void) { char name[MAX_OSPATH]; fileHandle_t f; Com_DPrintf("SV_ReadLevelFile()\n"); Com_sprintf(name, sizeof(name), "save/current/%s.sv2", sv.name); FS_FOpenFile(name, &f, FS_READ); if (!f) { Com_Printf("Failed to open %s\n", name); return; } FS_Read(sv.configstrings, sizeof(sv.configstrings), f); CM_ReadPortalState(f); FS_FCloseFile(f); Com_sprintf(name, sizeof(name), "%s/save/current/%s.sav", FS_Gamedir(), sv.name); ge->ReadLevel(name); }
/* ================== SV_GameMap_f Saves the state of the map just being exited and goes to a new map. If the initial character of the map string is '*', the next map is in a new unit, so the current savegame directory is cleared of map files. Example: *inter.cin+jail Clears the archived maps, plays the inter.cin cinematic, then goes to map jail.bsp. ================== */ void SV_GameMap_f (void) { char *map; int i; client_t *cl; qboolean *savedInuse; if (Cmd_Argc() != 2) { Com_Printf ("USAGE: gamemap <map>\n"); return; } Com_DPrintf("SV_GameMap(%s)\n", Cmd_Argv(1)); FS_CreatePath (va("%s/save/current/", FS_Gamedir())); // check for clearing the current savegame map = Cmd_Argv(1); if (map[0] == '*') { // wipe all the *.sav files SV_WipeSavegame ("current"); } else { // save the map just exited if (sv.state == ss_game) { // clear all the client inuse flags before saving so that // when the level is re-entered, the clients will spawn // at spawn points instead of occupying body shells savedInuse = malloc(maxclients->value * sizeof(qboolean)); for (i=0,cl=svs.clients ; i<maxclients->value; i++,cl++) { savedInuse[i] = cl->edict->inuse; cl->edict->inuse = false; } SV_WriteLevelFile (); // we must restore these for clients to transfer over correctly for (i=0,cl=svs.clients ; i<maxclients->value; i++,cl++) cl->edict->inuse = savedInuse[i]; free (savedInuse); } } // start up the next map SV_Map (false, Cmd_Argv(1), false ); // archive server state strncpy (svs.mapcmd, Cmd_Argv(1), sizeof(svs.mapcmd)-1); // copy off the level to the autosave slot if (!dedicated->value) { SV_WriteServerFile (true); SV_CopySaveGame ("current", "save0"); } }
/* * Writes key bindings and archived cvars to config.cfg */ void CL_WriteConfiguration(void) { FILE *f; char path[MAX_OSPATH]; if (cls.state == ca_uninitialized) { return; } Com_sprintf(path, sizeof(path), "%s/config.cfg", FS_Gamedir()); f = Q_fopen(path, "w"); if (!f) { Com_Printf("Couldn't write config.cfg.\n"); return; } fprintf(f, "// generated by quake, do not modify\n"); Key_WriteBindings(f); fflush(f); fclose(f); Cvar_WriteVariables(path); }
static void ConsoleLogfile (const char *msg) { // logfile if (logfile_active && logfile_active->value) { char name[MAX_QPATH]; if (!logfile) { // === // jit -- allow multiple console logs for servers on multiple ports. int port; port = Cvar_Get("port", va("%i", PORT_SERVER), CVAR_NOSET)->value; Com_sprintf(name, sizeof(name), "%s/qconsole%d.log", FS_Gamedir(), port); // === if (logfile_active->value > 2) logfile = fopen(name, "a"); else logfile = fopen(name, "w"); } if (logfile) fprintf(logfile, "%s", msg); if (logfile_active->value > 1) fflush(logfile); // force it to save every time } }
/* * Both client and server can use this, and it will output * to the apropriate place. */ void Com_Printf(char *fmt, ...) { va_list argptr; char msg[MAXPRINTMSG]; va_start(argptr, fmt); vsnprintf(msg, MAXPRINTMSG, fmt, argptr); va_end(argptr); if (rd_target) { if ((strlen(msg) + strlen(rd_buffer)) > (rd_buffersize - 1)) { rd_flush(rd_target, rd_buffer); *rd_buffer = 0; } strcat(rd_buffer, msg); return; } #ifndef DEDICATED_ONLY Con_Print(msg); #endif /* also echo to debugging console */ Sys_ConsoleOutput(msg); /* logfile */ if (logfile_active && logfile_active->value) { char name[MAX_QPATH]; if (!logfile) { Com_sprintf(name, sizeof(name), "%s/qconsole.log", FS_Gamedir()); if (logfile_active->value > 2) { logfile = fopen(name, "a"); } else { logfile = fopen(name, "w"); } } if (logfile) { fprintf(logfile, "%s", msg); } if (logfile_active->value > 1) { fflush(logfile); /* force it to save every time */ } } }
/* * ============== SV_Loadgame_f * * ============== */ void SV_Loadgame_f(void) { char name[MAX_OSPATH]; FILE *f; char *dir; if (Cmd_Argc() != 2) { Com_Printf("USAGE: loadgame <directory>\n"); return; } Com_Printf("Loading game...\n"); dir = Cmd_Argv(1); if (strstr(dir, "..") || strstr(dir, "/") || strstr(dir, "\\")) { Com_Printf("Bad savedir.\n"); } /* make sure the server.ssv file exists */ Com_sprintf(name, sizeof(name), "%s/save/%s/server.ssv", FS_Gamedir(), Cmd_Argv(1)); f = fopen(name, "rb"); if (!f) { Com_Printf("No such savegame: %s\n", name); return; } fclose(f); SV_CopySaveGame(Cmd_Argv(1), "current"); SV_ReadServerFile(); /* go to the map */ sv.state = ss_dead; /* don't save current level when changing */ SV_Map(false, svs.mapcmd, true); }
static void Maps_Scan( void) { int numFiles; char findname[1024]; char **list; int i; Maps_Free(); Com_sprintf(findname, sizeof(findname), "%s/maps/*.bsp", FS_Gamedir()); list = FS_ListFiles( findname, &numFiles, 0, SFF_SUBDIR | SFF_HIDDEN | SFF_SYSTEM ); if( !list ) { return; } for( i = 0; i < numFiles - 1; i++ ) { if( map_count < MAX_MENU_MAPS ) { list[i][strlen(list[i]) - 4] = 0; if (strrchr( list[i], '/' )) mapnames[map_count] = CopyString( strrchr( list[i], '/' ) + 1, TAG_MENU); else mapnames[map_count] = CopyString( list[i], TAG_MENU); map_count++; } Z_Free( list[i] ); } Z_Free( list ); }
void CL_DownloadFileName(char *dest, int destlen, char *fn) { //if (strncmp(fn, "players", 7) == 0) // Com_sprintf (dest, destlen, "%s/%s", BASEDIRNAME, fn); //else Com_sprintf (dest, destlen, "%s/%s", FS_Gamedir(), fn); }
/* ================ SV_CopySaveGame ================ */ void SV_CopySaveGame (char *src, char *dst) { char name[MAX_OSPATH], name2[MAX_OSPATH]; int l, len; char *found; Com_DPrintf("SV_CopySaveGame(%s, %s)\n", src, dst); SV_WipeSavegame (dst); // copy the savegame over Com_sprintf (name, sizeof(name), "%s/save/%s/server.ssv", FS_Gamedir(), src); Com_sprintf (name2, sizeof(name2), "%s/save/%s/server.ssv", FS_Gamedir(), dst); FS_CreatePath (name2); CopyFile (name, name2); Com_sprintf (name, sizeof(name), "%s/save/%s/game.ssv", FS_Gamedir(), src); Com_sprintf (name2, sizeof(name2), "%s/save/%s/game.ssv", FS_Gamedir(), dst); CopyFile (name, name2); // Knightmare- copy screenshot if (strcmp(dst, "kmq2save0")) // no screenshot for start of level autosaves { Com_sprintf (name, sizeof(name), "%s/save/%s/shot.jpg", FS_Gamedir(), src); Com_sprintf (name2, sizeof(name2), "%s/save/%s/shot.jpg", FS_Gamedir(), dst); CopyFile (name, name2); } Com_sprintf (name, sizeof(name), "%s/save/%s/", FS_Gamedir(), src); len = strlen(name); Com_sprintf (name, sizeof(name), "%s/save/%s/*.sav", FS_Gamedir(), src); found = Sys_FindFirst(name, 0, 0 ); while (found) { // strncpy (name+len, found+len); Q_strncpyz (name+len, found+len, sizeof(name)-len); Com_sprintf (name2, sizeof(name2), "%s/save/%s/%s", FS_Gamedir(), dst, found+len); CopyFile (name, name2); // change sav to sv2 l = strlen(name); // strncpy (name+l-3, "sv2"); Q_strncpyz (name+l-3, "sv2", sizeof(name)-l+3); l = strlen(name2); // strncpy (name2+l-3, "sv2"); Q_strncpyz (name2+l-3, "sv2", sizeof(name2)-l+3); CopyFile (name, name2); found = Sys_FindNext( 0, 0 ); } Sys_FindClose (); }
static void serverlist_save (void) { FILE *fp; char szFilename[MAX_QPATH]; if (!m_serverlist.actualsize) return; // don't write if there's no data. sprintf(szFilename, "%s/serverlist.dat", FS_Gamedir()); if ((fp = fopen(szFilename, "wb"))) { int endiantest = 123123123; register int i; short stemp; unsigned char ctemp; char *s; // Write Header: fwrite("PB2Serverlist1.00", sizeof("PB2Serverlist1.00")-1, 1, fp); fwrite(&endiantest, sizeof(int), 1, fp); // Write our data: pthread_mutex_lock(&m_mut_serverlist); // make sure no other threads are using it fwrite(&m_serverlist.actualsize, sizeof(int), 1, fp); fwrite(&m_serverlist.numservers, sizeof(int), 1, fp); fwrite(&m_serverlist.nummapped, sizeof(int), 1, fp); for (i=0; i<m_serverlist.numservers; i++) { fwrite(&m_serverlist.server[i].adr, sizeof(netadr_t), 1, fp); stemp = m_serverlist.server[i].remap; fwrite(&stemp, sizeof(short), 1, fp); s = m_serverlist.server[i].servername; fwrite(s, strlen(s)+1, 1, fp); s = m_serverlist.server[i].mapname; fwrite(s, strlen(s)+1, 1, fp); stemp = (short)m_serverlist.server[i].ping; fwrite(&stemp, sizeof(short), 1, fp); ctemp = (unsigned char)m_serverlist.server[i].players; fwrite(&ctemp, sizeof(unsigned char), 1, fp); ctemp = (unsigned char)m_serverlist.server[i].maxplayers; fwrite(&ctemp, sizeof(unsigned char), 1, fp); } for (i=0; i<m_serverlist.nummapped; i++) { s = m_serverlist.ips[i]; fwrite(s, strlen(s)+1, 1, fp); s = m_serverlist.info[i]; fwrite(s, strlen(s)+1, 1, fp); } pthread_mutex_unlock(&m_mut_serverlist); // tell other threads the serverlist is safe fclose(fp); } }
static int CDAudio_GetAudioDiskInfo(void) { int i; cdValid = false; maxTrack = 0; // CDDA track numbers are in range of 1..99 for (i=1; i<100; i++) { FILE *f; char filename[MAX_PATH]; sprintf(filename, "%s\\Track%03d.ogg", FS_Gamedir(), i); f = fopen(filename, "rb"); if (!f) { sprintf(filename, "%s\\Track%02d.ogg", FS_Gamedir(), i); f = fopen(filename, "rb"); } if (f) { maxTrack = i; remap[i] = i; fclose(f); } else { remap[i] = -1; // track 1 is allowed not to exist if (i > 1) break; } } if (maxTrack == 0) { Com_DPrintf("CDAudio: no music tracks\n"); return -1; } cdValid = true; return 0; }
/* ============== SV_ReadServerFile ============== */ void SV_ReadServerFile (void) { FILE *f; char name[MAX_OSPATH], string[128]; char comment[32]; char mapcmd[MAX_TOKEN_CHARS]; Com_DPrintf("SV_ReadServerFile()\n"); Com_sprintf (name, sizeof(name), "%s/save/current/server.ssv", FS_Gamedir()); f = fopen (name, "rb"); if (!f) { Com_Printf ("Couldn't read %s\n", name); return; } // read the comment field FS_Read (comment, sizeof(comment), f); // read the mapcmd FS_Read (mapcmd, sizeof(mapcmd), f); // read all CVAR_LATCH cvars // these will be things like coop, skill, deathmatch, etc while (1) { if (!fread (name, 1, sizeof(name), f)) break; FS_Read (string, sizeof(string), f); Com_DPrintf ("Set %s = %s\n", name, string); Cvar_ForceSet (name, string); } fclose (f); // start a new game fresh with new cvars SV_InitGame (); strcpy (svs.mapcmd, mapcmd); // read game state Com_sprintf (name, sizeof(name), "%s/save/current/game.ssv", FS_Gamedir()); ge->ReadGame (name); }
filehandle_t* FS_OpenFile( const char *filename, char* mode ) { char netpath[ MAX_OSPATH ]; filehandle_t *hFile; const char *pathBase; FILE* fd; int pos; int end; memset(netpath,0,MAX_OSPATH); pathBase = FS_Gamedir(); sprintf( netpath, "%s/%s", pathBase, filename ); //printf("Absolute path: '%s'",netpath); // high performance file mapping path, avoiding stdio fd = fopen( netpath, mode ); if ( !fd ) { printf("Could not open file'%s'\n",netpath); return NULL; } hFile = (filehandle_t*) calloc(1, sizeof( filehandle_t ) ); memset( hFile, 0, sizeof( filehandle_t ) ); pos = ftell (fd); fseek (fd, 0, SEEK_END); end = ftell (fd); fseek (fd, pos, SEEK_SET); hFile->filesize = end; //if (!strcmp("data/scenes/techDemo.scene", filename)) //{ // printf("techDemo.scene filesize = %d",hFile->filesize); //} hFile->filedata = calloc( hFile->filesize,sizeof(char) ); fread(hFile->filedata, sizeof(char),hFile->filesize, fd); hFile->ptrStart = hFile->ptrCurrent = (PW8)hFile->filedata; hFile->ptrEnd = (PW8)hFile->filedata + hFile->filesize; hFile->bLoaded = 1; //printf("Closing file: '%s'\n",netpath); fclose( fd ); return hFile; }
void loadNativePNG(texture_t* tmpTex) { ILuint texid; ILenum error ; char fullpath[256]; if (!devILinitialized) { ilInit(); Log_Printf("[DevIL] Initialized.\n"); devILinitialized = 1; } //Shmup ask texture loading via relative path, we need to append the game directory. fullpath[0] = '\0'; strcat(fullpath,FS_Gamedir()); strcat(fullpath,"/"); strcat(fullpath,tmpTex->path); ilGenImages(1, &texid); // Generation of one image name ilBindImage(texid); // Binding of image name ilLoadImage((const wchar_t*)fullpath); tmpTex->bpp = ilGetInteger(IL_IMAGE_BPP); tmpTex->width = ilGetInteger(IL_IMAGE_WIDTH) ; tmpTex->height = ilGetInteger(IL_IMAGE_HEIGHT) ; tmpTex->numMipmaps = 1; tmpTex->data = (ubyte**)calloc(1,sizeof(ubyte*)); tmpTex->data[0] = (ubyte*)calloc(tmpTex->width*tmpTex->height*tmpTex->bpp,sizeof(ubyte*)); tmpTex->dataLength = 0; error = ilGetError(); if (error != IL_NO_ERROR) { Log_Printf("Could not load texture: '%s'\n",tmpTex->path); return; } if (tmpTex->bpp == 4) { ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE); tmpTex->format = TEXTURE_GL_RGBA; } else { ilConvertImage(IL_RGB, IL_UNSIGNED_BYTE); tmpTex->format = TEXTURE_GL_RGB; } memcpy(tmpTex->data[0],(void*)ilGetData(), tmpTex->width*tmpTex->height * tmpTex->bpp); }
void SV_ReadServerFile(void) { fileHandle_t f; char name[MAX_OSPATH], string[128]; char comment[32]; char mapcmd[MAX_TOKEN_CHARS]; Com_DPrintf("SV_ReadServerFile()\n"); Com_sprintf(name, sizeof(name), "save/current/server.ssv"); FS_FOpenFile(name, &f, FS_READ); if (!f) { Com_Printf("Couldn't read %s\n", name); return; } /* read the comment field */ FS_Read(comment, sizeof(comment), f); /* read the mapcmd */ FS_Read(mapcmd, sizeof(mapcmd), f); /* read all CVAR_LATCH cvars these will be things like coop, skill, deathmatch, etc */ while (1) { char cvarname[LATCH_CVAR_SAVELENGTH] = {0}; if (!FS_FRead(cvarname, 1, sizeof(cvarname), f)) { break; } FS_Read(string, sizeof(string), f); Com_DPrintf("Set %s = %s\n", cvarname, string); Cvar_ForceSet(cvarname, string); } FS_FCloseFile(f); /* start a new game fresh with new cvars */ SV_InitGame(); strcpy(svs.mapcmd, mapcmd); /* read game state */ Com_sprintf(name, sizeof(name), "%s/save/current/game.ssv", FS_Gamedir()); ge->ReadGame(name); }
static void init(CURLM *cm, int i) { CURL *eh = curl_easy_init(); // dont redo downloads! // only start a download if it is not already marked as started! if (!cls.dlqueue[i].started) { char buf[1024]; char tmp[256]; char *priv=malloc(256); struct MemoryStruct *chunk=malloc(sizeof (struct MemoryStruct)); extern struct MemoryStruct *memPtr; memPtr=chunk; if (!chunk) Com_Printf("E: dlqueue malloc err!!!\n"); else { chunk->memory=malloc(1); chunk->size=0; snprintf(buf,sizeof(buf)-1,"%s/%s/%s", httpdirfix(cls.downloadServer), gdirfix(FS_Gamedir()), cls.dlqueue[i].url); //we got a working file handle we can hand over to curl cls.dlqueue[i].started=true; //for debug mio full webpath //Com_Printf("HTTP downloading %s ...\n ",buf); //Com_Printf("--- MULTI HTTP downloading, got %d\n", i); curl_easy_setopt(eh, CURLOPT_WRITEFUNCTION, cb); curl_easy_setopt(eh, CURLOPT_HEADER, 0L); curl_easy_setopt(eh, CURLOPT_URL, buf); strncpy(priv,cls.dlqueue[i].url,255); curl_easy_setopt(eh, CURLOPT_PRIVATE, priv); curl_easy_setopt(eh, CURLOPT_VERBOSE, 0L); curl_easy_setopt(eh, CURLOPT_USERAGENT, "quake2 curl 3.26"); //chunk is normally a FILE * but we feed it a struct function instead... //writememorycallback func takes a struct and writes it curl_easy_setopt(eh, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); curl_easy_setopt(eh, CURLOPT_WRITEDATA, chunk); //Com_Printf("HTTP DL added %s to dlqueue...\n" , buf); curl_multi_add_handle(cm, eh); } } }
/* ============== SV_WriteScreenshot ============== */ void SV_WriteScreenshot (void) { char name[MAX_OSPATH]; if (dedicated->value) // can't do this in dedicated mode return; Com_DPrintf("SV_WriteScreenshot()\n"); Com_sprintf (name, sizeof(name), "%s/save/current/shot.png", FS_Gamedir()); R_ScaledScreenshot(name); }
int FS_FOpenFile (char *filename, FILE **file) { searchpath_t *search; char netpath[MAX_OSPATH]; pack_t *pak; int i; file_from_pak = 0; // get config from directory, everything else from pak if (!strcmp(filename, "config.cfg") || !strncmp(filename, "players/", 8)) { Com_sprintf (netpath, sizeof(netpath), "%s/%s",FS_Gamedir(), filename); *file = fopen (netpath, "rb"); if (!*file) return -1; Com_DPrintf ("FindFile: %s\n",netpath); return FS_filelength (*file); } for (search = fs_searchpaths ; search ; search = search->next) if (search->pack) break; if (!search) { *file = NULL; return -1; } pak = search->pack; for (i=0 ; i<pak->numfiles ; i++) if (!Q_strcasecmp (pak->files[i].name, filename)) { // found it! file_from_pak = 1; Com_DPrintf ("PackFile: %s : %s\n",pak->filename, filename); // open a new file on the pakfile *file = fopen (pak->filename, "rb"); if (!*file) Com_Error (ERR_FATAL, "Couldn't reopen %s", pak->filename); fseek (*file, pak->files[i].filepos, SEEK_SET); return pak->files[i].filelen; } Com_DPrintf ("FindFile: can't find %s\n", filename); *file = NULL; return -1; }
void SV_CheckForSavegame ( void ) { char name [ MAX_OSPATH ]; FILE *f; int i; if ( sv_noreload->value ) { return; } if ( Cvar_VariableValue( "deathmatch" ) ) { return; } Com_sprintf( name, sizeof ( name ), "%s/save/current/%s.sav", FS_Gamedir(), sv.name ); f = fopen( name, "rb" ); if ( !f ) { return; /* no savegame */ } fclose( f ); SV_ClearWorld(); /* get configstrings and areaportals */ SV_ReadLevelFile(); if ( !sv.loadgame ) { /* coming back to a level after being in a different level, so run it for ten seconds */ server_state_t previousState; previousState = sv.state; sv.state = ss_loading; for ( i = 0; i < 100; i++ ) { ge->RunFrame(); } sv.state = previousState; } }
/* * ================= SV_CheckForSavegame ================= */ void SV_CheckForSavegame(void) { char name[MAX_OSPATH]; FILE *f; int i; if (sv_noreload->value) return; if (Cvar_VariableValue("deathmatch")) return; Com_sprintf(name, sizeof(name), "%s/save/current/%s.sav", FS_Gamedir(), sv.name); f = fopen(name, "rb"); if (!f) return; /* no savegame */ fclose(f); SV_ClearWorld(); /* get configstrings and areaportals */ SV_ReadLevelFile(); if (!sv.loadgame) { /* coming back to a level after being in a * different */ /* level, so run it for ten seconds */ /* * rlava2 was sending too many lightstyles, and overflowing * the */ /* * reliable data. temporarily changing the server state to * loading */ /* prevents these from being passed down. */ server_state_t previousState; /* PGM */ previousState = sv.state; /* PGM */ sv.state = ss_loading; /* PGM */ for (i = 0; i < 100; i++) ge->RunFrame(); sv.state = previousState; /* PGM */ } }
/* * ================= * SV_CheckForSavegame * ================= */ void SV_CheckForSavegame(void) { char name[MAX_OSPATH]; FILE *f; int i; if (sv_noreload->value) { return; } if (Cvar_VariableValue("deathmatch")) { return; } Com_sprintf(name, sizeof(name), "%s/save/current/%s.sav", FS_Gamedir(), sv.name); f = fopen(name, "rb"); if (!f) { return; // no savegame } fclose(f); SV_ClearWorld(); // get configstrings and areaportals SV_ReadLevelFile(); if (!sv.loadgame) { // coming back to a level after being in a different // level, so run it for ten seconds // rlava2 was sending too many lightstyles, and overflowing the // reliable data. temporarily changing the server state to loading // prevents these from being passed down. server_state_t previousState; // PGM previousState = sv.state; // PGM sv.state = ss_loading; // PGM for (i = 0; i < 100; i++) { ge->RunFrame(); } sv.state = previousState; // PGM } }
/* ============ FS_ExistsInGameDir See if a file exists in the mod directory/paks (ignores baseq2) ============ */ qboolean FS_ExistsInGameDir (char *filename) { size_t len; char *gamedir; char lowered[MAX_QPATH]; searchpath_t *search; pack_t *pak; Q_strncpy (lowered, filename, sizeof(lowered)-1); fast_strlwr (lowered); gamedir = FS_Gamedir(); len = strlen(gamedir); for (search = fs_searchpaths ; search ; search = search->next) { // is the element a pak file? if (search->pack) { packfile_t *entry; //r1: optimized btree search pak = search->pack; if (strncmp (pak->filename, gamedir, len)) continue; entry = rbfind (lowered, pak->rb); if (entry) return true; } else { char netpath[MAX_OSPATH]; if (strncmp (search->filename, gamedir, len)) continue; Com_sprintf (netpath, sizeof(netpath), "%s/%s",search->filename, filename); if (Sys_FileLength (netpath) != -1) return true; } } return false; }
static bool IsFemaleModel(const char *model) { static TString<32> LastGameDir; const char *gameDir = FS_Gamedir(); if (gameDir != LastGameDir) { LastGameDir = gameDir; ReadModelsGenderList(); } for (int i = 0; i < numFemaleModels; i++) if (!stricmp(femaleModels[i], model)) return true; return false; }
/** * @note Both client and server can use this, and it will * do the appropriate things. */ void Com_Error (int code, const char* fmt, ...) { va_list argptr; static char msg[MAXPRINTMSG]; static bool recursive = false; if (recursive) Sys_Error("recursive error after: %s", msg); recursive = true; va_start(argptr, fmt); Q_vsnprintf(msg, sizeof(msg), fmt, argptr); va_end(argptr); switch (code) { case ERR_DISCONNECT: Com_Printf("%s\n", msg); CL_Drop(); recursive = false; Com_Drop(); case ERR_DROP: Com_Printf("********************\n"); Com_Printf("ERROR: %s\n", msg); Com_Printf("********************\n"); Sys_Backtrace(); SV_Shutdown("Server crashed.", false); CL_Drop(); recursive = false; Com_Drop(); default: Com_Printf("%s\n", msg); SV_Shutdown("Server fatal crashed", false); /* send an receive net messages a last time */ NET_Wait(0); FS_CloseFile(&logfile); if (pipefile.f != nullptr) { FS_CloseFile(&pipefile); FS_RemoveFile(va("%s/%s", FS_Gamedir(), pipefile.name)); } CL_Shutdown(); Qcommon_Shutdown(); Sys_Error("Shutdown"); } }