]> Dogcows Code - chaz/thecheat/blob - NetTrafficController.m
The Cheat 1.1.1
[chaz/thecheat] / NetTrafficController.m
1
2 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3 // Project: The Cheat
4 //
5 // File: NetTrafficController.m
6 // Created: Wed Sep 24 2003
7 //
8 // Copyright: 2003 Chaz McGarvey. All rights reserved.
9 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10
11 #import "NetTrafficController.h"
12
13 #import "CheatServer.h"
14
15 #import "ServerHolder.h"
16
17
18 @implementation NetTrafficController
19
20
21 - (id)initWithDelegate:(id)del
22 {
23 if ( self = [super initWithWindowNibName:@"NetTraffic"] )
24 {
25 [self setWindowFrameAutosaveName:@"TCNetTrafficWindowPosition"];
26
27 delegate = del;
28 }
29
30 return self;
31 }
32
33 - (void)windowDidLoad
34 {
35 [self initialInterfaceSetup];
36 [self interfaceUpdate];
37 }
38
39
40 - (void)initialInterfaceSetup
41 {
42 //[netTrafficWindow setResizeIncrements:NSMakeSize( 1.0, 17.0 )];
43
44 [self serverSetAllowRemote:TCGlobalAllowRemote listenPort:TCGlobalListenPort broadcastName:TCGlobalBroadcastName];
45 //[self allowRemoteChanged:TCGlobalAllowRemote];
46 //[self listenPortChanged:TCGlobalListenPort];
47 [self setConnectionCount:[delegate netTrafficConnectionCount]];
48 [serverListTable reloadData];
49 }
50
51 - (void)interfaceUpdate
52 {
53 NSArray *array = [[serverListTable selectedRowEnumerator] allObjects];
54
55 if ( [array count] == 0 )
56 {
57 [killConnectionButton setEnabled:NO];
58 }
59 else
60 {
61 [killConnectionButton setEnabled:YES];
62
63 if ( [array count] > 1 )
64 {
65 [killConnectionButton setTitle:@"Kill Connections"];
66 }
67 else
68 {
69 [killConnectionButton setTitle:@"Kill Connection"];
70 }
71 }
72 }
73
74
75 - (void)serverSetAllowRemote:(BOOL)allow listenPort:(int)port broadcastName:(NSString *)name
76 {
77 if ( allow )
78 {
79 [listenPortText setStringValue:[NSString stringWithFormat:@"Listening on port %i.", port]];
80 [broadcastNameText setStringValue:[NSString stringWithFormat:@"Broadcasting service as \"%@.\"", name]];
81 }
82 else
83 {
84 [broadcastNameText setStringValue:@"Not accepting new connections from remote clients."];
85 [listenPortText setStringValue:@"Listening for local connections only."];
86 }
87 }
88
89
90 /*
91 - (void)allowRemoteChanged:(BOOL)allow
92 {
93 if ( allow )
94 {
95 [self broadcastNameChanged:TCGlobalBroadcastName];
96 [self listenPortChanged:TCGlobalListenPort];
97 }
98 else
99 {
100 [broadcastNameText setStringValue:@"Not accepting new connections from remote clients."];
101 [listenPortText setStringValue:@"Listening for local connections only."];
102 }
103 }
104
105 - (void)listenPortChanged:(int)port
106 {
107 if ( TCGlobalAllowRemote )
108 {
109 [listenPortText setStringValue:[NSString stringWithFormat:@"Listening on port %i.", port]];
110 }
111 }
112
113 - (void)broadcastNameChanged:(NSString *)name
114 {
115 if ( TCGlobalAllowRemote )
116 {
117 [broadcastNameText setStringValue:[NSString stringWithFormat:@"Broadcasting service as \"%@.\"", name]];
118 }
119 }
120 */
121
122
123 - (void)connectionListChanged
124 {
125 [self setConnectionCount:[delegate netTrafficConnectionCount]];
126 [serverListTable reloadData];
127 }
128
129
130 - (void)setConnectionCount:(int)count
131 {
132 [connectionCountText setStringValue:[NSString stringWithFormat:@"Now serving %i clients.", count]];
133 }
134
135
136 - (IBAction)killConnectionButton:(id)sender
137 {
138 NSArray *array = [[serverListTable selectedRowEnumerator] allObjects];
139 int i;
140
141 for ( i = [array count] - 1; i >= 0; i-- )
142 {
143 [delegate netTrafficKillConnection:[(NSNumber *)[array objectAtIndex:i] intValue]];
144 }
145 }
146
147
148 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
149 %%%%%%%%%%%%%%%%%%%%%% NSTableView Data Source/Delegate
150 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
151
152
153 - (int)numberOfRowsInTableView:(NSTableView *)table
154 {
155 return [delegate netTrafficConnectionCount];
156 }
157
158 - (id)tableView:(NSTableView *)table objectValueForTableColumn:(NSTableColumn *)column row:(int)row
159 {
160 ServerHolder *holder = [[delegate netTrafficConnectionList] objectAtIndex:row];
161
162 if ( [[column identifier] isEqualToString:@"IP Address"] )
163 {
164 return [holder address];
165 }
166 else if ( [[column identifier] isEqualToString:@"Current Action"] )
167 {
168 return [holder action];
169 }
170
171 return @"Unknown";
172 }
173
174 - (void)tableView:(NSTableView *) setObjectValue:(id)object forTableColumn:(NSTableColumn *)column row:(int)row
175 {
176 return;
177 }
178
179 - (void)tableViewSelectionDidChange:(NSNotification *)note
180 {
181 [self interfaceUpdate];
182 }
183
184
185 @end
This page took 0.037765 seconds and 4 git commands to generate.