~starkingdoms/starkingdoms

ref: 47203cc465de9356ff8f1df740e22ee6a7309713 starkingdoms/server/src/packet.rs -rw-r--r-- 3.2 KiB
47203cc4TerraMaster85 Tweak bound margin of dragging for Popup Component 1 year, 11 months 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// StarKingdoms.IO, a browser game about drifting through space
//     Copyright (C) 2023 ghostly_zsh, TerraMaster85, core
//
//     This program is free software: you can redistribute it and/or modify
//     it under the terms of the GNU Affero General Public License as published by
//     the Free Software Foundation, either version 3 of the License, or
//     (at your option) any later version.
//
//     This program is distributed in the hope that it will be useful,
//     but WITHOUT ANY WARRANTY; without even the implied warranty of
//     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//     GNU Affero General Public License for more details.
//
//     You should have received a copy of the GNU Affero General Public License
//     along with this program.  If not, see <https://www.gnu.org/licenses/>.
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,
    pub flags: ProtoPartFlags,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct ProtoPartFlags {
    pub attached: bool,
}

#[macro_export]
macro_rules! proto_part_flags {
    ($e:expr) => {
        $crate::packet::ProtoPartFlags {
            attached: $e.attached,
        }
    };
}

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

#[derive(Debug, Serialize, Deserialize)]
#[serde(tag = "t", content = "c")]
pub enum Packet {
    // serverbound
    ClientLogin {
        username: String,
        save: Option<String>,
        jwt: Option<String>,
    },
    SendMessage {
        target: Option<String>,
        content: String,
    },
    PlayerInput {
        up: bool,
        down: bool,
        left: bool,
        right: bool,
    },
    PlayerMouseInput {
        x: f32,
        y: f32,
        released: bool,
        button: ButtonType,
    },
    RequestSave {},
    // clientbound
    SpawnPlayer {
        id: u32,
        username: String,
    },
    PlayerList {
        players: Vec<(u32, String)>,
    },
    PlanetPositions {
        planets: Vec<(u32, Planet)>,
    },
    PartPositions {
        parts: Vec<(u32, Part)>,
    },
    SpawnPart {
        id: u32,
        part: Part,
    },
    DespawnPart {
        id: u32,
    },
    PlayerLeave {
        id: u32,
    },
    Message {
        message_type: MessageType,
        actor: String,
        content: String,
    },
    SaveEligibility {
        eligible: bool,
    },
    SaveData {
        payload: String,
    },
}