cocoaTouch/GameSetup.m
changeset 3335 2520ee7a5484
parent 3332 3c90a923f156
child 3349 5571592f10a8
equal deleted inserted replaced
3334:f94a52a763d4 3335:2520ee7a5484
     4 //
     4 //
     5 //  Created by Vittorio on 10/01/10.
     5 //  Created by Vittorio on 10/01/10.
     6 //  Copyright 2010 __MyCompanyName__. All rights reserved.
     6 //  Copyright 2010 __MyCompanyName__. All rights reserved.
     7 //
     7 //
     8 
     8 
       
     9 #include <sys/types.h>
       
    10 #include <sys/sysctl.h>
       
    11 
     9 #import "GameSetup.h"
    12 #import "GameSetup.h"
    10 #import "SDL_uikitappdelegate.h"
    13 #import "SDL_uikitappdelegate.h"
    11 #import "SDL_net.h"
    14 #import "SDL_net.h"
    12 #import "PascalImports.h"
    15 #import "PascalImports.h"
    13 #include <sys/types.h>
    16 #import "CommodityFunctions.h"
    14 #include <sys/sysctl.h>
       
    15 
    17 
    16 #define BUFFER_SIZE 256
    18 #define BUFFER_SIZE 256
    17 #define debug(format, ...) CFShow([NSString stringWithFormat:format, ## __VA_ARGS__]);
    19 #define debug(format, ...) CFShow([NSString stringWithFormat:format, ## __VA_ARGS__]);
    18 
    20 
    19 @implementation GameSetup
    21 @implementation GameSetup
    23 -(id) init {
    25 -(id) init {
    24 	if (self = [super init]) {
    26 	if (self = [super init]) {
    25     	srandom(time(NULL));
    27     	srandom(time(NULL));
    26         ipcPort = (random() % 64541) + 1025;
    28         ipcPort = (random() % 64541) + 1025;
    27         
    29         
    28         NSString *filePath = [[SDLUIKitDelegate sharedAppDelegate] dataFilePath:@"settings.plist"];
    30         systemSettings = [[NSDictionary alloc] initWithContentsOfFile:SETTINGS_FILE()]; //should check it exists
    29         systemSettings = [[NSDictionary alloc] initWithContentsOfFile:filePath]; //should check it exists
       
    30         return self;
    31         return self;
    31     } else
    32     } else
    32         return nil;
    33         return nil;
    33 }
    34 }
    34 
    35 
   326     */
   327     */
   327     
   328     
   328     // prevents using an empty nickname
   329     // prevents using an empty nickname
   329     NSString *username;
   330     NSString *username;
   330     NSString *originalUsername = [systemSettings objectForKey:@"username"];
   331     NSString *originalUsername = [systemSettings objectForKey:@"username"];
   331     if ([originalUsername isEqualToString:@""]) {
   332     if ([originalUsername length] == 0) {
   332         username = [[NSString alloc] initWithFormat:@"MobileUser-%@",ipcString];
   333         username = [[NSString alloc] initWithFormat:@"MobileUser-%@",ipcString];
   333     } else {
   334     } else {
   334         username = [[NSString alloc] initWithString:originalUsername];
   335         username = [[NSString alloc] initWithString:originalUsername];
   335     }
   336     }
   336     
   337     
   337 	gameArgs[0] = [username UTF8String];                                    //UserNick
   338 	gameArgs[0] = [username UTF8String];                                                    //UserNick
   338 	gameArgs[1] = [ipcString UTF8String];                                   //ipcPort
   339 	gameArgs[1] = [ipcString UTF8String];                                                   //ipcPort
   339 	gameArgs[2] = [[[systemSettings objectForKey:@"sounds"] stringValue] UTF8String];     //isSoundEnabled
   340 	gameArgs[2] = [[[systemSettings objectForKey:@"sound"] stringValue] UTF8String];        //isSoundEnabled
   340 	gameArgs[3] = [[[systemSettings objectForKey:@"music"] stringValue] UTF8String];      //isMusicEnabled
   341 	gameArgs[3] = [[[systemSettings objectForKey:@"music"] stringValue] UTF8String];        //isMusicEnabled
   341 	gameArgs[4] = [localeString UTF8String];                                //cLocaleFName
   342 	gameArgs[4] = [localeString UTF8String];                                                //cLocaleFName
   342 	gameArgs[5] = [[[systemSettings objectForKey:@"alternate"] stringValue] UTF8String];	//cAltDamage
   343 	gameArgs[5] = [[[systemSettings objectForKey:@"alternate"] stringValue] UTF8String];	//cAltDamage
   343 	gameArgs[6] = [wSize UTF8String];                                       //cScreenHeight
   344 	gameArgs[6] = [wSize UTF8String];                                                       //cScreenHeight
   344     gameArgs[7] = [hSize UTF8String];                                       //cScreenWidth
   345     gameArgs[7] = [hSize UTF8String];                                                       //cScreenWidth
   345     
   346     
   346     [wSize release];
   347     [wSize release];
   347     [hSize release];
   348     [hSize release];
   348 	[localeString release];
   349 	[localeString release];
   349 	[ipcString release];
   350 	[ipcString release];