From 300740dd4c9632f3d407eeafcaaf907cc0f15a98 Mon Sep 17 00:00:00 2001 From: ac_stef Date: Mon, 15 Sep 2008 21:31:07 +0000 Subject: [PATCH] demo description git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@2639 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/protos.h | 2 ++ source/src/server.cpp | 20 ++++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/source/src/protos.h b/source/src/protos.h index b71f8537..3695ad05 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -650,10 +650,12 @@ struct masterserver extern masterserver localmasterserver; // demo +#define DHDR_DESCCHARS 80 struct demoheader { char magic[16]; int version, protocol; + char desc[DHDR_DESCCHARS]; }; // logging diff --git a/source/src/server.cpp b/source/src/server.cpp index cdd7079c..5fc19ff8 100644 --- a/source/src/server.cpp +++ b/source/src/server.cpp @@ -590,6 +590,15 @@ void recordpacket(int chan, void *data, int len) if(recordpackets) writedemo(chan, data, len); } +char *asctime() +{ + time_t t = time(NULL); + char *timestr = ctime(&t); + char *trim = timestr + strlen(timestr); + while(trim>timestr && isspace(*--trim)) *trim = '\0'; + return timestr; +} + void enddemorecord() { if(!demorecord) return; @@ -612,10 +621,7 @@ void enddemorecord() demos.remove(0); } demofile &d = demos.add(); - time_t t = time(NULL); - char *timestr = ctime(&t), *trim = timestr + strlen(timestr); - while(trim>timestr && isspace(*--trim)) *trim = '\0'; - s_sprintf(d.info)("%s: %s, %s, %.2f%s", timestr, modestr(gamemode), smapname, len > 1024*1024 ? len/(1024*1024.f) : len/1024.0f, len > 1024*1024 ? "MB" : "kB"); + s_sprintf(d.info)("%s: %s, %s, %.2f%s", asctime(), modestr(gamemode), smapname, len > 1024*1024 ? len/(1024*1024.f) : len/1024.0f, len > 1024*1024 ? "MB" : "kB"); s_sprintfd(msg)("Demo \"%s\" recorded\nPress F10 to download it from the server..", d.info); sendservmsg(msg); d.data = new uchar[len]; @@ -657,6 +663,12 @@ void setupdemorecord() hdr.protocol = PROTOCOL_VERSION; endianswap(&hdr.version, sizeof(int), 1); endianswap(&hdr.protocol, sizeof(int), 1); + memset(hdr.desc, 0, DHDR_DESCCHARS); + s_sprintfd(desc)("%s, %s, %s %s", modestr(gamemode, false), behindpath(smapname), asctime(), servdesc_full); + if(strlen(desc > DHDR_DESCCHARS) + s_sprintfd(desc)("%s, %s, %s %s", modestr(gamemode, true), behindpath(smapname), asctime(), servdesc_full); + desc[DHDR_DESCCHARS - 1] = '\0'; + strcpy(hdr.desc, desc); gzwrite(demorecord, &hdr, sizeof(demoheader)); uchar buf[MAXTRANS];