Author Topic: JTS3ServerQuery lib can nicht zu gestoppten Servern connecten  (Read 7327 times)

noamik

  • Newbie
  • *
  • Posts: 1
    • View Profile
JTS3ServerQuery lib can nicht zu gestoppten Servern connecten
« on: February 01, 2012, 11:58:35 AM »
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();
   }
« Last Edit: February 01, 2012, 12:01:31 PM by noamik »

Stefan1200

  • Administrator
  • *****
  • Posts: 2244
    • View Profile
Re: JTS3ServerQuery lib can nicht zu gestoppten Servern connecten
« Reply #1 on: February 01, 2012, 05:15:16 PM »
Danke für den Hinweis. Wenn ich mal Zeit dafür finde, werde ich das berücksichtigen.