JTS3ServerQuery lib can nicht zu gestoppten Servern connecten

Started by noamik, February 01, 2012, 11:58:35 AM

Previous topic - Next topic

noamik

Hi,

ich baue derzeit an einem Tool und dabei fiel mir auf, dass es mit der Lib nicht möglich ist zu gestoppten Servern eine Verbindung aufzunehmen. Laut Spec gibt es dafür aber ein passendes Flag (use id -virtual). Ich habe mir erlaubt die Lib passend zu erweitern. Vielleicht magst du ja eine vergleichbare Funktion in eine kommende Version der lib aufnehmen (mein Patch ist ja nur ein Quick-Hack, mit dem Versuch "non-breaking" zu arbeiten).

/**
    * Select a virtual server to work with.
    * @param serverID A virtual server id
    * @return <code>true</code> if selection was successful, <code>false</code> if an error occurred (check error with getLastError()).
    * @see JTS3ServerQuery#getLastError()
    */
   public boolean selectVirtualServer(int serverID)
   {
      return selectVirtualServer(false, serverID, false);
   }
   
   /**
    * Select a virtual server to work with.
    * @param virtual If true, the "-virtual" flag is appended to virtual server selection (needed to query stopped servers without starting them)
    * @param serverID A virtual server id
    * @return <code>true</code> if selection was successful, <code>false</code> if an error occurred (check error with getLastError()).
    * @see JTS3ServerQuery#getLastError()
    */
   public boolean selectVirtualServer(Boolean virtual, int serverID)
   {
      return selectVirtualServer(virtual, serverID, false);
   }

   
   /**
    * Select a virtual server to work with. This method allows to select the virtual server by id or port.
    * @param server A virtual server id or port
    * @param selectPort <code>true</code> if <code>server</code> is the virtual server port, <code>false</code> if <code>server</code> is the virtual server id.
    * @return <code>true</code> if selection was successful, <code>false</code> if an error occurred (check error with getLastError()).
    * @since 0.9
    * @see JTS3ServerQuery#getLastError()
    */
   public boolean selectVirtualServer(int server, boolean selectPort)
   {
      return selectVirtualServer(false, server, selectPort);
   }
   
   /**
    * Select a virtual server to work with. This method allows to select the virtual server by id or port.
    * @param virtual If true, the "-virtual" flag is appended to virtual server selection (needed to query stopped servers without starting them)
    * @param server A virtual server id or port
    * @param selectPort <code>true</code> if <code>server</code> is the virtual server port, <code>false</code> if <code>server</code> is the virtual server id.
    * @return <code>true</code> if selection was successful, <code>false</code> if an error occurred (check error with getLastError()).
    * @since 0.9
    * @see JTS3ServerQuery#getLastError()
    */
   public boolean selectVirtualServer(Boolean virtual, int server, boolean selectPort)
   {
      resetLastError();
      
      if (!isConnected())
      {
         saveLastError("selectVirtualServer(): Not connected to TS3 server!");
         return false;
      }
      
      HashMap<String, String> hmIn;
      try
      {
         String command;
         if (selectPort)
         {
            command = "use port=" + Integer.toString(server);
         }
         else
         {
            command = "use " + Integer.toString(server);
         }
         if(virtual)
            command = command + " -virtual";

         hmIn = doInternalCommand(command);
         if (!hmIn.get("id").equals("0"))
         {
            saveLastError("selectVirtualServer()", hmIn.get("id"), hmIn.get("msg"), hmIn.get("extra_msg"), hmIn.get("failed_permid"));
            return false;
         }
      }
      catch (Exception e)
      {
         if (DEBUG) e.printStackTrace();
         saveLastError("Exception selectVirtualServer(): " + e.toString());
         return false;
      }
      
      return updateClientIDChannelID();
   }

Stefan1200

Danke für den Hinweis. Wenn ich mal Zeit dafür finde, werde ich das berücksichtigen.