//========= Copyright Valve Corporation, All rights reserved. ============// // // Purpose: Implemenation of CTFStatsReport // // $Workfile: $ // $Date: $ // //------------------------------------------------------------------------------------------------------ // $Log: $ // // $NoKeywords: $ //=============================================================================// #include #include #include "TFStatsReport.h" #include "LogEvent.h" #include "ScoreBoard.h" #include "WhoKilledWho.h" #include "memdbg.h" #include "awards.h" #include "MatchResults.h" #include "DialogueReadout.h" #include "cvars.h" #include "html.h" #include "TextFile.h" #include "CustomAward.h" #include "PlayerSpecifics.h" #include "util.h" //------------------------------------------------------------------------------------------------------ // Function: CTFStatsReport::CTFStatsReport // Purpose: CTFStatsReport Constructor // Input: pLogFile - the list of events we'll be reporting on //------------------------------------------------------------------------------------------------------ CTFStatsReport::CTFStatsReport() { init(); generate(); } void CTFStatsReport::genJavaScript() { errno=0; string jsname(g_pApp->supportDirectory); jsname+=g_pApp->os->pathSeperator(); jsname+="support.js"; FILE* f=fopen( jsname.c_str(),"wt"); if (!f) g_pApp->fatalError("Can't open output file \"%s\"! (reason: %s)\nPlease make sure that the file does not exist OR\nif the file does exit, make sure it is not read-only",jsname.c_str(),strerror(errno)); else fprintf(f,javaScriptSource); fclose(f); #ifndef WIN32 chmod( jsname.c_str(),PERMIT); #endif } void CTFStatsReport::genStyleSheet() { errno=0; string cssname(g_pApp->supportDirectory); cssname+=g_pApp->os->pathSeperator(); cssname+="style.css"; FILE* f=fopen(cssname.c_str(),"wt"); if (!f) g_pApp->fatalError("Can't open output file \"%s\"! (reason: %s)\nPlease make sure that the file does not exist OR\nif the file does exit, make sure it is not read-only",cssname.c_str(),strerror(errno)); else fprintf(f,styleSheetSource); fclose(f); #ifndef WIN32 chmod(cssname.c_str(),PERMIT); #endif } void CTFStatsReport::genAllPlayersStyleSheet() { errno=0; string cssname(g_pApp->playerDirectory.c_str()); cssname+=g_pApp->os->pathSeperator(); cssname+="support"; cssname+=g_pApp->os->pathSeperator(); cssname+="style.css"; FILE* f=fopen(cssname.c_str(),"wt"); if (!f) g_pApp->fatalError("Can't open output file \"%s\"! (reason: %s)\nPlease make sure that the file does not exist OR\nif the file does exit, make sure it is not read-only",cssname.c_str(),strerror(errno)); else fprintf(f,styleSheetSource); fclose(f); #ifndef WIN32 chmod(cssname.c_str(),PERMIT); #endif } void CTFStatsReport::genIndex() { CHTMLFile html("index.html","TF Match Report"); html.write("\n"); CHTMLFile html2("index2.html","TF Match Report",CHTMLFile::dontPrintBody); html2.write("\n"); html2.write("\n"); html2.write("\n"); html2.write("\n"); html2.write("\n"); html2.write(""); html2.write(""); } #include void CTFStatsReport::genImages() { int chresult=g_pApp->os->chdir(g_pApp->supportDirectory.c_str()); gifAwards.writeOut(); jpgBgLeft.writeOut(); jpgBgTop.writeOut(); gifBoxScore.writeOut(); gifGameDialogOff.writeOut(); gifGameDialogOn.writeOut(); gifMatchStatsOff.writeOut(); gifMatchStatsOn.writeOut(); gifScores.writeOut(); gifServerSettingsOff.writeOut(); gifServerSettingsOn.writeOut(); gifDetailedScores.writeOut(); gifPlayerStatsMatchOff.writeOut(); gifPlayerStatsMatchOn.writeOut(); gifPlayerStatsServerOff.writeOut(); gifPlayerStatsServerOn.writeOut(); chresult=g_pApp->os->chdir(g_pApp->outputDirectory.c_str()); } void CTFStatsReport::genTopFrame() { CHTMLFile html("top.html","top",CHTMLFile::printBody,NULL,0,0); html.write("\n",g_pApp->supportHTTPPath.c_str()); html.write("\t\n"); html.write("\t\t\n"); html.write("\t\n"); html.write("
\n"); html.write("\t\t
\n"); html.write("\t\t%s Match Report\n",g_pMatchInfo->getServerName().c_str()); html.write("\t\t
\n"); html.write("\t\t
\n"); if(g_pMatchInfo->mapName()!="") html.write("\t\tmap: %s ",g_pMatchInfo->mapName().c_str()); char buf[1000]; html.write(" %s\n",Util::makeDurationString(matchstart,matchend,buf)); html.write("\t\t
\n"); html.write("\t\t
\n"); } inline void writeEventHandlers(CHTMLFile& html, char* id) { html.write(" OnClick=\" clearAll(); %sImgLink.on(); return true; \" ",id,id); //html.write(" OnMouseDown=\"imageOn('%s');return true;\" ",id); html.write(" OnMouseOver=\" window.status='%s'; %sImgLink.over();return true; \" ",id,id); html.write(" OnMouseOut=\" window.status=' ';%sImgLink.out();return true; \" ",id,id); } void CTFStatsReport::genNavFrame() { string imgname(g_pApp->supportHTTPPath); imgname+="/bgleft.jpg"; CHTMLFile html("nav.html","top",CHTMLFile::printBody,imgname.c_str(),0,0); string jshttppath(g_pApp->supportHTTPPath); jshttppath+="/support.js"; html.write("\n",jshttppath.c_str()); html.write("\n"); html.write("\n"); html.write("\t\n"); html.write("\t\t\n"); html.write("\t\n"); html.write("
\n"); html.write("\t\t\t\n"); html.write("\t\t
\n"); html.write("\n"); } CTFStatsReport::~CTFStatsReport() { } void CTFStatsReport::init() { matchstart=0; matchend=0; matchhours=0; matchminutes=0; matchseconds=0; } /* const char* CTFStatsReport::makeDurationString() { //TODO: //handle case where start and end dates are not the same day tm* pstart=localtime(&matchstart); if (!pstart) { sprintf(DurationString,""); return DurationString; } int sday=pstart->tm_mday; int sweekday=pstart->tm_wday; int smo=pstart->tm_mon; int syear=pstart->tm_year+1900; int shour=pstart->tm_hour; if (pstart->tm_isdst) shour=(shour+23)%24; //this substracts 1 while accounting for backing up past 0 int smin=pstart->tm_min; tm* pend=localtime(&matchend); if (!pend) pend=pstart; int ehour=pend->tm_hour; int emin=pend->tm_min; if (pend->tm_isdst) ehour=(ehour+23)%24; //this substracts 1 while accounting for backing up past 0 char* matchtz=NULL; matchtz=g_pApp->os->gettzname()[0]; sprintf(DurationString,"%02li:%02li - %02li:%02li %s, %s %s %li%s %li",shour,smin,ehour,emin,matchtz, Util::daysofWeek[sweekday],Util::Months[smo],sday,(sday%10)<4?Util::numberSuffixes[sday%10]:"th",syear); return DurationString; }*/ void CTFStatsReport::generate() { if (g_pMatchInfo->eventList()->empty()) { matchstart=0; matchend=0; } else { matchstart=(*(g_pMatchInfo->eventList()->begin()))->getTime(); CEventListIterator it=g_pMatchInfo->eventList()->end(); --it; matchend=(*it)->getTime(); } time_t matchtime=matchend-matchstart; tm* pmatchtime=gmtime(&matchtime); matchhours=pmatchtime->tm_hour; matchminutes=pmatchtime->tm_min; matchseconds=pmatchtime->tm_sec; }