mirror of
https://github.com/EQEmu/Server.git
synced 2026-03-23 14:52:26 +00:00
Merge pull request #260 from addtheice/RunQueryToDatabaseQuery_world_worlddb
Run query to database query world worlddb
This commit is contained in:
commit
48eba3c092
@ -227,49 +227,28 @@ int WorldDatabase::MoveCharacterToBind(int CharID, uint8 bindnum) {
|
|||||||
|
|
||||||
bool WorldDatabase::GetStartZone(PlayerProfile_Struct* in_pp, CharCreate_Struct* in_cc)
|
bool WorldDatabase::GetStartZone(PlayerProfile_Struct* in_pp, CharCreate_Struct* in_cc)
|
||||||
{
|
{
|
||||||
char errbuf[MYSQL_ERRMSG_SIZE];
|
|
||||||
char *query = 0;
|
|
||||||
MYSQL_RES *result;
|
|
||||||
MYSQL_ROW row = 0;
|
|
||||||
int rows;
|
|
||||||
|
|
||||||
if(!in_pp || !in_cc)
|
if(!in_pp || !in_cc)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
in_pp->x = in_pp->y = in_pp->z = in_pp->heading = in_pp->zone_id = 0;
|
in_pp->x = in_pp->y = in_pp->z = in_pp->heading = in_pp->zone_id = 0;
|
||||||
in_pp->binds[0].x = in_pp->binds[0].y = in_pp->binds[0].z = in_pp->binds[0].zoneId = 0;
|
in_pp->binds[0].x = in_pp->binds[0].y = in_pp->binds[0].z = in_pp->binds[0].zoneId = 0;
|
||||||
|
|
||||||
if(!RunQuery(query, MakeAnyLenString(&query, "SELECT x,y,z,heading,zone_id,bind_id FROM start_zones WHERE player_choice=%i AND player_class=%i "
|
std::string query = StringFormat("SELECT x, y, z, heading, zone_id, bind_id "
|
||||||
"AND player_deity=%i AND player_race=%i",
|
"FROM start_zones WHERE player_choice = % i "
|
||||||
in_cc->start_zone,
|
"AND player_class = %i AND player_deity = %i "
|
||||||
in_cc->class_,
|
"AND player_race = %i",
|
||||||
in_cc->deity,
|
in_cc->start_zone, in_cc->class_, in_cc->deity,
|
||||||
in_cc->race), errbuf, &result))
|
in_cc->race);
|
||||||
{
|
auto results = QueryDatabase(query);
|
||||||
LogFile->write(EQEMuLog::Error, "Start zone query failed: %s : %s\n", query, errbuf);
|
if(!results.Success()) {
|
||||||
safe_delete_array(query);
|
LogFile->write(EQEMuLog::Error, "Start zone query failed: %s : %s\n", query.c_str(), results.ErrorMessage().c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
LogFile->write(EQEMuLog::Status, "Start zone query: %s\n", query);
|
LogFile->write(EQEMuLog::Status, "Start zone query: %s\n", query.c_str());
|
||||||
safe_delete_array(query);
|
|
||||||
|
|
||||||
if((rows = mysql_num_rows(result)) > 0)
|
if (results.RowCount() == 0) {
|
||||||
row = mysql_fetch_row(result);
|
printf("No start_zones entry in database, using defaults\n");
|
||||||
|
|
||||||
if(row)
|
|
||||||
{
|
|
||||||
LogFile->write(EQEMuLog::Status, "Found starting location in start_zones");
|
|
||||||
in_pp->x = atof(row[0]);
|
|
||||||
in_pp->y = atof(row[1]);
|
|
||||||
in_pp->z = atof(row[2]);
|
|
||||||
in_pp->heading = atof(row[3]);
|
|
||||||
in_pp->zone_id = atoi(row[4]);
|
|
||||||
in_pp->binds[0].zoneId = atoi(row[5]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("No start_zones entry in database, using defaults\n");
|
|
||||||
switch(in_cc->start_zone)
|
switch(in_cc->start_zone)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
@ -357,6 +336,16 @@ bool WorldDatabase::GetStartZone(PlayerProfile_Struct* in_pp, CharCreate_Struct*
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LogFile->write(EQEMuLog::Status, "Found starting location in start_zones");
|
||||||
|
auto row = results.begin();
|
||||||
|
in_pp->x = atof(row[0]);
|
||||||
|
in_pp->y = atof(row[1]);
|
||||||
|
in_pp->z = atof(row[2]);
|
||||||
|
in_pp->heading = atof(row[3]);
|
||||||
|
in_pp->zone_id = atoi(row[4]);
|
||||||
|
in_pp->binds[0].zoneId = atoi(row[5]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(in_pp->x == 0 && in_pp->y == 0 && in_pp->z == 0)
|
if(in_pp->x == 0 && in_pp->y == 0 && in_pp->z == 0)
|
||||||
@ -364,14 +353,12 @@ bool WorldDatabase::GetStartZone(PlayerProfile_Struct* in_pp, CharCreate_Struct*
|
|||||||
|
|
||||||
if(in_pp->binds[0].x == 0 && in_pp->binds[0].y == 0 && in_pp->binds[0].z == 0)
|
if(in_pp->binds[0].x == 0 && in_pp->binds[0].y == 0 && in_pp->binds[0].z == 0)
|
||||||
database.GetSafePoints(in_pp->binds[0].zoneId, 0, &in_pp->binds[0].x, &in_pp->binds[0].y, &in_pp->binds[0].z);
|
database.GetSafePoints(in_pp->binds[0].zoneId, 0, &in_pp->binds[0].x, &in_pp->binds[0].y, &in_pp->binds[0].z);
|
||||||
if(result)
|
|
||||||
mysql_free_result(result);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WorldDatabase::GetStartZoneSoF(PlayerProfile_Struct* in_pp, CharCreate_Struct* in_cc)
|
bool WorldDatabase::GetStartZoneSoF(PlayerProfile_Struct* in_pp, CharCreate_Struct* in_cc)
|
||||||
{
|
{
|
||||||
|
|
||||||
// SoF doesn't send the player_choice field in character creation, it now sends the real zoneID instead.
|
// SoF doesn't send the player_choice field in character creation, it now sends the real zoneID instead.
|
||||||
//
|
//
|
||||||
// For SoF, search for an entry in start_zones with a matching zone_id, class, race and deity.
|
// For SoF, search for an entry in start_zones with a matching zone_id, class, race and deity.
|
||||||
@ -379,53 +366,25 @@ bool WorldDatabase::GetStartZoneSoF(PlayerProfile_Struct* in_pp, CharCreate_Stru
|
|||||||
// For now, if no row matching row is found, send them to Crescent Reach, as that is probably the most likely
|
// For now, if no row matching row is found, send them to Crescent Reach, as that is probably the most likely
|
||||||
// reason for no match being found.
|
// reason for no match being found.
|
||||||
//
|
//
|
||||||
char errbuf[MYSQL_ERRMSG_SIZE];
|
|
||||||
char *query = 0;
|
|
||||||
MYSQL_RES *result;
|
|
||||||
MYSQL_ROW row = 0;
|
|
||||||
int rows;
|
|
||||||
|
|
||||||
if(!in_pp || !in_cc)
|
if(!in_pp || !in_cc)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
in_pp->x = in_pp->y = in_pp->z = in_pp->heading = in_pp->zone_id = 0;
|
in_pp->x = in_pp->y = in_pp->z = in_pp->heading = in_pp->zone_id = 0;
|
||||||
in_pp->binds[0].x = in_pp->binds[0].y = in_pp->binds[0].z = in_pp->binds[0].zoneId = 0;
|
in_pp->binds[0].x = in_pp->binds[0].y = in_pp->binds[0].z = in_pp->binds[0].zoneId = 0;
|
||||||
|
|
||||||
if(!RunQuery(query, MakeAnyLenString(&query, "SELECT x, y, z, heading, bind_id "
|
std::string query = StringFormat("SELECT x, y, z, heading, bind_id FROM start_zones WHERE zone_id = %i "
|
||||||
" FROM start_zones "
|
"AND player_class = %i AND player_deity = %i AND player_race = %i",
|
||||||
" WHERE zone_id = %i "
|
in_cc->start_zone, in_cc->class_, in_cc->deity, in_cc->race);
|
||||||
" AND player_class = %i "
|
auto results = QueryDatabase(query);
|
||||||
" AND player_deity = %i"
|
if(!results.Success()) {
|
||||||
" AND player_race = %i",
|
LogFile->write(EQEMuLog::Status, "SoF Start zone query failed: %s : %s\n", query.c_str(), results.ErrorMessage().c_str());
|
||||||
in_cc->start_zone,
|
|
||||||
in_cc->class_,
|
|
||||||
in_cc->deity,
|
|
||||||
in_cc->race), errbuf, &result))
|
|
||||||
{
|
|
||||||
LogFile->write(EQEMuLog::Status, "SoF Start zone query failed: %s : %s\n", query, errbuf);
|
|
||||||
safe_delete_array(query);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
LogFile->write(EQEMuLog::Status, "SoF Start zone query: %s\n", query);
|
LogFile->write(EQEMuLog::Status, "SoF Start zone query: %s\n", query.c_str());
|
||||||
safe_delete_array(query);
|
|
||||||
|
|
||||||
if((rows = mysql_num_rows(result)) > 0)
|
if (results.RowCount() == 0) {
|
||||||
row = mysql_fetch_row(result);
|
printf("No start_zones entry in database, using defaults\n");
|
||||||
|
|
||||||
if(row)
|
|
||||||
{
|
|
||||||
LogFile->write(EQEMuLog::Status, "Found starting location in start_zones");
|
|
||||||
in_pp->x = atof(row[0]);
|
|
||||||
in_pp->y = atof(row[1]);
|
|
||||||
in_pp->z = atof(row[2]);
|
|
||||||
in_pp->heading = atof(row[3]);
|
|
||||||
in_pp->zone_id = in_cc->start_zone;
|
|
||||||
in_pp->binds[0].zoneId = atoi(row[4]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("No start_zones entry in database, using defaults\n");
|
|
||||||
|
|
||||||
if(in_cc->start_zone == RuleI(World, TutorialZoneID))
|
if(in_cc->start_zone == RuleI(World, TutorialZoneID))
|
||||||
in_pp->zone_id = in_cc->start_zone;
|
in_pp->zone_id = in_cc->start_zone;
|
||||||
@ -435,7 +394,16 @@ bool WorldDatabase::GetStartZoneSoF(PlayerProfile_Struct* in_pp, CharCreate_Stru
|
|||||||
in_pp->z = in_pp->binds[0].z = 0.79;
|
in_pp->z = in_pp->binds[0].z = 0.79;
|
||||||
in_pp->zone_id = in_pp->binds[0].zoneId = 394; // Crescent Reach.
|
in_pp->zone_id = in_pp->binds[0].zoneId = 394; // Crescent Reach.
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
LogFile->write(EQEMuLog::Status, "Found starting location in start_zones");
|
||||||
|
auto row = results.begin();
|
||||||
|
in_pp->x = atof(row[0]);
|
||||||
|
in_pp->y = atof(row[1]);
|
||||||
|
in_pp->z = atof(row[2]);
|
||||||
|
in_pp->heading = atof(row[3]);
|
||||||
|
in_pp->zone_id = in_cc->start_zone;
|
||||||
|
in_pp->binds[0].zoneId = atoi(row[4]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(in_pp->x == 0 && in_pp->y == 0 && in_pp->z == 0)
|
if(in_pp->x == 0 && in_pp->y == 0 && in_pp->z == 0)
|
||||||
@ -443,39 +411,27 @@ bool WorldDatabase::GetStartZoneSoF(PlayerProfile_Struct* in_pp, CharCreate_Stru
|
|||||||
|
|
||||||
if(in_pp->binds[0].x == 0 && in_pp->binds[0].y == 0 && in_pp->binds[0].z == 0)
|
if(in_pp->binds[0].x == 0 && in_pp->binds[0].y == 0 && in_pp->binds[0].z == 0)
|
||||||
database.GetSafePoints(in_pp->binds[0].zoneId, 0, &in_pp->binds[0].x, &in_pp->binds[0].y, &in_pp->binds[0].z);
|
database.GetSafePoints(in_pp->binds[0].zoneId, 0, &in_pp->binds[0].x, &in_pp->binds[0].y, &in_pp->binds[0].z);
|
||||||
if(result)
|
|
||||||
mysql_free_result(result);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldDatabase::GetLauncherList(std::vector<std::string> &rl) {
|
void WorldDatabase::GetLauncherList(std::vector<std::string> &rl) {
|
||||||
char errbuf[MYSQL_ERRMSG_SIZE];
|
|
||||||
char* query = 0;
|
|
||||||
MYSQL_RES *result;
|
|
||||||
MYSQL_ROW row;
|
|
||||||
|
|
||||||
rl.clear();
|
rl.clear();
|
||||||
|
|
||||||
if (RunQuery(query, MakeAnyLenString(&query,
|
const std::string query = "SELECT name FROM launcher";
|
||||||
"SELECT name FROM launcher" )
|
auto results = QueryDatabase(query);
|
||||||
, errbuf, &result))
|
if (!results.Success()) {
|
||||||
{
|
LogFile->write(EQEMuLog::Error, "WorldDatabase::GetLauncherList: %s", results.ErrorMessage().c_str());
|
||||||
while ((row = mysql_fetch_row(result))) {
|
return;
|
||||||
rl.push_back(row[0]);
|
}
|
||||||
}
|
|
||||||
mysql_free_result(result);
|
for (auto row = results.begin(); row != results.end(); ++row)
|
||||||
}
|
rl.push_back(row[0]);
|
||||||
else {
|
|
||||||
LogFile->write(EQEMuLog::Error, "WorldDatabase::GetLauncherList: %s", errbuf);
|
|
||||||
}
|
|
||||||
safe_delete_array(query);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldDatabase::SetMailKey(int CharID, int IPAddress, int MailKey) {
|
void WorldDatabase::SetMailKey(int CharID, int IPAddress, int MailKey) {
|
||||||
|
|
||||||
char errbuf[MYSQL_ERRMSG_SIZE];
|
|
||||||
char *query = 0;
|
|
||||||
|
|
||||||
char MailKeyString[17];
|
char MailKeyString[17];
|
||||||
|
|
||||||
if(RuleB(Chat, EnableMailKeyIPVerification) == true)
|
if(RuleB(Chat, EnableMailKeyIPVerification) == true)
|
||||||
@ -483,75 +439,60 @@ void WorldDatabase::SetMailKey(int CharID, int IPAddress, int MailKey) {
|
|||||||
else
|
else
|
||||||
sprintf(MailKeyString, "%08X", MailKey);
|
sprintf(MailKeyString, "%08X", MailKey);
|
||||||
|
|
||||||
if (!RunQuery(query, MakeAnyLenString(&query, "UPDATE `character_data` SET mailkey = '%s' WHERE id='%i'",
|
std::string query = StringFormat("UPDATE character_data SET mailkey = '%s' WHERE id = '%i'",
|
||||||
MailKeyString, CharID), errbuf))
|
MailKeyString, CharID);
|
||||||
|
auto results = QueryDatabase(query);
|
||||||
LogFile->write(EQEMuLog::Error, "WorldDatabase::SetMailKey(%i, %s) : %s", CharID, MailKeyString, errbuf);
|
if (!results.Success())
|
||||||
|
LogFile->write(EQEMuLog::Error, "WorldDatabase::SetMailKey(%i, %s) : %s", CharID, MailKeyString, results.ErrorMessage().c_str());
|
||||||
safe_delete_array(query);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WorldDatabase::GetCharacterLevel(const char *name, int &level)
|
bool WorldDatabase::GetCharacterLevel(const char *name, int &level)
|
||||||
{
|
{
|
||||||
char errbuf[MYSQL_ERRMSG_SIZE];
|
std::string query = StringFormat("SELECT level FROM character_data WHERE name = '%s'", name);
|
||||||
char* query = 0;
|
auto results = QueryDatabase(query);
|
||||||
MYSQL_RES *result;
|
if (!results.Success()) {
|
||||||
MYSQL_ROW row;
|
LogFile->write(EQEMuLog::Error, "WorldDatabase::GetCharacterLevel: %s", results.ErrorMessage().c_str());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if(RunQuery(query, MakeAnyLenString(&query, "SELECT `level` FROM `character_data` WHERE `name` = '%s'", name), errbuf, &result))
|
if (results.RowCount() == 0)
|
||||||
{
|
return false;
|
||||||
if(row = mysql_fetch_row(result))
|
|
||||||
{
|
auto row = results.begin();
|
||||||
level = atoi(row[0]);
|
level = atoi(row[0]);
|
||||||
mysql_free_result(result);
|
|
||||||
safe_delete_array(query);
|
return true;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
mysql_free_result(result);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LogFile->write(EQEMuLog::Error, "WorldDatabase::GetCharacterLevel: %s", errbuf);
|
|
||||||
}
|
|
||||||
safe_delete_array(query);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WorldDatabase::LoadCharacterCreateAllocations() {
|
bool WorldDatabase::LoadCharacterCreateAllocations() {
|
||||||
character_create_allocations.clear();
|
character_create_allocations.clear();
|
||||||
|
|
||||||
char errbuf[MYSQL_ERRMSG_SIZE];
|
std::string query = "SELECT * FROM char_create_point_allocations ORDER BY id";
|
||||||
char* query = 0;
|
auto results = QueryDatabase(query);
|
||||||
MYSQL_RES *result;
|
if (!results.Success())
|
||||||
MYSQL_ROW row;
|
return false;
|
||||||
if(RunQuery(query, MakeAnyLenString(&query, "SELECT * FROM char_create_point_allocations order by id"), errbuf, &result)) {
|
|
||||||
safe_delete_array(query);
|
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||||
while(row = mysql_fetch_row(result)) {
|
RaceClassAllocation allocate;
|
||||||
RaceClassAllocation allocate;
|
allocate.Index = atoi(row[0]);
|
||||||
int r = 0;
|
allocate.BaseStats[0] = atoi(row[1]);
|
||||||
allocate.Index = atoi(row[r++]);
|
allocate.BaseStats[3] = atoi(row[2]);
|
||||||
allocate.BaseStats[0] = atoi(row[r++]);
|
allocate.BaseStats[1] = atoi(row[3]);
|
||||||
allocate.BaseStats[3] = atoi(row[r++]);
|
allocate.BaseStats[2] = atoi(row[4]);
|
||||||
allocate.BaseStats[1] = atoi(row[r++]);
|
allocate.BaseStats[4] = atoi(row[5]);
|
||||||
allocate.BaseStats[2] = atoi(row[r++]);
|
allocate.BaseStats[5] = atoi(row[6]);
|
||||||
allocate.BaseStats[4] = atoi(row[r++]);
|
allocate.BaseStats[6] = atoi(row[7]);
|
||||||
allocate.BaseStats[5] = atoi(row[r++]);
|
allocate.DefaultPointAllocation[0] = atoi(row[8]);
|
||||||
allocate.BaseStats[6] = atoi(row[r++]);
|
allocate.DefaultPointAllocation[3] = atoi(row[9]);
|
||||||
allocate.DefaultPointAllocation[0] = atoi(row[r++]);
|
allocate.DefaultPointAllocation[1] = atoi(row[10]);
|
||||||
allocate.DefaultPointAllocation[3] = atoi(row[r++]);
|
allocate.DefaultPointAllocation[2] = atoi(row[11]);
|
||||||
allocate.DefaultPointAllocation[1] = atoi(row[r++]);
|
allocate.DefaultPointAllocation[4] = atoi(row[12]);
|
||||||
allocate.DefaultPointAllocation[2] = atoi(row[r++]);
|
allocate.DefaultPointAllocation[5] = atoi(row[13]);
|
||||||
allocate.DefaultPointAllocation[4] = atoi(row[r++]);
|
allocate.DefaultPointAllocation[6] = atoi(row[14]);
|
||||||
allocate.DefaultPointAllocation[5] = atoi(row[r++]);
|
|
||||||
allocate.DefaultPointAllocation[6] = atoi(row[r++]);
|
character_create_allocations.push_back(allocate);
|
||||||
character_create_allocations.push_back(allocate);
|
}
|
||||||
}
|
|
||||||
mysql_free_result(result);
|
|
||||||
} else {
|
|
||||||
safe_delete_array(query);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -559,27 +500,21 @@ bool WorldDatabase::LoadCharacterCreateAllocations() {
|
|||||||
bool WorldDatabase::LoadCharacterCreateCombos() {
|
bool WorldDatabase::LoadCharacterCreateCombos() {
|
||||||
character_create_race_class_combos.clear();
|
character_create_race_class_combos.clear();
|
||||||
|
|
||||||
char errbuf[MYSQL_ERRMSG_SIZE];
|
std::string query = "SELECT * FROM char_create_combinations ORDER BY race, class, deity, start_zone";
|
||||||
char* query = 0;
|
auto results = QueryDatabase(query);
|
||||||
MYSQL_RES *result;
|
if (!results.Success())
|
||||||
MYSQL_ROW row;
|
return false;
|
||||||
if(RunQuery(query, MakeAnyLenString(&query, "select * from char_create_combinations order by race, class, deity, start_zone"), errbuf, &result)) {
|
|
||||||
safe_delete_array(query);
|
for (auto row = results.begin(); row != results.end(); ++row) {
|
||||||
while(row = mysql_fetch_row(result)) {
|
RaceClassCombos combo;
|
||||||
RaceClassCombos combo;
|
combo.AllocationIndex = atoi(row[0]);
|
||||||
int r = 0;
|
combo.Race = atoi(row[1]);
|
||||||
combo.AllocationIndex = atoi(row[r++]);
|
combo.Class = atoi(row[2]);
|
||||||
combo.Race = atoi(row[r++]);
|
combo.Deity = atoi(row[3]);
|
||||||
combo.Class = atoi(row[r++]);
|
combo.Zone = atoi(row[4]);
|
||||||
combo.Deity = atoi(row[r++]);
|
combo.ExpansionRequired = atoi(row[5]);
|
||||||
combo.Zone = atoi(row[r++]);
|
|
||||||
combo.ExpansionRequired = atoi(row[r++]);
|
character_create_race_class_combos.push_back(combo);
|
||||||
character_create_race_class_combos.push_back(combo);
|
|
||||||
}
|
|
||||||
mysql_free_result(result);
|
|
||||||
} else {
|
|
||||||
safe_delete_array(query);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user