Skip to content

Commit

Permalink
Issue #29 Allow for varied login protocols using a login multiplexer
Browse files Browse the repository at this point in the history
decoder in conjunction with the port unification example
  • Loading branch information
menacher committed Dec 16, 2012
1 parent 9f01cf4 commit 1691c50
Show file tree
Hide file tree
Showing 12 changed files with 794 additions and 744 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,13 @@ public void operationComplete(ChannelFuture future) throws Exception
public static ChannelBuffer getLoginBuffer(String refKey, ChannelBuffer udpAddress)
{
ChannelBuffer opCode = ChannelBuffers.buffer(1);
ChannelBuffer protocol = ChannelBuffers.buffer(1);
opCode.writeByte(Events.LOG_IN);
protocol.writeByte(Events.PROTCOL_VERSION);
String username = "user";
String password = "pass";
// write username,password and ref key.
ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(opCode,
ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(opCode,protocol,
NettyUtils.writeStrings(username,password,refKey),udpAddress);
return buffer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
*/
public class Events
{
/**
* The protocol version. This will be sent along with the login message so
* that appropriate login handlers can be set in the pipeline.
*/
public static final byte PROTOCOL_VERSION = 0X01;
/**
* Events should <b>NEVER</b> have this type. But event handlers can choose
* to have this type to signify that they will handle any type of incoming
Expand Down
Original file line number Diff line number Diff line change
@@ -1,52 +1,61 @@
package org.menacheri.jetclient.handlers.netty;

import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandler.Sharable;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
import org.menacheri.jetclient.communication.MessageBuffer;
import org.menacheri.jetclient.event.Event;

/**
* Converts an incoming {@link Event} which in turn has a
* IMessageBuffer<ChannelBuffer> payload to a Netty {@link ChannelBuffer}.
* <b>Note that {@link Event} instances containing other type of objects as its
* payload will result in {@link ClassCastException}.
*
* @author Abraham Menacherry.
*
*/
@Sharable
public class MessageBufferEventEncoder extends OneToOneEncoder
{

@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel,
Object msg) throws Exception
{
if (null == msg)
{
return msg;
}
Event event = (Event) msg;
ChannelBuffer opCode = ChannelBuffers.buffer(1);
opCode.writeByte(event.getType());
ChannelBuffer buffer = null;
if (null != event.getSource())
{
@SuppressWarnings("unchecked")
MessageBuffer<ChannelBuffer> msgBuffer = (MessageBuffer<ChannelBuffer>) event
.getSource();
ChannelBuffer data = msgBuffer.getNativeBuffer();
buffer = ChannelBuffers.wrappedBuffer(opCode, data);
}
else
{
buffer = opCode;
}
return buffer;
}

}
package org.menacheri.jetclient.handlers.netty;

import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.jboss.netty.channel.Channel;
import org.jboss.netty.channel.ChannelHandler.Sharable;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
import org.menacheri.jetclient.communication.MessageBuffer;
import org.menacheri.jetclient.event.Event;
import org.menacheri.jetclient.event.Events;

/**
* Converts an incoming {@link Event} which in turn has a
* IMessageBuffer<ChannelBuffer> payload to a Netty {@link ChannelBuffer}.
* <b>Note that {@link Event} instances containing other type of objects as its
* payload will result in {@link ClassCastException}.
*
* @author Abraham Menacherry.
*
*/
@Sharable
public class MessageBufferEventEncoder extends OneToOneEncoder
{

@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel,
Object msg) throws Exception
{
if (null == msg)
{
return msg;
}
Event event = (Event) msg;
ChannelBuffer opCode = ChannelBuffers.buffer(1);
opCode.writeByte(event.getType());
if (Events.LOG_IN == event.getType())
{
// write protocol version also
ChannelBuffer protocolVersion = ChannelBuffers.buffer(1);
protocolVersion.writeByte(Events.PROTOCOL_VERSION);
opCode = ChannelBuffers.wrappedBuffer(opCode, protocolVersion);
}

ChannelBuffer buffer = null;
if (null != event.getSource())
{
@SuppressWarnings("unchecked")
MessageBuffer<ChannelBuffer> msgBuffer = (MessageBuffer<ChannelBuffer>) event
.getSource();
ChannelBuffer data = msgBuffer.getNativeBuffer();
buffer = ChannelBuffers.wrappedBuffer(opCode, data);
}
else
{
buffer = opCode;
}
return buffer;
}

}
114 changes: 57 additions & 57 deletions jetserver/.classpath
Original file line number Diff line number Diff line change
@@ -1,58 +1,58 @@
<classpath>
<classpathentry kind="src" path="src/test/java" output="target/test-classes" including="**/*.aj|**/*.java|**/*.aj"/>
<classpathentry kind="src" path="src/main/java" including="**/*.aj|**/*.java|**/*.aj"/>
<classpathentry kind="src" path="src/main/resources" excluding="**/*.java"/>
<classpathentry kind="output" path="target/classes"/>
<classpathentry kind="var" path="M2_REPO/aopalliance/aopalliance/1.0/aopalliance-1.0.jar" sourcepath="M2_REPO/aopalliance/aopalliance/1.0/aopalliance-1.0-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/backport-util-concurrent/backport-util-concurrent/3.1/backport-util-concurrent-3.1.jar" sourcepath="M2_REPO/backport-util-concurrent/backport-util-concurrent/3.1/backport-util-concurrent-3.1-sources.jar">
<attributes>
<attribute value="jar:file:/C:/Documents%20and%20Settings/abraham/.m2/repository/backport-util-concurrent/backport-util-concurrent/3.1/backport-util-concurrent-3.1-javadoc.jar!/" name="javadoc_location"/>
</attributes>
</classpathentry>
<classpathentry kind="var" path="M2_REPO/com/adobe/blazeds/blazeds-common/3.2.0.3978/blazeds-common-3.2.0.3978.jar" sourcepath="M2_REPO/com/adobe/blazeds/blazeds-common/3.2.0.3978/blazeds-common-3.2.0.3978-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/com/adobe/blazeds/blazeds-core/3.2.0.3978/blazeds-core-3.2.0.3978.jar" sourcepath="M2_REPO/com/adobe/blazeds/blazeds-core/3.2.0.3978/blazeds-core-3.2.0.3978-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/cglib/cglib-nodep/2.1_3/cglib-nodep-2.1_3.jar" sourcepath="M2_REPO/cglib/cglib-nodep/2.1_3/cglib-nodep-2.1_3-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar" sourcepath="M2_REPO/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1-sources.jar">
<attributes>
<attribute value="jar:file:/C:/Documents%20and%20Settings/abraham/.m2/repository/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1-javadoc.jar!/" name="javadoc_location"/>
</attributes>
</classpathentry>
<classpathentry kind="var" path="M2_REPO/org/jetlang/jetlang/0.2.9/jetlang-0.2.9.jar" sourcepath="M2_REPO/org/jetlang/jetlang/0.2.9/jetlang-0.2.9-sources.jar">
<attributes>
<attribute value="jar:file:/C:/Documents%20and%20Settings/abraham/.m2/repository/org/jetlang/jetlang/0.2.9/jetlang-0.2.9-javadoc.jar!/" name="javadoc_location"/>
</attributes>
</classpathentry>
<classpathentry kind="var" path="M2_REPO/junit/junit/4.8.2/junit-4.8.2.jar" sourcepath="M2_REPO/junit/junit/4.8.2/junit-4.8.2-sources.jar">
<attributes>
<attribute value="jar:file:/C:/Documents%20and%20Settings/abraham/.m2/repository/junit/junit/4.8.2/junit-4.8.2-javadoc.jar!/" name="javadoc_location"/>
</attributes>
</classpathentry>
<classpathentry kind="var" path="M2_REPO/log4j/log4j/1.2.16/log4j-1.2.16.jar" sourcepath="M2_REPO/log4j/log4j/1.2.16/log4j-1.2.16-sources.jar">
<attributes>
<attribute value="jar:file:/C:/Documents%20and%20Settings/abraham/.m2/repository/log4j/log4j/1.2.16/log4j-1.2.16-javadoc.jar!/" name="javadoc_location"/>
</attributes>
</classpathentry>
<classpathentry kind="var" path="M2_REPO/io/netty/netty/3.3.1.Final/netty-3.3.1.Final.jar" sourcepath="M2_REPO/io/netty/netty/3.3.1.Final/netty-3.3.1.Final-sources.jar">
<attributes>
<attribute value="jar:file:/C:/Documents%20and%20Settings/abraham/.m2/repository/io/netty/netty/3.3.1.Final/netty-3.3.1.Final-javadoc.jar!/" name="javadoc_location"/>
</attributes>
</classpathentry>
<classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-api/1.6.1/slf4j-api-1.6.1.jar" sourcepath="M2_REPO/org/slf4j/slf4j-api/1.6.1/slf4j-api-1.6.1-sources.jar">
<attributes>
<attribute value="jar:file:/C:/Documents%20and%20Settings/abraham/.m2/repository/org/slf4j/slf4j-api/1.6.1/slf4j-api-1.6.1-javadoc.jar!/" name="javadoc_location"/>
</attributes>
</classpathentry>
<classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-log4j12/1.6.1/slf4j-log4j12-1.6.1.jar" sourcepath="M2_REPO/org/slf4j/slf4j-log4j12/1.6.1/slf4j-log4j12-1.6.1-sources.jar">
<attributes>
<attribute value="jar:file:/C:/Documents%20and%20Settings/abraham/.m2/repository/org/slf4j/slf4j-log4j12/1.6.1/slf4j-log4j12-1.6.1-javadoc.jar!/" name="javadoc_location"/>
</attributes>
</classpathentry>
<classpathentry kind="var" path="M2_REPO/org/springframework/spring-aop/3.1.0.RELEASE/spring-aop-3.1.0.RELEASE.jar" sourcepath="M2_REPO/org/springframework/spring-aop/3.1.0.RELEASE/spring-aop-3.1.0.RELEASE-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/org/springframework/spring-asm/3.1.0.RELEASE/spring-asm-3.1.0.RELEASE.jar" sourcepath="M2_REPO/org/springframework/spring-asm/3.1.0.RELEASE/spring-asm-3.1.0.RELEASE-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/org/springframework/spring-beans/3.1.0.RELEASE/spring-beans-3.1.0.RELEASE.jar" sourcepath="M2_REPO/org/springframework/spring-beans/3.1.0.RELEASE/spring-beans-3.1.0.RELEASE-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/org/springframework/spring-context/3.1.0.RELEASE/spring-context-3.1.0.RELEASE.jar" sourcepath="M2_REPO/org/springframework/spring-context/3.1.0.RELEASE/spring-context-3.1.0.RELEASE-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/org/springframework/spring-core/3.1.0.RELEASE/spring-core-3.1.0.RELEASE.jar" sourcepath="M2_REPO/org/springframework/spring-core/3.1.0.RELEASE/spring-core-3.1.0.RELEASE-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/org/springframework/spring-expression/3.1.0.RELEASE/spring-expression-3.1.0.RELEASE.jar" sourcepath="M2_REPO/org/springframework/spring-expression/3.1.0.RELEASE/spring-expression-3.1.0.RELEASE-sources.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.ajdt.core.ASPECTJRT_CONTAINER"/>
<classpath>
<classpathentry kind="src" path="src/test/java" output="target/test-classes" including="**/*.aj|**/*.java|**/*.aj"/>
<classpathentry kind="src" path="src/main/java" including="**/*.aj|**/*.java|**/*.aj"/>
<classpathentry kind="src" path="src/main/resources" excluding="**/*.java"/>
<classpathentry kind="output" path="target/classes"/>
<classpathentry kind="var" path="M2_REPO/aopalliance/aopalliance/1.0/aopalliance-1.0.jar" sourcepath="M2_REPO/aopalliance/aopalliance/1.0/aopalliance-1.0-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/backport-util-concurrent/backport-util-concurrent/3.1/backport-util-concurrent-3.1.jar" sourcepath="M2_REPO/backport-util-concurrent/backport-util-concurrent/3.1/backport-util-concurrent-3.1-sources.jar">
<attributes>
<attribute value="jar:file:/C:/Users/aby/.m2/repository/backport-util-concurrent/backport-util-concurrent/3.1/backport-util-concurrent-3.1-javadoc.jar!/" name="javadoc_location"/>
</attributes>
</classpathentry>
<classpathentry kind="var" path="M2_REPO/com/adobe/blazeds/blazeds-common/3.2.0.3978/blazeds-common-3.2.0.3978.jar" sourcepath="M2_REPO/com/adobe/blazeds/blazeds-common/3.2.0.3978/blazeds-common-3.2.0.3978-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/com/adobe/blazeds/blazeds-core/3.2.0.3978/blazeds-core-3.2.0.3978.jar" sourcepath="M2_REPO/com/adobe/blazeds/blazeds-core/3.2.0.3978/blazeds-core-3.2.0.3978-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/cglib/cglib-nodep/2.1_3/cglib-nodep-2.1_3.jar" sourcepath="M2_REPO/cglib/cglib-nodep/2.1_3/cglib-nodep-2.1_3-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar" sourcepath="M2_REPO/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1-sources.jar">
<attributes>
<attribute value="jar:file:/C:/Users/aby/.m2/repository/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1-javadoc.jar!/" name="javadoc_location"/>
</attributes>
</classpathentry>
<classpathentry kind="var" path="M2_REPO/org/jetlang/jetlang/0.2.9/jetlang-0.2.9.jar" sourcepath="M2_REPO/org/jetlang/jetlang/0.2.9/jetlang-0.2.9-sources.jar">
<attributes>
<attribute value="jar:file:/C:/Users/aby/.m2/repository/org/jetlang/jetlang/0.2.9/jetlang-0.2.9-javadoc.jar!/" name="javadoc_location"/>
</attributes>
</classpathentry>
<classpathentry kind="var" path="M2_REPO/junit/junit/4.8.2/junit-4.8.2.jar" sourcepath="M2_REPO/junit/junit/4.8.2/junit-4.8.2-sources.jar">
<attributes>
<attribute value="jar:file:/C:/Users/aby/.m2/repository/junit/junit/4.8.2/junit-4.8.2-javadoc.jar!/" name="javadoc_location"/>
</attributes>
</classpathentry>
<classpathentry kind="var" path="M2_REPO/log4j/log4j/1.2.16/log4j-1.2.16.jar" sourcepath="M2_REPO/log4j/log4j/1.2.16/log4j-1.2.16-sources.jar">
<attributes>
<attribute value="jar:file:/C:/Users/aby/.m2/repository/log4j/log4j/1.2.16/log4j-1.2.16-javadoc.jar!/" name="javadoc_location"/>
</attributes>
</classpathentry>
<classpathentry kind="var" path="M2_REPO/io/netty/netty/3.5.11.Final/netty-3.5.11.Final.jar" sourcepath="M2_REPO/io/netty/netty/3.5.11.Final/netty-3.5.11.Final-sources.jar">
<attributes>
<attribute value="jar:file:/C:/Users/aby/.m2/repository/io/netty/netty/3.5.11.Final/netty-3.5.11.Final-javadoc.jar!/" name="javadoc_location"/>
</attributes>
</classpathentry>
<classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-api/1.6.1/slf4j-api-1.6.1.jar" sourcepath="M2_REPO/org/slf4j/slf4j-api/1.6.1/slf4j-api-1.6.1-sources.jar">
<attributes>
<attribute value="jar:file:/C:/Users/aby/.m2/repository/org/slf4j/slf4j-api/1.6.1/slf4j-api-1.6.1-javadoc.jar!/" name="javadoc_location"/>
</attributes>
</classpathentry>
<classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-log4j12/1.6.1/slf4j-log4j12-1.6.1.jar" sourcepath="M2_REPO/org/slf4j/slf4j-log4j12/1.6.1/slf4j-log4j12-1.6.1-sources.jar">
<attributes>
<attribute value="jar:file:/C:/Users/aby/.m2/repository/org/slf4j/slf4j-log4j12/1.6.1/slf4j-log4j12-1.6.1-javadoc.jar!/" name="javadoc_location"/>
</attributes>
</classpathentry>
<classpathentry kind="var" path="M2_REPO/org/springframework/spring-aop/3.1.0.RELEASE/spring-aop-3.1.0.RELEASE.jar" sourcepath="M2_REPO/org/springframework/spring-aop/3.1.0.RELEASE/spring-aop-3.1.0.RELEASE-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/org/springframework/spring-asm/3.1.0.RELEASE/spring-asm-3.1.0.RELEASE.jar" sourcepath="M2_REPO/org/springframework/spring-asm/3.1.0.RELEASE/spring-asm-3.1.0.RELEASE-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/org/springframework/spring-beans/3.1.0.RELEASE/spring-beans-3.1.0.RELEASE.jar" sourcepath="M2_REPO/org/springframework/spring-beans/3.1.0.RELEASE/spring-beans-3.1.0.RELEASE-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/org/springframework/spring-context/3.1.0.RELEASE/spring-context-3.1.0.RELEASE.jar" sourcepath="M2_REPO/org/springframework/spring-context/3.1.0.RELEASE/spring-context-3.1.0.RELEASE-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/org/springframework/spring-core/3.1.0.RELEASE/spring-core-3.1.0.RELEASE.jar" sourcepath="M2_REPO/org/springframework/spring-core/3.1.0.RELEASE/spring-core-3.1.0.RELEASE-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/org/springframework/spring-expression/3.1.0.RELEASE/spring-expression-3.1.0.RELEASE.jar" sourcepath="M2_REPO/org/springframework/spring-expression/3.1.0.RELEASE/spring-expression-3.1.0.RELEASE-sources.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.ajdt.core.ASPECTJRT_CONTAINER"/>
</classpath>
30 changes: 15 additions & 15 deletions jetserver/.project
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<projectDescription>
<name>jetserver</name>
<comment>Jetserver is a high speed socket based java game server written using JBoss Netty and Mike Rettig&apos;s Jetlang.It is specifically tuned for network based multiplayer games and supports TCP and UDP network protocols. NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.</comment>
<projects/>
<buildSpec>
<buildCommand>
<name>org.eclipse.ajdt.core.ajbuilder</name>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.ajdt.ui.ajnature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.springframework.ide.eclipse.core.springnature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
</natures>
<projectDescription>
<name>jetserver</name>
<comment>Jetserver is a high speed socket based java game server written using JBoss Netty and Mike Rettig&apos;s Jetlang.It is specifically tuned for network based multiplayer games and supports TCP and UDP network protocols. NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.</comment>
<projects/>
<buildSpec>
<buildCommand>
<name>org.eclipse.ajdt.core.ajbuilder</name>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.ajdt.ui.ajnature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.springframework.ide.eclipse.core.springnature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
</natures>
</projectDescription>
Loading

0 comments on commit 1691c50

Please sign in to comment.