Ejemplo n.º 1
0
  public void close() throws XMPPException {
    for (Object name : Controller.getSettings().ADMIN_LIST.keySet().toArray()) {
      chat(name.toString())
          .sendMessage(Controller.getName() + " remote console is now closing down.");
    }

    for (Object name : Controller.getSettings().USER_LIST.keySet().toArray()) {
      chat(name.toString()).sendMessage(Controller.getName() + " remote chat is now closing down.");
    }

    connection.disconnect();
  }
Ejemplo n.º 2
0
  public void sendToAdmins(String message) {

    for (Object s : Controller.getSettings().ADMIN_LIST.keySet().toArray()) {
      try {
        chat(s.toString()).sendMessage("[Admin Priority Message] " + message);
      } catch (XMPPException ex) {
        Logger.getLogger(XMPPManager.class.getName()).log(Level.SEVERE, null, ex);
      }
    }
  }
Ejemplo n.º 3
0
  public void connect() {

    try {
      ConnectionConfiguration xmppConfig =
          new ConnectionConfiguration("talk.google.com", 5222, "gmail.com");
      connection = new XMPPConnection(xmppConfig);

      connection.connect();

      SASLAuthentication.supportSASLMechanism("PLAIN", 0);
      // Get data
      String user = Controller.getSettings().USERNAME;
      String password = Controller.getSettings().PASSWORD;
      connection.login(user, password);
      chatManager = connection.getChatManager();
      for (Object name : Controller.getSettings().ADMIN_LIST.keySet().toArray()) {

        createAndAddToChat(name.toString());
        chat(name.toString())
            .sendMessage(
                Controller.getName()
                    + " has activated on server : "
                    + Controller.getPluginInstance().getServer().getServerName());
      }

      for (Object name : Controller.getSettings().USER_LIST.keySet().toArray()) {
        createAndAddToChat(name.toString());
        chat(name.toString())
            .sendMessage(
                Controller.getName()
                    + " has activated on server : "
                    + Controller.getPluginInstance().getServer().getServerName());
      }
      chatManager.addChatListener(
          new ChatManagerListener() {

            public void chatCreated(Chat chat, boolean createdLocally) {
              if (!createdLocally && !chatExactlyExists(chat)) {
                if (Controller.getSettings().OPEN_CHANNEL) {
                  try {
                    chat.sendMessage("You have now been added to this server's chat room.");
                  } catch (XMPPException ex) {
                    Logger.getLogger(XMPPManager.class.getName()).log(Level.SEVERE, null, ex);
                  }
                  createAndAddToChat(chat);

                } else {

                  if (Controller.getSettings().isUser(correctAdress(chat.getParticipant()))) {
                    try {
                      chat.sendMessage("You have now been added to this server's chat room.");
                    } catch (XMPPException ex) {
                      Logger.getLogger(XMPPManager.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    createAndAddToChat(chat);

                  } else {
                    try {
                      chat.sendMessage(
                          "You do not have permission to join this server's chat. Please contact an admin.");
                    } catch (XMPPException ex) {
                      Logger.getLogger(XMPPManager.class.getName()).log(Level.SEVERE, null, ex);
                    }
                  }
                }
              }
            }
          });

    } catch (XMPPException ex) {
      System.out.println("Failure to connect : " + ex.getMessage());
    }
  }