2 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 // File: NetTrafficController.m
6 // Created: Wed Sep 24 2003
8 // Copyright: 2003 Chaz McGarvey. All rights reserved.
9 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11 #import "NetTrafficController.h"
13 #import "CheatServer.h"
15 #import "ServerHolder.h"
18 @implementation NetTrafficController
21 - (id)initWithDelegate
:(id)del
23 if ( self = [super initWithWindowNibName
:@
"NetTraffic"] )
25 [self setWindowFrameAutosaveName
:@
"TCNetTrafficWindowPosition"];
35 [self initialInterfaceSetup
];
36 [self interfaceUpdate
];
40 - (void)initialInterfaceSetup
42 //[netTrafficWindow setResizeIncrements:NSMakeSize( 1.0, 17.0 )];
44 [self allowRemoteChanged
:TCGlobalAllowRemote
];
45 [self listenPortChanged
:TCGlobalListenPort
];
46 [self setConnectionCount
:[delegate netTrafficConnectionCount
]];
47 [serverListTable reloadData
];
50 - (void)interfaceUpdate
52 NSArray
*array
= [[serverListTable selectedRowEnumerator
] allObjects
];
54 if ( [array count
] == 0 )
56 [killConnectionButton setEnabled
:NO
];
60 [killConnectionButton setEnabled
:YES
];
62 if ( [array count
] > 1 )
64 [killConnectionButton setTitle
:@
"Kill Connections"];
68 [killConnectionButton setTitle
:@
"Kill Connection"];
74 - (void)allowRemoteChanged
:(BOOL)allow
78 [self broadcastNameChanged
:TCGlobalBroadcastName
];
79 [self listenPortChanged
:TCGlobalListenPort
];
83 [broadcastNameText setStringValue
:@
"Not accepting new connections from remote clients."];
84 [listenPortText setStringValue
:@
"Listening for local connections only."];
88 - (void)listenPortChanged
:(int)port
90 if ( TCGlobalAllowRemote
)
92 [listenPortText setStringValue
:[NSString stringWithFormat
:@
"Listening on port %i.", port
]];
96 - (void)broadcastNameChanged
:(NSString
*)name
98 if ( TCGlobalAllowRemote
)
100 [broadcastNameText setStringValue
:[NSString stringWithFormat
:@
"Broadcasting service as \"%@.\"", name
]];
105 - (void)connectionListChanged
107 [self setConnectionCount
:[delegate netTrafficConnectionCount
]];
108 [serverListTable reloadData
];
112 - (void)setConnectionCount
:(int)count
114 [connectionCountText setStringValue
:[NSString stringWithFormat
:@
"Now serving %i clients.", count
]];
118 - (IBAction
)killConnectionButton
:(id)sender
120 NSArray
*array
= [[serverListTable selectedRowEnumerator
] allObjects
];
123 for ( i
= [array count
] - 1; i
>= 0; i
-- )
125 [delegate netTrafficKillConnection
:[(NSNumber
*)[array objectAtIndex
:i
] intValue
]];
130 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
131 %%%%%%%%%%%%%%%%%%%%%% NSTableView Data Source/Delegate
132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
135 - (int)numberOfRowsInTableView
:(NSTableView
*)table
137 return [delegate netTrafficConnectionCount
];
140 - (id)tableView
:(NSTableView
*)table objectValueForTableColumn
:(NSTableColumn
*)column row
:(int)row
142 ServerHolder
*holder
= [[delegate netTrafficConnectionList
] objectAtIndex
:row
];
144 if ( [[column identifier
] isEqualToString
:@
"IP Address"] )
146 return [holder address
];
148 else if ( [[column identifier
] isEqualToString
:@
"Current Action"] )
150 return [holder action
];
156 - (void)tableView
:(NSTableView
*) setObjectValue
:(id)object forTableColumn
:(NSTableColumn
*)column row
:(int)row
161 - (void)tableViewSelectionDidChange
:(NSNotification
*)note
163 [self interfaceUpdate
];