Beispiel #1
0
        private void BtnCancel_Click(object sender, EventArgs e)
        {
            LoggedInScreen f = new LoggedInScreen(this.context);

            this.Hide();
            f.ShowDialog();
            this.Close();
        }
Beispiel #2
0
        private void BtnLogIn_Click(object sender, EventArgs e)
        {
            try
            {
                string username = txtLogUsername.Text;
                string password = txtPassLog.Text;

                var factory = new ConnectionFactory()
                {
                    HostName = "localhost"
                };
                using (var connection = factory.CreateConnection())
                    using (var channel = connection.CreateModel())
                    {
                        channel.ExchangeDeclare(exchange: "loginResponse", type: "direct");

                        var queueName = channel.QueueDeclare().QueueName;
                        channel.QueueBind(queue: queueName,
                                          exchange: "loginResponse",
                                          routingKey: queueName);

                        Console.WriteLine(" [*] Waiting for logs.");

                        var  consumer = new EventingBasicConsumer(channel);
                        bool primio   = false;
                        var  messageR = "";
                        consumer.Received += (model, ea) =>
                        {
                            messageR = Encoding.UTF8.GetString(ea.Body);
                            primio   = true;
                        };

                        channel.BasicConsume(queue: queueName,
                                             autoAck: true,
                                             consumer: consumer);
                        var message = "username:"******": password:"******": routingKey:" + queueName;
                        var body    = Encoding.UTF8.GetBytes(message);
                        channel.BasicPublish(exchange: "loginCall",
                                             routingKey: "login",
                                             basicProperties: null,
                                             body: body);
                        while (!primio)
                        {
                            ;
                        }
                        if (messageR.Length < 30)
                        {
                            MessageBox.Show(messageR);
                        }
                        else
                        {
                            var s1 = JsonConvert.DeserializeObject <ViewClass>(messageR);
                            this.Hide();
                            LoggedInScreen f = new LoggedInScreen(s1);
                            f.ShowDialog();
                            this.Close();
                        }
                    };
            }
            catch (Exception ec)
            {
                MessageBox.Show(ec.Message);
            }
        }
Beispiel #3
0
        private void BtnExit_Click(object sender, EventArgs e)
        {
            if (!gameLogic.IsMyTurn() || this.finish == true)
            {
                string name = lblGameName.Text;

                var factory = new ConnectionFactory()
                {
                    HostName = "localhost"
                };
                using (var connection = factory.CreateConnection())
                    using (var channel = connection.CreateModel())
                    {
                        channel.ExchangeDeclare(exchange: "exitGameResponse", type: "direct");

                        var queueName = channel.QueueDeclare().QueueName;

                        channel.QueueBind(queue: queueName,
                                          exchange: "exitGameResponse",
                                          routingKey: queueName);

                        Console.WriteLine(" [*] Waiting for logs.");

                        var  consumer = new EventingBasicConsumer(channel);
                        bool primio   = false;
                        var  messageR = "";
                        consumer.Received += (model, ea) =>
                        {
                            var body1    = ea.Body;
                            var message1 = Encoding.UTF8.GetString(body1);
                            messageR = message1;
                            primio   = true;
                        };

                        channel.BasicConsume(queue: queueName,
                                             autoAck: true,
                                             consumer: consumer);

                        var message = "gamename:" + name + ":username:"******": routingKey:" + queueName;
                        var body    = Encoding.UTF8.GetBytes(message);
                        channel.BasicPublish(exchange: "exitGameCall",
                                             routingKey: "exitGame",
                                             basicProperties: null,
                                             body: body);


                        GameStartListening();

                        while (!primio)
                        {
                            ;
                        }

                        gameStarted = false;
                        isListening = false;
                        activeForm  = false;

                        this.context = JsonConvert.DeserializeObject <ViewClass>(messageR);
                        this.Hide();
                        activeForm = false;
                        LoggedInScreen l = new LoggedInScreen(this.context);
                        l.ShowDialog();
                        isListening = false;
                        this.Close();
                    };
            }
        }