Upload generated repositories

This commit is contained in:
Akkadius 2020-04-03 02:49:40 -05:00
parent 494811c04b
commit 82b017887d
170 changed files with 57003 additions and 8 deletions

View File

@ -0,0 +1,354 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_AA_ABILITY_REPOSITORY_H
#define EQEMU_AA_ABILITY_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class AaAbilityRepository {
public:
struct AaAbility {
int id;
std::string name;
int category;
int classes;
int races;
int drakkin_heritage;
int deities;
int status;
int type;
int charges;
int8 grant_only;
int first_rank_id;
int8 enabled;
int8 reset_on_death;
};
static std::string PrimaryKey()
{
return std::string("id");
}
static std::vector<std::string> Columns()
{
return {
"id",
"name",
"category",
"classes",
"races",
"drakkin_heritage",
"deities",
"status",
"type",
"charges",
"grant_only",
"first_rank_id",
"enabled",
"reset_on_death",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("aa_ability");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static AaAbility NewEntity()
{
AaAbility entry{};
entry.id = 0;
entry.name = 0;
entry.category = -1;
entry.classes = 131070;
entry.races = 65535;
entry.drakkin_heritage = 127;
entry.deities = 131071;
entry.status = 0;
entry.type = 0;
entry.charges = 0;
entry.grant_only = 0;
entry.first_rank_id = -1;
entry.enabled = 1;
entry.reset_on_death = 0;
return entry;
}
static AaAbility GetAaAbilityEntry(
const std::vector<AaAbility> &aa_abilitys,
int aa_ability_id
)
{
for (auto &aa_ability : aa_abilitys) {
if (aa_ability.id == aa_ability_id) {
return aa_ability;
}
}
return NewEntity();
}
static AaAbility FindOne(
int aa_ability_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
aa_ability_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
AaAbility entry{};
entry.id = atoi(row[0]);
entry.name = row[1];
entry.category = atoi(row[2]);
entry.classes = atoi(row[3]);
entry.races = atoi(row[4]);
entry.drakkin_heritage = atoi(row[5]);
entry.deities = atoi(row[6]);
entry.status = atoi(row[7]);
entry.type = atoi(row[8]);
entry.charges = atoi(row[9]);
entry.grant_only = atoi(row[10]);
entry.first_rank_id = atoi(row[11]);
entry.enabled = atoi(row[12]);
entry.reset_on_death = atoi(row[13]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int aa_ability_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
aa_ability_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
AaAbility aa_ability_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[1] + " = '" + EscapeString(aa_ability_entry.name) + "'");
update_values.push_back(columns[2] + " = " + std::to_string(aa_ability_entry.category));
update_values.push_back(columns[3] + " = " + std::to_string(aa_ability_entry.classes));
update_values.push_back(columns[4] + " = " + std::to_string(aa_ability_entry.races));
update_values.push_back(columns[5] + " = " + std::to_string(aa_ability_entry.drakkin_heritage));
update_values.push_back(columns[6] + " = " + std::to_string(aa_ability_entry.deities));
update_values.push_back(columns[7] + " = " + std::to_string(aa_ability_entry.status));
update_values.push_back(columns[8] + " = " + std::to_string(aa_ability_entry.type));
update_values.push_back(columns[9] + " = " + std::to_string(aa_ability_entry.charges));
update_values.push_back(columns[10] + " = " + std::to_string(aa_ability_entry.grant_only));
update_values.push_back(columns[11] + " = " + std::to_string(aa_ability_entry.first_rank_id));
update_values.push_back(columns[12] + " = " + std::to_string(aa_ability_entry.enabled));
update_values.push_back(columns[13] + " = " + std::to_string(aa_ability_entry.reset_on_death));
auto results = content_db.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
aa_ability_entry.id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static AaAbility InsertOne(
AaAbility aa_ability_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(aa_ability_entry.name) + "'");
insert_values.push_back(std::to_string(aa_ability_entry.category));
insert_values.push_back(std::to_string(aa_ability_entry.classes));
insert_values.push_back(std::to_string(aa_ability_entry.races));
insert_values.push_back(std::to_string(aa_ability_entry.drakkin_heritage));
insert_values.push_back(std::to_string(aa_ability_entry.deities));
insert_values.push_back(std::to_string(aa_ability_entry.status));
insert_values.push_back(std::to_string(aa_ability_entry.type));
insert_values.push_back(std::to_string(aa_ability_entry.charges));
insert_values.push_back(std::to_string(aa_ability_entry.grant_only));
insert_values.push_back(std::to_string(aa_ability_entry.first_rank_id));
insert_values.push_back(std::to_string(aa_ability_entry.enabled));
insert_values.push_back(std::to_string(aa_ability_entry.reset_on_death));
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
aa_ability_entry.id = results.LastInsertedID();
return aa_ability_entry;
}
aa_ability_entry = InstanceListRepository::NewEntity();
return aa_ability_entry;
}
static int InsertMany(
std::vector<AaAbility> aa_ability_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &aa_ability_entry: aa_ability_entries) {
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(aa_ability_entry.name) + "'");
insert_values.push_back(std::to_string(aa_ability_entry.category));
insert_values.push_back(std::to_string(aa_ability_entry.classes));
insert_values.push_back(std::to_string(aa_ability_entry.races));
insert_values.push_back(std::to_string(aa_ability_entry.drakkin_heritage));
insert_values.push_back(std::to_string(aa_ability_entry.deities));
insert_values.push_back(std::to_string(aa_ability_entry.status));
insert_values.push_back(std::to_string(aa_ability_entry.type));
insert_values.push_back(std::to_string(aa_ability_entry.charges));
insert_values.push_back(std::to_string(aa_ability_entry.grant_only));
insert_values.push_back(std::to_string(aa_ability_entry.first_rank_id));
insert_values.push_back(std::to_string(aa_ability_entry.enabled));
insert_values.push_back(std::to_string(aa_ability_entry.reset_on_death));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<AaAbility> All()
{
std::vector<AaAbility> all_entries;
auto results = content_db.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
AaAbility entry{};
entry.id = atoi(row[0]);
entry.name = row[1];
entry.category = atoi(row[2]);
entry.classes = atoi(row[3]);
entry.races = atoi(row[4]);
entry.drakkin_heritage = atoi(row[5]);
entry.deities = atoi(row[6]);
entry.status = atoi(row[7]);
entry.type = atoi(row[8]);
entry.charges = atoi(row[9]);
entry.grant_only = atoi(row[10]);
entry.first_rank_id = atoi(row[11]);
entry.enabled = atoi(row[12]);
entry.reset_on_death = atoi(row[13]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_AA_ABILITY_REPOSITORY_H

View File

@ -0,0 +1,279 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_AA_RANK_EFFECTS_REPOSITORY_H
#define EQEMU_AA_RANK_EFFECTS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class AaRankEffectsRepository {
public:
struct AaRankEffects {
int rank_id;
int slot;
int effect_id;
int base1;
int base2;
};
static std::string PrimaryKey()
{
return std::string("slot");
}
static std::vector<std::string> Columns()
{
return {
"rank_id",
"slot",
"effect_id",
"base1",
"base2",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("aa_rank_effects");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static AaRankEffects NewEntity()
{
AaRankEffects entry{};
entry.rank_id = 0;
entry.slot = 1;
entry.effect_id = 0;
entry.base1 = 0;
entry.base2 = 0;
return entry;
}
static AaRankEffects GetAaRankEffectsEntry(
const std::vector<AaRankEffects> &aa_rank_effectss,
int aa_rank_effects_id
)
{
for (auto &aa_rank_effects : aa_rank_effectss) {
if (aa_rank_effects.slot == aa_rank_effects_id) {
return aa_rank_effects;
}
}
return NewEntity();
}
static AaRankEffects FindOne(
int aa_rank_effects_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
aa_rank_effects_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
AaRankEffects entry{};
entry.rank_id = atoi(row[0]);
entry.slot = atoi(row[1]);
entry.effect_id = atoi(row[2]);
entry.base1 = atoi(row[3]);
entry.base2 = atoi(row[4]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int aa_rank_effects_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
aa_rank_effects_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
AaRankEffects aa_rank_effects_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[2] + " = " + std::to_string(aa_rank_effects_entry.effect_id));
update_values.push_back(columns[3] + " = " + std::to_string(aa_rank_effects_entry.base1));
update_values.push_back(columns[4] + " = " + std::to_string(aa_rank_effects_entry.base2));
auto results = content_db.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
aa_rank_effects_entry.slot
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static AaRankEffects InsertOne(
AaRankEffects aa_rank_effects_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(aa_rank_effects_entry.effect_id));
insert_values.push_back(std::to_string(aa_rank_effects_entry.base1));
insert_values.push_back(std::to_string(aa_rank_effects_entry.base2));
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
aa_rank_effects_entry.id = results.LastInsertedID();
return aa_rank_effects_entry;
}
aa_rank_effects_entry = InstanceListRepository::NewEntity();
return aa_rank_effects_entry;
}
static int InsertMany(
std::vector<AaRankEffects> aa_rank_effects_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &aa_rank_effects_entry: aa_rank_effects_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(aa_rank_effects_entry.effect_id));
insert_values.push_back(std::to_string(aa_rank_effects_entry.base1));
insert_values.push_back(std::to_string(aa_rank_effects_entry.base2));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<AaRankEffects> All()
{
std::vector<AaRankEffects> all_entries;
auto results = content_db.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
AaRankEffects entry{};
entry.rank_id = atoi(row[0]);
entry.slot = atoi(row[1]);
entry.effect_id = atoi(row[2]);
entry.base1 = atoi(row[3]);
entry.base2 = atoi(row[4]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_AA_RANK_EFFECTS_REPOSITORY_H

View File

@ -0,0 +1,263 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_AA_RANK_PREREQS_REPOSITORY_H
#define EQEMU_AA_RANK_PREREQS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class AaRankPrereqsRepository {
public:
struct AaRankPrereqs {
int rank_id;
int aa_id;
int points;
};
static std::string PrimaryKey()
{
return std::string("aa_id");
}
static std::vector<std::string> Columns()
{
return {
"rank_id",
"aa_id",
"points",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("aa_rank_prereqs");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static AaRankPrereqs NewEntity()
{
AaRankPrereqs entry{};
entry.rank_id = 0;
entry.aa_id = 0;
entry.points = 0;
return entry;
}
static AaRankPrereqs GetAaRankPrereqsEntry(
const std::vector<AaRankPrereqs> &aa_rank_prereqss,
int aa_rank_prereqs_id
)
{
for (auto &aa_rank_prereqs : aa_rank_prereqss) {
if (aa_rank_prereqs.aa_id == aa_rank_prereqs_id) {
return aa_rank_prereqs;
}
}
return NewEntity();
}
static AaRankPrereqs FindOne(
int aa_rank_prereqs_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
aa_rank_prereqs_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
AaRankPrereqs entry{};
entry.rank_id = atoi(row[0]);
entry.aa_id = atoi(row[1]);
entry.points = atoi(row[2]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int aa_rank_prereqs_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
aa_rank_prereqs_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
AaRankPrereqs aa_rank_prereqs_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[2] + " = " + std::to_string(aa_rank_prereqs_entry.points));
auto results = content_db.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
aa_rank_prereqs_entry.aa_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static AaRankPrereqs InsertOne(
AaRankPrereqs aa_rank_prereqs_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(aa_rank_prereqs_entry.points));
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
aa_rank_prereqs_entry.id = results.LastInsertedID();
return aa_rank_prereqs_entry;
}
aa_rank_prereqs_entry = InstanceListRepository::NewEntity();
return aa_rank_prereqs_entry;
}
static int InsertMany(
std::vector<AaRankPrereqs> aa_rank_prereqs_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &aa_rank_prereqs_entry: aa_rank_prereqs_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(aa_rank_prereqs_entry.points));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<AaRankPrereqs> All()
{
std::vector<AaRankPrereqs> all_entries;
auto results = content_db.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
AaRankPrereqs entry{};
entry.rank_id = atoi(row[0]);
entry.aa_id = atoi(row[1]);
entry.points = atoi(row[2]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_AA_RANK_PREREQS_REPOSITORY_H

View File

@ -0,0 +1,346 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_AA_RANKS_REPOSITORY_H
#define EQEMU_AA_RANKS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class AaRanksRepository {
public:
struct AaRanks {
int id;
int upper_hotkey_sid;
int lower_hotkey_sid;
int title_sid;
int desc_sid;
int cost;
int level_req;
int spell;
int spell_type;
int recast_time;
int expansion;
int prev_id;
int next_id;
};
static std::string PrimaryKey()
{
return std::string("id");
}
static std::vector<std::string> Columns()
{
return {
"id",
"upper_hotkey_sid",
"lower_hotkey_sid",
"title_sid",
"desc_sid",
"cost",
"level_req",
"spell",
"spell_type",
"recast_time",
"expansion",
"prev_id",
"next_id",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("aa_ranks");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static AaRanks NewEntity()
{
AaRanks entry{};
entry.id = 0;
entry.upper_hotkey_sid = -1;
entry.lower_hotkey_sid = -1;
entry.title_sid = -1;
entry.desc_sid = -1;
entry.cost = 1;
entry.level_req = 51;
entry.spell = -1;
entry.spell_type = 0;
entry.recast_time = 0;
entry.expansion = 0;
entry.prev_id = -1;
entry.next_id = -1;
return entry;
}
static AaRanks GetAaRanksEntry(
const std::vector<AaRanks> &aa_rankss,
int aa_ranks_id
)
{
for (auto &aa_ranks : aa_rankss) {
if (aa_ranks.id == aa_ranks_id) {
return aa_ranks;
}
}
return NewEntity();
}
static AaRanks FindOne(
int aa_ranks_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
aa_ranks_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
AaRanks entry{};
entry.id = atoi(row[0]);
entry.upper_hotkey_sid = atoi(row[1]);
entry.lower_hotkey_sid = atoi(row[2]);
entry.title_sid = atoi(row[3]);
entry.desc_sid = atoi(row[4]);
entry.cost = atoi(row[5]);
entry.level_req = atoi(row[6]);
entry.spell = atoi(row[7]);
entry.spell_type = atoi(row[8]);
entry.recast_time = atoi(row[9]);
entry.expansion = atoi(row[10]);
entry.prev_id = atoi(row[11]);
entry.next_id = atoi(row[12]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int aa_ranks_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
aa_ranks_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
AaRanks aa_ranks_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[1] + " = " + std::to_string(aa_ranks_entry.upper_hotkey_sid));
update_values.push_back(columns[2] + " = " + std::to_string(aa_ranks_entry.lower_hotkey_sid));
update_values.push_back(columns[3] + " = " + std::to_string(aa_ranks_entry.title_sid));
update_values.push_back(columns[4] + " = " + std::to_string(aa_ranks_entry.desc_sid));
update_values.push_back(columns[5] + " = " + std::to_string(aa_ranks_entry.cost));
update_values.push_back(columns[6] + " = " + std::to_string(aa_ranks_entry.level_req));
update_values.push_back(columns[7] + " = " + std::to_string(aa_ranks_entry.spell));
update_values.push_back(columns[8] + " = " + std::to_string(aa_ranks_entry.spell_type));
update_values.push_back(columns[9] + " = " + std::to_string(aa_ranks_entry.recast_time));
update_values.push_back(columns[10] + " = " + std::to_string(aa_ranks_entry.expansion));
update_values.push_back(columns[11] + " = " + std::to_string(aa_ranks_entry.prev_id));
update_values.push_back(columns[12] + " = " + std::to_string(aa_ranks_entry.next_id));
auto results = content_db.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
aa_ranks_entry.id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static AaRanks InsertOne(
AaRanks aa_ranks_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(aa_ranks_entry.upper_hotkey_sid));
insert_values.push_back(std::to_string(aa_ranks_entry.lower_hotkey_sid));
insert_values.push_back(std::to_string(aa_ranks_entry.title_sid));
insert_values.push_back(std::to_string(aa_ranks_entry.desc_sid));
insert_values.push_back(std::to_string(aa_ranks_entry.cost));
insert_values.push_back(std::to_string(aa_ranks_entry.level_req));
insert_values.push_back(std::to_string(aa_ranks_entry.spell));
insert_values.push_back(std::to_string(aa_ranks_entry.spell_type));
insert_values.push_back(std::to_string(aa_ranks_entry.recast_time));
insert_values.push_back(std::to_string(aa_ranks_entry.expansion));
insert_values.push_back(std::to_string(aa_ranks_entry.prev_id));
insert_values.push_back(std::to_string(aa_ranks_entry.next_id));
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
aa_ranks_entry.id = results.LastInsertedID();
return aa_ranks_entry;
}
aa_ranks_entry = InstanceListRepository::NewEntity();
return aa_ranks_entry;
}
static int InsertMany(
std::vector<AaRanks> aa_ranks_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &aa_ranks_entry: aa_ranks_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(aa_ranks_entry.upper_hotkey_sid));
insert_values.push_back(std::to_string(aa_ranks_entry.lower_hotkey_sid));
insert_values.push_back(std::to_string(aa_ranks_entry.title_sid));
insert_values.push_back(std::to_string(aa_ranks_entry.desc_sid));
insert_values.push_back(std::to_string(aa_ranks_entry.cost));
insert_values.push_back(std::to_string(aa_ranks_entry.level_req));
insert_values.push_back(std::to_string(aa_ranks_entry.spell));
insert_values.push_back(std::to_string(aa_ranks_entry.spell_type));
insert_values.push_back(std::to_string(aa_ranks_entry.recast_time));
insert_values.push_back(std::to_string(aa_ranks_entry.expansion));
insert_values.push_back(std::to_string(aa_ranks_entry.prev_id));
insert_values.push_back(std::to_string(aa_ranks_entry.next_id));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<AaRanks> All()
{
std::vector<AaRanks> all_entries;
auto results = content_db.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
AaRanks entry{};
entry.id = atoi(row[0]);
entry.upper_hotkey_sid = atoi(row[1]);
entry.lower_hotkey_sid = atoi(row[2]);
entry.title_sid = atoi(row[3]);
entry.desc_sid = atoi(row[4]);
entry.cost = atoi(row[5]);
entry.level_req = atoi(row[6]);
entry.spell = atoi(row[7]);
entry.spell_type = atoi(row[8]);
entry.recast_time = atoi(row[9]);
entry.expansion = atoi(row[10]);
entry.prev_id = atoi(row[11]);
entry.next_id = atoi(row[12]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_AA_RANKS_REPOSITORY_H

View File

@ -0,0 +1,263 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_ACCOUNT_FLAGS_REPOSITORY_H
#define EQEMU_ACCOUNT_FLAGS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class AccountFlagsRepository {
public:
struct AccountFlags {
int p_accid;
std::string p_flag;
std::string p_value;
};
static std::string PrimaryKey()
{
return std::string("p_flag");
}
static std::vector<std::string> Columns()
{
return {
"p_accid",
"p_flag",
"p_value",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("account_flags");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static AccountFlags NewEntity()
{
AccountFlags entry{};
entry.p_accid = 0;
entry.p_flag = 0;
entry.p_value = 0;
return entry;
}
static AccountFlags GetAccountFlagsEntry(
const std::vector<AccountFlags> &account_flagss,
int account_flags_id
)
{
for (auto &account_flags : account_flagss) {
if (account_flags.p_flag == account_flags_id) {
return account_flags;
}
}
return NewEntity();
}
static AccountFlags FindOne(
int account_flags_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
account_flags_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
AccountFlags entry{};
entry.p_accid = atoi(row[0]);
entry.p_flag = row[1];
entry.p_value = row[2];
return entry;
}
return NewEntity();
}
static int DeleteOne(
int account_flags_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
account_flags_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
AccountFlags account_flags_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[2] + " = '" + EscapeString(account_flags_entry.p_value) + "'");
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
account_flags_entry.p_flag
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static AccountFlags InsertOne(
AccountFlags account_flags_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(account_flags_entry.p_value) + "'");
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
account_flags_entry.id = results.LastInsertedID();
return account_flags_entry;
}
account_flags_entry = InstanceListRepository::NewEntity();
return account_flags_entry;
}
static int InsertMany(
std::vector<AccountFlags> account_flags_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &account_flags_entry: account_flags_entries) {
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(account_flags_entry.p_value) + "'");
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<AccountFlags> All()
{
std::vector<AccountFlags> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
AccountFlags entry{};
entry.p_accid = atoi(row[0]);
entry.p_flag = row[1];
entry.p_value = row[2];
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_ACCOUNT_FLAGS_REPOSITORY_H

View File

@ -0,0 +1,271 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_ACCOUNT_IP_REPOSITORY_H
#define EQEMU_ACCOUNT_IP_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class AccountIpRepository {
public:
struct AccountIp {
int accid;
std::string ip;
int count;
std::string lastused;
};
static std::string PrimaryKey()
{
return std::string("ip");
}
static std::vector<std::string> Columns()
{
return {
"accid",
"ip",
"count",
"lastused",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("account_ip");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static AccountIp NewEntity()
{
AccountIp entry{};
entry.accid = 0;
entry.ip = "";
entry.count = 1;
entry.lastused = current_timestamp();
return entry;
}
static AccountIp GetAccountIpEntry(
const std::vector<AccountIp> &account_ips,
int account_ip_id
)
{
for (auto &account_ip : account_ips) {
if (account_ip.ip == account_ip_id) {
return account_ip;
}
}
return NewEntity();
}
static AccountIp FindOne(
int account_ip_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
account_ip_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
AccountIp entry{};
entry.accid = atoi(row[0]);
entry.ip = row[1];
entry.count = atoi(row[2]);
entry.lastused = row[3];
return entry;
}
return NewEntity();
}
static int DeleteOne(
int account_ip_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
account_ip_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
AccountIp account_ip_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[2] + " = " + std::to_string(account_ip_entry.count));
update_values.push_back(columns[3] + " = '" + EscapeString(account_ip_entry.lastused) + "'");
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
account_ip_entry.ip
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static AccountIp InsertOne(
AccountIp account_ip_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(account_ip_entry.count));
insert_values.push_back("'" + EscapeString(account_ip_entry.lastused) + "'");
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
account_ip_entry.id = results.LastInsertedID();
return account_ip_entry;
}
account_ip_entry = InstanceListRepository::NewEntity();
return account_ip_entry;
}
static int InsertMany(
std::vector<AccountIp> account_ip_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &account_ip_entry: account_ip_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(account_ip_entry.count));
insert_values.push_back("'" + EscapeString(account_ip_entry.lastused) + "'");
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<AccountIp> All()
{
std::vector<AccountIp> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
AccountIp entry{};
entry.accid = atoi(row[0]);
entry.ip = row[1];
entry.count = atoi(row[2]);
entry.lastused = row[3];
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_ACCOUNT_IP_REPOSITORY_H

View File

@ -0,0 +1,263 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_ACCOUNT_REWARDS_REPOSITORY_H
#define EQEMU_ACCOUNT_REWARDS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class AccountRewardsRepository {
public:
struct AccountRewards {
int account_id;
int reward_id;
int amount;
};
static std::string PrimaryKey()
{
return std::string("reward_id");
}
static std::vector<std::string> Columns()
{
return {
"account_id",
"reward_id",
"amount",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("account_rewards");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static AccountRewards NewEntity()
{
AccountRewards entry{};
entry.account_id = 0;
entry.reward_id = 0;
entry.amount = 0;
return entry;
}
static AccountRewards GetAccountRewardsEntry(
const std::vector<AccountRewards> &account_rewardss,
int account_rewards_id
)
{
for (auto &account_rewards : account_rewardss) {
if (account_rewards.reward_id == account_rewards_id) {
return account_rewards;
}
}
return NewEntity();
}
static AccountRewards FindOne(
int account_rewards_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
account_rewards_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
AccountRewards entry{};
entry.account_id = atoi(row[0]);
entry.reward_id = atoi(row[1]);
entry.amount = atoi(row[2]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int account_rewards_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
account_rewards_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
AccountRewards account_rewards_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[2] + " = " + std::to_string(account_rewards_entry.amount));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
account_rewards_entry.reward_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static AccountRewards InsertOne(
AccountRewards account_rewards_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(account_rewards_entry.amount));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
account_rewards_entry.id = results.LastInsertedID();
return account_rewards_entry;
}
account_rewards_entry = InstanceListRepository::NewEntity();
return account_rewards_entry;
}
static int InsertMany(
std::vector<AccountRewards> account_rewards_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &account_rewards_entry: account_rewards_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(account_rewards_entry.amount));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<AccountRewards> All()
{
std::vector<AccountRewards> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
AccountRewards entry{};
entry.account_id = atoi(row[0]);
entry.reward_id = atoi(row[1]);
entry.amount = atoi(row[2]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_ACCOUNT_REWARDS_REPOSITORY_H

View File

@ -0,0 +1,314 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_ADVENTURE_DETAILS_REPOSITORY_H
#define EQEMU_ADVENTURE_DETAILS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class AdventureDetailsRepository {
public:
struct AdventureDetails {
int id;
int16 adventure_id;
int instance_id;
int16 count;
int16 assassinate_count;
int8 status;
int time_created;
int time_zoned;
int time_completed;
};
static std::string PrimaryKey()
{
return std::string("id");
}
static std::vector<std::string> Columns()
{
return {
"id",
"adventure_id",
"instance_id",
"count",
"assassinate_count",
"status",
"time_created",
"time_zoned",
"time_completed",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("adventure_details");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static AdventureDetails NewEntity()
{
AdventureDetails entry{};
entry.id = 0;
entry.adventure_id = 0;
entry.instance_id = -1;
entry.count = 0;
entry.assassinate_count = 0;
entry.status = 0;
entry.time_created = 0;
entry.time_zoned = 0;
entry.time_completed = 0;
return entry;
}
static AdventureDetails GetAdventureDetailsEntry(
const std::vector<AdventureDetails> &adventure_detailss,
int adventure_details_id
)
{
for (auto &adventure_details : adventure_detailss) {
if (adventure_details.id == adventure_details_id) {
return adventure_details;
}
}
return NewEntity();
}
static AdventureDetails FindOne(
int adventure_details_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
adventure_details_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
AdventureDetails entry{};
entry.id = atoi(row[0]);
entry.adventure_id = atoi(row[1]);
entry.instance_id = atoi(row[2]);
entry.count = atoi(row[3]);
entry.assassinate_count = atoi(row[4]);
entry.status = atoi(row[5]);
entry.time_created = atoi(row[6]);
entry.time_zoned = atoi(row[7]);
entry.time_completed = atoi(row[8]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int adventure_details_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
adventure_details_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
AdventureDetails adventure_details_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[1] + " = " + std::to_string(adventure_details_entry.adventure_id));
update_values.push_back(columns[2] + " = " + std::to_string(adventure_details_entry.instance_id));
update_values.push_back(columns[3] + " = " + std::to_string(adventure_details_entry.count));
update_values.push_back(columns[4] + " = " + std::to_string(adventure_details_entry.assassinate_count));
update_values.push_back(columns[5] + " = " + std::to_string(adventure_details_entry.status));
update_values.push_back(columns[6] + " = " + std::to_string(adventure_details_entry.time_created));
update_values.push_back(columns[7] + " = " + std::to_string(adventure_details_entry.time_zoned));
update_values.push_back(columns[8] + " = " + std::to_string(adventure_details_entry.time_completed));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
adventure_details_entry.id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static AdventureDetails InsertOne(
AdventureDetails adventure_details_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(adventure_details_entry.adventure_id));
insert_values.push_back(std::to_string(adventure_details_entry.instance_id));
insert_values.push_back(std::to_string(adventure_details_entry.count));
insert_values.push_back(std::to_string(adventure_details_entry.assassinate_count));
insert_values.push_back(std::to_string(adventure_details_entry.status));
insert_values.push_back(std::to_string(adventure_details_entry.time_created));
insert_values.push_back(std::to_string(adventure_details_entry.time_zoned));
insert_values.push_back(std::to_string(adventure_details_entry.time_completed));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
adventure_details_entry.id = results.LastInsertedID();
return adventure_details_entry;
}
adventure_details_entry = InstanceListRepository::NewEntity();
return adventure_details_entry;
}
static int InsertMany(
std::vector<AdventureDetails> adventure_details_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &adventure_details_entry: adventure_details_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(adventure_details_entry.adventure_id));
insert_values.push_back(std::to_string(adventure_details_entry.instance_id));
insert_values.push_back(std::to_string(adventure_details_entry.count));
insert_values.push_back(std::to_string(adventure_details_entry.assassinate_count));
insert_values.push_back(std::to_string(adventure_details_entry.status));
insert_values.push_back(std::to_string(adventure_details_entry.time_created));
insert_values.push_back(std::to_string(adventure_details_entry.time_zoned));
insert_values.push_back(std::to_string(adventure_details_entry.time_completed));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<AdventureDetails> All()
{
std::vector<AdventureDetails> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
AdventureDetails entry{};
entry.id = atoi(row[0]);
entry.adventure_id = atoi(row[1]);
entry.instance_id = atoi(row[2]);
entry.count = atoi(row[3]);
entry.assassinate_count = atoi(row[4]);
entry.status = atoi(row[5]);
entry.time_created = atoi(row[6]);
entry.time_zoned = atoi(row[7]);
entry.time_completed = atoi(row[8]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_ADVENTURE_DETAILS_REPOSITORY_H

View File

@ -0,0 +1,258 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_ADVENTURE_MEMBERS_REPOSITORY_H
#define EQEMU_ADVENTURE_MEMBERS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class AdventureMembersRepository {
public:
struct AdventureMembers {
int id;
int charid;
};
static std::string PrimaryKey()
{
return std::string("charid");
}
static std::vector<std::string> Columns()
{
return {
"id",
"charid",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("adventure_members");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static AdventureMembers NewEntity()
{
AdventureMembers entry{};
entry.id = 0;
entry.charid = 0;
return entry;
}
static AdventureMembers GetAdventureMembersEntry(
const std::vector<AdventureMembers> &adventure_memberss,
int adventure_members_id
)
{
for (auto &adventure_members : adventure_memberss) {
if (adventure_members.charid == adventure_members_id) {
return adventure_members;
}
}
return NewEntity();
}
static AdventureMembers FindOne(
int adventure_members_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
adventure_members_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
AdventureMembers entry{};
entry.id = atoi(row[0]);
entry.charid = atoi(row[1]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int adventure_members_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
adventure_members_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
AdventureMembers adventure_members_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[0] + " = " + std::to_string(adventure_members_entry.id));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
adventure_members_entry.charid
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static AdventureMembers InsertOne(
AdventureMembers adventure_members_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(adventure_members_entry.id));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
adventure_members_entry.id = results.LastInsertedID();
return adventure_members_entry;
}
adventure_members_entry = InstanceListRepository::NewEntity();
return adventure_members_entry;
}
static int InsertMany(
std::vector<AdventureMembers> adventure_members_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &adventure_members_entry: adventure_members_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(adventure_members_entry.id));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<AdventureMembers> All()
{
std::vector<AdventureMembers> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
AdventureMembers entry{};
entry.id = atoi(row[0]);
entry.charid = atoi(row[1]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_ADVENTURE_MEMBERS_REPOSITORY_H

View File

@ -0,0 +1,330 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_ADVENTURE_STATS_REPOSITORY_H
#define EQEMU_ADVENTURE_STATS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class AdventureStatsRepository {
public:
struct AdventureStats {
int player_id;
int guk_wins;
int mir_wins;
int mmc_wins;
int ruj_wins;
int tak_wins;
int guk_losses;
int mir_losses;
int mmc_losses;
int ruj_losses;
int tak_losses;
};
static std::string PrimaryKey()
{
return std::string("player_id");
}
static std::vector<std::string> Columns()
{
return {
"player_id",
"guk_wins",
"mir_wins",
"mmc_wins",
"ruj_wins",
"tak_wins",
"guk_losses",
"mir_losses",
"mmc_losses",
"ruj_losses",
"tak_losses",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("adventure_stats");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static AdventureStats NewEntity()
{
AdventureStats entry{};
entry.player_id = 0;
entry.guk_wins = 0;
entry.mir_wins = 0;
entry.mmc_wins = 0;
entry.ruj_wins = 0;
entry.tak_wins = 0;
entry.guk_losses = 0;
entry.mir_losses = 0;
entry.mmc_losses = 0;
entry.ruj_losses = 0;
entry.tak_losses = 0;
return entry;
}
static AdventureStats GetAdventureStatsEntry(
const std::vector<AdventureStats> &adventure_statss,
int adventure_stats_id
)
{
for (auto &adventure_stats : adventure_statss) {
if (adventure_stats.player_id == adventure_stats_id) {
return adventure_stats;
}
}
return NewEntity();
}
static AdventureStats FindOne(
int adventure_stats_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
adventure_stats_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
AdventureStats entry{};
entry.player_id = atoi(row[0]);
entry.guk_wins = atoi(row[1]);
entry.mir_wins = atoi(row[2]);
entry.mmc_wins = atoi(row[3]);
entry.ruj_wins = atoi(row[4]);
entry.tak_wins = atoi(row[5]);
entry.guk_losses = atoi(row[6]);
entry.mir_losses = atoi(row[7]);
entry.mmc_losses = atoi(row[8]);
entry.ruj_losses = atoi(row[9]);
entry.tak_losses = atoi(row[10]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int adventure_stats_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
adventure_stats_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
AdventureStats adventure_stats_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[1] + " = " + std::to_string(adventure_stats_entry.guk_wins));
update_values.push_back(columns[2] + " = " + std::to_string(adventure_stats_entry.mir_wins));
update_values.push_back(columns[3] + " = " + std::to_string(adventure_stats_entry.mmc_wins));
update_values.push_back(columns[4] + " = " + std::to_string(adventure_stats_entry.ruj_wins));
update_values.push_back(columns[5] + " = " + std::to_string(adventure_stats_entry.tak_wins));
update_values.push_back(columns[6] + " = " + std::to_string(adventure_stats_entry.guk_losses));
update_values.push_back(columns[7] + " = " + std::to_string(adventure_stats_entry.mir_losses));
update_values.push_back(columns[8] + " = " + std::to_string(adventure_stats_entry.mmc_losses));
update_values.push_back(columns[9] + " = " + std::to_string(adventure_stats_entry.ruj_losses));
update_values.push_back(columns[10] + " = " + std::to_string(adventure_stats_entry.tak_losses));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
adventure_stats_entry.player_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static AdventureStats InsertOne(
AdventureStats adventure_stats_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(adventure_stats_entry.guk_wins));
insert_values.push_back(std::to_string(adventure_stats_entry.mir_wins));
insert_values.push_back(std::to_string(adventure_stats_entry.mmc_wins));
insert_values.push_back(std::to_string(adventure_stats_entry.ruj_wins));
insert_values.push_back(std::to_string(adventure_stats_entry.tak_wins));
insert_values.push_back(std::to_string(adventure_stats_entry.guk_losses));
insert_values.push_back(std::to_string(adventure_stats_entry.mir_losses));
insert_values.push_back(std::to_string(adventure_stats_entry.mmc_losses));
insert_values.push_back(std::to_string(adventure_stats_entry.ruj_losses));
insert_values.push_back(std::to_string(adventure_stats_entry.tak_losses));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
adventure_stats_entry.id = results.LastInsertedID();
return adventure_stats_entry;
}
adventure_stats_entry = InstanceListRepository::NewEntity();
return adventure_stats_entry;
}
static int InsertMany(
std::vector<AdventureStats> adventure_stats_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &adventure_stats_entry: adventure_stats_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(adventure_stats_entry.guk_wins));
insert_values.push_back(std::to_string(adventure_stats_entry.mir_wins));
insert_values.push_back(std::to_string(adventure_stats_entry.mmc_wins));
insert_values.push_back(std::to_string(adventure_stats_entry.ruj_wins));
insert_values.push_back(std::to_string(adventure_stats_entry.tak_wins));
insert_values.push_back(std::to_string(adventure_stats_entry.guk_losses));
insert_values.push_back(std::to_string(adventure_stats_entry.mir_losses));
insert_values.push_back(std::to_string(adventure_stats_entry.mmc_losses));
insert_values.push_back(std::to_string(adventure_stats_entry.ruj_losses));
insert_values.push_back(std::to_string(adventure_stats_entry.tak_losses));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<AdventureStats> All()
{
std::vector<AdventureStats> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
AdventureStats entry{};
entry.player_id = atoi(row[0]);
entry.guk_wins = atoi(row[1]);
entry.mir_wins = atoi(row[2]);
entry.mmc_wins = atoi(row[3]);
entry.ruj_wins = atoi(row[4]);
entry.tak_wins = atoi(row[5]);
entry.guk_losses = atoi(row[6]);
entry.mir_losses = atoi(row[7]);
entry.mmc_losses = atoi(row[8]);
entry.ruj_losses = atoi(row[9]);
entry.tak_losses = atoi(row[10]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_ADVENTURE_STATS_REPOSITORY_H

View File

@ -0,0 +1,258 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_ADVENTURE_TEMPLATE_ENTRY_FLAVOR_REPOSITORY_H
#define EQEMU_ADVENTURE_TEMPLATE_ENTRY_FLAVOR_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class AdventureTemplateEntryFlavorRepository {
public:
struct AdventureTemplateEntryFlavor {
int id;
std::string text;
};
static std::string PrimaryKey()
{
return std::string("id");
}
static std::vector<std::string> Columns()
{
return {
"id",
"text",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("adventure_template_entry_flavor");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static AdventureTemplateEntryFlavor NewEntity()
{
AdventureTemplateEntryFlavor entry{};
entry.id = 0;
entry.text = 0;
return entry;
}
static AdventureTemplateEntryFlavor GetAdventureTemplateEntryFlavorEntry(
const std::vector<AdventureTemplateEntryFlavor> &adventure_template_entry_flavors,
int adventure_template_entry_flavor_id
)
{
for (auto &adventure_template_entry_flavor : adventure_template_entry_flavors) {
if (adventure_template_entry_flavor.id == adventure_template_entry_flavor_id) {
return adventure_template_entry_flavor;
}
}
return NewEntity();
}
static AdventureTemplateEntryFlavor FindOne(
int adventure_template_entry_flavor_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
adventure_template_entry_flavor_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
AdventureTemplateEntryFlavor entry{};
entry.id = atoi(row[0]);
entry.text = row[1];
return entry;
}
return NewEntity();
}
static int DeleteOne(
int adventure_template_entry_flavor_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
adventure_template_entry_flavor_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
AdventureTemplateEntryFlavor adventure_template_entry_flavor_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[1] + " = '" + EscapeString(adventure_template_entry_flavor_entry.text) + "'");
auto results = content_db.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
adventure_template_entry_flavor_entry.id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static AdventureTemplateEntryFlavor InsertOne(
AdventureTemplateEntryFlavor adventure_template_entry_flavor_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(adventure_template_entry_flavor_entry.text) + "'");
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
adventure_template_entry_flavor_entry.id = results.LastInsertedID();
return adventure_template_entry_flavor_entry;
}
adventure_template_entry_flavor_entry = InstanceListRepository::NewEntity();
return adventure_template_entry_flavor_entry;
}
static int InsertMany(
std::vector<AdventureTemplateEntryFlavor> adventure_template_entry_flavor_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &adventure_template_entry_flavor_entry: adventure_template_entry_flavor_entries) {
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(adventure_template_entry_flavor_entry.text) + "'");
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<AdventureTemplateEntryFlavor> All()
{
std::vector<AdventureTemplateEntryFlavor> all_entries;
auto results = content_db.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
AdventureTemplateEntryFlavor entry{};
entry.id = atoi(row[0]);
entry.text = row[1];
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_ADVENTURE_TEMPLATE_ENTRY_FLAVOR_REPOSITORY_H

View File

@ -0,0 +1,258 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_ADVENTURE_TEMPLATE_ENTRY_REPOSITORY_H
#define EQEMU_ADVENTURE_TEMPLATE_ENTRY_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class AdventureTemplateEntryRepository {
public:
struct AdventureTemplateEntry {
int id;
int template_id;
};
static std::string PrimaryKey()
{
return std::string("template_id");
}
static std::vector<std::string> Columns()
{
return {
"id",
"template_id",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("adventure_template_entry");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static AdventureTemplateEntry NewEntity()
{
AdventureTemplateEntry entry{};
entry.id = 0;
entry.template_id = 0;
return entry;
}
static AdventureTemplateEntry GetAdventureTemplateEntryEntry(
const std::vector<AdventureTemplateEntry> &adventure_template_entrys,
int adventure_template_entry_id
)
{
for (auto &adventure_template_entry : adventure_template_entrys) {
if (adventure_template_entry.template_id == adventure_template_entry_id) {
return adventure_template_entry;
}
}
return NewEntity();
}
static AdventureTemplateEntry FindOne(
int adventure_template_entry_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
adventure_template_entry_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
AdventureTemplateEntry entry{};
entry.id = atoi(row[0]);
entry.template_id = atoi(row[1]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int adventure_template_entry_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
adventure_template_entry_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
AdventureTemplateEntry adventure_template_entry_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
auto results = content_db.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
adventure_template_entry_entry.template_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static AdventureTemplateEntry InsertOne(
AdventureTemplateEntry adventure_template_entry_entry
)
{
std::vector<std::string> insert_values;
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
adventure_template_entry_entry.id = results.LastInsertedID();
return adventure_template_entry_entry;
}
adventure_template_entry_entry = InstanceListRepository::NewEntity();
return adventure_template_entry_entry;
}
static int InsertMany(
std::vector<AdventureTemplateEntry> adventure_template_entry_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &adventure_template_entry_entry: adventure_template_entry_entries) {
std::vector<std::string> insert_values;
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<AdventureTemplateEntry> All()
{
std::vector<AdventureTemplateEntry> all_entries;
auto results = content_db.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
AdventureTemplateEntry entry{};
entry.id = atoi(row[0]);
entry.template_id = atoi(row[1]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_ADVENTURE_TEMPLATE_ENTRY_REPOSITORY_H

View File

@ -0,0 +1,506 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_ADVENTURE_TEMPLATE_REPOSITORY_H
#define EQEMU_ADVENTURE_TEMPLATE_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class AdventureTemplateRepository {
public:
struct AdventureTemplate {
int id;
std::string zone;
int8 zone_version;
int8 is_hard;
int8 is_raid;
int8 min_level;
int8 max_level;
int8 type;
int type_data;
int16 type_count;
std::string assa_x;
std::string assa_y;
std::string assa_z;
std::string assa_h;
std::string text;
int duration;
int zone_in_time;
int16 win_points;
int16 lose_points;
int8 theme;
int16 zone_in_zone_id;
std::string zone_in_x;
std::string zone_in_y;
int16 zone_in_object_id;
std::string dest_x;
std::string dest_y;
std::string dest_z;
std::string dest_h;
int graveyard_zone_id;
std::string graveyard_x;
std::string graveyard_y;
std::string graveyard_z;
std::string graveyard_radius;
};
static std::string PrimaryKey()
{
return std::string("id");
}
static std::vector<std::string> Columns()
{
return {
"id",
"zone",
"zone_version",
"is_hard",
"is_raid",
"min_level",
"max_level",
"type",
"type_data",
"type_count",
"assa_x",
"assa_y",
"assa_z",
"assa_h",
"text",
"duration",
"zone_in_time",
"win_points",
"lose_points",
"theme",
"zone_in_zone_id",
"zone_in_x",
"zone_in_y",
"zone_in_object_id",
"dest_x",
"dest_y",
"dest_z",
"dest_h",
"graveyard_zone_id",
"graveyard_x",
"graveyard_y",
"graveyard_z",
"graveyard_radius",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("adventure_template");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static AdventureTemplate NewEntity()
{
AdventureTemplate entry{};
entry.id = 0;
entry.zone = 0;
entry.zone_version = 0;
entry.is_hard = 0;
entry.is_raid = 0;
entry.min_level = 1;
entry.max_level = 65;
entry.type = 0;
entry.type_data = 0;
entry.type_count = 0;
entry.assa_x = 0;
entry.assa_y = 0;
entry.assa_z = 0;
entry.assa_h = 0;
entry.text = 0;
entry.duration = 7200;
entry.zone_in_time = 1800;
entry.win_points = 0;
entry.lose_points = 0;
entry.theme = 1;
entry.zone_in_zone_id = 0;
entry.zone_in_x = 0;
entry.zone_in_y = 0;
entry.zone_in_object_id = 0;
entry.dest_x = 0;
entry.dest_y = 0;
entry.dest_z = 0;
entry.dest_h = 0;
entry.graveyard_zone_id = 0;
entry.graveyard_x = 0;
entry.graveyard_y = 0;
entry.graveyard_z = 0;
entry.graveyard_radius = 0;
return entry;
}
static AdventureTemplate GetAdventureTemplateEntry(
const std::vector<AdventureTemplate> &adventure_templates,
int adventure_template_id
)
{
for (auto &adventure_template : adventure_templates) {
if (adventure_template.id == adventure_template_id) {
return adventure_template;
}
}
return NewEntity();
}
static AdventureTemplate FindOne(
int adventure_template_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
adventure_template_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
AdventureTemplate entry{};
entry.id = atoi(row[0]);
entry.zone = row[1];
entry.zone_version = atoi(row[2]);
entry.is_hard = atoi(row[3]);
entry.is_raid = atoi(row[4]);
entry.min_level = atoi(row[5]);
entry.max_level = atoi(row[6]);
entry.type = atoi(row[7]);
entry.type_data = atoi(row[8]);
entry.type_count = atoi(row[9]);
entry.assa_x = atof(row[10]);
entry.assa_y = atof(row[11]);
entry.assa_z = atof(row[12]);
entry.assa_h = atof(row[13]);
entry.text = row[14];
entry.duration = atoi(row[15]);
entry.zone_in_time = atoi(row[16]);
entry.win_points = atoi(row[17]);
entry.lose_points = atoi(row[18]);
entry.theme = atoi(row[19]);
entry.zone_in_zone_id = atoi(row[20]);
entry.zone_in_x = atof(row[21]);
entry.zone_in_y = atof(row[22]);
entry.zone_in_object_id = atoi(row[23]);
entry.dest_x = atof(row[24]);
entry.dest_y = atof(row[25]);
entry.dest_z = atof(row[26]);
entry.dest_h = atof(row[27]);
entry.graveyard_zone_id = atoi(row[28]);
entry.graveyard_x = atof(row[29]);
entry.graveyard_y = atof(row[30]);
entry.graveyard_z = atof(row[31]);
entry.graveyard_radius = atof(row[32]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int adventure_template_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
adventure_template_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
AdventureTemplate adventure_template_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[1] + " = '" + EscapeString(adventure_template_entry.zone) + "'");
update_values.push_back(columns[2] + " = " + std::to_string(adventure_template_entry.zone_version));
update_values.push_back(columns[3] + " = " + std::to_string(adventure_template_entry.is_hard));
update_values.push_back(columns[4] + " = " + std::to_string(adventure_template_entry.is_raid));
update_values.push_back(columns[5] + " = " + std::to_string(adventure_template_entry.min_level));
update_values.push_back(columns[6] + " = " + std::to_string(adventure_template_entry.max_level));
update_values.push_back(columns[7] + " = " + std::to_string(adventure_template_entry.type));
update_values.push_back(columns[8] + " = " + std::to_string(adventure_template_entry.type_data));
update_values.push_back(columns[9] + " = " + std::to_string(adventure_template_entry.type_count));
update_values.push_back(columns[10] + " = '" + EscapeString(adventure_template_entry.assa_x) + "'");
update_values.push_back(columns[11] + " = '" + EscapeString(adventure_template_entry.assa_y) + "'");
update_values.push_back(columns[12] + " = '" + EscapeString(adventure_template_entry.assa_z) + "'");
update_values.push_back(columns[13] + " = '" + EscapeString(adventure_template_entry.assa_h) + "'");
update_values.push_back(columns[14] + " = '" + EscapeString(adventure_template_entry.text) + "'");
update_values.push_back(columns[15] + " = " + std::to_string(adventure_template_entry.duration));
update_values.push_back(columns[16] + " = " + std::to_string(adventure_template_entry.zone_in_time));
update_values.push_back(columns[17] + " = " + std::to_string(adventure_template_entry.win_points));
update_values.push_back(columns[18] + " = " + std::to_string(adventure_template_entry.lose_points));
update_values.push_back(columns[19] + " = " + std::to_string(adventure_template_entry.theme));
update_values.push_back(columns[20] + " = " + std::to_string(adventure_template_entry.zone_in_zone_id));
update_values.push_back(columns[21] + " = '" + EscapeString(adventure_template_entry.zone_in_x) + "'");
update_values.push_back(columns[22] + " = '" + EscapeString(adventure_template_entry.zone_in_y) + "'");
update_values.push_back(columns[23] + " = " + std::to_string(adventure_template_entry.zone_in_object_id));
update_values.push_back(columns[24] + " = '" + EscapeString(adventure_template_entry.dest_x) + "'");
update_values.push_back(columns[25] + " = '" + EscapeString(adventure_template_entry.dest_y) + "'");
update_values.push_back(columns[26] + " = '" + EscapeString(adventure_template_entry.dest_z) + "'");
update_values.push_back(columns[27] + " = '" + EscapeString(adventure_template_entry.dest_h) + "'");
update_values.push_back(columns[28] + " = " + std::to_string(adventure_template_entry.graveyard_zone_id));
update_values.push_back(columns[29] + " = '" + EscapeString(adventure_template_entry.graveyard_x) + "'");
update_values.push_back(columns[30] + " = '" + EscapeString(adventure_template_entry.graveyard_y) + "'");
update_values.push_back(columns[31] + " = '" + EscapeString(adventure_template_entry.graveyard_z) + "'");
update_values.push_back(columns[32] + " = '" + EscapeString(adventure_template_entry.graveyard_radius) + "'");
auto results = content_db.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
adventure_template_entry.id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static AdventureTemplate InsertOne(
AdventureTemplate adventure_template_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(adventure_template_entry.zone) + "'");
insert_values.push_back(std::to_string(adventure_template_entry.zone_version));
insert_values.push_back(std::to_string(adventure_template_entry.is_hard));
insert_values.push_back(std::to_string(adventure_template_entry.is_raid));
insert_values.push_back(std::to_string(adventure_template_entry.min_level));
insert_values.push_back(std::to_string(adventure_template_entry.max_level));
insert_values.push_back(std::to_string(adventure_template_entry.type));
insert_values.push_back(std::to_string(adventure_template_entry.type_data));
insert_values.push_back(std::to_string(adventure_template_entry.type_count));
insert_values.push_back("'" + EscapeString(adventure_template_entry.assa_x) + "'");
insert_values.push_back("'" + EscapeString(adventure_template_entry.assa_y) + "'");
insert_values.push_back("'" + EscapeString(adventure_template_entry.assa_z) + "'");
insert_values.push_back("'" + EscapeString(adventure_template_entry.assa_h) + "'");
insert_values.push_back("'" + EscapeString(adventure_template_entry.text) + "'");
insert_values.push_back(std::to_string(adventure_template_entry.duration));
insert_values.push_back(std::to_string(adventure_template_entry.zone_in_time));
insert_values.push_back(std::to_string(adventure_template_entry.win_points));
insert_values.push_back(std::to_string(adventure_template_entry.lose_points));
insert_values.push_back(std::to_string(adventure_template_entry.theme));
insert_values.push_back(std::to_string(adventure_template_entry.zone_in_zone_id));
insert_values.push_back("'" + EscapeString(adventure_template_entry.zone_in_x) + "'");
insert_values.push_back("'" + EscapeString(adventure_template_entry.zone_in_y) + "'");
insert_values.push_back(std::to_string(adventure_template_entry.zone_in_object_id));
insert_values.push_back("'" + EscapeString(adventure_template_entry.dest_x) + "'");
insert_values.push_back("'" + EscapeString(adventure_template_entry.dest_y) + "'");
insert_values.push_back("'" + EscapeString(adventure_template_entry.dest_z) + "'");
insert_values.push_back("'" + EscapeString(adventure_template_entry.dest_h) + "'");
insert_values.push_back(std::to_string(adventure_template_entry.graveyard_zone_id));
insert_values.push_back("'" + EscapeString(adventure_template_entry.graveyard_x) + "'");
insert_values.push_back("'" + EscapeString(adventure_template_entry.graveyard_y) + "'");
insert_values.push_back("'" + EscapeString(adventure_template_entry.graveyard_z) + "'");
insert_values.push_back("'" + EscapeString(adventure_template_entry.graveyard_radius) + "'");
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
adventure_template_entry.id = results.LastInsertedID();
return adventure_template_entry;
}
adventure_template_entry = InstanceListRepository::NewEntity();
return adventure_template_entry;
}
static int InsertMany(
std::vector<AdventureTemplate> adventure_template_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &adventure_template_entry: adventure_template_entries) {
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(adventure_template_entry.zone) + "'");
insert_values.push_back(std::to_string(adventure_template_entry.zone_version));
insert_values.push_back(std::to_string(adventure_template_entry.is_hard));
insert_values.push_back(std::to_string(adventure_template_entry.is_raid));
insert_values.push_back(std::to_string(adventure_template_entry.min_level));
insert_values.push_back(std::to_string(adventure_template_entry.max_level));
insert_values.push_back(std::to_string(adventure_template_entry.type));
insert_values.push_back(std::to_string(adventure_template_entry.type_data));
insert_values.push_back(std::to_string(adventure_template_entry.type_count));
insert_values.push_back("'" + EscapeString(adventure_template_entry.assa_x) + "'");
insert_values.push_back("'" + EscapeString(adventure_template_entry.assa_y) + "'");
insert_values.push_back("'" + EscapeString(adventure_template_entry.assa_z) + "'");
insert_values.push_back("'" + EscapeString(adventure_template_entry.assa_h) + "'");
insert_values.push_back("'" + EscapeString(adventure_template_entry.text) + "'");
insert_values.push_back(std::to_string(adventure_template_entry.duration));
insert_values.push_back(std::to_string(adventure_template_entry.zone_in_time));
insert_values.push_back(std::to_string(adventure_template_entry.win_points));
insert_values.push_back(std::to_string(adventure_template_entry.lose_points));
insert_values.push_back(std::to_string(adventure_template_entry.theme));
insert_values.push_back(std::to_string(adventure_template_entry.zone_in_zone_id));
insert_values.push_back("'" + EscapeString(adventure_template_entry.zone_in_x) + "'");
insert_values.push_back("'" + EscapeString(adventure_template_entry.zone_in_y) + "'");
insert_values.push_back(std::to_string(adventure_template_entry.zone_in_object_id));
insert_values.push_back("'" + EscapeString(adventure_template_entry.dest_x) + "'");
insert_values.push_back("'" + EscapeString(adventure_template_entry.dest_y) + "'");
insert_values.push_back("'" + EscapeString(adventure_template_entry.dest_z) + "'");
insert_values.push_back("'" + EscapeString(adventure_template_entry.dest_h) + "'");
insert_values.push_back(std::to_string(adventure_template_entry.graveyard_zone_id));
insert_values.push_back("'" + EscapeString(adventure_template_entry.graveyard_x) + "'");
insert_values.push_back("'" + EscapeString(adventure_template_entry.graveyard_y) + "'");
insert_values.push_back("'" + EscapeString(adventure_template_entry.graveyard_z) + "'");
insert_values.push_back("'" + EscapeString(adventure_template_entry.graveyard_radius) + "'");
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<AdventureTemplate> All()
{
std::vector<AdventureTemplate> all_entries;
auto results = content_db.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
AdventureTemplate entry{};
entry.id = atoi(row[0]);
entry.zone = row[1];
entry.zone_version = atoi(row[2]);
entry.is_hard = atoi(row[3]);
entry.is_raid = atoi(row[4]);
entry.min_level = atoi(row[5]);
entry.max_level = atoi(row[6]);
entry.type = atoi(row[7]);
entry.type_data = atoi(row[8]);
entry.type_count = atoi(row[9]);
entry.assa_x = atof(row[10]);
entry.assa_y = atof(row[11]);
entry.assa_z = atof(row[12]);
entry.assa_h = atof(row[13]);
entry.text = row[14];
entry.duration = atoi(row[15]);
entry.zone_in_time = atoi(row[16]);
entry.win_points = atoi(row[17]);
entry.lose_points = atoi(row[18]);
entry.theme = atoi(row[19]);
entry.zone_in_zone_id = atoi(row[20]);
entry.zone_in_x = atof(row[21]);
entry.zone_in_y = atof(row[22]);
entry.zone_in_object_id = atoi(row[23]);
entry.dest_x = atof(row[24]);
entry.dest_y = atof(row[25]);
entry.dest_z = atof(row[26]);
entry.dest_h = atof(row[27]);
entry.graveyard_zone_id = atoi(row[28]);
entry.graveyard_x = atof(row[29]);
entry.graveyard_y = atof(row[30]);
entry.graveyard_z = atof(row[31]);
entry.graveyard_radius = atof(row[32]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_ADVENTURE_TEMPLATE_REPOSITORY_H

View File

@ -0,0 +1,258 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_ALTERNATE_CURRENCY_REPOSITORY_H
#define EQEMU_ALTERNATE_CURRENCY_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class AlternateCurrencyRepository {
public:
struct AlternateCurrency {
int id;
int item_id;
};
static std::string PrimaryKey()
{
return std::string("id");
}
static std::vector<std::string> Columns()
{
return {
"id",
"item_id",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("alternate_currency");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static AlternateCurrency NewEntity()
{
AlternateCurrency entry{};
entry.id = 0;
entry.item_id = 0;
return entry;
}
static AlternateCurrency GetAlternateCurrencyEntry(
const std::vector<AlternateCurrency> &alternate_currencys,
int alternate_currency_id
)
{
for (auto &alternate_currency : alternate_currencys) {
if (alternate_currency.id == alternate_currency_id) {
return alternate_currency;
}
}
return NewEntity();
}
static AlternateCurrency FindOne(
int alternate_currency_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
alternate_currency_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
AlternateCurrency entry{};
entry.id = atoi(row[0]);
entry.item_id = atoi(row[1]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int alternate_currency_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
alternate_currency_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
AlternateCurrency alternate_currency_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[1] + " = " + std::to_string(alternate_currency_entry.item_id));
auto results = content_db.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
alternate_currency_entry.id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static AlternateCurrency InsertOne(
AlternateCurrency alternate_currency_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(alternate_currency_entry.item_id));
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
alternate_currency_entry.id = results.LastInsertedID();
return alternate_currency_entry;
}
alternate_currency_entry = InstanceListRepository::NewEntity();
return alternate_currency_entry;
}
static int InsertMany(
std::vector<AlternateCurrency> alternate_currency_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &alternate_currency_entry: alternate_currency_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(alternate_currency_entry.item_id));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<AlternateCurrency> All()
{
std::vector<AlternateCurrency> all_entries;
auto results = content_db.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
AlternateCurrency entry{};
entry.id = atoi(row[0]);
entry.item_id = atoi(row[1]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_ALTERNATE_CURRENCY_REPOSITORY_H

View File

@ -0,0 +1,330 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_AURAS_REPOSITORY_H
#define EQEMU_AURAS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class AurasRepository {
public:
struct Auras {
int type;
int npc_type;
std::string name;
int spell_id;
int distance;
int aura_type;
int spawn_type;
int movement;
int duration;
int icon;
int cast_time;
};
static std::string PrimaryKey()
{
return std::string("type");
}
static std::vector<std::string> Columns()
{
return {
"type",
"npc_type",
"name",
"spell_id",
"distance",
"aura_type",
"spawn_type",
"movement",
"duration",
"icon",
"cast_time",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("auras");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static Auras NewEntity()
{
Auras entry{};
entry.type = 0;
entry.npc_type = 0;
entry.name = 0;
entry.spell_id = 0;
entry.distance = 60;
entry.aura_type = 1;
entry.spawn_type = 0;
entry.movement = 0;
entry.duration = 5400;
entry.icon = -1;
entry.cast_time = 0;
return entry;
}
static Auras GetAurasEntry(
const std::vector<Auras> &aurass,
int auras_id
)
{
for (auto &auras : aurass) {
if (auras.type == auras_id) {
return auras;
}
}
return NewEntity();
}
static Auras FindOne(
int auras_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
auras_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
Auras entry{};
entry.type = atoi(row[0]);
entry.npc_type = atoi(row[1]);
entry.name = row[2];
entry.spell_id = atoi(row[3]);
entry.distance = atoi(row[4]);
entry.aura_type = atoi(row[5]);
entry.spawn_type = atoi(row[6]);
entry.movement = atoi(row[7]);
entry.duration = atoi(row[8]);
entry.icon = atoi(row[9]);
entry.cast_time = atoi(row[10]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int auras_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
auras_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
Auras auras_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[1] + " = " + std::to_string(auras_entry.npc_type));
update_values.push_back(columns[2] + " = '" + EscapeString(auras_entry.name) + "'");
update_values.push_back(columns[3] + " = " + std::to_string(auras_entry.spell_id));
update_values.push_back(columns[4] + " = " + std::to_string(auras_entry.distance));
update_values.push_back(columns[5] + " = " + std::to_string(auras_entry.aura_type));
update_values.push_back(columns[6] + " = " + std::to_string(auras_entry.spawn_type));
update_values.push_back(columns[7] + " = " + std::to_string(auras_entry.movement));
update_values.push_back(columns[8] + " = " + std::to_string(auras_entry.duration));
update_values.push_back(columns[9] + " = " + std::to_string(auras_entry.icon));
update_values.push_back(columns[10] + " = " + std::to_string(auras_entry.cast_time));
auto results = content_db.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
auras_entry.type
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static Auras InsertOne(
Auras auras_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(auras_entry.npc_type));
insert_values.push_back("'" + EscapeString(auras_entry.name) + "'");
insert_values.push_back(std::to_string(auras_entry.spell_id));
insert_values.push_back(std::to_string(auras_entry.distance));
insert_values.push_back(std::to_string(auras_entry.aura_type));
insert_values.push_back(std::to_string(auras_entry.spawn_type));
insert_values.push_back(std::to_string(auras_entry.movement));
insert_values.push_back(std::to_string(auras_entry.duration));
insert_values.push_back(std::to_string(auras_entry.icon));
insert_values.push_back(std::to_string(auras_entry.cast_time));
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
auras_entry.id = results.LastInsertedID();
return auras_entry;
}
auras_entry = InstanceListRepository::NewEntity();
return auras_entry;
}
static int InsertMany(
std::vector<Auras> auras_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &auras_entry: auras_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(auras_entry.npc_type));
insert_values.push_back("'" + EscapeString(auras_entry.name) + "'");
insert_values.push_back(std::to_string(auras_entry.spell_id));
insert_values.push_back(std::to_string(auras_entry.distance));
insert_values.push_back(std::to_string(auras_entry.aura_type));
insert_values.push_back(std::to_string(auras_entry.spawn_type));
insert_values.push_back(std::to_string(auras_entry.movement));
insert_values.push_back(std::to_string(auras_entry.duration));
insert_values.push_back(std::to_string(auras_entry.icon));
insert_values.push_back(std::to_string(auras_entry.cast_time));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<Auras> All()
{
std::vector<Auras> all_entries;
auto results = content_db.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
Auras entry{};
entry.type = atoi(row[0]);
entry.npc_type = atoi(row[1]);
entry.name = row[2];
entry.spell_id = atoi(row[3]);
entry.distance = atoi(row[4]);
entry.aura_type = atoi(row[5]);
entry.spawn_type = atoi(row[6]);
entry.movement = atoi(row[7]);
entry.duration = atoi(row[8]);
entry.icon = atoi(row[9]);
entry.cast_time = atoi(row[10]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_AURAS_REPOSITORY_H

View File

@ -0,0 +1,258 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_BANNED_IPS_REPOSITORY_H
#define EQEMU_BANNED_IPS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class BannedIpsRepository {
public:
struct BannedIps {
std::string ip_address;
std::string notes;
};
static std::string PrimaryKey()
{
return std::string("ip_address");
}
static std::vector<std::string> Columns()
{
return {
"ip_address",
"notes",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("banned_ips");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static BannedIps NewEntity()
{
BannedIps entry{};
entry.ip_address = 0;
entry.notes = 0;
return entry;
}
static BannedIps GetBannedIpsEntry(
const std::vector<BannedIps> &banned_ipss,
int banned_ips_id
)
{
for (auto &banned_ips : banned_ipss) {
if (banned_ips.ip_address == banned_ips_id) {
return banned_ips;
}
}
return NewEntity();
}
static BannedIps FindOne(
int banned_ips_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
banned_ips_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
BannedIps entry{};
entry.ip_address = row[0];
entry.notes = row[1];
return entry;
}
return NewEntity();
}
static int DeleteOne(
int banned_ips_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
banned_ips_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
BannedIps banned_ips_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[1] + " = '" + EscapeString(banned_ips_entry.notes) + "'");
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
banned_ips_entry.ip_address
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static BannedIps InsertOne(
BannedIps banned_ips_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(banned_ips_entry.notes) + "'");
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
banned_ips_entry.id = results.LastInsertedID();
return banned_ips_entry;
}
banned_ips_entry = InstanceListRepository::NewEntity();
return banned_ips_entry;
}
static int InsertMany(
std::vector<BannedIps> banned_ips_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &banned_ips_entry: banned_ips_entries) {
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(banned_ips_entry.notes) + "'");
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<BannedIps> All()
{
std::vector<BannedIps> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
BannedIps entry{};
entry.ip_address = row[0];
entry.notes = row[1];
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_BANNED_IPS_REPOSITORY_H

View File

@ -0,0 +1,324 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_BASE_DATA_REPOSITORY_H
#define EQEMU_BASE_DATA_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class BaseDataRepository {
public:
struct BaseData {
int level;
int class;
std::string hp;
std::string mana;
std::string end;
std::string unk1;
std::string unk2;
std::string hp_fac;
std::string mana_fac;
std::string end_fac;
};
static std::string PrimaryKey()
{
return std::string("class");
}
static std::vector<std::string> Columns()
{
return {
"level",
"class",
"hp",
"mana",
"end",
"unk1",
"unk2",
"hp_fac",
"mana_fac",
"end_fac",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("base_data");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static BaseData NewEntity()
{
BaseData entry{};
entry.level = 0;
entry.
class = 0;
entry.hp = 0;
entry.mana = 0;
entry.end = 0;
entry.unk1 = 0;
entry.unk2 = 0;
entry.hp_fac = 0;
entry.mana_fac = 0;
entry.end_fac = 0;
return entry;
}
static BaseData GetBaseDataEntry(
const std::vector<BaseData> &base_datas,
int base_data_id
)
{
for (auto &base_data : base_datas) {
if (base_data. { class }== base_data_id) {
return base_data;
}
}
return NewEntity();
}
static BaseData FindOne(
int base_data_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
base_data_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
BaseData entry{};
entry.level = atoi(row[0]);
entry.
class = atoi(row[1]);
entry.hp = atof(row[2]);
entry.mana = atof(row[3]);
entry.end = atof(row[4]);
entry.unk1 = atof(row[5]);
entry.unk2 = atof(row[6]);
entry.hp_fac = atof(row[7]);
entry.mana_fac = atof(row[8]);
entry.end_fac = atof(row[9]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int base_data_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
base_data_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
BaseData base_data_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[2] + " = '" + EscapeString(base_data_entry.hp) + "'");
update_values.push_back(columns[3] + " = '" + EscapeString(base_data_entry.mana) + "'");
update_values.push_back(columns[4] + " = '" + EscapeString(base_data_entry.end) + "'");
update_values.push_back(columns[5] + " = '" + EscapeString(base_data_entry.unk1) + "'");
update_values.push_back(columns[6] + " = '" + EscapeString(base_data_entry.unk2) + "'");
update_values.push_back(columns[7] + " = '" + EscapeString(base_data_entry.hp_fac) + "'");
update_values.push_back(columns[8] + " = '" + EscapeString(base_data_entry.mana_fac) + "'");
update_values.push_back(columns[9] + " = '" + EscapeString(base_data_entry.end_fac) + "'");
auto
results = content_db.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
base_data_entry.
class
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static BaseData InsertOne(
BaseData base_data_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(base_data_entry.hp) + "'");
insert_values.push_back("'" + EscapeString(base_data_entry.mana) + "'");
insert_values.push_back("'" + EscapeString(base_data_entry.end) + "'");
insert_values.push_back("'" + EscapeString(base_data_entry.unk1) + "'");
insert_values.push_back("'" + EscapeString(base_data_entry.unk2) + "'");
insert_values.push_back("'" + EscapeString(base_data_entry.hp_fac) + "'");
insert_values.push_back("'" + EscapeString(base_data_entry.mana_fac) + "'");
insert_values.push_back("'" + EscapeString(base_data_entry.end_fac) + "'");
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
base_data_entry.id = results.LastInsertedID();
return base_data_entry;
}
base_data_entry = InstanceListRepository::NewEntity();
return base_data_entry;
}
static int InsertMany(
std::vector<BaseData> base_data_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &base_data_entry: base_data_entries) {
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(base_data_entry.hp) + "'");
insert_values.push_back("'" + EscapeString(base_data_entry.mana) + "'");
insert_values.push_back("'" + EscapeString(base_data_entry.end) + "'");
insert_values.push_back("'" + EscapeString(base_data_entry.unk1) + "'");
insert_values.push_back("'" + EscapeString(base_data_entry.unk2) + "'");
insert_values.push_back("'" + EscapeString(base_data_entry.hp_fac) + "'");
insert_values.push_back("'" + EscapeString(base_data_entry.mana_fac) + "'");
insert_values.push_back("'" + EscapeString(base_data_entry.end_fac) + "'");
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<BaseData> All()
{
std::vector<BaseData> all_entries;
auto results = content_db.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
BaseData entry{};
entry.level = atoi(row[0]);
entry.
class = atoi(row[1]);
entry.hp = atof(row[2]);
entry.mana = atof(row[3]);
entry.end = atof(row[4]);
entry.unk1 = atof(row[5]);
entry.unk2 = atof(row[6]);
entry.hp_fac = atof(row[7]);
entry.mana_fac = atof(row[8]);
entry.end_fac = atof(row[9]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_BASE_DATA_REPOSITORY_H

View File

@ -0,0 +1,338 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_BLOCKED_SPELLS_REPOSITORY_H
#define EQEMU_BLOCKED_SPELLS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class BlockedSpellsRepository {
public:
struct BlockedSpells {
int id;
int spellid;
int8 type;
int zoneid;
std::string x;
std::string y;
std::string z;
std::string x_diff;
std::string y_diff;
std::string z_diff;
std::string message;
std::string description;
};
static std::string PrimaryKey()
{
return std::string("id");
}
static std::vector<std::string> Columns()
{
return {
"id",
"spellid",
"type",
"zoneid",
"x",
"y",
"z",
"x_diff",
"y_diff",
"z_diff",
"message",
"description",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("blocked_spells");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static BlockedSpells NewEntity()
{
BlockedSpells entry{};
entry.id = 0;
entry.spellid = 0;
entry.type = 0;
entry.zoneid = 0;
entry.x = 0;
entry.y = 0;
entry.z = 0;
entry.x_diff = 0;
entry.y_diff = 0;
entry.z_diff = 0;
entry.message = "";
entry.description = "";
return entry;
}
static BlockedSpells GetBlockedSpellsEntry(
const std::vector<BlockedSpells> &blocked_spellss,
int blocked_spells_id
)
{
for (auto &blocked_spells : blocked_spellss) {
if (blocked_spells.id == blocked_spells_id) {
return blocked_spells;
}
}
return NewEntity();
}
static BlockedSpells FindOne(
int blocked_spells_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
blocked_spells_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
BlockedSpells entry{};
entry.id = atoi(row[0]);
entry.spellid = atoi(row[1]);
entry.type = atoi(row[2]);
entry.zoneid = atoi(row[3]);
entry.x = atof(row[4]);
entry.y = atof(row[5]);
entry.z = atof(row[6]);
entry.x_diff = atof(row[7]);
entry.y_diff = atof(row[8]);
entry.z_diff = atof(row[9]);
entry.message = row[10];
entry.description = row[11];
return entry;
}
return NewEntity();
}
static int DeleteOne(
int blocked_spells_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
blocked_spells_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
BlockedSpells blocked_spells_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[1] + " = " + std::to_string(blocked_spells_entry.spellid));
update_values.push_back(columns[2] + " = " + std::to_string(blocked_spells_entry.type));
update_values.push_back(columns[3] + " = " + std::to_string(blocked_spells_entry.zoneid));
update_values.push_back(columns[4] + " = '" + EscapeString(blocked_spells_entry.x) + "'");
update_values.push_back(columns[5] + " = '" + EscapeString(blocked_spells_entry.y) + "'");
update_values.push_back(columns[6] + " = '" + EscapeString(blocked_spells_entry.z) + "'");
update_values.push_back(columns[7] + " = '" + EscapeString(blocked_spells_entry.x_diff) + "'");
update_values.push_back(columns[8] + " = '" + EscapeString(blocked_spells_entry.y_diff) + "'");
update_values.push_back(columns[9] + " = '" + EscapeString(blocked_spells_entry.z_diff) + "'");
update_values.push_back(columns[10] + " = '" + EscapeString(blocked_spells_entry.message) + "'");
update_values.push_back(columns[11] + " = '" + EscapeString(blocked_spells_entry.description) + "'");
auto results = content_db.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
blocked_spells_entry.id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static BlockedSpells InsertOne(
BlockedSpells blocked_spells_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(blocked_spells_entry.spellid));
insert_values.push_back(std::to_string(blocked_spells_entry.type));
insert_values.push_back(std::to_string(blocked_spells_entry.zoneid));
insert_values.push_back("'" + EscapeString(blocked_spells_entry.x) + "'");
insert_values.push_back("'" + EscapeString(blocked_spells_entry.y) + "'");
insert_values.push_back("'" + EscapeString(blocked_spells_entry.z) + "'");
insert_values.push_back("'" + EscapeString(blocked_spells_entry.x_diff) + "'");
insert_values.push_back("'" + EscapeString(blocked_spells_entry.y_diff) + "'");
insert_values.push_back("'" + EscapeString(blocked_spells_entry.z_diff) + "'");
insert_values.push_back("'" + EscapeString(blocked_spells_entry.message) + "'");
insert_values.push_back("'" + EscapeString(blocked_spells_entry.description) + "'");
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
blocked_spells_entry.id = results.LastInsertedID();
return blocked_spells_entry;
}
blocked_spells_entry = InstanceListRepository::NewEntity();
return blocked_spells_entry;
}
static int InsertMany(
std::vector<BlockedSpells> blocked_spells_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &blocked_spells_entry: blocked_spells_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(blocked_spells_entry.spellid));
insert_values.push_back(std::to_string(blocked_spells_entry.type));
insert_values.push_back(std::to_string(blocked_spells_entry.zoneid));
insert_values.push_back("'" + EscapeString(blocked_spells_entry.x) + "'");
insert_values.push_back("'" + EscapeString(blocked_spells_entry.y) + "'");
insert_values.push_back("'" + EscapeString(blocked_spells_entry.z) + "'");
insert_values.push_back("'" + EscapeString(blocked_spells_entry.x_diff) + "'");
insert_values.push_back("'" + EscapeString(blocked_spells_entry.y_diff) + "'");
insert_values.push_back("'" + EscapeString(blocked_spells_entry.z_diff) + "'");
insert_values.push_back("'" + EscapeString(blocked_spells_entry.message) + "'");
insert_values.push_back("'" + EscapeString(blocked_spells_entry.description) + "'");
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<BlockedSpells> All()
{
std::vector<BlockedSpells> all_entries;
auto results = content_db.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
BlockedSpells entry{};
entry.id = atoi(row[0]);
entry.spellid = atoi(row[1]);
entry.type = atoi(row[2]);
entry.zoneid = atoi(row[3]);
entry.x = atof(row[4]);
entry.y = atof(row[5]);
entry.z = atof(row[6]);
entry.x_diff = atof(row[7]);
entry.y_diff = atof(row[8]);
entry.z_diff = atof(row[9]);
entry.message = row[10];
entry.description = row[11];
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_BLOCKED_SPELLS_REPOSITORY_H

View File

@ -0,0 +1,266 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_BOOKS_REPOSITORY_H
#define EQEMU_BOOKS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class BooksRepository {
public:
struct Books {
std::string name;
std::string txtfile;
int language;
};
static std::string PrimaryKey()
{
return std::string("name");
}
static std::vector<std::string> Columns()
{
return {
"name",
"txtfile",
"language",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("books");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static Books NewEntity()
{
Books entry{};
entry.name = "";
entry.txtfile = 0;
entry.language = 0;
return entry;
}
static Books GetBooksEntry(
const std::vector<Books> &bookss,
int books_id
)
{
for (auto &books : bookss) {
if (books.name == books_id) {
return books;
}
}
return NewEntity();
}
static Books FindOne(
int books_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
books_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
Books entry{};
entry.name = row[0];
entry.txtfile = row[1];
entry.language = atoi(row[2]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int books_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
books_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
Books books_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[1] + " = '" + EscapeString(books_entry.txtfile) + "'");
update_values.push_back(columns[2] + " = " + std::to_string(books_entry.language));
auto results = content_db.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
books_entry.name
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static Books InsertOne(
Books books_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(books_entry.txtfile) + "'");
insert_values.push_back(std::to_string(books_entry.language));
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
books_entry.id = results.LastInsertedID();
return books_entry;
}
books_entry = InstanceListRepository::NewEntity();
return books_entry;
}
static int InsertMany(
std::vector<Books> books_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &books_entry: books_entries) {
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(books_entry.txtfile) + "'");
insert_values.push_back(std::to_string(books_entry.language));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<Books> All()
{
std::vector<Books> all_entries;
auto results = content_db.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
Books entry{};
entry.name = row[0];
entry.txtfile = row[1];
entry.language = atoi(row[2]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_BOOKS_REPOSITORY_H

View File

@ -0,0 +1,498 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_BUG_REPORTS_REPOSITORY_H
#define EQEMU_BUG_REPORTS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class BugReportsRepository {
public:
struct BugReports {
int id;
std::string zone;
int client_version_id;
std::string client_version_name;
int account_id;
int character_id;
std::string character_name;
int8 reporter_spoof;
int category_id;
std::string category_name;
std::string reporter_name;
std::string ui_path;
std::string pos_x;
std::string pos_y;
std::string pos_z;
int heading;
int time_played;
int target_id;
std::string target_name;
int optional_info_mask;
int8 _can_duplicate;
int8 _crash_bug;
int8 _target_info;
int8 _character_flags;
int8 _unknown_value;
std::string bug_report;
std::string system_info;
std::string report_datetime;
int8 bug_status;
std::string last_review;
std::string last_reviewer;
std::string reviewer_notes;
};
static std::string PrimaryKey()
{
return std::string("id");
}
static std::vector<std::string> Columns()
{
return {
"id",
"zone",
"client_version_id",
"client_version_name",
"account_id",
"character_id",
"character_name",
"reporter_spoof",
"category_id",
"category_name",
"reporter_name",
"ui_path",
"pos_x",
"pos_y",
"pos_z",
"heading",
"time_played",
"target_id",
"target_name",
"optional_info_mask",
"_can_duplicate",
"_crash_bug",
"_target_info",
"_character_flags",
"_unknown_value",
"bug_report",
"system_info",
"report_datetime",
"bug_status",
"last_review",
"last_reviewer",
"reviewer_notes",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("bug_reports");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static BugReports NewEntity()
{
BugReports entry{};
entry.id = 0;
entry.zone = 'Unknown';
entry.client_version_id = 0;
entry.client_version_name = 'Unknown';
entry.account_id = 0;
entry.character_id = 0;
entry.character_name = 'Unknown';
entry.reporter_spoof = 1;
entry.category_id = 0;
entry.category_name = 'Other';
entry.reporter_name = 'Unknown';
entry.ui_path = 'Unknown';
entry.pos_x = 0;
entry.pos_y = 0;
entry.pos_z = 0;
entry.heading = 0;
entry.time_played = 0;
entry.target_id = 0;
entry.target_name = 'Unknown';
entry.optional_info_mask = 0;
entry._can_duplicate = 0;
entry._crash_bug = 0;
entry._target_info = 0;
entry._character_flags = 0;
entry._unknown_value = 0;
entry.bug_report = "";
entry.system_info = "";
entry.report_datetime = current_timestamp();
entry.bug_status = 0;
entry.last_review = current_timestamp();
entry.last_reviewer = 'None';
entry.reviewer_notes = "";
return entry;
}
static BugReports GetBugReportsEntry(
const std::vector<BugReports> &bug_reportss,
int bug_reports_id
)
{
for (auto &bug_reports : bug_reportss) {
if (bug_reports.id == bug_reports_id) {
return bug_reports;
}
}
return NewEntity();
}
static BugReports FindOne(
int bug_reports_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
bug_reports_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
BugReports entry{};
entry.id = atoi(row[0]);
entry.zone = row[1];
entry.client_version_id = atoi(row[2]);
entry.client_version_name = row[3];
entry.account_id = atoi(row[4]);
entry.character_id = atoi(row[5]);
entry.character_name = row[6];
entry.reporter_spoof = atoi(row[7]);
entry.category_id = atoi(row[8]);
entry.category_name = row[9];
entry.reporter_name = row[10];
entry.ui_path = row[11];
entry.pos_x = atof(row[12]);
entry.pos_y = atof(row[13]);
entry.pos_z = atof(row[14]);
entry.heading = atoi(row[15]);
entry.time_played = atoi(row[16]);
entry.target_id = atoi(row[17]);
entry.target_name = row[18];
entry.optional_info_mask = atoi(row[19]);
entry._can_duplicate = atoi(row[20]);
entry._crash_bug = atoi(row[21]);
entry._target_info = atoi(row[22]);
entry._character_flags = atoi(row[23]);
entry._unknown_value = atoi(row[24]);
entry.bug_report = row[25];
entry.system_info = row[26];
entry.report_datetime = row[27];
entry.bug_status = atoi(row[28]);
entry.last_review = row[29];
entry.last_reviewer = row[30];
entry.reviewer_notes = row[31];
return entry;
}
return NewEntity();
}
static int DeleteOne(
int bug_reports_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
bug_reports_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
BugReports bug_reports_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[1] + " = '" + EscapeString(bug_reports_entry.zone) + "'");
update_values.push_back(columns[2] + " = " + std::to_string(bug_reports_entry.client_version_id));
update_values.push_back(columns[3] + " = '" + EscapeString(bug_reports_entry.client_version_name) + "'");
update_values.push_back(columns[4] + " = " + std::to_string(bug_reports_entry.account_id));
update_values.push_back(columns[5] + " = " + std::to_string(bug_reports_entry.character_id));
update_values.push_back(columns[6] + " = '" + EscapeString(bug_reports_entry.character_name) + "'");
update_values.push_back(columns[7] + " = " + std::to_string(bug_reports_entry.reporter_spoof));
update_values.push_back(columns[8] + " = " + std::to_string(bug_reports_entry.category_id));
update_values.push_back(columns[9] + " = '" + EscapeString(bug_reports_entry.category_name) + "'");
update_values.push_back(columns[10] + " = '" + EscapeString(bug_reports_entry.reporter_name) + "'");
update_values.push_back(columns[11] + " = '" + EscapeString(bug_reports_entry.ui_path) + "'");
update_values.push_back(columns[12] + " = '" + EscapeString(bug_reports_entry.pos_x) + "'");
update_values.push_back(columns[13] + " = '" + EscapeString(bug_reports_entry.pos_y) + "'");
update_values.push_back(columns[14] + " = '" + EscapeString(bug_reports_entry.pos_z) + "'");
update_values.push_back(columns[15] + " = " + std::to_string(bug_reports_entry.heading));
update_values.push_back(columns[16] + " = " + std::to_string(bug_reports_entry.time_played));
update_values.push_back(columns[17] + " = " + std::to_string(bug_reports_entry.target_id));
update_values.push_back(columns[18] + " = '" + EscapeString(bug_reports_entry.target_name) + "'");
update_values.push_back(columns[19] + " = " + std::to_string(bug_reports_entry.optional_info_mask));
update_values.push_back(columns[20] + " = " + std::to_string(bug_reports_entry._can_duplicate));
update_values.push_back(columns[21] + " = " + std::to_string(bug_reports_entry._crash_bug));
update_values.push_back(columns[22] + " = " + std::to_string(bug_reports_entry._target_info));
update_values.push_back(columns[23] + " = " + std::to_string(bug_reports_entry._character_flags));
update_values.push_back(columns[24] + " = " + std::to_string(bug_reports_entry._unknown_value));
update_values.push_back(columns[25] + " = '" + EscapeString(bug_reports_entry.bug_report) + "'");
update_values.push_back(columns[26] + " = '" + EscapeString(bug_reports_entry.system_info) + "'");
update_values.push_back(columns[27] + " = '" + EscapeString(bug_reports_entry.report_datetime) + "'");
update_values.push_back(columns[28] + " = " + std::to_string(bug_reports_entry.bug_status));
update_values.push_back(columns[29] + " = '" + EscapeString(bug_reports_entry.last_review) + "'");
update_values.push_back(columns[30] + " = '" + EscapeString(bug_reports_entry.last_reviewer) + "'");
update_values.push_back(columns[31] + " = '" + EscapeString(bug_reports_entry.reviewer_notes) + "'");
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
bug_reports_entry.id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static BugReports InsertOne(
BugReports bug_reports_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(bug_reports_entry.zone) + "'");
insert_values.push_back(std::to_string(bug_reports_entry.client_version_id));
insert_values.push_back("'" + EscapeString(bug_reports_entry.client_version_name) + "'");
insert_values.push_back(std::to_string(bug_reports_entry.account_id));
insert_values.push_back(std::to_string(bug_reports_entry.character_id));
insert_values.push_back("'" + EscapeString(bug_reports_entry.character_name) + "'");
insert_values.push_back(std::to_string(bug_reports_entry.reporter_spoof));
insert_values.push_back(std::to_string(bug_reports_entry.category_id));
insert_values.push_back("'" + EscapeString(bug_reports_entry.category_name) + "'");
insert_values.push_back("'" + EscapeString(bug_reports_entry.reporter_name) + "'");
insert_values.push_back("'" + EscapeString(bug_reports_entry.ui_path) + "'");
insert_values.push_back("'" + EscapeString(bug_reports_entry.pos_x) + "'");
insert_values.push_back("'" + EscapeString(bug_reports_entry.pos_y) + "'");
insert_values.push_back("'" + EscapeString(bug_reports_entry.pos_z) + "'");
insert_values.push_back(std::to_string(bug_reports_entry.heading));
insert_values.push_back(std::to_string(bug_reports_entry.time_played));
insert_values.push_back(std::to_string(bug_reports_entry.target_id));
insert_values.push_back("'" + EscapeString(bug_reports_entry.target_name) + "'");
insert_values.push_back(std::to_string(bug_reports_entry.optional_info_mask));
insert_values.push_back(std::to_string(bug_reports_entry._can_duplicate));
insert_values.push_back(std::to_string(bug_reports_entry._crash_bug));
insert_values.push_back(std::to_string(bug_reports_entry._target_info));
insert_values.push_back(std::to_string(bug_reports_entry._character_flags));
insert_values.push_back(std::to_string(bug_reports_entry._unknown_value));
insert_values.push_back("'" + EscapeString(bug_reports_entry.bug_report) + "'");
insert_values.push_back("'" + EscapeString(bug_reports_entry.system_info) + "'");
insert_values.push_back("'" + EscapeString(bug_reports_entry.report_datetime) + "'");
insert_values.push_back(std::to_string(bug_reports_entry.bug_status));
insert_values.push_back("'" + EscapeString(bug_reports_entry.last_review) + "'");
insert_values.push_back("'" + EscapeString(bug_reports_entry.last_reviewer) + "'");
insert_values.push_back("'" + EscapeString(bug_reports_entry.reviewer_notes) + "'");
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
bug_reports_entry.id = results.LastInsertedID();
return bug_reports_entry;
}
bug_reports_entry = InstanceListRepository::NewEntity();
return bug_reports_entry;
}
static int InsertMany(
std::vector<BugReports> bug_reports_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &bug_reports_entry: bug_reports_entries) {
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(bug_reports_entry.zone) + "'");
insert_values.push_back(std::to_string(bug_reports_entry.client_version_id));
insert_values.push_back("'" + EscapeString(bug_reports_entry.client_version_name) + "'");
insert_values.push_back(std::to_string(bug_reports_entry.account_id));
insert_values.push_back(std::to_string(bug_reports_entry.character_id));
insert_values.push_back("'" + EscapeString(bug_reports_entry.character_name) + "'");
insert_values.push_back(std::to_string(bug_reports_entry.reporter_spoof));
insert_values.push_back(std::to_string(bug_reports_entry.category_id));
insert_values.push_back("'" + EscapeString(bug_reports_entry.category_name) + "'");
insert_values.push_back("'" + EscapeString(bug_reports_entry.reporter_name) + "'");
insert_values.push_back("'" + EscapeString(bug_reports_entry.ui_path) + "'");
insert_values.push_back("'" + EscapeString(bug_reports_entry.pos_x) + "'");
insert_values.push_back("'" + EscapeString(bug_reports_entry.pos_y) + "'");
insert_values.push_back("'" + EscapeString(bug_reports_entry.pos_z) + "'");
insert_values.push_back(std::to_string(bug_reports_entry.heading));
insert_values.push_back(std::to_string(bug_reports_entry.time_played));
insert_values.push_back(std::to_string(bug_reports_entry.target_id));
insert_values.push_back("'" + EscapeString(bug_reports_entry.target_name) + "'");
insert_values.push_back(std::to_string(bug_reports_entry.optional_info_mask));
insert_values.push_back(std::to_string(bug_reports_entry._can_duplicate));
insert_values.push_back(std::to_string(bug_reports_entry._crash_bug));
insert_values.push_back(std::to_string(bug_reports_entry._target_info));
insert_values.push_back(std::to_string(bug_reports_entry._character_flags));
insert_values.push_back(std::to_string(bug_reports_entry._unknown_value));
insert_values.push_back("'" + EscapeString(bug_reports_entry.bug_report) + "'");
insert_values.push_back("'" + EscapeString(bug_reports_entry.system_info) + "'");
insert_values.push_back("'" + EscapeString(bug_reports_entry.report_datetime) + "'");
insert_values.push_back(std::to_string(bug_reports_entry.bug_status));
insert_values.push_back("'" + EscapeString(bug_reports_entry.last_review) + "'");
insert_values.push_back("'" + EscapeString(bug_reports_entry.last_reviewer) + "'");
insert_values.push_back("'" + EscapeString(bug_reports_entry.reviewer_notes) + "'");
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<BugReports> All()
{
std::vector<BugReports> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
BugReports entry{};
entry.id = atoi(row[0]);
entry.zone = row[1];
entry.client_version_id = atoi(row[2]);
entry.client_version_name = row[3];
entry.account_id = atoi(row[4]);
entry.character_id = atoi(row[5]);
entry.character_name = row[6];
entry.reporter_spoof = atoi(row[7]);
entry.category_id = atoi(row[8]);
entry.category_name = row[9];
entry.reporter_name = row[10];
entry.ui_path = row[11];
entry.pos_x = atof(row[12]);
entry.pos_y = atof(row[13]);
entry.pos_z = atof(row[14]);
entry.heading = atoi(row[15]);
entry.time_played = atoi(row[16]);
entry.target_id = atoi(row[17]);
entry.target_name = row[18];
entry.optional_info_mask = atoi(row[19]);
entry._can_duplicate = atoi(row[20]);
entry._crash_bug = atoi(row[21]);
entry._target_info = atoi(row[22]);
entry._character_flags = atoi(row[23]);
entry._unknown_value = atoi(row[24]);
entry.bug_report = row[25];
entry.system_info = row[26];
entry.report_datetime = row[27];
entry.bug_status = atoi(row[28]);
entry.last_review = row[29];
entry.last_reviewer = row[30];
entry.reviewer_notes = row[31];
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_BUG_REPORTS_REPOSITORY_H

View File

@ -0,0 +1,346 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_BUGS_REPOSITORY_H
#define EQEMU_BUGS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class BugsRepository {
public:
struct Bugs {
int id;
std::string zone;
std::string name;
std::string ui;
std::string x;
std::string y;
std::string z;
std::string type;
int8 flag;
std::string target;
std::string bug;
std::string date;
int8 status;
};
static std::string PrimaryKey()
{
return std::string("id");
}
static std::vector<std::string> Columns()
{
return {
"id",
"zone",
"name",
"ui",
"x",
"y",
"z",
"type",
"flag",
"target",
"bug",
"date",
"status",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("bugs");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static Bugs NewEntity()
{
Bugs entry{};
entry.id = 0;
entry.zone = 0;
entry.name = 0;
entry.ui = 0;
entry.x = 0;
entry.y = 0;
entry.z = 0;
entry.type = 0;
entry.flag = 0;
entry.target = 0;
entry.bug = 0;
entry.date = 0;
entry.status = 0;
return entry;
}
static Bugs GetBugsEntry(
const std::vector<Bugs> &bugss,
int bugs_id
)
{
for (auto &bugs : bugss) {
if (bugs.id == bugs_id) {
return bugs;
}
}
return NewEntity();
}
static Bugs FindOne(
int bugs_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
bugs_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
Bugs entry{};
entry.id = atoi(row[0]);
entry.zone = row[1];
entry.name = row[2];
entry.ui = row[3];
entry.x = atof(row[4]);
entry.y = atof(row[5]);
entry.z = atof(row[6]);
entry.type = row[7];
entry.flag = atoi(row[8]);
entry.target = row[9];
entry.bug = row[10];
entry.date = row[11];
entry.status = atoi(row[12]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int bugs_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
bugs_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
Bugs bugs_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[1] + " = '" + EscapeString(bugs_entry.zone) + "'");
update_values.push_back(columns[2] + " = '" + EscapeString(bugs_entry.name) + "'");
update_values.push_back(columns[3] + " = '" + EscapeString(bugs_entry.ui) + "'");
update_values.push_back(columns[4] + " = '" + EscapeString(bugs_entry.x) + "'");
update_values.push_back(columns[5] + " = '" + EscapeString(bugs_entry.y) + "'");
update_values.push_back(columns[6] + " = '" + EscapeString(bugs_entry.z) + "'");
update_values.push_back(columns[7] + " = '" + EscapeString(bugs_entry.type) + "'");
update_values.push_back(columns[8] + " = " + std::to_string(bugs_entry.flag));
update_values.push_back(columns[9] + " = '" + EscapeString(bugs_entry.target) + "'");
update_values.push_back(columns[10] + " = '" + EscapeString(bugs_entry.bug) + "'");
update_values.push_back(columns[11] + " = '" + EscapeString(bugs_entry.date) + "'");
update_values.push_back(columns[12] + " = " + std::to_string(bugs_entry.status));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
bugs_entry.id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static Bugs InsertOne(
Bugs bugs_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(bugs_entry.zone) + "'");
insert_values.push_back("'" + EscapeString(bugs_entry.name) + "'");
insert_values.push_back("'" + EscapeString(bugs_entry.ui) + "'");
insert_values.push_back("'" + EscapeString(bugs_entry.x) + "'");
insert_values.push_back("'" + EscapeString(bugs_entry.y) + "'");
insert_values.push_back("'" + EscapeString(bugs_entry.z) + "'");
insert_values.push_back("'" + EscapeString(bugs_entry.type) + "'");
insert_values.push_back(std::to_string(bugs_entry.flag));
insert_values.push_back("'" + EscapeString(bugs_entry.target) + "'");
insert_values.push_back("'" + EscapeString(bugs_entry.bug) + "'");
insert_values.push_back("'" + EscapeString(bugs_entry.date) + "'");
insert_values.push_back(std::to_string(bugs_entry.status));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
bugs_entry.id = results.LastInsertedID();
return bugs_entry;
}
bugs_entry = InstanceListRepository::NewEntity();
return bugs_entry;
}
static int InsertMany(
std::vector<Bugs> bugs_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &bugs_entry: bugs_entries) {
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(bugs_entry.zone) + "'");
insert_values.push_back("'" + EscapeString(bugs_entry.name) + "'");
insert_values.push_back("'" + EscapeString(bugs_entry.ui) + "'");
insert_values.push_back("'" + EscapeString(bugs_entry.x) + "'");
insert_values.push_back("'" + EscapeString(bugs_entry.y) + "'");
insert_values.push_back("'" + EscapeString(bugs_entry.z) + "'");
insert_values.push_back("'" + EscapeString(bugs_entry.type) + "'");
insert_values.push_back(std::to_string(bugs_entry.flag));
insert_values.push_back("'" + EscapeString(bugs_entry.target) + "'");
insert_values.push_back("'" + EscapeString(bugs_entry.bug) + "'");
insert_values.push_back("'" + EscapeString(bugs_entry.date) + "'");
insert_values.push_back(std::to_string(bugs_entry.status));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<Bugs> All()
{
std::vector<Bugs> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
Bugs entry{};
entry.id = atoi(row[0]);
entry.zone = row[1];
entry.name = row[2];
entry.ui = row[3];
entry.x = atof(row[4]);
entry.y = atof(row[5]);
entry.z = atof(row[6]);
entry.type = row[7];
entry.flag = atoi(row[8]);
entry.target = row[9];
entry.bug = row[10];
entry.date = row[11];
entry.status = atoi(row[12]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_BUGS_REPOSITORY_H

View File

@ -0,0 +1,287 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_BUYER_REPOSITORY_H
#define EQEMU_BUYER_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class BuyerRepository {
public:
struct Buyer {
int charid;
int buyslot;
int itemid;
std::string itemname;
int quantity;
int price;
};
static std::string PrimaryKey()
{
return std::string("buyslot");
}
static std::vector<std::string> Columns()
{
return {
"charid",
"buyslot",
"itemid",
"itemname",
"quantity",
"price",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("buyer");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static Buyer NewEntity()
{
Buyer entry{};
entry.charid = 0;
entry.buyslot = 0;
entry.itemid = 0;
entry.itemname = "";
entry.quantity = 0;
entry.price = 0;
return entry;
}
static Buyer GetBuyerEntry(
const std::vector<Buyer> &buyers,
int buyer_id
)
{
for (auto &buyer : buyers) {
if (buyer.buyslot == buyer_id) {
return buyer;
}
}
return NewEntity();
}
static Buyer FindOne(
int buyer_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
buyer_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
Buyer entry{};
entry.charid = atoi(row[0]);
entry.buyslot = atoi(row[1]);
entry.itemid = atoi(row[2]);
entry.itemname = row[3];
entry.quantity = atoi(row[4]);
entry.price = atoi(row[5]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int buyer_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
buyer_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
Buyer buyer_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[2] + " = " + std::to_string(buyer_entry.itemid));
update_values.push_back(columns[3] + " = '" + EscapeString(buyer_entry.itemname) + "'");
update_values.push_back(columns[4] + " = " + std::to_string(buyer_entry.quantity));
update_values.push_back(columns[5] + " = " + std::to_string(buyer_entry.price));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
buyer_entry.buyslot
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static Buyer InsertOne(
Buyer buyer_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(buyer_entry.itemid));
insert_values.push_back("'" + EscapeString(buyer_entry.itemname) + "'");
insert_values.push_back(std::to_string(buyer_entry.quantity));
insert_values.push_back(std::to_string(buyer_entry.price));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
buyer_entry.id = results.LastInsertedID();
return buyer_entry;
}
buyer_entry = InstanceListRepository::NewEntity();
return buyer_entry;
}
static int InsertMany(
std::vector<Buyer> buyer_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &buyer_entry: buyer_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(buyer_entry.itemid));
insert_values.push_back("'" + EscapeString(buyer_entry.itemname) + "'");
insert_values.push_back(std::to_string(buyer_entry.quantity));
insert_values.push_back(std::to_string(buyer_entry.price));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<Buyer> All()
{
std::vector<Buyer> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
Buyer entry{};
entry.charid = atoi(row[0]);
entry.buyslot = atoi(row[1]);
entry.itemid = atoi(row[2]);
entry.itemname = row[3];
entry.quantity = atoi(row[4]);
entry.price = atoi(row[5]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_BUYER_REPOSITORY_H

View File

@ -0,0 +1,281 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_CHAR_CREATE_COMBINATIONS_REPOSITORY_H
#define EQEMU_CHAR_CREATE_COMBINATIONS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class CharCreateCombinationsRepository {
public:
struct CharCreateCombinations {
int allocation_id;
int race;
int class;
int deity;
int start_zone;
int expansions_req;
};
static std::string PrimaryKey()
{
return std::string("start_zone");
}
static std::vector<std::string> Columns()
{
return {
"allocation_id",
"race",
"class",
"deity",
"start_zone",
"expansions_req",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("char_create_combinations");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static CharCreateCombinations NewEntity()
{
CharCreateCombinations entry{};
entry.allocation_id = 0;
entry.race = 0;
entry.class = 0;
entry.deity = 0;
entry.start_zone = 0;
entry.expansions_req = 0;
return entry;
}
static CharCreateCombinations GetCharCreateCombinationsEntry(
const std::vector<CharCreateCombinations> &char_create_combinationss,
int char_create_combinations_id
)
{
for (auto &char_create_combinations : char_create_combinationss) {
if (char_create_combinations.start_zone == char_create_combinations_id) {
return char_create_combinations;
}
}
return NewEntity();
}
static CharCreateCombinations FindOne(
int char_create_combinations_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
char_create_combinations_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
CharCreateCombinations entry{};
entry.allocation_id = atoi(row[0]);
entry.race = atoi(row[1]);
entry.class = atoi(row[2]);
entry.deity = atoi(row[3]);
entry.start_zone = atoi(row[4]);
entry.expansions_req = atoi(row[5]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int char_create_combinations_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
char_create_combinations_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
CharCreateCombinations char_create_combinations_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[0] + " = " + std::to_string(char_create_combinations_entry.allocation_id));
update_values.push_back(columns[5] + " = " + std::to_string(char_create_combinations_entry.expansions_req));
auto results = content_db.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
char_create_combinations_entry.start_zone
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static CharCreateCombinations InsertOne(
CharCreateCombinations char_create_combinations_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(char_create_combinations_entry.allocation_id));
insert_values.push_back(std::to_string(char_create_combinations_entry.expansions_req));
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
char_create_combinations_entry.id = results.LastInsertedID();
return char_create_combinations_entry;
}
char_create_combinations_entry = InstanceListRepository::NewEntity();
return char_create_combinations_entry;
}
static int InsertMany(
std::vector<CharCreateCombinations> char_create_combinations_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &char_create_combinations_entry: char_create_combinations_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(char_create_combinations_entry.allocation_id));
insert_values.push_back(std::to_string(char_create_combinations_entry.expansions_req));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<CharCreateCombinations> All()
{
std::vector<CharCreateCombinations> all_entries;
auto results = content_db.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
CharCreateCombinations entry{};
entry.allocation_id = atoi(row[0]);
entry.race = atoi(row[1]);
entry.class = atoi(row[2]);
entry.deity = atoi(row[3]);
entry.start_zone = atoi(row[4]);
entry.expansions_req = atoi(row[5]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_CHAR_CREATE_COMBINATIONS_REPOSITORY_H

View File

@ -0,0 +1,362 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_CHAR_CREATE_POINT_ALLOCATIONS_REPOSITORY_H
#define EQEMU_CHAR_CREATE_POINT_ALLOCATIONS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class CharCreatePointAllocationsRepository {
public:
struct CharCreatePointAllocations {
int id;
int base_str;
int base_sta;
int base_dex;
int base_agi;
int base_int;
int base_wis;
int base_cha;
int alloc_str;
int alloc_sta;
int alloc_dex;
int alloc_agi;
int alloc_int;
int alloc_wis;
int alloc_cha;
};
static std::string PrimaryKey()
{
return std::string("id");
}
static std::vector<std::string> Columns()
{
return {
"id",
"base_str",
"base_sta",
"base_dex",
"base_agi",
"base_int",
"base_wis",
"base_cha",
"alloc_str",
"alloc_sta",
"alloc_dex",
"alloc_agi",
"alloc_int",
"alloc_wis",
"alloc_cha",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("char_create_point_allocations");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static CharCreatePointAllocations NewEntity()
{
CharCreatePointAllocations entry{};
entry.id = 0;
entry.base_str = 0;
entry.base_sta = 0;
entry.base_dex = 0;
entry.base_agi = 0;
entry.base_int = 0;
entry.base_wis = 0;
entry.base_cha = 0;
entry.alloc_str = 0;
entry.alloc_sta = 0;
entry.alloc_dex = 0;
entry.alloc_agi = 0;
entry.alloc_int = 0;
entry.alloc_wis = 0;
entry.alloc_cha = 0;
return entry;
}
static CharCreatePointAllocations GetCharCreatePointAllocationsEntry(
const std::vector<CharCreatePointAllocations> &char_create_point_allocationss,
int char_create_point_allocations_id
)
{
for (auto &char_create_point_allocations : char_create_point_allocationss) {
if (char_create_point_allocations.id == char_create_point_allocations_id) {
return char_create_point_allocations;
}
}
return NewEntity();
}
static CharCreatePointAllocations FindOne(
int char_create_point_allocations_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
char_create_point_allocations_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
CharCreatePointAllocations entry{};
entry.id = atoi(row[0]);
entry.base_str = atoi(row[1]);
entry.base_sta = atoi(row[2]);
entry.base_dex = atoi(row[3]);
entry.base_agi = atoi(row[4]);
entry.base_int = atoi(row[5]);
entry.base_wis = atoi(row[6]);
entry.base_cha = atoi(row[7]);
entry.alloc_str = atoi(row[8]);
entry.alloc_sta = atoi(row[9]);
entry.alloc_dex = atoi(row[10]);
entry.alloc_agi = atoi(row[11]);
entry.alloc_int = atoi(row[12]);
entry.alloc_wis = atoi(row[13]);
entry.alloc_cha = atoi(row[14]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int char_create_point_allocations_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
char_create_point_allocations_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
CharCreatePointAllocations char_create_point_allocations_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[1] + " = " + std::to_string(char_create_point_allocations_entry.base_str));
update_values.push_back(columns[2] + " = " + std::to_string(char_create_point_allocations_entry.base_sta));
update_values.push_back(columns[3] + " = " + std::to_string(char_create_point_allocations_entry.base_dex));
update_values.push_back(columns[4] + " = " + std::to_string(char_create_point_allocations_entry.base_agi));
update_values.push_back(columns[5] + " = " + std::to_string(char_create_point_allocations_entry.base_int));
update_values.push_back(columns[6] + " = " + std::to_string(char_create_point_allocations_entry.base_wis));
update_values.push_back(columns[7] + " = " + std::to_string(char_create_point_allocations_entry.base_cha));
update_values.push_back(columns[8] + " = " + std::to_string(char_create_point_allocations_entry.alloc_str));
update_values.push_back(columns[9] + " = " + std::to_string(char_create_point_allocations_entry.alloc_sta));
update_values.push_back(columns[10] + " = " + std::to_string(char_create_point_allocations_entry.alloc_dex));
update_values.push_back(columns[11] + " = " + std::to_string(char_create_point_allocations_entry.alloc_agi));
update_values.push_back(columns[12] + " = " + std::to_string(char_create_point_allocations_entry.alloc_int));
update_values.push_back(columns[13] + " = " + std::to_string(char_create_point_allocations_entry.alloc_wis));
update_values.push_back(columns[14] + " = " + std::to_string(char_create_point_allocations_entry.alloc_cha));
auto results = content_db.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
char_create_point_allocations_entry.id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static CharCreatePointAllocations InsertOne(
CharCreatePointAllocations char_create_point_allocations_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(char_create_point_allocations_entry.base_str));
insert_values.push_back(std::to_string(char_create_point_allocations_entry.base_sta));
insert_values.push_back(std::to_string(char_create_point_allocations_entry.base_dex));
insert_values.push_back(std::to_string(char_create_point_allocations_entry.base_agi));
insert_values.push_back(std::to_string(char_create_point_allocations_entry.base_int));
insert_values.push_back(std::to_string(char_create_point_allocations_entry.base_wis));
insert_values.push_back(std::to_string(char_create_point_allocations_entry.base_cha));
insert_values.push_back(std::to_string(char_create_point_allocations_entry.alloc_str));
insert_values.push_back(std::to_string(char_create_point_allocations_entry.alloc_sta));
insert_values.push_back(std::to_string(char_create_point_allocations_entry.alloc_dex));
insert_values.push_back(std::to_string(char_create_point_allocations_entry.alloc_agi));
insert_values.push_back(std::to_string(char_create_point_allocations_entry.alloc_int));
insert_values.push_back(std::to_string(char_create_point_allocations_entry.alloc_wis));
insert_values.push_back(std::to_string(char_create_point_allocations_entry.alloc_cha));
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
char_create_point_allocations_entry.id = results.LastInsertedID();
return char_create_point_allocations_entry;
}
char_create_point_allocations_entry = InstanceListRepository::NewEntity();
return char_create_point_allocations_entry;
}
static int InsertMany(
std::vector<CharCreatePointAllocations> char_create_point_allocations_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &char_create_point_allocations_entry: char_create_point_allocations_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(char_create_point_allocations_entry.base_str));
insert_values.push_back(std::to_string(char_create_point_allocations_entry.base_sta));
insert_values.push_back(std::to_string(char_create_point_allocations_entry.base_dex));
insert_values.push_back(std::to_string(char_create_point_allocations_entry.base_agi));
insert_values.push_back(std::to_string(char_create_point_allocations_entry.base_int));
insert_values.push_back(std::to_string(char_create_point_allocations_entry.base_wis));
insert_values.push_back(std::to_string(char_create_point_allocations_entry.base_cha));
insert_values.push_back(std::to_string(char_create_point_allocations_entry.alloc_str));
insert_values.push_back(std::to_string(char_create_point_allocations_entry.alloc_sta));
insert_values.push_back(std::to_string(char_create_point_allocations_entry.alloc_dex));
insert_values.push_back(std::to_string(char_create_point_allocations_entry.alloc_agi));
insert_values.push_back(std::to_string(char_create_point_allocations_entry.alloc_int));
insert_values.push_back(std::to_string(char_create_point_allocations_entry.alloc_wis));
insert_values.push_back(std::to_string(char_create_point_allocations_entry.alloc_cha));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<CharCreatePointAllocations> All()
{
std::vector<CharCreatePointAllocations> all_entries;
auto results = content_db.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
CharCreatePointAllocations entry{};
entry.id = atoi(row[0]);
entry.base_str = atoi(row[1]);
entry.base_sta = atoi(row[2]);
entry.base_dex = atoi(row[3]);
entry.base_agi = atoi(row[4]);
entry.base_int = atoi(row[5]);
entry.base_wis = atoi(row[6]);
entry.base_cha = atoi(row[7]);
entry.alloc_str = atoi(row[8]);
entry.alloc_sta = atoi(row[9]);
entry.alloc_dex = atoi(row[10]);
entry.alloc_agi = atoi(row[11]);
entry.alloc_int = atoi(row[12]);
entry.alloc_wis = atoi(row[13]);
entry.alloc_cha = atoi(row[14]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_CHAR_CREATE_POINT_ALLOCATIONS_REPOSITORY_H

View File

@ -0,0 +1,263 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_CHAR_RECIPE_LIST_REPOSITORY_H
#define EQEMU_CHAR_RECIPE_LIST_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class CharRecipeListRepository {
public:
struct CharRecipeList {
int char_id;
int recipe_id;
int madecount;
};
static std::string PrimaryKey()
{
return std::string("recipe_id");
}
static std::vector<std::string> Columns()
{
return {
"char_id",
"recipe_id",
"madecount",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("char_recipe_list");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static CharRecipeList NewEntity()
{
CharRecipeList entry{};
entry.char_id = 0;
entry.recipe_id = 0;
entry.madecount = 0;
return entry;
}
static CharRecipeList GetCharRecipeListEntry(
const std::vector<CharRecipeList> &char_recipe_lists,
int char_recipe_list_id
)
{
for (auto &char_recipe_list : char_recipe_lists) {
if (char_recipe_list.recipe_id == char_recipe_list_id) {
return char_recipe_list;
}
}
return NewEntity();
}
static CharRecipeList FindOne(
int char_recipe_list_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
char_recipe_list_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
CharRecipeList entry{};
entry.char_id = atoi(row[0]);
entry.recipe_id = atoi(row[1]);
entry.madecount = atoi(row[2]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int char_recipe_list_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
char_recipe_list_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
CharRecipeList char_recipe_list_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[2] + " = " + std::to_string(char_recipe_list_entry.madecount));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
char_recipe_list_entry.recipe_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static CharRecipeList InsertOne(
CharRecipeList char_recipe_list_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(char_recipe_list_entry.madecount));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
char_recipe_list_entry.id = results.LastInsertedID();
return char_recipe_list_entry;
}
char_recipe_list_entry = InstanceListRepository::NewEntity();
return char_recipe_list_entry;
}
static int InsertMany(
std::vector<CharRecipeList> char_recipe_list_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &char_recipe_list_entry: char_recipe_list_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(char_recipe_list_entry.madecount));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<CharRecipeList> All()
{
std::vector<CharRecipeList> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
CharRecipeList entry{};
entry.char_id = atoi(row[0]);
entry.recipe_id = atoi(row[1]);
entry.madecount = atoi(row[2]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_CHAR_RECIPE_LIST_REPOSITORY_H

View File

@ -0,0 +1,276 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_CHARACTER_ACTIVITIES_REPOSITORY_H
#define EQEMU_CHARACTER_ACTIVITIES_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class CharacterActivitiesRepository {
public:
struct CharacterActivities {
int charid;
int taskid;
int activityid;
int donecount;
int8 completed;
};
static std::string PrimaryKey()
{
return std::string("activityid");
}
static std::vector<std::string> Columns()
{
return {
"charid",
"taskid",
"activityid",
"donecount",
"completed",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("character_activities");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static CharacterActivities NewEntity()
{
CharacterActivities entry{};
entry.charid = 0;
entry.taskid = 0;
entry.activityid = 0;
entry.donecount = 0;
entry.completed = 0;
return entry;
}
static CharacterActivities GetCharacterActivitiesEntry(
const std::vector<CharacterActivities> &character_activitiess,
int character_activities_id
)
{
for (auto &character_activities : character_activitiess) {
if (character_activities.activityid == character_activities_id) {
return character_activities;
}
}
return NewEntity();
}
static CharacterActivities FindOne(
int character_activities_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
character_activities_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
CharacterActivities entry{};
entry.charid = atoi(row[0]);
entry.taskid = atoi(row[1]);
entry.activityid = atoi(row[2]);
entry.donecount = atoi(row[3]);
entry.completed = atoi(row[4]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int character_activities_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
character_activities_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
CharacterActivities character_activities_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[3] + " = " + std::to_string(character_activities_entry.donecount));
update_values.push_back(columns[4] + " = " + std::to_string(character_activities_entry.completed));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
character_activities_entry.activityid
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static CharacterActivities InsertOne(
CharacterActivities character_activities_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(character_activities_entry.donecount));
insert_values.push_back(std::to_string(character_activities_entry.completed));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
character_activities_entry.id = results.LastInsertedID();
return character_activities_entry;
}
character_activities_entry = InstanceListRepository::NewEntity();
return character_activities_entry;
}
static int InsertMany(
std::vector<CharacterActivities> character_activities_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &character_activities_entry: character_activities_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(character_activities_entry.donecount));
insert_values.push_back(std::to_string(character_activities_entry.completed));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<CharacterActivities> All()
{
std::vector<CharacterActivities> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
CharacterActivities entry{};
entry.charid = atoi(row[0]);
entry.taskid = atoi(row[1]);
entry.activityid = atoi(row[2]);
entry.donecount = atoi(row[3]);
entry.completed = atoi(row[4]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_CHARACTER_ACTIVITIES_REPOSITORY_H

View File

@ -0,0 +1,263 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_CHARACTER_ALT_CURRENCY_REPOSITORY_H
#define EQEMU_CHARACTER_ALT_CURRENCY_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class CharacterAltCurrencyRepository {
public:
struct CharacterAltCurrency {
int char_id;
int currency_id;
int amount;
};
static std::string PrimaryKey()
{
return std::string("currency_id");
}
static std::vector<std::string> Columns()
{
return {
"char_id",
"currency_id",
"amount",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("character_alt_currency");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static CharacterAltCurrency NewEntity()
{
CharacterAltCurrency entry{};
entry.char_id = 0;
entry.currency_id = 0;
entry.amount = 0;
return entry;
}
static CharacterAltCurrency GetCharacterAltCurrencyEntry(
const std::vector<CharacterAltCurrency> &character_alt_currencys,
int character_alt_currency_id
)
{
for (auto &character_alt_currency : character_alt_currencys) {
if (character_alt_currency.currency_id == character_alt_currency_id) {
return character_alt_currency;
}
}
return NewEntity();
}
static CharacterAltCurrency FindOne(
int character_alt_currency_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
character_alt_currency_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
CharacterAltCurrency entry{};
entry.char_id = atoi(row[0]);
entry.currency_id = atoi(row[1]);
entry.amount = atoi(row[2]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int character_alt_currency_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
character_alt_currency_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
CharacterAltCurrency character_alt_currency_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[2] + " = " + std::to_string(character_alt_currency_entry.amount));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
character_alt_currency_entry.currency_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static CharacterAltCurrency InsertOne(
CharacterAltCurrency character_alt_currency_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(character_alt_currency_entry.amount));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
character_alt_currency_entry.id = results.LastInsertedID();
return character_alt_currency_entry;
}
character_alt_currency_entry = InstanceListRepository::NewEntity();
return character_alt_currency_entry;
}
static int InsertMany(
std::vector<CharacterAltCurrency> character_alt_currency_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &character_alt_currency_entry: character_alt_currency_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(character_alt_currency_entry.amount));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<CharacterAltCurrency> All()
{
std::vector<CharacterAltCurrency> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
CharacterAltCurrency entry{};
entry.char_id = atoi(row[0]);
entry.currency_id = atoi(row[1]);
entry.amount = atoi(row[2]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_CHARACTER_ALT_CURRENCY_REPOSITORY_H

View File

@ -0,0 +1,271 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_CHARACTER_ALTERNATE_ABILITIES_REPOSITORY_H
#define EQEMU_CHARACTER_ALTERNATE_ABILITIES_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class CharacterAlternateAbilitiesRepository {
public:
struct CharacterAlternateAbilities {
int id;
int16 aa_id;
int16 aa_value;
int16 charges;
};
static std::string PrimaryKey()
{
return std::string("aa_id");
}
static std::vector<std::string> Columns()
{
return {
"id",
"aa_id",
"aa_value",
"charges",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("character_alternate_abilities");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static CharacterAlternateAbilities NewEntity()
{
CharacterAlternateAbilities entry{};
entry.id = 0;
entry.aa_id = 0;
entry.aa_value = 0;
entry.charges = 0;
return entry;
}
static CharacterAlternateAbilities GetCharacterAlternateAbilitiesEntry(
const std::vector<CharacterAlternateAbilities> &character_alternate_abilitiess,
int character_alternate_abilities_id
)
{
for (auto &character_alternate_abilities : character_alternate_abilitiess) {
if (character_alternate_abilities.aa_id == character_alternate_abilities_id) {
return character_alternate_abilities;
}
}
return NewEntity();
}
static CharacterAlternateAbilities FindOne(
int character_alternate_abilities_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
character_alternate_abilities_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
CharacterAlternateAbilities entry{};
entry.id = atoi(row[0]);
entry.aa_id = atoi(row[1]);
entry.aa_value = atoi(row[2]);
entry.charges = atoi(row[3]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int character_alternate_abilities_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
character_alternate_abilities_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
CharacterAlternateAbilities character_alternate_abilities_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[2] + " = " + std::to_string(character_alternate_abilities_entry.aa_value));
update_values.push_back(columns[3] + " = " + std::to_string(character_alternate_abilities_entry.charges));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
character_alternate_abilities_entry.aa_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static CharacterAlternateAbilities InsertOne(
CharacterAlternateAbilities character_alternate_abilities_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(character_alternate_abilities_entry.aa_value));
insert_values.push_back(std::to_string(character_alternate_abilities_entry.charges));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
character_alternate_abilities_entry.id = results.LastInsertedID();
return character_alternate_abilities_entry;
}
character_alternate_abilities_entry = InstanceListRepository::NewEntity();
return character_alternate_abilities_entry;
}
static int InsertMany(
std::vector<CharacterAlternateAbilities> character_alternate_abilities_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &character_alternate_abilities_entry: character_alternate_abilities_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(character_alternate_abilities_entry.aa_value));
insert_values.push_back(std::to_string(character_alternate_abilities_entry.charges));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<CharacterAlternateAbilities> All()
{
std::vector<CharacterAlternateAbilities> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
CharacterAlternateAbilities entry{};
entry.id = atoi(row[0]);
entry.aa_id = atoi(row[1]);
entry.aa_value = atoi(row[2]);
entry.charges = atoi(row[3]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_CHARACTER_ALTERNATE_ABILITIES_REPOSITORY_H

View File

@ -0,0 +1,263 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_CHARACTER_AURAS_REPOSITORY_H
#define EQEMU_CHARACTER_AURAS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class CharacterAurasRepository {
public:
struct CharacterAuras {
int id;
int8 slot;
int spell_id;
};
static std::string PrimaryKey()
{
return std::string("slot");
}
static std::vector<std::string> Columns()
{
return {
"id",
"slot",
"spell_id",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("character_auras");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static CharacterAuras NewEntity()
{
CharacterAuras entry{};
entry.id = 0;
entry.slot = 0;
entry.spell_id = 0;
return entry;
}
static CharacterAuras GetCharacterAurasEntry(
const std::vector<CharacterAuras> &character_aurass,
int character_auras_id
)
{
for (auto &character_auras : character_aurass) {
if (character_auras.slot == character_auras_id) {
return character_auras;
}
}
return NewEntity();
}
static CharacterAuras FindOne(
int character_auras_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
character_auras_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
CharacterAuras entry{};
entry.id = atoi(row[0]);
entry.slot = atoi(row[1]);
entry.spell_id = atoi(row[2]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int character_auras_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
character_auras_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
CharacterAuras character_auras_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[2] + " = " + std::to_string(character_auras_entry.spell_id));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
character_auras_entry.slot
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static CharacterAuras InsertOne(
CharacterAuras character_auras_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(character_auras_entry.spell_id));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
character_auras_entry.id = results.LastInsertedID();
return character_auras_entry;
}
character_auras_entry = InstanceListRepository::NewEntity();
return character_auras_entry;
}
static int InsertMany(
std::vector<CharacterAuras> character_auras_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &character_auras_entry: character_auras_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(character_auras_entry.spell_id));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<CharacterAuras> All()
{
std::vector<CharacterAuras> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
CharacterAuras entry{};
entry.id = atoi(row[0]);
entry.slot = atoi(row[1]);
entry.spell_id = atoi(row[2]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_CHARACTER_AURAS_REPOSITORY_H

View File

@ -0,0 +1,284 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_CHARACTER_BANDOLIER_REPOSITORY_H
#define EQEMU_CHARACTER_BANDOLIER_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class CharacterBandolierRepository {
public:
struct CharacterBandolier {
int id;
int8 bandolier_id;
int8 bandolier_slot;
int item_id;
int icon;
std::string bandolier_name;
};
static std::string PrimaryKey()
{
return std::string("bandolier_slot");
}
static std::vector<std::string> Columns()
{
return {
"id",
"bandolier_id",
"bandolier_slot",
"item_id",
"icon",
"bandolier_name",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("character_bandolier");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static CharacterBandolier NewEntity()
{
CharacterBandolier entry{};
entry.id = 0;
entry.bandolier_id = 0;
entry.bandolier_slot = 0;
entry.item_id = 0;
entry.icon = 0;
entry.bandolier_name = '0';
return entry;
}
static CharacterBandolier GetCharacterBandolierEntry(
const std::vector<CharacterBandolier> &character_bandoliers,
int character_bandolier_id
)
{
for (auto &character_bandolier : character_bandoliers) {
if (character_bandolier.bandolier_slot == character_bandolier_id) {
return character_bandolier;
}
}
return NewEntity();
}
static CharacterBandolier FindOne(
int character_bandolier_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
character_bandolier_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
CharacterBandolier entry{};
entry.id = atoi(row[0]);
entry.bandolier_id = atoi(row[1]);
entry.bandolier_slot = atoi(row[2]);
entry.item_id = atoi(row[3]);
entry.icon = atoi(row[4]);
entry.bandolier_name = row[5];
return entry;
}
return NewEntity();
}
static int DeleteOne(
int character_bandolier_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
character_bandolier_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
CharacterBandolier character_bandolier_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[3] + " = " + std::to_string(character_bandolier_entry.item_id));
update_values.push_back(columns[4] + " = " + std::to_string(character_bandolier_entry.icon));
update_values.push_back(columns[5] + " = '" + EscapeString(character_bandolier_entry.bandolier_name) + "'");
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
character_bandolier_entry.bandolier_slot
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static CharacterBandolier InsertOne(
CharacterBandolier character_bandolier_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(character_bandolier_entry.item_id));
insert_values.push_back(std::to_string(character_bandolier_entry.icon));
insert_values.push_back("'" + EscapeString(character_bandolier_entry.bandolier_name) + "'");
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
character_bandolier_entry.id = results.LastInsertedID();
return character_bandolier_entry;
}
character_bandolier_entry = InstanceListRepository::NewEntity();
return character_bandolier_entry;
}
static int InsertMany(
std::vector<CharacterBandolier> character_bandolier_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &character_bandolier_entry: character_bandolier_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(character_bandolier_entry.item_id));
insert_values.push_back(std::to_string(character_bandolier_entry.icon));
insert_values.push_back("'" + EscapeString(character_bandolier_entry.bandolier_name) + "'");
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<CharacterBandolier> All()
{
std::vector<CharacterBandolier> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
CharacterBandolier entry{};
entry.id = atoi(row[0]);
entry.bandolier_id = atoi(row[1]);
entry.bandolier_slot = atoi(row[2]);
entry.item_id = atoi(row[3]);
entry.icon = atoi(row[4]);
entry.bandolier_name = row[5];
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_CHARACTER_BANDOLIER_REPOSITORY_H

View File

@ -0,0 +1,303 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_CHARACTER_BIND_REPOSITORY_H
#define EQEMU_CHARACTER_BIND_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class CharacterBindRepository {
public:
struct CharacterBind {
int id;
int slot;
int16 zone_id;
int instance_id;
std::string x;
std::string y;
std::string z;
std::string heading;
};
static std::string PrimaryKey()
{
return std::string("slot");
}
static std::vector<std::string> Columns()
{
return {
"id",
"slot",
"zone_id",
"instance_id",
"x",
"y",
"z",
"heading",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("character_bind");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static CharacterBind NewEntity()
{
CharacterBind entry{};
entry.id = 0;
entry.slot = 0;
entry.zone_id = 0;
entry.instance_id = 0;
entry.x = 0;
entry.y = 0;
entry.z = 0;
entry.heading = 0;
return entry;
}
static CharacterBind GetCharacterBindEntry(
const std::vector<CharacterBind> &character_binds,
int character_bind_id
)
{
for (auto &character_bind : character_binds) {
if (character_bind.slot == character_bind_id) {
return character_bind;
}
}
return NewEntity();
}
static CharacterBind FindOne(
int character_bind_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
character_bind_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
CharacterBind entry{};
entry.id = atoi(row[0]);
entry.slot = atoi(row[1]);
entry.zone_id = atoi(row[2]);
entry.instance_id = atoi(row[3]);
entry.x = atof(row[4]);
entry.y = atof(row[5]);
entry.z = atof(row[6]);
entry.heading = atof(row[7]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int character_bind_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
character_bind_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
CharacterBind character_bind_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[2] + " = " + std::to_string(character_bind_entry.zone_id));
update_values.push_back(columns[3] + " = " + std::to_string(character_bind_entry.instance_id));
update_values.push_back(columns[4] + " = '" + EscapeString(character_bind_entry.x) + "'");
update_values.push_back(columns[5] + " = '" + EscapeString(character_bind_entry.y) + "'");
update_values.push_back(columns[6] + " = '" + EscapeString(character_bind_entry.z) + "'");
update_values.push_back(columns[7] + " = '" + EscapeString(character_bind_entry.heading) + "'");
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
character_bind_entry.slot
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static CharacterBind InsertOne(
CharacterBind character_bind_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(character_bind_entry.zone_id));
insert_values.push_back(std::to_string(character_bind_entry.instance_id));
insert_values.push_back("'" + EscapeString(character_bind_entry.x) + "'");
insert_values.push_back("'" + EscapeString(character_bind_entry.y) + "'");
insert_values.push_back("'" + EscapeString(character_bind_entry.z) + "'");
insert_values.push_back("'" + EscapeString(character_bind_entry.heading) + "'");
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
character_bind_entry.id = results.LastInsertedID();
return character_bind_entry;
}
character_bind_entry = InstanceListRepository::NewEntity();
return character_bind_entry;
}
static int InsertMany(
std::vector<CharacterBind> character_bind_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &character_bind_entry: character_bind_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(character_bind_entry.zone_id));
insert_values.push_back(std::to_string(character_bind_entry.instance_id));
insert_values.push_back("'" + EscapeString(character_bind_entry.x) + "'");
insert_values.push_back("'" + EscapeString(character_bind_entry.y) + "'");
insert_values.push_back("'" + EscapeString(character_bind_entry.z) + "'");
insert_values.push_back("'" + EscapeString(character_bind_entry.heading) + "'");
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<CharacterBind> All()
{
std::vector<CharacterBind> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
CharacterBind entry{};
entry.id = atoi(row[0]);
entry.slot = atoi(row[1]);
entry.zone_id = atoi(row[2]);
entry.instance_id = atoi(row[3]);
entry.x = atof(row[4]);
entry.y = atof(row[5]);
entry.z = atof(row[6]);
entry.heading = atof(row[7]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_CHARACTER_BIND_REPOSITORY_H

View File

@ -0,0 +1,375 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_CHARACTER_BUFFS_REPOSITORY_H
#define EQEMU_CHARACTER_BUFFS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class CharacterBuffsRepository {
public:
struct CharacterBuffs {
int character_id;
int8 slot_id;
int16 spell_id;
int8 caster_level;
std::string caster_name;
int ticsremaining;
int counters;
int numhits;
int melee_rune;
int magic_rune;
int8 persistent;
int dot_rune;
int caston_x;
int caston_y;
int caston_z;
int ExtraDIChance;
int instrument_mod;
};
static std::string PrimaryKey()
{
return std::string("slot_id");
}
static std::vector<std::string> Columns()
{
return {
"character_id",
"slot_id",
"spell_id",
"caster_level",
"caster_name",
"ticsremaining",
"counters",
"numhits",
"melee_rune",
"magic_rune",
"persistent",
"dot_rune",
"caston_x",
"caston_y",
"caston_z",
"ExtraDIChance",
"instrument_mod",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("character_buffs");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static CharacterBuffs NewEntity()
{
CharacterBuffs entry{};
entry.character_id = 0;
entry.slot_id = 0;
entry.spell_id = 0;
entry.caster_level = 0;
entry.caster_name = 0;
entry.ticsremaining = 0;
entry.counters = 0;
entry.numhits = 0;
entry.melee_rune = 0;
entry.magic_rune = 0;
entry.persistent = 0;
entry.dot_rune = 0;
entry.caston_x = 0;
entry.caston_y = 0;
entry.caston_z = 0;
entry.ExtraDIChance = 0;
entry.instrument_mod = 10;
return entry;
}
static CharacterBuffs GetCharacterBuffsEntry(
const std::vector<CharacterBuffs> &character_buffss,
int character_buffs_id
)
{
for (auto &character_buffs : character_buffss) {
if (character_buffs.slot_id == character_buffs_id) {
return character_buffs;
}
}
return NewEntity();
}
static CharacterBuffs FindOne(
int character_buffs_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
character_buffs_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
CharacterBuffs entry{};
entry.character_id = atoi(row[0]);
entry.slot_id = atoi(row[1]);
entry.spell_id = atoi(row[2]);
entry.caster_level = atoi(row[3]);
entry.caster_name = row[4];
entry.ticsremaining = atoi(row[5]);
entry.counters = atoi(row[6]);
entry.numhits = atoi(row[7]);
entry.melee_rune = atoi(row[8]);
entry.magic_rune = atoi(row[9]);
entry.persistent = atoi(row[10]);
entry.dot_rune = atoi(row[11]);
entry.caston_x = atoi(row[12]);
entry.caston_y = atoi(row[13]);
entry.caston_z = atoi(row[14]);
entry.ExtraDIChance = atoi(row[15]);
entry.instrument_mod = atoi(row[16]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int character_buffs_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
character_buffs_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
CharacterBuffs character_buffs_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[2] + " = " + std::to_string(character_buffs_entry.spell_id));
update_values.push_back(columns[3] + " = " + std::to_string(character_buffs_entry.caster_level));
update_values.push_back(columns[4] + " = '" + EscapeString(character_buffs_entry.caster_name) + "'");
update_values.push_back(columns[5] + " = " + std::to_string(character_buffs_entry.ticsremaining));
update_values.push_back(columns[6] + " = " + std::to_string(character_buffs_entry.counters));
update_values.push_back(columns[7] + " = " + std::to_string(character_buffs_entry.numhits));
update_values.push_back(columns[8] + " = " + std::to_string(character_buffs_entry.melee_rune));
update_values.push_back(columns[9] + " = " + std::to_string(character_buffs_entry.magic_rune));
update_values.push_back(columns[10] + " = " + std::to_string(character_buffs_entry.persistent));
update_values.push_back(columns[11] + " = " + std::to_string(character_buffs_entry.dot_rune));
update_values.push_back(columns[12] + " = " + std::to_string(character_buffs_entry.caston_x));
update_values.push_back(columns[13] + " = " + std::to_string(character_buffs_entry.caston_y));
update_values.push_back(columns[14] + " = " + std::to_string(character_buffs_entry.caston_z));
update_values.push_back(columns[15] + " = " + std::to_string(character_buffs_entry.ExtraDIChance));
update_values.push_back(columns[16] + " = " + std::to_string(character_buffs_entry.instrument_mod));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
character_buffs_entry.slot_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static CharacterBuffs InsertOne(
CharacterBuffs character_buffs_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(character_buffs_entry.spell_id));
insert_values.push_back(std::to_string(character_buffs_entry.caster_level));
insert_values.push_back("'" + EscapeString(character_buffs_entry.caster_name) + "'");
insert_values.push_back(std::to_string(character_buffs_entry.ticsremaining));
insert_values.push_back(std::to_string(character_buffs_entry.counters));
insert_values.push_back(std::to_string(character_buffs_entry.numhits));
insert_values.push_back(std::to_string(character_buffs_entry.melee_rune));
insert_values.push_back(std::to_string(character_buffs_entry.magic_rune));
insert_values.push_back(std::to_string(character_buffs_entry.persistent));
insert_values.push_back(std::to_string(character_buffs_entry.dot_rune));
insert_values.push_back(std::to_string(character_buffs_entry.caston_x));
insert_values.push_back(std::to_string(character_buffs_entry.caston_y));
insert_values.push_back(std::to_string(character_buffs_entry.caston_z));
insert_values.push_back(std::to_string(character_buffs_entry.ExtraDIChance));
insert_values.push_back(std::to_string(character_buffs_entry.instrument_mod));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
character_buffs_entry.id = results.LastInsertedID();
return character_buffs_entry;
}
character_buffs_entry = InstanceListRepository::NewEntity();
return character_buffs_entry;
}
static int InsertMany(
std::vector<CharacterBuffs> character_buffs_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &character_buffs_entry: character_buffs_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(character_buffs_entry.spell_id));
insert_values.push_back(std::to_string(character_buffs_entry.caster_level));
insert_values.push_back("'" + EscapeString(character_buffs_entry.caster_name) + "'");
insert_values.push_back(std::to_string(character_buffs_entry.ticsremaining));
insert_values.push_back(std::to_string(character_buffs_entry.counters));
insert_values.push_back(std::to_string(character_buffs_entry.numhits));
insert_values.push_back(std::to_string(character_buffs_entry.melee_rune));
insert_values.push_back(std::to_string(character_buffs_entry.magic_rune));
insert_values.push_back(std::to_string(character_buffs_entry.persistent));
insert_values.push_back(std::to_string(character_buffs_entry.dot_rune));
insert_values.push_back(std::to_string(character_buffs_entry.caston_x));
insert_values.push_back(std::to_string(character_buffs_entry.caston_y));
insert_values.push_back(std::to_string(character_buffs_entry.caston_z));
insert_values.push_back(std::to_string(character_buffs_entry.ExtraDIChance));
insert_values.push_back(std::to_string(character_buffs_entry.instrument_mod));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<CharacterBuffs> All()
{
std::vector<CharacterBuffs> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
CharacterBuffs entry{};
entry.character_id = atoi(row[0]);
entry.slot_id = atoi(row[1]);
entry.spell_id = atoi(row[2]);
entry.caster_level = atoi(row[3]);
entry.caster_name = row[4];
entry.ticsremaining = atoi(row[5]);
entry.counters = atoi(row[6]);
entry.numhits = atoi(row[7]);
entry.melee_rune = atoi(row[8]);
entry.magic_rune = atoi(row[9]);
entry.persistent = atoi(row[10]);
entry.dot_rune = atoi(row[11]);
entry.caston_x = atoi(row[12]);
entry.caston_y = atoi(row[13]);
entry.caston_z = atoi(row[14]);
entry.ExtraDIChance = atoi(row[15]);
entry.instrument_mod = atoi(row[16]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_CHARACTER_BUFFS_REPOSITORY_H

View File

@ -0,0 +1,327 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_CHARACTER_CORPSE_ITEMS_REPOSITORY_H
#define EQEMU_CHARACTER_CORPSE_ITEMS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class CharacterCorpseItemsRepository {
public:
struct CharacterCorpseItems {
int corpse_id;
int equip_slot;
int item_id;
int charges;
int aug_1;
int aug_2;
int aug_3;
int aug_4;
int aug_5;
int aug_6;
int16 attuned;
};
static std::string PrimaryKey()
{
return std::string("equip_slot");
}
static std::vector<std::string> Columns()
{
return {
"corpse_id",
"equip_slot",
"item_id",
"charges",
"aug_1",
"aug_2",
"aug_3",
"aug_4",
"aug_5",
"aug_6",
"attuned",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("character_corpse_items");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static CharacterCorpseItems NewEntity()
{
CharacterCorpseItems entry{};
entry.corpse_id = 0;
entry.equip_slot = 0;
entry.item_id = 0;
entry.charges = 0;
entry.aug_1 = 0;
entry.aug_2 = 0;
entry.aug_3 = 0;
entry.aug_4 = 0;
entry.aug_5 = 0;
entry.aug_6 = 0;
entry.attuned = 0;
return entry;
}
static CharacterCorpseItems GetCharacterCorpseItemsEntry(
const std::vector<CharacterCorpseItems> &character_corpse_itemss,
int character_corpse_items_id
)
{
for (auto &character_corpse_items : character_corpse_itemss) {
if (character_corpse_items.equip_slot == character_corpse_items_id) {
return character_corpse_items;
}
}
return NewEntity();
}
static CharacterCorpseItems FindOne(
int character_corpse_items_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
character_corpse_items_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
CharacterCorpseItems entry{};
entry.corpse_id = atoi(row[0]);
entry.equip_slot = atoi(row[1]);
entry.item_id = atoi(row[2]);
entry.charges = atoi(row[3]);
entry.aug_1 = atoi(row[4]);
entry.aug_2 = atoi(row[5]);
entry.aug_3 = atoi(row[6]);
entry.aug_4 = atoi(row[7]);
entry.aug_5 = atoi(row[8]);
entry.aug_6 = atoi(row[9]);
entry.attuned = atoi(row[10]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int character_corpse_items_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
character_corpse_items_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
CharacterCorpseItems character_corpse_items_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[2] + " = " + std::to_string(character_corpse_items_entry.item_id));
update_values.push_back(columns[3] + " = " + std::to_string(character_corpse_items_entry.charges));
update_values.push_back(columns[4] + " = " + std::to_string(character_corpse_items_entry.aug_1));
update_values.push_back(columns[5] + " = " + std::to_string(character_corpse_items_entry.aug_2));
update_values.push_back(columns[6] + " = " + std::to_string(character_corpse_items_entry.aug_3));
update_values.push_back(columns[7] + " = " + std::to_string(character_corpse_items_entry.aug_4));
update_values.push_back(columns[8] + " = " + std::to_string(character_corpse_items_entry.aug_5));
update_values.push_back(columns[9] + " = " + std::to_string(character_corpse_items_entry.aug_6));
update_values.push_back(columns[10] + " = " + std::to_string(character_corpse_items_entry.attuned));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
character_corpse_items_entry.equip_slot
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static CharacterCorpseItems InsertOne(
CharacterCorpseItems character_corpse_items_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(character_corpse_items_entry.item_id));
insert_values.push_back(std::to_string(character_corpse_items_entry.charges));
insert_values.push_back(std::to_string(character_corpse_items_entry.aug_1));
insert_values.push_back(std::to_string(character_corpse_items_entry.aug_2));
insert_values.push_back(std::to_string(character_corpse_items_entry.aug_3));
insert_values.push_back(std::to_string(character_corpse_items_entry.aug_4));
insert_values.push_back(std::to_string(character_corpse_items_entry.aug_5));
insert_values.push_back(std::to_string(character_corpse_items_entry.aug_6));
insert_values.push_back(std::to_string(character_corpse_items_entry.attuned));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
character_corpse_items_entry.id = results.LastInsertedID();
return character_corpse_items_entry;
}
character_corpse_items_entry = InstanceListRepository::NewEntity();
return character_corpse_items_entry;
}
static int InsertMany(
std::vector<CharacterCorpseItems> character_corpse_items_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &character_corpse_items_entry: character_corpse_items_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(character_corpse_items_entry.item_id));
insert_values.push_back(std::to_string(character_corpse_items_entry.charges));
insert_values.push_back(std::to_string(character_corpse_items_entry.aug_1));
insert_values.push_back(std::to_string(character_corpse_items_entry.aug_2));
insert_values.push_back(std::to_string(character_corpse_items_entry.aug_3));
insert_values.push_back(std::to_string(character_corpse_items_entry.aug_4));
insert_values.push_back(std::to_string(character_corpse_items_entry.aug_5));
insert_values.push_back(std::to_string(character_corpse_items_entry.aug_6));
insert_values.push_back(std::to_string(character_corpse_items_entry.attuned));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<CharacterCorpseItems> All()
{
std::vector<CharacterCorpseItems> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
CharacterCorpseItems entry{};
entry.corpse_id = atoi(row[0]);
entry.equip_slot = atoi(row[1]);
entry.item_id = atoi(row[2]);
entry.charges = atoi(row[3]);
entry.aug_1 = atoi(row[4]);
entry.aug_2 = atoi(row[5]);
entry.aug_3 = atoi(row[6]);
entry.aug_4 = atoi(row[7]);
entry.aug_5 = atoi(row[8]);
entry.aug_6 = atoi(row[9]);
entry.attuned = atoi(row[10]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_CHARACTER_CORPSE_ITEMS_REPOSITORY_H

View File

@ -0,0 +1,618 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_CHARACTER_CORPSES_REPOSITORY_H
#define EQEMU_CHARACTER_CORPSES_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class CharacterCorpsesRepository {
public:
struct CharacterCorpses {
int id;
int charid;
std::string charname;
int16 zone_id;
int16 instance_id;
std::string x;
std::string y;
std::string z;
std::string heading;
std::string time_of_death;
int guild_consent_id;
int8 is_rezzed;
int8 is_buried;
int8 was_at_graveyard;
int8 is_locked;
int exp;
int size;
int level;
int race;
int gender;
int class;
int deity;
int texture;
int helm_texture;
int copper;
int silver;
int gold;
int platinum;
int hair_color;
int beard_color;
int eye_color_1;
int eye_color_2;
int hair_style;
int face;
int beard;
int drakkin_heritage;
int drakkin_tattoo;
int drakkin_details;
int wc_1;
int wc_2;
int wc_3;
int wc_4;
int wc_5;
int wc_6;
int wc_7;
int wc_8;
int wc_9;
};
static std::string PrimaryKey()
{
return std::string("id");
}
static std::vector<std::string> Columns()
{
return {
"id",
"charid",
"charname",
"zone_id",
"instance_id",
"x",
"y",
"z",
"heading",
"time_of_death",
"guild_consent_id",
"is_rezzed",
"is_buried",
"was_at_graveyard",
"is_locked",
"exp",
"size",
"level",
"race",
"gender",
"class",
"deity",
"texture",
"helm_texture",
"copper",
"silver",
"gold",
"platinum",
"hair_color",
"beard_color",
"eye_color_1",
"eye_color_2",
"hair_style",
"face",
"beard",
"drakkin_heritage",
"drakkin_tattoo",
"drakkin_details",
"wc_1",
"wc_2",
"wc_3",
"wc_4",
"wc_5",
"wc_6",
"wc_7",
"wc_8",
"wc_9",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("character_corpses");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static CharacterCorpses NewEntity()
{
CharacterCorpses entry{};
entry.id = 0;
entry.charid = 0;
entry.charname = "";
entry.zone_id = 0;
entry.instance_id = 0;
entry.x = 0;
entry.y = 0;
entry.z = 0;
entry.heading = 0;
entry.time_of_death = '0000-00-00 00:00:00';
entry.guild_consent_id = 0;
entry.is_rezzed = 0;
entry.is_buried = 0;
entry.was_at_graveyard = 0;
entry.is_locked = 0;
entry.exp = 0;
entry.size = 0;
entry.level = 0;
entry.race = 0;
entry.gender = 0;
entry.class = 0;
entry.deity = 0;
entry.texture = 0;
entry.helm_texture = 0;
entry.copper = 0;
entry.silver = 0;
entry.gold = 0;
entry.platinum = 0;
entry.hair_color = 0;
entry.beard_color = 0;
entry.eye_color_1 = 0;
entry.eye_color_2 = 0;
entry.hair_style = 0;
entry.face = 0;
entry.beard = 0;
entry.drakkin_heritage = 0;
entry.drakkin_tattoo = 0;
entry.drakkin_details = 0;
entry.wc_1 = 0;
entry.wc_2 = 0;
entry.wc_3 = 0;
entry.wc_4 = 0;
entry.wc_5 = 0;
entry.wc_6 = 0;
entry.wc_7 = 0;
entry.wc_8 = 0;
entry.wc_9 = 0;
return entry;
}
static CharacterCorpses GetCharacterCorpsesEntry(
const std::vector<CharacterCorpses> &character_corpsess,
int character_corpses_id
)
{
for (auto &character_corpses : character_corpsess) {
if (character_corpses.id == character_corpses_id) {
return character_corpses;
}
}
return NewEntity();
}
static CharacterCorpses FindOne(
int character_corpses_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
character_corpses_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
CharacterCorpses entry{};
entry.id = atoi(row[0]);
entry.charid = atoi(row[1]);
entry.charname = row[2];
entry.zone_id = atoi(row[3]);
entry.instance_id = atoi(row[4]);
entry.x = atof(row[5]);
entry.y = atof(row[6]);
entry.z = atof(row[7]);
entry.heading = atof(row[8]);
entry.time_of_death = row[9];
entry.guild_consent_id = atoi(row[10]);
entry.is_rezzed = atoi(row[11]);
entry.is_buried = atoi(row[12]);
entry.was_at_graveyard = atoi(row[13]);
entry.is_locked = atoi(row[14]);
entry.exp = atoi(row[15]);
entry.size = atoi(row[16]);
entry.level = atoi(row[17]);
entry.race = atoi(row[18]);
entry.gender = atoi(row[19]);
entry.class = atoi(row[20]);
entry.deity = atoi(row[21]);
entry.texture = atoi(row[22]);
entry.helm_texture = atoi(row[23]);
entry.copper = atoi(row[24]);
entry.silver = atoi(row[25]);
entry.gold = atoi(row[26]);
entry.platinum = atoi(row[27]);
entry.hair_color = atoi(row[28]);
entry.beard_color = atoi(row[29]);
entry.eye_color_1 = atoi(row[30]);
entry.eye_color_2 = atoi(row[31]);
entry.hair_style = atoi(row[32]);
entry.face = atoi(row[33]);
entry.beard = atoi(row[34]);
entry.drakkin_heritage = atoi(row[35]);
entry.drakkin_tattoo = atoi(row[36]);
entry.drakkin_details = atoi(row[37]);
entry.wc_1 = atoi(row[38]);
entry.wc_2 = atoi(row[39]);
entry.wc_3 = atoi(row[40]);
entry.wc_4 = atoi(row[41]);
entry.wc_5 = atoi(row[42]);
entry.wc_6 = atoi(row[43]);
entry.wc_7 = atoi(row[44]);
entry.wc_8 = atoi(row[45]);
entry.wc_9 = atoi(row[46]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int character_corpses_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
character_corpses_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
CharacterCorpses character_corpses_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[1] + " = " + std::to_string(character_corpses_entry.charid));
update_values.push_back(columns[2] + " = '" + EscapeString(character_corpses_entry.charname) + "'");
update_values.push_back(columns[3] + " = " + std::to_string(character_corpses_entry.zone_id));
update_values.push_back(columns[4] + " = " + std::to_string(character_corpses_entry.instance_id));
update_values.push_back(columns[5] + " = '" + EscapeString(character_corpses_entry.x) + "'");
update_values.push_back(columns[6] + " = '" + EscapeString(character_corpses_entry.y) + "'");
update_values.push_back(columns[7] + " = '" + EscapeString(character_corpses_entry.z) + "'");
update_values.push_back(columns[8] + " = '" + EscapeString(character_corpses_entry.heading) + "'");
update_values.push_back(columns[9] + " = '" + EscapeString(character_corpses_entry.time_of_death) + "'");
update_values.push_back(columns[10] + " = " + std::to_string(character_corpses_entry.guild_consent_id));
update_values.push_back(columns[11] + " = " + std::to_string(character_corpses_entry.is_rezzed));
update_values.push_back(columns[12] + " = " + std::to_string(character_corpses_entry.is_buried));
update_values.push_back(columns[13] + " = " + std::to_string(character_corpses_entry.was_at_graveyard));
update_values.push_back(columns[14] + " = " + std::to_string(character_corpses_entry.is_locked));
update_values.push_back(columns[15] + " = " + std::to_string(character_corpses_entry.exp));
update_values.push_back(columns[16] + " = " + std::to_string(character_corpses_entry.size));
update_values.push_back(columns[17] + " = " + std::to_string(character_corpses_entry.level));
update_values.push_back(columns[18] + " = " + std::to_string(character_corpses_entry.race));
update_values.push_back(columns[19] + " = " + std::to_string(character_corpses_entry.gender));
update_values.push_back(columns[20] + " = " + std::to_string(character_corpses_entry.class));
update_values.push_back(columns[21] + " = " + std::to_string(character_corpses_entry.deity));
update_values.push_back(columns[22] + " = " + std::to_string(character_corpses_entry.texture));
update_values.push_back(columns[23] + " = " + std::to_string(character_corpses_entry.helm_texture));
update_values.push_back(columns[24] + " = " + std::to_string(character_corpses_entry.copper));
update_values.push_back(columns[25] + " = " + std::to_string(character_corpses_entry.silver));
update_values.push_back(columns[26] + " = " + std::to_string(character_corpses_entry.gold));
update_values.push_back(columns[27] + " = " + std::to_string(character_corpses_entry.platinum));
update_values.push_back(columns[28] + " = " + std::to_string(character_corpses_entry.hair_color));
update_values.push_back(columns[29] + " = " + std::to_string(character_corpses_entry.beard_color));
update_values.push_back(columns[30] + " = " + std::to_string(character_corpses_entry.eye_color_1));
update_values.push_back(columns[31] + " = " + std::to_string(character_corpses_entry.eye_color_2));
update_values.push_back(columns[32] + " = " + std::to_string(character_corpses_entry.hair_style));
update_values.push_back(columns[33] + " = " + std::to_string(character_corpses_entry.face));
update_values.push_back(columns[34] + " = " + std::to_string(character_corpses_entry.beard));
update_values.push_back(columns[35] + " = " + std::to_string(character_corpses_entry.drakkin_heritage));
update_values.push_back(columns[36] + " = " + std::to_string(character_corpses_entry.drakkin_tattoo));
update_values.push_back(columns[37] + " = " + std::to_string(character_corpses_entry.drakkin_details));
update_values.push_back(columns[38] + " = " + std::to_string(character_corpses_entry.wc_1));
update_values.push_back(columns[39] + " = " + std::to_string(character_corpses_entry.wc_2));
update_values.push_back(columns[40] + " = " + std::to_string(character_corpses_entry.wc_3));
update_values.push_back(columns[41] + " = " + std::to_string(character_corpses_entry.wc_4));
update_values.push_back(columns[42] + " = " + std::to_string(character_corpses_entry.wc_5));
update_values.push_back(columns[43] + " = " + std::to_string(character_corpses_entry.wc_6));
update_values.push_back(columns[44] + " = " + std::to_string(character_corpses_entry.wc_7));
update_values.push_back(columns[45] + " = " + std::to_string(character_corpses_entry.wc_8));
update_values.push_back(columns[46] + " = " + std::to_string(character_corpses_entry.wc_9));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
character_corpses_entry.id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static CharacterCorpses InsertOne(
CharacterCorpses character_corpses_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(character_corpses_entry.charid));
insert_values.push_back("'" + EscapeString(character_corpses_entry.charname) + "'");
insert_values.push_back(std::to_string(character_corpses_entry.zone_id));
insert_values.push_back(std::to_string(character_corpses_entry.instance_id));
insert_values.push_back("'" + EscapeString(character_corpses_entry.x) + "'");
insert_values.push_back("'" + EscapeString(character_corpses_entry.y) + "'");
insert_values.push_back("'" + EscapeString(character_corpses_entry.z) + "'");
insert_values.push_back("'" + EscapeString(character_corpses_entry.heading) + "'");
insert_values.push_back("'" + EscapeString(character_corpses_entry.time_of_death) + "'");
insert_values.push_back(std::to_string(character_corpses_entry.guild_consent_id));
insert_values.push_back(std::to_string(character_corpses_entry.is_rezzed));
insert_values.push_back(std::to_string(character_corpses_entry.is_buried));
insert_values.push_back(std::to_string(character_corpses_entry.was_at_graveyard));
insert_values.push_back(std::to_string(character_corpses_entry.is_locked));
insert_values.push_back(std::to_string(character_corpses_entry.exp));
insert_values.push_back(std::to_string(character_corpses_entry.size));
insert_values.push_back(std::to_string(character_corpses_entry.level));
insert_values.push_back(std::to_string(character_corpses_entry.race));
insert_values.push_back(std::to_string(character_corpses_entry.gender));
insert_values.push_back(std::to_string(character_corpses_entry.class));
insert_values.push_back(std::to_string(character_corpses_entry.deity));
insert_values.push_back(std::to_string(character_corpses_entry.texture));
insert_values.push_back(std::to_string(character_corpses_entry.helm_texture));
insert_values.push_back(std::to_string(character_corpses_entry.copper));
insert_values.push_back(std::to_string(character_corpses_entry.silver));
insert_values.push_back(std::to_string(character_corpses_entry.gold));
insert_values.push_back(std::to_string(character_corpses_entry.platinum));
insert_values.push_back(std::to_string(character_corpses_entry.hair_color));
insert_values.push_back(std::to_string(character_corpses_entry.beard_color));
insert_values.push_back(std::to_string(character_corpses_entry.eye_color_1));
insert_values.push_back(std::to_string(character_corpses_entry.eye_color_2));
insert_values.push_back(std::to_string(character_corpses_entry.hair_style));
insert_values.push_back(std::to_string(character_corpses_entry.face));
insert_values.push_back(std::to_string(character_corpses_entry.beard));
insert_values.push_back(std::to_string(character_corpses_entry.drakkin_heritage));
insert_values.push_back(std::to_string(character_corpses_entry.drakkin_tattoo));
insert_values.push_back(std::to_string(character_corpses_entry.drakkin_details));
insert_values.push_back(std::to_string(character_corpses_entry.wc_1));
insert_values.push_back(std::to_string(character_corpses_entry.wc_2));
insert_values.push_back(std::to_string(character_corpses_entry.wc_3));
insert_values.push_back(std::to_string(character_corpses_entry.wc_4));
insert_values.push_back(std::to_string(character_corpses_entry.wc_5));
insert_values.push_back(std::to_string(character_corpses_entry.wc_6));
insert_values.push_back(std::to_string(character_corpses_entry.wc_7));
insert_values.push_back(std::to_string(character_corpses_entry.wc_8));
insert_values.push_back(std::to_string(character_corpses_entry.wc_9));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
character_corpses_entry.id = results.LastInsertedID();
return character_corpses_entry;
}
character_corpses_entry = InstanceListRepository::NewEntity();
return character_corpses_entry;
}
static int InsertMany(
std::vector<CharacterCorpses> character_corpses_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &character_corpses_entry: character_corpses_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(character_corpses_entry.charid));
insert_values.push_back("'" + EscapeString(character_corpses_entry.charname) + "'");
insert_values.push_back(std::to_string(character_corpses_entry.zone_id));
insert_values.push_back(std::to_string(character_corpses_entry.instance_id));
insert_values.push_back("'" + EscapeString(character_corpses_entry.x) + "'");
insert_values.push_back("'" + EscapeString(character_corpses_entry.y) + "'");
insert_values.push_back("'" + EscapeString(character_corpses_entry.z) + "'");
insert_values.push_back("'" + EscapeString(character_corpses_entry.heading) + "'");
insert_values.push_back("'" + EscapeString(character_corpses_entry.time_of_death) + "'");
insert_values.push_back(std::to_string(character_corpses_entry.guild_consent_id));
insert_values.push_back(std::to_string(character_corpses_entry.is_rezzed));
insert_values.push_back(std::to_string(character_corpses_entry.is_buried));
insert_values.push_back(std::to_string(character_corpses_entry.was_at_graveyard));
insert_values.push_back(std::to_string(character_corpses_entry.is_locked));
insert_values.push_back(std::to_string(character_corpses_entry.exp));
insert_values.push_back(std::to_string(character_corpses_entry.size));
insert_values.push_back(std::to_string(character_corpses_entry.level));
insert_values.push_back(std::to_string(character_corpses_entry.race));
insert_values.push_back(std::to_string(character_corpses_entry.gender));
insert_values.push_back(std::to_string(character_corpses_entry.class));
insert_values.push_back(std::to_string(character_corpses_entry.deity));
insert_values.push_back(std::to_string(character_corpses_entry.texture));
insert_values.push_back(std::to_string(character_corpses_entry.helm_texture));
insert_values.push_back(std::to_string(character_corpses_entry.copper));
insert_values.push_back(std::to_string(character_corpses_entry.silver));
insert_values.push_back(std::to_string(character_corpses_entry.gold));
insert_values.push_back(std::to_string(character_corpses_entry.platinum));
insert_values.push_back(std::to_string(character_corpses_entry.hair_color));
insert_values.push_back(std::to_string(character_corpses_entry.beard_color));
insert_values.push_back(std::to_string(character_corpses_entry.eye_color_1));
insert_values.push_back(std::to_string(character_corpses_entry.eye_color_2));
insert_values.push_back(std::to_string(character_corpses_entry.hair_style));
insert_values.push_back(std::to_string(character_corpses_entry.face));
insert_values.push_back(std::to_string(character_corpses_entry.beard));
insert_values.push_back(std::to_string(character_corpses_entry.drakkin_heritage));
insert_values.push_back(std::to_string(character_corpses_entry.drakkin_tattoo));
insert_values.push_back(std::to_string(character_corpses_entry.drakkin_details));
insert_values.push_back(std::to_string(character_corpses_entry.wc_1));
insert_values.push_back(std::to_string(character_corpses_entry.wc_2));
insert_values.push_back(std::to_string(character_corpses_entry.wc_3));
insert_values.push_back(std::to_string(character_corpses_entry.wc_4));
insert_values.push_back(std::to_string(character_corpses_entry.wc_5));
insert_values.push_back(std::to_string(character_corpses_entry.wc_6));
insert_values.push_back(std::to_string(character_corpses_entry.wc_7));
insert_values.push_back(std::to_string(character_corpses_entry.wc_8));
insert_values.push_back(std::to_string(character_corpses_entry.wc_9));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<CharacterCorpses> All()
{
std::vector<CharacterCorpses> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
CharacterCorpses entry{};
entry.id = atoi(row[0]);
entry.charid = atoi(row[1]);
entry.charname = row[2];
entry.zone_id = atoi(row[3]);
entry.instance_id = atoi(row[4]);
entry.x = atof(row[5]);
entry.y = atof(row[6]);
entry.z = atof(row[7]);
entry.heading = atof(row[8]);
entry.time_of_death = row[9];
entry.guild_consent_id = atoi(row[10]);
entry.is_rezzed = atoi(row[11]);
entry.is_buried = atoi(row[12]);
entry.was_at_graveyard = atoi(row[13]);
entry.is_locked = atoi(row[14]);
entry.exp = atoi(row[15]);
entry.size = atoi(row[16]);
entry.level = atoi(row[17]);
entry.race = atoi(row[18]);
entry.gender = atoi(row[19]);
entry.class = atoi(row[20]);
entry.deity = atoi(row[21]);
entry.texture = atoi(row[22]);
entry.helm_texture = atoi(row[23]);
entry.copper = atoi(row[24]);
entry.silver = atoi(row[25]);
entry.gold = atoi(row[26]);
entry.platinum = atoi(row[27]);
entry.hair_color = atoi(row[28]);
entry.beard_color = atoi(row[29]);
entry.eye_color_1 = atoi(row[30]);
entry.eye_color_2 = atoi(row[31]);
entry.hair_style = atoi(row[32]);
entry.face = atoi(row[33]);
entry.beard = atoi(row[34]);
entry.drakkin_heritage = atoi(row[35]);
entry.drakkin_tattoo = atoi(row[36]);
entry.drakkin_details = atoi(row[37]);
entry.wc_1 = atoi(row[38]);
entry.wc_2 = atoi(row[39]);
entry.wc_3 = atoi(row[40]);
entry.wc_4 = atoi(row[41]);
entry.wc_5 = atoi(row[42]);
entry.wc_6 = atoi(row[43]);
entry.wc_7 = atoi(row[44]);
entry.wc_8 = atoi(row[45]);
entry.wc_9 = atoi(row[46]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_CHARACTER_CORPSES_REPOSITORY_H

View File

@ -0,0 +1,378 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_CHARACTER_CURRENCY_REPOSITORY_H
#define EQEMU_CHARACTER_CURRENCY_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class CharacterCurrencyRepository {
public:
struct CharacterCurrency {
int id;
int platinum;
int gold;
int silver;
int copper;
int platinum_bank;
int gold_bank;
int silver_bank;
int copper_bank;
int platinum_cursor;
int gold_cursor;
int silver_cursor;
int copper_cursor;
int radiant_crystals;
int career_radiant_crystals;
int ebon_crystals;
int career_ebon_crystals;
};
static std::string PrimaryKey()
{
return std::string("id");
}
static std::vector<std::string> Columns()
{
return {
"id",
"platinum",
"gold",
"silver",
"copper",
"platinum_bank",
"gold_bank",
"silver_bank",
"copper_bank",
"platinum_cursor",
"gold_cursor",
"silver_cursor",
"copper_cursor",
"radiant_crystals",
"career_radiant_crystals",
"ebon_crystals",
"career_ebon_crystals",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("character_currency");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static CharacterCurrency NewEntity()
{
CharacterCurrency entry{};
entry.id = 0;
entry.platinum = 0;
entry.gold = 0;
entry.silver = 0;
entry.copper = 0;
entry.platinum_bank = 0;
entry.gold_bank = 0;
entry.silver_bank = 0;
entry.copper_bank = 0;
entry.platinum_cursor = 0;
entry.gold_cursor = 0;
entry.silver_cursor = 0;
entry.copper_cursor = 0;
entry.radiant_crystals = 0;
entry.career_radiant_crystals = 0;
entry.ebon_crystals = 0;
entry.career_ebon_crystals = 0;
return entry;
}
static CharacterCurrency GetCharacterCurrencyEntry(
const std::vector<CharacterCurrency> &character_currencys,
int character_currency_id
)
{
for (auto &character_currency : character_currencys) {
if (character_currency.id == character_currency_id) {
return character_currency;
}
}
return NewEntity();
}
static CharacterCurrency FindOne(
int character_currency_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
character_currency_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
CharacterCurrency entry{};
entry.id = atoi(row[0]);
entry.platinum = atoi(row[1]);
entry.gold = atoi(row[2]);
entry.silver = atoi(row[3]);
entry.copper = atoi(row[4]);
entry.platinum_bank = atoi(row[5]);
entry.gold_bank = atoi(row[6]);
entry.silver_bank = atoi(row[7]);
entry.copper_bank = atoi(row[8]);
entry.platinum_cursor = atoi(row[9]);
entry.gold_cursor = atoi(row[10]);
entry.silver_cursor = atoi(row[11]);
entry.copper_cursor = atoi(row[12]);
entry.radiant_crystals = atoi(row[13]);
entry.career_radiant_crystals = atoi(row[14]);
entry.ebon_crystals = atoi(row[15]);
entry.career_ebon_crystals = atoi(row[16]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int character_currency_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
character_currency_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
CharacterCurrency character_currency_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[1] + " = " + std::to_string(character_currency_entry.platinum));
update_values.push_back(columns[2] + " = " + std::to_string(character_currency_entry.gold));
update_values.push_back(columns[3] + " = " + std::to_string(character_currency_entry.silver));
update_values.push_back(columns[4] + " = " + std::to_string(character_currency_entry.copper));
update_values.push_back(columns[5] + " = " + std::to_string(character_currency_entry.platinum_bank));
update_values.push_back(columns[6] + " = " + std::to_string(character_currency_entry.gold_bank));
update_values.push_back(columns[7] + " = " + std::to_string(character_currency_entry.silver_bank));
update_values.push_back(columns[8] + " = " + std::to_string(character_currency_entry.copper_bank));
update_values.push_back(columns[9] + " = " + std::to_string(character_currency_entry.platinum_cursor));
update_values.push_back(columns[10] + " = " + std::to_string(character_currency_entry.gold_cursor));
update_values.push_back(columns[11] + " = " + std::to_string(character_currency_entry.silver_cursor));
update_values.push_back(columns[12] + " = " + std::to_string(character_currency_entry.copper_cursor));
update_values.push_back(columns[13] + " = " + std::to_string(character_currency_entry.radiant_crystals));
update_values.push_back(columns[14] + " = " + std::to_string(character_currency_entry.career_radiant_crystals));
update_values.push_back(columns[15] + " = " + std::to_string(character_currency_entry.ebon_crystals));
update_values.push_back(columns[16] + " = " + std::to_string(character_currency_entry.career_ebon_crystals));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
character_currency_entry.id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static CharacterCurrency InsertOne(
CharacterCurrency character_currency_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(character_currency_entry.platinum));
insert_values.push_back(std::to_string(character_currency_entry.gold));
insert_values.push_back(std::to_string(character_currency_entry.silver));
insert_values.push_back(std::to_string(character_currency_entry.copper));
insert_values.push_back(std::to_string(character_currency_entry.platinum_bank));
insert_values.push_back(std::to_string(character_currency_entry.gold_bank));
insert_values.push_back(std::to_string(character_currency_entry.silver_bank));
insert_values.push_back(std::to_string(character_currency_entry.copper_bank));
insert_values.push_back(std::to_string(character_currency_entry.platinum_cursor));
insert_values.push_back(std::to_string(character_currency_entry.gold_cursor));
insert_values.push_back(std::to_string(character_currency_entry.silver_cursor));
insert_values.push_back(std::to_string(character_currency_entry.copper_cursor));
insert_values.push_back(std::to_string(character_currency_entry.radiant_crystals));
insert_values.push_back(std::to_string(character_currency_entry.career_radiant_crystals));
insert_values.push_back(std::to_string(character_currency_entry.ebon_crystals));
insert_values.push_back(std::to_string(character_currency_entry.career_ebon_crystals));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
character_currency_entry.id = results.LastInsertedID();
return character_currency_entry;
}
character_currency_entry = InstanceListRepository::NewEntity();
return character_currency_entry;
}
static int InsertMany(
std::vector<CharacterCurrency> character_currency_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &character_currency_entry: character_currency_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(character_currency_entry.platinum));
insert_values.push_back(std::to_string(character_currency_entry.gold));
insert_values.push_back(std::to_string(character_currency_entry.silver));
insert_values.push_back(std::to_string(character_currency_entry.copper));
insert_values.push_back(std::to_string(character_currency_entry.platinum_bank));
insert_values.push_back(std::to_string(character_currency_entry.gold_bank));
insert_values.push_back(std::to_string(character_currency_entry.silver_bank));
insert_values.push_back(std::to_string(character_currency_entry.copper_bank));
insert_values.push_back(std::to_string(character_currency_entry.platinum_cursor));
insert_values.push_back(std::to_string(character_currency_entry.gold_cursor));
insert_values.push_back(std::to_string(character_currency_entry.silver_cursor));
insert_values.push_back(std::to_string(character_currency_entry.copper_cursor));
insert_values.push_back(std::to_string(character_currency_entry.radiant_crystals));
insert_values.push_back(std::to_string(character_currency_entry.career_radiant_crystals));
insert_values.push_back(std::to_string(character_currency_entry.ebon_crystals));
insert_values.push_back(std::to_string(character_currency_entry.career_ebon_crystals));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<CharacterCurrency> All()
{
std::vector<CharacterCurrency> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
CharacterCurrency entry{};
entry.id = atoi(row[0]);
entry.platinum = atoi(row[1]);
entry.gold = atoi(row[2]);
entry.silver = atoi(row[3]);
entry.copper = atoi(row[4]);
entry.platinum_bank = atoi(row[5]);
entry.gold_bank = atoi(row[6]);
entry.silver_bank = atoi(row[7]);
entry.copper_bank = atoi(row[8]);
entry.platinum_cursor = atoi(row[9]);
entry.gold_cursor = atoi(row[10]);
entry.silver_cursor = atoi(row[11]);
entry.copper_cursor = atoi(row[12]);
entry.radiant_crystals = atoi(row[13]);
entry.career_radiant_crystals = atoi(row[14]);
entry.ebon_crystals = atoi(row[15]);
entry.career_ebon_crystals = atoi(row[16]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_CHARACTER_CURRENCY_REPOSITORY_H

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,263 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_CHARACTER_DISCIPLINES_REPOSITORY_H
#define EQEMU_CHARACTER_DISCIPLINES_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class CharacterDisciplinesRepository {
public:
struct CharacterDisciplines {
int id;
int16 slot_id;
int16 disc_id;
};
static std::string PrimaryKey()
{
return std::string("slot_id");
}
static std::vector<std::string> Columns()
{
return {
"id",
"slot_id",
"disc_id",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("character_disciplines");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static CharacterDisciplines NewEntity()
{
CharacterDisciplines entry{};
entry.id = 0;
entry.slot_id = 0;
entry.disc_id = 0;
return entry;
}
static CharacterDisciplines GetCharacterDisciplinesEntry(
const std::vector<CharacterDisciplines> &character_discipliness,
int character_disciplines_id
)
{
for (auto &character_disciplines : character_discipliness) {
if (character_disciplines.slot_id == character_disciplines_id) {
return character_disciplines;
}
}
return NewEntity();
}
static CharacterDisciplines FindOne(
int character_disciplines_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
character_disciplines_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
CharacterDisciplines entry{};
entry.id = atoi(row[0]);
entry.slot_id = atoi(row[1]);
entry.disc_id = atoi(row[2]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int character_disciplines_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
character_disciplines_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
CharacterDisciplines character_disciplines_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[2] + " = " + std::to_string(character_disciplines_entry.disc_id));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
character_disciplines_entry.slot_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static CharacterDisciplines InsertOne(
CharacterDisciplines character_disciplines_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(character_disciplines_entry.disc_id));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
character_disciplines_entry.id = results.LastInsertedID();
return character_disciplines_entry;
}
character_disciplines_entry = InstanceListRepository::NewEntity();
return character_disciplines_entry;
}
static int InsertMany(
std::vector<CharacterDisciplines> character_disciplines_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &character_disciplines_entry: character_disciplines_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(character_disciplines_entry.disc_id));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<CharacterDisciplines> All()
{
std::vector<CharacterDisciplines> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
CharacterDisciplines entry{};
entry.id = atoi(row[0]);
entry.slot_id = atoi(row[1]);
entry.disc_id = atoi(row[2]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_CHARACTER_DISCIPLINES_REPOSITORY_H

View File

@ -0,0 +1,255 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_CHARACTER_ENABLEDTASKS_REPOSITORY_H
#define EQEMU_CHARACTER_ENABLEDTASKS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class CharacterEnabledtasksRepository {
public:
struct CharacterEnabledtasks {
int charid;
int taskid;
};
static std::string PrimaryKey()
{
return std::string("taskid");
}
static std::vector<std::string> Columns()
{
return {
"charid",
"taskid",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("character_enabledtasks");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static CharacterEnabledtasks NewEntity()
{
CharacterEnabledtasks entry{};
entry.charid = 0;
entry.taskid = 0;
return entry;
}
static CharacterEnabledtasks GetCharacterEnabledtasksEntry(
const std::vector<CharacterEnabledtasks> &character_enabledtaskss,
int character_enabledtasks_id
)
{
for (auto &character_enabledtasks : character_enabledtaskss) {
if (character_enabledtasks.taskid == character_enabledtasks_id) {
return character_enabledtasks;
}
}
return NewEntity();
}
static CharacterEnabledtasks FindOne(
int character_enabledtasks_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
character_enabledtasks_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
CharacterEnabledtasks entry{};
entry.charid = atoi(row[0]);
entry.taskid = atoi(row[1]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int character_enabledtasks_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
character_enabledtasks_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
CharacterEnabledtasks character_enabledtasks_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
character_enabledtasks_entry.taskid
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static CharacterEnabledtasks InsertOne(
CharacterEnabledtasks character_enabledtasks_entry
)
{
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
character_enabledtasks_entry.id = results.LastInsertedID();
return character_enabledtasks_entry;
}
character_enabledtasks_entry = InstanceListRepository::NewEntity();
return character_enabledtasks_entry;
}
static int InsertMany(
std::vector<CharacterEnabledtasks> character_enabledtasks_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &character_enabledtasks_entry: character_enabledtasks_entries) {
std::vector<std::string> insert_values;
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<CharacterEnabledtasks> All()
{
std::vector<CharacterEnabledtasks> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
CharacterEnabledtasks entry{};
entry.charid = atoi(row[0]);
entry.taskid = atoi(row[1]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_CHARACTER_ENABLEDTASKS_REPOSITORY_H

View File

@ -0,0 +1,260 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_CHARACTER_INSPECT_MESSAGES_REPOSITORY_H
#define EQEMU_CHARACTER_INSPECT_MESSAGES_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class CharacterInspectMessagesRepository {
public:
struct CharacterInspectMessages {
int id;
std::string inspect_message;
};
static std::string PrimaryKey()
{
return std::string("id");
}
static std::vector<std::string> Columns()
{
return {
"id",
"inspect_message",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("character_inspect_messages");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static CharacterInspectMessages NewEntity()
{
CharacterInspectMessages entry{};
entry.id = 0;
entry.inspect_message = "";
return entry;
}
static CharacterInspectMessages GetCharacterInspectMessagesEntry(
const std::vector<CharacterInspectMessages> &character_inspect_messagess,
int character_inspect_messages_id
)
{
for (auto &character_inspect_messages : character_inspect_messagess) {
if (character_inspect_messages.id == character_inspect_messages_id) {
return character_inspect_messages;
}
}
return NewEntity();
}
static CharacterInspectMessages FindOne(
int character_inspect_messages_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
character_inspect_messages_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
CharacterInspectMessages entry{};
entry.id = atoi(row[0]);
entry.inspect_message = row[1];
return entry;
}
return NewEntity();
}
static int DeleteOne(
int character_inspect_messages_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
character_inspect_messages_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
CharacterInspectMessages character_inspect_messages_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(
columns[1] + " = '" + EscapeString(character_inspect_messages_entry.inspect_message) + "'"
);
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
character_inspect_messages_entry.id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static CharacterInspectMessages InsertOne(
CharacterInspectMessages character_inspect_messages_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(character_inspect_messages_entry.inspect_message) + "'");
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
character_inspect_messages_entry.id = results.LastInsertedID();
return character_inspect_messages_entry;
}
character_inspect_messages_entry = InstanceListRepository::NewEntity();
return character_inspect_messages_entry;
}
static int InsertMany(
std::vector<CharacterInspectMessages> character_inspect_messages_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &character_inspect_messages_entry: character_inspect_messages_entries) {
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(character_inspect_messages_entry.inspect_message) + "'");
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<CharacterInspectMessages> All()
{
std::vector<CharacterInspectMessages> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
CharacterInspectMessages entry{};
entry.id = atoi(row[0]);
entry.inspect_message = row[1];
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_CHARACTER_INSPECT_MESSAGES_REPOSITORY_H

View File

@ -0,0 +1,263 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_CHARACTER_ITEM_RECAST_REPOSITORY_H
#define EQEMU_CHARACTER_ITEM_RECAST_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class CharacterItemRecastRepository {
public:
struct CharacterItemRecast {
int id;
int16 recast_type;
int timestamp;
};
static std::string PrimaryKey()
{
return std::string("recast_type");
}
static std::vector<std::string> Columns()
{
return {
"id",
"recast_type",
"timestamp",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("character_item_recast");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static CharacterItemRecast NewEntity()
{
CharacterItemRecast entry{};
entry.id = 0;
entry.recast_type = 0;
entry.timestamp = 0;
return entry;
}
static CharacterItemRecast GetCharacterItemRecastEntry(
const std::vector<CharacterItemRecast> &character_item_recasts,
int character_item_recast_id
)
{
for (auto &character_item_recast : character_item_recasts) {
if (character_item_recast.recast_type == character_item_recast_id) {
return character_item_recast;
}
}
return NewEntity();
}
static CharacterItemRecast FindOne(
int character_item_recast_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
character_item_recast_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
CharacterItemRecast entry{};
entry.id = atoi(row[0]);
entry.recast_type = atoi(row[1]);
entry.timestamp = atoi(row[2]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int character_item_recast_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
character_item_recast_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
CharacterItemRecast character_item_recast_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[2] + " = " + std::to_string(character_item_recast_entry.timestamp));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
character_item_recast_entry.recast_type
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static CharacterItemRecast InsertOne(
CharacterItemRecast character_item_recast_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(character_item_recast_entry.timestamp));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
character_item_recast_entry.id = results.LastInsertedID();
return character_item_recast_entry;
}
character_item_recast_entry = InstanceListRepository::NewEntity();
return character_item_recast_entry;
}
static int InsertMany(
std::vector<CharacterItemRecast> character_item_recast_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &character_item_recast_entry: character_item_recast_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(character_item_recast_entry.timestamp));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<CharacterItemRecast> All()
{
std::vector<CharacterItemRecast> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
CharacterItemRecast entry{};
entry.id = atoi(row[0]);
entry.recast_type = atoi(row[1]);
entry.timestamp = atoi(row[2]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_CHARACTER_ITEM_RECAST_REPOSITORY_H

View File

@ -0,0 +1,263 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_CHARACTER_LANGUAGES_REPOSITORY_H
#define EQEMU_CHARACTER_LANGUAGES_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class CharacterLanguagesRepository {
public:
struct CharacterLanguages {
int id;
int16 lang_id;
int16 value;
};
static std::string PrimaryKey()
{
return std::string("lang_id");
}
static std::vector<std::string> Columns()
{
return {
"id",
"lang_id",
"value",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("character_languages");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static CharacterLanguages NewEntity()
{
CharacterLanguages entry{};
entry.id = 0;
entry.lang_id = 0;
entry.value = 0;
return entry;
}
static CharacterLanguages GetCharacterLanguagesEntry(
const std::vector<CharacterLanguages> &character_languagess,
int character_languages_id
)
{
for (auto &character_languages : character_languagess) {
if (character_languages.lang_id == character_languages_id) {
return character_languages;
}
}
return NewEntity();
}
static CharacterLanguages FindOne(
int character_languages_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
character_languages_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
CharacterLanguages entry{};
entry.id = atoi(row[0]);
entry.lang_id = atoi(row[1]);
entry.value = atoi(row[2]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int character_languages_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
character_languages_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
CharacterLanguages character_languages_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[2] + " = " + std::to_string(character_languages_entry.value));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
character_languages_entry.lang_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static CharacterLanguages InsertOne(
CharacterLanguages character_languages_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(character_languages_entry.value));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
character_languages_entry.id = results.LastInsertedID();
return character_languages_entry;
}
character_languages_entry = InstanceListRepository::NewEntity();
return character_languages_entry;
}
static int InsertMany(
std::vector<CharacterLanguages> character_languages_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &character_languages_entry: character_languages_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(character_languages_entry.value));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<CharacterLanguages> All()
{
std::vector<CharacterLanguages> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
CharacterLanguages entry{};
entry.id = atoi(row[0]);
entry.lang_id = atoi(row[1]);
entry.value = atoi(row[2]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_CHARACTER_LANGUAGES_REPOSITORY_H

View File

@ -0,0 +1,263 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_CHARACTER_LEADERSHIP_ABILITIES_REPOSITORY_H
#define EQEMU_CHARACTER_LEADERSHIP_ABILITIES_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class CharacterLeadershipAbilitiesRepository {
public:
struct CharacterLeadershipAbilities {
int id;
int16 slot;
int16 rank;
};
static std::string PrimaryKey()
{
return std::string("slot");
}
static std::vector<std::string> Columns()
{
return {
"id",
"slot",
"rank",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("character_leadership_abilities");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static CharacterLeadershipAbilities NewEntity()
{
CharacterLeadershipAbilities entry{};
entry.id = 0;
entry.slot = 0;
entry.rank = 0;
return entry;
}
static CharacterLeadershipAbilities GetCharacterLeadershipAbilitiesEntry(
const std::vector<CharacterLeadershipAbilities> &character_leadership_abilitiess,
int character_leadership_abilities_id
)
{
for (auto &character_leadership_abilities : character_leadership_abilitiess) {
if (character_leadership_abilities.slot == character_leadership_abilities_id) {
return character_leadership_abilities;
}
}
return NewEntity();
}
static CharacterLeadershipAbilities FindOne(
int character_leadership_abilities_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
character_leadership_abilities_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
CharacterLeadershipAbilities entry{};
entry.id = atoi(row[0]);
entry.slot = atoi(row[1]);
entry.rank = atoi(row[2]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int character_leadership_abilities_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
character_leadership_abilities_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
CharacterLeadershipAbilities character_leadership_abilities_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[2] + " = " + std::to_string(character_leadership_abilities_entry.rank));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
character_leadership_abilities_entry.slot
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static CharacterLeadershipAbilities InsertOne(
CharacterLeadershipAbilities character_leadership_abilities_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(character_leadership_abilities_entry.rank));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
character_leadership_abilities_entry.id = results.LastInsertedID();
return character_leadership_abilities_entry;
}
character_leadership_abilities_entry = InstanceListRepository::NewEntity();
return character_leadership_abilities_entry;
}
static int InsertMany(
std::vector<CharacterLeadershipAbilities> character_leadership_abilities_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &character_leadership_abilities_entry: character_leadership_abilities_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(character_leadership_abilities_entry.rank));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<CharacterLeadershipAbilities> All()
{
std::vector<CharacterLeadershipAbilities> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
CharacterLeadershipAbilities entry{};
entry.id = atoi(row[0]);
entry.slot = atoi(row[1]);
entry.rank = atoi(row[2]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_CHARACTER_LEADERSHIP_ABILITIES_REPOSITORY_H

View File

@ -0,0 +1,295 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_CHARACTER_MATERIAL_REPOSITORY_H
#define EQEMU_CHARACTER_MATERIAL_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class CharacterMaterialRepository {
public:
struct CharacterMaterial {
int id;
int8 slot;
int8 blue;
int8 green;
int8 red;
int8 use_tint;
int color;
};
static std::string PrimaryKey()
{
return std::string("slot");
}
static std::vector<std::string> Columns()
{
return {
"id",
"slot",
"blue",
"green",
"red",
"use_tint",
"color",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("character_material");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static CharacterMaterial NewEntity()
{
CharacterMaterial entry{};
entry.id = 0;
entry.slot = 0;
entry.blue = 0;
entry.green = 0;
entry.red = 0;
entry.use_tint = 0;
entry.color = 0;
return entry;
}
static CharacterMaterial GetCharacterMaterialEntry(
const std::vector<CharacterMaterial> &character_materials,
int character_material_id
)
{
for (auto &character_material : character_materials) {
if (character_material.slot == character_material_id) {
return character_material;
}
}
return NewEntity();
}
static CharacterMaterial FindOne(
int character_material_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
character_material_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
CharacterMaterial entry{};
entry.id = atoi(row[0]);
entry.slot = atoi(row[1]);
entry.blue = atoi(row[2]);
entry.green = atoi(row[3]);
entry.red = atoi(row[4]);
entry.use_tint = atoi(row[5]);
entry.color = atoi(row[6]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int character_material_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
character_material_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
CharacterMaterial character_material_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[2] + " = " + std::to_string(character_material_entry.blue));
update_values.push_back(columns[3] + " = " + std::to_string(character_material_entry.green));
update_values.push_back(columns[4] + " = " + std::to_string(character_material_entry.red));
update_values.push_back(columns[5] + " = " + std::to_string(character_material_entry.use_tint));
update_values.push_back(columns[6] + " = " + std::to_string(character_material_entry.color));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
character_material_entry.slot
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static CharacterMaterial InsertOne(
CharacterMaterial character_material_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(character_material_entry.blue));
insert_values.push_back(std::to_string(character_material_entry.green));
insert_values.push_back(std::to_string(character_material_entry.red));
insert_values.push_back(std::to_string(character_material_entry.use_tint));
insert_values.push_back(std::to_string(character_material_entry.color));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
character_material_entry.id = results.LastInsertedID();
return character_material_entry;
}
character_material_entry = InstanceListRepository::NewEntity();
return character_material_entry;
}
static int InsertMany(
std::vector<CharacterMaterial> character_material_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &character_material_entry: character_material_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(character_material_entry.blue));
insert_values.push_back(std::to_string(character_material_entry.green));
insert_values.push_back(std::to_string(character_material_entry.red));
insert_values.push_back(std::to_string(character_material_entry.use_tint));
insert_values.push_back(std::to_string(character_material_entry.color));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<CharacterMaterial> All()
{
std::vector<CharacterMaterial> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
CharacterMaterial entry{};
entry.id = atoi(row[0]);
entry.slot = atoi(row[1]);
entry.blue = atoi(row[2]);
entry.green = atoi(row[3]);
entry.red = atoi(row[4]);
entry.use_tint = atoi(row[5]);
entry.color = atoi(row[6]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_CHARACTER_MATERIAL_REPOSITORY_H

View File

@ -0,0 +1,263 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_CHARACTER_MEMMED_SPELLS_REPOSITORY_H
#define EQEMU_CHARACTER_MEMMED_SPELLS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class CharacterMemmedSpellsRepository {
public:
struct CharacterMemmedSpells {
int id;
int16 slot_id;
int16 spell_id;
};
static std::string PrimaryKey()
{
return std::string("slot_id");
}
static std::vector<std::string> Columns()
{
return {
"id",
"slot_id",
"spell_id",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("character_memmed_spells");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static CharacterMemmedSpells NewEntity()
{
CharacterMemmedSpells entry{};
entry.id = 0;
entry.slot_id = 0;
entry.spell_id = 0;
return entry;
}
static CharacterMemmedSpells GetCharacterMemmedSpellsEntry(
const std::vector<CharacterMemmedSpells> &character_memmed_spellss,
int character_memmed_spells_id
)
{
for (auto &character_memmed_spells : character_memmed_spellss) {
if (character_memmed_spells.slot_id == character_memmed_spells_id) {
return character_memmed_spells;
}
}
return NewEntity();
}
static CharacterMemmedSpells FindOne(
int character_memmed_spells_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
character_memmed_spells_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
CharacterMemmedSpells entry{};
entry.id = atoi(row[0]);
entry.slot_id = atoi(row[1]);
entry.spell_id = atoi(row[2]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int character_memmed_spells_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
character_memmed_spells_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
CharacterMemmedSpells character_memmed_spells_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[2] + " = " + std::to_string(character_memmed_spells_entry.spell_id));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
character_memmed_spells_entry.slot_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static CharacterMemmedSpells InsertOne(
CharacterMemmedSpells character_memmed_spells_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(character_memmed_spells_entry.spell_id));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
character_memmed_spells_entry.id = results.LastInsertedID();
return character_memmed_spells_entry;
}
character_memmed_spells_entry = InstanceListRepository::NewEntity();
return character_memmed_spells_entry;
}
static int InsertMany(
std::vector<CharacterMemmedSpells> character_memmed_spells_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &character_memmed_spells_entry: character_memmed_spells_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(character_memmed_spells_entry.spell_id));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<CharacterMemmedSpells> All()
{
std::vector<CharacterMemmedSpells> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
CharacterMemmedSpells entry{};
entry.id = atoi(row[0]);
entry.slot_id = atoi(row[1]);
entry.spell_id = atoi(row[2]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_CHARACTER_MEMMED_SPELLS_REPOSITORY_H

View File

@ -0,0 +1,324 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_CHARACTER_PET_BUFFS_REPOSITORY_H
#define EQEMU_CHARACTER_PET_BUFFS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class CharacterPetBuffsRepository {
public:
struct CharacterPetBuffs {
int char_id;
int pet;
int slot;
int spell_id;
int8 caster_level;
std::string castername;
int ticsremaining;
int counters;
int numhits;
int rune;
int8 instrument_mod;
};
static std::string PrimaryKey()
{
return std::string("slot");
}
static std::vector<std::string> Columns()
{
return {
"char_id",
"pet",
"slot",
"spell_id",
"caster_level",
"castername",
"ticsremaining",
"counters",
"numhits",
"rune",
"instrument_mod",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("character_pet_buffs");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static CharacterPetBuffs NewEntity()
{
CharacterPetBuffs entry{};
entry.char_id = 0;
entry.pet = 0;
entry.slot = 0;
entry.spell_id = 0;
entry.caster_level = 0;
entry.castername = "";
entry.ticsremaining = 0;
entry.counters = 0;
entry.numhits = 0;
entry.rune = 0;
entry.instrument_mod = 10;
return entry;
}
static CharacterPetBuffs GetCharacterPetBuffsEntry(
const std::vector<CharacterPetBuffs> &character_pet_buffss,
int character_pet_buffs_id
)
{
for (auto &character_pet_buffs : character_pet_buffss) {
if (character_pet_buffs.slot == character_pet_buffs_id) {
return character_pet_buffs;
}
}
return NewEntity();
}
static CharacterPetBuffs FindOne(
int character_pet_buffs_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
character_pet_buffs_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
CharacterPetBuffs entry{};
entry.char_id = atoi(row[0]);
entry.pet = atoi(row[1]);
entry.slot = atoi(row[2]);
entry.spell_id = atoi(row[3]);
entry.caster_level = atoi(row[4]);
entry.castername = row[5];
entry.ticsremaining = atoi(row[6]);
entry.counters = atoi(row[7]);
entry.numhits = atoi(row[8]);
entry.rune = atoi(row[9]);
entry.instrument_mod = atoi(row[10]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int character_pet_buffs_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
character_pet_buffs_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
CharacterPetBuffs character_pet_buffs_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[3] + " = " + std::to_string(character_pet_buffs_entry.spell_id));
update_values.push_back(columns[4] + " = " + std::to_string(character_pet_buffs_entry.caster_level));
update_values.push_back(columns[5] + " = '" + EscapeString(character_pet_buffs_entry.castername) + "'");
update_values.push_back(columns[6] + " = " + std::to_string(character_pet_buffs_entry.ticsremaining));
update_values.push_back(columns[7] + " = " + std::to_string(character_pet_buffs_entry.counters));
update_values.push_back(columns[8] + " = " + std::to_string(character_pet_buffs_entry.numhits));
update_values.push_back(columns[9] + " = " + std::to_string(character_pet_buffs_entry.rune));
update_values.push_back(columns[10] + " = " + std::to_string(character_pet_buffs_entry.instrument_mod));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
character_pet_buffs_entry.slot
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static CharacterPetBuffs InsertOne(
CharacterPetBuffs character_pet_buffs_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(character_pet_buffs_entry.spell_id));
insert_values.push_back(std::to_string(character_pet_buffs_entry.caster_level));
insert_values.push_back("'" + EscapeString(character_pet_buffs_entry.castername) + "'");
insert_values.push_back(std::to_string(character_pet_buffs_entry.ticsremaining));
insert_values.push_back(std::to_string(character_pet_buffs_entry.counters));
insert_values.push_back(std::to_string(character_pet_buffs_entry.numhits));
insert_values.push_back(std::to_string(character_pet_buffs_entry.rune));
insert_values.push_back(std::to_string(character_pet_buffs_entry.instrument_mod));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
character_pet_buffs_entry.id = results.LastInsertedID();
return character_pet_buffs_entry;
}
character_pet_buffs_entry = InstanceListRepository::NewEntity();
return character_pet_buffs_entry;
}
static int InsertMany(
std::vector<CharacterPetBuffs> character_pet_buffs_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &character_pet_buffs_entry: character_pet_buffs_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(character_pet_buffs_entry.spell_id));
insert_values.push_back(std::to_string(character_pet_buffs_entry.caster_level));
insert_values.push_back("'" + EscapeString(character_pet_buffs_entry.castername) + "'");
insert_values.push_back(std::to_string(character_pet_buffs_entry.ticsremaining));
insert_values.push_back(std::to_string(character_pet_buffs_entry.counters));
insert_values.push_back(std::to_string(character_pet_buffs_entry.numhits));
insert_values.push_back(std::to_string(character_pet_buffs_entry.rune));
insert_values.push_back(std::to_string(character_pet_buffs_entry.instrument_mod));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<CharacterPetBuffs> All()
{
std::vector<CharacterPetBuffs> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
CharacterPetBuffs entry{};
entry.char_id = atoi(row[0]);
entry.pet = atoi(row[1]);
entry.slot = atoi(row[2]);
entry.spell_id = atoi(row[3]);
entry.caster_level = atoi(row[4]);
entry.castername = row[5];
entry.ticsremaining = atoi(row[6]);
entry.counters = atoi(row[7]);
entry.numhits = atoi(row[8]);
entry.rune = atoi(row[9]);
entry.instrument_mod = atoi(row[10]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_CHARACTER_PET_BUFFS_REPOSITORY_H

View File

@ -0,0 +1,303 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_CHARACTER_PET_INFO_REPOSITORY_H
#define EQEMU_CHARACTER_PET_INFO_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class CharacterPetInfoRepository {
public:
struct CharacterPetInfo {
int char_id;
int pet;
std::string petname;
int petpower;
int spell_id;
int hp;
int mana;
std::string size;
};
static std::string PrimaryKey()
{
return std::string("pet");
}
static std::vector<std::string> Columns()
{
return {
"char_id",
"pet",
"petname",
"petpower",
"spell_id",
"hp",
"mana",
"size",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("character_pet_info");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static CharacterPetInfo NewEntity()
{
CharacterPetInfo entry{};
entry.char_id = 0;
entry.pet = 0;
entry.petname = "";
entry.petpower = 0;
entry.spell_id = 0;
entry.hp = 0;
entry.mana = 0;
entry.size = 0;
return entry;
}
static CharacterPetInfo GetCharacterPetInfoEntry(
const std::vector<CharacterPetInfo> &character_pet_infos,
int character_pet_info_id
)
{
for (auto &character_pet_info : character_pet_infos) {
if (character_pet_info.pet == character_pet_info_id) {
return character_pet_info;
}
}
return NewEntity();
}
static CharacterPetInfo FindOne(
int character_pet_info_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
character_pet_info_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
CharacterPetInfo entry{};
entry.char_id = atoi(row[0]);
entry.pet = atoi(row[1]);
entry.petname = row[2];
entry.petpower = atoi(row[3]);
entry.spell_id = atoi(row[4]);
entry.hp = atoi(row[5]);
entry.mana = atoi(row[6]);
entry.size = atof(row[7]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int character_pet_info_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
character_pet_info_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
CharacterPetInfo character_pet_info_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[2] + " = '" + EscapeString(character_pet_info_entry.petname) + "'");
update_values.push_back(columns[3] + " = " + std::to_string(character_pet_info_entry.petpower));
update_values.push_back(columns[4] + " = " + std::to_string(character_pet_info_entry.spell_id));
update_values.push_back(columns[5] + " = " + std::to_string(character_pet_info_entry.hp));
update_values.push_back(columns[6] + " = " + std::to_string(character_pet_info_entry.mana));
update_values.push_back(columns[7] + " = '" + EscapeString(character_pet_info_entry.size) + "'");
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
character_pet_info_entry.pet
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static CharacterPetInfo InsertOne(
CharacterPetInfo character_pet_info_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(character_pet_info_entry.petname) + "'");
insert_values.push_back(std::to_string(character_pet_info_entry.petpower));
insert_values.push_back(std::to_string(character_pet_info_entry.spell_id));
insert_values.push_back(std::to_string(character_pet_info_entry.hp));
insert_values.push_back(std::to_string(character_pet_info_entry.mana));
insert_values.push_back("'" + EscapeString(character_pet_info_entry.size) + "'");
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
character_pet_info_entry.id = results.LastInsertedID();
return character_pet_info_entry;
}
character_pet_info_entry = InstanceListRepository::NewEntity();
return character_pet_info_entry;
}
static int InsertMany(
std::vector<CharacterPetInfo> character_pet_info_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &character_pet_info_entry: character_pet_info_entries) {
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(character_pet_info_entry.petname) + "'");
insert_values.push_back(std::to_string(character_pet_info_entry.petpower));
insert_values.push_back(std::to_string(character_pet_info_entry.spell_id));
insert_values.push_back(std::to_string(character_pet_info_entry.hp));
insert_values.push_back(std::to_string(character_pet_info_entry.mana));
insert_values.push_back("'" + EscapeString(character_pet_info_entry.size) + "'");
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<CharacterPetInfo> All()
{
std::vector<CharacterPetInfo> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
CharacterPetInfo entry{};
entry.char_id = atoi(row[0]);
entry.pet = atoi(row[1]);
entry.petname = row[2];
entry.petpower = atoi(row[3]);
entry.spell_id = atoi(row[4]);
entry.hp = atoi(row[5]);
entry.mana = atoi(row[6]);
entry.size = atof(row[7]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_CHARACTER_PET_INFO_REPOSITORY_H

View File

@ -0,0 +1,268 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_CHARACTER_PET_INVENTORY_REPOSITORY_H
#define EQEMU_CHARACTER_PET_INVENTORY_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class CharacterPetInventoryRepository {
public:
struct CharacterPetInventory {
int char_id;
int pet;
int slot;
int item_id;
};
static std::string PrimaryKey()
{
return std::string("slot");
}
static std::vector<std::string> Columns()
{
return {
"char_id",
"pet",
"slot",
"item_id",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("character_pet_inventory");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static CharacterPetInventory NewEntity()
{
CharacterPetInventory entry{};
entry.char_id = 0;
entry.pet = 0;
entry.slot = 0;
entry.item_id = 0;
return entry;
}
static CharacterPetInventory GetCharacterPetInventoryEntry(
const std::vector<CharacterPetInventory> &character_pet_inventorys,
int character_pet_inventory_id
)
{
for (auto &character_pet_inventory : character_pet_inventorys) {
if (character_pet_inventory.slot == character_pet_inventory_id) {
return character_pet_inventory;
}
}
return NewEntity();
}
static CharacterPetInventory FindOne(
int character_pet_inventory_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
character_pet_inventory_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
CharacterPetInventory entry{};
entry.char_id = atoi(row[0]);
entry.pet = atoi(row[1]);
entry.slot = atoi(row[2]);
entry.item_id = atoi(row[3]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int character_pet_inventory_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
character_pet_inventory_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
CharacterPetInventory character_pet_inventory_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[3] + " = " + std::to_string(character_pet_inventory_entry.item_id));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
character_pet_inventory_entry.slot
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static CharacterPetInventory InsertOne(
CharacterPetInventory character_pet_inventory_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(character_pet_inventory_entry.item_id));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
character_pet_inventory_entry.id = results.LastInsertedID();
return character_pet_inventory_entry;
}
character_pet_inventory_entry = InstanceListRepository::NewEntity();
return character_pet_inventory_entry;
}
static int InsertMany(
std::vector<CharacterPetInventory> character_pet_inventory_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &character_pet_inventory_entry: character_pet_inventory_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(character_pet_inventory_entry.item_id));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<CharacterPetInventory> All()
{
std::vector<CharacterPetInventory> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
CharacterPetInventory entry{};
entry.char_id = atoi(row[0]);
entry.pet = atoi(row[1]);
entry.slot = atoi(row[2]);
entry.item_id = atoi(row[3]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_CHARACTER_PET_INVENTORY_REPOSITORY_H

View File

@ -0,0 +1,271 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_CHARACTER_POTIONBELT_REPOSITORY_H
#define EQEMU_CHARACTER_POTIONBELT_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class CharacterPotionbeltRepository {
public:
struct CharacterPotionbelt {
int id;
int8 potion_id;
int item_id;
int icon;
};
static std::string PrimaryKey()
{
return std::string("potion_id");
}
static std::vector<std::string> Columns()
{
return {
"id",
"potion_id",
"item_id",
"icon",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("character_potionbelt");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static CharacterPotionbelt NewEntity()
{
CharacterPotionbelt entry{};
entry.id = 0;
entry.potion_id = 0;
entry.item_id = 0;
entry.icon = 0;
return entry;
}
static CharacterPotionbelt GetCharacterPotionbeltEntry(
const std::vector<CharacterPotionbelt> &character_potionbelts,
int character_potionbelt_id
)
{
for (auto &character_potionbelt : character_potionbelts) {
if (character_potionbelt.potion_id == character_potionbelt_id) {
return character_potionbelt;
}
}
return NewEntity();
}
static CharacterPotionbelt FindOne(
int character_potionbelt_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
character_potionbelt_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
CharacterPotionbelt entry{};
entry.id = atoi(row[0]);
entry.potion_id = atoi(row[1]);
entry.item_id = atoi(row[2]);
entry.icon = atoi(row[3]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int character_potionbelt_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
character_potionbelt_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
CharacterPotionbelt character_potionbelt_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[2] + " = " + std::to_string(character_potionbelt_entry.item_id));
update_values.push_back(columns[3] + " = " + std::to_string(character_potionbelt_entry.icon));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
character_potionbelt_entry.potion_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static CharacterPotionbelt InsertOne(
CharacterPotionbelt character_potionbelt_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(character_potionbelt_entry.item_id));
insert_values.push_back(std::to_string(character_potionbelt_entry.icon));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
character_potionbelt_entry.id = results.LastInsertedID();
return character_potionbelt_entry;
}
character_potionbelt_entry = InstanceListRepository::NewEntity();
return character_potionbelt_entry;
}
static int InsertMany(
std::vector<CharacterPotionbelt> character_potionbelt_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &character_potionbelt_entry: character_potionbelt_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(character_potionbelt_entry.item_id));
insert_values.push_back(std::to_string(character_potionbelt_entry.icon));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<CharacterPotionbelt> All()
{
std::vector<CharacterPotionbelt> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
CharacterPotionbelt entry{};
entry.id = atoi(row[0]);
entry.potion_id = atoi(row[1]);
entry.item_id = atoi(row[2]);
entry.icon = atoi(row[3]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_CHARACTER_POTIONBELT_REPOSITORY_H

View File

@ -0,0 +1,263 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_CHARACTER_SKILLS_REPOSITORY_H
#define EQEMU_CHARACTER_SKILLS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class CharacterSkillsRepository {
public:
struct CharacterSkills {
int id;
int16 skill_id;
int16 value;
};
static std::string PrimaryKey()
{
return std::string("skill_id");
}
static std::vector<std::string> Columns()
{
return {
"id",
"skill_id",
"value",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("character_skills");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static CharacterSkills NewEntity()
{
CharacterSkills entry{};
entry.id = 0;
entry.skill_id = 0;
entry.value = 0;
return entry;
}
static CharacterSkills GetCharacterSkillsEntry(
const std::vector<CharacterSkills> &character_skillss,
int character_skills_id
)
{
for (auto &character_skills : character_skillss) {
if (character_skills.skill_id == character_skills_id) {
return character_skills;
}
}
return NewEntity();
}
static CharacterSkills FindOne(
int character_skills_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
character_skills_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
CharacterSkills entry{};
entry.id = atoi(row[0]);
entry.skill_id = atoi(row[1]);
entry.value = atoi(row[2]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int character_skills_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
character_skills_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
CharacterSkills character_skills_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[2] + " = " + std::to_string(character_skills_entry.value));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
character_skills_entry.skill_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static CharacterSkills InsertOne(
CharacterSkills character_skills_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(character_skills_entry.value));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
character_skills_entry.id = results.LastInsertedID();
return character_skills_entry;
}
character_skills_entry = InstanceListRepository::NewEntity();
return character_skills_entry;
}
static int InsertMany(
std::vector<CharacterSkills> character_skills_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &character_skills_entry: character_skills_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(character_skills_entry.value));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<CharacterSkills> All()
{
std::vector<CharacterSkills> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
CharacterSkills entry{};
entry.id = atoi(row[0]);
entry.skill_id = atoi(row[1]);
entry.value = atoi(row[2]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_CHARACTER_SKILLS_REPOSITORY_H

View File

@ -0,0 +1,263 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_CHARACTER_SPELLS_REPOSITORY_H
#define EQEMU_CHARACTER_SPELLS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class CharacterSpellsRepository {
public:
struct CharacterSpells {
int id;
int16 slot_id;
int16 spell_id;
};
static std::string PrimaryKey()
{
return std::string("slot_id");
}
static std::vector<std::string> Columns()
{
return {
"id",
"slot_id",
"spell_id",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("character_spells");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static CharacterSpells NewEntity()
{
CharacterSpells entry{};
entry.id = 0;
entry.slot_id = 0;
entry.spell_id = 0;
return entry;
}
static CharacterSpells GetCharacterSpellsEntry(
const std::vector<CharacterSpells> &character_spellss,
int character_spells_id
)
{
for (auto &character_spells : character_spellss) {
if (character_spells.slot_id == character_spells_id) {
return character_spells;
}
}
return NewEntity();
}
static CharacterSpells FindOne(
int character_spells_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
character_spells_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
CharacterSpells entry{};
entry.id = atoi(row[0]);
entry.slot_id = atoi(row[1]);
entry.spell_id = atoi(row[2]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int character_spells_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
character_spells_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
CharacterSpells character_spells_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[2] + " = " + std::to_string(character_spells_entry.spell_id));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
character_spells_entry.slot_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static CharacterSpells InsertOne(
CharacterSpells character_spells_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(character_spells_entry.spell_id));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
character_spells_entry.id = results.LastInsertedID();
return character_spells_entry;
}
character_spells_entry = InstanceListRepository::NewEntity();
return character_spells_entry;
}
static int InsertMany(
std::vector<CharacterSpells> character_spells_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &character_spells_entry: character_spells_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(character_spells_entry.spell_id));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<CharacterSpells> All()
{
std::vector<CharacterSpells> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
CharacterSpells entry{};
entry.id = atoi(row[0]);
entry.slot_id = atoi(row[1]);
entry.spell_id = atoi(row[2]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_CHARACTER_SPELLS_REPOSITORY_H

View File

@ -0,0 +1,279 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_CHARACTER_TASKS_REPOSITORY_H
#define EQEMU_CHARACTER_TASKS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class CharacterTasksRepository {
public:
struct CharacterTasks {
int charid;
int taskid;
int slot;
int8 type;
int acceptedtime;
};
static std::string PrimaryKey()
{
return std::string("taskid");
}
static std::vector<std::string> Columns()
{
return {
"charid",
"taskid",
"slot",
"type",
"acceptedtime",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("character_tasks");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static CharacterTasks NewEntity()
{
CharacterTasks entry{};
entry.charid = 0;
entry.taskid = 0;
entry.slot = 0;
entry.type = 0;
entry.acceptedtime = 0;
return entry;
}
static CharacterTasks GetCharacterTasksEntry(
const std::vector<CharacterTasks> &character_taskss,
int character_tasks_id
)
{
for (auto &character_tasks : character_taskss) {
if (character_tasks.taskid == character_tasks_id) {
return character_tasks;
}
}
return NewEntity();
}
static CharacterTasks FindOne(
int character_tasks_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
character_tasks_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
CharacterTasks entry{};
entry.charid = atoi(row[0]);
entry.taskid = atoi(row[1]);
entry.slot = atoi(row[2]);
entry.type = atoi(row[3]);
entry.acceptedtime = atoi(row[4]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int character_tasks_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
character_tasks_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
CharacterTasks character_tasks_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[2] + " = " + std::to_string(character_tasks_entry.slot));
update_values.push_back(columns[3] + " = " + std::to_string(character_tasks_entry.type));
update_values.push_back(columns[4] + " = " + std::to_string(character_tasks_entry.acceptedtime));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
character_tasks_entry.taskid
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static CharacterTasks InsertOne(
CharacterTasks character_tasks_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(character_tasks_entry.slot));
insert_values.push_back(std::to_string(character_tasks_entry.type));
insert_values.push_back(std::to_string(character_tasks_entry.acceptedtime));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
character_tasks_entry.id = results.LastInsertedID();
return character_tasks_entry;
}
character_tasks_entry = InstanceListRepository::NewEntity();
return character_tasks_entry;
}
static int InsertMany(
std::vector<CharacterTasks> character_tasks_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &character_tasks_entry: character_tasks_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(character_tasks_entry.slot));
insert_values.push_back(std::to_string(character_tasks_entry.type));
insert_values.push_back(std::to_string(character_tasks_entry.acceptedtime));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<CharacterTasks> All()
{
std::vector<CharacterTasks> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
CharacterTasks entry{};
entry.charid = atoi(row[0]);
entry.taskid = atoi(row[1]);
entry.slot = atoi(row[2]);
entry.type = atoi(row[3]);
entry.acceptedtime = atoi(row[4]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_CHARACTER_TASKS_REPOSITORY_H

View File

@ -0,0 +1,269 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_CHARACTER_TRIBUTE_REPOSITORY_H
#define EQEMU_CHARACTER_TRIBUTE_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class CharacterTributeRepository {
public:
struct CharacterTribute {
int id;
int8 tier;
int tribute;
};
static std::string PrimaryKey()
{
return std::string("");
}
static std::vector<std::string> Columns()
{
return {
"id",
"tier",
"tribute",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("character_tribute");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static CharacterTribute NewEntity()
{
CharacterTribute entry{};
entry.id = 0;
entry.tier = 0;
entry.tribute = 0;
return entry;
}
static CharacterTribute GetCharacterTributeEntry(
const std::vector<CharacterTribute> &character_tributes,
int character_tribute_id
)
{
for (auto &character_tribute : character_tributes) {
if (character_tribute.== character_tribute_id) {
return character_tribute;
}
}
return NewEntity();
}
static CharacterTribute FindOne(
int character_tribute_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
character_tribute_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
CharacterTribute entry{};
entry.id = atoi(row[0]);
entry.tier = atoi(row[1]);
entry.tribute = atoi(row[2]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int character_tribute_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
character_tribute_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
CharacterTribute character_tribute_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[0] + " = " + std::to_string(character_tribute_entry.id));
update_values.push_back(columns[1] + " = " + std::to_string(character_tribute_entry.tier));
update_values.push_back(columns[2] + " = " + std::to_string(character_tribute_entry.tribute));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
character_tribute_entry.
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static CharacterTribute InsertOne(
CharacterTribute character_tribute_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(character_tribute_entry.id));
insert_values.push_back(std::to_string(character_tribute_entry.tier));
insert_values.push_back(std::to_string(character_tribute_entry.tribute));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
character_tribute_entry.id = results.LastInsertedID();
return character_tribute_entry;
}
character_tribute_entry = InstanceListRepository::NewEntity();
return character_tribute_entry;
}
static int InsertMany(
std::vector<CharacterTribute> character_tribute_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &character_tribute_entry: character_tribute_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(character_tribute_entry.id));
insert_values.push_back(std::to_string(character_tribute_entry.tier));
insert_values.push_back(std::to_string(character_tribute_entry.tribute));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<CharacterTribute> All()
{
std::vector<CharacterTribute> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
CharacterTribute entry{};
entry.id = atoi(row[0]);
entry.tier = atoi(row[1]);
entry.tribute = atoi(row[2]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_CHARACTER_TRIBUTE_REPOSITORY_H

View File

@ -0,0 +1,274 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_CHATCHANNELS_REPOSITORY_H
#define EQEMU_CHATCHANNELS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class ChatchannelsRepository {
public:
struct Chatchannels {
std::string name;
std::string owner;
std::string password;
int minstatus;
};
static std::string PrimaryKey()
{
return std::string("name");
}
static std::vector<std::string> Columns()
{
return {
"name",
"owner",
"password",
"minstatus",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("chatchannels");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static Chatchannels NewEntity()
{
Chatchannels entry{};
entry.name = "";
entry.owner = "";
entry.password = "";
entry.minstatus = 0;
return entry;
}
static Chatchannels GetChatchannelsEntry(
const std::vector<Chatchannels> &chatchannelss,
int chatchannels_id
)
{
for (auto &chatchannels : chatchannelss) {
if (chatchannels.name == chatchannels_id) {
return chatchannels;
}
}
return NewEntity();
}
static Chatchannels FindOne(
int chatchannels_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
chatchannels_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
Chatchannels entry{};
entry.name = row[0];
entry.owner = row[1];
entry.password = row[2];
entry.minstatus = atoi(row[3]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int chatchannels_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
chatchannels_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
Chatchannels chatchannels_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[1] + " = '" + EscapeString(chatchannels_entry.owner) + "'");
update_values.push_back(columns[2] + " = '" + EscapeString(chatchannels_entry.password) + "'");
update_values.push_back(columns[3] + " = " + std::to_string(chatchannels_entry.minstatus));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
chatchannels_entry.name
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static Chatchannels InsertOne(
Chatchannels chatchannels_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(chatchannels_entry.owner) + "'");
insert_values.push_back("'" + EscapeString(chatchannels_entry.password) + "'");
insert_values.push_back(std::to_string(chatchannels_entry.minstatus));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
chatchannels_entry.id = results.LastInsertedID();
return chatchannels_entry;
}
chatchannels_entry = InstanceListRepository::NewEntity();
return chatchannels_entry;
}
static int InsertMany(
std::vector<Chatchannels> chatchannels_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &chatchannels_entry: chatchannels_entries) {
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(chatchannels_entry.owner) + "'");
insert_values.push_back("'" + EscapeString(chatchannels_entry.password) + "'");
insert_values.push_back(std::to_string(chatchannels_entry.minstatus));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<Chatchannels> All()
{
std::vector<Chatchannels> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
Chatchannels entry{};
entry.name = row[0];
entry.owner = row[1];
entry.password = row[2];
entry.minstatus = atoi(row[3]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_CHATCHANNELS_REPOSITORY_H

View File

@ -0,0 +1,266 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_COMMAND_SETTINGS_REPOSITORY_H
#define EQEMU_COMMAND_SETTINGS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class CommandSettingsRepository {
public:
struct CommandSettings {
std::string command;
int access;
std::string aliases;
};
static std::string PrimaryKey()
{
return std::string("command");
}
static std::vector<std::string> Columns()
{
return {
"command",
"access",
"aliases",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("command_settings");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static CommandSettings NewEntity()
{
CommandSettings entry{};
entry.command = "";
entry.access = 0;
entry.aliases = "";
return entry;
}
static CommandSettings GetCommandSettingsEntry(
const std::vector<CommandSettings> &command_settingss,
int command_settings_id
)
{
for (auto &command_settings : command_settingss) {
if (command_settings.command == command_settings_id) {
return command_settings;
}
}
return NewEntity();
}
static CommandSettings FindOne(
int command_settings_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
command_settings_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
CommandSettings entry{};
entry.command = row[0];
entry.access = atoi(row[1]);
entry.aliases = row[2];
return entry;
}
return NewEntity();
}
static int DeleteOne(
int command_settings_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
command_settings_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
CommandSettings command_settings_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[1] + " = " + std::to_string(command_settings_entry.access));
update_values.push_back(columns[2] + " = '" + EscapeString(command_settings_entry.aliases) + "'");
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
command_settings_entry.command
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static CommandSettings InsertOne(
CommandSettings command_settings_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(command_settings_entry.access));
insert_values.push_back("'" + EscapeString(command_settings_entry.aliases) + "'");
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
command_settings_entry.id = results.LastInsertedID();
return command_settings_entry;
}
command_settings_entry = InstanceListRepository::NewEntity();
return command_settings_entry;
}
static int InsertMany(
std::vector<CommandSettings> command_settings_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &command_settings_entry: command_settings_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(command_settings_entry.access));
insert_values.push_back("'" + EscapeString(command_settings_entry.aliases) + "'");
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<CommandSettings> All()
{
std::vector<CommandSettings> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
CommandSettings entry{};
entry.command = row[0];
entry.access = atoi(row[1]);
entry.aliases = row[2];
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_COMMAND_SETTINGS_REPOSITORY_H

View File

@ -0,0 +1,268 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_COMPLETED_TASKS_REPOSITORY_H
#define EQEMU_COMPLETED_TASKS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class CompletedTasksRepository {
public:
struct CompletedTasks {
int charid;
int completedtime;
int taskid;
int activityid;
};
static std::string PrimaryKey()
{
return std::string("activityid");
}
static std::vector<std::string> Columns()
{
return {
"charid",
"completedtime",
"taskid",
"activityid",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("completed_tasks");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static CompletedTasks NewEntity()
{
CompletedTasks entry{};
entry.charid = 0;
entry.completedtime = 0;
entry.taskid = 0;
entry.activityid = 0;
return entry;
}
static CompletedTasks GetCompletedTasksEntry(
const std::vector<CompletedTasks> &completed_taskss,
int completed_tasks_id
)
{
for (auto &completed_tasks : completed_taskss) {
if (completed_tasks.activityid == completed_tasks_id) {
return completed_tasks;
}
}
return NewEntity();
}
static CompletedTasks FindOne(
int completed_tasks_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
completed_tasks_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
CompletedTasks entry{};
entry.charid = atoi(row[0]);
entry.completedtime = atoi(row[1]);
entry.taskid = atoi(row[2]);
entry.activityid = atoi(row[3]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int completed_tasks_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
completed_tasks_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
CompletedTasks completed_tasks_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
completed_tasks_entry.activityid
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static CompletedTasks InsertOne(
CompletedTasks completed_tasks_entry
)
{
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
completed_tasks_entry.id = results.LastInsertedID();
return completed_tasks_entry;
}
completed_tasks_entry = InstanceListRepository::NewEntity();
return completed_tasks_entry;
}
static int InsertMany(
std::vector<CompletedTasks> completed_tasks_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &completed_tasks_entry: completed_tasks_entries) {
std::vector<std::string> insert_values;
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<CompletedTasks> All()
{
std::vector<CompletedTasks> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
CompletedTasks entry{};
entry.charid = atoi(row[0]);
entry.completedtime = atoi(row[1]);
entry.taskid = atoi(row[2]);
entry.activityid = atoi(row[3]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_COMPLETED_TASKS_REPOSITORY_H

View File

@ -0,0 +1,274 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_DATA_BUCKETS_REPOSITORY_H
#define EQEMU_DATA_BUCKETS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class DataBucketsRepository {
public:
struct DataBuckets {
int id;
std::string key;
std::string value;
int expires;
};
static std::string PrimaryKey()
{
return std::string("id");
}
static std::vector<std::string> Columns()
{
return {
"id",
"key",
"value",
"expires",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("data_buckets");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static DataBuckets NewEntity()
{
DataBuckets entry{};
entry.id = 0;
entry.key = 0;
entry.value = 0;
entry.expires = 0;
return entry;
}
static DataBuckets GetDataBucketsEntry(
const std::vector<DataBuckets> &data_bucketss,
int data_buckets_id
)
{
for (auto &data_buckets : data_bucketss) {
if (data_buckets.id == data_buckets_id) {
return data_buckets;
}
}
return NewEntity();
}
static DataBuckets FindOne(
int data_buckets_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
data_buckets_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
DataBuckets entry{};
entry.id = atoi(row[0]);
entry.key = row[1];
entry.value = row[2];
entry.expires = atoi(row[3]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int data_buckets_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
data_buckets_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
DataBuckets data_buckets_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[1] + " = '" + EscapeString(data_buckets_entry.key) + "'");
update_values.push_back(columns[2] + " = '" + EscapeString(data_buckets_entry.value) + "'");
update_values.push_back(columns[3] + " = " + std::to_string(data_buckets_entry.expires));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
data_buckets_entry.id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static DataBuckets InsertOne(
DataBuckets data_buckets_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(data_buckets_entry.key) + "'");
insert_values.push_back("'" + EscapeString(data_buckets_entry.value) + "'");
insert_values.push_back(std::to_string(data_buckets_entry.expires));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
data_buckets_entry.id = results.LastInsertedID();
return data_buckets_entry;
}
data_buckets_entry = InstanceListRepository::NewEntity();
return data_buckets_entry;
}
static int InsertMany(
std::vector<DataBuckets> data_buckets_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &data_buckets_entry: data_buckets_entries) {
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(data_buckets_entry.key) + "'");
insert_values.push_back("'" + EscapeString(data_buckets_entry.value) + "'");
insert_values.push_back(std::to_string(data_buckets_entry.expires));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<DataBuckets> All()
{
std::vector<DataBuckets> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
DataBuckets entry{};
entry.id = atoi(row[0]);
entry.key = row[1];
entry.value = row[2];
entry.expires = atoi(row[3]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_DATA_BUCKETS_REPOSITORY_H

View File

@ -0,0 +1,263 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_DB_STR_REPOSITORY_H
#define EQEMU_DB_STR_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class DbStrRepository {
public:
struct DbStr {
int id;
int type;
std::string value;
};
static std::string PrimaryKey()
{
return std::string("type");
}
static std::vector<std::string> Columns()
{
return {
"id",
"type",
"value",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("db_str");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static DbStr NewEntity()
{
DbStr entry{};
entry.id = 0;
entry.type = 0;
entry.value = 0;
return entry;
}
static DbStr GetDbStrEntry(
const std::vector<DbStr> &db_strs,
int db_str_id
)
{
for (auto &db_str : db_strs) {
if (db_str.type == db_str_id) {
return db_str;
}
}
return NewEntity();
}
static DbStr FindOne(
int db_str_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
db_str_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
DbStr entry{};
entry.id = atoi(row[0]);
entry.type = atoi(row[1]);
entry.value = row[2];
return entry;
}
return NewEntity();
}
static int DeleteOne(
int db_str_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
db_str_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
DbStr db_str_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[2] + " = '" + EscapeString(db_str_entry.value) + "'");
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
db_str_entry.type
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static DbStr InsertOne(
DbStr db_str_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(db_str_entry.value) + "'");
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
db_str_entry.id = results.LastInsertedID();
return db_str_entry;
}
db_str_entry = InstanceListRepository::NewEntity();
return db_str_entry;
}
static int InsertMany(
std::vector<DbStr> db_str_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &db_str_entry: db_str_entries) {
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(db_str_entry.value) + "'");
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<DbStr> All()
{
std::vector<DbStr> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
DbStr entry{};
entry.id = atoi(row[0]);
entry.type = atoi(row[1]);
entry.value = row[2];
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_DB_STR_REPOSITORY_H

View File

@ -0,0 +1,253 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_DB_VERSION_REPOSITORY_H
#define EQEMU_DB_VERSION_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class DbVersionRepository {
public:
struct DbVersion {
int version;
};
static std::string PrimaryKey()
{
return std::string("");
}
static std::vector<std::string> Columns()
{
return {
"version",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("db_version");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static DbVersion NewEntity()
{
DbVersion entry{};
entry.version = 0;
return entry;
}
static DbVersion GetDbVersionEntry(
const std::vector<DbVersion> &db_versions,
int db_version_id
)
{
for (auto &db_version : db_versions) {
if (db_version. == db_version_id) {
return db_version;
}
}
return NewEntity();
}
static DbVersion FindOne(
int db_version_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
db_version_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
DbVersion entry{};
entry.version = atoi(row[0]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int db_version_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
db_version_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
DbVersion db_version_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[0] + " = " + std::to_string(db_version_entry.version));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
db_version_entry.
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static DbVersion InsertOne(
DbVersion db_version_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(db_version_entry.version));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
db_version_entry.id = results.LastInsertedID();
return db_version_entry;
}
db_version_entry = InstanceListRepository::NewEntity();
return db_version_entry;
}
static int InsertMany(
std::vector<DbVersion> db_version_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &db_version_entry: db_version_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(db_version_entry.version));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<DbVersion> All()
{
std::vector<DbVersion> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
DbVersion entry{};
entry.version = atoi(row[0]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_DB_VERSION_REPOSITORY_H

View File

@ -0,0 +1,274 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_DISCOVERED_ITEMS_REPOSITORY_H
#define EQEMU_DISCOVERED_ITEMS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class DiscoveredItemsRepository {
public:
struct DiscoveredItems {
int item_id;
std::string char_name;
int discovered_date;
int account_status;
};
static std::string PrimaryKey()
{
return std::string("item_id");
}
static std::vector<std::string> Columns()
{
return {
"item_id",
"char_name",
"discovered_date",
"account_status",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("discovered_items");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static DiscoveredItems NewEntity()
{
DiscoveredItems entry{};
entry.item_id = 0;
entry.char_name = "";
entry.discovered_date = 0;
entry.account_status = 0;
return entry;
}
static DiscoveredItems GetDiscoveredItemsEntry(
const std::vector<DiscoveredItems> &discovered_itemss,
int discovered_items_id
)
{
for (auto &discovered_items : discovered_itemss) {
if (discovered_items.item_id == discovered_items_id) {
return discovered_items;
}
}
return NewEntity();
}
static DiscoveredItems FindOne(
int discovered_items_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
discovered_items_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
DiscoveredItems entry{};
entry.item_id = atoi(row[0]);
entry.char_name = row[1];
entry.discovered_date = atoi(row[2]);
entry.account_status = atoi(row[3]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int discovered_items_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
discovered_items_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
DiscoveredItems discovered_items_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[1] + " = '" + EscapeString(discovered_items_entry.char_name) + "'");
update_values.push_back(columns[2] + " = " + std::to_string(discovered_items_entry.discovered_date));
update_values.push_back(columns[3] + " = " + std::to_string(discovered_items_entry.account_status));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
discovered_items_entry.item_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static DiscoveredItems InsertOne(
DiscoveredItems discovered_items_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(discovered_items_entry.char_name) + "'");
insert_values.push_back(std::to_string(discovered_items_entry.discovered_date));
insert_values.push_back(std::to_string(discovered_items_entry.account_status));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
discovered_items_entry.id = results.LastInsertedID();
return discovered_items_entry;
}
discovered_items_entry = InstanceListRepository::NewEntity();
return discovered_items_entry;
}
static int InsertMany(
std::vector<DiscoveredItems> discovered_items_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &discovered_items_entry: discovered_items_entries) {
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(discovered_items_entry.char_name) + "'");
insert_values.push_back(std::to_string(discovered_items_entry.discovered_date));
insert_values.push_back(std::to_string(discovered_items_entry.account_status));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<DiscoveredItems> All()
{
std::vector<DiscoveredItems> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
DiscoveredItems entry{};
entry.item_id = atoi(row[0]);
entry.char_name = row[1];
entry.discovered_date = atoi(row[2]);
entry.account_status = atoi(row[3]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_DISCOVERED_ITEMS_REPOSITORY_H

View File

@ -0,0 +1,490 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_DOORS_REPOSITORY_H
#define EQEMU_DOORS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class DoorsRepository {
public:
struct Doors {
int id;
int16 doorid;
std::string zone;
int16 version;
std::string name;
std::string pos_y;
std::string pos_x;
std::string pos_z;
std::string heading;
int16 opentype;
int16 guild;
int16 lockpick;
int keyitem;
int8 nokeyring;
int16 triggerdoor;
int16 triggertype;
int8 disable_timer;
int16 doorisopen;
int door_param;
std::string dest_zone;
int dest_instance;
std::string dest_x;
std::string dest_y;
std::string dest_z;
std::string dest_heading;
int invert_state;
int incline;
int16 size;
std::string buffer;
int client_version_mask;
int16 is_ldon_door;
};
static std::string PrimaryKey()
{
return std::string("id");
}
static std::vector<std::string> Columns()
{
return {
"id",
"doorid",
"zone",
"version",
"name",
"pos_y",
"pos_x",
"pos_z",
"heading",
"opentype",
"guild",
"lockpick",
"keyitem",
"nokeyring",
"triggerdoor",
"triggertype",
"disable_timer",
"doorisopen",
"door_param",
"dest_zone",
"dest_instance",
"dest_x",
"dest_y",
"dest_z",
"dest_heading",
"invert_state",
"incline",
"size",
"buffer",
"client_version_mask",
"is_ldon_door",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("doors");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static Doors NewEntity()
{
Doors entry{};
entry.id = 0;
entry.doorid = 0;
entry.zone = 0;
entry.version = 0;
entry.name = "";
entry.pos_y = 0;
entry.pos_x = 0;
entry.pos_z = 0;
entry.heading = 0;
entry.opentype = 0;
entry.guild = 0;
entry.lockpick = 0;
entry.keyitem = 0;
entry.nokeyring = 0;
entry.triggerdoor = 0;
entry.triggertype = 0;
entry.disable_timer = 0;
entry.doorisopen = 0;
entry.door_param = 0;
entry.dest_zone = 'NONE';
entry.dest_instance = 0;
entry.dest_x = 0;
entry.dest_y = 0;
entry.dest_z = 0;
entry.dest_heading = 0;
entry.invert_state = 0;
entry.incline = 0;
entry.size = 100;
entry.buffer = 0;
entry.client_version_mask = 4294967295;
entry.is_ldon_door = 0;
return entry;
}
static Doors GetDoorsEntry(
const std::vector<Doors> &doorss,
int doors_id
)
{
for (auto &doors : doorss) {
if (doors.id == doors_id) {
return doors;
}
}
return NewEntity();
}
static Doors FindOne(
int doors_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
doors_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
Doors entry{};
entry.id = atoi(row[0]);
entry.doorid = atoi(row[1]);
entry.zone = row[2];
entry.version = atoi(row[3]);
entry.name = row[4];
entry.pos_y = atof(row[5]);
entry.pos_x = atof(row[6]);
entry.pos_z = atof(row[7]);
entry.heading = atof(row[8]);
entry.opentype = atoi(row[9]);
entry.guild = atoi(row[10]);
entry.lockpick = atoi(row[11]);
entry.keyitem = atoi(row[12]);
entry.nokeyring = atoi(row[13]);
entry.triggerdoor = atoi(row[14]);
entry.triggertype = atoi(row[15]);
entry.disable_timer = atoi(row[16]);
entry.doorisopen = atoi(row[17]);
entry.door_param = atoi(row[18]);
entry.dest_zone = row[19];
entry.dest_instance = atoi(row[20]);
entry.dest_x = atof(row[21]);
entry.dest_y = atof(row[22]);
entry.dest_z = atof(row[23]);
entry.dest_heading = atof(row[24]);
entry.invert_state = atoi(row[25]);
entry.incline = atoi(row[26]);
entry.size = atoi(row[27]);
entry.buffer = atof(row[28]);
entry.client_version_mask = atoi(row[29]);
entry.is_ldon_door = atoi(row[30]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int doors_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
doors_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
Doors doors_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[1] + " = " + std::to_string(doors_entry.doorid));
update_values.push_back(columns[2] + " = '" + EscapeString(doors_entry.zone) + "'");
update_values.push_back(columns[3] + " = " + std::to_string(doors_entry.version));
update_values.push_back(columns[4] + " = '" + EscapeString(doors_entry.name) + "'");
update_values.push_back(columns[5] + " = '" + EscapeString(doors_entry.pos_y) + "'");
update_values.push_back(columns[6] + " = '" + EscapeString(doors_entry.pos_x) + "'");
update_values.push_back(columns[7] + " = '" + EscapeString(doors_entry.pos_z) + "'");
update_values.push_back(columns[8] + " = '" + EscapeString(doors_entry.heading) + "'");
update_values.push_back(columns[9] + " = " + std::to_string(doors_entry.opentype));
update_values.push_back(columns[10] + " = " + std::to_string(doors_entry.guild));
update_values.push_back(columns[11] + " = " + std::to_string(doors_entry.lockpick));
update_values.push_back(columns[12] + " = " + std::to_string(doors_entry.keyitem));
update_values.push_back(columns[13] + " = " + std::to_string(doors_entry.nokeyring));
update_values.push_back(columns[14] + " = " + std::to_string(doors_entry.triggerdoor));
update_values.push_back(columns[15] + " = " + std::to_string(doors_entry.triggertype));
update_values.push_back(columns[16] + " = " + std::to_string(doors_entry.disable_timer));
update_values.push_back(columns[17] + " = " + std::to_string(doors_entry.doorisopen));
update_values.push_back(columns[18] + " = " + std::to_string(doors_entry.door_param));
update_values.push_back(columns[19] + " = '" + EscapeString(doors_entry.dest_zone) + "'");
update_values.push_back(columns[20] + " = " + std::to_string(doors_entry.dest_instance));
update_values.push_back(columns[21] + " = '" + EscapeString(doors_entry.dest_x) + "'");
update_values.push_back(columns[22] + " = '" + EscapeString(doors_entry.dest_y) + "'");
update_values.push_back(columns[23] + " = '" + EscapeString(doors_entry.dest_z) + "'");
update_values.push_back(columns[24] + " = '" + EscapeString(doors_entry.dest_heading) + "'");
update_values.push_back(columns[25] + " = " + std::to_string(doors_entry.invert_state));
update_values.push_back(columns[26] + " = " + std::to_string(doors_entry.incline));
update_values.push_back(columns[27] + " = " + std::to_string(doors_entry.size));
update_values.push_back(columns[28] + " = '" + EscapeString(doors_entry.buffer) + "'");
update_values.push_back(columns[29] + " = " + std::to_string(doors_entry.client_version_mask));
update_values.push_back(columns[30] + " = " + std::to_string(doors_entry.is_ldon_door));
auto results = content_db.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
doors_entry.id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static Doors InsertOne(
Doors doors_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(doors_entry.doorid));
insert_values.push_back("'" + EscapeString(doors_entry.zone) + "'");
insert_values.push_back(std::to_string(doors_entry.version));
insert_values.push_back("'" + EscapeString(doors_entry.name) + "'");
insert_values.push_back("'" + EscapeString(doors_entry.pos_y) + "'");
insert_values.push_back("'" + EscapeString(doors_entry.pos_x) + "'");
insert_values.push_back("'" + EscapeString(doors_entry.pos_z) + "'");
insert_values.push_back("'" + EscapeString(doors_entry.heading) + "'");
insert_values.push_back(std::to_string(doors_entry.opentype));
insert_values.push_back(std::to_string(doors_entry.guild));
insert_values.push_back(std::to_string(doors_entry.lockpick));
insert_values.push_back(std::to_string(doors_entry.keyitem));
insert_values.push_back(std::to_string(doors_entry.nokeyring));
insert_values.push_back(std::to_string(doors_entry.triggerdoor));
insert_values.push_back(std::to_string(doors_entry.triggertype));
insert_values.push_back(std::to_string(doors_entry.disable_timer));
insert_values.push_back(std::to_string(doors_entry.doorisopen));
insert_values.push_back(std::to_string(doors_entry.door_param));
insert_values.push_back("'" + EscapeString(doors_entry.dest_zone) + "'");
insert_values.push_back(std::to_string(doors_entry.dest_instance));
insert_values.push_back("'" + EscapeString(doors_entry.dest_x) + "'");
insert_values.push_back("'" + EscapeString(doors_entry.dest_y) + "'");
insert_values.push_back("'" + EscapeString(doors_entry.dest_z) + "'");
insert_values.push_back("'" + EscapeString(doors_entry.dest_heading) + "'");
insert_values.push_back(std::to_string(doors_entry.invert_state));
insert_values.push_back(std::to_string(doors_entry.incline));
insert_values.push_back(std::to_string(doors_entry.size));
insert_values.push_back("'" + EscapeString(doors_entry.buffer) + "'");
insert_values.push_back(std::to_string(doors_entry.client_version_mask));
insert_values.push_back(std::to_string(doors_entry.is_ldon_door));
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
doors_entry.id = results.LastInsertedID();
return doors_entry;
}
doors_entry = InstanceListRepository::NewEntity();
return doors_entry;
}
static int InsertMany(
std::vector<Doors> doors_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &doors_entry: doors_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(doors_entry.doorid));
insert_values.push_back("'" + EscapeString(doors_entry.zone) + "'");
insert_values.push_back(std::to_string(doors_entry.version));
insert_values.push_back("'" + EscapeString(doors_entry.name) + "'");
insert_values.push_back("'" + EscapeString(doors_entry.pos_y) + "'");
insert_values.push_back("'" + EscapeString(doors_entry.pos_x) + "'");
insert_values.push_back("'" + EscapeString(doors_entry.pos_z) + "'");
insert_values.push_back("'" + EscapeString(doors_entry.heading) + "'");
insert_values.push_back(std::to_string(doors_entry.opentype));
insert_values.push_back(std::to_string(doors_entry.guild));
insert_values.push_back(std::to_string(doors_entry.lockpick));
insert_values.push_back(std::to_string(doors_entry.keyitem));
insert_values.push_back(std::to_string(doors_entry.nokeyring));
insert_values.push_back(std::to_string(doors_entry.triggerdoor));
insert_values.push_back(std::to_string(doors_entry.triggertype));
insert_values.push_back(std::to_string(doors_entry.disable_timer));
insert_values.push_back(std::to_string(doors_entry.doorisopen));
insert_values.push_back(std::to_string(doors_entry.door_param));
insert_values.push_back("'" + EscapeString(doors_entry.dest_zone) + "'");
insert_values.push_back(std::to_string(doors_entry.dest_instance));
insert_values.push_back("'" + EscapeString(doors_entry.dest_x) + "'");
insert_values.push_back("'" + EscapeString(doors_entry.dest_y) + "'");
insert_values.push_back("'" + EscapeString(doors_entry.dest_z) + "'");
insert_values.push_back("'" + EscapeString(doors_entry.dest_heading) + "'");
insert_values.push_back(std::to_string(doors_entry.invert_state));
insert_values.push_back(std::to_string(doors_entry.incline));
insert_values.push_back(std::to_string(doors_entry.size));
insert_values.push_back("'" + EscapeString(doors_entry.buffer) + "'");
insert_values.push_back(std::to_string(doors_entry.client_version_mask));
insert_values.push_back(std::to_string(doors_entry.is_ldon_door));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<Doors> All()
{
std::vector<Doors> all_entries;
auto results = content_db.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
Doors entry{};
entry.id = atoi(row[0]);
entry.doorid = atoi(row[1]);
entry.zone = row[2];
entry.version = atoi(row[3]);
entry.name = row[4];
entry.pos_y = atof(row[5]);
entry.pos_x = atof(row[6]);
entry.pos_z = atof(row[7]);
entry.heading = atof(row[8]);
entry.opentype = atoi(row[9]);
entry.guild = atoi(row[10]);
entry.lockpick = atoi(row[11]);
entry.keyitem = atoi(row[12]);
entry.nokeyring = atoi(row[13]);
entry.triggerdoor = atoi(row[14]);
entry.triggertype = atoi(row[15]);
entry.disable_timer = atoi(row[16]);
entry.doorisopen = atoi(row[17]);
entry.door_param = atoi(row[18]);
entry.dest_zone = row[19];
entry.dest_instance = atoi(row[20]);
entry.dest_x = atof(row[21]);
entry.dest_y = atof(row[22]);
entry.dest_z = atof(row[23]);
entry.dest_heading = atof(row[24]);
entry.invert_state = atoi(row[25]);
entry.incline = atoi(row[26]);
entry.size = atoi(row[27]);
entry.buffer = atof(row[28]);
entry.client_version_mask = atoi(row[29]);
entry.is_ldon_door = atoi(row[30]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_DOORS_REPOSITORY_H

View File

@ -0,0 +1,293 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_EQTIME_REPOSITORY_H
#define EQEMU_EQTIME_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class EqtimeRepository {
public:
struct Eqtime {
int8 minute;
int8 hour;
int8 day;
int8 month;
int year;
int realtime;
};
static std::string PrimaryKey()
{
return std::string("");
}
static std::vector<std::string> Columns()
{
return {
"minute",
"hour",
"day",
"month",
"year",
"realtime",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("eqtime");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static Eqtime NewEntity()
{
Eqtime entry{};
entry.minute = 0;
entry.hour = 0;
entry.day = 0;
entry.month = 0;
entry.year = 0;
entry.realtime = 0;
return entry;
}
static Eqtime GetEqtimeEntry(
const std::vector<Eqtime> &eqtimes,
int eqtime_id
)
{
for (auto &eqtime : eqtimes) {
if (eqtime. == eqtime_id) {
return eqtime;
}
}
return NewEntity();
}
static Eqtime FindOne(
int eqtime_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
eqtime_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
Eqtime entry{};
entry.minute = atoi(row[0]);
entry.hour = atoi(row[1]);
entry.day = atoi(row[2]);
entry.month = atoi(row[3]);
entry.year = atoi(row[4]);
entry.realtime = atoi(row[5]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int eqtime_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
eqtime_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
Eqtime eqtime_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[0] + " = " + std::to_string(eqtime_entry.minute));
update_values.push_back(columns[1] + " = " + std::to_string(eqtime_entry.hour));
update_values.push_back(columns[2] + " = " + std::to_string(eqtime_entry.day));
update_values.push_back(columns[3] + " = " + std::to_string(eqtime_entry.month));
update_values.push_back(columns[4] + " = " + std::to_string(eqtime_entry.year));
update_values.push_back(columns[5] + " = " + std::to_string(eqtime_entry.realtime));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
eqtime_entry.
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static Eqtime InsertOne(
Eqtime eqtime_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(eqtime_entry.minute));
insert_values.push_back(std::to_string(eqtime_entry.hour));
insert_values.push_back(std::to_string(eqtime_entry.day));
insert_values.push_back(std::to_string(eqtime_entry.month));
insert_values.push_back(std::to_string(eqtime_entry.year));
insert_values.push_back(std::to_string(eqtime_entry.realtime));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
eqtime_entry.id = results.LastInsertedID();
return eqtime_entry;
}
eqtime_entry = InstanceListRepository::NewEntity();
return eqtime_entry;
}
static int InsertMany(
std::vector<Eqtime> eqtime_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &eqtime_entry: eqtime_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(eqtime_entry.minute));
insert_values.push_back(std::to_string(eqtime_entry.hour));
insert_values.push_back(std::to_string(eqtime_entry.day));
insert_values.push_back(std::to_string(eqtime_entry.month));
insert_values.push_back(std::to_string(eqtime_entry.year));
insert_values.push_back(std::to_string(eqtime_entry.realtime));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<Eqtime> All()
{
std::vector<Eqtime> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
Eqtime entry{};
entry.minute = atoi(row[0]);
entry.hour = atoi(row[1]);
entry.day = atoi(row[2]);
entry.month = atoi(row[3]);
entry.year = atoi(row[4]);
entry.realtime = atoi(row[5]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_EQTIME_REPOSITORY_H

View File

@ -0,0 +1,322 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_EVENTLOG_REPOSITORY_H
#define EQEMU_EVENTLOG_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class EventlogRepository {
public:
struct Eventlog {
int id;
std::string accountname;
int accountid;
int status;
std::string charname;
std::string target;
std::string time;
std::string descriptiontype;
std::string description;
int event_nid;
};
static std::string PrimaryKey()
{
return std::string("id");
}
static std::vector<std::string> Columns()
{
return {
"id",
"accountname",
"accountid",
"status",
"charname",
"target",
"time",
"descriptiontype",
"description",
"event_nid",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("eventlog");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static Eventlog NewEntity()
{
Eventlog entry{};
entry.id = 0;
entry.accountname = "";
entry.accountid = 0;
entry.status = 0;
entry.charname = "";
entry.target = 'None';
entry.time = current_timestamp();
entry.descriptiontype = "";
entry.description = 0;
entry.event_nid = 0;
return entry;
}
static Eventlog GetEventlogEntry(
const std::vector<Eventlog> &eventlogs,
int eventlog_id
)
{
for (auto &eventlog : eventlogs) {
if (eventlog.id == eventlog_id) {
return eventlog;
}
}
return NewEntity();
}
static Eventlog FindOne(
int eventlog_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
eventlog_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
Eventlog entry{};
entry.id = atoi(row[0]);
entry.accountname = row[1];
entry.accountid = atoi(row[2]);
entry.status = atoi(row[3]);
entry.charname = row[4];
entry.target = row[5];
entry.time = row[6];
entry.descriptiontype = row[7];
entry.description = row[8];
entry.event_nid = atoi(row[9]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int eventlog_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
eventlog_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
Eventlog eventlog_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[1] + " = '" + EscapeString(eventlog_entry.accountname) + "'");
update_values.push_back(columns[2] + " = " + std::to_string(eventlog_entry.accountid));
update_values.push_back(columns[3] + " = " + std::to_string(eventlog_entry.status));
update_values.push_back(columns[4] + " = '" + EscapeString(eventlog_entry.charname) + "'");
update_values.push_back(columns[5] + " = '" + EscapeString(eventlog_entry.target) + "'");
update_values.push_back(columns[6] + " = '" + EscapeString(eventlog_entry.time) + "'");
update_values.push_back(columns[7] + " = '" + EscapeString(eventlog_entry.descriptiontype) + "'");
update_values.push_back(columns[8] + " = '" + EscapeString(eventlog_entry.description) + "'");
update_values.push_back(columns[9] + " = " + std::to_string(eventlog_entry.event_nid));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
eventlog_entry.id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static Eventlog InsertOne(
Eventlog eventlog_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(eventlog_entry.accountname) + "'");
insert_values.push_back(std::to_string(eventlog_entry.accountid));
insert_values.push_back(std::to_string(eventlog_entry.status));
insert_values.push_back("'" + EscapeString(eventlog_entry.charname) + "'");
insert_values.push_back("'" + EscapeString(eventlog_entry.target) + "'");
insert_values.push_back("'" + EscapeString(eventlog_entry.time) + "'");
insert_values.push_back("'" + EscapeString(eventlog_entry.descriptiontype) + "'");
insert_values.push_back("'" + EscapeString(eventlog_entry.description) + "'");
insert_values.push_back(std::to_string(eventlog_entry.event_nid));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
eventlog_entry.id = results.LastInsertedID();
return eventlog_entry;
}
eventlog_entry = InstanceListRepository::NewEntity();
return eventlog_entry;
}
static int InsertMany(
std::vector<Eventlog> eventlog_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &eventlog_entry: eventlog_entries) {
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(eventlog_entry.accountname) + "'");
insert_values.push_back(std::to_string(eventlog_entry.accountid));
insert_values.push_back(std::to_string(eventlog_entry.status));
insert_values.push_back("'" + EscapeString(eventlog_entry.charname) + "'");
insert_values.push_back("'" + EscapeString(eventlog_entry.target) + "'");
insert_values.push_back("'" + EscapeString(eventlog_entry.time) + "'");
insert_values.push_back("'" + EscapeString(eventlog_entry.descriptiontype) + "'");
insert_values.push_back("'" + EscapeString(eventlog_entry.description) + "'");
insert_values.push_back(std::to_string(eventlog_entry.event_nid));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<Eventlog> All()
{
std::vector<Eventlog> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
Eventlog entry{};
entry.id = atoi(row[0]);
entry.accountname = row[1];
entry.accountid = atoi(row[2]);
entry.status = atoi(row[3]);
entry.charname = row[4];
entry.target = row[5];
entry.time = row[6];
entry.descriptiontype = row[7];
entry.description = row[8];
entry.event_nid = atoi(row[9]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_EVENTLOG_REPOSITORY_H

View File

@ -0,0 +1,290 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_FACTION_BASE_DATA_REPOSITORY_H
#define EQEMU_FACTION_BASE_DATA_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class FactionBaseDataRepository {
public:
struct FactionBaseData {
int16 client_faction_id;
int16 min;
int16 max;
int16 unk_hero1;
int16 unk_hero2;
int16 unk_hero3;
};
static std::string PrimaryKey()
{
return std::string("client_faction_id");
}
static std::vector<std::string> Columns()
{
return {
"client_faction_id",
"min",
"max",
"unk_hero1",
"unk_hero2",
"unk_hero3",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("faction_base_data");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static FactionBaseData NewEntity()
{
FactionBaseData entry{};
entry.client_faction_id = 0;
entry.min = -2000;
entry.max = 2000;
entry.unk_hero1 = 0;
entry.unk_hero2 = 0;
entry.unk_hero3 = 0;
return entry;
}
static FactionBaseData GetFactionBaseDataEntry(
const std::vector<FactionBaseData> &faction_base_datas,
int faction_base_data_id
)
{
for (auto &faction_base_data : faction_base_datas) {
if (faction_base_data.client_faction_id == faction_base_data_id) {
return faction_base_data;
}
}
return NewEntity();
}
static FactionBaseData FindOne(
int faction_base_data_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
faction_base_data_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
FactionBaseData entry{};
entry.client_faction_id = atoi(row[0]);
entry.min = atoi(row[1]);
entry.max = atoi(row[2]);
entry.unk_hero1 = atoi(row[3]);
entry.unk_hero2 = atoi(row[4]);
entry.unk_hero3 = atoi(row[5]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int faction_base_data_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
faction_base_data_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
FactionBaseData faction_base_data_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[1] + " = " + std::to_string(faction_base_data_entry.min));
update_values.push_back(columns[2] + " = " + std::to_string(faction_base_data_entry.max));
update_values.push_back(columns[3] + " = " + std::to_string(faction_base_data_entry.unk_hero1));
update_values.push_back(columns[4] + " = " + std::to_string(faction_base_data_entry.unk_hero2));
update_values.push_back(columns[5] + " = " + std::to_string(faction_base_data_entry.unk_hero3));
auto results = content_db.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
faction_base_data_entry.client_faction_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static FactionBaseData InsertOne(
FactionBaseData faction_base_data_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(faction_base_data_entry.min));
insert_values.push_back(std::to_string(faction_base_data_entry.max));
insert_values.push_back(std::to_string(faction_base_data_entry.unk_hero1));
insert_values.push_back(std::to_string(faction_base_data_entry.unk_hero2));
insert_values.push_back(std::to_string(faction_base_data_entry.unk_hero3));
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
faction_base_data_entry.id = results.LastInsertedID();
return faction_base_data_entry;
}
faction_base_data_entry = InstanceListRepository::NewEntity();
return faction_base_data_entry;
}
static int InsertMany(
std::vector<FactionBaseData> faction_base_data_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &faction_base_data_entry: faction_base_data_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(faction_base_data_entry.min));
insert_values.push_back(std::to_string(faction_base_data_entry.max));
insert_values.push_back(std::to_string(faction_base_data_entry.unk_hero1));
insert_values.push_back(std::to_string(faction_base_data_entry.unk_hero2));
insert_values.push_back(std::to_string(faction_base_data_entry.unk_hero3));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<FactionBaseData> All()
{
std::vector<FactionBaseData> all_entries;
auto results = content_db.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
FactionBaseData entry{};
entry.client_faction_id = atoi(row[0]);
entry.min = atoi(row[1]);
entry.max = atoi(row[2]);
entry.unk_hero1 = atoi(row[3]);
entry.unk_hero2 = atoi(row[4]);
entry.unk_hero3 = atoi(row[5]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_FACTION_BASE_DATA_REPOSITORY_H

View File

@ -0,0 +1,274 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_FACTION_LIST_MOD_REPOSITORY_H
#define EQEMU_FACTION_LIST_MOD_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class FactionListModRepository {
public:
struct FactionListMod {
int id;
int faction_id;
int16 mod;
std::string mod_name;
};
static std::string PrimaryKey()
{
return std::string("id");
}
static std::vector<std::string> Columns()
{
return {
"id",
"faction_id",
"mod",
"mod_name",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("faction_list_mod");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static FactionListMod NewEntity()
{
FactionListMod entry{};
entry.id = 0;
entry.faction_id = 0;
entry.mod = 0;
entry.mod_name = 0;
return entry;
}
static FactionListMod GetFactionListModEntry(
const std::vector<FactionListMod> &faction_list_mods,
int faction_list_mod_id
)
{
for (auto &faction_list_mod : faction_list_mods) {
if (faction_list_mod.id == faction_list_mod_id) {
return faction_list_mod;
}
}
return NewEntity();
}
static FactionListMod FindOne(
int faction_list_mod_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
faction_list_mod_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
FactionListMod entry{};
entry.id = atoi(row[0]);
entry.faction_id = atoi(row[1]);
entry.mod = atoi(row[2]);
entry.mod_name = row[3];
return entry;
}
return NewEntity();
}
static int DeleteOne(
int faction_list_mod_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
faction_list_mod_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
FactionListMod faction_list_mod_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[1] + " = " + std::to_string(faction_list_mod_entry.faction_id));
update_values.push_back(columns[2] + " = " + std::to_string(faction_list_mod_entry.mod));
update_values.push_back(columns[3] + " = '" + EscapeString(faction_list_mod_entry.mod_name) + "'");
auto results = content_db.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
faction_list_mod_entry.id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static FactionListMod InsertOne(
FactionListMod faction_list_mod_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(faction_list_mod_entry.faction_id));
insert_values.push_back(std::to_string(faction_list_mod_entry.mod));
insert_values.push_back("'" + EscapeString(faction_list_mod_entry.mod_name) + "'");
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
faction_list_mod_entry.id = results.LastInsertedID();
return faction_list_mod_entry;
}
faction_list_mod_entry = InstanceListRepository::NewEntity();
return faction_list_mod_entry;
}
static int InsertMany(
std::vector<FactionListMod> faction_list_mod_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &faction_list_mod_entry: faction_list_mod_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(faction_list_mod_entry.faction_id));
insert_values.push_back(std::to_string(faction_list_mod_entry.mod));
insert_values.push_back("'" + EscapeString(faction_list_mod_entry.mod_name) + "'");
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<FactionListMod> All()
{
std::vector<FactionListMod> all_entries;
auto results = content_db.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
FactionListMod entry{};
entry.id = atoi(row[0]);
entry.faction_id = atoi(row[1]);
entry.mod = atoi(row[2]);
entry.mod_name = row[3];
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_FACTION_LIST_MOD_REPOSITORY_H

View File

@ -0,0 +1,266 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_FACTION_LIST_REPOSITORY_H
#define EQEMU_FACTION_LIST_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class FactionListRepository {
public:
struct FactionList {
int id;
std::string name;
int16 base;
};
static std::string PrimaryKey()
{
return std::string("id");
}
static std::vector<std::string> Columns()
{
return {
"id",
"name",
"base",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("faction_list");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static FactionList NewEntity()
{
FactionList entry{};
entry.id = 0;
entry.name = "";
entry.base = 0;
return entry;
}
static FactionList GetFactionListEntry(
const std::vector<FactionList> &faction_lists,
int faction_list_id
)
{
for (auto &faction_list : faction_lists) {
if (faction_list.id == faction_list_id) {
return faction_list;
}
}
return NewEntity();
}
static FactionList FindOne(
int faction_list_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
faction_list_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
FactionList entry{};
entry.id = atoi(row[0]);
entry.name = row[1];
entry.base = atoi(row[2]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int faction_list_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
faction_list_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
FactionList faction_list_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[1] + " = '" + EscapeString(faction_list_entry.name) + "'");
update_values.push_back(columns[2] + " = " + std::to_string(faction_list_entry.base));
auto results = content_db.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
faction_list_entry.id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static FactionList InsertOne(
FactionList faction_list_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(faction_list_entry.name) + "'");
insert_values.push_back(std::to_string(faction_list_entry.base));
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
faction_list_entry.id = results.LastInsertedID();
return faction_list_entry;
}
faction_list_entry = InstanceListRepository::NewEntity();
return faction_list_entry;
}
static int InsertMany(
std::vector<FactionList> faction_list_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &faction_list_entry: faction_list_entries) {
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(faction_list_entry.name) + "'");
insert_values.push_back(std::to_string(faction_list_entry.base));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<FactionList> All()
{
std::vector<FactionList> all_entries;
auto results = content_db.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
FactionList entry{};
entry.id = atoi(row[0]);
entry.name = row[1];
entry.base = atoi(row[2]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_FACTION_LIST_REPOSITORY_H

View File

@ -0,0 +1,271 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_FACTION_VALUES_REPOSITORY_H
#define EQEMU_FACTION_VALUES_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class FactionValuesRepository {
public:
struct FactionValues {
int char_id;
int faction_id;
int16 current_value;
int8 temp;
};
static std::string PrimaryKey()
{
return std::string("faction_id");
}
static std::vector<std::string> Columns()
{
return {
"char_id",
"faction_id",
"current_value",
"temp",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("faction_values");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static FactionValues NewEntity()
{
FactionValues entry{};
entry.char_id = 0;
entry.faction_id = 0;
entry.current_value = 0;
entry.temp = 0;
return entry;
}
static FactionValues GetFactionValuesEntry(
const std::vector<FactionValues> &faction_valuess,
int faction_values_id
)
{
for (auto &faction_values : faction_valuess) {
if (faction_values.faction_id == faction_values_id) {
return faction_values;
}
}
return NewEntity();
}
static FactionValues FindOne(
int faction_values_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
faction_values_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
FactionValues entry{};
entry.char_id = atoi(row[0]);
entry.faction_id = atoi(row[1]);
entry.current_value = atoi(row[2]);
entry.temp = atoi(row[3]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int faction_values_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
faction_values_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
FactionValues faction_values_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[2] + " = " + std::to_string(faction_values_entry.current_value));
update_values.push_back(columns[3] + " = " + std::to_string(faction_values_entry.temp));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
faction_values_entry.faction_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static FactionValues InsertOne(
FactionValues faction_values_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(faction_values_entry.current_value));
insert_values.push_back(std::to_string(faction_values_entry.temp));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
faction_values_entry.id = results.LastInsertedID();
return faction_values_entry;
}
faction_values_entry = InstanceListRepository::NewEntity();
return faction_values_entry;
}
static int InsertMany(
std::vector<FactionValues> faction_values_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &faction_values_entry: faction_values_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(faction_values_entry.current_value));
insert_values.push_back(std::to_string(faction_values_entry.temp));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<FactionValues> All()
{
std::vector<FactionValues> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
FactionValues entry{};
entry.char_id = atoi(row[0]);
entry.faction_id = atoi(row[1]);
entry.current_value = atoi(row[2]);
entry.temp = atoi(row[3]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_FACTION_VALUES_REPOSITORY_H

View File

@ -0,0 +1,298 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_FISHING_REPOSITORY_H
#define EQEMU_FISHING_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class FishingRepository {
public:
struct Fishing {
int id;
int zoneid;
int Itemid;
int16 skill_level;
int16 chance;
int npc_id;
int npc_chance;
};
static std::string PrimaryKey()
{
return std::string("id");
}
static std::vector<std::string> Columns()
{
return {
"id",
"zoneid",
"Itemid",
"skill_level",
"chance",
"npc_id",
"npc_chance",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("fishing");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static Fishing NewEntity()
{
Fishing entry{};
entry.id = 0;
entry.zoneid = 0;
entry.Itemid = 0;
entry.skill_level = 0;
entry.chance = 0;
entry.npc_id = 0;
entry.npc_chance = 0;
return entry;
}
static Fishing GetFishingEntry(
const std::vector<Fishing> &fishings,
int fishing_id
)
{
for (auto &fishing : fishings) {
if (fishing.id == fishing_id) {
return fishing;
}
}
return NewEntity();
}
static Fishing FindOne(
int fishing_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
fishing_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
Fishing entry{};
entry.id = atoi(row[0]);
entry.zoneid = atoi(row[1]);
entry.Itemid = atoi(row[2]);
entry.skill_level = atoi(row[3]);
entry.chance = atoi(row[4]);
entry.npc_id = atoi(row[5]);
entry.npc_chance = atoi(row[6]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int fishing_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
fishing_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
Fishing fishing_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[1] + " = " + std::to_string(fishing_entry.zoneid));
update_values.push_back(columns[2] + " = " + std::to_string(fishing_entry.Itemid));
update_values.push_back(columns[3] + " = " + std::to_string(fishing_entry.skill_level));
update_values.push_back(columns[4] + " = " + std::to_string(fishing_entry.chance));
update_values.push_back(columns[5] + " = " + std::to_string(fishing_entry.npc_id));
update_values.push_back(columns[6] + " = " + std::to_string(fishing_entry.npc_chance));
auto results = content_db.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
fishing_entry.id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static Fishing InsertOne(
Fishing fishing_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(fishing_entry.zoneid));
insert_values.push_back(std::to_string(fishing_entry.Itemid));
insert_values.push_back(std::to_string(fishing_entry.skill_level));
insert_values.push_back(std::to_string(fishing_entry.chance));
insert_values.push_back(std::to_string(fishing_entry.npc_id));
insert_values.push_back(std::to_string(fishing_entry.npc_chance));
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
fishing_entry.id = results.LastInsertedID();
return fishing_entry;
}
fishing_entry = InstanceListRepository::NewEntity();
return fishing_entry;
}
static int InsertMany(
std::vector<Fishing> fishing_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &fishing_entry: fishing_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(fishing_entry.zoneid));
insert_values.push_back(std::to_string(fishing_entry.Itemid));
insert_values.push_back(std::to_string(fishing_entry.skill_level));
insert_values.push_back(std::to_string(fishing_entry.chance));
insert_values.push_back(std::to_string(fishing_entry.npc_id));
insert_values.push_back(std::to_string(fishing_entry.npc_chance));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<Fishing> All()
{
std::vector<Fishing> all_entries;
auto results = content_db.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
Fishing entry{};
entry.id = atoi(row[0]);
entry.zoneid = atoi(row[1]);
entry.Itemid = atoi(row[2]);
entry.skill_level = atoi(row[3]);
entry.chance = atoi(row[4]);
entry.npc_id = atoi(row[5]);
entry.npc_chance = atoi(row[6]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_FISHING_REPOSITORY_H

View File

@ -0,0 +1,282 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_FORAGE_REPOSITORY_H
#define EQEMU_FORAGE_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class ForageRepository {
public:
struct Forage {
int id;
int zoneid;
int Itemid;
int16 level;
int16 chance;
};
static std::string PrimaryKey()
{
return std::string("id");
}
static std::vector<std::string> Columns()
{
return {
"id",
"zoneid",
"Itemid",
"level",
"chance",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("forage");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static Forage NewEntity()
{
Forage entry{};
entry.id = 0;
entry.zoneid = 0;
entry.Itemid = 0;
entry.level = 0;
entry.chance = 0;
return entry;
}
static Forage GetForageEntry(
const std::vector<Forage> &forages,
int forage_id
)
{
for (auto &forage : forages) {
if (forage.id == forage_id) {
return forage;
}
}
return NewEntity();
}
static Forage FindOne(
int forage_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
forage_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
Forage entry{};
entry.id = atoi(row[0]);
entry.zoneid = atoi(row[1]);
entry.Itemid = atoi(row[2]);
entry.level = atoi(row[3]);
entry.chance = atoi(row[4]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int forage_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
forage_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
Forage forage_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[1] + " = " + std::to_string(forage_entry.zoneid));
update_values.push_back(columns[2] + " = " + std::to_string(forage_entry.Itemid));
update_values.push_back(columns[3] + " = " + std::to_string(forage_entry.level));
update_values.push_back(columns[4] + " = " + std::to_string(forage_entry.chance));
auto results = content_db.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
forage_entry.id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static Forage InsertOne(
Forage forage_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(forage_entry.zoneid));
insert_values.push_back(std::to_string(forage_entry.Itemid));
insert_values.push_back(std::to_string(forage_entry.level));
insert_values.push_back(std::to_string(forage_entry.chance));
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
forage_entry.id = results.LastInsertedID();
return forage_entry;
}
forage_entry = InstanceListRepository::NewEntity();
return forage_entry;
}
static int InsertMany(
std::vector<Forage> forage_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &forage_entry: forage_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(forage_entry.zoneid));
insert_values.push_back(std::to_string(forage_entry.Itemid));
insert_values.push_back(std::to_string(forage_entry.level));
insert_values.push_back(std::to_string(forage_entry.chance));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<Forage> All()
{
std::vector<Forage> all_entries;
auto results = content_db.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
Forage entry{};
entry.id = atoi(row[0]);
entry.zoneid = atoi(row[1]);
entry.Itemid = atoi(row[2]);
entry.level = atoi(row[3]);
entry.chance = atoi(row[4]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_FORAGE_REPOSITORY_H

View File

@ -0,0 +1,263 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_FRIENDS_REPOSITORY_H
#define EQEMU_FRIENDS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class FriendsRepository {
public:
struct Friends {
int charid;
int8 type;
std::string name;
};
static std::string PrimaryKey()
{
return std::string("name");
}
static std::vector<std::string> Columns()
{
return {
"charid",
"type",
"name",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("friends");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static Friends NewEntity()
{
Friends entry{};
entry.charid = 0;
entry.type = 1;
entry.name = 0;
return entry;
}
static Friends GetFriendsEntry(
const std::vector<Friends> &friendss,
int friends_id
)
{
for (auto &friends : friendss) {
if (friends.name == friends_id) {
return friends;
}
}
return NewEntity();
}
static Friends FindOne(
int friends_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
friends_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
Friends entry{};
entry.charid = atoi(row[0]);
entry.type = atoi(row[1]);
entry.name = row[2];
return entry;
}
return NewEntity();
}
static int DeleteOne(
int friends_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
friends_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
Friends friends_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
friends_entry.name
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static Friends InsertOne(
Friends friends_entry
)
{
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
friends_entry.id = results.LastInsertedID();
return friends_entry;
}
friends_entry = InstanceListRepository::NewEntity();
return friends_entry;
}
static int InsertMany(
std::vector<Friends> friends_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &friends_entry: friends_entries) {
std::vector<std::string> insert_values;
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<Friends> All()
{
std::vector<Friends> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
Friends entry{};
entry.charid = atoi(row[0]);
entry.type = atoi(row[1]);
entry.name = row[2];
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_FRIENDS_REPOSITORY_H

View File

@ -0,0 +1,352 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_GLOBAL_LOOT_REPOSITORY_H
#define EQEMU_GLOBAL_LOOT_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class GlobalLootRepository {
public:
struct GlobalLoot {
int id;
std::string description;
int loottable_id;
int8 enabled;
int min_level;
int max_level;
int8 rare;
int8 raid;
std::string race;
std::string class;
std::string bodytype;
std::string zone;
int8 hot_zone;
};
static std::string PrimaryKey()
{
return std::string("id");
}
static std::vector<std::string> Columns()
{
return {
"id",
"description",
"loottable_id",
"enabled",
"min_level",
"max_level",
"rare",
"raid",
"race",
"class",
"bodytype",
"zone",
"hot_zone",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("global_loot");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static GlobalLoot NewEntity()
{
GlobalLoot entry{};
entry.id = 0;
entry.description = 0;
entry.loottable_id = 0;
entry.enabled = 1;
entry.min_level = 0;
entry.max_level = 0;
entry.rare = 0;
entry.raid = 0;
entry.race = 0;
entry.
class = 0;
entry.bodytype = 0;
entry.zone = 0;
entry.hot_zone = 0;
return entry;
}
static GlobalLoot GetGlobalLootEntry(
const std::vector<GlobalLoot> &global_loots,
int global_loot_id
)
{
for (auto &global_loot : global_loots) {
if (global_loot.id == global_loot_id) {
return global_loot;
}
}
return NewEntity();
}
static GlobalLoot FindOne(
int global_loot_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
global_loot_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
GlobalLoot entry{};
entry.id = atoi(row[0]);
entry.description = row[1];
entry.loottable_id = atoi(row[2]);
entry.enabled = atoi(row[3]);
entry.min_level = atoi(row[4]);
entry.max_level = atoi(row[5]);
entry.rare = atoi(row[6]);
entry.raid = atoi(row[7]);
entry.race = row[8];
entry.
class = row[9];
entry.bodytype = row[10];
entry.zone = row[11];
entry.hot_zone = atoi(row[12]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int global_loot_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
global_loot_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
GlobalLoot global_loot_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[1] + " = '" + EscapeString(global_loot_entry.description) + "'");
update_values.push_back(columns[2] + " = " + std::to_string(global_loot_entry.loottable_id));
update_values.push_back(columns[3] + " = " + std::to_string(global_loot_entry.enabled));
update_values.push_back(columns[4] + " = " + std::to_string(global_loot_entry.min_level));
update_values.push_back(columns[5] + " = " + std::to_string(global_loot_entry.max_level));
update_values.push_back(columns[6] + " = " + std::to_string(global_loot_entry.rare));
update_values.push_back(columns[7] + " = " + std::to_string(global_loot_entry.raid));
update_values.push_back(columns[8] + " = '" + EscapeString(global_loot_entry.race) + "'");
update_values.push_back(columns[9] + " = '" + EscapeString(global_loot_entry.
class) +"'");
update_values.push_back(columns[10] + " = '" + EscapeString(global_loot_entry.bodytype) + "'");
update_values.push_back(columns[11] + " = '" + EscapeString(global_loot_entry.zone) + "'");
update_values.push_back(columns[12] + " = " + std::to_string(global_loot_entry.hot_zone));
auto results = content_db.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
global_loot_entry.id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static GlobalLoot InsertOne(
GlobalLoot global_loot_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(global_loot_entry.description) + "'");
insert_values.push_back(std::to_string(global_loot_entry.loottable_id));
insert_values.push_back(std::to_string(global_loot_entry.enabled));
insert_values.push_back(std::to_string(global_loot_entry.min_level));
insert_values.push_back(std::to_string(global_loot_entry.max_level));
insert_values.push_back(std::to_string(global_loot_entry.rare));
insert_values.push_back(std::to_string(global_loot_entry.raid));
insert_values.push_back("'" + EscapeString(global_loot_entry.race) + "'");
insert_values.push_back("'" + EscapeString(global_loot_entry.
class) +"'");
insert_values.push_back("'" + EscapeString(global_loot_entry.bodytype) + "'");
insert_values.push_back("'" + EscapeString(global_loot_entry.zone) + "'");
insert_values.push_back(std::to_string(global_loot_entry.hot_zone));
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
global_loot_entry.id = results.LastInsertedID();
return global_loot_entry;
}
global_loot_entry = InstanceListRepository::NewEntity();
return global_loot_entry;
}
static int InsertMany(
std::vector<GlobalLoot> global_loot_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &global_loot_entry: global_loot_entries) {
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(global_loot_entry.description) + "'");
insert_values.push_back(std::to_string(global_loot_entry.loottable_id));
insert_values.push_back(std::to_string(global_loot_entry.enabled));
insert_values.push_back(std::to_string(global_loot_entry.min_level));
insert_values.push_back(std::to_string(global_loot_entry.max_level));
insert_values.push_back(std::to_string(global_loot_entry.rare));
insert_values.push_back(std::to_string(global_loot_entry.raid));
insert_values.push_back("'" + EscapeString(global_loot_entry.race) + "'");
insert_values.push_back("'" + EscapeString(global_loot_entry.
class) +"'");
insert_values.push_back("'" + EscapeString(global_loot_entry.bodytype) + "'");
insert_values.push_back("'" + EscapeString(global_loot_entry.zone) + "'");
insert_values.push_back(std::to_string(global_loot_entry.hot_zone));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<GlobalLoot> All()
{
std::vector<GlobalLoot> all_entries;
auto results = content_db.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
GlobalLoot entry{};
entry.id = atoi(row[0]);
entry.description = row[1];
entry.loottable_id = atoi(row[2]);
entry.enabled = atoi(row[3]);
entry.min_level = atoi(row[4]);
entry.max_level = atoi(row[5]);
entry.rare = atoi(row[6]);
entry.raid = atoi(row[7]);
entry.race = row[8];
entry.
class = row[9];
entry.bodytype = row[10];
entry.zone = row[11];
entry.hot_zone = atoi(row[12]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_GLOBAL_LOOT_REPOSITORY_H

View File

@ -0,0 +1,263 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_GM_IPS_REPOSITORY_H
#define EQEMU_GM_IPS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class GmIpsRepository {
public:
struct GmIps {
std::string name;
int account_id;
std::string ip_address;
};
static std::string PrimaryKey()
{
return std::string("ip_address");
}
static std::vector<std::string> Columns()
{
return {
"name",
"account_id",
"ip_address",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("gm_ips");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static GmIps NewEntity()
{
GmIps entry{};
entry.name = 0;
entry.account_id = 0;
entry.ip_address = 0;
return entry;
}
static GmIps GetGmIpsEntry(
const std::vector<GmIps> &gm_ipss,
int gm_ips_id
)
{
for (auto &gm_ips : gm_ipss) {
if (gm_ips.ip_address == gm_ips_id) {
return gm_ips;
}
}
return NewEntity();
}
static GmIps FindOne(
int gm_ips_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
gm_ips_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
GmIps entry{};
entry.name = row[0];
entry.account_id = atoi(row[1]);
entry.ip_address = row[2];
return entry;
}
return NewEntity();
}
static int DeleteOne(
int gm_ips_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
gm_ips_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
GmIps gm_ips_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[0] + " = '" + EscapeString(gm_ips_entry.name) + "'");
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
gm_ips_entry.ip_address
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static GmIps InsertOne(
GmIps gm_ips_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(gm_ips_entry.name) + "'");
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
gm_ips_entry.id = results.LastInsertedID();
return gm_ips_entry;
}
gm_ips_entry = InstanceListRepository::NewEntity();
return gm_ips_entry;
}
static int InsertMany(
std::vector<GmIps> gm_ips_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &gm_ips_entry: gm_ips_entries) {
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(gm_ips_entry.name) + "'");
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<GmIps> All()
{
std::vector<GmIps> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
GmIps entry{};
entry.name = row[0];
entry.account_id = atoi(row[1]);
entry.ip_address = row[2];
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_GM_IPS_REPOSITORY_H

View File

@ -0,0 +1,258 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_GOALLISTS_REPOSITORY_H
#define EQEMU_GOALLISTS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class GoallistsRepository {
public:
struct Goallists {
int listid;
int entry;
};
static std::string PrimaryKey()
{
return std::string("entry");
}
static std::vector<std::string> Columns()
{
return {
"listid",
"entry",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("goallists");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static Goallists NewEntity()
{
Goallists entry{};
entry.listid = 0;
entry.entry = 0;
return entry;
}
static Goallists GetGoallistsEntry(
const std::vector<Goallists> &goallistss,
int goallists_id
)
{
for (auto &goallists : goallistss) {
if (goallists.entry == goallists_id) {
return goallists;
}
}
return NewEntity();
}
static Goallists FindOne(
int goallists_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
goallists_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
Goallists entry{};
entry.listid = atoi(row[0]);
entry.entry = atoi(row[1]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int goallists_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
goallists_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
Goallists goallists_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
auto results = content_db.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
goallists_entry.entry
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static Goallists InsertOne(
Goallists goallists_entry
)
{
std::vector<std::string> insert_values;
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
goallists_entry.id = results.LastInsertedID();
return goallists_entry;
}
goallists_entry = InstanceListRepository::NewEntity();
return goallists_entry;
}
static int InsertMany(
std::vector<Goallists> goallists_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &goallists_entry: goallists_entries) {
std::vector<std::string> insert_values;
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<Goallists> All()
{
std::vector<Goallists> all_entries;
auto results = content_db.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
Goallists entry{};
entry.listid = atoi(row[0]);
entry.entry = atoi(row[1]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_GOALLISTS_REPOSITORY_H

View File

@ -0,0 +1,290 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_GRAVEYARD_REPOSITORY_H
#define EQEMU_GRAVEYARD_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class GraveyardRepository {
public:
struct Graveyard {
int id;
int zone_id;
std::string x;
std::string y;
std::string z;
std::string heading;
};
static std::string PrimaryKey()
{
return std::string("id");
}
static std::vector<std::string> Columns()
{
return {
"id",
"zone_id",
"x",
"y",
"z",
"heading",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("graveyard");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static Graveyard NewEntity()
{
Graveyard entry{};
entry.id = 0;
entry.zone_id = 0;
entry.x = 0;
entry.y = 0;
entry.z = 0;
entry.heading = 0;
return entry;
}
static Graveyard GetGraveyardEntry(
const std::vector<Graveyard> &graveyards,
int graveyard_id
)
{
for (auto &graveyard : graveyards) {
if (graveyard.id == graveyard_id) {
return graveyard;
}
}
return NewEntity();
}
static Graveyard FindOne(
int graveyard_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
graveyard_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
Graveyard entry{};
entry.id = atoi(row[0]);
entry.zone_id = atoi(row[1]);
entry.x = atof(row[2]);
entry.y = atof(row[3]);
entry.z = atof(row[4]);
entry.heading = atof(row[5]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int graveyard_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
graveyard_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
Graveyard graveyard_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[1] + " = " + std::to_string(graveyard_entry.zone_id));
update_values.push_back(columns[2] + " = '" + EscapeString(graveyard_entry.x) + "'");
update_values.push_back(columns[3] + " = '" + EscapeString(graveyard_entry.y) + "'");
update_values.push_back(columns[4] + " = '" + EscapeString(graveyard_entry.z) + "'");
update_values.push_back(columns[5] + " = '" + EscapeString(graveyard_entry.heading) + "'");
auto results = content_db.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
graveyard_entry.id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static Graveyard InsertOne(
Graveyard graveyard_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(graveyard_entry.zone_id));
insert_values.push_back("'" + EscapeString(graveyard_entry.x) + "'");
insert_values.push_back("'" + EscapeString(graveyard_entry.y) + "'");
insert_values.push_back("'" + EscapeString(graveyard_entry.z) + "'");
insert_values.push_back("'" + EscapeString(graveyard_entry.heading) + "'");
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
graveyard_entry.id = results.LastInsertedID();
return graveyard_entry;
}
graveyard_entry = InstanceListRepository::NewEntity();
return graveyard_entry;
}
static int InsertMany(
std::vector<Graveyard> graveyard_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &graveyard_entry: graveyard_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(graveyard_entry.zone_id));
insert_values.push_back("'" + EscapeString(graveyard_entry.x) + "'");
insert_values.push_back("'" + EscapeString(graveyard_entry.y) + "'");
insert_values.push_back("'" + EscapeString(graveyard_entry.z) + "'");
insert_values.push_back("'" + EscapeString(graveyard_entry.heading) + "'");
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<Graveyard> All()
{
std::vector<Graveyard> all_entries;
auto results = content_db.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
Graveyard entry{};
entry.id = atoi(row[0]);
entry.zone_id = atoi(row[1]);
entry.x = atof(row[2]);
entry.y = atof(row[3]);
entry.z = atof(row[4]);
entry.heading = atof(row[5]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_GRAVEYARD_REPOSITORY_H

View File

@ -0,0 +1,354 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_GROUND_SPAWNS_REPOSITORY_H
#define EQEMU_GROUND_SPAWNS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class GroundSpawnsRepository {
public:
struct GroundSpawns {
int id;
int zoneid;
int16 version;
std::string max_x;
std::string max_y;
std::string max_z;
std::string min_x;
std::string min_y;
std::string heading;
std::string name;
int item;
int max_allowed;
std::string comment;
int respawn_timer;
};
static std::string PrimaryKey()
{
return std::string("id");
}
static std::vector<std::string> Columns()
{
return {
"id",
"zoneid",
"version",
"max_x",
"max_y",
"max_z",
"min_x",
"min_y",
"heading",
"name",
"item",
"max_allowed",
"comment",
"respawn_timer",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("ground_spawns");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static GroundSpawns NewEntity()
{
GroundSpawns entry{};
entry.id = 0;
entry.zoneid = 0;
entry.version = 0;
entry.max_x = 2000;
entry.max_y = 2000;
entry.max_z = 10000;
entry.min_x = -2000;
entry.min_y = -2000;
entry.heading = 0;
entry.name = "";
entry.item = 0;
entry.max_allowed = 1;
entry.comment = "";
entry.respawn_timer = 300;
return entry;
}
static GroundSpawns GetGroundSpawnsEntry(
const std::vector<GroundSpawns> &ground_spawnss,
int ground_spawns_id
)
{
for (auto &ground_spawns : ground_spawnss) {
if (ground_spawns.id == ground_spawns_id) {
return ground_spawns;
}
}
return NewEntity();
}
static GroundSpawns FindOne(
int ground_spawns_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
ground_spawns_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
GroundSpawns entry{};
entry.id = atoi(row[0]);
entry.zoneid = atoi(row[1]);
entry.version = atoi(row[2]);
entry.max_x = atof(row[3]);
entry.max_y = atof(row[4]);
entry.max_z = atof(row[5]);
entry.min_x = atof(row[6]);
entry.min_y = atof(row[7]);
entry.heading = atof(row[8]);
entry.name = row[9];
entry.item = atoi(row[10]);
entry.max_allowed = atoi(row[11]);
entry.comment = row[12];
entry.respawn_timer = atoi(row[13]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int ground_spawns_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
ground_spawns_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
GroundSpawns ground_spawns_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[1] + " = " + std::to_string(ground_spawns_entry.zoneid));
update_values.push_back(columns[2] + " = " + std::to_string(ground_spawns_entry.version));
update_values.push_back(columns[3] + " = '" + EscapeString(ground_spawns_entry.max_x) + "'");
update_values.push_back(columns[4] + " = '" + EscapeString(ground_spawns_entry.max_y) + "'");
update_values.push_back(columns[5] + " = '" + EscapeString(ground_spawns_entry.max_z) + "'");
update_values.push_back(columns[6] + " = '" + EscapeString(ground_spawns_entry.min_x) + "'");
update_values.push_back(columns[7] + " = '" + EscapeString(ground_spawns_entry.min_y) + "'");
update_values.push_back(columns[8] + " = '" + EscapeString(ground_spawns_entry.heading) + "'");
update_values.push_back(columns[9] + " = '" + EscapeString(ground_spawns_entry.name) + "'");
update_values.push_back(columns[10] + " = " + std::to_string(ground_spawns_entry.item));
update_values.push_back(columns[11] + " = " + std::to_string(ground_spawns_entry.max_allowed));
update_values.push_back(columns[12] + " = '" + EscapeString(ground_spawns_entry.comment) + "'");
update_values.push_back(columns[13] + " = " + std::to_string(ground_spawns_entry.respawn_timer));
auto results = content_db.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
ground_spawns_entry.id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static GroundSpawns InsertOne(
GroundSpawns ground_spawns_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(ground_spawns_entry.zoneid));
insert_values.push_back(std::to_string(ground_spawns_entry.version));
insert_values.push_back("'" + EscapeString(ground_spawns_entry.max_x) + "'");
insert_values.push_back("'" + EscapeString(ground_spawns_entry.max_y) + "'");
insert_values.push_back("'" + EscapeString(ground_spawns_entry.max_z) + "'");
insert_values.push_back("'" + EscapeString(ground_spawns_entry.min_x) + "'");
insert_values.push_back("'" + EscapeString(ground_spawns_entry.min_y) + "'");
insert_values.push_back("'" + EscapeString(ground_spawns_entry.heading) + "'");
insert_values.push_back("'" + EscapeString(ground_spawns_entry.name) + "'");
insert_values.push_back(std::to_string(ground_spawns_entry.item));
insert_values.push_back(std::to_string(ground_spawns_entry.max_allowed));
insert_values.push_back("'" + EscapeString(ground_spawns_entry.comment) + "'");
insert_values.push_back(std::to_string(ground_spawns_entry.respawn_timer));
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
ground_spawns_entry.id = results.LastInsertedID();
return ground_spawns_entry;
}
ground_spawns_entry = InstanceListRepository::NewEntity();
return ground_spawns_entry;
}
static int InsertMany(
std::vector<GroundSpawns> ground_spawns_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &ground_spawns_entry: ground_spawns_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(ground_spawns_entry.zoneid));
insert_values.push_back(std::to_string(ground_spawns_entry.version));
insert_values.push_back("'" + EscapeString(ground_spawns_entry.max_x) + "'");
insert_values.push_back("'" + EscapeString(ground_spawns_entry.max_y) + "'");
insert_values.push_back("'" + EscapeString(ground_spawns_entry.max_z) + "'");
insert_values.push_back("'" + EscapeString(ground_spawns_entry.min_x) + "'");
insert_values.push_back("'" + EscapeString(ground_spawns_entry.min_y) + "'");
insert_values.push_back("'" + EscapeString(ground_spawns_entry.heading) + "'");
insert_values.push_back("'" + EscapeString(ground_spawns_entry.name) + "'");
insert_values.push_back(std::to_string(ground_spawns_entry.item));
insert_values.push_back(std::to_string(ground_spawns_entry.max_allowed));
insert_values.push_back("'" + EscapeString(ground_spawns_entry.comment) + "'");
insert_values.push_back(std::to_string(ground_spawns_entry.respawn_timer));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<GroundSpawns> All()
{
std::vector<GroundSpawns> all_entries;
auto results = content_db.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
GroundSpawns entry{};
entry.id = atoi(row[0]);
entry.zoneid = atoi(row[1]);
entry.version = atoi(row[2]);
entry.max_x = atof(row[3]);
entry.max_y = atof(row[4]);
entry.max_z = atof(row[5]);
entry.min_x = atof(row[6]);
entry.min_y = atof(row[7]);
entry.heading = atof(row[8]);
entry.name = row[9];
entry.item = atoi(row[10]);
entry.max_allowed = atoi(row[11]);
entry.comment = row[12];
entry.respawn_timer = atoi(row[13]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_GROUND_SPAWNS_REPOSITORY_H

View File

@ -0,0 +1,268 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_GROUP_ID_REPOSITORY_H
#define EQEMU_GROUP_ID_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class GroupIdRepository {
public:
struct GroupId {
int groupid;
int charid;
std::string name;
int8 ismerc;
};
static std::string PrimaryKey()
{
return std::string("ismerc");
}
static std::vector<std::string> Columns()
{
return {
"groupid",
"charid",
"name",
"ismerc",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("group_id");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static GroupId NewEntity()
{
GroupId entry{};
entry.groupid = 0;
entry.charid = 0;
entry.name = 0;
entry.ismerc = 0;
return entry;
}
static GroupId GetGroupIdEntry(
const std::vector<GroupId> &group_ids,
int group_id_id
)
{
for (auto &group_id : group_ids) {
if (group_id.ismerc == group_id_id) {
return group_id;
}
}
return NewEntity();
}
static GroupId FindOne(
int group_id_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
group_id_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
GroupId entry{};
entry.groupid = atoi(row[0]);
entry.charid = atoi(row[1]);
entry.name = row[2];
entry.ismerc = atoi(row[3]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int group_id_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
group_id_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
GroupId group_id_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[2] + " = '" + EscapeString(group_id_entry.name) + "'");
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
group_id_entry.ismerc
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static GroupId InsertOne(
GroupId group_id_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(group_id_entry.name) + "'");
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
group_id_entry.id = results.LastInsertedID();
return group_id_entry;
}
group_id_entry = InstanceListRepository::NewEntity();
return group_id_entry;
}
static int InsertMany(
std::vector<GroupId> group_id_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &group_id_entry: group_id_entries) {
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(group_id_entry.name) + "'");
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<GroupId> All()
{
std::vector<GroupId> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
GroupId entry{};
entry.groupid = atoi(row[0]);
entry.charid = atoi(row[1]);
entry.name = row[2];
entry.ismerc = atoi(row[3]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_GROUP_ID_REPOSITORY_H

View File

@ -0,0 +1,314 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_GROUP_LEADERS_REPOSITORY_H
#define EQEMU_GROUP_LEADERS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class GroupLeadersRepository {
public:
struct GroupLeaders {
int gid;
std::string leadername;
std::string marknpc;
std::string leadershipaa;
std::string maintank;
std::string assist;
std::string puller;
std::string mentoree;
int mentor_percent;
};
static std::string PrimaryKey()
{
return std::string("gid");
}
static std::vector<std::string> Columns()
{
return {
"gid",
"leadername",
"marknpc",
"leadershipaa",
"maintank",
"assist",
"puller",
"mentoree",
"mentor_percent",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("group_leaders");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static GroupLeaders NewEntity()
{
GroupLeaders entry{};
entry.gid = 0;
entry.leadername = "";
entry.marknpc = "";
entry.leadershipaa = 0;
entry.maintank = "";
entry.assist = "";
entry.puller = "";
entry.mentoree = 0;
entry.mentor_percent = 0;
return entry;
}
static GroupLeaders GetGroupLeadersEntry(
const std::vector<GroupLeaders> &group_leaderss,
int group_leaders_id
)
{
for (auto &group_leaders : group_leaderss) {
if (group_leaders.gid == group_leaders_id) {
return group_leaders;
}
}
return NewEntity();
}
static GroupLeaders FindOne(
int group_leaders_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
group_leaders_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
GroupLeaders entry{};
entry.gid = atoi(row[0]);
entry.leadername = row[1];
entry.marknpc = row[2];
entry.leadershipaa = row[3];
entry.maintank = row[4];
entry.assist = row[5];
entry.puller = row[6];
entry.mentoree = row[7];
entry.mentor_percent = atoi(row[8]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int group_leaders_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
group_leaders_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
GroupLeaders group_leaders_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[1] + " = '" + EscapeString(group_leaders_entry.leadername) + "'");
update_values.push_back(columns[2] + " = '" + EscapeString(group_leaders_entry.marknpc) + "'");
update_values.push_back(columns[3] + " = '" + EscapeString(group_leaders_entry.leadershipaa) + "'");
update_values.push_back(columns[4] + " = '" + EscapeString(group_leaders_entry.maintank) + "'");
update_values.push_back(columns[5] + " = '" + EscapeString(group_leaders_entry.assist) + "'");
update_values.push_back(columns[6] + " = '" + EscapeString(group_leaders_entry.puller) + "'");
update_values.push_back(columns[7] + " = '" + EscapeString(group_leaders_entry.mentoree) + "'");
update_values.push_back(columns[8] + " = " + std::to_string(group_leaders_entry.mentor_percent));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
group_leaders_entry.gid
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static GroupLeaders InsertOne(
GroupLeaders group_leaders_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(group_leaders_entry.leadername) + "'");
insert_values.push_back("'" + EscapeString(group_leaders_entry.marknpc) + "'");
insert_values.push_back("'" + EscapeString(group_leaders_entry.leadershipaa) + "'");
insert_values.push_back("'" + EscapeString(group_leaders_entry.maintank) + "'");
insert_values.push_back("'" + EscapeString(group_leaders_entry.assist) + "'");
insert_values.push_back("'" + EscapeString(group_leaders_entry.puller) + "'");
insert_values.push_back("'" + EscapeString(group_leaders_entry.mentoree) + "'");
insert_values.push_back(std::to_string(group_leaders_entry.mentor_percent));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
group_leaders_entry.id = results.LastInsertedID();
return group_leaders_entry;
}
group_leaders_entry = InstanceListRepository::NewEntity();
return group_leaders_entry;
}
static int InsertMany(
std::vector<GroupLeaders> group_leaders_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &group_leaders_entry: group_leaders_entries) {
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(group_leaders_entry.leadername) + "'");
insert_values.push_back("'" + EscapeString(group_leaders_entry.marknpc) + "'");
insert_values.push_back("'" + EscapeString(group_leaders_entry.leadershipaa) + "'");
insert_values.push_back("'" + EscapeString(group_leaders_entry.maintank) + "'");
insert_values.push_back("'" + EscapeString(group_leaders_entry.assist) + "'");
insert_values.push_back("'" + EscapeString(group_leaders_entry.puller) + "'");
insert_values.push_back("'" + EscapeString(group_leaders_entry.mentoree) + "'");
insert_values.push_back(std::to_string(group_leaders_entry.mentor_percent));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<GroupLeaders> All()
{
std::vector<GroupLeaders> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
GroupLeaders entry{};
entry.gid = atoi(row[0]);
entry.leadername = row[1];
entry.marknpc = row[2];
entry.leadershipaa = row[3];
entry.maintank = row[4];
entry.assist = row[5];
entry.puller = row[6];
entry.mentoree = row[7];
entry.mentor_percent = atoi(row[8]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_GROUP_LEADERS_REPOSITORY_H

View File

@ -0,0 +1,309 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_GUILD_BANK_REPOSITORY_H
#define EQEMU_GUILD_BANK_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class GuildBankRepository {
public:
struct GuildBank {
int guildid;
int8 area;
int slot;
int itemid;
int qty;
std::string donator;
int8 permissions;
std::string whofor;
};
static std::string PrimaryKey()
{
return std::string("");
}
static std::vector<std::string> Columns()
{
return {
"guildid",
"area",
"slot",
"itemid",
"qty",
"donator",
"permissions",
"whofor",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("guild_bank");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static GuildBank NewEntity()
{
GuildBank entry{};
entry.guildid = 0;
entry.area = 0;
entry.slot = 0;
entry.itemid = 0;
entry.qty = 0;
entry.donator = 0;
entry.permissions = 0;
entry.whofor = 0;
return entry;
}
static GuildBank GetGuildBankEntry(
const std::vector<GuildBank> &guild_banks,
int guild_bank_id
)
{
for (auto &guild_bank : guild_banks) {
if (guild_bank. == guild_bank_id) {
return guild_bank;
}
}
return NewEntity();
}
static GuildBank FindOne(
int guild_bank_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
guild_bank_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
GuildBank entry{};
entry.guildid = atoi(row[0]);
entry.area = atoi(row[1]);
entry.slot = atoi(row[2]);
entry.itemid = atoi(row[3]);
entry.qty = atoi(row[4]);
entry.donator = row[5];
entry.permissions = atoi(row[6]);
entry.whofor = row[7];
return entry;
}
return NewEntity();
}
static int DeleteOne(
int guild_bank_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
guild_bank_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
GuildBank guild_bank_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[0] + " = " + std::to_string(guild_bank_entry.guildid));
update_values.push_back(columns[1] + " = " + std::to_string(guild_bank_entry.area));
update_values.push_back(columns[2] + " = " + std::to_string(guild_bank_entry.slot));
update_values.push_back(columns[3] + " = " + std::to_string(guild_bank_entry.itemid));
update_values.push_back(columns[4] + " = " + std::to_string(guild_bank_entry.qty));
update_values.push_back(columns[5] + " = '" + EscapeString(guild_bank_entry.donator) + "'");
update_values.push_back(columns[6] + " = " + std::to_string(guild_bank_entry.permissions));
update_values.push_back(columns[7] + " = '" + EscapeString(guild_bank_entry.whofor) + "'");
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
guild_bank_entry.
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static GuildBank InsertOne(
GuildBank guild_bank_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(guild_bank_entry.guildid));
insert_values.push_back(std::to_string(guild_bank_entry.area));
insert_values.push_back(std::to_string(guild_bank_entry.slot));
insert_values.push_back(std::to_string(guild_bank_entry.itemid));
insert_values.push_back(std::to_string(guild_bank_entry.qty));
insert_values.push_back("'" + EscapeString(guild_bank_entry.donator) + "'");
insert_values.push_back(std::to_string(guild_bank_entry.permissions));
insert_values.push_back("'" + EscapeString(guild_bank_entry.whofor) + "'");
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
guild_bank_entry.id = results.LastInsertedID();
return guild_bank_entry;
}
guild_bank_entry = InstanceListRepository::NewEntity();
return guild_bank_entry;
}
static int InsertMany(
std::vector<GuildBank> guild_bank_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &guild_bank_entry: guild_bank_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(guild_bank_entry.guildid));
insert_values.push_back(std::to_string(guild_bank_entry.area));
insert_values.push_back(std::to_string(guild_bank_entry.slot));
insert_values.push_back(std::to_string(guild_bank_entry.itemid));
insert_values.push_back(std::to_string(guild_bank_entry.qty));
insert_values.push_back("'" + EscapeString(guild_bank_entry.donator) + "'");
insert_values.push_back(std::to_string(guild_bank_entry.permissions));
insert_values.push_back("'" + EscapeString(guild_bank_entry.whofor) + "'");
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<GuildBank> All()
{
std::vector<GuildBank> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
GuildBank entry{};
entry.guildid = atoi(row[0]);
entry.area = atoi(row[1]);
entry.slot = atoi(row[2]);
entry.itemid = atoi(row[3]);
entry.qty = atoi(row[4]);
entry.donator = row[5];
entry.permissions = atoi(row[6]);
entry.whofor = row[7];
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_GUILD_BANK_REPOSITORY_H

View File

@ -0,0 +1,314 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_GUILD_MEMBERS_REPOSITORY_H
#define EQEMU_GUILD_MEMBERS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class GuildMembersRepository {
public:
struct GuildMembers {
int char_id;
int guild_id;
int8 rank;
int8 tribute_enable;
int total_tribute;
int last_tribute;
int8 banker;
std::string public_note;
int8 alt;
};
static std::string PrimaryKey()
{
return std::string("char_id");
}
static std::vector<std::string> Columns()
{
return {
"char_id",
"guild_id",
"rank",
"tribute_enable",
"total_tribute",
"last_tribute",
"banker",
"public_note",
"alt",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("guild_members");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static GuildMembers NewEntity()
{
GuildMembers entry{};
entry.char_id = 0;
entry.guild_id = 0;
entry.rank = 0;
entry.tribute_enable = 0;
entry.total_tribute = 0;
entry.last_tribute = 0;
entry.banker = 0;
entry.public_note = 0;
entry.alt = 0;
return entry;
}
static GuildMembers GetGuildMembersEntry(
const std::vector<GuildMembers> &guild_memberss,
int guild_members_id
)
{
for (auto &guild_members : guild_memberss) {
if (guild_members.char_id == guild_members_id) {
return guild_members;
}
}
return NewEntity();
}
static GuildMembers FindOne(
int guild_members_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
guild_members_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
GuildMembers entry{};
entry.char_id = atoi(row[0]);
entry.guild_id = atoi(row[1]);
entry.rank = atoi(row[2]);
entry.tribute_enable = atoi(row[3]);
entry.total_tribute = atoi(row[4]);
entry.last_tribute = atoi(row[5]);
entry.banker = atoi(row[6]);
entry.public_note = row[7];
entry.alt = atoi(row[8]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int guild_members_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
guild_members_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
GuildMembers guild_members_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[1] + " = " + std::to_string(guild_members_entry.guild_id));
update_values.push_back(columns[2] + " = " + std::to_string(guild_members_entry.rank));
update_values.push_back(columns[3] + " = " + std::to_string(guild_members_entry.tribute_enable));
update_values.push_back(columns[4] + " = " + std::to_string(guild_members_entry.total_tribute));
update_values.push_back(columns[5] + " = " + std::to_string(guild_members_entry.last_tribute));
update_values.push_back(columns[6] + " = " + std::to_string(guild_members_entry.banker));
update_values.push_back(columns[7] + " = '" + EscapeString(guild_members_entry.public_note) + "'");
update_values.push_back(columns[8] + " = " + std::to_string(guild_members_entry.alt));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
guild_members_entry.char_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static GuildMembers InsertOne(
GuildMembers guild_members_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(guild_members_entry.guild_id));
insert_values.push_back(std::to_string(guild_members_entry.rank));
insert_values.push_back(std::to_string(guild_members_entry.tribute_enable));
insert_values.push_back(std::to_string(guild_members_entry.total_tribute));
insert_values.push_back(std::to_string(guild_members_entry.last_tribute));
insert_values.push_back(std::to_string(guild_members_entry.banker));
insert_values.push_back("'" + EscapeString(guild_members_entry.public_note) + "'");
insert_values.push_back(std::to_string(guild_members_entry.alt));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
guild_members_entry.id = results.LastInsertedID();
return guild_members_entry;
}
guild_members_entry = InstanceListRepository::NewEntity();
return guild_members_entry;
}
static int InsertMany(
std::vector<GuildMembers> guild_members_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &guild_members_entry: guild_members_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(guild_members_entry.guild_id));
insert_values.push_back(std::to_string(guild_members_entry.rank));
insert_values.push_back(std::to_string(guild_members_entry.tribute_enable));
insert_values.push_back(std::to_string(guild_members_entry.total_tribute));
insert_values.push_back(std::to_string(guild_members_entry.last_tribute));
insert_values.push_back(std::to_string(guild_members_entry.banker));
insert_values.push_back("'" + EscapeString(guild_members_entry.public_note) + "'");
insert_values.push_back(std::to_string(guild_members_entry.alt));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<GuildMembers> All()
{
std::vector<GuildMembers> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
GuildMembers entry{};
entry.char_id = atoi(row[0]);
entry.guild_id = atoi(row[1]);
entry.rank = atoi(row[2]);
entry.tribute_enable = atoi(row[3]);
entry.total_tribute = atoi(row[4]);
entry.last_tribute = atoi(row[5]);
entry.banker = atoi(row[6]);
entry.public_note = row[7];
entry.alt = atoi(row[8]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_GUILD_MEMBERS_REPOSITORY_H

View File

@ -0,0 +1,327 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_GUILD_RANKS_REPOSITORY_H
#define EQEMU_GUILD_RANKS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class GuildRanksRepository {
public:
struct GuildRanks {
int guild_id;
int8 rank;
std::string title;
int8 can_hear;
int8 can_speak;
int8 can_invite;
int8 can_remove;
int8 can_promote;
int8 can_demote;
int8 can_motd;
int8 can_warpeace;
};
static std::string PrimaryKey()
{
return std::string("rank");
}
static std::vector<std::string> Columns()
{
return {
"guild_id",
"rank",
"title",
"can_hear",
"can_speak",
"can_invite",
"can_remove",
"can_promote",
"can_demote",
"can_motd",
"can_warpeace",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("guild_ranks");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static GuildRanks NewEntity()
{
GuildRanks entry{};
entry.guild_id = 0;
entry.rank = 0;
entry.title = "";
entry.can_hear = 0;
entry.can_speak = 0;
entry.can_invite = 0;
entry.can_remove = 0;
entry.can_promote = 0;
entry.can_demote = 0;
entry.can_motd = 0;
entry.can_warpeace = 0;
return entry;
}
static GuildRanks GetGuildRanksEntry(
const std::vector<GuildRanks> &guild_rankss,
int guild_ranks_id
)
{
for (auto &guild_ranks : guild_rankss) {
if (guild_ranks.rank == guild_ranks_id) {
return guild_ranks;
}
}
return NewEntity();
}
static GuildRanks FindOne(
int guild_ranks_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
guild_ranks_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
GuildRanks entry{};
entry.guild_id = atoi(row[0]);
entry.rank = atoi(row[1]);
entry.title = row[2];
entry.can_hear = atoi(row[3]);
entry.can_speak = atoi(row[4]);
entry.can_invite = atoi(row[5]);
entry.can_remove = atoi(row[6]);
entry.can_promote = atoi(row[7]);
entry.can_demote = atoi(row[8]);
entry.can_motd = atoi(row[9]);
entry.can_warpeace = atoi(row[10]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int guild_ranks_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
guild_ranks_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
GuildRanks guild_ranks_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[2] + " = '" + EscapeString(guild_ranks_entry.title) + "'");
update_values.push_back(columns[3] + " = " + std::to_string(guild_ranks_entry.can_hear));
update_values.push_back(columns[4] + " = " + std::to_string(guild_ranks_entry.can_speak));
update_values.push_back(columns[5] + " = " + std::to_string(guild_ranks_entry.can_invite));
update_values.push_back(columns[6] + " = " + std::to_string(guild_ranks_entry.can_remove));
update_values.push_back(columns[7] + " = " + std::to_string(guild_ranks_entry.can_promote));
update_values.push_back(columns[8] + " = " + std::to_string(guild_ranks_entry.can_demote));
update_values.push_back(columns[9] + " = " + std::to_string(guild_ranks_entry.can_motd));
update_values.push_back(columns[10] + " = " + std::to_string(guild_ranks_entry.can_warpeace));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
guild_ranks_entry.rank
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static GuildRanks InsertOne(
GuildRanks guild_ranks_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(guild_ranks_entry.title) + "'");
insert_values.push_back(std::to_string(guild_ranks_entry.can_hear));
insert_values.push_back(std::to_string(guild_ranks_entry.can_speak));
insert_values.push_back(std::to_string(guild_ranks_entry.can_invite));
insert_values.push_back(std::to_string(guild_ranks_entry.can_remove));
insert_values.push_back(std::to_string(guild_ranks_entry.can_promote));
insert_values.push_back(std::to_string(guild_ranks_entry.can_demote));
insert_values.push_back(std::to_string(guild_ranks_entry.can_motd));
insert_values.push_back(std::to_string(guild_ranks_entry.can_warpeace));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
guild_ranks_entry.id = results.LastInsertedID();
return guild_ranks_entry;
}
guild_ranks_entry = InstanceListRepository::NewEntity();
return guild_ranks_entry;
}
static int InsertMany(
std::vector<GuildRanks> guild_ranks_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &guild_ranks_entry: guild_ranks_entries) {
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(guild_ranks_entry.title) + "'");
insert_values.push_back(std::to_string(guild_ranks_entry.can_hear));
insert_values.push_back(std::to_string(guild_ranks_entry.can_speak));
insert_values.push_back(std::to_string(guild_ranks_entry.can_invite));
insert_values.push_back(std::to_string(guild_ranks_entry.can_remove));
insert_values.push_back(std::to_string(guild_ranks_entry.can_promote));
insert_values.push_back(std::to_string(guild_ranks_entry.can_demote));
insert_values.push_back(std::to_string(guild_ranks_entry.can_motd));
insert_values.push_back(std::to_string(guild_ranks_entry.can_warpeace));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<GuildRanks> All()
{
std::vector<GuildRanks> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
GuildRanks entry{};
entry.guild_id = atoi(row[0]);
entry.rank = atoi(row[1]);
entry.title = row[2];
entry.can_hear = atoi(row[3]);
entry.can_speak = atoi(row[4]);
entry.can_invite = atoi(row[5]);
entry.can_remove = atoi(row[6]);
entry.can_promote = atoi(row[7]);
entry.can_demote = atoi(row[8]);
entry.can_motd = atoi(row[9]);
entry.can_warpeace = atoi(row[10]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_GUILD_RANKS_REPOSITORY_H

View File

@ -0,0 +1,263 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_GUILD_RELATIONS_REPOSITORY_H
#define EQEMU_GUILD_RELATIONS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class GuildRelationsRepository {
public:
struct GuildRelations {
int guild1;
int guild2;
int8 relation;
};
static std::string PrimaryKey()
{
return std::string("guild2");
}
static std::vector<std::string> Columns()
{
return {
"guild1",
"guild2",
"relation",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("guild_relations");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static GuildRelations NewEntity()
{
GuildRelations entry{};
entry.guild1 = 0;
entry.guild2 = 0;
entry.relation = 0;
return entry;
}
static GuildRelations GetGuildRelationsEntry(
const std::vector<GuildRelations> &guild_relationss,
int guild_relations_id
)
{
for (auto &guild_relations : guild_relationss) {
if (guild_relations.guild2 == guild_relations_id) {
return guild_relations;
}
}
return NewEntity();
}
static GuildRelations FindOne(
int guild_relations_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
guild_relations_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
GuildRelations entry{};
entry.guild1 = atoi(row[0]);
entry.guild2 = atoi(row[1]);
entry.relation = atoi(row[2]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int guild_relations_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
guild_relations_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
GuildRelations guild_relations_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[2] + " = " + std::to_string(guild_relations_entry.relation));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
guild_relations_entry.guild2
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static GuildRelations InsertOne(
GuildRelations guild_relations_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(guild_relations_entry.relation));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
guild_relations_entry.id = results.LastInsertedID();
return guild_relations_entry;
}
guild_relations_entry = InstanceListRepository::NewEntity();
return guild_relations_entry;
}
static int InsertMany(
std::vector<GuildRelations> guild_relations_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &guild_relations_entry: guild_relations_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(guild_relations_entry.relation));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<GuildRelations> All()
{
std::vector<GuildRelations> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
GuildRelations entry{};
entry.guild1 = atoi(row[0]);
entry.guild2 = atoi(row[1]);
entry.relation = atoi(row[2]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_GUILD_RELATIONS_REPOSITORY_H

View File

@ -0,0 +1,314 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_GUILDS_REPOSITORY_H
#define EQEMU_GUILDS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class GuildsRepository {
public:
struct Guilds {
int id;
std::string name;
int leader;
int16 minstatus;
std::string motd;
int tribute;
std::string motd_setter;
std::string channel;
std::string url;
};
static std::string PrimaryKey()
{
return std::string("id");
}
static std::vector<std::string> Columns()
{
return {
"id",
"name",
"leader",
"minstatus",
"motd",
"tribute",
"motd_setter",
"channel",
"url",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("guilds");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static Guilds NewEntity()
{
Guilds entry{};
entry.id = 0;
entry.name = "";
entry.leader = 0;
entry.minstatus = 0;
entry.motd = 0;
entry.tribute = 0;
entry.motd_setter = "";
entry.channel = "";
entry.url = "";
return entry;
}
static Guilds GetGuildsEntry(
const std::vector<Guilds> &guildss,
int guilds_id
)
{
for (auto &guilds : guildss) {
if (guilds.id == guilds_id) {
return guilds;
}
}
return NewEntity();
}
static Guilds FindOne(
int guilds_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
guilds_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
Guilds entry{};
entry.id = atoi(row[0]);
entry.name = row[1];
entry.leader = atoi(row[2]);
entry.minstatus = atoi(row[3]);
entry.motd = row[4];
entry.tribute = atoi(row[5]);
entry.motd_setter = row[6];
entry.channel = row[7];
entry.url = row[8];
return entry;
}
return NewEntity();
}
static int DeleteOne(
int guilds_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
guilds_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
Guilds guilds_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[1] + " = '" + EscapeString(guilds_entry.name) + "'");
update_values.push_back(columns[2] + " = " + std::to_string(guilds_entry.leader));
update_values.push_back(columns[3] + " = " + std::to_string(guilds_entry.minstatus));
update_values.push_back(columns[4] + " = '" + EscapeString(guilds_entry.motd) + "'");
update_values.push_back(columns[5] + " = " + std::to_string(guilds_entry.tribute));
update_values.push_back(columns[6] + " = '" + EscapeString(guilds_entry.motd_setter) + "'");
update_values.push_back(columns[7] + " = '" + EscapeString(guilds_entry.channel) + "'");
update_values.push_back(columns[8] + " = '" + EscapeString(guilds_entry.url) + "'");
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
guilds_entry.id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static Guilds InsertOne(
Guilds guilds_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(guilds_entry.name) + "'");
insert_values.push_back(std::to_string(guilds_entry.leader));
insert_values.push_back(std::to_string(guilds_entry.minstatus));
insert_values.push_back("'" + EscapeString(guilds_entry.motd) + "'");
insert_values.push_back(std::to_string(guilds_entry.tribute));
insert_values.push_back("'" + EscapeString(guilds_entry.motd_setter) + "'");
insert_values.push_back("'" + EscapeString(guilds_entry.channel) + "'");
insert_values.push_back("'" + EscapeString(guilds_entry.url) + "'");
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
guilds_entry.id = results.LastInsertedID();
return guilds_entry;
}
guilds_entry = InstanceListRepository::NewEntity();
return guilds_entry;
}
static int InsertMany(
std::vector<Guilds> guilds_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &guilds_entry: guilds_entries) {
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(guilds_entry.name) + "'");
insert_values.push_back(std::to_string(guilds_entry.leader));
insert_values.push_back(std::to_string(guilds_entry.minstatus));
insert_values.push_back("'" + EscapeString(guilds_entry.motd) + "'");
insert_values.push_back(std::to_string(guilds_entry.tribute));
insert_values.push_back("'" + EscapeString(guilds_entry.motd_setter) + "'");
insert_values.push_back("'" + EscapeString(guilds_entry.channel) + "'");
insert_values.push_back("'" + EscapeString(guilds_entry.url) + "'");
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<Guilds> All()
{
std::vector<Guilds> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
Guilds entry{};
entry.id = atoi(row[0]);
entry.name = row[1];
entry.leader = atoi(row[2]);
entry.minstatus = atoi(row[3]);
entry.motd = row[4];
entry.tribute = atoi(row[5]);
entry.motd_setter = row[6];
entry.channel = row[7];
entry.url = row[8];
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_GUILDS_REPOSITORY_H

View File

@ -0,0 +1,290 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_HACKERS_REPOSITORY_H
#define EQEMU_HACKERS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class HackersRepository {
public:
struct Hackers {
int id;
std::string account;
std::string name;
std::string hacked;
std::string zone;
std::string date;
};
static std::string PrimaryKey()
{
return std::string("id");
}
static std::vector<std::string> Columns()
{
return {
"id",
"account",
"name",
"hacked",
"zone",
"date",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("hackers");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static Hackers NewEntity()
{
Hackers entry{};
entry.id = 0;
entry.account = 0;
entry.name = 0;
entry.hacked = 0;
entry.zone = 0;
entry.date = current_timestamp();
return entry;
}
static Hackers GetHackersEntry(
const std::vector<Hackers> &hackerss,
int hackers_id
)
{
for (auto &hackers : hackerss) {
if (hackers.id == hackers_id) {
return hackers;
}
}
return NewEntity();
}
static Hackers FindOne(
int hackers_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
hackers_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
Hackers entry{};
entry.id = atoi(row[0]);
entry.account = row[1];
entry.name = row[2];
entry.hacked = row[3];
entry.zone = row[4];
entry.date = row[5];
return entry;
}
return NewEntity();
}
static int DeleteOne(
int hackers_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
hackers_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
Hackers hackers_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[1] + " = '" + EscapeString(hackers_entry.account) + "'");
update_values.push_back(columns[2] + " = '" + EscapeString(hackers_entry.name) + "'");
update_values.push_back(columns[3] + " = '" + EscapeString(hackers_entry.hacked) + "'");
update_values.push_back(columns[4] + " = '" + EscapeString(hackers_entry.zone) + "'");
update_values.push_back(columns[5] + " = '" + EscapeString(hackers_entry.date) + "'");
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
hackers_entry.id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static Hackers InsertOne(
Hackers hackers_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(hackers_entry.account) + "'");
insert_values.push_back("'" + EscapeString(hackers_entry.name) + "'");
insert_values.push_back("'" + EscapeString(hackers_entry.hacked) + "'");
insert_values.push_back("'" + EscapeString(hackers_entry.zone) + "'");
insert_values.push_back("'" + EscapeString(hackers_entry.date) + "'");
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
hackers_entry.id = results.LastInsertedID();
return hackers_entry;
}
hackers_entry = InstanceListRepository::NewEntity();
return hackers_entry;
}
static int InsertMany(
std::vector<Hackers> hackers_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &hackers_entry: hackers_entries) {
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(hackers_entry.account) + "'");
insert_values.push_back("'" + EscapeString(hackers_entry.name) + "'");
insert_values.push_back("'" + EscapeString(hackers_entry.hacked) + "'");
insert_values.push_back("'" + EscapeString(hackers_entry.zone) + "'");
insert_values.push_back("'" + EscapeString(hackers_entry.date) + "'");
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<Hackers> All()
{
std::vector<Hackers> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
Hackers entry{};
entry.id = atoi(row[0]);
entry.account = row[1];
entry.name = row[2];
entry.hacked = row[3];
entry.zone = row[4];
entry.date = row[5];
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_HACKERS_REPOSITORY_H

View File

@ -0,0 +1,290 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_HORSES_REPOSITORY_H
#define EQEMU_HORSES_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class HorsesRepository {
public:
struct Horses {
std::string filename;
int16 race;
int8 gender;
int8 texture;
std::string mountspeed;
std::string notes;
};
static std::string PrimaryKey()
{
return std::string("filename");
}
static std::vector<std::string> Columns()
{
return {
"filename",
"race",
"gender",
"texture",
"mountspeed",
"notes",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("horses");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static Horses NewEntity()
{
Horses entry{};
entry.filename = "";
entry.race = 216;
entry.gender = 0;
entry.texture = 0;
entry.mountspeed = 0.75;
entry.notes = 'Notes';
return entry;
}
static Horses GetHorsesEntry(
const std::vector<Horses> &horsess,
int horses_id
)
{
for (auto &horses : horsess) {
if (horses.filename == horses_id) {
return horses;
}
}
return NewEntity();
}
static Horses FindOne(
int horses_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
horses_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
Horses entry{};
entry.filename = row[0];
entry.race = atoi(row[1]);
entry.gender = atoi(row[2]);
entry.texture = atoi(row[3]);
entry.mountspeed = atof(row[4]);
entry.notes = row[5];
return entry;
}
return NewEntity();
}
static int DeleteOne(
int horses_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
horses_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
Horses horses_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[1] + " = " + std::to_string(horses_entry.race));
update_values.push_back(columns[2] + " = " + std::to_string(horses_entry.gender));
update_values.push_back(columns[3] + " = " + std::to_string(horses_entry.texture));
update_values.push_back(columns[4] + " = '" + EscapeString(horses_entry.mountspeed) + "'");
update_values.push_back(columns[5] + " = '" + EscapeString(horses_entry.notes) + "'");
auto results = content_db.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
horses_entry.filename
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static Horses InsertOne(
Horses horses_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(horses_entry.race));
insert_values.push_back(std::to_string(horses_entry.gender));
insert_values.push_back(std::to_string(horses_entry.texture));
insert_values.push_back("'" + EscapeString(horses_entry.mountspeed) + "'");
insert_values.push_back("'" + EscapeString(horses_entry.notes) + "'");
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
horses_entry.id = results.LastInsertedID();
return horses_entry;
}
horses_entry = InstanceListRepository::NewEntity();
return horses_entry;
}
static int InsertMany(
std::vector<Horses> horses_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &horses_entry: horses_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(horses_entry.race));
insert_values.push_back(std::to_string(horses_entry.gender));
insert_values.push_back(std::to_string(horses_entry.texture));
insert_values.push_back("'" + EscapeString(horses_entry.mountspeed) + "'");
insert_values.push_back("'" + EscapeString(horses_entry.notes) + "'");
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<Horses> All()
{
std::vector<Horses> all_entries;
auto results = content_db.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
Horses entry{};
entry.filename = row[0];
entry.race = atoi(row[1]);
entry.gender = atoi(row[2]);
entry.texture = atoi(row[3]);
entry.mountspeed = atof(row[4]);
entry.notes = row[5];
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_HORSES_REPOSITORY_H

View File

@ -0,0 +1,258 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_INSTANCE_LIST_PLAYER_REPOSITORY_H
#define EQEMU_INSTANCE_LIST_PLAYER_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class InstanceListPlayerRepository {
public:
struct InstanceListPlayer {
int id;
int charid;
};
static std::string PrimaryKey()
{
return std::string("charid");
}
static std::vector<std::string> Columns()
{
return {
"id",
"charid",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("instance_list_player");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static InstanceListPlayer NewEntity()
{
InstanceListPlayer entry{};
entry.id = 0;
entry.charid = 0;
return entry;
}
static InstanceListPlayer GetInstanceListPlayerEntry(
const std::vector<InstanceListPlayer> &instance_list_players,
int instance_list_player_id
)
{
for (auto &instance_list_player : instance_list_players) {
if (instance_list_player.charid == instance_list_player_id) {
return instance_list_player;
}
}
return NewEntity();
}
static InstanceListPlayer FindOne(
int instance_list_player_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
instance_list_player_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
InstanceListPlayer entry{};
entry.id = atoi(row[0]);
entry.charid = atoi(row[1]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int instance_list_player_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
instance_list_player_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
InstanceListPlayer instance_list_player_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
instance_list_player_entry.charid
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static InstanceListPlayer InsertOne(
InstanceListPlayer instance_list_player_entry
)
{
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
instance_list_player_entry.id = results.LastInsertedID();
return instance_list_player_entry;
}
instance_list_player_entry = InstanceListRepository::NewEntity();
return instance_list_player_entry;
}
static int InsertMany(
std::vector<InstanceListPlayer> instance_list_player_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &instance_list_player_entry: instance_list_player_entries) {
std::vector<std::string> insert_values;
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<InstanceListPlayer> All()
{
std::vector<InstanceListPlayer> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
InstanceListPlayer entry{};
entry.id = atoi(row[0]);
entry.charid = atoi(row[1]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_INSTANCE_LIST_PLAYER_REPOSITORY_H

View File

@ -29,11 +29,11 @@ public:
struct InstanceList {
int id;
int zone;
int8 version;
int8 is_global;
int version;
int is_global;
int start_time;
int duration;
int8 never_expires;
int never_expires;
};
static std::string PrimaryKey()

View File

@ -0,0 +1,367 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_INVENTORY_REPOSITORY_H
#define EQEMU_INVENTORY_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class InventoryRepository {
public:
struct Inventory {
int charid;
int slotid;
int itemid;
int16 charges;
int color;
int augslot1;
int augslot2;
int augslot3;
int augslot4;
int augslot5;
int augslot6;
int8 instnodrop;
std::string custom_data;
int ornamenticon;
int ornamentidfile;
int ornament_hero_model;
};
static std::string PrimaryKey()
{
return std::string("slotid");
}
static std::vector<std::string> Columns()
{
return {
"charid",
"slotid",
"itemid",
"charges",
"color",
"augslot1",
"augslot2",
"augslot3",
"augslot4",
"augslot5",
"augslot6",
"instnodrop",
"custom_data",
"ornamenticon",
"ornamentidfile",
"ornament_hero_model",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("inventory");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static Inventory NewEntity()
{
Inventory entry{};
entry.charid = 0;
entry.slotid = 0;
entry.itemid = 0;
entry.charges = 0;
entry.color = 0;
entry.augslot1 = 0;
entry.augslot2 = 0;
entry.augslot3 = 0;
entry.augslot4 = 0;
entry.augslot5 = 0;
entry.augslot6 = 0;
entry.instnodrop = 0;
entry.custom_data = 0;
entry.ornamenticon = 0;
entry.ornamentidfile = 0;
entry.ornament_hero_model = 0;
return entry;
}
static Inventory GetInventoryEntry(
const std::vector<Inventory> &inventorys,
int inventory_id
)
{
for (auto &inventory : inventorys) {
if (inventory.slotid == inventory_id) {
return inventory;
}
}
return NewEntity();
}
static Inventory FindOne(
int inventory_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
inventory_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
Inventory entry{};
entry.charid = atoi(row[0]);
entry.slotid = atoi(row[1]);
entry.itemid = atoi(row[2]);
entry.charges = atoi(row[3]);
entry.color = atoi(row[4]);
entry.augslot1 = atoi(row[5]);
entry.augslot2 = atoi(row[6]);
entry.augslot3 = atoi(row[7]);
entry.augslot4 = atoi(row[8]);
entry.augslot5 = atoi(row[9]);
entry.augslot6 = atoi(row[10]);
entry.instnodrop = atoi(row[11]);
entry.custom_data = row[12];
entry.ornamenticon = atoi(row[13]);
entry.ornamentidfile = atoi(row[14]);
entry.ornament_hero_model = atoi(row[15]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int inventory_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
inventory_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
Inventory inventory_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[2] + " = " + std::to_string(inventory_entry.itemid));
update_values.push_back(columns[3] + " = " + std::to_string(inventory_entry.charges));
update_values.push_back(columns[4] + " = " + std::to_string(inventory_entry.color));
update_values.push_back(columns[5] + " = " + std::to_string(inventory_entry.augslot1));
update_values.push_back(columns[6] + " = " + std::to_string(inventory_entry.augslot2));
update_values.push_back(columns[7] + " = " + std::to_string(inventory_entry.augslot3));
update_values.push_back(columns[8] + " = " + std::to_string(inventory_entry.augslot4));
update_values.push_back(columns[9] + " = " + std::to_string(inventory_entry.augslot5));
update_values.push_back(columns[10] + " = " + std::to_string(inventory_entry.augslot6));
update_values.push_back(columns[11] + " = " + std::to_string(inventory_entry.instnodrop));
update_values.push_back(columns[12] + " = '" + EscapeString(inventory_entry.custom_data) + "'");
update_values.push_back(columns[13] + " = " + std::to_string(inventory_entry.ornamenticon));
update_values.push_back(columns[14] + " = " + std::to_string(inventory_entry.ornamentidfile));
update_values.push_back(columns[15] + " = " + std::to_string(inventory_entry.ornament_hero_model));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
inventory_entry.slotid
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static Inventory InsertOne(
Inventory inventory_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(inventory_entry.itemid));
insert_values.push_back(std::to_string(inventory_entry.charges));
insert_values.push_back(std::to_string(inventory_entry.color));
insert_values.push_back(std::to_string(inventory_entry.augslot1));
insert_values.push_back(std::to_string(inventory_entry.augslot2));
insert_values.push_back(std::to_string(inventory_entry.augslot3));
insert_values.push_back(std::to_string(inventory_entry.augslot4));
insert_values.push_back(std::to_string(inventory_entry.augslot5));
insert_values.push_back(std::to_string(inventory_entry.augslot6));
insert_values.push_back(std::to_string(inventory_entry.instnodrop));
insert_values.push_back("'" + EscapeString(inventory_entry.custom_data) + "'");
insert_values.push_back(std::to_string(inventory_entry.ornamenticon));
insert_values.push_back(std::to_string(inventory_entry.ornamentidfile));
insert_values.push_back(std::to_string(inventory_entry.ornament_hero_model));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
inventory_entry.id = results.LastInsertedID();
return inventory_entry;
}
inventory_entry = InstanceListRepository::NewEntity();
return inventory_entry;
}
static int InsertMany(
std::vector<Inventory> inventory_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &inventory_entry: inventory_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(inventory_entry.itemid));
insert_values.push_back(std::to_string(inventory_entry.charges));
insert_values.push_back(std::to_string(inventory_entry.color));
insert_values.push_back(std::to_string(inventory_entry.augslot1));
insert_values.push_back(std::to_string(inventory_entry.augslot2));
insert_values.push_back(std::to_string(inventory_entry.augslot3));
insert_values.push_back(std::to_string(inventory_entry.augslot4));
insert_values.push_back(std::to_string(inventory_entry.augslot5));
insert_values.push_back(std::to_string(inventory_entry.augslot6));
insert_values.push_back(std::to_string(inventory_entry.instnodrop));
insert_values.push_back("'" + EscapeString(inventory_entry.custom_data) + "'");
insert_values.push_back(std::to_string(inventory_entry.ornamenticon));
insert_values.push_back(std::to_string(inventory_entry.ornamentidfile));
insert_values.push_back(std::to_string(inventory_entry.ornament_hero_model));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<Inventory> All()
{
std::vector<Inventory> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
Inventory entry{};
entry.charid = atoi(row[0]);
entry.slotid = atoi(row[1]);
entry.itemid = atoi(row[2]);
entry.charges = atoi(row[3]);
entry.color = atoi(row[4]);
entry.augslot1 = atoi(row[5]);
entry.augslot2 = atoi(row[6]);
entry.augslot3 = atoi(row[7]);
entry.augslot4 = atoi(row[8]);
entry.augslot5 = atoi(row[9]);
entry.augslot6 = atoi(row[10]);
entry.instnodrop = atoi(row[11]);
entry.custom_data = row[12];
entry.ornamenticon = atoi(row[13]);
entry.ornamentidfile = atoi(row[14]);
entry.ornament_hero_model = atoi(row[15]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_INVENTORY_REPOSITORY_H

View File

@ -0,0 +1,372 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_INVENTORY_SNAPSHOTS_REPOSITORY_H
#define EQEMU_INVENTORY_SNAPSHOTS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class InventorySnapshotsRepository {
public:
struct InventorySnapshots {
int time_index;
int charid;
int slotid;
int itemid;
int16 charges;
int color;
int augslot1;
int augslot2;
int augslot3;
int augslot4;
int augslot5;
int augslot6;
int8 instnodrop;
std::string custom_data;
int ornamenticon;
int ornamentidfile;
int ornament_hero_model;
};
static std::string PrimaryKey()
{
return std::string("slotid");
}
static std::vector<std::string> Columns()
{
return {
"time_index",
"charid",
"slotid",
"itemid",
"charges",
"color",
"augslot1",
"augslot2",
"augslot3",
"augslot4",
"augslot5",
"augslot6",
"instnodrop",
"custom_data",
"ornamenticon",
"ornamentidfile",
"ornament_hero_model",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("inventory_snapshots");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static InventorySnapshots NewEntity()
{
InventorySnapshots entry{};
entry.time_index = 0;
entry.charid = 0;
entry.slotid = 0;
entry.itemid = 0;
entry.charges = 0;
entry.color = 0;
entry.augslot1 = 0;
entry.augslot2 = 0;
entry.augslot3 = 0;
entry.augslot4 = 0;
entry.augslot5 = 0;
entry.augslot6 = 0;
entry.instnodrop = 0;
entry.custom_data = 0;
entry.ornamenticon = 0;
entry.ornamentidfile = 0;
entry.ornament_hero_model = 0;
return entry;
}
static InventorySnapshots GetInventorySnapshotsEntry(
const std::vector<InventorySnapshots> &inventory_snapshotss,
int inventory_snapshots_id
)
{
for (auto &inventory_snapshots : inventory_snapshotss) {
if (inventory_snapshots.slotid == inventory_snapshots_id) {
return inventory_snapshots;
}
}
return NewEntity();
}
static InventorySnapshots FindOne(
int inventory_snapshots_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
inventory_snapshots_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
InventorySnapshots entry{};
entry.time_index = atoi(row[0]);
entry.charid = atoi(row[1]);
entry.slotid = atoi(row[2]);
entry.itemid = atoi(row[3]);
entry.charges = atoi(row[4]);
entry.color = atoi(row[5]);
entry.augslot1 = atoi(row[6]);
entry.augslot2 = atoi(row[7]);
entry.augslot3 = atoi(row[8]);
entry.augslot4 = atoi(row[9]);
entry.augslot5 = atoi(row[10]);
entry.augslot6 = atoi(row[11]);
entry.instnodrop = atoi(row[12]);
entry.custom_data = row[13];
entry.ornamenticon = atoi(row[14]);
entry.ornamentidfile = atoi(row[15]);
entry.ornament_hero_model = atoi(row[16]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int inventory_snapshots_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
inventory_snapshots_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
InventorySnapshots inventory_snapshots_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[3] + " = " + std::to_string(inventory_snapshots_entry.itemid));
update_values.push_back(columns[4] + " = " + std::to_string(inventory_snapshots_entry.charges));
update_values.push_back(columns[5] + " = " + std::to_string(inventory_snapshots_entry.color));
update_values.push_back(columns[6] + " = " + std::to_string(inventory_snapshots_entry.augslot1));
update_values.push_back(columns[7] + " = " + std::to_string(inventory_snapshots_entry.augslot2));
update_values.push_back(columns[8] + " = " + std::to_string(inventory_snapshots_entry.augslot3));
update_values.push_back(columns[9] + " = " + std::to_string(inventory_snapshots_entry.augslot4));
update_values.push_back(columns[10] + " = " + std::to_string(inventory_snapshots_entry.augslot5));
update_values.push_back(columns[11] + " = " + std::to_string(inventory_snapshots_entry.augslot6));
update_values.push_back(columns[12] + " = " + std::to_string(inventory_snapshots_entry.instnodrop));
update_values.push_back(columns[13] + " = '" + EscapeString(inventory_snapshots_entry.custom_data) + "'");
update_values.push_back(columns[14] + " = " + std::to_string(inventory_snapshots_entry.ornamenticon));
update_values.push_back(columns[15] + " = " + std::to_string(inventory_snapshots_entry.ornamentidfile));
update_values.push_back(columns[16] + " = " + std::to_string(inventory_snapshots_entry.ornament_hero_model));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
inventory_snapshots_entry.slotid
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static InventorySnapshots InsertOne(
InventorySnapshots inventory_snapshots_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(inventory_snapshots_entry.itemid));
insert_values.push_back(std::to_string(inventory_snapshots_entry.charges));
insert_values.push_back(std::to_string(inventory_snapshots_entry.color));
insert_values.push_back(std::to_string(inventory_snapshots_entry.augslot1));
insert_values.push_back(std::to_string(inventory_snapshots_entry.augslot2));
insert_values.push_back(std::to_string(inventory_snapshots_entry.augslot3));
insert_values.push_back(std::to_string(inventory_snapshots_entry.augslot4));
insert_values.push_back(std::to_string(inventory_snapshots_entry.augslot5));
insert_values.push_back(std::to_string(inventory_snapshots_entry.augslot6));
insert_values.push_back(std::to_string(inventory_snapshots_entry.instnodrop));
insert_values.push_back("'" + EscapeString(inventory_snapshots_entry.custom_data) + "'");
insert_values.push_back(std::to_string(inventory_snapshots_entry.ornamenticon));
insert_values.push_back(std::to_string(inventory_snapshots_entry.ornamentidfile));
insert_values.push_back(std::to_string(inventory_snapshots_entry.ornament_hero_model));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
inventory_snapshots_entry.id = results.LastInsertedID();
return inventory_snapshots_entry;
}
inventory_snapshots_entry = InstanceListRepository::NewEntity();
return inventory_snapshots_entry;
}
static int InsertMany(
std::vector<InventorySnapshots> inventory_snapshots_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &inventory_snapshots_entry: inventory_snapshots_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(inventory_snapshots_entry.itemid));
insert_values.push_back(std::to_string(inventory_snapshots_entry.charges));
insert_values.push_back(std::to_string(inventory_snapshots_entry.color));
insert_values.push_back(std::to_string(inventory_snapshots_entry.augslot1));
insert_values.push_back(std::to_string(inventory_snapshots_entry.augslot2));
insert_values.push_back(std::to_string(inventory_snapshots_entry.augslot3));
insert_values.push_back(std::to_string(inventory_snapshots_entry.augslot4));
insert_values.push_back(std::to_string(inventory_snapshots_entry.augslot5));
insert_values.push_back(std::to_string(inventory_snapshots_entry.augslot6));
insert_values.push_back(std::to_string(inventory_snapshots_entry.instnodrop));
insert_values.push_back("'" + EscapeString(inventory_snapshots_entry.custom_data) + "'");
insert_values.push_back(std::to_string(inventory_snapshots_entry.ornamenticon));
insert_values.push_back(std::to_string(inventory_snapshots_entry.ornamentidfile));
insert_values.push_back(std::to_string(inventory_snapshots_entry.ornament_hero_model));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<InventorySnapshots> All()
{
std::vector<InventorySnapshots> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
InventorySnapshots entry{};
entry.time_index = atoi(row[0]);
entry.charid = atoi(row[1]);
entry.slotid = atoi(row[2]);
entry.itemid = atoi(row[3]);
entry.charges = atoi(row[4]);
entry.color = atoi(row[5]);
entry.augslot1 = atoi(row[6]);
entry.augslot2 = atoi(row[7]);
entry.augslot3 = atoi(row[8]);
entry.augslot4 = atoi(row[9]);
entry.augslot5 = atoi(row[10]);
entry.augslot6 = atoi(row[11]);
entry.instnodrop = atoi(row[12]);
entry.custom_data = row[13];
entry.ornamenticon = atoi(row[14]);
entry.ornamentidfile = atoi(row[15]);
entry.ornament_hero_model = atoi(row[16]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_INVENTORY_SNAPSHOTS_REPOSITORY_H

View File

@ -0,0 +1,269 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_INVENTORY_VERSIONS_REPOSITORY_H
#define EQEMU_INVENTORY_VERSIONS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class InventoryVersionsRepository {
public:
struct InventoryVersions {
int version;
int step;
int bot_step;
};
static std::string PrimaryKey()
{
return std::string("");
}
static std::vector<std::string> Columns()
{
return {
"version",
"step",
"bot_step",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("inventory_versions");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static InventoryVersions NewEntity()
{
InventoryVersions entry{};
entry.version = 0;
entry.step = 0;
entry.bot_step = 0;
return entry;
}
static InventoryVersions GetInventoryVersionsEntry(
const std::vector<InventoryVersions> &inventory_versionss,
int inventory_versions_id
)
{
for (auto &inventory_versions : inventory_versionss) {
if (inventory_versions. == inventory_versions_id) {
return inventory_versions;
}
}
return NewEntity();
}
static InventoryVersions FindOne(
int inventory_versions_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
inventory_versions_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
InventoryVersions entry{};
entry.version = atoi(row[0]);
entry.step = atoi(row[1]);
entry.bot_step = atoi(row[2]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int inventory_versions_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
inventory_versions_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
InventoryVersions inventory_versions_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[0] + " = " + std::to_string(inventory_versions_entry.version));
update_values.push_back(columns[1] + " = " + std::to_string(inventory_versions_entry.step));
update_values.push_back(columns[2] + " = " + std::to_string(inventory_versions_entry.bot_step));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
inventory_versions_entry.
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static InventoryVersions InsertOne(
InventoryVersions inventory_versions_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(inventory_versions_entry.version));
insert_values.push_back(std::to_string(inventory_versions_entry.step));
insert_values.push_back(std::to_string(inventory_versions_entry.bot_step));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
inventory_versions_entry.id = results.LastInsertedID();
return inventory_versions_entry;
}
inventory_versions_entry = InstanceListRepository::NewEntity();
return inventory_versions_entry;
}
static int InsertMany(
std::vector<InventoryVersions> inventory_versions_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &inventory_versions_entry: inventory_versions_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(inventory_versions_entry.version));
insert_values.push_back(std::to_string(inventory_versions_entry.step));
insert_values.push_back(std::to_string(inventory_versions_entry.bot_step));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<InventoryVersions> All()
{
std::vector<InventoryVersions> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
InventoryVersions entry{};
entry.version = atoi(row[0]);
entry.step = atoi(row[1]);
entry.bot_step = atoi(row[2]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_INVENTORY_VERSIONS_REPOSITORY_H

View File

@ -0,0 +1,266 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_IP_EXEMPTIONS_REPOSITORY_H
#define EQEMU_IP_EXEMPTIONS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class IpExemptionsRepository {
public:
struct IpExemptions {
int exemption_id;
std::string exemption_ip;
int exemption_amount;
};
static std::string PrimaryKey()
{
return std::string("exemption_id");
}
static std::vector<std::string> Columns()
{
return {
"exemption_id",
"exemption_ip",
"exemption_amount",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("ip_exemptions");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static IpExemptions NewEntity()
{
IpExemptions entry{};
entry.exemption_id = 0;
entry.exemption_ip = 0;
entry.exemption_amount = 0;
return entry;
}
static IpExemptions GetIpExemptionsEntry(
const std::vector<IpExemptions> &ip_exemptionss,
int ip_exemptions_id
)
{
for (auto &ip_exemptions : ip_exemptionss) {
if (ip_exemptions.exemption_id == ip_exemptions_id) {
return ip_exemptions;
}
}
return NewEntity();
}
static IpExemptions FindOne(
int ip_exemptions_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
ip_exemptions_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
IpExemptions entry{};
entry.exemption_id = atoi(row[0]);
entry.exemption_ip = row[1];
entry.exemption_amount = atoi(row[2]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int ip_exemptions_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
ip_exemptions_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
IpExemptions ip_exemptions_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[1] + " = '" + EscapeString(ip_exemptions_entry.exemption_ip) + "'");
update_values.push_back(columns[2] + " = " + std::to_string(ip_exemptions_entry.exemption_amount));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
ip_exemptions_entry.exemption_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static IpExemptions InsertOne(
IpExemptions ip_exemptions_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(ip_exemptions_entry.exemption_ip) + "'");
insert_values.push_back(std::to_string(ip_exemptions_entry.exemption_amount));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
ip_exemptions_entry.id = results.LastInsertedID();
return ip_exemptions_entry;
}
ip_exemptions_entry = InstanceListRepository::NewEntity();
return ip_exemptions_entry;
}
static int InsertMany(
std::vector<IpExemptions> ip_exemptions_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &ip_exemptions_entry: ip_exemptions_entries) {
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(ip_exemptions_entry.exemption_ip) + "'");
insert_values.push_back(std::to_string(ip_exemptions_entry.exemption_amount));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<IpExemptions> All()
{
std::vector<IpExemptions> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
IpExemptions entry{};
entry.exemption_id = atoi(row[0]);
entry.exemption_ip = row[1];
entry.exemption_amount = atoi(row[2]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_IP_EXEMPTIONS_REPOSITORY_H

View File

@ -0,0 +1,290 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_ITEM_TICK_REPOSITORY_H
#define EQEMU_ITEM_TICK_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class ItemTickRepository {
public:
struct ItemTick {
int it_itemid;
int it_chance;
int it_level;
int it_id;
std::string it_qglobal;
int8 it_bagslot;
};
static std::string PrimaryKey()
{
return std::string("it_id");
}
static std::vector<std::string> Columns()
{
return {
"it_itemid",
"it_chance",
"it_level",
"it_id",
"it_qglobal",
"it_bagslot",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("item_tick");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static ItemTick NewEntity()
{
ItemTick entry{};
entry.it_itemid = 0;
entry.it_chance = 0;
entry.it_level = 0;
entry.it_id = 0;
entry.it_qglobal = 0;
entry.it_bagslot = 0;
return entry;
}
static ItemTick GetItemTickEntry(
const std::vector<ItemTick> &item_ticks,
int item_tick_id
)
{
for (auto &item_tick : item_ticks) {
if (item_tick.it_id == item_tick_id) {
return item_tick;
}
}
return NewEntity();
}
static ItemTick FindOne(
int item_tick_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
item_tick_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
ItemTick entry{};
entry.it_itemid = atoi(row[0]);
entry.it_chance = atoi(row[1]);
entry.it_level = atoi(row[2]);
entry.it_id = atoi(row[3]);
entry.it_qglobal = row[4];
entry.it_bagslot = atoi(row[5]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int item_tick_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
item_tick_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
ItemTick item_tick_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[0] + " = " + std::to_string(item_tick_entry.it_itemid));
update_values.push_back(columns[1] + " = " + std::to_string(item_tick_entry.it_chance));
update_values.push_back(columns[2] + " = " + std::to_string(item_tick_entry.it_level));
update_values.push_back(columns[4] + " = '" + EscapeString(item_tick_entry.it_qglobal) + "'");
update_values.push_back(columns[5] + " = " + std::to_string(item_tick_entry.it_bagslot));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
item_tick_entry.it_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static ItemTick InsertOne(
ItemTick item_tick_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(item_tick_entry.it_itemid));
insert_values.push_back(std::to_string(item_tick_entry.it_chance));
insert_values.push_back(std::to_string(item_tick_entry.it_level));
insert_values.push_back("'" + EscapeString(item_tick_entry.it_qglobal) + "'");
insert_values.push_back(std::to_string(item_tick_entry.it_bagslot));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
item_tick_entry.id = results.LastInsertedID();
return item_tick_entry;
}
item_tick_entry = InstanceListRepository::NewEntity();
return item_tick_entry;
}
static int InsertMany(
std::vector<ItemTick> item_tick_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &item_tick_entry: item_tick_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(item_tick_entry.it_itemid));
insert_values.push_back(std::to_string(item_tick_entry.it_chance));
insert_values.push_back(std::to_string(item_tick_entry.it_level));
insert_values.push_back("'" + EscapeString(item_tick_entry.it_qglobal) + "'");
insert_values.push_back(std::to_string(item_tick_entry.it_bagslot));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<ItemTick> All()
{
std::vector<ItemTick> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
ItemTick entry{};
entry.it_itemid = atoi(row[0]);
entry.it_chance = atoi(row[1]);
entry.it_level = atoi(row[2]);
entry.it_id = atoi(row[3]);
entry.it_qglobal = row[4];
entry.it_bagslot = atoi(row[5]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_ITEM_TICK_REPOSITORY_H

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,261 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_KEYRING_REPOSITORY_H
#define EQEMU_KEYRING_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class KeyringRepository {
public:
struct Keyring {
int char_id;
int item_id;
};
static std::string PrimaryKey()
{
return std::string("");
}
static std::vector<std::string> Columns()
{
return {
"char_id",
"item_id",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("keyring");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static Keyring NewEntity()
{
Keyring entry{};
entry.char_id = 0;
entry.item_id = 0;
return entry;
}
static Keyring GetKeyringEntry(
const std::vector<Keyring> &keyrings,
int keyring_id
)
{
for (auto &keyring : keyrings) {
if (keyring.== keyring_id) {
return keyring;
}
}
return NewEntity();
}
static Keyring FindOne(
int keyring_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
keyring_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
Keyring entry{};
entry.char_id = atoi(row[0]);
entry.item_id = atoi(row[1]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int keyring_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
keyring_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
Keyring keyring_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[0] + " = " + std::to_string(keyring_entry.char_id));
update_values.push_back(columns[1] + " = " + std::to_string(keyring_entry.item_id));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
keyring_entry.
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static Keyring InsertOne(
Keyring keyring_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(keyring_entry.char_id));
insert_values.push_back(std::to_string(keyring_entry.item_id));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
keyring_entry.id = results.LastInsertedID();
return keyring_entry;
}
keyring_entry = InstanceListRepository::NewEntity();
return keyring_entry;
}
static int InsertMany(
std::vector<Keyring> keyring_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &keyring_entry: keyring_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(keyring_entry.char_id));
insert_values.push_back(std::to_string(keyring_entry.item_id));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<Keyring> All()
{
std::vector<Keyring> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
Keyring entry{};
entry.char_id = atoi(row[0]);
entry.item_id = atoi(row[1]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_KEYRING_REPOSITORY_H

View File

@ -0,0 +1,258 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_LAUNCHER_REPOSITORY_H
#define EQEMU_LAUNCHER_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class LauncherRepository {
public:
struct Launcher {
std::string name;
int8 dynamics;
};
static std::string PrimaryKey()
{
return std::string("name");
}
static std::vector<std::string> Columns()
{
return {
"name",
"dynamics",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("launcher");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static Launcher NewEntity()
{
Launcher entry{};
entry.name = "";
entry.dynamics = 0;
return entry;
}
static Launcher GetLauncherEntry(
const std::vector<Launcher> &launchers,
int launcher_id
)
{
for (auto &launcher : launchers) {
if (launcher.name == launcher_id) {
return launcher;
}
}
return NewEntity();
}
static Launcher FindOne(
int launcher_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
launcher_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
Launcher entry{};
entry.name = row[0];
entry.dynamics = atoi(row[1]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int launcher_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
launcher_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
Launcher launcher_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[1] + " = " + std::to_string(launcher_entry.dynamics));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
launcher_entry.name
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static Launcher InsertOne(
Launcher launcher_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(launcher_entry.dynamics));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
launcher_entry.id = results.LastInsertedID();
return launcher_entry;
}
launcher_entry = InstanceListRepository::NewEntity();
return launcher_entry;
}
static int InsertMany(
std::vector<Launcher> launcher_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &launcher_entry: launcher_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(launcher_entry.dynamics));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<Launcher> All()
{
std::vector<Launcher> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
Launcher entry{};
entry.name = row[0];
entry.dynamics = atoi(row[1]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_LAUNCHER_REPOSITORY_H

View File

@ -0,0 +1,263 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_LAUNCHER_ZONES_REPOSITORY_H
#define EQEMU_LAUNCHER_ZONES_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class LauncherZonesRepository {
public:
struct LauncherZones {
std::string launcher;
std::string zone;
int port;
};
static std::string PrimaryKey()
{
return std::string("zone");
}
static std::vector<std::string> Columns()
{
return {
"launcher",
"zone",
"port",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("launcher_zones");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static LauncherZones NewEntity()
{
LauncherZones entry{};
entry.launcher = "";
entry.zone = "";
entry.port = 0;
return entry;
}
static LauncherZones GetLauncherZonesEntry(
const std::vector<LauncherZones> &launcher_zoness,
int launcher_zones_id
)
{
for (auto &launcher_zones : launcher_zoness) {
if (launcher_zones.zone == launcher_zones_id) {
return launcher_zones;
}
}
return NewEntity();
}
static LauncherZones FindOne(
int launcher_zones_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
launcher_zones_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
LauncherZones entry{};
entry.launcher = row[0];
entry.zone = row[1];
entry.port = atoi(row[2]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int launcher_zones_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
launcher_zones_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
LauncherZones launcher_zones_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[2] + " = " + std::to_string(launcher_zones_entry.port));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
launcher_zones_entry.zone
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static LauncherZones InsertOne(
LauncherZones launcher_zones_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(launcher_zones_entry.port));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
launcher_zones_entry.id = results.LastInsertedID();
return launcher_zones_entry;
}
launcher_zones_entry = InstanceListRepository::NewEntity();
return launcher_zones_entry;
}
static int InsertMany(
std::vector<LauncherZones> launcher_zones_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &launcher_zones_entry: launcher_zones_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(launcher_zones_entry.port));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<LauncherZones> All()
{
std::vector<LauncherZones> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
LauncherZones entry{};
entry.launcher = row[0];
entry.zone = row[1];
entry.port = atoi(row[2]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_LAUNCHER_ZONES_REPOSITORY_H

View File

@ -0,0 +1,258 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_LDON_TRAP_ENTRIES_REPOSITORY_H
#define EQEMU_LDON_TRAP_ENTRIES_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class LdonTrapEntriesRepository {
public:
struct LdonTrapEntries {
int id;
int trap_id;
};
static std::string PrimaryKey()
{
return std::string("trap_id");
}
static std::vector<std::string> Columns()
{
return {
"id",
"trap_id",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("ldon_trap_entries");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static LdonTrapEntries NewEntity()
{
LdonTrapEntries entry{};
entry.id = 0;
entry.trap_id = 0;
return entry;
}
static LdonTrapEntries GetLdonTrapEntriesEntry(
const std::vector<LdonTrapEntries> &ldon_trap_entriess,
int ldon_trap_entries_id
)
{
for (auto &ldon_trap_entries : ldon_trap_entriess) {
if (ldon_trap_entries.trap_id == ldon_trap_entries_id) {
return ldon_trap_entries;
}
}
return NewEntity();
}
static LdonTrapEntries FindOne(
int ldon_trap_entries_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
ldon_trap_entries_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
LdonTrapEntries entry{};
entry.id = atoi(row[0]);
entry.trap_id = atoi(row[1]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int ldon_trap_entries_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
ldon_trap_entries_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
LdonTrapEntries ldon_trap_entries_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
auto results = content_db.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
ldon_trap_entries_entry.trap_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static LdonTrapEntries InsertOne(
LdonTrapEntries ldon_trap_entries_entry
)
{
std::vector<std::string> insert_values;
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
ldon_trap_entries_entry.id = results.LastInsertedID();
return ldon_trap_entries_entry;
}
ldon_trap_entries_entry = InstanceListRepository::NewEntity();
return ldon_trap_entries_entry;
}
static int InsertMany(
std::vector<LdonTrapEntries> ldon_trap_entries_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &ldon_trap_entries_entry: ldon_trap_entries_entries) {
std::vector<std::string> insert_values;
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<LdonTrapEntries> All()
{
std::vector<LdonTrapEntries> all_entries;
auto results = content_db.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
LdonTrapEntries entry{};
entry.id = atoi(row[0]);
entry.trap_id = atoi(row[1]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_LDON_TRAP_ENTRIES_REPOSITORY_H

View File

@ -0,0 +1,282 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_LDON_TRAP_TEMPLATES_REPOSITORY_H
#define EQEMU_LDON_TRAP_TEMPLATES_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class LdonTrapTemplatesRepository {
public:
struct LdonTrapTemplates {
int id;
int8 type;
int16 spell_id;
int16 skill;
int8 locked;
};
static std::string PrimaryKey()
{
return std::string("id");
}
static std::vector<std::string> Columns()
{
return {
"id",
"type",
"spell_id",
"skill",
"locked",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("ldon_trap_templates");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static LdonTrapTemplates NewEntity()
{
LdonTrapTemplates entry{};
entry.id = 0;
entry.type = 1;
entry.spell_id = 0;
entry.skill = 0;
entry.locked = 0;
return entry;
}
static LdonTrapTemplates GetLdonTrapTemplatesEntry(
const std::vector<LdonTrapTemplates> &ldon_trap_templatess,
int ldon_trap_templates_id
)
{
for (auto &ldon_trap_templates : ldon_trap_templatess) {
if (ldon_trap_templates.id == ldon_trap_templates_id) {
return ldon_trap_templates;
}
}
return NewEntity();
}
static LdonTrapTemplates FindOne(
int ldon_trap_templates_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
ldon_trap_templates_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
LdonTrapTemplates entry{};
entry.id = atoi(row[0]);
entry.type = atoi(row[1]);
entry.spell_id = atoi(row[2]);
entry.skill = atoi(row[3]);
entry.locked = atoi(row[4]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int ldon_trap_templates_id
)
{
auto results = content_db.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
ldon_trap_templates_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
LdonTrapTemplates ldon_trap_templates_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[1] + " = " + std::to_string(ldon_trap_templates_entry.type));
update_values.push_back(columns[2] + " = " + std::to_string(ldon_trap_templates_entry.spell_id));
update_values.push_back(columns[3] + " = " + std::to_string(ldon_trap_templates_entry.skill));
update_values.push_back(columns[4] + " = " + std::to_string(ldon_trap_templates_entry.locked));
auto results = content_db.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
ldon_trap_templates_entry.id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static LdonTrapTemplates InsertOne(
LdonTrapTemplates ldon_trap_templates_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(ldon_trap_templates_entry.type));
insert_values.push_back(std::to_string(ldon_trap_templates_entry.spell_id));
insert_values.push_back(std::to_string(ldon_trap_templates_entry.skill));
insert_values.push_back(std::to_string(ldon_trap_templates_entry.locked));
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
ldon_trap_templates_entry.id = results.LastInsertedID();
return ldon_trap_templates_entry;
}
ldon_trap_templates_entry = InstanceListRepository::NewEntity();
return ldon_trap_templates_entry;
}
static int InsertMany(
std::vector<LdonTrapTemplates> ldon_trap_templates_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &ldon_trap_templates_entry: ldon_trap_templates_entries) {
std::vector<std::string> insert_values;
insert_values.push_back(std::to_string(ldon_trap_templates_entry.type));
insert_values.push_back(std::to_string(ldon_trap_templates_entry.spell_id));
insert_values.push_back(std::to_string(ldon_trap_templates_entry.skill));
insert_values.push_back(std::to_string(ldon_trap_templates_entry.locked));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = content_db.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<LdonTrapTemplates> All()
{
std::vector<LdonTrapTemplates> all_entries;
auto results = content_db.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
LdonTrapTemplates entry{};
entry.id = atoi(row[0]);
entry.type = atoi(row[1]);
entry.spell_id = atoi(row[2]);
entry.skill = atoi(row[3]);
entry.locked = atoi(row[4]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_LDON_TRAP_TEMPLATES_REPOSITORY_H

View File

@ -0,0 +1,266 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_LEVEL_EXP_MODS_REPOSITORY_H
#define EQEMU_LEVEL_EXP_MODS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class LevelExpModsRepository {
public:
struct LevelExpMods {
int level;
std::string exp_mod;
std::string aa_exp_mod;
};
static std::string PrimaryKey()
{
return std::string("level");
}
static std::vector<std::string> Columns()
{
return {
"level",
"exp_mod",
"aa_exp_mod",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("level_exp_mods");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static LevelExpMods NewEntity()
{
LevelExpMods entry{};
entry.level = 0;
entry.exp_mod = 0;
entry.aa_exp_mod = 0;
return entry;
}
static LevelExpMods GetLevelExpModsEntry(
const std::vector<LevelExpMods> &level_exp_modss,
int level_exp_mods_id
)
{
for (auto &level_exp_mods : level_exp_modss) {
if (level_exp_mods.level == level_exp_mods_id) {
return level_exp_mods;
}
}
return NewEntity();
}
static LevelExpMods FindOne(
int level_exp_mods_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
level_exp_mods_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
LevelExpMods entry{};
entry.level = atoi(row[0]);
entry.exp_mod = atof(row[1]);
entry.aa_exp_mod = atof(row[2]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int level_exp_mods_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
level_exp_mods_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
LevelExpMods level_exp_mods_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[1] + " = '" + EscapeString(level_exp_mods_entry.exp_mod) + "'");
update_values.push_back(columns[2] + " = '" + EscapeString(level_exp_mods_entry.aa_exp_mod) + "'");
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
level_exp_mods_entry.level
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static LevelExpMods InsertOne(
LevelExpMods level_exp_mods_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(level_exp_mods_entry.exp_mod) + "'");
insert_values.push_back("'" + EscapeString(level_exp_mods_entry.aa_exp_mod) + "'");
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
level_exp_mods_entry.id = results.LastInsertedID();
return level_exp_mods_entry;
}
level_exp_mods_entry = InstanceListRepository::NewEntity();
return level_exp_mods_entry;
}
static int InsertMany(
std::vector<LevelExpMods> level_exp_mods_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &level_exp_mods_entry: level_exp_mods_entries) {
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(level_exp_mods_entry.exp_mod) + "'");
insert_values.push_back("'" + EscapeString(level_exp_mods_entry.aa_exp_mod) + "'");
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<LevelExpMods> All()
{
std::vector<LevelExpMods> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
LevelExpMods entry{};
entry.level = atoi(row[0]);
entry.exp_mod = atof(row[1]);
entry.aa_exp_mod = atof(row[2]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_LEVEL_EXP_MODS_REPOSITORY_H

View File

@ -0,0 +1,311 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_LFGUILD_REPOSITORY_H
#define EQEMU_LFGUILD_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class LfguildRepository {
public:
struct Lfguild {
int8 type;
std::string name;
std::string comment;
int8 fromlevel;
int8 tolevel;
int classes;
int aacount;
int timezone;
int timeposted;
};
static std::string PrimaryKey()
{
return std::string("name");
}
static std::vector<std::string> Columns()
{
return {
"type",
"name",
"comment",
"fromlevel",
"tolevel",
"classes",
"aacount",
"timezone",
"timeposted",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("lfguild");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static Lfguild NewEntity()
{
Lfguild entry{};
entry.type = 0;
entry.name = 0;
entry.comment = 0;
entry.fromlevel = 0;
entry.tolevel = 0;
entry.classes = 0;
entry.aacount = 0;
entry.timezone = 0;
entry.timeposted = 0;
return entry;
}
static Lfguild GetLfguildEntry(
const std::vector<Lfguild> &lfguilds,
int lfguild_id
)
{
for (auto &lfguild : lfguilds) {
if (lfguild.name == lfguild_id) {
return lfguild;
}
}
return NewEntity();
}
static Lfguild FindOne(
int lfguild_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
lfguild_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
Lfguild entry{};
entry.type = atoi(row[0]);
entry.name = row[1];
entry.comment = row[2];
entry.fromlevel = atoi(row[3]);
entry.tolevel = atoi(row[4]);
entry.classes = atoi(row[5]);
entry.aacount = atoi(row[6]);
entry.timezone = atoi(row[7]);
entry.timeposted = atoi(row[8]);
return entry;
}
return NewEntity();
}
static int DeleteOne(
int lfguild_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
lfguild_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
Lfguild lfguild_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[2] + " = '" + EscapeString(lfguild_entry.comment) + "'");
update_values.push_back(columns[3] + " = " + std::to_string(lfguild_entry.fromlevel));
update_values.push_back(columns[4] + " = " + std::to_string(lfguild_entry.tolevel));
update_values.push_back(columns[5] + " = " + std::to_string(lfguild_entry.classes));
update_values.push_back(columns[6] + " = " + std::to_string(lfguild_entry.aacount));
update_values.push_back(columns[7] + " = " + std::to_string(lfguild_entry.timezone));
update_values.push_back(columns[8] + " = " + std::to_string(lfguild_entry.timeposted));
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
lfguild_entry.name
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static Lfguild InsertOne(
Lfguild lfguild_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(lfguild_entry.comment) + "'");
insert_values.push_back(std::to_string(lfguild_entry.fromlevel));
insert_values.push_back(std::to_string(lfguild_entry.tolevel));
insert_values.push_back(std::to_string(lfguild_entry.classes));
insert_values.push_back(std::to_string(lfguild_entry.aacount));
insert_values.push_back(std::to_string(lfguild_entry.timezone));
insert_values.push_back(std::to_string(lfguild_entry.timeposted));
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
lfguild_entry.id = results.LastInsertedID();
return lfguild_entry;
}
lfguild_entry = InstanceListRepository::NewEntity();
return lfguild_entry;
}
static int InsertMany(
std::vector<Lfguild> lfguild_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &lfguild_entry: lfguild_entries) {
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(lfguild_entry.comment) + "'");
insert_values.push_back(std::to_string(lfguild_entry.fromlevel));
insert_values.push_back(std::to_string(lfguild_entry.tolevel));
insert_values.push_back(std::to_string(lfguild_entry.classes));
insert_values.push_back(std::to_string(lfguild_entry.aacount));
insert_values.push_back(std::to_string(lfguild_entry.timezone));
insert_values.push_back(std::to_string(lfguild_entry.timeposted));
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<Lfguild> All()
{
std::vector<Lfguild> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
Lfguild entry{};
entry.type = atoi(row[0]);
entry.name = row[1];
entry.comment = row[2];
entry.fromlevel = atoi(row[3]);
entry.tolevel = atoi(row[4]);
entry.classes = atoi(row[5]);
entry.aacount = atoi(row[6]);
entry.timezone = atoi(row[7]);
entry.timeposted = atoi(row[8]);
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_LFGUILD_REPOSITORY_H

View File

@ -0,0 +1,314 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_LOGIN_ACCOUNTS_REPOSITORY_H
#define EQEMU_LOGIN_ACCOUNTS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class LoginAccountsRepository {
public:
struct LoginAccounts {
int id;
std::string account_name;
std::string account_password;
std::string account_email;
std::string source_loginserver;
std::string last_ip_address;
std::string last_login_date;
std::string created_at;
std::string updated_at;
};
static std::string PrimaryKey()
{
return std::string("id");
}
static std::vector<std::string> Columns()
{
return {
"id",
"account_name",
"account_password",
"account_email",
"source_loginserver",
"last_ip_address",
"last_login_date",
"created_at",
"updated_at",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("login_accounts");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static LoginAccounts NewEntity()
{
LoginAccounts entry{};
entry.id = 0;
entry.account_name = 0;
entry.account_password = 0;
entry.account_email = 0;
entry.source_loginserver = 0;
entry.last_ip_address = 0;
entry.last_login_date = 0;
entry.created_at = 0;
entry.updated_at = current_timestamp();
return entry;
}
static LoginAccounts GetLoginAccountsEntry(
const std::vector<LoginAccounts> &login_accountss,
int login_accounts_id
)
{
for (auto &login_accounts : login_accountss) {
if (login_accounts.id == login_accounts_id) {
return login_accounts;
}
}
return NewEntity();
}
static LoginAccounts FindOne(
int login_accounts_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
login_accounts_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
LoginAccounts entry{};
entry.id = atoi(row[0]);
entry.account_name = row[1];
entry.account_password = row[2];
entry.account_email = row[3];
entry.source_loginserver = row[4];
entry.last_ip_address = row[5];
entry.last_login_date = row[6];
entry.created_at = row[7];
entry.updated_at = row[8];
return entry;
}
return NewEntity();
}
static int DeleteOne(
int login_accounts_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
login_accounts_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
LoginAccounts login_accounts_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[1] + " = '" + EscapeString(login_accounts_entry.account_name) + "'");
update_values.push_back(columns[2] + " = '" + EscapeString(login_accounts_entry.account_password) + "'");
update_values.push_back(columns[3] + " = '" + EscapeString(login_accounts_entry.account_email) + "'");
update_values.push_back(columns[4] + " = '" + EscapeString(login_accounts_entry.source_loginserver) + "'");
update_values.push_back(columns[5] + " = '" + EscapeString(login_accounts_entry.last_ip_address) + "'");
update_values.push_back(columns[6] + " = '" + EscapeString(login_accounts_entry.last_login_date) + "'");
update_values.push_back(columns[7] + " = '" + EscapeString(login_accounts_entry.created_at) + "'");
update_values.push_back(columns[8] + " = '" + EscapeString(login_accounts_entry.updated_at) + "'");
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
login_accounts_entry.id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static LoginAccounts InsertOne(
LoginAccounts login_accounts_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(login_accounts_entry.account_name) + "'");
insert_values.push_back("'" + EscapeString(login_accounts_entry.account_password) + "'");
insert_values.push_back("'" + EscapeString(login_accounts_entry.account_email) + "'");
insert_values.push_back("'" + EscapeString(login_accounts_entry.source_loginserver) + "'");
insert_values.push_back("'" + EscapeString(login_accounts_entry.last_ip_address) + "'");
insert_values.push_back("'" + EscapeString(login_accounts_entry.last_login_date) + "'");
insert_values.push_back("'" + EscapeString(login_accounts_entry.created_at) + "'");
insert_values.push_back("'" + EscapeString(login_accounts_entry.updated_at) + "'");
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
login_accounts_entry.id = results.LastInsertedID();
return login_accounts_entry;
}
login_accounts_entry = InstanceListRepository::NewEntity();
return login_accounts_entry;
}
static int InsertMany(
std::vector<LoginAccounts> login_accounts_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &login_accounts_entry: login_accounts_entries) {
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(login_accounts_entry.account_name) + "'");
insert_values.push_back("'" + EscapeString(login_accounts_entry.account_password) + "'");
insert_values.push_back("'" + EscapeString(login_accounts_entry.account_email) + "'");
insert_values.push_back("'" + EscapeString(login_accounts_entry.source_loginserver) + "'");
insert_values.push_back("'" + EscapeString(login_accounts_entry.last_ip_address) + "'");
insert_values.push_back("'" + EscapeString(login_accounts_entry.last_login_date) + "'");
insert_values.push_back("'" + EscapeString(login_accounts_entry.created_at) + "'");
insert_values.push_back("'" + EscapeString(login_accounts_entry.updated_at) + "'");
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<LoginAccounts> All()
{
std::vector<LoginAccounts> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
LoginAccounts entry{};
entry.id = atoi(row[0]);
entry.account_name = row[1];
entry.account_password = row[2];
entry.account_email = row[3];
entry.source_loginserver = row[4];
entry.last_ip_address = row[5];
entry.last_login_date = row[6];
entry.created_at = row[7];
entry.updated_at = row[8];
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_LOGIN_ACCOUNTS_REPOSITORY_H

View File

@ -0,0 +1,290 @@
/**
* EQEmulator: Everquest Server Emulator
* Copyright (C) 2001-2020 EQEmulator Development Team (https://github.com/EQEmu/Server)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY except by those people which sell it, which
* are required to give you total support for your newly bought product;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef EQEMU_LOGIN_API_TOKENS_REPOSITORY_H
#define EQEMU_LOGIN_API_TOKENS_REPOSITORY_H
#include "../database.h"
#include "../string_util.h"
class LoginApiTokensRepository {
public:
struct LoginApiTokens {
int id;
std::string token;
int can_write;
int can_read;
std::string created_at;
std::string updated_at;
};
static std::string PrimaryKey()
{
return std::string("id");
}
static std::vector<std::string> Columns()
{
return {
"id",
"token",
"can_write",
"can_read",
"created_at",
"updated_at",
};
}
static std::string ColumnsRaw()
{
return std::string(implode(", ", Columns()));
}
static std::string InsertColumnsRaw()
{
std::vector<std::string> insert_columns;
for (auto &column : Columns()) {
if (column == PrimaryKey()) {
continue;
}
insert_columns.push_back(column);
}
return std::string(implode(", ", insert_columns));
}
static std::string TableName()
{
return std::string("login_api_tokens");
}
static std::string BaseSelect()
{
return fmt::format(
"SELECT {} FROM {}",
ColumnsRaw(),
TableName()
);
}
static std::string BaseInsert()
{
return fmt::format(
"INSERT INTO {} ({}) ",
TableName(),
InsertColumnsRaw()
);
}
static LoginApiTokens NewEntity()
{
LoginApiTokens entry{};
entry.id = 0;
entry.token = 0;
entry.can_write = 0;
entry.can_read = 0;
entry.created_at = 0;
entry.updated_at = current_timestamp();
return entry;
}
static LoginApiTokens GetLoginApiTokensEntry(
const std::vector<LoginApiTokens> &login_api_tokenss,
int login_api_tokens_id
)
{
for (auto &login_api_tokens : login_api_tokenss) {
if (login_api_tokens.id == login_api_tokens_id) {
return login_api_tokens;
}
}
return NewEntity();
}
static LoginApiTokens FindOne(
int login_api_tokens_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"{} WHERE id = {} LIMIT 1",
BaseSelect(),
login_api_tokens_id
)
);
auto row = results.begin();
if (results.RowCount() == 1) {
LoginApiTokens entry{};
entry.id = atoi(row[0]);
entry.token = row[1];
entry.can_write = atoi(row[2]);
entry.can_read = atoi(row[3]);
entry.created_at = row[4];
entry.updated_at = row[5];
return entry;
}
return NewEntity();
}
static int DeleteOne(
int login_api_tokens_id
)
{
auto results = database.QueryDatabase(
fmt::format(
"DELETE FROM {} WHERE {} = {}",
TableName(),
PrimaryKey(),
login_api_tokens_id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static int UpdateOne(
LoginApiTokens login_api_tokens_entry
)
{
std::vector<std::string> update_values;
auto columns = Columns();
update_values.push_back(columns[1] + " = '" + EscapeString(login_api_tokens_entry.token) + "'");
update_values.push_back(columns[2] + " = " + std::to_string(login_api_tokens_entry.can_write));
update_values.push_back(columns[3] + " = " + std::to_string(login_api_tokens_entry.can_read));
update_values.push_back(columns[4] + " = '" + EscapeString(login_api_tokens_entry.created_at) + "'");
update_values.push_back(columns[5] + " = '" + EscapeString(login_api_tokens_entry.updated_at) + "'");
auto results = database.QueryDatabase(
fmt::format(
"UPDATE {} SET {} WHERE {} = {}",
TableName(),
implode(", ", update_values),
PrimaryKey(),
login_api_tokens_entry.id
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static LoginApiTokens InsertOne(
LoginApiTokens login_api_tokens_entry
)
{
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(login_api_tokens_entry.token) + "'");
insert_values.push_back(std::to_string(login_api_tokens_entry.can_write));
insert_values.push_back(std::to_string(login_api_tokens_entry.can_read));
insert_values.push_back("'" + EscapeString(login_api_tokens_entry.created_at) + "'");
insert_values.push_back("'" + EscapeString(login_api_tokens_entry.updated_at) + "'");
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES ({})",
BaseInsert(),
implode(",", insert_values)
)
);
if (results.Success()) {
login_api_tokens_entry.id = results.LastInsertedID();
return login_api_tokens_entry;
}
login_api_tokens_entry = InstanceListRepository::NewEntity();
return login_api_tokens_entry;
}
static int InsertMany(
std::vector<LoginApiTokens> login_api_tokens_entries
)
{
std::vector<std::string> insert_chunks;
for (auto &login_api_tokens_entry: login_api_tokens_entries) {
std::vector<std::string> insert_values;
insert_values.push_back("'" + EscapeString(login_api_tokens_entry.token) + "'");
insert_values.push_back(std::to_string(login_api_tokens_entry.can_write));
insert_values.push_back(std::to_string(login_api_tokens_entry.can_read));
insert_values.push_back("'" + EscapeString(login_api_tokens_entry.created_at) + "'");
insert_values.push_back("'" + EscapeString(login_api_tokens_entry.updated_at) + "'");
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
}
std::vector<std::string> insert_values;
auto results = database.QueryDatabase(
fmt::format(
"{} VALUES {}",
BaseInsert(),
implode(",", insert_chunks)
)
);
return (results.Success() ? results.RowsAffected() : 0);
}
static std::vector<LoginApiTokens> All()
{
std::vector<LoginApiTokens> all_entries;
auto results = database.QueryDatabase(
fmt::format(
"{}",
BaseSelect()
)
);
all_entries.reserve(results.RowCount());
for (auto row = results.begin(); row != results.end(); ++row) {
LoginApiTokens entry{};
entry.id = atoi(row[0]);
entry.token = row[1];
entry.can_write = atoi(row[2]);
entry.can_read = atoi(row[3]);
entry.created_at = row[4];
entry.updated_at = row[5];
all_entries.push_back(entry);
}
return all_entries;
}
};
#endif //EQEMU_LOGIN_API_TOKENS_REPOSITORY_H

Some files were not shown because too many files have changed in this diff Show More