コード例 #1
0
  public void writeData(OutputStream out) throws IOException {
    BinaryTools.writeUShort(out, family);

    if (roomInfo != null) {
      ByteBlock roomInfoBlock = ByteBlock.createByteBlock(roomInfo);
      new Tlv(TYPE_ROOM_INFO, roomInfoBlock).write(out);
    }
  }
コード例 #2
0
ファイル: ItemsCmd.java プロジェクト: RockManJoe64/joscar
  /**
   * Generates a new item-based command from the given incoming SNAC packet.
   *
   * @param command the SNAC command subtype for this command
   * @param packet an incoming item-based command packet
   */
  protected ItemsCmd(int command, SnacPacket packet) {
    super(command);

    DefensiveTools.checkNull(packet, "packet");

    ByteBlock block = packet.getData();

    List<SsiItem> itemList = new ArrayList<SsiItem>();

    for (; ; ) {
      SsiItem item = SsiItem.readSsiItem(block);
      if (item == null) break;

      itemList.add(item);

      block = block.subBlock(item.getTotalSize());
    }

    items = DefensiveTools.getUnmodifiable(itemList);
  }
コード例 #3
0
  /**
   * Generates a new service request command from the given incoming SNAC packet.
   *
   * @param packet the incoming service request packet
   */
  protected ServiceRequest(SnacPacket packet) {
    super(CMD_SERVICE_REQ);

    DefensiveTools.checkNull(packet, "packet");

    ByteBlock snacData = packet.getData();

    family = BinaryTools.getUShort(snacData, 0);

    ByteBlock tlvBlock = snacData.subBlock(2);

    TlvChain chatChain = TlvTools.readChain(tlvBlock);

    Tlv chatInfoTlv = chatChain.getLastTlv(TYPE_ROOM_INFO);

    if (chatInfoTlv != null) {
      ByteBlock chatBlock = chatInfoTlv.getData();

      roomInfo = MiniRoomInfo.readMiniRoomInfo(chatBlock);
    } else {
      roomInfo = null;
    }
  }
コード例 #4
0
ファイル: BOSConnection.java プロジェクト: nihed/magnetism
  protected void handleSnacResponse(SnacResponseEvent e) {
    super.handleSnacResponse(e);

    Log.debug("OSCAR bos snac response received: " + e);

    SnacCommand cmd = e.getSnacCommand();

    if (cmd instanceof LocRightsCmd) {
      request(new SetInfoCmd(new InfoData("oscargateway", null, MY_CAPS, null)));
      request(new MyInfoRequest());
    } else if (cmd instanceof ParamInfoCmd) {
      ParamInfoCmd pic = (ParamInfoCmd) cmd;

      ParamInfo info = pic.getParamInfo();

      request(
          new SetParamInfoCmd(
              new ParamInfo(
                  0,
                  info.getFlags() | ParamInfo.FLAG_TYPING_NOTIFICATION,
                  8000,
                  info.getMaxSenderWarning(),
                  info.getMaxReceiverWarning(),
                  0)));
    } else if (cmd instanceof ServiceRedirect) {
      ServiceRedirect sr = (ServiceRedirect) cmd;

      oscarSession.connectToService(sr.getSnacFamily(), sr.getRedirectHost(), sr.getCookie());

    } else if (cmd instanceof SsiDataCmd) {
      SsiDataCmd sdc = (SsiDataCmd) cmd;

      List<SsiItem> items = sdc.getItems();
      for (SsiItem item : items) {
        SsiItemObj obj = itemFactory.getItemObj(item);
        if (obj instanceof BuddyItem) {
          Log.debug("AIM got buddy item " + obj);
          oscarSession.gotBuddy((BuddyItem) obj);
        } else if (obj instanceof GroupItem) {
          Log.debug("AIM got group item " + obj);
          oscarSession.gotGroup((GroupItem) obj);
        }
      }

      if (sdc.getLastModDate() != 0) {
        request(new ActivateSsiCmd());
        clientReady();

        Presence p = new Presence();
        p.setTo(oscarSession.getJID());
        p.setFrom(oscarSession.getTransport().getJID());
        oscarSession.getTransport().sendPacket(p);

        oscarSession.setLoginStatus(TransportLoginStatus.LOGGED_IN);
        oscarSession.gotCompleteSSI();
      }
    } else if (cmd instanceof OfflineMsgIcqCmd) {
      OfflineMsgIcqCmd omic = (OfflineMsgIcqCmd) cmd;

      String sn = String.valueOf(omic.getFromUIN());
      // String msg = "Offline message sent at "+new
      // Date(omic.getDate().getTime()).toString()+"\n"+OscarTools.stripHtml(omic.getContents()).trim();
      String msg =
          "Offline message received:\n"
              + StringUtils.unescapeFromXML(OscarTools.stripHtml(omic.getContents()).trim());
      EncodedStringInfo encmsg = MinimalEncoder.encodeMinimally(msg);
      InstantMessage imsg =
          new InstantMessage(
              encmsg.getImEncoding().getCharsetCode(), ByteBlock.wrap(encmsg.getData()));

      oscarSession
          .getTransport()
          .sendMessage(
              oscarSession.getJIDWithHighestPriority(),
              oscarSession.getTransport().convertIDToJID(sn),
              imsg.getMessage());
    } else if (cmd instanceof OfflineMsgDoneCmd) {
      request(new OfflineMsgIcqAckCmd(oscarSession.getUIN(), (int) oscarSession.nextIcqId()));
    } else if (cmd instanceof MetaShortInfoCmd) {
      //            MetaShortInfoCmd msic = (MetaShortInfoCmd)cmd;
      //            Log.debug("RECEIVED META SHORT INFO: "+msic);
      //            oscarSession.updateRosterNickname(String.valueOf(msic.getUIN()),
      // msic.getNickname());
    } else if (cmd instanceof BuddyAddedYouCmd) {
      BuddyAddedYouCmd bay = (BuddyAddedYouCmd) cmd;

      Presence p = new Presence();
      p.setType(Presence.Type.subscribe);
      p.setTo(oscarSession.getJID());
      p.setFrom(oscarSession.getTransport().convertIDToJID(bay.getUin()));
      oscarSession.getTransport().sendPacket(p);
    } else if (cmd instanceof BuddyAuthRequest) {
      BuddyAuthRequest bar = (BuddyAuthRequest) cmd;

      Presence p = new Presence();
      p.setType(Presence.Type.subscribe);
      p.setTo(oscarSession.getJID());
      p.setFrom(oscarSession.getTransport().convertIDToJID(bar.getScreenname()));
      oscarSession.getTransport().sendPacket(p);
    } else if (cmd instanceof AuthReplyCmd) {
      AuthReplyCmd ar = (AuthReplyCmd) cmd;

      if (ar.isAccepted()) {
        Presence p = new Presence();
        p.setType(Presence.Type.subscribed);
        p.setTo(oscarSession.getJID());
        p.setFrom(oscarSession.getTransport().convertIDToJID(ar.getSender()));
        oscarSession.getTransport().sendPacket(p);
      } else {
        Presence p = new Presence();
        p.setType(Presence.Type.unsubscribed);
        p.setTo(oscarSession.getJID());
        p.setFrom(oscarSession.getTransport().convertIDToJID(ar.getSender()));
        oscarSession.getTransport().sendPacket(p);
      }
    } else if (cmd instanceof AuthFutureCmd) {
      AuthFutureCmd af = (AuthFutureCmd) cmd;

      Presence p = new Presence();
      p.setType(Presence.Type.subscribe);
      p.setTo(oscarSession.getJID());
      p.setFrom(oscarSession.getTransport().convertIDToJID(af.getUin()));
      oscarSession.getTransport().sendPacket(p);
    }
  }