Пример #1
0
        private void HandleCreation()
        {
            try
            {
                //send signin request
                string msg = "";
                msg = "213" + "##" + this.roomName.Text + "##" + this.playersNum.Text + "##" + this.questionNum.Text + "##" + this.timePerQuestion.Text;

                Program.SendMsg(sock, msg);

                string input = Program.RecvMsg(sock);

                //checking answer
                if (input == "1140")
                {                                                                                                                                                 //send as admin
                    WaitForRoom waiting = new WaitForRoom(sock, true, -1, roomName.Text, this.questionNum.Text, this.timePerQuestion.Text, this.playersNum.Text); //	-1 will be a default value for gameID
                    this.Hide();
                    waiting.ShowDialog();
                    this.Close();
                }
                else
                {
                    MessageBox.Show("The room was not created!\n\nPlease try again");
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
Пример #2
0
        private void HandleRoomJoin()
        {
            try
            {
                //send request
                string msg = "209";

                if (rooms.SelectedItem.ToString() != "")
                {
                    msg = msg + "#" + roomsDic[rooms.SelectedItem.ToString()];
                }
                else
                {
                    msg += "#-1";                    //expecting error code in return
                }

                Program.SendMsg(sock, msg);

                string input = Program.RecvMsg(sock);

                List <string> reply = Program.StrSplit(input, '#');

                if (reply[0] == "108")
                {
                    input = Program.RecvMsg(sock);

                    reply = Program.StrSplit(input, '#');

                    if (reply[0] == "1100")
                    {                    //send not as admin
                        WaitForRoom waiting = new WaitForRoom(sock, false, Int32.Parse(roomsDic[rooms.Text]), rooms.Text, reply[1], reply[2], "");
                        this.Hide();
                        waiting.ShowDialog();
                        this.Close();
                    }
                    else if (reply[0] == "1101")
                    {
                        this.alert.Text = "Room is full!";
                    }
                    else
                    {
                        this.alert.Text = "Room does not exist!";
                    }
                }
                else
                {
                    if (reply[0] == "1100")
                    {                    //send not as admin
                        WaitForRoom waiting = new WaitForRoom(sock, false, Int32.Parse(roomsDic[rooms.Text]), rooms.Text, reply[1], reply[2], "");
                        this.Hide();
                        waiting.ShowDialog();
                        this.Close();
                    }
                    else if (reply[0] == "1101")
                    {
                        this.alert.Text = "Room is full!";
                    }
                    else
                    {
                        this.alert.Text = "Room does not exist!";
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }