mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-06 16:51:37 +00:00
Reorder methods in StatefulFrameDecoder, make minor name changes to local variables in LoginDecoder.
This commit is contained in:
@@ -105,14 +105,14 @@ public final class LoginDecoder extends StatefulFrameDecoder<LoginDecoderState>
|
|||||||
*/
|
*/
|
||||||
private void decodeHeader(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) {
|
private void decodeHeader(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) {
|
||||||
if (buffer.readableBytes() >= 2) {
|
if (buffer.readableBytes() >= 2) {
|
||||||
int loginType = buffer.readUnsignedByte();
|
int type = buffer.readUnsignedByte();
|
||||||
|
|
||||||
if (loginType != LoginConstants.TYPE_STANDARD && loginType != LoginConstants.TYPE_RECONNECTION) {
|
if (type != LoginConstants.TYPE_STANDARD && type != LoginConstants.TYPE_RECONNECTION) {
|
||||||
writeResponseCode(ctx, LoginConstants.STATUS_LOGIN_SERVER_REJECTED_SESSION);
|
writeResponseCode(ctx, LoginConstants.STATUS_LOGIN_SERVER_REJECTED_SESSION);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
reconnecting = loginType == LoginConstants.TYPE_RECONNECTION;
|
reconnecting = type == LoginConstants.TYPE_RECONNECTION;
|
||||||
loginLength = buffer.readUnsignedByte();
|
loginLength = buffer.readUnsignedByte();
|
||||||
|
|
||||||
setState(LoginDecoderState.LOGIN_PAYLOAD);
|
setState(LoginDecoderState.LOGIN_PAYLOAD);
|
||||||
@@ -129,53 +129,51 @@ public final class LoginDecoder extends StatefulFrameDecoder<LoginDecoderState>
|
|||||||
private void decodePayload(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) {
|
private void decodePayload(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) {
|
||||||
if (buffer.readableBytes() >= loginLength) {
|
if (buffer.readableBytes() >= loginLength) {
|
||||||
ByteBuf payload = buffer.readBytes(loginLength);
|
ByteBuf payload = buffer.readBytes(loginLength);
|
||||||
int clientVersion = 255 - payload.readUnsignedByte();
|
int version = 255 - payload.readUnsignedByte();
|
||||||
|
|
||||||
int releaseNumber = payload.readUnsignedShort();
|
int release = payload.readUnsignedShort();
|
||||||
|
|
||||||
int lowMemoryFlag = payload.readUnsignedByte();
|
int memoryStatus = payload.readUnsignedByte();
|
||||||
if (lowMemoryFlag != 0 && lowMemoryFlag != 1) {
|
if (memoryStatus != 0 && memoryStatus != 1) {
|
||||||
writeResponseCode(ctx, LoginConstants.STATUS_LOGIN_SERVER_REJECTED_SESSION);
|
writeResponseCode(ctx, LoginConstants.STATUS_LOGIN_SERVER_REJECTED_SESSION);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean lowMemory = lowMemoryFlag == 1;
|
boolean lowMemory = memoryStatus == 1;
|
||||||
|
|
||||||
int[] archiveCrcs = new int[FileSystemConstants.ARCHIVE_COUNT];
|
int[] crcs = new int[FileSystemConstants.ARCHIVE_COUNT];
|
||||||
for (int i = 0; i < 9; i++) {
|
for (int index = 0; index < 9; index++) {
|
||||||
archiveCrcs[i] = payload.readInt();
|
crcs[index] = payload.readInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
int securePayloadLength = payload.readUnsignedByte();
|
int length = payload.readUnsignedByte();
|
||||||
if (securePayloadLength != loginLength - 41) {
|
if (length != loginLength - 41) {
|
||||||
writeResponseCode(ctx, LoginConstants.STATUS_LOGIN_SERVER_REJECTED_SESSION);
|
writeResponseCode(ctx, LoginConstants.STATUS_LOGIN_SERVER_REJECTED_SESSION);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ByteBuf securePayload = payload.readBytes(securePayloadLength);
|
ByteBuf secure = payload.readBytes(length);
|
||||||
|
|
||||||
BigInteger bigInteger = new BigInteger(securePayload.array());
|
BigInteger value = new BigInteger(secure.array());
|
||||||
bigInteger = bigInteger.modPow(NetworkConstants.RSA_EXPONENT, NetworkConstants.RSA_MODULUS);
|
value = value.modPow(NetworkConstants.RSA_EXPONENT, NetworkConstants.RSA_MODULUS);
|
||||||
|
secure = Unpooled.wrappedBuffer(value.toByteArray());
|
||||||
|
|
||||||
securePayload = Unpooled.wrappedBuffer(bigInteger.toByteArray());
|
int id = secure.readUnsignedByte();
|
||||||
|
if (id != 10) {
|
||||||
int secureId = securePayload.readUnsignedByte();
|
|
||||||
if (secureId != 10) {
|
|
||||||
writeResponseCode(ctx, LoginConstants.STATUS_LOGIN_SERVER_REJECTED_SESSION);
|
writeResponseCode(ctx, LoginConstants.STATUS_LOGIN_SERVER_REJECTED_SESSION);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
long clientSeed = securePayload.readLong();
|
long clientSeed = secure.readLong();
|
||||||
long reportedServerSeed = securePayload.readLong();
|
long reportedSeed = secure.readLong();
|
||||||
if (reportedServerSeed != serverSeed) {
|
if (reportedSeed != serverSeed) {
|
||||||
writeResponseCode(ctx, LoginConstants.STATUS_LOGIN_SERVER_REJECTED_SESSION);
|
writeResponseCode(ctx, LoginConstants.STATUS_LOGIN_SERVER_REJECTED_SESSION);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int uid = securePayload.readInt();
|
int uid = secure.readInt();
|
||||||
|
String username = BufferUtil.readString(secure);
|
||||||
String username = BufferUtil.readString(securePayload);
|
String password = BufferUtil.readString(secure);
|
||||||
String password = BufferUtil.readString(securePayload);
|
|
||||||
|
|
||||||
if (password.length() < 6 || password.length() > 20 || username.isEmpty() || username.length() > 12) {
|
if (password.length() < 6 || password.length() > 20 || username.isEmpty() || username.length() > 12) {
|
||||||
writeResponseCode(ctx, LoginConstants.STATUS_INVALID_CREDENTIALS);
|
writeResponseCode(ctx, LoginConstants.STATUS_INVALID_CREDENTIALS);
|
||||||
@@ -189,8 +187,8 @@ public final class LoginDecoder extends StatefulFrameDecoder<LoginDecoderState>
|
|||||||
seed[3] = (int) serverSeed;
|
seed[3] = (int) serverSeed;
|
||||||
|
|
||||||
IsaacRandom decodingRandom = new IsaacRandom(seed);
|
IsaacRandom decodingRandom = new IsaacRandom(seed);
|
||||||
for (int i = 0; i < seed.length; i++) {
|
for (int index = 0; index < seed.length; index++) {
|
||||||
seed[i] += 50;
|
seed[index] += 50;
|
||||||
}
|
}
|
||||||
|
|
||||||
IsaacRandom encodingRandom = new IsaacRandom(seed);
|
IsaacRandom encodingRandom = new IsaacRandom(seed);
|
||||||
@@ -198,9 +196,7 @@ public final class LoginDecoder extends StatefulFrameDecoder<LoginDecoderState>
|
|||||||
PlayerCredentials credentials = new PlayerCredentials(username, password, usernameHash, uid);
|
PlayerCredentials credentials = new PlayerCredentials(username, password, usernameHash, uid);
|
||||||
IsaacRandomPair randomPair = new IsaacRandomPair(encodingRandom, decodingRandom);
|
IsaacRandomPair randomPair = new IsaacRandomPair(encodingRandom, decodingRandom);
|
||||||
|
|
||||||
LoginRequest request = new LoginRequest(credentials, randomPair, reconnecting, lowMemory, releaseNumber, archiveCrcs, clientVersion);
|
out.add(new LoginRequest(credentials, randomPair, reconnecting, lowMemory, release, crcs, version));
|
||||||
|
|
||||||
out.add(request);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,11 +204,11 @@ public final class LoginDecoder extends StatefulFrameDecoder<LoginDecoderState>
|
|||||||
* Writes a response code to the client and closes the current channel.
|
* Writes a response code to the client and closes the current channel.
|
||||||
*
|
*
|
||||||
* @param ctx The context of the channel handler.
|
* @param ctx The context of the channel handler.
|
||||||
* @param responseCode The response code to write.
|
* @param response The response code to write.
|
||||||
*/
|
*/
|
||||||
private void writeResponseCode(ChannelHandlerContext ctx, int responseCode) {
|
private void writeResponseCode(ChannelHandlerContext ctx, int response) {
|
||||||
ByteBuf buffer = ctx.alloc().buffer(1);
|
ByteBuf buffer = ctx.alloc().buffer(1);
|
||||||
buffer.writeByte(responseCode);
|
buffer.writeByte(response);
|
||||||
|
|
||||||
ctx.writeAndFlush(buffer).addListener(ChannelFutureListener.CLOSE);
|
ctx.writeAndFlush(buffer).addListener(ChannelFutureListener.CLOSE);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,16 @@ public abstract class StatefulFrameDecoder<T extends Enum<T>> extends ByteToMess
|
|||||||
setState(state);
|
setState(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a new state.
|
||||||
|
*
|
||||||
|
* @param state The new state.
|
||||||
|
* @throws NullPointerException If the state is {@code null}.
|
||||||
|
*/
|
||||||
|
public final void setState(T state) {
|
||||||
|
this.state = Objects.requireNonNull(state, "State cannot be null.");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected final void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
|
protected final void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
|
||||||
decode(ctx, in, out, state);
|
decode(ctx, in, out, state);
|
||||||
@@ -54,14 +64,4 @@ public abstract class StatefulFrameDecoder<T extends Enum<T>> extends ByteToMess
|
|||||||
*/
|
*/
|
||||||
protected abstract void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out, T state) throws Exception;
|
protected abstract void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out, T state) throws Exception;
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets a new state.
|
|
||||||
*
|
|
||||||
* @param state The new state.
|
|
||||||
* @throws NullPointerException If the state is {@code null}.
|
|
||||||
*/
|
|
||||||
public final void setState(T state) {
|
|
||||||
this.state = Objects.requireNonNull(state, "State cannot be null.");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user