mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-16 01:01:30 +00:00
Beginning of zone copy work
This commit is contained in:
parent
448a33a60c
commit
1c09a25261
@ -95,6 +95,7 @@ SET(common_sources
|
||||
platform.cpp
|
||||
json/json.hpp
|
||||
json/jsoncpp.cpp
|
||||
zone_copy.cpp
|
||||
zone_store.cpp
|
||||
net/console_server.cpp
|
||||
net/console_server_connection.cpp
|
||||
@ -627,6 +628,7 @@ SET(common_headers
|
||||
unix.h
|
||||
useperl.h
|
||||
version.h
|
||||
zone_copy.h
|
||||
zone_store.h
|
||||
event/event_loop.h
|
||||
event/task.h
|
||||
|
||||
169
common/zone_copy.cpp
Normal file
169
common/zone_copy.cpp
Normal file
@ -0,0 +1,169 @@
|
||||
#include "zone_copy.h"
|
||||
|
||||
|
||||
void ZoneCopier::ZoneCopy()
|
||||
{
|
||||
LogSys.log_settings[Logs::MySQLQuery].is_category_enabled = 1;
|
||||
LogSys.log_settings[Logs::MySQLQuery].log_to_console = 1;
|
||||
|
||||
LoadZoneToCopy();
|
||||
|
||||
}
|
||||
|
||||
Database *ZoneCopier::GetDatabase() const
|
||||
{
|
||||
return m_database;
|
||||
}
|
||||
|
||||
ZoneCopier *ZoneCopier::SetDatabase(Database *database)
|
||||
{
|
||||
ZoneCopier::m_database = database;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
Database *ZoneCopier::GetContentDatabase() const
|
||||
{
|
||||
return m_content_database;
|
||||
}
|
||||
|
||||
ZoneCopier *ZoneCopier::SetContentDatabase(Database *database)
|
||||
{
|
||||
ZoneCopier::m_content_database = database;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
const std::string &ZoneCopier::GetShortName() const
|
||||
{
|
||||
return m_source_short_name;
|
||||
}
|
||||
|
||||
void ZoneCopier::SetSourceShortName(const std::string &short_name)
|
||||
{
|
||||
ZoneCopier::m_source_short_name = short_name;
|
||||
}
|
||||
|
||||
int ZoneCopier::GetSourceVersion() const
|
||||
{
|
||||
return m_source_version;
|
||||
}
|
||||
|
||||
void ZoneCopier::SetSourceVersion(int source_version)
|
||||
{
|
||||
ZoneCopier::m_source_version = source_version;
|
||||
}
|
||||
|
||||
int ZoneCopier::GetDestinationVersion() const
|
||||
{
|
||||
return m_destination_version;
|
||||
}
|
||||
|
||||
void ZoneCopier::SetDestinationVersion(int destination_version)
|
||||
{
|
||||
ZoneCopier::m_destination_version = destination_version;
|
||||
}
|
||||
|
||||
void ZoneCopier::LoadZoneToCopy()
|
||||
{
|
||||
auto zones = ZoneRepository::GetWhere(
|
||||
*m_content_database,
|
||||
fmt::format("short_name = '{}' and version = 0", m_source_short_name)
|
||||
);
|
||||
|
||||
if (zones.empty()) {
|
||||
LogError("Zone [{}] not found in content database", m_source_short_name);
|
||||
return;
|
||||
}
|
||||
|
||||
m_zone = zones.front();
|
||||
m_zone.id = 0;
|
||||
m_zone.version = m_destination_version;
|
||||
m_zone_id = m_zone.zoneidnumber;
|
||||
|
||||
LogInfo(
|
||||
"Zone [{}] copied from version [{}] to version [{}]",
|
||||
m_source_short_name,
|
||||
m_source_version,
|
||||
m_destination_version
|
||||
);
|
||||
|
||||
m_spawn2s = Spawn2Repository::GetWhere(
|
||||
*m_content_database,
|
||||
fmt::format("zone = '{}' and version = {}", m_source_short_name, m_source_version)
|
||||
);
|
||||
|
||||
if (m_spawn2s.empty()) {
|
||||
LogError("No spawn2 entries found for zone [{}] version [{}]", m_source_short_name, m_source_version);
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<std::string> spawn_group_ids;
|
||||
|
||||
for (auto &spawn: m_spawn2s) {
|
||||
auto id = fmt::format("{}", spawn.spawngroupID);
|
||||
if (std::find(spawn_group_ids.begin(), spawn_group_ids.end(), id) == spawn_group_ids.end()) {
|
||||
spawn_group_ids.push_back(id);
|
||||
}
|
||||
}
|
||||
|
||||
m_spawngroups = SpawngroupRepository::GetWhere(
|
||||
*m_content_database,
|
||||
fmt::format("id IN ({})", Strings::Join(spawn_group_ids, ","))
|
||||
);
|
||||
|
||||
m_spawnentries = SpawnentryRepository::GetWhere(
|
||||
*m_content_database,
|
||||
fmt::format("spawngroupID IN ({})", Strings::Join(spawn_group_ids, ","))
|
||||
);
|
||||
|
||||
m_zone_points = ZonePointsRepository::GetWhere(
|
||||
*m_content_database,
|
||||
fmt::format("zone = '{}'", m_source_short_name)
|
||||
);
|
||||
|
||||
std::vector<std::string> npc_type_ids;
|
||||
for (auto &e: m_spawnentries) {
|
||||
auto id = fmt::format("{}", e.npcID);
|
||||
if (std::find(npc_type_ids.begin(), npc_type_ids.end(), id) == npc_type_ids.end()) {
|
||||
npc_type_ids.push_back(id);
|
||||
}
|
||||
}
|
||||
|
||||
m_npc_types = NpcTypesRepository::GetWhere(
|
||||
*m_content_database,
|
||||
fmt::format("id IN ({})", Strings::Join(npc_type_ids, ","))
|
||||
);
|
||||
|
||||
m_doors = DoorsRepository::GetWhere(
|
||||
*m_content_database,
|
||||
fmt::format("LOWER(zone) = '{}' and version = {}", m_source_short_name, m_source_version)
|
||||
);
|
||||
|
||||
m_ground_spawns = GroundSpawnsRepository::GetWhere(
|
||||
*m_content_database,
|
||||
fmt::format("zoneid = {} and version = {}", m_zone_id, m_source_version)
|
||||
);
|
||||
|
||||
m_objects = ObjectRepository::GetWhere(
|
||||
*m_content_database,
|
||||
fmt::format("zoneid = {} and version = {}", m_zone_id, m_source_version)
|
||||
);
|
||||
|
||||
LogInfo(
|
||||
"Found zone short_name [{}] long_name [{}] id [{}] version [{}]",
|
||||
m_zone.short_name,
|
||||
m_zone.long_name,
|
||||
m_zone.zoneidnumber,
|
||||
m_zone.version
|
||||
);
|
||||
|
||||
LogInfo("Found [{}] doors", m_doors.size());
|
||||
LogInfo("Found [{}] ground_spawns", m_ground_spawns.size());
|
||||
LogInfo("Found [{}] npc_types", m_npc_types.size());
|
||||
LogInfo("Found [{}] objects", m_objects.size());
|
||||
LogInfo("Found [{}] spawn entries", m_spawnentries.size());
|
||||
LogInfo("Found [{}] spawn groups", m_spawngroups.size());
|
||||
LogInfo("Found [{}] spawn2 entries", m_spawn2s.size());
|
||||
LogInfo("Found [{}] zone_points", m_zone_points.size());
|
||||
}
|
||||
56
common/zone_copy.h
Normal file
56
common/zone_copy.h
Normal file
@ -0,0 +1,56 @@
|
||||
#ifndef EQEMU_ZONECOPY_H
|
||||
#define EQEMU_ZONECOPY_H
|
||||
|
||||
#include "database.h"
|
||||
#include "repositories/zone_repository.h"
|
||||
#include "repositories/spawn2_repository.h"
|
||||
#include "repositories/spawngroup_repository.h"
|
||||
#include "repositories/spawnentry_repository.h"
|
||||
#include "repositories/zone_points_repository.h"
|
||||
#include "repositories/npc_types_repository.h"
|
||||
#include "repositories/doors_repository.h"
|
||||
#include "repositories/ground_spawns_repository.h"
|
||||
#include "repositories/object_repository.h"
|
||||
|
||||
class ZoneCopier {
|
||||
public:
|
||||
void ZoneCopy();
|
||||
|
||||
// setters and getters
|
||||
ZoneCopier *SetDatabase(Database *database);
|
||||
Database *GetDatabase() const;
|
||||
ZoneCopier *SetContentDatabase(Database *database);
|
||||
Database *GetContentDatabase() const;
|
||||
const std::string &GetShortName() const;
|
||||
void SetSourceShortName(const std::string &short_name);
|
||||
int GetSourceVersion() const;
|
||||
void SetSourceVersion(int source_version);
|
||||
int GetDestinationVersion() const;
|
||||
void SetDestinationVersion(int destination_version);
|
||||
private:
|
||||
void LoadZoneToCopy();
|
||||
|
||||
// reference to database
|
||||
Database *m_database;
|
||||
Database *m_content_database;
|
||||
|
||||
// inputs
|
||||
std::string m_source_short_name;
|
||||
int m_source_version;
|
||||
int m_destination_version;
|
||||
|
||||
// hold the data
|
||||
ZoneRepository::Zone m_zone;
|
||||
int m_zone_id;
|
||||
std::vector<Spawn2Repository::Spawn2> m_spawn2s;
|
||||
std::vector<SpawngroupRepository::Spawngroup> m_spawngroups;
|
||||
std::vector<SpawnentryRepository::Spawnentry> m_spawnentries;
|
||||
std::vector<ZonePointsRepository::ZonePoints> m_zone_points;
|
||||
std::vector<NpcTypesRepository::NpcTypes> m_npc_types;
|
||||
std::vector<DoorsRepository::Doors> m_doors;
|
||||
std::vector<GroundSpawnsRepository::GroundSpawns> m_ground_spawns;
|
||||
std::vector<ObjectRepository::Object> m_objects;
|
||||
};
|
||||
|
||||
|
||||
#endif //EQEMU_ZONECOPY_H
|
||||
16
world/cli/zone_copy.cpp
Normal file
16
world/cli/zone_copy.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
#include "../../common/eqemu_logsys_log_aliases.h"
|
||||
#include "../../common/zone_copy.h"
|
||||
#include "../../common/database.h"
|
||||
|
||||
void WorldserverCLI::ZoneCopyCmd(int argc, char **argv, argh::parser &cmd, std::string &description)
|
||||
{
|
||||
description = "Copies a character into a destination account";
|
||||
|
||||
auto c = ZoneCopier();
|
||||
c.SetDatabase(&database);
|
||||
c.SetContentDatabase(&content_db);
|
||||
c.SetSourceShortName("soldungb");
|
||||
c.SetSourceVersion(0);
|
||||
c.SetDestinationVersion(1);
|
||||
c.ZoneCopy();
|
||||
}
|
||||
@ -27,6 +27,7 @@ void WorldserverCLI::CommandHandler(int argc, char **argv)
|
||||
function_map["database:schema"] = &WorldserverCLI::DatabaseGetSchema;
|
||||
function_map["database:dump"] = &WorldserverCLI::DatabaseDump;
|
||||
function_map["database:updates"] = &WorldserverCLI::DatabaseUpdates;
|
||||
function_map["zone:copy"] = &WorldserverCLI::ZoneCopyCmd;
|
||||
function_map["test:test"] = &WorldserverCLI::TestCommand;
|
||||
function_map["test:colors"] = &WorldserverCLI::TestColors;
|
||||
function_map["test:expansion"] = &WorldserverCLI::ExpansionTestCommand;
|
||||
@ -56,3 +57,4 @@ void WorldserverCLI::CommandHandler(int argc, char **argv)
|
||||
#include "cli/test_repository_2.cpp"
|
||||
#include "cli/test_string_benchmark.cpp"
|
||||
#include "cli/version.cpp"
|
||||
#include "cli/zone_copy.cpp"
|
||||
|
||||
@ -18,6 +18,7 @@ public:
|
||||
static void DatabaseGetSchema(int argc, char **argv, argh::parser &cmd, std::string &description);
|
||||
static void DatabaseDump(int argc, char **argv, argh::parser &cmd, std::string &description);
|
||||
static void DatabaseUpdates(int argc, char **argv, argh::parser &cmd, std::string &description);
|
||||
static void ZoneCopyCmd(int argc, char **argv, argh::parser &cmd, std::string &description);
|
||||
static void TestCommand(int argc, char **argv, argh::parser &cmd, std::string &description);
|
||||
static void TestColors(int argc, char **argv, argh::parser &cmd, std::string &description);
|
||||
static void ExpansionTestCommand(int argc, char **argv, argh::parser &cmd, std::string &description);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user