1package com.runehive.net;
3import com.google.common.collect.ConcurrentHashMultiset;
4import com.google.common.collect.Multiset;
5import com.runehive.Config;
6import com.runehive.game.world.entity.mob.player.IPBannedPlayers;
7import com.runehive.net.codec.login.LoginResponse;
8import com.runehive.net.codec.login.LoginResponsePacket;
9import io.netty.buffer.ByteBuf;
10import io.netty.channel.ChannelFutureListener;
11import io.netty.channel.ChannelHandler.Sharable;
12import io.netty.channel.ChannelHandlerContext;
13import io.netty.channel.ChannelInboundHandlerAdapter;
15import java.net.InetSocketAddress;
16import java.util.Objects;
17import java.util.concurrent.atomic.AtomicBoolean;
30 private final Multiset<Connection>
connections = ConcurrentHashMultiset.create();
51 if (connection.
getHost().equalsIgnoreCase(
"127.0.0.1")) {
76 ctx.fireChannelRegistered();
87 if (connection.
getHost().equalsIgnoreCase(
"127.0.0.1")) {
102 ctx.fireChannelUnregistered();
115 ByteBuf initialMessage = ctx.alloc().buffer(8).writeLong(0);
117 ctx.write(initialMessage, ctx.voidPromise());
118 ctx.writeAndFlush(message).addListener(ChannelFutureListener.CLOSE);
130 String host = ((InetSocketAddress) ctx.channel().remoteAddress()).getAddress().getHostAddress();
131 return connections.stream().filter(conn -> conn.getHost().equalsIgnoreCase(host)).findFirst().orElse(
new Connection(host));
142 private final AtomicBoolean
canConnect =
new AtomicBoolean(
true);
203 return Objects.hash(
host);
The class that contains setting-related constants for the server.
static final int CONNECTION_LIMIT
The maximum amount of connections that can be active at a time, or in other words how many clients ca...
static final List< String > ipBans
Creates a conenction for a host address.
final AtomicBoolean canConnect
The stopwatch which caches the time of our last login.
int connections
The amount of connections associated with this host address.
void addConnection()
Adds a connection.
Connection(String host)
Constructs a new Connection object.
void removeConnection()
Removes a connection.
boolean equals(Object obj)
final String host
The host address.
void setCanConnect(boolean val)
boolean canConnect()
Checks if this host can connect.
int getConnections()
Gets the amount of connections associated with this host address.
String getHost()
Gets the host address.
The ChannelInboundHandlerAdapter implementation that will filter out unwanted connections from propag...
final Multiset< Connection > connections
A set of connections currently active within the server.
void channelUnregistered(ChannelHandlerContext ctx)
void channelActive(ChannelHandlerContext ctx)
void disconnect(ChannelHandlerContext ctx, LoginResponse response)
Disconnects ctx with response as the response code.
void channelRegistered(ChannelHandlerContext ctx)
Connection getConenction(ChannelHandlerContext ctx)
Gets the host address of the user logging in.
An immutable message that is written through a channel and forwarded to the LoginResponseEncoder wher...
Represents the enumerated login response codes.