cCommands::instance()->loadACLs();
int main( int argc, char *argv[] ){	QApplication app( argc, argv ); // we need one instance	keeprun = 1; // First of all, we want to run :)	// Parse our arguments	if (argc > 1)	{		for (int index=1; index < argc ; index++)		{			QString param( argv[ index ] );			checkparm( param );		}	}		if( bDeamon )	{		// Under unix we go to deamon mode		cout << "Going into deamon mode, returning local control to terminal" <<endl;		init_deamon();		// set up our console redirection		fstream fconsole;		fconsole.open("console.txt", ios::out);		clConsole.setStreams(NULL, (dynamic_cast<ostream*>(&fconsole)), NULL, NULL);		}	#if defined(__unix__)	// We can use SIGHUP, SIGINT, and SIGWINCH as we should never recive them	// So we will use SIGHUP to reload our scripts (kinda a standard for sighup to be reload)	// We will use a SIGUSR2 to be world save	// and SIGUSR1 for an Account reload	signal(SIGUSR2,&signal_handler) ;	signal(SIGHUP,&signal_handler) ;	signal(SIGUSR1,&signal_handler) ;	signal(SIGTERM,&signal_handler) ;	// we have this here, because convient, but should be set regardless of deamon or not.	// Keeps a disconnected socket from terminating the server.		#if !defined(__linux__)		signal(SIGPIPE,&signal_handler) ;	#endif	#endif		#define CIAO_IF_ERROR if (error==1) { cNetwork::instance()->shutdown(); im_clearmenus(); DeleteClasses(); exit(-1); }	int i;	unsigned long tempSecs;	unsigned long loopSecs;	unsigned long tempTime;	unsigned int uiNextCheckConn=0;//CheckConnection rate - AntiChrist ( thnx to LB )	unsigned long CheckClientIdle=0;	int r;	uiCurrentTime = serverstarttime = getNormalizedTime();	// Print a seperator somehow	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( "This program is free software; you can redistribute it and/or modify\n");	clConsole.send( "it under the terms of the GNU General Public License as published by\n");	clConsole.send( "the Free Software Foundation; either version 2 of the License, or\n");	clConsole.send( "(at your option) any later version.\n\n");	clConsole.send( "Compiled on %s (%s %s)\n",__DATE__,__TIME__, wp_version.timezonestring.c_str() );	clConsole.send( "Programmed by: %s\n", wp_version.codersstring.c_str() );	clConsole.send( "\n" );	openings = 0;	scpfilename[0] = 0;		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 );	StartClasses();	CIAO_IF_ERROR;	DefManager->load();	startPython( argc, argv );	ScriptManager->load();	Map->Cache = 0;	clConsole.send( "Loading scripts:\n" );	for(i=0;i<NUM_SCRIPTS;i++)	{		if (i==custom_npc_script || i==custom_item_script)//Don't initialize these till we know the file names ;-)			continue;		if (i==npc_script /*||i==create_script || i==regions_script*/)			i_scripts[i] = new Script(n_scripts[i], SCP_PRELOADABLE);		else			i_scripts[i] = new Script(n_scripts[i]);	}		clConsole.send( "\n" );	QTranslator translator(0); // must be valid thru app life.	QString languageFile = SrvParams->getString("General", "Language File", "", true);	if ( !languageFile.isEmpty() )	{		translator.load( languageFile, "./languages" );		app.installTranslator( &translator );	}	//Now lets load the custom scripts, if they have them defined...	i=0;	LoadCustomScripts();	if (argc>1)	{		if (!(strcmp(argv[1],"#")))		{			return MenuListGenerator();		}	}	CIAO_IF_ERROR;	SetGlobalVars();	SkillVars();	// Set Creator Variables	clConsole.PrepareProgress( "Loading skills" );	loadskills();	clConsole.ProgressDone();	Accounts->load();	keeprun = 1;	//keeprun = cNetwork::instance()->kr; //LB. for some technical reasons global varaibles CANT be changed in constructors in c++.	//error = cNetwork::instance()->faul; // i hope i can find a cleaner solution for that, but this works !!!	// has to here and not at the cal cause it would get overriten later	CIAO_IF_ERROR;	Map->Cache = SrvParams->cacheMulFiles();	cAllTerritories::getInstance()->load();	CIAO_IF_ERROR;	Map->Load();	if (keeprun==0) { cNetwork::instance()->shutdown(); im_clearmenus(); DeleteClasses(); exit(-1); }			srand(uiCurrentTime); // initial randomization call	clConsole.send("\nLoading vital scripts:\n");		read_in_teleport();	cCommands::instance()->loadACLs();	CIAO_IF_ERROR;	serverstarttime = getNormalizedTime();	cwmWorldState->loadnewworld(SrvParams->worldSaveModule());	CIAO_IF_ERROR; // LB prevents file corruption	cAllSpawnRegions::getInstance()->load();	// this loop is for things that have to be done after *all* items and chars have been loaded (Duke)	P_ITEM pi;	AllItemsIterator iterItems;	for (iterItems.Begin(); !iterItems.atEnd(); iterItems++)	{		pi = iterItems.GetData();		// 1. this relies on the container the item is in		StoreItemRandomValue(pi, "none");		// 2. needs the char to be loaded		if (pi->dx2 && isCharSerial(pi->contserial))	// effect on dex ? like plate eg.		{			P_CHAR pc = FindCharBySerial(pi->contserial);			if (pc)				pc->chgDex(pi->dx2);		}	}	clConsole.PrepareProgress( "Resetting all Trade windows" ); // Should automatically be done whenever a char disconnects	Trade->clearalltrades();	clConsole.ProgressDone();	clConsole.PrepareProgress( "Initializing Multis" );	InitMultis();	clConsole.ProgressDone();	gcollect();	starttime=uiCurrentTime;	endtime=0;	lclock=0;	clConsole.PrepareProgress( "Start glowing items" );	start_glow();	clConsole.ProgressDone();	clConsole.PrepareProgress( "Initializing GM Pages" );	initque();	clConsole.ProgressDone();	clConsole.PrepareProgress( "Loading custom tiles" );	loadcustomtitle();	clConsole.ProgressDone();	clConsole.PrepareProgress( "Starting up Network" );	cNetwork::startup();	clConsole.ProgressDone();	cwmWorldState->announce(SrvParams->announceWorldSaves());	init_creatures(); // This initializes *fixed* data that should DEFINETLY be swaped out to the scripts !!!	Magic->load(); // Load the new magic system	clConsole.PrepareProgress( "Loading IP Blocking rules" );	cNetwork::instance()->load();	clConsole.ProgressDone();    if (SrvParams->EnableRA())		RemoteAdmin::initialize( SrvParams->ra_port() );	item_char_test(); //LB	MsgBoardMaintenance(); // Bad system	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.send( QString( "Wolfpack running on port %1\n" ).arg( SrvParams->port() ) );	PyThreadState *_save;	while (keeprun)	{		// Uncomment by Dupois July 18, 2000! see note above about InitKbThread()		#if !defined(__unix__)		checkkey();		#endif		// Python threading - start		_save = PyEval_SaveThread();		switch(SrvParams->niceLevel())		{			case 0: break;	// very unnice - hog all cpu time			case 1: if (now!=0) ZThread::Thread::sleep(10); else ZThread::Thread::sleep(100); break;			case 2: ZThread::Thread::sleep(10); break;			case 3: ZThread::Thread::sleep(40); break;// very nice			case 4: if (now!=0) ZThread::Thread::sleep(10); else ZThread::Thread::sleep(4000); break; // anti busy waiting			case 5: if (now!=0) ZThread::Thread::sleep(40); else ZThread::Thread::sleep(5000); break;			default: ZThread::Thread::sleep(10); break;		}		// Python threading - end		PyEval_RestoreThread(_save);		if(loopTimeCount >= 1000)		{			loopTimeCount = 0;			loopTime = 0;		}		++loopTimeCount;		loopSecs = getNormalizedTime();  // Starting time		if(networkTimeCount >= 1000)		{			networkTimeCount = 0;			networkTime = 0;		}		tempSecs = getNormalizedTime();		if (CheckClientIdle<=uiCurrentTime)		{			CheckClientIdle=((SrvParams->inactivityTimeout()/2)*MY_CLOCKS_PER_SEC)+uiCurrentTime;			for (r=0;r<now;r++)			{				if ((!currchar[r] && perm[r]) && !currchar[r]->free					&& !currchar[r]->isGM()					&& currchar[r]->clientidletime()<uiCurrentTime										)				{					clConsole.send("Player %s disconnected due to inactivity !\n", currchar[r]->name.c_str());					//sysmessage(r,"you have been idle for too long and have been disconnected!");					char msg[3];					msg[0]=0x53;					msg[1]=0x07;					Xsend(r, msg, 2);					//cNetwork::instance()->Disconnect(r);				}			}		}		//cNetwork::instance()->CheckMessage();		cNetwork::instance()->poll(); // Poll the network        if (SrvParams->EnableRA())           RemoteAdmin::instance()->processNextEvent();		tempTime = getNormalizedTime() - tempSecs ;		networkTime += tempTime;		++networkTimeCount;		if(timerTimeCount >= 1000)		{			timerTimeCount = 0;			timerTime = 0;		}		tempSecs = getNormalizedTime() ;				checktimers();		uiCurrentTime = getNormalizedTime();//getNormalizedTime() only once		tempTime = getNormalizedTime() - tempSecs;		timerTime += tempTime;		++timerTimeCount;		if(autoTimeCount >= 1000)		{			autoTimeCount = 0;			autoTime = 0;		}				tempSecs = getNormalizedTime() ;				checkauto();		tempTime = getNormalizedTime() - tempSecs;		autoTime += tempTime;		++autoTimeCount;		//cNetwork::instance()->ClearBuffers();		tempTime = getNormalizedTime() - loopSecs;		loopTime += tempTime;		qApp->processOneEvent();	}	sysbroadcast("The server is shutting down.");	if ( SrvParams->EnableRA() )		RemoteAdmin::stop();	if (SrvParams->html()>0)	{		clConsole.send("Writing offline HTML page...");		offlinehtml();//HTML	// lb, the if prevents a crash on shutdown if html deactivated ...		clConsole.send(" Done.\n");	}	// No need for progress bar	Magic->unload();	im_clearmenus();		clConsole.PrepareProgress( "Closing sockets" );	cNetwork::shutdown();	gcollect();		// cleanup before saving, especially items of deleted chars (Duke, 10.1.2001)	clConsole.ProgressDone();		cwmWorldState->savenewworld( SrvParams->worldSaveModule() );		DefManager->unload();	clConsole.PrepareProgress( "Saving Wolfpack.xml" );	SrvParams->flush();	clConsole.ProgressDone();	if (NewErrorsLogged())		clConsole.send("New ERRORS have been logged. Please send the error*.log and critical*.log files to the dev team !\n");	if (NewWarningsLogged())		clConsole.send("New WARNINGS have been logged. Probably scripting errors. See the warnings*.log for details !\n");	if (error) {		clConsole.send("ERROR: Server terminated by error!\n");		if( SrvParams->serverLog() ) 			savelog("Server terminated by error","server.log");	} else {		clConsole.send("WOLFPACK: Server shutdown complete!\n");				if( SrvParams->serverLog() ) 			savelog("Server shutdown","server.log");	}	clConsole.PrepareProgress( "Deleting Classes" );	DeleteClasses();	clConsole.ProgressDone();	stopPython();	return 0;}