Remove cache-server
It was split to https://github.com/runelite/cache-server
This commit is contained in:
@@ -1,86 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Copyright (c) 2016-2017, Adam <Adam@sigterm.info>
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>net.runelite</groupId>
|
||||
<artifactId>runelite-parent</artifactId>
|
||||
<version>1.5.5-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>cache-server</artifactId>
|
||||
<name>Cache Server</name>
|
||||
|
||||
<properties>
|
||||
<cache.version>165</cache.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>net.runelite</groupId>
|
||||
<artifactId>cache</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.runelite</groupId>
|
||||
<artifactId>protocol</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-simple</artifactId>
|
||||
<version>1.7.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.runelite</groupId>
|
||||
<artifactId>cache</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>test-jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.runelite.rs</groupId>
|
||||
<artifactId>cache</artifactId>
|
||||
<version>${cache.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.runelite</groupId>
|
||||
<artifactId>cache-client</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -1,158 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016-2017, Adam <Adam@sigterm.info>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.runelite.cache.server;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import net.runelite.cache.fs.Archive;
|
||||
import net.runelite.cache.fs.Container;
|
||||
import net.runelite.cache.fs.Index;
|
||||
import net.runelite.cache.fs.Storage;
|
||||
import net.runelite.cache.fs.Store;
|
||||
import net.runelite.cache.fs.jagex.CompressionType;
|
||||
import net.runelite.cache.fs.jagex.DiskStorage;
|
||||
import net.runelite.protocol.api.update.ArchiveRequestPacket;
|
||||
import net.runelite.protocol.api.update.ArchiveResponsePacket;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ArchiveRequestHandler extends SimpleChannelInboundHandler<ArchiveRequestPacket>
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(ArchiveRequestHandler.class);
|
||||
|
||||
private final Store store;
|
||||
|
||||
public ArchiveRequestHandler(Store store)
|
||||
{
|
||||
this.store = store;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void channelRead0(ChannelHandlerContext ctx, ArchiveRequestPacket archiveRequest) throws Exception
|
||||
{
|
||||
if (archiveRequest.getIndex() == 255)
|
||||
{
|
||||
handleRequest255(ctx, archiveRequest.getIndex(),
|
||||
archiveRequest.getArchive());
|
||||
}
|
||||
else
|
||||
{
|
||||
handleRequest(ctx, archiveRequest.getIndex(),
|
||||
archiveRequest.getArchive());
|
||||
}
|
||||
}
|
||||
|
||||
private void handleRequest255(ChannelHandlerContext ctx, int index, int archiveId) throws IOException
|
||||
{
|
||||
logger.info("Client {} requests 255: index {}, archive {}", ctx.channel().remoteAddress(), index, archiveId);
|
||||
|
||||
byte[] compressed;
|
||||
if (archiveId == 255)
|
||||
{
|
||||
// index 255 data, for each index:
|
||||
// 4 byte crc
|
||||
// 4 byte revision
|
||||
ByteBuf buffer = ctx.alloc().heapBuffer(store.getIndexes().size() * 8);
|
||||
for (Index i : store.getIndexes())
|
||||
{
|
||||
buffer.writeInt(i.getCrc());
|
||||
buffer.writeInt(i.getRevision());
|
||||
}
|
||||
|
||||
compressed = compress(CompressionType.NONE, Arrays.copyOf(buffer.array(), buffer.readableBytes()));
|
||||
buffer.release();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Requires disk storage. Use packed index data from
|
||||
// store as its crc matches
|
||||
DiskStorage storage = (DiskStorage) store.getStorage();
|
||||
compressed = storage.readIndex(archiveId);
|
||||
}
|
||||
|
||||
ArchiveResponsePacket response = new ArchiveResponsePacket();
|
||||
response.setIndex(index);
|
||||
response.setArchive(archiveId);
|
||||
response.setData(compressed);
|
||||
|
||||
ctx.writeAndFlush(response);
|
||||
}
|
||||
|
||||
private void handleRequest(ChannelHandlerContext ctx, int index, int archiveId) throws IOException
|
||||
{
|
||||
logger.info("Client {} requests index {} archive {}", ctx.channel().remoteAddress(), index, archiveId);
|
||||
|
||||
Index i = store.findIndex(index);
|
||||
assert i != null;
|
||||
|
||||
Archive archive = i.getArchive(archiveId);
|
||||
assert archive != null;
|
||||
|
||||
Storage storage = store.getStorage();
|
||||
byte[] packed = storage.loadArchive(archive); // is compressed, includes length and type
|
||||
|
||||
if (packed == null)
|
||||
{
|
||||
logger.warn("Missing archive {}/{}", index, archiveId);
|
||||
return; // is it possible to notify the client of an error with this?
|
||||
}
|
||||
|
||||
byte compression = packed[0];
|
||||
int compressedSize = Ints.fromBytes(packed[1], packed[2],
|
||||
packed[3], packed[4]);
|
||||
|
||||
// size the client expects the data to be
|
||||
int expectedSize = 1 // compression type
|
||||
+ 4 // compressed size
|
||||
+ compressedSize
|
||||
+ (compression != CompressionType.NONE ? 4 : 0);
|
||||
if (packed.length != expectedSize)
|
||||
{
|
||||
// It may have the archive revision appended at the end.
|
||||
// The data the client writes will have it, but the data fetched from
|
||||
// the update server will never have it
|
||||
assert packed.length - expectedSize == 2 : "packed length != expected size";
|
||||
packed = Arrays.copyOf(packed, packed.length - 2);
|
||||
}
|
||||
|
||||
ArchiveResponsePacket response = new ArchiveResponsePacket();
|
||||
response.setIndex(index);
|
||||
response.setArchive(archiveId);
|
||||
response.setData(packed);
|
||||
|
||||
ctx.writeAndFlush(response);
|
||||
}
|
||||
|
||||
private byte[] compress(int compression, byte[] data) throws IOException
|
||||
{
|
||||
Container container = new Container(compression, -1);
|
||||
container.compress(data, null);
|
||||
return container.data;
|
||||
}
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016-2017, Adam <Adam@sigterm.info>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.runelite.cache.server;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.ByteToMessageDecoder;
|
||||
import java.util.List;
|
||||
import static net.runelite.protocol.update.decoders.UpdateOpcodes.ARCHIVE_REQUEST_HIGH;
|
||||
import static net.runelite.protocol.update.decoders.UpdateOpcodes.ARCHIVE_REQUEST_LOW;
|
||||
import static net.runelite.protocol.update.decoders.UpdateOpcodes.CLIENT_LOGGED_IN;
|
||||
import static net.runelite.protocol.update.decoders.UpdateOpcodes.CLIENT_LOGGED_OUT;
|
||||
import static net.runelite.protocol.update.decoders.UpdateOpcodes.ENCRYPTION;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class CacheFrameDecoder extends ByteToMessageDecoder
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(CacheFrameDecoder.class);
|
||||
|
||||
@Override
|
||||
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception
|
||||
{
|
||||
in.markReaderIndex();
|
||||
byte opcode = in.readByte();
|
||||
in.resetReaderIndex();
|
||||
|
||||
int length;
|
||||
|
||||
switch (opcode)
|
||||
{
|
||||
case ARCHIVE_REQUEST_LOW:
|
||||
case ARCHIVE_REQUEST_HIGH:
|
||||
case CLIENT_LOGGED_IN:
|
||||
case CLIENT_LOGGED_OUT:
|
||||
case ENCRYPTION:
|
||||
length = 4;
|
||||
break;
|
||||
default:
|
||||
logger.debug("Unknown packet opcode from {}: {}",
|
||||
ctx.channel().remoteAddress(), opcode);
|
||||
ctx.close();
|
||||
return;
|
||||
}
|
||||
|
||||
if (in.readableBytes() < length)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ByteBuf packet = in.readRetainedSlice(length);
|
||||
out.add(packet);
|
||||
}
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Adam <Adam@sigterm.info>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.runelite.cache.server;
|
||||
|
||||
import io.netty.bootstrap.ServerBootstrap;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.channel.EventLoopGroup;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||
import net.runelite.cache.fs.Store;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class CacheServer implements AutoCloseable
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(CacheServer.class);
|
||||
|
||||
private static final int PORT = 43594;
|
||||
|
||||
private final EventLoopGroup group = new NioEventLoopGroup(1);
|
||||
|
||||
private Channel channel;
|
||||
|
||||
private final Store store;
|
||||
private final int revision;
|
||||
|
||||
public CacheServer(Store store, int revision)
|
||||
{
|
||||
this.store = store;
|
||||
this.revision = revision;
|
||||
}
|
||||
|
||||
public void start()
|
||||
{
|
||||
ServerBootstrap b = new ServerBootstrap();
|
||||
b.group(group)
|
||||
.channel(NioServerSocketChannel.class)
|
||||
.option(ChannelOption.TCP_NODELAY, true)
|
||||
.childHandler(new CacheServerInitializer(this));
|
||||
|
||||
ChannelFuture f = b.bind(PORT).syncUninterruptibly();
|
||||
channel = f.channel();
|
||||
|
||||
logger.info("Server is now listening on {}", PORT);
|
||||
}
|
||||
|
||||
public void waitForClose()
|
||||
{
|
||||
channel.closeFuture().awaitUninterruptibly();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close()
|
||||
{
|
||||
channel.close().syncUninterruptibly();
|
||||
group.shutdownGracefully();
|
||||
}
|
||||
|
||||
public int getRevision()
|
||||
{
|
||||
return revision;
|
||||
}
|
||||
|
||||
public Store getStore()
|
||||
{
|
||||
return store;
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016-2017, Adam <Adam@sigterm.info>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.runelite.cache.server;
|
||||
|
||||
import io.netty.channel.ChannelInitializer;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import net.runelite.protocol.update.decoders.ArchiveRequestDecoder;
|
||||
import net.runelite.protocol.update.decoders.EncryptionDecoder;
|
||||
import net.runelite.protocol.update.encoders.ArchiveResponseEncoder;
|
||||
import net.runelite.protocol.update.encoders.XorEncoder;
|
||||
import net.runelite.protocol.handshake.HandshakeDecoder;
|
||||
import net.runelite.protocol.handshake.HandshakeResponseEncoder;
|
||||
|
||||
public class CacheServerInitializer extends ChannelInitializer<SocketChannel>
|
||||
{
|
||||
private final CacheServer server;
|
||||
|
||||
public CacheServerInitializer(CacheServer server)
|
||||
{
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initChannel(SocketChannel ch) throws Exception
|
||||
{
|
||||
ChannelPipeline p = ch.pipeline();
|
||||
|
||||
p.addLast(
|
||||
new HandshakeDecoder(),
|
||||
new CacheFrameDecoder(),
|
||||
new EncryptionDecoder(),
|
||||
new ArchiveRequestDecoder()
|
||||
);
|
||||
|
||||
p.addLast(
|
||||
new HandshakeResponseEncoder(),
|
||||
new XorEncoder(),
|
||||
new ArchiveResponseEncoder()
|
||||
);
|
||||
|
||||
p.addLast(
|
||||
new ArchiveRequestHandler(server.getStore()),
|
||||
new EncryptionHandler(),
|
||||
new HandshakeHandler(server)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016-2017, Adam <Adam@sigterm.info>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.runelite.cache.server;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import net.runelite.protocol.update.encoders.XorEncoder;
|
||||
import net.runelite.protocol.api.update.EncryptionPacket;
|
||||
|
||||
public class EncryptionHandler extends SimpleChannelInboundHandler<EncryptionPacket>
|
||||
{
|
||||
|
||||
@Override
|
||||
protected void channelRead0(ChannelHandlerContext ctx, EncryptionPacket encryptionPacket) throws Exception
|
||||
{
|
||||
ChannelPipeline p = ctx.pipeline();
|
||||
XorEncoder xorEncoder = p.get(XorEncoder.class);
|
||||
if (xorEncoder != null)
|
||||
{
|
||||
xorEncoder.setKey(encryptionPacket.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2016-2017, Adam <Adam@sigterm.info>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.runelite.cache.server;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import net.runelite.protocol.api.handshake.HandshakeResponsePacket;
|
||||
import net.runelite.protocol.api.login.HandshakeResponseType;
|
||||
import net.runelite.protocol.api.handshake.UpdateHandshakePacket;
|
||||
import net.runelite.protocol.handshake.HandshakeDecoder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class HandshakeHandler extends SimpleChannelInboundHandler<UpdateHandshakePacket>
|
||||
{
|
||||
private static final Logger logger = LoggerFactory.getLogger(HandshakeHandler.class);
|
||||
|
||||
private final CacheServer server;
|
||||
|
||||
public HandshakeHandler(CacheServer server)
|
||||
{
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void channelRead0(ChannelHandlerContext ctx, UpdateHandshakePacket handshakePacket) throws Exception
|
||||
{
|
||||
ChannelPipeline pipeline = ctx.pipeline();
|
||||
|
||||
if (handshakePacket.getRevision() != server.getRevision())
|
||||
{
|
||||
logger.warn("Incorrect version for client {}, expected {}",
|
||||
handshakePacket.getRevision(), server.getRevision());
|
||||
ctx.close();
|
||||
return;
|
||||
}
|
||||
|
||||
logger.info("Handshake complete from client {}, revision {}",
|
||||
ctx.channel().remoteAddress(),
|
||||
handshakePacket.getRevision());
|
||||
|
||||
HandshakeResponsePacket handshakeResponse = new HandshakeResponsePacket();
|
||||
handshakeResponse.setResponse(HandshakeResponseType.RESPONSE_OK);
|
||||
ctx.channel().writeAndFlush(handshakeResponse);
|
||||
|
||||
pipeline.remove(HandshakeDecoder.class);
|
||||
pipeline.addFirst(new CacheFrameDecoder());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,125 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2017, Adam <Adam@sigterm.info>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package net.runelite.cache.server;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import net.runelite.cache.StoreLocation;
|
||||
import net.runelite.cache.client.CacheClient;
|
||||
import net.runelite.cache.fs.Archive;
|
||||
import net.runelite.cache.fs.Container;
|
||||
import net.runelite.cache.fs.Index;
|
||||
import net.runelite.cache.fs.Storage;
|
||||
import net.runelite.cache.fs.Store;
|
||||
import net.runelite.cache.index.FileData;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
public class CacheServerTest
|
||||
{
|
||||
private static final String HOST = "localhost";
|
||||
private static final int REVISION = 154;
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder folder = StoreLocation.getTemporaryFolder();
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testDownload() throws Exception
|
||||
{
|
||||
try (Store store = new Store(StoreLocation.LOCATION);
|
||||
CacheServer server = new CacheServer(store, REVISION))
|
||||
{
|
||||
store.load();
|
||||
|
||||
server.start();
|
||||
|
||||
try (CacheClient client = new CacheClient(new Store(folder.newFolder()), HOST, REVISION))
|
||||
{
|
||||
client.connect();
|
||||
client.handshake().get();
|
||||
client.download();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testServer() throws Exception
|
||||
{
|
||||
try (Store store = new Store(folder.newFolder());
|
||||
CacheServer server = new CacheServer(store, REVISION))
|
||||
{
|
||||
addInitialFilesToStore(store);
|
||||
|
||||
store.save();
|
||||
|
||||
server.start();
|
||||
|
||||
try (Store store2 = new Store(folder.newFolder());
|
||||
CacheClient client = new CacheClient(store2, HOST, REVISION))
|
||||
{
|
||||
client.connect();
|
||||
client.handshake().get();
|
||||
client.download();
|
||||
|
||||
Index index = store2.findIndex(0);
|
||||
Archive archive = index.getArchive(0);
|
||||
|
||||
FileData[] files = archive.getFileData();
|
||||
FileData file = files[0];
|
||||
assertEquals(7, file.getNameHash());
|
||||
|
||||
Storage storage = store2.getStorage();
|
||||
byte[] data = storage.loadArchive(archive);
|
||||
data = archive.decompress(data);
|
||||
assertArrayEquals("test".getBytes(), data);
|
||||
assertEquals(store.getIndexes().get(0).getArchive(0).getCrc(), archive.getCrc());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addInitialFilesToStore(Store store) throws FileNotFoundException, IOException
|
||||
{
|
||||
Storage storage = store.getStorage();
|
||||
Index index = store.addIndex(0);
|
||||
|
||||
Archive archive = index.addArchive(0);
|
||||
FileData[] files = new FileData[1];
|
||||
archive.setFileData(files);
|
||||
FileData file = files[0] = new FileData();
|
||||
file.setNameHash(7);
|
||||
byte[] data = "test".getBytes();
|
||||
|
||||
Container container = new Container(archive.getCompression(), -1);
|
||||
container.compress(data, null);
|
||||
byte[] compressedData = container.data;
|
||||
storage.saveArchive(archive, compressedData);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user