use of org.spongepowered.api.command.source.RemoteSource in project LanternServer by LanternPowered.
the class LanternContextCalculator method buildAddressCache.
private LoadingCache<RemoteSource, Set<Context>> buildAddressCache(final String contextKey, final Function<RemoteSource, InetAddress> function) {
return Caffeine.newBuilder().weakKeys().build(key -> {
final ImmutableSet.Builder<Context> builder = ImmutableSet.builder();
final InetAddress address = checkNotNull(function.apply(key), "address");
builder.add(new Context(contextKey, address.getHostAddress()));
for (String set : Maps.filterValues(Lantern.getGame().getGlobalConfig().getIpSets(), input -> input.test(address)).keySet()) {
builder.add(new Context(contextKey, set));
}
return builder.build();
});
}
use of org.spongepowered.api.command.source.RemoteSource in project LanternServer by LanternPowered.
the class LanternContextCalculator method accumulateContexts.
@Override
public void accumulateContexts(Subject subject, Set<Context> accumulator) {
final Optional<CommandSource> subjSource = subject.getCommandSource();
if (subjSource.isPresent()) {
final CommandSource source = subjSource.get();
if (source instanceof Locatable) {
final World currentExt = ((Locatable) source).getWorld();
accumulator.add(currentExt.getContext());
accumulator.add((currentExt.getDimension().getContext()));
}
if (source instanceof RemoteSource) {
final RemoteSource rem = (RemoteSource) source;
accumulator.addAll(this.remoteIpCache.get(rem));
accumulator.addAll(this.localIpCache.get(rem));
accumulator.add(new Context(Context.LOCAL_PORT_KEY, String.valueOf(rem.getConnection().getVirtualHost().getPort())));
accumulator.add(new Context(Context.LOCAL_HOST_KEY, rem.getConnection().getVirtualHost().getHostName()));
}
}
}
use of org.spongepowered.api.command.source.RemoteSource in project SpongeCommon by SpongePowered.
the class SpongeContextCalculator method accumulateContexts.
@Override
public void accumulateContexts(Subject subject, Set<Context> accumulator) {
Optional<CommandSource> subjSource = subject.getCommandSource();
if (subjSource.isPresent()) {
CommandSource source = subjSource.get();
if (source instanceof Locatable) {
World currentExt = ((Locatable) source).getWorld();
accumulator.add(currentExt.getContext());
accumulator.add((currentExt.getDimension().getContext()));
}
if (source instanceof RemoteSource) {
RemoteSource rem = (RemoteSource) source;
accumulator.addAll(this.remoteIpCache.getUnchecked(rem));
accumulator.addAll(this.localIpCache.getUnchecked(rem));
accumulator.add(new Context(Context.LOCAL_PORT_KEY, String.valueOf(rem.getConnection().getVirtualHost().getPort())));
accumulator.add(new Context(Context.LOCAL_HOST_KEY, rem.getConnection().getVirtualHost().getHostName()));
}
}
}
Aggregations