some make release changes for adding sql server files

Servers are no longer build with SQL by default.
fixed compilation on Mac OS X 10.5
This commit is contained in:
GreYFoX 2011-04-15 02:58:39 +02:00
parent c5d992dc2c
commit 9397c4a55f
17 changed files with 259 additions and 104 deletions

146
bam.lua
View file

@ -190,9 +190,10 @@ function build(settings)
server_settings = engine_settings:Copy()
client_settings = engine_settings:Copy()
launcher_settings = engine_settings:Copy()
launcher_settings_mysql = engine_settings:Copy()
if family == "unix" then
if not string.find(settings.config_name, "nosql") then
if string.find(settings.config_name, "sql") then
server_settings.link.libs:Add("mysqlcppconn-static")
server_settings.link.libs:Add("mysqlclient")
end
@ -203,7 +204,8 @@ function build(settings)
client_settings.link.frameworks:Add("Carbon")
client_settings.link.frameworks:Add("Cocoa")
launcher_settings.link.frameworks:Add("Cocoa")
if not string.find(settings.config_name, "nosql") then
launcher_settings_mysql.link.frameworks:Add("Cocoa")
if string.find(settings.config_name, "sql") then
if arch == "amd64" then
server_settings.link.libpath:Add("other/mysql/mac/lib64")
else
@ -214,7 +216,7 @@ function build(settings)
client_settings.link.libs:Add("X11")
client_settings.link.libs:Add("GL")
client_settings.link.libs:Add("GLU")
if not string.find(settings.config_name, "nosql") then
if string.find(settings.config_name, "sql") then
if arch == "amd64" then
server_settings.link.libpath:Add("other/mysql/linux/lib64")
else
@ -227,7 +229,7 @@ function build(settings)
client_settings.link.libs:Add("opengl32")
client_settings.link.libs:Add("glu32")
client_settings.link.libs:Add("winmm")
if not string.find(settings.config_name, "nosql") then
if string.find(settings.config_name, "sql") then
server_settings.link.libpath:Add("other/mysql/vc2005libs")
server_settings.link.libs:Add("mysqlcppconn")
end
@ -255,9 +257,11 @@ function build(settings)
client_osxlaunch = {}
server_osxlaunch = {}
server_osxlaunch_mysql = {}
if platform == "macosx" then
client_osxlaunch = Compile(client_settings, "src/osxlaunch/client.m")
server_osxlaunch = Compile(launcher_settings, "src/osxlaunch/server.m")
server_osxlaunch_mysql = Compile(launcher_settings_mysql, "src/osxlaunch/server_mysql.m")
end
tools = {}
@ -275,8 +279,10 @@ function build(settings)
game_shared, game_server, zlib, server_link_other)
serverlaunch = {}
serverlaunch_mysql = {}
if platform == "macosx" then
serverlaunch = Link(launcher_settings, "serverlaunch", server_osxlaunch)
serverlaunch_mysql = Link(launcher_settings_mysql, "serverlaunch_mysql", server_osxlaunch_mysql)
end
versionserver_exe = Link(server_settings, "versionsrv", versionserver,
@ -290,18 +296,10 @@ function build(settings)
-- make targets
c = PseudoTarget("client".."_"..settings.config_name, client_exe, client_depends)
if string.find(settings.config_name, "nosql") then
s = PseudoTarget("server".."_"..settings.config_name, server_exe, serverlaunch)
if string.find(settings.config_name, "sql") then
s = PseudoTarget("server".."_"..settings.config_name, server_exe, serverlaunch_mysql, server_sql_depends)
else
if family == "windows" then
if string.find(settings.config_name, "sql") or not string.find(settings.config_name, "release") then
s = PseudoTarget("server".."_"..settings.config_name, server_exe, serverlaunch, server_sql_depends)
else
s = PseudoTarget("server".."_"..settings.config_name, server_exe, serverlaunch)
end
else
s = PseudoTarget("server".."_"..settings.config_name, server_exe, serverlaunch, server_sql_depends)
end
s = PseudoTarget("server".."_"..settings.config_name, server_exe, serverlaunch)
end
g = PseudoTarget("game".."_"..settings.config_name, client_exe, server_exe)
@ -320,42 +318,28 @@ debug_settings.config_name = "debug"
debug_settings.config_ext = "_d"
debug_settings.debug = 1
debug_settings.optimize = 0
debug_settings.cc.defines:Add("CONF_DEBUG", "CONF_SQL")
debug_settings.cc.defines:Add("CONF_DEBUG")
debug_nosql_settings = NewSettings()
debug_nosql_settings.config_name = "nosql_debug"
debug_nosql_settings.config_ext = "_nosql_d"
debug_nosql_settings.debug = 1
debug_nosql_settings.optimize = 0
debug_nosql_settings.cc.defines:Add("CONF_DEBUG")
debug_sql_settings = NewSettings()
debug_sql_settings.config_name = "sql_debug"
debug_sql_settings.config_ext = "_sql_d"
debug_sql_settings.debug = 1
debug_sql_settings.optimize = 0
debug_sql_settings.cc.defines:Add("CONF_DEBUG", "CONF_SQL")
release_settings = NewSettings()
release_settings.config_name = "release"
release_settings.config_ext = ""
release_settings.debug = 0
release_settings.optimize = 1
if family == "windows" then
release_settings.cc.defines:Add("CONF_RELEASE")
release_settings.config_ext = ""
release_nosql_settings = NewSettings()
release_nosql_settings.config_name = "sql_release"
release_nosql_settings.config_ext = "_sql"
release_nosql_settings.debug = 0
release_nosql_settings.optimize = 1
release_nosql_settings.cc.defines:Add("CONF_RELEASE", "CONF_SQL")
else
release_settings.cc.defines:Add("CONF_RELEASE")
release_settings.cc.defines:Add("CONF_RELEASE", "CONF_SQL")
release_settings.config_ext = ""
release_nosql_settings = NewSettings()
release_nosql_settings.config_name = "nosql_release"
release_nosql_settings.config_ext = "_nosql"
release_nosql_settings.debug = 0
release_nosql_settings.optimize = 1
release_nosql_settings.cc.defines:Add("CONF_RELEASE")
end
release_sql_settings = NewSettings()
release_sql_settings.config_name = "sql_release"
release_sql_settings.config_ext = "_sql"
release_sql_settings.debug = 0
release_sql_settings.optimize = 1
release_sql_settings.cc.defines:Add("CONF_RELEASE", "CONF_SQL")
if platform == "macosx" and arch == "ia32" then
debug_settings_ppc = debug_settings:Copy()
@ -363,81 +347,81 @@ if platform == "macosx" and arch == "ia32" then
debug_settings_ppc.config_ext = "_ppc_d"
debug_settings_ppc.cc.flags:Add("-arch ppc")
debug_settings_ppc.link.flags:Add("-arch ppc")
debug_settings_ppc.cc.defines:Add("CONF_DEBUG", "CONF_SQL")
debug_settings_ppc.cc.defines:Add("CONF_DEBUG")
debug_nosql_settings_ppc = debug_nosql_settings:Copy()
debug_nosql_settings_ppc.config_name = "nosql_debug_ppc"
debug_nosql_settings_ppc.config_ext = "_nosql_ppc_d"
debug_nosql_settings_ppc.cc.flags:Add("-arch ppc")
debug_nosql_settings_ppc.link.flags:Add("-arch ppc")
debug_nosql_settings_ppc.cc.defines:Add("CONF_DEBUG")
debug_sql_settings_ppc = debug_sql_settings:Copy()
debug_sql_settings_ppc.config_name = "sql_debug_ppc"
debug_sql_settings_ppc.config_ext = "_sql_ppc_d"
debug_sql_settings_ppc.cc.flags:Add("-arch ppc")
debug_sql_settings_ppc.link.flags:Add("-arch ppc")
debug_sql_settings_ppc.cc.defines:Add("CONF_DEBUG", "CONF_SQL")
release_settings_ppc = release_settings:Copy()
release_settings_ppc.config_name = "release_ppc"
release_settings_ppc.config_ext = "_ppc"
release_settings_ppc.cc.flags:Add("-arch ppc")
release_settings_ppc.link.flags:Add("-arch ppc")
release_settings_ppc.cc.defines:Add("CONF_RELEASE", "CONF_SQL")
release_settings_ppc.cc.defines:Add("CONF_RELEASE")
release_nosql_settings_ppc = release_nosql_settings:Copy()
release_nosql_settings_ppc.config_name = "nosql_release_ppc"
release_nosql_settings_ppc.config_ext = "_nosql_ppc"
release_nosql_settings_ppc.cc.flags:Add("-arch ppc")
release_nosql_settings_ppc.link.flags:Add("-arch ppc")
release_nosql_settings_ppc.cc.defines:Add("CONF_RELEASE")
release_sql_settings_ppc = release_sql_settings:Copy()
release_sql_settings_ppc.config_name = "sql_release_ppc"
release_sql_settings_ppc.config_ext = "_sql_ppc"
release_sql_settings_ppc.cc.flags:Add("-arch ppc")
release_sql_settings_ppc.link.flags:Add("-arch ppc")
release_sql_settings_ppc.cc.defines:Add("CONF_RELEASE", "CONF_SQL")
debug_settings_x86 = debug_settings:Copy()
debug_settings_x86.config_name = "debug_x86"
debug_settings_x86.config_ext = "_x86_d"
debug_settings_x86.cc.flags:Add("-arch i386")
debug_settings_x86.link.flags:Add("-arch i386")
debug_settings_x86.cc.defines:Add("CONF_DEBUG", "CONF_SQL")
debug_settings_x86.cc.defines:Add("CONF_DEBUG")
debug_nosql_settings_x86 = debug_nosql_settings:Copy()
debug_nosql_settings_x86.config_name = "nosql_debug_x86"
debug_nosql_settings_x86.config_ext = "_nosql_x86_d"
debug_nosql_settings_x86.cc.flags:Add("-arch i386")
debug_nosql_settings_x86.link.flags:Add("-arch i386")
debug_nosql_settings_x86.cc.defines:Add("CONF_DEBUG")
debug_sql_settings_x86 = debug_sql_settings:Copy()
debug_sql_settings_x86.config_name = "sql_debug_x86"
debug_sql_settings_x86.config_ext = "_sql_x86_d"
debug_sql_settings_x86.cc.flags:Add("-arch i386")
debug_sql_settings_x86.link.flags:Add("-arch i386")
debug_sql_settings_x86.cc.defines:Add("CONF_DEBUG", "CONF_SQL")
release_settings_x86 = release_settings:Copy()
release_settings_x86.config_name = "release_x86"
release_settings_x86.config_ext = "_x86"
release_settings_x86.cc.flags:Add("-arch i386")
release_settings_x86.link.flags:Add("-arch i386")
release_settings_x86.cc.defines:Add("CONF_RELEASE", "CONF_SQL")
release_settings_x86.cc.defines:Add("CONF_RELEASE")
release_nosql_settings_x86 = release_nosql_settings:Copy()
release_nosql_settings_x86.config_name = "nosql_release_x86"
release_nosql_settings_x86.config_ext = "_nosql_x86"
release_nosql_settings_x86.cc.flags:Add("-arch i386")
release_nosql_settings_x86.link.flags:Add("-arch i386")
release_nosql_settings_x86.cc.defines:Add("CONF_RELEASE")
release_sql_settings_x86 = release_sql_settings:Copy()
release_sql_settings_x86.config_name = "sql_release_x86"
release_sql_settings_x86.config_ext = "_sql_x86"
release_sql_settings_x86.cc.flags:Add("-arch i386")
release_sql_settings_x86.link.flags:Add("-arch i386")
release_sql_settings_x86.cc.defines:Add("CONF_RELEASE", "CONF_SQL")
ppc_d = build(debug_settings_ppc)
x86_d = build(debug_settings_x86)
sql_ppc_d = build(debug_nosql_settings_ppc)
sql_x86_d = build(debug_nosql_settings_x86)
sql_ppc_d = build(debug_sql_settings_ppc)
sql_x86_d = build(debug_sql_settings_x86)
ppc_r = build(release_settings_ppc)
x86_r = build(release_settings_x86)
sql_ppc_r = build(release_nosql_settings_ppc)
sql_x86_r = build(release_nosql_settings_x86)
sql_ppc_r = build(release_sql_settings_ppc)
sql_x86_r = build(release_sql_settings_x86)
DefaultTarget("game_debug_x86")
PseudoTarget("release", ppc_r, x86_r)
PseudoTarget("nosql_release", nosql_ppc_r, nosql_x86_r)
PseudoTarget("sql_release", sql_ppc_r, sql_x86_r)
PseudoTarget("debug", ppc_d, x86_d)
PseudoTarget("nosql_debug", nosql_ppc_d, nosql_x86_d)
PseudoTarget("sql_debug", sql_ppc_d, sql_x86_d)
PseudoTarget("server_release", "server_release_x86", "server_release_ppc")
PseudoTarget("server_nosql_release", "server_nosql_release_x86", "server_nosql_release_ppc")
PseudoTarget("server_sql_release", "server_sql_release_x86", "server_sql_release_ppc")
PseudoTarget("server_debug", "server_debug_x86", "server_debug_ppc")
PseudoTarget("server_nosql_debug", "server_nosql_debug_x86", "server_nosql_debug_ppc")
PseudoTarget("server_sql_debug", "server_sql_debug_x86", "server_sql_debug_ppc")
PseudoTarget("client_release", "client_release_x86", "client_release_ppc")
PseudoTarget("client_debug", "client_debug_x86", "client_debug_ppc")
else
build(debug_settings)
build(debug_nosql_settings)
build(debug_sql_settings)
build(release_settings)
build(release_nosql_settings)
build(release_sql_settings)
DefaultTarget("game_debug")
end

View file

@ -72,10 +72,13 @@ if include_data and not use_bundle:
shutil.copy("other/config_directory.bat", package_dir)
shutil.copy("SDL.dll", package_dir)
shutil.copy("freetype.dll", package_dir)
shutil.copy("libmysql.dll", package_dir)
shutil.copy("mysqlcppconn.dll", package_dir)
if include_exe and not use_bundle:
shutil.copy(name+exe_ext, package_dir)
shutil.copy(name+"-Server"+exe_ext, package_dir)
shutil.copy(name+"-Server_sql"+exe_ext, package_dir)
if include_src:
for p in ["src", "scripts", "datasrc", "other", "objs"]:
@ -86,8 +89,10 @@ if include_src:
if use_bundle:
os.system("lipo -create -output "+name+"-Server "+name+"-Server"+"_ppc "+name+"-Server"+"_x86")
os.system("lipo -create -output "+name+"-Server_sql "+name+"-Server_sql"+"_ppc "+name+"-Server_sql"+"_x86")
os.system("lipo -create -output "+name+" "+name+"_ppc "+name+"_x86")
os.system("lipo -create -output serverlaunch serverlaunch_ppc serverlaunch_x86")
os.system("lipo -create -output serverlaunch_sql serverlaunch_sql_ppc serverlaunch_sql_x86")
# create Teeworlds appfolder
clientbundle_content_dir = os.path.join(package_dir, "DDRace.app/Contents")
@ -128,7 +133,7 @@ if use_bundle:
""" % (version))
file(os.path.join(clientbundle_content_dir, "PkgInfo"), "w").write("APPL????")
# create Teeworlds Server appfolder
# create DDRace Server appfolder
serverbundle_content_dir = os.path.join(package_dir, "DDRace-Server.app/Contents")
serverbundle_bin_dir = os.path.join(serverbundle_content_dir, "MacOS")
serverbundle_resource_dir = os.path.join(serverbundle_content_dir, "Resources")
@ -163,6 +168,45 @@ if use_bundle:
<key>CFBundleVersion</key>
<string>%s</string>
</dict>
</plist>
""" % (version))
file(os.path.join(serverbundle_content_dir, "PkgInfo"), "w").write("APPL????")
# create DDRace Server sql appfolder
serverbundle_content_dir = os.path.join(package_dir, "DDRace-Server_sql.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, "DDRace-Server_sql.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"))
os.mkdir(os.path.join(serverbundle_resource_dir, "data/mapres"))
copydir("data/maps", serverbundle_resource_dir)
shutil.copy("other/icons/DDRace-Server.icns", serverbundle_resource_dir)
shutil.copy(name+"-Server"+exe_ext, serverbundle_bin_dir)
shutil.copy("serverlaunch_sql"+exe_ext, serverbundle_bin_dir + "/"+name+"_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>DDRace_Server</string>
<key>CFBundleIconFile</key>
<string>DDRace-Server_sql</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????")

View file

@ -1,5 +1,8 @@
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
#include <base/tl/string.h>
#include <engine/shared/config.h>
#include <base/math.h>
@ -10,7 +13,6 @@
#include "camera.h"
#include "controls.h"
#include <base/tl/string.h>
#include <engine/serverbrowser.h>
CCamera::CCamera()

View file

@ -1,6 +1,8 @@
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
#include <base/tl/string.h>
#include <engine/engine.h>
#include <engine/graphics.h>
#include <engine/textrender.h>
@ -18,8 +20,6 @@
#include "chat.h"
#include <base/tl/string.h>
CChat::CChat()
{
OnReset();

View file

@ -1,5 +1,8 @@
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
#include <base/tl/sorted_array.h>
#include <math.h>
#include <game/generated/client_data.h>
@ -28,8 +31,6 @@
#include "console.h"
#include <base/tl/sorted_array.h>
enum
{
CONSOLE_CLOSED,

View file

@ -1,5 +1,8 @@
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
#include <base/tl/sorted_array.h>
#include <base/math.h>
#include <engine/shared/config.h>
@ -13,8 +16,6 @@
#include "controls.h"
#include <base/tl/sorted_array.h>
CControls::CControls()
{
mem_zero(&m_LastData, sizeof(m_LastData));

View file

@ -1,5 +1,8 @@
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
#include <base/tl/sorted_array.h>
#include <engine/demo.h>
#include <engine/engine.h>
@ -16,8 +19,6 @@
#include "effects.h"
#include <base/tl/sorted_array.h>
inline vec2 RandomDir() { return normalize(vec2(frandom()-0.5f, frandom()-0.5f)); }
CEffects::CEffects()

View file

@ -1,5 +1,8 @@
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
#include <base/tl/array.h>
#include <math.h>
#include <base/system.h>

View file

@ -1,6 +1,8 @@
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
#include <base/tl/string.h>
#include <base/math.h>
#include <engine/demo.h>
@ -19,8 +21,6 @@
#include "menus.h"
#include <base/tl/string.h>
int CMenus::DoButton_DemoPlayer(const void *pID, const char *pText, int Checked, const CUIRect *pRect)
{
RenderTools()->DrawUIRect(pRect, vec4(1,1,1, Checked ? 0.10f : 0.5f)*ButtonColorMul(pID), CUI::CORNER_ALL, 5.0f);

View file

@ -1,6 +1,8 @@
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
#include <base/tl/string.h>
#include <base/math.h>
#include <engine/engine.h>
@ -25,8 +27,6 @@
#include "menus.h"
#include "skins.h"
#include <base/tl/string.h>
CMenusKeyBinder CMenus::m_Binder;
CMenusKeyBinder::CMenusKeyBinder()

View file

@ -1,5 +1,8 @@
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
#include <base/tl/sorted_array.h>
#include <engine/demo.h>
#include <engine/engine.h>
#include <engine/graphics.h>
@ -21,8 +24,6 @@
#include "players.h"
#include <base/tl/sorted_array.h>
void CPlayers::RenderHand(CTeeRenderInfo *pInfo, vec2 CenterPos, vec2 Dir, float AngleOffset, vec2 PostRotOffset)
{
// for drawing hand

View file

@ -1,5 +1,8 @@
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
#include <base/tl/array.h>
#include <engine/engine.h>
#include <engine/sound.h>
#include <engine/shared/config.h>

View file

@ -1,6 +1,8 @@
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
#include <base/tl/array.h>
#include <base/system.h>
#include <engine/shared/datafile.h>
@ -23,8 +25,6 @@
#include <game/localization.h>
#include <base/tl/array.h>
int CEditor::ms_CheckerTexture;
int CEditor::ms_BackgroundTexture;
int CEditor::ms_CursorTexture;

View file

@ -1,5 +1,8 @@
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
#include <base/tl/array.h>
#include <engine/client.h>
#include <engine/console.h>
#include <engine/graphics.h>
@ -8,8 +11,6 @@
#include <game/gamecore.h>
#include "ed_editor.h"
#include <base/tl/array.h>
template<typename T>
static int MakeVersion(int i, const T &v)
{ return (i<<16)+sizeof(T); }

View file

@ -1,5 +1,8 @@
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
#include <base/tl/sorted_array.h>
#include <new>
#include <base/math.h>
#include <engine/shared/config.h>
@ -16,7 +19,6 @@
#include <stdio.h>
#include <string.h>
#include <base/tl/sorted_array.h>
#include <engine/server/server.h>
#include "gamemodes/DDRace.h"
#include "score.h"

View file

@ -83,7 +83,7 @@ void runServer()
backing: NSBackingStoreBuffered
defer: NO];
[window setTitle: @"Teeworlds Server"];
[window setTitle: @"DDRace Server"];
view = [[[ServerView alloc] initWithFrame: graphicsRect] autorelease];
[view setEditable: NO];
@ -94,7 +94,7 @@ void runServer()
[window makeKeyAndOrderFront: nil];
[view listenTo: task];
[task setLaunchPath: [mainBundle pathForAuxiliaryExecutable: @"teeworlds_srv"]];
[task setLaunchPath: [mainBundle pathForAuxiliaryExecutable: @"DDRace-Server"]];
[task setArguments: arguments];
[task launch];
[NSApp run];

View file

@ -0,0 +1,112 @@
#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] appendAttributedString: attrstr];
int length = [[self textStorage] length];
NSRange range = NSMakeRange(length, 0);
[self scrollRangeToVisible: range];
[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: @"DDRace 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: @"DDRace-Server_sql"]];
[task setArguments: arguments];
[task launch];
[NSApp run];
[task terminate];
[NSApp release];
[pool release];
}
int main (int argc, char **argv)
{
runServer();
return 0;
}