command_qglobal converted to QueryDatabase

This commit is contained in:
Arthur Ice 2014-10-04 11:58:24 -07:00
parent 6be2f6a7e4
commit a61b930bd9

View File

@ -7309,57 +7309,59 @@ void command_nologs(Client *c, const Seperator *sep)
void command_qglobal(Client *c, const Seperator *sep) { void command_qglobal(Client *c, const Seperator *sep) {
//In-game switch for qglobal column //In-game switch for qglobal column
char errbuf[MYSQL_ERRMSG_SIZE];
char *query = 0;
if(sep->arg[1][0] == 0) { if(sep->arg[1][0] == 0) {
c->Message(0, "Syntax: #qglobal [on/off/view]. Requires NPC target."); c->Message(0, "Syntax: #qglobal [on/off/view]. Requires NPC target.");
return; return;
} }
Mob *t = c->GetTarget();
if(!t || !t->IsNPC()) { Mob *target = c->GetTarget();
if(!target || !target->IsNPC()) {
c->Message(13, "NPC Target Required!"); c->Message(13, "NPC Target Required!");
return; return;
} }
if(!strcasecmp(sep->arg[1], "on"))
{ if(!strcasecmp(sep->arg[1], "on")) {
if(!database.RunQuery(query, MakeAnyLenString(&query, "UPDATE npc_types SET qglobal=1 WHERE id='%i'", t->GetNPCTypeID()), errbuf, 0)) std::string query = StringFormat("UPDATE npc_types SET qglobal = 1 WHERE id = '%i'",
{ target->GetNPCTypeID());
auto results = database.QueryDatabase(query);
if(!results.Success()) {
c->Message(15, "Could not update database."); c->Message(15, "Could not update database.");
return;
} }
else
{ c->LogSQL(query.c_str());
c->LogSQL(query);
c->Message(15, "Success! Changes take effect on zone reboot."); c->Message(15, "Success! Changes take effect on zone reboot.");
return;
} }
safe_delete(query);
} if(!strcasecmp(sep->arg[1], "off")) {
else if(!strcasecmp(sep->arg[1], "off")) std::string query = StringFormat("UPDATE npc_types SET qglobal = 0 WHERE id = '%i'",
{ target->GetNPCTypeID());
if(!database.RunQuery(query, MakeAnyLenString(&query, "UPDATE npc_types SET qglobal=0 WHERE id='%i'", t->GetNPCTypeID()), errbuf, 0)) auto results = database.QueryDatabase(query);
{ if(!results.Success()) {
c->Message(15, "Could not update database."); c->Message(15, "Could not update database.");
return;
} }
else
{ c->LogSQL(query.c_str());
c->LogSQL(query);
c->Message(15, "Success! Changes take effect on zone reboot."); c->Message(15, "Success! Changes take effect on zone reboot.");
return;
} }
safe_delete(query);
} if(!strcasecmp(sep->arg[1], "view")) {
else if(!strcasecmp(sep->arg[1], "view")) const NPCType *type = database.GetNPCType(target->GetNPCTypeID());
{ if(!type)
const NPCType *type = database.GetNPCType(t->GetNPCTypeID());
if(!type) {
c->Message(15, "Invalid NPC type."); c->Message(15, "Invalid NPC type.");
} else if(type->qglobal) { else if(type->qglobal)
c->Message(15, "This NPC has quest globals active."); c->Message(15, "This NPC has quest globals active.");
} else { else
c->Message(15, "This NPC has quest globals disabled."); c->Message(15, "This NPC has quest globals disabled.");
return;
} }
} else {
c->Message(15, "Invalid action specified."); c->Message(15, "Invalid action specified.");
} }
}
void command_path(Client *c, const Seperator *sep) void command_path(Client *c, const Seperator *sep)
{ {