Skip to content

Commit

Permalink
wip: agent compiles again
Browse files Browse the repository at this point in the history
  • Loading branch information
cilki committed Jul 24, 2024
1 parent db1d58c commit 1893da3
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 106 deletions.
55 changes: 53 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion sandpolis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ egui = { version = "0.28", optional = true }

# Agent dependencies
sysinfo = { version = "0.30.13", optional = true }
dialoguer = { version = "0.11.0", optional = true }

[features]
server = [ "dep:axum", "dep:axum-server", "dep:axum-macros" ]
agent = [ "dep:sysinfo" ]
agent = [ "dep:sysinfo", "dep:dialoguer" ]
probe = [ "agent" ]
client = [ "dep:bevy", "dep:bevy_rapier2d", "dep:bevy_egui", "dep:egui" ]

Expand Down
18 changes: 0 additions & 18 deletions sandpolis/src/agent/messages.rs

This file was deleted.

78 changes: 19 additions & 59 deletions sandpolis/src/agent/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,82 +192,42 @@
use anyhow::{bail, Result};
use clap::Parser;
use std::collections::HashMap;
use std::io::BufRead;
use std::io::{BufRead, IsTerminal};
use std::net::TcpStream;
use std::{thread, time};
use tracing::{debug, error, info};

use crate::core::database::Database;
use crate::CommandLine;

#[derive(Parser, Debug, Clone)]
pub struct AgentCommandLine {}

pub async fn main(args: CommandLine) -> Result<()> {
// Load build metadata
if let Some(build_properties) = BinaryAssets::get("build.properties") {
let properties: HashMap<String, String> = parse_from_slice(&build_properties)
.expect("Failed to parse properties file")
.into_iter()
.collect();
let mut db = Database::new(None, "test", "test").await?;

// Output debug build info
debug!("Build platform: {}", properties["build.platform"]);
debug!("Build JVM version: {}", properties["build.java_version"]);

info!("Starting Sandpolis agent v{}", properties["build.version"]);
if let Some(servers) = args.server {
for server in servers {
db.add_server(&server, "test", "test").await?;
}
} else {
error!("Failed to locate embedded build.properties resource");
bail!("");
}

// Load agent configuration
if let Some(config_bytes) = BinaryAssets::get("config.bin") {
if let Ok(config) = AgentConfig::parse_from_bytes(&config_bytes) {
if std::io::stdout().is_terminal() {
// TODO prompt
print!("Please enter the server's address [127.0.0.1]: ");
} else {
error!("The embedded configuration is invalid")
bail!("Cannot configure server");
}
} else {
debug!("Failed to locate embedded configuration")
}

// Prompt user
info!("Preparing to configure agent");
print!("Please enter the server's address [127.0.0.1]: ");
// if prompt_bool("Configure client certificate authentication?", false) {}

let mut server_host = String::new();
std::io::stdin().read_line(&mut server_host)?;

if server_host == "" {
server_host = "127.0.0.1".to_string();
}

// Attempt a connection
info!("Attempting connection to server");
if let Ok(connection) = connect(server_host.as_str(), 8768) {
// TODO
}

if prompt_bool("Configure client certificate authentication?", false) {}

if prompt_bool("Configure password authentication? ", false) {
let password = prompt_string(
"Enter password: ",
"",
&predicate::function(|x: &String| x.len() >= 5_usize),
);
}
// if prompt_bool("Configure password authentication? ", false) {
// let password = prompt_string(
// "Enter password: ",
// "",
// &predicate::function(|x: &String| x.len() >= 5_usize),
// );
// }

return Ok(());
}

fn connection_routine(config: &AgentConfig_LoopConfig) {
debug!("Starting connection routine");

let mut iteration: i32 = 0;
while iteration < config.iteration_limit || config.iteration_limit == 0 {
iteration += 1;
if let Ok(connection) = connect("127.0.0.1", 8768) {}

thread::sleep(time::Duration::from_millis(config.cooldown as u64));
}
}
31 changes: 29 additions & 2 deletions sandpolis/src/client/ui/layer/desktop.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,36 @@
use bevy::prelude::*;
use bevy_egui::EguiContexts;

use crate::{client::ui::CurrentLayer, core::Layer};
use crate::{
client::ui::{node::NodeId, CurrentLayer},
core::Layer,
};

pub fn check_layer_active(current_layer: Res<CurrentLayer>) -> bool {
return **current_layer == Layer::Desktop;
}

pub fn handle_layer(mut commands: Commands) {}
pub fn handle_layer(
mut commands: Commands,
mut contexts: EguiContexts,
mut nodes: Query<(&mut Transform, &NodeId), With<NodeId>>,
mut windows: Query<&mut Window>,
mut cameras: Query<&Transform, (With<Camera2d>, Without<NodeId>)>,
) {
let window_size = windows.single_mut().size();
let camera_transform = cameras.single();

for (mut transform, id) in nodes.iter_mut() {
egui::Window::new("Hello")
.movable(false)
.resizable(false)
.pivot(egui::Align2::CENTER_TOP)
.current_pos(egui::Pos2::new(
window_size.x / 2.0 + transform.translation.x - camera_transform.translation.x,
window_size.y / 2.0 + transform.translation.y + camera_transform.translation.y,
))
.show(contexts.ctx_mut(), |ui| {
ui.label("world");
});
}
}
8 changes: 0 additions & 8 deletions sandpolis/src/client/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ pub fn run(state: AppState) {
self::input::handle_layer_change,
button_handler,
handle_lifetime,
// ui_example_system,
),
);

Expand All @@ -88,12 +87,6 @@ pub fn run(state: AppState) {
app.run();
}

// fn ui_example_system(mut contexts: EguiContexts) {
// egui::Window::new("Hello").show(contexts.ctx_mut(), |ui| {
// ui.label("world");
// });
// }

fn setup(
mut commands: Commands,
mut rapier_config: ResMut<RapierConfiguration>,
Expand All @@ -108,7 +101,6 @@ fn setup(
spawn_node(
&asset_server,
&mut commands,
&mut contexts,
state.db.metadata.id,
state.db.metadata.os_info.os_type(),
);
Expand Down
18 changes: 3 additions & 15 deletions sandpolis/src/client/ui/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use bevy_rapier2d::{

use crate::core::InstanceId;

#[derive(Component, Clone)]
#[derive(Component, Clone, Debug, Deref, DerefMut)]
pub struct NodeId(InstanceId);

#[derive(Bundle)]
Expand All @@ -22,31 +22,19 @@ pub struct Node {
pub fn spawn_node(
asset_server: &AssetServer,
commands: &mut Commands,
contexts: &mut EguiContexts,
instance_id: InstanceId,
os_type: os_info::Type,
) {
let node = Node {
commands.spawn(Node {
id: NodeId(instance_id),
collier: Collider::ball(50.0),
rigid_body: RigidBody::Dynamic,
// visibility: todo!(),
restitution: Restitution::coefficient(0.7),
sprite: SpriteBundle {
texture: asset_server.load(get_os_image(os_type)),
..default()
},
};

// TODO store a handle somehow
// egui::Window::new("Hello")
// .resizable(false)
// .movable(false)
// .show(contexts.ctx_mut(), |ui| {
// ui.label("world");
// });

commands.spawn(node);
});
}

pub fn get_os_image(os_type: os_info::Type) -> String {
Expand Down
5 changes: 5 additions & 0 deletions sandpolis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ use clap::Parser;
pub mod api;
pub mod core;

/// Build info
pub mod built_info {
include!(concat!(env!("OUT_DIR"), "/built.rs"));
}

#[derive(Parser, Debug, Clone)]
#[clap(author, version, about, long_about = None)]
pub struct CommandLine {
Expand Down
2 changes: 1 addition & 1 deletion sandpolis/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async fn main() -> Result<ExitCode> {
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
.init();

info!(os_info = ?os_info::get(), "Starting instance");
info!(os_info = ?os_info::get(), version = sandpolis::built_info::PKG_VERSION, build_time = sandpolis::built_info::BUILT_TIME_UTC, "Starting instance");

#[cfg(feature = "server")]
let server_thread = {
Expand Down

0 comments on commit 1893da3

Please sign in to comment.