-
Notifications
You must be signed in to change notification settings - Fork 110
/
Client.java
249 lines (207 loc) · 6.86 KB
/
Client.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
package com.github.theholywaffle.teamspeak3.api.wrapper;
/*
* #%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.ClientProperty;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Date;
import java.util.Map;
public class Client extends Wrapper {
public Client(Map<String, String> map) {
super(map);
}
public boolean canTalk() {
return getBoolean(ClientProperty.CLIENT_IS_TALKER);
}
public String getAwayMessage() {
return get(ClientProperty.CLIENT_AWAY_MESSAGE);
}
public String[] getBadgeGUIDs() {
String raw = get(ClientProperty.CLIENT_BADGES);
String[] properties = raw.split("[\\s:;]");
for (String property : properties) {
if (!property.startsWith("badges=")) continue;
String commaSepBadges = property.substring("badges=".length());
return commaSepBadges.split(",");
}
return new String[0];
}
public int getChannelGroupId() {
return getInt(ClientProperty.CLIENT_CHANNEL_GROUP_ID);
}
public int getChannelId() {
return getInt(ClientProperty.CID);
}
/**
* Utility method. This method will return a client URI.
* A client URI can be used to reference a client in descriptions or just via chat.
* Example: {@code client://<clientId>/<clientUId>~<clientNickname>}
*
* @return Client's URI
*/
public String getClientURI() {
StringBuilder sb = new StringBuilder();
sb.append("client://").append(getId()).append('/');
sb.append(getUniqueIdentifier()).append('~');
try {
// We will encode the nickname, so characters like spaces work with this.
sb.append(URLEncoder.encode(getNickname(), "UTF-8"));
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException("JVM doesn't support UTF-8", e);
}
return sb.toString();
}
public String getCountry() {
return get(ClientProperty.CLIENT_COUNTRY);
}
public Date getCreatedDate() {
return new Date(getLong(ClientProperty.CLIENT_CREATED) * 1000);
}
public int getDatabaseId() {
return getInt(ClientProperty.CLIENT_DATABASE_ID);
}
public String getEstimatedLocation() {
return get(ClientProperty.CLIENT_ESTIMATED_LOCATION);
}
public long getIconId() {
return getLong(ClientProperty.CLIENT_ICON_ID);
}
public int getId() {
return getInt(ClientProperty.CLID);
}
public long getIdleTime() {
return getLong(ClientProperty.CLIENT_IDLE_TIME);
}
public int getInheritedChannelGroupId() {
return getInt(ClientProperty.CLIENT_CHANNEL_GROUP_INHERITED_CHANNEL_ID);
}
public String getIp() {
return get(ClientProperty.CONNECTION_CLIENT_IP);
}
public Date getLastConnectedDate() {
return new Date(getLong(ClientProperty.CLIENT_LASTCONNECTED) * 1000);
}
public String getNickname() {
return get(ClientProperty.CLIENT_NICKNAME);
}
public String getPlatform() {
return get(ClientProperty.CLIENT_PLATFORM);
}
public int[] getServerGroups() {
final String str = get(ClientProperty.CLIENT_SERVERGROUPS);
final String[] arr = str.split(",");
final int[] groups = new int[arr.length];
for (int i = 0; i < groups.length; i++) {
groups[i] = Integer.parseInt(arr[i]);
}
return groups;
}
public int getTalkPower() {
return getInt(ClientProperty.CLIENT_TALK_POWER);
}
public int getType() {
return getInt(ClientProperty.CLIENT_TYPE);
}
public String getUniqueIdentifier() {
return get(ClientProperty.CLIENT_UNIQUE_IDENTIFIER);
}
public String getVersion() {
return get(ClientProperty.CLIENT_VERSION);
}
public boolean hasOverwolf() {
String raw = get(ClientProperty.CLIENT_BADGES);
String[] properties = raw.split("[\\s:;]");
for (String property : properties) {
if (!(property.startsWith("overwolf=") || property.startsWith("Overwolf="))) continue;
String overwolfValue = property.substring("overwolf=".length());
return overwolfValue.equals("1");
}
return false;
}
public boolean isAway() {
return getBoolean(ClientProperty.CLIENT_AWAY);
}
public boolean isChannelCommander() {
return getBoolean(ClientProperty.CLIENT_IS_CHANNEL_COMMANDER);
}
/**
* Utility method that does a linear search on the array of server group IDs returned
* by {@link #getServerGroups()} and returns {@code true} if that array contains
* the given server group ID.
*
* @param serverGroupId
* the ID of the server group to search for
*
* @return whether this client is a member of the given server group
*/
public boolean isInServerGroup(int serverGroupId) {
int[] serverGroupIds = getServerGroups();
for (int s : serverGroupIds) {
if (s == serverGroupId) return true;
}
return false;
}
/**
* Utility method that does a linear search on the array of server group IDs returned
* by {@link #getServerGroups()} and returns {@code true} if that array contains
* the ID of the given server group.
*
* @param serverGroup
* the server group to search for
*
* @return whether this client is a member of the given server group
*/
public boolean isInServerGroup(ServerGroup serverGroup) {
return isInServerGroup(serverGroup.getId());
}
public boolean isInputHardware() {
return getBoolean(ClientProperty.CLIENT_INPUT_HARDWARE);
}
public boolean isInputMuted() {
return getBoolean(ClientProperty.CLIENT_INPUT_MUTED);
}
public boolean isOutputHardware() {
return getBoolean(ClientProperty.CLIENT_OUTPUT_HARDWARE);
}
public boolean isOutputMuted() {
return getBoolean(ClientProperty.CLIENT_OUTPUT_MUTED);
}
public boolean isPrioritySpeaker() {
return getBoolean(ClientProperty.CLIENT_IS_PRIORITY_SPEAKER);
}
public boolean isRecording() {
return getBoolean(ClientProperty.CLIENT_IS_RECORDING);
}
public boolean isRegularClient() {
return getType() == 0;
}
public boolean isServerQueryClient() {
return getType() == 1;
}
public boolean isTalking() {
return getBoolean(ClientProperty.CLIENT_FLAG_TALKING);
}
}