use of de.dytanic.cloudnet.lib.server.ServerGroup in project CloudNet by Dytanic.
the class CommandCloudDev method execute.
@Override
public void execute(CommandSender commandSender, String[] args) {
if (!(commandSender instanceof ProxiedPlayer))
return;
switch(args.length) {
case 0:
for (ServerInfo serverInfo : CloudProxy.getInstance().getCachedServers().values()) {
if (serverInfo.getServerConfig().getProperties().contains(NetworkUtils.DEV_PROPERTY)) {
DevService service = serverInfo.getServerConfig().getProperties().getObject(NetworkUtils.DEV_PROPERTY, DevService.class);
if (service.getUniqueId().equals(((ProxiedPlayer) commandSender).getUniqueId())) {
((ProxiedPlayer) commandSender).connect(ProxyServer.getInstance().getServerInfo(serverInfo.getServiceId().getServerId()));
return;
}
}
}
commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "/cdev forTemplate <group> <template>");
commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "/cdev forTemplate <group>");
commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "/cdev testServer <group>");
commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "/cdev testServer <group> <template>");
break;
case 2:
{
for (ServerInfo serverInfo : CloudProxy.getInstance().getCachedServers().values()) {
if (serverInfo.getServerConfig().getProperties().contains(NetworkUtils.DEV_PROPERTY)) {
DevService service = serverInfo.getServerConfig().getProperties().getObject(NetworkUtils.DEV_PROPERTY, DevService.class);
if (service.getUniqueId().equals(((ProxiedPlayer) commandSender).getUniqueId())) {
((ProxiedPlayer) commandSender).connect(ProxyServer.getInstance().getServerInfo(serverInfo.getServiceId().getServerId()));
return;
}
}
}
if (args[0].equalsIgnoreCase("forTemplate")) {
if (!CloudAPI.getInstance().getServerGroupMap().containsKey(args[1])) {
commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The group doesn't exist");
return;
}
ServerConfig serverConfig = new ServerConfig(true, commandSender.getName(), new Document(NetworkUtils.DEV_PROPERTY, new DevService(((ProxiedPlayer) commandSender).getUniqueId(), true)), System.currentTimeMillis());
CloudAPI.getInstance().startGameServer(CloudAPI.getInstance().getServerGroupData(args[1]), serverConfig, "Dev" + args[1] + "-" + commandSender.getName());
((ProxiedPlayer) commandSender).sendMessage(CloudAPI.getInstance().getPrefix() + "The server will start up now...");
return;
}
if (args[0].equalsIgnoreCase("testServer")) {
if (!CloudAPI.getInstance().getServerGroupMap().containsKey(args[1])) {
commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The group doesn't exist");
return;
}
ServerConfig serverConfig = new ServerConfig(true, commandSender.getName(), new Document(), System.currentTimeMillis());
CloudAPI.getInstance().startCloudServer("TestServer-" + ((ProxiedPlayer) commandSender).getUniqueId(), serverConfig, 356, true);
((ProxiedPlayer) commandSender).sendMessage(CloudAPI.getInstance().getPrefix() + "The server will start up now...");
return;
}
}
case 3:
{
for (ServerInfo serverInfo : CloudProxy.getInstance().getCachedServers().values()) {
if (serverInfo.getServerConfig().getProperties().contains(NetworkUtils.DEV_PROPERTY)) {
DevService service = serverInfo.getServerConfig().getProperties().getObject(NetworkUtils.DEV_PROPERTY, DevService.class);
if (service.getUniqueId().equals(((ProxiedPlayer) commandSender).getUniqueId())) {
((ProxiedPlayer) commandSender).connect(ProxyServer.getInstance().getServerInfo(serverInfo.getServiceId().getServerId()));
return;
}
}
}
if (args[0].equalsIgnoreCase("forTemplate")) {
if (!CloudAPI.getInstance().getServerGroupMap().containsKey(args[1])) {
commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The group doesn't exist");
return;
}
ServerGroup serverGroup = CloudAPI.getInstance().getServerGroup(args[1]);
if (CollectionWrapper.filter(serverGroup.getTemplates(), new Acceptable<Template>() {
@Override
public boolean isAccepted(Template template) {
return template.getName().equalsIgnoreCase(args[2]);
}
}) == null) {
commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The template doesn't exist");
return;
}
ServerConfig serverConfig = new ServerConfig(true, commandSender.getName(), new Document(NetworkUtils.DEV_PROPERTY, new DevService(((ProxiedPlayer) commandSender).getUniqueId(), true)), System.currentTimeMillis());
CloudAPI.getInstance().startGameServer(CloudAPI.getInstance().getServerGroupData(args[1]), serverConfig, CloudAPI.getInstance().getServerGroupData(args[1]).getMemory(), true, new Properties(), CollectionWrapper.filter(serverGroup.getTemplates(), new Acceptable<Template>() {
@Override
public boolean isAccepted(Template e) {
return e.getName().equalsIgnoreCase(args[2]);
}
}), "Dev" + args[1] + "-" + commandSender.getName());
((ProxiedPlayer) commandSender).sendMessage(CloudAPI.getInstance().getPrefix() + "The server will start up now...");
return;
}
if (args[0].equalsIgnoreCase("testServer")) {
if (!CloudAPI.getInstance().getServerGroupMap().containsKey(args[1])) {
commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The group doesn't exist");
return;
}
ServerGroup serverGroup = CloudAPI.getInstance().getServerGroup(args[1]);
if (CollectionWrapper.filter(serverGroup.getTemplates(), new Acceptable<Template>() {
@Override
public boolean isAccepted(Template template) {
return template.getName().equalsIgnoreCase(args[2]);
}
}) == null) {
commandSender.sendMessage(CloudAPI.getInstance().getPrefix() + "The template doesn't exist");
return;
}
ServerConfig serverConfig = new ServerConfig(true, commandSender.getName(), new Document(), System.currentTimeMillis());
/*
CloudAPI.getInstance().startGameServer(CloudAPI.getInstance().getServerGroupData(args[1]), serverConfig,
CloudAPI.getInstance().getServerGroupData(args[1]).getMemory(),
new String[0], null, "TestServer-" + commandSender.getName(), false, true, new Properties(),
null, Arrays.asList()
, "Dev" + args[1] + "-" + commandSender.getName());
*/
CloudAPI.getInstance().startCloudServer("TestServer-" + ((ProxiedPlayer) commandSender).getUniqueId(), serverConfig, 356, true);
((ProxiedPlayer) commandSender).sendMessage(CloudAPI.getInstance().getPrefix() + "The server will start up now...");
return;
}
}
break;
}
}
use of de.dytanic.cloudnet.lib.server.ServerGroup in project CloudNet by Dytanic.
the class NetworkManager method newCloudNetwork.
public CloudNetwork newCloudNetwork() {
CloudNetwork cloudNetwork = new CloudNetwork();
cloudNetwork.setOnlineCount(getOnlineCount());
cloudNetwork.setMessages(messageConfig.load());
cloudNetwork.setModules(moduleProperties);
// cloudNetwork.setNotifySystem(CloudNet.getInstance().getConfig().isNotifyService());
cloudNetwork.setWebPort(CloudNet.getInstance().getConfig().getWebServerConfig().getPort());
// cloudNetwork.setDevServices(CloudNet.getInstance().getConfig().isCloudDevServices());
Collection<WrapperInfo> wrappers = new LinkedList<>();
for (Wrapper wrapper : CloudNet.getInstance().getWrappers().values()) if (wrapper.getWrapperInfo() != null)
wrappers.add(wrapper.getWrapperInfo());
cloudNetwork.setWrappers(wrappers);
cloudNetwork.setServerGroups(MapWrapper.transform(CloudNet.getInstance().getServerGroups(), new Catcher<String, String>() {
@Override
public String doCatch(String key) {
return key;
}
}, new Catcher<SimpleServerGroup, ServerGroup>() {
@Override
public SimpleServerGroup doCatch(ServerGroup key) {
return key.toSimple();
}
}));
// cloudNetwork.setPermissionPool(permissionPool);
cloudNetwork.setProxyGroups(CloudNet.getInstance().getProxyGroups());
cloudNetwork.setModules(moduleProperties);
return cloudNetwork;
}
use of de.dytanic.cloudnet.lib.server.ServerGroup in project CloudNet by Dytanic.
the class Wrapper method updateWrapper.
public Wrapper updateWrapper() {
if (getChannel() == null)
return this;
java.util.Map<String, ServerGroup> groups = NetworkUtils.newConcurrentHashMap();
for (ServerGroup serverGroup : CloudNet.getInstance().getServerGroups().values()) if (serverGroup.getWrapper().contains(networkInfo.getId())) {
groups.put(serverGroup.getName(), serverGroup);
sendPacket(new PacketOutCreateTemplate(serverGroup));
}
java.util.Map<String, ProxyGroup> proxyGroups = NetworkUtils.newConcurrentHashMap();
for (ProxyGroup serverGroup : CloudNet.getInstance().getProxyGroups().values()) if (serverGroup.getWrapper().contains(networkInfo.getId())) {
proxyGroups.put(serverGroup.getName(), serverGroup);
sendPacket(new PacketOutCreateTemplate(serverGroup));
}
SimpledUser simpledUser = null;
User user = CollectionWrapper.filter(CloudNet.getInstance().getUsers(), new Acceptable<User>() {
@Override
public boolean isAccepted(User value) {
return networkInfo.getUser().equals(value.getName());
}
});
if (user != null) {
simpledUser = user.toSimple();
}
WrapperExternal wrapperExternal = new WrapperExternal(CloudNet.getInstance().getNetworkManager().newCloudNetwork(), simpledUser, groups, proxyGroups);
sendPacket(new PacketOutWrapperInfo(wrapperExternal));
return this;
}
use of de.dytanic.cloudnet.lib.server.ServerGroup 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.ServerGroup in project CloudNet by Dytanic.
the class CloudPriorityGroupStartupHandler method onHandle.
@Override
public void onHandle(CloudNet cloudNet) {
for (ServerGroup group : CloudNet.getInstance().getServerGroups().values()) {
double onlineCount = CloudNet.getInstance().getOnlineCount(group.getName());
if (group.getPriorityService().getGroup().getOnlineServers() == 0 || group.getPriorityService().getGlobal().getOnlineCount() == 0 || group.getGroupMode() == ServerGroupMode.STATIC || group.isMaintenance())
continue;
double priority = (group.getPriorityService().getGroup().getOnlineServers() / ((double) group.getPriorityService().getGroup().getOnlineCount())) * (onlineCount == 0 ? 1.0D : (onlineCount));
Collection<String> servers = CloudNet.getInstance().getServersAndWaitings(group.getName());
if (servers.size() == 0 && servers.size() < (priority <= 1 ? 1 : priority)) {
CloudNet.getInstance().startGameServer(group);
continue;
}
if (servers.size() < (priority <= 1 ? 1 : priority)) {
CloudNet.getInstance().startGameServer(group, new Document(), true);
}
}
}
Aggregations