Commit 206c3fc6 authored by Legodev's avatar Legodev

added possibility to limit the amount of objects returned by dumpObjects

parent 127fae0a
......@@ -140,6 +140,8 @@
#define PROTOCOL_DBCALL_ARGUMENT_RESERVEDONE "reservedone"
#define PROTOCOL_DBCALL_ARGUMENT_WEAPON "weapon"
#define PROTOCOL_DBCALL_ARGUMENT_WORLDUUID "worlduuid"
#define PROTOCOL_DBCALL_ARGUMENT_OFFSET "offset"
#define PROTOCOL_DBCALL_ARGUMENT_LIMIT "limit"
// Message Types
#define PROTOCOL_MESSAGE_TYPE_ERROR "ERROR"
......
......@@ -51,6 +51,17 @@ public:
return keyList;
}
bool keyExists(std::string identifier) {
std::string Argument;
ARGUMENT_MAP::iterator it = argmap.find(identifier);
if (it != argmap.end()) {
return true;
}
return false;
}
template<typename ReturnType>
ReturnType get(std::string identifier) {
std::string Argument;
......
......@@ -579,7 +579,7 @@ std::string mysql_db_handler::interdumpObjects(std::string &extFunction, ext_arg
bool placecommaone = false;
bool placecommatwo = false;
std::vector<object_mysql *> objectList = dumpObjects();
std::vector<object_mysql *> objectList = dumpObjects(extArgument);
matrix = "[";
for (object_mysql * object : objectList) {
if (placecommaone) {
......@@ -1349,7 +1349,7 @@ std::string mysql_db_handler::killObject(std::string objectuuid, std::string att
return killuuid;
}
std::vector<object_mysql *> mysql_db_handler::dumpObjects() {
std::vector<object_mysql *> mysql_db_handler::dumpObjects(ext_arguments &extArgument) {
std::vector<object_mysql *> objectList;
MYSQL_RES *result;
MYSQL_ROW row;
......@@ -1375,6 +1375,12 @@ std::vector<object_mysql *> mysql_db_handler::dumpObjects() {
"AND `world_has_objects`.`killinfo_uuid` IS NULL "
"ORDER BY `object`.priority ASC, `world_has_objects`.`parentobject_uuid` ASC"} % worlduuid);
if (extArgument.keyExists(PROTOCOL_DBCALL_ARGUMENT_OFFSET) && extArgument.keyExists(PROTOCOL_DBCALL_ARGUMENT_LIMIT)) {
unsigned int offset = extArgument.get<unsigned int>(PROTOCOL_DBCALL_ARGUMENT_OFFSET);
unsigned int limit = extArgument.get<unsigned int>(PROTOCOL_DBCALL_ARGUMENT_LIMIT);
query += " LIMIT " + std::to_string(offset) + "," + std::to_string(limit);
}
this->rawquery(query, &result);
fieldcount = mysql_num_fields(result);
......
......@@ -140,7 +140,7 @@ private:
std::string createObject(ext_arguments &extArgument);
std::string updateObject(ext_arguments &extArgument);
std::string killObject(std::string objectuuid, std::string attackeruuid, std::string type, std::string weapon, float distance);
std::vector<object_mysql *> dumpObjects();
std::vector<object_mysql *> dumpObjects(ext_arguments &extArgument);
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment