/* ================== SV_WriteBans_f Save bans to file. ================== */ static void SV_WriteBans(void) { int index; fileHandle_t writeto; char filepath[MAX_QPATH]; if(!sv_banFile->string || !*sv_banFile->string) return; Com_sprintf(filepath, sizeof(filepath), "%s/%s", FS_GetCurrentGameDir(), sv_banFile->string); if((writeto = FS_SV_FOpenFileWrite(filepath))) { char writebuf[128]; serverBan_t *curban; for(index = 0; index < serverBansCount; index++) { curban = &serverBans[index]; Com_sprintf(writebuf, sizeof(writebuf), "%d %s %d\n", curban->isexception, NET_AdrToString(curban->ip), curban->subnet); FS_Write(writebuf, strlen(writebuf), writeto); } FS_FCloseFile(writeto); } }
static size_t Curl_WriteCallback_f(void *ptr, size_t size, size_t nmemb, void *stream) { if (!f) { char dir[MAX_OSPATH]; char dirt[MAX_OSPATH]; char *c; // make sure Content-Type is either "application/octet-stream" or "application/zip". if (curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &c) != CURLE_OK || !c || (Q_stricmp(c, "application/octet-stream") && Q_stricmp(c, "application/zip"))) { Q_strncpyz(dl_error, "No pk3 returned - requested map is probably unknown.", sizeof(dl_error)); return 0; } // make sure the path doesn't have directory information. for (c=path; *c; c++) { if (*c == '\\' || *c == '/' || *c == ':') { Com_sprintf(dl_error, sizeof(dl_error), "Destination filename \"%s\" is not valid.", path); return 0; } } // make sure the file has an appropriate extension. c = path +strlen(path) -4; if (c <= path || strcmp(c, ".pk3")) { Com_sprintf(dl_error, sizeof(dl_error), "Returned file \"%s\" has wrong extension.", path); return 0; } // make out the directory in which to place the file Q_strncpyz(dir, (dl_usebaseq3->integer)?"baseq3":FS_GetCurrentGameDir(), sizeof(dir)); if (strlen(path) +strlen(dir) +1 >= sizeof(path)) { Com_sprintf(dl_error, sizeof(dl_error), "Returned filename is too large."); return 0; } Com_sprintf(dirt, sizeof(dirt), "%s/%s", dir, path); strcpy(path,dirt); // in case of a name collision, just fail - leave it to the user to sort out. if (FS_FileExists(path)) { Com_sprintf(dl_error, sizeof(dl_error), "Failed to download \"%s\", a pk3 by that name exists locally.", path); return 0; } // change the extension to .tmp - it will be changed back once the download is complete. c = path +strlen(path) -4; strcpy(c, ".tmp"); // FS should write the file in the appropriate gamedir and catch unsanitary paths. f = FS_SV_FOpenFileWrite(path); if (!f) { Com_sprintf(dl_error, sizeof(dl_error), "Failed to open \"%s\" for writing.\n", path); return 0; } Com_Printf("Writing to: %s\n", path); } return FS_Write(ptr, size*nmemb, f); }
/* ================ SV_Status_f ================ */ static void SV_Status_f( void ) { client_t *cl; // make sure server is running if ( !com_sv_running->integer ) { Com_Printf( "Server is not running.\n" ); return; } cl = &svs.clients[0]; if ( !cl ) { Com_Printf("Server is not running.\n"); return; } #if defined(_WIN32) #define STATUS_OS "Windows" #elif defined(__linux__) #define STATUS_OS "Linux" #elif defined(MACOS_X) #define STATUS_OS "OSX" #else #define STATUS_OS "Unknown" #endif Com_Printf( "name : %s^7\n", cl->name ); Com_Printf( "score : %i\n", cl->gentity->client->persistant[PERS_SCORE] ); Com_Printf( "version : %s %s %i\n", STATUS_OS, VERSION_STRING_DOTTED, PROTOCOL_VERSION ); #ifdef JK2_MODE Com_Printf( "game : Jedi Outcast %s\n", FS_GetCurrentGameDir() ); #else Com_Printf( "game : Jedi Academy %s\n", FS_GetCurrentGameDir() ); #endif Com_Printf( "map : %s at %s\n", sv_mapname->string, ivtos( cl->gentity->client->origin ) ); }
/* ================= Sys_Exit Single exit point (regular exit or in case of error) ================= */ static __attribute__ ((noreturn)) void Sys_Exit( int exitCode ) { CON_Shutdown( ); #ifndef DEDICATED SDL_Quit( ); #endif if( exitCode < 2 && com_fullyInitialized ) { // Normal exit Sys_RemovePIDFile( FS_GetCurrentGameDir() ); } NET_Shutdown( ); Sys_PlatformExit( ); exit( exitCode ); }
/* ================ SV_Status_f ================ */ static void SV_Status_f( void ) { int i, humans, bots; client_t *cl; playerState_t *ps; const char *s; int ping; char state[32]; qboolean avoidTruncation = qfalse; // make sure server is running if ( !com_sv_running->integer ) { //Ensiform: Why raven why, you didn't do this in other cmds. Com_Printf( "Server is not running.\n" ); //Com_Printf( SE_GetString("STR_SERVER_SERVER_NOT_RUNNING") ); return; } if ( Cmd_Argc() > 1 ) { if (!Q_stricmp("notrunc", Cmd_Argv(1))) { avoidTruncation = qtrue; } } humans = bots = 0; for ( i = 0 ; i < sv_maxclients->integer ; i++ ) { if ( svs.clients[i].state >= CS_CONNECTED ) { if ( svs.clients[i].netchan.remoteAddress.type != NA_BOT ) { humans++; } else { bots++; } } } #if defined(_WIN32) #define STATUS_OS "Windows" #elif defined(__linux__) #define STATUS_OS "Linux" #elif defined(MACOS_X) #define STATUS_OS "OSX" #else #define STATUS_OS "Unknown" #endif const char *ded_table[] = { "listen", "lan dedicated", "public dedicated", }; Com_Printf ("hostname: %s\n", sv_hostname->string ); Com_Printf ("version : %s %i\n", VERSION_STRING_DOTTED, PROTOCOL_VERSION ); Com_Printf ("game : %s\n", FS_GetCurrentGameDir() ); Com_Printf ("udp/ip : %s:%i os(%s) type(%s)\n", Cvar_VariableString("net_ip"), Cvar_VariableIntegerValue("net_port"), STATUS_OS, ded_table[com_dedicated->integer]); Com_Printf ("map : %s gametype(%i)\n", sv_mapname->string, sv_gametype->integer ); Com_Printf ("players : %i humans, %i bots (%i max)\n", humans, bots, sv_maxclients->integer - sv_privateClients->integer); Com_Printf ("num score ping name lastmsg address qport rate\n"); Com_Printf ("--- ----- ---- --------------- ------- --------------------- ----- -----\n"); for (i=0,cl=svs.clients ; i < sv_maxclients->integer ; i++,cl++) { if (!cl->state) { continue; } if (cl->state == CS_CONNECTED) { strcpy(state, "CNCT "); } else if (cl->state == CS_ZOMBIE) { strcpy(state, "ZMBI "); } else { ping = cl->ping < 9999 ? cl->ping : 9999; Com_sprintf(state, sizeof(state), "%4i", ping); } ps = SV_GameClientNum( i ); s = NET_AdrToString( cl->netchan.remoteAddress ); if (!avoidTruncation) { Com_Printf ("%3i %5i %s %-15.15s %7i %21s %5i %5i\n", i, ps->persistant[PERS_SCORE], state, cl->name, svs.time - cl->lastPacketTime, s, cl->netchan.qport, cl->rate ); } else { Com_Printf ("%3i %5i %s %s %7i %21s %5i %5i\n", i, ps->persistant[PERS_SCORE], state, cl->name, svs.time - cl->lastPacketTime, s, cl->netchan.qport, cl->rate ); } } Com_Printf ("\n"); }
/* ================== SV_RehashBans_f Load saved bans from file. ================== */ static void SV_RehashBans_f(void) { int index, filelen; fileHandle_t readfrom; char *textbuf, *curpos, *maskpos, *newlinepos, *endpos; char filepath[MAX_QPATH]; serverBansCount = 0; if(!sv_banFile->string || !*sv_banFile->string) return; Com_sprintf(filepath, sizeof(filepath), "%s/%s", FS_GetCurrentGameDir(), sv_banFile->string); if((filelen = FS_SV_FOpenFileRead(filepath, &readfrom)) >= 0) { if(filelen < 2) { // Don't bother if file is too short. FS_FCloseFile(readfrom); return; } curpos = textbuf = Z_Malloc(filelen); filelen = FS_Read(textbuf, filelen, readfrom); FS_FCloseFile(readfrom); endpos = textbuf + filelen; for(index = 0; index < SERVER_MAXBANS && curpos + 2 < endpos; index++) { // find the end of the address string for(maskpos = curpos + 2; maskpos < endpos && *maskpos != ' '; maskpos++); if(maskpos + 1 >= endpos) break; *maskpos = '\0'; maskpos++; // find the end of the subnet specifier for(newlinepos = maskpos; newlinepos < endpos && *newlinepos != '\n'; newlinepos++); if(newlinepos >= endpos) break; *newlinepos = '\0'; if(NET_StringToAdr(curpos + 2, &serverBans[index].ip, NA_UNSPEC)) { serverBans[index].isexception = (curpos[0] != '0'); serverBans[index].subnet = atoi(maskpos); if(serverBans[index].ip.type == NA_IP && (serverBans[index].subnet < 1 || serverBans[index].subnet > 32)) { serverBans[index].subnet = 32; } else if(serverBans[index].ip.type == NA_IP6 && (serverBans[index].subnet < 1 || serverBans[index].subnet > 128)) { serverBans[index].subnet = 128; } } curpos = newlinepos + 1; } serverBansCount = index; Z_Free(textbuf); } }
/* ================ SV_Status_f ================ */ static void SV_Status_f( void ) { int i, humans, bots; client_t *cl; playerState_t *ps; const char *s; int ping; char state[32]; qboolean avoidTruncation = qfalse; // make sure server is running if ( !com_sv_running->integer ) { Com_Printf( "Server is not running.\n" ); return; } if ( Cmd_Argc() > 1 ) { if (!Q_stricmp("notrunc", Cmd_Argv(1))) { avoidTruncation = qtrue; } } humans = bots = 0; for ( i = 0 ; i < sv_maxclients->integer ; i++ ) { if ( svs.clients[i].state >= CS_CONNECTED ) { if ( svs.clients[i].netchan.remoteAddress.type != NA_BOT ) { humans++; } else { bots++; } } } #if defined(_WIN32) #define STATUS_OS "Windows" #elif defined(__linux__) #define STATUS_OS "Linux" #elif defined(MACOS_X) #define STATUS_OS "OSX" #else #define STATUS_OS "Unknown" #endif const char *ded_table[] = { "listen", "lan dedicated", "public dedicated", }; char hostname[MAX_HOSTNAMELENGTH] = { 0 }; Q_strncpyz( hostname, sv_hostname->string, sizeof(hostname) ); Q_StripColor( hostname ); Com_Printf( "hostname: %s^7\n", hostname ); Com_Printf( "version : %s %i\n", VERSION_STRING_DOTTED, PROTOCOL_VERSION ); Com_Printf( "game : %s\n", FS_GetCurrentGameDir() ); Com_Printf( "udp/ip : %s:%i os(%s) type(%s)\n", Cvar_VariableString( "net_ip" ), Cvar_VariableIntegerValue( "net_port" ), STATUS_OS, ded_table[com_dedicated->integer] ); Com_Printf( "map : %s gametype(%i)\n", sv_mapname->string, sv_gametype->integer ); Com_Printf( "players : %i humans, %i bots (%i max)\n", humans, bots, sv_maxclients->integer - sv_privateClients->integer ); Com_Printf( "uptime : %s\n", SV_CalcUptime() ); Com_Printf ("cl score ping name address rate \n"); Com_Printf ("-- ----- ---- --------------- --------------------------------------- -----\n"); for (i=0,cl=svs.clients ; i < sv_maxclients->integer ; i++,cl++) { if ( !cl->state ) continue; if ( cl->state == CS_CONNECTED ) Q_strncpyz( state, "CON ", sizeof( state ) ); else if ( cl->state == CS_ZOMBIE ) Q_strncpyz( state, "ZMB ", sizeof( state ) ); else { ping = cl->ping < 9999 ? cl->ping : 9999; Com_sprintf( state, sizeof(state), "%4i", ping ); } ps = SV_GameClientNum( i ); s = NET_AdrToString( cl->netchan.remoteAddress ); if (!avoidTruncation) { Com_Printf ("%2i %5i %s %-15.15s ^7%39s %5i\n", i, ps->persistant[PERS_SCORE], state, cl->name, s, cl->rate ); } else { Com_Printf ("%2i %5i %s %s ^7%39s %5i\n", i, ps->persistant[PERS_SCORE], state, cl->name, s, cl->rate ); } } Com_Printf ("\n"); }