Esempio n. 1
0
        /* -END OF INITIALIZERS- */

        /* ------------------------------------------------------------------------------------------ */

        /* -BEGIN OF TAB CONTROL- */

        void TabControl_Selecting(object sender, TabControlCancelEventArgs e)
        {
            TabPage current = (sender as TabControl).SelectedTab;

            //if (current != ReadMailTabPage && selectedMailList != null)
            //{
            //    selectedMailList.Clear();
            //}

            if (current == WelcomeTabPage)
            {
                SignOutButton.Hide();
                InitializeWelcomePage();
            }
            else if (current == ForgotPasswordTabPage)
            {
                SignOutButton.Hide();
            }
            else
            {
                SignOutButton.Show();
                TabControl.TabPages.Remove(WelcomeTabPage);
                if (current == InboxTabPage)
                {
                    Refresh(InboxTabPage);
                }
                else if (current == OutboxTabPage)
                {
                    Refresh(OutboxTabPage);
                }
                else if (current == NewMailTabPage)
                {
                    ResetNewMail();
                }
            }
        }
Esempio n. 2
0
        public dynamic handleRecievedMessage(string MsgFromServer)
        {
            int msgCode = Int32.Parse(MsgFromServer.Substring(0, 3));

            if (msgCode == 0)
            {
                // nothing it just connected
            }
            else if (msgCode == ServerCodes.SIGN_IN)
            {
                int status = Int32.Parse(MsgFromServer[3].ToString());
                switch (status)
                {
                case 0:
                    // success
                    popUpText.Text = "";

                    this.UserName.Hide();
                    this.User_Name.Hide();
                    this.Password.Hide();
                    this.Password_Text.Hide();
                    this.SignInButton.Hide();
                    this.Show_Password.Hide();
                    this.Forgot_Password.Hide();
                    this.HelloUserLabel.Text = "Hello " + User_Name.Text;
                    this.HelloUserLabel.Show();

                    this.SignUpButton.Hide();

                    this.CreateRoomButton.Enabled = true;
                    this.JoinRoomButton.Enabled   = true;
                    this.MyStatusButton.Enabled   = true;
                    this.BestScoresButton.Enabled = true;
                    this.SignOutButton.Enabled    = true;

                    SignOutButton.Show();

                    break;

                case 1:
                    // TO DO : MNADE LL DSPLE
                    popUpText.Text = "Wrong Details..";

                    break;

                case 2:
                    // is aleardy connected
                    popUpText.Text = "this user is already signed in!!";
                    break;
                }
                return(null);
            }
            else if (msgCode == ServerCodes.SIGN_UP)
            {
                int status = Int32.Parse(MsgFromServer[3].ToString());

                switch (status)
                {
                case 0:
                    return("YOU ARE NOW REGESTURED");

                    break;

                case 1:
                    return("Illegal Pass");

                    break;

                case 2:
                    return("Username Already Exists!!");

                    break;

                case 3:
                    return("Username is Illegal!!");

                    break;

                case 4:
                    return("No Clue what the problem is!!");

                    break;
                }
                return(null);
            }
            else if (msgCode == ServerCodes.GET_FORGOT_PASSWORD)
            {
                int isFound = Int32.Parse(MsgFromServer[3].ToString());

                if (isFound == 1)
                {
                    int    passwordLength = Int32.Parse(MsgFromServer.Substring(4, 4));
                    string password       = MsgFromServer.Substring(8, passwordLength);

                    return("User is Found.!, Password : "******"User not found in the DATABASE.!");
                }
                return(null);
            }

            else if (msgCode == ServerCodes.SEND_ROOMS_LIST)
            {
                int numOfRooms = Int32.Parse(MsgFromServer.Substring(3, 4));
                // rooms <id, name>
                Dictionary <string, string> Rooms = new Dictionary <string, string>();

                int    firstRoomIDIndex       = 7;
                int    firstRoomNameSizeIndex = 11;
                string roomID;
                int    roomNameSize = 0;
                string roomName;
                int    roomNameSizeSum = 0;

                for (int i = 0; i < numOfRooms; i++)
                {
                    roomNameSize = Int32.Parse(MsgFromServer.Substring(firstRoomNameSizeIndex + roomNameSizeSum + i * 4 + i * 2, 2));

                    roomName         = MsgFromServer.Substring(firstRoomNameSizeIndex + 2 + roomNameSizeSum + i * 4 + i * 2, roomNameSize);
                    roomID           = MsgFromServer.Substring(firstRoomIDIndex + i * 4 + i * 2 + roomNameSizeSum, 4);
                    roomNameSizeSum += roomNameSize;
                    Rooms.Add(roomID, roomName);
                }

                return(Rooms);
                // Send Dict in Function
            }
            else if (msgCode == ServerCodes.SEND_USERS_LIST)
            {
                int numOfUsers = Int32.Parse(MsgFromServer.Substring(3, 3));
                if (numOfUsers == 0)
                {
                }
                else
                {
                    List <string> Users = new List <string>();

                    int    firstUserNameSizeIndex = 6;
                    string userName;
                    int    NameSize;
                    int    NameSizeSum = 0;

                    for (int i = 0; i < numOfUsers; i++)
                    {
                        NameSize = Int32.Parse(MsgFromServer.Substring(firstUserNameSizeIndex + NameSizeSum + i * 2, 2));

                        userName     = MsgFromServer.Substring(firstUserNameSizeIndex + 2 + NameSizeSum + 2 * i, NameSize);
                        NameSizeSum += NameSize;

                        Users.Add(userName);
                    }

                    return(Users);// Send usernames list to the function
                }
            }
            else if (msgCode == ServerCodes.RESPOND_TO_JOIN_ROOM)
            {
                int status = Int32.Parse(MsgFromServer[4].ToString());
                switch (status)
                {
                case 0:     // success
                    List <int> list = new List <int>();

                    int numOfQuestions    = Int32.Parse(MsgFromServer.Substring(4, 2));
                    int QuestionTimeInSec = Int32.Parse(MsgFromServer.Substring(6, 2));

                    list.Add(numOfQuestions);
                    list.Add(QuestionTimeInSec);

                    return(list);

                    break;

                case 1:     // room is full

                    break;

                case 2:     // room doesn't exsist or somthing like that

                    break;
                }
                return(null);
            }
            else if (msgCode == ServerCodes.RESPOND_TO_LEAVE_ROOM)
            {
                return(MsgFromServer[4] == '0' ? true : false);
            }
            else if (msgCode == ServerCodes.RESPOND_TO_CREATE_ROOM)
            {
                int status = Int32.Parse(MsgFromServer[3].ToString());

                switch (status)
                {
                case 0:     // success
                    return(true);

                    break;

                case 1:     // fail
                    return(false);

                    break;
                }
                return(null);
            }
            else if (msgCode == ServerCodes.RESPOND_TO_CLOSE_ROOM)
            {
                return(null);
            }
            else if (msgCode == ServerCodes.RESPOND_TO_QUESTION_WITH_ANSWERS) // start game
            {
                List <string> questionWithAnswersList = new List <string>();
                int           sizeSum = 0;

                int    QuestionSize = Int32.Parse(MsgFromServer.Substring(3, 3));
                string Question     = MsgFromServer.Substring(6, QuestionSize);

                sizeSum += QuestionSize;

                int    ans1Size = Int32.Parse(MsgFromServer.Substring(6 + sizeSum, 3));
                string ans1     = MsgFromServer.Substring(6 + 3 + sizeSum, ans1Size);

                sizeSum += ans1Size;
                // "118020Who is Eddie Vedder?011Phone model007TV Show008Computer008Musician

                int    ans2Size = Int32.Parse(MsgFromServer.Substring(6 + 3 + sizeSum, 3)); //problem
                string ans2     = MsgFromServer.Substring(6 + 3 * 2 + sizeSum, ans2Size);

                sizeSum += ans2Size;

                int    ans3Size = Int32.Parse(MsgFromServer.Substring(6 + 3 * 2 + sizeSum, 3));
                string ans3     = MsgFromServer.Substring(6 + 3 * 3 + sizeSum, ans3Size);

                sizeSum += ans3Size;

                int    ans4Size = Int32.Parse(MsgFromServer.Substring(6 + 3 * 3 + sizeSum, 3));
                string ans4     = MsgFromServer.Substring(6 + 3 * 4 + sizeSum, ans4Size);

                sizeSum += ans4Size;

                questionWithAnswersList.Add(Question);
                questionWithAnswersList.Add(ans1);
                questionWithAnswersList.Add(ans2);
                questionWithAnswersList.Add(ans3);
                questionWithAnswersList.Add(ans4);

                return(questionWithAnswersList);
            }
            else if (msgCode == ServerCodes.RESPOND_TO_USERS_ANS)
            {
                int status = Int32.Parse(MsgFromServer[3].ToString());

                switch (status)
                {
                case 0:     // wrong answer
                    return(false);

                    break;

                case 1:     // correct answer
                    return(true);

                    break;
                }
                return(null);
            }
            else if (msgCode == ServerCodes.GAME_IS_FINISHED)
            {
                int numOfUsers = Int32.Parse(MsgFromServer.Substring(3, 1));

                if (numOfUsers == 0)
                {
                }
                else
                {
                    Dictionary <string, int> Users = new Dictionary <string, int>();

                    int    firstUserNameSizeIndex = 4;
                    string userName;
                    int    NameSize;
                    int    sizeSum = 0;
                    int    UserScore;

                    for (int i = 0; i < numOfUsers; i++)
                    {
                        NameSize = Int32.Parse(MsgFromServer.Substring(firstUserNameSizeIndex + sizeSum + i * 4, 2));
                        userName = MsgFromServer.Substring(firstUserNameSizeIndex + 2 + sizeSum + i * 4, NameSize);

                        sizeSum += NameSize;

                        UserScore = Int32.Parse(MsgFromServer.Substring(firstUserNameSizeIndex + 2 + sizeSum + i * 4, 2));

                        Users[userName] = UserScore;
                    }

                    return(Users);// Send usernames list to the function
                }
            }
            else if (msgCode == ServerCodes.GET_BEST_SCORES_FROM_SERVER)
            {
                Dictionary <string, int> Users = new Dictionary <string, int>();

                int    firstUserNameSizeIndex = 3;
                string userName;
                int    NameSize;
                int    sizeSum = 0;
                int    UserScore;

                for (int i = 0; i < 3; i++)
                {
                    NameSize = Int32.Parse(MsgFromServer.Substring(firstUserNameSizeIndex + sizeSum + 8 * i, 2));
                    userName = MsgFromServer.Substring(firstUserNameSizeIndex + 2 + sizeSum + i * 8, NameSize);

                    sizeSum += NameSize;

                    UserScore = Int32.Parse(MsgFromServer.Substring(firstUserNameSizeIndex + 2 + sizeSum + i * 8, 6));

                    Users[userName] = UserScore;
                }
                return(Users);
            }
            else if (msgCode == ServerCodes.GET_PERSONAL_STATUS_FROM_SERVER)
            {
                int   numberOfGames = Int32.Parse(MsgFromServer.Substring(3, 4));
                int   numberOfRightAnswers;
                int   numberOfWrongAnswers;
                float avgTimeForAnswer;

                List <string> ans = new List <string>();

                if (numberOfGames == 0)
                {
                    //nvrmnd
                    numberOfRightAnswers = Int32.Parse(MsgFromServer.Substring(7, 6));
                    numberOfWrongAnswers = Int32.Parse(MsgFromServer.Substring(13, 6));
                    int tens    = Int32.Parse(MsgFromServer.Substring(19, 1));
                    int ones    = Int32.Parse(MsgFromServer.Substring(20, 1));
                    int tenth   = Int32.Parse(MsgFromServer.Substring(21, 1));
                    int percent = Int32.Parse(MsgFromServer.Substring(22, 1));

                    avgTimeForAnswer = tens * 10 + ones * 1 + (float)(tenth * 0.1) + (float)(percent * 0.01);

                    ans.Add(numberOfGames.ToString());
                    ans.Add(numberOfRightAnswers.ToString());
                    ans.Add(numberOfWrongAnswers.ToString());
                    ans.Add(avgTimeForAnswer.ToString());
                }
                else
                {
                    numberOfRightAnswers = Int32.Parse(MsgFromServer.Substring(7, 6));
                    numberOfWrongAnswers = Int32.Parse(MsgFromServer.Substring(13, 6));
                    int tens    = Int32.Parse(MsgFromServer.Substring(19, 1));
                    int ones    = Int32.Parse(MsgFromServer.Substring(20, 1));
                    int tenth   = Int32.Parse(MsgFromServer.Substring(21, 1));
                    int percent = Int32.Parse(MsgFromServer.Substring(22, 1));

                    avgTimeForAnswer = tens * 10 + ones * 1 + (float)(tenth * 0.1) + (float)(percent * 0.01);

                    ans.Add(numberOfGames.ToString());
                    ans.Add(numberOfRightAnswers.ToString());
                    ans.Add(numberOfWrongAnswers.ToString());
                    ans.Add(avgTimeForAnswer.ToString());
                }


                return(ans);
            }
            return(null);
        }