RuneHive-Game
Loading...
Searching...
No Matches
OnDemandRequestDecoder.java
Go to the documentation of this file.
1package dev.advo.fs.net.ondemand;
2
3
4import org.jboss.netty.buffer.ChannelBuffer;
5import org.jboss.netty.channel.Channel;
6import org.jboss.netty.channel.ChannelHandlerContext;
7import org.jboss.netty.handler.codec.frame.FrameDecoder;
8
9import dev.advo.fs.fs.FileDescriptor;
10
11public final class OnDemandRequestDecoder extends FrameDecoder {
12
13 @Override
14 protected Object decode(ChannelHandlerContext ctx, Channel c, ChannelBuffer buf) throws Exception {
15// System.out.println("corrupted request" + buf.readableBytes());//lmfao.
16// for(int i = 0; i < buf.readableBytes(); i++)
17// System.out.println("corrupted request " + i + " " + buf.readByte());
18 if (buf.readableBytes() >= 4) {
19 int check = buf.readUnsignedByte();
20 if(check != 1) {
21 System.out.println("corrupted request " + check);
22
23 //After the client submits type 0 for VT. All requestions should be 1.
24 return null;
25 }
26 int hashed = buf.readMedium();
27 int type = index(hashed);
28 int file = file(hashed);
29 System.out.println("requesting file " + type + " - " + file);
30
31 FileDescriptor desc = new FileDescriptor(type, file);
32
33 return new OnDemandRequest(desc);
34 } else
35 return null;
36 }
37
38 public static int index(int pair) {
39 return pair & 0x1F;
40 }
41
42 public static int file(int pair) {
43 return pair >>> 5 & 0x7FFFF;
44 }
45}
A class which points to a file in the cache.
Object decode(ChannelHandlerContext ctx, Channel c, ChannelBuffer buf)