mirror of
https://github.com/Rogiel/l2jserver2
synced 2025-12-06 07:32:46 +00:00
Change-Id: Ifa069a09d1b603781a2c9255d89b77cd6f25a359
This commit is contained in:
127
.fbprefs
Normal file
127
.fbprefs
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
#FindBugs User Preferences
|
||||||
|
#Thu Apr 28 21:39:39 BRT 2011
|
||||||
|
detectorAppendingToAnObjectOutputStream=AppendingToAnObjectOutputStream|true
|
||||||
|
detectorBadAppletConstructor=BadAppletConstructor|false
|
||||||
|
detectorBadResultSetAccess=BadResultSetAccess|true
|
||||||
|
detectorBadSyntaxForRegularExpression=BadSyntaxForRegularExpression|true
|
||||||
|
detectorBadUseOfReturnValue=BadUseOfReturnValue|true
|
||||||
|
detectorBadlyOverriddenAdapter=BadlyOverriddenAdapter|true
|
||||||
|
detectorBooleanReturnNull=BooleanReturnNull|true
|
||||||
|
detectorCallToUnsupportedMethod=CallToUnsupportedMethod|false
|
||||||
|
detectorCheckImmutableAnnotation=CheckImmutableAnnotation|true
|
||||||
|
detectorCheckTypeQualifiers=CheckTypeQualifiers|true
|
||||||
|
detectorCloneIdiom=CloneIdiom|true
|
||||||
|
detectorComparatorIdiom=ComparatorIdiom|true
|
||||||
|
detectorConfusedInheritance=ConfusedInheritance|true
|
||||||
|
detectorConfusionBetweenInheritedAndOuterMethod=ConfusionBetweenInheritedAndOuterMethod|true
|
||||||
|
detectorCrossSiteScripting=CrossSiteScripting|true
|
||||||
|
detectorDoInsideDoPrivileged=DoInsideDoPrivileged|true
|
||||||
|
detectorDontCatchIllegalMonitorStateException=DontCatchIllegalMonitorStateException|true
|
||||||
|
detectorDontIgnoreResultOfPutIfAbsent=DontIgnoreResultOfPutIfAbsent|true
|
||||||
|
detectorDontUseEnum=DontUseEnum|true
|
||||||
|
detectorDroppedException=DroppedException|true
|
||||||
|
detectorDumbMethodInvocations=DumbMethodInvocations|true
|
||||||
|
detectorDumbMethods=DumbMethods|true
|
||||||
|
detectorDuplicateBranches=DuplicateBranches|true
|
||||||
|
detectorEmptyZipFileEntry=EmptyZipFileEntry|true
|
||||||
|
detectorEqualsOperandShouldHaveClassCompatibleWithThis=EqualsOperandShouldHaveClassCompatibleWithThis|true
|
||||||
|
detectorFinalizerNullsFields=FinalizerNullsFields|true
|
||||||
|
detectorFindBadCast2=FindBadCast2|true
|
||||||
|
detectorFindBadForLoop=FindBadForLoop|true
|
||||||
|
detectorFindCircularDependencies=FindCircularDependencies|false
|
||||||
|
detectorFindDeadLocalStores=FindDeadLocalStores|true
|
||||||
|
detectorFindDoubleCheck=FindDoubleCheck|true
|
||||||
|
detectorFindEmptySynchronizedBlock=FindEmptySynchronizedBlock|true
|
||||||
|
detectorFindFieldSelfAssignment=FindFieldSelfAssignment|true
|
||||||
|
detectorFindFinalizeInvocations=FindFinalizeInvocations|true
|
||||||
|
detectorFindFloatEquality=FindFloatEquality|true
|
||||||
|
detectorFindHEmismatch=FindHEmismatch|true
|
||||||
|
detectorFindInconsistentSync2=FindInconsistentSync2|true
|
||||||
|
detectorFindJSR166LockMonitorenter=FindJSR166LockMonitorenter|true
|
||||||
|
detectorFindLocalSelfAssignment2=FindLocalSelfAssignment2|true
|
||||||
|
detectorFindMaskedFields=FindMaskedFields|true
|
||||||
|
detectorFindMismatchedWaitOrNotify=FindMismatchedWaitOrNotify|true
|
||||||
|
detectorFindNakedNotify=FindNakedNotify|true
|
||||||
|
detectorFindNonSerializableStoreIntoSession=FindNonSerializableStoreIntoSession|true
|
||||||
|
detectorFindNonSerializableValuePassedToWriteObject=FindNonSerializableValuePassedToWriteObject|true
|
||||||
|
detectorFindNonShortCircuit=FindNonShortCircuit|true
|
||||||
|
detectorFindNullDeref=FindNullDeref|true
|
||||||
|
detectorFindNullDerefsInvolvingNonShortCircuitEvaluation=FindNullDerefsInvolvingNonShortCircuitEvaluation|true
|
||||||
|
detectorFindOpenStream=FindOpenStream|true
|
||||||
|
detectorFindPuzzlers=FindPuzzlers|true
|
||||||
|
detectorFindRefComparison=FindRefComparison|true
|
||||||
|
detectorFindReturnRef=FindReturnRef|true
|
||||||
|
detectorFindRunInvocations=FindRunInvocations|true
|
||||||
|
detectorFindSelfComparison=FindSelfComparison|true
|
||||||
|
detectorFindSelfComparison2=FindSelfComparison2|true
|
||||||
|
detectorFindSleepWithLockHeld=FindSleepWithLockHeld|true
|
||||||
|
detectorFindSpinLoop=FindSpinLoop|true
|
||||||
|
detectorFindSqlInjection=FindSqlInjection|true
|
||||||
|
detectorFindTwoLockWait=FindTwoLockWait|true
|
||||||
|
detectorFindUncalledPrivateMethods=FindUncalledPrivateMethods|true
|
||||||
|
detectorFindUnconditionalWait=FindUnconditionalWait|true
|
||||||
|
detectorFindUninitializedGet=FindUninitializedGet|true
|
||||||
|
detectorFindUnrelatedTypesInGenericContainer=FindUnrelatedTypesInGenericContainer|true
|
||||||
|
detectorFindUnreleasedLock=FindUnreleasedLock|true
|
||||||
|
detectorFindUnsatisfiedObligation=FindUnsatisfiedObligation|true
|
||||||
|
detectorFindUnsyncGet=FindUnsyncGet|true
|
||||||
|
detectorFindUselessControlFlow=FindUselessControlFlow|true
|
||||||
|
detectorFormatStringChecker=FormatStringChecker|true
|
||||||
|
detectorHugeSharedStringConstants=HugeSharedStringConstants|true
|
||||||
|
detectorIDivResultCastToDouble=IDivResultCastToDouble|true
|
||||||
|
detectorIncompatMask=IncompatMask|true
|
||||||
|
detectorInconsistentAnnotations=InconsistentAnnotations|true
|
||||||
|
detectorInefficientMemberAccess=InefficientMemberAccess|false
|
||||||
|
detectorInefficientToArray=InefficientToArray|true
|
||||||
|
detectorInfiniteLoop=InfiniteLoop|true
|
||||||
|
detectorInfiniteRecursiveLoop=InfiniteRecursiveLoop|true
|
||||||
|
detectorInfiniteRecursiveLoop2=InfiniteRecursiveLoop2|false
|
||||||
|
detectorInheritanceUnsafeGetResource=InheritanceUnsafeGetResource|true
|
||||||
|
detectorInitializationChain=InitializationChain|true
|
||||||
|
detectorInstantiateStaticClass=InstantiateStaticClass|true
|
||||||
|
detectorInvalidJUnitTest=InvalidJUnitTest|true
|
||||||
|
detectorIteratorIdioms=IteratorIdioms|true
|
||||||
|
detectorLazyInit=LazyInit|true
|
||||||
|
detectorLoadOfKnownNullValue=LoadOfKnownNullValue|true
|
||||||
|
detectorLostLoggerDueToWeakReference=LostLoggerDueToWeakReference|true
|
||||||
|
detectorMethodReturnCheck=MethodReturnCheck|true
|
||||||
|
detectorMultithreadedInstanceAccess=MultithreadedInstanceAccess|true
|
||||||
|
detectorMutableLock=MutableLock|true
|
||||||
|
detectorMutableStaticFields=MutableStaticFields|true
|
||||||
|
detectorNaming=Naming|true
|
||||||
|
detectorNumberConstructor=NumberConstructor|true
|
||||||
|
detectorOverridingEqualsNotSymmetrical=OverridingEqualsNotSymmetrical|true
|
||||||
|
detectorPreferZeroLengthArrays=PreferZeroLengthArrays|true
|
||||||
|
detectorPublicSemaphores=PublicSemaphores|false
|
||||||
|
detectorQuestionableBooleanAssignment=QuestionableBooleanAssignment|true
|
||||||
|
detectorReadOfInstanceFieldInMethodInvokedByConstructorInSuperclass=ReadOfInstanceFieldInMethodInvokedByConstructorInSuperclass|true
|
||||||
|
detectorReadReturnShouldBeChecked=ReadReturnShouldBeChecked|true
|
||||||
|
detectorRedundantInterfaces=RedundantInterfaces|true
|
||||||
|
detectorRepeatedConditionals=RepeatedConditionals|true
|
||||||
|
detectorRuntimeExceptionCapture=RuntimeExceptionCapture|true
|
||||||
|
detectorSerializableIdiom=SerializableIdiom|true
|
||||||
|
detectorStartInConstructor=StartInConstructor|true
|
||||||
|
detectorStaticCalendarDetector=StaticCalendarDetector|true
|
||||||
|
detectorStringConcatenation=StringConcatenation|true
|
||||||
|
detectorSuperfluousInstanceOf=SuperfluousInstanceOf|true
|
||||||
|
detectorSuspiciousThreadInterrupted=SuspiciousThreadInterrupted|true
|
||||||
|
detectorSwitchFallthrough=SwitchFallthrough|true
|
||||||
|
detectorSynchronizeAndNullCheckField=SynchronizeAndNullCheckField|true
|
||||||
|
detectorSynchronizeOnClassLiteralNotGetClass=SynchronizeOnClassLiteralNotGetClass|true
|
||||||
|
detectorSynchronizingOnContentsOfFieldToProtectField=SynchronizingOnContentsOfFieldToProtectField|true
|
||||||
|
detectorURLProblems=URLProblems|true
|
||||||
|
detectorUncallableMethodOfAnonymousClass=UncallableMethodOfAnonymousClass|true
|
||||||
|
detectorUnnecessaryMath=UnnecessaryMath|true
|
||||||
|
detectorUnreadFields=UnreadFields|true
|
||||||
|
detectorUseObjectEquals=UseObjectEquals|false
|
||||||
|
detectorUselessSubclassMethod=UselessSubclassMethod|false
|
||||||
|
detectorVarArgsProblems=VarArgsProblems|true
|
||||||
|
detectorVolatileUsage=VolatileUsage|true
|
||||||
|
detectorWaitInLoop=WaitInLoop|true
|
||||||
|
detectorWrongMapIterator=WrongMapIterator|true
|
||||||
|
detectorXMLFactoryBypass=XMLFactoryBypass|true
|
||||||
|
detector_threshold=2
|
||||||
|
effort=default
|
||||||
|
filter_settings=Medium|BAD_PRACTICE,CORRECTNESS,MT_CORRECTNESS,PERFORMANCE,STYLE|false
|
||||||
|
filter_settings_neg=MALICIOUS_CODE,NOISE,I18N,SECURITY,EXPERIMENTAL|
|
||||||
|
run_at_full_build=false
|
||||||
6
.project
6
.project
@@ -15,9 +15,15 @@
|
|||||||
<arguments>
|
<arguments>
|
||||||
</arguments>
|
</arguments>
|
||||||
</buildCommand>
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>edu.umd.cs.findbugs.plugin.eclipse.findbugsBuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
</buildSpec>
|
</buildSpec>
|
||||||
<natures>
|
<natures>
|
||||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
<nature>org.maven.ide.eclipse.maven2Nature</nature>
|
<nature>org.maven.ide.eclipse.maven2Nature</nature>
|
||||||
|
<nature>edu.umd.cs.findbugs.plugin.eclipse.findbugsNature</nature>
|
||||||
</natures>
|
</natures>
|
||||||
</projectDescription>
|
</projectDescription>
|
||||||
|
|||||||
9
src/main/java/com/l2jserver/L2JServerRuntime.java
Normal file
9
src/main/java/com/l2jserver/L2JServerRuntime.java
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package com.l2jserver;
|
||||||
|
|
||||||
|
import com.l2jserver.service.logging.LoggingService;
|
||||||
|
|
||||||
|
public class L2JServerRuntime {
|
||||||
|
public LoggingService getLoggingService() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
50
src/main/java/com/l2jserver/game/net/Lineage2Connection.java
Normal file
50
src/main/java/com/l2jserver/game/net/Lineage2Connection.java
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
package com.l2jserver.game.net;
|
||||||
|
|
||||||
|
import org.jboss.netty.channel.Channel;
|
||||||
|
import org.jboss.netty.channel.ChannelFuture;
|
||||||
|
|
||||||
|
import com.l2jserver.game.net.codec.Lineage2Decrypter;
|
||||||
|
import com.l2jserver.game.net.codec.Lineage2Encrypter;
|
||||||
|
import com.l2jserver.game.net.packet.ServerPacket;
|
||||||
|
|
||||||
|
public class Lineage2Connection {
|
||||||
|
private final Channel channel;
|
||||||
|
|
||||||
|
public Lineage2Connection(Channel channel) {
|
||||||
|
this.channel = channel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Channel getChannel() {
|
||||||
|
return channel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isOpen() {
|
||||||
|
return channel.isOpen();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isConnected() {
|
||||||
|
return channel.isConnected();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ChannelFuture write(ServerPacket message) {
|
||||||
|
return channel.write(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ChannelFuture disconnect() {
|
||||||
|
return channel.disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ChannelFuture close() {
|
||||||
|
return channel.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Lineage2Decrypter getDecrypter() {
|
||||||
|
return (Lineage2Decrypter) channel.getPipeline().get(
|
||||||
|
Lineage2Decrypter.HANDLER_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Lineage2Encrypter getEncrypter() {
|
||||||
|
return (Lineage2Encrypter) channel.getPipeline().get(
|
||||||
|
Lineage2Encrypter.HANDLER_NAME);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package com.l2jserver.game.net;
|
||||||
|
|
||||||
|
import static org.jboss.netty.channel.Channels.pipeline;
|
||||||
|
|
||||||
|
import org.jboss.netty.channel.ChannelPipeline;
|
||||||
|
import org.jboss.netty.channel.ChannelPipelineFactory;
|
||||||
|
|
||||||
|
import com.l2jserver.game.net.codec.Lineage2Decoder;
|
||||||
|
import com.l2jserver.game.net.codec.Lineage2Decrypter;
|
||||||
|
import com.l2jserver.game.net.codec.Lineage2Encoder;
|
||||||
|
import com.l2jserver.game.net.codec.Lineage2Encrypter;
|
||||||
|
import com.l2jserver.game.net.codec.Lineage2PacketReader;
|
||||||
|
import com.l2jserver.game.net.codec.Lineage2PacketWriter;
|
||||||
|
import com.l2jserver.game.net.handler.Lineage2PacketHandler;
|
||||||
|
|
||||||
|
public class Lineage2PipelineFactory implements ChannelPipelineFactory {
|
||||||
|
@Override
|
||||||
|
public ChannelPipeline getPipeline() throws Exception {
|
||||||
|
final ChannelPipeline pipeline = pipeline();
|
||||||
|
|
||||||
|
pipeline.addLast(Lineage2Encrypter.HANDLER_NAME,
|
||||||
|
new Lineage2Encrypter());
|
||||||
|
pipeline.addLast(Lineage2Decrypter.HANDLER_NAME,
|
||||||
|
new Lineage2Decrypter());
|
||||||
|
|
||||||
|
pipeline.addLast("header.encoder", new Lineage2Encoder());
|
||||||
|
pipeline.addLast("header.decoder", new Lineage2Decoder());
|
||||||
|
|
||||||
|
pipeline.addLast("packet.writer", new Lineage2PacketWriter());
|
||||||
|
pipeline.addLast("packet.reader", new Lineage2PacketReader());
|
||||||
|
|
||||||
|
pipeline.addLast("packet.handler", new Lineage2PacketHandler());
|
||||||
|
|
||||||
|
return pipeline;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,14 +1,29 @@
|
|||||||
package com.l2jserver.game.net.codec;
|
package com.l2jserver.game.net.codec;
|
||||||
|
|
||||||
import org.jboss.netty.buffer.ChannelBuffer;
|
import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder;
|
||||||
import org.jboss.netty.channel.Channel;
|
|
||||||
import org.jboss.netty.channel.ChannelHandlerContext;
|
|
||||||
import org.jboss.netty.handler.codec.frame.FrameDecoder;
|
|
||||||
|
|
||||||
public class Lineage2Decoder extends FrameDecoder {
|
public class Lineage2Decoder extends LengthFieldBasedFrameDecoder {
|
||||||
@Override
|
// private static final int HEADER_SIZE = 2;
|
||||||
protected Object decode(ChannelHandlerContext ctx, Channel channel,
|
|
||||||
ChannelBuffer buffer) throws Exception {
|
public Lineage2Decoder() {
|
||||||
return null;
|
super(16 * 1024, 0, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Override
|
||||||
|
// protected Object decode(ChannelHandlerContext ctx, Channel channel,
|
||||||
|
// ChannelBuffer buffer) throws Exception {
|
||||||
|
// if (buffer.readableBytes() < 2)
|
||||||
|
// return null;
|
||||||
|
// buffer.markReaderIndex();
|
||||||
|
// final int pending = buffer.readUnsignedShort() - HEADER_SIZE;
|
||||||
|
// if(pending == 0)
|
||||||
|
// return null;
|
||||||
|
//
|
||||||
|
// if (buffer.readableBytes() < pending) {
|
||||||
|
// buffer.resetReaderIndex();
|
||||||
|
// return null;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return buffer.slice(buffer.readableBytes(), pending);
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package com.l2jserver.game.net.codec;
|
||||||
|
|
||||||
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
import org.jboss.netty.channel.Channel;
|
||||||
|
import org.jboss.netty.channel.ChannelHandlerContext;
|
||||||
|
import org.jboss.netty.handler.codec.oneone.OneToOneDecoder;
|
||||||
|
|
||||||
|
public class Lineage2Decrypter extends OneToOneDecoder {
|
||||||
|
public static final String HANDLER_NAME = "crypto.decoder";
|
||||||
|
|
||||||
|
private boolean enabled = false;
|
||||||
|
private final byte[] key = new byte[16];
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Object decode(ChannelHandlerContext ctx, Channel channel,
|
||||||
|
Object msg) throws Exception {
|
||||||
|
if (!(msg instanceof ChannelBuffer))
|
||||||
|
return msg;
|
||||||
|
if (!enabled)
|
||||||
|
return msg;
|
||||||
|
final ChannelBuffer buffer = (ChannelBuffer) msg;
|
||||||
|
|
||||||
|
final int offset = buffer.readerIndex();
|
||||||
|
final int size = buffer.readableBytes();
|
||||||
|
int temp = 0;
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
int temp2 = buffer.getUnsignedByte(offset + i);
|
||||||
|
buffer.setByte(offset + i, (byte) (temp2 ^ key[i & 15] ^ temp));
|
||||||
|
temp = temp2;
|
||||||
|
}
|
||||||
|
|
||||||
|
int old = key[8] & 0xff;
|
||||||
|
old |= key[9] << 8 & 0xff00;
|
||||||
|
old |= key[10] << 0x10 & 0xff0000;
|
||||||
|
old |= key[11] << 0x18 & 0xff000000;
|
||||||
|
|
||||||
|
old += size;
|
||||||
|
|
||||||
|
key[8] = (byte) (old & 0xff);
|
||||||
|
key[9] = (byte) (old >> 0x08 & 0xff);
|
||||||
|
key[10] = (byte) (old >> 0x10 & 0xff);
|
||||||
|
key[11] = (byte) (old >> 0x18 & 0xff);
|
||||||
|
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setKey(byte[] key) {
|
||||||
|
for (int i = 0; i < 16; i++) {
|
||||||
|
this.key[i] = key[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnabled(boolean enabled) {
|
||||||
|
this.enabled = enabled;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
package com.l2jserver.game.net.codec;
|
package com.l2jserver.game.net.codec;
|
||||||
|
|
||||||
public class Lineage2Encoder {
|
import org.jboss.netty.handler.codec.frame.LengthFieldPrepender;
|
||||||
|
|
||||||
|
public class Lineage2Encoder extends LengthFieldPrepender {
|
||||||
|
public Lineage2Encoder() {
|
||||||
|
super(2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package com.l2jserver.game.net.codec;
|
||||||
|
|
||||||
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
import org.jboss.netty.channel.Channel;
|
||||||
|
import org.jboss.netty.channel.ChannelHandlerContext;
|
||||||
|
import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
|
||||||
|
|
||||||
|
public class Lineage2Encrypter extends OneToOneEncoder {
|
||||||
|
public static final String HANDLER_NAME = "crypto.encoder";
|
||||||
|
|
||||||
|
private boolean enabled = false;
|
||||||
|
private final byte[] key = new byte[16];
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Object encode(ChannelHandlerContext ctx, Channel channel,
|
||||||
|
Object msg) throws Exception {
|
||||||
|
if (!(msg instanceof ChannelBuffer))
|
||||||
|
return msg;
|
||||||
|
final ChannelBuffer buffer = (ChannelBuffer) msg;
|
||||||
|
|
||||||
|
final int offset = buffer.readerIndex();
|
||||||
|
final int size = buffer.readableBytes();
|
||||||
|
int temp = 0;
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
|
int temp2 = buffer.getUnsignedByte(offset + i);
|
||||||
|
buffer.setByte(offset + i, (byte) (temp2 ^ key[i & 15] ^ temp));
|
||||||
|
temp = temp2;
|
||||||
|
}
|
||||||
|
|
||||||
|
int old = key[8] & 0xff;
|
||||||
|
old |= key[9] << 8 & 0xff00;
|
||||||
|
old |= key[10] << 0x10 & 0xff0000;
|
||||||
|
old |= key[11] << 0x18 & 0xff000000;
|
||||||
|
|
||||||
|
old += size;
|
||||||
|
|
||||||
|
key[8] = (byte) (old & 0xff);
|
||||||
|
key[9] = (byte) (old >> 0x08 & 0xff);
|
||||||
|
key[10] = (byte) (old >> 0x10 & 0xff);
|
||||||
|
key[11] = (byte) (old >> 0x18 & 0xff);
|
||||||
|
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setKey(byte[] key) {
|
||||||
|
for (int i = 0; i < 16; i++) {
|
||||||
|
this.key[i] = key[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnabled(boolean enabled) {
|
||||||
|
this.enabled = enabled;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package com.l2jserver.game.net.codec;
|
||||||
|
|
||||||
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
import org.jboss.netty.channel.Channel;
|
||||||
|
import org.jboss.netty.channel.ChannelHandlerContext;
|
||||||
|
import org.jboss.netty.handler.codec.oneone.OneToOneDecoder;
|
||||||
|
|
||||||
|
import com.l2jserver.game.net.packet.ClientPacket;
|
||||||
|
import com.l2jserver.game.net.packet.client.ProtocolVersionPacket;
|
||||||
|
|
||||||
|
public class Lineage2PacketReader extends OneToOneDecoder {
|
||||||
|
@Override
|
||||||
|
protected Object decode(ChannelHandlerContext ctx, Channel channel,
|
||||||
|
Object msg) throws Exception {
|
||||||
|
if (!(msg instanceof ChannelBuffer))
|
||||||
|
return msg;
|
||||||
|
final ChannelBuffer buffer = (ChannelBuffer) msg;
|
||||||
|
final ClientPacket packet = getPacket(buffer);
|
||||||
|
if (packet == null)
|
||||||
|
return null;
|
||||||
|
packet.read(buffer);
|
||||||
|
return packet;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ClientPacket getPacket(ChannelBuffer buffer) {
|
||||||
|
final short opcode = buffer.readUnsignedByte();
|
||||||
|
switch (opcode) {
|
||||||
|
case ProtocolVersionPacket.OPCODE:
|
||||||
|
return new ProtocolVersionPacket();
|
||||||
|
case 0x2b:
|
||||||
|
return null;
|
||||||
|
default:
|
||||||
|
System.out.println("Unk: " + opcode);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.l2jserver.game.net.codec;
|
||||||
|
|
||||||
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
import org.jboss.netty.buffer.ChannelBuffers;
|
||||||
|
import org.jboss.netty.channel.Channel;
|
||||||
|
import org.jboss.netty.channel.ChannelHandlerContext;
|
||||||
|
import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
|
||||||
|
|
||||||
|
import com.l2jserver.game.net.packet.ServerPacket;
|
||||||
|
|
||||||
|
public class Lineage2PacketWriter extends OneToOneEncoder {
|
||||||
|
@Override
|
||||||
|
protected Object encode(ChannelHandlerContext ctx, Channel channel,
|
||||||
|
Object msg) throws Exception {
|
||||||
|
if (!(msg instanceof ServerPacket))
|
||||||
|
return msg;
|
||||||
|
final ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
|
||||||
|
final ServerPacket packet = (ServerPacket) msg;
|
||||||
|
packet.write(buffer);
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package com.l2jserver.game.net.handler;
|
||||||
|
|
||||||
|
import org.jboss.netty.channel.ChannelHandlerContext;
|
||||||
|
import org.jboss.netty.channel.MessageEvent;
|
||||||
|
import org.jboss.netty.channel.SimpleChannelHandler;
|
||||||
|
|
||||||
|
import com.l2jserver.game.net.packet.ClientPacket;
|
||||||
|
|
||||||
|
public class Lineage2PacketHandler extends SimpleChannelHandler {
|
||||||
|
@Override
|
||||||
|
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
|
||||||
|
throws Exception {
|
||||||
|
final Object msg = e.getMessage();
|
||||||
|
if (!(msg instanceof ClientPacket))
|
||||||
|
return;
|
||||||
|
final ClientPacket packet = (ClientPacket) msg;
|
||||||
|
packet.process(null);
|
||||||
|
super.messageReceived(ctx, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeRequested(ChannelHandlerContext ctx, MessageEvent e)
|
||||||
|
throws Exception {
|
||||||
|
super.writeRequested(ctx, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,22 @@ package com.l2jserver.game.net.packet;
|
|||||||
|
|
||||||
import org.jboss.netty.buffer.ChannelBuffer;
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
|
||||||
|
import com.google.inject.Injector;
|
||||||
|
|
||||||
public interface ClientPacket extends Packet {
|
public interface ClientPacket extends Packet {
|
||||||
|
/**
|
||||||
|
* Read binary data in the {@link ChannelBuffer}.
|
||||||
|
*
|
||||||
|
* @param buffer
|
||||||
|
* the buffer
|
||||||
|
*/
|
||||||
void read(ChannelBuffer buffer);
|
void read(ChannelBuffer buffer);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process the packet
|
||||||
|
*
|
||||||
|
* @param injector
|
||||||
|
* the injector
|
||||||
|
*/
|
||||||
|
void process(Injector injector);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.l2jserver.game.net.packet.client;
|
||||||
|
|
||||||
|
import org.jboss.netty.buffer.ChannelBuffer;
|
||||||
|
|
||||||
|
import com.google.inject.Injector;
|
||||||
|
import com.l2jserver.game.net.packet.AbstractClientPacket;
|
||||||
|
|
||||||
|
public class ProtocolVersionPacket extends AbstractClientPacket {
|
||||||
|
public static final int OPCODE = 0x0e;
|
||||||
|
|
||||||
|
private int version;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(ChannelBuffer buffer) {
|
||||||
|
this.version = buffer.readInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void process(Injector injector) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getVersion() {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVersion(int version) {
|
||||||
|
this.version = version;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
package com.l2jserver.game.net.packet.client;
|
|
||||||
|
|
||||||
import org.jboss.netty.buffer.ChannelBuffer;
|
|
||||||
|
|
||||||
import com.l2jserver.game.net.packet.AbstractClientPacket;
|
|
||||||
|
|
||||||
public class TestPacket extends AbstractClientPacket {
|
|
||||||
public static final int OPCODE = 0x00;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void read(ChannelBuffer buffer) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +1,27 @@
|
|||||||
package com.l2jserver.model.world;
|
package com.l2jserver.model.world;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import com.l2jserver.model.world.capability.Attackable;
|
import com.l2jserver.model.world.capability.Attackable;
|
||||||
import com.l2jserver.model.world.capability.Attacker;
|
import com.l2jserver.model.world.capability.Attacker;
|
||||||
import com.l2jserver.model.world.capability.Child;
|
import com.l2jserver.model.world.capability.Child;
|
||||||
|
import com.l2jserver.model.world.capability.Listenable;
|
||||||
import com.l2jserver.model.world.capability.Playable;
|
import com.l2jserver.model.world.capability.Playable;
|
||||||
import com.l2jserver.model.world.capability.Spawnable;
|
import com.l2jserver.model.world.capability.Spawnable;
|
||||||
|
import com.l2jserver.model.world.item.ItemEvent;
|
||||||
|
import com.l2jserver.model.world.item.ItemListener;
|
||||||
import com.l2jserver.util.Coordinate;
|
import com.l2jserver.util.Coordinate;
|
||||||
|
import com.l2jserver.util.factory.CollectionFactory;
|
||||||
|
|
||||||
public class Item extends AbstractObject implements Playable, Spawnable,
|
public class Item extends AbstractObject implements Playable, Spawnable,
|
||||||
Attacker, Attackable, Child<Player> {
|
Attacker, Attackable, Child<Player>,
|
||||||
|
Listenable<ItemListener, ItemEvent> {
|
||||||
|
private final List<ItemListener> listeners = CollectionFactory
|
||||||
|
.newList(ItemListener.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void spawn(Coordinate coordinate) {
|
public void spawn(Coordinate coordinate) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -26,6 +36,23 @@ public class Item extends AbstractObject implements Playable, Spawnable,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addListener(ItemListener listener) {
|
||||||
|
listeners.add(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeListener(ItemListener listener) {
|
||||||
|
listeners.remove(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dispatch(ItemEvent e) {
|
||||||
|
for (final ItemListener listener : listeners) {
|
||||||
|
listener.dispatch(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSpawned() {
|
public boolean isSpawned() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import com.l2jserver.model.world.capability.Spawnable;
|
|||||||
import com.l2jserver.model.world.player.PlayerEvent;
|
import com.l2jserver.model.world.player.PlayerEvent;
|
||||||
import com.l2jserver.model.world.player.PlayerListener;
|
import com.l2jserver.model.world.player.PlayerListener;
|
||||||
import com.l2jserver.util.Coordinate;
|
import com.l2jserver.util.Coordinate;
|
||||||
|
import com.l2jserver.util.factory.CollectionFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link Player} is any object that can be controlled by the player. The most
|
* {@link Player} is any object that can be controlled by the player. The most
|
||||||
@@ -24,6 +25,9 @@ import com.l2jserver.util.Coordinate;
|
|||||||
public abstract class Player extends AbstractObject implements Playable,
|
public abstract class Player extends AbstractObject implements Playable,
|
||||||
Spawnable, Attacker, Attackable,
|
Spawnable, Attacker, Attackable,
|
||||||
Listenable<PlayerListener, PlayerEvent>, Caster, Parent {
|
Listenable<PlayerListener, PlayerEvent>, Caster, Parent {
|
||||||
|
private final List<PlayerListener> listeners = CollectionFactory
|
||||||
|
.newList(PlayerListener.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void spawn(Coordinate coordinate) {
|
public void spawn(Coordinate coordinate) {
|
||||||
|
|
||||||
@@ -43,37 +47,25 @@ public abstract class Player extends AbstractObject implements Playable,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addListener(PlayerListener listener) {
|
public void addListener(PlayerListener listener) {
|
||||||
// TODO Auto-generated method stub
|
listeners.add(listener);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeListener(PlayerListener listener) {
|
public void removeListener(PlayerListener listener) {
|
||||||
// TODO Auto-generated method stub
|
listeners.remove(listener);
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<PlayerListener> getListeners() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean support(Class<? extends PlayerEvent> eventType) {
|
|
||||||
return eventType.isAssignableFrom(PlayerEvent.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Coordinate getPosition() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dispatch(PlayerEvent e) {
|
public void dispatch(PlayerEvent e) {
|
||||||
// TODO Auto-generated method stub
|
for (final PlayerListener listener : listeners) {
|
||||||
|
listener.dispatch(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Coordinate getPosition() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
52
src/main/java/com/l2jserver/model/world/World.java
Normal file
52
src/main/java/com/l2jserver/model/world/World.java
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
package com.l2jserver.model.world;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
import com.l2jserver.model.world.event.WorldEventDispatcher;
|
||||||
|
import com.l2jserver.model.world.filter.WorldObjectFilter;
|
||||||
|
import com.l2jserver.model.world.iterator.FilterIterator;
|
||||||
|
import com.l2jserver.util.factory.CollectionFactory;
|
||||||
|
|
||||||
|
public class World implements Iterable<WorldObject> {
|
||||||
|
private final Set<WorldObject> objects = CollectionFactory
|
||||||
|
.newSet(WorldObject.class);
|
||||||
|
private final WorldEventDispatcher dispatcher = new WorldEventDispatcher(
|
||||||
|
this);
|
||||||
|
|
||||||
|
public void add(WorldObject object) {
|
||||||
|
objects.add(object);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove(WorldObject object) {
|
||||||
|
objects.remove(object);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean contains(WorldObject object) {
|
||||||
|
return objects.contains(object);
|
||||||
|
}
|
||||||
|
|
||||||
|
public WorldEventDispatcher getDispatcher() {
|
||||||
|
return dispatcher;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterator<WorldObject> iterator() {
|
||||||
|
return objects.iterator();
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T extends WorldObject> Iterator<T> iterator(
|
||||||
|
final WorldObjectFilter<T> filter) {
|
||||||
|
return new FilterIterator<T>(filter, objects.iterator());
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T extends WorldObject> Iterable<T> iterable(
|
||||||
|
final WorldObjectFilter<T> filter) {
|
||||||
|
return new Iterable<T>() {
|
||||||
|
@Override
|
||||||
|
public Iterator<T> iterator() {
|
||||||
|
return new FilterIterator<T>(filter, objects.iterator());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
package com.l2jserver.model.world.capability;
|
package com.l2jserver.model.world.capability;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.l2jserver.model.world.AbstractObject;
|
import com.l2jserver.model.world.AbstractObject;
|
||||||
import com.l2jserver.model.world.event.WorldEvent;
|
import com.l2jserver.model.world.event.WorldEvent;
|
||||||
import com.l2jserver.model.world.event.WorldListener;
|
import com.l2jserver.model.world.event.WorldListener;
|
||||||
@@ -19,13 +17,27 @@ import com.l2jserver.model.world.event.WorldListener;
|
|||||||
*/
|
*/
|
||||||
public interface Listenable<L extends WorldListener<E>, E extends WorldEvent>
|
public interface Listenable<L extends WorldListener<E>, E extends WorldEvent>
|
||||||
extends WorldCapability {
|
extends WorldCapability {
|
||||||
|
/**
|
||||||
|
* Adds a new listener
|
||||||
|
*
|
||||||
|
* @param listener
|
||||||
|
* the listener
|
||||||
|
*/
|
||||||
void addListener(L listener);
|
void addListener(L listener);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes an listener
|
||||||
|
*
|
||||||
|
* @param listener
|
||||||
|
* the listener
|
||||||
|
*/
|
||||||
void removeListener(L listener);
|
void removeListener(L listener);
|
||||||
|
|
||||||
List<L> getListeners();
|
/**
|
||||||
|
* Don't use this method directly. It is called by the event dispatcher.
|
||||||
boolean support(Class<? extends E> eventType);
|
*
|
||||||
|
* @param e
|
||||||
|
* the event
|
||||||
|
*/
|
||||||
void dispatch(E e);
|
void dispatch(E e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
package com.l2jserver.model.world.event;
|
package com.l2jserver.model.world.event;
|
||||||
|
|
||||||
public interface WorldEvent {
|
import com.l2jserver.model.world.WorldObject;
|
||||||
|
|
||||||
|
public interface WorldEvent {
|
||||||
|
WorldObject getObject();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dispatch this event to all the objects
|
||||||
|
*/
|
||||||
|
void dispatch();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.l2jserver.model.world.event;
|
||||||
|
|
||||||
|
import com.l2jserver.model.world.World;
|
||||||
|
|
||||||
|
public class WorldEventDispatcher {
|
||||||
|
private final World world;
|
||||||
|
|
||||||
|
public WorldEventDispatcher(World world) {
|
||||||
|
this.world = world;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dispatch(WorldEvent event) {
|
||||||
|
//TODO implement threaded model
|
||||||
|
event.dispatch();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,20 @@
|
|||||||
package com.l2jserver.model.world.event;
|
package com.l2jserver.model.world.event;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the most abstract listener for the listening engine.
|
||||||
|
*
|
||||||
|
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||||
|
*
|
||||||
|
* @param <E>
|
||||||
|
* the received event type
|
||||||
|
*/
|
||||||
public interface WorldListener<E extends WorldEvent> {
|
public interface WorldListener<E extends WorldEvent> {
|
||||||
void onAction(E e);
|
/**
|
||||||
|
* Once the event call is dispatched, the listener <b>WILL NOT</b> be
|
||||||
|
* removed. You must manually remove it from the <tt>event</tt> object.
|
||||||
|
*
|
||||||
|
* @param e
|
||||||
|
* the event
|
||||||
|
*/
|
||||||
|
void dispatch(E e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,16 +2,16 @@ package com.l2jserver.model.world.filter;
|
|||||||
|
|
||||||
import com.l2jserver.model.world.WorldObject;
|
import com.l2jserver.model.world.WorldObject;
|
||||||
|
|
||||||
public class AndFilter<O extends WorldObject> implements WorldFilter<O> {
|
public class AndFilter<O extends WorldObject> implements WorldObjectFilter<O> {
|
||||||
private WorldFilter<O>[] filters;
|
private WorldObjectFilter<O>[] filters;
|
||||||
|
|
||||||
public AndFilter(WorldFilter<O>... filters) {
|
public AndFilter(WorldObjectFilter<O>... filters) {
|
||||||
this.filters = filters;
|
this.filters = filters;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean accept(O object) {
|
public boolean accept(O object) {
|
||||||
for(final WorldFilter<O> filter : filters) {
|
for(final WorldObjectFilter<O> filter : filters) {
|
||||||
if(!filter.accept(object))
|
if(!filter.accept(object))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ package com.l2jserver.model.world.filter;
|
|||||||
|
|
||||||
import com.l2jserver.model.world.WorldObject;
|
import com.l2jserver.model.world.WorldObject;
|
||||||
|
|
||||||
public class NotFilter<O extends WorldObject> implements WorldFilter<O> {
|
public class NotFilter<O extends WorldObject> implements WorldObjectFilter<O> {
|
||||||
private WorldFilter<O> filter;
|
private WorldObjectFilter<O> filter;
|
||||||
|
|
||||||
public NotFilter(WorldFilter<O> filter) {
|
public NotFilter(WorldObjectFilter<O> filter) {
|
||||||
this.filter = filter;
|
this.filter = filter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,16 +2,16 @@ package com.l2jserver.model.world.filter;
|
|||||||
|
|
||||||
import com.l2jserver.model.world.WorldObject;
|
import com.l2jserver.model.world.WorldObject;
|
||||||
|
|
||||||
public class OrFilter<O extends WorldObject> implements WorldFilter<O> {
|
public class OrFilter<O extends WorldObject> implements WorldObjectFilter<O> {
|
||||||
private WorldFilter<O>[] filters;
|
private WorldObjectFilter<O>[] filters;
|
||||||
|
|
||||||
public OrFilter(WorldFilter<O>... filters) {
|
public OrFilter(WorldObjectFilter<O>... filters) {
|
||||||
this.filters = filters;
|
this.filters = filters;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean accept(O object) {
|
public boolean accept(O object) {
|
||||||
for(final WorldFilter<O> filter : filters) {
|
for(final WorldObjectFilter<O> filter : filters) {
|
||||||
if(filter.accept(object))
|
if(filter.accept(object))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,18 +3,18 @@ package com.l2jserver.model.world.filter;
|
|||||||
import com.l2jserver.model.world.WorldObject;
|
import com.l2jserver.model.world.WorldObject;
|
||||||
|
|
||||||
public final class WorldFilters {
|
public final class WorldFilters {
|
||||||
public static final <O extends WorldObject> WorldFilter<O> and(
|
public static final <O extends WorldObject> WorldObjectFilter<O> and(
|
||||||
WorldFilter<O>... filters) {
|
WorldObjectFilter<O>... filters) {
|
||||||
return new AndFilter<O>(filters);
|
return new AndFilter<O>(filters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final <O extends WorldObject> WorldFilter<O> or(
|
public static final <O extends WorldObject> WorldObjectFilter<O> or(
|
||||||
WorldFilter<O>... filters) {
|
WorldObjectFilter<O>... filters) {
|
||||||
return new OrFilter<O>(filters);
|
return new OrFilter<O>(filters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final <O extends WorldObject> WorldFilter<O> notf(
|
public static final <O extends WorldObject> WorldObjectFilter<O> notf(
|
||||||
WorldFilter<O> filter) {
|
WorldObjectFilter<O> filter) {
|
||||||
return new NotFilter<O>(filter);
|
return new NotFilter<O>(filter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import com.l2jserver.model.world.WorldObject;
|
|||||||
*
|
*
|
||||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||||
*/
|
*/
|
||||||
public interface WorldFilter<O extends WorldObject> {
|
public interface WorldObjectFilter<O extends WorldObject> {
|
||||||
/**
|
/**
|
||||||
* Test if <tt>object</tt> matches the filter requirements
|
* Test if <tt>object</tt> matches the filter requirements
|
||||||
*
|
*
|
||||||
@@ -2,9 +2,9 @@ package com.l2jserver.model.world.filter.impl;
|
|||||||
|
|
||||||
import com.l2jserver.model.id.ID;
|
import com.l2jserver.model.id.ID;
|
||||||
import com.l2jserver.model.world.capability.Positionable;
|
import com.l2jserver.model.world.capability.Positionable;
|
||||||
import com.l2jserver.model.world.filter.WorldFilter;
|
import com.l2jserver.model.world.filter.WorldObjectFilter;
|
||||||
|
|
||||||
public class IDFilter implements WorldFilter<Positionable> {
|
public class IDFilter implements WorldObjectFilter<Positionable> {
|
||||||
private final ID id;
|
private final ID id;
|
||||||
|
|
||||||
public IDFilter(final ID id) {
|
public IDFilter(final ID id) {
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.l2jserver.model.world.filter.impl;
|
||||||
|
|
||||||
|
import com.l2jserver.model.world.WorldObject;
|
||||||
|
import com.l2jserver.model.world.filter.WorldObjectFilter;
|
||||||
|
|
||||||
|
public class InstanceFilter<T extends WorldObject> implements WorldObjectFilter<T> {
|
||||||
|
private final Class<?> type;
|
||||||
|
|
||||||
|
public InstanceFilter(Class<?> instance) {
|
||||||
|
this.type = instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean accept(T other) {
|
||||||
|
if (other == null)
|
||||||
|
return false;
|
||||||
|
return type.isInstance(other);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
package com.l2jserver.model.world.filter.impl;
|
package com.l2jserver.model.world.filter.impl;
|
||||||
|
|
||||||
import com.l2jserver.model.world.capability.Positionable;
|
import com.l2jserver.model.world.capability.Positionable;
|
||||||
import com.l2jserver.model.world.filter.WorldFilter;
|
import com.l2jserver.model.world.filter.WorldObjectFilter;
|
||||||
import com.l2jserver.util.Coordinate;
|
import com.l2jserver.util.Coordinate;
|
||||||
|
|
||||||
public class RangeFilter implements WorldFilter<Positionable> {
|
public class RangeFilter implements WorldObjectFilter<Positionable> {
|
||||||
private final Coordinate coordinate;
|
private final Coordinate coordinate;
|
||||||
private final int range;
|
private final int range;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package com.l2jserver.model.world.item;
|
||||||
|
|
||||||
|
import com.l2jserver.model.world.Item;
|
||||||
|
import com.l2jserver.model.world.Player;
|
||||||
|
import com.l2jserver.model.world.WorldObject;
|
||||||
|
import com.l2jserver.model.world.player.PlayerEvent;
|
||||||
|
|
||||||
|
public class ItemDropEvent implements ItemEvent, PlayerEvent {
|
||||||
|
private final Player player;
|
||||||
|
private final Item item;
|
||||||
|
|
||||||
|
public ItemDropEvent(Player player, Item item) {
|
||||||
|
this.player = player;
|
||||||
|
this.item = item;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WorldObject getObject() {
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Player getPlayer() {
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Item getItem() {
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dispatch() {
|
||||||
|
item.dispatch(this);
|
||||||
|
if (player != null)
|
||||||
|
player.dispatch(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package com.l2jserver.model.world.iterator;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import com.l2jserver.model.world.WorldObject;
|
||||||
|
import com.l2jserver.model.world.filter.WorldObjectFilter;
|
||||||
|
|
||||||
|
public class FilterIterator<O extends WorldObject> implements Iterator<O> {
|
||||||
|
private final Iterator<WorldObject> objects;
|
||||||
|
private final WorldObjectFilter<O> filter;
|
||||||
|
|
||||||
|
private O selected;
|
||||||
|
|
||||||
|
public FilterIterator(final WorldObjectFilter<O> filter,
|
||||||
|
Iterator<WorldObject> objects) {
|
||||||
|
this.filter = filter;
|
||||||
|
this.objects = objects;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasNext() {
|
||||||
|
O next = findNext();
|
||||||
|
return (next != null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public O next() {
|
||||||
|
try {
|
||||||
|
return findNext();
|
||||||
|
} finally {
|
||||||
|
selected = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void remove() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public O findNext() {
|
||||||
|
if (selected != null)
|
||||||
|
return selected;
|
||||||
|
while (objects.hasNext()) {
|
||||||
|
try {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
final O object = (O) objects.next();
|
||||||
|
if (filter.accept(object)) {
|
||||||
|
selected = object;
|
||||||
|
return selected;
|
||||||
|
}
|
||||||
|
} catch (ClassCastException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,4 +20,10 @@ public class PlayerSpawnEvent implements PlayerEvent, SpawnEvent {
|
|||||||
public Player getPlayer() {
|
public Player getPlayer() {
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dispatch() {
|
||||||
|
if(player != null)
|
||||||
|
player.dispatch(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package com.l2jserver.model.world.player;
|
||||||
|
|
||||||
|
import com.l2jserver.model.world.event.WorldEvent;
|
||||||
|
|
||||||
|
public interface TestEvent extends WorldEvent {
|
||||||
|
}
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
package com.l2jserver.service.game.world;
|
|
||||||
|
|
||||||
import com.l2jserver.model.world.AbstractObject;
|
|
||||||
import com.l2jserver.model.world.event.WorldEvent;
|
|
||||||
|
|
||||||
public interface WorldEventDispatcher {
|
|
||||||
void dispatch(AbstractObject object, WorldEvent event);
|
|
||||||
}
|
|
||||||
@@ -1,16 +1,13 @@
|
|||||||
package com.l2jserver.service.game.world;
|
package com.l2jserver.service.game.world;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import com.l2jserver.model.world.WorldObject;
|
import com.l2jserver.model.world.WorldObject;
|
||||||
import com.l2jserver.model.world.filter.WorldFilter;
|
import com.l2jserver.model.world.filter.WorldObjectFilter;
|
||||||
import com.l2jserver.service.ServiceStartException;
|
import com.l2jserver.service.ServiceStartException;
|
||||||
import com.l2jserver.service.ServiceStopException;
|
import com.l2jserver.service.ServiceStopException;
|
||||||
|
|
||||||
public class WorldServiceImpl implements WorldService {
|
public class WorldServiceImpl implements WorldService {
|
||||||
private Set<WorldObject> objects;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start() throws ServiceStartException {
|
public void start() throws ServiceStartException {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
@@ -31,14 +28,15 @@ public class WorldServiceImpl implements WorldService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterator<WorldObject> iterator() {
|
public Iterator<WorldObject> iterator() {
|
||||||
return objects.iterator();
|
// return objects.iterator();
|
||||||
}
|
|
||||||
|
|
||||||
public <T extends WorldObject> Iterator<T> iterator(WorldFilter<T> filter) {
|
|
||||||
//return objects.iterator();
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public <T extends WorldObject> Iterator<T> iterator(WorldObjectFilter<T> filter) {
|
||||||
|
// return objects.iterator();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop() throws ServiceStopException {
|
public void stop() throws ServiceStopException {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|||||||
@@ -1,10 +1,18 @@
|
|||||||
package com.l2jserver.service.network;
|
package com.l2jserver.service.network;
|
||||||
|
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
|
import org.jboss.netty.bootstrap.ServerBootstrap;
|
||||||
|
import org.jboss.netty.channel.ServerChannel;
|
||||||
|
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.l2jserver.service.configuration.ConfigurationService;
|
import com.l2jserver.service.configuration.ConfigurationService;
|
||||||
|
|
||||||
public class NettyNetworkService implements NetworkService {
|
public class NettyNetworkService implements NetworkService {
|
||||||
private final NetworkConfiguration config;
|
private final NetworkConfiguration config;
|
||||||
|
private ServerBootstrap server;
|
||||||
|
private ServerChannel channel;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public NettyNetworkService(ConfigurationService configService) {
|
public NettyNetworkService(ConfigurationService configService) {
|
||||||
@@ -13,11 +21,19 @@ public class NettyNetworkService implements NetworkService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start() {
|
public void start() {
|
||||||
|
server = new ServerBootstrap(new NioServerSocketChannelFactory(
|
||||||
|
Executors.newCachedThreadPool(),
|
||||||
|
Executors.newCachedThreadPool()));
|
||||||
|
channel = (ServerChannel) server.bind(config.getListenAddress());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop() {
|
public void stop() {
|
||||||
|
try {
|
||||||
|
channel.close().awaitUninterruptibly();
|
||||||
|
} finally {
|
||||||
|
server = null;
|
||||||
|
channel = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
130
src/test/java/com/l2jserver/model/world/WorldTest.java
Normal file
130
src/test/java/com/l2jserver/model/world/WorldTest.java
Normal file
@@ -0,0 +1,130 @@
|
|||||||
|
package com.l2jserver.model.world;
|
||||||
|
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
|
import junit.framework.Assert;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.l2jserver.model.world.filter.impl.InstanceFilter;
|
||||||
|
import com.l2jserver.model.world.item.ItemDropEvent;
|
||||||
|
import com.l2jserver.model.world.item.ItemEvent;
|
||||||
|
import com.l2jserver.model.world.item.ItemListener;
|
||||||
|
import com.l2jserver.model.world.player.PlayerEvent;
|
||||||
|
import com.l2jserver.model.world.player.PlayerListener;
|
||||||
|
import com.l2jserver.model.world.player.PlayerSpawnEvent;
|
||||||
|
|
||||||
|
public class WorldTest {
|
||||||
|
@Test
|
||||||
|
public void testAdd() {
|
||||||
|
final World world = new World();
|
||||||
|
final Character character = new Character();
|
||||||
|
world.add(character);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRemove() {
|
||||||
|
final World world = new World();
|
||||||
|
final Character character = new Character();
|
||||||
|
world.add(character);
|
||||||
|
world.remove(character);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testContains() {
|
||||||
|
final World world = new World();
|
||||||
|
final Character character = new Character();
|
||||||
|
world.add(character);
|
||||||
|
Assert.assertTrue(world.contains(character));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIterator() {
|
||||||
|
final World world = new World();
|
||||||
|
final Character character1 = new Character();
|
||||||
|
final Character character2 = new Character();
|
||||||
|
final Item item1 = new Item();
|
||||||
|
world.add(character1);
|
||||||
|
world.add(character2);
|
||||||
|
world.add(item1);
|
||||||
|
|
||||||
|
for (final WorldObject o : world) {
|
||||||
|
Assert.assertNotNull(o);
|
||||||
|
}
|
||||||
|
final Iterable<Item> it = world.iterable(new InstanceFilter<Item>(
|
||||||
|
Item.class));
|
||||||
|
for (final WorldObject o : it) {
|
||||||
|
Assert.assertNotNull(o);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testListeners1() {
|
||||||
|
final World world = new World();
|
||||||
|
final Character character1 = new Character();
|
||||||
|
final Character character2 = new Character();
|
||||||
|
final Item item1 = new Item();
|
||||||
|
world.add(character1);
|
||||||
|
world.add(character2);
|
||||||
|
world.add(item1);
|
||||||
|
|
||||||
|
final AtomicBoolean bool = new AtomicBoolean();
|
||||||
|
Assert.assertFalse(bool.get());
|
||||||
|
character1.addListener(new PlayerListener() {
|
||||||
|
@Override
|
||||||
|
public void dispatch(PlayerEvent e) {
|
||||||
|
bool.set(true);
|
||||||
|
e.getPlayer().removeListener(this);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
character1.addListener(new PlayerListener() {
|
||||||
|
@Override
|
||||||
|
public void dispatch(PlayerEvent e) {
|
||||||
|
// bool.set(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
world.getDispatcher().dispatch(new PlayerSpawnEvent(character1));
|
||||||
|
Assert.assertTrue(bool.get());
|
||||||
|
|
||||||
|
bool.set(false);
|
||||||
|
|
||||||
|
world.getDispatcher().dispatch(new PlayerSpawnEvent(character1));
|
||||||
|
Assert.assertFalse(bool.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testListeners2() {
|
||||||
|
final World world = new World();
|
||||||
|
final Character character1 = new Character();
|
||||||
|
final Character character2 = new Character();
|
||||||
|
final Item item1 = new Item();
|
||||||
|
final Item item2 = new Item();
|
||||||
|
world.add(character1);
|
||||||
|
world.add(character2);
|
||||||
|
world.add(item1);
|
||||||
|
world.add(item2);
|
||||||
|
|
||||||
|
final AtomicBoolean bool1 = new AtomicBoolean();
|
||||||
|
final AtomicBoolean bool2 = new AtomicBoolean();
|
||||||
|
|
||||||
|
Assert.assertFalse(bool1.get());
|
||||||
|
Assert.assertFalse(bool2.get());
|
||||||
|
|
||||||
|
character1.addListener(new PlayerListener() {
|
||||||
|
@Override
|
||||||
|
public void dispatch(PlayerEvent e) {
|
||||||
|
bool1.set(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
item1.addListener(new ItemListener() {
|
||||||
|
@Override
|
||||||
|
public void dispatch(ItemEvent e) {
|
||||||
|
bool2.set(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
world.getDispatcher().dispatch(new ItemDropEvent(character1, item1));
|
||||||
|
Assert.assertTrue(bool1.get());
|
||||||
|
Assert.assertTrue(bool2.get());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user