mirror of
https://github.com/EQEmu/Server.git
synced 2026-01-15 10:03:51 +00:00
Converted StoreCharacter to QueryDatabase
This commit is contained in:
parent
ceccf2b1ca
commit
b0612f8cdf
@ -602,49 +602,18 @@ 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)
|
||||||
{
|
{
|
||||||
char errbuf[MYSQL_ERRMSG_SIZE];
|
|
||||||
char query[256+sizeof(PlayerProfile_Struct)*2+sizeof(ExtendedProfile_Struct)*2+5];
|
char query[256+sizeof(PlayerProfile_Struct)*2+sizeof(ExtendedProfile_Struct)*2+5];
|
||||||
char* end = query;
|
char* end = query;
|
||||||
uint32 affected_rows = 0;
|
char* invquery = nullptr;
|
||||||
int i;
|
|
||||||
uint32 charid = 0;
|
uint32 charid = 0;
|
||||||
char* charidquery = 0;
|
|
||||||
char* invquery = 0;
|
|
||||||
MYSQL_RES *result;
|
|
||||||
MYSQL_ROW row = 0;
|
|
||||||
char zone[50];
|
char zone[50];
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
|
|
||||||
// memset(&playeraa, 0, sizeof(playeraa));
|
charid = GetCharacterID(pp->name);
|
||||||
|
|
||||||
// get the char id (used in inventory inserts below)
|
|
||||||
if(!RunQuery
|
|
||||||
(
|
|
||||||
charidquery,
|
|
||||||
MakeAnyLenString
|
|
||||||
(
|
|
||||||
&charidquery,
|
|
||||||
"SELECT id FROM character_ where name='%s'",
|
|
||||||
pp->name
|
|
||||||
),
|
|
||||||
errbuf,
|
|
||||||
&result
|
|
||||||
)) {
|
|
||||||
safe_delete_array(charidquery);
|
|
||||||
LogFile->write(EQEMuLog::Error, "Error in char store id query: %s: %s", charidquery, errbuf);
|
|
||||||
return(false);
|
|
||||||
}
|
|
||||||
safe_delete_array(charidquery);
|
|
||||||
|
|
||||||
if(mysql_num_rows(result) == 1)
|
|
||||||
{
|
|
||||||
row = mysql_fetch_row(result);
|
|
||||||
if(row[0])
|
|
||||||
charid = atoi(row[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!charid)
|
if(!charid)
|
||||||
{
|
{
|
||||||
@ -659,6 +628,7 @@ bool Database::StoreCharacter(uint32 account_id, PlayerProfile_Struct* pp, Inven
|
|||||||
pp->zone_id = 1;
|
pp->zone_id = 1;
|
||||||
} else
|
} else
|
||||||
strn0cpy(zone, zname, 49);
|
strn0cpy(zone, zname, 49);
|
||||||
|
|
||||||
x=pp->x;
|
x=pp->x;
|
||||||
y=pp->y;
|
y=pp->y;
|
||||||
z=pp->z;
|
z=pp->z;
|
||||||
@ -674,44 +644,32 @@ bool Database::StoreCharacter(uint32 account_id, PlayerProfile_Struct* pp, Inven
|
|||||||
end += DoEscapeString(end, (char*)ext, sizeof(ExtendedProfile_Struct));
|
end += DoEscapeString(end, (char*)ext, sizeof(ExtendedProfile_Struct));
|
||||||
end += sprintf(end, "\' WHERE account_id=%d AND name='%s'",account_id, pp->name);
|
end += sprintf(end, "\' WHERE account_id=%d AND name='%s'",account_id, pp->name);
|
||||||
|
|
||||||
RunQuery(query, (uint32) (end - query), errbuf, 0, &affected_rows);
|
auto results = QueryDatabase(query, (uint32) (end - query));
|
||||||
|
// stack assigned query, no need to delete it.
|
||||||
|
|
||||||
if(!affected_rows)
|
if(!results.RowsAffected())
|
||||||
{
|
{
|
||||||
LogFile->write(EQEMuLog::Error, "StoreCharacter query '%s' %s", query, errbuf);
|
LogFile->write(EQEMuLog::Error, "StoreCharacter query '%s' %s", query, results.ErrorMessage().c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
affected_rows = 0;
|
|
||||||
|
|
||||||
|
|
||||||
// Doodman: Is this even used?
|
|
||||||
// now the inventory
|
// now the inventory
|
||||||
|
for (int16 i=0; i<=2270;)
|
||||||
for (i=0; i<=2270;)
|
|
||||||
{
|
{
|
||||||
const ItemInst* newinv = inv->GetItem((int16)i);
|
const ItemInst* newinv = inv->GetItem(i);
|
||||||
if (newinv)
|
if (!newinv)
|
||||||
{
|
{
|
||||||
MakeAnyLenString
|
auto results = QueryDatabase(invquery, MakeAnyLenString(&invquery,
|
||||||
(
|
|
||||||
&invquery,
|
|
||||||
"INSERT INTO inventory SET "
|
"INSERT INTO inventory SET "
|
||||||
"charid=%0u, slotid=%0d, itemid=%0u, charges=%0d, color=%0u",
|
"charid=%0u, slotid=%0d, itemid=%0u, charges=%0d, color=%0u",
|
||||||
charid, i, newinv->GetItem()->ID,
|
charid, i, newinv->GetItem()->ID,
|
||||||
newinv->GetCharges(), newinv->GetColor()
|
newinv->GetCharges(), newinv->GetColor()));
|
||||||
);
|
|
||||||
|
|
||||||
RunQuery(invquery, strlen(invquery), errbuf, 0, &affected_rows);
|
if (!results.RowsAffected())
|
||||||
if(!affected_rows)
|
LogFile->write(EQEMuLog::Error, "StoreCharacter inventory failed. Query '%s' %s", invquery, results.ErrorMessage().c_str());
|
||||||
{
|
|
||||||
LogFile->write(EQEMuLog::Error, "StoreCharacter inventory failed. Query '%s' %s", invquery, errbuf);
|
|
||||||
}
|
|
||||||
#if EQDEBUG >= 9
|
#if EQDEBUG >= 9
|
||||||
else
|
else
|
||||||
{
|
LogFile->write(EQEMuLog::Debug, "StoreCharacter inventory succeeded. Query '%s'", invquery);
|
||||||
LogFile->write(EQEMuLog::Debug, "StoreCharacter inventory succeeded. Query '%s' %s", invquery, errbuf);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
safe_delete_array(invquery);
|
safe_delete_array(invquery);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user