~starkingdoms/starkingdoms

ref: 3f9784408f5c43e366106d0f547d80d9b33ffa37 starkingdoms/server/src/packet.rs -rw-r--r-- 1.6 KiB
3f978440 — ghostlyzsh attaching and despawning modules works 2 years ago
                                                                                
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
use crate::component::{PartType, PlanetType};
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize)]
pub struct ProtoTransform {
    pub x: f32,
    pub y: f32,
    pub rot: f32,
}
#[macro_export]
macro_rules! proto_transform {
    ($e:expr) => {
        $crate::packet::ProtoTransform {
            x: $e.translation.x,
            y: $e.translation.y,
            rot: $e.rotation.to_euler(bevy::math::EulerRot::ZYX).0,
        }
    };
}

#[derive(Debug, Serialize, Deserialize)]
pub struct Planet {
    pub planet_type: PlanetType,
    pub transform: ProtoTransform,
    pub radius: f32,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Part {
    pub part_type: PartType,
    pub transform: ProtoTransform,
}

#[derive(Debug, Serialize, Deserialize)]
pub enum MessageType {
    Server,
    Error,
    Chat,
    Direct,
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(tag = "t", content = "c")]
pub enum Packet {
    // serverbound
    ClientLogin {
        username: String,
        jwt: Option<String>,
    },
    SendMessage {
        target: Option<String>,
        content: String,
    },
    PlayerInput {
        up: bool,
        down: bool,
        left: bool,
        right: bool,
    },
    // clientbound
    SpawnPlayer {
        id: u32,
        username: String,
    },
    PlayerList {
        players: Vec<(u32, String)>,
    },
    PlanetPositions {
        planets: Vec<(u32, Planet)>,
    },
    PartPositions {
        parts: Vec<(u32, Part)>,
    },
    PlayerLeave {
        id: u32,
    },
    Message {
        message_type: MessageType,
        actor: String,
        content: String,
    },
}