#include "cheat_shared.h"
+#import "SessionController.h"
#import "AboutBoxController.h"
#import "PreferenceController.h"
#import "NetTrafficController.h"
@implementation AppController
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+#pragma mark Initialization
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+
+ (void)initialize
{
NSMutableDictionary *defaults = [NSMutableDictionary dictionary];
char temp[104];
+ // set up logging
+//#ifndef TC_SHOW_LOGS
+ CMLogDisable();
+//#endif
+
// change the socket path to reside in the home directory of the current user
strncpy( temp, [NSHomeDirectory() lossyCString], 103 );
strncat( temp, TCDefaultListenPath, 103 - strlen(TCDefaultListenPath) );
[defaults setObject:[NSNumber numberWithBool:TCGlobalPlaySounds] forKey:TCPlaySoundsPref];
[defaults setObject:[NSNumber numberWithBool:TCGlobalWindowsOnTop] forKey:TCWindowsOnTopPref];
+ [defaults setObject:[NSNumber numberWithBool:TCGlobalUpdateCheck] forKey:TCUpdateCheckPref];
[defaults setObject:[NSNumber numberWithBool:TCGlobalAllowRemote] forKey:TCAllowRemotePref];
[defaults setObject:[NSNumber numberWithInt:TCGlobalListenPort] forKey:TCListenPortPref];
[defaults setObject:[NSString stringWithFormat:@"%@'s Computer", NSFullUserName()] forKey:TCBroadcastNamePref];
+ [defaults setObject:[NSNumber numberWithInt:TCGlobalHitsDisplayed] forKey:TCHitsDisplayedPref];
[[NSUserDefaults standardUserDefaults] registerDefaults:defaults];
- TCGlobalPlaySounds = [[NSUserDefaults standardUserDefaults] integerForKey:TCPlaySoundsPref];
- TCGlobalWindowsOnTop = [[NSUserDefaults standardUserDefaults] integerForKey:TCWindowsOnTopPref];
- TCGlobalListenPort = [[NSUserDefaults standardUserDefaults] integerForKey:TCListenPortPref];
+ TCGlobalPlaySounds = [[NSUserDefaults standardUserDefaults] boolForKey:TCPlaySoundsPref];
+ TCGlobalWindowsOnTop = [[NSUserDefaults standardUserDefaults] boolForKey:TCWindowsOnTopPref];
+ TCGlobalUpdateCheck = [[NSUserDefaults standardUserDefaults] boolForKey:TCUpdateCheckPref];
TCGlobalAllowRemote = [[NSUserDefaults standardUserDefaults] boolForKey:TCAllowRemotePref];
+ TCGlobalListenPort = [[NSUserDefaults standardUserDefaults] integerForKey:TCListenPortPref];
+ TCGlobalHitsDisplayed = [[NSUserDefaults standardUserDefaults] integerForKey:TCHitsDisplayedPref];
}
- (id)init
{
servers = [[NSMutableArray alloc] init];
+ // start the server with saved settings
[self listenOnPort:TCGlobalListenPort remote:TCGlobalAllowRemote];
- [self broadcastWithName:TCGlobalBroadcastName];
+ if ( TCGlobalAllowRemote ) [self broadcastWithName:TCGlobalBroadcastName];
// set up the network browser
browser = [[NSNetServiceBrowser alloc] init];
}
+- (void)dealloc
+{
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
+
+ [self stopListener];
+ [self stopBroadcast];
+
+ [servers release];
+
+ [browser release];
+ [serverList release];
+
+ [super dealloc];
+}
+
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+#pragma mark NSApplication Delegate
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+
+- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
+{
+ if ( TCGlobalUpdateCheck )
+ {
+ [CMUpdateCheck checkWithURL:@"http://www.brokenzipper.com/software.plist" verbose:NO];
+ }
+
+ [self newSessionWindow:self];
+}
+
+- (void)applicationDidBecomeActive:(NSNotification *)aNotification
+{
+ /*if ( TCGlobalSessionCount == 0 )
+ {
+ [self newSessionWindow:self];
+ }*/
+}
+
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+#pragma mark Server Starting/Stopping
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+
- (void)listenOnPort:(int)port remote:(BOOL)remote
{
if ( connection )
- (void)broadcastWithName:(NSString *)name
{
- if ( TCGlobalAllowRemote )
- {
- [self stopBroadcast];
+ [self stopBroadcast];
- service = [[NSNetService alloc] initWithDomain:@"local." type:@"_cheat._tcp." name:name port:TCGlobalListenPort];
- [service setDelegate:self];
- [service publish];
- }
+ service = [[NSNetService alloc] initWithDomain:@"local." type:@"_cheat._tcp." name:name port:TCGlobalListenPort];
+ [service setDelegate:self];
+ [service publish];
}
- (void)stopBroadcast
}
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+#pragma mark Interface Activation
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+
+- (IBAction)newSessionWindow:(id)sender
+{
+ [[[SessionController alloc] init] showWindow:self];
+}
+
- (IBAction)showAboutBoxWindow:(id)sender
{
if ( !aboutBoxController )
- (IBAction)launchHelpFile:(id)sender
{
//[[NSWorkspace sharedWorkspace] openFile:[[NSBundle mainBundle] pathForResource:@"Read Me" ofType:@"html"] withApplication:@"Safari"];
- [[NSWorkspace sharedWorkspace] openURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Read Me" ofType:@"pdf"]]];
+ [[NSWorkspace sharedWorkspace] openURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Read Me" ofType:@"rtf"]]];
+}
+
+- (IBAction)launchEmailMenu:(id)sender
+{
+ LaunchEmail();
}
- (IBAction)launchWebsiteMenu:(id)sender
}
-- (NSArray *)serverList
+- (IBAction)checkForUpdate:(id)sender
{
- return serverList;
+ [CMUpdateCheck checkWithURL:@"http://www.brokenzipper.com/software.plist"];
}
-- (void)dealloc
+- (NSArray *)serverList
{
- [[NSNotificationCenter defaultCenter] removeObserver:self];
+ return serverList;
+}
- [self stopListener];
- [self stopBroadcast];
- [servers release];
-
- [browser release];
- [serverList release];
-
- [super dealloc];
-}
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+#pragma mark Controlling Preferences
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
-/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%% PreferenceControlling
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+- (void)preferenceSetWindowsOnTop:(BOOL)windowsOnTop
+{
+ if ( TCGlobalWindowsOnTop != windowsOnTop )
+ {
+ [[NSNotificationCenter defaultCenter] postNotificationName:@"TCWindowsOnTopChanged" object:[NSNumber numberWithBool:windowsOnTop]];
+ }
+}
+- (void)preferenceSetAllowRemote:(BOOL)allow listenPort:(int)port broadcastName:(NSString *)name
+{
+ if ( TCGlobalAllowRemote != allow || TCGlobalListenPort != port )
+ {
+ [self listenOnPort:port remote:allow];
+ }
+ if ( allow )
+ {
+ if ( !TCGlobalAllowRemote || ![TCGlobalBroadcastName isEqualToString:name] )
+ {
+ [self broadcastWithName:name];
+ }
+ }
+ else
+ {
+ [self stopBroadcast];
+ }
+ [netTrafficController serverSetAllowRemote:allow listenPort:port broadcastName:name];
+ //[netTrafficController allowRemoteChanged:allow];
+ //[netTrafficController listenPortChanged:port];
+ //[netTrafficController broadcastNameChanged:name];
+}
+/*
- (void)preferenceAllowRemoteChanged:(BOOL)allow
{
[self listenOnPort:TCGlobalListenPort remote:allow];
[netTrafficController broadcastNameChanged:name];
}
+*/
-/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%% NetTrafficControlling
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+#pragma mark Controlling NetTraffic
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
- (int)netTrafficConnectionCount
- (void)netTrafficKillConnection:(int)index
{
- NSLog( @"kill connection" );
+ CMLog( @"kill connection" );
close( [[servers objectAtIndex:index] sockfd] );
}
-/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%% ListenerDelegate
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+#pragma mark Controlling Listener
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
- (void)listenerListeningWithSocket:(int)sock
}
-/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%% ServerDelegate
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+#pragma mark Controlling Server
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
- (void)server:(CheatServer *)server connectedWithSocket:(int)sock
}
-/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%% NetService Delegate
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+#pragma mark NetService Delegate
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
- (void)netServiceWillPublish:(NSNetService *)sender
{
- NSLog( @"service will publish" );
+ CMLog( @"service will publish" );
[sender resolve];
}
- (void)netService:(NSNetService *)sender didNotPublish:(NSDictionary *)errorDict
{
- NSLog( @"service did not publish" );
+ CMLog( @"service did not publish" );
if ( [[errorDict objectForKey:@"NSNetServicesErrorCode"] intValue] == NSNetServicesCollisionError )
{
- [self broadcastWithName:[NSString stringWithFormat:@"%@ %i", TCGlobalBroadcastName, TCGlobalAlternateBroadcastNameCount++]];
+ [self broadcastWithName:[NSString stringWithFormat:@"%@ %i", [sender name], TCGlobalAlternateBroadcastNameCount++]];
}
else
{
- (void)netServiceDidStop:(NSNetService *)sender
{
- NSLog( @"service stopped" );
+ CMLog( @"service stopped" );
[sender release];
}
-/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%% NSNetServiceBrowser Delegate
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+#pragma mark NetServiceBrowser Delegate
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
- (void)netServiceBrowser:(NSNetServiceBrowser *)browser didFindService:(NSNetService *)aService moreComing:(BOOL)more
}
[serverList addObject:aService];
- NSLog( @"server added: %i", [serverList count] );
+ CMLog( @"server added: %i", [serverList count] );
[[NSNotificationCenter defaultCenter] postNotificationName:@"TCServerFound" object:aService];
}
if ( [[aService name] isEqualToString:[(NSNetService *)[serverList objectAtIndex:i] name]] )
{
[serverList removeObjectAtIndex:i];
- NSLog( @"server deleted: %i", [serverList count] );
+ CMLog( @"server deleted: %i", [serverList count] );
break;
}
}