use of de.dytanic.cloudnet.lib.server.ProxyGroup in project CloudNet by Dytanic.
the class CommandCreate method onExecuteCommand.
@Override
public void onExecuteCommand(CommandSender sender, String[] args) {
if (args.length > 2) {
if (args[0].equalsIgnoreCase("dispatchCommand")) {
// create dispatchCommand name create
StringBuilder builder = new StringBuilder();
for (short i = 2; i < args.length; i++) {
builder.append(args[i]);
}
CloudNet.getInstance().getDbHandlers().getCommandDispatcherDatabase().appendCommand(args[1], builder.substring(0, (builder.substring(0).endsWith(" ") ? builder.length() - 1 : builder.length())));
sender.sendMessage("A dispatcher was created \"" + args[1] + "\": \"" + builder.substring(0) + "\"");
return;
}
}
switch(args.length) {
case 2:
if (args[0].equalsIgnoreCase("proxy") || args[0].equalsIgnoreCase("-p")) {
if (CloudNet.getInstance().getProxyGroups().containsKey(args[1])) {
CloudNet.getInstance().startProxy(CloudNet.getInstance().getProxyGroups().get(args[1]));
sender.sendMessage("Trying to startup a proxy server...");
} else {
sender.sendMessage("The proxy group doesn't exist");
}
return;
}
if (args[0].equalsIgnoreCase("server") || args[0].equalsIgnoreCase("-s")) {
if (CloudNet.getInstance().getServerGroups().containsKey(args[1])) {
CloudNet.getInstance().startGameServer(CloudNet.getInstance().getServerGroups().get(args[1]));
sender.sendMessage("Trying to startup a game server...");
} else {
sender.sendMessage("The server group doesn't exists");
}
return;
}
if (args[0].equalsIgnoreCase("wrapper") && !CloudNet.getInstance().getWrappers().containsKey(args[1])) {
new SetupWrapper(sender, args[1]);
return;
}
if (args[0].equalsIgnoreCase("serverGroup")) {
new SetupServerGroup(sender, args[1]);
return;
}
if (args[0].equalsIgnoreCase("proxyGroup")) {
new SetupProxyGroup(sender, args[1]);
return;
}
break;
case 3:
if ((args[0].equalsIgnoreCase("proxy") || args[0].equalsIgnoreCase("-p")) && NetworkUtils.checkIsNumber(args[2])) {
if (CloudNet.getInstance().getProxyGroups().containsKey(args[1])) {
for (short i = 0; i < Integer.parseInt(args[2]); i++) {
CloudNet.getInstance().startProxy(CloudNet.getInstance().getProxyGroups().get(args[1]));
NetworkUtils.sleepUninterruptedly(2000L);
}
sender.sendMessage("Trying to startup a proxy server...");
} else {
sender.sendMessage("The proxy group doesn't exists");
}
return;
}
if ((args[0].equalsIgnoreCase("server") || args[0].equalsIgnoreCase("-s")) && NetworkUtils.checkIsNumber(args[2])) {
if (CloudNet.getInstance().getServerGroups().containsKey(args[1])) {
for (short i = 0; i < Integer.parseInt(args[2]); i++) {
CloudNet.getInstance().startGameServer(CloudNet.getInstance().getServerGroups().get(args[1]));
NetworkUtils.sleepUninterruptedly(2000L);
}
sender.sendMessage("Trying to startup a game server...");
} else {
sender.sendMessage("The server group doesn't exists");
}
return;
}
if (args[0].equalsIgnoreCase("user")) {
if (!CloudNet.getInstance().getUsers().contains(args[1])) {
User user = new BasicUser(args[1], args[2], Arrays.asList());
CloudNet.getInstance().getUsers().add(user);
CloudNet.getInstance().getConfig().save(CloudNet.getInstance().getUsers());
sender.sendMessage("The user was created!");
} else {
sender.sendMessage("The user already exists!");
}
}
break;
case 4:
if (args[0].equalsIgnoreCase("cloudserver") || args[0].equalsIgnoreCase("cs")) {
if (NetworkUtils.checkIsNumber(args[2])) {
CloudNet.getInstance().startCloudServer(args[1], Integer.parseInt(args[2]), args[3].equalsIgnoreCase("true"));
sender.sendMessage("Trying to startup a cloud server...");
} else {
sender.sendMessage("Invalid argument!");
}
return;
}
if (args[0].equalsIgnoreCase("TEMPLATE")) {
if (CloudNet.getInstance().getServerGroups().containsKey(args[2])) {
if (args[3].equalsIgnoreCase("LOCAL")) {
ServerGroup serverGroup = CloudNet.getInstance().getServerGroups().get(args[2]);
serverGroup.getTemplates().add(new Template(args[1], TemplateResource.LOCAL, null, new String[] {}, Arrays.asList()));
CloudNet.getInstance().getConfig().createGroup(serverGroup);
NetworkUtils.addAll(CloudNet.getInstance().getServerGroups(), CloudNet.getInstance().getConfig().getServerGroups(), new Acceptable<ServerGroup>() {
@Override
public boolean isAccepted(ServerGroup value) {
return true;
}
});
NetworkUtils.addAll(CloudNet.getInstance().getProxyGroups(), CloudNet.getInstance().getConfig().getProxyGroups(), new Acceptable<ProxyGroup>() {
@Override
public boolean isAccepted(ProxyGroup value) {
return true;
}
});
CloudNet.getInstance().getWrappers().values().forEach(new Consumer<Wrapper>() {
@Override
public void accept(Wrapper wrapper) {
wrapper.updateWrapper();
}
});
sender.sendMessage("The template was created and all wrappers were updated!");
}
if (args[3].equalsIgnoreCase("MASTER")) {
ServerGroup serverGroup = CloudNet.getInstance().getServerGroups().get(args[2]);
serverGroup.getTemplates().add(new Template(args[1], TemplateResource.MASTER, null, new String[] {}, Arrays.asList()));
CloudNet.getInstance().getConfig().createGroup(serverGroup);
NetworkUtils.addAll(CloudNet.getInstance().getServerGroups(), CloudNet.getInstance().getConfig().getServerGroups(), new Acceptable<ServerGroup>() {
@Override
public boolean isAccepted(ServerGroup value) {
return true;
}
});
NetworkUtils.addAll(CloudNet.getInstance().getProxyGroups(), CloudNet.getInstance().getConfig().getProxyGroups(), new Acceptable<ProxyGroup>() {
@Override
public boolean isAccepted(ProxyGroup value) {
return true;
}
});
CloudNet.getInstance().getWrappers().values().forEach(new Consumer<Wrapper>() {
@Override
public void accept(Wrapper wrapper) {
wrapper.updateWrapper();
}
});
sender.sendMessage("The template was created and all wrappers were updated!");
}
} else {
sender.sendMessage("The server group doesn't exist");
}
}
break;
case 5:
if (args[0].equalsIgnoreCase("TEMPLATE")) {
if (CloudNet.getInstance().getServerGroups().containsKey(args[2])) {
if (args[3].equalsIgnoreCase("URL")) {
ServerGroup serverGroup = CloudNet.getInstance().getServerGroups().get(args[2]);
serverGroup.getTemplates().add(new Template(args[1], TemplateResource.URL, args[4], new String[] { ("-Dtest=true") }, Arrays.asList()));
CloudNet.getInstance().getConfig().createGroup(serverGroup);
NetworkUtils.addAll(CloudNet.getInstance().getServerGroups(), CloudNet.getInstance().getConfig().getServerGroups(), new Acceptable<ServerGroup>() {
@Override
public boolean isAccepted(ServerGroup value) {
return true;
}
});
NetworkUtils.addAll(CloudNet.getInstance().getProxyGroups(), CloudNet.getInstance().getConfig().getProxyGroups(), new Acceptable<ProxyGroup>() {
@Override
public boolean isAccepted(ProxyGroup value) {
return true;
}
});
CloudNet.getInstance().getWrappers().values().forEach(new Consumer<Wrapper>() {
@Override
public void accept(Wrapper wrapper) {
wrapper.updateWrapper();
}
});
sender.sendMessage("The template was created and all wrappers were updated!");
}
} else {
sender.sendMessage("The server group doesn't exists");
}
}
break;
default:
sender.sendMessage("create PROXY <proxyGroup> <count> | Creates a proxy server of a proxy group. <count> is not mandatory", "create SERVER <serverGroup> <count> | Creates a game server of a server group. <count> is not mandatory", "create CLOUDSERVER <name> <memory> <priorityStop>", "create USER <name> <password> | Creates a new user with specified name and password", "create PROXYGROUP <name> | Creates a completely new proxy group for BungeeCord with its own configurations, etc.", "create SERVERGROUP <name> | Creates a completely new server group for Minecraft servers with its own configurations, etc.", "create DISPATCHCOMMAND <main-command> <command> | Creates a simple command alias", "create WRAPPER <name> | Creates and whitelists a new wrapper. The wrapper can also have the same IP of a previous wrapper", "create TEMPLATE <name> <group> LOCAL | Creates a new locale (Wrapper locales) template for a server group", "create TEMPLATE <name> <group> MASTER | Creates a new master backend (Master locales) template for a server group", "create TEMPLATE <name> <group> URL <url> | Creates a new template of a server group via url");
break;
}
}
use of de.dytanic.cloudnet.lib.server.ProxyGroup in project CloudNet by Dytanic.
the class PacketInUpdateProxyGroup method handleInput.
@Override
public void handleInput(Document data, PacketSender packetSender) {
ProxyGroup proxyGroup = data.getObject("group", new TypeToken<ProxyGroup>() {
}.getType());
CloudNet.getInstance().getConfig().createGroup(proxyGroup);
try {
CloudNet.getInstance().getConfig().load();
} catch (Exception e) {
e.printStackTrace();
}
CloudNet.getInstance().getServerGroups().clear();
CloudNet.getInstance().getProxyGroups().clear();
NetworkUtils.addAll(CloudNet.getInstance().getServerGroups(), CloudNet.getInstance().getConfig().getServerGroups(), new Acceptable<ServerGroup>() {
@Override
public boolean isAccepted(ServerGroup value) {
System.out.println("Loading server group: " + value.getName());
return true;
}
});
NetworkUtils.addAll(CloudNet.getInstance().getProxyGroups(), CloudNet.getInstance().getConfig().getProxyGroups(), new Acceptable<ProxyGroup>() {
@Override
public boolean isAccepted(ProxyGroup value) {
System.out.println("Loading proxy group: " + value.getName());
return true;
}
});
CloudNet.getInstance().getNetworkManager().reload();
CloudNet.getInstance().getNetworkManager().updateAll0();
CloudNet.getInstance().getWrappers().values().forEach(new Consumer<Wrapper>() {
@Override
public void accept(Wrapper wrapper) {
wrapper.updateWrapper();
}
});
}
use of de.dytanic.cloudnet.lib.server.ProxyGroup in project CloudNet by Dytanic.
the class CloudNet method bootstrap.
@Override
public boolean bootstrap() throws Exception {
if (!optionSet.has("disable-autoupdate"))
checkForUpdates();
dbHandlers = new DatabaseBasicHandlers(databaseManager);
dbHandlers.getStatisticManager().addStartup();
this.moduleManager.setDisabledModuleList(config.getDisabledModules());
if (!optionSet.has("disable-modules")) {
System.out.println("Loading Modules...");
moduleManager.loadModules();
}
for (WrapperMeta wrapperMeta : config.getWrappers()) {
System.out.println("Loading Wrapper " + wrapperMeta.getId() + " @ " + wrapperMeta.getHostName());
this.wrappers.put(wrapperMeta.getId(), new Wrapper(wrapperMeta));
}
// Packet Init
this.users = config.getUsers();
// Groups Loading
NetworkUtils.addAll(this.serverGroups, config.getServerGroups(), new Acceptable<ServerGroup>() {
@Override
public boolean isAccepted(ServerGroup value) {
System.out.println("Loading ServerGroup: " + value.getName());
setupGroup(value);
return true;
}
});
NetworkUtils.addAll(this.proxyGroups, config.getProxyGroups(), new Acceptable<ProxyGroup>() {
@Override
public boolean isAccepted(ProxyGroup value) {
System.out.println("Loading ProxyGroup: " + value.getName());
setupProxy(value);
return true;
}
});
webServer = new WebServer(optionSet.has("ssl"), config.getWebServerConfig().getAddress(), config.getWebServerConfig().getPort());
// CommandManager Appending
this.initialCommands();
this.initWebHandlers();
this.initPacketHandlers();
// Scheduler Startup
{
Thread thread = new Thread(scheduler);
thread.setDaemon(true);
thread.start();
}
{
Thread thread = new Thread(subScheduler);
thread.setDaemon(true);
thread.start();
}
for (ConnectableAddress connectableAddress : config.getAddresses()) {
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
new CloudNetServer(optionSet, connectableAddress);
}
});
thread.setDaemon(true);
thread.start();
}
webServer.bind();
RUNNING = true;
Runtime.getRuntime().addShutdownHook(new Thread(this));
/*==================================*/
{
if (!optionSet.has("onlyConsole")) {
CloudStartupHandler cloudStartupHandler = new CloudStartupHandler();
CloudPriorityStartupHandler cloudPriorityStartupHandler = new CloudPriorityStartupHandler();
CloudPriorityGroupStartupHandler cloudPriorityGroupStartupHandler = new CloudPriorityGroupStartupHandler();
CloudPlayerRemoverHandler cloudPlayerRemoverHandler = new CloudPlayerRemoverHandler();
scheduler.runTaskRepeatSync(cloudStartupHandler, 0, cloudStartupHandler.getTicks());
scheduler.runTaskRepeatSync(cloudPriorityGroupStartupHandler, 0, cloudPriorityGroupStartupHandler.getTicks());
scheduler.runTaskRepeatSync(cloudPriorityStartupHandler, 0, cloudPriorityStartupHandler.getTicks());
scheduler.runTaskRepeatSync(cloudPlayerRemoverHandler, 0, cloudPlayerRemoverHandler.getTicks());
}
CloudStopCheckHandler cloudStopCheck = new CloudStopCheckHandler();
scheduler.runTaskRepeatSync(cloudStopCheck, 0, cloudStopCheck.getTicks());
scheduler.runTaskRepeatSync(serverLogManager, 0, 2000);
scheduler.runTaskRepeatSync(new Runnable() {
@Override
public void run() {
for (CloudPlayer cloudPlayer : networkManager.getWaitingPlayers().values()) {
if ((cloudPlayer.getLoginTimeStamp().getTime() + 10000L) < System.currentTimeMillis()) {
networkManager.getWaitingPlayers().remove(cloudPlayer.getUniqueId());
}
}
}
}, 0, 100);
}
if (!optionSet.has("disable-modules"))
System.out.println("Enabling Modules...");
moduleManager.enableModules();
// Event Init
eventManager.callEvent(new CloudInitEvent());
new LocalCloudWrapper().run(optionSet);
return true;
}
use of de.dytanic.cloudnet.lib.server.ProxyGroup in project CloudNet by Dytanic.
the class CloudNet method reload.
@Override
public void reload() throws Exception {
if (!optionSet.has("disable-modules")) {
System.out.println("Disabling modules...");
this.moduleManager.disableModules();
}
this.eventManager.clearAll();
this.commandManager.clearCommands();
this.webServer.getWebServerProvider().clear();
this.networkManager.getModuleProperties().clear();
databaseManager.save().clear();
this.users = config.getUsers();
this.serverGroups.clear();
this.proxyGroups.clear();
this.config.load();
NetworkUtils.addAll(this.serverGroups, config.getServerGroups(), new Acceptable<ServerGroup>() {
public boolean isAccepted(ServerGroup value) {
System.out.println("Loading server group: " + value.getName());
setupGroup(value);
return true;
}
});
NetworkUtils.addAll(this.proxyGroups, config.getProxyGroups(), new Acceptable<ProxyGroup>() {
public boolean isAccepted(ProxyGroup value) {
System.out.println("Loading proxy group: " + value.getName());
setupProxy(value);
return true;
}
});
this.initialCommands();
this.initWebHandlers();
this.initPacketHandlers();
if (!optionSet.has("disable-modules"))
this.moduleManager.loadModules().enableModules();
System.out.println("Updating wrappers...");
for (Wrapper wrapper : wrappers.values()) wrapper.updateWrapper();
networkManager.reload();
networkManager.updateAll();
}
Aggregations