forked from TheHolyWaffle/TeamSpeak-3-Java-API
-
Notifications
You must be signed in to change notification settings - Fork 1
/
TS3Api.java
1323 lines (1176 loc) · 38.1 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 java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import com.github.theholywaffle.teamspeak3.api.ChannelProperty;
import com.github.theholywaffle.teamspeak3.api.ClientProperty;
import com.github.theholywaffle.teamspeak3.api.PermissionGroupDatabaseType;
import com.github.theholywaffle.teamspeak3.api.ReasonIdentifier;
import com.github.theholywaffle.teamspeak3.api.ServerGroupType;
import com.github.theholywaffle.teamspeak3.api.ServerInstanceProperty;
import com.github.theholywaffle.teamspeak3.api.Snapshot;
import com.github.theholywaffle.teamspeak3.api.TextMessageTargetMode;
import com.github.theholywaffle.teamspeak3.api.VirtualServerProperty;
import com.github.theholywaffle.teamspeak3.api.event.TS3EventType;
import com.github.theholywaffle.teamspeak3.api.event.TS3Listener;
import com.github.theholywaffle.teamspeak3.api.wrapper.AdvancedPermission;
import com.github.theholywaffle.teamspeak3.api.wrapper.Ban;
import com.github.theholywaffle.teamspeak3.api.wrapper.Binding;
import com.github.theholywaffle.teamspeak3.api.wrapper.Channel;
import com.github.theholywaffle.teamspeak3.api.wrapper.ChannelGroup;
import com.github.theholywaffle.teamspeak3.api.wrapper.ChannelGroupClient;
import com.github.theholywaffle.teamspeak3.api.wrapper.ChannelInfo;
import com.github.theholywaffle.teamspeak3.api.wrapper.Client;
import com.github.theholywaffle.teamspeak3.api.wrapper.ClientInfo;
import com.github.theholywaffle.teamspeak3.api.wrapper.Complaint;
import com.github.theholywaffle.teamspeak3.api.wrapper.ConnectionInfo;
import com.github.theholywaffle.teamspeak3.api.wrapper.DatabaseClient;
import com.github.theholywaffle.teamspeak3.api.wrapper.DatabaseClientInfo;
import com.github.theholywaffle.teamspeak3.api.wrapper.HostInfo;
import com.github.theholywaffle.teamspeak3.api.wrapper.InstanceInfo;
import com.github.theholywaffle.teamspeak3.api.wrapper.Message;
import com.github.theholywaffle.teamspeak3.api.wrapper.Permission;
import com.github.theholywaffle.teamspeak3.api.wrapper.PermissionInfo;
import com.github.theholywaffle.teamspeak3.api.wrapper.PrivilegeKey;
import com.github.theholywaffle.teamspeak3.api.wrapper.ServerGroup;
import com.github.theholywaffle.teamspeak3.api.wrapper.ServerGroupClient;
import com.github.theholywaffle.teamspeak3.api.wrapper.ServerQueryInfo;
import com.github.theholywaffle.teamspeak3.api.wrapper.Version;
import com.github.theholywaffle.teamspeak3.api.wrapper.VirtualServer;
import com.github.theholywaffle.teamspeak3.api.wrapper.VirtualServerInfo;
import com.github.theholywaffle.teamspeak3.api.wrapper.Wrapper;
import com.github.theholywaffle.teamspeak3.commands.*;
public class TS3Api {
private final TS3Query query;
public TS3Api(TS3Query query) {
this.query = query;
}
/**
*
* Adds a new ban entry.
*
* @param ip
* target ip-adress, can be null
* @param name
* target name, can be null.
* @param uid
* target UID, can be null
* @param timeInSeconds
* the duration of the ban, 0 equals permanent
* @param reason
* the reason for the ban
* @return banid
*/
public int addBan(String ip, String name, String uid, long timeInSeconds,
String reason) {
final CBanAdd add = new CBanAdd(ip, name, uid, timeInSeconds, reason);
if (query.doCommand(add)) {
return StringUtil.getInt(add.getFirstResponse().get("banid"));
}
return -1;
}
public boolean addChannelClientPermission(int channelId, int clientDBId,
String permName, int permValue) {
final CChannelClientAddPerm add = new CChannelClientAddPerm(channelId,
clientDBId, permName, permValue);
if (query.doCommand(add)) {
return add.getError().isSuccessful();
}
return false;
}
public int addChannelGroup(String name) {
return addChannelGroup(name, null);
}
public int addChannelGroup(String name, PermissionGroupDatabaseType t) {
final CChannelGroupAdd add = new CChannelGroupAdd(name, t);
if (query.doCommand(add)) {
return StringUtil.getInt(add.getFirstResponse().get("cgid"));
}
return -1;
}
public boolean addChannelPermission(int channelId, String permName,
int permValue) {
final CChannelAddPerm perm = new CChannelAddPerm(channelId, permName,
permValue);
if (query.doCommand(perm)) {
return perm.getError().isSuccessful();
}
return false;
}
public boolean addClientPermission(int clientDBId, String permName,
int permValue, boolean permSkipped) {
final CClientAddPerm add = new CClientAddPerm(clientDBId, permName,
permValue, permSkipped);
if (query.doCommand(add)) {
return add.getError().isSuccessful();
}
return false;
}
public boolean addClientToServerGroup(int groupId, int clientDatabaseId) {
final CServerGroupAddClient add = new CServerGroupAddClient(groupId,
clientDatabaseId);
if (query.doCommand(add)) {
return add.getError().isSuccessful();
}
return false;
}
public boolean addComplain(int clientDBId, String text) {
final CComplainAdd add = new CComplainAdd(clientDBId, text);
if (query.doCommand(add)) {
return add.getError().isSuccessful();
}
return false;
}
public boolean addPermissionToAllServerGroups(ServerGroupType t,
String permName, int permValue, boolean permNegated,
boolean permSkipped) {
final CServerGroupAutoAddPerm add = new CServerGroupAutoAddPerm(t,
permName, permValue, permNegated, permSkipped);
if (query.doCommand(add)) {
return add.getError().isSuccessful();
}
return false;
}
public boolean addPermissionToChannelGroup(int groupId, String permName,
int permValue) {
final CChannelGroupAddPerm add = new CChannelGroupAddPerm(groupId,
permName, permValue);
if (query.doCommand(add)) {
return add.getError().isSuccessful();
}
return false;
}
public String addPrivilegeKey(int 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;
}
public String addPrivilegeKeyChannelGroup(int channelGroupId,
int channelId, String description) {
return addPrivilegeKey(1, channelGroupId, channelId, description);
}
public String addPrivilegeKeyServerGroup(int serverGroupId,
String description) {
return addPrivilegeKey(0, serverGroupId, 0, description);
}
public int addServerGroup(String name) {
return addServerGroup(name, PermissionGroupDatabaseType.REGULAR);
}
public int addServerGroup(String name, PermissionGroupDatabaseType t) {
final CServerGroupAdd add = new CServerGroupAdd(name, t);
if (query.doCommand(add)) {
return StringUtil.getInt(add.getFirstResponse().get("sgid"));
}
return -1;
}
public boolean addServerGroupPermission(int groupId, String permName,
int value, boolean negated, boolean skipped) {
final CServerGroupAddPerm add = new CServerGroupAddPerm(groupId,
permName, value, negated, skipped);
if (query.doCommand(add)) {
return add.getError().isSuccessful();
}
return false;
}
public void addTS3Listeners(TS3Listener... l) {
query.getEventManager().addListeners(l);
}
public int banClient(int clientId, long timeInSeconds) {
return banClient(clientId, timeInSeconds, null);
}
public int banClient(int clientId, long timeInSeconds, String reason) {
final CBanClient client = new CBanClient(clientId, timeInSeconds,
reason);
if (query.doCommand(client)) {
return StringUtil.getInt(client.getFirstResponse().get("banid"));
}
return -1;
}
public int banClient(int clientId, String reason) {
return banClient(clientId, 0, reason);
}
public boolean broadcast(String message) {
final CGM broadcast = new CGM(message);
if (query.doCommand(broadcast)) {
return broadcast.getError().isSuccessful();
}
return false;
}
public boolean copyChannelGroup(int sourceGroupId, int targetGroupId,
PermissionGroupDatabaseType t) {
final CChannelGroupCopy copy = new CChannelGroupCopy(sourceGroupId,
targetGroupId, t);
if (query.doCommand(copy)) {
return copy.getError().isSuccessful();
}
return false;
}
public int copyChannelGroup(int sourceGroupId, String targetName,
PermissionGroupDatabaseType t) {
final CChannelGroupCopy copy = new CChannelGroupCopy(sourceGroupId,
targetName, t);
if (query.doCommand(copy)) {
return StringUtil.getInt(copy.getFirstResponse().get("cgid"));
}
return -1;
}
public int copyServerGroup(int idSource, int idTarget,
PermissionGroupDatabaseType t) {
return copyServerGroup(idSource, idTarget, "ignored", t);
}
private int copyServerGroup(int idSource, int idTarget, String name,
PermissionGroupDatabaseType t) {
final CServerGroupCopy copy = new CServerGroupCopy(idSource, idTarget,
name, t);
if (query.doCommand(copy)) {
return StringUtil.getInt(copy.getFirstResponse().get("sgid"));
}
return -1;
}
public int copyServerGroup(int idSource, String name,
PermissionGroupDatabaseType t) {
return copyServerGroup(idSource, 0, name, t);
}
public int createChannel(String name,
HashMap<ChannelProperty, String> options) {
final CChannelCreate create = new CChannelCreate(name, options);
if (query.doCommand(create)) {
return StringUtil.getInt(create.getFirstResponse().get("cid"));
}
return -1;
}
public boolean createServer(String name,
HashMap<VirtualServerProperty, String> map) {
final CServerCreate create = new CServerCreate(name, map);
if (query.doCommand(create)) {
return create.getError().isSuccessful();
}
return false;
}
public String createServerQueryLogin(String name) {
final CClientSetServerQueryLogin login = new CClientSetServerQueryLogin(
name);
if (query.doCommand(login)) {
return login.getFirstResponse().get("client_login_password");
}
return null;
}
public Snapshot createServerSnapshot() {
final CServerSnapshotCreate create = new CServerSnapshotCreate();
if (query.doCommand(create)) {
return new Snapshot(create.getRaw());
}
return null;
}
public boolean deleteAllBans() {
final CBanDelAll del = new CBanDelAll();
if (query.doCommand(del)) {
return del.getError().isSuccessful();
}
return false;
}
public boolean deleteAllComplaints(int clientDBId) {
final CComplainDelAll del = new CComplainDelAll(clientDBId);
if (query.doCommand(del)) {
return del.getError().isSuccessful();
}
return false;
}
public boolean deleteBan(int banId) {
final CBanDel del = new CBanDel(banId);
if (query.doCommand(del)) {
return del.getError().isSuccessful();
}
return false;
}
public boolean deleteChannel(int channelId) {
final CChannelDelete del = new CChannelDelete(channelId, true);
if (query.doCommand(del)) {
return del.getError().isSuccessful();
}
return false;
}
public boolean deleteChannelClientPermission(int channelId, int clientDBId,
String permName) {
final CChannelClientDelPerm del = new CChannelClientDelPerm(channelId,
clientDBId, permName);
if (query.doCommand(del)) {
return del.getError().isSuccessful();
}
return false;
}
public boolean deleteChannelGroup(int groupId) {
final CChannelGroupDel del = new CChannelGroupDel(groupId, true);
if (query.doCommand(del)) {
return del.getError().isSuccessful();
}
return false;
}
public boolean deleteChannelGroupPermission(int groupId, String permName) {
final CChannelGroupDelPerm del = new CChannelGroupDelPerm(groupId,
permName);
if (query.doCommand(del)) {
return del.getError().isSuccessful();
}
return false;
}
public boolean deleteChannelPermission(int channelId, String permName) {
final CChannelDelPerm del = new CChannelDelPerm(channelId, permName);
if (query.doCommand(del)) {
return del.getError().isSuccessful();
}
return false;
}
public boolean deleteClientPermission(int clientDBId, String permName) {
final CClientDelPerm del = new CClientDelPerm(clientDBId, permName);
if (query.doCommand(del)) {
return del.getError().isSuccessful();
}
return false;
}
public boolean deleteComplaint(int targetClientDBId, int fromClientDBId) {
final CComplainDel del = new CComplainDel(targetClientDBId,
fromClientDBId);
if (query.doCommand(del)) {
return del.getError().isSuccessful();
}
return false;
}
public boolean deleteDatabaseClientProperties(int clientDBId) {
final CClientDBDelete del = new CClientDBDelete(clientDBId);
if (query.doCommand(del)) {
return del.getError().isSuccessful();
}
return false;
}
public boolean deleteOfflineMessage(int messageId) {
final CMessageDel del = new CMessageDel(messageId);
if (query.doCommand(del)) {
return del.getError().isSuccessful();
}
return false;
}
public boolean deletePermissionFromAllServerGroups(ServerGroupType t,
String permName) {
final CServerGroupAutoDelPerm del = new CServerGroupAutoDelPerm(t,
permName);
if (query.doCommand(del)) {
return del.getError().isSuccessful();
}
return false;
}
public boolean deletePrivilegeKey(String token) {
final CPrivilegeKeyDelete del = new CPrivilegeKeyDelete(token);
if (query.doCommand(del)) {
return del.getError().isSuccessful();
}
return false;
}
public boolean deleteServer(int id) {
final CServerDelete delete = new CServerDelete(id);
if (query.doCommand(delete)) {
return delete.getError().isSuccessful();
}
return false;
}
public boolean deleteServerGroup(int id) {
return deleteServerGroup(id, true);
}
public boolean deleteServerGroup(int id, boolean forced) {
final CServerGroupDel del = new CServerGroupDel(id, forced);
if (query.doCommand(del)) {
return del.getError().isSuccessful();
}
return false;
}
public boolean deleteServerGroupPermission(int groupId, String permName) {
final CServerGroupDelPerm del = new CServerGroupDelPerm(groupId,
permName);
if (query.doCommand(del)) {
return del.getError().isSuccessful();
}
return false;
}
public boolean deployServerSnapshot(Snapshot snapshot) {
final CServerSnapshotDeploy deploy = new CServerSnapshotDeploy(
snapshot.get());
if (query.doCommand(deploy)) {
return deploy.getError().isSuccessful();
}
return false;
}
public boolean editChannel(int channelId,
HashMap<ChannelProperty, String> options) {
final CChannelEdit edit = new CChannelEdit(channelId, options);
if (query.doCommand(edit)) {
return edit.getError().isSuccessful();
}
return false;
}
/**
* So far only ClientProperty.CLIENT_DESCRIPTION seems to be a correct
* ClientProperty. Others don't.
*/
public void editClient(int clientId, HashMap<ClientProperty, String> options) {
final CClientEdit edit = new CClientEdit(clientId, options);
query.doCommand(edit);
}
public boolean editDatabaseClient(int clientDBId,
HashMap<ClientProperty, String> options) {
final CClientDBEdit edit = new CClientDBEdit(clientDBId, options);
if (query.doCommand(edit)) {
return edit.getError().isSuccessful();
}
return false;
}
public boolean editInstance(ServerInstanceProperty p, String value) {
if (p.isChangeable()) {
final CInstanceEdit edit = new CInstanceEdit(p, value);
if (query.doCommand(edit)) {
return edit.getError().isSuccessful();
}
}
return false;
}
public boolean editServer(HashMap<VirtualServerProperty, String> map) {
final CServerEdit edit = new CServerEdit(map);
if (query.doCommand(edit)) {
return edit.getError().isSuccessful();
}
return false;
}
public List<Ban> getBans() {
final CBanList list = new CBanList();
if (query.doCommand(list)) {
final List<Ban> bans = new ArrayList<>();
for (final HashMap<String, String> opt : list.getResponse()) {
bans.add(new Ban(opt));
}
return bans;
}
return null;
}
public List<Binding> getBindings() {
final CBindingList list = new CBindingList();
if (query.doCommand(list)) {
final List<Binding> bindings = new ArrayList<>();
for (final HashMap<String, String> map : list.getResponse()) {
bindings.add(new Binding(map));
}
return bindings;
}
return null;
}
public Channel getChannelByName(String name) {
final CChannelFind find = new CChannelFind(name);
if (query.doCommand(find)) {
for (final Channel c : getChannels()) {
if (c.getId() == StringUtil.getInt(find.getFirstResponse().get(
"cid"))) {
return c;
}
}
}
return null;
}
public List<Permission> getChannelClientPermissions(int channelId,
int clientDBId) {
final CChannelClientPermList list = new CChannelClientPermList(
channelId, clientDBId);
if (query.doCommand(list)) {
final List<Permission> permissions = new ArrayList<>();
for (final HashMap<String, String> opt : list.getResponse()) {
permissions.add(new Permission(opt));
}
return permissions;
}
return null;
}
/**
* Use -1 to ingore an argument.
*
*/
public List<ChannelGroupClient> getChannelGroupClients(int channelId,
int clientDBId, int groupId) {
final CChannelGroupClientList list = new CChannelGroupClientList(
channelId, clientDBId, groupId);
if (query.doCommand(list)) {
final List<ChannelGroupClient> clients = new ArrayList<>();
for (final HashMap<String, String> opt : list.getResponse()) {
clients.add(new ChannelGroupClient(opt));
}
return clients;
}
return null;
}
public List<ChannelGroupClient> getChannelGroupClientsByChannelGroupId(
int groupId) {
return getChannelGroupClients(-1, -1, groupId);
}
public List<ChannelGroupClient> getChannelGroupClientsByChannelId(
int channelId) {
return getChannelGroupClients(channelId, -1, -1);
}
public List<ChannelGroupClient> getChannelGroupClientsByClientDBId(
int clientDBId) {
return getChannelGroupClients(-1, clientDBId, -1);
}
public List<Permission> getChannelGroupPermissions(int groupId) {
final CChannelGroupPermList list = new CChannelGroupPermList(groupId);
if (query.doCommand(list)) {
final List<Permission> p = new ArrayList<>();
for (final HashMap<String, String> opt : list.getResponse()) {
p.add(new Permission(opt));
}
return p;
}
return null;
}
public List<ChannelGroup> getChannelGroups() {
final CChannelGroupList list = new CChannelGroupList();
if (query.doCommand(list)) {
final List<ChannelGroup> groups = new ArrayList<>();
for (final HashMap<String, String> opt : list.getResponse()) {
groups.add(new ChannelGroup(opt));
}
return groups;
}
return null;
}
public ChannelInfo getChannelInfo(int channelId) {
final CChannelInfo info = new CChannelInfo(channelId);
if (query.doCommand(info)) {
return new ChannelInfo(info.getFirstResponse().getMap());
}
return null;
}
public List<Permission> getChannelPermissions(int channelId) {
final CChannelPermList list = new CChannelPermList(channelId);
if (query.doCommand(list)) {
final List<Permission> p = new ArrayList<>();
for (final HashMap<String, String> opt : list.getResponse()) {
p.add(new Permission(opt));
}
return p;
}
return null;
}
public List<Channel> getChannels() {
final CChannelList list = new CChannelList();
if (query.doCommand(list)) {
final List<Channel> channels = new ArrayList<>();
for (final HashMap<String, String> opt : list.getResponse()) {
channels.add(new Channel(opt));
}
return channels;
}
return null;
}
public List<Client> getClientByName(String pattern) {
final CClientFind find = new CClientFind(pattern);
if (query.doCommand(find)) {
final List<Client> clients = new ArrayList<>();
for (final Client c : getClients()) {
for (final HashMap<String, String> opt : find.getResponse()) {
if (c.getId() == StringUtil.getInt(new Wrapper(opt)
.get("clid"))) {
clients.add(c);
}
}
}
return clients;
}
return null;
}
public ClientInfo getClientByUId(String clientUId) {
final CClientGetIds get = new CClientGetIds(clientUId);
if (query.doCommand(get)) {
return getClientInfo(StringUtil.getInt(get.getFirstResponse()
.getMap().get("clid")));
}
return null;
}
public ClientInfo getClientInfo(int clientId) {
final CClientInfo info = new CClientInfo(clientId);
if (query.doCommand(info)) {
return new ClientInfo(info.getFirstResponse().getMap());
}
return null;
}
public List<Permission> getClientPermissions(int clientDBId) {
final CClientPermList list = new CClientPermList(clientDBId);
if (query.doCommand(list)) {
final List<Permission> permissions = new ArrayList<>();
for (final HashMap<String, String> opt : list.getResponse()) {
permissions.add(new Permission(opt));
}
return permissions;
}
return null;
}
public List<Client> getClients() {
final CClientList list = new CClientList();
if (query.doCommand(list)) {
final List<Client> clients = new ArrayList<>();
for (final HashMap<String, String> opt : list.getResponse()) {
clients.add(new Client(opt));
}
return clients;
}
return null;
}
public List<Complaint> getComplaints() {
return getComplaints(-1);
}
public List<Complaint> getComplaints(int clientDBId) {
final CComplainList list = new CComplainList(clientDBId);
if (query.doCommand(list)) {
final List<Complaint> complaints = new ArrayList<>();
for (final HashMap<String, String> opt : list.getResponse()) {
complaints.add(new Complaint(opt));
}
return complaints;
}
return null;
}
public ConnectionInfo getConnectionInfo() {
final CServerRequestConnectionInfo info = new CServerRequestConnectionInfo();
if (query.doCommand(info)) {
return new ConnectionInfo(info.getFirstResponse().getMap());
}
return null;
}
public DatabaseClientInfo getDatabaseClientByName(String name) {
final CClientDBFind find = new CClientDBFind(name, false);
if (query.doCommand(find)) {
return getDatabaseClientInfo(StringUtil.getInt(find
.getFirstResponse().get("cldbid")));
}
return null;
}
public DatabaseClientInfo getDatabaseClientByUId(String clientUId) {
final CClientGetDBIdFromUId get = new CClientGetDBIdFromUId(clientUId);
if (query.doCommand(get)) {
return getDatabaseClientInfo(StringUtil.getInt(get
.getFirstResponse().get("cldbid")));
}
return null;
}
public DatabaseClientInfo getDatabaseClientInfo(int clientDBId) {
final CClientDBInfo info = new CClientDBInfo(clientDBId);
if (query.doCommand(info)) {
return new DatabaseClientInfo(info.getFirstResponse().getMap());
}
return null;
}
/**
* Be warned, this method takes quite some time to execute.
*/
public List<DatabaseClient> getDatabaseClients() {
final CClientDBList countList = new CClientDBList(0, 1, true);
if (query.doCommand(countList)) {
final int count = StringUtil.getInt(countList.getFirstResponse()
.get("count"));
int i = 0;
final List<DatabaseClient> clients = new ArrayList<>(count);
while (i < count) {
final CClientDBList list = new CClientDBList(i, 200, false);
if (query.doCommand(list)) {
for (final HashMap<String, String> map : list.getResponse()) {
clients.add(new DatabaseClient(map));
}
}
i += 200;
}
return clients;
}
return null;
}
public HostInfo getHostInfo() {
final CHostInfo info = new CHostInfo();
if (query.doCommand(info)) {
return new HostInfo(info.getFirstResponse().getMap());
}
return null;
}
public InstanceInfo getInstanceInfo() {
final CInstanceInfo info = new CInstanceInfo();
if (query.doCommand(info)) {
return new InstanceInfo(info.getFirstResponse().getMap());
}
return null;
}
public String getOfflineMessage(int messageId) {
final CMessageGet get = new CMessageGet(messageId);
if (query.doCommand(get)) {
return get.getFirstResponse().get("message");
}
return null;
}
public List<Message> getOfflineMessages() {
final CMessageList list = new CMessageList();
if (query.doCommand(list)) {
final List<Message> msg = new ArrayList<>();
for (final HashMap<String, String> opt : list.getResponse()) {
msg.add(new Message(opt));
}
return msg;
}
return null;
}
public List<AdvancedPermission> getPermissionAssignments(String permName) {
final CPermFind find = new CPermFind(permName);
if (query.doCommand(find)) {
final List<AdvancedPermission> assignments = new ArrayList<>();
for (final HashMap<String, String> opt : find.getResponse()) {
assignments.add(new AdvancedPermission(opt));
}
return assignments;
}
return null;
}
public int getPermissionIdByName(String permName) {
final CPermIdGetByName get = new CPermIdGetByName(permName);
if (query.doCommand(get)) {
return StringUtil.getInt(get.getFirstResponse().get("permid"));
}
return -1;
}
public List<AdvancedPermission> getPermissionOverview(int channelId,
int clientDBId) {
final CPermOverview overview = new CPermOverview(channelId, clientDBId);
if (query.doCommand(overview)) {
final List<AdvancedPermission> permissions = new ArrayList<>();
for (final HashMap<String, String> opt : overview.getResponse()) {
permissions.add(new AdvancedPermission(opt));
}
return permissions;
}
return null;
}
public List<PermissionInfo> getPermissions() {
final CPermissionList list = new CPermissionList();
if (query.doCommand(list)) {
final List<PermissionInfo> permissions = new ArrayList<>();
for (final HashMap<String, String> opt : list.getResponse()) {
permissions.add(new PermissionInfo(opt));
}
return permissions;
}
return null;
}
public int getPermissionValue(String permName) {
final CPermGet get = new CPermGet(permName);
if (query.doCommand(get)) {
return StringUtil.getInt(get.getFirstResponse().get("permvalue"));
}
return -1;
}
public List<PrivilegeKey> getPrivilegeKeys() {
final CPrivilegeKeyList list = new CPrivilegeKeyList();
if (query.doCommand(list)) {
final List<PrivilegeKey> keys = new ArrayList<>();
for (final HashMap<String, String> opt : list.getResponse()) {
keys.add(new PrivilegeKey(opt));
}
return keys;
}
return null;
}
public List<ServerGroupClient> getServerGroupClients(int groupId) {
final CServerGroupClientList list = new CServerGroupClientList(groupId);
if (query.doCommand(list)) {
final List<ServerGroupClient> clients = new ArrayList<>();
for (final HashMap<String, String> opt : list.getResponse()) {
clients.add(new ServerGroupClient(opt));
}
return clients;
}
return null;
}
public List<Permission> getServerGroupPermissions(int id) {
final CServerGroupPermList list = new CServerGroupPermList(id);
if (query.doCommand(list)) {
final List<Permission> p = new ArrayList<>();
for (final HashMap<String, String> opt : list.getResponse()) {
p.add(new Permission(opt));
}
return p;
}
return null;
}
public List<ServerGroup> getServerGroups() {
final CServerGroupList list = new CServerGroupList();
if (query.doCommand(list)) {
final List<ServerGroup> groups = new ArrayList<>();
for (final HashMap<String, String> opt : list.getResponse()) {
groups.add(new ServerGroup(opt));
}
return groups;
}
return null;
}
public List<ServerGroup> getServerGroupsByClientId(int clientDatabaseId) {
final CServerGroupsByClientId client = new CServerGroupsByClientId(
clientDatabaseId);
if (query.doCommand(client)) {
final List<ServerGroup> list = new ArrayList<>();
final List<ServerGroup> allGroups = getServerGroups();
for (final HashMap<String, String> opt : client.getResponse()) {
for (final ServerGroup s : allGroups) {
if (s.getId() == StringUtil.getInt(opt.get("sgid"))) {
list.add(s);
}
}
}
return list;
}
return null;
}
public int getServerIdByPort(int port) {
final CServerIdGetByPort s = new CServerIdGetByPort(port);
if (query.doCommand(s)) {
return StringUtil.getInt(s.getFirstResponse().get("server_id"));
}
return -1;
}
public VirtualServerInfo getServerInfo() {
final CServerInfo info = new CServerInfo();
if (query.doCommand(info)) {
return new VirtualServerInfo(info.getFirstResponse().getMap());
}
return null;
}
public Version getVersion() {
final CVersion version = new CVersion();
if (query.doCommand(version)) {
return new Version(version.getFirstResponse().getMap());
}
return null;
}
public List<VirtualServer> getVirtualServers() {
final CServerList serverList = new CServerList();
if (query.doCommand(serverList)) {
final ArrayList<VirtualServer> servers = new ArrayList<>();
for (final HashMap<String, String> opt : serverList.getResponse()) {
servers.add((new VirtualServer(opt)));
}
return servers;
}
return null;
}
public boolean kickClientFromChannel(int... clientIds) {
return kickClients(ReasonIdentifier.REASON_KICK_CHANNEL, null,
clientIds);
}