Added fake player creation upon connection for the msg pipeline.

This commit is contained in:
ProfMobius committed 2014-10-02 00:19:36 +02:00
1 parent 6eb3e5880c
commit e127d4426a
3 files changed
+52 -3

No files matched your search

@@ -1,5 +1,13 @@
package mcp.mobius.opis.network.rconserver;
import java.util.UUID;
import com.mojang.authlib.GameProfile;
import mcp.mobius.opis.modOpis;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.common.util.FakePlayerFactory;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
@@ -7,17 +15,24 @@ import io.netty.util.ReferenceCountUtil;
class RConInboundHandler extends ChannelInboundHandlerAdapter{
// One object of this type is created by connection
// There is one permanent context per connection !
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
// This method is called when the connection is created.
ctx.fireChannelActive();
UUID fakeUUID = UUID.randomUUID();
FakePlayer fakePlayer = FakePlayerFactory.get(DimensionManager.getWorld(0), new GameProfile(fakeUUID, ctx.name()));
RConServer.instance.fakePlayers.put(fakePlayer, ctx);
modOpis.log.info(String.format("Connection to rcon detected. FakePlayer %s with uuid %s created.", ctx.name(), fakeUUID));
}
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
// This method is called when new data is readable in the stream.
System.out.printf("Context : %s\n", ctx);
ctx.write(msg);
ctx.flush();
@@ -31,7 +46,7 @@ class RConInboundHandler extends ChannelInboundHandlerAdapter{
} finally {
ReferenceCountUtil.release(msg);
}
*/
*/
}
@Override
@@ -1,5 +1,8 @@
package mcp.mobius.opis.network.rconserver;
import java.util.HashMap;
import net.minecraftforge.common.util.FakePlayer;
import mcp.mobius.opis.modOpis;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.ByteBuf;
@@ -17,6 +20,8 @@ import io.netty.util.ReferenceCountUtil;
public class RConServer implements Runnable {
public final static RConServer instance = new RConServer();
public HashMap<FakePlayer, ChannelHandlerContext> fakePlayers = new HashMap<FakePlayer, ChannelHandlerContext>();
private int port = -1;
private RConServer(){