mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-02 07:45:26 +00:00
refactor identification to its own method
This commit is contained in:
parent
ff33f1d42f
commit
e9805c3679
@ -105,4 +105,5 @@ private:
|
||||
thread_pool m_threadpool {};
|
||||
Sync<bool> m_shutdown { false };
|
||||
ip::udp::socket m_udp_socket { m_io };
|
||||
void handle_identification(ClientID id, const Packet& packet, std::shared_ptr<Client>& client);
|
||||
};
|
||||
|
@ -208,8 +208,23 @@ void Network::handle_packet(ClientID id, const Packet& packet) {
|
||||
// and fall through
|
||||
[[fallthrough]];
|
||||
case bmp::State::Identification:
|
||||
handle_identification(id, packet, client);
|
||||
break;
|
||||
case bmp::State::Authentication:
|
||||
break;
|
||||
case bmp::State::ModDownload:
|
||||
break;
|
||||
case bmp::State::SessionSetup:
|
||||
break;
|
||||
case bmp::State::Playing:
|
||||
break;
|
||||
case bmp::State::Leaving:
|
||||
break;
|
||||
}
|
||||
}
|
||||
void Network::handle_identification(ClientID id, const Packet& packet, std::shared_ptr<Client>& client) {
|
||||
switch (packet.purpose) {
|
||||
case bmp::Purpose::ProtocolVersion: {
|
||||
case bmp::ProtocolVersion: {
|
||||
struct bmp::ProtocolVersion protocol_version { };
|
||||
protocol_version.deserialize_from(packet.data);
|
||||
if (protocol_version.version.major != 1) {
|
||||
@ -230,7 +245,7 @@ void Network::handle_packet(ClientID id, const Packet& packet) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
case bmp::Purpose::ClientInfo: {
|
||||
case bmp::ClientInfo: {
|
||||
struct bmp::ClientInfo cinfo { };
|
||||
cinfo.deserialize_from(packet.data);
|
||||
beammp_debugf("{} is running game version: v{}.{}.{}, mod version: v{}.{}.{}, client implementation '{}' v{}.{}.{}",
|
||||
@ -258,14 +273,14 @@ void Network::handle_packet(ClientID id, const Packet& packet) {
|
||||
},
|
||||
};
|
||||
Packet sinfo_packet {
|
||||
.purpose = bmp::Purpose::ServerInfo,
|
||||
.purpose = bmp::ServerInfo,
|
||||
.data = std::vector<uint8_t>(1024),
|
||||
};
|
||||
sinfo.serialize_to(sinfo_packet.data);
|
||||
client->tcp_write(sinfo_packet);
|
||||
// now transfer to next state
|
||||
Packet auth_state {
|
||||
.purpose = bmp::Purpose::StateChangeAuthentication,
|
||||
.purpose = bmp::StateChangeAuthentication,
|
||||
};
|
||||
client->tcp_write(auth_state);
|
||||
break;
|
||||
@ -273,18 +288,6 @@ void Network::handle_packet(ClientID id, const Packet& packet) {
|
||||
default:
|
||||
beammp_errorf("Got 0x{:x} in state {}. This is not allowed disconnecting the client", uint16_t(packet.purpose), int(client->state));
|
||||
disconnect(id, "invalid purpose in current state");
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case bmp::State::Authentication:
|
||||
break;
|
||||
case bmp::State::ModDownload:
|
||||
break;
|
||||
case bmp::State::SessionSetup:
|
||||
break;
|
||||
case bmp::State::Playing:
|
||||
break;
|
||||
case bmp::State::Leaving:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user