Skip to content
This repository has been archived by the owner on Jun 7, 2022. It is now read-only.

Commit

Permalink
Merge pull request #99 from CloudNetService/development
Browse files Browse the repository at this point in the history
Merge development into master branch
  • Loading branch information
byRoadrunner authored Jan 20, 2019
2 parents 74d5490 + b4a54ec commit 98b7357
Show file tree
Hide file tree
Showing 22 changed files with 153 additions and 102 deletions.
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pipeline {
}
stage('Version') {
steps {
sh 'mvn versions:set -DnewVersion=2.1.14.2'
sh 'mvn versions:set -DnewVersion=2.1.14.3'
}
}
stage('Compile') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private void checkRegistryAccess()
{
Class.forName("net.md_5.bungee.api.chat.BaseComponent");
Class.forName("de.dytanic.cloudnet.bridge.internal.chat.DocumentRegistry").getMethod("fire").invoke(null);
} catch (Exception ex)
} catch (Exception ignored)
{
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,14 @@ public void onServerRemove(ServerInfo serverInfo)
if (serverInfo == null) return;

ProxyServer.getInstance().getPluginManager().callEvent(new ProxiedServerRemoveEvent(serverInfo));
ProxyServer.getInstance().getServers().remove(serverInfo.getServiceId().getServerId());

try
{
ProxyServer.getInstance().getServers().remove(serverInfo.getServiceId().getServerId());
} catch (Throwable ignored)
{
}

cachedServers.remove(serverInfo.getServiceId().getServerId());

if (serverInfo.getServiceId().getGroup().equalsIgnoreCase(getProxyGroup().getProxyConfig().getDynamicFallback().getDefaultFallback()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import de.dytanic.cloudnet.api.CloudAPI;
import de.dytanic.cloudnet.bridge.CloudServer;
import de.dytanic.cloudnet.bridge.event.bukkit.BukkitSubChannelMessageEvent;
import de.dytanic.cloudnet.bridge.internal.util.CloudPermissble;
import de.dytanic.cloudnet.bridge.internal.util.CloudPermissible;
import de.dytanic.cloudnet.bridge.internal.util.ReflectionUtil;
import de.dytanic.cloudnet.lib.player.CloudPlayer;
import de.dytanic.cloudnet.lib.player.permission.GroupEntityData;
Expand Down Expand Up @@ -97,8 +97,8 @@ public void handleFirst(PlayerLoginEvent event)
else field = Class.forName("net.glowstone.entity.GlowHumanEntity").getDeclaredField("permissions");

field.setAccessible(true);
final CloudPermissble cloudPermissble = new CloudPermissble(event.getPlayer());
field.set(event.getPlayer(), cloudPermissble);
final CloudPermissible cloudPermissible = new CloudPermissible(event.getPlayer());
field.set(event.getPlayer(), cloudPermissible);
} catch (Exception ex)
{
ex.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ public void onServerAdd(ServerInfo serverInfo)
changeBlock(location, signLayout.getBlockId(), signLayout.getSubId());
} else
{
sign.setServerInfo(null);
newSign.setServerInfo(null);
SignLayout signLayout = getSearchingLayout(((ThreadImpl) worker).animationTick);
String[] layout = updateOfflineAndMaintenance(signLayout.getSignLayout().clone(), sign);
for (Player all : Bukkit.getOnlinePlayers())
Expand Down Expand Up @@ -971,4 +971,4 @@ public void run()
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
/**
* Created by Tareko on 18.08.2017.
*/
public class CloudPermissble extends PermissibleBase {
public class CloudPermissible extends PermissibleBase {

private UUID uniqueId;

public CloudPermissble(Player player)
public CloudPermissible(Player player)
{
super(player);
this.uniqueId = player.getUniqueId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
import de.dytanic.cloudnet.cloudflare.util.DNSType;
import de.dytanic.cloudnet.cloudflare.util.DefaultDNSRecord;
import de.dytanic.cloudnet.cloudflare.util.SRVRecord;
import de.dytanic.cloudnet.lib.MultiValue;
import de.dytanic.cloudnet.lib.NetworkUtils;
import de.dytanic.cloudnet.lib.database.Database;
import de.dytanic.cloudnet.lib.server.ProxyGroup;
import de.dytanic.cloudnet.lib.server.ProxyProcessMeta;
import de.dytanic.cloudnet.lib.service.SimpledWrapperInfo;
import de.dytanic.cloudnet.lib.utility.Acceptable;
import de.dytanic.cloudnet.lib.utility.CollectionWrapper;
import de.dytanic.cloudnet.lib.utility.document.Document;
import lombok.Getter;
Expand All @@ -42,9 +43,9 @@ public class CloudFlareService {
private Collection<CloudFlareConfig> cloudFlareConfigs;

// WrapperId DNSRecord
private final Map<String, PostResponse>
ipARecords = NetworkUtils.newConcurrentHashMap(),
bungeeSRVRecords = NetworkUtils.newConcurrentHashMap();
private final Map<String, MultiValue<PostResponse, String>> ipARecords = NetworkUtils.newConcurrentHashMap();

private final Map<String, MultiValue<PostResponse, String>> bungeeSRVRecords = NetworkUtils.newConcurrentHashMap();

/**
* Constructs a new CloudFlare Service module with a given configuration.
Expand All @@ -61,12 +62,8 @@ public CloudFlareService(Collection<CloudFlareConfig> cloudFlareConfigs)
@Deprecated
public boolean bootstrap(Map<String, SimpledWrapperInfo> wrapperInfoMap, Map<String, ProxyGroup> groups, CloudFlareDatabase cloudFlareDatabase)
{
for (PostResponse id : cloudFlareDatabase.getAndRemove().values())
this.deleteRecord(id);

for (String key : cloudFlareDatabase.getAll())
if (!key.equalsIgnoreCase(Database.UNIQUE_NAME_KEY) && !wrapperInfoMap.containsKey(key))
deleteRecord(cloudFlareDatabase.getResponse(key));
for (MultiValue<PostResponse, String> id : cloudFlareDatabase.getAndRemove().values())
this.deleteRecord(id.getFirst());

for (CloudFlareConfig cloudFlareConfig : this.cloudFlareConfigs)
if (cloudFlareConfig.isEnabled())
Expand All @@ -75,15 +72,15 @@ public boolean bootstrap(Map<String, SimpledWrapperInfo> wrapperInfoMap, Map<Str
ProxyGroup proxyGroup = groups.get(cloudFlareProxyGroup.getName());
for (String wrapper : proxyGroup.getWrapper())
{
if (!cloudFlareDatabase.contains(wrapper))
if (!cloudFlareDatabase.contains(cloudFlareConfig, wrapper))
{
String host = wrapperInfoMap.get(wrapper).getHostName();
DNSRecord dnsRecord = new DefaultDNSRecord(DNSType.A, wrapper + "." + cloudFlareConfig.getDomainName(), host, new Document().obj());
if (!ipARecords.containsKey(wrapper))
{
PostResponse postResponse = this.createRecord(cloudFlareConfig, dnsRecord);
ipARecords.put(wrapper, postResponse);
cloudFlareDatabase.putPostResponse(wrapper, postResponse);
ipARecords.put(postResponse.getId(), new MultiValue<>(postResponse, wrapper));
cloudFlareDatabase.putPostResponse(new MultiValue<>(postResponse, wrapper));
NetworkUtils.sleepUninterruptedly(400);
}
}
Expand All @@ -94,16 +91,22 @@ public boolean bootstrap(Map<String, SimpledWrapperInfo> wrapperInfoMap, Map<Str

public boolean shutdown(CloudFlareDatabase cloudFlareDatabase)
{
for (PostResponse postResponse : this.bungeeSRVRecords.values())
for (MultiValue<PostResponse, String> postResponse : this.bungeeSRVRecords.values())
{
this.deleteRecord(postResponse);
NetworkUtils.sleepUninterruptedly(450);
try
{
this.deleteRecord(postResponse.getFirst());
NetworkUtils.sleepUninterruptedly(500);
} catch (Exception ex)
{
ex.printStackTrace();
}
}

for (PostResponse id : cloudFlareDatabase.getAndRemove().values())
for (MultiValue<PostResponse, String> id : cloudFlareDatabase.getAndRemove().values())
{
this.deleteRecord(id);
NetworkUtils.sleepUninterruptedly(450);
this.deleteRecord(id.getFirst());
NetworkUtils.sleepUninterruptedly(500);
}
return true;
}
Expand Down Expand Up @@ -163,9 +166,9 @@ public void addProxy(ProxyProcessMeta proxyServer, CloudFlareDatabase cloudFlare
proxyServer.getServiceId().getWrapperId() + "." + cloudFlareConfig.getDomainName()
);
}
PostResponse postResponse1 = this.createRecord(cloudFlareConfig, srvRecord);
cloudFlareDatabase.add(postResponse1);
this.bungeeSRVRecords.put(proxyServer.getServiceId().getServerId(), postResponse1);
PostResponse postResponse = this.createRecord(cloudFlareConfig, srvRecord);
cloudFlareDatabase.add(postResponse);
this.bungeeSRVRecords.put(postResponse.getId(), new MultiValue<>(postResponse, proxyServer.getServiceId().getServerId()));
}
}
}
Expand All @@ -178,13 +181,36 @@ public void addProxy(ProxyProcessMeta proxyServer, CloudFlareDatabase cloudFlare
*/
public void removeProxy(ProxyProcessMeta proxyServer, CloudFlareDatabase cloudFlareDatabase)
{
if (!bungeeSRVRecords.containsKey(proxyServer.getServiceId().getServerId())) return;
//if (!bungeeSRVRecords.containsKey(proxyServer.getServiceId().getServerId())) return;

PostResponse postResponse = bungeeSRVRecords.get(proxyServer.getServiceId().getServerId());
if (postResponse != null)
while (true)
{
cloudFlareDatabase.remove(postResponse.getId());
deleteRecord(postResponse);
Collection<MultiValue<PostResponse, String>> postResponses = CollectionWrapper.filterMany(bungeeSRVRecords.values(), new Acceptable<MultiValue<PostResponse, String>>() {
@Override
public boolean isAccepted(MultiValue<PostResponse, String> postResponseStringMultiValue)
{
return postResponseStringMultiValue.getSecond().equalsIgnoreCase(proxyServer.getServiceId().getServerId());
}
});

//MultiValue<PostResponse, String> postResponse = bungeeSRVRecords.get(proxyServer.getServiceId().getServerId());
/*
if (postResponse != null)
{
cloudFlareDatabase.remove(postResponse.getFirst().getId());
deleteRecord(postResponse.getFirst());
} else break;
*/

for (MultiValue<PostResponse, String> postResponse : postResponses)
if (postResponse != null)
{
bungeeSRVRecords.remove(postResponse.getSecond());
cloudFlareDatabase.remove(postResponse.getFirst().getId());
deleteRecord(postResponse.getFirst());

NetworkUtils.sleepUninterruptedly(500);
}
}
}

Expand All @@ -209,6 +235,7 @@ public PostResponse createRecord(CloudFlareConfig cloudFlareConfig, DNSRecord dn
httpPost.setRequestProperty("Content-Type", "application/json");
httpPost.setDoOutput(true);
httpPost.connect();

try (DataOutputStream dataOutputStream = new DataOutputStream(httpPost.getOutputStream()))
{
dataOutputStream.writeBytes(values);
Expand All @@ -231,6 +258,7 @@ public PostResponse createRecord(CloudFlareConfig cloudFlareConfig, DNSRecord dn
{
e.printStackTrace();
}

return null;
}

Expand All @@ -245,12 +273,14 @@ public void deleteRecord(PostResponse postResponse)
try
{
HttpURLConnection delete = (HttpURLConnection) new URL(PREFIX_URL + "zones/" + postResponse.getCloudFlareConfig().getZoneId() + "/dns_records/" + postResponse.getId()).openConnection();

delete.setRequestMethod("DELETE");
delete.setRequestProperty("X-Auth-Email", postResponse.getCloudFlareConfig().getEmail());
delete.setRequestProperty("X-Auth-Key", postResponse.getCloudFlareConfig().getToken());
delete.setRequestProperty("Accept", "application/json");
delete.setRequestProperty("Content-Type", "application/json");
delete.connect();

try (InputStream inputStream = delete.getInputStream())
{
JsonObject jsonObject = toJsonInput(inputStream);
Expand All @@ -259,6 +289,7 @@ public void deleteRecord(PostResponse postResponse)
System.out.println(prefix + " DNSRecord [" + postResponse.getId() + "] was removed");
}
}

delete.disconnect();
} catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
package de.dytanic.cloudnet.cloudflare.database;

import com.google.gson.reflect.TypeToken;
import de.dytanic.cloudnet.cloudflare.CloudFlareConfig;
import de.dytanic.cloudnet.cloudflare.PostResponse;
import de.dytanic.cloudnet.database.DatabaseUsable;
import de.dytanic.cloudnet.lib.MultiValue;
import de.dytanic.cloudnet.lib.database.Database;
import de.dytanic.cloudnet.lib.database.DatabaseDocument;
import de.dytanic.cloudnet.lib.utility.MapWrapper;
Expand Down Expand Up @@ -42,17 +44,44 @@ public Collection<String> getAll()
return collection;
}

public void putPostResponse(String wrapper, PostResponse postResponse)
public void putPostResponse(MultiValue<PostResponse, String> postResponse)
{
Document document = database.getDocument(CLOUDFLARE_CACHE);
document.append(wrapper, postResponse);
document.append(postResponse.getFirst().getId(), postResponse);
database.insert(document);
}

public boolean contains(String wrapper)
public boolean contains(CloudFlareConfig cloudFlareConfig, String wrapper)
{
Document document = database.getDocument(CLOUDFLARE_CACHE);
return document.contains(wrapper);

/*
Map<String, MultiValue<PostResponse, String>> responses = document.getObject("requests", new TypeToken<Map<String, MultiValue<PostResponse, String>>>() {
}.getType());
*/

/*
return CollectionWrapper.filter(responses.values(), new Acceptable<MultiValue<PostResponse, String>>() {
@Override
public boolean isAccepted(MultiValue<PostResponse, String> value)
{
return value.getSecond().equalsIgnoreCase(wrapper) && value.getFirst().getCloudFlareConfig().getDomainName().equalsIgnoreCase(cloudFlareConfig.getDomainName());
}
}) != null;
*/

for (String key : document.keys())
if (!key.equalsIgnoreCase(Database.UNIQUE_NAME_KEY))
{
MultiValue<PostResponse, String> value = document.getObject(key, new TypeToken<MultiValue<PostResponse, String>>() {
}.getType());

if (value != null && value.getSecond().equalsIgnoreCase(wrapper) && value.getFirst().getCloudFlareConfig().getDomainName().equalsIgnoreCase(cloudFlareConfig.getDomainName()))
return true;
}

return false;
//return document.contains(wrapper);
}

public void remove(String wrapper)
Expand Down Expand Up @@ -102,18 +131,17 @@ public void remove(PostResponse postResponse)
database.insert(document);
}

public Map<String, PostResponse> getAndRemove()
public Map<String, MultiValue<PostResponse, String>> getAndRemove()
{
Document document = database.getDocument(CLOUDFLARE_CACHE_REQ);
if (document.contains("requests"))
{
Map<String, PostResponse> responses = document.getObject("requests", new TypeToken<Map<String, PostResponse>>() {
Map<String, MultiValue<PostResponse, String>> responses = document.getObject("requests", new TypeToken<Map<String, MultiValue<PostResponse, String>>>() {
}.getType());
document.append("requests", new HashMap<>(0));
document.append("requests", Collections.EMPTY_MAP);
database.insert(document);
return responses;
}
return Collections.EMPTY_MAP;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void run(ProxyServer obj)
sender.sendMessage("Group doesn't exist");
return;
}
if (args[0].equalsIgnoreCase("server"))
if (args[0].equalsIgnoreCase("server") || args[0].equalsIgnoreCase("-s"))
{
MinecraftServer proxyServer = CloudNet.getInstance().getServer(args[1]);
if (proxyServer != null)
Expand All @@ -99,7 +99,7 @@ public void run(ProxyServer obj)
}
return;
}
if (args[0].equalsIgnoreCase("proxy"))
if (args[0].equalsIgnoreCase("proxy") || args[0].equalsIgnoreCase("-p"))
{
ProxyServer proxyServer = CloudNet.getInstance().getProxy(args[1]);
if (proxyServer != null)
Expand Down
10 changes: 5 additions & 5 deletions cloudnet-core/src/main/resources/modules/modules.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#
# Copyright (c) Tarek Hosni El Alaoui 2017
#
CloudNet-Service-PermissionModule=1.0.0.1
CloudNet-Service-MobModule=1.0.0.1
CloudNet-Service-SignsModule=1.0.0.1
CloudNet-Service-CloudFlareModule=1.0.0.1
CloudNet-Service-NotifyServiceModule=1.0.0.1
CloudNet-Service-PermissionModule=1.0.0.2
CloudNet-Service-MobModule=1.0.0.2
CloudNet-Service-SignsModule=1.0.0.2
CloudNet-Service-CloudFlareModule=1.0.0.2
CloudNet-Service-NotifyServiceModule=1.0.0.2
Loading

0 comments on commit 98b7357

Please sign in to comment.