Пример #1
0
        private string SubmitAnswer(string answer, uint timeElapsed)
        {
            JSON_Classes.SubmitAnswerRequest request = new JSON_Classes.SubmitAnswerRequest {
                Answer = answer, TimeUntilResponse = timeElapsed
            };
            byte[] message = GlobalHelpers.CreateMessage("132", request);
            ClientSocket.client.Send(message);
            byte[] response  = new byte[1024];
            int    bytesRead = ClientSocket.client.Receive(response);

            Array.Resize <byte>(ref response, bytesRead);
            if (GlobalHelpers.GetCode(response) == "232")
            {
                var submissionResult = MessagePack.MessagePackSerializer.Deserialize <JSON_Classes.SubmitAnswerResponse>(GlobalHelpers.GetMsgpack(response));
                switch (submissionResult.Status)
                {
                case 0:
                    return(submissionResult.CorrectAnswer);

                default:
                    MessageBox.Show("Could Not Submit Answer!");
                    this.Close();
                    DialogResult = DialogResult.Abort;
                    break;
                }
            }
            else
            {
                MessageBox.Show("Could Not Submit Answer!");
                this.Close();
                DialogResult = DialogResult.Abort;
            }
            return("");
        }
Пример #2
0
        private void SubmitButton_Click(object sender, EventArgs e)
        {
            var signupRequest = new JSON_Classes.SignupRequest {
                Username = UsernameTextBox.Text, Password = PasswordTextBox.Text, Email = EmailTextBox.Text
            };

            byte[] message = GlobalHelpers.CreateMessage("102", signupRequest);
            if (!ClientSocket.client.Connected)
            {
                ClientSocket.client.Connect(ClientSocket.serverEndPoint);
            }
            ClientSocket.client.Send(message);
            byte[] response  = new byte[1024];
            int    bytesRead = ClientSocket.client.Receive(response);

            Array.Resize <byte>(ref response, bytesRead);
            if (GlobalHelpers.GetCode(response) == "202")
            {
                var signupResponse = MessagePack.MessagePackSerializer.Deserialize <JSON_Classes.SignupResponse>(GlobalHelpers.GetMsgpack(response));
                switch (signupResponse.Status)
                {
                case 0:
                    this.username = UsernameTextBox.Text;
                    this.Close();
                    DialogResult = DialogResult.OK;
                    break;

                case 1:
                    MessageBox.Show("An Issue Occured With The Database, Can't Sign up!");
                    this.Close();
                    DialogResult = DialogResult.No;
                    break;

                default:
                    MessageBox.Show("Could Not Signup.. Please Check Your Credentials And Try Again!");
                    break;
                }
            }
            else
            {
                this.Close();
                DialogResult = DialogResult.No;
            }
        }
Пример #3
0
        private void JoinButton_Click(object sender, EventArgs e)
        {
            if (RoomListBox.SelectedIndex != -1)
            {
                var request = new JSON_Classes.JoinRoomRequest {
                    Id = rooms[RoomListBox.SelectedIndex].Metadata.id
                };
                byte[] message = GlobalHelpers.CreateMessage("115", request);
                ClientSocket.client.Send(message);
                byte[] response  = new byte[1024];
                int    bytesRead = ClientSocket.client.Receive(response);
                Array.Resize <byte>(ref response, bytesRead);
                if (GlobalHelpers.GetCode(response) == "215")
                {
                    var status = MessagePackSerializer.Deserialize <JSON_Classes.JoinRoomResponse>(GlobalHelpers.GetMsgpack(response));
                    switch (status.Status)
                    {
                    case 0:
                        string[] players = rooms[RoomListBox.SelectedIndex].Players;
                        Array.Resize(ref players, players.Length + 1);
                        players[players.Length - 1] = username;     // Insert new players into list
                        rooms[RoomListBox.SelectedIndex].Players = players;
                        var gameLobby = new LobbyScreenRegular(rooms[RoomListBox.SelectedIndex]);
                        this.Hide();
                        gameLobby.ShowDialog();
                        this.Close();
                        DialogResult = DialogResult.No;
                        break;

                    default:
                        MessageBox.Show("Could Not Join Lobby!");
                        break;
                    }
                }
                else
                {
                    MessageBox.Show("Could Not Join Lobby!");
                }
            }
        }
Пример #4
0
        private void CreateLobbyButton_Click(object sender, EventArgs e)
        {
            var form = new LobbyDetailsForm();

            this.Hide();
            form.ShowDialog();
            var request = new JSON_Classes.CreateRoomRequest {
                Name = form.Name, MaxUsers = form.MaxUsers, QuestionCount = form.QuestionCount, TimePerQuestion = form.TimePerQuestion
            };

            byte[] message = GlobalHelpers.CreateMessage("116", request);
            ClientSocket.client.Send(message);
            byte[] response  = new byte[1024];
            int    bytesRead = ClientSocket.client.Receive(response);

            Array.Resize <byte>(ref response, bytesRead);
            if (GlobalHelpers.GetCode(response) == "216")
            {
                var result   = MessagePack.MessagePackSerializer.Deserialize <JSON_Classes.CreateRoomResponse>(GlobalHelpers.GetMsgpack(response));
                var room     = new JSON_Classes.Room();
                var metadata = new JSON_Classes.RoomData();
                metadata.IsActive      = 0;
                metadata.id            = result.Id;
                metadata.name          = request.Name;
                metadata.MaxPlayers    = request.MaxUsers;
                metadata.QuestionCount = request.QuestionCount;
                metadata.AnswerTimeout = request.TimePerQuestion;
                room.Players           = new[] { username };
                room.Metadata          = metadata;
                var gameLobby = new LobbyScreenAdmin(room);
                this.Hide();
                gameLobby.ShowDialog();
                this.Show();
            }
            else
            {
                MessageBox.Show("Error Creating Lobby!");
                this.Close();
            }
        }