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 Shutdown by Error!\n=======================================================================\n\n\n","server.log"); } else { clConsole.send("WOLFPACK: Server shutdown complete!\n"); if (SrvParams->serverLog()) savelog("Server Shutdown!\n=======================================================================\n\n\n","server.log"); }
int main(int argc, char *argv[]){	QApplication app( argc, argv ); // we need one instance	bDeamon = false ;	keeprun = 1; // First of all, we want to run :)	if (argc > 1)		for (int index=1; index < argc ; index++)		{			string 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) { Network->SockClose(); 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();	#ifndef __unix__ // If X-Wolf mandatory flag is set don't start if wolfpack hasn't been started by X-Wolf#if 0//	if (0)	  int win = GetWindowsVersion();	  switch (win)	  {	      case W95:		  clConsole.send("Detected Windows Version: Windows 95\n");		  break;		  case W98:		  clConsole.send("Detected Windows Version: Windows 98\n");		  break;		  case WME:		  clConsole.send("Detected Windows Version: Windows ME\n");		  break;		  case WNT4:		  clConsole.send("Detected Windows Version: Windows NT 4.0\n");		  break;		  case W2K:		  clConsole.send("Detected Windows Version: Windows 2000\n");		  break;		  case XP:		  clConsole.send("Detected Windows Version: Windows XP\n");		  break;	  }	  if (wp_version.verstruct.flags & WPV_REQXWOLF)	  {				    // link dynamicaly so that it starts on systems that don't have the isdebuggerpresent() system call (w95)		    bool detectable;		  	BOOL  (WINAPI *lpfIsDebuggerPresent)   (void  ) = NULL;	        HINSTANCE hInstLib = LoadLibraryA ("Kernel32.DLL" );            if (hInstLib==NULL) FreeLibrary(hInstLib); else lpfIsDebuggerPresent = ( BOOL ( WINAPI* ) ( void ) )  GetProcAddress ( hInstLib, "IsDebuggerPresent" );		    BOOL debuggerpresent=false;			if (lpfIsDebuggerPresent==NULL) { detectable=false; } else { detectable=true; debuggerpresent = lpfIsDebuggerPresent(); }			if (!debuggerpresent && detectable)			{		     		   			               clConsole.send("This is a Wolfpack version that needs to be started by X-Wolf\n");			   clConsole.send("Wolfpack server detected that is hasn't been started by X-Wolf, quitting\n");               FreeLibrary(hInstLib);			   exit(666);			} else if (!detectable)			{			   clConsole.send("This is a Wolfpack version that needs to be started by X-Wolf\n");			   clConsole.send("But Wolfpack can't detect if it is started by X-Wolf or not\n");						}			if (hInstLib!=NULL) FreeLibrary(hInstLib);			  }	#endif    #endif	//constart();	clConsole.send( "Starting WOLFPACK...\n" );	openings = 0;	scpfilename[0] = 0;	sprintf((char*)temp, "%s %s %s", wp_version.productstring.c_str() , wp_version.betareleasestring.c_str() , wp_version.verstring.c_str() );	#ifndef __unix__	SetConsoleTitle((char*)temp);	#endif#if 1	#ifndef __unix__ // wip stuff is currently only for windows stuff	  BOOL w = WIP_Init();	  // that's all :) no wip stuff in wp-core	  if (w==FALSE)	  {		  clConsole.send("Error starting WIP, WIP clients won't work");	  }    #endif#endif	StartClasses();	CIAO_IF_ERROR;	Map->Cache = 0;	Admin->ReadIni();	clConsole.send("Initializing script pointers...\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("Done.\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; // no wolfpack.ini crashes further startup process. so stop insted of crash	SetGlobalVars();	SkillVars();	// Set Creator Variables	clConsole.send("Loading skills...");	loadskills();	clConsole.send(" Done\n");	clConsole.send("Building pointer arrays...");	BuildPointerArray();	clConsole.send(" Done. \n");	Accounts->LoadAccounts();	keeprun=Network->kr; //LB. for some technical reasons global varaibles CANT be changed in constructors in c++.	error=Network->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();	loadspawnregions();	loadregions();	CIAO_IF_ERROR;	Map->Load();	if (keeprun==0) { Network->SockClose(); im_clearmenus(); DeleteClasses(); exit(-1); }	clConsole.send("Loading Teleport...");	read_in_teleport();	clConsole.send(" Done.\n");	//Map->TileCache(); // has to be exactly here, or loadnewlorld cant access correct tiles ... LB	// (it does access them ..)	srand(uiCurrentTime); // initial randomization call	clConsole.send("Loading vital scripts...\n");	loadmetagm();	loadmenuprivs();	serverstarttime=getNormalizedTime();	CIAO_IF_ERROR;	cwmWorldState->loadnewworld(SrvParams->worldSaveModule());	CIAO_IF_ERROR; // LB prevents file corruption	// 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, -1);		// 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.send("Clearing all trades...");	Trade->clearalltrades();	clConsole.send(" Done.\n");	//Boats --Check the multi status of every item character at start up to get them set!	clConsole.send("Initializing multis...");	InitMultis();	clConsole.send(" Done.\n");	//End Boats --^	clConsole.send("Loading IM Menus...");	im_loadmenus( "inscribe.gmp", TellScroll ); //loading gump for inscribe()	clConsole.send(" Done.\n");	gcollect();	clConsole.send("Initializing glowing-items...");	start_glow();	clConsole.send(" Done!\n"); // Magius(CHE) (1)	FD_ZERO(&conn);	starttime=uiCurrentTime;	endtime=0;	lclock=0;	clConsole.send(".");LogMessage("Initializing Queue System...");	initque(); // Initialize gmpages[] array	clConsole.send(".");LogMessage("Done. Loading custom titles...");	loadcustomtitle();	clConsole.send(" Done.\n");	clConsole.send("Initializing Network...");	Network->Initialize();	clConsole.send(" Done.\n");	cwmWorldState->announce(SrvParams->announceWorldSaves());	clConsole.send("Initializing sounds... ");	init_creatures(); //lb, initilises the creatures array (with soudfiles and other creatures infos)	clConsole.send("Done.\n");	clConsole.send("Initializing Magery System... ");	Magic->InitSpells();	clConsole.send("Done.\n");	clConsole.send("Loading IP Blocking rules...");	Network->LoadHosts_deny();	clConsole.send("Done\n");    if (SrvParams->EnableRA())         racInit();#ifndef __unix__	clearscreen(); // Moved by Magiu s(CHE (1)	sprintf(idname, "%s %s %s [WIN32] compiled by %s\nCurrent developers: %s", wp_version.productstring.c_str() ,  wp_version.betareleasestring.c_str(), wp_version.verstring.c_str() , wp_version.compiledbystring.c_str() , wp_version.codersstring.c_str() );#else	sprintf(idname, "%s %s %s [LINUX] compiled by %s\nCurrent developers: %s", wp_version.productstring.c_str() ,  wp_version.betareleasestring.c_str(), wp_version.verstring.c_str() , wp_version.compiledbystring.c_str(), wp_version.codersstring.c_str() );#endif	clConsole.send(idname);	clConsole.send("\n");	clConsole.send("(Configured for connections by UO Clients supported by Ignition)\n\n");	clConsole.send("Copyright (C) 1997, 98 Marcus Rating (Cironian)\n\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("%s %s %s\n",wp_version.productstring.c_str() , wp_version.betareleasestring.c_str() , wp_version.verstring.c_str() );	clConsole.send("Compiled on %s (%s %s)\n",__DATE__,__TIME__, wp_version.timezonestring.c_str() );	clConsole.send("Compiled by %s at %s\n", wp_version.compiledbystring.c_str() , wp_version.emailstring.c_str() );	clConsole.send("Programmed by: %s\n", wp_version.codersstring.c_str() );//	if (sizeof(tile_st)!=37)//		clConsole.send("This version of WOLFPACK was compiled incorrectly. sizeof(tile_st) = %d \n", sizeof(tile_st));	clConsole.send("\n");	// Server.scp status --- By Magius(CHE)	clConsole.send( "Server Settings:\n");	InitServerSettings();	item_char_test(); //LB	//Guilds->CheckConsistancy(); // LB	//Weather->run() ;	//Network->InitConnThread();////////////////////////////////////////////////////////////////////////////////////////////////////// Removed by Dupois July 18, 2000!// - Crashes server during if '#' - Save World option is used and corrupts the world file//	quite nicely I might add. safer to just use the old checkkey() call in the main's while loop.//InitKbThread();////////////////////////////////////////////////////////////////////////////////////////////////////#if 1 // Duke, experimental stuffvoid qsfLoad(char *fn, short depth); // Load a quest script file	if (argc > 1)		if (!strcmp(argv[1],"import") && argc>2)			qsfLoad(argv[2],0);#endif//#if 1 // Duke, experimental stuff//	clConsole.send("sizeof cItem: %i\n", sizeof(cItem) );//#endif	clConsole.send("WOLFPACK: Startup Complete.\n\n");	if (SrvParams->serverLog()) savelog("-=Server Startup=-\n=======================================================================\n","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;    if (MapTileHeight>300)		clConsole.send("BRITANNIA MAP SERVER\n");	else		clConsole.send("ILSHENAR MAP SERVER \n");    // print allowed clients    clConsole.send("\nAllowed clients\n");	if ( SrvParams->clientsAllowed().contains("ALL") )		clConsole.send("ALL");	else	{		QStringList::const_iterator it = SrvParams->clientsAllowed().begin();		for (; it != SrvParams->clientsAllowed().end(); ++it)		{			if ( *it != "SERVER_DEFAULT" )				clConsole.send((*it).latin1());			else				clConsole.send(wp_version.clientsupportedstring.latin1());		}	}    clConsole.send("\n");	while (keeprun)	{		// Uncomment by Dupois July 18, 2000! see note above about InitKbThread()		#if !defined(__unix__)		checkkey();		#endif		switch(SrvParams->niceLevel())		{			case 0: break;	// very unnice - hog all cpu time			case 1: if (now!=0) Sleep(10); else Sleep(100); break;			case 2: Sleep(10); break;			case 3: Sleep(40); break;// very nice			case 4: if (now!=0) Sleep(10); else Sleep(4000); break; // anti busy waiting			case 5: if (now!=0) Sleep(40); else Sleep(5000); break;			default: Sleep(10); break;		}		if(loopTimeCount >= 1000)		{			loopTimeCount = 0;			loopTime = 0;		}		++loopTimeCount;		loopSecs = getNormalizedTime();  // Starting time		if(networkTimeCount >= 1000)		{			networkTimeCount = 0;			networkTime = 0;		}		tempSecs = getNormalizedTime();		if(Respawn->AreWeRespawning())	// pseudo-respawn-thread (Duke)			Respawn->Continue();		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);					Network->Disconnect(r);				}			}		}		if( uiNextCheckConn<=uiCurrentTime || overflow) // Cut lag on CheckConn by not doing it EVERY loop.		{			Network->CheckConn();            if (SrvParams->EnableRA())               racCheckConn();			uiNextCheckConn = (unsigned int)( uiCurrentTime + ( double )( 3 * MY_CLOCKS_PER_SEC ) );		}		Network->CheckMessage();        if (SrvParams->EnableRA())           racCheckInp();		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;		Network->ClearBuffers();		tempTime = getNormalizedTime() - loopSecs;		loopTime += tempTime;	}	sysbroadcast("The server is shutting down.");	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");	}	clConsole.send("Clearing IM Menus...");	im_clearmenus();	clConsole.send(" Done.\nClosing sockets...");	Network->SockClose();	gcollect();		// cleanup before saving, especially items of deleted chars (Duke, 10.1.2001)	clConsole.send(" Done.\n");	cwmWorldState->savenewworld(SrvParams->worldSaveModule());	clConsole.send("Saving Wolfpack.xml...\n");	SrvParams->flush();	clConsole.send("\n");	clConsole.send("Deleting Classes...");	DeleteClasses();	clConsole.send("Done!\n");	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 Shutdown by Error!\n=======================================================================\n\n\n","server.log");	} else {		clConsole.send("WOLFPACK: Server shutdown complete!\n");		if (SrvParams->serverLog()) savelog("Server Shutdown!\n=======================================================================\n\n\n","server.log");	}	//endScrn() ;	return 0;}