From: Kent Sutherland Date: Wed, 29 Oct 2003 06:45:00 +0000 (+0000) Subject: More work done to networking. Bugfixes out the wazoo, but there's still X-Git-Tag: v1.2~42 X-Git-Url: http://git.ithinksw.org/MenuTunes.git/commitdiff_plain/05ed443780b3696c53e100d7eee9ae63c633e22d More work done to networking. Bugfixes out the wazoo, but there's still like 99 left. --- diff --git a/English.lproj/Preferences.nib/classes.nib b/English.lproj/Preferences.nib/classes.nib index 68f916a..cebb794 100755 --- a/English.lproj/Preferences.nib/classes.nib +++ b/English.lproj/Preferences.nib/classes.nib @@ -20,6 +20,7 @@ appearanceEffectPopup = NSPopUpButton; appearanceSpeedSlider = NSSlider; artistCheckbox = NSButton; + clientPasswordTextField = NSTextField; hostTextField = NSTextField; hotKeysTableView = NSTableView; launchAtLoginCheckbox = NSButton; diff --git a/English.lproj/Preferences.nib/info.nib b/English.lproj/Preferences.nib/info.nib index d4a5e32..1c8a9f3 100755 --- a/English.lproj/Preferences.nib/info.nib +++ b/English.lproj/Preferences.nib/info.nib @@ -9,7 +9,7 @@ 634 386 421 380 180 0 0 1152 746 639 - 412 313 380 122 0 0 1152 746 + 386 450 380 122 0 0 1152 746 IBFramework Version 349.0 @@ -20,6 +20,8 @@ IBOpenObjects 6 + 699 + 624 IBSystem Version 7B85 diff --git a/English.lproj/Preferences.nib/keyedobjects.nib b/English.lproj/Preferences.nib/keyedobjects.nib index 7e4be37..e180aca 100755 Binary files a/English.lproj/Preferences.nib/keyedobjects.nib and b/English.lproj/Preferences.nib/keyedobjects.nib differ diff --git a/MainController.m b/MainController.m index aaddc7f..a9e67e9 100755 --- a/MainController.m +++ b/MainController.m @@ -945,18 +945,25 @@ static MainController *sharedController; - (BOOL)connectToServer { + int result; ITDebugLog(@"Attempting to connect to shared remote."); + result = [networkController connectToHost:[df stringForKey:@"sharedPlayerHost"]]; //Connect - if ([networkController connectToHost:[df stringForKey:@"sharedPlayerHost"]]) { + if (result == 1) { currentRemote = [[[networkController networkObject] remote] retain]; [self timerUpdate]; //[refreshTimer invalidate]; ITDebugLog(@"Connection successful."); return YES; - } else { + } else if (result == 0) { ITDebugLog(@"Connection failed."); currentRemote = [remoteArray objectAtIndex:0]; return NO; + } else if (result == -1) { + ITDebugLog(@"Connection failed."); + currentRemote = [remoteArray objectAtIndex:0]; + return NO; + //Do something about the password being invalid } } @@ -977,7 +984,9 @@ static MainController *sharedController; if ([networkController checkForServerAtHost:[df stringForKey:@"sharedPlayerHost"]]) { ITDebugLog(@"Remote server found."); [timer invalidate]; - [[StatusWindowController sharedController] showReconnectQueryWindow]; + if (![networkController isConnectedToServer]) { + [[StatusWindowController sharedController] showReconnectQueryWindow]; + } } else { ITDebugLog(@"Remote server not found."); } @@ -986,9 +995,10 @@ static MainController *sharedController; - (void)networkError:(NSException *)exception { ITDebugLog(@"Remote exception thrown: %@: %@", [exception name], [exception reason]); - if ([[exception name] isEqualToString:NSPortTimeoutException]) { + NSLog(@"%@", [exception reason]); + if ([[exception name] isEqualToString:NSPortTimeoutException] && [networkController isConnectedToServer]) { NSRunCriticalAlertPanel(@"Remote MenuTunes Disconnected", @"The MenuTunes server you were connected to stopped responding or quit. MenuTunes will revert back to the local player.", @"OK", nil, nil); - if ([networkController isConnectedToServer] && [self disconnectFromServer]) { + if ([self disconnectFromServer]) { [NSTimer scheduledTimerWithTimeInterval:45 target:self selector:@selector(checkForRemoteServer:) userInfo:nil repeats:YES]; } else { ITDebugLog(@"CRITICAL ERROR, DISCONNECTING!"); diff --git a/NetworkController.h b/NetworkController.h index ae40030..662e519 100755 --- a/NetworkController.h +++ b/NetworkController.h @@ -36,7 +36,7 @@ - (void)stopRemoteServerSearch; - (void)setServerStatus:(BOOL)status; -- (BOOL)connectToHost:(NSString *)host; +- (int)connectToHost:(NSString *)host; - (BOOL)checkForServerAtHost:(NSString *)host; - (BOOL)disconnect; - (BOOL)isServerOn; diff --git a/NetworkController.m b/NetworkController.m index 230e136..65962ba 100755 --- a/NetworkController.m +++ b/NetworkController.m @@ -112,7 +112,7 @@ static NetworkController *sharedController; } } -- (BOOL)connectToHost:(NSString *)host +- (int)connectToHost:(NSString *)host { NSData *fullPass = [[NSUserDefaults standardUserDefaults] dataForKey:@"connectPassword"]; unsigned char buffer; @@ -150,18 +150,14 @@ static NetworkController *sharedController; if (![clientProxy sendPassword:[[NSUserDefaults standardUserDefaults] dataForKey:@"connectPassword"]]) { ITDebugLog(@"Invalid password!"); [self disconnect]; - if ( NSRunCriticalAlertPanel(@"Invalid Password", @"The MenuTunes server you attempted to connect to rejected your password. Would you like to try to reconnect?.", @"Yes", @"No", nil) == NSOKButton ) { - return [self connectToHost:host]; - } else { - return NO; - } + return -1; } } ITDebugLog(@"Connected to host: %@", host); [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(disconnect) name:NSConnectionDidDieNotification object:clientConnection]; - connectedToServer = YES; - return YES; + connectedToServer = 1; + return 1; } - (BOOL)disconnect diff --git a/PreferencesController.h b/PreferencesController.h index 394934a..9ac7365 100755 --- a/PreferencesController.h +++ b/PreferencesController.h @@ -23,6 +23,7 @@ IBOutlet NSPopUpButton *appearanceEffectPopup; IBOutlet NSSlider *appearanceSpeedSlider; IBOutlet NSButton *artistCheckbox; + IBOutlet NSTextField *clientPasswordTextField; IBOutlet NSTextField *hostTextField; IBOutlet NSTableView *hotKeysTableView; IBOutlet NSButton *launchAtLoginCheckbox; diff --git a/PreferencesController.m b/PreferencesController.m index 96c19e8..f6c6d7b 100755 --- a/PreferencesController.m +++ b/PreferencesController.m @@ -220,9 +220,14 @@ static PreferencesController *prefs = nil; [selectSharedPlayerButton setEnabled:state]; if (state) { + [selectedPlayerTextField setStringValue:[[[NetworkController sharedController] networkObject] serverName]]; + [locationTextField setStringValue:[[NetworkController sharedController] remoteHost]]; [controller connectToServer]; } else { + [selectedPlayerTextField setStringValue:@"No shared player selected."]; + [locationTextField setStringValue:@"-"]; [controller disconnectFromServer]; + } } else if ( [sender tag] == 5050 ) { //Do nothing on table view click @@ -266,11 +271,13 @@ static PreferencesController *prefs = nil; [NSApp endSheet:selectPlayerSheet]; [selectPlayerSheet orderOut:nil]; + [self changeSharingSetting:clientPasswordTextField]; + if ([selectPlayerBox contentView] == manualView) { [df setObject:[hostTextField stringValue] forKey:@"sharedPlayerHost"]; } else { if ([sharingTableView selectedRow] > -1) { - [df setObject:[NSString stringWithCString:inet_ntoa((*(struct sockaddr_in*)[[[[NetworkController sharedController] remoteServices] objectAtIndex:[sharingTableView selectedRow]] bytes]).sin_addr)] forKey:@"sharedPlayerHost"]; + [df setObject:[NSString stringWithCString:inet_ntoa((*(struct sockaddr_in*)[[[[[[NetworkController sharedController] remoteServices] objectAtIndex:[sharingTableView selectedRow]] addresses] objectAtIndex:0] bytes]).sin_addr)] forKey:@"sharedPlayerHost"]; } } diff --git a/libValidate.a b/libValidate.a index 4a42a33..61c6a97 100755 Binary files a/libValidate.a and b/libValidate.a differ