|
40 | 40 | import java.io.IOException; |
41 | 41 | import java.io.InputStream; |
42 | 42 | import java.io.OutputStream; |
43 | | -import java.util.ArrayList; |
44 | | -import java.util.Arrays; |
45 | | -import java.util.Collection; |
46 | | -import java.util.Collections; |
47 | | -import java.util.List; |
48 | | -import java.util.Locale; |
49 | | -import java.util.Map; |
| 43 | +import java.util.*; |
50 | 44 | import java.util.concurrent.TimeUnit; |
51 | 45 | import java.util.function.Function; |
52 | 46 | import java.util.regex.Pattern; |
@@ -1073,6 +1067,28 @@ public CommandFuture<Void> deleteComplaint(int targetClientDBId, int fromClientD |
1073 | 1067 | return executeAndReturnError(cmd); |
1074 | 1068 | } |
1075 | 1069 |
|
| 1070 | + /** |
| 1071 | + * Removes the {@code key} custom client property from a client. |
| 1072 | + * |
| 1073 | + * @param clientDBId |
| 1074 | + * the database ID of the target client |
| 1075 | + * @param key |
| 1076 | + * the key of the custom property to delete, cannot be {@code null} |
| 1077 | + * |
| 1078 | + * @return a future to track the progress of this command |
| 1079 | + * |
| 1080 | + * @throws TS3CommandFailedException |
| 1081 | + * if the execution of a command fails |
| 1082 | + * @querycommands 1 |
| 1083 | + * @see Client#getDatabaseId() |
| 1084 | + */ |
| 1085 | + public CommandFuture<Void> deleteCustomClientProperty(int clientDBId, String key) { |
| 1086 | + if (key == null) throw new IllegalArgumentException("Key cannot be null"); |
| 1087 | + |
| 1088 | + Command cmd = CustomPropertyCommands.customDelete(clientDBId, key); |
| 1089 | + return executeAndReturnError(cmd); |
| 1090 | + } |
| 1091 | + |
1076 | 1092 | /** |
1077 | 1093 | * Removes all stored database information about the specified client. |
1078 | 1094 | * Please note that this data is also automatically removed after a configured time (usually 90 days). |
@@ -2251,6 +2267,39 @@ public CommandFuture<ConnectionInfo> getConnectionInfo() { |
2251 | 2267 | return executeAndTransformFirst(cmd, ConnectionInfo::new); |
2252 | 2268 | } |
2253 | 2269 |
|
| 2270 | + /** |
| 2271 | + * Gets a map of all custom client properties and their values |
| 2272 | + * assigned to the client with database ID {@code clientDBId}. |
| 2273 | + * |
| 2274 | + * @param clientDBId |
| 2275 | + * the database ID of the target client |
| 2276 | + * |
| 2277 | + * @return a map of the client's custom client property assignments |
| 2278 | + * |
| 2279 | + * @throws TS3CommandFailedException |
| 2280 | + * if the execution of a command fails |
| 2281 | + * @querycommands 1 |
| 2282 | + * @see Client#getDatabaseId() |
| 2283 | + * @see #searchCustomClientProperty(String) |
| 2284 | + * @see #searchCustomClientProperty(String, String) |
| 2285 | + */ |
| 2286 | + public CommandFuture<Map<String, String>> getCustomClientProperties(int clientDBId) { |
| 2287 | + Command cmd = CustomPropertyCommands.customInfo(clientDBId); |
| 2288 | + CommandFuture<Map<String, String>> future = cmd.getFuture() |
| 2289 | + .map(result -> { |
| 2290 | + List<Wrapper> response = result.getResponses(); |
| 2291 | + Map<String, String> properties = new HashMap<>(response.size()); |
| 2292 | + for (Wrapper wrapper : response) { |
| 2293 | + properties.put(wrapper.get("ident"), wrapper.get("value")); |
| 2294 | + } |
| 2295 | + |
| 2296 | + return properties; |
| 2297 | + }); |
| 2298 | + |
| 2299 | + query.doCommandAsync(cmd); |
| 2300 | + return future; |
| 2301 | + } |
| 2302 | + |
2254 | 2303 | /** |
2255 | 2304 | * Gets all clients in the database whose last nickname matches the specified name <b>exactly</b>. |
2256 | 2305 | * |
@@ -4152,6 +4201,56 @@ public CommandFuture<String> resetPermissions() { |
4152 | 4201 | return executeAndReturnStringProperty(cmd, "token"); |
4153 | 4202 | } |
4154 | 4203 |
|
| 4204 | + /** |
| 4205 | + * Finds all clients that have any value associated with the {@code key} custom client property, |
| 4206 | + * and returns the client's database ID and the key and value of the matching custom property. |
| 4207 | + * |
| 4208 | + * @param key |
| 4209 | + * the key to search for, cannot be {@code null} |
| 4210 | + * |
| 4211 | + * @return a list of client database IDs and their matching custom client properties |
| 4212 | + * |
| 4213 | + * @throws TS3CommandFailedException |
| 4214 | + * if the execution of a command fails |
| 4215 | + * @querycommands 1 |
| 4216 | + * @see Client#getDatabaseId() |
| 4217 | + * @see #searchCustomClientProperty(String, String) |
| 4218 | + * @see #getCustomClientProperties(int) |
| 4219 | + */ |
| 4220 | + public CommandFuture<List<CustomPropertyAssignment>> searchCustomClientProperty(String key) { |
| 4221 | + return searchCustomClientProperty(key, "%"); |
| 4222 | + } |
| 4223 | + |
| 4224 | + /** |
| 4225 | + * Finds all clients whose value associated with the {@code key} custom client property matches the |
| 4226 | + * SQL-like pattern {@code valuePattern}, and returns the client's database ID and the key and value |
| 4227 | + * of the matching custom property. |
| 4228 | + * <p> |
| 4229 | + * Patterns are case insensitive. They support the wildcard characters {@code %}, which matches any sequence of |
| 4230 | + * zero or more characters, and {@code _}, which matches exactly one arbitrary character. |
| 4231 | + * </p> |
| 4232 | + * |
| 4233 | + * @param key |
| 4234 | + * the key to search for, cannot be {@code null} |
| 4235 | + * @param valuePattern |
| 4236 | + * the pattern that values need to match to be included |
| 4237 | + * |
| 4238 | + * @return a list of client database IDs and their matching custom client properties |
| 4239 | + * |
| 4240 | + * @throws TS3CommandFailedException |
| 4241 | + * if the execution of a command fails |
| 4242 | + * @querycommands 1 |
| 4243 | + * @see Client#getDatabaseId() |
| 4244 | + * @see #searchCustomClientProperty(String) |
| 4245 | + * @see #getCustomClientProperties(int) |
| 4246 | + */ |
| 4247 | + public CommandFuture<List<CustomPropertyAssignment>> searchCustomClientProperty(String key, String valuePattern) { |
| 4248 | + if (key == null) throw new IllegalArgumentException("Key cannot be null"); |
| 4249 | + |
| 4250 | + Command cmd = CustomPropertyCommands.customSearch(key, valuePattern); |
| 4251 | + return executeAndTransform(cmd, CustomPropertyAssignment::new); |
| 4252 | + } |
| 4253 | + |
4155 | 4254 | /** |
4156 | 4255 | * Moves the server query into the virtual server with the specified ID. |
4157 | 4256 | * |
@@ -4394,6 +4493,77 @@ public CommandFuture<Void> setClientChannelGroup(int groupId, int channelId, int |
4394 | 4493 | return executeAndReturnError(cmd); |
4395 | 4494 | } |
4396 | 4495 |
|
| 4496 | + /** |
| 4497 | + * Sets the value of the multiple custom client properties for a client. |
| 4498 | + * <p> |
| 4499 | + * If any key present in the map already has a value assigned for this client, |
| 4500 | + * the existing value will be overwritten. |
| 4501 | + * This method does not delete keys not present in the map. |
| 4502 | + * </p><p> |
| 4503 | + * If {@code properties} contains an entry with {@code null} as its key, |
| 4504 | + * that entry will be ignored and no exception will be thrown. |
| 4505 | + * </p> |
| 4506 | + * |
| 4507 | + * @param clientDBId |
| 4508 | + * the database ID of the target client |
| 4509 | + * @param properties |
| 4510 | + * the map of properties to set, cannot be {@code null} |
| 4511 | + * |
| 4512 | + * @return a future to track the progress of this command |
| 4513 | + * |
| 4514 | + * @throws TS3CommandFailedException |
| 4515 | + * if the execution of a command fails |
| 4516 | + * @querycommands properties.size() |
| 4517 | + * @see Client#getDatabaseId() |
| 4518 | + * @see #setCustomClientProperty(int, String, String) |
| 4519 | + * @see #deleteCustomClientProperty(int, String) |
| 4520 | + */ |
| 4521 | + public CommandFuture<Void> setCustomClientProperties(int clientDBId, Map<String, String> properties) { |
| 4522 | + Collection<CommandFuture<Void>> futures = new ArrayList<>(properties.size()); |
| 4523 | + |
| 4524 | + for (Map.Entry<String, String> entry : properties.entrySet()) { |
| 4525 | + String key = entry.getKey(); |
| 4526 | + String value = entry.getValue(); |
| 4527 | + |
| 4528 | + if (key != null) { |
| 4529 | + futures.add(setCustomClientProperty(clientDBId, key, value)); |
| 4530 | + } |
| 4531 | + } |
| 4532 | + |
| 4533 | + return CommandFuture.ofAll(futures) |
| 4534 | + .map(__ -> null); // Return success as Void, not List<Void> |
| 4535 | + } |
| 4536 | + |
| 4537 | + /** |
| 4538 | + * Sets the value of the {@code key} custom client property for a client. |
| 4539 | + * <p> |
| 4540 | + * If there is already an assignment of the {@code key} custom client property |
| 4541 | + * for this client, the existing value will be overwritten. |
| 4542 | + * </p> |
| 4543 | + * |
| 4544 | + * @param clientDBId |
| 4545 | + * the database ID of the target client |
| 4546 | + * @param key |
| 4547 | + * the key of the custom property to set, cannot be {@code null} |
| 4548 | + * @param value |
| 4549 | + * the (new) value of the custom property to set |
| 4550 | + * |
| 4551 | + * @return a future to track the progress of this command |
| 4552 | + * |
| 4553 | + * @throws TS3CommandFailedException |
| 4554 | + * if the execution of a command fails |
| 4555 | + * @querycommands 1 |
| 4556 | + * @see Client#getDatabaseId() |
| 4557 | + * @see #setCustomClientProperties(int, Map) |
| 4558 | + * @see #deleteCustomClientProperty(int, String) |
| 4559 | + */ |
| 4560 | + public CommandFuture<Void> setCustomClientProperty(int clientDBId, String key, String value) { |
| 4561 | + if (key == null) throw new IllegalArgumentException("Key cannot be null"); |
| 4562 | + |
| 4563 | + Command cmd = CustomPropertyCommands.customSet(clientDBId, key, value); |
| 4564 | + return executeAndReturnError(cmd); |
| 4565 | + } |
| 4566 | + |
4397 | 4567 | /** |
4398 | 4568 | * Sets the read flag to true for a given message. This will not delete the message. |
4399 | 4569 | * |
|
0 commit comments