clConsole.log( LOG_FATAL, QString("Error trying to open %1 database driver, check your wolfpack.xml").arg(SrvParams->databaseDriver()) );
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*/	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		#define CIAO_IF_ERROR if (error==1) { cNetwork::instance()->shutdown(); exit( -1 ); }	unsigned long tempSecs;	unsigned long loopSecs;	unsigned long tempTime;	uiCurrentTime = serverstarttime = getNormalizedTime();	serverState = STARTUP;	// Print a seperator somehow	/*clConsole.send( QString::number( sizeof( cUObject ) ) );	return 0;*/	clConsole.send( QString( "\n%1 %2 %3 \n\n" ).arg( wp_version.productstring.c_str() ).arg( wp_version.betareleasestring.c_str() ).arg( wp_version.verstring.c_str() ) );	clConsole.send( "Copyright (C) 1997, 98 Marcus Rating (Cironian)\n");	clConsole.send( "Copyright (C) 2000-2003 Wolfpack Development Team\n");	clConsole.send( "Wolfpack Homepage: http://www.wpdev.org/\n");	clConsole.send( "By using this software you agree to the license accompanying this release.\n");	clConsole.send( "Compiled on " __DATE__ " " __TIME__ "\n" );	clConsole.send( "\n" );		QString consoleTitle = QString( "%1 %2 %3" ).arg( wp_version.productstring.c_str() ).arg( wp_version.betareleasestring.c_str() ).arg( wp_version.verstring.c_str() );	clConsole.setConsoleTitle( consoleTitle );	// Startup normal Classes	try	{		atexit( freeClasses );		startClasses();	}	catch( ... )	{		clConsole.log( LOG_FATAL, "Couldn't start up classes." );		exit( -1 );	}	// Startup Translator	try	{		QString languageFile = SrvParams->getString( "General", "Language File", "", true );		if ( !languageFile.isEmpty() )		{			translator.load( languageFile, "." );			qApp->installTranslator( &translator );		}	}	catch( ... )	{		clConsole.log( LOG_FATAL, "Couldn't load translator." );		exit( -1 );	}	// Try to start up python	try	{		startPython( argc, argv );	}	catch( ... )	{		clConsole.log( LOG_FATAL, "Couldn't start up python." );		exit( -1 );	}	unsigned int i;	for( i = 1; i <= argc; ++i )		parseParameter( QString( argv[ i ] ) );	// Load data	DefManager->load();	clConsole.send( "\n" );	// Scriptmanager can't be in the try{} block because it sometimes throws firstchance exceptions	// we don't like	ScriptManager->load();	clConsole.send( "\n" );	// Try to load several data files	try	{		clConsole.send( "Loading skills...\n" );		Skills->load();		clConsole.send( "Loading accounts...\n" );		Accounts::instance()->load();		clConsole.send( "Loading ip blocking rules...\n" );		cNetwork::instance()->load();		clConsole.send( "Loading regions...\n" );		AllTerritories::instance()->load();		clConsole.send( "Loading spawn regions...\n" );		SpawnRegions::instance()->load();		clConsole.send( "Loading resources...\n" );		Resources::instance()->load();		clConsole.send( "Loading makemenus...\n" );		MakeMenus::instance()->load();		clConsole.send( "Loading contextmenus...\n" );		ContextMenus::instance()->reload();		// Load some MUL Data		clConsole.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 );		clConsole.send( "\n" );	}	catch( wpException &exception )	{		clConsole.log( LOG_FATAL, exception.error() );		exit( -1 );	}	catch( ... )	{		clConsole.log( LOG_FATAL, "Unknown error while loading data files." );		exit( -1 );	}	SetGlobalVars();	keeprun = 1;	// initial randomization call	srand( uiCurrentTime );	serverstarttime = getNormalizedTime();	// Try to open our driver	if( !persistentBroker->openDriver( SrvParams->databaseDriver() ) )	{				exit( -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();	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;	}	try	{		World::instance()->load();	}	catch( QString &error )	{		clConsole.log( LOG_FATAL, error );		exit( -1 );	}	catch( ... )	{		clConsole.log( LOG_FATAL, "An unknown error occured while loading the world." );		exit( -1 );	}	clConsole.PrepareProgress( "Initializing Multis" );	InitMultis();	clConsole.ProgressDone();	starttime = uiCurrentTime;	endtime = 0;	lclock = 0;	init_creatures(); // This initializes *fixed* data that should DEFINETLY be swaped out to the scripts !!!		if( SrvParams->serverLog() )		savelog( "Server startup", "server.log" );	uiCurrentTime = getNormalizedTime();	serverstarttime = getNormalizedTime(); // dont remove, its absolutly necassairy that its 3 times in the startup sequence for several timing reasons.	CIAO_IF_ERROR;    // print allowed clients		clConsole.send( "Allowed clients: " );	if( SrvParams->clientsAllowed().contains( "ALL" ) )		clConsole.send( "All\n\n" );	else		clConsole.send( SrvParams->clientsAllowed().join( ", " ) + "\n\n" );	clConsole.PrepareProgress( "Starting up Network" );	cNetwork::startup();	clConsole.ProgressDone();	CIAO_IF_ERROR;	if( SrvParams->enableLogin() )        clConsole.send( QString( "LoginServer running on port %1\n" ).arg( SrvParams->loginPort() ) );	if( SrvParams->enableGame() )        clConsole.send( QString( "GameServer running on port %1\n" ).arg( SrvParams->gamePort() ) );	PyThreadState *_save;	ScriptManager->onServerStart();	// Start the Console Input thread	cConsoleThread consoleThread;	consoleThread.start();	serverState = RUNNING;	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;		}		// Python threading - end		PyEval_RestoreThread( _save );		// It's more likely that we have a new key-press now		// Checking every 25 loops should be enough.		#if !defined( __unix__ )		if( loopTimeCount % 25 == 0 )		{			QMutexLocker lock(&commandMutex);			if( commandQueue.count() > 0 )			{								// Interpret Command				interpretCommand( commandQueue[0] );				commandQueue.erase( commandQueue.begin() );			}		}		#endif		if( loopTimeCount >= 1000 )		{			loopTimeCount = 0;			loopTime = 0;		}		++loopTimeCount;		loopSecs = getNormalizedTime();  // Starting time		if( networkTimeCount >= 1000 )		{			networkTimeCount = 0;			networkTime = 0;		}		tempSecs = getNormalizedTime();		// Process any Network Events		cNetwork::instance()->poll();		for( cUOSocket *mSock = cNetwork::instance()->first(); mSock; mSock = cNetwork::instance()->next() )		{			P_PLAYER player = mSock->player();			if ( player && !player->isGM() && player->clientIdleTime() && player->clientIdleTime() < uiCurrentTime )			{				clConsole.send( tr("Player %1 disconnected due to inactivity !\n").arg( player->name() ) );				cUOTxMessageWarning packet;				packet.setReason( cUOTxMessageWarning::Idle );				mSock->send( &packet );				mSock->disconnect();			}		}		tempTime = getNormalizedTime() - tempSecs ;		networkTime += tempTime;		++networkTimeCount;		if( timerTimeCount >= 1000 )		{			timerTimeCount = 0;			timerTime = 0;		}		tempSecs = getNormalizedTime() ;				checktimers();		uiCurrentTime = getNormalizedTime();		tempTime = getNormalizedTime() - tempSecs;		timerTime += tempTime;		++timerTimeCount;		if( autoTimeCount >= 1000 )		{			autoTimeCount = 0;			autoTime = 0;		}				tempSecs = getNormalizedTime() ;				checkauto();		tempTime = getNormalizedTime() - tempSecs;		autoTime += tempTime;		++autoTimeCount;		tempTime = getNormalizedTime() - loopSecs;		loopTime += tempTime;				qApp->processEvents( 40 );	}	serverState = SHUTDOWN;	consoleThread.cancel();	ScriptManager->onServerStop();	cNetwork::instance()->broadcast( tr( "The server is shutting down." ) );	clConsole.PrepareProgress( tr( "Shutting down network" ) );	cNetwork::shutdown();	clConsole.ProgressDone();	SrvParams->flush(); // Save config options	// Simply emptying of containers, no progressbar needed	DefManager->unload();	// Stop Python Interpreter.	ScriptManager->unload();	stopPython();	if( SrvParams->serverLog() ) 		savelog( "Server shutdown","server.log" );	return 0;}