Пример #1
0
        public override bool Submit()
        {
            //get user inputs
            User user = new User(this.GetInputByIndex(0), this.GetInputByIndex(1));

            //send login packet
            Client.GetClient().SendPacket(new UserInfoPacket().Construct(user), Client.GetSocket());
            //wait for response
            Packet response = Client.GetClient().ReceivePacket <Packet>(Client.GetSocket());

            if (response.PacketType == -2)
            {
                //if successful, request available planes
                // Client.GetClient().SendPacket(new RequestAvailablePlanesPacket().Construct(user), Client.GetSocket());
                // SendAvailablePlanesPacket response2 = Client.GetClient().ReceivePacket<SendAvailablePlanesPacket>(Client.GetSocket());
                // //this one is async for some reason so we wait until response2 is not null.
                // while (response2 == null);
                // SessionData.Planes = response2.PlaneInfos;
                SessionData.CurrentUser = user;
                //go to next menu
                Program.MenuManager.ChangeMenu(new SelectPlaneMenu(Utillity.UpdatePlanes(user)));

                return(true);
            }
            else
            {
                this.ErrorMessage = "Invalid login (check username and password)";
                return(false);
            }
        }
Пример #2
0
        public override bool Submit()
        {
            string selectedPlaneStr = this.GetInputByIndex(0);

            int selectedSeat;

            if (!Int32.TryParse(selectedPlaneStr, out selectedSeat))
            {
                this.ErrorMessage = "The input was NOT a number!";
                return(false);
            }

            if (selectedSeat > this.Plane.MaxNumberOfSeats - 1)
            {
                this.ErrorMessage = "The plane does not have that many seats!";
                return(false);
            }

            foreach (int takenPlane in this.Plane.TakenSeats)
            {
                if (selectedSeat == takenPlane)
                {
                    this.ErrorMessage = "That plane is already known to be taken!";
                    return(false);
                }
            }

            Client.GetClient().SendPacket(new BookPlaneSeatPacket().Construct(this.Plane.PlaneID, selectedSeat, SessionData.CurrentUser), Client.GetSocket());
            //receive response packet
            Packet response = Client.GetClient().ReceivePacket <Packet>(Client.GetSocket());

            if (response.PacketType != -2)
            {
                this.ErrorMessage = "An error occurred.";
                return(false);
            }

            Program.MenuManager.ChangeMenu(new SelectPlaneMenu(Utillity.UpdatePlanes(SessionData.CurrentUser)));

            return(true);
        }