Changeset 1187

Show
Ignore:
Timestamp:
05/16/04 17:21:37 (5 years ago)
Author:
morris
Message:

delay final login till after we've received a 200, so what we can adjust commands according to the server protocol version

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • WiredClient/trunk/WCClient.h

    r1184 r1187  
    1 /* $Id: WCClient.h,v 1.4 2004/05/16 12:27:00 morris Exp $ */ 
     1/* $Id: WCClient.h,v 1.5 2004/05/16 15:21:37 morris Exp $ */ 
    22 
    33/* 
     
    100100- (id)                                                  initWithConnection:(WCConnection *)connection type:(unsigned int)type tracker:(WCTracker *)tracker; 
    101101 
    102 - (void)                                                connectToServer:(NSURL *)url
    103 - (void)                                                connectToTracker:(NSURL *)url
     102- (void)                                                connectToServer
     103- (void)                                                connectToTracker
    104104- (BOOL)                                                connected; 
    105105 
  • WiredClient/trunk/WCClient.m

    r1186 r1187  
    1 /* $Id: WCClient.m,v 1.14 2004/05/16 14:46:41 morris Exp $ */ 
     1/* $Id: WCClient.m,v 1.15 2004/05/16 15:21:37 morris Exp $ */ 
    22 
    33/* 
     
    7878        [[NSNotificationCenter defaultCenter] 
    7979                addObserver:self 
     80                   selector:@selector(connectionGotServerInfo:) 
     81                           name:WCConnectionGotServerInfo 
     82                         object:NULL]; 
     83         
     84        [[NSNotificationCenter defaultCenter] 
     85                addObserver:self 
    8086                   selector:@selector(nickDidChange:) 
    8187                           name:WCNickDidChange 
     
    152158 
    153159 
     160- (void)connectionGotServerInfo:(NSNotification *)notification { 
     161        NSArray                 *fields; 
     162        NSString                *argument, *protocol, *name; 
     163        NSURL                   *url; 
     164        WCConnection    *connection; 
     165         
     166        // --- get objects 
     167        connection      = [[notification object] objectAtIndex:0]; 
     168        argument        = [[notification object] objectAtIndex:1]; 
     169         
     170        if(connection != _connection) 
     171                return; 
     172         
     173        // --- get url 
     174        url = [_connection URL]; 
     175         
     176        // --- separate the fields 
     177        fields          = [argument componentsSeparatedByString:WCFieldSeparator]; 
     178        protocol        = [fields objectAtIndex:1]; 
     179        name            = [fields objectAtIndex:2]; 
     180         
     181        if([_connection type] == WCConnectionTypeServer) { 
     182                // --- check protocol version 
     183                if([protocol doubleValue] > WCServerProtocolVersion) { 
     184                        [[_connection error] setError:WCApplicationErrorProtocolMismatch]; 
     185                        [[_connection error] raiseError]; 
     186                } 
     187                 
     188                // --- set values 
     189                [[_connection server] setName:name]; 
     190                [[_connection server] setProtocol:[protocol doubleValue]]; 
     191                 
     192                // --- rest of login 
     193                [self sendCommand:WCNickCommand withArgument:[WCSettings objectForKey:WCNick]]; 
     194                 
     195                // --- protocol 1.1 
     196                if([[_connection server] protocol] >= 1.1) { 
     197                        [self sendCommand:WCIconCommand withArgument:[NSString stringWithFormat: 
     198                                @"%@%@%@", [WCSettings objectForKey:WCIcon], WCFieldSeparator, @"foo"]]; 
     199                } else { 
     200                        [self sendCommand:WCIconCommand withArgument:[WCSettings objectForKey:WCIcon]]; 
     201                } 
     202 
     203                [self sendCommand:WCClientCommand withArgument:[WCSharedMain clientVersion]]; 
     204                 
     205                [self sendCommand:WCUserCommand withArgument:[[url user] length] > 0 
     206                        ? [[url user] stringByReplacingURLPercentEscapes] 
     207                        : @"guest"]; 
     208                [self sendCommand:WCPassCommand withArgument:[[url password] length] > 0 
     209                        ? [[[url password] stringByReplacingURLPercentEscapes] SHA1] 
     210                        : @""]; 
     211                [self sendCommand:WCPrivilegesCommand]; 
     212                [self sendCommand:WCWhoCommand withArgument:[NSString stringWithFormat:@"%d", 1]]; 
     213                 
     214                if([[WCSettings objectForKey:WCLoadNewsOnLogin] boolValue]) 
     215                        [self sendCommand:WCNewsCommand]; 
     216                 
     217                // --- protocol 1.1 
     218                if([[_connection server] protocol] >= 1.1) 
     219                        [self sendCommand:WCBannerCommand]; 
     220        } 
     221        else if([_connection type] == WCConnectionTypeServer) { 
     222                // --- check protocol version 
     223                if([protocol doubleValue] > WCTrackerProtocolVersion) { 
     224                        [[_connection error] setError:WCApplicationErrorProtocolMismatch]; 
     225                        [[_connection error] raiseError]; 
     226                } 
     227                 
     228                // --- set values 
     229                [[_connection tracker] setName:name]; 
     230                [[_connection tracker] setProtocol:[protocol doubleValue]]; 
     231        } 
     232} 
     233 
     234 
     235 
    154236- (void)nickDidChange:(NSNotification *)notification { 
    155237        [self sendCommand:WCNickCommand withArgument:[WCSettings objectForKey:WCNick]]; 
     
    166248#pragma mark - 
    167249 
    168 - (void)connectToServer:(NSURL *)url
     250- (void)connectToServer
    169251        // --- ping at intervals 
    170252        _timer = [NSTimer scheduledTimerWithTimeInterval:60 
     
    176258         
    177259        // --- fork a client thread 
    178         [NSThread detachNewThreadSelector:@selector(clientThread:) toTarget:self withObject:url]; 
    179 } 
    180  
    181  
    182  
    183 - (void)connectToTracker:(NSURL *)url
     260        [NSThread detachNewThreadSelector:@selector(clientThread:) toTarget:self withObject:NULL]; 
     261} 
     262 
     263 
     264 
     265- (void)connectToTracker
    184266        // --- fork a tracker thread 
    185         [NSThread detachNewThreadSelector:@selector(trackerThread:) toTarget:self withObject:url]; 
     267        [NSThread detachNewThreadSelector:@selector(trackerThread:) toTarget:self withObject:NULL]; 
    186268} 
    187269 
     
    194276 
    195277 
    196 - (void)clientThread:(NSURL *)url
     278- (void)clientThread:(id)arg
    197279        NSAutoreleasePool       *pool; 
     280        NSURL                           *url; 
    198281        int                                     bytes; 
    199282         
    200283        // --- create a pool 
    201284        pool = [[NSAutoreleasePool alloc] init]; 
     285         
     286        // --- get url 
     287        url = [_connection URL]; 
    202288 
    203289        // --- connect to the host 
     
    214300        } 
    215301         
    216         // --- login 
     302        // --- initial login 
    217303        [self sendCommand:WCHelloCommand]; 
    218         [self sendCommand:WCNickCommand withArgument:[WCSettings objectForKey:WCNick]]; 
    219         [self sendCommand:WCIconCommand withArgument:[WCSettings objectForKey:WCIcon]]; 
    220         [self sendCommand:WCClientCommand withArgument:[WCSharedMain clientVersion]]; 
    221  
    222         [self sendCommand:WCUserCommand withArgument:[[url user] length] > 0 
    223                 ? [[url user] stringByReplacingURLPercentEscapes] 
    224                 : @"guest"]; 
    225         [self sendCommand:WCPassCommand withArgument:[[url password] length] > 0 
    226                 ? [[[url password] stringByReplacingURLPercentEscapes] SHA1] 
    227                 : @""]; 
    228         [self sendCommand:WCPrivilegesCommand]; 
    229         [self sendCommand:WCWhoCommand withArgument:[NSString stringWithFormat:@"%d", 1]]; 
    230  
    231         if([[WCSettings objectForKey:WCLoadNewsOnLogin] boolValue]) 
    232                 [self sendCommand:WCNewsCommand]; 
    233304 
    234305        // --- start reading from server 
     
    250321 
    251322 
    252 - (void)trackerThread:(NSURL *)url
     323- (void)trackerThread:(id)arg
    253324        NSAutoreleasePool       *pool; 
     325        NSURL                           *url; 
    254326        int                                     bytes; 
    255327         
    256328        // --- create a pool 
    257329        pool = [[NSAutoreleasePool alloc] init]; 
     330         
     331        // --- get url 
     332        url = [_connection URL]; 
    258333         
    259334        // --- connect to the host 
     
    368443 
    369444 
    370 - (void)sendCommand:(NSString *)command withArgument:(NSString *)argument { 
     445- (void)sendCommand:(NSString *)command withArgument:(id)argument { 
    371446        NSString        *string; 
    372447         
  • WiredClient/trunk/WCConnection.h

    r1155 r1187  
    1 /* $Id: WCConnection.h,v 1.5 2004/05/13 17:58:09 morris Exp $ */ 
     1/* $Id: WCConnection.h,v 1.6 2004/05/16 15:21:37 morris Exp $ */ 
    22 
    33/* 
     
    4848        WCTracker                                               *_tracker; 
    4949         
     50        unsigned int                                    _type; 
    5051        unsigned int                                    _uid; 
    5152} 
    5253 
    5354 
    54 #define                                                         WCProtocolVersion                                       1.1 
     55#define                                                         WCServerProtocolVersion                         1.1 
     56#define                                                         WCTrackerProtocolVersion                        1.0 
     57 
     58#define                                                         WCConnectionTypeServer                          0 
     59#define                                                         WCConnectionTypeTracker                         1 
    5560 
    5661#define                                                         WCConnectionHasAttached                         @"WCConnectionHasAttached" 
     
    8085- (WCTransfers *)                                       transfers; 
    8186 
     87- (unsigned int)                                        type; 
    8288- (WCCache *)                                           cache; 
    8389- (WCServer *)                                          server; 
  • WiredClient/trunk/WCConnection.m

    r1155 r1187  
    1 /* $Id: WCConnection.m,v 1.8 2004/05/13 17:58:09 morris Exp $ */ 
     1/* $Id: WCConnection.m,v 1.9 2004/05/16 15:21:37 morris Exp $ */ 
    22 
    33/* 
     
    5858        self = [super init]; 
    5959         
     60        // --- set type 
     61        _type           = WCConnectionTypeServer; 
     62         
    6063        // --- initate cache 
    6164        _cache          = [[WCCache alloc] initWithCount:100]; 
     
    100103        [[NSNotificationCenter defaultCenter] 
    101104                addObserver:self 
    102                    selector:@selector(connectionGotServerInfo:) 
    103                            name:WCConnectionGotServerInfo 
    104                          object:NULL]; 
    105          
    106         [[NSNotificationCenter defaultCenter] 
    107                 addObserver:self 
    108105                   selector:@selector(connectionGotPrivileges:) 
    109106                           name:WCConnectionGotPrivileges 
     
    111108         
    112109        // --- start connection 
    113         [_client connectToServer:url]; 
     110        [_client connectToServer]; 
    114111 
    115112        return self; 
     
    120117- (id)initTrackerConnectionWithURL:(NSURL *)url tracker:(WCTracker *)tracker { 
    121118        self = [super init]; 
     119         
     120        // --- set type 
     121        _type           = WCConnectionTypeTracker; 
    122122         
    123123        // --- get parameters 
     
    136136 
    137137        // --- start connection 
    138         [_client connectToTracker:url]; 
     138        [_client connectToTracker]; 
    139139         
    140140        return self; 
     
    183183 
    184184 
    185 - (void)connectionGotServerInfo:(NSNotification *)notification { 
    186         NSArray                 *fields; 
    187         NSString                *argument, *protocol, *name; 
     185- (void)connectionGotPrivileges:(NSNotification *)notification { 
     186        NSString                *argument; 
    188187        WCConnection    *connection; 
    189188         
     
    195194                return; 
    196195         
    197         // --- separate the fields 
    198         fields          = [argument componentsSeparatedByString:WCFieldSeparator]; 
    199         protocol        = [fields objectAtIndex:1]; 
    200         name            = [fields objectAtIndex:2]; 
    201          
    202         // --- check protocol version 
    203         if([protocol doubleValue] > WCProtocolVersion) { 
    204                 [[self error] setError:WCApplicationErrorProtocolMismatch]; 
    205                 [[self error] raiseError]; 
    206         } 
    207          
    208         // --- set values 
    209         [_server setName:name]; 
    210         [_server setProtocol:[protocol doubleValue]]; 
    211 } 
    212  
    213  
    214  
    215 - (void)connectionGotPrivileges:(NSNotification *)notification { 
    216         NSString                *argument; 
    217         WCConnection    *connection; 
    218          
    219         // --- get objects 
    220         connection      = [[notification object] objectAtIndex:0]; 
    221         argument        = [[notification object] objectAtIndex:1]; 
    222          
    223         if(connection != self) 
    224                 return; 
    225          
    226196        // --- set privileges 
    227197        [[_server account] setPrivileges:[argument componentsSeparatedByString:WCFieldSeparator]]; 
     
    305275#pragma mark - 
    306276 
     277- (unsigned int)type { 
     278        return _type; 
     279} 
     280 
     281 
     282 
    307283- (WCCache *)cache { 
    308284        return _cache; 
  • WiredClient/trunk/WCServerInfo.m

    r1186 r1187  
    1 /* $Id: WCServerInfo.m,v 1.10 2004/05/16 14:46:41 morris Exp $ */ 
     1/* $Id: WCServerInfo.m,v 1.11 2004/05/16 15:21:37 morris Exp $ */ 
    22 
    33/* 
     
    220220        rect.size.height = _last + 109; 
    221221        [[self window] setContentSize:rect.size]; 
    222  
    223         // --- protocol 1.1 
    224         if([protocol doubleValue] >= 1.1) 
    225                 [[_connection client] sendCommand:WCBannerCommand]; 
    226222         
    227223} 
  • WiredClient/trunk/WCTracker.h

    r1170 r1187  
    1 /* $Id: WCTracker.h,v 1.5 2004/05/16 03:52:00 morris Exp $ */ 
     1/* $Id: WCTracker.h,v 1.6 2004/05/16 15:21:37 morris Exp $ */ 
    22 
    33/* 
     
    4141        NSNetService                    *_service; 
    4242        NSURL                                   *_url; 
     43        double                                  _protocol; 
    4344        NSMutableArray                  *_children; 
    4445} 
     
    9596- (void)                                        setURL:(NSURL *)value; 
    9697- (NSURL *)                                     URL; 
     98 
     99- (void)                                        setProtocol:(double)value; 
     100- (double)                                      protocol; 
    97101         
    98102- (void)                                        addChild:(WCTracker *)child; 
  • WiredClient/trunk/WCTracker.m

    r1109 r1187  
    1 /* $Id: WCTracker.m,v 1.4 2004/03/29 02:12:52 morris Exp $ */ 
     1/* $Id: WCTracker.m,v 1.5 2004/05/16 15:21:37 morris Exp $ */ 
    22 
    33/* 
     
    7777        [coder decodeValueOfObjCType:@encode(unsigned int) at:&_files]; 
    7878        [coder decodeValueOfObjCType:@encode(unsigned long long) at:&_size]; 
     79        [coder decodeValueOfObjCType:@encode(unsigned int) at:&_protocol]; 
    7980 
    8081        _name                   = [[coder decodeObject] retain]; 
     
    9899        [coder encodeValueOfObjCType:@encode(unsigned int) at:&_files]; 
    99100        [coder encodeValueOfObjCType:@encode(unsigned long long) at:&_size]; 
     101        [coder encodeValueOfObjCType:@encode(unsigned int) at:&_protocol]; 
    100102         
    101103        [coder encodeObject:_name]; 
     
    298300- (NSURL *)URL { 
    299301        return _url; 
     302} 
     303 
     304 
     305 
     306#pragma mark - 
     307 
     308- (void)setProtocol:(double)value { 
     309        _protocol = value; 
     310} 
     311 
     312 
     313 
     314- (double)protocol { 
     315        return _protocol; 
    300316} 
    301317