check is_replay on [set_global_variable] and [do_command]

adds a new method is_replay() to check whether we are in a replay.
fixes http://gna.org/bugs/?21906
Also also we make [do_command]/run_in_synced_context_if_not_already more
robust by checking is_replay
This commit is contained in:
gfgtdf 2015-01-06 23:47:39 +01:00
parent d71d39ec7a
commit 88de21a5ff
4 changed files with 13 additions and 3 deletions

View file

@ -1139,7 +1139,7 @@ WML_HANDLER_FUNCTION(role, /*event_info*/, cfg)
/// @todo Finish experimenting.
WML_HANDLER_FUNCTION(set_global_variable,/**/,pcfg)
{
if (get_replay_source().at_end() || (network::nconnections() != 0))
if (!resources::controller->is_replay())
verify_and_set_global_variable(pcfg);
}

View file

@ -195,7 +195,7 @@ public:
bool is_lingering() { return linger_; }
class hotkey_handler;
virtual bool is_replay() { return false; }
protected:
game_display& get_display();

View file

@ -16,6 +16,7 @@
#ifndef REPLAY_CONTROLLER_H_INCLUDED
#define REPLAY_CONTROLLER_H_INCLUDED
#include "global.hpp"
#include "game_end_exceptions.hpp"
#include "saved_game.hpp"
#include "play_controller.hpp"
@ -54,7 +55,8 @@ public:
bool recorder_at_end();
class hotkey_handler;
virtual bool is_replay() OVERRIDE { return true; }
protected:
virtual void init_gui();

View file

@ -103,10 +103,18 @@ bool synced_context::run_in_synced_context_if_not_already(const std::string& com
switch(synced_context::get_synced_state())
{
case(synced_context::UNSYNCED):
{
if(resources::controller->is_replay())
{
ERR_REPLAY << "ignored attempt to invoke a synced command during replay\n";
}
return run_in_synced_context(commandname, data, use_undo, show, true, error_handler);
}
case(synced_context::LOCAL_CHOICE):
ERR_REPLAY << "trying to execute action while being in a local_choice" << std::endl;
//we reject it because such actions usually change the gamestate badly which is not intented during a local_choice.
//Also we cannot invoke synced commands here, becasue multiple clients might run local choices
//simultaniously so it could result in invoking different synced commands simultaniously.
return false;
case(synced_context::SYNCED):
{