Mask write to configs from certain scripts

This commit is contained in:
yvt 2015-01-24 12:44:57 +09:00
parent 66627a4de2
commit 7072e15b63
7 changed files with 153 additions and 12 deletions

View File

@ -733,6 +733,7 @@
E844888517D26411005105D0 /* OpenSpades.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OpenSpades.h; sourceTree = SOURCE_ROOT; };
E844888617D26699005105D0 /* libcurl.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libcurl.dylib; path = usr/lib/libcurl.dylib; sourceTree = SDKROOT; };
E844888B17D3A059005105D0 /* CMakeLists.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CMakeLists.txt; sourceTree = "<group>"; };
E8493DB61A7349030055731A /* Config.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Config.h; sourceTree = "<group>"; };
E849654B18E9487300B9706D /* FltkPreferenceImporter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FltkPreferenceImporter.cpp; sourceTree = "<group>"; };
E849654C18E9487300B9706D /* FltkPreferenceImporter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FltkPreferenceImporter.h; sourceTree = "<group>"; };
E849654E18E94F1200B9706D /* SdlFileStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SdlFileStream.cpp; sourceTree = "<group>"; };
@ -1649,6 +1650,7 @@
E8F74CF0183FBB070085AA54 /* MainScreenHelper.cpp */,
E842888F18A3D6470060743D /* StartupScreenHelper.cpp */,
E8F74CF31840D4CC0085AA54 /* Config.cpp */,
E8493DB61A7349030055731A /* Config.h */,
E8F74CFC1845C8D50085AA54 /* ClientUIHelper.cpp */,
E8F74CFE184C753F0085AA54 /* Clipboard.cpp */,
);

View File

@ -161,16 +161,41 @@ namespace spades {
base->SetColorAlphaPremultiplied(col);
}
void DrawImage(IImage *, const Vector2& outTopLeft)
{ OnProhibitedAction(); }
void DrawImage(IImage *, const AABB2& outRect)
{ OnProhibitedAction(); }
void DrawImage(IImage *, const Vector2& outTopLeft, const AABB2& inRect)
{ OnProhibitedAction(); }
void DrawImage(IImage *, const AABB2& outRect, const AABB2& inRect)
{ OnProhibitedAction(); }
void DrawImage(IImage *, const Vector2& outTopLeft, const Vector2& outTopRight, const Vector2& outBottomLeft, const AABB2& inRect)
{ OnProhibitedAction(); }
void DrawImage(IImage *img, const Vector2& outTopLeft)
{
if (allowDepthHack)
base->DrawImage(img, outTopLeft);
else
OnProhibitedAction();
}
void DrawImage(IImage *img, const AABB2& outRect)
{
if (allowDepthHack)
base->DrawImage(img, outRect);
else
OnProhibitedAction();
}
void DrawImage(IImage *img, const Vector2& outTopLeft, const AABB2& inRect)
{
if (allowDepthHack)
base->DrawImage(img, outTopLeft, inRect);
else
OnProhibitedAction();
}
void DrawImage(IImage *img, const AABB2& outRect, const AABB2& inRect)
{
if (allowDepthHack)
base->DrawImage(img, outRect, inRect);
else
OnProhibitedAction();
}
void DrawImage(IImage *img, const Vector2& outTopLeft, const Vector2& outTopRight, const Vector2& outBottomLeft, const AABB2& inRect)
{
if (allowDepthHack)
base->DrawImage(img, outTopLeft, outTopRight, outBottomLeft, inRect);
else
OnProhibitedAction();
}
void DrawFlatGameMap(const AABB2& outRect, const AABB2& inRect)
{ OnProhibitedAction(); }

View File

@ -29,6 +29,7 @@
#include <Client/Client.h>
#include <Core/Settings.h>
#include "NetClient.h"
#include <ScriptBindings/Config.h>
namespace spades {
namespace client {
@ -44,6 +45,7 @@ namespace spades {
helper.Set(new ClientUIHelper(this), false);
ScopedPrivilegeEscalation privilege;
static ScriptFunction uiFactory("ClientUI@ CreateClientUI(Renderer@, AudioDevice@, Font@, ClientUIHelper@)");
{
ScriptContextHandle ctx = uiFactory.Prepare();
@ -94,6 +96,7 @@ namespace spades {
return;
}
ScopedPrivilegeEscalation privilege;
static ScriptFunction func("ClientUI", "void MouseEvent(float, float)");
ScriptContextHandle c = func.Prepare();
c->SetObject(&*ui);
@ -108,6 +111,7 @@ namespace spades {
return;
}
ScopedPrivilegeEscalation privilege;
static ScriptFunction func("ClientUI", "void WheelEvent(float, float)");
ScriptContextHandle c = func.Prepare();
c->SetObject(&*ui);
@ -121,6 +125,8 @@ namespace spades {
if(!ui){
return;
}
ScopedPrivilegeEscalation privilege;
static ScriptFunction func("ClientUI", "void KeyEvent(string, bool)");
ScriptContextHandle c = func.Prepare();
std::string k = key;
@ -135,6 +141,8 @@ namespace spades {
if(!ui){
return;
}
ScopedPrivilegeEscalation privilege;
static ScriptFunction func("ClientUI", "void TextInputEvent(string)");
ScriptContextHandle c = func.Prepare();
std::string k = ch;
@ -149,6 +157,8 @@ namespace spades {
if(!ui){
return;
}
ScopedPrivilegeEscalation privilege;
static ScriptFunction func("ClientUI", "void TextEditingEvent(string,int,int)");
ScriptContextHandle c = func.Prepare();
std::string k = ch;
@ -164,6 +174,8 @@ namespace spades {
if(!ui){
return false;
}
ScopedPrivilegeEscalation privilege;
static ScriptFunction func("ClientUI", "bool AcceptsTextInput()");
ScriptContextHandle c = func.Prepare();
c->SetObject(&*ui);
@ -176,6 +188,8 @@ namespace spades {
if(!ui){
return AABB2();
}
ScopedPrivilegeEscalation privilege;
static ScriptFunction func("ClientUI", "AABB2 GetTextInputRect()");
ScriptContextHandle c = func.Prepare();
c->SetObject(&*ui);
@ -188,6 +202,8 @@ namespace spades {
if(!ui){
return false;
}
ScopedPrivilegeEscalation privilege;
static ScriptFunction func("ClientUI", "bool WantsClientToBeClosed()");
ScriptContextHandle c = func.Prepare();
c->SetObject(&*ui);
@ -200,6 +216,8 @@ namespace spades {
if(!ui){
return false;
}
ScopedPrivilegeEscalation privilege;
static ScriptFunction func("ClientUI", "bool NeedsInput()");
ScriptContextHandle c = func.Prepare();
c->SetObject(&*ui);
@ -209,6 +227,8 @@ namespace spades {
void ClientUI::RunFrame(float dt) {
SPADES_MARK_FUNCTION();
ScopedPrivilegeEscalation privilege;
static ScriptFunction func("ClientUI", "void RunFrame(float)");
ScriptContextHandle c = func.Prepare();
c->SetObject(&*ui);
@ -221,6 +241,8 @@ namespace spades {
if(!ui){
return;
}
ScopedPrivilegeEscalation privilege;
static ScriptFunction func("ClientUI", "void Closing()");
ScriptContextHandle c = func.Prepare();
c->SetObject(&*ui);
@ -233,6 +255,8 @@ namespace spades {
if(!ui){
return;
}
ScopedPrivilegeEscalation privilege;
static ScriptFunction func("ClientUI", "void RecordChatLog(string, Vector4)");
ScriptContextHandle c = func.Prepare();
std::string k = msg;
@ -247,6 +271,8 @@ namespace spades {
if(!ui){
return;
}
ScopedPrivilegeEscalation privilege;
static ScriptFunction func("ClientUI", "void EnterClientMenu()");
ScriptContextHandle c = func.Prepare();
c->SetObject(&*ui);
@ -257,6 +283,8 @@ namespace spades {
if(!ui){
return;
}
ScopedPrivilegeEscalation privilege;
static ScriptFunction func("ClientUI", "void EnterGlobalChatWindow()");
ScriptContextHandle c = func.Prepare();
c->SetObject(&*ui);
@ -267,6 +295,8 @@ namespace spades {
if(!ui){
return;
}
ScopedPrivilegeEscalation privilege;
static ScriptFunction func("ClientUI", "void EnterTeamChatWindow()");
ScriptContextHandle c = func.Prepare();
c->SetObject(&*ui);
@ -277,6 +307,8 @@ namespace spades {
if(!ui){
return;
}
ScopedPrivilegeEscalation privilege;
static ScriptFunction func("ClientUI", "void EnterCommandWindow()");
ScriptContextHandle c = func.Prepare();
c->SetObject(&*ui);
@ -287,6 +319,8 @@ namespace spades {
if(!ui){
return;
}
ScopedPrivilegeEscalation privilege;
static ScriptFunction func("ClientUI", "void CloseUI()");
ScriptContextHandle c = func.Prepare();
c->SetObject(&*ui);
@ -295,7 +329,6 @@ namespace spades {
bool ClientUI::isIgnored(const std::string& key)
{
return !ignoreInput.empty() && EqualsIgnoringCase(ignoreInput, key );
}
void ClientUI::setIgnored(const std::string& key)

View File

@ -28,6 +28,7 @@
#include <Core/Settings.h>
#include <Client/Fonts.h>
#include <Core/Strings.h>
#include <ScriptBindings/Config.h>
SPADES_SETTING(cg_lastQuickConnectHost, "127.0.0.1");
SPADES_SETTING(cg_protocolVersion, "");
@ -61,6 +62,7 @@ namespace spades {
// Restores renderer's state (game map, fog color)
// after returning from the game client.
void MainScreen::RestoreRenderer() {
ScopedPrivilegeEscalation privilege;
static ScriptFunction func("MainScreenUI", "void SetupRenderer()");
ScriptContextHandle c = func.Prepare();
c->SetObject(&*ui);
@ -85,6 +87,7 @@ namespace spades {
return;
}
ScopedPrivilegeEscalation privilege;
static ScriptFunction func("MainScreenUI", "void MouseEvent(float, float)");
ScriptContextHandle c = func.Prepare();
c->SetObject(&*ui);
@ -104,6 +107,7 @@ namespace spades {
return;
}
ScopedPrivilegeEscalation privilege;
static ScriptFunction func("MainScreenUI", "void WheelEvent(float, float)");
ScriptContextHandle c = func.Prepare();
c->SetObject(&*ui);
@ -121,6 +125,7 @@ namespace spades {
if(!ui){
return;
}
ScopedPrivilegeEscalation privilege;
static ScriptFunction func("MainScreenUI", "void KeyEvent(string, bool)");
ScriptContextHandle c = func.Prepare();
std::string k = key;
@ -139,6 +144,7 @@ namespace spades {
if(!ui){
return;
}
ScopedPrivilegeEscalation privilege;
static ScriptFunction func("MainScreenUI", "void TextInputEvent(string)");
ScriptContextHandle c = func.Prepare();
std::string k = ch;
@ -157,6 +163,7 @@ namespace spades {
if(!ui){
return;
}
ScopedPrivilegeEscalation privilege;
static ScriptFunction func("MainScreenUI", "void TextEditingEvent(string, int, int)");
ScriptContextHandle c = func.Prepare();
std::string k = ch;
@ -175,6 +182,7 @@ namespace spades {
if(!ui){
return false;
}
ScopedPrivilegeEscalation privilege;
static ScriptFunction func("MainScreenUI", "bool AcceptsTextInput()");
ScriptContextHandle c = func.Prepare();
c->SetObject(&*ui);
@ -190,6 +198,7 @@ namespace spades {
if(!ui){
return AABB2();
}
ScopedPrivilegeEscalation privilege;
static ScriptFunction func("MainScreenUI", "AABB2 GetTextInputRect()");
ScriptContextHandle c = func.Prepare();
c->SetObject(&*ui);
@ -202,6 +211,7 @@ namespace spades {
if(!ui){
return false;
}
ScopedPrivilegeEscalation privilege;
static ScriptFunction func("MainScreenUI", "bool WantsToBeClosed()");
ScriptContextHandle c = func.Prepare();
c->SetObject(&*ui);
@ -263,6 +273,7 @@ namespace spades {
return;
}
ScopedPrivilegeEscalation privilege;
static ScriptFunction func("MainScreenUI", "void RunFrame(float)");
ScriptContextHandle c = func.Prepare();
c->SetObject(&*ui);
@ -274,6 +285,7 @@ namespace spades {
SPADES_MARK_FUNCTION();
renderer->Init();
ScopedPrivilegeEscalation privilege;
static ScriptFunction uiFactory("MainScreenUI@ CreateMainScreenUI(Renderer@, AudioDevice@, Font@, MainScreenHelper@)");
{
ScriptContextHandle ctx = uiFactory.Prepare();
@ -298,6 +310,7 @@ namespace spades {
if(!ui){
return;
}
ScopedPrivilegeEscalation privilege;
static ScriptFunction func("MainScreenUI", "void Closing()");
ScriptContextHandle c = func.Prepare();
c->SetObject(&*ui);

View File

@ -29,6 +29,7 @@
#include <Gui/Main.h>
#include <Audio/NullDevice.h>
#include <Client/Fonts.h>
#include <ScriptBindings/Config.h>
namespace spades {
namespace gui {
@ -59,6 +60,7 @@ namespace spades {
// Restores renderer's state (game map, fog color)
// after returning from the game client.
void StartupScreen::RestoreRenderer() {
ScopedPrivilegeEscalation privilege;
static ScriptFunction func("StartupScreenUI", "void SetupRenderer()");
ScriptContextHandle c = func.Prepare();
c->SetObject(&*ui);
@ -76,6 +78,7 @@ namespace spades {
return;
}
ScopedPrivilegeEscalation privilege;
static ScriptFunction func("StartupScreenUI", "void MouseEvent(float, float)");
ScriptContextHandle c = func.Prepare();
c->SetObject(&*ui);
@ -91,6 +94,7 @@ namespace spades {
return;
}
ScopedPrivilegeEscalation privilege;
static ScriptFunction func("StartupScreenUI", "void WheelEvent(float, float)");
ScriptContextHandle c = func.Prepare();
c->SetObject(&*ui);
@ -104,6 +108,7 @@ namespace spades {
if(!ui){
return;
}
ScopedPrivilegeEscalation privilege;
static ScriptFunction func("StartupScreenUI", "void KeyEvent(string, bool)");
ScriptContextHandle c = func.Prepare();
std::string k = key;
@ -118,6 +123,7 @@ namespace spades {
if(!ui){
return;
}
ScopedPrivilegeEscalation privilege;
static ScriptFunction func("StartupScreenUI", "void TextInputEvent(string)");
ScriptContextHandle c = func.Prepare();
std::string k = ch;
@ -132,6 +138,7 @@ namespace spades {
if(!ui){
return;
}
ScopedPrivilegeEscalation privilege;
static ScriptFunction func("StartupScreenUI", "void TextEditingEvent(string, int, int)");
ScriptContextHandle c = func.Prepare();
std::string k = ch;
@ -147,6 +154,7 @@ namespace spades {
if(!ui){
return false;
}
ScopedPrivilegeEscalation privilege;
static ScriptFunction func("StartupScreenUI", "bool AcceptsTextInput()");
ScriptContextHandle c = func.Prepare();
c->SetObject(&*ui);
@ -159,6 +167,7 @@ namespace spades {
if(!ui){
return AABB2();
}
ScopedPrivilegeEscalation privilege;
static ScriptFunction func("StartupScreenUI", "AABB2 GetTextInputRect()");
ScriptContextHandle c = func.Prepare();
c->SetObject(&*ui);
@ -171,6 +180,7 @@ namespace spades {
if(!ui){
return false;
}
ScopedPrivilegeEscalation privilege;
static ScriptFunction func("StartupScreenUI", "bool WantsToBeClosed()");
ScriptContextHandle c = func.Prepare();
c->SetObject(&*ui);
@ -204,6 +214,7 @@ namespace spades {
void StartupScreen::RunFrame(float dt) {
SPADES_MARK_FUNCTION();
ScopedPrivilegeEscalation privilege;
static ScriptFunction func("StartupScreenUI", "void RunFrame(float)");
ScriptContextHandle c = func.Prepare();
c->SetObject(&*ui);
@ -214,6 +225,7 @@ namespace spades {
void StartupScreen::DoInit() {
SPADES_MARK_FUNCTION();
ScopedPrivilegeEscalation privilege;
static ScriptFunction uiFactory("StartupScreenUI@ CreateStartupScreenUI(Renderer@, AudioDevice@, Font@, StartupScreenHelper@)");
{
ScriptContextHandle ctx = uiFactory.Prepare();
@ -234,6 +246,7 @@ namespace spades {
if(!ui){
return;
}
ScopedPrivilegeEscalation privilege;
static ScriptFunction func("StartupScreenUI", "void Closing()");
ScriptContextHandle c = func.Prepare();
c->SetObject(&*ui);

View File

@ -21,9 +21,20 @@
#include "ScriptManager.h"
#include <Core/Settings.h>
#include <Core/RefCountedObject.h>
#include <Core/ThreadLocalStorage.h>
namespace spades {
static ThreadLocalStorage<bool> writeAllowed;
void MaskConfigUpdateByScript(bool disabled)
{
if (!writeAllowed) {
writeAllowed = new bool;
}
*writeAllowed = !disabled;
}
class ConfigRegistrar: public ScriptObjectRegistrar {
@ -46,16 +57,27 @@ namespace spades {
}
ConfigItem *operator =(float fv) {
if (!writeAllowed || !*writeAllowed) {
return this;
}
handle = fv;
AddRef();
return this;
}
ConfigItem *operator =(int v) {
if (!writeAllowed || !*writeAllowed) {
return this;
}
handle = v;
AddRef();
return this;
}
ConfigItem *operator =(const std::string& v) {
if (!writeAllowed || !*writeAllowed) {
return this;
}
handle = v;
AddRef();
return this;
@ -189,5 +211,6 @@ namespace spades {
};
static ConfigRegistrar registrar;
}

View File

@ -0,0 +1,32 @@
/*
Copyright (c) 2013 yvt
This file is part of OpenSpades.
OpenSpades is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenSpades is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OpenSpades. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
namespace spades {
void MaskConfigUpdateByScript(bool);
class ScopedPrivilegeEscalation
{
public:
ScopedPrivilegeEscalation() { MaskConfigUpdateByScript(false); }
~ScopedPrivilegeEscalation() { MaskConfigUpdateByScript(true); }
};
}