diff --git a/default.bam b/default.bam index a4902b4e3..51bf05096 100644 --- a/default.bam +++ b/default.bam @@ -199,9 +199,11 @@ function build(settings) -- build tools (TODO: fix this so we don't get double _d_d stuff) tools_src = Collect("src/tools/*.cpp", "src/tools/*.c") - osxlaunch = {} + client_osxlaunch = {} + server_osxlaunch = {} if platform == "macosx" then - osxlaunch = Compile(client_settings, Collect("src/osxlaunch/*.m")) + client_osxlaunch = Compile(client_settings, "src/osxlaunch/client.m") + server_osxlaunch = Compile(client_settings, "src/osxlaunch/server.m") end tools = {} @@ -213,10 +215,15 @@ function build(settings) -- build client, server, version server and master server client_exe = Link(client_settings, "teeworlds", game_shared, game_client, engine, client, game_editor, zlib, pnglite, wavpack, - client_link_other, osxlaunch) + client_link_other, client_osxlaunch) server_exe = Link(server_settings, "teeworlds_srv", engine, server, game_shared, game_server, zlib) + + serverlaunch = {} + if platform == "macosx" then + serverlaunch = Link(client_settings, "serverlaunch", server_osxlaunch) + end versionserver_exe = Link(server_settings, "versionsrv", versionserver, engine, zlib) @@ -226,7 +233,7 @@ function build(settings) -- make targets c = PseudoTarget("client".."_"..settings.config_name, client_exe, client_depends) - s = PseudoTarget("server".."_"..settings.config_name, server_exe) + s = PseudoTarget("server".."_"..settings.config_name, server_exe, serverlaunch) g = PseudoTarget("game".."_"..settings.config_name, client_exe, server_exe) v = PseudoTarget("versionserver".."_"..settings.config_name, versionserver_exe) diff --git a/scripts/make_release.py b/scripts/make_release.py index 08839da7c..7bc74b159 100644 --- a/scripts/make_release.py +++ b/scripts/make_release.py @@ -82,22 +82,24 @@ if include_src: if use_bundle: os.system("lipo -create -output teeworlds_srv teeworlds_srv_ppc teeworlds_srv_x86") os.system("lipo -create -output teeworlds teeworlds_ppc teeworlds_x86") - bundle_content_dir = os.path.join(package_dir, "Teeworlds.app/Contents") - bundle_bin_dir = os.path.join(bundle_content_dir, "MacOS") - bundle_resource_dir = os.path.join(bundle_content_dir, "Resources") - bundle_framework_dir = os.path.join(bundle_content_dir, "Frameworks") + os.system("lipo -create -output serverlaunch serverlaunch_ppc serverlaunch_x86") + + # create Teeworlds appfolder + clientbundle_content_dir = os.path.join(package_dir, "Teeworlds.app/Contents") + clientbundle_bin_dir = os.path.join(clientbundle_content_dir, "MacOS") + clientbundle_resource_dir = os.path.join(clientbundle_content_dir, "Resources") + clientbundle_framework_dir = os.path.join(clientbundle_content_dir, "Frameworks") os.mkdir(os.path.join(package_dir, "Teeworlds.app")) - os.mkdir(bundle_content_dir) - os.mkdir(bundle_bin_dir) - os.mkdir(bundle_resource_dir) - os.mkdir(bundle_framework_dir) - os.mkdir(os.path.join(bundle_resource_dir, "data")) - copydir("data", bundle_resource_dir) - shutil.copy("other/icons/Teeworlds.icns", bundle_resource_dir) - shutil.copy(name+exe_ext, bundle_bin_dir) - shutil.copy(name+"_srv"+exe_ext, bundle_bin_dir) - os.system("cp -R /Library/Frameworks/SDL.framework " + bundle_framework_dir) - file(os.path.join(bundle_content_dir, "Info.plist"), "w").write(""" + os.mkdir(clientbundle_content_dir) + os.mkdir(clientbundle_bin_dir) + os.mkdir(clientbundle_resource_dir) + os.mkdir(clientbundle_framework_dir) + os.mkdir(os.path.join(clientbundle_resource_dir, "data")) + copydir("data", clientbundle_resource_dir) + shutil.copy("other/icons/Teeworlds.icns", clientbundle_resource_dir) + shutil.copy(name+exe_ext, clientbundle_bin_dir) + os.system("cp -R /Library/Frameworks/SDL.framework " + clientbundle_framework_dir) + file(os.path.join(clientbundle_content_dir, "Info.plist"), "w").write(""" @@ -119,7 +121,45 @@ if use_bundle: """ % (version)) - file(os.path.join(bundle_content_dir, "PkgInfo"), "w").write("APPL????") + file(os.path.join(clientbundle_content_dir, "PkgInfo"), "w").write("APPL????") + + # create Teeworlds Server appfolder + serverbundle_content_dir = os.path.join(package_dir, "Teeworlds Server.app/Contents") + serverbundle_bin_dir = os.path.join(serverbundle_content_dir, "MacOS") + serverbundle_resource_dir = os.path.join(serverbundle_content_dir, "Resources") + os.mkdir(os.path.join(package_dir, "Teeworlds Server.app")) + os.mkdir(serverbundle_content_dir) + os.mkdir(serverbundle_bin_dir) + os.mkdir(serverbundle_resource_dir) + os.mkdir(os.path.join(serverbundle_resource_dir, "data")) + os.mkdir(os.path.join(serverbundle_resource_dir, "data/maps")) + copydir("data/maps", serverbundle_resource_dir) + shutil.copy("other/icons/Teeworlds_srv.icns", serverbundle_resource_dir) + shutil.copy(name+"_srv"+exe_ext, serverbundle_bin_dir) + shutil.copy("serverlaunch"+exe_ext, serverbundle_bin_dir + "/teeworlds_server") + file(os.path.join(serverbundle_content_dir, "Info.plist"), "w").write(""" + + + + + CFBundleDevelopmentRegion + English + CFBundleExecutable + teeworlds_server + CFBundleIconFile + Teeworlds_srv + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + APPL + CFBundleSignature + ???? + CFBundleVersion + %s + + + """ % (version)) + file(os.path.join(serverbundle_content_dir, "PkgInfo"), "w").write("APPL????") if use_zip: print "making zip archive" diff --git a/src/osxlaunch/SDLMain.h b/src/osxlaunch/client.h similarity index 100% rename from src/osxlaunch/SDLMain.h rename to src/osxlaunch/client.h diff --git a/src/osxlaunch/SDLMain.m b/src/osxlaunch/client.m similarity index 81% rename from src/osxlaunch/SDLMain.m rename to src/osxlaunch/client.m index a1e0d156c..c6e6203e3 100644 --- a/src/osxlaunch/SDLMain.m +++ b/src/osxlaunch/client.m @@ -6,10 +6,9 @@ */ #import -#import "SDLMain.h" +#import "client.h" #import /* for MAXPATHLEN */ #import -#include /* For some reaon, Apple removed setAppleMenu from the headers in 10.4, but the method still is there and works. To avoid warnings, we declare @@ -337,105 +336,14 @@ static void CustomApplicationMain (int argc, char **argv) @end - - #ifdef main # undef main #endif -@interface ServerView : NSTextView -{ - NSTask *task; - NSFileHandle *file; -} -- (void)listenTo: (NSTask*)t; -@end - -@implementation ServerView -- (void)listenTo: (NSTask*)t; -{ - NSPipe *pipe; - task = t; - pipe = [NSPipe pipe]; - [task setStandardOutput: pipe]; - file = [pipe fileHandleForReading]; - - [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(outputNotification:) name: NSFileHandleReadCompletionNotification object: file]; - - [file readInBackgroundAndNotify]; -} - -- (void) outputNotification: (NSNotification *) notification -{ - NSData *data = [[[notification userInfo] objectForKey: NSFileHandleNotificationDataItem] retain]; - NSString *string = [[NSString alloc] initWithData: data encoding: NSASCIIStringEncoding]; - - NSRange end = NSMakeRange([[self string] length], 0); - - [self replaceCharactersInRange: end withString: string]; - end.location += [string length]; - [self scrollRangeToVisible: end]; - - [string release]; - [file readInBackgroundAndNotify]; -} - --(void)windowWillClose:(NSNotification *)notification -{ - [task terminate]; - [NSApp terminate:self]; -} -@end - -void runServer() -{ - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - NSApp = [NSApplication sharedApplication]; - NSBundle* mainBundle = [NSBundle mainBundle]; - NSTask *task; - task = [[NSTask alloc] init]; - [task setCurrentDirectoryPath: [mainBundle resourcePath]]; - - // run server - NSWindow *window; - ServerView *view; - NSRect graphicsRect; - - graphicsRect = NSMakeRect(100.0, 1000.0, 600.0, 400.0); - - window = [[NSWindow alloc] - initWithContentRect: graphicsRect - styleMask: NSTitledWindowMask - | NSClosableWindowMask - | NSMiniaturizableWindowMask - backing: NSBackingStoreBuffered - defer: NO]; - - [window setTitle: @"Teewars Server"]; - - view = [[[ServerView alloc] initWithFrame: graphicsRect] autorelease]; - [view setEditable: NO]; - - [window setContentView: view]; - [window setDelegate: view]; - [window makeKeyAndOrderFront: nil]; - - [view listenTo: task]; - [task setLaunchPath: [mainBundle pathForAuxiliaryExecutable: @"teeworlds_srv"]]; - [task launch]; - [NSApp run]; - [task terminate]; - - [NSApp release]; - [pool release]; -} - /* Main entry point to executable - should *not* be SDL_main! */ int main (int argc, char **argv) { - UInt32 mod = GetCurrentKeyModifiers(); - /* Copy the arguments into a global variable */ /* This is passed if we are launched by double-clicking */ if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) { @@ -453,19 +361,12 @@ int main (int argc, char **argv) gFinderLaunch = NO; } - if(mod & optionKey) - { - runServer(); - } - else - { #if SDL_USE_NIB_FILE - [SDLApplication poseAsClass:[NSApplication class]]; - NSApplicationMain (argc, argv); + [SDLApplication poseAsClass:[NSApplication class]]; + NSApplicationMain (argc, argv); #else - CustomApplicationMain (argc, argv); + CustomApplicationMain (argc, argv); #endif - } return 0; } diff --git a/src/osxlaunch/server.m b/src/osxlaunch/server.m new file mode 100644 index 000000000..263fc4085 --- /dev/null +++ b/src/osxlaunch/server.m @@ -0,0 +1,114 @@ +#import + +@interface ServerView : NSTextView +{ + NSTask *task; + NSFileHandle *file; +} +- (void)listenTo: (NSTask*)t; +@end + +@implementation ServerView +- (void)listenTo: (NSTask*)t; +{ + NSPipe *pipe; + task = t; + pipe = [NSPipe pipe]; + [task setStandardOutput: pipe]; + file = [pipe fileHandleForReading]; + + [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(outputNotification:) name: NSFileHandleReadCompletionNotification object: file]; + + [file readInBackgroundAndNotify]; +} + +- (void) outputNotification: (NSNotification *) notification +{ + NSData *data = [[[notification userInfo] objectForKey: NSFileHandleNotificationDataItem] retain]; + NSString *string = [[NSString alloc] initWithData: data encoding: NSASCIIStringEncoding]; + NSAttributedString *attrstr = [[NSAttributedString alloc] initWithString: string]; + + [[self textStorage] beginEditing]; + [[self textStorage] appendAttributedString: attrstr]; + int length = [[self textStorage] length]; + NSRange range = NSMakeRange(length, 0); + [self scrollRangeToVisible: range]; + [[self textStorage] endEditing]; + + [attrstr release]; + [string release]; + [file readInBackgroundAndNotify]; +} + +-(void)windowWillClose:(NSNotification *)notification +{ + [task terminate]; + [NSApp terminate:self]; +} +@end + +void runServer() +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + NSApp = [NSApplication sharedApplication]; + NSBundle* mainBundle = [NSBundle mainBundle]; + NSTask *task; + task = [[NSTask alloc] init]; + [task setCurrentDirectoryPath: [mainBundle resourcePath]]; + + // get a server config + NSOpenPanel* openDlg = [NSOpenPanel openPanel]; + [openDlg setCanChooseFiles:YES]; + + if([openDlg runModalForDirectory:nil file:nil] != NSOKButton) + return; + + NSArray* filenames = [openDlg filenames]; + if([filenames count] != 1) + return; + + NSString* filename = [filenames objectAtIndex: 0]; + NSArray* arguments = [NSArray arrayWithObjects: @"-f", filename, nil]; + + // run server + NSWindow *window; + ServerView *view; + NSRect graphicsRect; + + graphicsRect = NSMakeRect(100.0, 1000.0, 600.0, 400.0); + + window = [[NSWindow alloc] + initWithContentRect: graphicsRect + styleMask: NSTitledWindowMask + | NSClosableWindowMask + | NSMiniaturizableWindowMask + backing: NSBackingStoreBuffered + defer: NO]; + + [window setTitle: @"Teeworlds Server"]; + + view = [[[ServerView alloc] initWithFrame: graphicsRect] autorelease]; + [view setEditable: NO]; + [view setRulerVisible: YES]; + + [window setContentView: view]; + [window setDelegate: view]; + [window makeKeyAndOrderFront: nil]; + + [view listenTo: task]; + [task setLaunchPath: [mainBundle pathForAuxiliaryExecutable: @"teeworlds_srv"]]; + [task setArguments: arguments]; + [task launch]; + [NSApp run]; + [task terminate]; + + [NSApp release]; + [pool release]; +} + +int main (int argc, char **argv) +{ + runServer(); + + return 0; +}