Hook up protocol generator for now
This commit is contained in:
parent
31e9a181a3
commit
47430c68d2
|
@ -45,4 +45,6 @@ else
|
||||||
feather_deps += [ libevent_pthreads_dep ]
|
feather_deps += [ libevent_pthreads_dep ]
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
python = find_program('python')
|
||||||
|
|
||||||
subdir('src')
|
subdir('src')
|
||||||
|
|
|
@ -30,21 +30,16 @@ namespace Feather
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
int clientProtocolVersion = packet.ReadVarInt();
|
HandshakeMessage handshake(packet);
|
||||||
string serverIp = packet.ReadString();
|
|
||||||
uint16_t port = packet.Read<uint16_t>();
|
|
||||||
|
|
||||||
// next desired state
|
|
||||||
ProtocolState intention = packet.ReadVarInt<ProtocolState>();
|
|
||||||
|
|
||||||
printf("[Protocol] Client Intention Packet: version=%d, serverIp=%s, port=%u, intention=%d\n",
|
printf("[Protocol] Client Intention Packet: version=%d, serverIp=%s, port=%u, intention=%d\n",
|
||||||
clientProtocolVersion,
|
handshake.protocolVersion,
|
||||||
serverIp.c_str(),
|
handshake.serverIP.c_str(),
|
||||||
port,
|
handshake.port,
|
||||||
intention
|
handshake.intention
|
||||||
);
|
);
|
||||||
|
|
||||||
context.SetState(intention);
|
context.SetState(handshake.intention);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -72,13 +67,13 @@ namespace Feather
|
||||||
}
|
}
|
||||||
case ServerboundStatusPacketId::Ping:
|
case ServerboundStatusPacketId::Ping:
|
||||||
{
|
{
|
||||||
int64_t timestamp = packet.Read<int64_t>();
|
PingMessage ping(packet);
|
||||||
printf("[Protocol] Client sent STATUS_PING: %lld\n", timestamp);
|
printf("[Protocol] Client sent STATUS_PING: %lld\n", ping.timestamp);
|
||||||
|
|
||||||
NetworkMessage msg(VARINT_MAX_SIZE + sizeof(int64_t));
|
NetworkMessage msg(VARINT_MAX_SIZE + sizeof(int64_t));
|
||||||
|
|
||||||
msg.WriteVarInt(ClientBoundStatusPacketId::Pong);
|
msg.WriteVarInt(ClientBoundStatusPacketId::Pong);
|
||||||
msg.Write<uint64_t>(timestamp);
|
msg.Write<uint64_t>(ping.timestamp);
|
||||||
msg.Finalize();
|
msg.Finalize();
|
||||||
|
|
||||||
client.SendMessage(msg);
|
client.SendMessage(msg);
|
||||||
|
@ -97,13 +92,14 @@ namespace Feather
|
||||||
{
|
{
|
||||||
case ServerboundLoginPacketId::LoginStart:
|
case ServerboundLoginPacketId::LoginStart:
|
||||||
{
|
{
|
||||||
std::string username = packet.ReadString();
|
LoginStartMessage loginStart(packet);
|
||||||
std::string uuid = "ecb99913-96a8-40a7-8529-a2ca6ad95768";
|
|
||||||
|
|
||||||
uuid.resize(36);
|
// 1.15.2...
|
||||||
username.resize(16);
|
//std::string uuid = "ecb99913-96a8-40a7-8529-a2ca6ad95768";
|
||||||
|
//uuid.resize(36);
|
||||||
|
//NetworkMessage msg(VARINT_MAX_SIZE * 3 + uuid.length() + loginStart.username.length());
|
||||||
|
|
||||||
NetworkMessage msg(VARINT_MAX_SIZE * 3 + uuid.length() + username.length());
|
NetworkMessage msg(VARINT_MAX_SIZE * 3 + 2 * sizeof(uint64_t) + loginStart.username.length());
|
||||||
|
|
||||||
msg.WriteVarInt(ClientboundLoginPacketId::LoginSuccess);
|
msg.WriteVarInt(ClientboundLoginPacketId::LoginSuccess);
|
||||||
// UUID 1.16.1
|
// UUID 1.16.1
|
||||||
|
@ -113,7 +109,7 @@ namespace Feather
|
||||||
// UUID 1.15.2
|
// UUID 1.15.2
|
||||||
//msg.WriteString(uuid.c_str(), uuid.length());
|
//msg.WriteString(uuid.c_str(), uuid.length());
|
||||||
|
|
||||||
msg.WriteString(username.c_str(), username.length());
|
msg.WriteString(loginStart.username.c_str(), loginStart.username.length());
|
||||||
msg.Finalize();
|
msg.Finalize();
|
||||||
|
|
||||||
client.SendMessage(msg);
|
client.SendMessage(msg);
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
#include "NetworkMessage.h"
|
#include "NetworkMessage.h"
|
||||||
|
#include "protocol/ProtocolDefinitions.h"
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
|
@ -11,14 +12,6 @@ namespace Feather
|
||||||
class PacketReader;
|
class PacketReader;
|
||||||
class MinecraftClient;
|
class MinecraftClient;
|
||||||
|
|
||||||
enum class ProtocolState : int32_t
|
|
||||||
{
|
|
||||||
Handholding = -1,
|
|
||||||
Play = 0,
|
|
||||||
Status = 1,
|
|
||||||
Login = 2,
|
|
||||||
};
|
|
||||||
|
|
||||||
class ProtocolContext
|
class ProtocolContext
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -18,7 +18,9 @@ feather_src = [
|
||||||
'config/ServerProperties.cpp',
|
'config/ServerProperties.cpp',
|
||||||
]
|
]
|
||||||
|
|
||||||
executable('FeatherMC', feather_src,
|
subdir('protocol')
|
||||||
|
|
||||||
|
executable('FeatherMC', feather_src, protocol_headers,
|
||||||
dependencies : feather_deps,
|
dependencies : feather_deps,
|
||||||
include_directories : include_directories('.', '../subprojects/rapidjson/include'),
|
include_directories : include_directories('.', '../subprojects/rapidjson/include'),
|
||||||
install : true,
|
install : true,
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import hjson
|
import hjson
|
||||||
|
import sys
|
||||||
|
|
||||||
text = ''
|
text = ''
|
||||||
|
|
||||||
|
@ -21,7 +22,10 @@ def print_states(states):
|
||||||
def get_rw_func(primitiveType, aliasedType, read):
|
def get_rw_func(primitiveType, aliasedType, read):
|
||||||
prefix = 'Read' if read else 'Write'
|
prefix = 'Read' if read else 'Write'
|
||||||
if aliasedType == 'varint':
|
if aliasedType == 'varint':
|
||||||
return '{}VarInt<{}>'.format(prefix, primitiveType)
|
if primitiveType == 'int32_t':
|
||||||
|
return '{}VarInt'.format(prefix)
|
||||||
|
else:
|
||||||
|
return '{}VarInt<{}>'.format(prefix, primitiveType)
|
||||||
elif aliasedType == 'string':
|
elif aliasedType == 'string':
|
||||||
return '{}String'.format(prefix)
|
return '{}String'.format(prefix)
|
||||||
else:
|
else:
|
||||||
|
@ -48,9 +52,10 @@ def print_messages(list, aliases, primitives, serverbound):
|
||||||
add_text(' {} {};', resolve_type(primitives, type), name)
|
add_text(' {} {};', resolve_type(primitives, type), name)
|
||||||
|
|
||||||
add_text(' }};')
|
add_text(' }};')
|
||||||
|
add_text('')
|
||||||
|
|
||||||
def print_protocol():
|
def print_protocol():
|
||||||
with open('protocol.hjson') as message_file:
|
with open(sys.argv[1]) as message_file:
|
||||||
message_scheme = hjson.load(message_file)
|
message_scheme = hjson.load(message_file)
|
||||||
|
|
||||||
print_states(message_scheme['states'])
|
print_states(message_scheme['states'])
|
||||||
|
@ -63,13 +68,24 @@ def print_protocol():
|
||||||
message_scheme['types']['primitives'],
|
message_scheme['types']['primitives'],
|
||||||
True)
|
True)
|
||||||
|
|
||||||
add_text('#pragma once')
|
def main():
|
||||||
add_text('')
|
if len(sys.argv) != 2:
|
||||||
add_text('#include <cstdint>')
|
print('Please specify the input file.')
|
||||||
add_text('')
|
return
|
||||||
add_text('namespace Feather')
|
|
||||||
add_text('{{')
|
|
||||||
print_protocol()
|
|
||||||
add_text('}}')
|
|
||||||
|
|
||||||
print(text)
|
add_text('#pragma once')
|
||||||
|
add_text('')
|
||||||
|
add_text('#include <cstdint>')
|
||||||
|
add_text('#include "PacketReader.h"')
|
||||||
|
add_text('')
|
||||||
|
add_text('namespace Feather')
|
||||||
|
add_text('{{')
|
||||||
|
print_protocol()
|
||||||
|
add_text('}}')
|
||||||
|
add_text('')
|
||||||
|
|
||||||
|
with open('ProtocolDefinitions.h', 'w') as out_file:
|
||||||
|
out_file.write(text)
|
||||||
|
out_file.close()
|
||||||
|
|
||||||
|
main()
|
|
@ -0,0 +1,4 @@
|
||||||
|
protocol_headers = custom_target('ProtocolHeader',
|
||||||
|
input : [ 'generate_protocol.py', 'protocol.hjson' ],
|
||||||
|
output : [ 'ProtocolDefinitions.h' ],
|
||||||
|
command : [ python, '@INPUT@' ])
|
|
@ -9,6 +9,7 @@
|
||||||
primitives :
|
primitives :
|
||||||
{
|
{
|
||||||
varint : int32_t
|
varint : int32_t
|
||||||
|
string : std::string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,6 +37,26 @@
|
||||||
intention : ProtocolState
|
intention : ProtocolState
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ping :
|
||||||
|
{
|
||||||
|
id : 1
|
||||||
|
state : Login
|
||||||
|
vars :
|
||||||
|
{
|
||||||
|
timestamp : uint64_t
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LoginStart :
|
||||||
|
{
|
||||||
|
id : 0
|
||||||
|
state : Login
|
||||||
|
vars :
|
||||||
|
{
|
||||||
|
username : string
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
clientbound :
|
clientbound :
|
||||||
|
|
Loading…
Reference in New Issue