Switch on packet type through an anonymous container

This commit is contained in:
deathcap 2016-01-23 17:02:07 -08:00
parent 74c5b74950
commit b9bc0e1cb8

View file

@ -58,40 +58,40 @@ proto.addType('fml|hsMapper',
// TODO: refactor to use one big switch like https://github.com/PrismarineJS/node-minecraft-protocol/blob/master/src/transforms/serializer.js#L21 // TODO: refactor to use one big switch like https://github.com/PrismarineJS/node-minecraft-protocol/blob/master/src/transforms/serializer.js#L21
proto.addType('FML|HS', proto.addType('FML|HS',
[ [
'container', "container",
[ [
{ {
"name": "discriminator", "name": "discriminator",
"type": "fml|hsMapper" "type": "fml|hsMapper"
}, },
// ServerHello
{ {
"name": "fmlProtocolVersionServer", "anon": true,
"type": [ "type":
[
"switch", "switch",
{ {
"compareTo": "discriminator", "compareTo": "discriminator",
"fields": { "fields":
"ServerHello": "byte" {
}, "ServerHello":
"default": "void" [
}, "container",
], [
{
"name": "fmlProtocolVersionServer",
"type": "byte"
}, },
{ {
"name": "overrideDimension", "name": "overrideDimension",
"type": [ "type":
"switch", [
{
"compareTo": "discriminator",
"fields": {
"ServerHello": [
"switch", "switch",
{ {
// "Only sent if protocol version is greater than 1." // "Only sent if protocol version is greater than 1."
"compareTo": "fmlProtocolVersion", "compareTo": "fmlProtocolVersionServer",
"fields": { "fields":
{
"0": "void", "0": "void",
"1": "void" "1": "void"
}, },
@ -99,39 +99,33 @@ proto.addType('FML|HS',
} }
] ]
}, },
"default": "void"
},
], ],
}, ],
// ClientHello "ClientHello":
[
"container",
[
{ {
"name": "fmlProtocolVersionClient", // TODO: merge or fix name collision with fmlProtocolVersionServer? "name": "fmlProtocolVersionClient",
"type": [ "type": "byte"
"switch",
{
"compareTo": "discriminator",
"fields": {
"ClientHello": "byte"
},
"default": "void"
} }
]
], ],
},
// ModList "ModList":
[
"container",
[
{ {
"name": "mods", "name": "mods",
"type": [ "type":
"switch", [
{
"compareTo": "discriminator",
"fields": {
"ModList": [
"array", "array",
{ {
"countType": "varint", "countType": "varint",
"type": [ "type":
[
"container", "container",
[ [
{ {
@ -145,57 +139,44 @@ proto.addType('FML|HS',
] ]
], ],
}, },
], ]
},
"default": "void"
} }
// TODO: mods array: modname string, modversion string
], ],
}, ],
// RegistryData "RegistryData":
[
"container",
[
{ {
"name": "hasMore", "name": "hasMore",
"type": [ "type": "boolean"
"switch",
{
"compareTo": "discriminator",
"fields": {
"RegistryData": "boolean"
}, },
"default": "void"
},
],
/* TODO: support all fields /* TODO: support all fields
"name": "registryName",
"type": [
"switch",
{ {
"compareTo": "discriminator", "name": "registryName",
"fields": { "type": "string"
"3": "string"
}, },
"default": "void"
},
],
*/ */
}, ],
],
// HandshakeAck "HandshakeAck":
[
"container",
[
{ {
"name": "phase", "name": "phase",
"type": [ "type": "byte"
"switch",
{
"compareTo": "discriminator",
"fields": {
"HandshakeAck": "byte"
},
"default": "void"
}, },
], ],
],
}, },
}
]
}
] ]
] ]
); );
@ -245,6 +226,7 @@ client.on('custom_payload', function(packet) {
data: clientHello data: clientHello
}); });
console.log('Sending client modlist');
var modList = proto.createPacketBuffer('FML|HS', { var modList = proto.createPacketBuffer('FML|HS', {
discriminator: 'ModList', discriminator: 'ModList',
//mods: [] //mods: []