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 void TestMethod() { HatUser u = new HatUser(); u.Login = "******"; IFactory<HatUser> factory = HatUserFactory.Instance(); factory.Save( u ); HatUser ut = factory.Load( new object() )[0]; Assert.AreEqual( u.Login, ut.Login ); }