More bugfixes in networking. Added password panels. Fixed bug with 0:60 time.
[MenuTunes.git] / NetworkObject.m
1 /*
2  *  MenuTunes
3  *  NetworkObject
4  *    Remote network object that is vended
5  *
6  *  Original Author : Kent Sutherland <ksutherland@ithinksw.com>
7  *   Responsibility : Kent Sutherland <ksutherland@ithinksw.com>
8  *
9  *  Copyright (c) 2002 - 2003 iThink Software.
10  *  All Rights Reserved
11  *
12  *      This header defines the Objective-C protocol which all MenuTunes Remote
13  *  plugins must implement.  To build a remote, create a subclass of this
14  *  object, and implement each method in the @protocol below.
15  *
16  */
17
18 #import "NetworkObject.h"
19 #import "MainController.h"
20 #import <ITMTRemote/ITMTRemote.h>
21
22 @implementation NetworkObject
23
24 - (id)init
25 {
26     if ( (self = [super init]) ) {
27         if (![self requiresPassword]) {
28             _authenticated = YES;
29         } else {
30             _authenticated = NO;
31         }
32     }
33     return self;
34 }
35
36 - (ITMTRemote *)remote
37 {
38     if (_authenticated)
39         return [[MainController sharedController] currentRemote];
40     else
41         return nil;
42 }
43
44 - (NSString *)serverName
45 {
46     NSString *name = [[NSUserDefaults standardUserDefaults] stringForKey:@"sharedPlayerName"];
47     if (!name)
48         name = @"MenuTunes Shared Player";
49     return name;
50 }
51
52 - (BOOL)requiresPassword
53 {
54     return [[NSUserDefaults standardUserDefaults] boolForKey:@"enableSharingPassword"];
55 }
56
57 - (BOOL)sendPassword:(NSData *)password
58 {
59     if ([password isEqualToData:[[NSUserDefaults standardUserDefaults] dataForKey:@"sharedPlayerPassword"]]) {
60         _authenticated = YES;
61         return YES;
62     } else {
63         _authenticated = NO;
64         return NO;
65     }
66 }
67
68 @end