public static void join(String name, String pass, int maxStanzas) {
    StaticData sd = StaticData.getInstance();

    ConferenceGroup grp = sd.roster.initMuc(name, pass);
    // требуется для возможности нормального выхода
    // sd.roster.mucContact(name, Contact.ORIGIN_GC_MYSELF);
    // sd.roster.activeRooms.addElement(jid);

    JabberDataBlock x = new JabberDataBlock("x", null, null);
    x.setNameSpace("http://jabber.org/protocol/muc");
    if (pass.length() != 0) {
      // adding password to presence
      x.addChild("password", pass);
    }

    JabberDataBlock history = x.addChild("history", null);
    history.setAttribute("maxstanzas", String.valueOf(maxStanzas));
    history.setAttribute("maxchars", "32768");
    try {
      long last = grp.getConference().lastMessageTime;
      long delay = (grp.conferenceJoinTime - last) / 1000;
      if (last != 0)
        history.setAttribute("seconds", String.valueOf(delay)); // todo: change to since
    } catch (Exception e) {
    }
    ;

    // sd.roster.groups.getGroup(name.substring(0,
    // name.indexOf('@'))).imageExpandedIndex=ImageList.ICON_GCJOIN_INDEX;
    sd.roster.sendPresence(name, null, x);
    sd.roster.reEnumRoster();
  }
 void eventNotify() {
   int event = -1;
   synchronized (taskList) {
     for (Enumeration e = taskList.elements(); e.hasMoreElements(); ) {
       TransferTask t = (TransferTask) e.nextElement();
       if (t.showEvent) event = t.getImageIndex();
     }
   }
   Integer icon = (event < 0) ? null : new Integer(event);
   StaticData.getInstance().roster.setEventIcon(icon);
 }
  // send shortcut
  void send(JabberDataBlock data, boolean async) {
    // StaticData.getInstance().roster.theStream.send(data);
    try {
      StringBuffer sb = new StringBuffer();
      data.constructXML(sb);
      StaticData.getInstance().roster.theStream.sendBuf(sb);

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  private void switchType() {
    int index = choiseType.getSelectedIndex();
    try {
      Object rfocus = StaticData.getInstance().roster.getFocusedObject();
      switch (index) {
        case 0: // jid
          if (targetList != null)
            if (rfocus instanceof Contact) {
              textValue.setString(((Contact) rfocus).getBareJid());
            }
          form.set(2, textValue);
          break;
        case 1: // group
          if (targetList != null)
            textValue.setString(
                ((rfocus instanceof Group) ? (Group) rfocus : ((Contact) rfocus).getGroup())
                    .getName());

          form.set(2, textValue);
          break;
        case 2: // subscription
          form.set(2, choiceSubscr);
          break;

        case 3:
          form.set(2, new StringItem(null, "(ANY)"));
      }
      /*if (index==2) {
          form.set(2, choiceSubscr);
      } else {
          textValue.setLabel(PrivacyItem.types[index]);
          form.set(2, textValue);
      }
       */
    } catch (Exception e) {
      /* При смене на самого себя */
    }
  }
  public int blockArrived(JabberDataBlock data) {
    if (data instanceof Iq) {
      String id = data.getAttribute("id");

      JabberDataBlock si = data.getChildBlock("si");
      if (si != null) {
        // stream initiating
        String sid = si.getAttribute("id");

        JabberDataBlock file = si.getChildBlock("file");
        JabberDataBlock feature = si.getChildBlock("feature");

        String type = data.getTypeAttribute();
        if (type.equals("set")) {
          // sender initiates file sending process
          TransferTask task =
              new TransferTask(
                  data.getAttribute("from"),
                  id,
                  sid,
                  file.getAttribute("name"),
                  file.getChildBlockText("desc"),
                  Integer.parseInt(file.getAttribute("size")),
                  null);

          synchronized (taskList) {
            taskList.addElement(task);
          }

          eventNotify();
          StaticData.getInstance().roster.playNotify(0);
          return BLOCK_PROCESSED;
        }
        if (type.equals("result")) {
          // our file were accepted
          TransferTask task = getTransferBySid(id);
          task.initIBB();

          eventNotify();
          return BLOCK_PROCESSED;
        }
      }
      JabberDataBlock open = data.getChildBlock("open");
      if (open != null) {
        String sid = open.getAttribute("sid");
        TransferTask task = getTransferBySid(sid);

        JabberDataBlock accept = new Iq(task.jid, Iq.TYPE_RESULT, id);
        send(accept, true);
        eventNotify();
        return BLOCK_PROCESSED;
      }
      JabberDataBlock close = data.getChildBlock("close");
      if (close != null) {
        String sid = close.getAttribute("sid");
        TransferTask task = getTransferBySid(sid);

        JabberDataBlock done = new Iq(task.jid, Iq.TYPE_RESULT, id);
        send(done, true);
        task.closeFile();
        eventNotify();
        return BLOCK_PROCESSED;
      }
      if (data.getTypeAttribute().equals("result")) {
        TransferTask task = getTransferBySid(id);
        if (task != null) {
          task.startTransfer();
        }
      }
      if (data.getTypeAttribute().equals("error")) {
        TransferTask task = getTransferBySid(id);
        if (task != null) {
          task.cancel();
        }
      }
    }
    if (data instanceof Message) {
      JabberDataBlock bdata = data.getChildBlock("data");
      if (bdata == null) return BLOCK_REJECTED;
      if (!bdata.isJabberNameSpace("http://jabber.org/protocol/ibb")) return BLOCK_REJECTED;
      String sid = bdata.getAttribute("sid");
      TransferTask task = getTransferBySid(sid);

      byte b[] = strconv.fromBase64(bdata.getText());
      System.out.println("data chunk received");
      repaintNotify();
      task.writeFile(b);
    }
    return BLOCK_REJECTED;
  }
 void repaintNotify() {
   StaticData.getInstance().roster.redraw();
 }
/** @author EvgS */
public class ConferenceForm implements CommandListener {

  private Display display;
  private Displayable parentView;

  Command cmdJoin = new Command(SR.MS_JOIN, Command.SCREEN, 1);
  // Command cmdBookmarks=new Command(SR.MS_BOOKMARKS, Command.SCREEN, 2);
  Command cmdAdd = new Command(SR.MS_ADD_BOOKMARK, Command.SCREEN, 5);
  Command cmdCancel = new Command(SR.MS_CANCEL, Command.BACK, 99);

  TextField roomField;
  TextField hostField;
  TextField nickField;
  TextField passField;
  NumberField msgLimitField;

  StaticData sd = StaticData.getInstance();
  /** Creates a new instance of GroupChatForm */
  public ConferenceForm(Display display) {
    String room = Config.getInstance().defGcRoom;
    String server = null;
    // trying to split string like room@server
    int roomE = room.indexOf('@');
    if (roomE > 0) {
      server = room.substring(roomE + 1);
      room = room.substring(0, roomE);
    }
    // default server
    if (server == null) server = "conference." + sd.account.getServer();
    createForm(display, room, server, null, null);
  }
  /** Creates a new instance of GroupChatForm */

  /** Creates a new instance of GroupChatForm */
  public ConferenceForm(Display display, String confJid, String password) {
    int roomEnd = confJid.indexOf('@');
    String room = "";
    if (roomEnd > 0) room = confJid.substring(0, roomEnd);
    String server;
    String nick = null;
    int serverEnd = confJid.indexOf('/');
    if (serverEnd > 0) {
      server = confJid.substring(roomEnd + 1, serverEnd);
      nick = confJid.substring(serverEnd + 1);
    } else {
      server = confJid.substring(roomEnd + 1);
    }
    createForm(display, room, server, nick, password);
  }

  public ConferenceForm(Display display, String room, String server, String nick, String password) {
    createForm(display, room, server, nick, password);
  }

  private void createForm(
      final Display display, String room, String server, String nick, final String password) {
    this.display = display;
    parentView = display.getCurrent();

    Form formJoin = new Form(SR.MS_JOIN_CONFERENCE);

    roomField = new TextField(SR.MS_ROOM, room, 64, ConstMIDP.TEXTFIELD_URL);
    TextFieldCombo.setLowerCaseLatin(roomField);
    formJoin.append(roomField);

    hostField = new TextField(SR.MS_AT_HOST, server, 64, ConstMIDP.TEXTFIELD_URL);
    TextFieldCombo.setLowerCaseLatin(hostField);
    formJoin.append(hostField);

    if (nick == null) nick = sd.account.getNickName();
    nickField = new TextFieldCombo(SR.MS_NICKNAME, nick, 32, TextField.ANY, "roomnick", display);
    formJoin.append(nickField);

    passField =
        new TextField(SR.MS_PASSWORD, password, 32, TextField.ANY | ConstMIDP.TEXTFIELD_SENSITIVE);
    formJoin.append(passField);

    msgLimitField = new NumberField(SR.MS_MSG_LIMIT, 20, 0, 20);
    formJoin.append(msgLimitField);

    formJoin.addCommand(cmdJoin);
    // formJoin.addCommand(cmdBookmarks);
    formJoin.addCommand(cmdAdd);

    formJoin.addCommand(cmdCancel);
    formJoin.setCommandListener(this);
    display.setCurrent(formJoin);
  }

  public void commandAction(Command c, Displayable d) {
    if (c == cmdCancel) {
      destroyView();
    }
    // if (c==cmdBookmarks) { new Bookmarks(display, null); }
    if (c == cmdJoin || c == cmdAdd) {
      String nick = nickField.getString().trim();
      String host = hostField.getString().trim();
      String room = roomField.getString().trim();
      String pass = passField.getString();
      int msgLimit = msgLimitField.getValue();

      if (nick.length() == 0) return;
      if (room.length() == 0) return;
      if (host.length() == 0) return;
      StringBuffer gchat = new StringBuffer(room.trim());
      gchat.append('@');
      gchat.append(host.trim());
      // sd.roster.mucContact(gchat.toString(), Contact.ORIGIN_GROUPCHAT);
      if (c == cmdAdd) new Bookmarks(display, new BookmarkItem(gchat.toString(), nick, pass));
      else {
        try {
          gchat.append('/');
          gchat.append(nick);
          join(gchat.toString(), pass, msgLimit);

          display.setCurrent(sd.roster);
        } catch (Exception e) {
          e.printStackTrace();
          // display.setCurrent(new Alert("Exception", e.toString(), null, AlertType.ERROR),
          // sd.roster);
        }
      }
    }
  }

  public static void join(String name, String pass, int maxStanzas) {
    StaticData sd = StaticData.getInstance();

    ConferenceGroup grp = sd.roster.initMuc(name, pass);
    // требуется для возможности нормального выхода
    // sd.roster.mucContact(name, Contact.ORIGIN_GC_MYSELF);
    // sd.roster.activeRooms.addElement(jid);

    JabberDataBlock x = new JabberDataBlock("x", null, null);
    x.setNameSpace("http://jabber.org/protocol/muc");
    if (pass.length() != 0) {
      // adding password to presence
      x.addChild("password", pass);
    }

    JabberDataBlock history = x.addChild("history", null);
    history.setAttribute("maxstanzas", String.valueOf(maxStanzas));
    history.setAttribute("maxchars", "32768");
    try {
      long last = grp.getConference().lastMessageTime;
      long delay = (grp.conferenceJoinTime - last) / 1000;
      if (last != 0)
        history.setAttribute("seconds", String.valueOf(delay)); // todo: change to since
    } catch (Exception e) {
    }
    ;

    // sd.roster.groups.getGroup(name.substring(0,
    // name.indexOf('@'))).imageExpandedIndex=ImageList.ICON_GCJOIN_INDEX;
    sd.roster.sendPresence(name, null, x);
    sd.roster.reEnumRoster();
  }

  public void destroyView() {
    if (parentView != null) display.setCurrent(parentView);
  }
}
Пример #8
0
  private void setMucMod() {
    JabberDataBlock iq = new Iq(victim.jid.getBareJid(), Iq.TYPE_SET, "itemmuc");
    JabberDataBlock query = iq.addChildNs("query", "http://jabber.org/protocol/muc#admin");
    // TODO: separate usecases to muc#owner, muc#admin and muc#moderator
    JabberDataBlock item = new JabberDataBlock("item", null, null);
    query.addChild(item);

    try {
      String rzn = reason.getValue();
      String Nick = "";
      if (rzn.charAt(0) == '!') {
        rzn = rzn.substring(1);
      } else {
        Nick = (myNick == null) ? myNick : myNick + ": ";
      }
      if (rzn.length() != 0 && myNick != null) {
        item.addChild("reason", Nick + rzn);
      } else {
        item.addChild("reason", Nick);
      }
    } catch (Exception e) {
    }

    switch (action) {
      case KICK:
        item.setAttribute("role", "none");
        item.setAttribute("nick", victim.getNick());
        break;

      case OUTCAST:
        item.setAttribute("affiliation", "outcast");
        item.setAttribute("jid", victim.realJid);
        break;

      case PARTICIPANT:
        item.setAttribute("role", "participant");
        item.setAttribute("nick", victim.getNick());
        break;

      case VISITOR:
        item.setAttribute("role", "visitor");
        item.setAttribute("nick", victim.getNick());
        break;

      case MODERATOR:
        item.setAttribute("role", "moderator");
        item.setAttribute("nick", victim.getNick());
        break;

      case MEMBER:
        item.setAttribute("affiliation", "member");
        item.setAttribute("jid", victim.realJid);
        break;

      case NONE:
        item.setAttribute("affiliation", "none");
        item.setAttribute("jid", victim.realJid);
        break;

      case ADMIN:
        item.setAttribute("affiliation", "admin");
        item.setAttribute("jid", victim.realJid);
        break;

      case OWNER:
        item.setAttribute("affiliation", "owner");
        item.setAttribute("jid", victim.realJid);
    }

    StaticData.getInstance().roster.theStream.send(iq);
  }
Пример #9
0
 public static void request(String jid, String id) {
   StaticData.getInstance().roster.setQuerySign(true);
   StaticData.getInstance().roster.theStream.send(getQueryVCard(jid, "getvc" + id));
 }