mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 08:39:11 +00:00
Let PlayerCredentials house the connecting remote address.
This commit is contained in:
@@ -6,6 +6,7 @@ import io.netty.channel.ChannelFutureListener;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.List;
|
||||
|
||||
@@ -18,6 +19,8 @@ import org.apollo.security.PlayerCredentials;
|
||||
import org.apollo.util.BufferUtil;
|
||||
import org.apollo.util.StatefulFrameDecoder;
|
||||
|
||||
import com.google.common.net.InetAddresses;
|
||||
|
||||
/**
|
||||
* A {@link StatefulFrameDecoder} which decodes the login request frames.
|
||||
*
|
||||
@@ -174,6 +177,8 @@ public final class LoginDecoder extends StatefulFrameDecoder<LoginDecoderState>
|
||||
int uid = secure.readInt();
|
||||
String username = BufferUtil.readString(secure);
|
||||
String password = BufferUtil.readString(secure);
|
||||
InetSocketAddress socketAddress = (InetSocketAddress) ctx.channel().remoteAddress();
|
||||
String hostAddress = InetAddresses.toAddrString(socketAddress.getAddress());
|
||||
|
||||
if (password.length() < 6 || password.length() > 20 || username.isEmpty() || username.length() > 12) {
|
||||
writeResponseCode(ctx, LoginConstants.STATUS_INVALID_CREDENTIALS);
|
||||
@@ -193,7 +198,7 @@ public final class LoginDecoder extends StatefulFrameDecoder<LoginDecoderState>
|
||||
|
||||
IsaacRandom encodingRandom = new IsaacRandom(seed);
|
||||
|
||||
PlayerCredentials credentials = new PlayerCredentials(username, password, usernameHash, uid);
|
||||
PlayerCredentials credentials = new PlayerCredentials(username, password, usernameHash, uid, hostAddress);
|
||||
IsaacRandomPair randomPair = new IsaacRandomPair(encodingRandom, decodingRandom);
|
||||
|
||||
out.add(new LoginRequest(credentials, randomPair, reconnecting, lowMemory, release, crcs, version));
|
||||
@@ -207,7 +212,7 @@ public final class LoginDecoder extends StatefulFrameDecoder<LoginDecoderState>
|
||||
* @param response The response code to write.
|
||||
*/
|
||||
private void writeResponseCode(ChannelHandlerContext ctx, int response) {
|
||||
ByteBuf buffer = ctx.alloc().buffer(1);
|
||||
ByteBuf buffer = ctx.alloc().buffer(Byte.BYTES);
|
||||
buffer.writeByte(response);
|
||||
|
||||
ctx.write(buffer).addListener(ChannelFutureListener.CLOSE);
|
||||
|
||||
@@ -34,6 +34,11 @@ public final class PlayerCredentials {
|
||||
*/
|
||||
private final int usernameHash;
|
||||
|
||||
/**
|
||||
* The Player's host address, represented as a String.
|
||||
*/
|
||||
private final String hostAddress;
|
||||
|
||||
/**
|
||||
* Creates a new {@link PlayerCredentials} object with the specified name, password and uid.
|
||||
*
|
||||
@@ -41,13 +46,15 @@ public final class PlayerCredentials {
|
||||
* @param password The player's password.
|
||||
* @param usernameHash The hash of the player's username.
|
||||
* @param uid The computer's uid.
|
||||
* @param hostAddress The Player's connecting host address.
|
||||
*/
|
||||
public PlayerCredentials(String username, String password, int usernameHash, int uid) {
|
||||
public PlayerCredentials(String username, String password, int usernameHash, int uid, String hostAddress) {
|
||||
this.username = username;
|
||||
encodedUsername = NameUtil.encodeBase37(username);
|
||||
this.password = password;
|
||||
this.usernameHash = usernameHash;
|
||||
this.uid = uid;
|
||||
this.hostAddress = hostAddress;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,6 +111,15 @@ public final class PlayerCredentials {
|
||||
return usernameHash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Player's connecting host address.
|
||||
*
|
||||
* @return The Player's host address, represented as a String.
|
||||
*/
|
||||
public String getHostAddress() {
|
||||
return hostAddress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Long.hashCode(encodedUsername);
|
||||
|
||||
Reference in New Issue
Block a user