author | alfadur |
Wed, 10 Oct 2018 23:54:57 +0300 | |
changeset 13894 | 7984ed53ac3b |
parent 12877 | 00215a7ec5f5 |
permissions | -rw-r--r-- |
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 |
10108
c68cf030eded
update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents:
8835
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
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
|
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 | 23 |
#import <netinet/in.h> |
24 |
#import <SystemConfiguration/SCNetworkReachability.h> |
|
8835 | 25 |
#import "hwconsts.h" |
6832 | 26 |
|
6208
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
6108
diff
changeset
|
27 |
static NSString *cachedModel = nil; |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
6108
diff
changeset
|
28 |
static NSArray *cachedColors = nil; |
6822
206db098f8c5
ios headers cleanup, with tweaks to +randomPort and grenade timer handling in overlay
koda
parents:
6700
diff
changeset
|
29 |
static NSMutableArray *activePorts = nil; |
6208
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
6108
diff
changeset
|
30 |
|
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
|
31 |
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
|
32 |
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
|
33 |
|
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
|
34 |
@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
|
35 |
|
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
|
36 |
#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
|
37 |
#pragma mark game status and type info |
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11559
diff
changeset
|
38 |
+ (TGameType)gameType { |
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
|
39 |
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
|
40 |
} |
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 |
|
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11559
diff
changeset
|
42 |
+ (void)setGameType:(TGameType)type { |
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
|
43 |
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
|
44 |
} |
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 |
|
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11559
diff
changeset
|
46 |
+ (TGameStatus)gameStatus { |
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
|
47 |
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
|
48 |
} |
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 |
|
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11559
diff
changeset
|
50 |
+ (void)setGameStatus:(TGameStatus)status { |
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
|
51 |
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
|
52 |
} |
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 |
|
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11559
diff
changeset
|
54 |
+ (BOOL)isGameLaunched { |
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
|
55 |
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
|
56 |
} |
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 |
|
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11559
diff
changeset
|
58 |
+ (BOOL)isGameRunning { |
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
|
59 |
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
|
60 |
} |
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 |
#pragma mark - |
6409 | 63 |
#pragma mark Helper Functions with cache |
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11559
diff
changeset
|
64 |
+ (NSString *)modelType { |
6208
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
6108
diff
changeset
|
65 |
if (cachedModel == nil) { |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
6108
diff
changeset
|
66 |
size_t size; |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
6108
diff
changeset
|
67 |
// 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
|
68 |
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
|
69 |
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
|
70 |
// get the platform name |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
6108
diff
changeset
|
71 |
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
|
72 |
|
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11559
diff
changeset
|
73 |
cachedModel = [NSString stringWithUTF8String:name]; |
6208
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
6108
diff
changeset
|
74 |
free(name); |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
6108
diff
changeset
|
75 |
} |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
6108
diff
changeset
|
76 |
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
|
77 |
} |
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 |
|
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11559
diff
changeset
|
79 |
+ (NSArray *)teamColors { |
6208
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
6108
diff
changeset
|
80 |
if (cachedColors == nil) { |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
6108
diff
changeset
|
81 |
// 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
|
82 |
unsigned int colors[] = HW_TEAMCOLOR_ARRAY; |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
6108
diff
changeset
|
83 |
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
|
84 |
|
6208
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
6108
diff
changeset
|
85 |
int i = 0; |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
6108
diff
changeset
|
86 |
while(colors[i] != 0) |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
6108
diff
changeset
|
87 |
[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
|
88 |
|
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11559
diff
changeset
|
89 |
cachedColors = [NSArray arrayWithArray:array]; |
6208
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
6108
diff
changeset
|
90 |
} |
b831679e9467
move all extra categories in a single source, add caching for HWUtils
koda
parents:
6108
diff
changeset
|
91 |
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
|
92 |
} |
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
|
93 |
|
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11559
diff
changeset
|
94 |
+ (void)releaseCache { |
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11559
diff
changeset
|
95 |
cachedModel = nil; |
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11559
diff
changeset
|
96 |
cachedColors = nil; |
6822
206db098f8c5
ios headers cleanup, with tweaks to +randomPort and grenade timer handling in overlay
koda
parents:
6700
diff
changeset
|
97 |
// don't release activePorts here |
6409 | 98 |
} |
99 |
||
100 |
#pragma mark - |
|
101 |
#pragma mark Helper Functions without cache |
|
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11559
diff
changeset
|
102 |
+ (NSInteger)randomPort { |
6822
206db098f8c5
ios headers cleanup, with tweaks to +randomPort and grenade timer handling in overlay
koda
parents:
6700
diff
changeset
|
103 |
// 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
|
104 |
if (activePorts == nil) { |
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11559
diff
changeset
|
105 |
activePorts = [NSMutableArray arrayWithObject:[NSNumber numberWithInt:NETGAME_DEFAULT_PORT]]; |
6822
206db098f8c5
ios headers cleanup, with tweaks to +randomPort and grenade timer handling in overlay
koda
parents:
6700
diff
changeset
|
106 |
} |
206db098f8c5
ios headers cleanup, with tweaks to +randomPort and grenade timer handling in overlay
koda
parents:
6700
diff
changeset
|
107 |
|
206db098f8c5
ios headers cleanup, with tweaks to +randomPort and grenade timer handling in overlay
koda
parents:
6700
diff
changeset
|
108 |
// 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
|
109 |
NSInteger res = 0; |
206db098f8c5
ios headers cleanup, with tweaks to +randomPort and grenade timer handling in overlay
koda
parents:
6700
diff
changeset
|
110 |
do { |
11210
2e80c9861818
- Better random number generation for front-end: random() replaced with arc4random_uniform()
antonc27 <antonc27@mail.ru>
parents:
11148
diff
changeset
|
111 |
res = (arc4random_uniform(64511)) + 1024; |
11148
064a53861759
- Refactoring in order to remove some warning related to using of int instead of NSInteger
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
112 |
} while ([activePorts containsObject:[NSNumber numberWithInteger:res]]); |
6822
206db098f8c5
ios headers cleanup, with tweaks to +randomPort and grenade timer handling in overlay
koda
parents:
6700
diff
changeset
|
113 |
|
206db098f8c5
ios headers cleanup, with tweaks to +randomPort and grenade timer handling in overlay
koda
parents:
6700
diff
changeset
|
114 |
// add this number to the forbdding list |
11148
064a53861759
- Refactoring in order to remove some warning related to using of int instead of NSInteger
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
115 |
[activePorts addObject:[NSNumber numberWithInteger:res]]; |
6822
206db098f8c5
ios headers cleanup, with tweaks to +randomPort and grenade timer handling in overlay
koda
parents:
6700
diff
changeset
|
116 |
return res; |
206db098f8c5
ios headers cleanup, with tweaks to +randomPort and grenade timer handling in overlay
koda
parents:
6700
diff
changeset
|
117 |
} |
206db098f8c5
ios headers cleanup, with tweaks to +randomPort and grenade timer handling in overlay
koda
parents:
6700
diff
changeset
|
118 |
|
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11559
diff
changeset
|
119 |
+ (void)freePort:(NSInteger)port { |
11148
064a53861759
- Refactoring in order to remove some warning related to using of int instead of NSInteger
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
120 |
[activePorts removeObject:[NSNumber numberWithInteger:port]]; |
6246 | 121 |
} |
122 |
||
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11559
diff
changeset
|
123 |
+ (BOOL)isNetworkReachable { |
6246 | 124 |
// Create zero addy |
125 |
struct sockaddr_in zeroAddress; |
|
126 |
bzero(&zeroAddress, sizeof(zeroAddress)); |
|
127 |
zeroAddress.sin_len = sizeof(zeroAddress); |
|
128 |
zeroAddress.sin_family = AF_INET; |
|
129 |
||
130 |
// Recover reachability flags |
|
131 |
SCNetworkReachabilityRef defaultRouteReachability = SCNetworkReachabilityCreateWithAddress(NULL, (struct sockaddr *)&zeroAddress); |
|
132 |
SCNetworkReachabilityFlags flags; |
|
133 |
||
134 |
BOOL didRetrieveFlags = SCNetworkReachabilityGetFlags(defaultRouteReachability, &flags); |
|
135 |
CFRelease(defaultRouteReachability); |
|
136 |
||
137 |
if (!didRetrieveFlags) { |
|
138 |
NSLog(@"Error. Could not recover network reachability flags"); |
|
139 |
return NO; |
|
140 |
} |
|
141 |
||
142 |
BOOL isReachable = flags & kSCNetworkFlagsReachable; |
|
143 |
BOOL needsConnection = flags & kSCNetworkFlagsConnectionRequired; |
|
144 |
BOOL nonWiFi = flags & kSCNetworkReachabilityFlagsTransientConnection; |
|
145 |
||
146 |
NSURL *testURL = [NSURL URLWithString:@"http://www.apple.com/"]; |
|
147 |
NSURLRequest *testRequest = [NSURLRequest requestWithURL:testURL |
|
148 |
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData |
|
149 |
timeoutInterval:20.0]; |
|
150 |
NSURLConnection *testConnection = [[NSURLConnection alloc] initWithRequest:testRequest delegate:nil]; |
|
151 |
BOOL testResult = testConnection ? YES : NO; |
|
152 |
||
153 |
return ((isReachable && !needsConnection) || nonWiFi) ? testResult : NO; |
|
154 |
} |
|
155 |
||
11223
c51ecb9bcf05
- Retrieving language ID moved to HWUtils
antonc27 <antonc27@mail.ru>
parents:
11210
diff
changeset
|
156 |
+ (NSString *)languageID |
c51ecb9bcf05
- Retrieving language ID moved to HWUtils
antonc27 <antonc27@mail.ru>
parents:
11210
diff
changeset
|
157 |
{ |
c51ecb9bcf05
- Retrieving language ID moved to HWUtils
antonc27 <antonc27@mail.ru>
parents:
11210
diff
changeset
|
158 |
NSString *language = [[NSLocale preferredLanguages] firstObject]; |
c51ecb9bcf05
- Retrieving language ID moved to HWUtils
antonc27 <antonc27@mail.ru>
parents:
11210
diff
changeset
|
159 |
return [[language componentsSeparatedByString:@"-"] firstObject]; |
c51ecb9bcf05
- Retrieving language ID moved to HWUtils
antonc27 <antonc27@mail.ru>
parents:
11210
diff
changeset
|
160 |
} |
c51ecb9bcf05
- Retrieving language ID moved to HWUtils
antonc27 <antonc27@mail.ru>
parents:
11210
diff
changeset
|
161 |
|
7048
0a4c88935902
the ios port runs again, although with a few things to sort out
koda
parents:
6832
diff
changeset
|
162 |
/* |
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11559
diff
changeset
|
163 |
+ (UIView *)mainSDLViewInstance { |
6409 | 164 |
SDL_Window *window = HW_getSDLWindow(); |
165 |
if (window == NULL) { |
|
166 |
SDL_SetError("Window does not exist"); |
|
167 |
return nil; |
|
168 |
} |
|
169 |
SDL_WindowData *data = (SDL_WindowData *)window->driverdata; |
|
170 |
SDL_uikitview *view = data != NULL ? data->view : nil; |
|
171 |
return view; |
|
6108 | 172 |
} |
7048
0a4c88935902
the ios port runs again, although with a few things to sort out
koda
parents:
6832
diff
changeset
|
173 |
*/ |
6108 | 174 |
|
11559
73e6a3d2f768
- Small refactoring for seed generation on iOS side
antonc27 <antonc27@mail.ru>
parents:
11223
diff
changeset
|
175 |
+ (NSString *)seed |
73e6a3d2f768
- Small refactoring for seed generation on iOS side
antonc27 <antonc27@mail.ru>
parents:
11223
diff
changeset
|
176 |
{ |
73e6a3d2f768
- Small refactoring for seed generation on iOS side
antonc27 <antonc27@mail.ru>
parents:
11223
diff
changeset
|
177 |
CFUUIDRef uuid = CFUUIDCreate(kCFAllocatorDefault); |
12877
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11559
diff
changeset
|
178 |
NSString *seed = (NSString *)CFBridgingRelease(CFUUIDCreateString(kCFAllocatorDefault, uuid)); |
11559
73e6a3d2f768
- Small refactoring for seed generation on iOS side
antonc27 <antonc27@mail.ru>
parents:
11223
diff
changeset
|
179 |
CFRelease(uuid); |
73e6a3d2f768
- Small refactoring for seed generation on iOS side
antonc27 <antonc27@mail.ru>
parents:
11223
diff
changeset
|
180 |
return seed; |
73e6a3d2f768
- Small refactoring for seed generation on iOS side
antonc27 <antonc27@mail.ru>
parents:
11223
diff
changeset
|
181 |
} |
73e6a3d2f768
- Small refactoring for seed generation on iOS side
antonc27 <antonc27@mail.ru>
parents:
11223
diff
changeset
|
182 |
|
6108 | 183 |
@end |