Skip to content

Commit

Permalink
Merge branch 'master' into stopnow
Browse files Browse the repository at this point in the history
  • Loading branch information
LtRipley36706 authored Apr 12, 2020
2 parents dc09b9e + f862d12 commit c23cf71
Show file tree
Hide file tree
Showing 52 changed files with 669 additions and 320 deletions.
2 changes: 1 addition & 1 deletion AppVeyor/dbversion.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.167
0.9.168
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
USE ace_shard;

ALTER TABLE `biota_properties_palette`
ADD COLUMN `order` TINYINT(3) UNSIGNED NULL DEFAULT NULL AFTER `length`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
USE ace_shard;

ALTER TABLE `character_properties_spell_bar`
DROP FOREIGN KEY `wcid_spellbar`;
ALTER TABLE `character_properties_spell_bar`
DROP INDEX `wcid_spellbar_barId_spellId_uidx`;

UPDATE character_properties_spell_bar
SET spell_Bar_Number = spell_Bar_Number + 1,
spell_Bar_Index = spell_Bar_Index + 1
WHERE id > 0;

ALTER TABLE `character_properties_spell_bar`
DROP COLUMN `id`,
DROP PRIMARY KEY,
ADD PRIMARY KEY (`character_Id`, `spell_Bar_Number`, `spell_Id`),
ADD INDEX `spellBar_idx` (`spell_Bar_Index` ASC);

ALTER TABLE `character_properties_spell_bar`
ADD CONSTRAINT `characterId_spellbar`
FOREIGN KEY (`character_Id`)
REFERENCES `character` (`id`)
ON DELETE CASCADE;
8 changes: 5 additions & 3 deletions Source/ACE.Database/Adapter/BiotaConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public static ACE.Entity.Models.Biota ConvertToEntityBiota(ACE.Database.Models.S
{
result.PropertiesPalette = new Collection<PropertiesPalette>();

foreach (var record in biota.BiotaPropertiesPalette)
foreach (var record in biota.BiotaPropertiesPalette.OrderBy(r => r.Order))
{
var newEntity = new PropertiesPalette
{
Expand Down Expand Up @@ -557,9 +557,11 @@ public static ACE.Database.Models.Shard.Biota ConvertFromEntityBiota(ACE.Entity.

if (biota.PropertiesPalette != null)
{
foreach (var value in biota.PropertiesPalette)
for (int i = 0; i < biota.PropertiesPalette.Count; i++)
{
var entity = new BiotaPropertiesPalette { ObjectId = biota.Id, SubPaletteId = value.SubPaletteId, Offset = value.Offset, Length = value.Length };
var value = biota.PropertiesPalette[i];

var entity = new BiotaPropertiesPalette { ObjectId = biota.Id, SubPaletteId = value.SubPaletteId, Offset = value.Offset, Length = value.Length, Order = (byte)i };

result.BiotaPropertiesPalette.Add(entity);
}
Expand Down
15 changes: 11 additions & 4 deletions Source/ACE.Database/Adapter/BiotaUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,21 +177,28 @@ public static void UpdateDatabaseBiota(ShardDbContext context, ACE.Entity.Models

if (sourceBiota.PropertiesPalette != null)
{
foreach (var value in sourceBiota.PropertiesPalette)
for (int i = 0; i < sourceBiota.PropertiesPalette.Count; i++)
{
BiotaPropertiesPalette existingValue = targetBiota.BiotaPropertiesPalette.FirstOrDefault(r => r.SubPaletteId == value.SubPaletteId && r.Offset == value.Offset && r.Length == value.Length);
var value = sourceBiota.PropertiesPalette[i];

BiotaPropertiesPalette existingValue = targetBiota.BiotaPropertiesPalette.FirstOrDefault(r => r.Order == i);

if (existingValue == null)
{
existingValue = new BiotaPropertiesPalette { ObjectId = sourceBiota.Id, SubPaletteId = value.SubPaletteId, Offset = value.Offset, Length = value.Length };
existingValue = new BiotaPropertiesPalette { ObjectId = sourceBiota.Id };

targetBiota.BiotaPropertiesPalette.Add(existingValue);
}

existingValue.SubPaletteId = value.SubPaletteId;
existingValue.Offset = value.Offset;
existingValue.Length = value.Length;
existingValue.Order = (byte)i;
}
}
foreach (var value in targetBiota.BiotaPropertiesPalette)
{
if (sourceBiota.PropertiesPalette == null || !sourceBiota.PropertiesPalette.Any(p => p.SubPaletteId == value.SubPaletteId && p.Offset == value.Offset && p.Length == value.Length))
if (sourceBiota.PropertiesPalette == null || value.Order == null || value.Order >= sourceBiota.PropertiesPalette.Count)
context.BiotaPropertiesPalette.Remove(value);
}

Expand Down
22 changes: 19 additions & 3 deletions Source/ACE.Database/AuthenticationDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,6 @@ public bool UpdateAccountAccessLevel(uint accountId, AccessLevel accessLevel)
return true;
}

/// <summary>
/// Will return null if the accountId was not found.
/// </summary>
public List<string> GetListofAccountsByAccessLevel(AccessLevel accessLevel)
{
using (var context = new AuthDbContext())
Expand All @@ -160,5 +157,24 @@ public List<string> GetListofAccountsByAccessLevel(AccessLevel accessLevel)
return result;
}
}

public List<string> GetListofBannedAccounts()
{
using (var context = new AuthDbContext())
{
var results = context.Account
.AsNoTracking()
.Where(r => r.BanExpireTime > DateTime.UtcNow).ToList();

var result = new List<string>();
foreach (var account in results)
{
var bannedbyAccount = account.BannedByAccountId.Value > 0 ? $"account {GetAccountById(account.BannedByAccountId.Value).AccountName}" : "CONSOLE";
result.Add($"{account.AccountName} -- banned by {bannedbyAccount} until server time {account.BanExpireTime.Value.ToLocalTime():MMM dd yyyy h:mmtt}{(!string.IsNullOrWhiteSpace(account.BanReason) ? $" -- Reason: {account.BanReason}" : "")}");
}

return result;
}
}
}
}
3 changes: 2 additions & 1 deletion Source/ACE.Database/DatabaseManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public static void Start()

public static void Stop()
{
serializedShardDb.Stop();
if (serializedShardDb != null)
serializedShardDb.Stop();
}
}
}
10 changes: 10 additions & 0 deletions Source/ACE.Database/Models/Auth/AccountExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,15 @@ public static void UpdateLastLogin(this Account account, IPAddress address)

DatabaseManager.Authentication.UpdateAccount(account);
}

public static void UnBan(this Account account)
{
account.BanExpireTime = null;
account.BannedByAccountId = null;
account.BannedTime = null;
account.BanReason = null;

DatabaseManager.Authentication.UpdateAccount(account);
}
}
}
1 change: 1 addition & 0 deletions Source/ACE.Database/Models/Shard/BiotaPropertiesPalette.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public partial class BiotaPropertiesPalette
public uint SubPaletteId { get; set; }
public ushort Offset { get; set; }
public ushort Length { get; set; }
public byte? Order { get; set; }

public virtual Biota Object { get; set; }
}
Expand Down
32 changes: 22 additions & 10 deletions Source/ACE.Database/Models/Shard/CharacterExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public static List<CharacterPropertiesSpellBar> GetSpellsInBar(this Character ch
rwLock.EnterReadLock();
try
{
return character.CharacterPropertiesSpellBar.Where(x => x.SpellBarNumber == barNumber).ToList();
return character.CharacterPropertiesSpellBar.Where(x => x.SpellBarNumber == barNumber + 1).OrderBy(x => x.SpellBarIndex).ToList();
}
finally
{
Expand All @@ -289,21 +289,28 @@ public static void AddSpellToBar(this Character character, uint barNumber, uint
rwLock.EnterWriteLock();
try
{
var spellCountInThisBar = character.CharacterPropertiesSpellBar.Count(x => x.SpellBarNumber == barNumber);
var spellCountInThisBar = character.CharacterPropertiesSpellBar.Count(x => x.SpellBarNumber == barNumber + 1);

if (indexInBar > spellCountInThisBar + 1)
indexInBar = (uint)(spellCountInThisBar + 1);
//Console.WriteLine($"Character.AddSpellToBar.Entry: barNumber = {barNumber} ({barNumber + 1}) | indexInBar = {indexInBar} ({indexInBar + 1}) | spell = {spell} | spellCountInThisBar = {spellCountInThisBar}");

if (indexInBar > spellCountInThisBar)
indexInBar = (uint)(spellCountInThisBar);

// We must increment the position of existing spells in the bar that exist on or after this position
foreach (var property in character.CharacterPropertiesSpellBar)
foreach (var property in character.CharacterPropertiesSpellBar.OrderBy(x => x.SpellBarIndex))
{
if (property.SpellBarNumber == barNumber && property.SpellBarIndex >= indexInBar)
if (property.SpellBarNumber == barNumber + 1 && property.SpellBarIndex >= indexInBar + 1)
{
property.SpellBarIndex++;
//Console.WriteLine($"Character.AddSpellToBar.Adjust: SpellBarNumber = {property.SpellBarNumber} | SpellBarIndex = {property.SpellBarIndex} ({property.SpellBarIndex - 1}) | SpellId = {property.SpellId}");
}
}

var entity = new CharacterPropertiesSpellBar { CharacterId = character.Id, SpellBarNumber = barNumber, SpellBarIndex = indexInBar, SpellId = spell, Character = character };
var entity = new CharacterPropertiesSpellBar { CharacterId = character.Id, SpellBarNumber = barNumber + 1, SpellBarIndex = indexInBar + 1, SpellId = spell, Character = character };

character.CharacterPropertiesSpellBar.Add(entity);

//Console.WriteLine($"Character.AddSpellToBar.Add: barNumber = {barNumber + 1} | indexInBar = {indexInBar + 1} | spell = {spell}");
}
finally
{
Expand All @@ -319,20 +326,25 @@ public static bool TryRemoveSpellFromBar(this Character character, uint barNumbe
rwLock.EnterUpgradeableReadLock();
try
{
entity = character.CharacterPropertiesSpellBar.FirstOrDefault(x => x.SpellBarNumber == barNumber && x.SpellId == spell);
//Console.WriteLine($"Character.TryRemoveSpellFromBar.Entry: barNumber = {barNumber} ({barNumber + 1}) | spell = {spell}");
entity = character.CharacterPropertiesSpellBar.FirstOrDefault(x => x.SpellBarNumber == barNumber + 1 && x.SpellId == spell);
if (entity != null)
{
rwLock.EnterWriteLock();
try
{
//Console.WriteLine($"Character.TryRemoveSpellFromBar.Remove: SpellBarNumber = {entity.SpellBarNumber} | SpellBarIndex = {entity.SpellBarIndex} | SpellId = {entity.SpellId}");
character.CharacterPropertiesSpellBar.Remove(entity);
entity.Character = null;

// We must decrement the position of existing spells in the bar that exist after this position
foreach (var property in character.CharacterPropertiesSpellBar)
foreach (var property in character.CharacterPropertiesSpellBar.OrderBy(x => x.SpellBarIndex))
{
if (property.SpellBarNumber == barNumber && property.SpellBarIndex > entity.SpellBarIndex)
if (property.SpellBarNumber == barNumber + 1 && property.SpellBarIndex > entity.SpellBarIndex)
{
property.SpellBarIndex--;
//Console.WriteLine($"Character.TryRemoveSpellFromBar.Adjust: SpellBarNumber = {property.SpellBarNumber} | SpellBarIndex = {property.SpellBarIndex} ({property.SpellBarIndex + 1}) | SpellId = {property.SpellId}");
}
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace ACE.Database.Models.Shard
{
public partial class CharacterPropertiesSpellBar
{
public uint Id { get; set; }
public uint CharacterId { get; set; }
public uint SpellBarNumber { get; set; }
public uint SpellBarIndex { get; set; }
Expand Down
Loading

0 comments on commit c23cf71

Please sign in to comment.