use of de.dytanic.cloudnet.lib.network.auth.packetio.PacketOutAuthResult in project CloudNet by Dytanic.
the class PacketInAuthHandler method handleAuth.
@Override
public void handleAuth(Auth auth, AuthType authType, Document authData, PacketSender packetSender) {
if (!(packetSender instanceof CloudNetClientAuth))
return;
CloudNetClientAuth client = (CloudNetClientAuth) packetSender;
switch(authType) {
case CLOUD_NET:
{
String key = authData.getString("key");
String id = authData.getString("id");
if (CloudNet.getInstance().getWrappers().containsKey(id)) {
Wrapper cn = CloudNet.getInstance().getWrappers().get(id);
String wrapperKey = CloudNet.getInstance().getConfig().getWrapperKey();
if (wrapperKey != null && cn.getChannel() == null && wrapperKey.equals(key)) {
Channel channel = client.getChannel();
channel.pipeline().remove("client");
client.getChannel().writeAndFlush(new PacketOutAuthResult(new AuthLoginResult(true))).syncUninterruptibly();
channel.pipeline().addLast(new CloudNetClient(cn, channel));
return;
} else {
client.getChannel().writeAndFlush(new PacketOutAuthResult(new AuthLoginResult(false))).syncUninterruptibly();
CloudNet.getLogger().info("Authentication failed [" + (wrapperKey != null ? "Invalid WrapperKey or Wrapper is already connected!" : "WrapperKey not found, please copy a wrapper key to this instance") + "]");
}
} else {
client.getChannel().writeAndFlush(new PacketOutAuthResult(new AuthLoginResult(false))).syncUninterruptibly();
}
}
return;
case GAMESERVER_OR_BUNGEE:
{
ServiceId serviceId = authData.getObject("serviceId", ServiceId.class);
if (CloudNet.getInstance().getWrappers().containsKey(serviceId.getWrapperId())) {
Wrapper wrapper = CloudNet.getInstance().getWrappers().get(serviceId.getWrapperId());
if (wrapper.getServers().containsKey(serviceId.getServerId())) {
MinecraftServer minecraftServer = wrapper.getServers().get(serviceId.getServerId());
if (minecraftServer.getChannel() == null && minecraftServer.getServerInfo().getServiceId().getUniqueId().equals(serviceId.getUniqueId())) {
Channel channel = client.getChannel();
channel.pipeline().remove("client");
channel.pipeline().addLast(new CloudNetClient(minecraftServer, channel));
return;
}
} else if (wrapper.getCloudServers().containsKey(serviceId.getServerId())) {
CloudServer minecraftServer = wrapper.getCloudServers().get(serviceId.getServerId());
if (minecraftServer.getChannel() == null && minecraftServer.getServerInfo().getServiceId().getUniqueId().equals(serviceId.getUniqueId())) {
Channel channel = client.getChannel();
channel.pipeline().remove("client");
channel.pipeline().addLast(new CloudNetClient(minecraftServer, channel));
return;
}
} else if (wrapper.getProxys().containsKey(serviceId.getServerId())) {
ProxyServer minecraftServer = wrapper.getProxys().get(serviceId.getServerId());
if (minecraftServer.getChannel() == null && minecraftServer.getProxyInfo().getServiceId().getUniqueId().equals(serviceId.getUniqueId())) {
Channel channel = client.getChannel();
channel.pipeline().remove("client");
channel.pipeline().addLast(new CloudNetClient(minecraftServer, channel));
return;
}
} else {
client.getChannel().close().syncUninterruptibly();
}
} else {
client.getChannel().close().syncUninterruptibly();
}
}
return;
default:
return;
}
}
Aggregations