mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-15 04:11:30 +00:00
command_findnpctype converted to QueryDatabase
This commit is contained in:
parent
ca2c2ccfac
commit
61cd48ff44
@ -3096,67 +3096,47 @@ void command_peekinv(Client *c, const Seperator *sep)
|
|||||||
|
|
||||||
void command_findnpctype(Client *c, const Seperator *sep)
|
void command_findnpctype(Client *c, const Seperator *sep)
|
||||||
{
|
{
|
||||||
if(sep->arg[1][0] == 0)
|
if(sep->arg[1][0] == 0) {
|
||||||
c->Message(0, "Usage: #findnpctype [search criteria]");
|
c->Message(0, "Usage: #findnpctype [search criteria]");
|
||||||
else
|
return;
|
||||||
{
|
}
|
||||||
int id;
|
|
||||||
int count;
|
|
||||||
const int maxrows = 20;
|
|
||||||
char errbuf[MYSQL_ERRMSG_SIZE];
|
|
||||||
char *query;
|
|
||||||
MYSQL_RES *result;
|
|
||||||
MYSQL_ROW row;
|
|
||||||
|
|
||||||
query = new char[256];
|
std::string query;
|
||||||
|
|
||||||
// If id evaluates to 0, then search as if user entered a string.
|
int id = atoi((const char *)sep->arg[1]);
|
||||||
if ((id = atoi((const char *)sep->arg[1])) == 0)
|
if (id == 0) // If id evaluates to 0, then search as if user entered a string.
|
||||||
MakeAnyLenString(&query,
|
query = StringFormat("SELECT id, name FROM npc_types WHERE name LIKE '%%%s%%'", sep->arg[1]);
|
||||||
"SELECT id,name"
|
else // Otherwise, look for just that npc id.
|
||||||
" FROM npc_types WHERE name LIKE '%%%s%%'",
|
query = StringFormat("SELECT id, name FROM npc_types WHERE id = %i", id);
|
||||||
sep->arg[1]);
|
|
||||||
// Otherwise, look for just that npc id.
|
|
||||||
else
|
|
||||||
MakeAnyLenString(&query,
|
|
||||||
"SELECT id,name FROM npc_types WHERE id=%i", id);
|
|
||||||
|
|
||||||
// If query runs successfully.
|
auto results = database.QueryDatabase(query);
|
||||||
if (database.RunQuery(query, strlen(query), errbuf, &result))
|
if (!results.Success()) {
|
||||||
{
|
c->Message (0, "Error querying database.");
|
||||||
count = 0;
|
c->Message (0, query.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
// Process each row returned.
|
if (results.RowCount() == 0) // No matches found.
|
||||||
while((row = mysql_fetch_row(result)))
|
c->Message (0, "No matches found for %s.", sep->arg[1]);
|
||||||
{
|
|
||||||
// Limit to returning maxrows rows.
|
|
||||||
if (++count > maxrows)
|
|
||||||
{
|
|
||||||
c->Message (0,
|
|
||||||
"%i npc types shown. Too many results.", maxrows);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
c->Message (0, " %s: %s", row[0], row[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we did not hit the maxrows limit.
|
// If query runs successfully.
|
||||||
if (count <= maxrows)
|
int count = 0;
|
||||||
c->Message (0, "Query complete. %i rows shown.", count);
|
const int maxrows = 20;
|
||||||
// No matches found.
|
|
||||||
else if (count == 0)
|
|
||||||
c->Message (0, "No matches found for %s.", sep->arg[1]);
|
|
||||||
|
|
||||||
mysql_free_result(result);
|
// Process each row returned.
|
||||||
}
|
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||||
// If query failed.
|
// Limit to returning maxrows rows.
|
||||||
else
|
if (++count > maxrows) {
|
||||||
{
|
c->Message (0, "%i npc types shown. Too many results.", maxrows);
|
||||||
c->Message (0, "Error querying database.");
|
break;
|
||||||
c->Message (0, query);
|
}
|
||||||
}
|
|
||||||
|
c->Message (0, " %s: %s", row[0], row[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we did not hit the maxrows limit.
|
||||||
|
if (count <= maxrows)
|
||||||
|
c->Message (0, "Query complete. %i rows shown.", count);
|
||||||
|
|
||||||
safe_delete_array(query);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void command_findzone(Client *c, const Seperator *sep)
|
void command_findzone(Client *c, const Seperator *sep)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user