mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-31 00:46:46 +00:00
[GM Command] Door Manipulation Command Port (#1524)
* Initial commit * Push latest * Update door_manipulation.cpp * More door work * More doors work * Upload notes * Finalize changes * Remove comment * Add missing chat line * Swapped URI parser with something not using deprecated C++ functions
This commit is contained in:
@@ -0,0 +1,346 @@
|
||||
/**
|
||||
* DO NOT MODIFY THIS FILE
|
||||
*
|
||||
* This repository was automatically generated and is NOT to be modified directly.
|
||||
* Any repository modifications are meant to be made to the repository extending the base.
|
||||
* Any modifications to base repositories are to be made by the generator only
|
||||
*
|
||||
* @generator ./utils/scripts/generators/repository-generator.pl
|
||||
* @docs https://eqemu.gitbook.io/server/in-development/developer-area/repositories
|
||||
*/
|
||||
|
||||
#ifndef EQEMU_BASE_TOOL_GAME_OBJECTS_REPOSITORY_H
|
||||
#define EQEMU_BASE_TOOL_GAME_OBJECTS_REPOSITORY_H
|
||||
|
||||
#include "../../database.h"
|
||||
#include "../../string_util.h"
|
||||
#include <ctime>
|
||||
|
||||
class BaseToolGameObjectsRepository {
|
||||
public:
|
||||
struct ToolGameObjects {
|
||||
int id;
|
||||
int zoneid;
|
||||
std::string zonesn;
|
||||
std::string object_name;
|
||||
std::string file_from;
|
||||
int is_global;
|
||||
};
|
||||
|
||||
static std::string PrimaryKey()
|
||||
{
|
||||
return std::string("id");
|
||||
}
|
||||
|
||||
static std::vector<std::string> Columns()
|
||||
{
|
||||
return {
|
||||
"id",
|
||||
"zoneid",
|
||||
"zonesn",
|
||||
"object_name",
|
||||
"file_from",
|
||||
"is_global",
|
||||
};
|
||||
}
|
||||
|
||||
static std::vector<std::string> SelectColumns()
|
||||
{
|
||||
return {
|
||||
"id",
|
||||
"zoneid",
|
||||
"zonesn",
|
||||
"object_name",
|
||||
"file_from",
|
||||
"is_global",
|
||||
};
|
||||
}
|
||||
|
||||
static std::string ColumnsRaw()
|
||||
{
|
||||
return std::string(implode(", ", Columns()));
|
||||
}
|
||||
|
||||
static std::string SelectColumnsRaw()
|
||||
{
|
||||
return std::string(implode(", ", SelectColumns()));
|
||||
}
|
||||
|
||||
static std::string TableName()
|
||||
{
|
||||
return std::string("tool_game_objects");
|
||||
}
|
||||
|
||||
static std::string BaseSelect()
|
||||
{
|
||||
return fmt::format(
|
||||
"SELECT {} FROM {}",
|
||||
SelectColumnsRaw(),
|
||||
TableName()
|
||||
);
|
||||
}
|
||||
|
||||
static std::string BaseInsert()
|
||||
{
|
||||
return fmt::format(
|
||||
"INSERT INTO {} ({}) ",
|
||||
TableName(),
|
||||
ColumnsRaw()
|
||||
);
|
||||
}
|
||||
|
||||
static ToolGameObjects NewEntity()
|
||||
{
|
||||
ToolGameObjects entry{};
|
||||
|
||||
entry.id = 0;
|
||||
entry.zoneid = 0;
|
||||
entry.zonesn = "";
|
||||
entry.object_name = "";
|
||||
entry.file_from = "";
|
||||
entry.is_global = 0;
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
static ToolGameObjects GetToolGameObjectsEntry(
|
||||
const std::vector<ToolGameObjects> &tool_game_objectss,
|
||||
int tool_game_objects_id
|
||||
)
|
||||
{
|
||||
for (auto &tool_game_objects : tool_game_objectss) {
|
||||
if (tool_game_objects.id == tool_game_objects_id) {
|
||||
return tool_game_objects;
|
||||
}
|
||||
}
|
||||
|
||||
return NewEntity();
|
||||
}
|
||||
|
||||
static ToolGameObjects FindOne(
|
||||
Database& db,
|
||||
int tool_game_objects_id
|
||||
)
|
||||
{
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} WHERE id = {} LIMIT 1",
|
||||
BaseSelect(),
|
||||
tool_game_objects_id
|
||||
)
|
||||
);
|
||||
|
||||
auto row = results.begin();
|
||||
if (results.RowCount() == 1) {
|
||||
ToolGameObjects entry{};
|
||||
|
||||
entry.id = atoi(row[0]);
|
||||
entry.zoneid = atoi(row[1]);
|
||||
entry.zonesn = row[2] ? row[2] : "";
|
||||
entry.object_name = row[3] ? row[3] : "";
|
||||
entry.file_from = row[4] ? row[4] : "";
|
||||
entry.is_global = atoi(row[5]);
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
return NewEntity();
|
||||
}
|
||||
|
||||
static int DeleteOne(
|
||||
Database& db,
|
||||
int tool_game_objects_id
|
||||
)
|
||||
{
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"DELETE FROM {} WHERE {} = {}",
|
||||
TableName(),
|
||||
PrimaryKey(),
|
||||
tool_game_objects_id
|
||||
)
|
||||
);
|
||||
|
||||
return (results.Success() ? results.RowsAffected() : 0);
|
||||
}
|
||||
|
||||
static int UpdateOne(
|
||||
Database& db,
|
||||
ToolGameObjects tool_game_objects_entry
|
||||
)
|
||||
{
|
||||
std::vector<std::string> update_values;
|
||||
|
||||
auto columns = Columns();
|
||||
|
||||
update_values.push_back(columns[1] + " = " + std::to_string(tool_game_objects_entry.zoneid));
|
||||
update_values.push_back(columns[2] + " = '" + EscapeString(tool_game_objects_entry.zonesn) + "'");
|
||||
update_values.push_back(columns[3] + " = '" + EscapeString(tool_game_objects_entry.object_name) + "'");
|
||||
update_values.push_back(columns[4] + " = '" + EscapeString(tool_game_objects_entry.file_from) + "'");
|
||||
update_values.push_back(columns[5] + " = " + std::to_string(tool_game_objects_entry.is_global));
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"UPDATE {} SET {} WHERE {} = {}",
|
||||
TableName(),
|
||||
implode(", ", update_values),
|
||||
PrimaryKey(),
|
||||
tool_game_objects_entry.id
|
||||
)
|
||||
);
|
||||
|
||||
return (results.Success() ? results.RowsAffected() : 0);
|
||||
}
|
||||
|
||||
static ToolGameObjects InsertOne(
|
||||
Database& db,
|
||||
ToolGameObjects tool_game_objects_entry
|
||||
)
|
||||
{
|
||||
std::vector<std::string> insert_values;
|
||||
|
||||
insert_values.push_back(std::to_string(tool_game_objects_entry.id));
|
||||
insert_values.push_back(std::to_string(tool_game_objects_entry.zoneid));
|
||||
insert_values.push_back("'" + EscapeString(tool_game_objects_entry.zonesn) + "'");
|
||||
insert_values.push_back("'" + EscapeString(tool_game_objects_entry.object_name) + "'");
|
||||
insert_values.push_back("'" + EscapeString(tool_game_objects_entry.file_from) + "'");
|
||||
insert_values.push_back(std::to_string(tool_game_objects_entry.is_global));
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} VALUES ({})",
|
||||
BaseInsert(),
|
||||
implode(",", insert_values)
|
||||
)
|
||||
);
|
||||
|
||||
if (results.Success()) {
|
||||
tool_game_objects_entry.id = results.LastInsertedID();
|
||||
return tool_game_objects_entry;
|
||||
}
|
||||
|
||||
tool_game_objects_entry = NewEntity();
|
||||
|
||||
return tool_game_objects_entry;
|
||||
}
|
||||
|
||||
static int InsertMany(
|
||||
Database& db,
|
||||
std::vector<ToolGameObjects> tool_game_objects_entries
|
||||
)
|
||||
{
|
||||
std::vector<std::string> insert_chunks;
|
||||
|
||||
for (auto &tool_game_objects_entry: tool_game_objects_entries) {
|
||||
std::vector<std::string> insert_values;
|
||||
|
||||
insert_values.push_back(std::to_string(tool_game_objects_entry.id));
|
||||
insert_values.push_back(std::to_string(tool_game_objects_entry.zoneid));
|
||||
insert_values.push_back("'" + EscapeString(tool_game_objects_entry.zonesn) + "'");
|
||||
insert_values.push_back("'" + EscapeString(tool_game_objects_entry.object_name) + "'");
|
||||
insert_values.push_back("'" + EscapeString(tool_game_objects_entry.file_from) + "'");
|
||||
insert_values.push_back(std::to_string(tool_game_objects_entry.is_global));
|
||||
|
||||
insert_chunks.push_back("(" + implode(",", insert_values) + ")");
|
||||
}
|
||||
|
||||
std::vector<std::string> insert_values;
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} VALUES {}",
|
||||
BaseInsert(),
|
||||
implode(",", insert_chunks)
|
||||
)
|
||||
);
|
||||
|
||||
return (results.Success() ? results.RowsAffected() : 0);
|
||||
}
|
||||
|
||||
static std::vector<ToolGameObjects> All(Database& db)
|
||||
{
|
||||
std::vector<ToolGameObjects> all_entries;
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{}",
|
||||
BaseSelect()
|
||||
)
|
||||
);
|
||||
|
||||
all_entries.reserve(results.RowCount());
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
ToolGameObjects entry{};
|
||||
|
||||
entry.id = atoi(row[0]);
|
||||
entry.zoneid = atoi(row[1]);
|
||||
entry.zonesn = row[2] ? row[2] : "";
|
||||
entry.object_name = row[3] ? row[3] : "";
|
||||
entry.file_from = row[4] ? row[4] : "";
|
||||
entry.is_global = atoi(row[5]);
|
||||
|
||||
all_entries.push_back(entry);
|
||||
}
|
||||
|
||||
return all_entries;
|
||||
}
|
||||
|
||||
static std::vector<ToolGameObjects> GetWhere(Database& db, std::string where_filter)
|
||||
{
|
||||
std::vector<ToolGameObjects> all_entries;
|
||||
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"{} WHERE {}",
|
||||
BaseSelect(),
|
||||
where_filter
|
||||
)
|
||||
);
|
||||
|
||||
all_entries.reserve(results.RowCount());
|
||||
|
||||
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||
ToolGameObjects entry{};
|
||||
|
||||
entry.id = atoi(row[0]);
|
||||
entry.zoneid = atoi(row[1]);
|
||||
entry.zonesn = row[2] ? row[2] : "";
|
||||
entry.object_name = row[3] ? row[3] : "";
|
||||
entry.file_from = row[4] ? row[4] : "";
|
||||
entry.is_global = atoi(row[5]);
|
||||
|
||||
all_entries.push_back(entry);
|
||||
}
|
||||
|
||||
return all_entries;
|
||||
}
|
||||
|
||||
static int DeleteWhere(Database& db, std::string where_filter)
|
||||
{
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"DELETE FROM {} WHERE {}",
|
||||
TableName(),
|
||||
where_filter
|
||||
)
|
||||
);
|
||||
|
||||
return (results.Success() ? results.RowsAffected() : 0);
|
||||
}
|
||||
|
||||
static int Truncate(Database& db)
|
||||
{
|
||||
auto results = db.QueryDatabase(
|
||||
fmt::format(
|
||||
"TRUNCATE TABLE {}",
|
||||
TableName()
|
||||
)
|
||||
);
|
||||
|
||||
return (results.Success() ? results.RowsAffected() : 0);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif //EQEMU_BASE_TOOL_GAME_OBJECTS_REPOSITORY_H
|
||||
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* 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_TOOL_GAME_OBJECTS_REPOSITORY_H
|
||||
#define EQEMU_TOOL_GAME_OBJECTS_REPOSITORY_H
|
||||
|
||||
#include "../database.h"
|
||||
#include "../string_util.h"
|
||||
#include "base/base_tool_game_objects_repository.h"
|
||||
|
||||
class ToolGameObjectsRepository: public BaseToolGameObjectsRepository {
|
||||
public:
|
||||
|
||||
/**
|
||||
* This file was auto generated and can be modified and extended upon
|
||||
*
|
||||
* Base repository methods are automatically
|
||||
* generated in the "base" version of this repository. The base repository
|
||||
* is immutable and to be left untouched, while methods in this class
|
||||
* are used as extension methods for more specific persistence-layer
|
||||
* accessors or mutators.
|
||||
*
|
||||
* Base Methods (Subject to be expanded upon in time)
|
||||
*
|
||||
* Note: Not all tables are designed appropriately to fit functionality with all base methods
|
||||
*
|
||||
* InsertOne
|
||||
* UpdateOne
|
||||
* DeleteOne
|
||||
* FindOne
|
||||
* GetWhere(std::string where_filter)
|
||||
* DeleteWhere(std::string where_filter)
|
||||
* InsertMany
|
||||
* All
|
||||
*
|
||||
* Example custom methods in a repository
|
||||
*
|
||||
* ToolGameObjectsRepository::GetByZoneAndVersion(int zone_id, int zone_version)
|
||||
* ToolGameObjectsRepository::GetWhereNeverExpires()
|
||||
* ToolGameObjectsRepository::GetWhereXAndY()
|
||||
* ToolGameObjectsRepository::DeleteWhereXAndY()
|
||||
*
|
||||
* Most of the above could be covered by base methods, but if you as a developer
|
||||
* find yourself re-using logic for other parts of the code, its best to just make a
|
||||
* method that can be re-used easily elsewhere especially if it can use a base repository
|
||||
* method and encapsulate filters there
|
||||
*/
|
||||
|
||||
// Custom extended repository methods here
|
||||
|
||||
};
|
||||
|
||||
#endif //EQEMU_TOOL_GAME_OBJECTS_REPOSITORY_H
|
||||
Reference in New Issue
Block a user