1
// $Id: demo_recorder.cxx,v 1.16 2003/04/04 11:23:27 grumbel Exp $
3
// Pingus - A free Lemmings clone
4
// Copyright (C) 2000 Ingo Ruhnke <grumbel@gmx.de>
6
// This program is free software; you can redistribute it and/or
7
// modify it under the terms of the GNU General Public License
8
// as published by the Free Software Foundation; either version 2
9
// of the License, or (at your option) any later version.
11
// This program is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
// GNU General Public License for more details.
16
// You should have received a copy of the GNU General Public License
17
// along with this program; if not, write to the Free Software
18
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
#include "demo_recorder.hxx"
26
#include "my_gettext.hxx"
28
DemoRecorder::DemoRecorder (Server* server)
31
std::string levelname = server->get_plf()->get_resname();
32
std::string flat_levelname = levelname;
34
// 'Flatten' the levelname so that we don't need directories
35
for (std::string::iterator i = flat_levelname.begin(); i != flat_levelname.end(); ++i)
39
if (!levelname.empty())
41
std::string filename = System::get_statdir() + "demos/" + flat_levelname + "-" + get_date() + ".xml";
42
out.open(filename.c_str());
47
std::cout << "DemoRecorder: Error: Couldn't write DemoFile '" << filename
48
<< "', demo recording will be disabled" << std::endl;
52
std::cout << "DemoRecorder: Writing demo to: " << filename << std::endl;
56
out << "<pingus-demo>\n"
57
<< " <level>" << levelname << "</level>\n"
58
<< " <events>" << std::endl;
64
// This point should only be reachable if we have a bug
65
// somewhere or provide a way to get a PLF without using XMLPLF,
66
// since we don't do that, a bug must be somewhere when we reach
68
assert(!"ERROR: DemoRecorder: Couldn't get levelname, please report this as a bug!");
72
DemoRecorder::~DemoRecorder ()
78
<< "</pingus-demo>" << std::endl;
84
DemoRecorder::record_event (const ServerEvent& event)
89
//event.write_xml(std::cout);
94
DemoRecorder::get_date ()
99
curtime = time (NULL);
100
loctime = localtime(&curtime);
101
strftime(buffer, 32, "%Y%m%d-%H%M%S", loctime);
103
return std::string(buffer);