src/macosx/AAURLHandler.mm

Go to the documentation of this file.
00001 /*
00002  
00003  *************************************************************************
00004  
00005  ArmageTron -- Just another Tron Lightcycle Game in 3D.
00006  Copyright (C) 2005  by Daniel Harple
00007  and the AA DevTeam (see the file AUTHORS(.txt) in the main source directory)
00008  
00009  **************************************************************************
00010  
00011  This program is free software; you can redistribute it and/or
00012  modify it under the terms of the GNU General Public License
00013  as published by the Free Software Foundation; either version 2
00014  of the License, or (at your option) any later version.
00015  
00016  This program is distributed in the hope that it will be useful,
00017  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  GNU General Public License for more details.
00020  
00021  You should have received a copy of the GNU General Public License
00022  along with this program; if not, write to the Free Software
00023  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00024  
00025  ***************************************************************************
00026  
00027  */
00028 
00029 #include "AAURLHandler.h"
00030 #include "tString.h"
00031 #include "nServerInfo.h"
00032 #include "gCommandLineJumpStart.h"
00033 
00034 @interface AAURLHandler : NSObject
00035 {
00036     NSMutableString *_startupEvent; 
00037     BOOL _shouldConnect;
00038 }
00039 - (void) setShouldConnect:(BOOL)shouldConnect;
00040 @end
00041 
00042 @implementation AAURLHandler
00043 
00044 - (id) init
00045 {
00046     self = [super init];
00047     if ( self )
00048     {
00049         [[NSAppleEventManager sharedAppleEventManager] setEventHandler:self
00050                                                            andSelector:@selector(handleURLEvent:withReplyEvent:)
00051                                                          forEventClass:kInternetEventClass
00052                                                             andEventID:kAEGetURL];
00053         _startupEvent = [[NSMutableString alloc] init];
00054         _shouldConnect = NO;
00055     }
00056     return self;
00057 }
00058 
00059 - (void)connectToServer:(NSString *)server
00060 {
00061     if ( ![server isEqualToString:@"armagetronad://"] )
00062     {
00063         tString raw( [server UTF8String] );
00064         tString servername;
00065         tString port;
00066         ExtractConnectionInformation( raw, servername, port );
00067         nServerInfoRedirect server( servername, port.ToInt() );
00068         AAURLHandlerConnect( &server );
00069     }
00070 }
00071 
00072 - (void) handleURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
00073 {
00074     if ( _shouldConnect )
00075     {
00076         [self connectToServer:[[[event descriptorAtIndex:1] stringValue] retain]];
00077     }
00078     // Save the event for later, we must finish initializing
00079     else
00080     {
00081         _startupEvent = [[[event descriptorAtIndex:1] stringValue] retain];
00082     }
00083 }
00084 
00086 - (void) setShouldConnect:(BOOL)shouldConnect
00087 {
00088     _shouldConnect = shouldConnect;
00089     if ( _shouldConnect )
00090     {
00091         // _startupEvent is initialized to an empty string. Check if a URL event actually occured
00092         if ( ![_startupEvent isEqualToString:@""] )
00093         {
00094             [self connectToServer:_startupEvent];
00095         }
00096     }
00097 
00098 }
00099 
00100 - (void) dealloc
00101 {
00102     [_startupEvent release];
00103     [super dealloc];
00104 }
00105 
00106 @end
00107 
00108 AAURLHandler *urlhandler;
00109 
00110 void SetupAAURLHandler()
00111 {
00112     urlhandler = [[AAURLHandler alloc] init];
00113 }
00114 
00115 void StartAAURLHandler()
00116 {
00117     [urlhandler setShouldConnect:YES];
00118 }
00119 
00120 void CleanupAAURLHandler()
00121 {
00122     [urlhandler release];
00123 }

Generated on Sat Mar 15 22:55:48 2008 for Armagetron Advanced by  doxygen 1.5.4