void Database::ExpireMail() { _log(UCS__INIT, "Expiring mail..."); std::string query = "SELECT COUNT(*) FROM `mail`"; auto results = QueryDatabase(query); if (!results.Success()) { _log(UCS__ERROR, "Unable to get message count from database. %s %s", query.c_str(), results.ErrorMessage().c_str()); return; } auto row = results.begin(); _log(UCS__INIT, "There are %s messages in the database.", row[0]); // Expire Trash if(RuleI(Mail, ExpireTrash) >= 0) { query = StringFormat("DELETE FROM `mail` WHERE `status`=4 AND `timestamp` < %i", time(nullptr) - RuleI(Mail, ExpireTrash)); results = QueryDatabase(query); if(results.Success()) _log(UCS__ERROR, "Error expiring trash messages, %s %s", query.c_str(), results.ErrorMessage().c_str()); else _log(UCS__INIT, "Expired %i trash messages.", results.RowsAffected()); } // Expire Read if(RuleI(Mail, ExpireRead) >= 0) { query = StringFormat("DELETE FROM `mail` WHERE `status` = 3 AND `timestamp` < %i", time(nullptr) - RuleI(Mail, ExpireRead)); results = QueryDatabase(query); if(results.Success()) _log(UCS__INIT, "Expired %i read messages.", results.RowsAffected()); else _log(UCS__ERROR, "Error expiring read messages, %s %s", query.c_str(), results.ErrorMessage().c_str()); } // Expire Unread if(RuleI(Mail, ExpireUnread) >= 0) { query = StringFormat("DELETE FROM `mail` WHERE `status`=1 AND `timestamp` < %i", time(nullptr) - RuleI(Mail, ExpireUnread)); results = QueryDatabase(query); if(results.Success()) _log(UCS__INIT, "Expired %i unread messages.", results.RowsAffected()); else _log(UCS__ERROR, "Error expiring unread messages, %s %s", query.c_str(), results.ErrorMessage().c_str()); } }
bool ZoneDatabase::DisableRecipe(uint32 recipe_id) { std::string query = StringFormat("UPDATE tradeskill_recipe SET enabled = 0 " "WHERE id = %u;", recipe_id); auto results = QueryDatabase(query); if (!results.Success()) return results.RowsAffected() > 0; return false; }
void ZoneDatabase::AssignGrid(Client *client, int grid, int spawn2id) { std::string query = StringFormat("UPDATE spawn2 SET pathgrid = %d WHERE id = %d", grid, spawn2id); auto results = QueryDatabase(query); if (!results.Success()) return; if (results.RowsAffected() != 1) { return; } client->Message(0, "Grid assign: spawn2 id = %d updated", spawn2id); }
bool ZoneDatabase::SetGuildDoor(uint8 doorid,uint16 guild_id, const char* zone) { if (doorid > 127) doorid = doorid - 128; std::string query = StringFormat("UPDATE doors SET guild = %i WHERE (doorid=%i) AND (zone='%s')", guild_id, doorid, zone); auto results = QueryDatabase(query); if (!results.Success()) { return false; } return (results.RowsAffected() > 0); }
bool ZoneDatabase::CreateSpawn2(Client *client, uint32 spawngroup, const char* zone, const glm::vec4& position, uint32 respawn, uint32 variance, uint16 condition, int16 cond_value) { std::string query = StringFormat("INSERT INTO spawn2 (spawngroupID, zone, x, y, z, heading, " "respawntime, variance, _condition, cond_value) " "VALUES (%i, '%s', %f, %f, %f, %f, %i, %i, %u, %i)", spawngroup, zone, position.x, position.y, position.z, position.w, respawn, variance, condition, cond_value); auto results = QueryDatabase(query); if (!results.Success()) { return false; } if (results.RowsAffected() != 1) return false; return true; }
void ZoneDatabase::AssignGrid(Client *client, float x, float y, uint32 grid) { int matches = 0, fuzzy = 0, spawn2id = 0; float dbx = 0, dby = 0; // looks like most of the stuff in spawn2 is straight integers // so let's try that first std::string query = StringFormat("SELECT id, x, y FROM spawn2 WHERE zone = '%s' AND x = %i AND y = %i", zone->GetShortName(), (int)x, (int)y); auto results = QueryDatabase(query); if(!results.Success()) { LogFile->write(EQEMuLog::Error, "Error querying spawn2 '%s': '%s'", query.c_str(), results.ErrorMessage().c_str()); return; } // how much it's allowed to be off by #define _GASSIGN_TOLERANCE 1.0 if (results.RowCount() == 0) // try a fuzzy match if that didn't find it { query = StringFormat("SELECT id,x,y FROM spawn2 WHERE zone='%s' AND " "ABS( ABS(x) - ABS(%f) ) < %f AND " "ABS( ABS(y) - ABS(%f) ) < %f", zone->GetShortName(), x, _GASSIGN_TOLERANCE, y, _GASSIGN_TOLERANCE); results = QueryDatabase(query); if (!results.Success()) { LogFile->write(EQEMuLog::Error, "Error querying fuzzy spawn2 '%s': '%s'", query.c_str(), results.ErrorMessage().c_str()); return; } fuzzy = 1; matches = results.RowCount(); } if (matches == 0) { client->Message(0, "ERROR: Unable to assign grid - can't find it in spawn2"); return; } if(matches > 1) { client->Message(0, "ERROR: Unable to assign grid - multiple spawn2 rows match"); return; } auto row = results.begin(); spawn2id = atoi(row[0]); dbx = atof(row[1]); dby = atof(row[2]); query = StringFormat("UPDATE spawn2 SET pathgrid = %d WHERE id = %d", grid, spawn2id); results = QueryDatabase(query); if (!results.Success()) { LogFile->write(EQEMuLog::Error, "Error updating spawn2 '%s': '%s'", query.c_str(), results.ErrorMessage().c_str()); return; } if (results.RowsAffected() != 1) { client->Message(0, "ERROR: found spawn2 id %d but the update query failed", spawn2id); return; } if(client) client->LogSQL(query.c_str()); if (!fuzzy) { client->Message(0, "Grid assign: spawn2 id = %d updated - exact match", spawn2id); return; } float difference = sqrtf(pow(fabs(x - dbx) , 2) + pow(fabs(y - dby), 2)); client->Message(0, "Grid assign: spawn2 id = %d updated - fuzzy match: deviation %f", spawn2id, difference); }