keypad: save code hashed, so that they can't be read off in editor mode

stable-8
Maikel de Vries 2018-02-25 11:31:39 +01:00
parent 3e0ed99c83
commit 66f52a4097
1 changed files with 21 additions and 8 deletions

View File

@ -12,7 +12,7 @@ static const KEYPADMENU_BackgroundColor = 0x77000000;
static const KEYPADMENU_HoverColor = 0x99888888; static const KEYPADMENU_HoverColor = 0x99888888;
static const KEYPADMENU_BarColor = 0x99888888; static const KEYPADMENU_BarColor = 0x99888888;
local code, correct_code; local code, correct_code, correct_code_hashed;
local correct_code_action, wrong_code_action; local correct_code_action, wrong_code_action;
local replacement_images; local replacement_images;
local menu, menu_id, menu_target, menu_controller; local menu, menu_id, menu_target, menu_controller;
@ -40,6 +40,12 @@ public func SetKeypadCode(string to_code)
return; return;
} }
public func SetKeypadHashedCode(string to_code)
{
correct_code_hashed = to_code;
return;
}
public func GiveAccess(object clonk) public func GiveAccess(object clonk)
{ {
SetSwitchState(true, clonk); SetSwitchState(true, clonk);
@ -115,10 +121,17 @@ private func UpdateKeypadGraphics()
public func SaveScenarioObject(proplist props) public func SaveScenarioObject(proplist props)
{ {
if (!_inherited(props, ...)) return false; if (!_inherited(props, ...))
if (correct_code) props->AddCall("Code", this, "SetKeypadCode", Format("%v", correct_code)); return false;
if (correct_code_action || wrong_code_action) props->AddCall("Action", this, "SetCodeActions", correct_code_action, wrong_code_action); // Store the hashed code, but override if the scenario designer changed the code.
if (replacement_images) props->AddCall("Replacements", this, "SetReplacementImages", replacement_images); if (correct_code)
props->AddCall("Code", this, "SetKeypadHashedCode", Format("%v", Crypto->ComputeHash(correct_code)));
else if (correct_code_hashed)
props->AddCall("Code", this, "SetKeypadHashedCode", Format("%v", correct_code_hashed));
if (correct_code_action || wrong_code_action)
props->AddCall("Action", this, "SetCodeActions", correct_code_action, wrong_code_action);
if (replacement_images)
props->AddCall("Replacements", this, "SetReplacementImages", replacement_images);
return true; return true;
} }
@ -358,13 +371,13 @@ public func EnterKeypadCode()
} }
else else
{ {
if (correct_code == nil) if (correct_code == nil && correct_code_hashed == nil)
{ {
code = nil; code = nil;
menu.code.value.Text = "$MsgNoCode$"; menu.code.value.Text = "$MsgNoCode$";
Sound("UI::Error", {player = menu_controller->GetOwner()}); Sound("UI::Error", {player = menu_controller->GetOwner()});
} }
else if (correct_code == code) else if (correct_code == code || correct_code_hashed == Crypto->ComputeHash(code))
{ {
code = nil; code = nil;
Sound("UI::Confirmed", {player = menu_controller->GetOwner()}); Sound("UI::Confirmed", {player = menu_controller->GetOwner()});
@ -398,7 +411,7 @@ public func EnterKeypadCode()
public func ResetKeypadCode() public func ResetKeypadCode()
{ {
// Only allow resetting the code if the clonk (menu_target) has entered the correct code before. // Only allow resetting the code if the clonk (menu_target) has entered the correct code before.
if (correct_code == nil) if (correct_code == nil && correct_code_hashed == nil)
{ {
menu_controller.code_reset_state = "reset"; menu_controller.code_reset_state = "reset";
menu.code.text.Text = "$MsgEnterNewCode$"; menu.code.text.Text = "$MsgEnterNewCode$";