mirror of
https://github.com/EQEmu/Server.git
synced 2026-03-12 08:02:25 +00:00
AssignGrid converted to QueryDatabase
This commit is contained in:
parent
5f2db0d1cb
commit
cab0beb77f
@ -1049,6 +1049,9 @@ uint8 ZoneDatabase::GetGridType2(uint32 grid, uint16 zoneid) {
|
|||||||
|
|
||||||
bool ZoneDatabase::GetWaypoints(uint32 grid, uint16 zoneid, uint32 num, wplist* wp) {
|
bool ZoneDatabase::GetWaypoints(uint32 grid, uint16 zoneid, uint32 num, wplist* wp) {
|
||||||
|
|
||||||
|
if (wp == nullptr)
|
||||||
|
return false;
|
||||||
|
|
||||||
std::string query = StringFormat("SELECT x, y, z, pause, heading FROM grid_entries "
|
std::string query = StringFormat("SELECT x, y, z, pause, heading FROM grid_entries "
|
||||||
"WHERE gridid = %i AND number = %i AND zoneid = %i", grid, num, zoneid);
|
"WHERE gridid = %i AND number = %i AND zoneid = %i", grid, num, zoneid);
|
||||||
auto results = QueryDatabase(query);
|
auto results = QueryDatabase(query);
|
||||||
@ -1062,122 +1065,88 @@ bool ZoneDatabase::GetWaypoints(uint32 grid, uint16 zoneid, uint32 num, wplist*
|
|||||||
|
|
||||||
auto row = results.begin();
|
auto row = results.begin();
|
||||||
|
|
||||||
if (wp) {
|
wp->x = atof(row[0]);
|
||||||
wp->x = atof( row[0] );
|
wp->y = atof(row[1]);
|
||||||
wp->y = atof( row[1] );
|
wp->z = atof(row[2]);
|
||||||
wp->z = atof( row[2] );
|
wp->pause = atoi(row[3]);
|
||||||
wp->pause = atoi( row[3] );
|
wp->heading = atof(row[4]);
|
||||||
wp->heading = atof( row[4] );
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZoneDatabase::AssignGrid(Client *client, float x, float y, uint32 grid)
|
void ZoneDatabase::AssignGrid(Client *client, float x, float y, uint32 grid)
|
||||||
{
|
{
|
||||||
char *query = 0;
|
|
||||||
char errbuf[MYSQL_ERRMSG_SIZE];
|
|
||||||
MYSQL_RES *result;
|
|
||||||
MYSQL_ROW row;
|
|
||||||
int matches = 0, fuzzy = 0, spawn2id = 0;
|
int matches = 0, fuzzy = 0, spawn2id = 0;
|
||||||
uint32 affected_rows;
|
|
||||||
float dbx = 0, dby = 0;
|
float dbx = 0, dby = 0;
|
||||||
|
|
||||||
// looks like most of the stuff in spawn2 is straight integers
|
// looks like most of the stuff in spawn2 is straight integers
|
||||||
// so let's try that first
|
// so let's try that first
|
||||||
if(!RunQuery(
|
std::string query = StringFormat("SELECT id, x, y FROM spawn2 WHERE zone = '%s' AND x = %i AND y = %i",
|
||||||
query,
|
zone->GetShortName(), (int)x, (int)y);
|
||||||
MakeAnyLenString(
|
auto results = QueryDatabase(query);
|
||||||
&query,
|
if(!results.Success()) {
|
||||||
"SELECT id,x,y FROM spawn2 WHERE zone='%s' AND x=%i AND y=%i",
|
LogFile->write(EQEMuLog::Error, "Error querying spawn2 '%s': '%s'", query.c_str(), results.ErrorMessage().c_str());
|
||||||
zone->GetShortName(), (int)x, (int)y
|
return;
|
||||||
),
|
|
||||||
errbuf,
|
|
||||||
&result
|
|
||||||
)) {
|
|
||||||
LogFile->write(EQEMuLog::Error, "Error querying spawn2 '%s': '%s'", query, errbuf);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
safe_delete_array(query);
|
|
||||||
|
|
||||||
// how much it's allowed to be off by
|
// how much it's allowed to be off by
|
||||||
#define _GASSIGN_TOLERANCE 1.0
|
#define _GASSIGN_TOLERANCE 1.0
|
||||||
if(!(matches = mysql_num_rows(result))) // try a fuzzy match if that didn't find it
|
if(results.RowCount() == 0) // try a fuzzy match if that didn't find it
|
||||||
{
|
{
|
||||||
mysql_free_result(result);
|
query = StringFormat("SELECT id,x,y FROM spawn2 WHERE zone='%s' AND "
|
||||||
if(!RunQuery(
|
"ABS( ABS(x) - ABS(%f) ) < %f AND "
|
||||||
query,
|
"ABS( ABS(y) - ABS(%f) ) < %f",
|
||||||
MakeAnyLenString(
|
zone->GetShortName(), x, _GASSIGN_TOLERANCE, y, _GASSIGN_TOLERANCE);
|
||||||
&query,
|
results = QueryDatabase(query);
|
||||||
"SELECT id,x,y FROM spawn2 WHERE zone='%s' AND "
|
if(!results.Success()) {
|
||||||
"ABS( ABS(x) - ABS(%f) ) < %f AND "
|
LogFile->write(EQEMuLog::Error, "Error querying fuzzy spawn2 '%s': '%s'", query.c_str(), results.ErrorMessage().c_str());
|
||||||
"ABS( ABS(y) - ABS(%f) ) < %f",
|
|
||||||
zone->GetShortName(), x, _GASSIGN_TOLERANCE, y, _GASSIGN_TOLERANCE
|
|
||||||
),
|
|
||||||
errbuf,
|
|
||||||
&result
|
|
||||||
)) {
|
|
||||||
LogFile->write(EQEMuLog::Error, "Error querying fuzzy spawn2 '%s': '%s'", query, errbuf);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
safe_delete_array(query);
|
|
||||||
fuzzy = 1;
|
fuzzy = 1;
|
||||||
if(!(matches = mysql_num_rows(result)))
|
matches = results.RowCount();
|
||||||
mysql_free_result(result);
|
|
||||||
}
|
}
|
||||||
if(matches)
|
|
||||||
|
if (matches == 0) {
|
||||||
|
client->Message(0, "ERROR: Unable to assign grid - can't find it in spawn2");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(matches == 1)
|
||||||
{
|
{
|
||||||
if(matches > 1)
|
client->Message(0, "ERROR: Unable to assign grid - multiple spawn2 rows match");
|
||||||
{
|
return;
|
||||||
client->Message(0, "ERROR: Unable to assign grid - multiple spawn2 rows match");
|
|
||||||
mysql_free_result(result);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
row = mysql_fetch_row(result);
|
|
||||||
spawn2id = atoi(row[0]);
|
|
||||||
dbx = atof(row[1]);
|
|
||||||
dby = atof(row[2]);
|
|
||||||
if(!RunQuery(
|
|
||||||
query,
|
|
||||||
MakeAnyLenString(
|
|
||||||
&query,
|
|
||||||
"UPDATE spawn2 SET pathgrid = %d WHERE id = %d", grid, spawn2id
|
|
||||||
),
|
|
||||||
errbuf,
|
|
||||||
&result,
|
|
||||||
&affected_rows
|
|
||||||
)) {
|
|
||||||
LogFile->write(EQEMuLog::Error, "Error updating spawn2 '%s': '%s'", query, errbuf);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(affected_rows == 1)
|
|
||||||
{
|
|
||||||
if(client) client->LogSQL(query);
|
|
||||||
if(fuzzy)
|
|
||||||
{
|
|
||||||
float difference;
|
|
||||||
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
|
|
||||||
);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
client->Message(0, "Grid assign: spawn2 id = %d updated - exact match", spawn2id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
client->Message(0, "ERROR: found spawn2 id %d but the update query failed", spawn2id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
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())
|
||||||
{
|
{
|
||||||
client->Message(0, "ERROR: Unable to assign grid - can't find it in spawn2");
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************
|
/******************
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user