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.VirtualServerProperty;
030import com.github.theholywaffle.teamspeak3.commands.parameter.KeyValueParam;
031import com.github.theholywaffle.teamspeak3.commands.parameter.OptionParam;
032import com.github.theholywaffle.teamspeak3.commands.parameter.RawParam;
033
034import java.util.Map;
035
036public final class VirtualServerCommands {
037
038        private VirtualServerCommands() {
039                throw new Error("No instances");
040        }
041
042        public static Command serverCreate(String name, Map<VirtualServerProperty, String> options) {
043                if (name == null || name.isEmpty()) {
044                        throw new IllegalArgumentException("Server name must be a non-empty string");
045                }
046
047                CommandBuilder builder = new CommandBuilder("servercreate", 2);
048                builder.add(new KeyValueParam(VirtualServerProperty.VIRTUALSERVER_NAME.getName(), name));
049                builder.addProperties(options);
050                return builder.build();
051        }
052
053        public static Command serverDelete(int id) {
054                return new CommandBuilder("serverdelete", 1).add(new KeyValueParam("sid", id)).build();
055        }
056
057        public static Command serverEdit(Map<VirtualServerProperty, String> options) {
058                return new CommandBuilder("serveredit", 1).addProperties(options).build();
059        }
060
061        public static Command serverIdGetByPort(int port) {
062                return new CommandBuilder("serveridgetbyport", 1).add(new KeyValueParam("virtualserver_port", port)).build();
063        }
064
065        public static Command serverInfo() {
066                return new CommandBuilder("serverinfo").build();
067        }
068
069        public static Command serverList() {
070                CommandBuilder builder = new CommandBuilder("serverlist", 2);
071                builder.add(new OptionParam("uid"));
072                builder.add(new OptionParam("all"));
073                return builder.build();
074        }
075
076        public static Command serverRequestConnectionInfo() {
077                return new CommandBuilder("serverrequestconnectioninfo").build();
078        }
079
080        public static Command serverSnapshotCreate() {
081                return new CommandBuilder("serversnapshotcreate").build();
082        }
083
084        public static Command serverSnapshotDeploy(String snapshot) {
085                if (snapshot == null || snapshot.isEmpty()) {
086                        throw new IllegalArgumentException("Server snapshot must be a non-empty string");
087                }
088
089                return new CommandBuilder("serversnapshotdeploy", 1).add(new RawParam(snapshot)).build();
090        }
091
092        public static Command serverStart(int id) {
093                return new CommandBuilder("serverstart", 1).add(new KeyValueParam("sid", id)).build();
094        }
095
096        public static Command serverStop(int id, String reason) {
097                CommandBuilder builder = new CommandBuilder("serverstop", 2);
098                builder.add(new KeyValueParam("sid", id));
099                builder.addIf(reason != null, new KeyValueParam("reasonmsg", reason));
100                return builder.build();
101        }
102}