Implemented HUD dial whitelisting.

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@3370 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Jens Ayton 2010-05-18 19:26:26 +00:00
parent 62456b09f6
commit 3df2a3e3dd
4 changed files with 26 additions and 20 deletions

View File

@ -288,20 +288,8 @@
"fuelLeakRate_number"
);
hud_methods =
hud_dial_methods =
(
// accepted keys
"crosshairs",
"crosshair_scale",
"crosshair_width",
"crosshair_color",
"legends",
"overall_alpha",
"reticle_target_sensitive",
"cloak_indicator_on_status_light",
"dials",
// possible dials
"drawTrumbles:",
"drawTargetReticle:",
"drawScanner:",

View File

@ -201,7 +201,7 @@ MA 02110-1301, USA.
GLfloat z1;
GLfloat line_width;
NSString *hudName;
NSString *hudName;
GLfloat overallAlpha;

View File

@ -170,6 +170,8 @@ OOINLINE void GLColorWithOverallAlpha(const GLfloat *color, GLfloat alpha)
if (sFontTexture == nil) InitTextEngine();
hudName = [hudFileName copy];
// init arrays
dialArray = [[NSMutableArray alloc] initWithCapacity:16]; // alloc retains
legendArray = [[NSMutableArray alloc] initWithCapacity:16]; // alloc retains
@ -203,8 +205,6 @@ OOINLINE void GLColorWithOverallAlpha(const GLfloat *color, GLfloat alpha)
cloakIndicatorOnStatusLight = [hudinfo oo_boolForKey:@"cloak_indicator_on_status_light" defaultValue:YES];
if (hudFileName != nil) hudName = [[NSString stringWithString:hudFileName] retain];
last_transmitter = NO_TARGET;
_crosshairOverrides = [[hudinfo oo_dictionaryForKey:@"crosshairs"] retain];
@ -407,11 +407,29 @@ OOINLINE void GLColorWithOverallAlpha(const GLfloat *color, GLfloat alpha)
- (void) addDial:(NSDictionary *) info
{
if ([info oo_stringForKey:SELECTOR_KEY] != nil)
static NSSet *allowedSelectors = nil;
if (allowedSelectors == nil)
{
SEL _selector = NSSelectorFromString([info oo_stringForKey:SELECTOR_KEY]);
if ([self respondsToSelector:_selector]) [dialArray addObject:info];
NSDictionary *whitelist = [ResourceManager whitelistDictionary];
allowedSelectors = [[NSSet alloc] initWithArray:[whitelist oo_arrayForKey:@"hud_dial_methods"]];
}
NSString *dialSelector = [info oo_stringForKey:SELECTOR_KEY];
if (dialSelector == nil)
{
OOLogERR(@"hud.dial.noSelector", @"HUD dial in %@ is missing selector.", hudName);
return;
}
if (![allowedSelectors containsObject:dialSelector])
{
OOLogERR(@"hud.dial.invalidSelector", @"HUD dial in %@ uses selector \"%@\" which is not in whitelist, and will be ignored.", hudName, dialSelector);
return;
}
NSAssert2([self respondsToSelector:NSSelectorFromString(dialSelector)], @"HUD dial in %@ uses selector \"%@\" which is in whitelist, but not implemented.", hudName, dialSelector);
[dialArray addObject:info];
}

View File

@ -75,7 +75,7 @@ static NSString * const kCacheKeyCaches = @"caches";
enum
{
kEndianTagValue = 0x0123456789ABCDEFULL,
kFormatVersionValue = 39
kFormatVersionValue = 40
};