/// <summary> /// Updates the status from a user to the status that the user has set while being online, if the login succeeds based on username and password combinations. /// </summary> public States Login(string guid, string password, Status status) { try { using (AuraContext database = new AuraContext()) { var user = database.Clients.Where(client => client.GUID == guid).FirstOrDefault(); if (user != null) { if (user.Password == password) { user.StatusEnumerator = status; database.SaveChanges(); return(States.LoginCorrect); } return(States.LoginWrong); } return(States.LoginNonexistent); } } catch (Exception) { return(States.LoginError); } }
/// <summary> /// Initializes the database or creates a new one if it does not exists already. /// </summary> internal bool Load() { try { using (AuraContext database = new AuraContext()) { bool cine = database.Database.CreateIfNotExists(); if (cine) { ServerLogger.Database("Creating database..."); } else { ServerLogger.Database("Preparing database..."); } return(true); } } catch (Exception) { ServerLogger.Error("Failed to load the database!"); return(false); } }
///<summary> /// Returns a <see cref="bool"/> value whether the instance of the <see cref="Client"/> class is banned based on the GUID property. ///</summary> public bool IsBanned(string guid) { using (AuraContext database = new AuraContext()) { return(database.Clients.FirstOrDefault(o => o.GUID == guid).IsBanned); } }
/// <summary> /// Gets a client instance based on the GUID property. /// </summary> public Client Get(string guid) { using (AuraContext database = new AuraContext()) { return(database.Clients.Where(o => o.GUID == guid).FirstOrDefault()); } }
///<summary> /// Returns a <see cref="bool"/> value whether the GUID of the client exists in the database. ///</summary> public bool Exists(string guid) { using (AuraContext database = new AuraContext()) { return(database.Clients.Any(o => o.GUID == guid)); } }
///<summary> /// Returns a <see cref="bool"/> value whether the instance of the <see cref="Client"/> class is banned. ///</summary> public bool IsBanned(Client client) { using (AuraContext database = new AuraContext()) { return(database.Clients.FirstOrDefault(o => o == client).IsBanned); } }
///<summary> /// Returns a <see cref="bool"/> value whether the client exists in the database. ///</summary> public bool Exists(Client client) { using (AuraContext database = new AuraContext()) { return(database.Clients.Contains(client)); } }
/// <summary> /// Updates a client with the modified data. /// </summary> public void Update(Client client) { using (AuraContext database = new AuraContext()) { database.Entry(client).State = EntityState.Modified; database.SaveChanges(); } }
/// <summary> /// Removes an instance of the <see cref="Client"/> class to the database. /// </summary> public async void Remove(Client client) { using (AuraContext database = new AuraContext()) { database.Clients.Remove(client); await database.SaveChangesAsync(); } }
/// <summary> /// Updates the status from a user to 'offline'. /// </summary> public void Logout(string guid) { using (AuraContext database = new AuraContext()) { var user = database.Clients.FirstOrDefault(client => client.GUID == guid); if (user != null) { user.StatusEnumerator = Status.Offline; database.SaveChanges(); } } }
/// <summary> /// Removes an instance of the <see cref="Client"/> class to the database. /// </summary> public async void Remove(string guid) { using (AuraContext database = new AuraContext()) { var user = database.Clients.FirstOrDefault(o => o.GUID == guid); if (user != null) { database.Clients.Remove(user); } await database.SaveChangesAsync(); } }
/// <summary> /// Bans a user based on their GUID. /// </summary> public void Unban(string guid) { using (AuraContext database = new AuraContext()) { var user = database.Clients.Where(client => client.GUID == guid).FirstOrDefault(); if (user != null) { user.Unban(); } database.SaveChanges(); } }
/// <summary> /// Removes a client based on the GUID property and . /// </summary> public void UnRegister(string guid, string password) { using (AuraContext database = new AuraContext()) { var user = database.Clients.FirstOrDefault(client => client.GUID == guid); if (user != null) { if (user.Password == password) { ServerLogger.Warning($"Removing a user: {user.FullName} ({user.GUID})"); database.Clients.Remove(user); ServerLogger.Important($"Removed {user.FullName} from Aura."); database.SaveChanges(); } } } }
/// <summary> /// Registers and adds a new client to the database. /// </summary> public States Register(string username, string password) { try { using (AuraContext database = new AuraContext()) { var user = database.Clients.FirstOrDefault(client => client.FullName == username); if (user != null) { try { database.Clients.Add(new Client() { FullName = username, Password = password }); database.SaveChanges(); return(States.RegisterCorrect); } catch (Exception e) { ServerLogger.Error(e); return(States.RegisterFailed); } } else { return(States.RegisterAlreadyTaken); } } } catch (Exception e) { ServerLogger.Error(e); return(States.RegisterFailed); } }
public override void Notify(Entity activeStats, ActionContext actionContext) { Entity targetEntity = m_ShipAsTarget ? activeStats.EntityBehaviour.Entity : activeStats; if (targetEntity == null) { targetEntity = activeStats; } Stat target = targetEntity.GetStat(m_Target.Identifier); Stat source = activeStats.GetStat(ModType.Identifier); AuraContext auraContext = actionContext as AuraContext; object sourceObject = this; sourceObject = auraContext?.Source; target.RemoveStatModifiersBySource(sourceObject); target.AddStatModifier(new StatModifierByStat(source, CalculationType.Flat, sourceObject)); target.AddStatModifier(new StatModifierByStat(source, CalculationType.Increased, sourceObject)); target.AddStatModifier(new StatModifierByStat(source, CalculationType.More, sourceObject)); target.AddStatModifier(new StatModifierByStat(source, CalculationType.FlatExtra, sourceObject)); }