1
0
mirror of https://git.ngram.ca/OpenJam/rc-servers synced 2026-08-23 23:08:52 +00:00

Implement minimal chat service, fix some implement bugs

This commit is contained in:
NGnius (Graham)
2025-02-23 20:17:46 -05:00
parent 2907376722
commit 2106613f62
21 changed files with 227 additions and 194 deletions

View File

@@ -4,7 +4,7 @@ use clap::Parser;
#[command(version, about, long_about = None)]
pub struct CliArgs {
/// TCP port on which to accept connections
#[arg(short, long, default_value_t = 4534)]
#[arg(short, long, default_value_t = 4536)]
pub port: u16,
/// IP Address on which to accept connections
@@ -16,7 +16,7 @@ pub struct CliArgs {
pub retries: usize,
/// Domain and port of the game server to send new connections
#[arg(long, default_value_t = {"127.0.0.1:4535".to_string()})]
#[arg(long, default_value_t = {"127.0.0.1:4537".to_string()})]
pub redirect: String,
/// Name of game server to send new connections

View File

@@ -146,7 +146,7 @@ async fn send_packet(packet: Packet, buf: &mut Vec<u8>, socket: &mut net::TcpStr
Ok(())
}
const APP_ID: &str = "SocialServer";
const APP_ID: &str = "ChatServer";
struct AuthImpl;

View File

@@ -4,7 +4,7 @@ use clap::Parser;
#[command(version, about, long_about = None)]
pub struct CliArgs {
/// TCP port on which to accept connections
#[arg(short, long, default_value_t = 4535)]
#[arg(short, long, default_value_t = 4537)]
pub port: u16,
/// IP Address on which to accept connections

View File

@@ -1,23 +0,0 @@
use polariton::operation::Typed;
pub struct ClanInviteInfo {
pub username: String,
pub display_name: String,
pub clan_name: String,
pub clan_size: i32,
pub use_custom_avatar: bool,
pub avatar_id: i32,
}
impl ClanInviteInfo {
pub fn as_transmissible(&self) -> Typed {
Typed::HashMap(vec![
(Typed::Str("userName".into()), Typed::Str(self.username.clone().into())),
(Typed::Str("displayName".into()), Typed::Str(self.display_name.clone().into())),
(Typed::Str("clanName".into()), Typed::Str(self.clan_name.clone().into())),
(Typed::Str("clanSize".into()), Typed::Int(self.clan_size)),
(Typed::Str("useCustomAvatar".into()), Typed::Bool(self.use_custom_avatar.into())),
(Typed::Str("avatarId".into()), Typed::Int(self.avatar_id)),
].into())
}
}

View File

@@ -1,19 +0,0 @@
use polariton::operation::Typed;
pub struct AvatarInfo {
pub name: String,
pub use_custom_avatar: bool,
pub avatar_id: i32,
}
impl AvatarInfo {
pub fn as_transmissible(&self) -> Typed {
Typed::HashMap(vec![
(Typed::Str("name".into()), Typed::Str(self.name.clone().into())),
(Typed::Str("useCustomAvatar".into()), Typed::Bool(self.use_custom_avatar.into())),
(Typed::Str("avatarId".into()), Typed::Int(self.avatar_id)),
].into())
}
}
// TODO pub struct FriendInfo {}

View File

@@ -1,2 +0,0 @@
pub mod friend;
pub mod clan_invite;

View File

@@ -191,7 +191,7 @@ async fn send_packet(packet: Packet, buf: &mut Vec<u8>, socket: &mut net::TcpStr
Ok(())
}
const APP_ID: &str = "SocialServer";
const APP_ID: &str = "ChatServer";
struct AuthImpl;

View File

@@ -0,0 +1,17 @@
use polariton_server::operations::SimpleFunc;
use polariton::operation::{ParameterTable, Typed, Arr};
const PARAM_KEY: u8 = 15;
pub(super) fn ignores_provider() -> SimpleFunc<8, crate::UserTy, impl (Fn(ParameterTable, &crate::UserTy) -> Result<ParameterTable, i16>) + Sync + Sync> {
SimpleFunc::new(|params, _| {
let mut params = params.to_dict();
params.insert(PARAM_KEY, Typed::Arr(Arr {
ty: 115, // str
items: vec![
Typed::Str("Pluto".into()),
],
}));
Ok(params.into())
})
}

View File

@@ -1,26 +0,0 @@
use polariton_server::operations::SimpleFunc;
use polariton::operation::{ParameterTable, Typed, Arr};
use crate::data::clan_invite::*;
const PARAM_KEY: u8 = 42;
pub(super) fn clan_invites_provider() -> SimpleFunc<39, crate::UserTy, impl (Fn(ParameterTable, &crate::UserTy) -> Result<ParameterTable, i16>) + Sync + Sync> {
SimpleFunc::new(|params, _| {
let mut params = params.to_dict();
params.insert(PARAM_KEY, Typed::Arr(Arr {
ty: 104, // hashmap
items: vec![
ClanInviteInfo {
username: "RE_user1".to_owned(),
display_name: "RE_user1".to_owned(),
clan_name: "RE_clan1".to_owned(),
clan_size: 42,
use_custom_avatar: false,
avatar_id: 0,
}.as_transmissible()
],
}));
Ok(params.into())
})
}

View File

@@ -1,29 +0,0 @@
use polariton_server::operations::SimpleFunc;
use polariton::operation::{ParameterTable, Typed, Arr};
use crate::data::friend::*;
const FRIENDS_PARAM_KEY: u8 = 5;
const AVATAR_PARAM_KEY: u8 = 76;
pub(super) fn friends_provider() -> SimpleFunc<4, crate::UserTy, impl (Fn(ParameterTable, &crate::UserTy) -> Result<ParameterTable, i16>) + Sync + Sync> {
SimpleFunc::new(|params, _| {
let mut params = params.to_dict();
params.insert(FRIENDS_PARAM_KEY, Typed::Arr(Arr {
ty: 99, // custom
items: vec![Typed::Custom(vec![ // FIXME don't manually serialize
0u8, // byte custom type
0u8, 5u8, // short custom object size
3u8, 0u8, 0u8, 0u8, 0u8, // content
].into())] }));
params.insert(AVATAR_PARAM_KEY, Typed::Arr(Arr {
ty: 104, // hashmap
items: vec![AvatarInfo {
name: "".to_string(),
use_custom_avatar: false,
avatar_id: 1,
}.as_transmissible()],
}));
Ok(params.into())
})
}

View File

@@ -1,17 +1,13 @@
mod more_auth;
mod friend_list;
mod settings;
mod clan_invite;
mod chat_ignores;
mod pending_sanctions;
use polariton_server::operations::OperationsHandler;
pub fn handler() -> OperationsHandler<crate::UserTy> {
OperationsHandler::new()
.without_state(more_auth::MoreLobbyAuth)
.without_state(polariton_server::operations::Ack::<33, _>::default()) // get user clan info (this is equivalent to not being in a clan)
.without_state(friend_list::friends_provider()) // TODO friend object parsing Token: 0x0200169C RID: 5788
.without_state(settings::settings_provider()) // TODO save settings persistently
.without_state(polariton_server::operations::Ack::<43, _>::default()) // get my clan info (this is equivalent to not being in a clan)
.without_state(clan_invite::clan_invites_provider())
.without_state(polariton_server::operations::Ack::<19, _>::default()) // get pending platoon invite (this is equivalent to having no pending invite)
.without_state(chat_ignores::ignores_provider())
.without_state(pending_sanctions::pending_sanctions_checker())
//.without_state(polariton_server::operations::Ack::<00000, _>::default())
}

View File

@@ -0,0 +1,12 @@
use polariton_server::operations::SimpleFunc;
use polariton::operation::{ParameterTable, Typed};
const PARAM_KEY: u8 = 28;
pub(super) fn pending_sanctions_checker() -> SimpleFunc<15, crate::UserTy, impl (Fn(ParameterTable, &crate::UserTy) -> Result<ParameterTable, i16>) + Sync + Sync> {
SimpleFunc::new(|params, _| {
let mut params = params.to_dict();
params.insert(PARAM_KEY, Typed::Bool(false.into()));
Ok(params.into())
})
}

View File

@@ -1,20 +0,0 @@
use polariton_server::operations::SimpleFunc;
use polariton::operation::{ParameterTable, Typed, Arr};
use crate::data::friend::*;
const INVITER_NAME_PARAM_KEY: u8 = 19;
const INVITER_DISPLAY_NAME_PARAM_KEY: u8 = 75;
const INVITER_CUSTOM_AVATAR_NAME_PARAM_KEY: u8 = 13;
const INVITER_AVATAR_ID_NAME_PARAM_KEY: u8 = 14;
pub(super) fn platoon_pending_provider() -> SimpleFunc<19, crate::UserTy, impl (Fn(ParameterTable, &crate::UserTy) -> Result<ParameterTable, i16>) + Sync + Sync> {
SimpleFunc::new(|params, _| {
let mut params = params.to_dict();
params.insert(INVITER_NAME_PARAM_KEY, Typed::Str("RE_platoon_inviter".into())));
params.insert(INVITER_DISPLAY_NAME_PARAM_KEY, Typed::Str("RE_platoon_inviter_display".into())));
params.insert(INVITER_CUSTOM_AVATAR_NAME_PARAM_KEY, Typed::Bool(false.into())));
params.insert(INVITER_AVATAR_ID_NAME_PARAM_KEY, Typed::Int(1)));
Ok(params.into())
})
}

View File

@@ -1,16 +0,0 @@
use polariton_server::operations::SimpleFunc;
use polariton::operation::{ParameterTable, Typed, Dict};
const PARAM_KEY: u8 = 30;
pub(super) fn settings_provider() -> SimpleFunc<24, crate::UserTy, impl (Fn(ParameterTable, &crate::UserTy) -> Result<ParameterTable, i16>) + Sync + Sync> {
SimpleFunc::new(|params, _| {
let mut params = params.to_dict();
params.insert(PARAM_KEY, Typed::Dict(Dict {
key_ty: 115,
val_ty: 42,
items: Vec::default(),
}));
Ok(params.into())
})
}

View File

@@ -9,7 +9,7 @@ pub struct CubeInfo {
pub grey_out_in_tutorial: bool,
pub visibility: VisibilityMode,
pub indestructible: bool,
pub category: u32,
pub category: super::weapon_list::ItemCategory,
pub placements: u32, // default 63
pub protonium: bool,
pub unlocked_by_league: bool,

View File

@@ -48,8 +48,8 @@ pub struct GarageSlotInfo {
pub bay_cpu: u32,
pub tutorial_robot: bool, // assumed to be false (when omitted)
pub starter_robot_index: i32, // assumed to be -1 (whem omitted)
pub control_type: i32, // enum???
pub control_options: Vec<bool>,
pub control_type: ControlType,
pub control_options: ControlOptions,
pub mastery_level: i32,
pub bay_skin_id: String,
pub weapon_order: Vec<i32>,
@@ -75,10 +75,14 @@ impl GarageSlotInfo {
(Typed::Str("bayCpu".into()), Typed::Int(self.bay_cpu as i32)),
(Typed::Str("tutorialRobot".into()), Typed::Bool(self.tutorial_robot.into())),
(Typed::Str("starterRobotIndex".into()), Typed::Int(self.starter_robot_index)),
(Typed::Str("controlType".into()), Typed::Int(self.control_type)),
(Typed::Str("controlType".into()), Typed::Int(self.control_type as i32)),
(Typed::Str("controlOptions".into()), Typed::Arr(Arr {
ty: 111, // bool
items: self.control_options.iter().map(|&x| Typed::Bool(x.into())).collect(),
items: vec![
Typed::Bool(self.control_options.vertical_strafing.into()),
Typed::Bool(self.control_options.sideways_driving.into()),
Typed::Bool(self.control_options.tracks_turn_on_spot.into()),
],
})),
(Typed::Str("masteryLevel".into()), Typed::Int(self.mastery_level)),
(Typed::Str("baySkinId".into()), Typed::Str(self.bay_skin_id.clone().into())),
@@ -90,4 +94,19 @@ impl GarageSlotInfo {
}
}
#[allow(dead_code)]
#[repr(i32)]
#[derive(Copy, Clone)]
pub enum ControlType {
Camera = 0,
Keyboard = 1,
Count = 2,
}
pub struct ControlOptions {
pub vertical_strafing: bool,
pub sideways_driving: bool,
pub tracks_turn_on_spot: bool,
}

View File

@@ -145,19 +145,19 @@ impl WeaponData {
#[repr(u32)]
#[derive(Clone, Copy)]
pub enum ItemCategory {
NoFunction,
Wheel,
Hover,
Wing,
Rudder,
Thruster,
InsectLeg,
MechLeg,
Ski,
TankTrack,
Rotor,
SrpinterLeg,
Propeller,
NoFunction = 0,
Wheel = 1,
Hover = 2,
Wing = 3,
Rudder = 4,
Thruster = 5,
InsectLeg = 6,
MechLeg = 7,
Ski = 8,
TankTrack = 9,
Rotor = 10,
SrpinterLeg = 11,
Propeller = 12,
Laser = 100,
Plasma = 200,
Mortar = 250,
@@ -169,10 +169,10 @@ pub enum ItemCategory {
Seeker = 701,
Chaingun = 750,
ShieldModule = 800,
GhostModule,
BlinkModule,
EmpModule,
WindowmakerModule,
GhostModule = 801,
BlinkModule = 802,
EmpModule = 803,
WindowmakerModule = 804,
EnergyModule = 900,
}

View File

@@ -6,6 +6,7 @@ use polariton::operation::{ParameterTable, Typed, Dict};
use crate::data::cube_list::*;
const PARAM_KEY: u8 = 1;
// const DEFAULT_CUBE_ID: u32 = 227205318;
pub(super) fn cube_list_provider() -> SimpleFunc<2, crate::UserTy, impl (Fn(ParameterTable, &crate::UserTy) -> Result<ParameterTable, i16>) + Sync + Sync> {
SimpleFunc::new(|params, _| {
@@ -22,7 +23,7 @@ pub(super) fn cube_list_provider() -> SimpleFunc<2, crate::UserTy, impl (Fn(Para
grey_out_in_tutorial: false,
visibility: VisibilityMode::All,
indestructible: true,
category: 1,
category: crate::data::weapon_list::ItemCategory::NoFunction,
placements: 63,
protonium: false,
unlocked_by_league: false,
@@ -35,7 +36,133 @@ pub(super) fn cube_list_provider() -> SimpleFunc<2, crate::UserTy, impl (Fn(Para
cosmetic: false,
variant_of: "0".to_string(),
ignore_in_weapon_list: true,
}.as_transmissible())
}.as_transmissible()),
(Typed::Str("0".into()), CubeInfo {
cpu: 1,
health: 1,
health_boost: 1.0,
grey_out_in_tutorial: false,
visibility: VisibilityMode::All,
indestructible: true,
category: crate::data::weapon_list::ItemCategory::Laser,
placements: 63,
protonium: false,
unlocked_by_league: false,
league_unlock_index: 1,
stats: HashMap::default(),
description: "This is a very descriptive description".to_string(),
size: ItemTier::T0,
type_: ItemType::Weapon,
ranking: 1,
cosmetic: false,
variant_of: "0".to_string(),
ignore_in_weapon_list: true,
}.as_transmissible()),
(Typed::Str("1".into()), CubeInfo {
cpu: 1,
health: 1,
health_boost: 1.0,
grey_out_in_tutorial: false,
visibility: VisibilityMode::All,
indestructible: true,
category: crate::data::weapon_list::ItemCategory::Laser,
placements: 63,
protonium: false,
unlocked_by_league: false,
league_unlock_index: 1,
stats: HashMap::default(),
description: "This is a very descriptive description".to_string(),
size: ItemTier::T1,
type_: ItemType::Weapon,
ranking: 1,
cosmetic: false,
variant_of: "0".to_string(),
ignore_in_weapon_list: true,
}.as_transmissible()),
(Typed::Str("2".into()), CubeInfo {
cpu: 1,
health: 1,
health_boost: 1.0,
grey_out_in_tutorial: false,
visibility: VisibilityMode::All,
indestructible: true,
category: crate::data::weapon_list::ItemCategory::Laser,
placements: 63,
protonium: false,
unlocked_by_league: false,
league_unlock_index: 1,
stats: HashMap::default(),
description: "This is a very descriptive description".to_string(),
size: ItemTier::T2,
type_: ItemType::Weapon,
ranking: 1,
cosmetic: false,
variant_of: "0".to_string(),
ignore_in_weapon_list: true,
}.as_transmissible()),
(Typed::Str("3".into()), CubeInfo {
cpu: 1,
health: 1,
health_boost: 1.0,
grey_out_in_tutorial: false,
visibility: VisibilityMode::All,
indestructible: true,
category: crate::data::weapon_list::ItemCategory::Laser,
placements: 63,
protonium: false,
unlocked_by_league: false,
league_unlock_index: 1,
stats: HashMap::default(),
description: "This is a very descriptive description".to_string(),
size: ItemTier::T3,
type_: ItemType::Weapon,
ranking: 1,
cosmetic: false,
variant_of: "0".to_string(),
ignore_in_weapon_list: true,
}.as_transmissible()),
(Typed::Str("4".into()), CubeInfo {
cpu: 1,
health: 1,
health_boost: 1.0,
grey_out_in_tutorial: false,
visibility: VisibilityMode::All,
indestructible: true,
category: crate::data::weapon_list::ItemCategory::Laser,
placements: 63,
protonium: false,
unlocked_by_league: false,
league_unlock_index: 1,
stats: HashMap::default(),
description: "This is a very descriptive description".to_string(),
size: ItemTier::T4,
type_: ItemType::Weapon,
ranking: 1,
cosmetic: false,
variant_of: "0".to_string(),
ignore_in_weapon_list: true,
}.as_transmissible()),
(Typed::Str("5".into()), CubeInfo {
cpu: 1,
health: 1,
health_boost: 1.0,
grey_out_in_tutorial: false,
visibility: VisibilityMode::All,
indestructible: true,
category: crate::data::weapon_list::ItemCategory::Laser,
placements: 63,
protonium: false,
unlocked_by_league: false,
league_unlock_index: 1,
stats: HashMap::default(),
description: "This is a very descriptive description".to_string(),
size: ItemTier::T5,
type_: ItemType::Weapon,
ranking: 1,
cosmetic: false,
variant_of: "0".to_string(),
ignore_in_weapon_list: true,
}.as_transmissible()),
].into(),
}));
Ok(params.into())

View File

@@ -1,5 +1,5 @@
use polariton_server::operations::SimpleFunc;
use polariton::operation::{ParameterTable, Typed, Dict, Arr};
use polariton::operation::{ParameterTable, Typed, Dict};
use crate::data::custom_games::*;
@@ -11,26 +11,22 @@ pub(super) fn allowed_maps_provider() -> SimpleFunc<146, crate::UserTy, impl (Fn
let mut params = params.to_dict();
params.insert(MODE_MAP_PARAM_KEY, Typed::Dict(Dict {
key_ty: 115, // str
val_ty: 121, // arr
val_ty: 122, // obj arr
items: vec![
(Typed::Str(GameMode::BattleArena.as_str().into()), Typed::Arr(Arr {
ty: 115, // str
items: vec![
(Typed::Str(GameMode::BattleArena.as_str().into()), Typed::ObjArr(vec![
Typed::Str("Assets/Scenes/Planet_Neptune/RC_Planet_Neptune_02_BA".into()),
Typed::Str("Assets/Scenes/Planet_Mars/RC_Planet_Mars_03_BA".into()),
Typed::Str("Assets/Scenes/Planet_Mars/RC_Planet_Mars_02_BA".into()),
Typed::Str("Assets/Scenes/Planet_Earth/RC_Planet_Earth_02_BA".into()),
Typed::Str("Assets/Scenes/Planet_Earth/RC_Planet_Earth_01_BA".into()),
Typed::Str("Assets/Scenes/Planet_Neptune/RC_Planet_Neptune_03_BA".into()),
]
})),
(Typed::Str(GameMode::TeamDeathmatch.as_str().into()), Typed::Arr(Arr {
ty: 115, // str
items: vec![
].into())
),
(Typed::Str(GameMode::TeamDeathmatch.as_str().into()), Typed::ObjArr(vec![
Typed::Str("Assets/Scenes/Planet_Neptune/RC_Planet_Neptune_01_CTF".into()),
Typed::Str("Assets/Scenes/Planet_Mars/RC_Planet_Mars_01_CTF".into()),
]
})),
].into())
),
],
}));
params.insert(MAP_NAMES_PARAM_KEY, Typed::Dict(Dict {

View File

@@ -1,12 +1,14 @@
use polariton_server::operations::SimpleFunc;
use polariton::operation::{ParameterTable, Typed};
const PARAM_KEY: u8 = 2;
const MESSAGE_PARAM_KEY: u8 = 2;
const DISPLAY_TIME_PARAM_KEY: u8 = 15;
pub(super) fn dev_message_provider() -> SimpleFunc<8, crate::UserTy, impl (Fn(ParameterTable, &crate::UserTy) -> Result<ParameterTable, i16>) + Sync + Sync> {
SimpleFunc::new(|params, _| {
let mut params = params.to_dict();
params.insert(PARAM_KEY, Typed::Bytes(Vec::from("No jam was harmed in the reverse-engineering of this game".as_bytes()).into()));
params.insert(MESSAGE_PARAM_KEY, Typed::Bytes(Vec::from("No jam was harmed in the reverse-engineering of this game".as_bytes()).into()));
params.insert(DISPLAY_TIME_PARAM_KEY, Typed::Int(60 /* seconds??? */));
Ok(params.into())
})
}

View File

@@ -1,5 +1,5 @@
use polariton_server::operations::SimpleFunc;
use polariton::operation::{ParameterTable, Typed, Dict, Arr};
use polariton::operation::{ParameterTable, Typed, Dict};
use crate::data::garage_bay::*;
@@ -28,8 +28,8 @@ pub(super) fn garage_slot_provider() -> SimpleFunc<40, crate::UserTy, impl (Fn(P
bay_cpu: 2_000,
tutorial_robot: false,
starter_robot_index: -1,
control_type: 0,
control_options: vec![false, false],
control_type: ControlType::Camera,
control_options: ControlOptions { vertical_strafing: false, sideways_driving: false, tracks_turn_on_spot: false, },
mastery_level: 1,
bay_skin_id: "".to_owned(), // TODO
weapon_order: vec![0],
@@ -37,10 +37,9 @@ pub(super) fn garage_slot_provider() -> SimpleFunc<40, crate::UserTy, impl (Fn(P
],
}));
params.insert(SELECTED_SLOT_PARAM_KEY, Typed::Int(0));
params.insert(SLOT_ORDER_PARAM_KEY, Typed::Arr(Arr {
ty: 105, // int
items: vec![Typed::Int(0)],
}));
params.insert(SLOT_ORDER_PARAM_KEY, Typed::ObjArr(vec![
Typed::Int(0),
].into()));
Ok(params.into())
})
}