Changeset 1187
- Timestamp:
- 05/16/04 17:21:37 (5 years ago)
- Files:
-
- WiredClient/trunk/WCClient.h (modified) (2 diffs)
- WiredClient/trunk/WCClient.m (modified) (9 diffs)
- WiredClient/trunk/WCConnection.h (modified) (3 diffs)
- WiredClient/trunk/WCConnection.m (modified) (9 diffs)
- WiredClient/trunk/WCServerInfo.m (modified) (2 diffs)
- WiredClient/trunk/WCTracker.h (modified) (3 diffs)
- WiredClient/trunk/WCTracker.m (modified) (4 diffs)
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:00morris Exp $ */1 /* $Id: WCClient.h,v 1.5 2004/05/16 15:21:37 morris Exp $ */ 2 2 3 3 /* … … 100 100 - (id) initWithConnection:(WCConnection *)connection type:(unsigned int)type tracker:(WCTracker *)tracker; 101 101 102 - (void) connectToServer :(NSURL *)url;103 - (void) connectToTracker :(NSURL *)url;102 - (void) connectToServer; 103 - (void) connectToTracker; 104 104 - (BOOL) connected; 105 105 WiredClient/trunk/WCClient.m
r1186 r1187 1 /* $Id: WCClient.m,v 1.1 4 2004/05/16 14:46:41morris Exp $ */1 /* $Id: WCClient.m,v 1.15 2004/05/16 15:21:37 morris Exp $ */ 2 2 3 3 /* … … 78 78 [[NSNotificationCenter defaultCenter] 79 79 addObserver:self 80 selector:@selector(connectionGotServerInfo:) 81 name:WCConnectionGotServerInfo 82 object:NULL]; 83 84 [[NSNotificationCenter defaultCenter] 85 addObserver:self 80 86 selector:@selector(nickDidChange:) 81 87 name:WCNickDidChange … … 152 158 153 159 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 154 236 - (void)nickDidChange:(NSNotification *)notification { 155 237 [self sendCommand:WCNickCommand withArgument:[WCSettings objectForKey:WCNick]]; … … 166 248 #pragma mark - 167 249 168 - (void)connectToServer :(NSURL *)url{250 - (void)connectToServer { 169 251 // --- ping at intervals 170 252 _timer = [NSTimer scheduledTimerWithTimeInterval:60 … … 176 258 177 259 // --- 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 { 184 266 // --- fork a tracker thread 185 [NSThread detachNewThreadSelector:@selector(trackerThread:) toTarget:self withObject: url];267 [NSThread detachNewThreadSelector:@selector(trackerThread:) toTarget:self withObject:NULL]; 186 268 } 187 269 … … 194 276 195 277 196 - (void)clientThread:( NSURL *)url{278 - (void)clientThread:(id)arg { 197 279 NSAutoreleasePool *pool; 280 NSURL *url; 198 281 int bytes; 199 282 200 283 // --- create a pool 201 284 pool = [[NSAutoreleasePool alloc] init]; 285 286 // --- get url 287 url = [_connection URL]; 202 288 203 289 // --- connect to the host … … 214 300 } 215 301 216 // --- login302 // --- initial login 217 303 [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] > 0223 ? [[url user] stringByReplacingURLPercentEscapes]224 : @"guest"];225 [self sendCommand:WCPassCommand withArgument:[[url password] length] > 0226 ? [[[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];233 304 234 305 // --- start reading from server … … 250 321 251 322 252 - (void)trackerThread:( NSURL *)url{323 - (void)trackerThread:(id)arg { 253 324 NSAutoreleasePool *pool; 325 NSURL *url; 254 326 int bytes; 255 327 256 328 // --- create a pool 257 329 pool = [[NSAutoreleasePool alloc] init]; 330 331 // --- get url 332 url = [_connection URL]; 258 333 259 334 // --- connect to the host … … 368 443 369 444 370 - (void)sendCommand:(NSString *)command withArgument:( NSString *)argument {445 - (void)sendCommand:(NSString *)command withArgument:(id)argument { 371 446 NSString *string; 372 447 WiredClient/trunk/WCConnection.h
r1155 r1187 1 /* $Id: WCConnection.h,v 1. 5 2004/05/13 17:58:09morris Exp $ */1 /* $Id: WCConnection.h,v 1.6 2004/05/16 15:21:37 morris Exp $ */ 2 2 3 3 /* … … 48 48 WCTracker *_tracker; 49 49 50 unsigned int _type; 50 51 unsigned int _uid; 51 52 } 52 53 53 54 54 #define WCProtocolVersion 1.1 55 #define WCServerProtocolVersion 1.1 56 #define WCTrackerProtocolVersion 1.0 57 58 #define WCConnectionTypeServer 0 59 #define WCConnectionTypeTracker 1 55 60 56 61 #define WCConnectionHasAttached @"WCConnectionHasAttached" … … 80 85 - (WCTransfers *) transfers; 81 86 87 - (unsigned int) type; 82 88 - (WCCache *) cache; 83 89 - (WCServer *) server; WiredClient/trunk/WCConnection.m
r1155 r1187 1 /* $Id: WCConnection.m,v 1. 8 2004/05/13 17:58:09morris Exp $ */1 /* $Id: WCConnection.m,v 1.9 2004/05/16 15:21:37 morris Exp $ */ 2 2 3 3 /* … … 58 58 self = [super init]; 59 59 60 // --- set type 61 _type = WCConnectionTypeServer; 62 60 63 // --- initate cache 61 64 _cache = [[WCCache alloc] initWithCount:100]; … … 100 103 [[NSNotificationCenter defaultCenter] 101 104 addObserver:self 102 selector:@selector(connectionGotServerInfo:)103 name:WCConnectionGotServerInfo104 object:NULL];105 106 [[NSNotificationCenter defaultCenter]107 addObserver:self108 105 selector:@selector(connectionGotPrivileges:) 109 106 name:WCConnectionGotPrivileges … … 111 108 112 109 // --- start connection 113 [_client connectToServer :url];110 [_client connectToServer]; 114 111 115 112 return self; … … 120 117 - (id)initTrackerConnectionWithURL:(NSURL *)url tracker:(WCTracker *)tracker { 121 118 self = [super init]; 119 120 // --- set type 121 _type = WCConnectionTypeTracker; 122 122 123 123 // --- get parameters … … 136 136 137 137 // --- start connection 138 [_client connectToTracker :url];138 [_client connectToTracker]; 139 139 140 140 return self; … … 183 183 184 184 185 - (void)connectionGotServerInfo:(NSNotification *)notification { 186 NSArray *fields; 187 NSString *argument, *protocol, *name; 185 - (void)connectionGotPrivileges:(NSNotification *)notification { 186 NSString *argument; 188 187 WCConnection *connection; 189 188 … … 195 194 return; 196 195 197 // --- separate the fields198 fields = [argument componentsSeparatedByString:WCFieldSeparator];199 protocol = [fields objectAtIndex:1];200 name = [fields objectAtIndex:2];201 202 // --- check protocol version203 if([protocol doubleValue] > WCProtocolVersion) {204 [[self error] setError:WCApplicationErrorProtocolMismatch];205 [[self error] raiseError];206 }207 208 // --- set values209 [_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 objects220 connection = [[notification object] objectAtIndex:0];221 argument = [[notification object] objectAtIndex:1];222 223 if(connection != self)224 return;225 226 196 // --- set privileges 227 197 [[_server account] setPrivileges:[argument componentsSeparatedByString:WCFieldSeparator]]; … … 305 275 #pragma mark - 306 276 277 - (unsigned int)type { 278 return _type; 279 } 280 281 282 307 283 - (WCCache *)cache { 308 284 return _cache; WiredClient/trunk/WCServerInfo.m
r1186 r1187 1 /* $Id: WCServerInfo.m,v 1.1 0 2004/05/16 14:46:41morris Exp $ */1 /* $Id: WCServerInfo.m,v 1.11 2004/05/16 15:21:37 morris Exp $ */ 2 2 3 3 /* … … 220 220 rect.size.height = _last + 109; 221 221 [[self window] setContentSize:rect.size]; 222 223 // --- protocol 1.1224 if([protocol doubleValue] >= 1.1)225 [[_connection client] sendCommand:WCBannerCommand];226 222 227 223 } WiredClient/trunk/WCTracker.h
r1170 r1187 1 /* $Id: WCTracker.h,v 1. 5 2004/05/16 03:52:00morris Exp $ */1 /* $Id: WCTracker.h,v 1.6 2004/05/16 15:21:37 morris Exp $ */ 2 2 3 3 /* … … 41 41 NSNetService *_service; 42 42 NSURL *_url; 43 double _protocol; 43 44 NSMutableArray *_children; 44 45 } … … 95 96 - (void) setURL:(NSURL *)value; 96 97 - (NSURL *) URL; 98 99 - (void) setProtocol:(double)value; 100 - (double) protocol; 97 101 98 102 - (void) addChild:(WCTracker *)child; WiredClient/trunk/WCTracker.m
r1109 r1187 1 /* $Id: WCTracker.m,v 1. 4 2004/03/29 02:12:52morris Exp $ */1 /* $Id: WCTracker.m,v 1.5 2004/05/16 15:21:37 morris Exp $ */ 2 2 3 3 /* … … 77 77 [coder decodeValueOfObjCType:@encode(unsigned int) at:&_files]; 78 78 [coder decodeValueOfObjCType:@encode(unsigned long long) at:&_size]; 79 [coder decodeValueOfObjCType:@encode(unsigned int) at:&_protocol]; 79 80 80 81 _name = [[coder decodeObject] retain]; … … 98 99 [coder encodeValueOfObjCType:@encode(unsigned int) at:&_files]; 99 100 [coder encodeValueOfObjCType:@encode(unsigned long long) at:&_size]; 101 [coder encodeValueOfObjCType:@encode(unsigned int) at:&_protocol]; 100 102 101 103 [coder encodeObject:_name]; … … 298 300 - (NSURL *)URL { 299 301 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; 300 316 } 301 317
