⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 setpermsuserinforequest.java

📁 一个类似QQ的在线通讯聊天软件原码,适合初学者参考学习。
💻 JAVA
字号:
package openicq.net;

import JOscarLib.*;
import JOscarLib.Core.OscarConnection;
import JOscarLib.Request.Event.RequestAnswerEvent;
import JOscarLib.Request.Event.RequestListener;

/**
 * The <code>SetPermsUserInfoRequest</code> class updates your own permission
 * info on the ICQ server.
 * @author Hansgeorg Schwibbe
 * @copyright 2004
 */
public abstract class SetPermsUserInfoRequest implements RequestListener
{
  /**
   * Initializes a new instance of the class
   * <code>SetPermsUserInfoRequest</code>.
   * @param connection the connection to the ICQ server
   * @param ownID your own user ID
   * @param authorization the authorization flag (0 = authorization is required,
   *        1 = authorization is not required)
   * @param webaware the webaware flag (0 = yes, 1 = no)
   * @param dc_perms the permissions flag (0 = all, 1 = contact, 2 =
   *        authorization)
   */
  public SetPermsUserInfoRequest(OscarConnection connection, int ownID,
                                 int authorization, int webaware, int dc_perms)
  {
    RawData reqSubType = new RawData(0x2404, RawData.WORD_LENGHT);
    RawData reqSeqNum = new RawData(0x0200, RawData.WORD_LENGHT);
    RawData reqDataType = new RawData(0xD007, RawData.WORD_LENGHT);
    RawData reqOwnerID = new RawData(ownID, RawData.DWORD_LENGHT);
    reqOwnerID.invertIndianness();
    int chunkSize = reqOwnerID.getForcedLenght()
                    + reqDataType.getForcedLenght()
                    + reqSeqNum.getForcedLenght()
                    + reqSubType.getForcedLenght() + 4;
    RawData reqChunkSize = new RawData(chunkSize, RawData.WORD_LENGHT);
    reqChunkSize.invertIndianness();
    // TLV
    Tlv requestTlv = new Tlv(reqChunkSize, 0x01);
    requestTlv.appendRawDataToTlv(reqOwnerID);
    requestTlv.appendRawDataToTlv(reqDataType);
    requestTlv.appendRawDataToTlv(reqSeqNum);
    requestTlv.appendRawDataToTlv(reqSubType);
    requestTlv.appendRawDataToTlv(new RawData(authorization,
                                              RawData.BYTE_LENGHT));
    requestTlv.appendRawDataToTlv(new RawData(webaware, RawData.BYTE_LENGHT));
    requestTlv.appendRawDataToTlv(new RawData(dc_perms, RawData.BYTE_LENGHT));
    requestTlv.appendRawDataToTlv(new RawData(0x00, RawData.BYTE_LENGHT));
    // Snac
    Snac requestSnac = new Snac(0x15, 0x02, 0x00, 0x00, ownID);
    requestSnac.addTlvToSnac(requestTlv);
    // Flap
    Flap requestFlap = new Flap(0x02, requestSnac);
    connection.sendMonitoredFlap(requestFlap, this);
  }

  /**
   * Prototype for processing the success byte.
   * @param success the success byte
   */
  public abstract void onResponse(int success);

  /**
   * Sets the success byte and runs the <code>onResponse()</code> method.
   * @param e answer event
   */
  public void onRequestAnswer(RequestAnswerEvent e)
  {
    Flap flap = e.getRequestAnswerPacket();
    int success;
    if (flap.getChannelId() != 0x02)
    {
      success = -1;
    }
    else if (flap.getSnac().getFamilyId() != 0x15
             || flap.getSnac().getSubTypeId() != 0x03)
    {
      success = -1;
    }
    else
    {
      success = flap.getSnac().getDataFieldByteArray()[16];
    }
    this.onResponse(success);
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -