Send game options to player at connection

This commit is contained in:
Sofia 2026-08-03 19:51:49 +03:00
parent ad574ec381
commit 6ba4e37bab
3 changed files with 7 additions and 2 deletions

View File

@ -2,7 +2,7 @@ use std::collections::HashMap;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive(Debug)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GameOptions { pub struct GameOptions {
pub values: HashMap<GameOption, GameOptionValue>, pub values: HashMap<GameOption, GameOptionValue>,
} }

View File

@ -12,7 +12,7 @@ use crate::{
announcer::Announcement, announcer::Announcement,
game::{ game::{
Game, GameManager, NetPlayer, Game, GameManager, NetPlayer,
opts::{GameOption, GameOptionValue}, opts::{GameOption, GameOptionValue, GameOptions},
}, },
game_settings::GameSettingsManager, game_settings::GameSettingsManager,
net::{net_stats::Stats, util::NetVector3}, net::{net_stats::Stats, util::NetVector3},
@ -321,6 +321,7 @@ pub enum Package {
NewPlayer(NetPlayer), NewPlayer(NetPlayer),
PlayerLeft(NetPlayer), PlayerLeft(NetPlayer),
SetTeam(u16, u8), SetTeam(u16, u8),
GameOptions(GameOptions),
GameOptionChanged(GameOption, GameOptionValue), GameOptionChanged(GameOption, GameOptionValue),
ChatMessage(u16, String), ChatMessage(u16, String),

View File

@ -264,6 +264,10 @@ impl NetworkManager {
self_id, self_id,
), ),
); );
peer.send_reliable(
&connection.address,
Package::GameOptions(game.bind().opts.clone()),
);
peer.broadcast_reliable(Package::NewPlayer( peer.broadcast_reliable(Package::NewPlayer(
game.bind().find_player(self_id).unwrap().clone().into(), game.bind().find_player(self_id).unwrap().clone().into(),
)); ));