X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fthecheat;a=blobdiff_plain;f=NetTrafficController.m;fp=NetTrafficController.m;h=5649110a23334e39c027fbeb7fc5e84f527c5a66;hp=0000000000000000000000000000000000000000;hb=42cf7bbe564d70233a0d73baee613f209eb00eb6;hpb=2d60a59a8ad195dd0af8f90c8d5b74a69ce7f4fa diff --git a/NetTrafficController.m b/NetTrafficController.m new file mode 100644 index 0000000..5649110 --- /dev/null +++ b/NetTrafficController.m @@ -0,0 +1,167 @@ + +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// Project: The Cheat +// +// File: NetTrafficController.m +// Created: Wed Sep 24 2003 +// +// Copyright: 2003 Chaz McGarvey. All rights reserved. +// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +#import "NetTrafficController.h" + +#import "CheatServer.h" + +#import "ServerHolder.h" + + +@implementation NetTrafficController + + +- (id)initWithDelegate:(id)del +{ + if ( self = [super initWithWindowNibName:@"NetTraffic"] ) + { + [self setWindowFrameAutosaveName:@"TCNetTrafficWindowPosition"]; + + delegate = del; + } + + return self; +} + +- (void)windowDidLoad +{ + [self initialInterfaceSetup]; + [self interfaceUpdate]; +} + + +- (void)initialInterfaceSetup +{ + //[netTrafficWindow setResizeIncrements:NSMakeSize( 1.0, 17.0 )]; + + [self allowRemoteChanged:TCGlobalAllowRemote]; + [self listenPortChanged:TCGlobalListenPort]; + [self setConnectionCount:[delegate netTrafficConnectionCount]]; + [serverListTable reloadData]; +} + +- (void)interfaceUpdate +{ + NSArray *array = [[serverListTable selectedRowEnumerator] allObjects]; + + if ( [array count] == 0 ) + { + [killConnectionButton setEnabled:NO]; + } + else + { + [killConnectionButton setEnabled:YES]; + + if ( [array count] > 1 ) + { + [killConnectionButton setTitle:@"Kill Connections"]; + } + else + { + [killConnectionButton setTitle:@"Kill Connection"]; + } + } +} + + +- (void)allowRemoteChanged:(BOOL)allow +{ + if ( allow ) + { + [self broadcastNameChanged:TCGlobalBroadcastName]; + [self listenPortChanged:TCGlobalListenPort]; + } + else + { + [broadcastNameText setStringValue:@"Not accepting new connections from remote clients."]; + [listenPortText setStringValue:@"Listening for local connections only."]; + } +} + +- (void)listenPortChanged:(int)port +{ + if ( TCGlobalAllowRemote ) + { + [listenPortText setStringValue:[NSString stringWithFormat:@"Listening on port %i.", port]]; + } +} + +- (void)broadcastNameChanged:(NSString *)name +{ + if ( TCGlobalAllowRemote ) + { + [broadcastNameText setStringValue:[NSString stringWithFormat:@"Broadcasting service as \"%@.\"", name]]; + } +} + + +- (void)connectionListChanged +{ + [self setConnectionCount:[delegate netTrafficConnectionCount]]; + [serverListTable reloadData]; +} + + +- (void)setConnectionCount:(int)count +{ + [connectionCountText setStringValue:[NSString stringWithFormat:@"Now serving %i clients.", count]]; +} + + +- (IBAction)killConnectionButton:(id)sender +{ + NSArray *array = [[serverListTable selectedRowEnumerator] allObjects]; + int i; + + for ( i = [array count] - 1; i >= 0; i-- ) + { + [delegate netTrafficKillConnection:[(NSNumber *)[array objectAtIndex:i] intValue]]; + } +} + + +/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%% NSTableView Data Source/Delegate +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ + + +- (int)numberOfRowsInTableView:(NSTableView *)table +{ + return [delegate netTrafficConnectionCount]; +} + +- (id)tableView:(NSTableView *)table objectValueForTableColumn:(NSTableColumn *)column row:(int)row +{ + ServerHolder *holder = [[delegate netTrafficConnectionList] objectAtIndex:row]; + + if ( [[column identifier] isEqualToString:@"IP Address"] ) + { + return [holder address]; + } + else if ( [[column identifier] isEqualToString:@"Current Action"] ) + { + return [holder action]; + } + + return @"Unknown"; +} + +- (void)tableView:(NSTableView *) setObjectValue:(id)object forTableColumn:(NSTableColumn *)column row:(int)row +{ + return; +} + +- (void)tableViewSelectionDidChange:(NSNotification *)note +{ + [self interfaceUpdate]; +} + + +@end \ No newline at end of file