mirror of
https://github.com/ACEmulator/ACE
synced 2026-08-17 12:26:06 -04:00
* PlayerManager initial checkin * OfflinePlayer initial checkin * More progress * Comment out Console.WriteLine debug messages * Add property dictionaries to OfflinePlayer * IPlayer initial checkin * Add allegiance vars to IPlayer * Couple comments * More progress * Add more to IPlayer * line endings fix * More progress. Compiles. Friends list works again. * Friend status updates now work (again) * PlayerManager save OfflinePlayers every 1hr * Bye bye legacy AllPlayers * using cleanup * Allegience switch to PlayerManager progress * More Allegiance progress * More progress * More allegiance progress * IPlayer adds * Migrate inversefriends to PlayerManager * Switch WorldManager GetPlayerByGuid over to PlayerManager * WorldManager Find(ObjectGuid characterGuid) removed. Use PlayerManager instead * WorldManager FindByPlayerName(string name) removed. Use PlayerManager instead * PlayerManager thread safety switched to ReaderWriterLockSlim * More progress * ServerStatus added TotalAccountsCreated, TotalCharactersCreated * No more Player access/management stuff in WorldManager. It's all in PlayerManager now * Player.IsOnline is no more. * Friends AppearOnline fix * Handle dead session better to switch player from online to offline * Remove adding the + to names in ChatChannels. Name property should be changed to not include + * serverstatus total accounts and characters on same line * Allegience initial fix, still more bugs though * PlayerManager minor cleanup uint should be faster key than ObjectGuid Changed the dictionaries to private. We don't want anyone outside of this class referencing them. * Thread safety added to LScape.get_landcell
139 lines
4.1 KiB
C#
139 lines
4.1 KiB
C#
using System.Linq;
|
|
using System.Threading;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
using log4net;
|
|
|
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
|
using Microsoft.EntityFrameworkCore.Storage;
|
|
|
|
using ACE.Database.Models.Auth;
|
|
using ACE.Entity.Enum;
|
|
|
|
namespace ACE.Database
|
|
{
|
|
public class AuthenticationDatabase
|
|
{
|
|
private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
|
|
|
public bool Exists(bool retryUntilFound)
|
|
{
|
|
var config = Common.ConfigManager.Config.MySql.Authentication;
|
|
|
|
for (; ; )
|
|
{
|
|
using (var context = new AuthDbContext())
|
|
{
|
|
if (((RelationalDatabaseCreator)context.Database.GetService<IDatabaseCreator>()).Exists())
|
|
{
|
|
log.Debug($"Successfully connected to {config.Database} database on {config.Host}:{config.Port}.");
|
|
return true;
|
|
}
|
|
}
|
|
|
|
log.Error($"Attempting to reconnect to {config.Database} database on {config.Host}:{config.Port} in 5 seconds...");
|
|
|
|
if (retryUntilFound)
|
|
Thread.Sleep(5000);
|
|
else
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
public int GetAccountCount()
|
|
{
|
|
using (var context = new AuthDbContext())
|
|
return context.Account.Count();
|
|
}
|
|
|
|
/// <exception cref="MySqlException">Account with name already exists.</exception>
|
|
public Account CreateAccount(string name, string password, AccessLevel accessLevel)
|
|
{
|
|
var account = new Account();
|
|
account.CreateRandomSalt();
|
|
|
|
account.AccountName = name;
|
|
account.SetPassword(password);
|
|
account.AccessLevel = (uint)accessLevel;
|
|
|
|
using (var context = new AuthDbContext())
|
|
{
|
|
context.Account.Add(account);
|
|
|
|
context.SaveChanges();
|
|
}
|
|
|
|
return account;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Will return null if the accountId was not found.
|
|
/// </summary>
|
|
public Account GetAccountById(uint accountId)
|
|
{
|
|
using (var context = new AuthDbContext())
|
|
{
|
|
return context.Account
|
|
.AsNoTracking()
|
|
.FirstOrDefault(r => r.AccountId == accountId);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Will return null if the accountName was not found.
|
|
/// </summary>
|
|
public Account GetAccountByName(string accountName)
|
|
{
|
|
using (var context = new AuthDbContext())
|
|
{
|
|
return context.Account
|
|
.AsNoTracking()
|
|
.FirstOrDefault(r => r.AccountName == accountName);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// id will be 0 if the accountName was not found.
|
|
/// </summary>
|
|
public uint GetAccountIdByName(string accountName)
|
|
{
|
|
using (var context = new AuthDbContext())
|
|
{
|
|
var result = context.Account
|
|
.AsNoTracking()
|
|
.FirstOrDefault(r => r.AccountName == accountName);
|
|
|
|
return (result != null) ? result.AccountId : 0;
|
|
}
|
|
}
|
|
|
|
public void UpdateAccount(Account account)
|
|
{
|
|
using (var context = new AuthDbContext())
|
|
{
|
|
context.Entry(account).State = EntityState.Modified;
|
|
|
|
context.SaveChanges();
|
|
}
|
|
}
|
|
|
|
public bool UpdateAccountAccessLevel(uint accountId, AccessLevel accessLevel)
|
|
{
|
|
using (var context = new AuthDbContext())
|
|
{
|
|
var account = context.Account
|
|
.First(r => r.AccountId == accountId);
|
|
|
|
if (account == null)
|
|
return false;
|
|
|
|
account.AccessLevel = (uint)accessLevel;
|
|
|
|
context.SaveChanges();
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
}
|