예제 #1
0
  public static void login(long contentNetworkID, long maxDelayMS) {
    PlatformManager pm = PlatformManagerFactory.getPlatformManager();
    String azComputerID = "";
    try {
      azComputerID = pm.getAzComputerID();
    } catch (PlatformManagerException e) {
    }

    String sourceRef = null;
    if (contentNetworkID != ConstantsVuze.DEFAULT_CONTENT_NETWORK_ID) {
      ContentNetwork cn =
          ContentNetworkManagerFactory.getSingleton().getContentNetwork(contentNetworkID);
      sourceRef = (String) cn.getPersistentProperty(ContentNetwork.PP_SOURCE_REF);
    }
    if (sourceRef == null) {
      sourceRef = "unknown";
    }

    Object[] params =
        new Object[] {
          "version",
          org.gudy.azureus2.core3.util.Constants.AZUREUS_VERSION,
          "locale",
          Locale.getDefault().toString(),
          "azCID",
          azComputerID,
          "vid",
          COConfigurationManager.getStringParameter("ID"),
          "source-ref",
          sourceRef
        };
    PlatformMessage message =
        new PlatformMessage("AZMSG", LISTENER_ID, "login", params, maxDelayMS);
    message.setContentNetworkID(contentNetworkID);

    PlatformMessengerListener listener =
        new PlatformMessengerListener() {

          public void replyReceived(PlatformMessage message, String replyType, Map reply) {
            if (reply == null) {
              return;
            }

            boolean allowMulti =
                MapUtils.getMapBoolean(reply, "allow-multi-rpc", PlatformMessenger.getAllowMulti());
            PlatformMessenger.setAllowMulti(allowMulti);

            try {
              List listURLs =
                  (List) MapUtils.getMapObject(reply, "url-whitelist", null, List.class);
              if (listURLs != null) {
                for (int i = 0; i < listURLs.size(); i++) {
                  String string = (String) listURLs.get(i);
                  UrlFilter.getInstance().addUrlWhitelist(string);
                }
              }
            } catch (Exception e) {
              Debug.out(e);
            }

            try {
              List listURLs =
                  (List) MapUtils.getMapObject(reply, "url-blacklist", null, List.class);
              if (listURLs != null) {
                for (int i = 0; i < listURLs.size(); i++) {
                  String string = (String) listURLs.get(i);
                  UrlFilter.getInstance().addUrlBlacklist(string);
                }
              }
            } catch (Exception e) {
              Debug.out(e);
            }

            try {
              List listDomains =
                  (List) MapUtils.getMapObject(reply, "tracker-domains", null, List.class);
              if (listDomains != null) {
                for (int i = 0; i < listDomains.size(); i++) {
                  String s = (String) listDomains.get(i);
                  PlatformTorrentUtils.addPlatformHost(s);
                  PlatformMessenger.debug("v3.login: got tracker domain of " + s);
                }
              }
            } catch (Exception e) {
              Debug.out(e);
            }

            if (message.getContentNetworkID() != ConstantsVuze.getDefaultContentNetwork().getID()) {
              return;
            }

            try {
              sendStats = MapUtils.getMapBoolean(reply, "send-stats", false);
              doUrlQOS = MapUtils.getMapBoolean(reply, "do-url-qos", false);
              allowSendDeviceList = MapUtils.getMapBoolean(reply, "send-device-list", false);
            } catch (Exception e) {
            }

            try {
              iRPCVersion = MapUtils.getMapInt(reply, "rpc-version", 0);
              playAfterURL = (String) MapUtils.getMapString(reply, "play-after-url", null);
            } catch (Exception e) {
              Debug.out(e);
            }

            platformLoginComplete = true;
            Object[] listeners = platformLoginCompleteListeners.toArray();
            platformLoginCompleteListeners = Collections.EMPTY_LIST;
            for (int i = 0; i < listeners.length; i++) {
              try {
                PlatformLoginCompleteListener l = (PlatformLoginCompleteListener) listeners[i];
                l.platformLoginComplete();
              } catch (Exception e) {
                Debug.out(e);
              }
            }
          }

          public void messageSent(PlatformMessage message) {}
        };

    PlatformMessenger.pushMessageNow(message, listener);
  }