Changeset 1232

Show
Ignore:
Timestamp:
05/18/04 18:46:01 (5 years ago)
Author:
morris
Message:

add support for STATUS command

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • WiredClient/trunk/WCChat.m

    r1229 r1232  
    1 /* $Id: WCChat.m,v 1.36 2004/05/18 00:48:05 morris Exp $ */ 
     1/* $Id: WCChat.m,v 1.37 2004/05/18 16:46:00 morris Exp $ */ 
    22 
    33/* 
     
    194194 
    195195- (void)chatShouldAddUser:(NSNotification *)notification { 
    196         NSString                *argument, *cid, *uid, *idle, *admin, *icon, *nick, *login, *address, *host, *image = NULL; 
     196        NSString                *argument, *cid, *uid, *idle, *admin, *icon, *nick, *login, *address, *host, *status = NULL, *image = NULL; 
    197197        NSArray                 *fields; 
    198198        NSData                  *data; 
     
    222222        // --- protocol 1.1 
    223223        if([_connection protocol] >= 1.1) { 
    224                 image = [fields objectAtIndex:9]; 
     224                status  = [fields objectAtIndex:9]; 
     225                image   = [fields objectAtIndex:10]; 
    225226        } 
    226227         
     
    242243        // --- protocol 1.1 
    243244        if([_connection protocol] >= 1.1) { 
     245                // --- set status 
     246                [user setStatus:status]; 
     247                 
    244248                // --- decode data 
    245249                data = [NSData dataWithBase64EncodedString:image]; 
     
    418422 
    419423- (void)userHasChanged:(NSNotification *)notification { 
    420         NSString                *argument, *uid, *idle, *admin, *icon, *nick, *image
     424        NSString                *argument, *uid, *idle, *admin, *icon, *nick, *status = NULL, *image = NULL
    421425        NSArray                 *fields; 
    422426        NSData                  *data; 
     
    442446        // --- protocol 1.1 
    443447        if([_connection protocol] >= 1.1) { 
    444                 image = [fields objectAtIndex:5]; 
     448                status  = [fields objectAtIndex:5]; 
     449                image   = [fields objectAtIndex:6]; 
    445450        } 
    446451         
     
    467472        // --- protocol 1.1 
    468473        if([_connection protocol] >= 1.1) { 
     474                // --- set status 
     475                [user setStatus:status]; 
     476                 
    469477                // --- decode data 
    470478                data = [NSData dataWithBase64EncodedString:image]; 
     
    13301338                return YES; 
    13311339        } 
     1340        else if([command isEqualToString:@"/status"] && [argument length] > 0) { 
     1341                [[_connection client] sendCommand:WCStatusCommand withArgument:argument]; 
     1342                 
     1343                return YES; 
     1344        } 
    13321345        else if([command isEqualToString:@"/stats"]) { 
    13331346                [[_connection client] sendCommand:WCSayCommand withArgument:[NSString stringWithFormat: 
  • WiredClient/trunk/WCClient.h

    r1197 r1232  
    1 /* $Id: WCClient.h,v 1.6 2004/05/17 11:14:40 morris Exp $ */ 
     1/* $Id: WCClient.h,v 1.7 2004/05/18 16:46:01 morris Exp $ */ 
    22 
    33/* 
     
    9191#define                                                 WCServersCommand                @"SERVERS" 
    9292#define                                                 WCStatCommand                   @"STAT" 
     93#define                                                 WCStatusCommand                 @"STATUS" 
    9394#define                                                 WCTransferCommand               @"TRANSFER" 
    9495#define                                                 WCUserCommand                   @"USER" 
  • WiredClient/trunk/WCClient.m

    r1222 r1232  
    1 /* $Id: WCClient.m,v 1.19 2004/05/17 23:57:49 morris Exp $ */ 
     1/* $Id: WCClient.m,v 1.20 2004/05/18 16:46:01 morris Exp $ */ 
    22 
    33/* 
     
    7777                         object:NULL]; 
    7878         
    79         [[NSNotificationCenter defaultCenter] 
    80                 addObserver:self 
    81                    selector:@selector(connectionGotServerInfo:) 
    82                            name:WCConnectionGotServerInfo 
    83                          object:NULL]; 
    84          
    85         [[NSNotificationCenter defaultCenter] 
    86                 addObserver:self 
    87                    selector:@selector(nickDidChange:) 
    88                            name:WCNickDidChange 
    89                          object:NULL]; 
    90          
    91         [[NSNotificationCenter defaultCenter] 
    92                 addObserver:self 
    93                    selector:@selector(iconDidChange:) 
    94                            name:WCIconDidChange 
    95                          object:NULL]; 
     79        if([_connection type] == WCConnectionTypeServer) { 
     80                [[NSNotificationCenter defaultCenter] 
     81                        addObserver:self 
     82                           selector:@selector(connectionGotServerInfo:) 
     83                                   name:WCConnectionGotServerInfo 
     84                                 object:NULL]; 
     85                 
     86                [[NSNotificationCenter defaultCenter] 
     87                        addObserver:self 
     88                           selector:@selector(nickDidChange:) 
     89                                   name:WCNickDidChange 
     90                                 object:NULL]; 
     91                 
     92                [[NSNotificationCenter defaultCenter] 
     93                        addObserver:self 
     94                           selector:@selector(iconDidChange:) 
     95                                   name:WCIconDidChange 
     96                                 object:NULL]; 
     97        } 
     98        else if([_connection type] == WCConnectionTypeTracker) { 
     99                [[NSNotificationCenter defaultCenter] 
     100                        addObserver:self 
     101                           selector:@selector(connectionGotTrackerInfo:) 
     102                                   name:WCConnectionGotTrackerInfo 
     103                                 object:NULL]; 
     104        } 
    96105 
    97106        return self; 
     
    180189        name            = [fields objectAtIndex:2]; 
    181190         
    182         if([_connection type] == WCConnectionTypeServer) { 
    183                 // --- check protocol version 
    184                 if([protocol doubleValue] > WCServerProtocolVersion) { 
    185                         [[_connection error] setError:WCApplicationErrorProtocolMismatch]; 
    186                         [[_connection error] raiseError]; 
    187                 } 
    188                  
    189                 // --- set values 
    190                 [[_connection server] setName:name]; 
    191                 [[_connection server] setProtocol:[protocol doubleValue]]; 
    192                  
    193                 // --- rest of login 
    194                 [self sendCommand:WCNickCommand withArgument:[WCSettings objectForKey:WCNick]]; 
    195                  
    196                 // --- protocol 1.1 
    197                 if([[_connection server] protocol] >= 1.1) { 
    198                         [self sendCommand:WCIconCommand withArgument:[NSString stringWithFormat: 
    199                                 @"%@%@%@", 
    200                                 [WCSettings objectForKey:WCIcon], 
    201                                 WCFieldSeparator, 
    202                                 [WCSettings objectForKey:WCCustomIcon]]]; 
    203                 } else { 
    204                         [self sendCommand:WCIconCommand withArgument:[WCSettings objectForKey:WCIcon]]; 
    205                 } 
    206  
    207                 [self sendCommand:WCClientCommand withArgument:[WCSharedMain clientVersion]]; 
    208                  
    209                 [self sendCommand:WCUserCommand withArgument:[[url user] length] > 0 
    210                         ? [[url user] stringByReplacingURLPercentEscapes] 
    211                         : @"guest"]; 
    212                 [self sendCommand:WCPassCommand withArgument:[[url password] length] > 0 
    213                         ? [[[url password] stringByReplacingURLPercentEscapes] SHA1] 
    214                         : @""]; 
    215                 [self sendCommand:WCPrivilegesCommand]; 
    216                 [self sendCommand:WCWhoCommand withArgument:[NSString stringWithFormat:@"%d", 1]]; 
    217                  
    218                 if([[WCSettings objectForKey:WCLoadNewsOnLogin] boolValue]) 
    219                         [self sendCommand:WCNewsCommand]; 
    220                  
    221                 // --- protocol 1.1 
    222                 if([[_connection server] protocol] >= 1.1) 
    223                         [self sendCommand:WCBannerCommand]; 
    224         } 
    225         else if([_connection type] == WCConnectionTypeServer) { 
    226                 // --- check protocol version 
    227                 if([protocol doubleValue] > WCTrackerProtocolVersion) { 
    228                         [[_connection error] setError:WCApplicationErrorProtocolMismatch]; 
    229                         [[_connection error] raiseError]; 
    230                 } 
    231                  
    232                 // --- set values 
    233                 [[_connection tracker] setName:name]; 
    234                 [[_connection tracker] setProtocol:[protocol doubleValue]]; 
     191        // --- check protocol version 
     192        if([protocol doubleValue] > WCServerProtocolVersion) { 
     193                [[_connection error] setError:WCApplicationErrorProtocolMismatch]; 
     194                [[_connection error] raiseError]; 
     195        } 
     196         
     197        // --- set values 
     198        [[_connection server] setName:name]; 
     199        [[_connection server] setProtocol:[protocol doubleValue]]; 
     200         
     201        // --- rest of login 
     202        [self sendCommand:WCNickCommand withArgument:[WCSettings objectForKey:WCNick]]; 
     203         
     204        // --- protocol 1.1 
     205        if([[_connection server] protocol] >= 1.1) { 
     206                [self sendCommand:WCIconCommand withArgument:[NSString stringWithFormat: 
     207                        @"%@%@%@", 
     208                        [WCSettings objectForKey:WCIcon], 
     209                        WCFieldSeparator, 
     210                        [WCSettings objectForKey:WCCustomIcon]]]; 
     211                [self sendCommand:WCStatusCommand withArgument:@"hi"]; 
     212        } else { 
     213                [self sendCommand:WCIconCommand withArgument:[WCSettings objectForKey:WCIcon]]; 
     214        } 
     215 
     216        [self sendCommand:WCClientCommand withArgument:[WCSharedMain clientVersion]]; 
     217         
     218        [self sendCommand:WCUserCommand withArgument:[[url user] length] > 0 
     219                ? [[url user] stringByReplacingURLPercentEscapes] 
     220                : @"guest"]; 
     221        [self sendCommand:WCPassCommand withArgument:[[url password] length] > 0 
     222                ? [[[url password] stringByReplacingURLPercentEscapes] SHA1] 
     223                : @""]; 
     224        [self sendCommand:WCPrivilegesCommand]; 
     225        [self sendCommand:WCWhoCommand withArgument:[NSString stringWithFormat:@"%d", 1]]; 
     226         
     227        if([[WCSettings objectForKey:WCLoadNewsOnLogin] boolValue]) 
     228                [self sendCommand:WCNewsCommand]; 
     229         
     230        // --- protocol 1.1 
     231        if([[_connection server] protocol] >= 1.1) 
     232                [self sendCommand:WCBannerCommand]; 
     233
     234 
     235 
     236 
     237- (void)connectionGotTrackerInfo:(NSNotification *)notification { 
     238        NSArray                 *fields; 
     239        NSString                *argument, *protocol, *name; 
     240        WCConnection    *connection; 
     241         
     242        // --- get objects 
     243        connection      = [[notification object] objectAtIndex:0]; 
     244        argument        = [[notification object] objectAtIndex:1]; 
     245         
     246        if(connection != _connection) 
     247                return; 
     248         
     249        // --- separate the fields 
     250        fields          = [argument componentsSeparatedByString:WCFieldSeparator]; 
     251        protocol        = [fields objectAtIndex:1]; 
     252        name            = [fields objectAtIndex:2]; 
     253         
     254        // --- set values 
     255        [[_connection tracker] setName:name]; 
     256        [[_connection tracker] setProtocol:[protocol doubleValue]]; 
     257         
     258        // --- check protocol version 
     259        if([[_connection tracker] protocol] > WCTrackerProtocolVersion) { 
     260                [[_connection error] setError:WCApplicationErrorProtocolMismatch]; 
     261                [[_connection error] raiseError]; 
    235262        } 
    236263} 
     
    478505        switch(message) { 
    479506                case 200: 
    480                         [[NSNotificationCenter defaultCenter] 
    481                                 mainThreadPostNotificationName:WCConnectionGotServerInfo 
    482                                 object:[NSArray arrayWithObjects:_connection, argument, NULL]]; 
     507                        if([_connection type] == WCConnectionTypeServer) { 
     508                                [[NSNotificationCenter defaultCenter] 
     509                                        mainThreadPostNotificationName:WCConnectionGotServerInfo 
     510                                        object:[NSArray arrayWithObjects:_connection, argument, NULL]]; 
     511                        } 
     512                        else if([_connection type] == WCConnectionTypeTracker) { 
     513                                [[NSNotificationCenter defaultCenter] 
     514                                        mainThreadPostNotificationName:WCConnectionGotTrackerInfo 
     515                                        object:[NSArray arrayWithObjects:_connection, argument, NULL]]; 
     516                        } 
    483517                        break; 
    484518                         
  • WiredClient/trunk/WCConnection.h

    r1187 r1232  
    1 /* $Id: WCConnection.h,v 1.6 2004/05/16 15:21:37 morris Exp $ */ 
     1/* $Id: WCConnection.h,v 1.7 2004/05/18 16:46:01 morris Exp $ */ 
    22 
    33/* 
     
    6868#define                                                         WCConnectionPrivilegesDidChange         @"WCConnectionPrivilegesDidChange" 
    6969 
     70#define                                                         WCConnectionGotTrackerInfo                      @"WCConnectionGotTrackerInfo" 
     71 
    7072 
    7173- (id)                                                          initServerConnectionWithURL:(NSURL *)url; 
  • WiredClient/trunk/WCUser.h

    r1214 r1232  
    1 /* $Id: WCUser.h,v 1.4 2004/05/17 18:29:56 morris Exp $ */ 
     1/* $Id: WCUser.h,v 1.5 2004/05/18 16:46:01 morris Exp $ */ 
    22 
    33/* 
     
    3636        NSString                                *_address; 
    3737        NSString                                *_host; 
     38        NSString                                *_status; 
     39        NSImage                                 *_iconImage; 
    3840        NSDate                                  *_joinTime; 
    39         NSImage                                 *_iconImage; 
    4041} 
    4142 
     
    6667- (NSString *)                          host; 
    6768 
     69- (void)                                        setStatus:(NSString *)value; 
     70- (NSString *)                          status; 
     71 
    6872- (void)                                        setJoinTime:(NSDate *)value; 
    6973- (NSDate *)                            joinTime; 
  • WiredClient/trunk/WCUser.m

    r1220 r1232  
    1 /* $Id: WCUser.m,v 1.6 2004/05/17 23:06:06 morris Exp $ */ 
     1/* $Id: WCUser.m,v 1.7 2004/05/18 16:46:00 morris Exp $ */ 
    22 
    33/* 
     
    6161        _address        = [[coder decodeObject] retain]; 
    6262        _host           = [[coder decodeObject] retain]; 
     63        _status         = [[coder decodeObject] retain]; 
     64        _iconImage      = [[coder decodeObject] retain]; 
    6365        _joinTime       = [[coder decodeObject] retain]; 
    64         _iconImage      = [[coder decodeObject] retain]; 
    6566         
    6667        return self; 
     
    7980        [coder encodeObject:_address]; 
    8081        [coder encodeObject:_host]; 
     82        [coder encodeObject:_status]; 
     83        [coder encodeObject:_iconImage]; 
    8184        [coder encodeObject:_joinTime]; 
    82         [coder encodeObject:_iconImage]; 
    8385} 
    8486 
     
    221223- (NSString *)host { 
    222224        return _host; 
     225} 
     226 
     227 
     228 
     229#pragma mark - 
     230 
     231- (void)setStatus:(NSString *)value { 
     232        [value retain]; 
     233        [_status release]; 
     234         
     235        _status = value; 
     236} 
     237 
     238 
     239 
     240- (NSString *)status { 
     241        return _status; 
    223242} 
    224243