netcode bugfixes
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit
This commit is contained in:
parent
c7cd9dfa34
commit
04336f6f30
@ -205,7 +205,10 @@ public class ClientNetworking implements Runnable {
|
||||
extraData.add(metadata);
|
||||
castMessage.setExtraData(extraData);
|
||||
} else {
|
||||
buff.get();
|
||||
byte errorCheckByte = buff.get();
|
||||
if(errorCheckByte != -1){
|
||||
LoggerInterface.loggerNetworking.WARNING("Error byte failed! " + errorCheckByte);
|
||||
}
|
||||
}
|
||||
});
|
||||
parser.registerCustomParser(TypeBytes.MESSAGE_TYPE_TERRAIN, TypeBytes.TERRAIN_MESSAGE_TYPE_SENDREDUCEDCHUNKDATA, (NetworkMessage message, ByteBuffer buff) -> {
|
||||
|
||||
@ -281,7 +281,7 @@ public class EntityProtocol implements ClientProtocolTemplate<EntityMessage> {
|
||||
try {
|
||||
newlySpawnedEntity = CommonEntityUtils.clientSpawnBasicObject(objectType);
|
||||
} catch (Error e){
|
||||
throw new Error(message.getentityID() + " " + objectType, e);
|
||||
throw new Error("Failed to spawn common entity: " + message.getentityID() + " \"" + objectType + "\"", e);
|
||||
}
|
||||
//position
|
||||
ClientEntityUtils.initiallyPositionEntity(
|
||||
|
||||
@ -246,8 +246,8 @@ public class AuthMessage extends NetworkMessage {
|
||||
|
||||
//
|
||||
//Write variable length table in packet
|
||||
ByteStreamUtils.writeInt(stream, user.length());
|
||||
ByteStreamUtils.writeInt(stream, pass.length());
|
||||
ByteStreamUtils.writeInt(stream, user.getBytes().length);
|
||||
ByteStreamUtils.writeInt(stream, pass.getBytes().length);
|
||||
|
||||
//
|
||||
//Write body of packet
|
||||
|
||||
@ -383,7 +383,7 @@ public class CharacterMessage extends NetworkMessage {
|
||||
|
||||
//
|
||||
//Write variable length table in packet
|
||||
ByteStreamUtils.writeInt(stream, data.length());
|
||||
ByteStreamUtils.writeInt(stream, data.getBytes().length);
|
||||
|
||||
//
|
||||
//Write body of packet
|
||||
@ -398,7 +398,7 @@ public class CharacterMessage extends NetworkMessage {
|
||||
|
||||
//
|
||||
//Write variable length table in packet
|
||||
ByteStreamUtils.writeInt(stream, data.length());
|
||||
ByteStreamUtils.writeInt(stream, data.getBytes().length);
|
||||
|
||||
//
|
||||
//Write body of packet
|
||||
@ -433,7 +433,7 @@ public class CharacterMessage extends NetworkMessage {
|
||||
|
||||
//
|
||||
//Write variable length table in packet
|
||||
ByteStreamUtils.writeInt(stream, data.length());
|
||||
ByteStreamUtils.writeInt(stream, data.getBytes().length);
|
||||
|
||||
//
|
||||
//Write body of packet
|
||||
@ -448,7 +448,7 @@ public class CharacterMessage extends NetworkMessage {
|
||||
|
||||
//
|
||||
//Write variable length table in packet
|
||||
ByteStreamUtils.writeInt(stream, data.length());
|
||||
ByteStreamUtils.writeInt(stream, data.getBytes().length);
|
||||
|
||||
//
|
||||
//Write body of packet
|
||||
|
||||
@ -338,8 +338,8 @@ public class CombatMessage extends NetworkMessage {
|
||||
|
||||
//
|
||||
//Write variable length table in packet
|
||||
ByteStreamUtils.writeInt(stream, hitboxType.length());
|
||||
ByteStreamUtils.writeInt(stream, hurtboxType.length());
|
||||
ByteStreamUtils.writeInt(stream, hitboxType.getBytes().length);
|
||||
ByteStreamUtils.writeInt(stream, hurtboxType.getBytes().length);
|
||||
|
||||
//
|
||||
//Write body of packet
|
||||
|
||||
@ -1365,8 +1365,8 @@ public class EntityMessage extends NetworkMessage {
|
||||
|
||||
//
|
||||
//Write variable length table in packet
|
||||
ByteStreamUtils.writeInt(stream, entitySubtype.length());
|
||||
ByteStreamUtils.writeInt(stream, creatureTemplate.length());
|
||||
ByteStreamUtils.writeInt(stream, entitySubtype.getBytes().length);
|
||||
ByteStreamUtils.writeInt(stream, creatureTemplate.getBytes().length);
|
||||
|
||||
//
|
||||
//Write body of packet
|
||||
@ -1480,7 +1480,7 @@ public class EntityMessage extends NetworkMessage {
|
||||
|
||||
//
|
||||
//Write variable length table in packet
|
||||
ByteStreamUtils.writeInt(stream, bone.length());
|
||||
ByteStreamUtils.writeInt(stream, bone.getBytes().length);
|
||||
|
||||
//
|
||||
//Write body of packet
|
||||
@ -1543,7 +1543,7 @@ public class EntityMessage extends NetworkMessage {
|
||||
|
||||
//
|
||||
//Write variable length table in packet
|
||||
ByteStreamUtils.writeInt(stream, interactionSignal.length());
|
||||
ByteStreamUtils.writeInt(stream, interactionSignal.getBytes().length);
|
||||
|
||||
//
|
||||
//Write body of packet
|
||||
|
||||
@ -1166,7 +1166,7 @@ public class InventoryMessage extends NetworkMessage {
|
||||
|
||||
//
|
||||
//Write variable length table in packet
|
||||
ByteStreamUtils.writeInt(stream, itemTemplate.length());
|
||||
ByteStreamUtils.writeInt(stream, itemTemplate.getBytes().length);
|
||||
|
||||
//
|
||||
//Write body of packet
|
||||
@ -1194,7 +1194,7 @@ public class InventoryMessage extends NetworkMessage {
|
||||
|
||||
//
|
||||
//Write variable length table in packet
|
||||
ByteStreamUtils.writeInt(stream, equipPointId.length());
|
||||
ByteStreamUtils.writeInt(stream, equipPointId.getBytes().length);
|
||||
|
||||
//
|
||||
//Write body of packet
|
||||
@ -1210,7 +1210,7 @@ public class InventoryMessage extends NetworkMessage {
|
||||
|
||||
//
|
||||
//Write variable length table in packet
|
||||
ByteStreamUtils.writeInt(stream, equipPointId.length());
|
||||
ByteStreamUtils.writeInt(stream, equipPointId.getBytes().length);
|
||||
|
||||
//
|
||||
//Write body of packet
|
||||
@ -1227,8 +1227,8 @@ public class InventoryMessage extends NetworkMessage {
|
||||
|
||||
//
|
||||
//Write variable length table in packet
|
||||
ByteStreamUtils.writeInt(stream, equipPointId.length());
|
||||
ByteStreamUtils.writeInt(stream, itemTemplate.length());
|
||||
ByteStreamUtils.writeInt(stream, equipPointId.getBytes().length);
|
||||
ByteStreamUtils.writeInt(stream, itemTemplate.getBytes().length);
|
||||
|
||||
//
|
||||
//Write body of packet
|
||||
@ -1247,7 +1247,7 @@ public class InventoryMessage extends NetworkMessage {
|
||||
|
||||
//
|
||||
//Write variable length table in packet
|
||||
ByteStreamUtils.writeInt(stream, equipPointId.length());
|
||||
ByteStreamUtils.writeInt(stream, equipPointId.getBytes().length);
|
||||
|
||||
//
|
||||
//Write body of packet
|
||||
@ -1264,7 +1264,7 @@ public class InventoryMessage extends NetworkMessage {
|
||||
|
||||
//
|
||||
//Write variable length table in packet
|
||||
ByteStreamUtils.writeInt(stream, equipPointId.length());
|
||||
ByteStreamUtils.writeInt(stream, equipPointId.getBytes().length);
|
||||
|
||||
//
|
||||
//Write body of packet
|
||||
@ -1279,7 +1279,7 @@ public class InventoryMessage extends NetworkMessage {
|
||||
|
||||
//
|
||||
//Write variable length table in packet
|
||||
ByteStreamUtils.writeInt(stream, equipPointId.length());
|
||||
ByteStreamUtils.writeInt(stream, equipPointId.getBytes().length);
|
||||
|
||||
//
|
||||
//Write body of packet
|
||||
@ -1297,8 +1297,8 @@ public class InventoryMessage extends NetworkMessage {
|
||||
|
||||
//
|
||||
//Write variable length table in packet
|
||||
ByteStreamUtils.writeInt(stream, itemTemplate.length());
|
||||
ByteStreamUtils.writeInt(stream, equipPointId.length());
|
||||
ByteStreamUtils.writeInt(stream, itemTemplate.getBytes().length);
|
||||
ByteStreamUtils.writeInt(stream, equipPointId.getBytes().length);
|
||||
|
||||
//
|
||||
//Write body of packet
|
||||
@ -1373,7 +1373,7 @@ public class InventoryMessage extends NetworkMessage {
|
||||
|
||||
//
|
||||
//Write variable length table in packet
|
||||
ByteStreamUtils.writeInt(stream, equipPointId.length());
|
||||
ByteStreamUtils.writeInt(stream, equipPointId.getBytes().length);
|
||||
|
||||
//
|
||||
//Write body of packet
|
||||
|
||||
@ -161,7 +161,7 @@ public class LoreMessage extends NetworkMessage {
|
||||
|
||||
//
|
||||
//Write variable length table in packet
|
||||
ByteStreamUtils.writeInt(stream, data.length());
|
||||
ByteStreamUtils.writeInt(stream, data.getBytes().length);
|
||||
|
||||
//
|
||||
//Write body of packet
|
||||
|
||||
@ -363,6 +363,8 @@ public abstract class NetworkMessage {
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new Error("Unsupported message type! " + firstByte);
|
||||
}
|
||||
if(rVal == null){
|
||||
//failed to read the message
|
||||
|
||||
@ -758,7 +758,7 @@ public class SynchronizationMessage extends NetworkMessage {
|
||||
|
||||
//
|
||||
//Write variable length table in packet
|
||||
ByteStreamUtils.writeInt(stream, stringValue.length());
|
||||
ByteStreamUtils.writeInt(stream, stringValue.getBytes().length);
|
||||
|
||||
//
|
||||
//Write body of packet
|
||||
@ -883,7 +883,7 @@ public class SynchronizationMessage extends NetworkMessage {
|
||||
|
||||
//
|
||||
//Write variable length table in packet
|
||||
ByteStreamUtils.writeInt(stream, stringValue.length());
|
||||
ByteStreamUtils.writeInt(stream, stringValue.getBytes().length);
|
||||
|
||||
//
|
||||
//Write body of packet
|
||||
|
||||
@ -813,7 +813,7 @@ public class TerrainMessage extends NetworkMessage {
|
||||
}
|
||||
TerrainMessage rVal = (TerrainMessage)pool.get(MessageType.TERRAIN_MESSAGE);
|
||||
rVal.messageType = TerrainMessageType.SENDREDUCEDCHUNKDATA;
|
||||
short pair = (short)((TypeBytes.MESSAGE_TYPE_TERRAIN << 4) & TypeBytes.TERRAIN_MESSAGE_TYPE_SENDREDUCEDCHUNKDATA);
|
||||
short pair = (short)((TypeBytes.MESSAGE_TYPE_TERRAIN << 4) | TypeBytes.TERRAIN_MESSAGE_TYPE_SENDREDUCEDCHUNKDATA);
|
||||
BiConsumer<NetworkMessage,ByteBuffer> customParser = customParserMap.get(pair);
|
||||
if(customParser == null){
|
||||
throw new Error("Custom parser undefined for message pair!");
|
||||
@ -879,7 +879,7 @@ public class TerrainMessage extends NetworkMessage {
|
||||
}
|
||||
TerrainMessage rVal = (TerrainMessage)pool.get(MessageType.TERRAIN_MESSAGE);
|
||||
rVal.messageType = TerrainMessageType.SENDREDUCEDBLOCKDATA;
|
||||
short pair = (short)((TypeBytes.MESSAGE_TYPE_TERRAIN << 4) & TypeBytes.TERRAIN_MESSAGE_TYPE_SENDREDUCEDBLOCKDATA);
|
||||
short pair = (short)((TypeBytes.MESSAGE_TYPE_TERRAIN << 4) | TypeBytes.TERRAIN_MESSAGE_TYPE_SENDREDUCEDBLOCKDATA);
|
||||
BiConsumer<NetworkMessage,ByteBuffer> customParser = customParserMap.get(pair);
|
||||
if(customParser == null){
|
||||
throw new Error("Custom parser undefined for message pair!");
|
||||
@ -1978,7 +1978,7 @@ public class TerrainMessage extends NetworkMessage {
|
||||
|
||||
//
|
||||
//Write variable length table in packet
|
||||
ByteStreamUtils.writeInt(stream, fabPath.length());
|
||||
ByteStreamUtils.writeInt(stream, fabPath.getBytes().length);
|
||||
|
||||
//
|
||||
//Write body of packet
|
||||
|
||||
@ -7,16 +7,16 @@ public class TypeBytes {
|
||||
/**
|
||||
* Message categories
|
||||
*/
|
||||
public static final byte MESSAGE_TYPE_ENTITY = 0;
|
||||
public static final byte MESSAGE_TYPE_LORE = 1;
|
||||
public static final byte MESSAGE_TYPE_PLAYER = 2;
|
||||
public static final byte MESSAGE_TYPE_TERRAIN = 3;
|
||||
public static final byte MESSAGE_TYPE_SERVER = 4;
|
||||
public static final byte MESSAGE_TYPE_AUTH = 5;
|
||||
public static final byte MESSAGE_TYPE_CHARACTER = 6;
|
||||
public static final byte MESSAGE_TYPE_INVENTORY = 7;
|
||||
public static final byte MESSAGE_TYPE_SYNCHRONIZATION = 8;
|
||||
public static final byte MESSAGE_TYPE_COMBAT = 9;
|
||||
public static final byte MESSAGE_TYPE_ENTITY = 1;
|
||||
public static final byte MESSAGE_TYPE_LORE = 2;
|
||||
public static final byte MESSAGE_TYPE_PLAYER = 3;
|
||||
public static final byte MESSAGE_TYPE_TERRAIN = 4;
|
||||
public static final byte MESSAGE_TYPE_SERVER = 5;
|
||||
public static final byte MESSAGE_TYPE_AUTH = 6;
|
||||
public static final byte MESSAGE_TYPE_CHARACTER = 7;
|
||||
public static final byte MESSAGE_TYPE_INVENTORY = 8;
|
||||
public static final byte MESSAGE_TYPE_SYNCHRONIZATION = 9;
|
||||
public static final byte MESSAGE_TYPE_COMBAT = 10;
|
||||
/*
|
||||
Entity subcategories
|
||||
*/
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
package electrosphere.net.parser.net.raw;
|
||||
|
||||
import electrosphere.net.parser.net.message.MessagePool;
|
||||
import electrosphere.net.parser.net.message.NetworkMessage;
|
||||
package electrosphere.net.parser.net.raw;
|
||||
|
||||
import electrosphere.net.parser.net.message.MessagePool;
|
||||
import electrosphere.net.parser.net.message.NetworkMessage;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
@ -82,6 +83,11 @@ public class NetworkParser {
|
||||
* The map of messasge type -> custom function to produce the message from a byte stream
|
||||
*/
|
||||
private Map<Short,BiConsumer<NetworkMessage,ByteBuffer>> customParserMap = new HashMap<Short,BiConsumer<NetworkMessage,ByteBuffer>>();
|
||||
|
||||
/**
|
||||
* Stores the most recent message type for debugging purposes
|
||||
*/
|
||||
private NetworkMessage mostRecentMessage = null;
|
||||
|
||||
|
||||
/**
|
||||
@ -122,9 +128,9 @@ public class NetworkParser {
|
||||
incomingByteBuffer.put(readBuffer, 0, bytesRead);
|
||||
|
||||
//fake flip
|
||||
incomingByteBuffer.position(0);
|
||||
incomingByteBuffer.limit(existingBytes + bytesRead);
|
||||
existingBytes = existingBytes + bytesRead;
|
||||
incomingByteBuffer.position(0);
|
||||
incomingByteBuffer.limit(existingBytes);
|
||||
|
||||
//tracking
|
||||
totalBytesRead = totalBytesRead + bytesRead;
|
||||
@ -133,8 +139,15 @@ public class NetworkParser {
|
||||
//for each message, append to clientIncomingMessageQueue
|
||||
NetworkMessage newMessage;
|
||||
if(existingBytes > 0 || bytesRead > 0){
|
||||
while((newMessage = NetworkMessage.parseBytestreamForMessage(incomingByteBuffer,this.pool,this.customParserMap)) != null){
|
||||
incomingMessageQueue.add(newMessage);
|
||||
try {
|
||||
newMessage = NetworkMessage.parseBytestreamForMessage(incomingByteBuffer,this.pool,this.customParserMap);
|
||||
while(newMessage != null){
|
||||
mostRecentMessage = newMessage;
|
||||
incomingMessageQueue.add(newMessage);
|
||||
newMessage = NetworkMessage.parseBytestreamForMessage(incomingByteBuffer,this.pool,this.customParserMap);
|
||||
}
|
||||
} catch (Error e){
|
||||
throw new Error(mostRecentMessage + " failed to parse!",e);
|
||||
}
|
||||
|
||||
//compact the byte buffer
|
||||
@ -251,7 +264,7 @@ public class NetworkParser {
|
||||
* @param parserFunc The parser function
|
||||
*/
|
||||
public void registerCustomParser(byte messageType, byte messageSubtype, BiConsumer<NetworkMessage,ByteBuffer> parserFunc){
|
||||
short pair = (short)((messageType << 4) & messageSubtype);
|
||||
short pair = (short)((messageType << 4) | messageSubtype);
|
||||
this.customParserMap.put(pair,parserFunc);
|
||||
}
|
||||
|
||||
|
||||
@ -364,7 +364,8 @@ public class TerrainProtocol implements ServerProtocolTemplate<TerrainMessage> {
|
||||
}
|
||||
toSend = buffer.array();
|
||||
} else {
|
||||
toSend = new byte[]{ 0 };
|
||||
//error checking byte
|
||||
toSend = new byte[]{ -1 };
|
||||
}
|
||||
|
||||
LoggerInterface.loggerNetworking.DEBUG("(Server) Send block data at " + worldX + " " + worldY + " " + worldZ);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user