001package com.github.theholywaffle.teamspeak3.commands;
002
003/*
004 * #%L
005 * TeamSpeak 3 Java API
006 * %%
007 * Copyright (C) 2017 Bert De Geyter, Roger Baumgartner
008 * %%
009 * Permission is hereby granted, free of charge, to any person obtaining a copy
010 * of this software and associated documentation files (the "Software"), to deal
011 * in the Software without restriction, including without limitation the rights
012 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
013 * copies of the Software, and to permit persons to whom the Software is
014 * furnished to do so, subject to the following conditions:
015 * 
016 * The above copyright notice and this permission notice shall be included in
017 * all copies or substantial portions of the Software.
018 * 
019 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
020 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
021 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
022 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
023 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
024 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
025 * THE SOFTWARE.
026 * #L%
027 */
028
029import com.github.theholywaffle.teamspeak3.api.event.TS3EventType;
030import com.github.theholywaffle.teamspeak3.commands.parameter.KeyValueParam;
031import com.github.theholywaffle.teamspeak3.commands.parameter.OptionParam;
032import com.github.theholywaffle.teamspeak3.commands.parameter.ValueParam;
033
034public final class QueryCommands {
035
036        private QueryCommands() {
037                throw new Error("No instances");
038        }
039
040        public static Command logIn(String username, String password) {
041                if (username == null || username.isEmpty()) {
042                        throw new IllegalArgumentException("Username must be a non-empty string");
043                }
044                if (password == null || password.isEmpty()) {
045                        throw new IllegalArgumentException("Password must be a non-empty string");
046                }
047
048                return new CommandBuilder("login", 2).add(new ValueParam(username)).add(new ValueParam(password)).build();
049        }
050
051        public static Command logOut() {
052                return new CommandBuilder("logout").build();
053        }
054
055        public static Command quit() {
056                return new CommandBuilder("quit").build();
057        }
058
059        public static Command serverNotifyRegister(TS3EventType eventType, int channelId) {
060                if (eventType == null) {
061                        throw new IllegalArgumentException("Event type cannot be null");
062                }
063
064                CommandBuilder builder = new CommandBuilder("servernotifyregister", 2);
065                builder.add(new KeyValueParam("event", eventType.toString()));
066                builder.addIf(channelId >= 0, new KeyValueParam("id", channelId));
067                return builder.build();
068        }
069
070        public static Command serverNotifyUnregister() {
071                return new CommandBuilder("servernotifyunregister").build();
072        }
073
074        public static Command useId(int id, String nickname) {
075                CommandBuilder builder = new CommandBuilder("use", 3);
076                builder.add(new KeyValueParam("sid", id));
077                builder.add(new OptionParam("virtual"));
078                builder.addIf(nickname != null, new KeyValueParam("client_nickname", nickname));
079                return builder.build();
080        }
081
082        public static Command usePort(int port, String nickname) {
083                CommandBuilder builder = new CommandBuilder("use", 3);
084                builder.add(new KeyValueParam("port", port));
085                builder.add(new OptionParam("virtual"));
086                builder.addIf(nickname != null, new KeyValueParam("client_nickname", nickname));
087                return builder.build();
088        }
089
090        public static Command whoAmI() {
091                return new CommandBuilder("whoami").build();
092        }
093}