[DEV V Rev 12] Fixed itemmall give item to other player

If you want to help us or give some corrections / codes, put it here ;)

Moderators: osRose dev team, ospRose dev team, osiRose dev team, Moderators

[DEV V Rev 12] Fixed itemmall give item to other player

Postby WiseGuy on Sat May 24, 2014 7:00 pm

to avoid duplicate entries when giving an item to another player

wordpacket pakItemmall

search:
  1.        case 4: // Observe: Confirm receiver information


replace the whole case by:
  1.  
  2.         case 4: // Observe: Confirm receiver information
  3.         {
  4.             int imSlot = GETBYTE ((*P), 4 );
  5.             char name[30];
  6.             char accountName[30];
  7.             memcpy( name, &P->Buffer[5], P->Size );
  8.  
  9.             MYSQL_RES *accName = GServer->DB->QStore("SELECT account_name FROM characters WHERE char_name='%s'",name);
  10.             if(accName==NULL) return false;
  11.  
  12.             MYSQL_ROW row = mysql_fetch_row(accName);
  13.             memcpy( accountName, row[0], 25 );
  14.             GServer->DB->FreeResult( );
  15.  
  16.             MYSQL_RES *result = GServer->DB->QStore("SELECT id FROM accounts WHERE username='%s'", accountName);
  17.             if(accName==NULL) return false;
  18.  
  19.             MYSQL_ROW row2 = mysql_fetch_row(result);
  20.             int otherID = atoi(row[0]);
  21.             GServer->DB->FreeResult( );
  22.  
  23.             int otherSlot;
  24.             result = GServer->DB->QStore("SELECT MAX(slotnum) FROM mileage WHERE owner='%i'", otherID);
  25.             if(result==NULL){
  26.                 otherSlot = 0;
  27.             } else {
  28.                 row = mysql_fetch_row(result);
  29.                 otherSlot = atoi(row[0])+1;
  30.             }
  31.             GServer->DB->FreeResult( );
  32.  
  33.             BEGINPACKET ( pak, 0x7d9 );
  34.             ADDBYTE     ( pak, 0x06 );
  35.             ADDWORD     ( pak, imSlot );
  36.             ADDWORD     ( pak, imSlot );
  37.  
  38.             for(byte i=0; i<30; i++)
  39.             {
  40.                 ADDBYTE ( pak, 0 );
  41.             }
  42.  
  43.             GServer->DB->Query("UPDATE mileage SET owner='%i', slotnum='%i' WHERE owner='%i' AND slotnum='%i'", otherID, otherSlot, thisclient->Session->userid, imSlot);
  44.             thisclient->client->SendPacket(&pak);
  45.         }
  46.         break;
  47.  


to fInd free slotnum, I prepare SELECT MAX(slotnum)
raher than: SELECT *
in my opinion more secure to avoid duplicate entry
CMIIW
It is nice to be important
but very very important to be nice
User avatar
WiseGuy
Pomic
Pomic
 
Posts: 112
Joined: Sat Nov 21, 2009 4:03 am
Location: Jakarta

Return to Submit Code

Who is online

Users browsing this forum: No registered users and 4 guests

cron