project_files/HedgewarsMobile/Classes/HWUtils.m
author koda
Wed, 28 Mar 2012 01:56:42 +0200
changeset 6832 fae8fd118da9
parent 6822 206db098f8c5
child 7048 0a4c88935902
permissions -rw-r--r--
dates are no more!
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6078
8c0cc07731e5 headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
diff changeset
     1
/*
8c0cc07731e5 headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
diff changeset
     2
 * Hedgewars-iOS, a Hedgewars port for iOS devices
8c0cc07731e5 headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
diff changeset
     3
 * Copyright (c) 2009-2010 Vittorio Giovara <vittorio.giovara@gmail.com>
8c0cc07731e5 headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
diff changeset
     4
 *
8c0cc07731e5 headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
8c0cc07731e5 headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
8c0cc07731e5 headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
8c0cc07731e5 headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
diff changeset
     8
 *
8c0cc07731e5 headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
8c0cc07731e5 headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8c0cc07731e5 headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
8c0cc07731e5 headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
diff changeset
    12
 * GNU General Public License for more details.
8c0cc07731e5 headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
diff changeset
    13
 *
8c0cc07731e5 headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
8c0cc07731e5 headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
8c0cc07731e5 headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
8c0cc07731e5 headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
diff changeset
    17
 */
8c0cc07731e5 headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
diff changeset
    18
8c0cc07731e5 headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
diff changeset
    19
8c0cc07731e5 headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
diff changeset
    20
#import "HWUtils.h"
8c0cc07731e5 headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
diff changeset
    21
#import <sys/types.h>
8c0cc07731e5 headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
diff changeset
    22
#import <sys/sysctl.h>
6246
6b2d19ed521a just moving ios server stuff around
koda
parents: 6209
diff changeset
    23
#import <netinet/in.h>
6b2d19ed521a just moving ios server stuff around
koda
parents: 6209
diff changeset
    24
#import <SystemConfiguration/SCNetworkReachability.h>
6409
ca93f38a1aab SDL included some of our patches mainstream
koda
parents: 6321
diff changeset
    25
#import "SDL_uikitwindow.h"
6078
8c0cc07731e5 headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
diff changeset
    26
6832
fae8fd118da9 dates are no more!
koda
parents: 6822
diff changeset
    27
6208
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents: 6108
diff changeset
    28
static NSString *cachedModel = nil;
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents: 6108
diff changeset
    29
static NSArray *cachedColors = nil;
6822
206db098f8c5 ios headers cleanup, with tweaks to +randomPort and grenade timer handling in overlay
koda
parents: 6700
diff changeset
    30
static NSMutableArray *activePorts = nil;
6208
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents: 6108
diff changeset
    31
6247
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6246
diff changeset
    32
static TGameType gameType = gtNone;
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6246
diff changeset
    33
static TGameStatus gameStatus = gsNone;
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6246
diff changeset
    34
6078
8c0cc07731e5 headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
diff changeset
    35
@implementation HWUtils
8c0cc07731e5 headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
diff changeset
    36
6247
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6246
diff changeset
    37
#pragma mark -
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6246
diff changeset
    38
#pragma mark game status and type info
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6246
diff changeset
    39
+(TGameType) gameType {
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6246
diff changeset
    40
    return gameType;
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6246
diff changeset
    41
}
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6246
diff changeset
    42
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6246
diff changeset
    43
+(void) setGameType:(TGameType) type {
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6246
diff changeset
    44
    gameType = type;
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6246
diff changeset
    45
}
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6246
diff changeset
    46
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6246
diff changeset
    47
+(TGameStatus) gameStatus {
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6246
diff changeset
    48
    return gameStatus;
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6246
diff changeset
    49
}
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6246
diff changeset
    50
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6246
diff changeset
    51
+(void) setGameStatus:(TGameStatus) status {
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6246
diff changeset
    52
    gameStatus = status;
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6246
diff changeset
    53
}
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6246
diff changeset
    54
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6246
diff changeset
    55
+(BOOL) isGameLaunched {
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6246
diff changeset
    56
    return ((gameStatus == gsLoading) || (gameStatus == gsInGame));
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6246
diff changeset
    57
}
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6246
diff changeset
    58
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6246
diff changeset
    59
+(BOOL) isGameRunning {
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6246
diff changeset
    60
    return (gameStatus == gsInGame);
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6246
diff changeset
    61
}
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6246
diff changeset
    62
6dfad55fd71c unified the objc game state in a single place, which allowed some optimization to ObjcExport class (and more)
koda
parents: 6246
diff changeset
    63
#pragma mark -
6409
ca93f38a1aab SDL included some of our patches mainstream
koda
parents: 6321
diff changeset
    64
#pragma mark Helper Functions with cache
6078
8c0cc07731e5 headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
diff changeset
    65
+(NSString *)modelType {
6208
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents: 6108
diff changeset
    66
    if (cachedModel == nil) {
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents: 6108
diff changeset
    67
        size_t size;
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents: 6108
diff changeset
    68
        // set 'oldp' parameter to NULL to get the size of the data returned so we can allocate appropriate amount of space
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents: 6108
diff changeset
    69
        sysctlbyname("hw.machine", NULL, &size, NULL, 0);
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents: 6108
diff changeset
    70
        char *name = (char *)malloc(sizeof(char) * size);
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents: 6108
diff changeset
    71
        // get the platform name
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents: 6108
diff changeset
    72
        sysctlbyname("hw.machine", name, &size, NULL, 0);
6078
8c0cc07731e5 headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
diff changeset
    73
6208
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents: 6108
diff changeset
    74
        cachedModel = [[NSString stringWithUTF8String:name] retain];
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents: 6108
diff changeset
    75
        free(name);
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents: 6108
diff changeset
    76
    }
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents: 6108
diff changeset
    77
    return cachedModel;
6078
8c0cc07731e5 headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
diff changeset
    78
}
8c0cc07731e5 headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
diff changeset
    79
8c0cc07731e5 headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
diff changeset
    80
+(NSArray *)teamColors {
6208
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents: 6108
diff changeset
    81
    if (cachedColors == nil) {
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents: 6108
diff changeset
    82
        // by default colors are ARGB but we do computation over RGB, hence we have to "& 0x00FFFFFF" before processing
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents: 6108
diff changeset
    83
        unsigned int colors[] = HW_TEAMCOLOR_ARRAY;
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents: 6108
diff changeset
    84
        NSMutableArray *array = [[NSMutableArray alloc] init];
6078
8c0cc07731e5 headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
diff changeset
    85
6208
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents: 6108
diff changeset
    86
        int i = 0;
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents: 6108
diff changeset
    87
        while(colors[i] != 0)
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents: 6108
diff changeset
    88
            [array addObject:[NSNumber numberWithUnsignedInt:(colors[i++] & 0x00FFFFFF)]];
6078
8c0cc07731e5 headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
diff changeset
    89
6208
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents: 6108
diff changeset
    90
        cachedColors = [[NSArray arrayWithArray:array] retain];
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents: 6108
diff changeset
    91
        [array release];
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents: 6108
diff changeset
    92
    }
b831679e9467 move all extra categories in a single source, add caching for HWUtils
koda
parents: 6108
diff changeset
    93
    return cachedColors;
6078
8c0cc07731e5 headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
diff changeset
    94
}
8c0cc07731e5 headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
diff changeset
    95
6409
ca93f38a1aab SDL included some of our patches mainstream
koda
parents: 6321
diff changeset
    96
+(void) releaseCache {
ca93f38a1aab SDL included some of our patches mainstream
koda
parents: 6321
diff changeset
    97
    [cachedModel release], cachedModel = nil;
ca93f38a1aab SDL included some of our patches mainstream
koda
parents: 6321
diff changeset
    98
    [cachedColors release], cachedColors = nil;
6822
206db098f8c5 ios headers cleanup, with tweaks to +randomPort and grenade timer handling in overlay
koda
parents: 6700
diff changeset
    99
    // don't release activePorts here
6409
ca93f38a1aab SDL included some of our patches mainstream
koda
parents: 6321
diff changeset
   100
}
ca93f38a1aab SDL included some of our patches mainstream
koda
parents: 6321
diff changeset
   101
ca93f38a1aab SDL included some of our patches mainstream
koda
parents: 6321
diff changeset
   102
#pragma mark -
ca93f38a1aab SDL included some of our patches mainstream
koda
parents: 6321
diff changeset
   103
#pragma mark Helper Functions without cache
6246
6b2d19ed521a just moving ios server stuff around
koda
parents: 6209
diff changeset
   104
+(NSInteger) randomPort {
6822
206db098f8c5 ios headers cleanup, with tweaks to +randomPort and grenade timer handling in overlay
koda
parents: 6700
diff changeset
   105
    // set a new feed only at initialization time and forbid connecting to the server port
206db098f8c5 ios headers cleanup, with tweaks to +randomPort and grenade timer handling in overlay
koda
parents: 6700
diff changeset
   106
    if (activePorts == nil) {
206db098f8c5 ios headers cleanup, with tweaks to +randomPort and grenade timer handling in overlay
koda
parents: 6700
diff changeset
   107
        srandom(time(NULL));
206db098f8c5 ios headers cleanup, with tweaks to +randomPort and grenade timer handling in overlay
koda
parents: 6700
diff changeset
   108
        activePorts = [[NSMutableArray arrayWithObject:[NSNumber numberWithInt:NETGAME_DEFAULT_PORT]] retain];
206db098f8c5 ios headers cleanup, with tweaks to +randomPort and grenade timer handling in overlay
koda
parents: 6700
diff changeset
   109
    }
206db098f8c5 ios headers cleanup, with tweaks to +randomPort and grenade timer handling in overlay
koda
parents: 6700
diff changeset
   110
206db098f8c5 ios headers cleanup, with tweaks to +randomPort and grenade timer handling in overlay
koda
parents: 6700
diff changeset
   111
    // pick a random number from the free ports list
206db098f8c5 ios headers cleanup, with tweaks to +randomPort and grenade timer handling in overlay
koda
parents: 6700
diff changeset
   112
    NSInteger res = 0;
206db098f8c5 ios headers cleanup, with tweaks to +randomPort and grenade timer handling in overlay
koda
parents: 6700
diff changeset
   113
    do {
206db098f8c5 ios headers cleanup, with tweaks to +randomPort and grenade timer handling in overlay
koda
parents: 6700
diff changeset
   114
        res = (random() % 64511) + 1024;
206db098f8c5 ios headers cleanup, with tweaks to +randomPort and grenade timer handling in overlay
koda
parents: 6700
diff changeset
   115
    } while ([activePorts containsObject:[NSNumber numberWithInt:res]]);
206db098f8c5 ios headers cleanup, with tweaks to +randomPort and grenade timer handling in overlay
koda
parents: 6700
diff changeset
   116
206db098f8c5 ios headers cleanup, with tweaks to +randomPort and grenade timer handling in overlay
koda
parents: 6700
diff changeset
   117
    // add this number to the forbdding list
206db098f8c5 ios headers cleanup, with tweaks to +randomPort and grenade timer handling in overlay
koda
parents: 6700
diff changeset
   118
    [activePorts addObject:[NSNumber numberWithInt:res]];
206db098f8c5 ios headers cleanup, with tweaks to +randomPort and grenade timer handling in overlay
koda
parents: 6700
diff changeset
   119
    return res;
206db098f8c5 ios headers cleanup, with tweaks to +randomPort and grenade timer handling in overlay
koda
parents: 6700
diff changeset
   120
}
206db098f8c5 ios headers cleanup, with tweaks to +randomPort and grenade timer handling in overlay
koda
parents: 6700
diff changeset
   121
206db098f8c5 ios headers cleanup, with tweaks to +randomPort and grenade timer handling in overlay
koda
parents: 6700
diff changeset
   122
+(void) freePort:(NSInteger) port {
206db098f8c5 ios headers cleanup, with tweaks to +randomPort and grenade timer handling in overlay
koda
parents: 6700
diff changeset
   123
    [activePorts removeObject:[NSNumber numberWithInt:port]];
6246
6b2d19ed521a just moving ios server stuff around
koda
parents: 6209
diff changeset
   124
}
6b2d19ed521a just moving ios server stuff around
koda
parents: 6209
diff changeset
   125
6b2d19ed521a just moving ios server stuff around
koda
parents: 6209
diff changeset
   126
+(BOOL) isNetworkReachable {
6b2d19ed521a just moving ios server stuff around
koda
parents: 6209
diff changeset
   127
    // Create zero addy
6b2d19ed521a just moving ios server stuff around
koda
parents: 6209
diff changeset
   128
    struct sockaddr_in zeroAddress;
6b2d19ed521a just moving ios server stuff around
koda
parents: 6209
diff changeset
   129
    bzero(&zeroAddress, sizeof(zeroAddress));
6b2d19ed521a just moving ios server stuff around
koda
parents: 6209
diff changeset
   130
    zeroAddress.sin_len = sizeof(zeroAddress);
6b2d19ed521a just moving ios server stuff around
koda
parents: 6209
diff changeset
   131
    zeroAddress.sin_family = AF_INET;
6b2d19ed521a just moving ios server stuff around
koda
parents: 6209
diff changeset
   132
6b2d19ed521a just moving ios server stuff around
koda
parents: 6209
diff changeset
   133
    // Recover reachability flags
6b2d19ed521a just moving ios server stuff around
koda
parents: 6209
diff changeset
   134
    SCNetworkReachabilityRef defaultRouteReachability = SCNetworkReachabilityCreateWithAddress(NULL, (struct sockaddr *)&zeroAddress);
6b2d19ed521a just moving ios server stuff around
koda
parents: 6209
diff changeset
   135
    SCNetworkReachabilityFlags flags;
6b2d19ed521a just moving ios server stuff around
koda
parents: 6209
diff changeset
   136
6b2d19ed521a just moving ios server stuff around
koda
parents: 6209
diff changeset
   137
    BOOL didRetrieveFlags = SCNetworkReachabilityGetFlags(defaultRouteReachability, &flags);
6b2d19ed521a just moving ios server stuff around
koda
parents: 6209
diff changeset
   138
    CFRelease(defaultRouteReachability);
6b2d19ed521a just moving ios server stuff around
koda
parents: 6209
diff changeset
   139
6b2d19ed521a just moving ios server stuff around
koda
parents: 6209
diff changeset
   140
    if (!didRetrieveFlags) {
6b2d19ed521a just moving ios server stuff around
koda
parents: 6209
diff changeset
   141
        NSLog(@"Error. Could not recover network reachability flags");
6b2d19ed521a just moving ios server stuff around
koda
parents: 6209
diff changeset
   142
        return NO;
6b2d19ed521a just moving ios server stuff around
koda
parents: 6209
diff changeset
   143
    }
6b2d19ed521a just moving ios server stuff around
koda
parents: 6209
diff changeset
   144
6b2d19ed521a just moving ios server stuff around
koda
parents: 6209
diff changeset
   145
    BOOL isReachable = flags & kSCNetworkFlagsReachable;
6b2d19ed521a just moving ios server stuff around
koda
parents: 6209
diff changeset
   146
    BOOL needsConnection = flags & kSCNetworkFlagsConnectionRequired;
6b2d19ed521a just moving ios server stuff around
koda
parents: 6209
diff changeset
   147
    BOOL nonWiFi = flags & kSCNetworkReachabilityFlagsTransientConnection;
6b2d19ed521a just moving ios server stuff around
koda
parents: 6209
diff changeset
   148
6b2d19ed521a just moving ios server stuff around
koda
parents: 6209
diff changeset
   149
    NSURL *testURL = [NSURL URLWithString:@"http://www.apple.com/"];
6b2d19ed521a just moving ios server stuff around
koda
parents: 6209
diff changeset
   150
    NSURLRequest *testRequest = [NSURLRequest requestWithURL:testURL
6b2d19ed521a just moving ios server stuff around
koda
parents: 6209
diff changeset
   151
                                                 cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
6b2d19ed521a just moving ios server stuff around
koda
parents: 6209
diff changeset
   152
                                             timeoutInterval:20.0];
6b2d19ed521a just moving ios server stuff around
koda
parents: 6209
diff changeset
   153
    NSURLConnection *testConnection = [[NSURLConnection alloc] initWithRequest:testRequest delegate:nil];
6b2d19ed521a just moving ios server stuff around
koda
parents: 6209
diff changeset
   154
    BOOL testResult = testConnection ? YES : NO;
6b2d19ed521a just moving ios server stuff around
koda
parents: 6209
diff changeset
   155
    [testConnection release];
6b2d19ed521a just moving ios server stuff around
koda
parents: 6209
diff changeset
   156
6b2d19ed521a just moving ios server stuff around
koda
parents: 6209
diff changeset
   157
    return ((isReachable && !needsConnection) || nonWiFi) ? testResult : NO;
6b2d19ed521a just moving ios server stuff around
koda
parents: 6209
diff changeset
   158
}
6b2d19ed521a just moving ios server stuff around
koda
parents: 6209
diff changeset
   159
6409
ca93f38a1aab SDL included some of our patches mainstream
koda
parents: 6321
diff changeset
   160
+(UIView *)mainSDLViewInstance {
ca93f38a1aab SDL included some of our patches mainstream
koda
parents: 6321
diff changeset
   161
    SDL_Window *window = HW_getSDLWindow();
ca93f38a1aab SDL included some of our patches mainstream
koda
parents: 6321
diff changeset
   162
    if (window == NULL) {
ca93f38a1aab SDL included some of our patches mainstream
koda
parents: 6321
diff changeset
   163
        SDL_SetError("Window does not exist");
ca93f38a1aab SDL included some of our patches mainstream
koda
parents: 6321
diff changeset
   164
        return nil;
ca93f38a1aab SDL included some of our patches mainstream
koda
parents: 6321
diff changeset
   165
    }
ca93f38a1aab SDL included some of our patches mainstream
koda
parents: 6321
diff changeset
   166
    SDL_WindowData *data = (SDL_WindowData *)window->driverdata;
ca93f38a1aab SDL included some of our patches mainstream
koda
parents: 6321
diff changeset
   167
    SDL_uikitview *view = data != NULL ? data->view : nil;
ca93f38a1aab SDL included some of our patches mainstream
koda
parents: 6321
diff changeset
   168
    return view;
6108
7a8da11a6144 refreshed the ipad interface with some white
koda
parents: 6094
diff changeset
   169
}
7a8da11a6144 refreshed the ipad interface with some white
koda
parents: 6094
diff changeset
   170
7a8da11a6144 refreshed the ipad interface with some white
koda
parents: 6094
diff changeset
   171
@end