Go Back   EQEmulator Home > EQEmulator Forums > Development > Development::Development

Development::Development Forum for development topics and for those interested in EQEMu development. (Not a support forum)

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 10-14-2013, 06:01 PM
Furniture
Hill Giant
 
Join Date: Aug 2012
Posts: 205
Default Use database queries in source code?

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?
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 05:51 AM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3