Пример #1
0
        private void Account(Socket socket, Subheader sh, PacketReader pr)
        {
            ServerUserInformation usrInfo = new ServerUserInformation();
            UserInformation       info;

            switch (sh)
            {
            case Subheader.LOGIN:
                info = pr.ReadObject <UserInformation>();
                sh   = DatabaseQuery.Login(ref info, ref usrInfo);
                UpdateClientInfo(usrInfo);
                if (sh != Subheader.NULL)
                {
                    SendError(socket, sh, null);
                }
                else
                {
                    SendUserInfo(socket, info);
                }
                break;

            case Subheader.REGISTER:
                info = pr.ReadObject <UserInformation>();
                sh   = DatabaseQuery.Register(ref info, ref usrInfo);
                UpdateClientInfo(usrInfo);
                if (sh != Subheader.NULL)
                {
                    SendError(socket, sh, null);
                }
                else
                {
                    SendUserInfo(socket, info);
                }
                break;

            case Subheader.USERNAME:
                sh = DatabaseQuery.UserExists(pr.ReadString());
                if (sh != Subheader.NULL)
                {
                    SendError(socket, sh, null);
                }
                else
                {
                    SendHeaders(socket, Header.Account, Subheader.USERNAME);
                }
                break;

            case Subheader.CHANGEPASS:
                info = pr.ReadObject <UserInformation>();
                sh   = DatabaseQuery.ChangePassword(ref info, ref usrInfo);
                UpdateClientInfo(usrInfo);
                if (sh != Subheader.NULL)
                {
                    SendError(socket, sh, null);
                }
                else
                {
                    SendUserInfo(socket, info);
                }
                break;

            default:     // Invalid Subheader
                SendError(socket, Subheader.INVALIDREQ, null);
                break;
            }
        }