| 76514d10 |
sago007 |
2016-06-05 20:25 |
1 |
/* |
| 76514d10 |
sago007 |
2016-06-05 20:25 |
2 |
=========================================================================== |
| 76514d10 |
sago007 |
2016-06-05 20:25 |
3 |
blockattack - Block Attack - Rise of the Blocks |
| 76514d10 |
sago007 |
2016-06-05 20:25 |
4 |
Copyright (C) 2005-2016 Poul Sander |
| 76514d10 |
sago007 |
2016-06-05 20:25 |
5 |
|
| 76514d10 |
sago007 |
2016-06-05 20:25 |
6 |
This program is free software: you can redistribute it and/or modify |
| 76514d10 |
sago007 |
2016-06-05 20:25 |
7 |
it under the terms of the GNU General Public License as published by |
| 76514d10 |
sago007 |
2016-06-05 20:25 |
8 |
the Free Software Foundation, either version 2 of the License, or |
| 76514d10 |
sago007 |
2016-06-05 20:25 |
9 |
(at your option) any later version. |
| 76514d10 |
sago007 |
2016-06-05 20:25 |
10 |
|
| 76514d10 |
sago007 |
2016-06-05 20:25 |
11 |
This program is distributed in the hope that it will be useful, |
| 76514d10 |
sago007 |
2016-06-05 20:25 |
12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 76514d10 |
sago007 |
2016-06-05 20:25 |
13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 76514d10 |
sago007 |
2016-06-05 20:25 |
14 |
GNU General Public License for more details. |
| 76514d10 |
sago007 |
2016-06-05 20:25 |
15 |
|
| 76514d10 |
sago007 |
2016-06-05 20:25 |
16 |
You should have received a copy of the GNU General Public License |
| 76514d10 |
sago007 |
2016-06-05 20:25 |
17 |
along with this program. If not, see http://www.gnu.org/licenses/ |
| 76514d10 |
sago007 |
2016-06-05 20:25 |
18 |
|
| 76514d10 |
sago007 |
2016-06-05 20:25 |
19 |
Source information and contacts persons can be found at |
| 76514d10 |
sago007 |
2016-06-05 20:25 |
20 |
http://www.blockattack.net |
| 76514d10 |
sago007 |
2016-06-05 20:25 |
21 |
=========================================================================== |
| 76514d10 |
sago007 |
2016-06-05 20:25 |
22 |
*/ |
| 76514d10 |
sago007 |
2016-06-05 20:25 |
23 |
|
| 76514d10 |
sago007 |
2016-06-05 20:25 |
24 |
#include "replayhandler.hpp" |
| 76514d10 |
sago007 |
2016-06-05 20:25 |
25 |
#include <sstream> |
| 76514d10 |
sago007 |
2016-06-05 20:25 |
26 |
#include "cereal/archives/json.hpp" |
| 76514d10 |
sago007 |
2016-06-05 20:25 |
27 |
#include "sago/SagoMisc.hpp" |
| 76514d10 |
sago007 |
2016-06-05 20:25 |
28 |
|
| 4d05e984 |
sago007 |
2016-06-07 22:02 |
29 |
static std::tm GetLocalTime() { |
| 4d05e984 |
sago007 |
2016-06-07 22:02 |
30 |
std::time_t t = std::time(nullptr); |
| 4d05e984 |
sago007 |
2016-06-07 22:02 |
31 |
std::tm ret = *std::localtime(&t); |
| 4d05e984 |
sago007 |
2016-06-07 22:02 |
32 |
return ret; |
| 4d05e984 |
sago007 |
2016-06-07 22:02 |
33 |
} |
| 4d05e984 |
sago007 |
2016-06-07 22:02 |
34 |
|
| 4d05e984 |
sago007 |
2016-06-07 22:02 |
35 |
static std::string CreateFileName(const std::tm& t ) { |
| 4d05e984 |
sago007 |
2016-06-07 22:02 |
36 |
std::string ret = "replays/blockattack_game_"; |
| 4d05e984 |
sago007 |
2016-06-07 22:02 |
37 |
char buffer[200]; |
| 4d05e984 |
sago007 |
2016-06-07 22:02 |
38 |
snprintf(buffer, sizeof(buffer), "replays/blockattack_game_%i-%02i-%02iT%02i_%02i_%02i_AUTO.replay", t.tm_year+1900, t.tm_mon+1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec); |
| 4d05e984 |
sago007 |
2016-06-07 22:02 |
39 |
ret = buffer; |
| 4d05e984 |
sago007 |
2016-06-07 22:02 |
40 |
return ret; |
| 4d05e984 |
sago007 |
2016-06-07 22:02 |
41 |
} |
| 4d05e984 |
sago007 |
2016-06-07 22:02 |
42 |
|
| 4d05e984 |
sago007 |
2016-06-07 22:02 |
43 |
static void SaveReplayToFile(const SavedReplayStruct& sr, const std::string& filename) { |
| 76514d10 |
sago007 |
2016-06-05 20:25 |
44 |
std::stringstream ss; |
| 76514d10 |
sago007 |
2016-06-05 20:25 |
45 |
{ |
| 76514d10 |
sago007 |
2016-06-05 20:25 |
46 |
cereal::JSONOutputArchive archive(ss,cereal::JSONOutputArchive::Options::NoIndent()); |
| 76514d10 |
sago007 |
2016-06-05 20:25 |
47 |
archive(cereal::make_nvp("savedReplay", sr)); |
| 76514d10 |
sago007 |
2016-06-05 20:25 |
48 |
} |
| 4d05e984 |
sago007 |
2016-06-07 22:02 |
49 |
sago::WriteFileContent(filename.c_str(), ss.str()); |
| 76514d10 |
sago007 |
2016-06-05 20:25 |
50 |
} |
| 76514d10 |
sago007 |
2016-06-05 20:25 |
51 |
|
| 76514d10 |
sago007 |
2016-06-05 20:25 |
52 |
void SaveReplay(const BlockGameInfo& game1) { |
| 76514d10 |
sago007 |
2016-06-05 20:25 |
53 |
SavedReplayStruct sr; |
| 76514d10 |
sago007 |
2016-06-05 20:25 |
54 |
sr.numberOfPlayers = 1; |
| 76514d10 |
sago007 |
2016-06-05 20:25 |
55 |
sr.playerInfo.push_back(game1); |
| 4d05e984 |
sago007 |
2016-06-07 22:02 |
56 |
std::tm t = GetLocalTime(); |
| 4d05e984 |
sago007 |
2016-06-07 22:02 |
57 |
std::string filename = CreateFileName(t); |
| 4d05e984 |
sago007 |
2016-06-07 22:02 |
58 |
SaveReplayToFile(sr, filename); |
| 76514d10 |
sago007 |
2016-06-05 20:25 |
59 |
} |
| 76514d10 |
sago007 |
2016-06-05 20:25 |
60 |
|
| 76514d10 |
sago007 |
2016-06-05 20:25 |
61 |
void SaveReplay(const BlockGameInfo& game1, const BlockGameInfo& game2) { |
| 76514d10 |
sago007 |
2016-06-05 20:25 |
62 |
SavedReplayStruct sr; |
| 76514d10 |
sago007 |
2016-06-05 20:25 |
63 |
sr.numberOfPlayers = 2; |
| 76514d10 |
sago007 |
2016-06-05 20:25 |
64 |
sr.playerInfo.push_back(game1); |
| 76514d10 |
sago007 |
2016-06-05 20:25 |
65 |
sr.playerInfo.push_back(game2); |
| 4d05e984 |
sago007 |
2016-06-07 22:02 |
66 |
std::tm t = GetLocalTime(); |
| 4d05e984 |
sago007 |
2016-06-07 22:02 |
67 |
std::string filename = CreateFileName(t); |
| 4d05e984 |
sago007 |
2016-06-07 22:02 |
68 |
SaveReplayToFile(sr, filename); |
| 76514d10 |
sago007 |
2016-06-05 20:25 |
69 |
} |