TheHolyWaffle / TeamSpeak-3-Java-API

A Java wrapper of TeamSpeak's 3 server query API.
MIT License
306 stars 107 forks source link

how to add query login and get login data #419

Closed qeinz closed 6 months ago

qeinz commented 6 months ago

hello, how can i add a querylogin and get the login credentials afterwards?

        try {
            final String UID = Utils.getUIDFromSeckey(seckey);
            final int DBID = Main.api.getDatabaseClientByUId(UID).getDatabaseId();
            final String login_password = Main.api.addServerQueryLogin(UID, DBID).getQueryClientLoginPassword();
            System.out.println("logind login_password" + login_password);
            System.out.println("logind dbid" + DBID);
            System.out.println("logind uid" + UID);
            //update("INSERT INTO ");

        } catch (Exception exception) {
            System.out.println("ERROR " + exception);
        }

this is my current setup, but im only facing some spicy errors

2024-03-10T20:42:50.227560347Z ERROR com.github.theholywaffle.teamspeak3.api.exception.TS3CommandFailedException: A "queryloginadd" command returned with a server error.
2024-03-10T20:42:50.227605824Z >> invalid parameter size (ID 1541)
rogermb commented 6 months ago

Hi @qeinz!

The only way I managed to reproduce an invalid parameter size (ID 1541) error with the "queryloginadd" command was when the loginName argument was null, an empty string, or a string of length greater than 20. It does not appear that this size constraint is documented anywhere in the TS3 documentation...

Could you please check whether your UID string fits within these constraints? Considering that you appear to be generating your query login name, I could well imagine its size being longer than 20 characters 😄

qeinz commented 6 months ago

thx, its now working, the problem was indeed the length of the login_name, i've tried to fit the UID into the loginName. Now i used this to get it working:

    public static void createChatAppContactQueryLogin(String seckey) {
        try {
            final String UID = Utils.getUIDFromSeckey(seckey);
            final String login_name = UID.substring(0, 19);
            final int DBID = Main.api.getDatabaseClientByUId(UID).getDatabaseId();
            final String login_password =
                    Main.api.addServerQueryLogin(login_name, DBID).getQueryClientLoginPassword();
            System.out.println("logind login_password " + login_password);
            System.out.println("logind dbid " + DBID);
            System.out.println("logind uid " + UID);
            update("INSERT INTO app_queryaccounts (seckey, login_name, password) VALUES " +
                    "('" + seckey + "', '" + login_name + "', '" + login_password + "');");

        } catch (Exception exception) {
            System.out.println("ERROR " + exception);
        }
    }
rogermb commented 6 months ago

Awesome, great to hear that! 🥳 🎉