Skip to content

Commit

Permalink
fix servergenerated replays
Browse files Browse the repository at this point in the history
I also removed 'mp_game_title' because if i leave it, it casues an 'attributes not in order' error since level_ contains attributes. Idk what it does so i removed it. if we want it we should write in into level_
  • Loading branch information
gfgtdf committed Jun 15, 2014
1 parent f4db54b commit ac9628e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/saved_game.cpp
Expand Up @@ -81,8 +81,15 @@ saved_game::saved_game(const config& cfg)

carryover_sides = cfg.child_or_empty("carryover_sides");
carryover_sides_start = cfg.child_or_empty("carryover_sides_start");

//Serversided replays can contain multiple [replay]
replay_start_ = cfg.child_or_empty("replay_start");
replay_data = cfg.child_or_empty("replay");
replay_data = config(); //cfg.child_or_empty("replay");
BOOST_FOREACH(const config& replay, cfg.child_range("replay"))
{
replay_data.append_children(replay);
}

if(const config& snapshot = cfg.child("snapshot"))
{
this->starting_pos_type_ = STARTINGPOS_SNAPSHOT;
Expand Down
12 changes: 11 additions & 1 deletion src/server/game.cpp
Expand Up @@ -1470,11 +1470,13 @@ void game::save_replay() {
history_.clear();

std::stringstream name;
name << level_["name"] << " Turn " << current_turn();
name << (*starting_pos( level_.root()))["name"] << " Turn " << current_turn();

std::stringstream replay_data;
try {
#if 0
replay_data << "campaign_type=\"multiplayer\"\n"
//why did we save difficulcy here ? esp in scmapogn difficulacy = normal is not bguaranteed
<< "difficulty=\"NORMAL\"\n"
<< "label=\"" << name.str() << "\"\n"
<< "mp_game_title=\"" << name_ << "\"\n"
Expand All @@ -1485,7 +1487,15 @@ void game::save_replay() {
<< replay_commands
<< "[/replay]\n"
<< "[replay_start]\n" << level_.output() << "[/replay_start]\n";
#else
replay_data << level_.output()
//This can result in having 2 [replay] at toplevel since level_ can contain one already. But the client can handle this (simply merges them).
<< "[replay]\n"
<< "\t[command]\n\t\t[start]\n\t\t[/start]\n\t[/command]\n" //this is required by gfgtdf's sync mechanism, in PR 121
<< replay_commands
<< "[/replay]\n";

#endif
name << " (" << id_ << ").bz2";

std::string replay_data_str = replay_data.str();
Expand Down

0 comments on commit ac9628e

Please sign in to comment.