示例#1
0
文件: MainFrm.cs 项目: rachid1805/TCP
        private void mniEnter_Click(object sender, EventArgs e)
        {
            if (mniEnter.Text == "Login")
            {
                LoginFrm dlg = new LoginFrm(_serverIpv4, _serverPort, true);
                dlg.ShowDialog();
                _client = dlg.Client;

                if (_client.Connected)
                {
                    _client.CommandReceived += new CommandReceivedEventHandler(client_CommandReceived);
                    _client.SendCommand(new CommandContainer(CommandType.RequestClientList, null));
                    _client.SendCommand(new CommandContainer(CommandType.RequestRoomList, null));
                    Text                        = "Online : " + _client.UserName;
                    mniEnter.Text               = "Log Off";
                    mniCreateRoom.Enabled       = true;
                    mniConnectMyProfile.Enabled = true;
                }
            }
            else
            {
                Text                        = "Offline";
                mniEnter.Text               = "Login";
                mniCreateRoom.Enabled       = false;
                mniConnectMyProfile.Enabled = false;
                _client.SendCommand(new CommandContainer(CommandType.ClientLogOff, new ProfileContainer(_client.UserName, _client.Password)));
                _client.Disconnect();
                _client = null;
                lstViwUsers.Items.Clear();
                ClearRoomItems();
                CloseRooms();
            }
        }
示例#2
0
文件: RoomFrm.cs 项目: rachid1805/TCP
 private void SendMessage()
 {
     if (_client.Connected && txtNewMessage.Text.Trim() != "")
     {
         var newMsg = new MessageContainer(_client.UserName, new RoomContainer(_roomName), txtNewMessage.Text, _msgId++);
         _client.SendCommand(new CommandContainer(CommandType.Message, newMsg));
         AddMessage(newMsg);
         txtNewMessage.Text = "";
         txtNewMessage.Focus();
     }
 }
示例#3
0
文件: MainFrm.cs 项目: rachid1805/TCP
        private void mniSignup_Click(object sender, EventArgs e)
        {
            LoginFrm dlg = new LoginFrm(_serverIpv4, _serverPort, false);

            dlg.ShowDialog();
            if (_client != null)
            {
                if (_client.Connected)
                {
                    frmPopup popup = new frmPopup(PopupSkins.SmallInfoSkin);
                    popup.ShowPopup("Warning", string.Format("Disconnected user {0} !", _client.UserName), 300, 2000, 2000);
                    _client.SendCommand(new CommandContainer(CommandType.ClientLogOff, new ProfileContainer(_client.UserName, _client.Password)));
                }
                Text = "Offline";
                _client.Disconnect();
                lstViwUsers.Items.Clear();
                ClearRoomItems();
                CloseRooms();
            }
            _client = dlg.Client;

            if (_client.Connected)
            {
                _client.CommandReceived += new CommandReceivedEventHandler(client_CommandReceived);
                _client.SendCommand(new CommandContainer(CommandType.RequestClientList, null));
                _client.SendCommand(new CommandContainer(CommandType.RequestRoomList, null));
                Text                        = "Online : " + _client.UserName;
                mniEnter.Text               = "Log Off";
                mniCreateRoom.Enabled       = true;
                mniConnectMyProfile.Enabled = true;
            }
            else
            {
                _client = null;
            }
        }
示例#4
0
 private void SendRoomInfoToServer()
 {
     if (txtRoomName.Text.Trim() == "")
     {
         frmPopup popup = new frmPopup(PopupSkins.SmallInfoSkin);
         popup.ShowPopup("Error", "Room name is empty !", 1000, 2000, 2000);
         SetEnablity(true);
     }
     else if (txtRoomDescription.Text.Trim() == "")
     {
         frmPopup popup = new frmPopup(PopupSkins.SmallInfoSkin);
         popup.ShowPopup("Error", "Room description is empty !", 1000, 2000, 2000);
         SetEnablity(true);
     }
     else
     {
         _roomName        = txtRoomName.Text.Trim();
         _roomDescription = txtRoomDescription.Text.Trim();
         var cmd = new CommandContainer(CommandType.CreateRoom, new RoomContainer(_roomName, _roomDescription));
         _client.SendCommand(cmd);
     }
 }