protected void validate() {
    boolean fail = true;
    if (textPortName.getText().trim().equals("")) setErrorMessage("Connection name can't be empty");
    else if (client.getConnectionPool().hasConnection(textPortName.getText().trim()))
      setErrorMessage("Connection name has already been used by other port");
    else if (familyList.getSelection().isEmpty())
      setErrorMessage("Should select at least one family");
    else if (textServerAddress.getText().trim().equals(""))
      setErrorMessage("Server address can't be empty");
    else if (Util.getInt(textServerPort.getText().trim(), 0) == 0)
      setErrorMessage("The server port format is incorrect");
    else if (chkUdp.getSelection() && comboProxyType.getSelectionIndex() == 1)
      setErrorMessage("Can't use Http proxy with UDP mode");
    else if (comboProxyType.getSelectionIndex() != 0
        && textProxyAddress.getText().trim().equals(""))
      setErrorMessage("Proxy address can't be empty");
    else if (comboProxyType.getSelectionIndex() != 0
        && Util.getInt(textProxyPort.getText().trim(), 0) == 0)
      setErrorMessage("The proxy port format is incorrect");
    else {
      setErrorMessage(null);
      fail = false;
    }

    getButton(IDialogConstants.OK_ID).setEnabled(!fail);
  }
Exemple #2
0
 /**
  * @param qq QQ号
  * @param pwd 密码
  */
 public QQUser(int qqNum, String pwd) {
   this.qq = qqNum;
   setPassword(pwd);
   ip = new byte[4];
   serverIp = new byte[4];
   lastLoginIp = new byte[4];
   loggedIn = false;
   loginMode = QQ.QQ_LOGIN_MODE_NORMAL;
   udp = true;
   contactInfo = new ContactInfo();
   showFakeCam = false;
   iniKey = Util.randomKey();
   loginTokenRandomKey = Util.randomKey();
 }
 @Override
 protected void parseBody(ByteBuffer buf) throws PacketParseException {
   if (replyCode == QQ.QQ_REPLY_OK) {
     int count = buf.getInt();
     servers = new ArrayList<String>();
     while (count-- > 0) {
       String server = Util.getString(buf, (byte) 0, 15);
       servers.add(server);
     }
   }
 }
 /* (non-Javadoc)
  * @see edu.tsinghua.lumaqq.qq.packets.OutPacket#putBody(java.nio.ByteBuffer)
  */
 @Override
 protected void putBody(ByteBuffer buf) {
   // 组装内容
   // 目的的QQ号的字符串形式
   buf.put(String.valueOf(to).getBytes());
   // 分隔符
   buf.put(DELIMIT);
   // 响应码
   buf.put(action);
   // 分隔符
   buf.put(DELIMIT);
   // 附带消息
   byte[] msg = Util.getBytes(message);
   buf.put(msg);
 }
Exemple #5
0
 public void setLatestSize(String text) {
   int size = Util.getInt(text, 20);
   options.getOtherOption().setLatestSize(size);
 }
Exemple #6
0
 public void setTcpPort(String text) {
   int port = Util.getInt(text, 80);
   options.getLoginOption().setTcpPort(port);
 }
 /* (non-Javadoc)
  * @see edu.tsinghua.lumaqq.qq.packets.OutPacket#putBody(java.nio.ByteBuffer)
  */
 @Override
 protected void putBody(ByteBuffer buf) {
   // 短消息序号
   buf.putChar(messageSequence);
   // 未知2字节
   buf.putChar((char) 0);
   // 未知4字节
   buf.putInt(0);
   // 发送者昵称
   byte[] b = Util.getBytes(senderName);
   if (b.length > QQ.QQ_MAX_SMS_SENDER_NAME) {
     buf.put(b, 0, QQ.QQ_MAX_SMS_SENDER_NAME);
   } else {
     buf.put(b);
     int stuff = QQ.QQ_MAX_SMS_SENDER_NAME - b.length;
     while (stuff-- > 0) buf.put((byte) 0);
   }
   // 未知1字节
   buf.put((byte) 0x01);
   // 发送模式
   buf.put(sendMode);
   // 内容类型
   buf.put(contentType);
   // 内容编号
   buf.putInt(contentId);
   // 未知1字节
   buf.put((byte) 0x01);
   // 手机个数
   if (receiverMobile == null) buf.put((byte) 0);
   else {
     buf.put((byte) receiverMobile.size());
     for (String mobile : receiverMobile) {
       b = Util.getBytes(mobile);
       if (b.length > QQ.QQ_MAX_SMS_MOBILE_LENGTH) {
         buf.put(b, 0, QQ.QQ_MAX_SMS_MOBILE_LENGTH);
       } else {
         buf.put(b);
         int stuff = QQ.QQ_MAX_SMS_MOBILE_LENGTH - b.length;
         while (stuff-- > 0) buf.put((byte) 0);
       }
       // 未知的2字节
       buf.putChar((char) 0);
       // 未知的1字节
       buf.put((byte) 0);
     }
   }
   // QQ号码个数
   if (receiverQQ == null) buf.put((byte) 0);
   else {
     buf.put((byte) receiverQQ.size());
     for (Integer qq : receiverQQ) buf.putInt(qq);
   }
   // 未知1字节
   buf.put((byte) 0x03);
   // 消息
   if (message == null) buf.putChar((char) 0);
   else {
     buf.putChar((char) message.length);
     // 消息
     buf.put(message);
   }
 }
  @Override
  @SuppressWarnings("unchecked")
  protected void okPressed() {
    String portName = textPortName.getText().trim();
    int supportedFamily = 0;
    for (Iterator<Integer> i = ((IStructuredSelection) familyList.getSelection()).iterator();
        i.hasNext(); ) supportedFamily |= i.next();

    IConnection conn = null;

    IConnectionPolicy policy =
        client
            .getConnectionPolicyFactory()
            .createPolicy(
                client,
                portName,
                supportedFamily,
                (Integer) ((IStructuredSelection) familyList.getSelection()).getFirstElement(),
                null,
                null,
                null);
    try {
      if (chkUdp.getSelection()) {
        switch (comboProxyType.getSelectionIndex()) {
          case 0:
            conn =
                client
                    .getConnectionPool()
                    .newUDPConnection(
                        policy,
                        new InetSocketAddress(
                            textServerAddress.getText().trim(),
                            Util.getInt(textServerPort.getText().trim(), 0)),
                        true);
            break;
          case 2:
            policy.setProxy(
                new InetSocketAddress(
                    textProxyAddress.getText().trim(),
                    Util.getInt(textProxyPort.getText().trim(), 0)));
            policy.setProxyUsername(textUsername.getText().trim());
            policy.setProxyPassword(textPassword.getText());
            conn =
                client
                    .getConnectionPool()
                    .newUDPSocks5Connection(
                        policy,
                        new InetSocketAddress(
                            textServerAddress.getText().trim(),
                            Util.getInt(textServerPort.getText().trim(), 0)),
                        true);
            break;
        }
      } else {
        switch (comboProxyType.getSelectionIndex()) {
          case 0:
            conn =
                client
                    .getConnectionPool()
                    .newTCPConnection(
                        policy,
                        new InetSocketAddress(
                            textServerAddress.getText().trim(),
                            Util.getInt(textServerPort.getText().trim(), 0)),
                        true);
            break;
          case 1:
            policy.setProxy(
                new InetSocketAddress(
                    textProxyAddress.getText().trim(),
                    Util.getInt(textProxyPort.getText().trim(), 0)));
            policy.setProxyUsername(textUsername.getText().trim());
            policy.setProxyPassword(textPassword.getText());
            conn =
                client
                    .getConnectionPool()
                    .newTCPHttpConnection(
                        policy,
                        new InetSocketAddress(
                            textServerAddress.getText().trim(),
                            Util.getInt(textServerPort.getText().trim(), 0)),
                        true);
            break;
          case 2:
            policy.setProxy(
                new InetSocketAddress(
                    textProxyAddress.getText().trim(),
                    Util.getInt(textProxyPort.getText().trim(), 0)));
            policy.setProxyUsername(textUsername.getText().trim());
            policy.setProxyPassword(textPassword.getText());
            conn =
                client
                    .getConnectionPool()
                    .newTCPSocks5Connection(
                        policy,
                        new InetSocketAddress(
                            textServerAddress.getText().trim(),
                            Util.getInt(textServerPort.getText().trim(), 0)),
                        true);
            break;
        }
      }
    } catch (UnresolvedAddressException e) {
      conn = null;
    }

    if (conn == null) MessageDialog.openError(getShell(), "Failed", "Create connection failed");
    else super.okPressed();
  }