-
Notifications
You must be signed in to change notification settings - Fork 107
/
TS3ApiAsync.java
5793 lines (5474 loc) · 188 KB
/
TS3ApiAsync.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package com.github.theholywaffle.teamspeak3;
/*
* #%L
* TeamSpeak 3 Java API
* %%
* Copyright (C) 2014 Bert De Geyter
* %%
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
* #L%
*/
import com.github.theholywaffle.teamspeak3.api.*;
import com.github.theholywaffle.teamspeak3.api.event.TS3EventType;
import com.github.theholywaffle.teamspeak3.api.event.TS3Listener;
import com.github.theholywaffle.teamspeak3.api.exception.TS3CommandFailedException;
import com.github.theholywaffle.teamspeak3.api.exception.TS3Exception;
import com.github.theholywaffle.teamspeak3.api.exception.TS3FileTransferFailedException;
import com.github.theholywaffle.teamspeak3.api.wrapper.*;
import com.github.theholywaffle.teamspeak3.commands.*;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
* Asynchronous version of {@link TS3Api} to interact with the {@link TS3Query}.
* <p>
* This class is used to easily interact with a {@link TS3Query}. It constructs commands,
* sends them to the TeamSpeak3 server, processes the response and returns the result.
* </p><p>
* All methods in this class are asynchronous (so they won't block) and
* will return a {@link CommandFuture} of the corresponding return type in {@link TS3Api}.
* If a command fails, no exception will be thrown directly. It will however be rethrown in
* {@link CommandFuture#get()} and {@link CommandFuture#get(long, TimeUnit)}.
* Usually, the thrown exception is a {@link TS3CommandFailedException}, which will get you
* access to the {@link QueryError} from which more information about the error can be obtained.
* </p><p>
* Also note that while these methods are asynchronous, the commands will still be sent through a
* synchronous command pipeline. That means if an asynchronous method is called immediately
* followed by a synchronous method, the synchronous method will first have to wait until the
* asynchronous method completed until it its command is sent.
* </p><p>
* You won't be able to execute most commands while you're not logged in due to missing permissions.
* Make sure to either pass your login credentials to the {@link TS3Config} object when
* creating the {@code TS3Query} or to call {@link #login(String, String)} to log in.
* </p><p>
* After that, most commands also require you to select a {@linkplain VirtualServer virtual server}.
* To do so, call either {@link #selectVirtualServerByPort(int)} or {@link #selectVirtualServerById(int)}.
* </p>
*
* @see TS3Api The synchronous version of the API
*/
public class TS3ApiAsync {
/**
* The TS3 query that holds the event manager and the file transfer helper.
*/
private final TS3Query query;
/**
* The queue that this TS3ApiAsync sends its commands to.
*/
private final CommandQueue commandQueue;
/**
* Creates a new asynchronous API object for the given {@code TS3Query}.
* <p>
* <b>Usually, this constructor should not be called.</b> Use {@link TS3Query#getAsyncApi()} instead.
* </p>
*
* @param query
* the TS3Query to use
* @param commandQueue
* the queue to send commands to
*/
TS3ApiAsync(TS3Query query, CommandQueue commandQueue) {
this.query = query;
this.commandQueue = commandQueue;
}
/**
* Adds a new ban entry. At least one of the parameters {@code ip}, {@code name} or {@code uid} needs to be non-null.
* Returns the ID of the newly created ban entry.
*
* @param ip
* a RegEx pattern to match a client's IP against, can be {@code null}
* @param name
* a RegEx pattern to match a client's name against, can be {@code null}
* @param uid
* the unique identifier of a client, can be {@code null}
* @param timeInSeconds
* the duration of the ban in seconds. 0 equals a permanent ban
* @param reason
* the reason for the ban, can be {@code null}
*
* @return the ID of the newly created ban entry
*
* @throws TS3CommandFailedException
* if the execution of a command fails
* @querycommands 1
* @see Pattern RegEx Pattern
* @see #addBan(String, String, String, String, long, String)
* @see Client#getId()
* @see Client#getUniqueIdentifier()
* @see ClientInfo#getIp()
*/
public CommandFuture<Integer> addBan(String ip, String name, String uid, long timeInSeconds, String reason) {
return addBan(ip, name, uid, null, timeInSeconds, reason);
}
/**
* Adds a new ban entry. At least one of the parameters {@code ip}, {@code name}, {@code uid}, or
* {@code myTSId} needs to be non-null. Returns the ID of the newly created ban entry.
* <p>
* Note that creating a ban entry for the {@code "empty"} "myTeamSpeak" ID will ban all clients who
* don't have a linked "myTeamSpeak" account.
* </p>
*
* @param ip
* a RegEx pattern to match a client's IP against, can be {@code null}
* @param name
* a RegEx pattern to match a client's name against, can be {@code null}
* @param uid
* the unique identifier of a client, can be {@code null}
* @param myTSId
* the "myTeamSpeak" ID of a client, the string {@code "empty"}, or {@code null}
* @param timeInSeconds
* the duration of the ban in seconds. 0 equals a permanent ban
* @param reason
* the reason for the ban, can be {@code null}
*
* @return the ID of the newly created ban entry
*
* @throws TS3CommandFailedException
* if the execution of a command fails
* @querycommands 1
* @see Pattern RegEx Pattern
* @see Client#getId()
* @see Client#getUniqueIdentifier()
* @see ClientInfo#getIp()
*/
public CommandFuture<Integer> addBan(String ip, String name, String uid, String myTSId, long timeInSeconds, String reason) {
Command cmd = BanCommands.banAdd(ip, name, uid, myTSId, timeInSeconds, reason);
return executeAndReturnIntProperty(cmd, "banid");
}
/**
* Adds a specified permission to a client in a specific channel.
*
* @param channelId
* the ID of the channel wherein the permission should be granted
* @param clientDBId
* the database ID of the client to add a permission to
* @param permName
* the name of the permission to grant
* @param permValue
* the numeric value of the permission (or for boolean permissions: 1 = true, 0 = false)
*
* @return a future to track the progress of this command
*
* @throws TS3CommandFailedException
* if the execution of a command fails
* @querycommands 1
* @see Channel#getId()
* @see Client#getDatabaseId()
* @see Permission
*/
public CommandFuture<Void> addChannelClientPermission(int channelId, int clientDBId, String permName, int permValue) {
Command cmd = PermissionCommands.channelClientAddPerm(channelId, clientDBId, permName, permValue);
return executeAndReturnError(cmd);
}
/**
* Creates a new channel group for clients using a given name and returns its ID.
* <p>
* To create channel group templates or ones for server queries,
* use {@link #addChannelGroup(String, PermissionGroupDatabaseType)}.
* </p>
*
* @param name
* the name of the new channel group
*
* @return the ID of the newly created channel group
*
* @throws TS3CommandFailedException
* if the execution of a command fails
* @querycommands 1
* @see ChannelGroup
*/
public CommandFuture<Integer> addChannelGroup(String name) {
return addChannelGroup(name, null);
}
/**
* Creates a new channel group using a given name and returns its ID.
*
* @param name
* the name of the new channel group
* @param type
* the desired type of channel group
*
* @return the ID of the newly created channel group
*
* @throws TS3CommandFailedException
* if the execution of a command fails
* @querycommands 1
* @see ChannelGroup
*/
public CommandFuture<Integer> addChannelGroup(String name, PermissionGroupDatabaseType type) {
Command cmd = ChannelGroupCommands.channelGroupAdd(name, type);
return executeAndReturnIntProperty(cmd, "cgid");
}
/**
* Adds a specified permission to a channel group.
*
* @param groupId
* the ID of the channel group to grant the permission
* @param permName
* the name of the permission to be granted
* @param permValue
* the numeric value of the permission (or for boolean permissions: 1 = true, 0 = false)
*
* @return a future to track the progress of this command
*
* @throws TS3CommandFailedException
* if the execution of a command fails
* @querycommands 1
* @see ChannelGroup#getId()
* @see Permission
*/
public CommandFuture<Void> addChannelGroupPermission(int groupId, String permName, int permValue) {
Command cmd = PermissionCommands.channelGroupAddPerm(groupId, permName, permValue);
return executeAndReturnError(cmd);
}
/**
* Adds a specified permission to a channel.
*
* @param channelId
* the ID of the channel wherein the permission should be granted
* @param permName
* the name of the permission to grant
* @param permValue
* the numeric value of the permission (or for boolean permissions: 1 = true, 0 = false)
*
* @return a future to track the progress of this command
*
* @throws TS3CommandFailedException
* if the execution of a command fails
* @querycommands 1
* @see Channel#getId()
* @see Permission
*/
public CommandFuture<Void> addChannelPermission(int channelId, String permName, int permValue) {
Command cmd = PermissionCommands.channelAddPerm(channelId, permName, permValue);
return executeAndReturnError(cmd);
}
/**
* Adds a specified permission to a channel.
*
* @deprecated
* This method is no longer preferred for adding permissions to a client.
* <p>
* Use {@link TS3ApiAsync#addClientPermission(int, IPermissionType, int, boolean)}
* or {@link TS3ApiAsync#addClientPermission(int, BPermissionType, boolean, boolean)} instead.
* </p>
*
* @param clientDBId
* the database ID of the client to grant the permission
* @param permName
* the name of the permission to grant
* @param value
* the numeric value of the permission (or for boolean permissions: 1 = true, 0 = false)
* @param skipped
* if set to {@code true}, the permission will not be overridden by channel group permissions
*
* @return a future to track the progress of this command
*
* @throws TS3CommandFailedException
* if the execution of a command fails
* @querycommands 1
* @see Client#getDatabaseId()
* @see Permission
*/
@Deprecated
public CommandFuture<Void> addClientPermission(int clientDBId, String permName, int value, boolean skipped) {
Command cmd = PermissionCommands.clientAddPerm(clientDBId, permName, value, skipped);
return executeAndReturnError(cmd);
}
/**
* Adds a specified permission to a client.
*
* @param clientDBId
* the database ID of the client to grant the permission
* @param permName
* the enum of the permission to grant
* @see IPermissionType
* @param value
* the numeric value of the permission
* @param skipped
* if set to {@code true}, the permission will not be overridden by channel group permissions
*
* @return a future to track the progress of this command
*
* @throws TS3CommandFailedException
* if the execution of a command fails
* @querycommands 1
* @see Client#getDatabaseId()
* @see Permission
*/
public CommandFuture<Void> addClientPermission(int clientDBId, IPermissionType permName, int value, boolean skipped) {
Command cmd = PermissionCommands.clientAddPerm(clientDBId, permName.getName(), value, skipped);
return executeAndReturnError(cmd);
}
/**
* Adds a specified permission to a client.
*
* @param clientDBId
* the database ID of the client to grant the permission
* @param permName
* the enum of the permission to grant
* @see BPermissionType
* @param value
* the boolean value of the permission
* @param skipped
* if set to {@code true}, the permission will not be overridden by channel group permissions
*
* @return a future to track the progress of this command
*
* @throws TS3CommandFailedException
* if the execution of a command fails
* @querycommands 1
* @see Client#getDatabaseId()
* @see Permission
*/
public CommandFuture<Void> addClientPermission(int clientDBId, BPermissionType permName, boolean value, boolean skipped) {
Command cmd = PermissionCommands.clientAddPerm(clientDBId, permName.getName(), value, skipped);
return executeAndReturnError(cmd);
}
/**
* Adds a client to the specified server group.
* <p>
* Please note that a client cannot be added to default groups or template groups.
* </p>
*
* @param groupId
* the ID of the server group to add the client to
* @param clientDatabaseId
* the database ID of the client to add
*
* @return a future to track the progress of this command
*
* @throws TS3CommandFailedException
* if the execution of a command fails
* @querycommands 1
* @see ServerGroup#getId()
* @see Client#getDatabaseId()
*/
public CommandFuture<Void> addClientToServerGroup(int groupId, int clientDatabaseId) {
Command cmd = ServerGroupCommands.serverGroupAddClient(groupId, clientDatabaseId);
return executeAndReturnError(cmd);
}
/**
* Submits a complaint about the specified client.
* The length of the message is limited to 200 UTF-8 bytes and BB codes in it will be ignored.
*
* @param clientDBId
* the database ID of the client
* @param message
* the message of the complaint, may not contain BB codes
*
* @return a future to track the progress of this command
*
* @throws TS3CommandFailedException
* if the execution of a command fails
* @querycommands 1
* @see Client#getDatabaseId()
* @see Complaint#getMessage()
*/
public CommandFuture<Void> addComplaint(int clientDBId, String message) {
Command cmd = ComplaintCommands.complainAdd(clientDBId, message);
return executeAndReturnError(cmd);
}
/**
* Adds a specified permission to all server groups of the type specified by {@code type} on all virtual servers.
*
* @param type
* the kind of server group this permission should be added to
* @param permName
* the name of the permission to be granted
* @param value
* the numeric value of the permission (or for boolean permissions: 1 = true, 0 = false)
* @param negated
* if set to true, the lowest permission value will be selected instead of the highest
* @param skipped
* if set to true, this permission will not be overridden by client or channel group permissions
*
* @return a future to track the progress of this command
*
* @throws TS3CommandFailedException
* if the execution of a command fails
* @querycommands 1
* @see ServerGroupType
* @see Permission
*/
public CommandFuture<Void> addPermissionToAllServerGroups(ServerGroupType type, String permName, int value, boolean negated, boolean skipped) {
Command cmd = PermissionCommands.serverGroupAutoAddPerm(type, permName, value, negated, skipped);
return executeAndReturnError(cmd);
}
/**
* Create a new privilege key that allows one client to join a server or channel group.
* <ul>
* <li>If {@code type} is set to {@linkplain PrivilegeKeyType#SERVER_GROUP SERVER_GROUP},
* {@code groupId} is used as a server group ID and {@code channelId} is ignored.</li>
* <li>If {@code type} is set to {@linkplain PrivilegeKeyType#CHANNEL_GROUP CHANNEL_GROUP},
* {@code groupId} is used as a channel group ID and {@code channelId} is used as the channel in which the group should be set.</li>
* </ul>
*
* @param type
* the type of token that should be created
* @param groupId
* the ID of the server or channel group
* @param channelId
* the ID of the channel, in case the token is channel group token
* @param description
* the description for the token, can be null
*
* @return the created token for a client to use
*
* @throws TS3CommandFailedException
* if the execution of a command fails
* @querycommands 1
* @see PrivilegeKeyType
* @see #addPrivilegeKeyServerGroup(int, String)
* @see #addPrivilegeKeyChannelGroup(int, int, String)
*/
public CommandFuture<String> addPrivilegeKey(PrivilegeKeyType type, int groupId, int channelId, String description) {
Command cmd = PrivilegeKeyCommands.privilegeKeyAdd(type, groupId, channelId, description);
return executeAndReturnStringProperty(cmd, "token");
}
/**
* Creates a new privilege key for a channel group.
*
* @param channelGroupId
* the ID of the channel group
* @param channelId
* the ID of the channel in which the channel group should be set
* @param description
* the description for the token, can be null
*
* @return the created token for a client to use
*
* @throws TS3CommandFailedException
* if the execution of a command fails
* @querycommands 1
* @see ChannelGroup#getId()
* @see Channel#getId()
* @see #addPrivilegeKey(PrivilegeKeyType, int, int, String)
* @see #addPrivilegeKeyServerGroup(int, String)
*/
public CommandFuture<String> addPrivilegeKeyChannelGroup(int channelGroupId, int channelId, String description) {
return addPrivilegeKey(PrivilegeKeyType.CHANNEL_GROUP, channelGroupId, channelId, description);
}
/**
* Creates a new privilege key for a server group.
*
* @param serverGroupId
* the ID of the server group
* @param description
* the description for the token, can be null
*
* @return the created token for a client to use
*
* @throws TS3CommandFailedException
* if the execution of a command fails
* @querycommands 1
* @see ServerGroup#getId()
* @see #addPrivilegeKey(PrivilegeKeyType, int, int, String)
* @see #addPrivilegeKeyChannelGroup(int, int, String)
*/
public CommandFuture<String> addPrivilegeKeyServerGroup(int serverGroupId, String description) {
return addPrivilegeKey(PrivilegeKeyType.SERVER_GROUP, serverGroupId, 0, description);
}
/**
* Creates a new server group for clients using a given name and returns its ID.
* <p>
* To create server group templates or ones for server queries,
* use {@link #addServerGroup(String, PermissionGroupDatabaseType)}.
* </p>
*
* @param name
* the name of the new server group
*
* @return the ID of the newly created server group
*
* @throws TS3CommandFailedException
* if the execution of a command fails
* @querycommands 1
* @see ServerGroup
*/
public CommandFuture<Integer> addServerGroup(String name) {
return addServerGroup(name, PermissionGroupDatabaseType.REGULAR);
}
/**
* Creates a new server group using a given name and returns its ID.
*
* @param name
* the name of the new server group
* @param type
* the desired type of server group
*
* @return the ID of the newly created server group
*
* @throws TS3CommandFailedException
* if the execution of a command fails
* @querycommands 1
* @see ServerGroup
* @see PermissionGroupDatabaseType
*/
public CommandFuture<Integer> addServerGroup(String name, PermissionGroupDatabaseType type) {
Command cmd = ServerGroupCommands.serverGroupAdd(name, type);
return executeAndReturnIntProperty(cmd, "sgid");
}
/**
* Adds a specified permission to a server group.
*
* @param groupId
* the ID of the channel group to which the permission should be added
* @param permName
* the name of the permission to add
* @param value
* the numeric value of the permission (or for boolean permissions: 1 = true, 0 = false)
* @param negated
* if set to true, the lowest permission value will be selected instead of the highest
* @param skipped
* if set to true, this permission will not be overridden by client or channel group permissions
*
* @return a future to track the progress of this command
*
* @throws TS3CommandFailedException
* if the execution of a command fails
* @querycommands 1
* @see ServerGroup#getId()
* @see Permission
*/
public CommandFuture<Void> addServerGroupPermission(int groupId, String permName, int value, boolean negated, boolean skipped) {
Command cmd = PermissionCommands.serverGroupAddPerm(groupId, permName, value, negated, skipped);
return executeAndReturnError(cmd);
}
/**
* Creates a server query login with name {@code loginName} for the client specified by {@code clientDBId}
* on the currently selected virtual server and returns the password of the created login.
* If the client already had a server query login, the existing login will be deleted and replaced.
* <p>
* Moreover, this method can be used to create new <i>global</i> server query logins that are not tied to any
* particular virtual server or client. To create such a server query login, make sure no virtual server is
* selected (e.g. use {@code selectVirtualServerById(0)}) and call this method with {@code clientDBId = 0}.
* </p>
*
* @param loginName
* the name of the server query login to add
* @param clientDBId
* the database ID of the client for which a server query login should be created
*
* @return an object containing the password of the new server query login
*
* @throws TS3CommandFailedException
* if the execution of a command fails
* @querycommands 1
* @see #deleteServerQueryLogin(int)
* @see #getServerQueryLogins()
* @see #updateServerQueryLogin(String)
*/
public CommandFuture<CreatedQueryLogin> addServerQueryLogin(String loginName, int clientDBId) {
Command cmd = QueryLoginCommands.queryLoginAdd(loginName, clientDBId);
return executeAndTransformFirst(cmd, CreatedQueryLogin::new);
}
/**
* Adds one or more {@link TS3Listener}s to the event manager of the query.
* These listeners will be notified when the TS3 server fires an event.
* <p>
* Note that for the TS3 server to fire events, you must first also register
* the event types you want to listen to.
* </p>
*
* @param listeners
* one or more listeners to register
*
* @see #registerAllEvents()
* @see #registerEvent(TS3EventType, int)
* @see TS3Listener
* @see TS3EventType
*/
public void addTS3Listeners(TS3Listener... listeners) {
query.getEventManager().addListeners(listeners);
}
/**
* Bans a client with a given client ID for a given time.
* <p>
* Please note that this will create up to three separate ban rules,
* one for the targeted client's IP address, one for their unique identifier,
* and potentially one more entry for their "myTeamSpeak" ID, if available.
* </p><p>
* <i>Exception:</i> If the banned client connects via a loopback address
* (i.e. {@code 127.0.0.1} or {@code localhost}), no IP ban is created.
* </p>
*
* @param clientId
* the ID of the client
* @param timeInSeconds
* the duration of the ban in seconds. 0 equals a permanent ban
*
* @return an array containing the IDs of the created ban entries
*
* @throws TS3CommandFailedException
* if the execution of a command fails
* @querycommands 1
* @see Client#getId()
* @see #addBan(String, String, String, long, String)
*/
public CommandFuture<int[]> banClient(int clientId, long timeInSeconds) {
return banClient(clientId, timeInSeconds, null);
}
/**
* Bans a client with a given client ID for a given time for the specified reason.
* <p>
* Please note that this will create up to three separate ban rules,
* one for the targeted client's IP address, one for their unique identifier,
* and potentially one more entry for their "myTeamSpeak" ID, if available.
* </p><p>
* <i>Exception:</i> If the banned client connects via a loopback address
* (i.e. {@code 127.0.0.1} or {@code localhost}), no IP ban is created.
* </p>
*
* @param clientId
* the ID of the client
* @param timeInSeconds
* the duration of the ban in seconds. 0 equals a permanent ban
* @param reason
* the reason for the ban, can be null
*
* @return an array containing the IDs of the created ban entries
*
* @throws TS3CommandFailedException
* if the execution of a command fails
* @querycommands 1
* @see Client#getId()
* @see #addBan(String, String, String, long, String)
*/
public CommandFuture<int[]> banClient(int clientId, long timeInSeconds, String reason) {
Command cmd = BanCommands.banClient(new int[] {clientId}, timeInSeconds, reason, false);
return executeAndReturnIntArray(cmd, "banid");
}
/**
* Bans a client with a given client ID permanently for the specified reason.
* <p>
* Please note that this will create up to three separate ban rules,
* one for the targeted client's IP address, one for their unique identifier,
* and potentially one more entry for their "myTeamSpeak" ID, if available.
* </p><p>
* <i>Exception:</i> If the banned client connects via a loopback address
* (i.e. {@code 127.0.0.1} or {@code localhost}), no IP ban is created.
* </p>
*
* @param clientId
* the ID of the client
* @param reason
* the reason for the ban, can be null
*
* @return an array containing the IDs of the created ban entries
*
* @throws TS3CommandFailedException
* if the execution of a command fails
* @querycommands 1
* @see Client#getId()
* @see #addBan(String, String, String, long, String)
*/
public CommandFuture<int[]> banClient(int clientId, String reason) {
return banClient(clientId, 0, reason);
}
/**
* Bans multiple clients by their client ID for a given time for the specified reason.
* <p>
* Please note that this will create up to three separate ban rules for each client,
* one for the targeted client's IP address, one for their unique identifier,
* and potentially one more entry for their "myTeamSpeak" ID, if available.
* </p><p>
* <i>Exception:</i> If the banned client connects via a loopback address
* (i.e. {@code 127.0.0.1} or {@code localhost}), no IP ban is created.
* </p><p>
* <i>Exception:</i> If two or more clients are connecting from the
* same IP address, only one IP ban entry for that IP will be created.
* </p>
*
* @param clientIds
* the IDs of the clients to be banned
* @param timeInSeconds
* the duration of the ban in seconds. 0 equals a permanent ban
* @param reason
* the reason for the ban, can be null
* @param continueOnError
* if true, continue to the next client if banning one client fails, else do not create any bans on error
*
* @return an array containing the IDs of the created ban entries
*
* @throws TS3CommandFailedException
* if the execution of a command fails
* @querycommands 1
* @see Client#getId()
* @see #addBan(String, String, String, long, String)
*/
public CommandFuture<int[]> banClients(int[] clientIds, long timeInSeconds, String reason, boolean continueOnError) {
if (clientIds == null) throw new IllegalArgumentException("Client ID array was null");
if (clientIds.length == 0) return CommandFuture.immediate(new int[0]); // Success
Command cmd = BanCommands.banClient(clientIds, timeInSeconds, reason, continueOnError);
return executeAndReturnIntArray(cmd, "banid");
}
/**
* Sends a text message to all clients on all virtual servers.
* These messages will appear to clients in the tab for server messages.
*
* @param message
* the message to be sent
*
* @return a future to track the progress of this command
*
* @throws TS3CommandFailedException
* if the execution of a command fails
* @querycommands 1
*/
public CommandFuture<Void> broadcast(String message) {
Command cmd = ServerCommands.gm(message);
return executeAndReturnError(cmd);
}
/**
* Creates a copy of the channel group specified by {@code sourceGroupId},
* overwriting any other channel group specified by {@code targetGroupId}.
* <p>
* The parameter {@code type} can be used to create server query and template groups.
* </p>
*
* @param sourceGroupId
* the ID of the channel group to copy
* @param targetGroupId
* the ID of another channel group to overwrite
* @param type
* the desired type of channel group
*
* @return a future to track the progress of this command
*
* @throws TS3CommandFailedException
* if the execution of a command fails
* @querycommands 1
* @see ChannelGroup#getId()
*/
public CommandFuture<Void> copyChannelGroup(int sourceGroupId, int targetGroupId, PermissionGroupDatabaseType type) {
if (targetGroupId <= 0) {
throw new IllegalArgumentException("To create a new channel group, use the method with a String argument");
}
Command cmd = ChannelGroupCommands.channelGroupCopy(sourceGroupId, targetGroupId, type);
return executeAndReturnError(cmd);
}
/**
* Creates a copy of the channel group specified by {@code sourceGroupId} with a given name
* and returns the ID of the newly created channel group.
*
* @param sourceGroupId
* the ID of the channel group to copy
* @param targetName
* the name for the copy of the channel group
* @param type
* the desired type of channel group
*
* @return the ID of the newly created channel group
*
* @throws TS3CommandFailedException
* if the execution of a command fails
* @querycommands 1
* @see ChannelGroup#getId()
*/
public CommandFuture<Integer> copyChannelGroup(int sourceGroupId, String targetName, PermissionGroupDatabaseType type) {
Command cmd = ChannelGroupCommands.channelGroupCopy(sourceGroupId, targetName, type);
return executeAndReturnIntProperty(cmd, "cgid");
}
/**
* Creates a copy of the server group specified by {@code sourceGroupId},
* overwriting another server group specified by {@code targetGroupId}.
* <p>
* The parameter {@code type} can be used to create server query and template groups.
* </p>
*
* @param sourceGroupId
* the ID of the server group to copy
* @param targetGroupId
* the ID of another server group to overwrite
* @param type
* the desired type of server group
*
* @return the ID of the newly created server group
*
* @throws TS3CommandFailedException
* if the execution of a command fails
* @querycommands 1
* @see ServerGroup#getId()
*/
public CommandFuture<Integer> copyServerGroup(int sourceGroupId, int targetGroupId, PermissionGroupDatabaseType type) {
if (targetGroupId <= 0) {
throw new IllegalArgumentException("To create a new server group, use the method with a String argument");
}
Command cmd = ServerGroupCommands.serverGroupCopy(sourceGroupId, targetGroupId, type);
return executeAndReturnIntProperty(cmd, "sgid");
}
/**
* Creates a copy of the server group specified by {@code sourceGroupId} with a given name
* and returns the ID of the newly created server group.
*
* @param sourceGroupId
* the ID of the server group to copy
* @param targetName
* the name for the copy of the server group
* @param type
* the desired type of server group
*
* @return the ID of the newly created server group
*
* @throws TS3CommandFailedException
* if the execution of a command fails
* @querycommands 1
* @see ServerGroup#getId()
*/
public CommandFuture<Integer> copyServerGroup(int sourceGroupId, String targetName, PermissionGroupDatabaseType type) {
Command cmd = ServerGroupCommands.serverGroupCopy(sourceGroupId, targetName, type);
return executeAndReturnIntProperty(cmd, "sgid");
}
/**
* Creates a new channel with a given name using the given properties and returns its ID.
*
* @param name
* the name for the new channel
* @param options
* a map of options that should be set for the channel
*
* @return the ID of the newly created channel
*
* @throws TS3CommandFailedException
* if the execution of a command fails
* @querycommands 1
* @see Channel
*/
public CommandFuture<Integer> createChannel(String name, Map<ChannelProperty, String> options) {
Command cmd = ChannelCommands.channelCreate(name, options);
return executeAndReturnIntProperty(cmd, "cid");
}
/**
* Creates a new directory on the file repository in the specified channel.
*
* @param directoryPath
* the path to the directory that should be created
* @param channelId
* the ID of the channel the directory should be created in
*
* @return a future to track the progress of this command
*
* @throws TS3CommandFailedException
* if the execution of a command fails
* @querycommands 1
* @see FileInfo#getPath()
* @see Channel#getId()
*/
public CommandFuture<Void> createFileDirectory(String directoryPath, int channelId) {
return createFileDirectory(directoryPath, channelId, null);
}
/**
* Creates a new directory on the file repository in the specified channel.
*
* @param directoryPath
* the path to the directory that should be created
* @param channelId
* the ID of the channel the directory should be created in
* @param channelPassword
* the password of that channel
*
* @return a future to track the progress of this command
*
* @throws TS3CommandFailedException
* if the execution of a command fails
* @querycommands 1
* @see FileInfo#getPath()
* @see Channel#getId()
*/
public CommandFuture<Void> createFileDirectory(String directoryPath, int channelId, String channelPassword) {
Command cmd = FileCommands.ftCreateDir(directoryPath, channelId, channelPassword);
return executeAndReturnError(cmd);
}
/**
* Creates a new virtual server with the given name and returns an object containing the ID of the newly
* created virtual server, the default server admin token and the virtual server's voice port. Usually,
* the virtual server is also automatically started. This can be turned off on the TS3 server, though.
* <p>
* If {@link VirtualServerProperty#VIRTUALSERVER_PORT} is not specified in the virtual server properties,
* the server will test for the first unused UDP port.
* </p><p>
* Please also note that creating virtual servers usually requires the server query admin account
* and that there is a limit to how many virtual servers can be created, which is dependent on your license.
* Unlicensed TS3 server instances are limited to 1 virtual server with up to 32 client slots.
* </p>
*
* @param name
* the name for the new virtual server
* @param options
* a map of options that should be set for the virtual server
*
* @return information about the newly created virtual server
*
* @throws TS3CommandFailedException
* if the execution of a command fails
* @querycommands 1
* @see VirtualServer
*/
public CommandFuture<CreatedVirtualServer> createServer(String name, Map<VirtualServerProperty, String> options) {
Command cmd = VirtualServerCommands.serverCreate(name, options);
return executeAndTransformFirst(cmd, CreatedVirtualServer::new);
}
/**
* Creates a {@link Snapshot} of the selected virtual server containing all settings,
* groups and known client identities. The data from a server snapshot can be
* used to restore a virtual servers configuration.
*
* @return a snapshot of the virtual server
*
* @throws TS3CommandFailedException
* if the execution of a command fails
* @querycommands 1
* @see #deployServerSnapshot(Snapshot)
*/
public CommandFuture<Snapshot> createServerSnapshot() {
Command cmd = VirtualServerCommands.serverSnapshotCreate();
CommandFuture<Snapshot> future = cmd.getFuture()
.map(result -> new Snapshot(result.getRawResponse()));
commandQueue.enqueueCommand(cmd);
return future;
}