Adding ts3-API dependency
Dieser Commit ist enthalten in:
Ursprung
43809981fb
Commit
0ee13b11fe
178
src/com/github/theholywaffle/teamspeak3/EventManager.java
Normale Datei
178
src/com/github/theholywaffle/teamspeak3/EventManager.java
Normale Datei
@ -0,0 +1,178 @@
|
||||
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.event.*;
|
||||
import com.github.theholywaffle.teamspeak3.api.exception.TS3UnknownEventException;
|
||||
import com.github.theholywaffle.teamspeak3.api.wrapper.Wrapper;
|
||||
import com.github.theholywaffle.teamspeak3.commands.response.DefaultArrayResponse;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class EventManager {
|
||||
|
||||
private static final Logger log = ProxyServer.getInstance().getLogger();
|
||||
|
||||
// CopyOnWriteArrayList for thread safety
|
||||
private final Collection<ListenerTask> tasks = new CopyOnWriteArrayList<>();
|
||||
private final TS3Query ts3;
|
||||
|
||||
EventManager(TS3Query query) {
|
||||
ts3 = query;
|
||||
}
|
||||
|
||||
public void addListeners(TS3Listener... listeners) {
|
||||
for (TS3Listener listener : listeners) {
|
||||
if (listener == null) throw new IllegalArgumentException("A listener was null");
|
||||
ListenerTask task = new ListenerTask(listener);
|
||||
tasks.add(task);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeListeners(TS3Listener... listeners) {
|
||||
// Bad performance (O(n*m)), but this method is rarely if ever used
|
||||
Iterator<ListenerTask> taskIterator = tasks.iterator();
|
||||
while (taskIterator.hasNext()) {
|
||||
ListenerTask task = taskIterator.next();
|
||||
TS3Listener taskListener = task.getListener();
|
||||
|
||||
for (TS3Listener listener : listeners) {
|
||||
if (taskListener.equals(listener)) {
|
||||
taskIterator.remove();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void fireEvent(String notifyName, String notifyBody) {
|
||||
final DefaultArrayResponse response = DefaultArrayResponse.parse(notifyBody);
|
||||
|
||||
for (Wrapper dataWrapper : response.getResponses()) {
|
||||
Map<String, String> eventData = dataWrapper.getMap();
|
||||
TS3Event event = createEvent(notifyName, eventData);
|
||||
|
||||
fireEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
public void fireEvent(TS3Event event) {
|
||||
if (event == null) throw new IllegalArgumentException("TS3Event was null");
|
||||
for (ListenerTask task : tasks) {
|
||||
task.enqueueEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
private static TS3Event createEvent(String notifyName, Map<String, String> eventData) {
|
||||
switch (notifyName) {
|
||||
case "notifytextmessage":
|
||||
return new TextMessageEvent(eventData);
|
||||
case "notifycliententerview":
|
||||
return new ClientJoinEvent(eventData);
|
||||
case "notifyclientleftview":
|
||||
return new ClientLeaveEvent(eventData);
|
||||
case "notifyserveredited":
|
||||
return new ServerEditedEvent(eventData);
|
||||
case "notifychanneledited":
|
||||
return new ChannelEditedEvent(eventData);
|
||||
case "notifychanneldescriptionchanged":
|
||||
return new ChannelDescriptionEditedEvent(eventData);
|
||||
case "notifyclientmoved":
|
||||
return new ClientMovedEvent(eventData);
|
||||
case "notifychannelcreated":
|
||||
return new ChannelCreateEvent(eventData);
|
||||
case "notifychanneldeleted":
|
||||
return new ChannelDeletedEvent(eventData);
|
||||
case "notifychannelmoved":
|
||||
return new ChannelMovedEvent(eventData);
|
||||
case "notifychannelpasswordchanged":
|
||||
return new ChannelPasswordChangedEvent(eventData);
|
||||
case "notifytokenused":
|
||||
return new PrivilegeKeyUsedEvent(eventData);
|
||||
default:
|
||||
throw new TS3UnknownEventException(notifyName + " " + eventData);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Do not synchronize on instances of this class from outside the class itself!
|
||||
*/
|
||||
private class ListenerTask implements Runnable {
|
||||
|
||||
private static final int START_QUEUE_SIZE = 16;
|
||||
|
||||
private final TS3Listener listener;
|
||||
private final Queue<TS3Event> eventQueue;
|
||||
|
||||
ListenerTask(TS3Listener ts3Listener) {
|
||||
listener = ts3Listener;
|
||||
eventQueue = new ArrayDeque<>(START_QUEUE_SIZE);
|
||||
}
|
||||
|
||||
TS3Listener getListener() {
|
||||
return listener;
|
||||
}
|
||||
|
||||
synchronized void enqueueEvent(TS3Event event) {
|
||||
if (eventQueue.isEmpty()) {
|
||||
// Add the event to the queue and start a task to process this event and any events
|
||||
// that might be enqueued before the last event is removed from the queue
|
||||
eventQueue.add(event);
|
||||
ts3.submitUserTask("Event listener task", this);
|
||||
} else {
|
||||
// Just add the event to the queue, the running task will pick it up
|
||||
eventQueue.add(event);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
TS3Event currentEvent;
|
||||
synchronized (this) {
|
||||
currentEvent = eventQueue.peek();
|
||||
if (currentEvent == null) throw new IllegalStateException("Task started without events");
|
||||
}
|
||||
|
||||
do {
|
||||
try {
|
||||
currentEvent.fire(listener);
|
||||
} catch (Throwable throwable) {
|
||||
log.log(Level.SEVERE, "Event listener threw an exception", throwable);
|
||||
}
|
||||
|
||||
synchronized (this) {
|
||||
eventQueue.remove();
|
||||
currentEvent = eventQueue.peek();
|
||||
}
|
||||
} while (currentEvent != null);
|
||||
}
|
||||
}
|
||||
}
|
161
src/com/github/theholywaffle/teamspeak3/FileTransferHelper.java
Normale Datei
161
src/com/github/theholywaffle/teamspeak3/FileTransferHelper.java
Normale Datei
@ -0,0 +1,161 @@
|
||||
package com.github.theholywaffle.teamspeak3;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* TeamSpeak 3 Java API
|
||||
* %%
|
||||
* Copyright (C) 2016 Bert De Geyter, Roger Baumgartner
|
||||
* %%
|
||||
* 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.wrapper.FileTransferParameters;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.Socket;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.zip.CRC32;
|
||||
|
||||
public class FileTransferHelper {
|
||||
|
||||
private static final Logger log = ProxyServer.getInstance().getLogger();
|
||||
private static final int BUFFER_SIZE = 16_384; // 16 kB
|
||||
|
||||
// Can only be in the range 0 - 65535
|
||||
private final AtomicInteger clientTransferId = new AtomicInteger(0);
|
||||
private final String defaultHost;
|
||||
|
||||
FileTransferHelper(String host) {
|
||||
defaultHost = host;
|
||||
}
|
||||
|
||||
// FILES
|
||||
|
||||
public void downloadFile(OutputStream dataOut, FileTransferParameters params) throws IOException {
|
||||
final String host = getHostFromResponse(params.getFileServerHost());
|
||||
final int port = params.getFileServerPort();
|
||||
final long dataLength = params.getFileSize();
|
||||
final int downloadId = params.getClientTransferId() + 1;
|
||||
|
||||
log.log(Level.INFO, "[Download {}] Download started", downloadId);
|
||||
try (Socket socket = new Socket(host, port)) {
|
||||
socket.setReceiveBufferSize(BUFFER_SIZE);
|
||||
int actualSize = socket.getReceiveBufferSize();
|
||||
|
||||
OutputStream out = socket.getOutputStream();
|
||||
out.write(params.getFileTransferKey().getBytes("UTF-8"));
|
||||
out.flush();
|
||||
|
||||
InputStream in = socket.getInputStream();
|
||||
byte[] buffer = new byte[actualSize];
|
||||
long total = 0;
|
||||
while (total < dataLength) {
|
||||
int read = in.read(buffer);
|
||||
if (read < 0) throw new IOException("Server response contained less data than specified");
|
||||
total += read;
|
||||
if (total > dataLength) throw new IOException("Server response contained more data than specified");
|
||||
dataOut.write(buffer, 0, read);
|
||||
}
|
||||
log.log(Level.INFO, "[Download {}] Download finished", downloadId);
|
||||
} catch (IOException e) {
|
||||
// Log and re-throw
|
||||
log.log(Level.INFO, String.format("[Download %s] Download failed: %s", downloadId, e.getMessage()));
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public void uploadFile(InputStream dataIn, long dataLength, FileTransferParameters params) throws IOException {
|
||||
final String host = getHostFromResponse(params.getFileServerHost());
|
||||
final int port = params.getFileServerPort();
|
||||
final int uploadId = params.getClientTransferId() + 1;
|
||||
|
||||
log.log(Level.INFO, "[Upload {}] Upload started", uploadId);
|
||||
try (Socket socket = new Socket(host, port)) {
|
||||
socket.setSendBufferSize(BUFFER_SIZE);
|
||||
int actualSize = socket.getSendBufferSize();
|
||||
|
||||
OutputStream out = socket.getOutputStream();
|
||||
out.write(params.getFileTransferKey().getBytes("UTF-8"));
|
||||
out.flush();
|
||||
|
||||
byte[] buffer = new byte[actualSize];
|
||||
long total = 0;
|
||||
while (total < dataLength) {
|
||||
int toRead = (int) Math.min(actualSize, dataLength - total);
|
||||
int read = dataIn.read(buffer, 0, toRead);
|
||||
if (read < 0) throw new IOException("User stream did not contain enough data");
|
||||
total += read;
|
||||
out.write(buffer, 0, read);
|
||||
}
|
||||
log.log(Level.INFO, "[Upload {}] Upload finished", uploadId);
|
||||
} catch (IOException e) {
|
||||
// Log and re-throw
|
||||
log.log(Level.WARNING, String.format("[Upload %s] Upload failed: %s", uploadId, e.getMessage()));
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
// ICONS
|
||||
|
||||
public long getIconId(byte[] data) {
|
||||
final CRC32 crc32 = new CRC32();
|
||||
crc32.update(data);
|
||||
return crc32.getValue();
|
||||
}
|
||||
|
||||
// UTIL
|
||||
|
||||
public byte[] readFully(InputStream dataIn, long dataLength) throws IOException {
|
||||
if (dataLength > Integer.MAX_VALUE - 64) throw new IOException("File too large");
|
||||
|
||||
final int len = (int) dataLength;
|
||||
byte[] data = new byte[len];
|
||||
int total = 0;
|
||||
while (total < len) {
|
||||
int read = dataIn.read(data, total, len - total);
|
||||
if (read < 0) throw new IOException("User stream did not contain enough data");
|
||||
total += read;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public int getClientTransferId() {
|
||||
// AtomicInteger#getAndUpdate without Java 8
|
||||
int prev, next;
|
||||
do {
|
||||
prev = clientTransferId.get();
|
||||
next = (prev + 1) & 0xFFFF;
|
||||
} while (!clientTransferId.compareAndSet(prev, next));
|
||||
return prev;
|
||||
}
|
||||
|
||||
private String getHostFromResponse(String raw) {
|
||||
if (raw == null || raw.isEmpty()) return defaultHost;
|
||||
if (raw.startsWith("0.0.0.0")) return defaultHost;
|
||||
int firstComma = raw.indexOf(',');
|
||||
if (firstComma <= 0) return defaultHost;
|
||||
return raw.substring(0, firstComma);
|
||||
}
|
||||
}
|
67
src/com/github/theholywaffle/teamspeak3/KeepAliveThread.java
Normale Datei
67
src/com/github/theholywaffle/teamspeak3/KeepAliveThread.java
Normale Datei
@ -0,0 +1,67 @@
|
||||
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 net.md_5.bungee.api.ProxyServer;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class KeepAliveThread extends Thread {
|
||||
|
||||
private static final Logger log = ProxyServer.getInstance().getLogger();
|
||||
private static final int SLEEP = 60_000;
|
||||
|
||||
private final SocketWriter writer;
|
||||
private final TS3ApiAsync asyncApi;
|
||||
|
||||
public KeepAliveThread(SocketWriter writer, TS3ApiAsync asyncApi) {
|
||||
super("[TeamSpeak-3-Java-API] Keep alive");
|
||||
this.writer = writer;
|
||||
this.asyncApi = asyncApi;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
while (!isInterrupted()) {
|
||||
final long idleTime = writer.getIdleTime();
|
||||
if (idleTime >= SLEEP) {
|
||||
// Using the asynchronous API so we get InterruptedExceptions
|
||||
asyncApi.whoAmI().await();
|
||||
} else {
|
||||
Thread.sleep(SLEEP - idleTime);
|
||||
}
|
||||
}
|
||||
} catch (final InterruptedException e) {
|
||||
// Thread stopped properly, ignore
|
||||
} catch (final Exception e) {
|
||||
log.log(Level.WARNING, "KeepAlive thread has stopped!", e);
|
||||
}
|
||||
}
|
||||
}
|
152
src/com/github/theholywaffle/teamspeak3/QueryIO.java
Normale Datei
152
src/com/github/theholywaffle/teamspeak3/QueryIO.java
Normale Datei
@ -0,0 +1,152 @@
|
||||
package com.github.theholywaffle.teamspeak3;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* TeamSpeak 3 Java API
|
||||
* %%
|
||||
* Copyright (C) 2015 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.exception.TS3ConnectionFailedException;
|
||||
import com.github.theholywaffle.teamspeak3.api.exception.TS3QueryShutDownException;
|
||||
import com.github.theholywaffle.teamspeak3.api.reconnect.ConnectionHandler;
|
||||
import com.github.theholywaffle.teamspeak3.api.reconnect.DisconnectingConnectionHandler;
|
||||
import com.github.theholywaffle.teamspeak3.commands.Command;
|
||||
import com.github.theholywaffle.teamspeak3.commands.response.ResponseBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
public class QueryIO {
|
||||
|
||||
private final Socket socket;
|
||||
private final SocketReader socketReader;
|
||||
private final SocketWriter socketWriter;
|
||||
private final KeepAliveThread keepAlive;
|
||||
|
||||
private final BlockingQueue<Command> sendQueue;
|
||||
private final BlockingQueue<ResponseBuilder> receiveQueue;
|
||||
|
||||
QueryIO(TS3Query query, TS3Config config) {
|
||||
sendQueue = new LinkedBlockingQueue<>();
|
||||
ConnectionHandler handler = config.getReconnectStrategy().create(null);
|
||||
if (config.getFloodRate() == TS3Query.FloodRate.UNLIMITED && handler instanceof DisconnectingConnectionHandler) {
|
||||
// Don't wait for the last response before sending more commands
|
||||
receiveQueue = new LinkedBlockingQueue<>();
|
||||
} else {
|
||||
// Wait for the response to the last command to arrive before sending the next one
|
||||
receiveQueue = new ArrayBlockingQueue<>(1);
|
||||
}
|
||||
|
||||
Socket tmpSocket = null;
|
||||
try {
|
||||
tmpSocket = new Socket(config.getHost(), config.getQueryPort());
|
||||
socket = tmpSocket;
|
||||
socket.setTcpNoDelay(true);
|
||||
socket.setSoTimeout(config.getCommandTimeout());
|
||||
|
||||
socketWriter = new SocketWriter(this, config);
|
||||
socketReader = new SocketReader(this, socketWriter, query, config);
|
||||
keepAlive = new KeepAliveThread(socketWriter, query.getAsyncApi());
|
||||
} catch (IOException e) {
|
||||
// Clean up resources and fail
|
||||
if (tmpSocket != null) {
|
||||
try {
|
||||
tmpSocket.close();
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
throw new TS3ConnectionFailedException(e);
|
||||
}
|
||||
|
||||
// From here on: all resources have been initialized and are non-null
|
||||
socketReader.start();
|
||||
socketWriter.start();
|
||||
keepAlive.start();
|
||||
}
|
||||
|
||||
public void continueFrom(QueryIO io) {
|
||||
if (io == null) return;
|
||||
|
||||
// Resend commands which remained unanswered first
|
||||
io.socketReader.drainCommandsTo(sendQueue);
|
||||
io.socketWriter.drainCommandsTo(sendQueue);
|
||||
|
||||
io.receiveQueue.clear();
|
||||
io.sendQueue.clear();
|
||||
}
|
||||
|
||||
public void disconnect() {
|
||||
keepAlive.interrupt();
|
||||
socketWriter.interrupt();
|
||||
socketReader.interrupt();
|
||||
|
||||
try {
|
||||
keepAlive.join();
|
||||
socketWriter.join();
|
||||
socketReader.join();
|
||||
} catch (final InterruptedException e) {
|
||||
// Restore the interrupt for the caller
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
|
||||
try {
|
||||
socket.close();
|
||||
} catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
void failRemainingCommands() {
|
||||
Collection<Command> commands = new ArrayList<>(receiveQueue.size() + sendQueue.size() + 1);
|
||||
socketReader.drainCommandsTo(commands);
|
||||
socketWriter.drainCommandsTo(commands);
|
||||
|
||||
for (Command command : commands) {
|
||||
command.getFuture().fail(new TS3QueryShutDownException());
|
||||
}
|
||||
}
|
||||
|
||||
public void enqueueCommand(Command command) {
|
||||
if (command == null) throw new IllegalArgumentException("Command cannot be null!");
|
||||
sendQueue.add(command);
|
||||
}
|
||||
|
||||
// Internals for communication with other IO classes
|
||||
|
||||
Socket getSocket() {
|
||||
return socket;
|
||||
}
|
||||
|
||||
BlockingQueue<Command> getSendQueue() {
|
||||
return sendQueue;
|
||||
}
|
||||
|
||||
BlockingQueue<ResponseBuilder> getReceiveQueue() {
|
||||
return receiveQueue;
|
||||
}
|
||||
}
|
200
src/com/github/theholywaffle/teamspeak3/SocketReader.java
Normale Datei
200
src/com/github/theholywaffle/teamspeak3/SocketReader.java
Normale Datei
@ -0,0 +1,200 @@
|
||||
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.CommandFuture;
|
||||
import com.github.theholywaffle.teamspeak3.api.exception.TS3CommandFailedException;
|
||||
import com.github.theholywaffle.teamspeak3.api.wrapper.QueryError;
|
||||
import com.github.theholywaffle.teamspeak3.commands.Command;
|
||||
import com.github.theholywaffle.teamspeak3.commands.response.DefaultArrayResponse;
|
||||
import com.github.theholywaffle.teamspeak3.commands.response.ResponseBuilder;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.util.Collection;
|
||||
import java.util.Queue;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class SocketReader extends Thread {
|
||||
|
||||
private static final Logger log = ProxyServer.getInstance().getLogger();
|
||||
|
||||
private final TS3Query ts3;
|
||||
private final Queue<ResponseBuilder> receiveQueue;
|
||||
private final BufferedReader in;
|
||||
private final SocketWriter writer;
|
||||
private final long commandTimeout;
|
||||
private final boolean logComms;
|
||||
|
||||
private String lastEvent = "";
|
||||
|
||||
public SocketReader(QueryIO io, SocketWriter writer, TS3Query ts3Query, TS3Config config) throws IOException {
|
||||
super("[TeamSpeak-3-Java-API] SocketReader");
|
||||
this.receiveQueue = io.getReceiveQueue();
|
||||
this.writer = writer;
|
||||
this.commandTimeout = config.getCommandTimeout();
|
||||
this.ts3 = ts3Query;
|
||||
this.logComms = config.getEnableCommunicationsLogging();
|
||||
|
||||
// Connect
|
||||
this.in = new BufferedReader(new InputStreamReader(io.getSocket().getInputStream(), "UTF-8"));
|
||||
int i = 0;
|
||||
while (i < 4 || in.ready()) {
|
||||
String welcomeMessage = in.readLine();
|
||||
if (logComms) log.log(Level.FINE, "< {}", welcomeMessage);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while (!isInterrupted()) {
|
||||
final String line;
|
||||
|
||||
try {
|
||||
// Will block until a full line of text could be read.
|
||||
line = in.readLine();
|
||||
} catch (SocketTimeoutException socketTimeout) {
|
||||
// Really disconnected or just no data transferred for <commandTimeout> milliseconds?
|
||||
if (receiveQueue.isEmpty() || writer.getIdleTime() < commandTimeout) {
|
||||
continue;
|
||||
} else {
|
||||
log.log(Level.SEVERE, "Connection timed out.", socketTimeout);
|
||||
break;
|
||||
}
|
||||
} catch (IOException io) {
|
||||
if (!isInterrupted()) {
|
||||
log.log(Level.SEVERE, "Connection error occurred.", io);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (line == null) {
|
||||
// End of stream: connection terminated by server
|
||||
log.log(Level.SEVERE, "Connection closed by the server.");
|
||||
break;
|
||||
} else if (line.isEmpty()) {
|
||||
continue; // The server is sending garbage
|
||||
}
|
||||
|
||||
if (line.startsWith("notify")) {
|
||||
handleEvent(line);
|
||||
} else {
|
||||
handleCommandResponse(line);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
in.close();
|
||||
} catch (IOException ignored) {
|
||||
// Ignore
|
||||
}
|
||||
|
||||
if (!isInterrupted()) {
|
||||
ts3.fireDisconnect();
|
||||
}
|
||||
}
|
||||
|
||||
private void handleEvent(final String event) {
|
||||
if (logComms) log.log(Level.FINE, "[event] < {}", event);
|
||||
|
||||
// Filter out duplicate events for join, quit and channel move events
|
||||
if (!isDuplicate(event)) {
|
||||
final String arr[] = event.split(" ", 2);
|
||||
ts3.getEventManager().fireEvent(arr[0], arr[1]);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleCommandResponse(final String response) {
|
||||
final ResponseBuilder responseBuilder = receiveQueue.peek();
|
||||
if (responseBuilder == null) {
|
||||
log.log(Level.WARNING, "[UNHANDLED] < {}", response);
|
||||
return;
|
||||
}
|
||||
|
||||
if (logComms) log.log(Level.FINE, responseBuilder.getCommand().getName() + " < " + response);
|
||||
|
||||
if (response.startsWith("error ")) {
|
||||
handleCommandError(responseBuilder, response);
|
||||
} else {
|
||||
responseBuilder.appendResponse(response);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleCommandError(ResponseBuilder responseBuilder, final String error) {
|
||||
final Command command = responseBuilder.getCommand();
|
||||
if (command.getName().equals("quit")) {
|
||||
// Response to a quit command received, we're done
|
||||
interrupt();
|
||||
}
|
||||
|
||||
receiveQueue.remove();
|
||||
|
||||
final QueryError queryError = DefaultArrayResponse.parseError(error);
|
||||
final CommandFuture<DefaultArrayResponse> future = command.getFuture();
|
||||
|
||||
if (queryError.isSuccessful()) {
|
||||
final DefaultArrayResponse response = responseBuilder.buildResponse();
|
||||
|
||||
ts3.submitUserTask("Future SuccessListener (" + command.getName() + ")", () -> future.set(response));
|
||||
} else {
|
||||
log.log(Level.FINE, "TS3 command error: {}", queryError);
|
||||
|
||||
ts3.submitUserTask("Future FailureListener (" + command.getName() + ")",
|
||||
() -> future.fail(new TS3CommandFailedException(queryError, command.getName())));
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isDuplicate(String eventMessage) {
|
||||
if (!(eventMessage.startsWith("notifyclientmoved")
|
||||
|| eventMessage.startsWith("notifycliententerview")
|
||||
|| eventMessage.startsWith("notifyclientleftview"))) {
|
||||
|
||||
// Event that will never cause duplicates
|
||||
return false;
|
||||
}
|
||||
|
||||
if (eventMessage.equals(lastEvent)) {
|
||||
// Duplicate event!
|
||||
lastEvent = ""; // Let's only ever filter one duplicate
|
||||
return true;
|
||||
}
|
||||
|
||||
lastEvent = eventMessage;
|
||||
return false;
|
||||
}
|
||||
|
||||
void drainCommandsTo(Collection<Command> commands) {
|
||||
for (ResponseBuilder responseBuilder : receiveQueue) {
|
||||
commands.add(responseBuilder.getCommand());
|
||||
}
|
||||
}
|
||||
}
|
112
src/com/github/theholywaffle/teamspeak3/SocketWriter.java
Normale Datei
112
src/com/github/theholywaffle/teamspeak3/SocketWriter.java
Normale Datei
@ -0,0 +1,112 @@
|
||||
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.commands.Command;
|
||||
import com.github.theholywaffle.teamspeak3.commands.response.ResponseBuilder;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.util.Collection;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class SocketWriter extends Thread {
|
||||
|
||||
private static final Logger log = ProxyServer.getInstance().getLogger();
|
||||
|
||||
private final BlockingQueue<Command> sendQueue;
|
||||
private final BlockingQueue<ResponseBuilder> receiveQueue;
|
||||
private final int floodRate;
|
||||
private final boolean logComms;
|
||||
private final PrintStream out;
|
||||
|
||||
private volatile long lastCommandTime = System.currentTimeMillis();
|
||||
|
||||
private Command interruptedCommand = null;
|
||||
|
||||
public SocketWriter(QueryIO io, TS3Config config) throws IOException {
|
||||
super("[TeamSpeak-3-Java-API] SocketWriter");
|
||||
this.sendQueue = io.getSendQueue();
|
||||
this.receiveQueue = io.getReceiveQueue();
|
||||
this.floodRate = config.getFloodRate().getMs();
|
||||
this.logComms = config.getEnableCommunicationsLogging();
|
||||
this.out = new PrintStream(io.getSocket().getOutputStream(), true, "UTF-8");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
// Initial sleep to prevent flood ban shortly after connecting
|
||||
if (floodRate > 0) Thread.sleep(floodRate);
|
||||
|
||||
while (!isInterrupted()) {
|
||||
final Command c = sendQueue.take();
|
||||
final String msg = c.toString();
|
||||
|
||||
lastCommandTime = System.currentTimeMillis();
|
||||
|
||||
try {
|
||||
receiveQueue.put(new ResponseBuilder(c));
|
||||
} catch (InterruptedException e) {
|
||||
// Properly handle commands removed from the sendQueue
|
||||
// but not inserted into the receiveQueue
|
||||
interruptedCommand = c;
|
||||
interrupt();
|
||||
break;
|
||||
}
|
||||
|
||||
if (logComms) log.log(Level.FINE, String.format("%s > %s", c.getName(), msg));
|
||||
out.println(msg);
|
||||
|
||||
if (floodRate > 0) Thread.sleep(floodRate);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
// Regular shutdown
|
||||
interrupt();
|
||||
}
|
||||
|
||||
out.close();
|
||||
|
||||
if (!isInterrupted()) {
|
||||
log.log(Level.WARNING, "SocketWriter has stopped!");
|
||||
}
|
||||
}
|
||||
|
||||
long getIdleTime() {
|
||||
return System.currentTimeMillis() - lastCommandTime;
|
||||
}
|
||||
|
||||
void drainCommandsTo(Collection<Command> commands) {
|
||||
if (interruptedCommand != null) {
|
||||
commands.add(interruptedCommand);
|
||||
}
|
||||
sendQueue.drainTo(commands);
|
||||
}
|
||||
}
|
4578
src/com/github/theholywaffle/teamspeak3/TS3Api.java
Normale Datei
4578
src/com/github/theholywaffle/teamspeak3/TS3Api.java
Normale Datei
Datei-Diff unterdrückt, da er zu groß ist
Diff laden
5541
src/com/github/theholywaffle/teamspeak3/TS3ApiAsync.java
Normale Datei
5541
src/com/github/theholywaffle/teamspeak3/TS3ApiAsync.java
Normale Datei
Datei-Diff unterdrückt, da er zu groß ist
Diff laden
139
src/com/github/theholywaffle/teamspeak3/TS3Config.java
Normale Datei
139
src/com/github/theholywaffle/teamspeak3/TS3Config.java
Normale Datei
@ -0,0 +1,139 @@
|
||||
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.TS3Query.FloodRate;
|
||||
import com.github.theholywaffle.teamspeak3.api.reconnect.ConnectionHandler;
|
||||
import com.github.theholywaffle.teamspeak3.api.reconnect.ReconnectStrategy;
|
||||
|
||||
public class TS3Config {
|
||||
|
||||
private String host = null;
|
||||
private int queryPort = 10011;
|
||||
private FloodRate floodRate = FloodRate.DEFAULT;
|
||||
private boolean enableCommunicationsLogging = false;
|
||||
private int commandTimeout = 4000;
|
||||
private ReconnectStrategy reconnectStrategy = ReconnectStrategy.disconnect();
|
||||
private ConnectionHandler connectionHandler = null;
|
||||
|
||||
public TS3Config setHost(String host) {
|
||||
this.host = host;
|
||||
return this;
|
||||
}
|
||||
|
||||
String getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
public TS3Config setQueryPort(int queryPort) {
|
||||
if (queryPort <= 0 || queryPort > 65535) {
|
||||
throw new IllegalArgumentException("Port out of range: " + queryPort);
|
||||
}
|
||||
this.queryPort = queryPort;
|
||||
return this;
|
||||
}
|
||||
|
||||
int getQueryPort() {
|
||||
return queryPort;
|
||||
}
|
||||
|
||||
public TS3Config setFloodRate(FloodRate rate) {
|
||||
if (rate == null) throw new IllegalArgumentException("rate cannot be null!");
|
||||
this.floodRate = rate;
|
||||
return this;
|
||||
}
|
||||
|
||||
FloodRate getFloodRate() {
|
||||
return floodRate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setting this value to {@code true} will log the communication between the
|
||||
* query client and the TS3 server at the {@code DEBUG} level.
|
||||
* <p>
|
||||
* By default, this is turned off to prevent leaking IPs, tokens, passwords, etc.
|
||||
* into the console and / or log files.
|
||||
* </p>
|
||||
*
|
||||
* @param enable
|
||||
* whether to log query commands
|
||||
*
|
||||
* @return this TS3Config object for chaining
|
||||
*/
|
||||
public TS3Config setEnableCommunicationsLogging(boolean enable) {
|
||||
enableCommunicationsLogging = enable;
|
||||
return this;
|
||||
}
|
||||
|
||||
boolean getEnableCommunicationsLogging() {
|
||||
return enableCommunicationsLogging;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets how many milliseconds a call in {@link TS3Api} should block at most until a command
|
||||
* without response fails. By default, this timeout is 4000 milliseconds.
|
||||
*
|
||||
* @param commandTimeout
|
||||
* the maximum time to wait for a response until a synchronous command call fails
|
||||
*
|
||||
* @return this TS3Config object for chaining
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* if the timeout value is smaller than or equal to {@code 0}
|
||||
*/
|
||||
public TS3Config setCommandTimeout(int commandTimeout) {
|
||||
if (commandTimeout <= 0) {
|
||||
throw new IllegalArgumentException("Timeout value must be greater than 0");
|
||||
}
|
||||
|
||||
this.commandTimeout = commandTimeout;
|
||||
return this;
|
||||
}
|
||||
|
||||
int getCommandTimeout() {
|
||||
return commandTimeout;
|
||||
}
|
||||
|
||||
public TS3Config setReconnectStrategy(ReconnectStrategy reconnectStrategy) {
|
||||
if (reconnectStrategy == null) throw new IllegalArgumentException("reconnectStrategy cannot be null!");
|
||||
this.reconnectStrategy = reconnectStrategy;
|
||||
return this;
|
||||
}
|
||||
|
||||
ReconnectStrategy getReconnectStrategy() {
|
||||
return reconnectStrategy;
|
||||
}
|
||||
|
||||
public TS3Config setConnectionHandler(ConnectionHandler connectionHandler) {
|
||||
this.connectionHandler = connectionHandler;
|
||||
return this;
|
||||
}
|
||||
|
||||
ConnectionHandler getConnectionHandler() {
|
||||
return connectionHandler;
|
||||
}
|
||||
}
|
296
src/com/github/theholywaffle/teamspeak3/TS3Query.java
Normale Datei
296
src/com/github/theholywaffle/teamspeak3/TS3Query.java
Normale Datei
@ -0,0 +1,296 @@
|
||||
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.exception.TS3Exception;
|
||||
import com.github.theholywaffle.teamspeak3.api.exception.TS3QueryShutDownException;
|
||||
import com.github.theholywaffle.teamspeak3.api.reconnect.ConnectionHandler;
|
||||
import com.github.theholywaffle.teamspeak3.api.reconnect.ReconnectStrategy;
|
||||
import com.github.theholywaffle.teamspeak3.commands.Command;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class TS3Query {
|
||||
|
||||
private static final Logger log = ProxyServer.getInstance().getLogger();
|
||||
|
||||
public static class FloodRate {
|
||||
|
||||
public static final FloodRate DEFAULT = new FloodRate(350);
|
||||
public static final FloodRate UNLIMITED = new FloodRate(0);
|
||||
|
||||
public static FloodRate custom(int milliseconds) {
|
||||
if (milliseconds < 0) throw new IllegalArgumentException("Timeout must be positive");
|
||||
return new FloodRate(milliseconds);
|
||||
}
|
||||
|
||||
private final int ms;
|
||||
|
||||
private FloodRate(int ms) {
|
||||
this.ms = ms;
|
||||
}
|
||||
|
||||
public int getMs() {
|
||||
return ms;
|
||||
}
|
||||
}
|
||||
|
||||
private final ConnectionHandler connectionHandler;
|
||||
private final EventManager eventManager;
|
||||
private final ExecutorService userThreadPool;
|
||||
private final FileTransferHelper fileTransferHelper;
|
||||
private final TS3Api api;
|
||||
private final TS3ApiAsync asyncApi;
|
||||
private final TS3Config config;
|
||||
|
||||
private final AtomicBoolean connected = new AtomicBoolean(false);
|
||||
private final AtomicBoolean shuttingDown = new AtomicBoolean(false);
|
||||
|
||||
private QueryIO io;
|
||||
|
||||
/**
|
||||
* Creates a TS3Query that connects to a TS3 server at
|
||||
* {@code localhost:10011} using default settings.
|
||||
*/
|
||||
public TS3Query() {
|
||||
this(new TS3Config());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a customized TS3Query that connects to a server
|
||||
* specified by {@code config}.
|
||||
*
|
||||
* @param config
|
||||
* configuration for this TS3Query
|
||||
*/
|
||||
public TS3Query(TS3Config config) {
|
||||
this.config = config;
|
||||
this.eventManager = new EventManager(this);
|
||||
this.userThreadPool = Executors.newCachedThreadPool();
|
||||
this.fileTransferHelper = new FileTransferHelper(config.getHost());
|
||||
this.connectionHandler = config.getReconnectStrategy().create(config.getConnectionHandler());
|
||||
|
||||
this.asyncApi = new TS3ApiAsync(this);
|
||||
this.api = new TS3Api(asyncApi);
|
||||
}
|
||||
|
||||
/*
|
||||
* Copy constructor only used for ReconnectQuery
|
||||
*/
|
||||
private TS3Query(TS3Query query) {
|
||||
this.config = query.config;
|
||||
this.eventManager = query.eventManager;
|
||||
this.userThreadPool = query.userThreadPool;
|
||||
this.fileTransferHelper = query.fileTransferHelper;
|
||||
this.connectionHandler = null;
|
||||
|
||||
this.asyncApi = new TS3ApiAsync(this);
|
||||
this.api = new TS3Api(asyncApi);
|
||||
}
|
||||
|
||||
// PUBLIC
|
||||
|
||||
public void connect() {
|
||||
synchronized (this) {
|
||||
if (userThreadPool.isShutdown()) {
|
||||
throw new IllegalStateException("The query has already been shut down");
|
||||
}
|
||||
}
|
||||
|
||||
QueryIO newIO = new QueryIO(this, config);
|
||||
|
||||
try {
|
||||
connectionHandler.onConnect(new ReconnectQuery(this, newIO));
|
||||
} catch (Exception e) {
|
||||
log.log(Level.SEVERE, "ConnectionHandler threw exception in connect handler", e);
|
||||
}
|
||||
|
||||
synchronized (this) {
|
||||
QueryIO oldIO = io;
|
||||
io = newIO;
|
||||
if (oldIO != null) {
|
||||
oldIO.disconnect();
|
||||
newIO.continueFrom(oldIO);
|
||||
}
|
||||
connected.set(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes and closes all used resources to the TeamSpeak server.
|
||||
*/
|
||||
public void exit() {
|
||||
if (shuttingDown.compareAndSet(false, true)) {
|
||||
try {
|
||||
// Sending this command will guarantee that all previously sent commands have been processed
|
||||
api.quit();
|
||||
} catch (TS3Exception e) {
|
||||
log.log(Level.WARNING, "Could not send a quit command to terminate the connection", e);
|
||||
} finally {
|
||||
shutDown();
|
||||
}
|
||||
} else {
|
||||
// Only 1 thread shall ever send quit, the rest of the threads wait for the first thread to finish
|
||||
try {
|
||||
synchronized (this) {
|
||||
while (connected.get()) {
|
||||
wait();
|
||||
}
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
// Restore interrupt, then bail out
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void shutDown() {
|
||||
if (userThreadPool.isShutdown()) return;
|
||||
|
||||
if (io != null) {
|
||||
io.disconnect();
|
||||
io.failRemainingCommands();
|
||||
}
|
||||
|
||||
userThreadPool.shutdown();
|
||||
connected.set(false);
|
||||
notifyAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if the query is likely connected,
|
||||
* {@code false} if the query is disconnected or currently trying to reconnect.
|
||||
* <p>
|
||||
* Note that the only way to really determine whether the query is connected or not
|
||||
* is to send a command and check whether it succeeds.
|
||||
* Thus this method could return {@code true} almost a minute after the connection
|
||||
* has been lost, when the last keep-alive command was sent.
|
||||
* </p><p>
|
||||
* Please do not use this method to write your own connection handler.
|
||||
* Instead, use the built-in classes in the {@code api.reconnect} package.
|
||||
* </p>
|
||||
*
|
||||
* @return whether the query is connected or not
|
||||
*
|
||||
* @see TS3Config#setReconnectStrategy(ReconnectStrategy)
|
||||
* @see TS3Config#setConnectionHandler(ConnectionHandler)
|
||||
*/
|
||||
public boolean isConnected() {
|
||||
return connected.get();
|
||||
}
|
||||
|
||||
public TS3Api getApi() {
|
||||
return api;
|
||||
}
|
||||
|
||||
public TS3ApiAsync getAsyncApi() {
|
||||
return asyncApi;
|
||||
}
|
||||
|
||||
// INTERNAL
|
||||
|
||||
synchronized void doCommandAsync(Command c) {
|
||||
if (userThreadPool.isShutdown()) {
|
||||
c.getFuture().fail(new TS3QueryShutDownException());
|
||||
return;
|
||||
}
|
||||
|
||||
io.enqueueCommand(c);
|
||||
}
|
||||
|
||||
void submitUserTask(final String name, final Runnable task) {
|
||||
userThreadPool.submit(() -> {
|
||||
try {
|
||||
task.run();
|
||||
} catch (Throwable throwable) {
|
||||
log.log(Level.SEVERE, name + " threw an exception", throwable);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
EventManager getEventManager() {
|
||||
return eventManager;
|
||||
}
|
||||
|
||||
FileTransferHelper getFileTransferHelper() {
|
||||
return fileTransferHelper;
|
||||
}
|
||||
|
||||
void fireDisconnect() {
|
||||
connected.set(false);
|
||||
|
||||
submitUserTask("ConnectionHandler disconnect task", this::handleDisconnect);
|
||||
}
|
||||
|
||||
private void handleDisconnect() {
|
||||
try {
|
||||
connectionHandler.onDisconnect(this);
|
||||
} finally {
|
||||
synchronized (this) {
|
||||
if (!connected.get()) {
|
||||
shuttingDown.set(true); // Try to prevent extraneous exit commands
|
||||
shutDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class ReconnectQuery extends TS3Query {
|
||||
|
||||
private final TS3Query parent;
|
||||
|
||||
private ReconnectQuery(TS3Query query, QueryIO io) {
|
||||
super(query);
|
||||
super.io = io;
|
||||
this.parent = query;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connect() {
|
||||
throw new UnsupportedOperationException("Can't call connect from onConnect handler");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exit() {
|
||||
parent.exit();
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized void fireDisconnect() {
|
||||
// If a reconnect query fails, we do not want this to affect the parent query.
|
||||
// Instead, simply fail all remaining onConnect commands.
|
||||
QueryIO io = super.io;
|
||||
io.disconnect();
|
||||
io.failRemainingCommands();
|
||||
}
|
||||
}
|
||||
}
|
79
src/com/github/theholywaffle/teamspeak3/api/ChannelProperty.java
Normale Datei
79
src/com/github/theholywaffle/teamspeak3/api/ChannelProperty.java
Normale Datei
@ -0,0 +1,79 @@
|
||||
package com.github.theholywaffle.teamspeak3.api;
|
||||
|
||||
/*
|
||||
* #%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.Locale;
|
||||
|
||||
public enum ChannelProperty implements Property {
|
||||
|
||||
CHANNEL_CODEC(true),
|
||||
CHANNEL_CODEC_IS_UNENCRYPTED(true),
|
||||
CHANNEL_CODEC_LATENCY_FACTOR(false),
|
||||
CHANNEL_CODEC_QUALITY(true),
|
||||
CHANNEL_DELETE_DELAY(true),
|
||||
CHANNEL_DESCRIPTION(true),
|
||||
CHANNEL_FILEPATH(false),
|
||||
CHANNEL_FLAG_DEFAULT(true),
|
||||
CHANNEL_FLAG_MAXCLIENTS_UNLIMITED(true),
|
||||
CHANNEL_FLAG_MAXFAMILYCLIENTS_INHERITED(true),
|
||||
CHANNEL_FLAG_MAXFAMILYCLIENTS_UNLIMITED(true),
|
||||
CHANNEL_FLAG_PASSWORD(false),
|
||||
CHANNEL_FLAG_PERMANENT(true),
|
||||
CHANNEL_FLAG_SEMI_PERMANENT(true),
|
||||
CHANNEL_FLAG_TEMPORARY(true),
|
||||
CHANNEL_FORCED_SILENCE(false),
|
||||
CHANNEL_ICON_ID(true),
|
||||
CHANNEL_MAXCLIENTS(true),
|
||||
CHANNEL_MAXFAMILYCLIENTS(true),
|
||||
CHANNEL_NAME(true),
|
||||
CHANNEL_NAME_PHONETIC(true),
|
||||
CHANNEL_NEEDED_SUBSCRIBE_POWER(false),
|
||||
CHANNEL_NEEDED_TALK_POWER(true),
|
||||
CHANNEL_ORDER(true),
|
||||
CHANNEL_PASSWORD(true),
|
||||
CHANNEL_TOPIC(true),
|
||||
SECONDS_EMPTY(false),
|
||||
CID(false),
|
||||
PID(false),
|
||||
CPID(true);
|
||||
|
||||
private final boolean changeable;
|
||||
|
||||
ChannelProperty(boolean changeable) {
|
||||
this.changeable = changeable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChangeable() {
|
||||
return changeable;
|
||||
}
|
||||
}
|
118
src/com/github/theholywaffle/teamspeak3/api/ClientProperty.java
Normale Datei
118
src/com/github/theholywaffle/teamspeak3/api/ClientProperty.java
Normale Datei
@ -0,0 +1,118 @@
|
||||
package com.github.theholywaffle.teamspeak3.api;
|
||||
|
||||
/*
|
||||
* #%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.TS3Api;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public enum ClientProperty implements Property {
|
||||
|
||||
CID(false),
|
||||
CLIENT_AWAY(false),
|
||||
CLIENT_AWAY_MESSAGE(false),
|
||||
/**
|
||||
* Property for the Overwolf badge and any myTeamSpeak badges.
|
||||
* Can be changed only for the own client by using {@link TS3Api#updateClient(Map)}.
|
||||
* <p>
|
||||
* String format: {@code overwolf=n:badges=guid,guid,guid(,guid...)}<br>
|
||||
* where {@code n} is 0 or 1 and {@code guid} is 128-bit badge GUIDs
|
||||
* </p>
|
||||
*/
|
||||
CLIENT_BADGES(true),
|
||||
CLIENT_BASE64HASHCLIENTUID(false),
|
||||
CLIENT_CHANNEL_GROUP_ID(false),
|
||||
CLIENT_CHANNEL_GROUP_INHERITED_CHANNEL_ID(false),
|
||||
CLIENT_COUNTRY(false),
|
||||
CLIENT_CREATED(false),
|
||||
CLIENT_DATABASE_ID(false),
|
||||
CLIENT_DEFAULT_CHANNEL(false),
|
||||
CLIENT_DEFAULT_TOKEN(false),
|
||||
CLIENT_DESCRIPTION(true),
|
||||
CLIENT_FLAG_AVATAR(false),
|
||||
CLIENT_FLAG_TALKING(false),
|
||||
CLIENT_ICON_ID(true),
|
||||
CLIENT_IDLE_TIME(false),
|
||||
CLIENT_INPUT_HARDWARE(false),
|
||||
CLIENT_INPUT_MUTED(false),
|
||||
CLIENT_IS_CHANNEL_COMMANDER(true),
|
||||
CLIENT_IS_PRIORITY_SPEAKER(false),
|
||||
CLIENT_IS_RECORDING(false),
|
||||
CLIENT_IS_TALKER(true),
|
||||
CLIENT_LASTCONNECTED(false),
|
||||
CLIENT_LOGIN_NAME(false),
|
||||
CLIENT_META_DATA(false),
|
||||
CLIENT_MONTH_BYTES_DOWNLOADED(false),
|
||||
CLIENT_MONTH_BYTES_UPLOADED(false),
|
||||
CLIENT_NEEDED_SERVERQUERY_VIEW_POWER(false),
|
||||
CLIENT_NICKNAME(true),
|
||||
CLIENT_NICKNAME_PHONETIC(false),
|
||||
CLIENT_OUTPUT_HARDWARE(false),
|
||||
CLIENT_OUTPUT_MUTED(false),
|
||||
CLIENT_OUTPUTONLY_MUTED(false),
|
||||
CLIENT_PLATFORM(false),
|
||||
CLIENT_SERVERGROUPS(false),
|
||||
CLIENT_TALK_POWER(false),
|
||||
CLIENT_TALK_REQUEST(false),
|
||||
CLIENT_TALK_REQUEST_MSG(false),
|
||||
CLIENT_TOTAL_BYTES_DOWNLOADED(false),
|
||||
CLIENT_TOTAL_BYTES_UPLOADED(false),
|
||||
CLIENT_TOTALCONNECTIONS(false),
|
||||
CLIENT_TYPE(false),
|
||||
CLIENT_UNIQUE_IDENTIFIER(false),
|
||||
CLIENT_UNREAD_MESSAGES(false),
|
||||
CLIENT_VERSION(false),
|
||||
CONNECTION_BANDWIDTH_RECEIVED_LAST_MINUTE_TOTAL(false),
|
||||
CONNECTION_BANDWIDTH_RECEIVED_LAST_SECOND_TOTAL(false),
|
||||
CONNECTION_BANDWIDTH_SENT_LAST_MINUTE_TOTAL(false),
|
||||
CONNECTION_BANDWIDTH_SENT_LAST_SECOND_TOTAL(false),
|
||||
CONNECTION_BYTES_RECEIVED_TOTAL(false),
|
||||
CONNECTION_BYTES_SENT_TOTAL(false),
|
||||
CONNECTION_CLIENT_IP(false),
|
||||
CONNECTION_CONNECTED_TIME(false),
|
||||
CONNECTION_FILETRANSFER_BANDWIDTH_RECEIVED(false),
|
||||
CONNECTION_FILETRANSFER_BANDWIDTH_SENT(false),
|
||||
CONNECTION_PACKETS_RECEIVED_TOTAL(false),
|
||||
CONNECTION_PACKETS_SENT_TOTAL(false);
|
||||
|
||||
private final boolean changeable;
|
||||
|
||||
ClientProperty(boolean changeable) {
|
||||
this.changeable = changeable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChangeable() {
|
||||
return changeable;
|
||||
}
|
||||
}
|
132
src/com/github/theholywaffle/teamspeak3/api/Codec.java
Normale Datei
132
src/com/github/theholywaffle/teamspeak3/api/Codec.java
Normale Datei
@ -0,0 +1,132 @@
|
||||
package com.github.theholywaffle.teamspeak3.api;
|
||||
|
||||
/*
|
||||
* #%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.TS3Api;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Voice codecs currently used by TeamSpeak3.
|
||||
* <p>
|
||||
* A channel's codec may be edited by using {@link TS3Api#editChannel(int, Map)}.
|
||||
* All voice data may also be encrypted.
|
||||
* </p>
|
||||
*/
|
||||
public enum Codec {
|
||||
|
||||
/**
|
||||
* The Speex narrowband codec with a sampling rate of 8kHz.
|
||||
* <p>
|
||||
* All Speex codecs are basically obsolete as Opus is better
|
||||
* in every aspect and has a comparable required bandwidth.
|
||||
* </p><ul>
|
||||
* <li>Bandwidth per client with codec quality 0: 2.49 KiB/s</li>
|
||||
* <li>Bandwidth per client with codec quality 10: 5.22 KiB/s</li>
|
||||
* </ul>
|
||||
*/
|
||||
SPEEX_NARROWBAND(0),
|
||||
|
||||
/**
|
||||
* The Speex wideband codec with a sampling rate of 16kHz.
|
||||
* <p>
|
||||
* All Speex codecs are basically obsolete as Opus is better
|
||||
* in every aspect and has a comparable required bandwidth.
|
||||
* </p><ul>
|
||||
* <li>Bandwidth per client with codec quality 0: 2.69 KiB/s</li>
|
||||
* <li>Bandwidth per client with codec quality 10: 7.37 KiB/s</li>
|
||||
* </ul>
|
||||
*/
|
||||
SPEEX_WIDEBAND(1),
|
||||
|
||||
/**
|
||||
* The Speex ultra-wideband codec with a sampling rate of 32kHz.
|
||||
* <p>
|
||||
* All Speex codecs are basically obsolete as Opus is better
|
||||
* in every aspect and has a comparable required bandwidth.
|
||||
* </p><ul>
|
||||
* <li>Bandwidth per client with codec quality 0: 2.73 KiB/s</li>
|
||||
* <li>Bandwidth per client with codec quality 10: 7.57 KiB/s</li>
|
||||
* </ul>
|
||||
*/
|
||||
SPEEX_ULTRAWIDEBAND(2),
|
||||
|
||||
/**
|
||||
* The CELT Mono codec. It is optimised for music but still generates very good
|
||||
* results in voice transmission.
|
||||
* <p>
|
||||
* Note that this codec requires the most bandwidth of all currently available codecs.
|
||||
* </p><ul>
|
||||
* <li>Bandwidth per client with codec quality 0: 6.10 KiB/s</li>
|
||||
* <li>Bandwidth per client with codec quality 10: 13.92 KiB/s</li>
|
||||
* </ul>
|
||||
*/
|
||||
CELT_MONO(3),
|
||||
|
||||
/**
|
||||
* The Opus codec optimised for voice transmission.
|
||||
* <p>
|
||||
* This is the default codec used by TeamSpeak and usually achieves the
|
||||
* best results for voice transmission.
|
||||
* </p><ul>
|
||||
* <li>Bandwidth per client with codec quality 0: 2.73 KiB/s</li>
|
||||
* <li>Bandwidth per client with codec quality 10: 7.71 KiB/s</li>
|
||||
* </ul>
|
||||
*/
|
||||
OPUS_VOICE(4),
|
||||
|
||||
/**
|
||||
* The Opus codec optimised for music transmission.
|
||||
* <p>
|
||||
* Please note that if used only to transmit speech, this codec can
|
||||
* sound worse than Opus Voice despite a higher bandwidth.
|
||||
* </p><ul>
|
||||
* <li>Bandwidth per client with codec quality 0: 3.08 KiB/s</li>
|
||||
* <li>Bandwidth per client with codec quality 10: 11.87 KiB/s</li>
|
||||
* </ul>
|
||||
*/
|
||||
OPUS_MUSIC(5),
|
||||
|
||||
/**
|
||||
* An unknown codec.
|
||||
* <p>
|
||||
* If you ever encounter an unknown codec, please tell us!
|
||||
* We may have to update the API.
|
||||
* </p>
|
||||
*/
|
||||
UNKNOWN(-1);
|
||||
|
||||
private final int i;
|
||||
|
||||
Codec(int i) {
|
||||
this.i = i;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return i;
|
||||
}
|
||||
}
|
76
src/com/github/theholywaffle/teamspeak3/api/CodecEncryptionMode.java
Normale Datei
76
src/com/github/theholywaffle/teamspeak3/api/CodecEncryptionMode.java
Normale Datei
@ -0,0 +1,76 @@
|
||||
package com.github.theholywaffle.teamspeak3.api;
|
||||
|
||||
/*
|
||||
* #%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.TS3Api;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Describes how the virtual server manages audio encryption.
|
||||
* <p>
|
||||
* Can be edited with {@link TS3Api#editServer(Map)}.
|
||||
* </p>
|
||||
*/
|
||||
public enum CodecEncryptionMode {
|
||||
|
||||
/**
|
||||
* Each channel manages audio encryption on its own.
|
||||
*
|
||||
* @see TS3Api#editChannel(int, Map)
|
||||
*/
|
||||
CODEC_CRYPT_INDIVIDUAL(0),
|
||||
|
||||
/**
|
||||
* Audio encryption is globally disabled on this virtual server.
|
||||
*/
|
||||
CODEC_CRYPT_DISABLED(1),
|
||||
|
||||
/**
|
||||
* Audio encryption is globally enabled on this virtual server.
|
||||
*/
|
||||
CODEC_CRYPT_ENABLED(2),
|
||||
|
||||
/**
|
||||
* An unknown codec encryption mode.
|
||||
* <p>
|
||||
* If you ever encounter an unknown mode, please tell us!
|
||||
* We may have to update the API.
|
||||
* </p>
|
||||
*/
|
||||
UNKNOWN(-1);
|
||||
|
||||
private final int i;
|
||||
|
||||
CodecEncryptionMode(int i) {
|
||||
this.i = i;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return i;
|
||||
}
|
||||
}
|
891
src/com/github/theholywaffle/teamspeak3/api/CommandFuture.java
Normale Datei
891
src/com/github/theholywaffle/teamspeak3/api/CommandFuture.java
Normale Datei
@ -0,0 +1,891 @@
|
||||
package com.github.theholywaffle.teamspeak3.api;
|
||||
|
||||
/*
|
||||
* #%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.TS3ApiAsync;
|
||||
import com.github.theholywaffle.teamspeak3.api.exception.TS3Exception;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Function;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Represents the result of an asynchronous execution of a query command.
|
||||
* <p>
|
||||
* Basically, this class is a container for a server response which will
|
||||
* arrive at some time in the future. It also accounts for the possibility
|
||||
* that a command might fail and that a future might be cancelled by a user.
|
||||
* </p>
|
||||
* A {@code CommandFuture} can therefore have 4 different states:
|
||||
* <ul>
|
||||
* <li><b>Waiting</b> - No response from the server has arrived yet</li>
|
||||
* <li><b>Cancelled</b> - A user cancelled this future before a response from the server could arrive</li>
|
||||
* <li><b>Failed</b> - The server received the command but responded with an error message</li>
|
||||
* <li><b>Succeeded</b> - The server successfully processed the command and sent back a result</li>
|
||||
* </ul>
|
||||
* You can check the state of the future using the methods {@link #isDone()},
|
||||
* {@link #isSuccessful()}, {@link #hasFailed()} and {@link #isCancelled()}.
|
||||
* <p>
|
||||
* A {@code CommandFuture}'s value can be retrieved by calling {@link #get()}
|
||||
* or {@link #get(long, TimeUnit)}, which block the current thread until the
|
||||
* server response arrives. The method with a timeout should be preferred
|
||||
* as there's no guarantee that a proper response (or an error message)
|
||||
* will ever arrive, e.g. in case of a permanent disconnect.
|
||||
* There are also variations of these methods which ignore thread interrupts,
|
||||
* {@link #getUninterruptibly()} and {@link #getUninterruptibly(long, TimeUnit)}.
|
||||
* </p><p>
|
||||
* Note that <b>these methods</b> all wait for the response to arrive and thereby
|
||||
* <b>revert to synchronous</b> execution. If you want to handle the server response
|
||||
* asynchronously, you need to register success and failure listeners.
|
||||
* These listeners will be called in a separate thread once a response arrives.
|
||||
* </p><p>
|
||||
* Each {@code CommandFuture} can only ever have one {@link SuccessListener} and
|
||||
* one {@link FailureListener} registered. All {@link TS3ApiAsync} methods are
|
||||
* guaranteed to return a {@code CommandFuture} with no listeners registered.
|
||||
* </p><p>
|
||||
* To set the value of a {@code CommandFuture}, the {@link #set(Object)} method is used;
|
||||
* to notify it of a failure, {@link #fail(TS3Exception)} is used. You usually
|
||||
* shouldn't call these methods yourself, however. That's the job of the API.
|
||||
* </p><p>
|
||||
* {@code CommandFuture}s are thread-safe. All state-changing methods are synchronized.
|
||||
* </p>
|
||||
*
|
||||
* @param <V>
|
||||
* the type of the value
|
||||
*
|
||||
* @see TS3ApiAsync
|
||||
*/
|
||||
public class CommandFuture<V> implements Future<V> {
|
||||
|
||||
private static final Logger log = ProxyServer.getInstance().getLogger();
|
||||
|
||||
private enum FutureState {
|
||||
WAITING,
|
||||
CANCELLED,
|
||||
FAILED,
|
||||
SUCCEEDED
|
||||
}
|
||||
|
||||
/**
|
||||
* Just a plain object used for its monitor to synchronize access to the
|
||||
* critical sections of this future and to signal state changes to any
|
||||
* threads waiting in {@link #get()} and {@link #getUninterruptibly()} methods.
|
||||
*/
|
||||
private final Object monitor = new Object();
|
||||
|
||||
/**
|
||||
* The current state of the future. Marked as volatile so {@link #isDone()}
|
||||
* and similar functions can work without synchronization.
|
||||
* State transitions and check-then-acts must be guarded by monitor.
|
||||
*/
|
||||
private volatile FutureState state = FutureState.WAITING;
|
||||
|
||||
// All guarded by monitor
|
||||
private V value = null;
|
||||
private TS3Exception exception = null;
|
||||
private SuccessListener<? super V> successListener = null;
|
||||
private FailureListener failureListener = null;
|
||||
|
||||
/**
|
||||
* Waits indefinitely until the command completes.
|
||||
* <p>
|
||||
* If the thread is interrupted while waiting for the command
|
||||
* to complete, this method will throw an {@code InterruptedException}
|
||||
* and the thread's interrupt flag will be cleared.
|
||||
* </p><p><i>
|
||||
* Please note that this method is blocking and thus negates
|
||||
* the advantage of the asynchronous nature of this class.
|
||||
* Consider using {@link #onSuccess(SuccessListener)} and
|
||||
* {@link #onFailure(FailureListener)} instead.
|
||||
* </i></p>
|
||||
*
|
||||
* @throws InterruptedException
|
||||
* if the method is interrupted by calling {@link Thread#interrupt()}.
|
||||
* The interrupt flag will be cleared
|
||||
*/
|
||||
public void await() throws InterruptedException {
|
||||
synchronized (monitor) {
|
||||
while (state == FutureState.WAITING) {
|
||||
monitor.wait();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits for at most the given time until the command completes.
|
||||
* <p>
|
||||
* If the thread is interrupted while waiting for the command
|
||||
* to complete, this method will throw an {@code InterruptedException}
|
||||
* and the thread's interrupt flag will be cleared.
|
||||
* </p><p><i>
|
||||
* Please note that this method is blocking and thus negates
|
||||
* the advantage of the asynchronous nature of this class.
|
||||
* Consider using {@link #onSuccess(SuccessListener)} and
|
||||
* {@link #onFailure(FailureListener)} instead.
|
||||
* </i></p>
|
||||
*
|
||||
* @param timeout
|
||||
* the maximum amount of the given time unit to wait
|
||||
* @param unit
|
||||
* the time unit of the timeout argument
|
||||
*
|
||||
* @throws InterruptedException
|
||||
* if the method is interrupted by calling {@link Thread#interrupt()}.
|
||||
* The interrupt flag will be cleared
|
||||
* @throws TimeoutException
|
||||
* if the given time elapsed without the command completing
|
||||
*/
|
||||
public void await(long timeout, TimeUnit unit) throws InterruptedException, TimeoutException {
|
||||
synchronized (monitor) {
|
||||
final long end = System.currentTimeMillis() + unit.toMillis(timeout);
|
||||
while (state == FutureState.WAITING && System.currentTimeMillis() < end) {
|
||||
monitor.wait(end - System.currentTimeMillis());
|
||||
}
|
||||
|
||||
if (state == FutureState.WAITING) throw new TimeoutException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits indefinitely until the command completes.
|
||||
* <p>
|
||||
* If the thread is interrupted while waiting for the command
|
||||
* to complete, the interrupt is simply ignored and no
|
||||
* {@link InterruptedException} is thrown.
|
||||
* </p><p><i>
|
||||
* Please note that this method is blocking and thus negates
|
||||
* the advantage of the asynchronous nature of this class.
|
||||
* Consider using {@link #onSuccess(SuccessListener)} and
|
||||
* {@link #onFailure(FailureListener)} instead.
|
||||
* </i></p>
|
||||
*/
|
||||
public void awaitUninterruptibly() {
|
||||
synchronized (monitor) {
|
||||
boolean interrupted = false;
|
||||
while (state == FutureState.WAITING) {
|
||||
try {
|
||||
monitor.wait();
|
||||
} catch (InterruptedException e) {
|
||||
interrupted = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (interrupted) {
|
||||
// Restore the interrupt for the caller
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits for at most the given time until the command completes.
|
||||
* <p>
|
||||
* If the thread is interrupted while waiting for the command
|
||||
* to complete, the interrupt is simply ignored and no
|
||||
* {@link InterruptedException} is thrown.
|
||||
* </p><p><i>
|
||||
* Please note that this method is blocking and thus negates
|
||||
* the advantage of the asynchronous nature of this class.
|
||||
* Consider using {@link #onSuccess(SuccessListener)} and
|
||||
* {@link #onFailure(FailureListener)} instead.
|
||||
* </i></p>
|
||||
*
|
||||
* @param timeout
|
||||
* the maximum amount of the given time unit to wait
|
||||
* @param unit
|
||||
* the time unit of the timeout argument
|
||||
*
|
||||
* @throws TimeoutException
|
||||
* if the given time elapsed without the command completing
|
||||
*/
|
||||
public void awaitUninterruptibly(long timeout, TimeUnit unit) throws TimeoutException {
|
||||
synchronized (monitor) {
|
||||
final long end = System.currentTimeMillis() + unit.toMillis(timeout);
|
||||
boolean interrupted = false;
|
||||
|
||||
while (state == FutureState.WAITING && System.currentTimeMillis() < end) {
|
||||
try {
|
||||
monitor.wait(end - System.currentTimeMillis());
|
||||
} catch (InterruptedException e) {
|
||||
interrupted = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (interrupted) {
|
||||
// Restore the interrupt for the caller
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
|
||||
if (state == FutureState.WAITING) throw new TimeoutException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits indefinitely until the command completes
|
||||
* and returns the result of the command.
|
||||
* <p>
|
||||
* If the thread is interrupted while waiting for the command
|
||||
* to complete, this method will throw an {@code InterruptedException}
|
||||
* and the thread's interrupt flag will be cleared.
|
||||
* </p><p><i>
|
||||
* Please note that this method is blocking and thus negates
|
||||
* the advantage of the asynchronous nature of this class.
|
||||
* Consider using {@link #onSuccess(SuccessListener)} and
|
||||
* {@link #onFailure(FailureListener)} instead.
|
||||
* </i></p>
|
||||
*
|
||||
* @return the server response to the command
|
||||
*
|
||||
* @throws InterruptedException
|
||||
* if the method is interrupted by calling {@link Thread#interrupt()}.
|
||||
* The interrupt flag will be cleared
|
||||
* @throws CancellationException
|
||||
* if the {@code CommandFuture} was cancelled before the command completed
|
||||
* @throws TS3Exception
|
||||
* if the command fails
|
||||
*/
|
||||
@Override
|
||||
public V get() throws InterruptedException {
|
||||
synchronized (monitor) {
|
||||
await();
|
||||
|
||||
checkForFailure();
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits for at most the given time until the command completes
|
||||
* and returns the result of the command.
|
||||
* <p>
|
||||
* If the thread is interrupted while waiting for the command
|
||||
* to complete, this method will throw an {@code InterruptedException}
|
||||
* and the thread's interrupt flag will be cleared.
|
||||
* </p><p><i>
|
||||
* Please note that this method is blocking and thus negates
|
||||
* the advantage of the asynchronous nature of this class.
|
||||
* Consider using {@link #onSuccess(SuccessListener)} and
|
||||
* {@link #onFailure(FailureListener)} instead.
|
||||
* </i></p>
|
||||
*
|
||||
* @param timeout
|
||||
* the maximum amount of the given time unit to wait
|
||||
* @param unit
|
||||
* the time unit of the timeout argument
|
||||
*
|
||||
* @return the server response to the command
|
||||
*
|
||||
* @throws InterruptedException
|
||||
* if the method is interrupted by calling {@link Thread#interrupt()}.
|
||||
* The interrupt flag will be cleared
|
||||
* @throws TimeoutException
|
||||
* if the given time elapsed without the command completing
|
||||
* @throws CancellationException
|
||||
* if the {@code CommandFuture} was cancelled before the command completed
|
||||
* @throws TS3Exception
|
||||
* if the command fails
|
||||
*/
|
||||
@Override
|
||||
public V get(long timeout, TimeUnit unit) throws InterruptedException, TimeoutException {
|
||||
synchronized (monitor) {
|
||||
await(timeout, unit);
|
||||
|
||||
checkForFailure();
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits indefinitely until the command completes
|
||||
* and returns the result of the command.
|
||||
* <p>
|
||||
* If the thread is interrupted while waiting for the command
|
||||
* to complete, the interrupt is simply ignored and no
|
||||
* {@link InterruptedException} is thrown.
|
||||
* </p><p><i>
|
||||
* Please note that this method is blocking and thus negates
|
||||
* the advantage of the asynchronous nature of this class.
|
||||
* Consider using {@link #onSuccess(SuccessListener)} and
|
||||
* {@link #onFailure(FailureListener)} instead.
|
||||
* </i></p>
|
||||
*
|
||||
* @return the server response to the command
|
||||
*
|
||||
* @throws CancellationException
|
||||
* if the {@code CommandFuture} was cancelled before the command completed
|
||||
* @throws TS3Exception
|
||||
* if the command fails
|
||||
*/
|
||||
public V getUninterruptibly() {
|
||||
synchronized (monitor) {
|
||||
awaitUninterruptibly();
|
||||
|
||||
checkForFailure();
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits for at most the given time until the command completes
|
||||
* and returns the result of the command.
|
||||
* <p>
|
||||
* If the thread is interrupted while waiting for the command
|
||||
* to complete, the interrupt is simply ignored and no
|
||||
* {@link InterruptedException} is thrown.
|
||||
* </p><p><i>
|
||||
* Please note that this method is blocking and thus negates
|
||||
* the advantage of the asynchronous nature of this class.
|
||||
* Consider using {@link #onSuccess(SuccessListener)} and
|
||||
* {@link #onFailure(FailureListener)} instead.
|
||||
* </i></p>
|
||||
*
|
||||
* @param timeout
|
||||
* the maximum amount of the given time unit to wait
|
||||
* @param unit
|
||||
* the time unit of the timeout argument
|
||||
*
|
||||
* @return the server response to the command
|
||||
*
|
||||
* @throws TimeoutException
|
||||
* if the given time elapsed without the command completing
|
||||
* @throws CancellationException
|
||||
* if the {@code CommandFuture} was cancelled before the command completed
|
||||
* @throws TS3Exception
|
||||
* if the command fails
|
||||
*/
|
||||
public V getUninterruptibly(long timeout, TimeUnit unit) throws TimeoutException {
|
||||
synchronized (monitor) {
|
||||
awaitUninterruptibly(timeout, unit);
|
||||
|
||||
checkForFailure();
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws an exception if the future was either cancelled or the command failed.
|
||||
* <p>
|
||||
* <strong>Must be called with the monitor lock held!</strong>
|
||||
* </p>
|
||||
*
|
||||
* @throws CancellationException
|
||||
* if the future was cancelled
|
||||
* @throws TS3Exception
|
||||
* if the command failed
|
||||
*/
|
||||
private void checkForFailure() {
|
||||
if (state == FutureState.CANCELLED) {
|
||||
throw new CancellationException();
|
||||
} else if (state == FutureState.FAILED) {
|
||||
// Make the stack trace of the exception point to this method and not
|
||||
// SocketReader#run -> TS3ApiAsync#hasFailed, which wouldn't be helpful
|
||||
exception.fillInStackTrace();
|
||||
throw exception;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDone() {
|
||||
return state != FutureState.WAITING;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if this command completed successfully,
|
||||
* i.e. the future wasn't cancelled and the command completed without throwing an exception.
|
||||
*
|
||||
* @return {@code true} if the command completed successfully
|
||||
*/
|
||||
public boolean isSuccessful() {
|
||||
return state == FutureState.SUCCEEDED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return state == FutureState.CANCELLED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if the command failed and threw a {@link TS3Exception}.
|
||||
*
|
||||
* @return {@code true} if the command failed
|
||||
*/
|
||||
public boolean hasFailed() {
|
||||
return state == FutureState.FAILED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of this future. This will mark the future as successful.
|
||||
* <p>
|
||||
* Furthermore, this will run the {@link SuccessListener}, if one is registered.
|
||||
* All exceptions thrown from the body of the {@code SuccessListener} are caught
|
||||
* so no exceptions can leak into user code.
|
||||
* </p><p>
|
||||
* Note that a future's value can only be set once. Subsequent calls to
|
||||
* this method will be ignored.
|
||||
* </p>
|
||||
*
|
||||
* @param value
|
||||
* the value to set this future to
|
||||
*
|
||||
* @return {@code true} if the command was marked as successful
|
||||
*/
|
||||
public boolean set(V value) {
|
||||
SuccessListener<? super V> listener;
|
||||
|
||||
synchronized (monitor) {
|
||||
if (isDone()) return false; // Ignore
|
||||
|
||||
this.state = FutureState.SUCCEEDED;
|
||||
this.value = value;
|
||||
listener = successListener;
|
||||
monitor.notifyAll();
|
||||
}
|
||||
|
||||
if (listener != null) {
|
||||
try {
|
||||
listener.handleSuccess(value);
|
||||
} catch (Exception e) {
|
||||
// Whatever happens, we do not want a user error to leak into our logic
|
||||
log.log(Level.SEVERE, "SuccessListener threw an exception", e);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies this future that the command has failed.
|
||||
* <p>
|
||||
* Furthermore, this will run the {@link FailureListener}, if one is registered.
|
||||
* All exceptions thrown from the body of the {@code FailureListener} are caught
|
||||
* so no exceptions can leak into user code.
|
||||
* </p><p>
|
||||
* Note that a future can only fail once. Subsequent calls to this method will be ignored.
|
||||
* </p>
|
||||
*
|
||||
* @param exception
|
||||
* the exception that occurred while executing this command
|
||||
*
|
||||
* @return {@code true} if the command was marked as failed
|
||||
*/
|
||||
public boolean fail(TS3Exception exception) {
|
||||
FailureListener listener;
|
||||
|
||||
synchronized (monitor) {
|
||||
if (isDone()) return false; // Ignore
|
||||
|
||||
this.state = FutureState.FAILED;
|
||||
this.exception = exception;
|
||||
listener = failureListener;
|
||||
monitor.notifyAll();
|
||||
}
|
||||
|
||||
if (listener != null) {
|
||||
try {
|
||||
listener.handleFailure(exception);
|
||||
} catch (Exception e) {
|
||||
// Whatever happens, we do not want a user error to leak into our logic
|
||||
log.log(Level.SEVERE, "FailureListener threw an exception", e);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* <p>
|
||||
* Cancelling a {@code CommandFuture} will <b>not</b> actually cancel the
|
||||
* execution of the command which was sent to the TeamSpeak server.
|
||||
* </p><p>
|
||||
* It will, however, prevent the {@link SuccessListener} and the
|
||||
* {@link FailureListener} from firing, provided a response from the
|
||||
* server has not yet arrived.
|
||||
* </p>
|
||||
*/
|
||||
@Override
|
||||
public boolean cancel(boolean mayInterruptIfRunning) {
|
||||
synchronized (monitor) {
|
||||
if (isDone()) return false; // Ignore
|
||||
|
||||
this.state = FutureState.CANCELLED;
|
||||
monitor.notifyAll();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a {@link SuccessListener} which will be notified when this future
|
||||
* succeeded and a value has been set.
|
||||
* <p>
|
||||
* If this future has already succeeded, this method will immediately call
|
||||
* the listener method, which will be executed synchronously.
|
||||
* </p>
|
||||
*
|
||||
* @param listener
|
||||
* the listener to notify of a success
|
||||
*
|
||||
* @return this object for chaining
|
||||
*/
|
||||
public CommandFuture<V> onSuccess(SuccessListener<? super V> listener) {
|
||||
boolean runSuccessListener;
|
||||
V successValue;
|
||||
|
||||
synchronized (monitor) {
|
||||
if (successListener != null) {
|
||||
throw new IllegalStateException("Listener already set");
|
||||
}
|
||||
successListener = listener;
|
||||
|
||||
runSuccessListener = isSuccessful();
|
||||
successValue = value;
|
||||
}
|
||||
|
||||
if (runSuccessListener) {
|
||||
listener.handleSuccess(successValue);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a {@link FailureListener} which will be notified when this future
|
||||
* fails because of a error returned by the TeamSpeak server.
|
||||
* <p>
|
||||
* If this future has already failed, this method will immediately call
|
||||
* the listener method, which will be executed synchronously.
|
||||
* </p>
|
||||
*
|
||||
* @param listener
|
||||
* the listener to notify of a failure
|
||||
*
|
||||
* @return this object for chaining
|
||||
*/
|
||||
public CommandFuture<V> onFailure(FailureListener listener) {
|
||||
boolean runFailureListener;
|
||||
TS3Exception failureException;
|
||||
|
||||
synchronized (monitor) {
|
||||
if (failureListener != null) {
|
||||
throw new IllegalStateException("Listener already set");
|
||||
}
|
||||
failureListener = listener;
|
||||
|
||||
runFailureListener = hasFailed();
|
||||
failureException = exception;
|
||||
}
|
||||
|
||||
if (runFailureListener) {
|
||||
listener.handleFailure(failureException);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Forwards a success to another future by calling {@link #set(Object)} on
|
||||
* that future with the value this future was set to.
|
||||
* <p>
|
||||
* This will register a {@link SuccessListener}, meaning that you will not
|
||||
* be able to register another {@code SuccessListener}.
|
||||
* </p>
|
||||
*
|
||||
* @param otherFuture
|
||||
* the future to forward a success to
|
||||
*
|
||||
* @return this object for chaining
|
||||
*/
|
||||
public CommandFuture<V> forwardSuccess(final CommandFuture<? super V> otherFuture) {
|
||||
return onSuccess(otherFuture::set);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forwards a failure to another future by calling {@link #fail(TS3Exception)}
|
||||
* on that future with the error that caused this future to fail.
|
||||
* <p>
|
||||
* This will register a {@link FailureListener}, meaning that you will not
|
||||
* be able to register another {@code FailureListener}.
|
||||
* </p>
|
||||
*
|
||||
* @param otherFuture
|
||||
* the future to forward a failure to
|
||||
*
|
||||
* @return this object for chaining
|
||||
*/
|
||||
public CommandFuture<V> forwardFailure(final CommandFuture<?> otherFuture) {
|
||||
return onFailure(otherFuture::fail);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forwards both a success as well as a failure to another {@code CommandFuture}.
|
||||
* This method just calls both {@link #forwardSuccess(CommandFuture)} and
|
||||
* {@link #forwardFailure(CommandFuture)}.
|
||||
* <p>
|
||||
* This will set both a {@link SuccessListener} as well as a {@link FailureListener},
|
||||
* so no other listeners can be registered.
|
||||
* </p>
|
||||
*
|
||||
* @param otherFuture
|
||||
* the future which should be notified about
|
||||
*/
|
||||
public void forwardResult(final CommandFuture<V> otherFuture) {
|
||||
forwardSuccess(otherFuture).forwardFailure(otherFuture);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@code CommandFuture} that succeeds with {@code fn(result)}
|
||||
* if the original future succeeded with a value {@code result}, and fails
|
||||
* if the original future failed or if the mapping function {@code fn} threw
|
||||
* an exception.
|
||||
*
|
||||
* @param fn
|
||||
* a function that maps the result value of type {@code V} to a value of type {@code F}
|
||||
* @param <F>
|
||||
* the result type of {@code fn}
|
||||
*
|
||||
* @return a new {@code CommandFuture} that will hold the return value of {@code fn}
|
||||
*/
|
||||
public <F> CommandFuture<F> map(Function<? super V, ? extends F> fn) {
|
||||
CommandFuture<F> target = new CommandFuture<>();
|
||||
onSuccess(result -> {
|
||||
F output;
|
||||
try {
|
||||
output = fn.apply(result);
|
||||
} catch (Exception ex) {
|
||||
target.fail(new TS3Exception("CommandFuture 'map' function threw an exception", ex));
|
||||
return;
|
||||
}
|
||||
target.set(output);
|
||||
}).forwardFailure(target);
|
||||
return target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@code CommandFuture} that succeeds with the result value of
|
||||
* the {@code CommandFuture} returned by {@code fn} if both the original future
|
||||
* and the future returned by {@code fn} succeed.
|
||||
* <p>
|
||||
* The created {@code CommandFuture} fails if the original future failed,
|
||||
* the future returned by {@code fn} fails, or if {@code fn} throws an exception.
|
||||
* </p><p>
|
||||
* If {@code fn} returns {@code null}, the created {@code CommandFuture}
|
||||
* will immediately succeed with a value of {@code null}. To create this effect
|
||||
* with non-null values, return an {@link #immediate(Object)} future instead.
|
||||
* </p>
|
||||
*
|
||||
* @param fn
|
||||
* a function that maps the result value of type {@code V} to a {@code CommandFuture<F>}
|
||||
* @param <F>
|
||||
* the result type of the future returned by {@code fn}
|
||||
*
|
||||
* @return a new {@code CommandFuture} that will hold the result of the future returned by {@code fn}
|
||||
*/
|
||||
public <F> CommandFuture<F> then(Function<? super V, CommandFuture<F>> fn) {
|
||||
CommandFuture<F> target = new CommandFuture<>();
|
||||
onSuccess(result -> {
|
||||
CommandFuture<F> nextFuture;
|
||||
try {
|
||||
nextFuture = fn.apply(result);
|
||||
} catch (Exception ex) {
|
||||
target.fail(new TS3Exception("CommandFuture 'then' function threw an exception", ex));
|
||||
return;
|
||||
}
|
||||
|
||||
if (nextFuture == null) {
|
||||
target.set(null); // Propagate null shortcut
|
||||
} else {
|
||||
nextFuture.forwardResult(target);
|
||||
}
|
||||
}).forwardFailure(target);
|
||||
return target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new {@code CommandFuture} that already has a value set.
|
||||
*
|
||||
* @param value
|
||||
* the default value for the new {@code CommandFuture}
|
||||
* @param <V>
|
||||
* the dynamic type of the value, will usually be inferred
|
||||
*
|
||||
* @return a new {@code CommandFuture} with a default value
|
||||
*/
|
||||
public static <V> CommandFuture<V> immediate(V value) {
|
||||
final CommandFuture<V> future = new CommandFuture<>();
|
||||
future.set(value);
|
||||
return future;
|
||||
}
|
||||
|
||||
/**
|
||||
* Combines multiple {@code CommandFuture}s into a single future, which will
|
||||
* succeed if all futures succeed and fail as soon as one future fails.
|
||||
*
|
||||
* @param futures
|
||||
* the futures to combine
|
||||
* @param <F>
|
||||
* the common return type of the futures
|
||||
*
|
||||
* @return a future which succeeds if all supplied futures succeed
|
||||
*/
|
||||
@SafeVarargs
|
||||
public static <F> CommandFuture<List<F>> ofAll(CommandFuture<F>... futures) {
|
||||
return ofAll(Arrays.asList(futures));
|
||||
}
|
||||
|
||||
/**
|
||||
* Combines a collection of {@code CommandFuture}s into a single future, which will
|
||||
* succeed if all futures succeed and fail as soon as one future fails.
|
||||
*
|
||||
* @param futures
|
||||
* the futures to combine
|
||||
* @param <F>
|
||||
* the common return type of the futures
|
||||
*
|
||||
* @return a future which succeeds if all supplied futures succeed
|
||||
*/
|
||||
public static <F> CommandFuture<List<F>> ofAll(final Collection<CommandFuture<F>> futures) {
|
||||
if (futures.isEmpty()) throw new IllegalArgumentException("Requires at least 1 future");
|
||||
|
||||
@SuppressWarnings("unchecked") final F[] results = (F[]) new Object[futures.size()];
|
||||
final AtomicInteger successCounter = new AtomicInteger(futures.size());
|
||||
final CommandFuture<List<F>> combined = new CommandFuture<>();
|
||||
|
||||
final Iterator<CommandFuture<F>> iterator = futures.iterator();
|
||||
for (int i = 0; iterator.hasNext(); ++i) {
|
||||
final int index = i;
|
||||
final CommandFuture<F> future = iterator.next();
|
||||
|
||||
future.forwardFailure(combined).onSuccess(result -> {
|
||||
results[index] = result;
|
||||
|
||||
if (successCounter.decrementAndGet() == 0) {
|
||||
combined.set(Arrays.asList(results));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return combined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Combines multiple {@code CommandFuture}s into a single future, which will
|
||||
* succeed if any of the futures succeeds and fail if all of the futures fail.
|
||||
*
|
||||
* @param futures
|
||||
* the futures to combine
|
||||
* @param <F>
|
||||
* the common return type of the futures
|
||||
*
|
||||
* @return a future which succeeds if one of the supplied futures succeeds
|
||||
*/
|
||||
@SafeVarargs
|
||||
public static <F> CommandFuture<F> ofAny(CommandFuture<F>... futures) {
|
||||
return ofAny(Arrays.asList(futures));
|
||||
}
|
||||
|
||||
/**
|
||||
* Combines a collection of {@code CommandFuture}s into a single future, which will
|
||||
* succeed as soon as one of the futures succeeds and fail if all futures fail.
|
||||
*
|
||||
* @param futures
|
||||
* the futures to combine
|
||||
* @param <F>
|
||||
* the common return type of the futures
|
||||
*
|
||||
* @return a future which succeeds if one of the supplied futures succeeds
|
||||
*/
|
||||
public static <F> CommandFuture<F> ofAny(final Collection<CommandFuture<F>> futures) {
|
||||
if (futures.isEmpty()) throw new IllegalArgumentException("Requires at least 1 future");
|
||||
|
||||
final CommandFuture<F> any = new CommandFuture<>();
|
||||
final AtomicInteger failureCounter = new AtomicInteger(futures.size());
|
||||
|
||||
for (CommandFuture<F> future : futures) {
|
||||
future.forwardSuccess(any).onFailure(exception -> {
|
||||
if (failureCounter.decrementAndGet() == 0) {
|
||||
any.fail(exception);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return any;
|
||||
}
|
||||
|
||||
/**
|
||||
* A listener which will be notified if the {@link CommandFuture} succeeded.
|
||||
* In that case, {@link #handleSuccess(Object)} will be called with the value
|
||||
* the future has been set to.
|
||||
* <p>
|
||||
* A {@code CommandFuture}'s {@code SuccessListener} can be set by calling
|
||||
* {@link #onSuccess(SuccessListener)}.
|
||||
* </p>
|
||||
*
|
||||
* @param <V>
|
||||
* the type of the value
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface SuccessListener<V> {
|
||||
|
||||
/**
|
||||
* The method to be executed when the command succeeds.
|
||||
*
|
||||
* @param result
|
||||
* the result of the command
|
||||
*/
|
||||
void handleSuccess(V result);
|
||||
}
|
||||
|
||||
/**
|
||||
* A listener which will be notified if the {@link CommandFuture} failed.
|
||||
* In that case, {@link #handleFailure(TS3Exception)} will be called with
|
||||
* the exception that occurred while executing this command.
|
||||
* <p>
|
||||
* A {@code CommandFuture}'s {@code FailureListener} can be set by calling
|
||||
* {@link #onFailure(FailureListener)}.
|
||||
* </p>
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface FailureListener {
|
||||
|
||||
/**
|
||||
* The method to be executed when the command failed.
|
||||
*
|
||||
* @param exception
|
||||
* the exception that occurred while executing this command
|
||||
*/
|
||||
void handleFailure(TS3Exception exception);
|
||||
}
|
||||
}
|
45
src/com/github/theholywaffle/teamspeak3/api/HostBannerMode.java
Normale Datei
45
src/com/github/theholywaffle/teamspeak3/api/HostBannerMode.java
Normale Datei
@ -0,0 +1,45 @@
|
||||
package com.github.theholywaffle.teamspeak3.api;
|
||||
|
||||
/*
|
||||
* #%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%
|
||||
*/
|
||||
|
||||
public enum HostBannerMode {
|
||||
NO_ADJUST(0),
|
||||
IGNORE_ASPECT(1),
|
||||
KEEP_ASPECT(2),
|
||||
UNKNOWN(-1);
|
||||
|
||||
private final int i;
|
||||
|
||||
HostBannerMode(int i) {
|
||||
this.i = i;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return i;
|
||||
}
|
||||
|
||||
}
|
46
src/com/github/theholywaffle/teamspeak3/api/HostMessageMode.java
Normale Datei
46
src/com/github/theholywaffle/teamspeak3/api/HostMessageMode.java
Normale Datei
@ -0,0 +1,46 @@
|
||||
package com.github.theholywaffle.teamspeak3.api;
|
||||
|
||||
/*
|
||||
* #%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%
|
||||
*/
|
||||
|
||||
public enum HostMessageMode {
|
||||
|
||||
LOG(1),
|
||||
MODAL(2),
|
||||
MODAL_QUIT(3),
|
||||
UNKNOWN(-1);
|
||||
|
||||
private final int i;
|
||||
|
||||
HostMessageMode(int i) {
|
||||
this.i = i;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return i;
|
||||
}
|
||||
|
||||
}
|
46
src/com/github/theholywaffle/teamspeak3/api/LogLevel.java
Normale Datei
46
src/com/github/theholywaffle/teamspeak3/api/LogLevel.java
Normale Datei
@ -0,0 +1,46 @@
|
||||
package com.github.theholywaffle.teamspeak3.api;
|
||||
|
||||
/*
|
||||
* #%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%
|
||||
*/
|
||||
|
||||
public enum LogLevel {
|
||||
|
||||
ERROR(1),
|
||||
WARNING(2),
|
||||
DEBUG(3),
|
||||
INFO(4);
|
||||
|
||||
private final int i;
|
||||
|
||||
LogLevel(int i) {
|
||||
this.i = i;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return i;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package com.github.theholywaffle.teamspeak3.api;
|
||||
|
||||
/*
|
||||
* #%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%
|
||||
*/
|
||||
|
||||
public enum PermissionGroupDatabaseType {
|
||||
|
||||
TEMPLATE(0),
|
||||
REGULAR(1),
|
||||
QUERY(2);
|
||||
|
||||
private final int i;
|
||||
|
||||
PermissionGroupDatabaseType(int i) {
|
||||
this.i = i;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return i;
|
||||
}
|
||||
|
||||
}
|
78
src/com/github/theholywaffle/teamspeak3/api/PermissionGroupType.java
Normale Datei
78
src/com/github/theholywaffle/teamspeak3/api/PermissionGroupType.java
Normale Datei
@ -0,0 +1,78 @@
|
||||
package com.github.theholywaffle.teamspeak3.api;
|
||||
|
||||
/*
|
||||
* #%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.wrapper.PermissionAssignment;
|
||||
|
||||
/**
|
||||
* An enum describing where a {@link PermissionAssignment} originates from.
|
||||
*/
|
||||
public enum PermissionGroupType {
|
||||
|
||||
/**
|
||||
* A permission assigned to a server group.
|
||||
*/
|
||||
SERVER_GROUP(0),
|
||||
|
||||
/**
|
||||
* A permission assigned to a client on a server-wide level.
|
||||
*/
|
||||
GLOBAL_CLIENT(1),
|
||||
|
||||
/**
|
||||
* A permission requirement for certain actions in a channel.
|
||||
* <p>
|
||||
* Examples: Join, talk, subscribe and file upload permission requirements
|
||||
* </p>
|
||||
*/
|
||||
CHANNEL(2),
|
||||
|
||||
/**
|
||||
* A permission assigned to a channel group.
|
||||
*/
|
||||
CHANNEL_GROUP(3),
|
||||
|
||||
/**
|
||||
* A permission assigned to a client in a specific channel.
|
||||
* <p>
|
||||
* This is mostly used for the priority speaker feature by granting
|
||||
* {@code b_client_is_priority_speaker} to a client in a channel.
|
||||
* </p>
|
||||
*/
|
||||
CHANNEL_CLIENT(4);
|
||||
|
||||
private final int i;
|
||||
|
||||
PermissionGroupType(int i) {
|
||||
this.i = i;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return i;
|
||||
}
|
||||
|
||||
}
|
44
src/com/github/theholywaffle/teamspeak3/api/PrivilegeKeyType.java
Normale Datei
44
src/com/github/theholywaffle/teamspeak3/api/PrivilegeKeyType.java
Normale Datei
@ -0,0 +1,44 @@
|
||||
package com.github.theholywaffle.teamspeak3.api;
|
||||
|
||||
/*
|
||||
* #%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%
|
||||
*/
|
||||
|
||||
public enum PrivilegeKeyType {
|
||||
|
||||
SERVER_GROUP(0),
|
||||
CHANNEL_GROUP(1);
|
||||
|
||||
private final int i;
|
||||
|
||||
PrivilegeKeyType(int i) {
|
||||
this.i = i;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return i;
|
||||
}
|
||||
|
||||
}
|
34
src/com/github/theholywaffle/teamspeak3/api/Property.java
Normale Datei
34
src/com/github/theholywaffle/teamspeak3/api/Property.java
Normale Datei
@ -0,0 +1,34 @@
|
||||
package com.github.theholywaffle.teamspeak3.api;
|
||||
|
||||
/*
|
||||
* #%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%
|
||||
*/
|
||||
|
||||
public interface Property {
|
||||
|
||||
String getName();
|
||||
|
||||
boolean isChangeable();
|
||||
}
|
44
src/com/github/theholywaffle/teamspeak3/api/ReasonIdentifier.java
Normale Datei
44
src/com/github/theholywaffle/teamspeak3/api/ReasonIdentifier.java
Normale Datei
@ -0,0 +1,44 @@
|
||||
package com.github.theholywaffle.teamspeak3.api;
|
||||
|
||||
/*
|
||||
* #%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%
|
||||
*/
|
||||
|
||||
public enum ReasonIdentifier {
|
||||
|
||||
REASON_KICK_CHANNEL(4),
|
||||
REASON_KICK_SERVER(5);
|
||||
|
||||
private final int i;
|
||||
|
||||
ReasonIdentifier(int i) {
|
||||
this.i = i;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return i;
|
||||
}
|
||||
|
||||
}
|
51
src/com/github/theholywaffle/teamspeak3/api/ServerGroupType.java
Normale Datei
51
src/com/github/theholywaffle/teamspeak3/api/ServerGroupType.java
Normale Datei
@ -0,0 +1,51 @@
|
||||
package com.github.theholywaffle.teamspeak3.api;
|
||||
|
||||
/*
|
||||
* #%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%
|
||||
*/
|
||||
|
||||
public enum ServerGroupType {
|
||||
|
||||
CHANNEL_GUEST(10),
|
||||
SERVER_GUEST(15),
|
||||
QUERY_GUEST(20),
|
||||
CHANNEL_VOICE(25),
|
||||
SERVER_NORMAL(30),
|
||||
CHANNEL_OPERATOR(35),
|
||||
CHANNEL_ADMIN(40),
|
||||
SERVER_ADMIN(45),
|
||||
QUERY_ADMIN(50);
|
||||
|
||||
private final int i;
|
||||
|
||||
ServerGroupType(int i) {
|
||||
this.i = i;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return i;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
package com.github.theholywaffle.teamspeak3.api;
|
||||
|
||||
/*
|
||||
* #%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.Locale;
|
||||
|
||||
public enum ServerInstanceProperty implements Property {
|
||||
|
||||
CONNECTION_BANDWIDTH_RECEIVED_LAST_MINUTE_TOTAL(false),
|
||||
CONNECTION_BANDWIDTH_RECEIVED_LAST_SECOND_TOTAL(false),
|
||||
CONNECTION_BANDWIDTH_SENT_LAST_MINUTE_TOTAL(false),
|
||||
CONNECTION_BANDWIDTH_SENT_LAST_SECOND_TOTAL(false),
|
||||
CONNECTION_BYTES_RECEIVED_TOTAL(false),
|
||||
CONNECTION_BYTES_SENT_TOTAL(false),
|
||||
CONNECTION_FILETRANSFER_BANDWIDTH_RECEIVED(false),
|
||||
CONNECTION_FILETRANSFER_BANDWIDTH_SENT(false),
|
||||
CONNECTION_FILETRANSFER_BYTES_RECEIVED_TOTAL(false),
|
||||
CONNECTION_FILETRANSFER_BYTES_SENT_TOTAL(false),
|
||||
CONNECTION_PACKETS_RECEIVED_TOTAL(false),
|
||||
CONNECTION_PACKETS_SENT_TOTAL(false),
|
||||
HOST_TIMESTAMP_UTC(false),
|
||||
INSTANCE_UPTIME(false),
|
||||
SERVERINSTANCE_DATABASE_VERSION(false),
|
||||
SERVERINSTANCE_FILETRANSFER_PORT(true),
|
||||
SERVERINSTANCE_GUEST_SERVERQUERY_GROUP(true),
|
||||
SERVERINSTANCE_MAX_DOWNLOAD_TOTAL_BANDWIDTH(true),
|
||||
SERVERINSTANCE_MAX_UPLOAD_TOTAL_BANDWIDTH(true),
|
||||
SERVERINSTANCE_PERMISSIONS_VERSION(false),
|
||||
SERVERINSTANCE_SERVERQUERY_BAN_TIME(true),
|
||||
SERVERINSTANCE_SERVERQUERY_FLOOD_COMMANDS(true),
|
||||
SERVERINSTANCE_SERVERQUERY_FLOOD_TIME(true),
|
||||
SERVERINSTANCE_TEMPLATE_CHANNELADMIN_GROUP(true),
|
||||
SERVERINSTANCE_TEMPLATE_CHANNELDEFAULT_GROUP(true),
|
||||
SERVERINSTANCE_TEMPLATE_SERVERADMIN_GROUP(true),
|
||||
SERVERINSTANCE_TEMPLATE_SERVERDEFAULT_GROUP(true),
|
||||
VIRTUALSERVERS_RUNNING_TOTAL(false),
|
||||
VIRTUALSERVERS_TOTAL_CHANNELS_ONLINE(false),
|
||||
VIRTUALSERVERS_TOTAL_CLIENTS_ONLINE(false),
|
||||
VIRTUALSERVERS_TOTAL_MAXCLIENTS(false);
|
||||
|
||||
private final boolean changeable;
|
||||
|
||||
ServerInstanceProperty(boolean changeable) {
|
||||
this.changeable = changeable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChangeable() {
|
||||
return changeable;
|
||||
}
|
||||
}
|
41
src/com/github/theholywaffle/teamspeak3/api/Snapshot.java
Normale Datei
41
src/com/github/theholywaffle/teamspeak3/api/Snapshot.java
Normale Datei
@ -0,0 +1,41 @@
|
||||
package com.github.theholywaffle.teamspeak3.api;
|
||||
|
||||
/*
|
||||
* #%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%
|
||||
*/
|
||||
|
||||
public class Snapshot {
|
||||
|
||||
private final String snapshot;
|
||||
|
||||
public Snapshot(String snapshot) {
|
||||
this.snapshot = snapshot;
|
||||
}
|
||||
|
||||
public String get() {
|
||||
return snapshot;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package com.github.theholywaffle.teamspeak3.api;
|
||||
|
||||
/*
|
||||
* #%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%
|
||||
*/
|
||||
|
||||
public enum TextMessageTargetMode {
|
||||
|
||||
CLIENT(1),
|
||||
CHANNEL(2),
|
||||
SERVER(3);
|
||||
|
||||
private final int i;
|
||||
|
||||
TextMessageTargetMode(int i) {
|
||||
this.i = i;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return i;
|
||||
}
|
||||
|
||||
}
|
142
src/com/github/theholywaffle/teamspeak3/api/VirtualServerProperty.java
Normale Datei
142
src/com/github/theholywaffle/teamspeak3/api/VirtualServerProperty.java
Normale Datei
@ -0,0 +1,142 @@
|
||||
package com.github.theholywaffle.teamspeak3.api;
|
||||
|
||||
/*
|
||||
* #%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.Locale;
|
||||
|
||||
public enum VirtualServerProperty implements Property {
|
||||
|
||||
CONNECTION_BANDWIDTH_RECEIVED_LAST_MINUTE_TOTAL(false),
|
||||
CONNECTION_BANDWIDTH_RECEIVED_LAST_SECOND_TOTAL(false),
|
||||
CONNECTION_BANDWIDTH_SENT_LAST_MINUTE_TOTAL(false),
|
||||
CONNECTION_BANDWIDTH_SENT_LAST_SECOND_TOTAL(false),
|
||||
CONNECTION_BYTES_RECEIVED_CONTROL(false),
|
||||
CONNECTION_BYTES_RECEIVED_KEEPALIVE(false),
|
||||
CONNECTION_BYTES_RECEIVED_SPEECH(false),
|
||||
CONNECTION_BYTES_RECEIVED_TOTAL(false),
|
||||
CONNECTION_BYTES_SENT_CONTROL(false),
|
||||
CONNECTION_BYTES_SENT_KEEPALIVE(false),
|
||||
CONNECTION_BYTES_SENT_SPEECH(false),
|
||||
CONNECTION_BYTES_SENT_TOTAL(false),
|
||||
CONNECTION_FILETRANSFER_BANDWIDTH_RECEIVED(false),
|
||||
CONNECTION_FILETRANSFER_BANDWIDTH_SENT(false),
|
||||
CONNECTION_FILETRANSFER_BYTES_RECEIVED_TOTAL(false),
|
||||
CONNECTION_FILETRANSFER_BYTES_SENT_TOTAL(false),
|
||||
CONNECTION_PACKETS_RECEIVED_CONTROL(false),
|
||||
CONNECTION_PACKETS_RECEIVED_KEEPALIVE(false),
|
||||
CONNECTION_PACKETS_RECEIVED_SPEECH(false),
|
||||
CONNECTION_PACKETS_RECEIVED_TOTAL(false),
|
||||
CONNECTION_PACKETS_SENT_CONTROL(false),
|
||||
CONNECTION_PACKETS_SENT_KEEPALIVE(false),
|
||||
CONNECTION_PACKETS_SENT_SPEECH(false),
|
||||
CONNECTION_PACKETS_SENT_TOTAL(false),
|
||||
VIRTUALSERVER_ANTIFLOOD_POINTS_NEEDED_COMMAND_BLOCK(true),
|
||||
VIRTUALSERVER_ANTIFLOOD_POINTS_NEEDED_IP_BLOCK(true),
|
||||
VIRTUALSERVER_ANTIFLOOD_POINTS_TICK_REDUCE(true),
|
||||
VIRTUALSERVER_ASK_FOR_PRIVILEGEKEY(false),
|
||||
VIRTUALSERVER_AUTOSTART(true),
|
||||
VIRTUALSERVER_CHANNELSONLINE(false),
|
||||
VIRTUALSERVER_CLIENT_CONNECTIONS(false),
|
||||
VIRTUALSERVER_CLIENTSONLINE(false),
|
||||
VIRTUALSERVER_CODEC_ENCRYPTION_MODE(true),
|
||||
VIRTUALSERVER_COMPLAIN_AUTOBAN_COUNT(true),
|
||||
VIRTUALSERVER_COMPLAIN_AUTOBAN_TIME(true),
|
||||
VIRTUALSERVER_COMPLAIN_REMOVE_TIME(true),
|
||||
VIRTUALSERVER_CREATED(false),
|
||||
VIRTUALSERVER_DEFAULT_CHANNEL_ADMIN_GROUP(true),
|
||||
VIRTUALSERVER_DEFAULT_CHANNEL_GROUP(true),
|
||||
VIRTUALSERVER_DEFAULT_SERVER_GROUP(true),
|
||||
VIRTUALSERVER_DOWNLOAD_QUOTA(true),
|
||||
VIRTUALSERVER_FILEBASE(false),
|
||||
VIRTUALSERVER_FLAG_PASSWORD(false),
|
||||
VIRTUALSERVER_HOSTBANNER_GFX_INTERVAL(true),
|
||||
VIRTUALSERVER_HOSTBANNER_GFX_URL(true),
|
||||
VIRTUALSERVER_HOSTBANNER_MODE(true),
|
||||
VIRTUALSERVER_HOSTBANNER_URL(true),
|
||||
VIRTUALSERVER_HOSTBUTTON_GFX_URL(true),
|
||||
VIRTUALSERVER_HOSTBUTTON_TOOLTIP(true),
|
||||
VIRTUALSERVER_HOSTBUTTON_URL(true),
|
||||
VIRTUALSERVER_HOSTMESSAGE(true),
|
||||
VIRTUALSERVER_HOSTMESSAGE_MODE(true),
|
||||
VIRTUALSERVER_ICON_ID(true),
|
||||
VIRTUALSERVER_ID(false),
|
||||
VIRTUALSERVER_IP(false),
|
||||
VIRTUALSERVER_LOG_CHANNEL(true),
|
||||
VIRTUALSERVER_LOG_CLIENT(true),
|
||||
VIRTUALSERVER_LOG_FILETRANSFER(true),
|
||||
VIRTUALSERVER_LOG_PERMISSIONS(true),
|
||||
VIRTUALSERVER_LOG_QUERY(true),
|
||||
VIRTUALSERVER_LOG_SERVER(true),
|
||||
VIRTUALSERVER_MACHINE_ID(true),
|
||||
VIRTUALSERVER_MAX_DOWNLOAD_TOTAL_BANDWIDTH(true),
|
||||
VIRTUALSERVER_MAX_UPLOAD_TOTAL_BANDWIDTH(true),
|
||||
VIRTUALSERVER_MAXCLIENTS(true),
|
||||
VIRTUALSERVER_MIN_CLIENT_VERSION(true),
|
||||
VIRTUALSERVER_MIN_CLIENTS_IN_CHANNEL_BEFORE_FORCED_SILENCE(true),
|
||||
VIRTUALSERVER_MONTH_BYTES_DOWNLOADED(false),
|
||||
VIRTUALSERVER_MONTH_BYTES_UPLOADED(false),
|
||||
VIRTUALSERVER_NAME(true),
|
||||
VIRTUALSERVER_NAME_PHONETIC(true),
|
||||
VIRTUALSERVER_NEEDED_IDENTITY_SECURITY_LEVEL(true),
|
||||
VIRTUALSERVER_PASSWORD(true),
|
||||
VIRTUALSERVER_PLATFORM(false),
|
||||
VIRTUALSERVER_PORT(true),
|
||||
VIRTUALSERVER_PRIORITY_SPEAKER_DIMM_MODIFICATOR(true),
|
||||
VIRTUALSERVER_QUERY_CLIENT_CONNECTIONS(false),
|
||||
VIRTUALSERVER_QUERYCLIENTSONLINE(false),
|
||||
VIRTUALSERVER_RESERVED_SLOTS(true),
|
||||
VIRTUALSERVER_STATUS(true),
|
||||
VIRTUALSERVER_TOTAL_BYTES_DOWNLOADED(false),
|
||||
VIRTUALSERVER_TOTAL_BYTES_UPLOADED(false),
|
||||
VIRTUALSERVER_TOTAL_PACKETLOSS_CONTROL(false),
|
||||
VIRTUALSERVER_TOTAL_PACKETLOSS_KEEPALIVE(false),
|
||||
VIRTUALSERVER_TOTAL_PACKETLOSS_SPEECH(false),
|
||||
VIRTUALSERVER_TOTAL_PACKETLOSS_TOTAL(false),
|
||||
VIRTUALSERVER_TOTAL_PING(false),
|
||||
VIRTUALSERVER_UNIQUE_IDENTIFIER(false),
|
||||
VIRTUALSERVER_UPLOAD_QUOTA(true),
|
||||
VIRTUALSERVER_UPTIME(false),
|
||||
VIRTUALSERVER_VERSION(false),
|
||||
VIRTUALSERVER_WEBLIST_ENABLED(true),
|
||||
VIRTUALSERVER_WELCOMEMESSAGE(true);
|
||||
|
||||
private final boolean changeable;
|
||||
|
||||
VirtualServerProperty(boolean changeable) {
|
||||
this.changeable = changeable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChangeable() {
|
||||
return changeable;
|
||||
}
|
||||
}
|
48
src/com/github/theholywaffle/teamspeak3/api/VirtualServerStatus.java
Normale Datei
48
src/com/github/theholywaffle/teamspeak3/api/VirtualServerStatus.java
Normale Datei
@ -0,0 +1,48 @@
|
||||
package com.github.theholywaffle.teamspeak3.api;
|
||||
|
||||
/*
|
||||
* #%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%
|
||||
*/
|
||||
|
||||
public enum VirtualServerStatus {
|
||||
|
||||
ONLINE("online"),
|
||||
OFFLINE("offline"),
|
||||
DEPLOY_RUNNING("deploy running"),
|
||||
BOOTING_UP("booting up"),
|
||||
SHUTTING_DOWN("shutting down"),
|
||||
VIRTUAL_ONLINE("virtual online"),
|
||||
UNKNOWN("unknown");
|
||||
|
||||
private final String name;
|
||||
|
||||
VirtualServerStatus(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
131
src/com/github/theholywaffle/teamspeak3/api/event/BaseEvent.java
Normale Datei
131
src/com/github/theholywaffle/teamspeak3/api/event/BaseEvent.java
Normale Datei
@ -0,0 +1,131 @@
|
||||
package com.github.theholywaffle.teamspeak3.api.event;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* TeamSpeak 3 Java API
|
||||
* %%
|
||||
* Copyright (C) 2014 - 2015 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.wrapper.Wrapper;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class BaseEvent extends Wrapper implements TS3Event {
|
||||
|
||||
protected BaseEvent(Map<String, String> map) {
|
||||
super(Collections.unmodifiableMap(map));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ID of the client who caused this event to happen.
|
||||
* <p>
|
||||
* Because not all events are caused by clients, not all events have an invoker.<br>
|
||||
* Most importantly, client events (i.e. {@link ClientJoinEvent}, {@link ClientLeaveEvent}
|
||||
* {@link ClientMovedEvent}) do <b>not</b> have an invoker if a client joined,
|
||||
* quit or changed channels themselves. These values are only present if another client
|
||||
* caused the event to happen by moving, kicking or banning a client.
|
||||
* </p><p>
|
||||
* If the event response does not contain an invoker, this method will return {@code -1}.
|
||||
* </p>
|
||||
*
|
||||
* @return the client ID of the invoker or {@code -1} if the event does not contain an invoker
|
||||
*/
|
||||
public int getInvokerId() {
|
||||
return getInt("invokerid");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the nickname of the client who caused this event to happen.
|
||||
* <p>
|
||||
* Because not all events are caused by clients, not all events have an invoker.<br>
|
||||
* Most importantly, client events (i.e. {@link ClientJoinEvent}, {@link ClientLeaveEvent}
|
||||
* {@link ClientMovedEvent}) do <b>not</b> have an invoker if a client joined,
|
||||
* quit or changed channels themselves. These values are only present if another client
|
||||
* caused the event to happen by moving, kicking or banning a client.
|
||||
* </p><p>
|
||||
* If the event response does not contain an invoker, this method will return an empty string.
|
||||
* </p>
|
||||
*
|
||||
* @return the nickname of the invoker or an empty string if the event does not contain an invoker
|
||||
*/
|
||||
public String getInvokerName() {
|
||||
return get("invokername");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the unique identifier of the client who caused this event to happen.
|
||||
* <p>
|
||||
* Because not all events are caused by clients, not all events have an invoker.<br>
|
||||
* Most importantly, client events (i.e. {@link ClientJoinEvent}, {@link ClientLeaveEvent}
|
||||
* {@link ClientMovedEvent}) do <b>not</b> have an invoker if a client joined,
|
||||
* quit or changed channels themselves. These values are only present if another client
|
||||
* caused the event to happen by moving, kicking or banning a client.
|
||||
* </p><p>
|
||||
* If the event response does not contain an invoker, this method will return an empty string.
|
||||
* </p>
|
||||
*
|
||||
* @return the unique ID the invoker or an empty string if the event does not contain an invoker
|
||||
*/
|
||||
public String getInvokerUniqueId() {
|
||||
return get("invokeruid");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the reason ID of the cause of this event.
|
||||
* <p>
|
||||
* Here's an incomplete list of known reason IDs:
|
||||
* </p>
|
||||
* <table summary="Incomplete list of known reason IDs">
|
||||
* <tr><th>ID</th><th>Description</th></tr>
|
||||
* <tr><td>-1</td><td>No reason present</td></tr>
|
||||
* <tr><td>0</td><td>No external cause</td></tr>
|
||||
* <tr><td>1</td><td>Client was moved (by other client / by creating a new channel)</td></tr>
|
||||
* <tr><td>3</td><td>Client timed out</td></tr>
|
||||
* <tr><td>4</td><td>Client kicked from a channel or channel deleted</td></tr>
|
||||
* <tr><td>5</td><td>Client kicked from the server</td></tr>
|
||||
* <tr><td>6</td><td>Client banned from the server</td></tr>
|
||||
* <tr><td>8</td><td>Client left the server (no external cause)</td></tr>
|
||||
* <tr><td>10</td><td>Virtual server or channel edited</td></tr>
|
||||
* <tr><td>11</td><td>Server shut down</td></tr>
|
||||
* </table>
|
||||
*
|
||||
* @return the reason ID for this event
|
||||
*/
|
||||
public int getReasonId() {
|
||||
return getInt("reasonid");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the reason for this event.
|
||||
* This field is rarely present, even if the reason ID is non-zero.
|
||||
* <p>
|
||||
* In case of a client getting kicked or banned, this will return the user-provided reason.
|
||||
* </p>
|
||||
*
|
||||
* @return the reason for this event or an empty string if no reason message is present
|
||||
*/
|
||||
public String getReasonMessage() {
|
||||
return get("reasonmsg");
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package com.github.theholywaffle.teamspeak3.api.event;
|
||||
|
||||
/*
|
||||
* #%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.ChannelProperty;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ChannelCreateEvent extends BaseEvent {
|
||||
|
||||
public ChannelCreateEvent(Map<String, String> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
public int getChannelId() {
|
||||
return getInt(ChannelProperty.CID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fire(TS3Listener listener) {
|
||||
listener.onChannelCreate(this);
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package com.github.theholywaffle.teamspeak3.api.event;
|
||||
|
||||
/*
|
||||
* #%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.ChannelProperty;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ChannelDeletedEvent extends BaseEvent {
|
||||
|
||||
public ChannelDeletedEvent(Map<String, String> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
public int getChannelId() {
|
||||
return getInt(ChannelProperty.CID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fire(TS3Listener listener) {
|
||||
listener.onChannelDeleted(this);
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package com.github.theholywaffle.teamspeak3.api.event;
|
||||
|
||||
/*
|
||||
* #%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.ChannelProperty;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ChannelDescriptionEditedEvent extends BaseEvent {
|
||||
|
||||
public ChannelDescriptionEditedEvent(Map<String, String> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
public int getChannelId() {
|
||||
return getInt(ChannelProperty.CID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fire(TS3Listener listener) {
|
||||
listener.onChannelDescriptionChanged(this);
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package com.github.theholywaffle.teamspeak3.api.event;
|
||||
|
||||
/*
|
||||
* #%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.ChannelProperty;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ChannelEditedEvent extends BaseEvent {
|
||||
|
||||
public ChannelEditedEvent(Map<String, String> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
public int getChannelId() {
|
||||
return getInt(ChannelProperty.CID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fire(TS3Listener listener) {
|
||||
listener.onChannelEdit(this);
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package com.github.theholywaffle.teamspeak3.api.event;
|
||||
|
||||
/*
|
||||
* #%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.ChannelProperty;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ChannelMovedEvent extends BaseEvent {
|
||||
|
||||
public ChannelMovedEvent(Map<String, String> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
public int getChannelId() {
|
||||
return getInt(ChannelProperty.CID);
|
||||
}
|
||||
|
||||
public int getChannelParentId() {
|
||||
return getInt(ChannelProperty.CPID);
|
||||
}
|
||||
|
||||
public int getChannelOrder() {
|
||||
return getInt(ChannelProperty.CHANNEL_ORDER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fire(TS3Listener listener) {
|
||||
listener.onChannelMoved(this);
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package com.github.theholywaffle.teamspeak3.api.event;
|
||||
|
||||
/*
|
||||
* #%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.ChannelProperty;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ChannelPasswordChangedEvent extends BaseEvent {
|
||||
|
||||
public ChannelPasswordChangedEvent(Map<String, String> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
public int getChannelId() {
|
||||
return getInt(ChannelProperty.CID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fire(TS3Listener listener) {
|
||||
listener.onChannelPasswordChanged(this);
|
||||
}
|
||||
}
|
179
src/com/github/theholywaffle/teamspeak3/api/event/ClientJoinEvent.java
Normale Datei
179
src/com/github/theholywaffle/teamspeak3/api/event/ClientJoinEvent.java
Normale Datei
@ -0,0 +1,179 @@
|
||||
package com.github.theholywaffle.teamspeak3.api.event;
|
||||
|
||||
/*
|
||||
* #%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.util.Map;
|
||||
|
||||
public class ClientJoinEvent extends BaseEvent {
|
||||
|
||||
public ClientJoinEvent(Map<String, String> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
public int getClientFromId() {
|
||||
return getInt("cfid");
|
||||
}
|
||||
|
||||
public int getClientTargetId() {
|
||||
return getInt("ctid");
|
||||
}
|
||||
|
||||
public int getClientId() {
|
||||
return getInt("clid");
|
||||
}
|
||||
|
||||
public String getUniqueClientIdentifier() {
|
||||
return get(ClientProperty.CLIENT_UNIQUE_IDENTIFIER);
|
||||
}
|
||||
|
||||
public String getClientNickname() {
|
||||
return get(ClientProperty.CLIENT_NICKNAME);
|
||||
}
|
||||
|
||||
public boolean isClientInputMuted() {
|
||||
return getBoolean(ClientProperty.CLIENT_INPUT_MUTED);
|
||||
}
|
||||
|
||||
public boolean isClientOutputMuted() {
|
||||
return getBoolean(ClientProperty.CLIENT_OUTPUT_MUTED);
|
||||
}
|
||||
|
||||
public boolean isClientOutputOnlyMuted() {
|
||||
return getBoolean(ClientProperty.CLIENT_OUTPUTONLY_MUTED);
|
||||
}
|
||||
|
||||
public boolean isClientUsingHardwareInput() {
|
||||
return getBoolean(ClientProperty.CLIENT_INPUT_HARDWARE);
|
||||
}
|
||||
|
||||
public boolean isClientUsingHardwareOutput() {
|
||||
return getBoolean(ClientProperty.CLIENT_OUTPUT_HARDWARE);
|
||||
}
|
||||
|
||||
public String getClientMetadata() {
|
||||
return get(ClientProperty.CLIENT_META_DATA);
|
||||
}
|
||||
|
||||
public boolean isClientRecording() {
|
||||
return getBoolean(ClientProperty.CLIENT_IS_RECORDING);
|
||||
}
|
||||
|
||||
public int getClientDatabaseId() {
|
||||
return getInt(ClientProperty.CLIENT_DATABASE_ID);
|
||||
}
|
||||
|
||||
public int getClientChannelGroupId() {
|
||||
return getInt(ClientProperty.CLIENT_CHANNEL_GROUP_ID);
|
||||
}
|
||||
|
||||
public int getAmountOfServerGroups() {
|
||||
//getInt was turning the String 1,2,3,.. to a int which wasn't right.
|
||||
//Now it gets the Amount even if the ID is <=10
|
||||
String[] split = get(ClientProperty.CLIENT_SERVERGROUPS).split(",");
|
||||
return split.length;
|
||||
}
|
||||
|
||||
public String getClientServerGroups() {
|
||||
//getClientServerGroups returns a string containing the server group ID for example 1,2,3,...
|
||||
return get(ClientProperty.CLIENT_SERVERGROUPS);
|
||||
}
|
||||
|
||||
public boolean isClientAway() {
|
||||
return getBoolean(ClientProperty.CLIENT_AWAY);
|
||||
}
|
||||
|
||||
public String getClientAwayMessage() {
|
||||
return get(ClientProperty.CLIENT_AWAY_MESSAGE);
|
||||
}
|
||||
|
||||
public int getClientType() {
|
||||
return getInt(ClientProperty.CLIENT_TYPE);
|
||||
}
|
||||
|
||||
public String getClientFlagAvatarId() {
|
||||
return get(ClientProperty.CLIENT_FLAG_AVATAR);
|
||||
}
|
||||
|
||||
public int getClientTalkPower() {
|
||||
return getInt(ClientProperty.CLIENT_TALK_POWER);
|
||||
}
|
||||
|
||||
public boolean isClientRequestingToTalk() {
|
||||
return getBoolean(ClientProperty.CLIENT_TALK_REQUEST);
|
||||
}
|
||||
|
||||
public String getClientTalkRequestMessage() {
|
||||
return get(ClientProperty.CLIENT_TALK_REQUEST_MSG);
|
||||
}
|
||||
|
||||
public String getClientDescription() {
|
||||
return get(ClientProperty.CLIENT_DESCRIPTION);
|
||||
}
|
||||
|
||||
public boolean isClientTalking() {
|
||||
return getBoolean(ClientProperty.CLIENT_IS_TALKER);
|
||||
}
|
||||
|
||||
public boolean isClientPrioritySpeaker() {
|
||||
return getBoolean(ClientProperty.CLIENT_IS_PRIORITY_SPEAKER);
|
||||
}
|
||||
|
||||
public int getClientUnreadMessages() {
|
||||
return getInt(ClientProperty.CLIENT_UNREAD_MESSAGES);
|
||||
}
|
||||
|
||||
public String getClientPhoneticNickname() {
|
||||
return get(ClientProperty.CLIENT_NICKNAME_PHONETIC);
|
||||
}
|
||||
|
||||
public int getClientNeededServerQueryViewPower() {
|
||||
return getInt(ClientProperty.CLIENT_NEEDED_SERVERQUERY_VIEW_POWER);
|
||||
}
|
||||
|
||||
public long getClientIconId() {
|
||||
return getLong(ClientProperty.CLIENT_ICON_ID);
|
||||
}
|
||||
|
||||
public boolean isClientChannelCommander() {
|
||||
return getBoolean(ClientProperty.CLIENT_IS_CHANNEL_COMMANDER);
|
||||
}
|
||||
|
||||
public String getClientCountry() {
|
||||
return get(ClientProperty.CLIENT_COUNTRY);
|
||||
}
|
||||
|
||||
public int getClientInheritedChannelGroupId() {
|
||||
return getInt(ClientProperty.CLIENT_CHANNEL_GROUP_INHERITED_CHANNEL_ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fire(TS3Listener listener) {
|
||||
listener.onClientJoin(this);
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package com.github.theholywaffle.teamspeak3.api.event;
|
||||
|
||||
/*
|
||||
* #%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.Map;
|
||||
|
||||
public class ClientLeaveEvent extends BaseEvent {
|
||||
|
||||
public ClientLeaveEvent(Map<String, String> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
public int getClientFromId() {
|
||||
return getInt("cfid");
|
||||
}
|
||||
|
||||
public int getClientTargetId() {
|
||||
return getInt("ctid");
|
||||
}
|
||||
|
||||
public int getClientId() {
|
||||
return getInt("clid");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fire(TS3Listener listener) {
|
||||
listener.onClientLeave(this);
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
package com.github.theholywaffle.teamspeak3.api.event;
|
||||
|
||||
/*
|
||||
* #%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.wrapper.Channel;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ClientMovedEvent extends BaseEvent {
|
||||
|
||||
public ClientMovedEvent(Map<String, String> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ID of the channel the client has moved to.
|
||||
*
|
||||
* @return the ID of the target channel
|
||||
*
|
||||
* @see Channel#getId()
|
||||
*/
|
||||
public int getTargetChannelId() {
|
||||
return getInt("ctid");
|
||||
}
|
||||
|
||||
public int getClientId() {
|
||||
return getInt("clid");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fire(TS3Listener listener) {
|
||||
listener.onClientMoved(this);
|
||||
}
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
package com.github.theholywaffle.teamspeak3.api.event;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* TeamSpeak 3 Java API
|
||||
* %%
|
||||
* Copyright (C) 2016 Bert De Geyter, Roger Baumgartner
|
||||
* %%
|
||||
* 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.PrivilegeKeyType;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class PrivilegeKeyUsedEvent extends BaseEvent {
|
||||
|
||||
public PrivilegeKeyUsedEvent(Map<String, String> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
public int getClientId() {
|
||||
return getInt("clid");
|
||||
}
|
||||
|
||||
public int getClientDatabaseId() {
|
||||
return getInt("cldbid");
|
||||
}
|
||||
|
||||
public String getClientUniqueIdentifier() {
|
||||
return get("cluid");
|
||||
}
|
||||
|
||||
public String getPrivilegeKey() {
|
||||
return get("token");
|
||||
}
|
||||
|
||||
public PrivilegeKeyType getPrivilegeKeyType() {
|
||||
if (getPrivilegeKeyChannelId() == 0) {
|
||||
return PrivilegeKeyType.SERVER_GROUP;
|
||||
} else {
|
||||
return PrivilegeKeyType.CHANNEL_GROUP;
|
||||
}
|
||||
}
|
||||
|
||||
public int getPrivilegeKeyGroupId() {
|
||||
return getInt("token1");
|
||||
}
|
||||
|
||||
public int getPrivilegeKeyChannelId() {
|
||||
return getInt("token2");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fire(TS3Listener listener) {
|
||||
listener.onPrivilegeKeyUsed(this);
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package com.github.theholywaffle.teamspeak3.api.event;
|
||||
|
||||
/*
|
||||
* #%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.Map;
|
||||
|
||||
public class ServerEditedEvent extends BaseEvent {
|
||||
|
||||
public ServerEditedEvent(Map<String, String> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fire(TS3Listener listener) {
|
||||
listener.onServerEdit(this);
|
||||
}
|
||||
}
|
32
src/com/github/theholywaffle/teamspeak3/api/event/TS3Event.java
Normale Datei
32
src/com/github/theholywaffle/teamspeak3/api/event/TS3Event.java
Normale Datei
@ -0,0 +1,32 @@
|
||||
package com.github.theholywaffle.teamspeak3.api.event;
|
||||
|
||||
/*
|
||||
* #%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%
|
||||
*/
|
||||
|
||||
public interface TS3Event {
|
||||
|
||||
void fire(TS3Listener listener);
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
package com.github.theholywaffle.teamspeak3.api.event;
|
||||
|
||||
/*
|
||||
* #%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%
|
||||
*/
|
||||
|
||||
/**
|
||||
* A template class implementing {@link TS3Listener} similar to Swing's event adapters.
|
||||
* <p>
|
||||
* All method in this class do nothing, so the user only has to override the interface
|
||||
* methods for the events they want to take action on.
|
||||
* </p>
|
||||
*/
|
||||
public abstract class TS3EventAdapter implements TS3Listener {
|
||||
|
||||
@Override
|
||||
public void onTextMessage(TextMessageEvent e) {}
|
||||
|
||||
@Override
|
||||
public void onClientJoin(ClientJoinEvent e) {}
|
||||
|
||||
@Override
|
||||
public void onClientLeave(ClientLeaveEvent e) {}
|
||||
|
||||
@Override
|
||||
public void onServerEdit(ServerEditedEvent e) {}
|
||||
|
||||
@Override
|
||||
public void onChannelEdit(ChannelEditedEvent e) {}
|
||||
|
||||
@Override
|
||||
public void onChannelDescriptionChanged(ChannelDescriptionEditedEvent e) {}
|
||||
|
||||
@Override
|
||||
public void onClientMoved(ClientMovedEvent e) {}
|
||||
|
||||
@Override
|
||||
public void onChannelCreate(ChannelCreateEvent e) {}
|
||||
|
||||
@Override
|
||||
public void onChannelDeleted(ChannelDeletedEvent e) {}
|
||||
|
||||
@Override
|
||||
public void onChannelMoved(ChannelMovedEvent e) {}
|
||||
|
||||
@Override
|
||||
public void onChannelPasswordChanged(ChannelPasswordChangedEvent e) {}
|
||||
|
||||
@Override
|
||||
public void onPrivilegeKeyUsed(PrivilegeKeyUsedEvent e) {}
|
||||
}
|
49
src/com/github/theholywaffle/teamspeak3/api/event/TS3EventType.java
Normale Datei
49
src/com/github/theholywaffle/teamspeak3/api/event/TS3EventType.java
Normale Datei
@ -0,0 +1,49 @@
|
||||
package com.github.theholywaffle.teamspeak3.api.event;
|
||||
|
||||
/*
|
||||
* #%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%
|
||||
*/
|
||||
|
||||
public enum TS3EventType {
|
||||
|
||||
SERVER("server"),
|
||||
CHANNEL("channel"),
|
||||
TEXT_SERVER("textserver"),
|
||||
TEXT_CHANNEL("textchannel"),
|
||||
TEXT_PRIVATE("textprivate"),
|
||||
PRIVILEGE_KEY_USED("tokenused");
|
||||
|
||||
private final String name;
|
||||
|
||||
TS3EventType(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
54
src/com/github/theholywaffle/teamspeak3/api/event/TS3Listener.java
Normale Datei
54
src/com/github/theholywaffle/teamspeak3/api/event/TS3Listener.java
Normale Datei
@ -0,0 +1,54 @@
|
||||
package com.github.theholywaffle.teamspeak3.api.event;
|
||||
|
||||
/*
|
||||
* #%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%
|
||||
*/
|
||||
|
||||
public interface TS3Listener {
|
||||
|
||||
void onTextMessage(TextMessageEvent e);
|
||||
|
||||
void onClientJoin(ClientJoinEvent e);
|
||||
|
||||
void onClientLeave(ClientLeaveEvent e);
|
||||
|
||||
void onServerEdit(ServerEditedEvent e);
|
||||
|
||||
void onChannelEdit(ChannelEditedEvent e);
|
||||
|
||||
void onChannelDescriptionChanged(ChannelDescriptionEditedEvent e);
|
||||
|
||||
void onClientMoved(ClientMovedEvent e);
|
||||
|
||||
void onChannelCreate(ChannelCreateEvent e);
|
||||
|
||||
void onChannelDeleted(ChannelDeletedEvent e);
|
||||
|
||||
void onChannelMoved(ChannelMovedEvent e);
|
||||
|
||||
void onChannelPasswordChanged(ChannelPasswordChangedEvent e);
|
||||
|
||||
void onPrivilegeKeyUsed(PrivilegeKeyUsedEvent e);
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
package com.github.theholywaffle.teamspeak3.api.event;
|
||||
|
||||
/*
|
||||
* #%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.TextMessageTargetMode;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class TextMessageEvent extends BaseEvent {
|
||||
|
||||
public TextMessageEvent(Map<String, String> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
public TextMessageTargetMode getTargetMode() {
|
||||
int mode = getInt("targetmode");
|
||||
for (TextMessageTargetMode m : TextMessageTargetMode.values()) {
|
||||
if (m.getIndex() == mode) {
|
||||
return m;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return get("msg");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the client ID of the recipient of a private message.
|
||||
* <ul>
|
||||
* <li>If the private message was sent <b>to</b> the query, the target ID will be the query's client ID</li>
|
||||
* <li>If the private message was sent <b>by</b> the query, the target ID will be the recipient's client ID</li>
|
||||
* <li>If this is not an event for a private message, this method will return {@code -1}</li>
|
||||
* </ul>
|
||||
*
|
||||
* @return the client ID of the recipient
|
||||
*/
|
||||
public int getTargetClientId() {
|
||||
return getInt("target");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fire(TS3Listener listener) {
|
||||
listener.onTextMessage(this);
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
package com.github.theholywaffle.teamspeak3.api.exception;
|
||||
|
||||
/*
|
||||
* #%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.wrapper.QueryError;
|
||||
|
||||
public class TS3CommandFailedException extends TS3Exception {
|
||||
|
||||
private static final long serialVersionUID = 8179203326662268882L;
|
||||
|
||||
private final QueryError queryError;
|
||||
|
||||
public TS3CommandFailedException(QueryError error, String commandName) {
|
||||
super(buildMessage(error, commandName));
|
||||
queryError = error;
|
||||
}
|
||||
|
||||
private static String buildMessage(QueryError error, String cmdName) {
|
||||
final StringBuilder msg = new StringBuilder();
|
||||
msg.append("A \"").append(cmdName).append("\" command returned with a server error.\n");
|
||||
msg.append(">> ").append(error.getMessage()).append(" (ID ").append(error.getId()).append(')');
|
||||
|
||||
final String extra = error.getExtraMessage();
|
||||
if (extra != null && !extra.isEmpty()) {
|
||||
msg.append(": ").append(extra);
|
||||
}
|
||||
|
||||
final int failedPermissionId = error.getFailedPermissionId();
|
||||
if (failedPermissionId > 0) {
|
||||
msg.append(", failed permission with ID ").append(failedPermissionId);
|
||||
}
|
||||
|
||||
return msg.toString();
|
||||
}
|
||||
|
||||
public QueryError getError() {
|
||||
return queryError;
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package com.github.theholywaffle.teamspeak3.api.exception;
|
||||
|
||||
/*
|
||||
* #%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%
|
||||
*/
|
||||
|
||||
public class TS3ConnectionFailedException extends TS3Exception {
|
||||
|
||||
private static final long serialVersionUID = 6849777544299282019L;
|
||||
|
||||
public TS3ConnectionFailedException(Throwable c) {
|
||||
super("Could not connect to the TeamSpeak3 server", c);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package com.github.theholywaffle.teamspeak3.api.exception;
|
||||
|
||||
/*
|
||||
* #%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%
|
||||
*/
|
||||
|
||||
public class TS3Exception extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 7167169981592989359L;
|
||||
|
||||
public TS3Exception(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public TS3Exception(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package com.github.theholywaffle.teamspeak3.api.exception;
|
||||
|
||||
/*
|
||||
* #%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.io.IOException;
|
||||
|
||||
public class TS3FileTransferFailedException extends TS3Exception {
|
||||
|
||||
private static final long serialVersionUID = 2819130214534186875L;
|
||||
|
||||
public TS3FileTransferFailedException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
public TS3FileTransferFailedException(String msg, IOException cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package com.github.theholywaffle.teamspeak3.api.exception;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* TeamSpeak 3 Java API
|
||||
* %%
|
||||
* Copyright (C) 2018 Bert De Geyter, Roger Baumgartner
|
||||
* %%
|
||||
* 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%
|
||||
*/
|
||||
|
||||
public class TS3QueryShutDownException extends TS3Exception {
|
||||
|
||||
private static final long serialVersionUID = -6727279731231409306L;
|
||||
|
||||
public TS3QueryShutDownException() {
|
||||
super("The query was shut down or disconnected.");
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package com.github.theholywaffle.teamspeak3.api.exception;
|
||||
|
||||
/*
|
||||
* #%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%
|
||||
*/
|
||||
|
||||
public class TS3UnknownErrorException extends TS3Exception {
|
||||
|
||||
private static final long serialVersionUID = -8458508268312921713L;
|
||||
|
||||
public TS3UnknownErrorException(String error) {
|
||||
super(error + " [Please report this exception to the developer!]");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package com.github.theholywaffle.teamspeak3.api.exception;
|
||||
|
||||
/*
|
||||
* #%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%
|
||||
*/
|
||||
|
||||
public class TS3UnknownEventException extends TS3Exception {
|
||||
|
||||
private static final long serialVersionUID = -9179157153557357715L;
|
||||
|
||||
public TS3UnknownEventException(String event) {
|
||||
super(event + " [Please report this exception to the developer!]");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package com.github.theholywaffle.teamspeak3.api.reconnect;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* TeamSpeak 3 Java API
|
||||
* %%
|
||||
* Copyright (C) 2015 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.TS3Query;
|
||||
|
||||
public interface ConnectionHandler {
|
||||
|
||||
void onConnect(TS3Query ts3Query);
|
||||
|
||||
void onDisconnect(TS3Query ts3Query);
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
package com.github.theholywaffle.teamspeak3.api.reconnect;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* TeamSpeak 3 Java API
|
||||
* %%
|
||||
* Copyright (C) 2015 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.TS3Query;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class DisconnectingConnectionHandler implements ConnectionHandler {
|
||||
|
||||
private static final Logger log = ProxyServer.getInstance().getLogger();
|
||||
private final ConnectionHandler userConnectionHandler;
|
||||
|
||||
public DisconnectingConnectionHandler(ConnectionHandler userConnectionHandler) {
|
||||
this.userConnectionHandler = userConnectionHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnect(TS3Query ts3Query) {
|
||||
if (userConnectionHandler != null) {
|
||||
userConnectionHandler.onConnect(ts3Query);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisconnect(TS3Query ts3Query) {
|
||||
log.log(Level.SEVERE, "[Connection] Disconnected from TS3 server");
|
||||
|
||||
if (userConnectionHandler != null) {
|
||||
userConnectionHandler.onDisconnect(ts3Query);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,156 @@
|
||||
package com.github.theholywaffle.teamspeak3.api.reconnect;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* TeamSpeak 3 Java API
|
||||
* %%
|
||||
* Copyright (C) 2014 - 2016 Bert De Geyter, Roger Baumgartner
|
||||
* %%
|
||||
* 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%
|
||||
*/
|
||||
|
||||
public abstract class ReconnectStrategy {
|
||||
|
||||
private static final int CONSTANT_BACKOFF = 10000;
|
||||
private static final int START_TIMEOUT = 1000;
|
||||
private static final int TIMEOUT_CAP = 60000;
|
||||
private static final int ADDEND = 2000;
|
||||
private static final double MULTIPLIER = 1.5;
|
||||
|
||||
private ReconnectStrategy() {}
|
||||
|
||||
public abstract ConnectionHandler create(ConnectionHandler userConnectionHandler);
|
||||
|
||||
public static ReconnectStrategy userControlled() {
|
||||
return new UserControlled();
|
||||
}
|
||||
|
||||
public static ReconnectStrategy disconnect() {
|
||||
return new Disconnect();
|
||||
}
|
||||
|
||||
public static ReconnectStrategy constantBackoff() {
|
||||
return constantBackoff(CONSTANT_BACKOFF);
|
||||
}
|
||||
|
||||
public static ReconnectStrategy constantBackoff(int timeout) {
|
||||
return new Constant(timeout);
|
||||
}
|
||||
|
||||
public static ReconnectStrategy linearBackoff() {
|
||||
return linearBackoff(START_TIMEOUT, ADDEND, TIMEOUT_CAP);
|
||||
}
|
||||
|
||||
public static ReconnectStrategy linearBackoff(int startTimeout, int addend) {
|
||||
return linearBackoff(startTimeout, addend, TIMEOUT_CAP);
|
||||
}
|
||||
|
||||
public static ReconnectStrategy linearBackoff(int startTimeout, int addend, int timeoutCap) {
|
||||
return new Linear(startTimeout, addend, timeoutCap);
|
||||
}
|
||||
|
||||
public static ReconnectStrategy exponentialBackoff() {
|
||||
return exponentialBackoff(START_TIMEOUT, MULTIPLIER, TIMEOUT_CAP);
|
||||
}
|
||||
|
||||
public static ReconnectStrategy exponentialBackoff(int startTimeout, double multiplier) {
|
||||
return exponentialBackoff(startTimeout, multiplier, TIMEOUT_CAP);
|
||||
}
|
||||
|
||||
public static ReconnectStrategy exponentialBackoff(int startTimeout, double multiplier, int timeoutCap) {
|
||||
return new Exponential(startTimeout, multiplier, timeoutCap);
|
||||
}
|
||||
|
||||
private static class UserControlled extends ReconnectStrategy {
|
||||
|
||||
@Override
|
||||
public ConnectionHandler create(ConnectionHandler userConnectionHandler) {
|
||||
String message = "userConnectionHandler cannot be null when using strategy UserControlled!";
|
||||
if (userConnectionHandler == null) throw new IllegalArgumentException(message);
|
||||
return userConnectionHandler;
|
||||
}
|
||||
}
|
||||
|
||||
private static class Disconnect extends ReconnectStrategy {
|
||||
|
||||
@Override
|
||||
public ConnectionHandler create(ConnectionHandler userConnectionHandler) {
|
||||
return new DisconnectingConnectionHandler(userConnectionHandler);
|
||||
}
|
||||
}
|
||||
|
||||
private static class Constant extends ReconnectStrategy {
|
||||
|
||||
private final int timeout;
|
||||
|
||||
public Constant(int timeout) {
|
||||
if (timeout <= 0) throw new IllegalArgumentException("Timeout must be greater than 0");
|
||||
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConnectionHandler create(ConnectionHandler userConnectionHandler) {
|
||||
return new ReconnectingConnectionHandler(userConnectionHandler, timeout, timeout, 0, 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
private static class Linear extends ReconnectStrategy {
|
||||
|
||||
private final int startTimeout;
|
||||
private final int addend;
|
||||
private final int timeoutCap;
|
||||
|
||||
private Linear(int startTimeout, int addend, int timeoutCap) {
|
||||
if (startTimeout <= 0) throw new IllegalArgumentException("Starting timeout must be greater than 0");
|
||||
if (addend <= 0) throw new IllegalArgumentException("Addend must be greater than 0");
|
||||
|
||||
this.startTimeout = startTimeout;
|
||||
this.addend = addend;
|
||||
this.timeoutCap = timeoutCap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConnectionHandler create(ConnectionHandler userConnectionHandler) {
|
||||
return new ReconnectingConnectionHandler(userConnectionHandler, startTimeout, timeoutCap, addend, 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
private static class Exponential extends ReconnectStrategy {
|
||||
|
||||
private final int startTimeout;
|
||||
private final double multiplier;
|
||||
private final int timeoutCap;
|
||||
|
||||
private Exponential(int startTimeout, double multiplier, int timeoutCap) {
|
||||
if (startTimeout <= 0) throw new IllegalArgumentException("Starting timeout must be greater than 0");
|
||||
if (multiplier <= 1.0) throw new IllegalArgumentException("Multiplier must be greater than 1");
|
||||
|
||||
this.startTimeout = startTimeout;
|
||||
this.multiplier = multiplier;
|
||||
this.timeoutCap = timeoutCap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConnectionHandler create(ConnectionHandler userConnectionHandler) {
|
||||
return new ReconnectingConnectionHandler(userConnectionHandler, startTimeout, timeoutCap, 0, multiplier);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
package com.github.theholywaffle.teamspeak3.api.reconnect;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* TeamSpeak 3 Java API
|
||||
* %%
|
||||
* Copyright (C) 2015 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.TS3Query;
|
||||
import com.github.theholywaffle.teamspeak3.api.exception.TS3ConnectionFailedException;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class ReconnectingConnectionHandler implements ConnectionHandler {
|
||||
|
||||
private static final Logger log = ProxyServer.getInstance().getLogger();
|
||||
|
||||
private final ConnectionHandler userConnectionHandler;
|
||||
private final int startTimeout;
|
||||
private final int timeoutCap;
|
||||
private final int addend;
|
||||
private final double multiplier;
|
||||
|
||||
public ReconnectingConnectionHandler(ConnectionHandler userConnectionHandler, int startTimeout,
|
||||
int timeoutCap, int addend, double multiplier) {
|
||||
this.userConnectionHandler = userConnectionHandler;
|
||||
this.startTimeout = startTimeout;
|
||||
this.timeoutCap = timeoutCap;
|
||||
this.addend = addend;
|
||||
this.multiplier = multiplier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnect(TS3Query ts3Query) {
|
||||
if (userConnectionHandler != null) {
|
||||
userConnectionHandler.onConnect(ts3Query);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisconnect(TS3Query ts3Query) {
|
||||
// Announce disconnect and run user connection handler
|
||||
log.log(Level.INFO, "[Connection] Disconnected from TS3 server - reconnecting in {}ms", startTimeout);
|
||||
if (userConnectionHandler != null) {
|
||||
userConnectionHandler.onDisconnect(ts3Query);
|
||||
}
|
||||
|
||||
int timeout = startTimeout;
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
Thread.sleep(timeout);
|
||||
} catch (InterruptedException e) {
|
||||
return;
|
||||
}
|
||||
|
||||
timeout = (int) Math.ceil(timeout * multiplier) + addend;
|
||||
if (timeoutCap > 0) timeout = Math.min(timeout, timeoutCap);
|
||||
|
||||
try {
|
||||
ts3Query.connect();
|
||||
return; // Successfully reconnected, return
|
||||
} catch (TS3ConnectionFailedException conFailed) {
|
||||
// Ignore exception, announce reconnect failure
|
||||
log.log(Level.FINE, "[Connection] Failed to reconnect - waiting {}ms until next attempt", timeout);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
85
src/com/github/theholywaffle/teamspeak3/api/wrapper/Ban.java
Normale Datei
85
src/com/github/theholywaffle/teamspeak3/api/wrapper/Ban.java
Normale Datei
@ -0,0 +1,85 @@
|
||||
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 java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
public class Ban extends Wrapper {
|
||||
|
||||
public Ban(Map<String, String> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return getInt("banid");
|
||||
}
|
||||
|
||||
public String getBannedIp() {
|
||||
return get("ip");
|
||||
}
|
||||
|
||||
public String getBannedName() {
|
||||
return get("name");
|
||||
}
|
||||
|
||||
public String getBannedUId() {
|
||||
return get("uid");
|
||||
}
|
||||
|
||||
public String getLastNickname() {
|
||||
return get("lastnickname");
|
||||
}
|
||||
|
||||
public Date getCreatedDate() {
|
||||
return new Date(getLong("created") * 1000);
|
||||
}
|
||||
|
||||
public long getDuration() {
|
||||
return getLong("duration");
|
||||
}
|
||||
|
||||
public String getInvokerName() {
|
||||
return get("invokername");
|
||||
}
|
||||
|
||||
public int getInvokerClientDBId() {
|
||||
return getInt("invokercldbid");
|
||||
}
|
||||
|
||||
public String getInvokerUId() {
|
||||
return get("invokeruid");
|
||||
}
|
||||
|
||||
public String getReason() {
|
||||
return get("reason");
|
||||
}
|
||||
|
||||
public int getEnforcements() {
|
||||
return getInt("enforcements");
|
||||
}
|
||||
}
|
41
src/com/github/theholywaffle/teamspeak3/api/wrapper/Binding.java
Normale Datei
41
src/com/github/theholywaffle/teamspeak3/api/wrapper/Binding.java
Normale Datei
@ -0,0 +1,41 @@
|
||||
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 java.util.Map;
|
||||
|
||||
public class Binding extends Wrapper {
|
||||
|
||||
public Binding(Map<String, String> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
public String getIp() {
|
||||
return get("ip");
|
||||
}
|
||||
|
||||
}
|
67
src/com/github/theholywaffle/teamspeak3/api/wrapper/Channel.java
Normale Datei
67
src/com/github/theholywaffle/teamspeak3/api/wrapper/Channel.java
Normale Datei
@ -0,0 +1,67 @@
|
||||
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 java.util.Map;
|
||||
|
||||
import com.github.theholywaffle.teamspeak3.api.ChannelProperty;
|
||||
|
||||
public class Channel extends ChannelBase {
|
||||
|
||||
public Channel(Map<String, String> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return getInt(ChannelProperty.CID);
|
||||
}
|
||||
|
||||
public int getTotalClientsFamily() {
|
||||
return getInt("total_clients_family");
|
||||
}
|
||||
|
||||
public int getTotalClients() {
|
||||
return getInt("total_clients");
|
||||
}
|
||||
|
||||
public int getNeededSubscribePower() {
|
||||
return getInt(ChannelProperty.CHANNEL_NEEDED_SUBSCRIBE_POWER);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@code true}, if the channel is empty, {@code false} otherwise.
|
||||
*/
|
||||
public boolean isEmpty() {
|
||||
return (getTotalClients() == 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFamilyEmpty() {
|
||||
return (getTotalClientsFamily() == 0);
|
||||
}
|
||||
}
|
112
src/com/github/theholywaffle/teamspeak3/api/wrapper/ChannelBase.java
Normale Datei
112
src/com/github/theholywaffle/teamspeak3/api/wrapper/ChannelBase.java
Normale Datei
@ -0,0 +1,112 @@
|
||||
package com.github.theholywaffle.teamspeak3.api.wrapper;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* TeamSpeak 3 Java API
|
||||
* %%
|
||||
* Copyright (C) 2014 - 2015 Bert De Geyter, Roger Baumgartner
|
||||
* %%
|
||||
* 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.ChannelProperty;
|
||||
import com.github.theholywaffle.teamspeak3.api.Codec;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class ChannelBase extends Wrapper {
|
||||
|
||||
protected ChannelBase(Map<String, String> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
public abstract int getId();
|
||||
|
||||
public int getParentChannelId() {
|
||||
return getInt(ChannelProperty.PID);
|
||||
}
|
||||
|
||||
public int getOrder() {
|
||||
return getInt(ChannelProperty.CHANNEL_ORDER);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return get(ChannelProperty.CHANNEL_NAME);
|
||||
}
|
||||
|
||||
public String getTopic() {
|
||||
return get(ChannelProperty.CHANNEL_TOPIC);
|
||||
}
|
||||
|
||||
public boolean isDefault() {
|
||||
return getBoolean(ChannelProperty.CHANNEL_FLAG_DEFAULT);
|
||||
}
|
||||
|
||||
public boolean hasPassword() {
|
||||
return getBoolean(ChannelProperty.CHANNEL_FLAG_PASSWORD);
|
||||
}
|
||||
|
||||
public boolean isPermanent() {
|
||||
return getBoolean(ChannelProperty.CHANNEL_FLAG_PERMANENT);
|
||||
}
|
||||
|
||||
public boolean isSemiPermanent() {
|
||||
return getBoolean(ChannelProperty.CHANNEL_FLAG_SEMI_PERMANENT);
|
||||
}
|
||||
|
||||
public Codec getCodec() {
|
||||
final int codec = getInt(ChannelProperty.CHANNEL_CODEC);
|
||||
for (final Codec c : Codec.values()) {
|
||||
if (c.getIndex() == codec) {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
return Codec.UNKNOWN;
|
||||
}
|
||||
|
||||
public int getCodecQuality() {
|
||||
return getInt(ChannelProperty.CHANNEL_CODEC_QUALITY);
|
||||
}
|
||||
|
||||
public int getNeededTalkPower() {
|
||||
return getInt(ChannelProperty.CHANNEL_NEEDED_TALK_POWER);
|
||||
}
|
||||
|
||||
public long getIconId() {
|
||||
return getLong(ChannelProperty.CHANNEL_ICON_ID);
|
||||
}
|
||||
|
||||
public int getMaxClients() {
|
||||
return getInt(ChannelProperty.CHANNEL_MAXCLIENTS);
|
||||
}
|
||||
|
||||
public int getMaxFamilyClients() {
|
||||
return getInt(ChannelProperty.CHANNEL_MAXFAMILYCLIENTS);
|
||||
}
|
||||
|
||||
public int getSecondsEmpty() {
|
||||
return getInt(ChannelProperty.SECONDS_EMPTY);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@code true}, if the channel and all child channels are empty, {@code false} otherwise.
|
||||
*/
|
||||
abstract public boolean isFamilyEmpty();
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
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.PermissionGroupDatabaseType;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ChannelGroup extends Wrapper {
|
||||
|
||||
public ChannelGroup(Map<String, String> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return getInt("cgid");
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return get("name");
|
||||
}
|
||||
|
||||
public PermissionGroupDatabaseType getType() {
|
||||
final int type = getInt("type");
|
||||
for (final PermissionGroupDatabaseType t : PermissionGroupDatabaseType.values()) {
|
||||
if (t.getIndex() == type) {
|
||||
return t;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public long getIconId() {
|
||||
return getLong("iconid");
|
||||
}
|
||||
|
||||
public boolean isSavedInDatabase() {
|
||||
return getBoolean("savedb");
|
||||
}
|
||||
|
||||
public int getSortId() {
|
||||
return getInt("sortid");
|
||||
}
|
||||
|
||||
public int getNameMode() {
|
||||
return getInt("namemode");
|
||||
}
|
||||
|
||||
public int getModifyPower() {
|
||||
return getInt("n_modifyp");
|
||||
}
|
||||
|
||||
public int getMemberAddPower() {
|
||||
return getInt("n_member_addp");
|
||||
}
|
||||
|
||||
public int getMemberRemovePower() {
|
||||
return getInt("n_member_removep");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
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 java.util.Map;
|
||||
|
||||
public class ChannelGroupClient extends Wrapper {
|
||||
|
||||
public ChannelGroupClient(Map<String, String> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
public int getChannelId() {
|
||||
return getInt("cid");
|
||||
}
|
||||
|
||||
public int getClientDatabaseId() {
|
||||
return getInt("cldbid");
|
||||
}
|
||||
|
||||
public int getChannelGroupId() {
|
||||
return getInt("cgid");
|
||||
}
|
||||
|
||||
}
|
91
src/com/github/theholywaffle/teamspeak3/api/wrapper/ChannelInfo.java
Normale Datei
91
src/com/github/theholywaffle/teamspeak3/api/wrapper/ChannelInfo.java
Normale Datei
@ -0,0 +1,91 @@
|
||||
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 java.util.Map;
|
||||
|
||||
import com.github.theholywaffle.teamspeak3.api.ChannelProperty;
|
||||
|
||||
public class ChannelInfo extends ChannelBase {
|
||||
|
||||
private final int channelId;
|
||||
|
||||
public ChannelInfo(int channelId, Map<String, String> map) {
|
||||
super(map);
|
||||
this.channelId = channelId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return channelId;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return get(ChannelProperty.CHANNEL_DESCRIPTION);
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return get(ChannelProperty.CHANNEL_PASSWORD);
|
||||
}
|
||||
|
||||
public int getCodecLatencyFactor() {
|
||||
return getInt(ChannelProperty.CHANNEL_CODEC_LATENCY_FACTOR);
|
||||
}
|
||||
|
||||
public boolean isEncrypted() {
|
||||
return !getBoolean(ChannelProperty.CHANNEL_CODEC_IS_UNENCRYPTED);
|
||||
}
|
||||
|
||||
public boolean hasUnlimitedClients() {
|
||||
return getBoolean(ChannelProperty.CHANNEL_FLAG_MAXCLIENTS_UNLIMITED);
|
||||
}
|
||||
|
||||
public boolean hasUnlimitedFamilyClients() {
|
||||
return getBoolean(ChannelProperty.CHANNEL_FLAG_MAXFAMILYCLIENTS_UNLIMITED);
|
||||
}
|
||||
|
||||
public boolean hasInheritedMaxFamilyClients() {
|
||||
return getBoolean(ChannelProperty.CHANNEL_FLAG_MAXFAMILYCLIENTS_INHERITED);
|
||||
}
|
||||
|
||||
public String getFilePath() {
|
||||
return get(ChannelProperty.CHANNEL_FILEPATH);
|
||||
}
|
||||
|
||||
public boolean isForcedSilence() {
|
||||
return getBoolean(ChannelProperty.CHANNEL_FORCED_SILENCE);
|
||||
}
|
||||
|
||||
public String getPhoneticName() {
|
||||
return get(ChannelProperty.CHANNEL_NAME_PHONETIC);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFamilyEmpty() {
|
||||
return (getSecondsEmpty() >= 0);
|
||||
}
|
||||
}
|
245
src/com/github/theholywaffle/teamspeak3/api/wrapper/Client.java
Normale Datei
245
src/com/github/theholywaffle/teamspeak3/api/wrapper/Client.java
Normale Datei
@ -0,0 +1,245 @@
|
||||
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 long getIconId() {
|
||||
return getLong(ClientProperty.CLIENT_ICON_ID);
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return getInt("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);
|
||||
}
|
||||
}
|
170
src/com/github/theholywaffle/teamspeak3/api/wrapper/ClientInfo.java
Normale Datei
170
src/com/github/theholywaffle/teamspeak3/api/wrapper/ClientInfo.java
Normale Datei
@ -0,0 +1,170 @@
|
||||
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.util.Map;
|
||||
|
||||
public class ClientInfo extends Client {
|
||||
|
||||
private final int clientId;
|
||||
|
||||
public ClientInfo(int clientId, Map<String, String> map) {
|
||||
super(map);
|
||||
this.clientId = clientId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return clientId;
|
||||
}
|
||||
|
||||
public String getAvatar() {
|
||||
return get(ClientProperty.CLIENT_FLAG_AVATAR);
|
||||
}
|
||||
|
||||
public long getBandwidthReceivedLastMinute() {
|
||||
return getLong(ClientProperty.CONNECTION_BANDWIDTH_RECEIVED_LAST_MINUTE_TOTAL);
|
||||
}
|
||||
|
||||
public long getBandwidthReceivedLastSecond() {
|
||||
return getLong(ClientProperty.CONNECTION_BANDWIDTH_RECEIVED_LAST_SECOND_TOTAL);
|
||||
}
|
||||
|
||||
public long getBandwidthSentlastMinute() {
|
||||
return getLong(ClientProperty.CONNECTION_BANDWIDTH_SENT_LAST_MINUTE_TOTAL);
|
||||
}
|
||||
|
||||
public long getBandwidthSentLastSecond() {
|
||||
return getLong(ClientProperty.CONNECTION_BANDWIDTH_SENT_LAST_SECOND_TOTAL);
|
||||
}
|
||||
|
||||
public String getBase64ClientUId() {
|
||||
return get("client_base64HashClientUID");
|
||||
}
|
||||
|
||||
public int getDefaultChannel() {
|
||||
// TeamSpeak decided to prefix the channel ID with a forward slash (/)...
|
||||
final String channelId = get(ClientProperty.CLIENT_DEFAULT_CHANNEL);
|
||||
if (channelId.isEmpty()) return -1;
|
||||
return Integer.parseInt(channelId.substring(1));
|
||||
}
|
||||
|
||||
public String getDefaultToken() {
|
||||
return get(ClientProperty.CLIENT_DEFAULT_TOKEN);
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return get(ClientProperty.CLIENT_DESCRIPTION);
|
||||
}
|
||||
|
||||
public long getFiletransferBandwidthReceived() {
|
||||
return getLong(ClientProperty.CONNECTION_FILETRANSFER_BANDWIDTH_RECEIVED);
|
||||
}
|
||||
|
||||
public long getFiletransferBandwidthSent() {
|
||||
return getLong(ClientProperty.CONNECTION_FILETRANSFER_BANDWIDTH_SENT);
|
||||
}
|
||||
|
||||
public String getLoginName() {
|
||||
return get(ClientProperty.CLIENT_LOGIN_NAME);
|
||||
}
|
||||
|
||||
public String getMetaData() {
|
||||
return get(ClientProperty.CLIENT_META_DATA);
|
||||
}
|
||||
|
||||
public long getMonthlyBytesDownloaded() {
|
||||
return getLong(ClientProperty.CLIENT_MONTH_BYTES_DOWNLOADED);
|
||||
}
|
||||
|
||||
public long getMonthlyBytesUploaded() {
|
||||
return getLong(ClientProperty.CLIENT_MONTH_BYTES_UPLOADED);
|
||||
}
|
||||
|
||||
public int getNeededServerQueryViewPower() {
|
||||
return getInt(ClientProperty.CLIENT_NEEDED_SERVERQUERY_VIEW_POWER);
|
||||
}
|
||||
|
||||
public String getPhoneticNickname() {
|
||||
return get(ClientProperty.CLIENT_NICKNAME_PHONETIC);
|
||||
}
|
||||
|
||||
public String getTalkRequestMessage() {
|
||||
return get(ClientProperty.CLIENT_TALK_REQUEST_MSG);
|
||||
}
|
||||
|
||||
public long getTimeConnected() { // milliseconds
|
||||
return getLong(ClientProperty.CONNECTION_CONNECTED_TIME);
|
||||
}
|
||||
|
||||
public long getTotalBytesDownloaded() {
|
||||
return getLong(ClientProperty.CLIENT_TOTAL_BYTES_DOWNLOADED);
|
||||
}
|
||||
|
||||
public long getTotalBytesReceived() {
|
||||
return getLong(ClientProperty.CONNECTION_BYTES_RECEIVED_TOTAL);
|
||||
}
|
||||
|
||||
public long getTotalBytesSent() {
|
||||
return getLong(ClientProperty.CONNECTION_BYTES_SENT_TOTAL);
|
||||
}
|
||||
|
||||
public long getTotalBytesUploaded() {
|
||||
return getLong(ClientProperty.CLIENT_TOTAL_BYTES_UPLOADED);
|
||||
}
|
||||
|
||||
public int getTotalConnections() {
|
||||
return getInt(ClientProperty.CLIENT_TOTALCONNECTIONS);
|
||||
}
|
||||
|
||||
public long getTotalPacketsReceived() {
|
||||
return getLong(ClientProperty.CONNECTION_PACKETS_RECEIVED_TOTAL);
|
||||
}
|
||||
|
||||
public long getTotalPacketsSent() {
|
||||
return getLong(ClientProperty.CONNECTION_PACKETS_SENT_TOTAL);
|
||||
}
|
||||
|
||||
public int getUnreadMessages() {
|
||||
return getInt(ClientProperty.CLIENT_UNREAD_MESSAGES);
|
||||
}
|
||||
|
||||
public boolean isOutputOnlyMuted() {
|
||||
return getBoolean(ClientProperty.CLIENT_OUTPUTONLY_MUTED);
|
||||
}
|
||||
|
||||
public boolean isRequestingToTalk() {
|
||||
return getBoolean(ClientProperty.CLIENT_TALK_REQUEST);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTalking() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
62
src/com/github/theholywaffle/teamspeak3/api/wrapper/Complaint.java
Normale Datei
62
src/com/github/theholywaffle/teamspeak3/api/wrapper/Complaint.java
Normale Datei
@ -0,0 +1,62 @@
|
||||
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 java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
public class Complaint extends Wrapper {
|
||||
|
||||
public Complaint(Map<String, String> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
public int getTargetClientDatabaseId() {
|
||||
return getInt("tcldbid");
|
||||
}
|
||||
|
||||
public String getTargetName() {
|
||||
return get("tname");
|
||||
}
|
||||
|
||||
public int getSourceClientDatabaseId() {
|
||||
return getInt("fcldbid");
|
||||
}
|
||||
|
||||
public String getSourceName() {
|
||||
return get("fname");
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return get("message");
|
||||
}
|
||||
|
||||
public Date getTimestamp() {
|
||||
return new Date(getLong("timestamp") * 1000);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
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 java.util.Map;
|
||||
|
||||
import com.github.theholywaffle.teamspeak3.api.VirtualServerProperty;
|
||||
|
||||
public class ConnectionInfo extends Wrapper {
|
||||
|
||||
public ConnectionInfo(Map<String, String> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
public long getFiletransferBandwidthSent() {
|
||||
return getLong(VirtualServerProperty.CONNECTION_FILETRANSFER_BANDWIDTH_SENT);
|
||||
}
|
||||
|
||||
public long getFiletransferBandwidthReceived() {
|
||||
return getLong(VirtualServerProperty.CONNECTION_FILETRANSFER_BANDWIDTH_RECEIVED);
|
||||
}
|
||||
|
||||
public long getFiletransferBytesSent() {
|
||||
return getLong(VirtualServerProperty.CONNECTION_FILETRANSFER_BYTES_SENT_TOTAL);
|
||||
}
|
||||
|
||||
public long getFiletransferBytesReceived() {
|
||||
return getLong(VirtualServerProperty.CONNECTION_FILETRANSFER_BYTES_RECEIVED_TOTAL);
|
||||
}
|
||||
|
||||
public long getTotalPacketsSent() {
|
||||
return getLong(VirtualServerProperty.CONNECTION_PACKETS_SENT_TOTAL);
|
||||
}
|
||||
|
||||
public long getTotalBytesSent() {
|
||||
return getLong(VirtualServerProperty.CONNECTION_BYTES_SENT_TOTAL);
|
||||
}
|
||||
|
||||
public long getTotalPacketsReceived() {
|
||||
return getLong(VirtualServerProperty.CONNECTION_PACKETS_RECEIVED_TOTAL);
|
||||
}
|
||||
|
||||
public long getTotalBytesReceived() {
|
||||
return getLong(VirtualServerProperty.CONNECTION_BYTES_RECEIVED_TOTAL);
|
||||
}
|
||||
|
||||
public long getBandwidthSentLastSecond() {
|
||||
return getLong(VirtualServerProperty.CONNECTION_BANDWIDTH_SENT_LAST_SECOND_TOTAL);
|
||||
}
|
||||
|
||||
public long getBandwidthSentLastMinute() {
|
||||
return getLong(VirtualServerProperty.CONNECTION_BANDWIDTH_SENT_LAST_MINUTE_TOTAL);
|
||||
}
|
||||
|
||||
public long getBandwidthReceivedLastSecond() {
|
||||
return getLong(VirtualServerProperty.CONNECTION_BANDWIDTH_RECEIVED_LAST_SECOND_TOTAL);
|
||||
}
|
||||
|
||||
public long getBandwidthReceivedLastMinute() {
|
||||
return getLong(VirtualServerProperty.CONNECTION_BANDWIDTH_RECEIVED_LAST_MINUTE_TOTAL);
|
||||
}
|
||||
|
||||
public long getConnectedTime() {
|
||||
return getLong("connection_connected_time");
|
||||
}
|
||||
|
||||
public double getPacketLoss() {
|
||||
return getDouble("connection_packetloss_total");
|
||||
}
|
||||
|
||||
public double getPing() {
|
||||
return getDouble("connection_ping");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
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 java.util.Map;
|
||||
|
||||
public class CreatedVirtualServer extends Wrapper {
|
||||
|
||||
public CreatedVirtualServer(Map<String, String> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return getInt("sid");
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return getInt("virtualserver_port");
|
||||
}
|
||||
|
||||
public String getServerAdminToken() {
|
||||
return get("token");
|
||||
}
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
package com.github.theholywaffle.teamspeak3.api.wrapper;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* TeamSpeak 3 Java API
|
||||
* %%
|
||||
* Copyright (C) 2018 Bert De Geyter, Roger Baumgartner
|
||||
* %%
|
||||
* 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.Map;
|
||||
|
||||
/**
|
||||
* Wrapper class for the result to a {@code customsearch} command.
|
||||
*/
|
||||
public class CustomPropertyAssignment extends Wrapper {
|
||||
|
||||
public CustomPropertyAssignment(Map<String, String> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the database ID of the client that matched the custom client property search.
|
||||
*
|
||||
* @return the client's database ID
|
||||
*
|
||||
* @see Client#getDatabaseId()
|
||||
*/
|
||||
public int getClientDatabaseId() {
|
||||
return getInt("cldbid");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the key of the matched custom client property.
|
||||
*
|
||||
* @return the key of the property
|
||||
*/
|
||||
public String getKey() {
|
||||
return get("ident");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the matched custom client property.
|
||||
*
|
||||
* @return the value of the property
|
||||
*/
|
||||
public String getValue() {
|
||||
return get("value");
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
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.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
public class DatabaseClient extends Wrapper {
|
||||
|
||||
public DatabaseClient(Map<String, String> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
public int getDatabaseId() {
|
||||
return getInt("cldbid");
|
||||
}
|
||||
|
||||
public String getUniqueIdentifier() {
|
||||
return get(ClientProperty.CLIENT_UNIQUE_IDENTIFIER);
|
||||
}
|
||||
|
||||
public String getNickname() {
|
||||
return get(ClientProperty.CLIENT_NICKNAME);
|
||||
}
|
||||
|
||||
public Date getCreatedDate() {
|
||||
return new Date(getLong(ClientProperty.CLIENT_CREATED) * 1000);
|
||||
}
|
||||
|
||||
public Date getLastConnectedDate() {
|
||||
return new Date(getLong(ClientProperty.CLIENT_LASTCONNECTED) * 1000);
|
||||
}
|
||||
|
||||
public int getTotalConnections() {
|
||||
return getInt(ClientProperty.CLIENT_TOTALCONNECTIONS);
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return get(ClientProperty.CLIENT_DESCRIPTION);
|
||||
}
|
||||
|
||||
public String getLastIp() {
|
||||
return get("client_lastip");
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
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.util.Map;
|
||||
|
||||
public class DatabaseClientInfo extends DatabaseClient {
|
||||
|
||||
public DatabaseClientInfo(Map<String, String> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDatabaseId() {
|
||||
return getInt(ClientProperty.CLIENT_DATABASE_ID);
|
||||
}
|
||||
|
||||
public String getAvatar() {
|
||||
return get(ClientProperty.CLIENT_FLAG_AVATAR);
|
||||
}
|
||||
|
||||
public long getMonthlyBytesUploaded() {
|
||||
return getLong(ClientProperty.CLIENT_MONTH_BYTES_UPLOADED);
|
||||
}
|
||||
|
||||
public long getMonthlyBytesDownloaded() {
|
||||
return getLong(ClientProperty.CLIENT_MONTH_BYTES_DOWNLOADED);
|
||||
}
|
||||
|
||||
public long getTotalBytesUploaded() {
|
||||
return getLong(ClientProperty.CLIENT_TOTAL_BYTES_UPLOADED);
|
||||
}
|
||||
|
||||
public long getTotalBytesDownloaded() {
|
||||
return getLong(ClientProperty.CLIENT_TOTAL_BYTES_DOWNLOADED);
|
||||
}
|
||||
|
||||
public long getIconId() {
|
||||
return getLong(ClientProperty.CLIENT_ICON_ID);
|
||||
}
|
||||
|
||||
public String getBase64HashClientUID() {
|
||||
return get("client_base64HashClientUID");
|
||||
}
|
||||
}
|
134
src/com/github/theholywaffle/teamspeak3/api/wrapper/FileInfo.java
Normale Datei
134
src/com/github/theholywaffle/teamspeak3/api/wrapper/FileInfo.java
Normale Datei
@ -0,0 +1,134 @@
|
||||
package com.github.theholywaffle.teamspeak3.api.wrapper;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* TeamSpeak 3 Java API
|
||||
* %%
|
||||
* Copyright (C) 2016 Bert De Geyter, Roger Baumgartner
|
||||
* %%
|
||||
* 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.Date;
|
||||
import java.util.Map;
|
||||
|
||||
public class FileInfo extends Wrapper {
|
||||
|
||||
public FileInfo(Map<String, String> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ID of the channel this file is stored on.
|
||||
*
|
||||
* @return the ID of the file's channel
|
||||
*/
|
||||
public int getChannelId() {
|
||||
return getInt("cid");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the path to this file or directory, including its name.
|
||||
* This path can be used in other file transfer commands.
|
||||
*
|
||||
* @return the path to the file or directory
|
||||
*/
|
||||
public String getPath() {
|
||||
return get("name");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of this file or directory.
|
||||
*
|
||||
* @return the name of this file or directory
|
||||
*/
|
||||
public String getName() {
|
||||
String fullPath = getPath();
|
||||
int slashPos = fullPath.lastIndexOf('/');
|
||||
if (slashPos < 0) return fullPath;
|
||||
return fullPath.substring(slashPos + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the path of the directory containing this file or directory.
|
||||
*
|
||||
* @return the path to the parent directory
|
||||
*
|
||||
* @see #getPath()
|
||||
*/
|
||||
public String getParentPath() {
|
||||
String fullPath = getPath();
|
||||
int slashPos = fullPath.lastIndexOf('/');
|
||||
if (slashPos < 0) return "/";
|
||||
return fullPath.substring(0, slashPos + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the size of the file in bytes.
|
||||
* Note that this can return wrong values if the file is still being uploaded
|
||||
* or if the upload has been paused by the uploading client.
|
||||
*
|
||||
* @return the file's size
|
||||
*/
|
||||
public long getFileSize() {
|
||||
return getLong("size");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the date of the last modification to this file.
|
||||
* The date has a one-second resolution.
|
||||
*
|
||||
* @return the file's last modification date
|
||||
*/
|
||||
public Date getLastModifiedDate() {
|
||||
return new Date(getLong("datetime") * 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets whether this entry is a directory or a file.
|
||||
* {@code 0} stands for a directory, {@code 1} for a file.
|
||||
* <p>
|
||||
* Consider using {@link #isFile} and {@link #isDirectory} instead.
|
||||
* </p>
|
||||
*
|
||||
* @return the type of this file entry
|
||||
*/
|
||||
public int getType() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if this entry is a file and not a directory.
|
||||
*
|
||||
* @return whether this is a file
|
||||
*/
|
||||
public boolean isFile() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if this entry is a directory and not a file.
|
||||
*
|
||||
* @return whether this is a directory
|
||||
*/
|
||||
public boolean isDirectory() {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
package com.github.theholywaffle.teamspeak3.api.wrapper;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* TeamSpeak 3 Java API
|
||||
* %%
|
||||
* Copyright (C) 2016 Bert De Geyter, Roger Baumgartner
|
||||
* %%
|
||||
* 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.Map;
|
||||
|
||||
public class FileListEntry extends FileInfo {
|
||||
|
||||
public FileListEntry(Map<String, String> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPath() {
|
||||
return getParentPath() + getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return get("name");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getParentPath() {
|
||||
return get("path");
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getFileSize() {
|
||||
// Present if still uploading and returns
|
||||
final long finishedSize = getLong("incompletesize");
|
||||
return (finishedSize > 0) ? finishedSize : super.getFileSize();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getType() {
|
||||
return getInt("type");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFile() {
|
||||
return getType() == 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDirectory() {
|
||||
return getType() == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if this file was actively being uploaded at the time
|
||||
* this object was created. Note that this will return {@code false} if a
|
||||
* client has paused an upload.
|
||||
*
|
||||
* @return whether this file is actively being uploaded
|
||||
*/
|
||||
public boolean isStillUploading() {
|
||||
return getLong("incompletesize") > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* If this file is still uploading, this method will return how many bytes have already
|
||||
* been uploaded. Otherwise the normal file size is returned.
|
||||
*
|
||||
* @return how many bytes of this file have been uploaded
|
||||
*/
|
||||
public long getUploadedBytes() {
|
||||
return super.getFileSize();
|
||||
}
|
||||
}
|
166
src/com/github/theholywaffle/teamspeak3/api/wrapper/FileTransfer.java
Normale Datei
166
src/com/github/theholywaffle/teamspeak3/api/wrapper/FileTransfer.java
Normale Datei
@ -0,0 +1,166 @@
|
||||
package com.github.theholywaffle.teamspeak3.api.wrapper;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* TeamSpeak 3 Java API
|
||||
* %%
|
||||
* Copyright (C) 2016 Bert De Geyter, Roger Baumgartner
|
||||
* %%
|
||||
* 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.Map;
|
||||
|
||||
public class FileTransfer extends Wrapper {
|
||||
|
||||
public FileTransfer(Map<String, String> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ID of the client who started this file transfer.
|
||||
*
|
||||
* @return the ID of the involved client
|
||||
*/
|
||||
public int getClientId() {
|
||||
return getInt("clid");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the path of the folder that the file which is being transferred is stored in on disk.
|
||||
* This path seems to be relative to the folder the TS3 server is installed in.
|
||||
*
|
||||
* @return the disk path of the folder containing the transferring file
|
||||
*/
|
||||
public String getDiskFilePath() {
|
||||
return get("path");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the file on the TS3 server without its full path.
|
||||
*
|
||||
* @return the file's name
|
||||
*/
|
||||
public String getFileName() {
|
||||
return get("name");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the size in bytes the file will have once it is fully transferred.
|
||||
*
|
||||
* @return the final file size in bytes
|
||||
*/
|
||||
public long getTotalFileSize() {
|
||||
return getLong("size");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the amount of bytes that have already been transferred.
|
||||
*
|
||||
* @return the amount of transferred bytes
|
||||
*/
|
||||
public long getTransferredFileSize() {
|
||||
return getLong("sizedone");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key that the client has sent to the server to identify their file transfer.
|
||||
*
|
||||
* @return the client's file transfer ID
|
||||
*/
|
||||
public int getClientTransferId() {
|
||||
return getInt("clientftfid");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an internal ID that the server uses to identify their file transfer.
|
||||
* This is <strong>not</strong> the key that can be used to request a file from the file server.
|
||||
*
|
||||
* @return the server's file transfer ID
|
||||
*/
|
||||
public int getServerTransferId() {
|
||||
return getInt("serverftfid");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current status of the file transfer.
|
||||
* <p>
|
||||
* Currently known status codes:
|
||||
* </p>
|
||||
* <ul>
|
||||
* <li>0 - Not started</li>
|
||||
* <li>1 - Active</li>
|
||||
* <li>2 - Inactive (paused, stalled or done)</li>
|
||||
* </ul>
|
||||
*
|
||||
* @return the current transfer status
|
||||
*/
|
||||
public int getStatus() {
|
||||
return getInt("status");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if the file transfer has started.
|
||||
*
|
||||
* @return whether the file transfer has started
|
||||
*/
|
||||
public boolean hasStarted() {
|
||||
return getStatus() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if the file transfer is still active.
|
||||
* This is the case when the transfer has started and is not done or paused.
|
||||
*
|
||||
* @return whether the file transfer is active
|
||||
*/
|
||||
public boolean isActive() {
|
||||
return getStatus() == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current file transfer speed in bytes per second.
|
||||
*
|
||||
* @return the current transfer speed
|
||||
*/
|
||||
public double getCurrentSpeed() {
|
||||
return getDouble("current_speed");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current file transfer speed in bytes per second.
|
||||
*
|
||||
* @return the current transfer speed
|
||||
*/
|
||||
public double getAverageSpeed() {
|
||||
return getDouble("average_speed");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns how many milliseconds have elapsed since the file transfer was first announced to
|
||||
* the server. This value will count up even if the file transfer has not yet been started,
|
||||
* but will stop if the transfer has been paused or is complete.
|
||||
*
|
||||
* @return the transfer runtime in milliseconds
|
||||
*/
|
||||
public long getRuntime() {
|
||||
return getLong("runtime");
|
||||
}
|
||||
}
|
@ -0,0 +1,127 @@
|
||||
package com.github.theholywaffle.teamspeak3.api.wrapper;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* TeamSpeak 3 Java API
|
||||
* %%
|
||||
* Copyright (C) 2016 Bert De Geyter, Roger Baumgartner
|
||||
* %%
|
||||
* 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.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Represents an internally started file transfer and encapsulates the command response.
|
||||
*/
|
||||
public class FileTransferParameters extends Wrapper {
|
||||
|
||||
public FileTransferParameters(Map<String, String> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key that the client has sent to the server to identify their file transfer.
|
||||
*
|
||||
* @return the client's file transfer ID
|
||||
*/
|
||||
public int getClientTransferId() {
|
||||
return getInt("clientftfid");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an internal ID that the server uses to identify their file transfer.
|
||||
* This is <strong>not</strong> the key that can be used to request a file from the file server.
|
||||
*
|
||||
* @return the server's file transfer ID
|
||||
*/
|
||||
public int getServerTransferId() {
|
||||
return getInt("serverftfid");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the key needed identify ourselves to the file server and to start the file transfer.
|
||||
*
|
||||
* @return the file transfer key
|
||||
*/
|
||||
public String getFileTransferKey() {
|
||||
return get("ftkey");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the IP address or hostname of the file server the TS3 instance wants us to send our data to.
|
||||
*
|
||||
* @return the IP address of the file server
|
||||
*/
|
||||
public String getFileServerHost() {
|
||||
return get("ip");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the port of the file server the TS3 instance wants us to send our data to.
|
||||
*
|
||||
* @return the port of the file server
|
||||
*/
|
||||
public int getFileServerPort() {
|
||||
return getInt("port");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the size of the file being downloaded in bytes.
|
||||
* Only present if this is a successfully started download.
|
||||
*
|
||||
* @return the size of the file being downloaded.
|
||||
*/
|
||||
public long getFileSize() {
|
||||
return getLong("size");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a {@link QueryError} that can be used when throwing an exception.
|
||||
*
|
||||
* @return a query error for this command's success value
|
||||
*/
|
||||
public QueryError getQueryError() {
|
||||
Map<String, String> errorMap = new HashMap<>(2);
|
||||
errorMap.put("id", String.valueOf(getStatus()));
|
||||
errorMap.put("msg", getMessage());
|
||||
return new QueryError(errorMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the status / error code of this command. Only present if the command failed.
|
||||
*
|
||||
* @return the command's status value
|
||||
*/
|
||||
public int getStatus() {
|
||||
final int status = getInt("status");
|
||||
return status == -1 ? 0 : status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the message that is provided in case the command fails.
|
||||
*
|
||||
* @return the failure message
|
||||
*/
|
||||
public String getMessage() {
|
||||
return get("msg");
|
||||
}
|
||||
}
|
112
src/com/github/theholywaffle/teamspeak3/api/wrapper/HostInfo.java
Normale Datei
112
src/com/github/theholywaffle/teamspeak3/api/wrapper/HostInfo.java
Normale Datei
@ -0,0 +1,112 @@
|
||||
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 java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
import com.github.theholywaffle.teamspeak3.api.ServerInstanceProperty;
|
||||
|
||||
public class HostInfo extends Wrapper {
|
||||
|
||||
public HostInfo(Map<String, String> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
public long getUptime() {
|
||||
return getLong(ServerInstanceProperty.INSTANCE_UPTIME);
|
||||
}
|
||||
|
||||
public Date getTimeStamp() {
|
||||
return new Date(getLong(ServerInstanceProperty.HOST_TIMESTAMP_UTC) * 1000);
|
||||
}
|
||||
|
||||
public int getTotalRunningServers() {
|
||||
return getInt(ServerInstanceProperty.VIRTUALSERVERS_RUNNING_TOTAL);
|
||||
}
|
||||
|
||||
public int getTotalMaxClients() {
|
||||
return getInt(ServerInstanceProperty.VIRTUALSERVERS_TOTAL_MAXCLIENTS);
|
||||
}
|
||||
|
||||
public int getTotalClientsOnline() {
|
||||
return getInt(ServerInstanceProperty.VIRTUALSERVERS_TOTAL_CLIENTS_ONLINE);
|
||||
}
|
||||
|
||||
public int getTotalChannels() {
|
||||
return getInt(ServerInstanceProperty.VIRTUALSERVERS_TOTAL_CHANNELS_ONLINE);
|
||||
}
|
||||
|
||||
public long getFileTransferBandwidthSent() {
|
||||
return getLong(ServerInstanceProperty.CONNECTION_FILETRANSFER_BANDWIDTH_SENT);
|
||||
}
|
||||
|
||||
public long getFileTransferBandwidthReceived() {
|
||||
return getLong(ServerInstanceProperty.CONNECTION_FILETRANSFER_BANDWIDTH_RECEIVED);
|
||||
}
|
||||
|
||||
public long getFileTransferBytesSent() {
|
||||
return getLong(ServerInstanceProperty.CONNECTION_FILETRANSFER_BYTES_SENT_TOTAL);
|
||||
}
|
||||
|
||||
public long getFileTransferBytesReceived() {
|
||||
return getLong(ServerInstanceProperty.CONNECTION_FILETRANSFER_BYTES_RECEIVED_TOTAL);
|
||||
}
|
||||
|
||||
public long getPacketsSentTotal() {
|
||||
return getLong(ServerInstanceProperty.CONNECTION_PACKETS_SENT_TOTAL);
|
||||
}
|
||||
|
||||
public long getBytesSentTotal() {
|
||||
return getLong(ServerInstanceProperty.CONNECTION_BYTES_SENT_TOTAL);
|
||||
}
|
||||
|
||||
public long getPacketsReceivedTotal() {
|
||||
return getLong(ServerInstanceProperty.CONNECTION_PACKETS_RECEIVED_TOTAL);
|
||||
}
|
||||
|
||||
public long getBytesReceivedTotal() {
|
||||
return getLong(ServerInstanceProperty.CONNECTION_BYTES_RECEIVED_TOTAL);
|
||||
}
|
||||
|
||||
public long getBandwidthSentLastSecond() {
|
||||
return getLong(ServerInstanceProperty.CONNECTION_BANDWIDTH_SENT_LAST_SECOND_TOTAL);
|
||||
}
|
||||
|
||||
public long getBandwidthSentLastMinute() {
|
||||
return getLong(ServerInstanceProperty.CONNECTION_BANDWIDTH_SENT_LAST_MINUTE_TOTAL);
|
||||
}
|
||||
|
||||
public long getBandwidthReceivedLastSecond() {
|
||||
return getLong(ServerInstanceProperty.CONNECTION_BANDWIDTH_RECEIVED_LAST_SECOND_TOTAL);
|
||||
}
|
||||
|
||||
public long getBandwidthReceivedLastMinute() {
|
||||
return getLong(ServerInstanceProperty.CONNECTION_BANDWIDTH_RECEIVED_LAST_MINUTE_TOTAL);
|
||||
}
|
||||
|
||||
}
|
50
src/com/github/theholywaffle/teamspeak3/api/wrapper/IconFile.java
Normale Datei
50
src/com/github/theholywaffle/teamspeak3/api/wrapper/IconFile.java
Normale Datei
@ -0,0 +1,50 @@
|
||||
package com.github.theholywaffle.teamspeak3.api.wrapper;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* TeamSpeak 3 Java API
|
||||
* %%
|
||||
* Copyright (C) 2016 Bert De Geyter, Roger Baumgartner
|
||||
* %%
|
||||
* 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.Map;
|
||||
|
||||
public class IconFile extends FileListEntry {
|
||||
|
||||
public IconFile(Map<String, String> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the icon ID corresponding to this file, or {@code -1} if the file name
|
||||
* doesn't follow the standard format.
|
||||
*
|
||||
* @return this file's icon ID
|
||||
*/
|
||||
public long getIconId() {
|
||||
String fileName = getName();
|
||||
if (!fileName.matches("icon_\\d{1,10}")) return -1L; // Doesn't match standard pattern
|
||||
long id = Long.parseLong(fileName.substring("icon_".length()));
|
||||
if ((id & 0xFFFF_FFFF_0000_0000L) != 0) return -1L; // CRC32 is 32 bits, so needs to fit into an int
|
||||
return id;
|
||||
}
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
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 java.util.Map;
|
||||
|
||||
import com.github.theholywaffle.teamspeak3.api.ServerInstanceProperty;
|
||||
|
||||
public class InstanceInfo extends Wrapper {
|
||||
|
||||
public InstanceInfo(Map<String, String> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
public int getDatabaseVersion() {
|
||||
return getInt(ServerInstanceProperty.SERVERINSTANCE_DATABASE_VERSION);
|
||||
}
|
||||
|
||||
public int getFileTransferPort() {
|
||||
return getInt(ServerInstanceProperty.SERVERINSTANCE_FILETRANSFER_PORT);
|
||||
}
|
||||
|
||||
public long getMaxDownloadBandwidth() {
|
||||
return getLong(ServerInstanceProperty.SERVERINSTANCE_MAX_DOWNLOAD_TOTAL_BANDWIDTH);
|
||||
}
|
||||
|
||||
public long getMaxUploadBandwidth() {
|
||||
return getLong(ServerInstanceProperty.SERVERINSTANCE_MAX_UPLOAD_TOTAL_BANDWIDTH);
|
||||
}
|
||||
|
||||
public int getGuestServerQueryGroup() {
|
||||
return getInt(ServerInstanceProperty.SERVERINSTANCE_GUEST_SERVERQUERY_GROUP);
|
||||
}
|
||||
|
||||
public int getMaxFloodCommands() {
|
||||
return getInt(ServerInstanceProperty.SERVERINSTANCE_SERVERQUERY_FLOOD_COMMANDS);
|
||||
}
|
||||
|
||||
public int getMaxFloodTime() { // SECONDS
|
||||
return getInt(ServerInstanceProperty.SERVERINSTANCE_SERVERQUERY_FLOOD_TIME);
|
||||
}
|
||||
|
||||
public int getFloodBanTime() {// SECONDS
|
||||
return getInt(ServerInstanceProperty.SERVERINSTANCE_SERVERQUERY_BAN_TIME);
|
||||
}
|
||||
|
||||
public int getServerAdminGroup() {
|
||||
return getInt(ServerInstanceProperty.SERVERINSTANCE_TEMPLATE_SERVERADMIN_GROUP);
|
||||
}
|
||||
|
||||
public int getDefaultServerGroup() {
|
||||
return getInt(ServerInstanceProperty.SERVERINSTANCE_TEMPLATE_SERVERDEFAULT_GROUP);
|
||||
}
|
||||
|
||||
public int getChannelAdminGroup() {
|
||||
return getInt(ServerInstanceProperty.SERVERINSTANCE_TEMPLATE_CHANNELADMIN_GROUP);
|
||||
}
|
||||
|
||||
public int getDefaultChannelGroup() {
|
||||
return getInt(ServerInstanceProperty.SERVERINSTANCE_TEMPLATE_CHANNELDEFAULT_GROUP);
|
||||
}
|
||||
|
||||
public int getPermissionsVersion() {
|
||||
return getInt(ServerInstanceProperty.SERVERINSTANCE_PERMISSIONS_VERSION);
|
||||
}
|
||||
}
|
57
src/com/github/theholywaffle/teamspeak3/api/wrapper/Message.java
Normale Datei
57
src/com/github/theholywaffle/teamspeak3/api/wrapper/Message.java
Normale Datei
@ -0,0 +1,57 @@
|
||||
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 java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
public class Message extends Wrapper {
|
||||
|
||||
public Message(Map<String, String> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return getInt("msgid");
|
||||
}
|
||||
|
||||
public String getSenderUniqueIdentifier() {
|
||||
return get("cluid");
|
||||
}
|
||||
|
||||
public String getSubject() {
|
||||
return get("subject");
|
||||
}
|
||||
|
||||
public Date getReceivedDate() {
|
||||
return new Date(getLong("timestamp") * 1000);
|
||||
}
|
||||
|
||||
public boolean hasBeenRead() {
|
||||
return getBoolean("flag_read");
|
||||
}
|
||||
}
|
110
src/com/github/theholywaffle/teamspeak3/api/wrapper/Permission.java
Normale Datei
110
src/com/github/theholywaffle/teamspeak3/api/wrapper/Permission.java
Normale Datei
@ -0,0 +1,110 @@
|
||||
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 java.util.Map;
|
||||
|
||||
/**
|
||||
* Describes a permission that has been assigned to a client,
|
||||
* a channel group or a server group.
|
||||
* <p>
|
||||
* For a complete description of the TS3 permission system, refer to
|
||||
* <a href="http://forum.teamspeak.com/threads/49581-The-New-Permission-Documentataions">
|
||||
* this post</a> on the TeamSpeak forums.
|
||||
* </p>
|
||||
*/
|
||||
public class Permission extends Wrapper {
|
||||
|
||||
public Permission(Map<String, String> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of this permission.
|
||||
* <p>
|
||||
* Boolean permissions are prefixed with {@code b_}<br>
|
||||
* Integer permissions are prefixed with {@code i_}
|
||||
* </p>
|
||||
*
|
||||
* @return this permission's name
|
||||
*/
|
||||
public String getName() {
|
||||
return get("permsid");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of this permission assignment.
|
||||
* <p>
|
||||
* Please note that this value doesn't necessarily have to be
|
||||
* the effective permission value for a client, as this assignment
|
||||
* can be overridden by another assignment.
|
||||
* </p><p>
|
||||
* Integer permissions usually have values between 0 and 100,
|
||||
* but any integer value is theoretically valid.
|
||||
* </p><p>
|
||||
* Boolean permissions have a value of {@code 0} to represent
|
||||
* {@code false} and {@code 1} to represent {@code true}.
|
||||
* </p>
|
||||
*
|
||||
* @return the value of this permission assignment
|
||||
*/
|
||||
public int getValue() {
|
||||
return getInt("permvalue");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if this permission is negated.
|
||||
* <p>
|
||||
* Negated means that instead of the highest value, the lowest
|
||||
* value will be selected for this permission instead.
|
||||
* </p>
|
||||
*
|
||||
* @return whether this permission is negated or not
|
||||
*/
|
||||
public boolean isNegated() {
|
||||
return getBoolean("permnegated");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if this permission is skipped.
|
||||
* <p>
|
||||
* Skipped only exists for server group and client permissions,
|
||||
* therefore this value will always be false for channel group permissions.
|
||||
* </p><p>
|
||||
* If a client permission is skipped, it won't be overridden by channel
|
||||
* group permissions.<br>
|
||||
* If a server group permission is skipped, it won't be overridden by
|
||||
* channel group or client permissions.
|
||||
* </p>
|
||||
*
|
||||
* @return whether this permission is negated or not
|
||||
*/
|
||||
public boolean isSkipped() {
|
||||
return getBoolean("permskip");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,162 @@
|
||||
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.PermissionGroupType;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Describes a single permission that is assigned to a varying target.
|
||||
* <p>
|
||||
* This class is used when a lot of permissions are sent at once.
|
||||
* To reduce bandwidth usage, the TS3 server only transmit the numeric
|
||||
* permission ID and not the permission name.
|
||||
* </p><p>
|
||||
* For a complete description of the TS3 permission system, refer to
|
||||
* <a href="http://forum.teamspeak.com/threads/49581-The-New-Permission-Documentataions">
|
||||
* this post</a> on the TeamSpeak forums.
|
||||
* </p>
|
||||
*/
|
||||
public class PermissionAssignment extends Wrapper {
|
||||
|
||||
public PermissionAssignment(Map<String, String> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* Where this permission assignment originates from.
|
||||
*
|
||||
* @return the type of this permission assignment
|
||||
*/
|
||||
public PermissionGroupType getType() {
|
||||
final int type = getInt("t");
|
||||
for (final PermissionGroupType p : PermissionGroupType.values()) {
|
||||
if (p.getIndex() == type) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies where this permission assignment originates from,
|
||||
* depending on the {@linkplain #getType() type} of this assignment.
|
||||
* <p>
|
||||
* {@code x -> y} := <i>In case {@code type} is {@code x}, {@code majorId} means {@code y}</i>
|
||||
* </p><p>
|
||||
* {@linkplain PermissionGroupType#SERVER_GROUP SERVER_GROUP} {@code ->} {@linkplain ServerGroup#getId() Server group ID}<br>
|
||||
* {@linkplain PermissionGroupType#GLOBAL_CLIENT GLOBAL_CLIENT} {@code ->} {@linkplain Client#getDatabaseId() Client database ID}<br>
|
||||
* {@linkplain PermissionGroupType#CHANNEL CHANNEL} {@code ->} {@linkplain Channel#getId() Channel ID}<br>
|
||||
* {@linkplain PermissionGroupType#CHANNEL_GROUP CHANNEL_GROUP} {@code ->} {@linkplain Channel#getId() Channel ID}<br>
|
||||
* {@linkplain PermissionGroupType#CHANNEL_CLIENT CHANNEL_CLIENT} {@code ->} {@linkplain Channel#getId() Channel ID}
|
||||
* </p>
|
||||
*
|
||||
* @return the major ID of the source of this assignment as described above
|
||||
*/
|
||||
public int getMajorId() {
|
||||
return getInt("id1");
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies where this permission assignment originates from,
|
||||
* depending on the {@linkplain #getType() type} of this assignment.
|
||||
* <p>
|
||||
* {@code x -> y} := <i>In case {@code type} is {@code x}, {@code minorId} means {@code y}</i>
|
||||
* </p><p>
|
||||
* {@linkplain PermissionGroupType#CHANNEL_GROUP CHANNEL_GROUP} {@code ->} {@linkplain ChannelGroup#getId() Channel group ID}<br>
|
||||
* {@linkplain PermissionGroupType#CHANNEL_CLIENT CHANNEL_CLIENT} {@code ->} {@linkplain Client#getDatabaseId() Client database ID}
|
||||
* </p><p>
|
||||
* Otherwise {@code getMinorId()} is undefined should return {@code 0}.
|
||||
* </p>
|
||||
*
|
||||
* @return the minor ID of the source of this assignment as described above
|
||||
*/
|
||||
public int getMinorId() {
|
||||
return getInt("id2");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the numerical ID of this permission.
|
||||
*
|
||||
* @return this permission's numerical ID
|
||||
*/
|
||||
public int getId() {
|
||||
return getInt("p");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of this permission assignment.
|
||||
* <p>
|
||||
* Please note that this value doesn't necessarily have to be
|
||||
* the effective permission value for a client, as this assignment
|
||||
* can be overridden by another assignment.
|
||||
* </p><p>
|
||||
* Integer permissions usually have values between 0 and 100,
|
||||
* but any integer value is theoretically valid.
|
||||
* </p><p>
|
||||
* Boolean permissions have a value of {@code 0} to represent
|
||||
* {@code false} and {@code 1} to represent {@code true}.
|
||||
* </p>
|
||||
*
|
||||
* @return the value of this permission assignment
|
||||
*/
|
||||
public int getValue() {
|
||||
return getInt("v");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if this permission is negated.
|
||||
* <p>
|
||||
* Negated means that instead of the highest value, the lowest
|
||||
* value will be selected for this permission instead.
|
||||
* </p>
|
||||
*
|
||||
* @return whether this permission is negated or not
|
||||
*/
|
||||
public boolean isNegated() {
|
||||
return getBoolean("n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if this permission is skipped.
|
||||
* <p>
|
||||
* Skipped only exists for server group and client permissions,
|
||||
* therefore this value will always be false for channel group permissions.
|
||||
* </p><p>
|
||||
* If a client permission is skipped, it won't be overridden by channel
|
||||
* group permissions.<br>
|
||||
* If a server group permission is skipped, it won't be overridden by
|
||||
* channel group or client permissions.
|
||||
* </p>
|
||||
*
|
||||
* @return whether this permission is negated or not
|
||||
*/
|
||||
public boolean isSkipped() {
|
||||
return getBoolean("s");
|
||||
}
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
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 java.util.Map;
|
||||
|
||||
/**
|
||||
* Describes a single permission on the TS3 server.
|
||||
* <p>
|
||||
* Includes the numerical ID and the name of the permission, as well
|
||||
* as an optional short description of this permission. Does not
|
||||
* include any information about any possible permission assignments.
|
||||
* </p><p>
|
||||
* For a complete description of the TS3 permission system, refer to
|
||||
* <a href="http://forum.teamspeak.com/threads/49581-The-New-Permission-Documentataions">
|
||||
* this post</a> on the TeamSpeak forums.
|
||||
* </p>
|
||||
*/
|
||||
public class PermissionInfo extends Wrapper {
|
||||
|
||||
public PermissionInfo(Map<String, String> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the numerical ID of this permission.
|
||||
* <p>
|
||||
* In most cases, the name of the permission should be
|
||||
* preferred over the numerical ID.
|
||||
* </p>
|
||||
*
|
||||
* @return this permission's numerical ID
|
||||
*/
|
||||
public int getId() {
|
||||
return getInt("permid");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of this permission.
|
||||
* <p>
|
||||
* Boolean permissions are prefixed with {@code b_}<br>
|
||||
* Integer permissions are prefixed with {@code i_}
|
||||
* </p>
|
||||
*
|
||||
* @return this permission's name
|
||||
*/
|
||||
public String getName() {
|
||||
return get("permname");
|
||||
}
|
||||
|
||||
/**
|
||||
* A short description about what this permission does.
|
||||
* <p>
|
||||
* Does not exist for all permissions. In that case, an
|
||||
* empty String will be returned instead.
|
||||
* </p>
|
||||
*
|
||||
* @return a short description of this permission
|
||||
*/
|
||||
public String getDescription() {
|
||||
return get("permdesc");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
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 java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
public class PrivilegeKey extends Wrapper {
|
||||
|
||||
public PrivilegeKey(Map<String, String> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
return get("token");
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return getInt("token_type");
|
||||
}
|
||||
|
||||
public boolean isServerGroupToken() {
|
||||
return getType() == 0;
|
||||
}
|
||||
|
||||
public boolean isChannelGroupToken() {
|
||||
return !isServerGroupToken();
|
||||
}
|
||||
|
||||
public int getGroupId() {
|
||||
return getInt("token_id1");
|
||||
}
|
||||
|
||||
public int getChannelId() {
|
||||
return getInt("token_id2");
|
||||
}
|
||||
|
||||
public Date getCreated() {
|
||||
return new Date(getLong("token_created") * 1000);
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return get("token_description");
|
||||
}
|
||||
}
|
60
src/com/github/theholywaffle/teamspeak3/api/wrapper/QueryError.java
Normale Datei
60
src/com/github/theholywaffle/teamspeak3/api/wrapper/QueryError.java
Normale Datei
@ -0,0 +1,60 @@
|
||||
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 java.util.Map;
|
||||
|
||||
public class QueryError extends Wrapper {
|
||||
|
||||
private static final int ERROR_ID_OK = 0;
|
||||
private static final int ERROR_ID_EMPTY_RESULT_SET = 1281;
|
||||
|
||||
public QueryError(Map<String, String> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return getInt("id");
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return get("msg");
|
||||
}
|
||||
|
||||
public String getExtraMessage() {
|
||||
return get("extra_msg");
|
||||
}
|
||||
|
||||
public int getFailedPermissionId() {
|
||||
return getInt("failed_permid");
|
||||
}
|
||||
|
||||
public boolean isSuccessful() {
|
||||
final int id = getId();
|
||||
return (id == ERROR_ID_OK || id == ERROR_ID_EMPTY_RESULT_SET);
|
||||
}
|
||||
}
|
85
src/com/github/theholywaffle/teamspeak3/api/wrapper/ServerGroup.java
Normale Datei
85
src/com/github/theholywaffle/teamspeak3/api/wrapper/ServerGroup.java
Normale Datei
@ -0,0 +1,85 @@
|
||||
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 java.util.Map;
|
||||
|
||||
import com.github.theholywaffle.teamspeak3.api.PermissionGroupDatabaseType;
|
||||
|
||||
public class ServerGroup extends Wrapper {
|
||||
|
||||
public ServerGroup(Map<String, String> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return getInt("sgid");
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return get("name");
|
||||
}
|
||||
|
||||
public PermissionGroupDatabaseType getType() {
|
||||
final int type = getInt("type");
|
||||
for (final PermissionGroupDatabaseType p : PermissionGroupDatabaseType.values()) {
|
||||
if (p.getIndex() == type) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public long getIconId() {
|
||||
return getLong("iconid");
|
||||
}
|
||||
|
||||
public int getSaveDb() {
|
||||
return getInt("savedb");
|
||||
}
|
||||
|
||||
public int getSortId() {
|
||||
return getInt("sortid");
|
||||
}
|
||||
|
||||
public int getNameMode() {
|
||||
return getInt("namemode");
|
||||
}
|
||||
|
||||
public int getModifyPower() {
|
||||
return getInt("n_modifyp");
|
||||
}
|
||||
|
||||
public int getMemberAddPower() {
|
||||
return getInt("n_member_addp");
|
||||
}
|
||||
|
||||
public int getMemberRemovePower() {
|
||||
return getInt("n_member_removep");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
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 java.util.Map;
|
||||
|
||||
public class ServerGroupClient extends Wrapper {
|
||||
|
||||
public ServerGroupClient(Map<String, String> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
public int getClientDatabaseId() {
|
||||
return getInt("cldbid");
|
||||
}
|
||||
|
||||
public String getNickname() {
|
||||
return get("client_nickname");
|
||||
}
|
||||
|
||||
public String getUniqueIdentifier() {
|
||||
return get("client_unique_identifier");
|
||||
}
|
||||
|
||||
}
|
198
src/com/github/theholywaffle/teamspeak3/api/wrapper/ServerQueryInfo.java
Normale Datei
198
src/com/github/theholywaffle/teamspeak3/api/wrapper/ServerQueryInfo.java
Normale Datei
@ -0,0 +1,198 @@
|
||||
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.TS3Api;
|
||||
import com.github.theholywaffle.teamspeak3.TS3ApiAsync;
|
||||
import com.github.theholywaffle.teamspeak3.api.ClientProperty;
|
||||
import com.github.theholywaffle.teamspeak3.api.VirtualServerProperty;
|
||||
import com.github.theholywaffle.teamspeak3.api.VirtualServerStatus;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A class containing information about a server query, returned by the
|
||||
* API methods {@link TS3Api#whoAmI()} and {@link TS3ApiAsync#whoAmI()}.
|
||||
*/
|
||||
public class ServerQueryInfo extends Wrapper {
|
||||
|
||||
/**
|
||||
* Creates a new {@code ServerQueryInfo} from the information present in the provided map.
|
||||
*
|
||||
* @param map
|
||||
* the map containing the key-value pairs abstracted by this object
|
||||
*/
|
||||
public ServerQueryInfo(Map<String, String> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ID of the channel the server query is currently in.
|
||||
*
|
||||
* @return the ID of the current channel
|
||||
*/
|
||||
public int getChannelId() {
|
||||
return getInt("client_channel_id");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ID of the server query in the database.
|
||||
* <p>
|
||||
* In case this server query account was created by a client,
|
||||
* its database ID will be identical to the client's database ID.
|
||||
* </p>
|
||||
*
|
||||
* @return the server query's database ID
|
||||
*/
|
||||
public int getDatabaseId() {
|
||||
return getInt(ClientProperty.CLIENT_DATABASE_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the client ID of the server query.
|
||||
*
|
||||
* @return the server query's client ID
|
||||
*/
|
||||
public int getId() {
|
||||
return getInt("client_id");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the username that was used when logging the query in (using a username-password combination).
|
||||
* <p>
|
||||
* This username was set when creating the server query login and doesn't have to be related to
|
||||
* the client who created the server query login.
|
||||
* <br>
|
||||
* In case a server query is not logged in yet, this method will return an empty string.
|
||||
* </p>
|
||||
*
|
||||
* @return the username used when logging this query in
|
||||
*
|
||||
* @see TS3Api#login(String, String) TS3Api#login(username, password) - logging in server queries
|
||||
*/
|
||||
public String getLoginName() {
|
||||
return get(ClientProperty.CLIENT_LOGIN_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the nickname currently used by the server query.
|
||||
* Unless explicitly set, the nickname will be formatted like
|
||||
* <pre><i>username</i> from <i>ip</i>:<i>port</i></pre>
|
||||
* <p>
|
||||
* Nicknames are only assigned after a virtual server has been selected.
|
||||
* Until then, this method will return an empty string.
|
||||
* </p>
|
||||
*
|
||||
* @return the current nickname of the server query
|
||||
*/
|
||||
public String getNickname() {
|
||||
return get(ClientProperty.CLIENT_NICKNAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ID of the virtual server on which the server query login was created.
|
||||
* <p>
|
||||
* This method will return {@code 0} (the ID of the template server) if a server query is
|
||||
* not logged in or using the {@code serveradmin} login.
|
||||
* </p>
|
||||
*
|
||||
* @return the ID of the virtual server this server query belongs to
|
||||
*/
|
||||
public int getOriginServerId() {
|
||||
return getInt("client_origin_server_id");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the unique identifier of the server query.
|
||||
* <p>
|
||||
* In case this server query account was created by a client,
|
||||
* its unique ID will be identical to the client's unique ID.
|
||||
* </p>
|
||||
*
|
||||
* @return the server query's unique ID
|
||||
*/
|
||||
public String getUniqueIdentifier() {
|
||||
return get(ClientProperty.CLIENT_UNIQUE_IDENTIFIER);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the ID of the currently selected virtual server.
|
||||
* <p>
|
||||
* If used on a non-commercial TeamSpeak instance which can only host 1 virtual server,
|
||||
* this ID will always be 1.
|
||||
* <br>
|
||||
* If no virtual server has been selected yet, this method will return {@code 0}.
|
||||
* </p>
|
||||
*
|
||||
* @return the ID of the current virtual server or {@code 0} if none is selected
|
||||
*/
|
||||
public int getVirtualServerId() {
|
||||
return getInt(VirtualServerProperty.VIRTUALSERVER_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the port used by the currently selected virtual server.
|
||||
* <p>
|
||||
* If no virtual server has been selected yet, this method will return {@code 0}.
|
||||
* </p>
|
||||
*
|
||||
* @return the port used by the current virtual server or {@code 0} if none is selected
|
||||
*/
|
||||
public int getVirtualServerPort() {
|
||||
return getInt(VirtualServerProperty.VIRTUALSERVER_PORT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the status of the currently selected virtual server.
|
||||
* <p>
|
||||
* If no virtual server has been selected yet, this method will return {@link VirtualServerStatus#UNKNOWN}.
|
||||
* </p>
|
||||
*
|
||||
* @return the status of the current virtual server
|
||||
*/
|
||||
public VirtualServerStatus getVirtualServerStatus() {
|
||||
final String status = get(VirtualServerProperty.VIRTUALSERVER_STATUS);
|
||||
for (final VirtualServerStatus s : VirtualServerStatus.values()) {
|
||||
if (s.getName().equals(status)) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
return VirtualServerStatus.UNKNOWN;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the unique identifier of the currently selected virtual server.
|
||||
* <p>
|
||||
* If no virtual server has been selected yet, this method will return an empty string.
|
||||
* </p>
|
||||
*
|
||||
* @return the unique ID of the current virtual server
|
||||
*/
|
||||
public String getVirtualServerUniqueIdentifier() {
|
||||
return get(VirtualServerProperty.VIRTUALSERVER_UNIQUE_IDENTIFIER);
|
||||
}
|
||||
}
|
49
src/com/github/theholywaffle/teamspeak3/api/wrapper/Version.java
Normale Datei
49
src/com/github/theholywaffle/teamspeak3/api/wrapper/Version.java
Normale Datei
@ -0,0 +1,49 @@
|
||||
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 java.util.Map;
|
||||
|
||||
public class Version extends Wrapper {
|
||||
|
||||
public Version(Map<String, String> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return get("version");
|
||||
}
|
||||
|
||||
public String getBuild() {
|
||||
return get("build");
|
||||
}
|
||||
|
||||
public String getPlatform() {
|
||||
return get("platform");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
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.VirtualServerProperty;
|
||||
import com.github.theholywaffle.teamspeak3.api.VirtualServerStatus;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class VirtualServer extends Wrapper {
|
||||
|
||||
public VirtualServer(Map<String, String> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return getInt(VirtualServerProperty.VIRTUALSERVER_ID);
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return getInt(VirtualServerProperty.VIRTUALSERVER_PORT);
|
||||
}
|
||||
|
||||
public VirtualServerStatus getStatus() {
|
||||
final String status = get(VirtualServerProperty.VIRTUALSERVER_STATUS);
|
||||
for (final VirtualServerStatus s : VirtualServerStatus.values()) {
|
||||
if (status.equals(s.getName())) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
return VirtualServerStatus.UNKNOWN;
|
||||
}
|
||||
|
||||
public int getClientsOnline() {
|
||||
return getInt(VirtualServerProperty.VIRTUALSERVER_CLIENTSONLINE);
|
||||
}
|
||||
|
||||
public int getQueryClientsOnline() {
|
||||
return getInt(VirtualServerProperty.VIRTUALSERVER_QUERYCLIENTSONLINE);
|
||||
}
|
||||
|
||||
public int getMaxClients() {
|
||||
return getInt(VirtualServerProperty.VIRTUALSERVER_MAXCLIENTS);
|
||||
}
|
||||
|
||||
public String getUniqueIdentifier() {
|
||||
return get(VirtualServerProperty.VIRTUALSERVER_UNIQUE_IDENTIFIER);
|
||||
}
|
||||
|
||||
public long getUptime() {
|
||||
return getLong(VirtualServerProperty.VIRTUALSERVER_UPTIME); // in seconds
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return get(VirtualServerProperty.VIRTUALSERVER_NAME);
|
||||
}
|
||||
|
||||
public boolean isAutoStart() {
|
||||
return getBoolean(VirtualServerProperty.VIRTUALSERVER_AUTOSTART);
|
||||
}
|
||||
}
|
@ -0,0 +1,392 @@
|
||||
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.CodecEncryptionMode;
|
||||
import com.github.theholywaffle.teamspeak3.api.HostBannerMode;
|
||||
import com.github.theholywaffle.teamspeak3.api.HostMessageMode;
|
||||
import com.github.theholywaffle.teamspeak3.api.VirtualServerProperty;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
public class VirtualServerInfo extends VirtualServer {
|
||||
|
||||
public VirtualServerInfo(Map<String, String> map) {
|
||||
super(map);
|
||||
}
|
||||
|
||||
public int getAntifloodPointsNeededCommandBlock() {
|
||||
return getInt(VirtualServerProperty.VIRTUALSERVER_ANTIFLOOD_POINTS_NEEDED_COMMAND_BLOCK);
|
||||
}
|
||||
|
||||
public int getAntifloodPointsNeedIpBlock() {
|
||||
return getInt(VirtualServerProperty.VIRTUALSERVER_ANTIFLOOD_POINTS_NEEDED_IP_BLOCK);
|
||||
}
|
||||
|
||||
public int getAntifloodPointsTickReduce() {
|
||||
return getInt(VirtualServerProperty.VIRTUALSERVER_ANTIFLOOD_POINTS_TICK_REDUCE);
|
||||
}
|
||||
|
||||
public long getBandwidthReceivedLastMinute() {
|
||||
return getInt(VirtualServerProperty.CONNECTION_BANDWIDTH_RECEIVED_LAST_MINUTE_TOTAL);
|
||||
}
|
||||
|
||||
public long getBandwidthReceivedLastSecond() {
|
||||
return getLong(VirtualServerProperty.CONNECTION_BANDWIDTH_RECEIVED_LAST_SECOND_TOTAL);
|
||||
}
|
||||
|
||||
public long getBandwidthSentLastMinute() {
|
||||
return getLong(VirtualServerProperty.CONNECTION_BANDWIDTH_SENT_LAST_MINUTE_TOTAL);
|
||||
}
|
||||
|
||||
public long getBandwidthSentLastSecond() {
|
||||
return getLong(VirtualServerProperty.CONNECTION_BANDWIDTH_SENT_LAST_SECOND_TOTAL);
|
||||
}
|
||||
|
||||
public int getChannelsOnline() {
|
||||
return getInt(VirtualServerProperty.VIRTUALSERVER_CHANNELSONLINE);
|
||||
}
|
||||
|
||||
public CodecEncryptionMode getCodecEncryptionMode() {
|
||||
final int encryptionMode = getInt(VirtualServerProperty.VIRTUALSERVER_CODEC_ENCRYPTION_MODE);
|
||||
for (final CodecEncryptionMode m : CodecEncryptionMode.values()) {
|
||||
if (m.getIndex() == encryptionMode) {
|
||||
return m;
|
||||
}
|
||||
}
|
||||
return CodecEncryptionMode.UNKNOWN;
|
||||
}
|
||||
|
||||
public int getComplaintAutobanCount() {
|
||||
return getInt(VirtualServerProperty.VIRTUALSERVER_COMPLAIN_AUTOBAN_COUNT);
|
||||
}
|
||||
|
||||
public long getComplaintAutobanTime() {// SEC
|
||||
return getLong(VirtualServerProperty.VIRTUALSERVER_COMPLAIN_AUTOBAN_TIME);
|
||||
}
|
||||
|
||||
public long getComplaintRemoveTime() {
|
||||
return getLong(VirtualServerProperty.VIRTUALSERVER_COMPLAIN_REMOVE_TIME);
|
||||
}
|
||||
|
||||
public long getControlBytesReceived() {
|
||||
return getLong(VirtualServerProperty.CONNECTION_BYTES_RECEIVED_CONTROL);
|
||||
}
|
||||
|
||||
public long getControlBytesSent() {
|
||||
return getLong(VirtualServerProperty.CONNECTION_BYTES_SENT_CONTROL);
|
||||
}
|
||||
|
||||
public long getControlPacketsReceived() {
|
||||
return getLong(VirtualServerProperty.CONNECTION_PACKETS_RECEIVED_CONTROL);
|
||||
}
|
||||
|
||||
public long getControlPacketsSent() {
|
||||
return getLong(VirtualServerProperty.CONNECTION_PACKETS_SENT_CONTROL);
|
||||
}
|
||||
|
||||
public Date getCreatedDate() {
|
||||
return new Date(getLong(VirtualServerProperty.VIRTUALSERVER_CREATED) * 1000);
|
||||
}
|
||||
|
||||
public int getDefaultChannelAdminGroup() {
|
||||
return getInt(VirtualServerProperty.VIRTUALSERVER_DEFAULT_CHANNEL_ADMIN_GROUP);
|
||||
}
|
||||
|
||||
public int getDefaultChannelGroup() {
|
||||
return getInt(VirtualServerProperty.VIRTUALSERVER_DEFAULT_CHANNEL_GROUP);
|
||||
}
|
||||
|
||||
public int getDefaultServerGroup() {
|
||||
return getInt(VirtualServerProperty.VIRTUALSERVER_DEFAULT_SERVER_GROUP);
|
||||
}
|
||||
|
||||
public long getDownloadQuota() {
|
||||
return getLong(VirtualServerProperty.VIRTUALSERVER_DOWNLOAD_QUOTA);
|
||||
}
|
||||
|
||||
public String getFileBase() {
|
||||
return get(VirtualServerProperty.VIRTUALSERVER_FILEBASE);
|
||||
}
|
||||
|
||||
public long getFiletransferBandwidthReceived() {
|
||||
return getLong(VirtualServerProperty.CONNECTION_FILETRANSFER_BANDWIDTH_RECEIVED);
|
||||
}
|
||||
|
||||
public long getFiletransferBandwidthSent() {
|
||||
return getLong(VirtualServerProperty.CONNECTION_FILETRANSFER_BANDWIDTH_SENT);
|
||||
}
|
||||
|
||||
public long getFiletransferBytesReceived() {
|
||||
return getLong(VirtualServerProperty.CONNECTION_FILETRANSFER_BYTES_RECEIVED_TOTAL);
|
||||
}
|
||||
|
||||
public long getFiletransferBytesSent() {
|
||||
return getLong(VirtualServerProperty.CONNECTION_FILETRANSFER_BYTES_SENT_TOTAL);
|
||||
}
|
||||
|
||||
public int getHostbannerGfxInterval() {
|
||||
return getInt(VirtualServerProperty.VIRTUALSERVER_HOSTBANNER_GFX_INTERVAL);
|
||||
}
|
||||
|
||||
public String getHostbannerGfxUrl() {
|
||||
return get(VirtualServerProperty.VIRTUALSERVER_HOSTBANNER_GFX_URL);
|
||||
}
|
||||
|
||||
public HostBannerMode getHostbannerMode() {
|
||||
final int hostbannerMode = getInt(VirtualServerProperty.VIRTUALSERVER_HOSTBANNER_MODE);
|
||||
for (final HostBannerMode m : HostBannerMode.values()) {
|
||||
if (m.getIndex() == hostbannerMode) {
|
||||
return m;
|
||||
}
|
||||
}
|
||||
return HostBannerMode.UNKNOWN;
|
||||
}
|
||||
|
||||
public String getHostbannerUrl() {
|
||||
return get(VirtualServerProperty.VIRTUALSERVER_HOSTBANNER_URL);
|
||||
}
|
||||
|
||||
public String getHostbuttonGfxUrl() {
|
||||
return get(VirtualServerProperty.VIRTUALSERVER_HOSTBUTTON_GFX_URL);
|
||||
}
|
||||
|
||||
public String getHostbuttonTooltip() {
|
||||
return get(VirtualServerProperty.VIRTUALSERVER_HOSTBUTTON_TOOLTIP);
|
||||
}
|
||||
|
||||
public String getHostbuttonUrl() {
|
||||
return get(VirtualServerProperty.VIRTUALSERVER_HOSTBUTTON_URL);
|
||||
}
|
||||
|
||||
public String getHostMessage() {
|
||||
return get(VirtualServerProperty.VIRTUALSERVER_HOSTMESSAGE);
|
||||
}
|
||||
|
||||
public HostMessageMode getHostMessageMode() {
|
||||
final int hostmessageMode = getInt(VirtualServerProperty.VIRTUALSERVER_HOSTMESSAGE_MODE);
|
||||
for (final HostMessageMode m : HostMessageMode.values()) {
|
||||
if (m.getIndex() == hostmessageMode) {
|
||||
return m;
|
||||
}
|
||||
}
|
||||
return HostMessageMode.UNKNOWN;
|
||||
}
|
||||
|
||||
public long getIconId() {
|
||||
return getLong(VirtualServerProperty.VIRTUALSERVER_ICON_ID);
|
||||
}
|
||||
|
||||
public String getIp() {
|
||||
return get(VirtualServerProperty.VIRTUALSERVER_IP);
|
||||
}
|
||||
|
||||
public long getKeepAliveBytesReceived() {
|
||||
return getLong(VirtualServerProperty.CONNECTION_BYTES_RECEIVED_KEEPALIVE);
|
||||
}
|
||||
|
||||
public long getKeepAliveBytesSent() {
|
||||
return getLong(VirtualServerProperty.CONNECTION_BYTES_SENT_KEEPALIVE);
|
||||
}
|
||||
|
||||
public long getKeepAlivePacketsReceived() {
|
||||
return getLong(VirtualServerProperty.CONNECTION_PACKETS_RECEIVED_KEEPALIVE);
|
||||
}
|
||||
|
||||
public long getKeepAlivePacketsSent() {
|
||||
return getLong(VirtualServerProperty.CONNECTION_PACKETS_SENT_KEEPALIVE);
|
||||
}
|
||||
|
||||
public String getMachineId() {
|
||||
return get(VirtualServerProperty.VIRTUALSERVER_MACHINE_ID);
|
||||
}
|
||||
|
||||
public long getMaxDownloadBandwidth() {
|
||||
return getLong(VirtualServerProperty.VIRTUALSERVER_MAX_DOWNLOAD_TOTAL_BANDWIDTH);
|
||||
}
|
||||
|
||||
public long getMaxUploadBandwidth() {
|
||||
return getLong(VirtualServerProperty.VIRTUALSERVER_MAX_UPLOAD_TOTAL_BANDWIDTH);
|
||||
}
|
||||
|
||||
public int getMinClientsInChannelBeforeForcedSilence() {
|
||||
return getInt(VirtualServerProperty.VIRTUALSERVER_MIN_CLIENTS_IN_CHANNEL_BEFORE_FORCED_SILENCE);
|
||||
}
|
||||
|
||||
public int getMinimumClientVersion() {
|
||||
return getInt(VirtualServerProperty.VIRTUALSERVER_MIN_CLIENT_VERSION);
|
||||
}
|
||||
|
||||
public long getMonthlyBytesDownloaded() {
|
||||
return getLong(VirtualServerProperty.VIRTUALSERVER_MONTH_BYTES_DOWNLOADED);
|
||||
}
|
||||
|
||||
public long getMonthlyBytesUploaded() {
|
||||
return getLong(VirtualServerProperty.VIRTUALSERVER_MONTH_BYTES_UPLOADED);
|
||||
}
|
||||
|
||||
public int getNeededIdentitySecurityLevel() {
|
||||
return getInt(VirtualServerProperty.VIRTUALSERVER_NEEDED_IDENTITY_SECURITY_LEVEL);
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return get(VirtualServerProperty.VIRTUALSERVER_PASSWORD);
|
||||
}
|
||||
|
||||
public String getPhoneticName() {
|
||||
return get(VirtualServerProperty.VIRTUALSERVER_NAME_PHONETIC);
|
||||
}
|
||||
|
||||
public double getPing() {
|
||||
return getDouble(VirtualServerProperty.VIRTUALSERVER_TOTAL_PING);
|
||||
}
|
||||
|
||||
public String getPlatform() {
|
||||
return get(VirtualServerProperty.VIRTUALSERVER_PLATFORM);
|
||||
}
|
||||
|
||||
public double getPrioritySpeakerDimmModificator() {
|
||||
return getDouble(VirtualServerProperty.VIRTUALSERVER_PRIORITY_SPEAKER_DIMM_MODIFICATOR);
|
||||
}
|
||||
|
||||
public int getReservedSlots() {
|
||||
return getInt(VirtualServerProperty.VIRTUALSERVER_RESERVED_SLOTS);
|
||||
}
|
||||
|
||||
public long getSpeechBytesReceived() {
|
||||
return getLong(VirtualServerProperty.CONNECTION_BYTES_RECEIVED_SPEECH);
|
||||
}
|
||||
|
||||
public long getSpeechBytesSent() {
|
||||
return getLong(VirtualServerProperty.CONNECTION_BYTES_SENT_SPEECH);
|
||||
}
|
||||
|
||||
public long getSpeechPacketsReceived() {
|
||||
return getLong(VirtualServerProperty.CONNECTION_PACKETS_RECEIVED_SPEECH);
|
||||
}
|
||||
|
||||
public long getSpeechPacketsSent() {
|
||||
return getLong(VirtualServerProperty.CONNECTION_PACKETS_SENT_SPEECH);
|
||||
}
|
||||
|
||||
public long getTotalBytesDownloaded() {
|
||||
return getLong(VirtualServerProperty.VIRTUALSERVER_TOTAL_BYTES_DOWNLOADED);
|
||||
}
|
||||
|
||||
public long getTotalBytesReceived() {
|
||||
return getLong(VirtualServerProperty.CONNECTION_BYTES_RECEIVED_TOTAL);
|
||||
}
|
||||
|
||||
public long getTotalBytesSent() {
|
||||
return getLong(VirtualServerProperty.CONNECTION_BYTES_SENT_TOTAL);
|
||||
}
|
||||
|
||||
public long getTotalBytesUploaded() {
|
||||
return getLong(VirtualServerProperty.VIRTUALSERVER_TOTAL_BYTES_UPLOADED);
|
||||
}
|
||||
|
||||
public int getTotalClientConnections() {
|
||||
return getInt(VirtualServerProperty.VIRTUALSERVER_CLIENT_CONNECTIONS);
|
||||
}
|
||||
|
||||
public double getTotalControlPacketloss() {
|
||||
return getDouble(VirtualServerProperty.VIRTUALSERVER_TOTAL_PACKETLOSS_CONTROL);
|
||||
}
|
||||
|
||||
public double getTotalKeepAlivePacketloss() {
|
||||
return getDouble(VirtualServerProperty.VIRTUALSERVER_TOTAL_PACKETLOSS_KEEPALIVE);
|
||||
}
|
||||
|
||||
public double getTotalPacketloss() {
|
||||
return getDouble(VirtualServerProperty.VIRTUALSERVER_TOTAL_PACKETLOSS_TOTAL);
|
||||
}
|
||||
|
||||
public long getTotalPacketsReceived() {
|
||||
return getLong(VirtualServerProperty.CONNECTION_PACKETS_RECEIVED_TOTAL);
|
||||
}
|
||||
|
||||
public long getTotalPacketsSent() {
|
||||
return getLong(VirtualServerProperty.CONNECTION_PACKETS_SENT_TOTAL);
|
||||
}
|
||||
|
||||
public int getTotalQueryClientConnections() {
|
||||
return getInt(VirtualServerProperty.VIRTUALSERVER_QUERY_CLIENT_CONNECTIONS);
|
||||
}
|
||||
|
||||
public double getTotalSpeechPacketloss() {
|
||||
return getDouble(VirtualServerProperty.VIRTUALSERVER_TOTAL_PACKETLOSS_SPEECH);
|
||||
}
|
||||
|
||||
public long getUploadQuota() {
|
||||
return getLong(VirtualServerProperty.VIRTUALSERVER_UPLOAD_QUOTA);
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return get(VirtualServerProperty.VIRTUALSERVER_VERSION);
|
||||
}
|
||||
|
||||
public String getWelcomeMessage() {
|
||||
return get(VirtualServerProperty.VIRTUALSERVER_WELCOMEMESSAGE);
|
||||
}
|
||||
|
||||
public boolean hasPassword() {
|
||||
return getBoolean(VirtualServerProperty.VIRTUALSERVER_FLAG_PASSWORD);
|
||||
}
|
||||
|
||||
public boolean isAskingPrivilegeKey() {
|
||||
return getBoolean(VirtualServerProperty.VIRTUALSERVER_ASK_FOR_PRIVILEGEKEY);
|
||||
}
|
||||
|
||||
public boolean isLoggingChannel() {
|
||||
return getBoolean(VirtualServerProperty.VIRTUALSERVER_LOG_CHANNEL);
|
||||
}
|
||||
|
||||
public boolean isLoggingClient() {
|
||||
return getBoolean(VirtualServerProperty.VIRTUALSERVER_LOG_CLIENT);
|
||||
}
|
||||
|
||||
public boolean isLoggingFileTransfer() {
|
||||
return getBoolean(VirtualServerProperty.VIRTUALSERVER_LOG_FILETRANSFER);
|
||||
}
|
||||
|
||||
public boolean isLoggingPermissions() {
|
||||
return getBoolean(VirtualServerProperty.VIRTUALSERVER_LOG_PERMISSIONS);
|
||||
}
|
||||
|
||||
public boolean isLoggingQuery() {
|
||||
return getBoolean(VirtualServerProperty.VIRTUALSERVER_LOG_QUERY);
|
||||
}
|
||||
|
||||
public boolean isLoggingServer() {
|
||||
return getBoolean(VirtualServerProperty.VIRTUALSERVER_LOG_SERVER);
|
||||
}
|
||||
|
||||
public boolean isWeblistEnabled() {
|
||||
return getBoolean(VirtualServerProperty.VIRTUALSERVER_WEBLIST_ENABLED);
|
||||
}
|
||||
}
|
217
src/com/github/theholywaffle/teamspeak3/api/wrapper/Wrapper.java
Normale Datei
217
src/com/github/theholywaffle/teamspeak3/api/wrapper/Wrapper.java
Normale Datei
@ -0,0 +1,217 @@
|
||||
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.Property;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A wrapper class around a {@link Map}.
|
||||
* <p>
|
||||
* We use wrapper classes instead of just passing around plain Maps because
|
||||
* </p><ul>
|
||||
* <li>it's more descriptive</li>
|
||||
* <li>there's no confusion between types (e.g. {@code Client} and {@code Channel})</li>
|
||||
* <li>we can create getters for the specific use-cases</li>
|
||||
* <li>we don't have to check for {@code null} each time</li>
|
||||
* </ul>
|
||||
*/
|
||||
public class Wrapper {
|
||||
|
||||
public static final Wrapper EMPTY = new Wrapper(Collections.<String, String>emptyMap());
|
||||
|
||||
private final Map<String, String> map;
|
||||
|
||||
/**
|
||||
* Creates a new wrapper around the given map.
|
||||
*
|
||||
* @param map
|
||||
* the Map to abstract, cannot be {@code null}
|
||||
*/
|
||||
public Wrapper(Map<String, String> map) {
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the map underlying this {@code Wrapper}.
|
||||
*
|
||||
* @return the underlying map
|
||||
*/
|
||||
public Map<String, String> getMap() {
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a property as a boolean from the underlying map.
|
||||
* Returns {@code true} if the property exists in the map and its value is {@code "1"}.
|
||||
*
|
||||
* @param propertyName
|
||||
* the name of the property
|
||||
*
|
||||
* @return the boolean value of the property or {@code false} if the property doesn't exist
|
||||
*/
|
||||
public boolean getBoolean(String propertyName) {
|
||||
return getInt(propertyName) == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a property as a boolean from the underlying map.
|
||||
* Returns {@code true} if the property exists in the map and its value is {@code "1"}.
|
||||
*
|
||||
* @param property
|
||||
* the property
|
||||
*
|
||||
* @return the boolean value of the property or {@code false} if the property doesn't exist
|
||||
*/
|
||||
public boolean getBoolean(Property property) {
|
||||
return getBoolean(property.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a property as a double from the underlying map.
|
||||
* If the property doesn't exist in the underlying map, {@code -1.0} is returned.
|
||||
*
|
||||
* @param propertyName
|
||||
* the name of the property
|
||||
*
|
||||
* @return the double value of the property or {@code -1.0} if the property doesn't exist
|
||||
*/
|
||||
public double getDouble(String propertyName) {
|
||||
final String value = get(propertyName);
|
||||
if (value == null || value.isEmpty()) {
|
||||
return -1D;
|
||||
}
|
||||
return Double.valueOf(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a property as a double from the underlying map.
|
||||
* If the property doesn't exist in the underlying map, {@code -1.0} is returned.
|
||||
*
|
||||
* @param property
|
||||
* the property
|
||||
*
|
||||
* @return the double value of the property or {@code -1.0} if the property doesn't exist
|
||||
*/
|
||||
public double getDouble(Property property) {
|
||||
return getDouble(property.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a property as a long from the underlying map.
|
||||
* If the property doesn't exist in the underlying map, {@code -1} is returned.
|
||||
*
|
||||
* @param propertyName
|
||||
* the name of the property
|
||||
*
|
||||
* @return the long value of the property or {@code -1} if the property doesn't exist
|
||||
*/
|
||||
public long getLong(String propertyName) {
|
||||
final String value = get(propertyName);
|
||||
if (value == null || value.isEmpty()) {
|
||||
return -1L;
|
||||
}
|
||||
return Long.parseLong(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a property as a long from the underlying map.
|
||||
* If the property doesn't exist in the underlying map, {@code -1} is returned.
|
||||
*
|
||||
* @param property
|
||||
* the property
|
||||
*
|
||||
* @return the long value of the property or {@code -1} if the property doesn't exist
|
||||
*/
|
||||
public long getLong(Property property) {
|
||||
return getLong(property.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a property as an integer from the underlying map.
|
||||
* If the property doesn't exist in the underlying map, {@code -1} is returned.
|
||||
*
|
||||
* @param propertyName
|
||||
* the name of the property
|
||||
*
|
||||
* @return the integer value of the property or {@code -1} if the property doesn't exist
|
||||
*/
|
||||
public int getInt(String propertyName) {
|
||||
final String value = get(propertyName);
|
||||
if (value == null || value.isEmpty()) {
|
||||
return -1;
|
||||
}
|
||||
return Integer.parseInt(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a property as an integer from the underlying map.
|
||||
* If the property doesn't exist in the underlying map, {@code -1} is returned.
|
||||
*
|
||||
* @param property
|
||||
* the property
|
||||
*
|
||||
* @return the integer value of the property or {@code -1} if the property doesn't exist
|
||||
*/
|
||||
public int getInt(Property property) {
|
||||
return getInt(property.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a property as a String from the underlying map.
|
||||
* If the property doesn't exist in the underlying map, an empty String is returned.
|
||||
*
|
||||
* @param propertyName
|
||||
* the name of the property
|
||||
*
|
||||
* @return the String value of the property or an empty String if the property doesn't exist
|
||||
*/
|
||||
public String get(String propertyName) {
|
||||
final String result = map.get(propertyName);
|
||||
return result != null ? result : "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a property as a {@code String} from the underlying map.
|
||||
* If the property doesn't exist in the underlying map, an empty String is returned.
|
||||
*
|
||||
* @param property
|
||||
* the property
|
||||
*
|
||||
* @return the String value of the property or an empty String if the property doesn't exist
|
||||
*/
|
||||
public String get(Property property) {
|
||||
return get(property.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return map.toString();
|
||||
}
|
||||
}
|
71
src/com/github/theholywaffle/teamspeak3/commands/BanCommands.java
Normale Datei
71
src/com/github/theholywaffle/teamspeak3/commands/BanCommands.java
Normale Datei
@ -0,0 +1,71 @@
|
||||
package com.github.theholywaffle.teamspeak3.commands;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* TeamSpeak 3 Java API
|
||||
* %%
|
||||
* Copyright (C) 2017 Bert De Geyter, Roger Baumgartner
|
||||
* %%
|
||||
* 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.commands.parameter.KeyValueParam;
|
||||
|
||||
public final class BanCommands {
|
||||
|
||||
private BanCommands() {
|
||||
throw new Error("No instances");
|
||||
}
|
||||
|
||||
public static Command banAdd(String ip, String name, String uid, String myTSId, long timeInSeconds, String reason) {
|
||||
if (ip == null && name == null && uid == null) {
|
||||
throw new IllegalArgumentException("Either IP, name or UId must be non-null");
|
||||
}
|
||||
|
||||
CommandBuilder builder = new CommandBuilder("banadd", 6);
|
||||
builder.addIf(ip != null, new KeyValueParam("ip", ip));
|
||||
builder.addIf(name != null, new KeyValueParam("name", name));
|
||||
builder.addIf(uid != null, new KeyValueParam("uid", uid));
|
||||
builder.addIf(myTSId != null, new KeyValueParam("mytsid", myTSId));
|
||||
builder.addIf(timeInSeconds > 0, new KeyValueParam("time", timeInSeconds));
|
||||
builder.addIf(reason != null, new KeyValueParam("banreason", reason));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public static Command banClient(int clientId, long timeInSeconds, String reason) {
|
||||
CommandBuilder builder = new CommandBuilder("banclient", 3);
|
||||
builder.add(new KeyValueParam("clid", clientId));
|
||||
builder.addIf(timeInSeconds > 0, new KeyValueParam("time", timeInSeconds));
|
||||
builder.addIf(reason != null, new KeyValueParam("banreason", reason));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public static Command banDel(int banId) {
|
||||
return new CommandBuilder("bandel", 1).add(new KeyValueParam("banid", banId)).build();
|
||||
}
|
||||
|
||||
public static Command banDelAll() {
|
||||
return new CommandBuilder("bandelall").build();
|
||||
}
|
||||
|
||||
public static Command banList() {
|
||||
return new CommandBuilder("banlist").build();
|
||||
}
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
package com.github.theholywaffle.teamspeak3.commands;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* TeamSpeak 3 Java API
|
||||
* %%
|
||||
* Copyright (C) 2017 Bert De Geyter, Roger Baumgartner
|
||||
* %%
|
||||
* 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.ChannelProperty;
|
||||
import com.github.theholywaffle.teamspeak3.commands.parameter.KeyValueParam;
|
||||
import com.github.theholywaffle.teamspeak3.commands.parameter.OptionParam;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public final class ChannelCommands {
|
||||
|
||||
private ChannelCommands() {
|
||||
throw new Error("No instances");
|
||||
}
|
||||
|
||||
public static Command channelCreate(String name, Map<ChannelProperty, String> options) {
|
||||
if (name == null || name.isEmpty()) {
|
||||
throw new IllegalArgumentException("Channel name must be a non-empty string");
|
||||
}
|
||||
|
||||
CommandBuilder builder = new CommandBuilder("channelcreate", 2);
|
||||
builder.add(new KeyValueParam("channel_name", name));
|
||||
builder.addProperties(options);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public static Command channelDelete(int channelId, boolean force) {
|
||||
CommandBuilder builder = new CommandBuilder("channeldelete", 2);
|
||||
builder.add(new KeyValueParam("cid", channelId));
|
||||
builder.add(new KeyValueParam("force", force));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public static Command channelEdit(int channelId, Map<ChannelProperty, String> options) {
|
||||
CommandBuilder builder = new CommandBuilder("channeledit", 2);
|
||||
builder.add(new KeyValueParam("cid", channelId));
|
||||
builder.addProperties(options);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public static Command channelFind(String pattern) {
|
||||
if (pattern == null || pattern.isEmpty()) {
|
||||
throw new IllegalArgumentException("Channel name pattern must be a non-empty string");
|
||||
}
|
||||
|
||||
return new CommandBuilder("channelfind", 1).add(new KeyValueParam("pattern", pattern)).build();
|
||||
}
|
||||
|
||||
public static Command channelInfo(int channelId) {
|
||||
return new CommandBuilder("channelinfo", 1).add(new KeyValueParam("cid", channelId)).build();
|
||||
}
|
||||
|
||||
public static Command channelList() {
|
||||
CommandBuilder builder = new CommandBuilder("channellist", 6);
|
||||
builder.add(new OptionParam("topic"));
|
||||
builder.add(new OptionParam("flags"));
|
||||
builder.add(new OptionParam("voice"));
|
||||
builder.add(new OptionParam("limits"));
|
||||
builder.add(new OptionParam("icon"));
|
||||
builder.add(new OptionParam("secondsempty"));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public static Command channelMove(int channelId, int channelParentId, int order) {
|
||||
CommandBuilder builder = new CommandBuilder("channelmove", 3);
|
||||
builder.add(new KeyValueParam("cid", channelId));
|
||||
builder.add(new KeyValueParam("cpid", channelParentId));
|
||||
builder.add(new KeyValueParam("order", order < 0 ? 0 : order));
|
||||
return builder.build();
|
||||
}
|
||||
}
|
@ -0,0 +1,112 @@
|
||||
package com.github.theholywaffle.teamspeak3.commands;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* TeamSpeak 3 Java API
|
||||
* %%
|
||||
* Copyright (C) 2017 Bert De Geyter, Roger Baumgartner
|
||||
* %%
|
||||
* 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.PermissionGroupDatabaseType;
|
||||
import com.github.theholywaffle.teamspeak3.commands.parameter.KeyValueParam;
|
||||
|
||||
public final class ChannelGroupCommands {
|
||||
|
||||
private ChannelGroupCommands() {
|
||||
throw new Error("No instances");
|
||||
}
|
||||
|
||||
public static Command channelGroupAdd(String groupName, PermissionGroupDatabaseType type) {
|
||||
if (groupName == null || groupName.isEmpty()) {
|
||||
throw new IllegalArgumentException("Channel group name must be a non-empty string");
|
||||
}
|
||||
|
||||
CommandBuilder builder = new CommandBuilder("channelgroupadd", 2);
|
||||
builder.add(new KeyValueParam("name", groupName));
|
||||
if (type != null) {
|
||||
builder.add(new KeyValueParam("type", type.getIndex()));
|
||||
}
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public static Command channelGroupClientList(int channelId, int clientDBId, int groupId) {
|
||||
CommandBuilder builder = new CommandBuilder("channelgroupclientlist", 3);
|
||||
builder.addIf(channelId > 0, new KeyValueParam("cid", channelId));
|
||||
builder.addIf(clientDBId > 0, new KeyValueParam("cldbid", clientDBId));
|
||||
builder.addIf(groupId > 0, new KeyValueParam("cgid", groupId));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public static Command channelGroupCopy(int sourceGroupId, int targetGroupId, PermissionGroupDatabaseType type) {
|
||||
return channelGroupCopy(sourceGroupId, targetGroupId, "name", type);
|
||||
}
|
||||
|
||||
public static Command channelGroupCopy(int sourceGroupId, String groupName, PermissionGroupDatabaseType type) {
|
||||
return channelGroupCopy(sourceGroupId, 0, groupName, type);
|
||||
}
|
||||
|
||||
private static Command channelGroupCopy(int sourceGroupId, int targetGroupId, String groupName, PermissionGroupDatabaseType type) {
|
||||
if (type == null) {
|
||||
throw new IllegalArgumentException("Group type cannot be null");
|
||||
}
|
||||
if (groupName == null || groupName.isEmpty()) {
|
||||
throw new IllegalArgumentException("Channel group name must be a non-empty string");
|
||||
}
|
||||
|
||||
CommandBuilder builder = new CommandBuilder("channelgroupcopy", 4);
|
||||
builder.add(new KeyValueParam("scgid", sourceGroupId));
|
||||
builder.add(new KeyValueParam("tcgid", targetGroupId));
|
||||
builder.add(new KeyValueParam("name", groupName));
|
||||
builder.add(new KeyValueParam("type", type.getIndex()));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public static Command channelGroupDel(int channelGroupId, boolean forced) {
|
||||
CommandBuilder builder = new CommandBuilder("channelgroupdel", 2);
|
||||
builder.add(new KeyValueParam("cgid", channelGroupId));
|
||||
builder.add(new KeyValueParam("force", forced));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public static Command channelGroupList() {
|
||||
return new CommandBuilder("channelgrouplist").build();
|
||||
}
|
||||
|
||||
public static Command channelGroupRename(int groupId, String groupName) {
|
||||
if (groupName == null || groupName.isEmpty()) {
|
||||
throw new IllegalArgumentException("Channel group name must be a non-empty string");
|
||||
}
|
||||
|
||||
CommandBuilder builder = new CommandBuilder("channelgrouprename", 2);
|
||||
builder.add(new KeyValueParam("cgid", groupId));
|
||||
builder.add(new KeyValueParam("name", groupName));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public static Command setClientChannelGroup(int groupId, int channelId, int clientDBId) {
|
||||
CommandBuilder builder = new CommandBuilder("setclientchannelgroup", 3);
|
||||
builder.add(new KeyValueParam("cgid", groupId));
|
||||
builder.add(new KeyValueParam("cid", channelId));
|
||||
builder.add(new KeyValueParam("cldbid", clientDBId));
|
||||
return builder.build();
|
||||
}
|
||||
}
|
161
src/com/github/theholywaffle/teamspeak3/commands/ClientCommands.java
Normale Datei
161
src/com/github/theholywaffle/teamspeak3/commands/ClientCommands.java
Normale Datei
@ -0,0 +1,161 @@
|
||||
package com.github.theholywaffle.teamspeak3.commands;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* TeamSpeak 3 Java API
|
||||
* %%
|
||||
* Copyright (C) 2017 Bert De Geyter, Roger Baumgartner
|
||||
* %%
|
||||
* 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 com.github.theholywaffle.teamspeak3.api.ReasonIdentifier;
|
||||
import com.github.theholywaffle.teamspeak3.commands.parameter.ArrayParameter;
|
||||
import com.github.theholywaffle.teamspeak3.commands.parameter.KeyValueParam;
|
||||
import com.github.theholywaffle.teamspeak3.commands.parameter.OptionParam;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public final class ClientCommands {
|
||||
|
||||
private ClientCommands() {
|
||||
throw new Error("No instances");
|
||||
}
|
||||
|
||||
public static Command clientEdit(int clientId, Map<ClientProperty, String> options) {
|
||||
CommandBuilder builder = new CommandBuilder("clientedit", 2);
|
||||
builder.add(new KeyValueParam("clid", clientId));
|
||||
builder.addProperties(options);
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public static Command clientFind(String pattern) {
|
||||
if (pattern == null || pattern.isEmpty()) {
|
||||
throw new IllegalArgumentException("Client name pattern must be a non-empty string");
|
||||
}
|
||||
|
||||
return new CommandBuilder("clientfind", 1).add(new KeyValueParam("pattern", pattern)).build();
|
||||
}
|
||||
|
||||
public static Command clientGetDBIdFromUId(String clientUId) {
|
||||
if (clientUId == null || clientUId.isEmpty()) {
|
||||
throw new IllegalArgumentException("Client UId must be a non-empty string");
|
||||
}
|
||||
|
||||
return new CommandBuilder("clientgetdbidfromuid", 1).add(new KeyValueParam("cluid", clientUId)).build();
|
||||
}
|
||||
|
||||
public static Command clientGetIds(String clientUId) {
|
||||
if (clientUId == null || clientUId.isEmpty()) {
|
||||
throw new IllegalArgumentException("Client UId must be a non-empty string");
|
||||
}
|
||||
|
||||
return new CommandBuilder("clientgetids", 1).add(new KeyValueParam("cluid", clientUId)).build();
|
||||
}
|
||||
|
||||
public static Command clientInfo(int clientId) {
|
||||
return new CommandBuilder("clientinfo", 1).add(new KeyValueParam("clid", clientId)).build();
|
||||
}
|
||||
|
||||
public static Command clientKick(ReasonIdentifier reason, String reasonMessage, int... clientIds) {
|
||||
if (clientIds == null || clientIds.length == 0) {
|
||||
throw new IllegalArgumentException("Client ID array cannot be null or empty");
|
||||
}
|
||||
|
||||
CommandBuilder builder = new CommandBuilder("clientkick", 3);
|
||||
builder.add(new KeyValueParam("reasonid", reason.getIndex()));
|
||||
builder.addIf(reasonMessage != null, new KeyValueParam("reasonmsg", reasonMessage));
|
||||
|
||||
ArrayParameter clients = new ArrayParameter(clientIds.length);
|
||||
for (final int id : clientIds) {
|
||||
clients.add(new KeyValueParam("clid", id));
|
||||
}
|
||||
builder.add(clients);
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public static Command clientList() {
|
||||
CommandBuilder builder = new CommandBuilder("clientlist", 10);
|
||||
builder.add(new OptionParam("uid"));
|
||||
builder.add(new OptionParam("away"));
|
||||
builder.add(new OptionParam("voice"));
|
||||
builder.add(new OptionParam("times"));
|
||||
builder.add(new OptionParam("groups"));
|
||||
builder.add(new OptionParam("info"));
|
||||
builder.add(new OptionParam("icon"));
|
||||
builder.add(new OptionParam("country"));
|
||||
builder.add(new OptionParam("ip"));
|
||||
builder.add(new OptionParam("badges"));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public static Command clientMove(int clientId, int channelId, String channelPassword) {
|
||||
CommandBuilder builder = new CommandBuilder("clientmove", 3);
|
||||
builder.add(new KeyValueParam("clid", clientId));
|
||||
builder.add(new KeyValueParam("cid", channelId));
|
||||
builder.addIf(channelPassword != null, new KeyValueParam("cpw", channelPassword));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public static Command clientMove(int[] clientIds, int channelId, String channelPassword) {
|
||||
if (clientIds == null || clientIds.length == 0) {
|
||||
throw new IllegalArgumentException("Client ID array cannot be null or empty");
|
||||
}
|
||||
|
||||
CommandBuilder builder = new CommandBuilder("clientmove", 3);
|
||||
builder.add(new KeyValueParam("cid", channelId));
|
||||
builder.addIf(channelPassword != null, new KeyValueParam("cpw", channelPassword));
|
||||
|
||||
ArrayParameter clients = new ArrayParameter(clientIds.length);
|
||||
for (final int clientId : clientIds) {
|
||||
clients.add(new KeyValueParam("clid", clientId));
|
||||
}
|
||||
builder.add(clients);
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public static Command clientPoke(int clientId, String message) {
|
||||
CommandBuilder builder = new CommandBuilder("clientpoke", 2);
|
||||
builder.add(new KeyValueParam("clid", clientId));
|
||||
builder.add(new KeyValueParam("msg", message));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public static Command clientSetServerQueryLogin(String username) {
|
||||
CommandBuilder builder = new CommandBuilder("clientsetserverquerylogin", 1);
|
||||
builder.add(new KeyValueParam("client_login_name", username));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public static Command clientUpdate(Map<ClientProperty, String> options) {
|
||||
return new CommandBuilder("clientupdate", 1).addProperties(options).build();
|
||||
}
|
||||
|
||||
public static Command sendTextMessage(int targetMode, int targetId, String message) {
|
||||
CommandBuilder builder = new CommandBuilder("sendtextmessage", 3);
|
||||
builder.add(new KeyValueParam("targetmode", targetMode));
|
||||
builder.add(new KeyValueParam("target", targetId));
|
||||
builder.add(new KeyValueParam("msg", message));
|
||||
return builder.build();
|
||||
}
|
||||
}
|
64
src/com/github/theholywaffle/teamspeak3/commands/Command.java
Normale Datei
64
src/com/github/theholywaffle/teamspeak3/commands/Command.java
Normale Datei
@ -0,0 +1,64 @@
|
||||
package com.github.theholywaffle.teamspeak3.commands;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* TeamSpeak 3 Java API
|
||||
* %%
|
||||
* Copyright (C) 2017 Bert De Geyter, Roger Baumgartner
|
||||
* %%
|
||||
* 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.CommandFuture;
|
||||
import com.github.theholywaffle.teamspeak3.commands.parameter.Parameter;
|
||||
import com.github.theholywaffle.teamspeak3.commands.response.DefaultArrayResponse;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class Command {
|
||||
|
||||
private final String name;
|
||||
private final Collection<Parameter> parameters;
|
||||
private final CommandFuture<DefaultArrayResponse> future;
|
||||
|
||||
Command(String commandName, Collection<Parameter> parameters) {
|
||||
this.name = commandName;
|
||||
this.parameters = parameters;
|
||||
this.future = new CommandFuture<>();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public CommandFuture<DefaultArrayResponse> getFuture() {
|
||||
return future;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder(name);
|
||||
for (Parameter param : parameters) {
|
||||
builder.append(' ');
|
||||
param.appendTo(builder);
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
89
src/com/github/theholywaffle/teamspeak3/commands/CommandBuilder.java
Normale Datei
89
src/com/github/theholywaffle/teamspeak3/commands/CommandBuilder.java
Normale Datei
@ -0,0 +1,89 @@
|
||||
package com.github.theholywaffle.teamspeak3.commands;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* TeamSpeak 3 Java API
|
||||
* %%
|
||||
* Copyright (C) 2017 Bert De Geyter, Roger Baumgartner
|
||||
* %%
|
||||
* 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.Property;
|
||||
import com.github.theholywaffle.teamspeak3.commands.parameter.ArrayParameter;
|
||||
import com.github.theholywaffle.teamspeak3.commands.parameter.KeyValueParam;
|
||||
import com.github.theholywaffle.teamspeak3.commands.parameter.Parameter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
final class CommandBuilder {
|
||||
|
||||
private final String commandName;
|
||||
private final Collection<Parameter> parameters;
|
||||
|
||||
public CommandBuilder(String commandName) {
|
||||
this(commandName, 0);
|
||||
}
|
||||
|
||||
public CommandBuilder(String commandName, int expectedParamCount) {
|
||||
this.commandName = commandName;
|
||||
this.parameters = new ArrayList<>(expectedParamCount);
|
||||
}
|
||||
|
||||
public CommandBuilder add(Parameter parameter) {
|
||||
parameters.add(parameter);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandBuilder addIf(boolean test, Parameter parameter) {
|
||||
if (test) {
|
||||
parameters.add(parameter);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandBuilder addProperties(Map<? extends Property, String> properties) {
|
||||
if (properties == null || properties.isEmpty()) return this;
|
||||
|
||||
ArrayParameter parameter = new ArrayParameter(1, properties.size());
|
||||
for (Map.Entry<? extends Property, String> entry : properties.entrySet()) {
|
||||
Property property = entry.getKey();
|
||||
String value = entry.getValue();
|
||||
|
||||
if (property == null) {
|
||||
throw new IllegalArgumentException("Property cannot be null");
|
||||
} else if (!property.isChangeable()) {
|
||||
String className = property.getClass().getSimpleName();
|
||||
throw new IllegalArgumentException(className + " " + property.getName() + " is not changeable");
|
||||
}
|
||||
|
||||
parameter.add(new KeyValueParam(property.getName(), value));
|
||||
}
|
||||
parameters.add(parameter);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public Command build() {
|
||||
return new Command(commandName, parameters);
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
package com.github.theholywaffle.teamspeak3.commands;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* TeamSpeak 3 Java API
|
||||
* %%
|
||||
* Copyright (C) 2015 Bert De Geyter, Roger Baumgartner
|
||||
* %%
|
||||
* 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%
|
||||
*/
|
||||
|
||||
public final class CommandEncoding {
|
||||
|
||||
private CommandEncoding() {}
|
||||
|
||||
public static String encode(String str) {
|
||||
str = str.replace("\\", "\\\\");
|
||||
|
||||
str = str.replace(" ", "\\s");
|
||||
str = str.replace("/", "\\/");
|
||||
str = str.replace("|", "\\p");
|
||||
str = str.replace("\b", "\\b");
|
||||
str = str.replace("\f", "\\f");
|
||||
str = str.replace("\n", "\\n");
|
||||
str = str.replace("\r", "\\r");
|
||||
str = str.replace("\t", "\\t");
|
||||
str = str.replace(String.valueOf((char) 7), "\\a");
|
||||
str = str.replace(String.valueOf((char) 11), "\\v");
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
public static String decode(String str) {
|
||||
str = str.replace("\\s", " ");
|
||||
str = str.replace("\\/", "/");
|
||||
str = str.replace("\\p", "|");
|
||||
str = str.replace("\\b", "\b");
|
||||
str = str.replace("\\f", "\f");
|
||||
str = str.replace("\\n", "\n");
|
||||
str = str.replace("\\r", "\r");
|
||||
str = str.replace("\\t", "\t");
|
||||
str = str.replace("\\a", String.valueOf((char) 7)); // Bell
|
||||
str = str.replace("\\v", String.valueOf((char) 11)); // Vertical Tab
|
||||
|
||||
str = str.replace("\\\\", "\\");
|
||||
|
||||
return str;
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
package com.github.theholywaffle.teamspeak3.commands;
|
||||
|
||||
/*
|
||||
* #%L
|
||||
* TeamSpeak 3 Java API
|
||||
* %%
|
||||
* Copyright (C) 2017 Bert De Geyter, Roger Baumgartner
|
||||
* %%
|
||||
* 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.commands.parameter.KeyValueParam;
|
||||
|
||||
public final class ComplaintCommands {
|
||||
|
||||
private ComplaintCommands() {
|
||||
throw new Error("No instances");
|
||||
}
|
||||
|
||||
public static Command complainAdd(int clientDBId, String message) {
|
||||
CommandBuilder builder = new CommandBuilder("complainadd", 2);
|
||||
builder.add(new KeyValueParam("tcldbid", clientDBId));
|
||||
builder.add(new KeyValueParam("message", message));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public static Command complainDel(int clientDBId, int fromClientDBId) {
|
||||
CommandBuilder builder = new CommandBuilder("complaindel", 2);
|
||||
builder.add(new KeyValueParam("tcldbid", clientDBId));
|
||||
builder.add(new KeyValueParam("fcldbid", fromClientDBId));
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public static Command complainDelAll(int clientDBId) {
|
||||
return new CommandBuilder("complaindelall", 1).add(new KeyValueParam("tcldbid", clientDBId)).build();
|
||||
}
|
||||
|
||||
public static Command complainList(int clientDBId) {
|
||||
return new CommandBuilder("complainlist", 1).addIf(clientDBId > 0, new KeyValueParam("tcldbid", clientDBId)).build();
|
||||
}
|
||||
}
|
Einige Dateien werden nicht angezeigt, da zu viele Dateien in diesem Diff geändert wurden Mehr anzeigen
In neuem Issue referenzieren
Einen Benutzer sperren