]> Dogcows Code - chaz/thecheat/blob - NetTrafficController.m
The Cheat 1.0b4
[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 allowRemoteChanged:TCGlobalAllowRemote];
45 [self listenPortChanged:TCGlobalListenPort];
46 [self setConnectionCount:[delegate netTrafficConnectionCount]];
47 [serverListTable reloadData];
48 }
49
50 - (void)interfaceUpdate
51 {
52 NSArray *array = [[serverListTable selectedRowEnumerator] allObjects];
53
54 if ( [array count] == 0 )
55 {
56 [killConnectionButton setEnabled:NO];
57 }
58 else
59 {
60 [killConnectionButton setEnabled:YES];
61
62 if ( [array count] > 1 )
63 {
64 [killConnectionButton setTitle:@"Kill Connections"];
65 }
66 else
67 {
68 [killConnectionButton setTitle:@"Kill Connection"];
69 }
70 }
71 }
72
73
74 - (void)allowRemoteChanged:(BOOL)allow
75 {
76 if ( allow )
77 {
78 [self broadcastNameChanged:TCGlobalBroadcastName];
79 [self listenPortChanged:TCGlobalListenPort];
80 }
81 else
82 {
83 [broadcastNameText setStringValue:@"Not accepting new connections from remote clients."];
84 [listenPortText setStringValue:@"Listening for local connections only."];
85 }
86 }
87
88 - (void)listenPortChanged:(int)port
89 {
90 if ( TCGlobalAllowRemote )
91 {
92 [listenPortText setStringValue:[NSString stringWithFormat:@"Listening on port %i.", port]];
93 }
94 }
95
96 - (void)broadcastNameChanged:(NSString *)name
97 {
98 if ( TCGlobalAllowRemote )
99 {
100 [broadcastNameText setStringValue:[NSString stringWithFormat:@"Broadcasting service as \"%@.\"", name]];
101 }
102 }
103
104
105 - (void)connectionListChanged
106 {
107 [self setConnectionCount:[delegate netTrafficConnectionCount]];
108 [serverListTable reloadData];
109 }
110
111
112 - (void)setConnectionCount:(int)count
113 {
114 [connectionCountText setStringValue:[NSString stringWithFormat:@"Now serving %i clients.", count]];
115 }
116
117
118 - (IBAction)killConnectionButton:(id)sender
119 {
120 NSArray *array = [[serverListTable selectedRowEnumerator] allObjects];
121 int i;
122
123 for ( i = [array count] - 1; i >= 0; i-- )
124 {
125 [delegate netTrafficKillConnection:[(NSNumber *)[array objectAtIndex:i] intValue]];
126 }
127 }
128
129
130 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
131 %%%%%%%%%%%%%%%%%%%%%% NSTableView Data Source/Delegate
132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
133
134
135 - (int)numberOfRowsInTableView:(NSTableView *)table
136 {
137 return [delegate netTrafficConnectionCount];
138 }
139
140 - (id)tableView:(NSTableView *)table objectValueForTableColumn:(NSTableColumn *)column row:(int)row
141 {
142 ServerHolder *holder = [[delegate netTrafficConnectionList] objectAtIndex:row];
143
144 if ( [[column identifier] isEqualToString:@"IP Address"] )
145 {
146 return [holder address];
147 }
148 else if ( [[column identifier] isEqualToString:@"Current Action"] )
149 {
150 return [holder action];
151 }
152
153 return @"Unknown";
154 }
155
156 - (void)tableView:(NSTableView *) setObjectValue:(id)object forTableColumn:(NSTableColumn *)column row:(int)row
157 {
158 return;
159 }
160
161 - (void)tableViewSelectionDidChange:(NSNotification *)note
162 {
163 [self interfaceUpdate];
164 }
165
166
167 @end
This page took 0.036637 seconds and 4 git commands to generate.