// use std::time::Duration; use csgo_gsi2::{GSIConfigBuilder, GSIServer, Subscription}; use csgo_gsi2::{Update}; use csgo_gsi2::update::player::{WeaponState, WeaponType::*}; #[tokio::main] async fn main() { let config = GSIConfigBuilder::new("csgo-gsi") // Use this to set config with instant request speed // Just example // .timeout(Duration::new(1,0)) // .buffer(Duration::new(0, 0)) // .throttle(Duration::new(0, 0)) // .heartbeat(Duration::new(30, 0)) .subscribe_multiple(Subscription::UNRESTRICTED) //UNRESTRICTED or SPECTATOR_ONLY .build(); let mut server = GSIServer::new(config, 3000); fn handle_update(update: &Update){ if let None = &update.map{ println!("Load map!"); return; } let player = update.player.as_ref().unwrap(); let state = player.state.as_ref().unwrap(); let weapons = &player.weapons; print!("\x1B[2J\x1B[1;1H"); //clear println!("Health: {}", state.health); println!("Armor: {}", state.armor); println!("Helmet: {}", state.helmet); println!("Money: {}", state.money); println!("Activity {:?}", player.activity); for (_k, weapon) in weapons.iter() { // The weapon that is currently active if let WeaponState::Active = weapon.state{ // Check weapon type // The taser has no type, but has an ammo clip. match weapon.r#type { Some(Knife) => println!("Knife"), Some(Fists) => println!("Fists"), Some(Melee) => println!("Melee"), Some(StackableItem) => println!("StackableItem"), Some(Tablet) => println!("Tablet"), Some(Grenade) => println!("Grenade"), Some(C4) => println!("C4"), _ => { if let None = weapon.ammo_clip{ // The shield has no type and no clip. if weapon.name == "weapon_shield" { println!("Shield") } return; } println!("{} ({}/{})", weapon.name, weapon.ammo_clip.unwrap(), weapon.ammo_reserve.unwrap()) } } } if let WeaponState::Reloading = weapon.state{ println!("Reloading..."); } } } server.add_listener(move |update| handle_update(update)); // Automatically install the .cfg in the csgo folder or use autoinstall feature // server.install(); // Install the .cfg to your csgo folder // let path = r"/home/user/.local/share/Steam/steamapps/common/Counter-Strike Global Offensive/csgo/cfg/"; // let result = server.install_into(path); // if let Err(error) = result { // eprintln!("{:#?}", error); // std::process::exit(1) // } server .run() .await .expect("server didn't start"); }