public byte[] Execute(HatContext context) { // search login into database // if found, then return account data // else return fail or create new account. HatUserFactory factory = HatUserFactory.Instance(); HatUser u = factory.LoadOne( Encoding.Default.GetBytes( Login ) ); if ( u != null ) { var sha = new SHA1CryptoServiceProvider(); var hash = sha.ComputeHash( Encoding.Default.GetBytes( Password ) ); if ( u.Password != BitConverter.ToString( hash ) ) { return NetworkHelper.ClientMessageBuild( ClientOperation.SendMessage, ClientMessage.M_INVALID_LOGIN_PASSWORD ); } } else { if (Hat.Configuration.IsRegistrationAllowed) { u = new HatUser(); u.Login = Login; var sha = new SHA1CryptoServiceProvider(); var hash = sha.ComputeHash(Encoding.Default.GetBytes(Password)); u.Password = BitConverter.ToString(hash); factory.Save(u); } else { return NetworkHelper.ClientMessageBuild(ClientOperation.SendMessage, ClientMessage.M_INVALID_LOGIN_PASSWORD); } } context.User = u; var characters = u.GetCharacters(); var chars = new byte[characters.Count*8 + 9]; using (var mem = new MemoryStream(chars)) { var bw = new BinaryWriter(mem); bw.Write((byte) 0xCE); bw.Write((characters.Count*8) + 4); bw.Write(Consts.HatIdentifier); foreach (var user in characters) { bw.Write(user.CharacterId); } return chars; } }
public HatService( HatContext hatContext , IMapper mapper) { _hatContext = hatContext; _mapper = mapper; }
public IHttpActionResult GetAllPeople() { using (var db = new HatContext()) { var rv = db.People.OrderBy(o => o.Name).ToList(); return(Ok(rv)); } }
public IHttpActionResult AddPerson([FromBody] People person) { using (var db = new HatContext()) { db.People.Add(person); db.SaveChanges(); return(Ok(person)); } }
public IHttpActionResult DeletePerson([FromUri] int id) { using (var db = new HatContext()) { var person = db.People.SingleOrDefault(s => s.Id == id); if (person == null) { return(NotFound()); } db.People.Remove(person); db.SaveChanges(); return(Ok()); } }
public IHttpActionResult CreateGroups([FromBody] CreateGroupViewModel data) { // divide the amount of people by group size // define group size // get all people using (var db = new HatContext()) { var groupSize = data.Size; var people = db.People.OrderBy(o => Guid.NewGuid()).ToList(); var rv = new List <Groups>(); var loopTimes = people.Count / groupSize; // get the even groups var availibleStudents = new Queue <People>(people); for (int i = 0; i < loopTimes; i++) { var newGroup = new Groups { Name = data.Name, People = new List <People>() }; for (int j = 0; j < groupSize; j++) { newGroup.People.Add(availibleStudents.Dequeue()); } rv.Add(newGroup); } var pos = 0; while (availibleStudents.Count > 0) { if (pos >= rv.Count) { pos = 0; } rv[pos++].People.Add(availibleStudents.Dequeue()); } return(Ok(rv)); } }
public HomeController(ShirtContext context, JeansContext con_jea, HatContext con_hat) { db = context; db_jea = con_jea; db_hat = con_hat; }
public byte[] Execute(HatContext context) { return null; }
public byte[] Execute( HatContext context ) { if( context == null || context.User == null ) return null; HatUser user = context.User; }