Move common components to shared lib

This commit is contained in:
NGnius (Graham) committed 2025-03-30 16:22:25 -04:00
1 parent 610f54e236
commit 0e048a17b1
76 files changed
+284 -1110

No files matched your search

@@ -1,878 +1,37 @@
use polariton_server::operations::SimpleFunc;
use polariton::operation::{ParameterTable, Typed};
use crate::data::player_data::*;
const PARAM_KEY: u8 = 8;
const VALID_ROBOT: &[u8] = &[64,
0,
0,
0,
38,
190,
25,
77,
24,
6,
29,
0,
80,
135,
103,
211,
27,
4,
27,
6,
80,
135,
103,
211,
21,
4,
27,
12,
198,
224,
138,
13,
24,
4,
26,
0,
198,
224,
138,
13,
24,
4,
27,
22,
198,
224,
138,
13,
24,
4,
28,
22,
198,
224,
138,
13,
24,
4,
25,
0,
198,
224,
138,
13,
24,
4,
29,
0,
198,
224,
138,
13,
23,
4,
29,
0,
198,
224,
138,
13,
23,
4,
28,
0,
198,
224,
138,
13,
23,
4,
27,
0,
198,
224,
138,
13,
23,
4,
26,
22,
198,
224,
138,
13,
23,
4,
25,
22,
198,
224,
138,
13,
25,
4,
29,
0,
198,
224,
138,
13,
25,
4,
27,
22,
198,
224,
138,
13,
25,
4,
28,
22,
198,
224,
138,
13,
25,
4,
26,
22,
198,
224,
138,
13,
25,
4,
25,
22,
198,
224,
138,
13,
26,
4,
29,
0,
198,
224,
138,
13,
26,
4,
28,
22,
198,
224,
138,
13,
26,
4,
27,
22,
198,
224,
138,
13,
26,
4,
26,
22,
198,
224,
138,
13,
26,
4,
25,
22,
198,
224,
138,
13,
22,
4,
25,
0,
198,
224,
138,
13,
22,
4,
26,
0,
198,
224,
138,
13,
22,
4,
27,
23,
198,
224,
138,
13,
22,
4,
28,
23,
198,
224,
138,
13,
22,
4,
29,
0,
198,
224,
138,
13,
25,
5,
29,
0,
198,
224,
138,
13,
23,
5,
29,
0,
198,
224,
138,
13,
24,
5,
29,
0,
198,
224,
138,
13,
22,
5,
28,
0,
198,
224,
138,
13,
26,
5,
28,
0,
198,
224,
138,
13,
25,
5,
26,
0,
198,
224,
138,
13,
23,
5,
26,
0,
198,
224,
138,
13,
24,
4,
24,
22,
198,
224,
138,
13,
24,
4,
23,
22,
198,
224,
138,
13,
24,
4,
22,
22,
198,
224,
138,
13,
24,
4,
21,
22,
198,
224,
138,
13,
24,
4,
20,
22,
198,
224,
138,
13,
24,
4,
19,
22,
198,
224,
138,
13,
24,
4,
18,
22,
198,
224,
138,
13,
24,
4,
17,
22,
198,
224,
138,
13,
24,
4,
16,
22,
198,
224,
138,
13,
24,
4,
15,
22,
198,
224,
138,
13,
24,
4,
14,
22,
198,
224,
138,
13,
23,
4,
17,
12,
198,
224,
138,
13,
25,
4,
17,
6,
198,
224,
138,
13,
23,
4,
16,
12,
198,
224,
138,
13,
25,
4,
16,
6,
198,
224,
138,
13,
23,
4,
15,
12,
198,
224,
138,
13,
25,
4,
15,
6,
198,
224,
138,
13,
23,
4,
14,
12,
198,
224,
138,
13,
25,
4,
14,
6,
198,
224,
138,
13,
22,
4,
17,
12,
198,
224,
138,
13,
26,
4,
17,
6,
198,
224,
138,
13,
22,
4,
16,
12,
198,
224,
138,
13,
26,
4,
16,
6,
198,
224,
138,
13,
22,
4,
15,
12,
198,
224,
138,
13,
26,
4,
15,
6,
198,
224,
138,
13,
22,
4,
14,
12,
198,
224,
138,
13,
26,
4,
14,
6,
240,
75,
110,
137,
21,
4,
15,
12,
240,
75,
110,
137,
27,
4,
15,
6];
const VALID_COLOUR: &[u8] = &[64,
0,
0,
0,
0,
24,
6,
29,
0,
27,
4,
27,
0,
21,
4,
27,
0,
24,
4,
26,
0,
24,
4,
27,
0,
24,
4,
28,
0,
24,
4,
25,
0,
24,
4,
29,
0,
23,
4,
29,
0,
23,
4,
28,
0,
23,
4,
27,
0,
23,
4,
26,
0,
23,
4,
25,
0,
25,
4,
29,
0,
25,
4,
27,
0,
25,
4,
28,
0,
25,
4,
26,
0,
25,
4,
25,
0,
26,
4,
29,
0,
26,
4,
28,
0,
26,
4,
27,
0,
26,
4,
26,
0,
26,
4,
25,
0,
22,
4,
25,
0,
22,
4,
26,
0,
22,
4,
27,
0,
22,
4,
28,
0,
22,
4,
29,
1,
25,
5,
29,
1,
23,
5,
29,
1,
24,
5,
29,
1,
22,
5,
28,
1,
26,
5,
28,
1,
25,
5,
26,
1,
23,
5,
26,
0,
24,
4,
24,
0,
24,
4,
23,
0,
24,
4,
22,
0,
24,
4,
21,
0,
24,
4,
20,
0,
24,
4,
19,
0,
24,
4,
18,
0,
24,
4,
17,
0,
24,
4,
16,
0,
24,
4,
15,
0,
24,
4,
14,
0,
23,
4,
17,
0,
25,
4,
17,
0,
23,
4,
16,
0,
25,
4,
16,
0,
23,
4,
15,
0,
25,
4,
15,
0,
23,
4,
14,
0,
25,
4,
14,
0,
22,
4,
17,
0,
26,
4,
17,
0,
22,
4,
16,
0,
26,
4,
16,
0,
22,
4,
15,
0,
26,
4,
15,
0,
22,
4,
14,
0,
26,
4,
14,
0,
21,
4,
15,
0,
27,
4,
15];
pub(super) fn tdm_machines_provider() -> SimpleFunc<1, crate::UserTy, impl (Fn(ParameterTable, &crate::UserTy) -> Result<ParameterTable, i16>) + Sync + Sync> {
SimpleFunc::new(|params, user: &crate::UserTy| {
let ulock = user.auth.read().unwrap();
let ulock = user.user()?;
let mut params = params.to_dict();
params.insert(PARAM_KEY, PlayerDatas {
players: vec![
PlayerData {
name: ulock.uuid.clone(),
display_name: ulock.uuid.clone(),
mastery: 1,
tier: 1,
robot_name: "RE_machine_name_mine_sp".to_owned(),
robot_map: VALID_ROBOT.iter().map(|x| *x).collect(),
team: 0,
has_premium: false,
robot_uuid: "12345_12345".to_owned(),
cpu: 0,
weapon_order: vec![20000200, 0, 0],
colour_map: VALID_COLOUR.iter().map(|x| *x).collect(),
is_ai: false,
spawn_effect: "Spawn_Warp".to_owned(),
death_effect: "Explosion_Warp".to_owned(),
player_rank: 1,
weapon_rank: vec![(20000200, 1), (0, 0)].into_iter().collect(),
},
// TODO: use SingleplayerEvent 3 (SpawnRobot) to spawn enemy bots instead
// doing it through this op response seems to have a bug/flaw (intentional?) in the code
/*PlayerData {
name: "RE_username0".to_owned(),
display_name: "RE_displayname0".to_owned(),
mastery: 1,
tier: 1,
robot_name: "RE_machine_name0_sp".to_owned(),
robot_map: VALID_ROBOT.iter().map(|x| *x).collect(),
team: 1,
has_premium: false,
robot_uuid: "123_123".to_owned(),
cpu: 0,
weapon_order: vec![20000200, 0, 0],
colour_map: VALID_COLOUR.iter().map(|x| *x).collect(),
is_ai: true,
spawn_effect: "Spawn_Warp".to_owned(),
death_effect: "Explosion_Warp".to_owned(),
player_rank: 1,
weapon_rank: vec![(20000200, 1), (0, 0)].into_iter().collect(),
},
PlayerData {
name: "RE_username1".to_owned(),
display_name: "RE_displayname1".to_owned(),
mastery: 1,
tier: 1,
robot_name: "RE_machine_name1_sp".to_owned(),
robot_map: VALID_ROBOT.iter().map(|x| *x).collect(),
team: 1,
has_premium: false,
robot_uuid: "12_12".to_owned(),
cpu: 0,
weapon_order: vec![20000200, 0, 0],
colour_map: VALID_COLOUR.iter().map(|x| *x).collect(),
is_ai: true,
spawn_effect: "Spawn_Warp".to_owned(),
death_effect: "Explosion_Warp".to_owned(),
player_rank: 1,
weapon_rank: vec![(20000200, 1), (0, 0)].into_iter().collect(),
},*/
]
}.as_transmissible());
let event_tx = user.event_tx.clone();
params.insert(PARAM_KEY, ulock.singleplayer_robots()?);
let event_tx = user.event_sender();
let user_bot_data = ulock.slot_by_id(ulock.selected_garage_slot() as _)?;
tokio::spawn(async move {
tokio::time::sleep(std::time::Duration::from_secs(10)).await;
log::debug!("Sending singleplayer events");
tokio::time::sleep(std::time::Duration::from_secs(20)).await;
log::debug!("Sending singleplayer event");
let mut spawn_params = std::collections::HashMap::with_capacity(4);
spawn_params.insert(2 /* robot GUID */, Typed::Str("12_12".into()));
spawn_params.insert(3 /* machine model */, Typed::Bytes(VALID_ROBOT.iter().map(|x| *x).collect::<Vec<_>>().into()));
spawn_params.insert(4 /* robot name */, Typed::Str("RE_robot_spawn_name0".into()));
spawn_params.insert(7 /* color model */, Typed::Bytes(VALID_COLOUR.iter().map(|x| *x).collect::<Vec<_>>().into()));
spawn_params.insert(2 /* robot GUID */, Typed::Str("1337_1337".into()));
spawn_params.insert(3 /* machine model */, user_bot_data.data);
spawn_params.insert(4 /* robot name */, Typed::Str("RE_robot_spawn_name0".into())); // FIXME
spawn_params.insert(7 /* color model */, user_bot_data.colour_data);
event_tx.send(polariton_server::ToSend::Data {
data: polariton::packet::Data::Event(polariton::operation::Event { code: 3, params: spawn_params.into() }),
encrypt: true,
channel: 0,
reliable: true,
}).unwrap();
let mut update_params = std::collections::HashMap::with_capacity(1);
/*let mut update_params = std::collections::HashMap::with_capacity(1);
update_params.insert(6 /* ??? */, Typed::Int(5));
event_tx.send(polariton_server::ToSend::Data {
data: polariton::packet::Data::Event(polariton::operation::Event { code: 5, params: update_params.into() }),
encrypt: true,
channel: 0,
reliable: true,
}).unwrap();
}).unwrap();*/
});
Ok(params.into())
})