Skip to content

Commit

Permalink
ConnectionInfo renaming, ByteBuf writeXXX method switched.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle Fricilone authored and Adam- committed Jun 8, 2016
1 parent 1c9d8b1 commit 16d0040
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 25 deletions.
17 changes: 13 additions & 4 deletions cache/src/main/java/net/runelite/cache/downloader/CacheClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,18 @@ public void initChannel(SocketChannel ch) throws Exception

public void stop()
{
group.shutdownGracefully();
try
{
channel.closeFuture().sync();
}
catch (InterruptedException e)
{
logger.warn(null, e);
}
finally
{
group.shutdownGracefully();
}
}

public int getClientRevision()
Expand Down Expand Up @@ -224,9 +235,7 @@ public synchronized CompletableFuture<FileResult> requestFile(int index, int fil

buf.writeByte(request.getIndex() == 255 ? 1 : 0);
int hash = pf.computeHash();
buf.writeByte(hash >> 16);
buf.writeByte(hash >> 8);
buf.writeByte(hash);
buf.writeMedium(hash);

logger.trace("Sending request for {}/{}", index, fileId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void channelActive(ChannelHandlerContext ctx)
msg.setRevision(client.getClientRevision());

ByteBuf message = Unpooled.buffer(5);
message.writeByte(msg.getVersion()); // handshake type
message.writeByte(msg.getType()); // handshake type
message.writeInt(msg.getRevision()); // client revision

ctx.writeAndFlush(message);
Expand Down Expand Up @@ -97,10 +97,8 @@ public void channelRead(ChannelHandlerContext ctx, Object msg)

ConnectionInfo cinfo = new ConnectionInfo();
ByteBuf outbuf = Unpooled.buffer(4);
outbuf.writeByte(cinfo.getVar1());
outbuf.writeByte(cinfo.getVar2() >> 16);
outbuf.writeByte(cinfo.getVar2() >> 8);
outbuf.writeByte(cinfo.getVar2());
outbuf.writeByte(cinfo.getType());
outbuf.writeMedium(cinfo.getPadding());

ctx.writeAndFlush(outbuf);
state = ClientState.CONNECTED;
Expand All @@ -110,7 +108,7 @@ else if (state == ClientState.CONNECTED)
ByteBuf copy = buffer.slice();

int index = copy.readUnsignedByte();
int file = copy.readShort();
int file = copy.readUnsignedShort();
// decompress() starts reading here
int compression = copy.readUnsignedByte();
int compressedFileSize = copy.readInt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,31 @@

public class ConnectionInfo
{
private byte var1 = 3; // I don't know what this is
private int var2;
//login state of client
// 2 - logged in (in-game)
// 3 - logged out (not in-game)
private byte type = 3;

public byte getVar1()
//padding to make packet size == 4
private int padding;

public byte getType()
{
return var1;
return type;
}

public void setVar1(byte var1)
public void setType(byte type)
{
this.var1 = var1;
this.type = type;
}

public int getVar2()
public int getPadding()
{
return var2;
return padding;
}

public void setVar2(int var2)
public void setPadding(int padding)
{
this.var2 = var2;
this.padding = padding;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class HelloHandshake
public static final int RESPONSE_OK = 0;
public static final int RESPONSE_OUTDATED = 6;

private byte version = 15; // handshake type
private byte type = 15; // handshake type
private int revision;

public int getRevision()
Expand All @@ -47,14 +47,14 @@ public void setRevision(int revision)
{
this.revision = revision;
}
public byte getVersion()
public byte getType()
{
return version;
return type;
}

public void setVersion(byte version)
public void setType(byte type)
{
this.version = version;
this.type = type;
}

}

0 comments on commit 16d0040

Please sign in to comment.