project_files/HedgewarsMobile/Classes/HWUtils.m
changeset 6321 5a0416e5a6de
parent 6262 32a032f1b178
child 6409 ca93f38a1aab
equal deleted inserted replaced
6320:238a6dc0e7ad 6321:5a0416e5a6de
    23 #import <sys/types.h>
    23 #import <sys/types.h>
    24 #import <sys/sysctl.h>
    24 #import <sys/sysctl.h>
    25 #import <netinet/in.h>
    25 #import <netinet/in.h>
    26 #import <SystemConfiguration/SCNetworkReachability.h>
    26 #import <SystemConfiguration/SCNetworkReachability.h>
    27 #import "hwconsts.h"
    27 #import "hwconsts.h"
       
    28 #import "EngineProtocolNetwork.h"
    28 
    29 
    29 static NSString *cachedModel = nil;
    30 static NSString *cachedModel = nil;
    30 static NSArray *cachedColors = nil;
    31 static NSArray *cachedColors = nil;
    31 
    32 
    32 static TGameType gameType = gtNone;
    33 static TGameType gameType = gtNone;
    94 }
    95 }
    95 
    96 
    96 +(NSInteger) randomPort {
    97 +(NSInteger) randomPort {
    97     srandom(time(NULL));
    98     srandom(time(NULL));
    98     NSInteger res = (random() % 64511) + 1024;
    99     NSInteger res = (random() % 64511) + 1024;
    99     return (res == NETGAME_DEFAULT_PORT) ? [HWUtils randomPort] : res;
   100     // recall self until you get a free port
       
   101     if (res == NETGAME_DEFAULT_PORT || res == [EngineProtocolNetwork activeEnginePort])
       
   102         return [self randomPort];
       
   103     else
       
   104         return res;
   100 }
   105 }
   101 
   106 
   102 +(BOOL) isNetworkReachable {
   107 +(BOOL) isNetworkReachable {
   103     // Create zero addy
   108     // Create zero addy
   104     struct sockaddr_in zeroAddress;
   109     struct sockaddr_in zeroAddress;