Exemple #1
0
 public AuthenticationHandler(User user)
 {
     this.user = user;
     webSocket = new WebSocket("ws://" + ClientBase.serverAdress + PORT_ROUTE);
     webSocket.Opened += new EventHandler(authenticate);
     //webSocket.Closed += new EventHandler(websocket_Closed);
     webSocket.MessageReceived += new EventHandler<MessageReceivedEventArgs>(receiveThisUserObject);
     webSocket.Open();
 }
Exemple #2
0
        private void connectButton_Click(object sender, EventArgs e)
        {
            String serverAdress = serverTextBox.Text;
            String userName = userNameTextBox.Text;
            ludo.ServerAdress = serverAdress;
            User user = new User();
            user.UserName = userName;
            ludo.Users.Add(user);
            authenticationHandler = new AuthenticationHandler(ludo);

            rootConnectTableLayout.Hide();
            rootServerTableLayout.Show();
        }
Exemple #3
0
 private void receiveThisUserObject(object sender, MessageReceivedEventArgs args)
 {
     var jsonString = JsonConvert.DeserializeObject<User>(args.Message);
     int userListIndex = jsonString.UserListIndex;
     this.user = JsonConvert.DeserializeObject<User>(args.Message); // receiving my user object
     Main.ludo.Users[0] = this.user;
     if (isUserNameAvailable())
     {
         ClientBase.myUserListIndex = userListIndex;
     }
     else
     {
         MessageBox.Show("Username is already used");
     }
 }
Exemple #4
0
        private void connectButton_Click(object sender, EventArgs e)
        {
            connectButton.Enabled = false;

            Main main = new Main(); // Run Construtor of Main to initialize Main Ludo Object
            String serverAdress = serverTextBox.Text;
            String userName = userNameTextBox.Text;
            ClientBase.serverAdress = serverAdress;

            user = new User();
            user.UserName = userName;
            Main.ludo.Users.Add(user);

            authenticationHandler = new AuthenticationHandler(user);

            if (authenticationSuceed())
            {
                //Main.ludo.Users[ClientBase.myUserListIndex].CurrentView = "server";
                onlineUserHandler = new OnlineUserHandler(this.onlineUserList);
                chatHandler = new ChatHandler(this.messageList, this.roomMessageList);
                roomHandler = new RoomHandler(this.roomList, this.userInLobbyListBox, this.readyButton, this.startButton, this.backButton,
                    this.roomMessageList, this.gameTableLayout, this.gameFieldPanel, this.dicePictureBox, this.rollTheDiceButton, this.playerListBox);

                ClientBase.isConnected = true;

                rootConnectTableLayout.Hide();
                rootServerTableLayout.Show();
                messageTextBox.Focus();
                this.UseWaitCursor = false;
            }
            else
            {
                ClientBase.myUserListIndex = -1;
                Main.ludo.Users.Clear();
                connectButton.Enabled = true;
            }
        }