mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-04 19:22:38 +00:00
Fixed the way we work with blobs.
quoting and length on runquery. Fixed fence post error on StringFormat()
This commit is contained in:
parent
2631861370
commit
9ebe02d363
@ -56,10 +56,10 @@ void vStringFormat(std::string& output, const char* format, va_list args)
|
|||||||
|
|
||||||
throw std::runtime_error(errorMessage);
|
throw std::runtime_error(errorMessage);
|
||||||
}
|
}
|
||||||
else if ((unsigned int)characters_used > output.capacity()) {
|
if ((unsigned int)characters_used > output.capacity()) {
|
||||||
output.resize(characters_used+1);
|
output.resize(characters_used);
|
||||||
va_copy(tmpargs,args);
|
va_copy(tmpargs,args);
|
||||||
characters_used = vsnprintf(&output[0], output.capacity(), format, tmpargs);
|
characters_used = vsnprintf(&output[0], output.capacity()+1, format, tmpargs);
|
||||||
va_end(tmpargs);
|
va_end(tmpargs);
|
||||||
|
|
||||||
if (characters_used < 0) {
|
if (characters_used < 0) {
|
||||||
@ -70,24 +70,23 @@ void vStringFormat(std::string& output, const char* format, va_list args)
|
|||||||
|
|
||||||
throw std::runtime_error(errorMessage);
|
throw std::runtime_error(errorMessage);
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else {
|
output.resize(characters_used+1);
|
||||||
output.resize(characters_used + 1);
|
|
||||||
|
|
||||||
va_copy(tmpargs,args);
|
va_copy(tmpargs,args);
|
||||||
characters_used = vsnprintf(&output[0], output.capacity(), format, tmpargs);
|
characters_used = vsnprintf(&output[0], output.capacity()+1, format, tmpargs);
|
||||||
va_end(tmpargs);
|
va_end(tmpargs);
|
||||||
|
|
||||||
if (characters_used < 0) {
|
if (characters_used < 0) {
|
||||||
// We shouldn't have a format error by this point, but I can't imagine what error we
|
// We shouldn't have a format error by this point, but I can't imagine what error we
|
||||||
// could have by this point. still error out and report it.
|
// could have by this point. still error out and report it.
|
||||||
std::string errorMessage("Invalid format string or unknown vsnprintf error; vsnprintf returned negative with format string: ");
|
std::string errorMessage("Invalid format string or unknown vsnprintf error; vsnprintf returned negative with format string: ");
|
||||||
errorMessage.append(format);
|
errorMessage.append(format);
|
||||||
|
|
||||||
throw std::runtime_error(errorMessage);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
throw std::runtime_error(errorMessage);
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StringFormat(std::string& output, const char* format, ...)
|
void StringFormat(std::string& output, const char* format, ...)
|
||||||
|
|||||||
@ -626,6 +626,7 @@ bool Database::DeleteCharacter(char *name)
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store new character information into the character_ and inventory tables
|
// Store new character information into the character_ and inventory tables
|
||||||
bool Database::StoreCharacter(uint32 account_id, PlayerProfile_Struct* pp, Inventory* inv, ExtendedProfile_Struct *ext)
|
bool Database::StoreCharacter(uint32 account_id, PlayerProfile_Struct* pp, Inventory* inv, ExtendedProfile_Struct *ext)
|
||||||
{
|
{
|
||||||
@ -637,8 +638,7 @@ bool Database::StoreCharacter(uint32 account_id, PlayerProfile_Struct* pp, Inven
|
|||||||
uint32 charid = 0;
|
uint32 charid = 0;
|
||||||
MYSQL_RES *result;
|
MYSQL_RES *result;
|
||||||
MYSQL_ROW row = 0;
|
MYSQL_ROW row = 0;
|
||||||
std::string playerProfileBuffer;
|
|
||||||
std::string extendedProfileBuffer;
|
|
||||||
char zone[50];
|
char zone[50];
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
|
|
||||||
@ -675,22 +675,30 @@ bool Database::StoreCharacter(uint32 account_id, PlayerProfile_Struct* pp, Inven
|
|||||||
y=pp->y;
|
y=pp->y;
|
||||||
z=pp->z;
|
z=pp->z;
|
||||||
|
|
||||||
|
std::string playerProfileBuffer;
|
||||||
|
std::string extendedProfileBuffer;
|
||||||
|
|
||||||
// construct the character_ query
|
// construct the character_ query
|
||||||
StringFormat(query, "UPDATE character_ SET timelaston=0, "
|
StringFormat(query, "UPDATE character_ SET timelaston=0, "
|
||||||
"zonename=\'%s\', x=%f, y=%f, z=%f, profile=\'",
|
"zonename=\'%s\', x=%f, y=%f, z=%f, profile=\'",
|
||||||
zone, x, y, z);
|
zone, x, y, z);
|
||||||
|
|
||||||
DoEscapeString(playerProfileBuffer, (char*)pp, sizeof(PlayerProfile_Struct));
|
DoEscapeString(playerProfileBuffer, (char*)pp, sizeof(PlayerProfile_Struct));
|
||||||
|
|
||||||
query.append(playerProfileBuffer);
|
query.append(playerProfileBuffer);
|
||||||
|
|
||||||
query.append("\', extprofile=\'");
|
query.append("\', extprofile=\'");
|
||||||
|
|
||||||
DoEscapeString(extendedProfileBuffer, (char*)ext, sizeof(ExtendedProfile_Struct));
|
DoEscapeString(extendedProfileBuffer, (char*)ext, sizeof(ExtendedProfile_Struct));
|
||||||
|
|
||||||
query.append(extendedProfileBuffer);
|
query.append(extendedProfileBuffer);
|
||||||
|
|
||||||
std::string ending;
|
std::string ending;
|
||||||
|
|
||||||
StringFormat(ending, "\' WHERE account_id=%d AND name='%s'",account_id, pp->name);
|
StringFormat(ending, "\' WHERE account_id=%d AND name='%s'",account_id, pp->name);
|
||||||
|
|
||||||
query.append(ending);
|
query.append(ending);
|
||||||
|
|
||||||
RunQuery(query, errbuf, 0, &affected_rows);
|
RunQuery(query, errbuf, 0, &affected_rows);
|
||||||
|
|
||||||
if(!affected_rows)
|
if(!affected_rows)
|
||||||
|
|||||||
@ -74,7 +74,7 @@ bool DBcore::RunQuery(const std::string query, char* errbuf, MYSQL_RES** result,
|
|||||||
strn0cpy(tmp, query.c_str(), sizeof(tmp));
|
strn0cpy(tmp, query.c_str(), sizeof(tmp));
|
||||||
std::cout << "QUERY: " << tmp << std::endl;
|
std::cout << "QUERY: " << tmp << std::endl;
|
||||||
#endif
|
#endif
|
||||||
if (mysql_real_query(&mysql, query.c_str(), strlen(query.c_str()))) {
|
if (mysql_real_query(&mysql, query.c_str(), query.length())) {
|
||||||
if (mysql_errno(&mysql) == CR_SERVER_GONE_ERROR)
|
if (mysql_errno(&mysql) == CR_SERVER_GONE_ERROR)
|
||||||
pStatus = Error;
|
pStatus = Error;
|
||||||
if (mysql_errno(&mysql) == CR_SERVER_LOST || mysql_errno(&mysql) == CR_SERVER_GONE_ERROR) {
|
if (mysql_errno(&mysql) == CR_SERVER_LOST || mysql_errno(&mysql) == CR_SERVER_GONE_ERROR) {
|
||||||
@ -156,9 +156,9 @@ bool DBcore::RunQuery(const std::string query, char* errbuf, MYSQL_RES** result,
|
|||||||
void DBcore::DoEscapeString(std::string& outString, const char* frombuf, uint32 fromlen) {
|
void DBcore::DoEscapeString(std::string& outString, const char* frombuf, uint32 fromlen) {
|
||||||
// No good reason to lock the DB, we only need it in the first place to check char encoding.
|
// No good reason to lock the DB, we only need it in the first place to check char encoding.
|
||||||
// LockMutex lock(&MDatabase);
|
// LockMutex lock(&MDatabase);
|
||||||
char* tobuf = new char[sizeof(frombuf)*fromlen]();
|
char* tobuf = new char[sizeof(frombuf)*fromlen*2]();
|
||||||
mysql_real_escape_string(&mysql, tobuf, frombuf, fromlen);
|
unsigned long length = mysql_real_escape_string(&mysql, tobuf, frombuf, fromlen);
|
||||||
outString.assign(tobuf,sizeof(frombuf)*fromlen);
|
outString.assign(tobuf,length);
|
||||||
safe_delete_array(tobuf);
|
safe_delete_array(tobuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user