Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Conquer_Online_Server.DB.Model;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Conquer_Online_Server.DB
- {
- public class AccountsTable
- {
- public enum AccountState : byte
- {
- NotActivated = 100,
- ProjectManager = 4,
- Entity = 2,
- Banned = 1,
- DoesntExist = 0
- }
- public string Username;
- public string Password;
- public string IP;
- public uint EntityID;
- public AccountState State;
- private int RandomKey;
- public bool Login(string username)
- {
- bool Exists = false;
- using(var context = new MyContext())
- {
- var acc = context.accounts.Find(username);
- if (acc == null)
- Exists = false;
- else
- {
- Exists = true;
- this.Username = acc.Username;
- this.Password = acc.Password;
- this.State = (AccountState)acc.State;
- this.IP = acc.IP;
- this.EntityID = (uint)acc.EntityID;
- }
- }
- return Exists;
- }
- public uint GenerateKey(int randomKey = 0)
- {
- if (randomKey == 0)
- RandomKey = Kernel.Random.Next(11, 253) % 100 + 1;
- return (uint)
- (Username.GetHashCode() *
- Password.GetHashCode() *
- RandomKey);
- }
- public void Save()
- {
- using (var db = new MyContext())
- {
- var acc = db.accounts.Find(this.Username);
- acc.EntityID = EntityID;
- acc.State = (byte)State;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement