//Third generation methods inventory bool LoadInventoryEx(MySqlConnection connection, IInfoProvider2 dbq, bool continueOnError) { IDataSortableItemCollection sortableItemCollection = dbq.createInventoryCollection(); MySqlCommand command = new MySqlCommand(_query_29, connection); MySqlDataReader reader = null; command.Parameters.AddWithValue("CharId", sortableItemCollection.CharacterId); try { reader = command.ExecuteReader(); while (reader.Read()) { sortableItemCollection.Collection.Capacity = reader.GetByte(0); if (reader.IsDBNull(1)) continue; byte[] buffer2 = new byte[4]; reader.GetBytes(1, 0, buffer2, 0, 4); uint count = BitConverter.ToUInt32(buffer2, 0); int offset = 4; for (int i = 0; i < count; i++) { //BUFFER byte[] buffer = new byte[67]; reader.GetBytes(1, offset, buffer, 0, 67); Rag2Item item; if (Rag2Item.Deserialize(out item, buffer, 0)) sortableItemCollection.Collection.Add(item); offset += 67; } return true; } __dbtracelog.WriteError("Database", "player inventory-data of player with id {0} is missing", sortableItemCollection.CharacterId); return continueOnError; } catch (Exception e) { __dbtracelog.WriteError("Database", e.Message); return false; } finally { if (reader != null) reader.Close(); } }
bool SaveInventoryEx(MySqlConnection connection, IInfoProvider2 dbq) { //HELPER VARIABLES IDataSortableItemCollection sortableItemCollection = dbq.createInventoryCollection(); MySqlCommand command = new MySqlCommand(_query_30, connection); byte[] buffer = new byte[4]; int items = 0; try { //SERIALIZE ALL ITEMS foreach (Rag2Item item in sortableItemCollection.Collection) { if (item == null) continue; int offset = buffer.Length; Array.Resize<byte>(ref buffer, offset + 67); Rag2Item.Serialize(item, buffer, offset); items++; } //WRITE THE NUMBER OF ITEMS Array.Copy(BitConverter.GetBytes(items), 0, buffer, 0, 4); command.Parameters.AddWithValue("CharId", sortableItemCollection.CharacterId); command.Parameters.AddWithValue("ContainerMaxStorage", sortableItemCollection.Collection.Capacity); command.Parameters.AddWithValue("Container", buffer); return command.ExecuteNonQuery() > 0; } catch (Exception e) { __dbtracelog.WriteError("Database", e.Message); return false; } }