Skip to content

Commit 2efd11b

Browse files
committed
Add new [add|get|delete]ServerQueryLogin methods to TS3Api(Async)
These methods can be used to create server-local and global server query logins, look up server query logins (optionally filtered by name), and delete existing server query logins.
1 parent 549596d commit 2efd11b

5 files changed

Lines changed: 328 additions & 0 deletions

File tree

src/main/java/com/github/theholywaffle/teamspeak3/TS3Api.java

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,34 @@ public void addServerGroupPermission(int groupId, String permName, int value, bo
476476
asyncApi.addServerGroupPermission(groupId, permName, value, negated, skipped).getUninterruptibly();
477477
}
478478

479+
/**
480+
* Creates a server query login with name {@code loginName} for the client specified by {@code clientDBId}
481+
* on the currently selected virtual server and returns the password of the created login.
482+
* If the client already had a server query login, the existing login will be deleted and replaced.
483+
* <p>
484+
* Moreover, this method can be used to create new <i>global</i> server query logins that are not tied to any
485+
* particular virtual server or client. To create such a server query login, make sure no virtual server is
486+
* selected (e.g. use {@code selectVirtualServerById(0)}) and call this method with {@code clientDBId = 0}.
487+
* </p>
488+
*
489+
* @param loginName
490+
* the name of the server query login to add
491+
* @param clientDBId
492+
* the database ID of the client for which a server query login should be created
493+
*
494+
* @return an object containing the password of the new server query login
495+
*
496+
* @throws TS3CommandFailedException
497+
* if the execution of a command fails
498+
* @querycommands 1
499+
* @see #deleteServerQueryLogin(int)
500+
* @see #getServerQueryLogins()
501+
* @see #updateServerQueryLogin(String)
502+
*/
503+
public CreatedQueryLogin addServerQueryLogin(String loginName, int clientDBId) {
504+
return asyncApi.addServerQueryLogin(loginName, clientDBId).getUninterruptibly();
505+
}
506+
479507
/**
480508
* Adds one or more {@link TS3Listener}s to the event manager of the query.
481509
* These listeners will be notified when the TS3 server fires an event.
@@ -1298,6 +1326,26 @@ public void deleteServerGroupPermission(int groupId, String permName) {
12981326
asyncApi.deleteServerGroupPermission(groupId, permName).getUninterruptibly();
12991327
}
13001328

1329+
/**
1330+
* Deletes the server query login with the specified client database ID.
1331+
* <p>
1332+
* If you only know the name of the server query login, use {@link #getServerQueryLoginsByName(String)} first.
1333+
* </p>
1334+
*
1335+
* @param clientDBId
1336+
* the client database ID of the server query login (usually the ID of the associated client)
1337+
*
1338+
* @throws TS3CommandFailedException
1339+
* if the execution of a command fails
1340+
* @querycommands 1
1341+
* @see #addServerQueryLogin(String, int)
1342+
* @see #getServerQueryLogins()
1343+
* @see #updateServerQueryLogin(String)
1344+
*/
1345+
public void deleteServerQueryLogin(int clientDBId) {
1346+
asyncApi.deleteServerQueryLogin(clientDBId).getUninterruptibly();
1347+
}
1348+
13011349
/**
13021350
* Restores the selected virtual servers configuration using the data from a
13031351
* previously created server snapshot.
@@ -2770,6 +2818,46 @@ public VirtualServerInfo getServerInfo() {
27702818
return asyncApi.getServerInfo().getUninterruptibly();
27712819
}
27722820

2821+
/**
2822+
* Gets a list of all server query logins (containing login name, virtual server ID, and client database ID).
2823+
* If a virtual server is selected, only the server query logins of the selected virtual server are returned.
2824+
*
2825+
* @return a list of {@code QueryLogin} objects describing existing server query logins
2826+
*
2827+
* @throws TS3CommandFailedException
2828+
* if the execution of a command fails
2829+
* @querycommands 1
2830+
* @see #addServerQueryLogin(String, int)
2831+
* @see #deleteServerQueryLogin(int)
2832+
* @see #getServerQueryLoginsByName(String)
2833+
* @see #updateServerQueryLogin(String)
2834+
*/
2835+
public List<QueryLogin> getServerQueryLogins() {
2836+
return asyncApi.getServerQueryLogins().getUninterruptibly();
2837+
}
2838+
2839+
/**
2840+
* Gets a list of all server query logins (containing login name, virtual server ID, and client database ID)
2841+
* whose login name matches the specified SQL-like pattern.
2842+
* If a virtual server is selected, only the server query logins of the selected virtual server are returned.
2843+
*
2844+
* @param pattern
2845+
* the SQL-like pattern to match the server query login name against
2846+
*
2847+
* @return a list of {@code QueryLogin} objects describing existing server query logins
2848+
*
2849+
* @throws TS3CommandFailedException
2850+
* if the execution of a command fails
2851+
* @querycommands 1
2852+
* @see #addServerQueryLogin(String, int)
2853+
* @see #deleteServerQueryLogin(int)
2854+
* @see #getServerQueryLogins()
2855+
* @see #updateServerQueryLogin(String)
2856+
*/
2857+
public List<QueryLogin> getServerQueryLoginsByName(String pattern) {
2858+
return asyncApi.getServerQueryLoginsByName(pattern).getUninterruptibly();
2859+
}
2860+
27732861
/**
27742862
* Gets the version, build number and platform of the TeamSpeak3 server.
27752863
*
@@ -4370,6 +4458,9 @@ public void updateClient(ClientProperty property, String value) {
43704458
* @throws TS3CommandFailedException
43714459
* if the execution of a command fails
43724460
* @querycommands 1
4461+
* @see #addServerQueryLogin(String, int)
4462+
* @see #deleteServerQueryLogin(int)
4463+
* @see #getServerQueryLogins()
43734464
*/
43744465
public String updateServerQueryLogin(String loginName) {
43754466
return asyncApi.updateServerQueryLogin(loginName).getUninterruptibly();

src/main/java/com/github/theholywaffle/teamspeak3/TS3ApiAsync.java

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,35 @@ public CommandFuture<Void> addServerGroupPermission(int groupId, String permName
525525
return executeAndReturnError(cmd);
526526
}
527527

528+
/**
529+
* Creates a server query login with name {@code loginName} for the client specified by {@code clientDBId}
530+
* on the currently selected virtual server and returns the password of the created login.
531+
* If the client already had a server query login, the existing login will be deleted and replaced.
532+
* <p>
533+
* Moreover, this method can be used to create new <i>global</i> server query logins that are not tied to any
534+
* particular virtual server or client. To create such a server query login, make sure no virtual server is
535+
* selected (e.g. use {@code selectVirtualServerById(0)}) and call this method with {@code clientDBId = 0}.
536+
* </p>
537+
*
538+
* @param loginName
539+
* the name of the server query login to add
540+
* @param clientDBId
541+
* the database ID of the client for which a server query login should be created
542+
*
543+
* @return an object containing the password of the new server query login
544+
*
545+
* @throws TS3CommandFailedException
546+
* if the execution of a command fails
547+
* @querycommands 1
548+
* @see #deleteServerQueryLogin(int)
549+
* @see #getServerQueryLogins()
550+
* @see #updateServerQueryLogin(String)
551+
*/
552+
public CommandFuture<CreatedQueryLogin> addServerQueryLogin(String loginName, int clientDBId) {
553+
Command cmd = QueryLoginCommands.queryLoginAdd(loginName, clientDBId);
554+
return executeAndTransformFirst(cmd, CreatedQueryLogin::new);
555+
}
556+
528557
/**
529558
* Adds one or more {@link TS3Listener}s to the event manager of the query.
530559
* These listeners will be notified when the TS3 server fires an event.
@@ -1462,6 +1491,29 @@ public CommandFuture<Void> deleteServerGroupPermission(int groupId, String permN
14621491
return executeAndReturnError(cmd);
14631492
}
14641493

1494+
/**
1495+
* Deletes the server query login with the specified client database ID.
1496+
* <p>
1497+
* If you only know the name of the server query login, use {@link #getServerQueryLoginsByName(String)} first.
1498+
* </p>
1499+
*
1500+
* @param clientDBId
1501+
* the client database ID of the server query login (usually the ID of the associated client)
1502+
*
1503+
* @return a future to track the progress of this command
1504+
*
1505+
* @throws TS3CommandFailedException
1506+
* if the execution of a command fails
1507+
* @querycommands 1
1508+
* @see #addServerQueryLogin(String, int)
1509+
* @see #getServerQueryLogins()
1510+
* @see #updateServerQueryLogin(String)
1511+
*/
1512+
public CommandFuture<Void> deleteServerQueryLogin(int clientDBId) {
1513+
Command cmd = QueryLoginCommands.queryLoginDel(clientDBId);
1514+
return executeAndReturnError(cmd);
1515+
}
1516+
14651517
/**
14661518
* Restores the selected virtual servers configuration using the data from a
14671519
* previously created server snapshot.
@@ -3150,6 +3202,47 @@ public CommandFuture<VirtualServerInfo> getServerInfo() {
31503202
return executeAndTransformFirst(cmd, VirtualServerInfo::new);
31513203
}
31523204

3205+
/**
3206+
* Gets a list of all server query logins (containing login name, virtual server ID, and client database ID).
3207+
* If a virtual server is selected, only the server query logins of the selected virtual server are returned.
3208+
*
3209+
* @return a list of {@code QueryLogin} objects describing existing server query logins
3210+
*
3211+
* @throws TS3CommandFailedException
3212+
* if the execution of a command fails
3213+
* @querycommands 1
3214+
* @see #addServerQueryLogin(String, int)
3215+
* @see #deleteServerQueryLogin(int)
3216+
* @see #getServerQueryLoginsByName(String)
3217+
* @see #updateServerQueryLogin(String)
3218+
*/
3219+
public CommandFuture<List<QueryLogin>> getServerQueryLogins() {
3220+
return getServerQueryLoginsByName(null);
3221+
}
3222+
3223+
/**
3224+
* Gets a list of all server query logins (containing login name, virtual server ID, and client database ID)
3225+
* whose login name matches the specified SQL-like pattern.
3226+
* If a virtual server is selected, only the server query logins of the selected virtual server are returned.
3227+
*
3228+
* @param pattern
3229+
* the SQL-like pattern to match the server query login name against
3230+
*
3231+
* @return a list of {@code QueryLogin} objects describing existing server query logins
3232+
*
3233+
* @throws TS3CommandFailedException
3234+
* if the execution of a command fails
3235+
* @querycommands 1
3236+
* @see #addServerQueryLogin(String, int)
3237+
* @see #deleteServerQueryLogin(int)
3238+
* @see #getServerQueryLogins()
3239+
* @see #updateServerQueryLogin(String)
3240+
*/
3241+
public CommandFuture<List<QueryLogin>> getServerQueryLoginsByName(String pattern) {
3242+
Command cmd = QueryLoginCommands.queryLoginList(pattern);
3243+
return executeAndTransform(cmd, QueryLogin::new);
3244+
}
3245+
31533246
/**
31543247
* Gets the version, build number and platform of the TeamSpeak3 server.
31553248
*
@@ -5039,6 +5132,9 @@ public CommandFuture<Void> updateClient(ClientProperty property, String value) {
50395132
* @throws TS3CommandFailedException
50405133
* if the execution of a command fails
50415134
* @querycommands 1
5135+
* @see #addServerQueryLogin(String, int)
5136+
* @see #deleteServerQueryLogin(int)
5137+
* @see #getServerQueryLogins()
50425138
*/
50435139
public CommandFuture<String> updateServerQueryLogin(String loginName) {
50445140
Command cmd = ClientCommands.clientSetServerQueryLogin(loginName);
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.github.theholywaffle.teamspeak3.api.wrapper;
2+
3+
/*
4+
* #%L
5+
* TeamSpeak 3 Java API
6+
* %%
7+
* Copyright (C) 2021 Bert De Geyter, Roger Baumgartner
8+
* %%
9+
* Permission is hereby granted, free of charge, to any person obtaining a copy
10+
* of this software and associated documentation files (the "Software"), to deal
11+
* in the Software without restriction, including without limitation the rights
12+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
* copies of the Software, and to permit persons to whom the Software is
14+
* furnished to do so, subject to the following conditions:
15+
*
16+
* The above copyright notice and this permission notice shall be included in
17+
* all copies or substantial portions of the Software.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
* THE SOFTWARE.
26+
* #L%
27+
*/
28+
29+
import java.util.Map;
30+
31+
public class CreatedQueryLogin extends QueryLogin {
32+
33+
public CreatedQueryLogin(Map<String, String> map) {
34+
super(map);
35+
}
36+
37+
public String getQueryClientLoginPassword() {
38+
return get("client_login_password");
39+
}
40+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.github.theholywaffle.teamspeak3.api.wrapper;
2+
3+
/*
4+
* #%L
5+
* TeamSpeak 3 Java API
6+
* %%
7+
* Copyright (C) 2021 Bert De Geyter, Roger Baumgartner
8+
* %%
9+
* Permission is hereby granted, free of charge, to any person obtaining a copy
10+
* of this software and associated documentation files (the "Software"), to deal
11+
* in the Software without restriction, including without limitation the rights
12+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
* copies of the Software, and to permit persons to whom the Software is
14+
* furnished to do so, subject to the following conditions:
15+
*
16+
* The above copyright notice and this permission notice shall be included in
17+
* all copies or substantial portions of the Software.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
* THE SOFTWARE.
26+
* #L%
27+
*/
28+
29+
import java.util.Map;
30+
31+
public class QueryLogin extends Wrapper {
32+
33+
public QueryLogin(Map<String, String> map) {
34+
super(map);
35+
}
36+
37+
public int getClientDatabaseId() {
38+
return getInt("cldbid");
39+
}
40+
41+
public int getVirtualServerId() {
42+
return getInt("sid");
43+
}
44+
45+
public String getQueryClientLoginName() {
46+
return get("client_login_name");
47+
}
48+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.github.theholywaffle.teamspeak3.commands;
2+
3+
/*
4+
* #%L
5+
* TeamSpeak 3 Java API
6+
* %%
7+
* Copyright (C) 2021 Bert De Geyter, Roger Baumgartner
8+
* %%
9+
* Permission is hereby granted, free of charge, to any person obtaining a copy
10+
* of this software and associated documentation files (the "Software"), to deal
11+
* in the Software without restriction, including without limitation the rights
12+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
* copies of the Software, and to permit persons to whom the Software is
14+
* furnished to do so, subject to the following conditions:
15+
*
16+
* The above copyright notice and this permission notice shall be included in
17+
* all copies or substantial portions of the Software.
18+
*
19+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
* THE SOFTWARE.
26+
* #L%
27+
*/
28+
29+
import com.github.theholywaffle.teamspeak3.commands.parameter.KeyValueParam;
30+
31+
public final class QueryLoginCommands {
32+
33+
private QueryLoginCommands() {
34+
throw new Error("No instances");
35+
}
36+
37+
public static Command queryLoginAdd(String loginName, int clientDBId) {
38+
CommandBuilder builder = new CommandBuilder("queryloginadd", 2);
39+
builder.add(new KeyValueParam("client_login_name", loginName));
40+
builder.addIf(clientDBId > 0, new KeyValueParam("cldbid", clientDBId));
41+
return builder.build();
42+
}
43+
44+
public static Command queryLoginDel(int clientDBId) {
45+
return new CommandBuilder("querylogindel", 1).add(new KeyValueParam("cldbid", clientDBId)).build();
46+
}
47+
48+
public static Command queryLoginList(String pattern) {
49+
CommandBuilder builder = new CommandBuilder("queryloginlist", 1);
50+
builder.addIf(pattern != null, new KeyValueParam("pattern", pattern));
51+
return builder.build();
52+
}
53+
}

0 commit comments

Comments
 (0)