project_files/HedgewarsMobile/Classes/EngineProtocolNetwork.m
changeset 6822 206db098f8c5
parent 6700 e04da46ee43c
child 6832 fae8fd118da9
equal deleted inserted replaced
6821:d4f75843cf5d 6822:206db098f8c5
    18  * File created on 10/01/2010.
    18  * File created on 10/01/2010.
    19  */
    19  */
    20 
    20 
    21 
    21 
    22 #import "EngineProtocolNetwork.h"
    22 #import "EngineProtocolNetwork.h"
    23 #import "OverlayViewController.h"
       
    24 
    23 
    25 
    24 
    26 #define BUFFER_SIZE 255     // like in original frontend
    25 #define BUFFER_SIZE 255     // like in original frontend
    27 
       
    28 static NSInteger activeEnginePort;
       
    29 
    26 
    30 @implementation EngineProtocolNetwork
    27 @implementation EngineProtocolNetwork
    31 @synthesize statsArray, stream, csd, enginePort;
    28 @synthesize statsArray, stream, csd, enginePort;
    32 
    29 
    33 -(id) init {
    30 -(id) init {
    35         self.statsArray = nil;
    32         self.statsArray = nil;
    36         self.csd = NULL;
    33         self.csd = NULL;
    37         self.stream = nil;
    34         self.stream = nil;
    38         self.enginePort = [HWUtils randomPort];
    35         self.enginePort = [HWUtils randomPort];
    39     }
    36     }
    40     activeEnginePort = self.enginePort;
       
    41     return self;
    37     return self;
    42 }
    38 }
    43 
    39 
    44 -(void) dealloc {
    40 -(void) dealloc {
    45     releaseAndNil(statsArray);
    41     releaseAndNil(statsArray);
    55 
    51 
    56     // +detachNewThreadSelector retain/release self automatically
    52     // +detachNewThreadSelector retain/release self automatically
    57     [NSThread detachNewThreadSelector:@selector(engineProtocol:)
    53     [NSThread detachNewThreadSelector:@selector(engineProtocol:)
    58                              toTarget:self
    54                              toTarget:self
    59                            withObject:dictionary];
    55                            withObject:dictionary];
    60 }
       
    61 
       
    62 +(NSInteger) activeEnginePort {
       
    63     return activeEnginePort;
       
    64 }
    56 }
    65 
    57 
    66 #pragma mark -
    58 #pragma mark -
    67 #pragma mark Provider functions
    59 #pragma mark Provider functions
    68 // unpacks team data from the selected team.plist to a sequence of engine commands
    60 // unpacks team data from the selected team.plist to a sequence of engine commands
   400 
   392 
   401     [self.stream close];
   393     [self.stream close];
   402     [self.stream release];
   394     [self.stream release];
   403 
   395 
   404     // Close the client socket
   396     // Close the client socket
       
   397     [HWUtils freePort:self.enginePort];
   405     SDLNet_TCP_Close(csd);
   398     SDLNet_TCP_Close(csd);
   406     SDLNet_Quit();
   399     SDLNet_Quit();
   407 
   400 
   408     [pool release];
   401     [pool release];
   409     // Invoking this method should be avoided as it does not give your thread a chance
   402     // Invoking this method should be avoided as it does not give your thread a chance