Exemple #1
0
void ExportBaseData(SharedDatabase *db) {
	Log.Out(Logs::General, Logs::Status, "Exporting Base Data...");

	FILE *f = fopen("export/BaseData.txt", "w");
	if(!f) {
		Log.Out(Logs::General, Logs::Error, "Unable to open export/BaseData.txt to write, skipping.");
		return;
	}

	const std::string query = "SELECT * FROM base_data ORDER BY level, class";
	auto results = db->QueryDatabase(query);
	if(results.Success()) {
        for (auto row = results.begin();row != results.end();++row) {
			std::string line;
			unsigned int fields = results.ColumnCount();
			for(unsigned int rowIndex = 0; rowIndex < fields; ++rowIndex) {
				if(rowIndex != 0)
					line.push_back('^');

				if(row[rowIndex] != nullptr) {
					line += row[rowIndex];
				}
			}

			fprintf(f, "%s\n", line.c_str());
		}
	} else {
	}

	fclose(f);
}
Exemple #2
0
void ExportSpells(SharedDatabase *db) {
	Log.Out(Logs::General, Logs::Status, "Exporting Spells...");

	FILE *f = fopen("export/spells_us.txt", "w");
	if(!f) {
		Log.Out(Logs::General, Logs::Error, "Unable to open export/spells_us.txt to write, skipping.");
		return;
	}

	const std::string query = "SELECT * FROM spells_new ORDER BY id";
	auto results = db->QueryDatabase(query);

	if(results.Success()) {
        for (auto row = results.begin(); row != results.end(); ++row) {
			std::string line;
			unsigned int fields = results.ColumnCount();
			for(unsigned int i = 0; i < fields; ++i) {
				if(i != 0) {
					line.push_back('^');
				}

				if(row[i] != nullptr) {
					line += row[i];
				}
			}

			fprintf(f, "%s\n", line.c_str());
		}
	} else {
	}

	fclose(f);
}
Exemple #3
0
void ExportSkillCaps(SharedDatabase *db) {
	Log.Out(Logs::General, Logs::Status, "Exporting Skill Caps...");

	FILE *f = fopen("export/SkillCaps.txt", "w");
	if(!f) {
		Log.Out(Logs::General, Logs::Error, "Unable to open export/SkillCaps.txt to write, skipping.");
		return;
	}

	for(int cl = 1; cl <= 16; ++cl) {
		for(int skill = 0; skill <= 77; ++skill) {
			if(SkillUsable(db, skill, cl)) {
				int previous_cap = 0;
				for(int level = 1; level <= 100; ++level) {
					int cap = GetSkill(db, skill, cl, level);
					if(cap < previous_cap) {
						cap = previous_cap;
					}

					fprintf(f, "%d^%d^%d^%d^0\n", cl, skill, level, cap);
					previous_cap = cap;
				}
			}
		}
	}

	fclose(f);
}
Exemple #4
0
void ExportDBStrings(SharedDatabase *db) {
	Log.Out(Logs::General, Logs::Status, "Exporting DB Strings...");

	FILE *f = fopen("export/dbstr_us.txt", "w");
	if(!f) {
		Log.Out(Logs::General, Logs::Error, "Unable to open export/dbstr_us.txt to write, skipping.");
		return;
	}

	fprintf(f, "Major^Minor^String(New)\n");
	const std::string query = "SELECT * FROM db_str ORDER BY id, type";
	auto results = db->QueryDatabase(query);
	if(results.Success()) {
		for(auto row = results.begin(); row != results.end(); ++row) {
			std::string line;
			unsigned int fields = results.ColumnCount();
			for(unsigned int rowIndex = 0; rowIndex < fields; ++rowIndex) {
				if(rowIndex != 0)
					line.push_back('^');

				if(row[rowIndex] != nullptr) {
					line += row[rowIndex];
				}
			}

			fprintf(f, "%s\n", line.c_str());
		}
	}

	fclose(f);
}
Exemple #5
0
void ImportSkillCaps(SharedDatabase *db) {
	Log.Out(Logs::General, Logs::Status, "Importing Skill Caps...");

	FILE *f = fopen("import/SkillCaps.txt", "r");
	if(!f) {
		Log.Out(Logs::General, Logs::Error, "Unable to open import/SkillCaps.txt to read, skipping.");
		return;
	}

	std::string delete_sql = "DELETE FROM skill_caps";
	db->QueryDatabase(delete_sql);

	char buffer[2048];
	while(fgets(buffer, 2048, f)) {
		auto split = SplitString(buffer, '^');

		if(split.size() < 4) {
			continue;
		}


		int class_id, skill_id, level, cap;
		class_id = atoi(split[0].c_str());
		skill_id = atoi(split[1].c_str());
		level = atoi(split[2].c_str());
		cap = atoi(split[3].c_str());

		std::string sql = StringFormat("INSERT INTO skill_caps(class, skillID, level, cap) VALUES(%d, %d, %d, %d)",
			class_id, skill_id, level, cap);

		db->QueryDatabase(sql);
	}

	fclose(f);
}
Exemple #6
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 #7
0
void Shutdown()
{
    Zone::Shutdown(true);
    RunLoops = false;
    worldserver.Disconnect();
    Log.Out(Logs::General, Logs::Zone_Server, "Shutting down...");
    Log.CloseFileLogs();
}
Exemple #8
0
void ImportBaseData(SharedDatabase *db) {
	Log.Out(Logs::General, Logs::Status, "Importing Base Data...");

	FILE *f = fopen("import/BaseData.txt", "r");
	if(!f) {
		Log.Out(Logs::General, Logs::Error, "Unable to open import/BaseData.txt to read, skipping.");
		return;
	}

	std::string delete_sql = "DELETE FROM base_data";
	db->QueryDatabase(delete_sql);

	char buffer[2048];
	while(fgets(buffer, 2048, f)) {
		auto split = SplitString(buffer, '^');

		if(split.size() < 10) {
			continue;
		}

		std::string sql;
		int level, class_id;
		double hp, mana, end, unk1, unk2, hp_fac, mana_fac, end_fac;

		level = atoi(split[0].c_str());
		class_id = atoi(split[1].c_str());
		hp = atof(split[2].c_str());
		mana = atof(split[3].c_str());
		end = atof(split[4].c_str());
		unk1 = atof(split[5].c_str());
		unk2 = atof(split[6].c_str());
		hp_fac = atof(split[7].c_str());
		mana_fac = atof(split[8].c_str());
		end_fac = atof(split[9].c_str());

		sql = StringFormat("INSERT INTO base_data(level, class, hp, mana, end, unk1, unk2, hp_fac, "
			"mana_fac, end_fac) VALUES(%d, %d, %f, %f, %f, %f, %f, %f, %f, %f)",
			level, class_id, hp, mana, end, unk1, unk2, hp_fac, mana_fac, end_fac);

		db->QueryDatabase(sql);
	}

	fclose(f);
}
Exemple #9
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 #10
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 #11
0
void CatchSignal(int sig_num) {
	Log.Out(Logs::General, Logs::World_Server,"Caught signal %d",sig_num);
	RunLoops = false;
}
Exemple #12
0
int main(int argc, char** argv) {
	RegisterExecutablePlatform(ExePlatformWorld);
	Log.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.Out(Logs::General, Logs::World_Server, "Loading server configuration..");
	if (!WorldConfig::LoadConfig()) {
		Log.Out(Logs::General, Logs::World_Server, "Loading server configuration failed.");
		return 1;
	}
	const WorldConfig *Config=WorldConfig::get();

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

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

	if (signal(SIGINT, CatchSignal) == SIG_ERR)	{
		Log.Out(Logs::General, Logs::World_Server, "Could not set signal handler");
		return 1;
	}
	if (signal(SIGTERM, CatchSignal) == SIG_ERR)	{
		Log.Out(Logs::General, Logs::World_Server, "Could not set signal handler");
		return 1;
	}
	#ifndef WIN32
	if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)	{
		Log.Out(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());
			Log.Out(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());
			Log.Out(Logs::General, Logs::World_Server, "Added loginserver %s:%i", iterator.GetData()->LoginHost.c_str(), iterator.GetData()->LoginPort);
			iterator.Advance();
		}
	}

	Log.Out(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.Out(Logs::General, Logs::World_Server, "Cannot continue without a database connection.");
		return 1;
	}
	guild_mgr.SetDatabase(&database);

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

	bool ignore_db = false;
	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 if(strcasecmp(argv[1], "ignore_db") == 0) {
			ignore_db = true;
		}
		else {
			std::cerr << "Error, unknown command line option" << std::endl;
			return 1;
		}
	}

	if(Config->WorldHTTPEnabled) {
		Log.Out(Logs::General, Logs::World_Server, "Starting HTTP world service...");
		http_server.Start(Config->WorldHTTPPort, Config->WorldHTTPMimeFile.c_str());
	} else {
		Log.Out(Logs::General, Logs::World_Server, "HTTP world service disabled.");
	}

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

	char hotfix_name[256] = { 0 };
	if(database.GetVariable("hotfix_name", hotfix_name, 256)) {
		if(strlen(hotfix_name) > 0) {
			Log.Out(Logs::General, Logs::Zone_Server, "Current hotfix in use: '%s'", hotfix_name);
		}
	}

	Log.Out(Logs::General, Logs::World_Server, "Loading zones..");
	database.LoadZoneNames();
	Log.Out(Logs::General, Logs::World_Server, "Clearing groups..");
	database.ClearGroup();
	Log.Out(Logs::General, Logs::World_Server, "Clearing raids..");
	database.ClearRaid();
	database.ClearRaidDetails();
	database.ClearRaidLeader();
	Log.Out(Logs::General, Logs::World_Server, "Clearing inventory snapshots..");
	database.ClearInvSnapshots();
	Log.Out(Logs::General, Logs::World_Server, "Loading items..");
	if(!database.LoadItems(hotfix_name))
		Log.Out(Logs::General, Logs::World_Server, "Error: Could not load item data. But ignoring");
	Log.Out(Logs::General, Logs::World_Server, "Loading skill caps..");
	if(!database.LoadSkillCaps(std::string(hotfix_name)))
		Log.Out(Logs::General, Logs::World_Server, "Error: Could not load skill cap data. But ignoring");
	Log.Out(Logs::General, Logs::World_Server, "Loading guilds..");
	guild_mgr.LoadGuilds();
	//rules:
	{
		char tmp[64];
		if (database.GetVariable("RuleSet", tmp, sizeof(tmp)-1)) {
			Log.Out(Logs::General, Logs::World_Server, "Loading rule set '%s'", tmp);
			if(!RuleManager::Instance()->LoadRules(&database, tmp)) {
				Log.Out(Logs::General, Logs::World_Server, "Failed to load ruleset '%s', falling back to defaults.", tmp);
			}
		} else {
			if(!RuleManager::Instance()->LoadRules(&database, "default")) {
				Log.Out(Logs::General, Logs::World_Server, "No rule set configured, using default rules");
			} else {
				Log.Out(Logs::General, Logs::World_Server, "Loaded default rule set 'default'", tmp);
			}
		}
	}
	if(RuleB(World, ClearTempMerchantlist)){
		Log.Out(Logs::General, Logs::World_Server, "Clearing temporary merchant lists..");
		database.ClearMerchantTemp();
	}
	Log.Out(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.Out(Logs::General, Logs::World_Server, "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.Out(Logs::General, Logs::World_Server, "Reboot zone modes %s",holdzones ? "ON" : "OFF");

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

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

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

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

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

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

	char errbuf[TCPConnection_ErrorBufferSize];
	if (tcps.Open(Config->WorldTCPPort, errbuf)) {
		Log.Out(Logs::General, Logs::World_Server,"Zone (TCP) listener started.");
	} else {
		Log.Out(Logs::General, Logs::World_Server,"Failed to start zone (TCP) listener on port %d:",Config->WorldTCPPort);
		Log.Out(Logs::General, Logs::World_Server,"        %s",errbuf);
		return 1;
	}
	if (eqsf.Open()) {
		Log.Out(Logs::General, Logs::World_Server,"Client (UDP) listener started.");
	} else {
		Log.Out(Logs::General, Logs::World_Server,"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;
	std::shared_ptr<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.Out(Logs::General, Logs::World_Server, "New connection from %s:%d", inet_ntoa(in),ntohs(eqs->GetRemotePort()));
			stream_identifier.AddStream(eqs);	//takes the stream
		}

		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.Out(Logs::General, 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.Out(Logs::General, 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.Out(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.Out(Logs::General, 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();

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

		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.Out(Logs::General, Logs::World_Server, "Failed to save eqtime.");
			else
				Log.Out(Logs::Detail, Logs::World_Server, "EQTime successfully saved.");
		}
		
		//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();

			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.Out(Logs::General, Logs::World_Server, "World main loop completed.");
	Log.Out(Logs::General, Logs::World_Server, "Shutting down console connections (if any).");
	console_list.KillAll();
	Log.Out(Logs::General, Logs::World_Server, "Shutting down zone connections (if any).");
	zoneserver_list.KillAll();
	Log.Out(Logs::General, Logs::World_Server, "Zone (TCP) listener stopped.");
	tcps.Close();
	Log.Out(Logs::General, Logs::World_Server, "Client (UDP) listener stopped.");
	eqsf.Close();
	Log.Out(Logs::General, Logs::World_Server, "Signaling HTTP service to stop...");
	http_server.Stop();
	Log.CloseFileLogs();

	return 0;
}
Exemple #13
0
void CatchSignal(int sig_num) {
	Log.Out(Logs::Detail, Logs::Launcher, "Caught signal %d", sig_num);
	RunLoops = false;
}
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 #15
0
/**
* Opens a file and passes it to the tokenizer
* Then it parses the tokens returned and puts them into titles and variables.
*/
void Config::Parse(const char *file_name)
{
	if(file_name == nullptr)
	{
		Log.Out(Logs::General, Logs::Error, "Config::Parse(), file_name passed was null.");
		return;
	}

	vars.clear();
	FILE *input = fopen(file_name, "r");
	if(input)
	{
		std::list<std::string> tokens;
		Tokenize(input, tokens);

		char mode = 0;
		std::string title, param, arg;
		std::list<std::string>::iterator iter = tokens.begin();
		while(iter != tokens.end())
		{
			if((*iter).compare("[") == 0)
			{
				title.clear();
				bool first = true;
				++iter;
				if(iter == tokens.end())
				{
					Log.Out(Logs::General, Logs::Error, "Config::Parse(), EOF before title done parsing.");
					fclose(input);
					vars.clear();
					return;
				}

				while((*iter).compare("]") != 0 && iter != tokens.end())
				{
					if(!first)
					{
						title += " ";
					}
					else
					{
						first = false;
					}

					title += (*iter);
					++iter;
				}
				++iter;
			}

			if(mode == 0)
			{
				param = (*iter);
				mode++;
			}
			else if(mode == 1)
			{
				mode++;
				if((*iter).compare("=") != 0)
				{
					Log.Out(Logs::General, Logs::Error, "Config::Parse(), invalid parse token where = should be.");
					fclose(input);
					vars.clear();
					return;
				}
			}
			else
			{
				arg = (*iter);
				mode = 0;
				std::map<std::string, std::map<std::string, std::string> >::iterator map_iter = vars.find(title);
				if(map_iter != vars.end())
				{
					map_iter->second[param] = arg;
					vars[title] = map_iter->second;
				}
				else
				{
					std::map<std::string, std::string> var_map;
					var_map[param] = arg;
					vars[title] = var_map;
				}
			}
			++iter;
		}
		fclose(input);
	}
	else
	{
		Log.Out(Logs::General, Logs::Error, "Config::Parse(), file was unable to be opened for parsing.");
	}
}
Exemple #16
0
void ImportSpells(SharedDatabase *db) {
	Log.Out(Logs::General, Logs::Status, "Importing Spells...");
	FILE *f = fopen("import/spells_us.txt", "r");
	if(!f) {
		Log.Out(Logs::General, Logs::Error, "Unable to open import/spells_us.txt to read, skipping.");
		return;
	}

	std::string query = "DELETE FROM spells_new";
	db->QueryDatabase(query);

	int columns = GetSpellColumns(db);
	int spells_imported = 0;

	char buffer[2048];
	while(fgets(buffer, 2048, f)) {
		for(int i = 0; i < 2048; ++i) {
			if(buffer[i] == '\n') {
				buffer[i] = 0;
				break;
			}
		}

		std::string escaped = ::EscapeString(buffer);
		auto split = SplitString(escaped, '^');
		int line_columns = (int)split.size();

		std::string sql;
		if(line_columns >= columns) {
			sql = "INSERT INTO spells_new VALUES(";
			for(int i = 0; i < columns; ++i) {
				if(i != 0) {
					sql += ", '";
				} else {
					sql += "'";
				}

				sql += split[i];
				sql += "'";
			}

			sql += ");";
		} else {
			int i = 0;
			sql = "INSERT INTO spells_new VALUES(";
			for(; i < line_columns; ++i) {
				if(i != 0) {
					sql += ", '";
				} else {
					sql += "'";
				}

				sql += split[i];
				sql += "'";
			}

			for(; i < columns; ++i) {
				sql += ", '0'";
			}

			sql += ");";
		}

		db->QueryDatabase(sql);

		spells_imported++;
		if(spells_imported % 1000 == 0) {
			Log.Out(Logs::General, Logs::Status, "%d spells imported.", spells_imported);
		}
	}

	if(spells_imported % 1000 != 0) {
		Log.Out(Logs::General, Logs::Status, "%d spells imported.", spells_imported);
	}

	fclose(f);
}
Exemple #17
0
int main(int argc, char *argv[]) {
	RegisterExecutablePlatform(ExePlatformLaunch);
	Log.LoadLogSettingsDefaults();
	set_exception_handler();

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

	Log.Out(Logs::Detail, Logs::Launcher, "Loading server configuration..");
	if (!EQEmuConfig::LoadConfig()) {
		Log.Out(Logs::Detail, Logs::Launcher, "Loading server configuration failed.");
		return 1;
	}
	const EQEmuConfig *Config = EQEmuConfig::get();

	/*
	* Setup nice signal handlers
	*/
	if (signal(SIGINT, CatchSignal) == SIG_ERR)	{
		Log.Out(Logs::Detail, Logs::Launcher, "Could not set signal handler");
		return 1;
	}
	if (signal(SIGTERM, CatchSignal) == SIG_ERR)	{
		Log.Out(Logs::Detail, Logs::Launcher, "Could not set signal handler");
		return 1;
	}
	#ifndef WIN32
	if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)	{
		Log.Out(Logs::Detail, Logs::Launcher, "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.Out(Logs::Detail, Logs::Launcher, "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.Out(Logs::Detail, Logs::Launcher, "Starting main loop...");

	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;
	}

	Log.CloseFileLogs();

	return 0;
}
Exemple #18
0
void CatchSignal(int sig_num) {
#ifdef _WINDOWS
    Log.Out(Logs::General, Logs::Zone_Server, "Recieved signal: %i", sig_num);
#endif
    RunLoops = false;
}
Exemple #19
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;
}