aboutsummaryrefslogtreecommitdiff
path: root/minecraft-protocol/src/packets/mod.rs
blob: 5fb34743f28050e03f4fe163412332b14a8461c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
mod game;
mod handshake;
mod login;
mod status;

use async_trait::async_trait;
use tokio::io::AsyncRead;

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum ConnectionProtocol {
    Handshake = -1,
    Game = 0,
    Status = 1,
    Login = 2,
}

pub enum Packet<'a> {
    // game
    // handshake
    ClientIntentionPacket(&'a handshake::client_intention_packet::ClientIntentionPacket<'a>),
    // login
    // status
    ServerboundStatusRequestPacket(
        &'a status::serverbound_status_request_packet::ServerboundStatusRequestPacket,
    ),
    ClientboundStatusRequestPacket(
        &'a status::clientbound_status_response_packet::ClientboundStatusRequestPacket,
    ),
}

pub trait PacketTrait {
    /// Return a version of the packet that you can actually use for stuff
    fn get(&self) -> Packet;
    fn write(&self, buf: &mut Vec<u8>) -> ();
    fn parse<T: AsyncRead + std::marker::Unpin>(
        buf: &mut T,
        // is using a static lifetime here a good idea? idk
    ) -> Result<Packet<'_>, String>;
}