void ClientReliableWrite_ZLib(client_t *cl, void *data, int len) { int i; char out[MAX_QWMSGLEN*2]; short *written = (short *)((char *)cl->netchan.message.data + cl->netchan.message.cursize); z_stream strm = { data, len, 0, NULL,//out, sizeof(out), 0, NULL, NULL, NULL, NULL, NULL, Z_BINARY, 0, 0 }; i=0; strm.next_out = out; deflateInit(&strm, Z_BEST_COMPRESSION); while(deflate(&strm, Z_FINISH) == Z_OK) { Sys_Error("Couldn't compile well\n"); // ClientReliableWrite_SZ(cl, out, sizeof(out) - strm.avail_out); //compress in chunks of 8192. Saves having to allocate a huge-mega-big buffer // i+=sizeof(out) - strm.avail_out; // strm.next_out = out; // strm.avail_out = sizeof(out); } if (strm.total_out > len) { ClientReliableWrite_Short(cl, 0); ClientReliableWrite_SZ(cl, data, len); } else { ClientReliableWrite_Short(cl, strm.total_out); ClientReliableWrite_SZ(cl, out, sizeof(out) - strm.avail_out); } i+=sizeof(out) - strm.avail_out; deflateEnd(&strm); // return i; }
void SV_NextDownload_f (void) { byte buffer[1024]; int r; int percent; int size; if (!host_client->download) return; r = host_client->downloadsize - host_client->downloadcount; if (r > 768) r = 768; r = fread (buffer, 1, r, host_client->download); ClientReliableWrite_Begin (host_client, svc_download, 6+r); ClientReliableWrite_Short (host_client, r); host_client->downloadcount += r; size = host_client->downloadsize; if (!size) size = 1; percent = host_client->downloadcount*100/size; ClientReliableWrite_Byte (host_client, percent); ClientReliableWrite_SZ (host_client, buffer, r); if (host_client->downloadcount != host_client->downloadsize) return; fclose (host_client->download); host_client->download = NULL; }
void SV_Pings_f (void) { client_t *client; int j; for (j = 0, client = svs.clients; j < MAX_CLIENTS; j++, client++) { if (client->state != cs_spawned) continue; ClientReliableWrite_Begin (host_client, svc_updateping, 4); ClientReliableWrite_Byte (host_client, j); ClientReliableWrite_Short (host_client, SV_CalcPing(client)); ClientReliableWrite_Begin (host_client, svc_updatepl, 4); ClientReliableWrite_Byte (host_client, j); ClientReliableWrite_Byte (host_client, client->lossage); } }
void SV_BeginDownload_f(void) { char *name; extern cvar_t allow_download; extern cvar_t allow_download_skins; extern cvar_t allow_download_models; extern cvar_t allow_download_sounds; extern cvar_t allow_download_maps; extern int file_from_pak; // ZOID did file come from pak? name = Cmd_Argv(1); // hacked by zoid to allow more conrol over download // first off, no .. or global allow check if (strstr (name, "..") || !allow_download.value // leading dot is no good || *name == '.' // leading slash bad as well, must be in subdir || *name == '/' // next up, skin check || (strncmp(name, "skins/", 6) == 0 && !allow_download_skins.value) // now models || (strncmp(name, "progs/", 6) == 0 && !allow_download_models.value) // now sounds || (strncmp(name, "sound/", 6) == 0 && !allow_download_sounds.value) // now maps (note special case for maps, must not be in pak) || (strncmp(name, "maps/", 6) == 0 && !allow_download_maps.value) // MUST be in a subdirectory || !strstr (name, "/") ) { // don't allow anything with .. path ClientReliableWrite_Begin (host_client, svc_download, 4); ClientReliableWrite_Short (host_client, -1); ClientReliableWrite_Byte (host_client, 0); return; } if (host_client->download) { fclose (host_client->download); host_client->download = NULL; } // lowercase name (needed for casesen file systems) { char *p; for (p = name; *p; p++) *p = (char)tolower(*p); } host_client->downloadsize = COM_FOpenFile (name, &host_client->download); host_client->downloadcount = 0; if (!host_client->download // special check for maps, if it came from a pak file, don't allow // download ZOID || (strncmp(name, "maps/", 5) == 0 && file_from_pak)) { if (host_client->download) { fclose(host_client->download); host_client->download = NULL; } Sys_Printf ("Couldn't download %s to %s\n", name, host_client->name); ClientReliableWrite_Begin (host_client, svc_download, 4); ClientReliableWrite_Short (host_client, -1); ClientReliableWrite_Byte (host_client, 0); return; } SV_NextDownload_f (); Sys_Printf ("Downloading %s to %s\n", name, host_client->name); }