forked from TheHolyWaffle/TeamSpeak-3-Java-API
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TS3Api.java
4720 lines (4449 loc) · 142 KB
/
TS3Api.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.TS3ConnectionFailedException;
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.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.regex.Pattern;
/**
* API to interact with the {@link TS3Query} synchronously.
* <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 synchronous, so they will block until the response arrives.
* Calls to this API will usually take about 50 milliseconds to complete (plus ping),
* but delays can range up to 4 seconds.
* If a command takes longer than 4 seconds to complete, a {@link TS3ConnectionFailedException}
* will be thrown.
* </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><p>
* Be aware that many methods in this class will return {@code null} or {@code -1} if a command fails.
* </p>
*
* @see TS3ApiAsync The asynchronous version of the API
*/
public class TS3Api {
/**
* The TS3 query to which this API sends its commands.
*/
private final TS3Query query;
/**
* Creates a new synchronous API object for the given {@code TS3Query}.
* <p>
* <b>Usually, this constructor should not be called.</b> Use {@link TS3Query#getApi()} instead.
* </p>
*
* @param query
* the TS3Query to call
*/
public TS3Api(TS3Query query) {
this.query = query;
}
/**
* Adds a new ban entry. At least one of the parameters {@code ip}, {@code name} or {@code uid} needs to be not null.
* Returns the ID of the newly created ban.
*
* @param ip
* a RegEx pattern to match a client's IP against, can be null
* @param name
* a RegEx pattern to match a client's name against, can be null
* @param uid
* the unique identifier of a client, can be null
* @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 the ID of the newly created ban entry
*
* @querycommands 1
* @see Pattern RegEx Pattern
* @see Client#getId()
* @see Client#getUniqueIdentifier()
* @see ClientInfo#getIp()
*/
public int addBan(String ip, String name, String uid, long timeInSeconds, String reason) {
if (ip == null && name == null && uid == null) {
throw new IllegalArgumentException("Either IP, Name or UID must be set");
}
final CBanAdd add = new CBanAdd(ip, name, uid, timeInSeconds, reason);
if (query.doCommand(add)) {
return add.getFirstResponse().getInt("banid");
}
return -1;
}
/**
* 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 whether the command succeeded or not
*
* @querycommands 1
* @see Channel#getId()
* @see Client#getDatabaseId()
* @see Permission
*/
public boolean addChannelClientPermission(int channelId, int clientDBId, String permName, int permValue) {
final CChannelClientAddPerm add = new CChannelClientAddPerm(channelId, clientDBId, permName, permValue);
return query.doCommand(add);
}
/**
* 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
*
* @querycommands 1
* @see ChannelGroup
*/
public int 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
*
* @querycommands 1
* @see ChannelGroup
*/
public int addChannelGroup(String name, PermissionGroupDatabaseType type) {
final CChannelGroupAdd add = new CChannelGroupAdd(name, type);
if (query.doCommand(add)) {
return add.getFirstResponse().getInt("cgid");
}
return -1;
}
/**
* 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 whether the command succeeded or not
*
* @querycommands 1
* @see ChannelGroup#getId()
* @see Permission
*/
public boolean addChannelGroupPermission(int groupId, String permName, int permValue) {
final CChannelGroupAddPerm add = new CChannelGroupAddPerm(groupId, permName, permValue);
return query.doCommand(add);
}
/**
* 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 whether the command succeeded or not
*
* @querycommands 1
* @see Channel#getId()
* @see Permission
*/
public boolean addChannelPermission(int channelId, String permName, int permValue) {
final CChannelAddPerm perm = new CChannelAddPerm(channelId, permName, permValue);
return query.doCommand(perm);
}
/**
* Adds a specified permission to a channel.
*
* @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 whether the command succeeded or not
*
* @querycommands 1
* @see Client#getDatabaseId()
* @see Permission
*/
public boolean addClientPermission(int clientDBId, String permName, int value, boolean skipped) {
final CClientAddPerm add = new CClientAddPerm(clientDBId, permName, value, skipped);
return query.doCommand(add);
}
/**
* 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 whether the command succeeded or not
*
* @querycommands 1
* @see ServerGroup#getId()
* @see Client#getDatabaseId()
*/
public boolean addClientToServerGroup(int groupId, int clientDatabaseId) {
final CServerGroupAddClient add = new CServerGroupAddClient(groupId, clientDatabaseId);
return query.doCommand(add);
}
/**
* 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 whether the command succeeded or not
*
* @querycommands 1
* @see Client#getDatabaseId()
* @see Complaint#getMessage()
*/
public boolean addComplaint(int clientDBId, String message) {
final CComplainAdd add = new CComplainAdd(clientDBId, message);
return query.doCommand(add);
}
/**
* 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 whether the command succeeded or not
*
* @querycommands 1
* @see ServerGroupType
* @see Permission
*/
public boolean addPermissionToAllServerGroups(ServerGroupType type, String permName, int value, boolean negated, boolean skipped) {
final CServerGroupAutoAddPerm add = new CServerGroupAutoAddPerm(type, permName, value, negated, skipped);
return query.doCommand(add);
}
/**
* 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
*
* @querycommands 1
* @see PrivilegeKeyType
* @see #addPrivilegeKeyServerGroup(int, String)
* @see #addPrivilegeKeyChannelGroup(int, int, String)
*/
public String addPrivilegeKey(PrivilegeKeyType type, int groupId, int channelId, String description) {
final CPrivilegeKeyAdd add = new CPrivilegeKeyAdd(type, groupId, channelId, description);
if (query.doCommand(add)) {
return add.getFirstResponse().get("token");
}
return null;
}
/**
* 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
*
* @querycommands 1
* @see ChannelGroup#getId()
* @see Channel#getId()
* @see #addPrivilegeKey(PrivilegeKeyType, int, int, String)
* @see #addPrivilegeKeyServerGroup(int, String)
*/
public 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
*
* @querycommands 1
* @see ServerGroup#getId()
* @see #addPrivilegeKey(PrivilegeKeyType, int, int, String)
* @see #addPrivilegeKeyChannelGroup(int, int, String)
*/
public 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
*
* @querycommands 1
* @see ServerGroup
*/
public int 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
*
* @querycommands 1
* @see ServerGroup
* @see PermissionGroupDatabaseType
*/
public int addServerGroup(String name, PermissionGroupDatabaseType type) {
final CServerGroupAdd add = new CServerGroupAdd(name, type);
if (query.doCommand(add)) {
return add.getFirstResponse().getInt("sgid");
}
return -1;
}
/**
* 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 whether the command succeeded or not
*
* @querycommands 1
* @see ServerGroup#getId()
* @see Permission
*/
public boolean addServerGroupPermission(int groupId, String permName, int value, boolean negated, boolean skipped) {
final CServerGroupAddPerm add = new CServerGroupAddPerm(groupId, permName, value, negated, skipped);
return query.doCommand(add);
}
/**
* 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 two separate ban rules,
* one for the targeted client's IP address and their unique identifier.
* </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
* and the returned array will only have 1 entry.
* </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 first and the second ban entry
*
* @querycommands 1
* @see Client#getId()
* @see #addBan(String, String, String, long, String)
*/
public 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 two separate ban rules,
* one for the targeted client's IP address and their unique identifier.
* </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
* and the returned array will only have 1 entry.
* </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 first and the second ban entry
*
* @querycommands 1
* @see Client#getId()
* @see #addBan(String, String, String, long, String)
*/
public int[] banClient(int clientId, long timeInSeconds, String reason) {
final CBanClient client = new CBanClient(clientId, timeInSeconds, reason);
if (query.doCommand(client)) {
final List<Wrapper> response = client.getResponse();
final int[] banIds = new int[response.size()];
for (int i = 0; i < banIds.length; ++i) {
banIds[i] = response.get(i).getInt("banid");
}
return banIds;
}
return null;
}
/**
* Bans a client with a given client ID permanently for the specified reason.
* <p>
* Please note that this will create two separate ban rules,
* one for the targeted client's IP address and their unique identifier.
* </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
* and the returned array will only have 1 entry.
* </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 first and the second ban entry
*
* @querycommands 1
* @see Client#getId()
* @see #addBan(String, String, String, long, String)
*/
public int[] banClient(int clientId, String reason) {
return banClient(clientId, 0, reason);
}
/**
* 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 whether the command succeeded or not
*
* @querycommands 1
*/
public boolean broadcast(String message) {
final CGM broadcast = new CGM(message);
return query.doCommand(broadcast);
}
/**
* 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 whether the command succeeded or not
*
* @querycommands 1
* @see ChannelGroup#getId()
*/
public boolean 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");
}
final CChannelGroupCopy copy = new CChannelGroupCopy(sourceGroupId, targetGroupId, type);
return query.doCommand(copy);
}
/**
* 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
*
* @querycommands 1
* @see ChannelGroup#getId()
*/
public int copyChannelGroup(int sourceGroupId, String targetName, PermissionGroupDatabaseType type) {
final CChannelGroupCopy copy = new CChannelGroupCopy(sourceGroupId, targetName, type);
if (query.doCommand(copy)) {
return copy.getFirstResponse().getInt("cgid");
}
return -1;
}
/**
* 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 whether the command succeeded or not
*
* @querycommands 1
* @see ServerGroup#getId()
*/
public boolean 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");
}
final CServerGroupCopy copy = new CServerGroupCopy(sourceGroupId, targetGroupId, type);
return query.doCommand(copy);
}
/**
* 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
*
* @querycommands 1
* @see ServerGroup#getId()
*/
public int copyServerGroup(int sourceGroupId, String targetName, PermissionGroupDatabaseType type) {
final CServerGroupCopy copy = new CServerGroupCopy(sourceGroupId, targetName, type);
if (query.doCommand(copy)) {
return copy.getFirstResponse().getInt("sgid");
}
return -1;
}
/**
* 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
*
* @querycommands 1
* @see Channel
*/
public int createChannel(String name, Map<ChannelProperty, String> options) {
final CChannelCreate create = new CChannelCreate(name, options);
if (query.doCommand(create)) {
return create.getFirstResponse().getInt("cid");
}
return -1;
}
/**
* 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 whether the command succeeded or not
*
* @querycommands 1
* @see FileInfo#getPath()
* @see Channel#getId()
*/
public boolean 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 whether the command succeeded or not
*
* @querycommands 1
* @see FileInfo#getPath()
* @see Channel#getId()
*/
public boolean createFileDirectory(String directoryPath, int channelId, String channelPassword) {
final CFtCreateDir create = new CFtCreateDir(directoryPath, channelId, channelPassword);
return query.doCommand(create);
}
/**
* 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
*
* @querycommands 1
* @see VirtualServer
*/
public CreatedVirtualServer createServer(String name, Map<VirtualServerProperty, String> options) {
final CServerCreate create = new CServerCreate(name, options);
if (query.doCommand(create)) {
return new CreatedVirtualServer(create.getFirstResponse().getMap());
}
return null;
}
/**
* 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
*
* @querycommands 1
* @see #deployServerSnapshot(Snapshot)
*/
public Snapshot createServerSnapshot() {
final CServerSnapshotCreate create = new CServerSnapshotCreate();
if (query.doCommand(create)) {
return new Snapshot(create.getRawResponse());
}
return null;
}
/**
* Deletes all active ban rules from the server. Use with caution.
*
* @return whether the command succeeded or not
*
* @querycommands 1
*/
public boolean deleteAllBans() {
final CBanDelAll del = new CBanDelAll();
return query.doCommand(del);
}
/**
* Deletes all complaints about the client with specified database ID from the server.
*
* @param clientDBId
* the database ID of the client
*
* @return whether the command succeeded or not
*
* @querycommands 1
* @see Client#getDatabaseId()
* @see Complaint
*/
public boolean deleteAllComplaints(int clientDBId) {
final CComplainDelAll del = new CComplainDelAll(clientDBId);
return query.doCommand(del);
}
/**
* Deletes the ban rule with the specified ID from the server.
*
* @param banId
* the ID of the ban to delete
*
* @return whether the command succeeded or not
*
* @querycommands 1
* @see Ban#getId()
*/
public boolean deleteBan(int banId) {
final CBanDel del = new CBanDel(banId);
return query.doCommand(del);
}
/**
* Deletes an existing channel specified by its ID, kicking all clients out of the channel.
*
* @param channelId
* the ID of the channel to delete
*
* @return whether the command succeeded or not
*
* @querycommands 1
* @see Channel#getId()
* @see #deleteChannel(int, boolean)
* @see #kickClientFromChannel(String, int...)
*/
public boolean deleteChannel(int channelId) {
return deleteChannel(channelId, true);
}
/**
* Deletes an existing channel with a given ID.
* If {@code force} is true, the channel will be deleted even if there are clients within,
* else the command will fail in this situation.
*
* @param channelId
* the ID of the channel to delete
* @param force
* whether clients should be kicked out of the channel
*
* @return whether the command succeeded or not
*
* @querycommands 1
* @see Channel#getId()
* @see #kickClientFromChannel(String, int...)
*/
public boolean deleteChannel(int channelId, boolean force) {
final CChannelDelete del = new CChannelDelete(channelId, force);
return query.doCommand(del);
}
/**
* Removes a specified permission from a client in a specific channel.
*
* @param channelId
* the ID of the channel wherein the permission should be removed
* @param clientDBId
* the database ID of the client
* @param permName
* the name of the permission to revoke
*
* @return whether the command succeeded or not
*
* @querycommands 1
* @see Channel#getId()
* @see Client#getDatabaseId()
* @see Permission#getName()
*/
public boolean deleteChannelClientPermission(int channelId, int clientDBId, String permName) {
final CChannelClientDelPerm del = new CChannelClientDelPerm(channelId, clientDBId, permName);
return query.doCommand(del);
}
/**
* Removes the channel group with the given ID.
*
* @param groupId
* the ID of the channel group
*
* @return whether the command succeeded or not
*
* @querycommands 1
* @see ChannelGroup#getId()
*/
public boolean deleteChannelGroup(int groupId) {
return deleteChannelGroup(groupId, true);
}
/**
* Removes the channel group with the given ID.
* If {@code force} is true, the channel group will be deleted even if it still contains clients,
* else the command will fail in this situation.
*
* @param groupId
* the ID of the channel group
* @param force
* whether the channel group should be deleted even if it still contains clients
*
* @return whether the command succeeded or not
*
* @querycommands 1
* @see ChannelGroup#getId()
*/
public boolean deleteChannelGroup(int groupId, boolean force) {
final CChannelGroupDel del = new CChannelGroupDel(groupId, force);
return query.doCommand(del);
}
/**
* Removes a permission from the channel group with the given ID.
*
* @param groupId
* the ID of the channel group
* @param permName
* the name of the permission to revoke
*
* @return whether the command succeeded or not
*
* @querycommands 1
* @see ChannelGroup#getId()
* @see Permission#getName()
*/
public boolean deleteChannelGroupPermission(int groupId, String permName) {
final CChannelGroupDelPerm del = new CChannelGroupDelPerm(groupId, permName);
return query.doCommand(del);
}
/**
* Removes a permission from the channel with the given ID.
*
* @param channelId
* the ID of the channel
* @param permName
* the name of the permission to revoke
*
* @return whether the command succeeded or not
*
* @querycommands 1
* @see Channel#getId()
* @see Permission#getName()
*/
public boolean deleteChannelPermission(int channelId, String permName) {
final CChannelDelPerm del = new CChannelDelPerm(channelId, permName);
return query.doCommand(del);
}
/**
* Removes a permission from a client.
*
* @param clientDBId
* the database ID of the client
* @param permName
* the name of the permission to revoke
*
* @return whether the command succeeded or not
*
* @querycommands 1
* @see Client#getDatabaseId()
* @see Permission#getName()
*/
public boolean deleteClientPermission(int clientDBId, String permName) {
final CClientDelPerm del = new CClientDelPerm(clientDBId, permName);
return query.doCommand(del);
}
/**
* Deletes the complaint about the client with database ID {@code targetClientDBId} submitted by