Hi, I need to know how to run database queries in my source code. I am trying to remove trade between characters who have different "expansion" values in my character_vars table as I made per here:
http://www.eqemulator.net/wiki/wikka...mCharacterData
Here is my code:
Code:
void Client::Handle_OP_TradeRequest(const EQApplicationPacket *app)
{
if (app->size != sizeof(TradeRequest_Struct)) {
LogFile->write(EQEMuLog::Error, "Wrong size: OP_TradeRequest, size=%i, expected %i", app->size, sizeof(TradeRequest_Struct));
return;
}
// Client requesting a trade session from an npc/client
// Trade session not started until OP_TradeRequestAck is sent
BreakInvis();
// Pass trade request on to recipient
TradeRequest_Struct* msg = (TradeRequest_Struct*) app->pBuffer;
Mob* tradee = entity_list.GetMob(msg->to_mob_id);
if (tradee && tradee->IsClient()) { {
char *query = 0;
MYSQL_RES *result;
MYSQL_ROW row;
char errbuf[MYSQL_ERRMSG_SIZE];
int myExpansion = -1;
int tradeeExpansion = -2;
MakeAnyLenString(&query, "SELECT %s FROM character_vars WHERE character_id = %i", expansion, AccountID());
if (database.RunQuery(query, strlen(query), errbuf, &result))
{
safe_delete_array(query);
row = mysql_fetch_row(result);
mysql_free_result(result);
myExpansion = (atoi(row[0]));
}
MakeAnyLenString(&query, "SELECT %s FROM character_vars WHERE character_id = %i", expansion, tradee->CastToClient()->AccountID());
if (database.RunQuery(query, strlen(query), errbuf, &result))
{
safe_delete_array(query);
row = mysql_fetch_row(result);
mysql_free_result(result);
tradeeExpansion = (atoi(row[0]));
}
if (myExpansion != tradeeExpansion)
{
return;
}
tradee->CastToClient()->QueuePacket(app);
}
This compiles fine but crashes the zone when a trade initiates. Can anybody help me fix this or even know if there is an easier way I could do this?