+- (BOOL)checkForServerAtHost:(NSString *)host
+{
+ NSData *fullPass = [[NSUserDefaults standardUserDefaults] dataForKey:@"connectPassword"];
+ unsigned char buffer;
+ NSConnection *testConnection = nil;
+ NSSocketPort *testPort = nil;
+ NetworkObject *tempProxy;
+ BOOL valid;
+ ITDebugLog(@"Checking for shared remote at %@.", host);
+ if (fullPass) {
+ [fullPass getBytes:&buffer range:NSMakeRange(6, 4)];
+ [clientPass release];
+ clientPass = [[NSData alloc] initWithBytes:&buffer length:strlen(&buffer)];
+ } else {
+ clientPass = nil;
+ }
+
+ NS_DURING
+ testPort = [[NSSocketPort alloc] initRemoteWithTCPPort:SERVER_PORT
+ host:host];
+ testConnection = [[NSConnection connectionWithReceivePort:nil sendPort:testPort] retain];
+ [testConnection setReplyTimeout:5];
+ [testConnection setRequestTimeout:5];
+ tempProxy = (NetworkObject *)[testConnection rootProxy];
+ [tempProxy serverName];
+ valid = [tempProxy isValid];
+ NS_HANDLER
+ ITDebugLog(@"Connection to host failed: %@", host);
+ [testConnection release];
+ [testPort release];
+ return NO;
+ NS_ENDHANDLER
+
+ if (!tempProxy) {
+ ITDebugLog(@"Null proxy! Couldn't connect!");
+ [testConnection release];
+ [testPort release];
+ return NO;
+ }
+ [testConnection release];
+ [testPort release];
+ return valid;
+}
+
+- (void)resetServerName
+{
+ if ([self isServerOn]) {
+ [service stop];
+ [service release];
+ service = [[NSNetService alloc] initWithDomain:@""
+ type:@"_mttp._tcp."
+ name:[[NSUserDefaults standardUserDefaults] stringForKey:@"sharedPlayerName"]
+ port:SERVER_PORT];
+ }
+}
+