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; }