Exemple #1
0
int main(int argc, char **argv) {
	RegisterExecutablePlatform(ExePlatformClientExport);
	set_exception_handler();
	
	LogFile->write(EQEMuLog::Status, "Client Files Export Utility");
	if(!EQEmuConfig::LoadConfig()) {
		LogFile->write(EQEMuLog::Error, "Unable to load configuration file.");
		return 1;
	}

	const EQEmuConfig *config = EQEmuConfig::get();
	if(!load_log_settings(config->LogSettingsFile.c_str())) {
		LogFile->write(EQEMuLog::Error, "Warning: unable to read %s.", config->LogSettingsFile.c_str());
	}

	SharedDatabase database;
	LogFile->write(EQEMuLog::Status, "Connecting to database...");
	if(!database.Connect(config->DatabaseHost.c_str(), config->DatabaseUsername.c_str(),
		config->DatabasePassword.c_str(), config->DatabaseDB.c_str(), config->DatabasePort)) {
		LogFile->write(EQEMuLog::Error, "Unable to connect to the database, cannot continue without a "
			"database connection");
		return 1;
	}
	
	ExportSpells(&database);
	ExportSkillCaps(&database);
	ExportBaseData(&database);
	
	return 0;
}
Exemple #2
0
int main(int argc, char **argv) {
	RegisterExecutablePlatform(ExePlatformClientExport);
	Log.LoadLogSettingsDefaults();
	set_exception_handler();

	Log.Out(Logs::General, Logs::Status, "Client Files Export Utility");
	if(!EQEmuConfig::LoadConfig()) {
		Log.Out(Logs::General, Logs::Error, "Unable to load configuration file.");
		return 1;
	}

	const EQEmuConfig *config = EQEmuConfig::get();

	SharedDatabase database;
	Log.Out(Logs::General, Logs::Status, "Connecting to database...");
	if(!database.Connect(config->DatabaseHost.c_str(), config->DatabaseUsername.c_str(),
		config->DatabasePassword.c_str(), config->DatabaseDB.c_str(), config->DatabasePort)) {
		Log.Out(Logs::General, Logs::Error, "Unable to connect to the database, cannot continue without a "
			"database connection");
		return 1;
	}

	/* Register Log System and Settings */
	database.LoadLogSettings(Log.log_settings);
	Log.StartFileLogs();

	ExportSpells(&database);
	ExportSkillCaps(&database);
	ExportBaseData(&database);

	Log.CloseFileLogs();

	return 0;
}
Exemple #3
0
int main(int argc, char **argv) {
	RegisterExecutablePlatform(ExePlatformSharedMemory);
	Log.LoadLogSettingsDefaults();
	set_exception_handler();

	Log.Out(Logs::General, Logs::Status, "Shared Memory Loader Program");
	if(!EQEmuConfig::LoadConfig()) {
		Log.Out(Logs::General, Logs::Error, "Unable to load configuration file.");
		return 1;
	}

	const EQEmuConfig *config = EQEmuConfig::get();

	SharedDatabase database;
	Log.Out(Logs::General, Logs::Status, "Connecting to database...");
	if(!database.Connect(config->DatabaseHost.c_str(), config->DatabaseUsername.c_str(),
		config->DatabasePassword.c_str(), config->DatabaseDB.c_str(), config->DatabasePort)) {
		Log.Out(Logs::General, Logs::Error, "Unable to connect to the database, cannot continue without a "
			"database connection");
		return 1;
	}

	/* Register Log System and Settings */
	database.LoadLogSettings(Log.log_settings);
	Log.StartFileLogs();

	bool load_all = true;
	bool load_items = false;
	bool load_factions = false;
	bool load_loot = false;
	bool load_skill_caps = false;
	bool load_spells = false;
	bool load_bd = false;
	if(argc > 1) {
		load_all = false;

		for(int i = 1; i < argc; ++i) {
			switch(argv[i][0]) {
			case 'a':
				if(strcasecmp("all", argv[i]) == 0) {
					load_all = true;
				}
				break;

			case 'b':
				if(strcasecmp("base_data", argv[i]) == 0) {
					load_bd = true;
				}
				break;

			case 'i':
				if(strcasecmp("items", argv[i]) == 0) {
					load_items = true;
				}
				break;

			case 'f':
				if(strcasecmp("factions", argv[i]) == 0) {
					load_factions = true;
				}
				break;

			case 'l':
				if(strcasecmp("loot", argv[i]) == 0) {
					load_loot = true;
				}
				break;

			case 's':
				if(strcasecmp("skill_caps", argv[i]) == 0) {
					load_skill_caps = true;
				} else if(strcasecmp("spells", argv[i]) == 0) {
					load_spells = true;
				}
				break;
			}
		}
	}

	if(load_all || load_items) {
		Log.Out(Logs::General, Logs::Status, "Loading items...");
		try {
			LoadItems(&database);
		} catch(std::exception &ex) {
			Log.Out(Logs::General, Logs::Error, "%s", ex.what());
			return 1;
		}
	}

	if(load_all || load_factions) {
		Log.Out(Logs::General, Logs::Status, "Loading factions...");
		try {
			LoadFactions(&database);
		} catch(std::exception &ex) {
			Log.Out(Logs::General, Logs::Error, "%s", ex.what());
			return 1;
		}
	}

	if(load_all || load_loot) {
		Log.Out(Logs::General, Logs::Status, "Loading loot...");
		try {
			LoadLoot(&database);
		} catch(std::exception &ex) {
			Log.Out(Logs::General, Logs::Error, "%s", ex.what());
			return 1;
		}
	}

	if(load_all || load_skill_caps) {
		Log.Out(Logs::General, Logs::Status, "Loading skill caps...");
		try {
			LoadSkillCaps(&database);
		} catch(std::exception &ex) {
			Log.Out(Logs::General, Logs::Error, "%s", ex.what());
			return 1;
		}
	}

	if(load_all || load_spells) {
		Log.Out(Logs::General, Logs::Status, "Loading spells...");
		try {
			LoadSpells(&database);
		} catch(std::exception &ex) {
			Log.Out(Logs::General, Logs::Error, "%s", ex.what());
			return 1;
		}
	}

	if(load_all || load_bd) {
		Log.Out(Logs::General, Logs::Status, "Loading base data...");
		try {
			LoadBaseData(&database);
		} catch(std::exception &ex) {
			Log.Out(Logs::General, Logs::Error, "%s", ex.what());
			return 1;
		}
	}

	Log.CloseFileLogs();

	return 0;
}
Exemple #4
0
int main(int argc, char** argv) {
	RegisterExecutablePlatform(ExePlatformWorld);
	set_exception_handler();

	/* Database Version Check */
	uint32 Database_Version = CURRENT_BINARY_DATABASE_VERSION;
	if (argc >= 2) { 
		if (strcasecmp(argv[1], "db_version") == 0) {
			std::cout << "Binary Database Version: " << Database_Version << std::endl;
			return 0;
		}
	}

	// Load server configuration
	_log(WORLD__INIT, "Loading server configuration..");
	if (!WorldConfig::LoadConfig()) {
		_log(WORLD__INIT_ERR, "Loading server configuration failed.");
		return 1;
	}
	const WorldConfig *Config=WorldConfig::get();

	if(!load_log_settings(Config->LogSettingsFile.c_str()))
		_log(WORLD__INIT, "Warning: Unable to read %s", Config->LogSettingsFile.c_str());
	else
		_log(WORLD__INIT, "Log settings loaded from %s", Config->LogSettingsFile.c_str());


	_log(WORLD__INIT, "CURRENT_VERSION: %s", CURRENT_VERSION);

	#ifdef _DEBUG
		_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
	#endif

	if (signal(SIGINT, CatchSignal) == SIG_ERR)	{
		_log(WORLD__INIT_ERR, "Could not set signal handler");
		return 1;
	}
	if (signal(SIGTERM, CatchSignal) == SIG_ERR)	{
		_log(WORLD__INIT_ERR, "Could not set signal handler");
		return 1;
	}
	#ifndef WIN32
	if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)	{
		_log(WORLD__INIT_ERR, "Could not set signal handler");
		return 1;
	}
	#endif

	// add login server config to list
	if (Config->LoginCount == 0) {
		if (Config->LoginHost.length()) {
			loginserverlist.Add(Config->LoginHost.c_str(), Config->LoginPort, Config->LoginAccount.c_str(), Config->LoginPassword.c_str());
			_log(WORLD__INIT, "Added loginserver %s:%i", Config->LoginHost.c_str(), Config->LoginPort);
		}
	} else {
		LinkedList<LoginConfig*> loginlist=Config->loginlist;
		LinkedListIterator<LoginConfig*> iterator(loginlist);
		iterator.Reset();
		while(iterator.MoreElements()) {
			loginserverlist.Add(iterator.GetData()->LoginHost.c_str(), iterator.GetData()->LoginPort, iterator.GetData()->LoginAccount.c_str(), iterator.GetData()->LoginPassword.c_str());
			_log(WORLD__INIT, "Added loginserver %s:%i", iterator.GetData()->LoginHost.c_str(), iterator.GetData()->LoginPort);
			iterator.Advance();
		}
	}

	_log(WORLD__INIT, "Connecting to MySQL...");
	if (!database.Connect(
		Config->DatabaseHost.c_str(),
		Config->DatabaseUsername.c_str(),
		Config->DatabasePassword.c_str(),
		Config->DatabaseDB.c_str(),
		Config->DatabasePort)) {
		_log(WORLD__INIT_ERR, "Cannot continue without a database connection.");
		return 1;
	}
	guild_mgr.SetDatabase(&database);

	if (argc >= 2) {
		char tmp[2];
		if (strcasecmp(argv[1], "help") == 0 || strcasecmp(argv[1], "?") == 0 || strcasecmp(argv[1], "/?") == 0 || strcasecmp(argv[1], "-?") == 0 || strcasecmp(argv[1], "-h") == 0 || strcasecmp(argv[1], "-help") == 0) {
			std::cout << "Worldserver command line commands:" << std::endl;
			std::cout << "adduser username password flag    - adds a user account" << std::endl;
			std::cout << "flag username flag    - sets GM flag on the account" << std::endl;
			std::cout << "startzone zoneshortname    - sets the starting zone" << std::endl;
			std::cout << "-holdzones    - reboots lost zones" << std::endl;
			return 0;
		}
		else if (strcasecmp(argv[1], "-holdzones") == 0) {
			std::cout << "Reboot Zones mode ON" << std::endl;
			holdzones = true;
		}
		else if (database.GetVariable("disablecommandline", tmp, 2)) {
			if (strlen(tmp) == 1) {
				if (tmp[0] == '1') {
					std::cerr << "Command line disabled in database... exiting" << std::endl;
					return 1;
				}
			}
		}
		else if (strcasecmp(argv[1], "adduser") == 0) {
			if (argc == 5) {
				if (Seperator::IsNumber(argv[4])) {
					if (atoi(argv[4]) >= 0 && atoi(argv[4]) <= 255) {
						if (database.CreateAccount(argv[2], argv[3], atoi(argv[4])) == 0) {
							std::cerr << "database.CreateAccount failed." << std::endl;
							return 1;
						}
						else {
							std::cout << "Account created: Username='******', Password='******', status=" << argv[4] << std::endl;
							return 0;
						}
					}
				}
			}
			std::cout << "Usage: world adduser username password flag" << std::endl;
			std::cout << "flag = 0, 1 or 2" << std::endl;
			return 0;
		}
		else if (strcasecmp(argv[1], "flag") == 0) {
			if (argc == 4) {
				if (Seperator::IsNumber(argv[3])) {
					if (atoi(argv[3]) >= 0 && atoi(argv[3]) <= 255) {
						if (database.SetAccountStatus(argv[2], atoi(argv[3]))){
							std::cout << "Account flagged: Username='******', status=" << argv[3] << std::endl;
							return 0;
						}
						else {
							std::cerr << "database.SetAccountStatus failed." << std::endl;
							return 1;
						}
					}
				}
			}
			std::cout << "Usage: world flag username flag" << std::endl;
			std::cout << "flag = 0-200" << std::endl;
			return 0;
		}
		else if (strcasecmp(argv[1], "startzone") == 0) {
			if (argc == 3) {
				if (strlen(argv[2]) < 3) {
					std::cerr << "Error: zone name too short" << std::endl;
					return 1;
				}
				else if (strlen(argv[2]) > 15) {
					std::cerr << "Error: zone name too long" << std::endl;
					return 1;
				}
				else {
					if (database.SetVariable("startzone", argv[2])) {
						std::cout << "Starting zone changed: '" << argv[2] << "'" << std::endl;
						return 0;
					}
					else {
						std::cerr << "database.SetVariable failed." << std::endl;
						return 1;
					}
				}
			}
			std::cout << "Usage: world startzone zoneshortname" << std::endl;
			return 0;
		}
		else {
			std::cerr << "Error, unknown command line option" << std::endl;
			return 1;
		}
	}

	if(Config->WorldHTTPEnabled) {
		_log(WORLD__INIT, "Starting HTTP world service...");
		http_server.Start(Config->WorldHTTPPort, Config->WorldHTTPMimeFile.c_str());
	} else {
		_log(WORLD__INIT, "HTTP world service disabled.");
	}

	_log(WORLD__INIT, "Checking Database Conversions..");
	database.CheckDatabaseConversions(); 
	_log(WORLD__INIT, "Loading variables..");
	database.LoadVariables();
	_log(WORLD__INIT, "Loading zones..");
	database.LoadZoneNames();
	_log(WORLD__INIT, "Clearing groups..");
	database.ClearGroup();
	_log(WORLD__INIT, "Clearing raids..");
	database.ClearRaid();
	database.ClearRaidDetails();
	database.ClearRaidLeader();
	_log(WORLD__INIT, "Loading items..");
	if (!database.LoadItems())
		_log(WORLD__INIT_ERR, "Error: Could not load item data. But ignoring");
	_log(WORLD__INIT, "Loading skill caps..");
	if (!database.LoadSkillCaps())
		_log(WORLD__INIT_ERR, "Error: Could not load skill cap data. But ignoring");
	_log(WORLD__INIT, "Loading guilds..");
	guild_mgr.LoadGuilds();
	//rules:
	{
		char tmp[64];
		if (database.GetVariable("RuleSet", tmp, sizeof(tmp)-1)) {
			_log(WORLD__INIT, "Loading rule set '%s'", tmp);
			if(!RuleManager::Instance()->LoadRules(&database, tmp)) {
				_log(WORLD__INIT_ERR, "Failed to load ruleset '%s', falling back to defaults.", tmp);
			}
		} else {
			if(!RuleManager::Instance()->LoadRules(&database, "default")) {
				_log(WORLD__INIT, "No rule set configured, using default rules");
			} else {
				_log(WORLD__INIT, "Loaded default rule set 'default'", tmp);
			}
		}
	}
	if(RuleB(World, ClearTempMerchantlist)){
		_log(WORLD__INIT, "Clearing temporary merchant lists..");
		database.ClearMerchantTemp();
	}
	_log(WORLD__INIT, "Loading EQ time of day..");
	if (!zoneserver_list.worldclock.loadFile(Config->EQTimeFile.c_str()))
		_log(WORLD__INIT_ERR, "Unable to load %s", Config->EQTimeFile.c_str());
	_log(WORLD__INIT, "Loading launcher list..");
	launcher_list.LoadList();

	char tmp[20];
	tmp[0] = '\0';
	database.GetVariable("holdzones",tmp, 20);
	if ((strcasecmp(tmp, "1") == 0)) {
		holdzones = true;
	}
	_log(WORLD__INIT, "Reboot zone modes %s",holdzones ? "ON" : "OFF");

	_log(WORLD__INIT, "Deleted %i stale player corpses from database", database.DeleteStalePlayerCorpses());
	if (RuleB(World, DeleteStaleCorpeBackups) == true) {
	_log(WORLD__INIT, "Deleted %i stale player backups from database", database.DeleteStalePlayerBackups());
	}

	_log(WORLD__INIT, "Loading adventures...");
	if(!adventure_manager.LoadAdventureTemplates())
	{
		_log(WORLD__INIT_ERR, "Unable to load adventure templates.");
	}

	if(!adventure_manager.LoadAdventureEntries())
	{
		_log(WORLD__INIT_ERR, "Unable to load adventure templates.");
	}

	adventure_manager.Load();
	adventure_manager.LoadLeaderboardInfo();

	_log(WORLD__INIT, "Purging expired instances");
	database.PurgeExpiredInstances();
	Timer PurgeInstanceTimer(450000);
	PurgeInstanceTimer.Start(450000);

	_log(WORLD__INIT, "Loading char create info...");
	database.LoadCharacterCreateAllocations();
	database.LoadCharacterCreateCombos();

	char errbuf[TCPConnection_ErrorBufferSize];
	if (tcps.Open(Config->WorldTCPPort, errbuf)) {
		_log(WORLD__INIT,"Zone (TCP) listener started.");
	} else {
		_log(WORLD__INIT_ERR,"Failed to start zone (TCP) listener on port %d:",Config->WorldTCPPort);
		_log(WORLD__INIT_ERR,"        %s",errbuf);
		return 1;
	}
	if (eqsf.Open()) {
		_log(WORLD__INIT,"Client (UDP) listener started.");
	} else {
		_log(WORLD__INIT_ERR,"Failed to start client (UDP) listener (port 9000)");
		return 1;
	}

	//register all the patches we have avaliable with the stream identifier.
	EQStreamIdentifier stream_identifier;
	RegisterAllPatches(stream_identifier);
	zoneserver_list.shutdowntimer = new Timer(60000);
	zoneserver_list.shutdowntimer->Disable();
	zoneserver_list.reminder = new Timer(20000);
	zoneserver_list.reminder->Disable();
	Timer InterserverTimer(INTERSERVER_TIMER); // does MySQL pings and auto-reconnect
	InterserverTimer.Trigger();
	uint8 ReconnectCounter = 100;
	EQStream* eqs;
	EmuTCPConnection* tcpc;
	EQStreamInterface *eqsi;

	while(RunLoops) {
		Timer::SetCurrentTime();

		//check the factory for any new incoming streams.
		while ((eqs = eqsf.Pop())) {
			//pull the stream out of the factory and give it to the stream identifier
			//which will figure out what patch they are running, and set up the dynamic
			//structures and opcodes for that patch.
			struct in_addr	in;
			in.s_addr = eqs->GetRemoteIP();
			_log(WORLD__CLIENT, "New connection from %s:%d", inet_ntoa(in),ntohs(eqs->GetRemotePort()));
			stream_identifier.AddStream(eqs);	//takes the stream
		}

		//give the stream identifier a chance to do its work....
		stream_identifier.Process();

		//check the stream identifier for any now-identified streams
		while((eqsi = stream_identifier.PopIdentified())) {
			//now that we know what patch they are running, start up their client object
			struct in_addr	in;
			in.s_addr = eqsi->GetRemoteIP();
			if (RuleB(World, UseBannedIPsTable)){ //Lieka: Check to see if we have the responsibility for blocking IPs.
				_log(WORLD__CLIENT, "Checking inbound connection %s against BannedIPs table", inet_ntoa(in));
				if (!database.CheckBannedIPs(inet_ntoa(in))){ //Lieka: Check inbound IP against banned IP table.
					_log(WORLD__CLIENT, "Connection %s PASSED banned IPs check. Processing connection.", inet_ntoa(in));
					Client* client = new Client(eqsi);
					// @merth: client->zoneattempt=0;
					client_list.Add(client);
				} else {
					_log(WORLD__CLIENT, "Connection from %s FAILED banned IPs check. Closing connection.", inet_ntoa(in));
					eqsi->Close(); //Lieka: If the inbound IP is on the banned table, close the EQStream.
				}
			}
			if (!RuleB(World, UseBannedIPsTable)){
					_log(WORLD__CLIENT, "New connection from %s:%d, processing connection", inet_ntoa(in), ntohs(eqsi->GetRemotePort()));
					Client* client = new Client(eqsi);
					// @merth: client->zoneattempt=0;
					client_list.Add(client);
			}
		}

		client_list.Process();

		while ((tcpc = tcps.NewQueuePop())) {
			struct in_addr in;
			in.s_addr = tcpc->GetrIP();
			_log(WORLD__ZONE, "New TCP connection from %s:%d", inet_ntoa(in),tcpc->GetrPort());
			console_list.Add(new Console(tcpc));
		}

		if(PurgeInstanceTimer.Check())
		{
			database.PurgeExpiredInstances();
		}

		//check for timeouts in other threads
		timeout_manager.CheckTimeouts();

		loginserverlist.Process();

		console_list.Process();

		zoneserver_list.Process();

		launcher_list.Process();

		UCSLink.Process();

		QSLink.Process();

		LFPGroupList.Process();

		adventure_manager.Process();

		if (InterserverTimer.Check()) {
			InterserverTimer.Start();
			database.ping();
			// AsyncLoadVariables(dbasync, &database);
			ReconnectCounter++;
			if (ReconnectCounter >= 12) { // only create thread to reconnect every 10 minutes. previously we were creating a new thread every 10 seconds
				ReconnectCounter = 0;
				if (loginserverlist.AllConnected() == false) {
#ifdef _WINDOWS
					_beginthread(AutoInitLoginServer, 0, nullptr);
#else
					pthread_t thread;
					pthread_create(&thread, nullptr, &AutoInitLoginServer, nullptr);
#endif
				}
			}
		}
		if (numclients == 0) {
			Sleep(50);
			continue;
		}
		Sleep(20);
	}
	_log(WORLD__SHUTDOWN,"World main loop completed.");
	_log(WORLD__SHUTDOWN,"Shutting down console connections (if any).");
	console_list.KillAll();
	_log(WORLD__SHUTDOWN,"Shutting down zone connections (if any).");
	zoneserver_list.KillAll();
	_log(WORLD__SHUTDOWN,"Zone (TCP) listener stopped.");
	tcps.Close();
	_log(WORLD__SHUTDOWN,"Client (UDP) listener stopped.");
	eqsf.Close();
	_log(WORLD__SHUTDOWN,"Signaling HTTP service to stop...");
	http_server.Stop();

	CheckEQEMuErrorAndPause();
	return 0;
}
int main() {
	RegisterExecutablePlatform(ExePlatformWebInterface);
	Log.LoadLogSettingsDefaults();
	
	set_exception_handler();
	register_methods();
	Timer InterserverTimer(INTERSERVER_TIMER); // does auto-reconnect
	Log.Out(Logs::General, Logs::WebInterface_Server, "Starting EQEmu Web Server.");
	
	if (signal(SIGINT, CatchSignal) == SIG_ERR)	{
		Log.Out(Logs::General, Logs::Error, "Could not set signal handler");
		return 1;
	}
	
	if (signal(SIGTERM, CatchSignal) == SIG_ERR)	{
		Log.Out(Logs::General, Logs::Error, "Could not set signal handler");
		return 1;
	}

	Timer writable_socket_timer;
	config = EQEmuConfig::get();
	lws_context_creation_info info;
	memset(&info, 0, sizeof info);
	info.port = config->WebInterfacePort;
	info.protocols = protocols;
	info.extensions = nullptr;
	info.gid = -1;
	info.uid = -1;

	context = libwebsocket_create_context(&info);
	if (context == NULL) {
		Log.Out(Logs::General, Logs::Error, "Could not create websocket handler.");
		return 1;
	}

	db = new SharedDatabase();
	Log.Out(Logs::General, Logs::WebInterface_Server, "Connecting to database...");
	if(!db->Connect(config->DatabaseHost.c_str(), config->DatabaseUsername.c_str(),
		config->DatabasePassword.c_str(), config->DatabaseDB.c_str(), config->DatabasePort)) {
		Log.Out(Logs::General, Logs::WebInterface_Server, "Unable to connect to the database, cannot continue without a database connection");
		return 1;
	}
	db->LoadLogSettings(Log.log_settings);
	worldserver = new WorldServer(config->SharedKey);
	worldserver->Connect();
	writable_socket_timer.Start(10);

	while(run) { 
		Timer::SetCurrentTime(); 
		
		if (InterserverTimer.Check()) {
			if (worldserver->TryReconnect() && (!worldserver->Connected()))
				worldserver->AsyncConnect();
		}
		worldserver->Process(); 

		timeout_manager.CheckTimeouts();

		if (writable_socket_timer.Check(true)) {
			libwebsocket_callback_on_writable_all_protocol(&protocols[1]);
		}

		libwebsocket_service(context, 5);
		Sleep(1);
	}

	safe_delete(worldserver);
	safe_delete(db);
	libwebsocket_context_destroy(context);

	return 0;
}
Exemple #6
0
int main(int argc, char** argv) {
    RegisterExecutablePlatform(ExePlatformZone);
    Log.LoadLogSettingsDefaults();

    set_exception_handler();
    QServ = new QueryServ;

    Log.Out(Logs::General, Logs::Zone_Server, "Loading server configuration..");
    if(!ZoneConfig::LoadConfig()) {
        Log.Out(Logs::General, Logs::Error, "Loading server configuration failed.");
        return 1;
    }
    Config = ZoneConfig::get();

    const char *zone_name;
    uint32 instance_id = 0;
    std::string z_name;
    if(argc == 4) {
        instance_id = atoi(argv[3]);
        worldserver.SetLauncherName(argv[2]);
        auto zone_port = SplitString(argv[1], ':');

        if(!zone_port.empty()) {
            z_name = zone_port[0];
        }

        if(zone_port.size() > 1) {
            std::string p_name = zone_port[1];
            Config->SetZonePort(atoi(p_name.c_str()));
        }

        worldserver.SetLaunchedName(z_name.c_str());
        if(strncmp(z_name.c_str(), "dynamic_", 8) == 0) {
            zone_name = ".";
        }
        else {
            zone_name = z_name.c_str();
        }
    } else if(argc == 3) {
        worldserver.SetLauncherName(argv[2]);
        auto zone_port = SplitString(argv[1], ':');

        if(!zone_port.empty()) {
            z_name = zone_port[0];
        }

        if(zone_port.size() > 1) {
            std::string p_name = zone_port[1];
            Config->SetZonePort(atoi(p_name.c_str()));
        }

        worldserver.SetLaunchedName(z_name.c_str());
        if(strncmp(z_name.c_str(), "dynamic_", 8) == 0) {
            zone_name = ".";
        } else {
            zone_name = z_name.c_str();
        }
    } else if (argc == 2) {
        worldserver.SetLauncherName("NONE");
        auto zone_port = SplitString(argv[1], ':');

        if(!zone_port.empty()) {
            z_name = zone_port[0];
        }

        if(zone_port.size() > 1) {
            std::string p_name = zone_port[1];
            Config->SetZonePort(atoi(p_name.c_str()));
        }

        worldserver.SetLaunchedName(z_name.c_str());
        if(strncmp(z_name.c_str(), "dynamic_", 8) == 0) {
            zone_name = ".";
        }
        else {
            zone_name = z_name.c_str();
        }
    } else {
        zone_name = ".";
        worldserver.SetLaunchedName(".");
        worldserver.SetLauncherName("NONE");
    }

    worldserver.SetPassword(Config->SharedKey.c_str());

    Log.Out(Logs::General, Logs::Zone_Server, "Connecting to MySQL...");
    if (!database.Connect(
                Config->DatabaseHost.c_str(),
                Config->DatabaseUsername.c_str(),
                Config->DatabasePassword.c_str(),
                Config->DatabaseDB.c_str(),
                Config->DatabasePort)) {
        Log.Out(Logs::General, Logs::Error, "Cannot continue without a database connection.");
        return 1;
    }

#ifdef BOTS
    if (!botdb.Connect(
                Config->DatabaseHost.c_str(),
                Config->DatabaseUsername.c_str(),
                Config->DatabasePassword.c_str(),
                Config->DatabaseDB.c_str(),
                Config->DatabasePort)) {
        Log.Out(Logs::General, Logs::Error, "Cannot continue without a bots database connection.");
        return 1;
    }
#endif

    /* Register Log System and Settings */
    Log.OnLogHookCallBackZone(&Zone::GMSayHookCallBackProcess);
    database.LoadLogSettings(Log.log_settings);
    Log.StartFileLogs();

    /* Guilds */
    guild_mgr.SetDatabase(&database);
    GuildBanks = nullptr;

#ifdef _EQDEBUG
    _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif

    Log.Out(Logs::General, Logs::Zone_Server, "CURRENT_VERSION: %s", CURRENT_VERSION);

    /*
    * Setup nice signal handlers
    */
    if (signal(SIGINT, CatchSignal) == SIG_ERR)	{
        Log.Out(Logs::General, Logs::Error, "Could not set signal handler");
        return 1;
    }
    if (signal(SIGTERM, CatchSignal) == SIG_ERR)	{
        Log.Out(Logs::General, Logs::Error, "Could not set signal handler");
        return 1;
    }
#ifndef WIN32
    if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)	{
        Log.Out(Logs::General, Logs::Error, "Could not set signal handler");
        return 1;
    }
#endif

    Log.Out(Logs::General, Logs::Zone_Server, "Mapping Incoming Opcodes");
    MapOpcodes();

    Log.Out(Logs::General, Logs::Zone_Server, "Loading Variables");
    database.LoadVariables();

    std::string hotfix_name;
    if(database.GetVariable("hotfix_name", hotfix_name)) {
        if(!hotfix_name.empty()) {
            Log.Out(Logs::General, Logs::Zone_Server, "Current hotfix in use: '%s'", hotfix_name.c_str());
        }
    }

    Log.Out(Logs::General, Logs::Zone_Server, "Loading zone names");
    database.LoadZoneNames();

    Log.Out(Logs::General, Logs::Zone_Server, "Loading items");
    if(!database.LoadItems(hotfix_name)) {
        Log.Out(Logs::General, Logs::Error, "Loading items FAILED!");
        Log.Out(Logs::General, Logs::Error, "Failed. But ignoring error and going on...");
    }

    Log.Out(Logs::General, Logs::Zone_Server, "Loading npc faction lists");
    if(!database.LoadNPCFactionLists(hotfix_name)) {
        Log.Out(Logs::General, Logs::Error, "Loading npcs faction lists FAILED!");
        return 1;
    }
    Log.Out(Logs::General, Logs::Zone_Server, "Loading loot tables");
    if(!database.LoadLoot(hotfix_name)) {
        Log.Out(Logs::General, Logs::Error, "Loading loot FAILED!");
        return 1;
    }
    Log.Out(Logs::General, Logs::Zone_Server, "Loading skill caps");
    if(!database.LoadSkillCaps(std::string(hotfix_name))) {
        Log.Out(Logs::General, Logs::Error, "Loading skill caps FAILED!");
        return 1;
    }

    Log.Out(Logs::General, Logs::Zone_Server, "Loading spells");
    if(!database.LoadSpells(hotfix_name, &SPDAT_RECORDS, &spells)) {
        Log.Out(Logs::General, Logs::Error, "Loading spells FAILED!");
        return 1;
    }

    Log.Out(Logs::General, Logs::Zone_Server, "Loading base data");
    if(!database.LoadBaseData(hotfix_name)) {
        Log.Out(Logs::General, Logs::Error, "Loading base data FAILED!");
        return 1;
    }

    Log.Out(Logs::General, Logs::Zone_Server, "Loading guilds");
    guild_mgr.LoadGuilds();

    Log.Out(Logs::General, Logs::Zone_Server, "Loading factions");
    database.LoadFactionData();

    Log.Out(Logs::General, Logs::Zone_Server, "Loading titles");
    title_manager.LoadTitles();

    Log.Out(Logs::General, Logs::Zone_Server, "Loading tributes");
    database.LoadTributes();

    Log.Out(Logs::General, Logs::Zone_Server, "Loading corpse timers");
    database.GetDecayTimes(npcCorpseDecayTimes);

    Log.Out(Logs::General, Logs::Zone_Server, "Loading commands");
    int retval=command_init();
    if(retval<0)
        Log.Out(Logs::General, Logs::Error, "Command loading FAILED");
    else
        Log.Out(Logs::General, Logs::Zone_Server, "%d commands loaded", retval);

    //rules:
    {
        std::string tmp;
        if (database.GetVariable("RuleSet", tmp)) {
            Log.Out(Logs::General, Logs::Zone_Server, "Loading rule set '%s'", tmp.c_str());
            if(!RuleManager::Instance()->LoadRules(&database, tmp.c_str())) {
                Log.Out(Logs::General, Logs::Error, "Failed to load ruleset '%s', falling back to defaults.", tmp.c_str());
            }
        } else {
            if(!RuleManager::Instance()->LoadRules(&database, "default")) {
                Log.Out(Logs::General, Logs::Zone_Server, "No rule set configured, using default rules");
            } else {
                Log.Out(Logs::General, Logs::Zone_Server, "Loaded default rule set 'default'", tmp.c_str());
            }
        }
    }

#ifdef BOTS
    Log.Out(Logs::General, Logs::Zone_Server, "Loading bot commands");
    int botretval = bot_command_init();
    if (botretval<0)
        Log.Out(Logs::General, Logs::Error, "Bot command loading FAILED");
    else
        Log.Out(Logs::General, Logs::Zone_Server, "%d bot commands loaded", botretval);
#endif

    if(RuleB(TaskSystem, EnableTaskSystem)) {
        Log.Out(Logs::General, Logs::Tasks, "[INIT] Loading Tasks");
        taskmanager = new TaskManager;
        taskmanager->LoadTasks();
    }

    parse = new QuestParserCollection();
#ifdef LUA_EQEMU
    auto lua_parser = new LuaParser();
    parse->RegisterQuestInterface(lua_parser, "lua");
#endif

#ifdef EMBPERL
    auto perl_parser = new PerlembParser();
    parse->RegisterQuestInterface(perl_parser, "pl");

    /* Load Perl Event Export Settings */
    parse->LoadPerlEventExportSettings(parse->perl_event_export_settings);

#endif

    //now we have our parser, load the quests
    Log.Out(Logs::General, Logs::Zone_Server, "Loading quests");
    parse->ReloadQuests();

    if (!worldserver.Connect()) {
        Log.Out(Logs::General, Logs::Error, "Worldserver Connection Failed :: worldserver.Connect()");
    }

    Timer InterserverTimer(INTERSERVER_TIMER); // does MySQL pings and auto-reconnect
#ifdef EQPROFILE
#ifdef PROFILE_DUMP_TIME
    Timer profile_dump_timer(PROFILE_DUMP_TIME*1000);
    profile_dump_timer.Start();
#endif
#endif
    if (!strlen(zone_name) || !strcmp(zone_name,".")) {
        Log.Out(Logs::General, Logs::Zone_Server, "Entering sleep mode");
    } else if (!Zone::Bootup(database.GetZoneID(zone_name), instance_id, true)) {
        Log.Out(Logs::General, Logs::Error, "Zone Bootup failed :: Zone::Bootup");
        zone = 0;
    }

    //register all the patches we have avaliable with the stream identifier.
    EQStreamIdentifier stream_identifier;
    RegisterAllPatches(stream_identifier);

#ifndef WIN32
    Log.Out(Logs::Detail, Logs::None,  "Main thread running with thread id %d", pthread_self());
#endif

    Timer quest_timers(100);
    UpdateWindowTitle();
    bool worldwasconnected = worldserver.Connected();
    std::shared_ptr<EQStream> eqss;
    EQStreamInterface *eqsi;
    uint8 IDLEZONEUPDATE = 200;
    uint8 ZONEUPDATE = 10;
    Timer zoneupdate_timer(ZONEUPDATE);
    zoneupdate_timer.Start();
    while(RunLoops) {
        {   //profiler block to omit the sleep from times

            //Advance the timer to our current point in time
            Timer::SetCurrentTime();

            worldserver.Process();

            if (!eqsf.IsOpen() && Config->ZonePort != 0) {
                Log.Out(Logs::General, Logs::Zone_Server, "Starting EQ Network server on port %d", Config->ZonePort);
                if (!eqsf.Open(Config->ZonePort)) {
                    Log.Out(Logs::General, Logs::Error, "Failed to open port %d", Config->ZonePort);
                    ZoneConfig::SetZonePort(0);
                    worldserver.Disconnect();
                    worldwasconnected = false;
                }
            }

            //check the factory for any new incoming streams.
            while ((eqss = eqsf.Pop())) {
                //pull the stream out of the factory and give it to the stream identifier
                //which will figure out what patch they are running, and set up the dynamic
                //structures and opcodes for that patch.
                struct in_addr	in;
                in.s_addr = eqss->GetRemoteIP();
                Log.Out(Logs::Detail, Logs::World_Server, "New connection from %s:%d", inet_ntoa(in), ntohs(eqss->GetRemotePort()));
                stream_identifier.AddStream(eqss);	//takes the stream
            }

            //give the stream identifier a chance to do its work....
            stream_identifier.Process();

            //check the stream identifier for any now-identified streams
            while((eqsi = stream_identifier.PopIdentified())) {
                //now that we know what patch they are running, start up their client object
                struct in_addr	in;
                in.s_addr = eqsi->GetRemoteIP();
                Log.Out(Logs::Detail, Logs::World_Server, "New client from %s:%d", inet_ntoa(in), ntohs(eqsi->GetRemotePort()));
                auto client = new Client(eqsi);
                entity_list.AddClient(client);
            }

            if ( numclients < 1 && zoneupdate_timer.GetDuration() != IDLEZONEUPDATE )
                zoneupdate_timer.SetTimer(IDLEZONEUPDATE);
            else if ( numclients > 0 && zoneupdate_timer.GetDuration() == IDLEZONEUPDATE )
            {
                zoneupdate_timer.SetTimer(ZONEUPDATE);
                zoneupdate_timer.Trigger();
            }

            //check for timeouts in other threads
            timeout_manager.CheckTimeouts();

            if (worldserver.Connected()) {
                worldwasconnected = true;
            }
            else {
                if (worldwasconnected && is_zone_loaded)
                    entity_list.ChannelMessageFromWorld(0, 0, 6, 0, 0, "WARNING: World server connection lost");
                worldwasconnected = false;
            }

            if (is_zone_loaded && zoneupdate_timer.Check()) {
                {
                    if(net.group_timer.Enabled() && net.group_timer.Check())
                        entity_list.GroupProcess();

                    if(net.door_timer.Enabled() && net.door_timer.Check())
                        entity_list.DoorProcess();

                    if(net.object_timer.Enabled() && net.object_timer.Check())
                        entity_list.ObjectProcess();

                    if(net.corpse_timer.Enabled() && net.corpse_timer.Check())
                        entity_list.CorpseProcess();

                    if(net.trap_timer.Enabled() && net.trap_timer.Check())
                        entity_list.TrapProcess();

                    if(net.raid_timer.Enabled() && net.raid_timer.Check())
                        entity_list.RaidProcess();

                    entity_list.Process();
                    entity_list.MobProcess();
                    entity_list.BeaconProcess();
                    entity_list.EncounterProcess();

                    if (zone) {
                        if(!zone->Process()) {
                            Zone::Shutdown();
                        }
                    }

                    if(quest_timers.Check())
                        quest_manager.Process();

                }
            }
            if (InterserverTimer.Check()) {
                InterserverTimer.Start();
                database.ping();
                // AsyncLoadVariables(dbasync, &database);
                entity_list.UpdateWho();
                if (worldserver.TryReconnect() && (!worldserver.Connected()))
                    worldserver.AsyncConnect();
            }

#ifdef EQPROFILE
#ifdef PROFILE_DUMP_TIME
            if(profile_dump_timer.Check()) {
                DumpZoneProfile();
            }
#endif
#endif
        }	//end extra profiler block
        Sleep(ZoneTimerResolution);
    }

    entity_list.Clear();

    parse->ClearInterfaces();

#ifdef EMBPERL
    safe_delete(perl_parser);
#endif

#ifdef LUA_EQEMU
    safe_delete(lua_parser);
#endif

    safe_delete(Config);

    if (zone != 0)
        Zone::Shutdown(true);
    //Fix for Linux world server problem.
    eqsf.Close();
    worldserver.Disconnect();
    safe_delete(taskmanager);
    command_deinit();
#ifdef BOTS
    bot_command_deinit();
#endif
    safe_delete(parse);
    Log.Out(Logs::General, Logs::Zone_Server, "Proper zone shutdown complete.");
    Log.CloseFileLogs();
    return 0;
}
Exemple #7
0
int main(int argc, char** argv) {
	RegisterExecutablePlatform(ExePlatformWorld);
	LogSys.LoadLogSettingsDefaults();
	set_exception_handler();

	/* Database Version Check */
	uint32 Database_Version = CURRENT_BINARY_DATABASE_VERSION;
	uint32 Bots_Database_Version = CURRENT_BINARY_BOTS_DATABASE_VERSION;
	if (argc >= 2) {
		if (strcasecmp(argv[1], "db_version") == 0) {
			std::cout << "Binary Database Version: " << Database_Version << " : " << Bots_Database_Version << std::endl;
			return 0;
		}
	}

	// Load server configuration
	Log(Logs::General, Logs::World_Server, "Loading server configuration..");
	if (!WorldConfig::LoadConfig()) {
		Log(Logs::General, Logs::World_Server, "Loading server configuration failed.");
		return 1;
	}

	Config = WorldConfig::get();

	Log(Logs::General, Logs::World_Server, "CURRENT_VERSION: %s", CURRENT_VERSION);

	if (signal(SIGINT, CatchSignal) == SIG_ERR) {
		Log(Logs::General, Logs::World_Server, "Could not set signal handler");
		return 1;
	}

	if (signal(SIGTERM, CatchSignal) == SIG_ERR) {
		Log(Logs::General, Logs::World_Server, "Could not set signal handler");
		return 1;
	}

#ifndef WIN32
	if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) {
		Log(Logs::General, Logs::World_Server, "Could not set signal handler");
		return 1;
	}
#endif

	// add login server config to list
	if (Config->LoginCount == 0) {
		if (Config->LoginHost.length()) {
			loginserverlist.Add(Config->LoginHost.c_str(), Config->LoginPort, Config->LoginAccount.c_str(), Config->LoginPassword.c_str(), Config->LoginLegacy);
			Log(Logs::General, Logs::World_Server, "Added loginserver %s:%i", Config->LoginHost.c_str(), Config->LoginPort);
		}
	}
	else {
		LinkedList<LoginConfig*> loginlist = Config->loginlist;
		LinkedListIterator<LoginConfig*> iterator(loginlist);
		iterator.Reset();
		while (iterator.MoreElements()) {
			loginserverlist.Add(iterator.GetData()->LoginHost.c_str(), iterator.GetData()->LoginPort, iterator.GetData()->LoginAccount.c_str(), iterator.GetData()->LoginPassword.c_str(),
				iterator.GetData()->LoginLegacy);
			Log(Logs::General, Logs::World_Server, "Added loginserver %s:%i", iterator.GetData()->LoginHost.c_str(), iterator.GetData()->LoginPort);
			iterator.Advance();
		}
	}

	Log(Logs::General, Logs::World_Server, "Connecting to MySQL...");
	if (!database.Connect(
		Config->DatabaseHost.c_str(),
		Config->DatabaseUsername.c_str(),
		Config->DatabasePassword.c_str(),
		Config->DatabaseDB.c_str(),
		Config->DatabasePort)) {
		Log(Logs::General, Logs::World_Server, "Cannot continue without a database connection.");
		return 1;
	}
	guild_mgr.SetDatabase(&database);

	/* Register Log System and Settings */
	database.LoadLogSettings(LogSys.log_settings);
	LogSys.StartFileLogs();

	bool ignore_db = false;
	if (argc >= 2) {
		std::string tmp;
		if (strcasecmp(argv[1], "help") == 0 || strcasecmp(argv[1], "?") == 0 || strcasecmp(argv[1], "/?") == 0 || strcasecmp(argv[1], "-?") == 0 || strcasecmp(argv[1], "-h") == 0 || strcasecmp(argv[1], "-help") == 0) {
			std::cout << "Worldserver command line commands:" << std::endl;
			std::cout << "adduser username password flag    - adds a user account" << std::endl;
			std::cout << "flag username flag    - sets GM flag on the account" << std::endl;
			std::cout << "startzone zoneshortname    - sets the starting zone" << std::endl;
			std::cout << "-holdzones    - reboots lost zones" << std::endl;
			return 0;
		}
		else if (strcasecmp(argv[1], "-holdzones") == 0) {
			std::cout << "Reboot Zones mode ON" << std::endl;
			holdzones = true;
		}
		else if (database.GetVariable("disablecommandline", tmp)) {
			if (tmp.length() == 1) {
				if (tmp[0] == '1') {
					std::cerr << "Command line disabled in database... exiting" << std::endl;
					return 1;
				}
			}
		}
		else if (strcasecmp(argv[1], "adduser") == 0) {
			if (argc == 5) {
				if (Seperator::IsNumber(argv[4])) {
					if (atoi(argv[4]) >= 0 && atoi(argv[4]) <= 255) {
						if (database.CreateAccount(argv[2], argv[3], atoi(argv[4])) == 0) {
							std::cerr << "database.CreateAccount failed." << std::endl;
							return 1;
						}
						else {
							std::cout << "Account created: Username='******', Password='******', status=" << argv[4] << std::endl;
							return 0;
						}
					}
				}
			}
			std::cout << "Usage: world adduser username password flag" << std::endl;
			std::cout << "flag = 0, 1 or 2" << std::endl;
			return 0;
		}
		else if (strcasecmp(argv[1], "flag") == 0) {
			if (argc == 4) {
				if (Seperator::IsNumber(argv[3])) {
					if (atoi(argv[3]) >= 0 && atoi(argv[3]) <= 255) {
						if (database.SetAccountStatus(argv[2], atoi(argv[3]))) {
							std::cout << "Account flagged: Username='******', status=" << argv[3] << std::endl;
							return 0;
						}
						else {
							std::cerr << "database.SetAccountStatus failed." << std::endl;
							return 1;
						}
					}
				}
			}
			std::cout << "Usage: world flag username flag" << std::endl;
			std::cout << "flag = 0-200" << std::endl;
			return 0;
		}
		else if (strcasecmp(argv[1], "startzone") == 0) {
			if (argc == 3) {
				if (strlen(argv[2]) < 3) {
					std::cerr << "Error: zone name too short" << std::endl;
					return 1;
				}
				else if (strlen(argv[2]) > 15) {
					std::cerr << "Error: zone name too long" << std::endl;
					return 1;
				}
				else {
					if (database.SetVariable("startzone", argv[2])) {
						std::cout << "Starting zone changed: '" << argv[2] << "'" << std::endl;
						return 0;
					}
					else {
						std::cerr << "database.SetVariable failed." << std::endl;
						return 1;
					}
				}
			}
			std::cout << "Usage: world startzone zoneshortname" << std::endl;
			return 0;
		}
		else if (strcasecmp(argv[1], "ignore_db") == 0) {
			ignore_db = true;
		}
		else {
			std::cerr << "Error, unknown command line option" << std::endl;
			return 1;
		}
	}

	if (!ignore_db) {
		Log(Logs::General, Logs::World_Server, "Checking Database Conversions..");
		database.CheckDatabaseConversions();
	}
	Log(Logs::General, Logs::World_Server, "Loading variables..");
	database.LoadVariables();

	std::string hotfix_name;
	if (database.GetVariable("hotfix_name", hotfix_name)) {
		if (!hotfix_name.empty()) {
			Log(Logs::General, Logs::Zone_Server, "Current hotfix in use: '%s'", hotfix_name.c_str());
		}
	}

	Log(Logs::General, Logs::World_Server, "Loading zones..");
	database.LoadZoneNames();
	Log(Logs::General, Logs::World_Server, "Clearing groups..");
	database.ClearGroup();
	Log(Logs::General, Logs::World_Server, "Clearing raids..");
	database.ClearRaid();
	database.ClearRaidDetails();
	database.ClearRaidLeader();
	Log(Logs::General, Logs::World_Server, "Clearing inventory snapshots..");
	database.ClearInvSnapshots();
	Log(Logs::General, Logs::World_Server, "Loading items..");
	if (!database.LoadItems(hotfix_name))
		Log(Logs::General, Logs::World_Server, "Error: Could not load item data. But ignoring");
	Log(Logs::General, Logs::World_Server, "Loading skill caps..");
	if (!database.LoadSkillCaps(std::string(hotfix_name)))
		Log(Logs::General, Logs::World_Server, "Error: Could not load skill cap data. But ignoring");
	Log(Logs::General, Logs::World_Server, "Loading guilds..");
	guild_mgr.LoadGuilds();
	//rules:
	{
		std::string tmp;
		if (database.GetVariable("RuleSet", tmp)) {
			Log(Logs::General, Logs::World_Server, "Loading rule set '%s'", tmp.c_str());
			if (!RuleManager::Instance()->LoadRules(&database, tmp.c_str())) {
				Log(Logs::General, Logs::World_Server, "Failed to load ruleset '%s', falling back to defaults.", tmp.c_str());
			}
		}
		else {
			if (!RuleManager::Instance()->LoadRules(&database, "default")) {
				Log(Logs::General, Logs::World_Server, "No rule set configured, using default rules");
			}
			else {
				Log(Logs::General, Logs::World_Server, "Loaded default rule set 'default'", tmp.c_str());
			}
		}
	}

	if (RuleB(World, ClearTempMerchantlist)) {
		Log(Logs::General, Logs::World_Server, "Clearing temporary merchant lists..");
		database.ClearMerchantTemp();
	}

	RuleManager::Instance()->SaveRules(&database);

	Log(Logs::General, Logs::World_Server, "Loading EQ time of day..");
	TimeOfDay_Struct eqTime;
	time_t realtime;
	eqTime = database.LoadTime(realtime);
	zoneserver_list.worldclock.SetCurrentEQTimeOfDay(eqTime, realtime);
	Timer EQTimeTimer(600000);
	EQTimeTimer.Start(600000);

	Log(Logs::General, Logs::World_Server, "Loading launcher list..");
	launcher_list.LoadList();

	std::string tmp;
	database.GetVariable("holdzones", tmp);
	if (tmp.length() == 1 && tmp[0] == '1') {
		holdzones = true;
	}
	Log(Logs::General, Logs::World_Server, "Reboot zone modes %s", holdzones ? "ON" : "OFF");

	Log(Logs::General, Logs::World_Server, "Deleted %i stale player corpses from database", database.DeleteStalePlayerCorpses());

	Log(Logs::General, Logs::World_Server, "Loading adventures...");
	if (!adventure_manager.LoadAdventureTemplates())
	{
		Log(Logs::General, Logs::World_Server, "Unable to load adventure templates.");
	}

	if (!adventure_manager.LoadAdventureEntries())
	{
		Log(Logs::General, Logs::World_Server, "Unable to load adventure templates.");
	}

	adventure_manager.Load();
	adventure_manager.LoadLeaderboardInfo();

	Log(Logs::General, Logs::World_Server, "Purging expired instances");
	database.PurgeExpiredInstances();
	Timer PurgeInstanceTimer(450000);
	PurgeInstanceTimer.Start(450000);

	Log(Logs::General, Logs::World_Server, "Loading char create info...");
	database.LoadCharacterCreateAllocations();
	database.LoadCharacterCreateCombos();

	std::unique_ptr<EQ::Net::ConsoleServer> console;
	if (Config->TelnetEnabled) {
		Log(Logs::General, Logs::World_Server, "Console (TCP) listener started.");
		console.reset(new EQ::Net::ConsoleServer(Config->TelnetIP, Config->TelnetTCPPort));
		RegisterConsoleFunctions(console);
	}

	std::unique_ptr<EQ::Net::ServertalkServer> server_connection;
	server_connection.reset(new EQ::Net::ServertalkServer());

	EQ::Net::ServertalkServerOptions server_opts;
	server_opts.port = Config->WorldTCPPort;
	server_opts.ipv6 = false;
	server_opts.credentials = Config->SharedKey;
	server_connection->Listen(server_opts);
	Log(Logs::General, Logs::World_Server, "Server (TCP) listener started.");

	server_connection->OnConnectionIdentified("Zone", [&console](std::shared_ptr<EQ::Net::ServertalkServerConnection> connection) {
		LogF(Logs::General, Logs::World_Server, "New Zone Server connection from {2} at {0}:{1}",
			connection->Handle()->RemoteIP(), connection->Handle()->RemotePort(), connection->GetUUID());

		numzones++;
		zoneserver_list.Add(new ZoneServer(connection, console.get()));
	});

	server_connection->OnConnectionRemoved("Zone", [](std::shared_ptr<EQ::Net::ServertalkServerConnection> connection) {
		LogF(Logs::General, Logs::World_Server, "Removed Zone Server connection from {0}",
			connection->GetUUID());

		numzones--;
		zoneserver_list.Remove(connection->GetUUID());
	});

	server_connection->OnConnectionIdentified("Launcher", [](std::shared_ptr<EQ::Net::ServertalkServerConnection> connection) {
		LogF(Logs::General, Logs::World_Server, "New Launcher connection from {2} at {0}:{1}",
			connection->Handle()->RemoteIP(), connection->Handle()->RemotePort(), connection->GetUUID());

		launcher_list.Add(connection);
	});

	server_connection->OnConnectionRemoved("Launcher", [](std::shared_ptr<EQ::Net::ServertalkServerConnection> connection) {
		LogF(Logs::General, Logs::World_Server, "Removed Launcher connection from {0}",
			connection->GetUUID());

		launcher_list.Remove(connection);
	});

	server_connection->OnConnectionIdentified("QueryServ", [](std::shared_ptr<EQ::Net::ServertalkServerConnection> connection) {
		LogF(Logs::General, Logs::World_Server, "New Query Server connection from {2} at {0}:{1}",
			connection->Handle()->RemoteIP(), connection->Handle()->RemotePort(), connection->GetUUID());

		QSLink.AddConnection(connection);
	});

	server_connection->OnConnectionRemoved("QueryServ", [](std::shared_ptr<EQ::Net::ServertalkServerConnection> connection) {
		LogF(Logs::General, Logs::World_Server, "Removed Query Server connection from {0}",
			connection->GetUUID());

		QSLink.RemoveConnection(connection);
	});

	server_connection->OnConnectionIdentified("UCS", [](std::shared_ptr<EQ::Net::ServertalkServerConnection> connection) {
		LogF(Logs::General, Logs::World_Server, "New UCS Server connection from {2} at {0}:{1}",
			connection->Handle()->RemoteIP(), connection->Handle()->RemotePort(), connection->GetUUID());

		UCSLink.SetConnection(connection);
	});

	server_connection->OnConnectionRemoved("UCS", [](std::shared_ptr<EQ::Net::ServertalkServerConnection> connection) {
		LogF(Logs::General, Logs::World_Server, "Removed Query Server connection from {0}",
			connection->GetUUID());

		UCSLink.SetConnection(nullptr);
	});

	server_connection->OnConnectionIdentified("WebInterface", [](std::shared_ptr<EQ::Net::ServertalkServerConnection> connection) {
		LogF(Logs::General, Logs::World_Server, "New WebInterface Server connection from {2} at {0}:{1}",
			connection->Handle()->RemoteIP(), connection->Handle()->RemotePort(), connection->GetUUID());

		web_interface.AddConnection(connection);
	});

	server_connection->OnConnectionRemoved("WebInterface", [](std::shared_ptr<EQ::Net::ServertalkServerConnection> connection) {
		LogF(Logs::General, Logs::World_Server, "Removed WebInterface Server connection from {0}",
			connection->GetUUID());

		web_interface.RemoveConnection(connection);
	});

	EQ::Net::EQStreamManagerOptions opts(9000, false, false);
	EQ::Net::EQStreamManager eqsm(opts);

	//register all the patches we have avaliable with the stream identifier.
	EQStreamIdentifier stream_identifier;
	RegisterAllPatches(stream_identifier);
	zoneserver_list.shutdowntimer = new Timer(60000);
	zoneserver_list.shutdowntimer->Disable();
	zoneserver_list.reminder = new Timer(20000);
	zoneserver_list.reminder->Disable();
	Timer InterserverTimer(INTERSERVER_TIMER); // does MySQL pings and auto-reconnect
	InterserverTimer.Trigger();
	uint8 ReconnectCounter = 100;
	std::shared_ptr<EQStreamInterface> eqs;
	EQStreamInterface *eqsi;

	eqsm.OnNewConnection([&stream_identifier](std::shared_ptr<EQ::Net::EQStream> stream) {
		stream_identifier.AddStream(stream);
		LogF(Logs::Detail, Logs::World_Server, "New connection from IP {0}:{1}", stream->RemoteEndpoint(), ntohs(stream->GetRemotePort()));
	});

	while (RunLoops) {
		Timer::SetCurrentTime();
		eqs = nullptr;

		//give the stream identifier a chance to do its work....
		stream_identifier.Process();

		//check the stream identifier for any now-identified streams
		while ((eqsi = stream_identifier.PopIdentified())) {
			//now that we know what patch they are running, start up their client object
			struct in_addr	in;
			in.s_addr = eqsi->GetRemoteIP();
			if (RuleB(World, UseBannedIPsTable)) { //Lieka: Check to see if we have the responsibility for blocking IPs.
				Log(Logs::Detail, Logs::World_Server, "Checking inbound connection %s against BannedIPs table", inet_ntoa(in));
				if (!database.CheckBannedIPs(inet_ntoa(in))) { //Lieka: Check inbound IP against banned IP table.
					Log(Logs::Detail, Logs::World_Server, "Connection %s PASSED banned IPs check. Processing connection.", inet_ntoa(in));
					auto client = new Client(eqsi);
					// @merth: client->zoneattempt=0;
					client_list.Add(client);
				}
				else {
					Log(Logs::General, Logs::World_Server, "Connection from %s FAILED banned IPs check. Closing connection.", inet_ntoa(in));
					eqsi->Close(); //Lieka: If the inbound IP is on the banned table, close the EQStream.
				}
			}
			if (!RuleB(World, UseBannedIPsTable)) {
				Log(Logs::Detail, Logs::World_Server, "New connection from %s:%d, processing connection", inet_ntoa(in), ntohs(eqsi->GetRemotePort()));
				auto client = new Client(eqsi);
				// @merth: client->zoneattempt=0;
				client_list.Add(client);
			}
		}

		client_list.Process();

		if (PurgeInstanceTimer.Check())
		{
			database.PurgeExpiredInstances();
		}

		if (EQTimeTimer.Check()) {
			TimeOfDay_Struct tod;
			zoneserver_list.worldclock.GetCurrentEQTimeOfDay(time(0), &tod);
			if (!database.SaveTime(tod.minute, tod.hour, tod.day, tod.month, tod.year))
				Log(Logs::General, Logs::World_Server, "Failed to save eqtime.");
			else
				Log(Logs::Detail, Logs::World_Server, "EQTime successfully saved.");
		}

		zoneserver_list.Process();
		launcher_list.Process();
		LFPGroupList.Process();
		adventure_manager.Process();

		if (InterserverTimer.Check()) {
			InterserverTimer.Start();
			database.ping();

			std::string window_title = StringFormat("World: %s Clients: %i", Config->LongName.c_str(), client_list.GetClientCount());
			UpdateWindowTitle(window_title);
		}

		EQ::EventLoop::Get().Process();
		Sleep(5);
	}
	Log(Logs::General, Logs::World_Server, "World main loop completed.");
	Log(Logs::General, Logs::World_Server, "Shutting down zone connections (if any).");
	zoneserver_list.KillAll();
	Log(Logs::General, Logs::World_Server, "Zone (TCP) listener stopped.");
	Log(Logs::General, Logs::World_Server, "Signaling HTTP service to stop...");
	LogSys.CloseFileLogs();

	return 0;
}
Exemple #8
0
int main()
{
	RegisterExecutablePlatform(ExePlatformLogin);
	set_exception_handler();

	//Create our error log, is of format login_<number>.log
	time_t current_time = time(nullptr);
	std::stringstream log_name(std::stringstream::in | std::stringstream::out);
#ifdef WIN32
	log_name << ".\\logs\\login_" << (unsigned int)current_time << ".log";
#else
	log_name << "./logs/login_" << (unsigned int)current_time << ".log";
#endif
	server_log = new ErrorLog(log_name.str().c_str());
	server_log->Log(log_debug, "Logging System Init.");

	//Create our subsystem and parse the ini file.
	server.config = new Config();
	server_log->Log(log_debug, "Config System Init.");
	server.config->Parse("login.ini");

	//Parse unregistered allowed option.
	if(server.config->GetVariable("options", "unregistered_allowed").compare("FALSE") == 0)
	{
		server.options.AllowUnregistered(false);
	}

	//Parse trace option.
	if(server.config->GetVariable("options", "trace").compare("TRUE") == 0)
	{
		server.options.Trace(true);
	}

	//Parse trace option.
	if(server.config->GetVariable("options", "world_trace").compare("TRUE") == 0)
	{
		server.options.WorldTrace(true);
	}

	//Parse packet inc dump option.
	if(server.config->GetVariable("options", "dump_packets_in").compare("TRUE") == 0)
	{
		server.options.DumpInPackets(true);
	}

	//Parse packet out dump option.
	if(server.config->GetVariable("options", "dump_packets_out").compare("TRUE") == 0)
	{
		server.options.DumpOutPackets(true);
	}

	//Parse encryption mode option.
	std::string mode = server.config->GetVariable("security", "mode");
	if(mode.size() > 0)
	{
		server.options.EncryptionMode(atoi(mode.c_str()));
	}

	//Parse local network option.
	std::string ln = server.config->GetVariable("options", "local_network");
	if(ln.size() > 0)
	{
		server.options.LocalNetwork(ln);
	}

	//Parse reject duplicate servers option.
	if(server.config->GetVariable("options", "reject_duplicate_servers").compare("TRUE") == 0)
	{
		server.options.RejectDuplicateServers(true);
	}

	//Parse account table option.
	ln = server.config->GetVariable("schema", "account_table");
	if(ln.size() > 0)
	{
		server.options.AccountTable(ln);
	}

	//Parse world account table option.
	ln = server.config->GetVariable("schema", "world_registration_table");
	if(ln.size() > 0)
	{
		server.options.WorldRegistrationTable(ln);
	}

	//Parse admin world account table option.
	ln = server.config->GetVariable("schema", "world_admin_registration_table");
	if(ln.size() > 0)
	{
		server.options.WorldAdminRegistrationTable(ln);
	}

	//Parse world type table option.
	ln = server.config->GetVariable("schema", "world_server_type_table");
	if(ln.size() > 0)
	{
		server.options.WorldServerTypeTable(ln);
	}

	//Create our DB from options.
	if(server.config->GetVariable("database", "subsystem").compare("MySQL") == 0)
	{
#ifdef EQEMU_MYSQL_ENABLED
		server_log->Log(log_debug, "MySQL Database Init.");
		server.db = (Database*)new DatabaseMySQL(
			server.config->GetVariable("database", "user"),
			server.config->GetVariable("database", "password"),
			server.config->GetVariable("database", "host"),
			server.config->GetVariable("database", "port"),
			server.config->GetVariable("database", "db"));
#endif
	}
	else if(server.config->GetVariable("database", "subsystem").compare("PostgreSQL") == 0)
	{
#ifdef EQEMU_POSTGRESQL_ENABLED
		server_log->Log(log_debug, "PostgreSQL Database Init.");
		server.db = (Database*)new DatabasePostgreSQL(
			server.config->GetVariable("database", "user"),
			server.config->GetVariable("database", "password"),
			server.config->GetVariable("database", "host"),
			server.config->GetVariable("database", "port"),
			server.config->GetVariable("database", "db"));
#endif
	}

	//Make sure our database got created okay, otherwise cleanup and exit.
	if(!server.db)
	{
		server_log->Log(log_error, "Database Initialization Failure.");
		server_log->Log(log_debug, "Config System Shutdown.");
		delete server.config;
		server_log->Log(log_debug, "Log System Shutdown.");
		delete server_log;
		return 1;
	}

#if WIN32
	//initialize our encryption.
	server_log->Log(log_debug, "Encryption Initialize.");
	server.eq_crypto = new Encryption();
	if(server.eq_crypto->LoadCrypto(server.config->GetVariable("security", "plugin")))
	{
		server_log->Log(log_debug, "Encryption Loaded Successfully.");
	}
	else
	{
		//We can't run without encryption, cleanup and exit.
		server_log->Log(log_error, "Encryption Failed to Load.");
		server_log->Log(log_debug, "Database System Shutdown.");
		delete server.db;
		server_log->Log(log_debug, "Config System Shutdown.");
		delete server.config;
		server_log->Log(log_debug, "Log System Shutdown.");
		delete server_log;
		return 1;
	}
#endif

	//create our server manager.
	server_log->Log(log_debug, "Server Manager Initialize.");
	server.SM = new ServerManager();
	if(!server.SM)
	{
		//We can't run without a server manager, cleanup and exit.
		server_log->Log(log_error, "Server Manager Failed to Start.");
#ifdef WIN32
		server_log->Log(log_debug, "Encryption System Shutdown.");
		delete server.eq_crypto;
#endif
		server_log->Log(log_debug, "Database System Shutdown.");
		delete server.db;
		server_log->Log(log_debug, "Config System Shutdown.");
		delete server.config;
		server_log->Log(log_debug, "Log System Shutdown.");
		delete server_log;
		return 1;
	}

	//create our client manager.
	server_log->Log(log_debug, "Client Manager Initialize.");
	server.CM = new ClientManager();
	if(!server.CM)
	{
		//We can't run without a client manager, cleanup and exit.
		server_log->Log(log_error, "Client Manager Failed to Start.");
		server_log->Log(log_debug, "Server Manager Shutdown.");
		delete server.SM;
#ifdef WIN32
		server_log->Log(log_debug, "Encryption System Shutdown.");
		delete server.eq_crypto;
#endif
		server_log->Log(log_debug, "Database System Shutdown.");
		delete server.db;
		server_log->Log(log_debug, "Config System Shutdown.");
		delete server.config;
		server_log->Log(log_debug, "Log System Shutdown.");
		delete server_log;
		return 1;
	}

#ifdef WIN32
#ifdef UNICODE
	SetConsoleTitle(L"EQEmu Login Server");
#else
	SetConsoleTitle("EQEmu Login Server");
#endif
#endif

	server_log->Log(log_debug, "Server Started.");
	while(run_server)
	{
		Timer::SetCurrentTime();
		server.CM->Process();
		server.SM->Process();
		Sleep(100);
	}

	server_log->Log(log_debug, "Server Shutdown.");
	server_log->Log(log_debug, "Client Manager Shutdown.");
	delete server.CM;
	server_log->Log(log_debug, "Server Manager Shutdown.");
	delete server.SM;
#ifdef WIN32
	server_log->Log(log_debug, "Encryption System Shutdown.");
	delete server.eq_crypto;
#endif
	server_log->Log(log_debug, "Database System Shutdown.");
	delete server.db;
	server_log->Log(log_debug, "Config System Shutdown.");
	delete server.config;
	server_log->Log(log_debug, "Log System Shutdown.");
	delete server_log;
	return 0;
}
Exemple #9
0
int main(int argc, char *argv[]) {
	RegisterExecutablePlatform(ExePlatformLaunch);
	set_exception_handler();

	std::string launcher_name;
	if(argc == 2) {
		launcher_name = argv[1];
	}
	if(launcher_name.length() < 1) {
		_log(LAUNCHER__ERROR, "You must specfify a launcher name as the first argument to this program.");
		return(1);
	}

	_log(LAUNCHER__INIT, "Loading server configuration..");
	if (!EQEmuConfig::LoadConfig()) {
		_log(LAUNCHER__ERROR, "Loading server configuration failed.");
		return(1);
	}
	const EQEmuConfig *Config = EQEmuConfig::get();

	/*
	* Setup nice signal handlers
	*/
	if (signal(SIGINT, CatchSignal) == SIG_ERR)	{
		_log(LAUNCHER__ERROR, "Could not set signal handler");
		return 1;
	}
	if (signal(SIGTERM, CatchSignal) == SIG_ERR)	{
		_log(LAUNCHER__ERROR, "Could not set signal handler");
		return 1;
	}
	#ifndef WIN32
	if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)	{
		_log(LAUNCHER__ERROR, "Could not set signal handler");
		return 1;
	}

	/*
	* Add '.' to LD_LIBRARY_PATH
	*/
	//the storage passed to putenv must remain valid... crazy unix people
	const char *pv = getenv("LD_LIBRARY_PATH");
	if(pv == nullptr) {
		putenv(strdup("LD_LIBRARY_PATH=."));
	} else {
		char *v = (char *) malloc(strlen(pv) + 19);
		sprintf(v, "LD_LIBRARY_PATH=.:%s", pv);
		putenv(v);
	}
	#endif

	std::map<std::string, ZoneLaunch *> zones;
	WorldServer world(zones, launcher_name.c_str(), Config);
	if (!world.Connect()) {
		_log(LAUNCHER__ERROR, "worldserver.Connect() FAILED! Will retry.");
	}

	std::map<std::string, ZoneLaunch *>::iterator zone, zend;
	std::set<std::string> to_remove;

	Timer InterserverTimer(INTERSERVER_TIMER); // does auto-reconnect

	_log(LAUNCHER__INIT, "Starting main loop...");

//	zones["test"] = new ZoneLaunch(&world, "./zone", "dynamic_1");

	ProcLauncher *launch = ProcLauncher::get();
	RunLoops = true;
	while(RunLoops) {
		//Advance the timer to our current point in time
		Timer::SetCurrentTime();

		/*
		* Process the world connection
		*/
		world.Process();

		/*
		* Let the process manager look for dead children
		*/
		launch->Process();

		/*
		* Give all zones a chance to process.
		*/
		zone = zones.begin();
		zend = zones.end();
		for(; zone != zend; zone++) {
			if(!zone->second->Process())
				to_remove.insert(zone->first);
		}

		/*
		* Kill off any zones which have stopped
		*/
		while(!to_remove.empty()) {
			std::string rem = *to_remove.begin();
			to_remove.erase(rem);
			zone = zones.find(rem);
			if(zone == zones.end()) {
				//wtf...
				continue;
			}
			delete zone->second;
			zones.erase(rem);
		}


		if (InterserverTimer.Check()) {
			if (world.TryReconnect() && (!world.Connected()))
				world.AsyncConnect();
		}

		/*
		* Take a nice nap until next cycle
		*/
		if(zones.empty())
			Sleep(5000);
		else
			Sleep(2000);
	}

	//try to be semi-nice about this... without waiting too long
	zone = zones.begin();
	zend = zones.end();
	for(; zone != zend; zone++) {
		zone->second->Stop();
	}
	Sleep(1);
	launch->Process();
	launch->TerminateAll(false);
	Sleep(1);
	launch->Process();
	//kill anybody left
	launch->TerminateAll(true);
	for(; zone != zend; zone++) {
		delete zone->second;
	}

	return(0);
}
Exemple #10
0
int main() {
	RegisterExecutablePlatform(ExePlatformQueryServ);
	set_exception_handler();

	Timer LFGuildExpireTimer(60000);

	Timer InterserverTimer(INTERSERVER_TIMER); // does auto-reconnect

	_log(QUERYSERV__INIT, "Starting EQEmu QueryServ.");

	if (!queryservconfig::LoadConfig()) {

		_log(QUERYSERV__INIT, "Loading server configuration failed.");

		return 1;
	}

	Config = queryservconfig::get();

	if(!load_log_settings(Config->LogSettingsFile.c_str()))
		_log(QUERYSERV__INIT, "Warning: Unable to read %s", Config->LogSettingsFile.c_str());
	else
		_log(QUERYSERV__INIT, "Log settings loaded from %s", Config->LogSettingsFile.c_str());

	WorldShortName = Config->ShortName;

	_log(QUERYSERV__INIT, "Connecting to MySQL...");

	if (!database.Connect(
		Config->QSDatabaseHost.c_str(),
		Config->QSDatabaseUsername.c_str(),
		Config->QSDatabasePassword.c_str(),
		Config->QSDatabaseDB.c_str(),
		Config->QSDatabasePort)) {
		_log(WORLD__INIT_ERR, "Cannot continue without a database connection.");
		return 1;
	}

	if (signal(SIGINT, CatchSignal) == SIG_ERR)	{
		_log(QUERYSERV__ERROR, "Could not set signal handler");
		return 1;
	}
	if (signal(SIGTERM, CatchSignal) == SIG_ERR)	{
		_log(QUERYSERV__ERROR, "Could not set signal handler");
		return 1;
	}

	worldserver = new WorldServer;

	worldserver->Connect();

	lfguildmanager.LoadDatabase();

	while(RunLoops) {

		Timer::SetCurrentTime();

		if(LFGuildExpireTimer.Check())
			lfguildmanager.ExpireEntries();

		if (InterserverTimer.Check()) {
			if (worldserver->TryReconnect() && (!worldserver->Connected()))
				worldserver->AsyncConnect();
		}
		worldserver->Process();

		timeout_manager.CheckTimeouts();

		Sleep(100);
	}
}
Exemple #11
0
int main() {
	RegisterExecutablePlatform(ExePlatformUCS);
	set_exception_handler();

	// Check every minute for unused channels we can delete
	//
	Timer ChannelListProcessTimer(60000);

	Timer InterserverTimer(INTERSERVER_TIMER); // does auto-reconnect

	_log(UCS__INIT, "Starting EQEmu Universal Chat Server.");

	if (!ucsconfig::LoadConfig()) {

		_log(UCS__INIT, "Loading server configuration failed.");

		return 1;
	}

	Config = ucsconfig::get();

	if(!load_log_settings(Config->LogSettingsFile.c_str()))
		_log(UCS__INIT, "Warning: Unable to read %s", Config->LogSettingsFile.c_str());
	else
		_log(UCS__INIT, "Log settings loaded from %s", Config->LogSettingsFile.c_str());

	WorldShortName = Config->ShortName;

	_log(UCS__INIT, "Connecting to MySQL...");

	if (!database.Connect(
		Config->DatabaseHost.c_str(),
		Config->DatabaseUsername.c_str(),
		Config->DatabasePassword.c_str(),
		Config->DatabaseDB.c_str(),
		Config->DatabasePort)) {
		_log(WORLD__INIT_ERR, "Cannot continue without a database connection.");
		return 1;
	}

	char tmp[64];

	if (database.GetVariable("RuleSet", tmp, sizeof(tmp)-1)) {
		_log(WORLD__INIT, "Loading rule set '%s'", tmp);
		if(!RuleManager::Instance()->LoadRules(&database, tmp)) {
			_log(UCS__ERROR, "Failed to load ruleset '%s', falling back to defaults.", tmp);
		}
	} else {
		if(!RuleManager::Instance()->LoadRules(&database, "default")) {
			_log(UCS__INIT, "No rule set configured, using default rules");
		} else {
			_log(UCS__INIT, "Loaded default rule set 'default'", tmp);
		}
	}

	database.ExpireMail();

	if(Config->ChatPort != Config->MailPort)
	{
		_log(UCS__ERROR, "MailPort and CharPort must be the same in eqemu_config.xml for UCS.");
		exit(1);
	}

	CL = new Clientlist(Config->ChatPort);

	ChannelList = new ChatChannelList();

	database.LoadChatChannels();

	if (signal(SIGINT, CatchSignal) == SIG_ERR)	{
		_log(UCS__ERROR, "Could not set signal handler");
		return 1;
	}
	if (signal(SIGTERM, CatchSignal) == SIG_ERR)	{
		_log(UCS__ERROR, "Could not set signal handler");
		return 1;
	}

	worldserver = new WorldServer;

	worldserver->Connect();

	while(RunLoops) {

		Timer::SetCurrentTime();

		CL->Process();

		if(ChannelListProcessTimer.Check())
			ChannelList->Process();

		if (InterserverTimer.Check()) {
			if (worldserver->TryReconnect() && (!worldserver->Connected()))
				worldserver->AsyncConnect();
		}
		worldserver->Process();

		timeout_manager.CheckTimeouts();

		Sleep(100);
	}

	ChannelList->RemoveAllChannels();

	CL->CloseAllConnections();

}
Exemple #12
0
int main(int argc, char **argv) {
	RegisterExecutablePlatform(ExePlatformSharedMemory);
	set_exception_handler();

	LogFile->write(EQEMuLog::Status, "Shared Memory Loader Program");
	if(!EQEmuConfig::LoadConfig()) {
		LogFile->write(EQEMuLog::Error, "Unable to load configuration file.");
		return 0;
	}

	const EQEmuConfig *config = EQEmuConfig::get();
	if(!load_log_settings(config->LogSettingsFile.c_str())) {
		LogFile->write(EQEMuLog::Error, "Warning: unable to read %s.", config->LogSettingsFile.c_str());
	}

	SharedDatabase database;
	LogFile->write(EQEMuLog::Status, "Connecting to database...");
	if(!database.Connect(config->DatabaseHost.c_str(), config->DatabaseUsername.c_str(),
		config->DatabasePassword.c_str(), config->DatabaseDB.c_str(), config->DatabasePort)) {
		LogFile->write(EQEMuLog::Error, "Unable to connect to the database, cannot continue without a "
			"database connection");
		return 0;
	}

	bool load_all = true;
	bool load_items = true;
	bool load_factions = true;
	bool load_loot = true;
	bool load_skill_caps = true;
	bool load_spells = true;
	if(argc > 1) {
		load_all = false;
		load_items = false;
		load_factions = false;
		load_loot = false;
		load_skill_caps = false;
		load_spells = false;

		for(int i = 1; i < argc; ++i) {
			switch(argv[i][0]) {
			case 'a':
				if(strcasecmp("all", argv[i]) == 0) {
					load_all = true;
				}
				break;

			case 'i':
				if(strcasecmp("items", argv[i]) == 0) {
					load_items = true;
				}
				break;

			case 'f':
				if(strcasecmp("factions", argv[i]) == 0) {
					load_factions = true;
				}
				break;

			case 'l':
				if(strcasecmp("loot", argv[i]) == 0) {
					load_loot = true;
				}
				break;

			case 's':
				if(strcasecmp("skill_caps", argv[i]) == 0) {
					load_skill_caps = true;
				} else if(strcasecmp("spells", argv[i]) == 0) {
					load_spells = true;
				}
				break;
			}
		}
	}

	if(load_all || load_items) {
		LogFile->write(EQEMuLog::Status, "Loading items...");
		try {
			LoadItems(&database);
		} catch(std::exception &ex) {
			LogFile->write(EQEMuLog::Error, "%s", ex.what());
			return 0;
		}
	}

	if(load_all || load_factions) {
		LogFile->write(EQEMuLog::Status, "Loading factions...");
		try {
			LoadFactions(&database);
		} catch(std::exception &ex) {
			LogFile->write(EQEMuLog::Error, "%s", ex.what());
			return 0;
		}
	}

	if(load_all || load_loot) {
		LogFile->write(EQEMuLog::Status, "Loading loot...");
		try {
			LoadLoot(&database);
		} catch(std::exception &ex) {
			LogFile->write(EQEMuLog::Error, "%s", ex.what());
			return 0;
		}
	}

	if(load_all || load_skill_caps) {
		LogFile->write(EQEMuLog::Status, "Loading skill caps...");
		try {
			LoadSkillCaps(&database);
		} catch(std::exception &ex) {
			LogFile->write(EQEMuLog::Error, "%s", ex.what());
			return 0;
		}
	}

	if(load_all || load_spells) {
		LogFile->write(EQEMuLog::Status, "Loading spells...");
		try {
			LoadSpells(&database);
		} catch(std::exception &ex) {
			LogFile->write(EQEMuLog::Error, "%s", ex.what());
			return 0;
		}
	}

	return 0;
}
Exemple #13
0
int main(int argc, char **argv) {
	RegisterExecutablePlatform(ExePlatformSharedMemory);
	Log.LoadLogSettingsDefaults();
	set_exception_handler();

	Log.Out(Logs::General, Logs::Status, "Shared Memory Loader Program");
	if(!EQEmuConfig::LoadConfig()) {
		Log.Out(Logs::General, Logs::Error, "Unable to load configuration file.");
		return 1;
	}

	auto Config = EQEmuConfig::get();

	SharedDatabase database;
	Log.Out(Logs::General, Logs::Status, "Connecting to database...");
	if(!database.Connect(Config->DatabaseHost.c_str(), Config->DatabaseUsername.c_str(),
		Config->DatabasePassword.c_str(), Config->DatabaseDB.c_str(), Config->DatabasePort)) {
		Log.Out(Logs::General, Logs::Error, "Unable to connect to the database, cannot continue without a "
			"database connection");
		return 1;
	}

	/* Register Log System and Settings */
	database.LoadLogSettings(Log.log_settings);
	Log.StartFileLogs();

	database.LoadVariables();

	/* If we're running shared memory and hotfix has no custom name, we probably want to start from scratch... */
	std::string db_hotfix_name;
	if (database.GetVariable("hotfix_name", db_hotfix_name)) {
		if (!db_hotfix_name.empty() && strcasecmp("hotfix_", db_hotfix_name.c_str()) == 0) {
			Log.Out(Logs::General, Logs::Status, "Current hotfix in variables is the default %s, clearing out variable", db_hotfix_name.c_str());
			std::string query = StringFormat("UPDATE `variables` SET `value`='' WHERE (`varname`='hotfix_name')");
			database.QueryDatabase(query);
		}
	}

	std::string hotfix_name = "";
	bool load_all = true;
	bool load_items = false;
	bool load_factions = false;
	bool load_loot = false;
	bool load_skill_caps = false;
	bool load_spells = false;
	bool load_bd = false;
	if(argc > 1) {
		for(int i = 1; i < argc; ++i) {
			switch(argv[i][0]) {	
			case 'b':
				if(strcasecmp("base_data", argv[i]) == 0) {
					load_bd = true;
					load_all = false;
				}
				break;
	
			case 'i':
				if(strcasecmp("items", argv[i]) == 0) {
					load_items = true;
					load_all = false;
				}
				break;
	
			case 'f':
				if(strcasecmp("factions", argv[i]) == 0) {
					load_factions = true;
					load_all = false;
				}
				break;
	
			case 'l':
				if(strcasecmp("loot", argv[i]) == 0) {
					load_loot = true;
					load_all = false;
				}
				break;
	
			case 's':
				if(strcasecmp("skill_caps", argv[i]) == 0) {
					load_skill_caps = true;
					load_all = false;
				} else if(strcasecmp("spells", argv[i]) == 0) {
					load_spells = true;
					load_all = false;
				}
				break;
			case '-': {
				auto split = SplitString(argv[i], '=');
				if(split.size() >= 2) {
					auto command = split[0];
					auto argument = split[1];
					if(strcasecmp("-hotfix", command.c_str()) == 0) {
						hotfix_name = argument;
						load_all = true;
					}
				}
				break;
			}
			}
		}
	}

	if(hotfix_name.length() > 0) {
		Log.Out(Logs::General, Logs::Status, "Writing data for hotfix '%s'", hotfix_name.c_str());
	}
	
	if(load_all || load_items) {
		Log.Out(Logs::General, Logs::Status, "Loading items...");
		try {
			LoadItems(&database, hotfix_name);
		} catch(std::exception &ex) {
			Log.Out(Logs::General, Logs::Error, "%s", ex.what());
			return 1;
		}
	}
	
	if(load_all || load_factions) {
		Log.Out(Logs::General, Logs::Status, "Loading factions...");
		try {
			LoadFactions(&database, hotfix_name);
		} catch(std::exception &ex) {
			Log.Out(Logs::General, Logs::Error, "%s", ex.what());
			return 1;
		}
	}
	
	if(load_all || load_loot) {
		Log.Out(Logs::General, Logs::Status, "Loading loot...");
		try {
			LoadLoot(&database, hotfix_name);
		} catch(std::exception &ex) {
			Log.Out(Logs::General, Logs::Error, "%s", ex.what());
			return 1;
		}
	}
	
	if(load_all || load_skill_caps) {
		Log.Out(Logs::General, Logs::Status, "Loading skill caps...");
		try {
			LoadSkillCaps(&database, hotfix_name);
		} catch(std::exception &ex) {
			Log.Out(Logs::General, Logs::Error, "%s", ex.what());
			return 1;
		}
	}
	
	if(load_all || load_spells) {
		Log.Out(Logs::General, Logs::Status, "Loading spells...");
		try {
			LoadSpells(&database, hotfix_name);
		} catch(std::exception &ex) {
			Log.Out(Logs::General, Logs::Error, "%s", ex.what());
			return 1;
		}
	}
	
	if(load_all || load_bd) {
		Log.Out(Logs::General, Logs::Status, "Loading base data...");
		try {
			LoadBaseData(&database, hotfix_name);
		} catch(std::exception &ex) {
			Log.Out(Logs::General, Logs::Error, "%s", ex.what());
			return 1;
		}
	}
	
	Log.CloseFileLogs();
	return 0;
}
Exemple #14
0
int main(int argc, char** argv) {
	RegisterExecutablePlatform(ExePlatformZone);
	LogSys.LoadLogSettingsDefaults();

	set_exception_handler();

#ifdef USE_MAP_MMFS
	if (argc == 3 && strcasecmp(argv[1], "convert_map") == 0) {
		if (!ZoneConfig::LoadConfig())
			return 1;
		Config = ZoneConfig::get();

		std::string mapfile = argv[2];
		std::transform(mapfile.begin(), mapfile.end(), mapfile.begin(), ::tolower);
		std::string filename = Config->MapDir;
		filename += mapfile;

		auto m = new Map();
		auto success = m->Load(filename, true);
		delete m;
		std::cout << mapfile.c_str() << " conversion " << (success ? "succeeded" : "failed") << std::endl;

		return 0;
	}
#endif /*USE_MAP_MMFS*/

	QServ = new QueryServ;

	Log(Logs::General, Logs::Zone_Server, "Loading server configuration..");
	if (!ZoneConfig::LoadConfig()) {
		Log(Logs::General, Logs::Error, "Loading server configuration failed.");
		return 1;
	}
	Config = ZoneConfig::get();

	const char *zone_name;
	uint32 instance_id = 0;
	std::string z_name;
	if (argc == 4) {
		instance_id = atoi(argv[3]);
		worldserver.SetLauncherName(argv[2]);
		auto zone_port = SplitString(argv[1], ':');

		if (!zone_port.empty()) {
			z_name = zone_port[0];
		}

		if (zone_port.size() > 1) {
			std::string p_name = zone_port[1];
			Config->SetZonePort(atoi(p_name.c_str()));
		}

		worldserver.SetLaunchedName(z_name.c_str());
		if (strncmp(z_name.c_str(), "dynamic_", 8) == 0) {
			zone_name = ".";
		}
		else {
			zone_name = z_name.c_str();
		}
	}
	else if (argc == 3) {
		worldserver.SetLauncherName(argv[2]);
		auto zone_port = SplitString(argv[1], ':');

		if (!zone_port.empty()) {
			z_name = zone_port[0];
		}

		if (zone_port.size() > 1) {
			std::string p_name = zone_port[1];
			Config->SetZonePort(atoi(p_name.c_str()));
		}

		worldserver.SetLaunchedName(z_name.c_str());
		if (strncmp(z_name.c_str(), "dynamic_", 8) == 0) {
			zone_name = ".";
		}
		else {
			zone_name = z_name.c_str();
		}
	}
	else if (argc == 2) {
		worldserver.SetLauncherName("NONE");
		auto zone_port = SplitString(argv[1], ':');

		if (!zone_port.empty()) {
			z_name = zone_port[0];
		}

		if (zone_port.size() > 1) {
			std::string p_name = zone_port[1];
			Config->SetZonePort(atoi(p_name.c_str()));
		}

		worldserver.SetLaunchedName(z_name.c_str());
		if (strncmp(z_name.c_str(), "dynamic_", 8) == 0) {
			zone_name = ".";
		}
		else {
			zone_name = z_name.c_str();
		}
	}
	else {
		zone_name = ".";
		worldserver.SetLaunchedName(".");
		worldserver.SetLauncherName("NONE");
	}

	Log(Logs::General, Logs::Zone_Server, "Connecting to MySQL...");
	if (!database.Connect(
		Config->DatabaseHost.c_str(),
		Config->DatabaseUsername.c_str(),
		Config->DatabasePassword.c_str(),
		Config->DatabaseDB.c_str(),
		Config->DatabasePort)) {
		Log(Logs::General, Logs::Error, "Cannot continue without a database connection.");
		return 1;
	}

#ifdef BOTS
	if (!botdb.Connect(
		Config->DatabaseHost.c_str(),
		Config->DatabaseUsername.c_str(),
		Config->DatabasePassword.c_str(),
		Config->DatabaseDB.c_str(),
		Config->DatabasePort)) {
		Log(Logs::General, Logs::Error, "Cannot continue without a bots database connection.");
		return 1;
	}
#endif

	/* Register Log System and Settings */
	LogSys.OnLogHookCallBackZone(&Zone::GMSayHookCallBackProcess);
	database.LoadLogSettings(LogSys.log_settings);
	LogSys.StartFileLogs();

	/* Guilds */
	guild_mgr.SetDatabase(&database);
	GuildBanks = nullptr;

	/**
	 * NPC Scale Manager
	 */
	npc_scale_manager = new NpcScaleManager;
	npc_scale_manager->LoadScaleData();

#ifdef _EQDEBUG
	_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif

	Log(Logs::General, Logs::Zone_Server, "CURRENT_VERSION: %s", CURRENT_VERSION);

	/*
	* Setup nice signal handlers
	*/
	if (signal(SIGINT, CatchSignal) == SIG_ERR) {
		Log(Logs::General, Logs::Error, "Could not set signal handler");
		return 1;
	}
	if (signal(SIGTERM, CatchSignal) == SIG_ERR) {
		Log(Logs::General, Logs::Error, "Could not set signal handler");
		return 1;
	}
#ifndef WIN32
	if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) {
		Log(Logs::General, Logs::Error, "Could not set signal handler");
		return 1;
	}
#endif

	Log(Logs::General, Logs::Zone_Server, "Mapping Incoming Opcodes");
	MapOpcodes();

	Log(Logs::General, Logs::Zone_Server, "Loading Variables");
	database.LoadVariables();

	std::string hotfix_name;
	if (database.GetVariable("hotfix_name", hotfix_name)) {
		if (!hotfix_name.empty()) {
			Log(Logs::General, Logs::Zone_Server, "Current hotfix in use: '%s'", hotfix_name.c_str());
		}
	}

	Log(Logs::General, Logs::Zone_Server, "Loading zone names");
	database.LoadZoneNames();

	Log(Logs::General, Logs::Zone_Server, "Loading items");
	if (!database.LoadItems(hotfix_name)) {
		Log(Logs::General, Logs::Error, "Loading items FAILED!");
		Log(Logs::General, Logs::Error, "Failed. But ignoring error and going on...");
	}

	Log(Logs::General, Logs::Zone_Server, "Loading npc faction lists");
	if (!database.LoadNPCFactionLists(hotfix_name)) {
		Log(Logs::General, Logs::Error, "Loading npcs faction lists FAILED!");
		return 1;
	}
	Log(Logs::General, Logs::Zone_Server, "Loading loot tables");
	if (!database.LoadLoot(hotfix_name)) {
		Log(Logs::General, Logs::Error, "Loading loot FAILED!");
		return 1;
	}
	Log(Logs::General, Logs::Zone_Server, "Loading skill caps");
	if (!database.LoadSkillCaps(std::string(hotfix_name))) {
		Log(Logs::General, Logs::Error, "Loading skill caps FAILED!");
		return 1;
	}

	Log(Logs::General, Logs::Zone_Server, "Loading spells");
	if (!database.LoadSpells(hotfix_name, &SPDAT_RECORDS, &spells)) {
		Log(Logs::General, Logs::Error, "Loading spells FAILED!");
		return 1;
	}

	Log(Logs::General, Logs::Zone_Server, "Loading base data");
	if (!database.LoadBaseData(hotfix_name)) {
		Log(Logs::General, Logs::Error, "Loading base data FAILED!");
		return 1;
	}

	Log(Logs::General, Logs::Zone_Server, "Loading guilds");
	guild_mgr.LoadGuilds();

	Log(Logs::General, Logs::Zone_Server, "Loading factions");
	database.LoadFactionData();

	Log(Logs::General, Logs::Zone_Server, "Loading titles");
	title_manager.LoadTitles();

	Log(Logs::General, Logs::Zone_Server, "Loading tributes");
	database.LoadTributes();

	Log(Logs::General, Logs::Zone_Server, "Loading corpse timers");
	database.GetDecayTimes(npcCorpseDecayTimes);

	Log(Logs::General, Logs::Zone_Server, "Loading profanity list");
	if (!EQEmu::ProfanityManager::LoadProfanityList(&database))
		Log(Logs::General, Logs::Error, "Loading profanity list FAILED!");

	Log(Logs::General, Logs::Zone_Server, "Loading commands");
	int retval = command_init();
	if (retval<0)
		Log(Logs::General, Logs::Error, "Command loading FAILED");
	else
		Log(Logs::General, Logs::Zone_Server, "%d commands loaded", retval);

	//rules:
	{
		std::string tmp;
		if (database.GetVariable("RuleSet", tmp)) {
			Log(Logs::General, Logs::Zone_Server, "Loading rule set '%s'", tmp.c_str());
			if (!RuleManager::Instance()->LoadRules(&database, tmp.c_str(), false)) {
				Log(Logs::General, Logs::Error, "Failed to load ruleset '%s', falling back to defaults.", tmp.c_str());
			}
		}
		else {
			if (!RuleManager::Instance()->LoadRules(&database, "default", false)) {
				Log(Logs::General, Logs::Zone_Server, "No rule set configured, using default rules");
			}
			else {
				Log(Logs::General, Logs::Zone_Server, "Loaded default rule set 'default'", tmp.c_str());
			}
		}

		EQEmu::InitializeDynamicLookups();
		Log(Logs::General, Logs::Zone_Server, "Initialized dynamic dictionary entries");
	}

#ifdef BOTS
	Log(Logs::General, Logs::Zone_Server, "Loading bot commands");
	int botretval = bot_command_init();
	if (botretval<0)
		Log(Logs::General, Logs::Error, "Bot command loading FAILED");
	else
		Log(Logs::General, Logs::Zone_Server, "%d bot commands loaded", botretval);

	Log(Logs::General, Logs::Zone_Server, "Loading bot spell casting chances");
	if (!botdb.LoadBotSpellCastingChances())
		Log(Logs::General, Logs::Error, "Bot spell casting chances loading FAILED");
#endif

	if (RuleB(TaskSystem, EnableTaskSystem)) {
		Log(Logs::General, Logs::Tasks, "[INIT] Loading Tasks");
		taskmanager = new TaskManager;
		taskmanager->LoadTasks();
	}

	parse = new QuestParserCollection();
#ifdef LUA_EQEMU
	parse->RegisterQuestInterface(LuaParser::Instance(), "lua");
#endif

#ifdef EMBPERL
	auto perl_parser = new PerlembParser();
	parse->RegisterQuestInterface(perl_parser, "pl");

	/* Load Perl Event Export Settings */
	parse->LoadPerlEventExportSettings(parse->perl_event_export_settings);

#endif

	//now we have our parser, load the quests
	Log(Logs::General, Logs::Zone_Server, "Loading quests");
	parse->ReloadQuests();

	worldserver.Connect();

	Timer InterserverTimer(INTERSERVER_TIMER); // does MySQL pings and auto-reconnect
#ifdef EQPROFILE
#ifdef PROFILE_DUMP_TIME
	Timer profile_dump_timer(PROFILE_DUMP_TIME * 1000);
	profile_dump_timer.Start();
#endif
#endif
	if (!strlen(zone_name) || !strcmp(zone_name, ".")) {
		Log(Logs::General, Logs::Zone_Server, "Entering sleep mode");
	}
	else if (!Zone::Bootup(database.GetZoneID(zone_name), instance_id, true)) {
		Log(Logs::General, Logs::Error, "Zone Bootup failed :: Zone::Bootup");
		zone = 0;
	}

	//register all the patches we have avaliable with the stream identifier.
	EQStreamIdentifier stream_identifier;
	RegisterAllPatches(stream_identifier);

#ifndef WIN32
	Log(Logs::Detail, Logs::None, "Main thread running with thread id %d", pthread_self());
#endif

	Timer quest_timers(100);
	UpdateWindowTitle();
	bool worldwasconnected = worldserver.Connected();
	std::shared_ptr<EQStreamInterface> eqss;
	EQStreamInterface *eqsi;
	bool eqsf_open = false;
	std::unique_ptr<EQ::Net::EQStreamManager> eqsm;
	std::chrono::time_point<std::chrono::system_clock> frame_prev = std::chrono::system_clock::now();

	auto loop_fn = [&](EQ::Timer* t) {
		//Advance the timer to our current point in time
		Timer::SetCurrentTime();

		//Calculate frame time
		std::chrono::time_point<std::chrono::system_clock> frame_now = std::chrono::system_clock::now();
		frame_time = std::chrono::duration_cast<std::chrono::duration<double>>(frame_now - frame_prev).count();
		frame_prev = frame_now;

		if (!eqsf_open && Config->ZonePort != 0) {
			Log(Logs::General, Logs::Zone_Server, "Starting EQ Network server on port %d", Config->ZonePort);

			EQ::Net::EQStreamManagerOptions opts(Config->ZonePort, false, true);
			opts.daybreak_options.resend_delay_ms = RuleI(Network, ResendDelayBaseMS);
			opts.daybreak_options.resend_delay_factor = RuleR(Network, ResendDelayFactor);
			opts.daybreak_options.resend_delay_min = RuleI(Network, ResendDelayMinMS);
			opts.daybreak_options.resend_delay_max = RuleI(Network, ResendDelayMaxMS);
			eqsm.reset(new EQ::Net::EQStreamManager(opts));
			eqsf_open = true;

			eqsm->OnNewConnection([&stream_identifier](std::shared_ptr<EQ::Net::EQStream> stream) {
				stream_identifier.AddStream(stream);
				LogF(Logs::Detail, Logs::World_Server, "New connection from IP {0}:{1}", stream->RemoteEndpoint(), ntohs(stream->GetRemotePort()));
			});
		}

		//give the stream identifier a chance to do its work....
		stream_identifier.Process();

		//check the stream identifier for any now-identified streams
		while ((eqsi = stream_identifier.PopIdentified())) {
			//now that we know what patch they are running, start up their client object
			struct in_addr	in;
			in.s_addr = eqsi->GetRemoteIP();
			Log(Logs::Detail, Logs::World_Server, "New client from %s:%d", inet_ntoa(in), ntohs(eqsi->GetRemotePort()));
			auto client = new Client(eqsi);
			entity_list.AddClient(client);
		}

		if (worldserver.Connected()) {
			worldwasconnected = true;
		}
		else {
			if (worldwasconnected && is_zone_loaded) {
				entity_list.ChannelMessageFromWorld(0, 0, 6, 0, 0, "WARNING: World server connection lost");
				worldwasconnected = false;
			}
		}

		if (is_zone_loaded) {
			{
				if (net.group_timer.Enabled() && net.group_timer.Check())
					entity_list.GroupProcess();

				if (net.door_timer.Enabled() && net.door_timer.Check())
					entity_list.DoorProcess();

				if (net.object_timer.Enabled() && net.object_timer.Check())
					entity_list.ObjectProcess();

				if (net.corpse_timer.Enabled() && net.corpse_timer.Check())
					entity_list.CorpseProcess();

				if (net.trap_timer.Enabled() && net.trap_timer.Check())
					entity_list.TrapProcess();

				if (net.raid_timer.Enabled() && net.raid_timer.Check())
					entity_list.RaidProcess();

				entity_list.Process();
				entity_list.MobProcess();
				entity_list.BeaconProcess();
				entity_list.EncounterProcess();

				if (zone) {
					if (!zone->Process()) {
						Zone::Shutdown();
					}
				}

				if (quest_timers.Check())
					quest_manager.Process();

			}
		}

		if (InterserverTimer.Check()) {
			InterserverTimer.Start();
			database.ping();
			entity_list.UpdateWho();
		}
	};

	EQ::Timer process_timer(loop_fn);
	bool is_boat_zone = strstr(zone_name, "erudnext") != NULL || strstr(zone_name, "freporte") != NULL || strstr(zone_name, "qeynos") != NULL || strstr(zone_name, "oot") != NULL || strstr(zone_name, "timorous") != NULL || strstr(zone_name, "erudsxing") != NULL || strstr(zone_name, "firiona") != NULL || strstr(zone_name, "butcher") != NULL || strstr(zone_name, "overthere") != NULL || strstr(zone_name, "oasis") != NULL || strstr(zone_name, "nro") != NULL || strstr(zone_name, "iceclad") != NULL;
	if (!is_boat_zone)
		process_timer.Start(1000, true);
	else
		process_timer.Start(100, true);

	while (RunLoops) {
		if (!is_boat_zone)
		{
			bool previous_loaded = is_zone_loaded && numclients > 0;
			EQ::EventLoop::Get().Process();

			bool current_loaded = is_zone_loaded && numclients > 0;
			if (previous_loaded && !current_loaded) {
				process_timer.Stop();
				process_timer.Start(1000, true);
			}
			else if (!previous_loaded && current_loaded) {
				process_timer.Stop();
				process_timer.Start(32, true);
			}

			if (current_loaded) {
				Sleep(1);
			}
			else {
				Sleep(10);
			}
		}
		else
		{
			bool previous_loaded = is_zone_loaded;
			EQ::EventLoop::Get().Process();
			bool current_loaded = is_zone_loaded;
			if (previous_loaded && !current_loaded)
			{
				process_timer.Stop();
				process_timer.Start(100, true);

				if (zone && zone->GetZoneID() && zone->GetInstanceVersion()) {
					uint32 shutdown_timer = database.getZoneShutDownDelay(zone->GetZoneID(), zone->GetInstanceVersion());
					zone->StartShutdownTimer(shutdown_timer);
				}
			}
			else if (!previous_loaded && current_loaded)
			{
				process_timer.Stop();
				process_timer.Start(10, true);
			}
			Sleep(1);
		}
	}

	entity_list.Clear();
	entity_list.RemoveAllEncounters(); // gotta do it manually or rewrite lots of shit :P

	parse->ClearInterfaces();

#ifdef EMBPERL
	safe_delete(perl_parser);
#endif

	safe_delete(Config);

	if (zone != 0)
		Zone::Shutdown(true);
	//Fix for Linux world server problem.
	safe_delete(taskmanager);
	command_deinit();
#ifdef BOTS
	bot_command_deinit();
#endif
	safe_delete(parse);
	Log(Logs::General, Logs::Zone_Server, "Proper zone shutdown complete.");
	LogSys.CloseFileLogs();
	return 0;
}
Exemple #15
0
int main()
{
	RegisterExecutablePlatform(ExePlatformLogin);
	set_exception_handler();
#ifdef _WINDOWS //Starts window minimized on Windows.
	HWND handleWindow;
	AllocConsole();
	handleWindow = FindWindowA("ConsoleWindowClass", nullptr);
	ShowWindow(handleWindow, 2);
#endif

	//Create our error log, is of format login_<number>.log
	time_t current_time = time(nullptr);
	std::stringstream log_name(std::stringstream::in | std::stringstream::out);
#ifdef WIN32
	log_name << ".\\logs\\login_" << (unsigned int)current_time << ".log";
#else
	log_name << "./logs/login_" << (unsigned int)current_time << ".log";
#endif
	server_log = new ErrorLog(log_name.str().c_str());
	server_log->Log(log_debug, "Logging System Init.");

	//Create our subsystem and parse the ini file.
	server.config = new Config();
	server_log->Log(log_debug, "Config System Init.");

	std::string configFile = "login.ini"; 
	ifstream f(configFile.c_str());
	if (f.good())
	{
	}
	else
	{
		f.close();
		server_log->Log(log_debug, "login.ini errors. Incomplete or missing.");
		#ifdef WIN32 //Almost never ran in a terminal on linux, so no need to hold window open to see error.
		server_log->Log(log_debug, "Press any key to close");
		std::getchar();
		#endif
	}

	server.config->Parse("login.ini");

	//Parse auto account creation option.
	if (server.config->GetVariable("options", "auto_account_create").compare("TRUE") == 0)
	{
		server.options.AutoCreate(true);
	}

	//Parse auto account activation option.
	if (server.config->GetVariable("options", "auto_account_activate").compare("TRUE") == 0)
	{
		server.options.AutoActivate(true);
	}

	//Parse failed access log option.
	if (server.config->GetVariable("options", "failed_login_log").compare("TRUE") == 0)
	{
		server.options.LoginFails(true);
	}

	//Parse IP login access log option. For cross checking account/IP "anti cheat/box record"
	if (server.config->GetVariable("options", "good_loginIP_log").compare("TRUE") == 0)
	{
		server.options.LoginGood(true);
	}

	//Parse unregistered allowed option.
	if(server.config->GetVariable("options", "unregistered_allowed").compare("FALSE") == 0)
	{
		server.options.AllowUnregistered(false);
	}

	//Parse trace option.
	if(server.config->GetVariable("options", "trace").compare("TRUE") == 0)
	{
		server.options.Trace(true);
	}

	//Parse trace option.
	if(server.config->GetVariable("options", "world_trace").compare("TRUE") == 0)
	{
		server.options.WorldTrace(true);
	}

	//Parse packet inc dump option.
	if(server.config->GetVariable("options", "dump_packets_in").compare("TRUE") == 0)
	{
		server.options.DumpInPackets(true);
	}

	//Parse packet out dump option.
	if(server.config->GetVariable("options", "dump_packets_out").compare("TRUE") == 0)
	{
		server.options.DumpOutPackets(true);
	}

	//Parse encryption mode option.
	std::string mode = server.config->GetVariable("security", "mode");
	if(mode.size() > 0)
	{
		server.options.EncryptionMode(atoi(mode.c_str()));
	}

	//Parse local network option.
	std::string ln = server.config->GetVariable("options", "local_network");
	if(ln.size() > 0)
	{
		server.options.LocalNetwork(ln);
	}

	//Parse local network option.
	std::string mip = server.config->GetVariable("options", "network_ip");
	if(mip.size() > 0)
	{
		server.options.NetworkIP(mip);
	}

	//Parse local network option.
	std::string pws = server.config->GetVariable("options", "salt");
	if(pws.size() > 0)
	{
		server.options.SetSalt(pws);
	}

	//Parse reject duplicate servers option.
	if(server.config->GetVariable("options", "reject_duplicate_servers").compare("TRUE") == 0)
	{
		server.options.RejectDuplicateServers(true);
	}

	//Parse account table option.
	ln = server.config->GetVariable("schema", "account_table");
	if(ln.size() > 0)
	{
		server.options.AccountTable(ln);
	}

	//Parse access log table option.
	ln = server.config->GetVariable("schema", "access_log_table");
	if (ln.size() > 0)
	{
		server.options.AccountAccessLogTable(ln);
	}

	//Parse world account table option.
	ln = server.config->GetVariable("schema", "world_registration_table");
	if(ln.size() > 0)
	{
		server.options.WorldRegistrationTable(ln);
	}

	//Parse admin world account table option.
	ln = server.config->GetVariable("schema", "world_admin_registration_table");
	if(ln.size() > 0)
	{
		server.options.WorldAdminRegistrationTable(ln);
	}

	//Parse world type table option.
	ln = server.config->GetVariable("schema", "world_server_type_table");
	if(ln.size() > 0)
	{
		server.options.WorldServerTypeTable(ln);
	}

	//Create our DB from options.
	if(server.config->GetVariable("database", "subsystem").compare("MySQL") == 0)
	{
#ifdef EQEMU_MYSQL_ENABLED
		server_log->Log(log_debug, "MySQL Database Init.");
		server.db = (Database*)new DatabaseMySQL(
			server.config->GetVariable("database", "user"),
			server.config->GetVariable("database", "password"),
			server.config->GetVariable("database", "host"),
			server.config->GetVariable("database", "port"),
			server.config->GetVariable("database", "db"));
#endif
	}
	else if(server.config->GetVariable("database", "subsystem").compare("PostgreSQL") == 0)
	{
#ifdef EQEMU_POSTGRESQL_ENABLED
		server_log->Log(log_debug, "PostgreSQL Database Init.");
		server.db = (Database*)new DatabasePostgreSQL(
			server.config->GetVariable("database", "user"),
			server.config->GetVariable("database", "password"),
			server.config->GetVariable("database", "host"),
			server.config->GetVariable("database", "port"),
			server.config->GetVariable("database", "db"));
#endif
	}

	//Make sure our database got created okay, otherwise cleanup and exit.
	if(!server.db)
	{
		server_log->Log(log_error, "Database Initialization Failure.");
		server_log->Log(log_debug, "Config System Shutdown.");
		delete server.config;
		server_log->Log(log_debug, "Log System Shutdown.");
		delete server_log;
		return 1;
	}

	//create our server manager.
	server_log->Log(log_debug, "Server Manager Initialize.");
	server.SM = new ServerManager();
	if(!server.SM)
	{
		//We can't run without a server manager, cleanup and exit.
		server_log->Log(log_error, "Server Manager Failed to Start.");
		server_log->Log(log_debug, "Database System Shutdown.");
		delete server.db;
		server_log->Log(log_debug, "Config System Shutdown.");
		delete server.config;
		server_log->Log(log_debug, "Log System Shutdown.");
		delete server_log;
		return 1;
	}

	//create our client manager.
	server_log->Log(log_debug, "Client Manager Initialize.");
	server.CM = new ClientManager();
	if(!server.CM)
	{
		//We can't run without a client manager, cleanup and exit.
		server_log->Log(log_error, "Client Manager Failed to Start.");
		server_log->Log(log_debug, "Server Manager Shutdown.");
		delete server.SM;
		server_log->Log(log_debug, "Database System Shutdown.");
		delete server.db;
		server_log->Log(log_debug, "Config System Shutdown.");
		delete server.config;
		server_log->Log(log_debug, "Log System Shutdown.");
		delete server_log;
		return 1;
	}

#ifdef WIN32
#ifdef UNICODE
	SetConsoleTitle(L"EQEmu Login Server");
#else
	SetConsoleTitle("EQEmu Login Server");
#endif
#endif

	server_log->Log(log_debug, "Server Started.");
	while(run_server)
	{
		Timer::SetCurrentTime();
		server.CM->Process();
		server.SM->Process();
		Sleep(100);
	}
	server_log->Log(log_debug, "Server Shutdown.");
	server_log->Log(log_debug, "Client Manager Shutdown.");
	delete server.CM;
	server_log->Log(log_debug, "Server Manager Shutdown.");
	delete server.SM;
	server_log->Log(log_debug, "Database System Shutdown.");
	delete server.db;
	server_log->Log(log_debug, "Config System Shutdown.");
	delete server.config;
	server_log->Log(log_debug, "Log System Shutdown.");
	delete server_log;
	return 0;
}