viewing paste Unknown #6092 | Text

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
//------------------------------------------------
//Guild bound items pull for offline characters [Akinari]
//Fills in item structure to be used elsewhere
//------------------------------------------------
int mapif_parse_itembound_retrieve(int fd)
{
    StringBuf buf;
    SqlStmt* stmt;
    struct item item;
    int j, i=0, s;
    bool found=false;
    struct item items[MAX_INVENTORY];
    int char_id = RFIFOL(fd,2);
    int aid = RFIFOL(fd,6);
    int guild_id = RFIFOW(fd,10);
 
    StringBuf_Init(&buf);
    StringBuf_AppendStr(&buf, "SELECT `id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `expire_time`, `bound`");
    for( j = 0; j < MAX_SLOTS; ++j )
        StringBuf_Printf(&buf, ", `card%d`", j);
    StringBuf_Printf(&buf, " FROM `%s` WHERE `char_id`='%d'",inventory_db,char_id);
 
    stmt = SqlStmt_Malloc(sql_handle);
    if( SQL_ERROR == SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf))
    ||  SQL_ERROR == SqlStmt_Execute(stmt) )
    {
        SqlStmt_ShowDebug(stmt);
        SqlStmt_Free(stmt);
        StringBuf_Destroy(&buf);
        return 1;
    }
 
    SqlStmt_BindColumn(stmt, 0, SQLDT_INT,       &item.id,          0, NULL, NULL);
    SqlStmt_BindColumn(stmt, 1, SQLDT_SHORT,     &item.nameid,      0, NULL, NULL);
    SqlStmt_BindColumn(stmt, 2, SQLDT_SHORT,     &item.amount,      0, NULL, NULL);
    SqlStmt_BindColumn(stmt, 3, SQLDT_USHORT,    &item.equip,       0, NULL, NULL);
    SqlStmt_BindColumn(stmt, 4, SQLDT_CHAR,      &item.identify,    0, NULL, NULL);
    SqlStmt_BindColumn(stmt, 5, SQLDT_CHAR,      &item.refine,      0, NULL, NULL);
    SqlStmt_BindColumn(stmt, 6, SQLDT_CHAR,      &item.attribute,   0, NULL, NULL);
    SqlStmt_BindColumn(stmt, 7, SQLDT_UINT,      &item.expire_time, 0, NULL, NULL);
    SqlStmt_BindColumn(stmt, 8, SQLDT_UINT,      &item.bound,       0, NULL, NULL);
    for( j = 0; j < MAX_SLOTS; ++j )
        SqlStmt_BindColumn(stmt, 9+j, SQLDT_SHORT, &item.card[j], 0, NULL, NULL);
 
    while( SQL_SUCCESS == SqlStmt_NextRow(stmt) ) {
        if(item.bound == 2) {
            ShowDebug("Found an item: Item=%d\n",item.nameid);
            memcpy(&items[i],&item,sizeof(struct item));
            i++;
        }
    }
 
    StringBuf_Clear(&buf);
    StringBuf_Printf(&buf, "DELETE FROM `%s`",inventory_db);
    for(j=0; j<i; j++)
        StringBuf_Printf(&buf, " WHERE `id`=%d",items[j].id);
 
    stmt = SqlStmt_Malloc(sql_handle);
    if( SQL_ERROR == SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf))
    ||  SQL_ERROR == SqlStmt_Execute(stmt) )
    {
        SqlStmt_ShowDebug(stmt);
        SqlStmt_Free(stmt);
        StringBuf_Destroy(&buf);
        return 1;
    }
 
    StringBuf_Clear(&buf);
    StringBuf_Printf(&buf, "INSERT INTO `%s` (`nameid`, `amount`, `identify`, `refine`, `attribute`, `expire_time`, `bound`", guild_storage_db);
    for( j = 0; j < MAX_SLOTS; ++j )
        StringBuf_Printf(&buf, ", `card%d`", j);
    StringBuf_AppendStr(&buf, ") VALUES ");
    
    for( j = 0; j < i; ++j ) {
        if( found )
            StringBuf_AppendStr(&buf, ",");
        else
            found = true;
 
        StringBuf_Printf(&buf, "('%d', '%d', '%d', '%d', '%d', '%d', '%d'",
            items[i].nameid, items[i].amount, items[i].identify, items[i].refine, items[i].attribute, items[i].expire_time, items[i].bound);
        for( s = 0; s < MAX_SLOTS; ++s )
            StringBuf_Printf(&buf, ", '%d'", items[i].card[s]);
        StringBuf_AppendStr(&buf, ")");
    }
    if( SQL_ERROR == SqlStmt_PrepareStr(stmt, StringBuf_Value(&buf))
    ||  SQL_ERROR == SqlStmt_Execute(stmt) )
    {
        SqlStmt_ShowDebug(stmt);
        SqlStmt_Free(stmt);
        StringBuf_Destroy(&buf);
        return 1;
    }
 
    mapif_load_guild_storage(fd,aid,guild_id,0);
    mapif_itembound_ack(fd,aid,guild_id);
    return 0;
}
Viewed 814 times, submitted by Guest.