From a698eff1060f0fb43ced5d19977a19e22ebef0ef Mon Sep 17 00:00:00 2001 From: Akkadius Date: Sun, 25 Jan 2015 23:27:44 -0600 Subject: [PATCH] Natedog: Fix #gassign to work more appropriately and simplify the function --- zone/command.cpp | 25 +++++++++++++--- zone/command.h | 1 + zone/waypoints.cpp | 73 ++++++---------------------------------------- zone/zonedb.h | 2 +- 4 files changed, 32 insertions(+), 69 deletions(-) diff --git a/zone/command.cpp b/zone/command.cpp index ce6825a2e..8190bf9fc 100644 --- a/zone/command.cpp +++ b/zone/command.cpp @@ -282,6 +282,7 @@ int command_init(void) { command_add("motd", "[new motd] - Set message of the day", 150, command_motd) || command_add("movechar", "[charname] [zonename] - Move charname to zonename", 50, command_movechar) || command_add("myskills", "- Show details about your current skill levels", 0, command_myskills) || + command_add("mysqltest", "Akkadius MySQL Bench Test", 250, command_mysqltest) || command_add("mysql", "Mysql CLI, see 'help' for options.", 250, command_mysql) || command_add("mystats", "- Show details about you or your pet", 50, command_mystats) || command_add("name", "[newname] - Rename your player target", 150, command_name) || @@ -428,7 +429,7 @@ int command_init(void) { command_add("zsave", " - Saves zheader to the database", 80, command_zsave) || command_add("zsky", "[skytype] - Change zone sky type", 80, command_zsky) || command_add("zstats", "- Show info about zone header", 80, command_zstats) || - command_add("zunderworld", "[zcoord] - Sets the underworld using zcoord", 80, command_zunderworld) || + command_add("zunderworld", "[zcoord] - Sets the underworld using zcoord", 80, command_zunderworld) || command_add("zuwcoords", "[z coord] - Set underworld coord", 80, command_zuwcoords) ) { @@ -1778,10 +1779,12 @@ void command_itemtest(Client *c, const Seperator *sep) void command_gassign(Client *c, const Seperator *sep) { - if (sep->IsNumber(1) && c->GetTarget() && c->GetTarget()->IsNPC()) - database.AssignGrid(c, glm::vec2(c->GetTarget()->CastToNPC()->m_SpawnPoint), atoi(sep->arg[1])); + if (sep->IsNumber(1) && c->GetTarget() && c->GetTarget()->IsNPC() && c->GetTarget()->CastToNPC()->GetSpawnPointID() > 0) { + int spawn2id = c->GetTarget()->CastToNPC()->GetSpawnPointID(); + database.AssignGrid(c, atoi(sep->arg[1]), spawn2id); + } else - c->Message(0,"Usage: #gassign [num] - must have an npc target!"); + c->Message(0, "Usage: #gassign [num] - must have an npc target!"); } void command_ai(Client *c, const Seperator *sep) @@ -10541,3 +10544,17 @@ void command_logs(Client *c, const Seperator *sep){ c->Message(0, "--- #logs set [console|file|gmsay] - Sets log settings during the lifetime of the zone"); } } + +void command_mysqltest(Client *c, const Seperator *sep) +{ + clock_t t = std::clock(); /* Function timer start */ + if (sep->IsNumber(1)){ + uint32 i = 0; + t = std::clock(); + for (i = 0; i < atoi(sep->arg[1]); i++){ + std::string query = "SELECT * FROM `zone`"; + auto results = database.QueryDatabase(query); + } + } + Log.Out(Logs::General, Logs::Debug, "MySQL Test... Took %f seconds", ((float)(std::clock() - t)) / CLOCKS_PER_SEC); +} \ No newline at end of file diff --git a/zone/command.h b/zone/command.h index 4471cacb4..0560b8eff 100644 --- a/zone/command.h +++ b/zone/command.h @@ -323,6 +323,7 @@ void command_merchantcloseshop(Client *c, const Seperator *sep); void command_shownumhits(Client *c, const Seperator *sep); void command_tune(Client *c, const Seperator *sep); void command_logtest(Client *c, const Seperator *sep); +void command_mysqltest(Client *c, const Seperator *sep); void command_logs(Client *c, const Seperator *sep); #ifdef EQPROFILE diff --git a/zone/waypoints.cpp b/zone/waypoints.cpp index 75054ef93..d3b85bf03 100644 --- a/zone/waypoints.cpp +++ b/zone/waypoints.cpp @@ -1033,76 +1033,21 @@ bool ZoneDatabase::GetWaypoints(uint32 grid, uint16 zoneid, uint32 num, wplist* return true; } -void ZoneDatabase::AssignGrid(Client *client, const glm::vec2& location, uint32 grid) -{ - int matches = 0, fuzzy = 0, spawn2id = 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)location.x, (int)location.y); +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()) { + + if (!results.Success()) + return; + + if (results.RowsAffected() != 1) { 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(), location.x, _GASSIGN_TOLERANCE, location.y, _GASSIGN_TOLERANCE); - results = QueryDatabase(query); - if (!results.Success()) { - 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]); - glm::vec2 dbLocation = glm::vec2(atof(row[1]), atof(row[2])); - - query = StringFormat("UPDATE spawn2 SET pathgrid = %d WHERE id = %d", grid, spawn2id); - results = QueryDatabase(query); - if (!results.Success()) { - return; - } - - if (results.RowsAffected() != 1) - { - client->Message(0, "ERROR: found spawn2 id %d but the update query failed", spawn2id); - return; - } - - if (!fuzzy) - { - client->Message(0, "Grid assign: spawn2 id = %d updated - exact match", spawn2id); - return; - } - - float difference = - sqrtf(pow(std::abs(location.x - dbLocation.x), 2) + pow(std::abs(location.y - dbLocation.y), 2)); - client->Message(0, "Grid assign: spawn2 id = %d updated - fuzzy match: deviation %f", spawn2id, difference); + client->Message(0, "Grid assign: spawn2 id = %d updated", spawn2id); } + /****************** * ModifyGrid - Either adds an empty grid, or removes a grid and all its waypoints, for a particular zone. * remove: TRUE if we are deleting the specified grid, FALSE if we are adding it diff --git a/zone/zonedb.h b/zone/zonedb.h index c605533bf..5c3ed3d0e 100644 --- a/zone/zonedb.h +++ b/zone/zonedb.h @@ -379,7 +379,7 @@ public: uint8 GetGridType(uint32 grid, uint32 zoneid); uint8 GetGridType2(uint32 grid, uint16 zoneid); bool GetWaypoints(uint32 grid, uint16 zoneid, uint32 num, wplist* wp); - void AssignGrid(Client *client, const glm::vec2& location, uint32 id); + void AssignGrid(Client *client, int grid, int spawn2id); int GetHighestGrid(uint32 zoneid); int GetHighestWaypoint(uint32 zoneid, uint32 gridid);