+- (void)checkForRemoteServer
+{
+ [self checkForRemoteServerAndConnectImmediately:NO];
+}
+
+- (void)checkForRemoteServerAndConnectImmediately:(BOOL)connectImmediately
+{
+ ITDebugLog(@"Checking for remote server.");
+ if (!_checkingForServer) {
+ if (!_serverCheckLock) {
+ _serverCheckLock = [[NSLock alloc] init];
+ }
+ [_serverCheckLock lock];
+ _checkingForServer = YES;
+ [_serverCheckLock unlock];
+ [NSThread detachNewThreadSelector:@selector(runRemoteServerCheck:) toTarget:self withObject:[NSNumber numberWithBool:connectImmediately]];
+ }
+}
+
+- (void)runRemoteServerCheck:(id)sender
+{
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ ITDebugLog(@"Remote server check running.");
+ if ([networkController checkForServerAtHost:[df stringForKey:@"sharedPlayerHost"]]) {
+ ITDebugLog(@"Remote server found.");
+ if ([sender boolValue]) {
+ [self performSelectorOnMainThread:@selector(connectToServer) withObject:nil waitUntilDone:NO];
+ } else {
+ [self performSelectorOnMainThread:@selector(remoteServerFound:) withObject:nil waitUntilDone:NO];
+ }
+ } else {
+ ITDebugLog(@"Remote server not found.");
+ [self performSelectorOnMainThread:@selector(remoteServerNotFound:) withObject:nil waitUntilDone:NO];
+ }
+ [_serverCheckLock lock];
+ _checkingForServer = NO;
+ [_serverCheckLock unlock];
+ [pool release];
+}
+
+- (void)remoteServerFound:(id)sender
+{
+ if (![networkController isServerOn] && ![networkController isConnectedToServer]) {
+ [[StatusWindowController sharedController] showReconnectQueryWindow];
+ }
+}
+
+- (void)remoteServerNotFound:(id)sender
+{
+ if (![[NetworkController sharedController] isConnectedToServer]) {
+ [NSTimer scheduledTimerWithTimeInterval:90.0 target:self selector:@selector(checkForRemoteServer) userInfo:nil repeats:NO];
+ }
+}
+