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 serverSetAllowRemote
:TCGlobalAllowRemote listenPort
:TCGlobalListenPort broadcastName
:TCGlobalBroadcastName
];
45 //[self allowRemoteChanged:TCGlobalAllowRemote];
46 //[self listenPortChanged:TCGlobalListenPort];
47 [self setConnectionCount
:[delegate netTrafficConnectionCount
]];
48 [serverListTable reloadData
];
51 - (void)interfaceUpdate
53 NSArray
*array
= [[serverListTable selectedRowEnumerator
] allObjects
];
55 if ( [array count
] == 0 )
57 [killConnectionButton setEnabled
:NO
];
61 [killConnectionButton setEnabled
:YES
];
63 if ( [array count
] > 1 )
65 [killConnectionButton setTitle
:@
"Kill Connections"];
69 [killConnectionButton setTitle
:@
"Kill Connection"];
75 - (void)serverSetAllowRemote
:(BOOL)allow listenPort
:(int)port broadcastName
:(NSString
*)name
79 [listenPortText setStringValue
:[NSString stringWithFormat
:@
"Listening on port %i.", port
]];
80 [broadcastNameText setStringValue
:[NSString stringWithFormat
:@
"Broadcasting service as \"%@.\"", name
]];
84 [broadcastNameText setStringValue
:@
"Not accepting new connections from remote clients."];
85 [listenPortText setStringValue
:@
"Listening for local connections only."];
91 - (void)allowRemoteChanged:(BOOL)allow
95 [self broadcastNameChanged:TCGlobalBroadcastName];
96 [self listenPortChanged:TCGlobalListenPort];
100 [broadcastNameText setStringValue:@"Not accepting new connections from remote clients."];
101 [listenPortText setStringValue:@"Listening for local connections only."];
105 - (void)listenPortChanged:(int)port
107 if ( TCGlobalAllowRemote )
109 [listenPortText setStringValue:[NSString stringWithFormat:@"Listening on port %i.", port]];
113 - (void)broadcastNameChanged:(NSString *)name
115 if ( TCGlobalAllowRemote )
117 [broadcastNameText setStringValue:[NSString stringWithFormat:@"Broadcasting service as \"%@.\"", name]];
123 - (void)connectionListChanged
125 [self setConnectionCount
:[delegate netTrafficConnectionCount
]];
126 [serverListTable reloadData
];
130 - (void)setConnectionCount
:(int)count
132 [connectionCountText setStringValue
:[NSString stringWithFormat
:@
"Now serving %i clients.", count
]];
136 - (IBAction
)killConnectionButton
:(id)sender
138 NSArray
*array
= [[serverListTable selectedRowEnumerator
] allObjects
];
141 for ( i
= [array count
] - 1; i
>= 0; i
-- )
143 [delegate netTrafficKillConnection
:[(NSNumber
*)[array objectAtIndex
:i
] intValue
]];
148 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
149 %%%%%%%%%%%%%%%%%%%%%% NSTableView Data Source/Delegate
150 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
153 - (int)numberOfRowsInTableView
:(NSTableView
*)table
155 return [delegate netTrafficConnectionCount
];
158 - (id)tableView
:(NSTableView
*)table objectValueForTableColumn
:(NSTableColumn
*)column row
:(int)row
160 ServerHolder
*holder
= [[delegate netTrafficConnectionList
] objectAtIndex
:row
];
162 if ( [[column identifier
] isEqualToString
:@
"IP Address"] )
164 return [holder address
];
166 else if ( [[column identifier
] isEqualToString
:@
"Current Action"] )
168 return [holder action
];
174 - (void)tableView
:(NSTableView
*) setObjectValue
:(id)object forTableColumn
:(NSTableColumn
*)column row
:(int)row
179 - (void)tableViewSelectionDidChange
:(NSNotification
*)note
181 [self interfaceUpdate
];