try {
int main( int argc, char *argv[] ){/*#if defined(_DEBUG)	InstallCrashHandler( HANDLE_HTTPREPORT, GSTSO_PARAMS | GSTSO_MODULE | GSTSO_SYMBOL | GSTSO_SRCLINE );	SetCustomMessage("A crash occurred. Please send this bug report to developers\n");	SetVersion(wp_version.verstring.c_str());#endif*/	keeprun = 1;	QApplication app( argc, argv, false ); // we need one instance	QTranslator translator( 0 ); // must be valid thru app life.	// Unix Signal Handling#if defined( Q_OS_UNIX )		signal( SIGHUP,  &signal_handler ); // Reload Scripts	signal( SIGUSR1, &signal_handler ); // Save World	signal( SIGUSR2, &signal_handler ); // Reload Accounts	signal( SIGTERM, &signal_handler ); // Terminate Server	signal( SIGPIPE, SIG_IGN );			// Ignore SIGPIPE#endif	serverState = STARTUP;	Console::instance()->setAttributes( true, false, true, 60, 140, 70, 12, FONT_NOSERIF );	Console::instance()->send( QString( "\n%1 %2 %3\n\n" ).arg( wp_version.productstring.latin1() ).arg( wp_version.betareleasestring.latin1() ).arg( wp_version.verstring.latin1() ) );	Console::instance()->setAttributes( false, false, false, 0xAF, 0xAF, 0xAF, 0, FONT_FIXEDWIDTH );	Console::instance()->send( "Copyright (C) 2000-2004 Wolfpack Development Team\n");	Console::instance()->send( "Wolfpack Homepage: http://www.wpdev.org/\n");	Console::instance()->send( "By using this software you agree to the license accompanying this release.\n");	Console::instance()->send( "Compiled on " __DATE__ " " __TIME__ "\n" );	Console::instance()->send( "\n" );		QString consoleTitle = QString( "%1 %2 %3" ).arg( wp_version.productstring.latin1() ).arg( wp_version.betareleasestring.latin1() ).arg( wp_version.verstring.latin1() );	Console::instance()->setConsoleTitle( consoleTitle );	// Startup normal Classes	try	{		atexit( freeClasses );		startClasses();	}	catch( ... )	{		Console::instance()->log( LOG_ERROR, "Couldn't start up classes.\n" );		return 1;	}	// Startup Translator	try	{		QString languageFile = SrvParams->getString( "General", "Language File", "", true );		if ( !languageFile.isEmpty() )		{			translator.load( languageFile, "." );			qApp->installTranslator( &translator );		}	}	catch( ... )	{		Console::instance()->log( LOG_ERROR, "Couldn't load translator.\n" );		return 1;	}	// Try to start up python	try	{		startPython( argc, argv );	}	catch( ... )	{		Console::instance()->log( LOG_ERROR, "Couldn't start up python.\n" );		return 1;	}	unsigned int i;	for( i = 1; i <= argc; ++i )		if( !parseParameter( QString( argv[ i ] ) ) )			return 1;	// Load data	DefManager->load();	Console::instance()->send( "\n" );/*	Console::instance()->send( "SIZEOF(cItem):" + QString::number( sizeof( cItem ) ) );		Sleep( 5000 );	for( int x = 0; x < 400000; ++x )	{		cItem *it = cItem::createFromScript( "e75" );	}	return 1;*/	// Scriptmanager can't be in the try{} block because it sometimes throws firstchance exceptions	// we don't like	ScriptManager::instance()->load();	Console::instance()->send( "\n" );	// Try to load several data files	try	{		Console::instance()->send( "Loading skills...\n" );		Skills->load();		Console::instance()->send( "Loading accounts...\n" );		Accounts::instance()->load();		Console::instance()->send( "Loading ip blocking rules...\n" );		cNetwork::instance()->load();		Console::instance()->send( "Loading regions...\n" );		AllTerritories::instance()->load();		Console::instance()->send( "Loading spawn regions...\n" );		SpawnRegions::instance()->load();		Console::instance()->send( "Loading resources...\n" );		Resources::instance()->load();		Console::instance()->send( "Loading makemenus...\n" );		MakeMenus::instance()->load();		Console::instance()->send( "Loading contextmenus...\n" );		ContextMenus::instance()->reload();		// Load some MUL Data		Console::instance()->send( "Loading muls...\n" );		TileCache::instance()->load( SrvParams->mulPath() );		MultiCache::instance()->load( SrvParams->mulPath() );				Map->registerMap(0, "map0.mul", 768, 512, "statics0.mul", "staidx0.mul");		Map->registerMap(1, "map0.mul", 768, 512, "statics0.mul", "staidx0.mul");		Map->registerMap(2, "map2.mul", 288, 200, "statics2.mul", "staidx2.mul");		Map->registerMap(3, "map3.mul", 320, 256, "statics3.mul", "staidx3.mul");		// For each map we register, register a GridMap as well		MapObjects::instance()->addMap( 0, 6144, 4096 );		MapObjects::instance()->addMap( 1, 6144, 4096 );		MapObjects::instance()->addMap( 2, 2304, 1600 );		MapObjects::instance()->addMap( 3, 2560, 2048 );		Console::instance()->send( "\n" );	}	catch( wpException &exception )	{		Console::instance()->log( LOG_ERROR, exception.error() );		return 1;	}	catch( ... )	{		Console::instance()->log( LOG_ERROR, "Unknown error while loading data files.\n" );		return 1;	}	SetGlobalVars();	// initial randomization call	srand( uiCurrentTime );	/*		Check for valid database driers.	*/	if( !persistentBroker->openDriver( SrvParams->databaseDriver() ) )	{				Console::instance()->log( LOG_ERROR, QString( "Unknown Worldsave Database Driver '%1', check your wolfpack.xml").arg( SrvParams->databaseDriver() ) );		return 1;	}	if( !persistentBroker->openDriver( SrvParams->accountsDriver() ) )	{		Console::instance()->log( LOG_ERROR, QString( "Unknown Account Database Driver '%1', check your wolfpack.xml").arg( SrvParams->accountsDriver() ) );		return 1;	}	// Registers our Built-in types into factory.	cPlayer::registerInFactory();	cNPC::registerInFactory();	cItem::registerInFactory();	cCorpse::registerInFactory();	cBoat::registerInFactory();	cHouse::registerInFactory();	cResourceItem::registerInFactory();	// NPC AI types	Monster_Aggressive_L0::registerInFactory();	Monster_Aggressive_L1::registerInFactory();	Human_Vendor::registerInFactory();	Human_Stablemaster::registerInFactory();	Human_Guard::registerInFactory();	Human_Guard_Called::registerInFactory();	Animal_Wild::registerInFactory();	Animal_Domestic::registerInFactory();	// Script NPC AI types	QStringList aiSections = DefManager->getSections( WPDT_AI );	QStringList::const_iterator aiit = aiSections.begin();	while( aiit != aiSections.end() )	{		ScriptAI::registerInFactory( *aiit );		++aiit;	}#if !defined(_DEBUG)	try	{#endif		World::instance()->load();#if !defined(_DEBUG)	}	catch( QString &error )	{		Console::instance()->log( LOG_ERROR, error );		return 1;	}	catch( ... )	{		Console::instance()->log( LOG_ERROR, "An unknown error occured while loading the world.\n" );		return 1;	}#endif	Console::instance()->PrepareProgress( "Initializing Multis" );	InitMultis();	Console::instance()->ProgressDone();	uiCurrentTime = getNormalizedTime();	// network startup	Console::instance()->PrepareProgress( "Starting up Network" );	cNetwork::startup();	Console::instance()->ProgressDone();	if( SrvParams->enableLogin() )        Console::instance()->send( QString( "LoginServer running on port %1\n" ).arg( SrvParams->loginPort() ) );	if( SrvParams->enableGame() )        Console::instance()->send( QString( "GameServer running on port %1\n" ).arg( SrvParams->gamePort() ) );	PyThreadState *_save;	ScriptManager::instance()->onServerStart();	serverState = RUNNING;	Console::instance()->start(); // Startup Console	QWaitCondition niceLevel;	// This is our main loop	while( keeprun )	{				// Python threading - start		_save = PyEval_SaveThread();		switch( SrvParams->niceLevel() )		{			case 0: break;	// very unnice - hog all cpu time			case 1: if ( cNetwork::instance()->count() != 0) niceLevel.wait(10); else niceLevel.wait(100); break;			case 2: niceLevel.wait(10); break;			case 3: niceLevel.wait(40); break;// very nice			case 4: if ( cNetwork::instance()->count() != 0 ) niceLevel.wait(10); else niceLevel.wait(4000); break; // anti busy waiting			case 5: if ( cNetwork::instance()->count() != 0 ) niceLevel.wait(40); else niceLevel.wait(5000); break;			default: niceLevel.wait(10); break;		}		qApp->processEvents( 40 );		// Python threading - end		PyEval_RestoreThread( _save );		// Update our currenttime		uiCurrentTime = getNormalizedTime();		// Perform Threadsafe Actions		actionMutex.lock();		while( actionQueue.begin() != actionQueue.end() )		{			eActionType type = *(actionQueue.begin());			actionQueue.erase( actionQueue.begin() );			switch( type )			{			case RELOAD_ACCOUNTS:				Console::instance()->PrepareProgress( "Reloading Accounts" );				Accounts::instance()->reload();				Console::instance()->ProgressDone();				break;			case RELOAD_CONFIGURATION:				Console::instance()->PrepareProgress( "Reloading Configuration" );				SrvParams->reload();				Console::instance()->ProgressDone();				break;			case RELOAD_SCRIPTS:				DefManager->reload();			case RELOAD_PYTHON:				ScriptManager::instance()->reload();				break;			case SAVE_WORLD:				World::instance()->save();				break;			}		}		actionMutex.unlock();		Console::instance()->poll();		// Process any Network Events		cNetwork::instance()->poll();		checkauto();	}	serverState = SHUTDOWN;	ScriptManager::instance()->onServerStop();	cNetwork::instance()->broadcast( tr( "The server is shutting down." ) );	Console::instance()->PrepareProgress( tr( "Shutting down network" ) );	cNetwork::shutdown();	Console::instance()->ProgressDone();	SrvParams->flush(); // Save config options	// Simply emptying of containers, no progressbar needed	DefManager->unload();	// Stop Python Interpreter.	ScriptManager::instance()->unload();	stopPython();	Console::instance()->stop(); // Stop the Console	return 0;}