Permalink
Browse files

Added protocol setup based on MC custom data packets

  • Loading branch information...
1 parent 918752e commit 63efa15546680857c0de161440e958b227412e82 @Raphfrk Raphfrk committed Apr 2, 2012
@@ -25,7 +25,6 @@
*/
package org.spout.vanilla;
-import org.spout.vanilla.material.VanillaMaterials;
import java.net.InetSocketAddress;
import java.util.HashMap;
@@ -43,7 +42,7 @@
import org.spout.api.math.Vector3;
import org.spout.api.plugin.CommonPlugin;
import org.spout.api.protocol.Protocol;
-
+import org.spout.api.protocol.common.CommonBootstrapProtocol;
import org.spout.vanilla.command.AdministrationCommands;
import org.spout.vanilla.command.TestCommands;
import org.spout.vanilla.configuration.VanillaConfiguration;
@@ -56,6 +55,7 @@
import org.spout.vanilla.generator.nether.NetherGenerator;
import org.spout.vanilla.generator.normal.NormalGenerator;
import org.spout.vanilla.generator.theend.TheEndGenerator;
+import org.spout.vanilla.material.VanillaMaterials;
import org.spout.vanilla.protocol.VanillaProtocol;
import org.spout.vanilla.protocol.bootstrap.VanillaBootstrapProtocol;
@@ -75,7 +75,7 @@ public VanillaPlugin() {
public void onLoad() {
// TODO - do we need a protocol manager ?
// getGame().getProtocolManager().register ...
- Protocol.registerProtocol(0, new VanillaProtocol());
+ Protocol.registerProtocol("VanillaProtocol", new VanillaProtocol());
Game game = getGame();
@@ -91,6 +91,7 @@ public void onLoad() {
}
((Server) game).bind(new InetSocketAddress(split[0], port), new VanillaBootstrapProtocol());
+ ((Server) game).bind(new InetSocketAddress(split[0], port + 1), new CommonBootstrapProtocol());
}
VanillaMaterials.initialize();
@@ -26,7 +26,7 @@
package org.spout.vanilla.protocol;
import org.spout.api.protocol.CodecLookupService;
-
+import org.spout.api.protocol.common.codec.CustomDataCodec;
import org.spout.vanilla.protocol.codec.AttachEntityCodec;
import org.spout.vanilla.protocol.codec.BlockActionCodec;
import org.spout.vanilla.protocol.codec.BlockChangeCodec;
@@ -37,7 +37,7 @@
import org.spout.vanilla.protocol.codec.CollectItemCodec;
import org.spout.vanilla.protocol.codec.CompressedChunkCodec;
import org.spout.vanilla.protocol.codec.CreateEntityCodec;
-import org.spout.vanilla.protocol.codec.CustomDataCodec;
+import org.spout.vanilla.protocol.codec.CreativeCodec;
import org.spout.vanilla.protocol.codec.DestroyEntityCodec;
import org.spout.vanilla.protocol.codec.DiggingCodec;
import org.spout.vanilla.protocol.codec.EnchantItemCodec;
@@ -71,7 +71,6 @@
import org.spout.vanilla.protocol.codec.PositionCodec;
import org.spout.vanilla.protocol.codec.PositionRotationCodec;
import org.spout.vanilla.protocol.codec.ProgressBarCodec;
-import org.spout.vanilla.protocol.codec.CreativeCodec;
import org.spout.vanilla.protocol.codec.RelativeEntityPositionCodec;
import org.spout.vanilla.protocol.codec.RelativeEntityPositionRotationCodec;
import org.spout.vanilla.protocol.codec.RespawnCodec;
@@ -26,7 +26,7 @@
package org.spout.vanilla.protocol.bootstrap;
import org.spout.api.protocol.CodecLookupService;
-
+import org.spout.api.protocol.common.codec.CustomDataCodec;
import org.spout.vanilla.protocol.codec.HandshakeCodec;
import org.spout.vanilla.protocol.codec.IdentificationCodec;
import org.spout.vanilla.protocol.codec.KickCodec;
@@ -40,6 +40,8 @@ public VanillaBootstrapCodecLookupService() {
bind(IdentificationCodec.class);
/* 0x02 */
bind(HandshakeCodec.class);
+ /* 0xFA */
+ bind(CustomDataCodec.class);
/* 0xFE */
bind(ServerListPingCodec.class);
/* 0xFF */
@@ -26,7 +26,8 @@
package org.spout.vanilla.protocol.bootstrap;
import org.spout.api.protocol.HandlerLookupService;
-
+import org.spout.api.protocol.common.handler.CustomDataMessageHandler;
+import org.spout.api.protocol.common.message.CustomDataMessage;
import org.spout.vanilla.protocol.bootstrap.handler.BootstrapHandshakeMessageHandler;
import org.spout.vanilla.protocol.bootstrap.handler.BootstrapIdentificationMessageHandler;
import org.spout.vanilla.protocol.bootstrap.handler.BootstrapPingMessageHandler;
@@ -40,6 +41,7 @@ public VanillaBootstrapHandlerLookupService() {
bind(HandshakeMessage.class, BootstrapHandshakeMessageHandler.class);
bind(IdentificationMessage.class, BootstrapIdentificationMessageHandler.class);
bind(ServerListPingMessage.class, BootstrapPingMessageHandler.class);
+ bind(CustomDataMessage.class, CustomDataMessageHandler.class);
} catch (Exception e) {
throw new ExceptionInInitializerError(e);
}
@@ -28,19 +28,13 @@
import org.spout.api.protocol.Message;
import org.spout.api.protocol.bootstrap.BootstrapProtocol;
-import org.spout.vanilla.protocol.msg.IdentificationMessage;
-
public class VanillaBootstrapProtocol extends BootstrapProtocol {
public VanillaBootstrapProtocol() {
super("VanillaBootstrap", new VanillaBootstrapCodecLookupService(), new VanillaBootstrapHandlerLookupService());
}
@Override
- public long detectProtocolDefinition(Message message) {
- if (message instanceof IdentificationMessage) {
- IdentificationMessage idMessage = (IdentificationMessage) message;
- return idMessage.getDimension();
- }
- return -1L;
+ public String detectProtocolDefinition(Message message) {
+ return "VanillaProtocol";
}
}
@@ -1,60 +0,0 @@
-/*
- * This file is part of Vanilla (http://www.spout.org/).
- *
- * Vanilla is licensed under the SpoutDev License Version 1.
- *
- * Vanilla is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * In addition, 180 days after any changes are published, you can use the
- * software, incorporating those changes, under the terms of the MIT license,
- * as described in the SpoutDev License Version 1.
- *
- * Vanilla is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License,
- * the MIT license and the SpoutDev License Version 1 along with this program.
- * If not, see <http://www.gnu.org/licenses/> for the GNU Lesser General Public
- * License and see <http://www.spout.org/SpoutDevLicenseV1.txt> for the full license,
- * including the MIT license.
- */
-package org.spout.vanilla.protocol.codec;
-
-import java.io.IOException;
-
-import org.jboss.netty.buffer.ChannelBuffer;
-import org.jboss.netty.buffer.ChannelBuffers;
-
-import org.spout.api.protocol.MessageCodec;
-
-import org.spout.vanilla.protocol.ChannelBufferUtils;
-import org.spout.vanilla.protocol.msg.CustomDataMessage;
-
-public class CustomDataCodec extends MessageCodec<CustomDataMessage> {
- public CustomDataCodec() {
- super(CustomDataMessage.class, 0xFA);
- }
-
- @Override
- public CustomDataMessage decode(ChannelBuffer buffer) throws IOException {
- String type = ChannelBufferUtils.readString(buffer);
- int length = buffer.readUnsignedShort();
- byte[] data = new byte[length];
- buffer.readBytes(data);
- return new CustomDataMessage(type, data);
- }
-
- @Override
- public ChannelBuffer encode(CustomDataMessage message) throws IOException {
- ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
- ChannelBufferUtils.writeString(buffer, message.getType());
- buffer.writeShort(message.getData().length);
- buffer.writeBytes(message.getData());
- return buffer;
- }
-}
@@ -1,53 +0,0 @@
-/*
- * This file is part of Vanilla (http://www.spout.org/).
- *
- * Vanilla is licensed under the SpoutDev License Version 1.
- *
- * Vanilla is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * In addition, 180 days after any changes are published, you can use the
- * software, incorporating those changes, under the terms of the MIT license,
- * as described in the SpoutDev License Version 1.
- *
- * Vanilla is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License,
- * the MIT license and the SpoutDev License Version 1 along with this program.
- * If not, see <http://www.gnu.org/licenses/> for the GNU Lesser General Public
- * License and see <http://www.spout.org/SpoutDevLicenseV1.txt> for the full license,
- * including the MIT license.
- */
-package org.spout.vanilla.protocol.msg;
-
-import java.util.Arrays;
-
-import org.spout.api.protocol.Message;
-
-public class CustomDataMessage extends Message {
- private final byte[] data;
- private final String type;
-
- public CustomDataMessage(String type, byte[] data) {
- this.type = type;
- this.data = data;
- }
-
- public String getType() {
- return type;
- }
-
- public byte[] getData() {
- return data;
- }
-
- @Override
- public String toString() {
- return "CustomDataMessage{" + "data=" + Arrays.toString(data) + ", type=" + type + '}';
- }
-}

0 comments on commit 63efa15

Please sign in to comment.