project_files/HedgewarsMobile/Classes/HWUtils.m
branchqmlfrontend
changeset 11408 b894922d58cc
parent 11223 c51ecb9bcf05
child 11559 73e6a3d2f768
--- a/project_files/HedgewarsMobile/Classes/HWUtils.m	Tue Sep 08 19:20:58 2015 +0300
+++ b/project_files/HedgewarsMobile/Classes/HWUtils.m	Mon Nov 16 22:57:24 2015 +0300
@@ -103,23 +103,22 @@
 +(NSInteger) randomPort {
     // set a new feed only at initialization time and forbid connecting to the server port
     if (activePorts == nil) {
-        srandom(time(NULL));
         activePorts = [[NSMutableArray arrayWithObject:[NSNumber numberWithInt:NETGAME_DEFAULT_PORT]] retain];
     }
 
     // pick a random number from the free ports list
     NSInteger res = 0;
     do {
-        res = (random() % 64511) + 1024;
-    } while ([activePorts containsObject:[NSNumber numberWithInt:res]]);
+        res = (arc4random_uniform(64511)) + 1024;
+    } while ([activePorts containsObject:[NSNumber numberWithInteger:res]]);
 
     // add this number to the forbdding list
-    [activePorts addObject:[NSNumber numberWithInt:res]];
+    [activePorts addObject:[NSNumber numberWithInteger:res]];
     return res;
 }
 
 +(void) freePort:(NSInteger) port {
-    [activePorts removeObject:[NSNumber numberWithInt:port]];
+    [activePorts removeObject:[NSNumber numberWithInteger:port]];
 }
 
 +(BOOL) isNetworkReachable {
@@ -156,6 +155,12 @@
     return ((isReachable && !needsConnection) || nonWiFi) ? testResult : NO;
 }
 
++ (NSString *)languageID
+{
+    NSString *language = [[NSLocale preferredLanguages] firstObject];
+    return [[language componentsSeparatedByString:@"-"] firstObject];
+}
+
 /*
 +(UIView *)mainSDLViewInstance {
     SDL_Window *window = HW_getSDLWindow();