/Volumes/Plantain/MyDocuments/Projects/MacTrek/MacTrek/Data/FeatureList.m

00001 //
00002 //  FeatureList.m
00003 //  MacTrek
00004 //
00005 //  Created by Aqua on 26/04/2006.
00006 //  Copyright 2006 __MyCompanyName__. All rights reserved.
00007 //
00008 
00009 #import "FeatureList.h"
00010 #import "BeepLite.h"
00011 
00012 
00013 @implementation FeatureList
00014 
00015 - (id) init {
00016     features = nil;
00017     self = [super init];
00018     if (self != nil) {
00019         features = [NSArray arrayWithObjects:
00020                 [[Feature alloc] initWithName:@"FEATURE_PACKETS" type: FEATURE_SERVER_TYPE 
00021                                  desiredValue:FEATURE_ON sendWithRSA: FEATURE_ALREADY_SENT],
00022                 [[Feature alloc] initWithName:@"NEWMACRO" type: FEATURE_CLIENT_TYPE 
00023                                  desiredValue:FEATURE_ON sendWithRSA: FEATURE_SEND_FEATURE],
00024                 [[Feature alloc] initWithName:@"SMARTMACRO" type: FEATURE_CLIENT_TYPE 
00025                                  desiredValue:FEATURE_ON sendWithRSA: FEATURE_SEND_FEATURE],
00026                 [[Feature alloc] initWithName:@"WHY_DEAD" type: FEATURE_SERVER_TYPE 
00027                                  desiredValue:FEATURE_ON sendWithRSA: FEATURE_SEND_FEATURE],
00028                 [[Feature alloc] initWithName:@"SBHOURS" type: FEATURE_SERVER_TYPE 
00029                                  desiredValue:FEATURE_ON sendWithRSA: FEATURE_SEND_FEATURE],
00030                 [[Feature alloc] initWithName:@"CLOAK_MAXWARP" type: FEATURE_SERVER_TYPE 
00031                                  desiredValue:FEATURE_ON sendWithRSA: FEATURE_SEND_FEATURE],
00032                 [[Feature alloc] initWithName:@"SELF_8FLAGS" type: FEATURE_SERVER_TYPE 
00033                                  desiredValue:FEATURE_ON sendWithRSA: FEATURE_SEND_FEATURE],
00034                 [[Feature alloc] initWithName:@"SELF_8FLAGS2" type: FEATURE_SERVER_TYPE 
00035                                  desiredValue:FEATURE_OFF sendWithRSA: FEATURE_SEND_FEATURE],
00036                 [[Feature alloc] initWithName:@"RC_DISTRESS" type: FEATURE_SERVER_TYPE 
00037                                  desiredValue:FEATURE_ON sendWithRSA: FEATURE_SEND_FEATURE],
00038                 [[Feature alloc] initWithName:@"MULTIMACROS" type: FEATURE_SERVER_TYPE 
00039                                  desiredValue:FEATURE_ON sendWithRSA: FEATURE_SEND_FEATURE],
00040                 [[Feature alloc] initWithName:@"SHIP_CAP" type: FEATURE_SERVER_TYPE 
00041                                  desiredValue:FEATURE_ON sendWithRSA: FEATURE_SEND_FEATURE],
00042                 [[Feature alloc] initWithName:@"BEEPLITE" type: FEATURE_CLIENT_TYPE 
00043                                  desiredValue:FEATURE_ON sendWithRSA: FEATURE_SEND_FEATURE],
00044                 [[Feature alloc] initWithName:@"CONTINUOUS_MOUSE" type: FEATURE_CLIENT_TYPE 
00045                                  desiredValue:FEATURE_ON sendWithRSA: FEATURE_SEND_FEATURE],
00046                 [[Feature alloc] initWithName:@"CONTINUOUS_STEER" type: FEATURE_CLIENT_TYPE 
00047                                  desiredValue:FEATURE_ON sendWithRSA: FEATURE_SEND_FEATURE],
00048                 nil];
00049         // important! arrayWithObjects is autoretained ! so lock it here
00050         [features retain];
00051                 
00052     }
00053     return self;
00054 }
00055 
00056 - (int) valueForFeature:(int)feature {
00057     Feature *feat = [features objectAtIndex:feature];
00058     return [feat value];
00059 }
00060 
00061 -(void) checkFeature:(NSString*)name withType:(char)type withArg1:(int)arg1 withArg2:(int)arg2 withValue:(int)value {
00062     
00063     if (features == nil) {
00064         NSLog(@"FeatureList.checkFeature %@ initialization ERROR", name);
00065         return;
00066     }
00067     
00068     for(int f = 0; f < [features count]; f++) {
00069         Feature *feature = [features objectAtIndex: f]; 
00070         if([name isEqualToString:[feature name]]) {
00071             // if server returns unknown, set to off for server mods, desired
00072             // value for client mods. Otherwise,  set to value from server.
00073             if (value == FEATURE_UNKNOWN) {
00074                 if ([feature type] == FEATURE_SERVER_TYPE) {
00075                     [feature setValue: FEATURE_OFF];
00076                 } else {
00077                     [feature setValue:[feature desiredValue]];
00078                 }
00079             } else {
00080                 [feature setValue:value];
00081             }
00082 
00083             if ([feature arg1] != 0) {
00084                 [feature setArg1:arg1];
00085             }
00086             if ([feature arg2] != 0) {
00087                 [feature setArg2:arg2];
00088             }
00089             
00090             if([name isEqualToString:@"FEATURE_PACKETS"]) {
00091               //  for (int i = 0; i < [features count]; i++) {
00092               //     NSLog([NSString stringWithFormat:@"FeatureList.checkFeature: SERVER FEATURES - %@ = %d", 
00093               //         [[features objectAtIndex:i] name], 
00094               //         [[features objectAtIndex:i] value]]);
00095               //  }
00096             }
00097             else if([name isEqualToString: @"RC_DISTRESS"] && 
00098                     [self valueForFeature: FEATURE_LIST_GEN_DISTRESS] != FEATURE_OFF) {
00099                 //$$ no idea what to do with that
00100                 //Defaults.rcds = Defaults.preferred_rcds;
00101             }
00102             else if([name isEqualToString:@"BEEPLITE"]) {
00103                 
00104                 feature = [features objectAtIndex:FEATURE_LIST_BEEPLITE];
00105                 switch (value) {
00106                                         case FEATURE_UNKNOWN: // Unknown, we can use all of the features!
00107                                                 [feature setArg1: BEEPLITE_PLAYERS_MAP | BEEPLITE_PLAYERS_LOCAL 
00108                         | BEEPLITE_SELF | BEEPLITE_PLANETS | BEEPLITE_SOUNDS 
00109                         | BEEPLITE_COLOR | BEEPLITE_TTS];
00110                                                 break;
00111                                         case FEATURE_ON:
00112                                                 if ([feature arg1] == 0) {                                      
00113                                                         // Server says we can have beeplite, but no
00114                                                         // options??? must be configured wrong.
00115                                                         [feature setArg1: BEEPLITE_PLAYERS_MAP | BEEPLITE_PLAYERS_LOCAL
00116                                 | BEEPLITE_SELF | BEEPLITE_PLANETS | BEEPLITE_SOUNDS 
00117                                 | BEEPLITE_COLOR | BEEPLITE_TTS];
00118                                                 }
00119                                                 int flags = [feature arg1];
00120                                                 NSMutableString *s;
00121                                                 if ((flags & BEEPLITE_PLAYERS_MAP) == 0) {
00122                                                         [s appendString:@" PLAYERS_MAP"];
00123                                                 }
00124                         if ((flags & BEEPLITE_PLAYERS_LOCAL) == 0) {
00125                             [s appendString:@" PLAYERS_LOCAL"];
00126                         }
00127                         if ((flags & BEEPLITE_SELF) == 0) {
00128                             [s appendString:@" SELF"];
00129                         }
00130                         if ((flags & BEEPLITE_PLANETS) == 0) {
00131                             [s appendString:@" PLANETS"];
00132                         }
00133                         if ((flags & BEEPLITE_SOUNDS) == 0) {
00134                             [s appendString:@" SOUNDS"];
00135                         }
00136                         if ((flags & BEEPLITE_COLOR) == 0) {
00137                             [s appendString:@" COLOR"];
00138                         }
00139                         if ((flags & BEEPLITE_TTS) == 0) {
00140                             [s appendString:@" TTS"];
00141                         }
00142                         if ([s length] > 0) {
00143                             NSLog([NSString stringWithFormat:@"%@ disabled", s]);
00144                         }
00145                         break;
00146                                         case FEATURE_OFF:
00147                                                 [feature setArg1: 0];
00148                                                 break;
00149                 }
00150             }
00151         } 
00152         //NSLog([NSString stringWithFormat:@"FeatureList.checkFeature: Feature %@ from server unknown to client!", name]);
00153     }
00154     
00155 }
00156 
00157 
00158 @end

Generated on Fri Jul 28 19:15:16 2006 for MacTrek by  doxygen 1.4.7