mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-31 04:56:20 +00:00
Upload generated repositories
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user