Skip to content

Commit

Permalink
show the oos savegame dialog when receiving a debug command in mp
Browse files Browse the repository at this point in the history
with a different text of course.

fixes #2683

(cherry-picked from commit 7621af9)
  • Loading branch information
gfgtdf authored and Vultraz committed Oct 7, 2018
1 parent 0b6e877 commit 1e0c357
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/play_controller.hpp
Expand Up @@ -266,13 +266,17 @@ class play_controller : public controller_base, public events::observer, public
virtual void send_to_wesnothd(const config&, const std::string& = "unknown") const { }
virtual bool receive_from_wesnothd(config&) const { return false; }
void show_objectives() const;
protected:

struct scoped_savegame_snapshot
{
scoped_savegame_snapshot(const play_controller& controller);
~scoped_savegame_snapshot();
const play_controller& controller_;
};

saved_game& get_saved_game() { return saved_game_; }

protected:
friend struct scoped_savegame_snapshot;
void play_slice_catch();
bool have_keyboard_focus() override;
Expand Down
24 changes: 19 additions & 5 deletions src/synced_commands.cpp
Expand Up @@ -32,6 +32,7 @@
#include "units/helper.hpp"
#include "recall_list_manager.hpp"
#include "resources.hpp"
#include "savegame.hpp"
#include "scripting/game_lua_kernel.hpp"
#include "formula/string_utils.hpp"
#include "units/types.hpp"
Expand Down Expand Up @@ -389,11 +390,24 @@ namespace
{
void debug_notification(const char* message)
{
utils::string_map symbols;
symbols["player"] = resources::controller->current_team().current_player();
display::announce_options announce_options;
announce_options.lifetime = 250;
display::get_singleton()->announce(VGETTEXT(message, symbols), font::NORMAL_COLOR, announce_options);
auto& controller = *resources::controller;
auto& current_team = controller.current_team();
static bool ignore = false;
bool show_long_message = controller.is_replay() || !current_team.is_local();

if(show_long_message && !ignore) {
play_controller::scoped_savegame_snapshot snapshot(controller);
std::stringstream sbuilder;
// TODO: improve message and mark translatable.
sbuilder << "The game detected the use of a debug command, maybe another player is cheating";
sbuilder << "\n\n" << "details:" << "\n\n" << VGETTEXT(message, {{"player", current_team.current_player()}});
savegame::oos_savegame save(controller.get_saved_game(), ignore);
save.save_game_interactive(sbuilder.str(), savegame::savegame::YES_NO); // can throw quit_game_exception
}
else {
display::announce_options announce_options;
display::get_singleton()->announce(VGETTEXT(message, {{"player", current_team.current_player()}}), font::NORMAL_COLOR, announce_options);
}
}
}
SYNCED_COMMAND_HANDLER_FUNCTION(debug_unit, child, use_undo, /*show*/, /*error_handler*/)
Expand Down

0 comments on commit 1e0c357

Please sign in to comment.