initial server launcher for osx

This commit is contained in:
Joel de Vahl 2009-01-12 20:04:14 +00:00
parent baaf1bcf0d
commit 1d6668583a
5 changed files with 185 additions and 123 deletions

View file

@ -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)

View file

@ -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("""
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
@ -119,7 +121,45 @@ if use_bundle:
</dict>
</plist>
""" % (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("""
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>teeworlds_server</string>
<key>CFBundleIconFile</key>
<string>Teeworlds_srv</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>%s</string>
</dict>
</plist>
""" % (version))
file(os.path.join(serverbundle_content_dir, "PkgInfo"), "w").write("APPL????")
if use_zip:
print "making zip archive"

View file

@ -6,10 +6,9 @@
*/
#import <SDL.h>
#import "SDLMain.h"
#import "client.h"
#import <sys/param.h> /* for MAXPATHLEN */
#import <unistd.h>
#include <Carbon/Carbon.h>
/* 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;
}

114
src/osxlaunch/server.m Normal file
View file

@ -0,0 +1,114 @@
#import <Cocoa/Cocoa.h>
@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;
}