//Third generation methods addition bool LoadAdditionsEx(MySqlConnection connection, IInfoProvider2 dbq, bool continueOnError) { MySqlCommand command = new MySqlCommand(_query_03, connection); IDataAdditionCollection additionCollection = dbq.createAdditionCollection(); command.Parameters.AddWithValue("CharId", additionCollection.CharacterId); MySqlDataReader reader = null; try { reader = command.ExecuteReader(); while (reader.Read()) { if (reader.IsDBNull(1) == true) return true; byte[] buffer = new byte[8]; reader.GetBytes(1, 0, buffer, 0, 4); uint count = BitConverter.ToUInt32(buffer, 0); for (int i = 0; i < count; i++) { reader.GetBytes(1, 4 + (8 * i), buffer, 0, 8); uint addition = BitConverter.ToUInt32(buffer, 0); uint duration = BitConverter.ToUInt32(buffer, 4); additionCollection.Create(addition, duration); } return true; } __dbtracelog.WriteError("Database", "player addition-data of player with id {0} is missing", additionCollection.CharacterId); return continueOnError; } catch (MySqlException e) { __dbtracelog.WriteError("Database", e.Message); return false; } finally { if (reader != null) reader.Close(); } }
bool InsertAdditionsEx(MySqlConnection connection, IInfoProvider2 dbq) { IDataAdditionCollection additionCollection = dbq.createAdditionCollection(); MySqlCommand command = new MySqlCommand(_query_05, connection); byte[] buffer = new byte[2044]; int items = 0; try { int offset = 4; foreach (AdditionState current in additionCollection.Additions) { uint duration = (current.CanExpire) ? current.Lifetime : 0; uint addition = current.Addition; Array.Copy(BitConverter.GetBytes(addition), 0, buffer, offset + 0, 4); Array.Copy(BitConverter.GetBytes(duration), 0, buffer, offset + 4, 4); items++; offset += 8; } Array.Copy(BitConverter.GetBytes(items), 0, buffer, 0, 4); command.Parameters.AddWithValue("CharId", additionCollection.CharacterId); command.Parameters.AddWithValue("Additions", buffer); return command.ExecuteNonQuery() > 0; } catch (MySqlException e) { __dbtracelog.WriteError("Database", e.Message); return false; } }