Exemplo n.º 1
0
        public byte[] Execute(HatContext context)
        {
            if (context == null || context.User == null)
            {
                return(null);
            }

            HatUser user = context.User;
        }
Exemplo n.º 2
0
        private void childThread(object obj)
        {
            var me      = Thread.CurrentThread;
            var context = new HatContext();

            try {
                var handler = obj as Socket;
                if (handler != null)
                {
                    while (true)
                    {
                        byte[] buffer = new byte[256];
                        int    rcvd   = handler.Receive(buffer);

                        if (rcvd > 0)
                        {
                            try {
                                var decoded = NetworkHelper.PacketDecoding(buffer);

                                var command = PacketParser.Parse(decoded);

                                var response = command.Execute(context);

                                response = NetworkHelper.PacketEncoding(response);

                                handler.Send(response);
                            }
                            catch (InvalidPacketException ex) {
                                logger.Error("Invalid packet came from client", ex);
                                using (var mem = new MemoryStream()) {
                                    NetworkHelper.DumpArray(mem, NetworkHelper.PacketDecoding(buffer));

                                    logger.Debug(mem.ToString());
                                }
                            }
                            catch (Exception ex) {
                                logger.Error("Unexpected exception raised while packet handled", ex);
                                sock.Close();
                                break;
                            }
                        }
                    }
                }
            }
            catch (ThreadAbortException ex) {
            }
            catch (ThreadInterruptedException ex) {
            }
            finally {
                lock ( childLock ) {
                    childs.Remove(me);
                }

                Thread.CurrentThread.Abort();
            }
        }
Exemplo n.º 3
0
        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);
            }
        }
Exemplo n.º 4
0
 public byte[] Execute(HatContext context)
 {
     return(null);
 }