Skip to content

Commit

Permalink
savefile mgmt stubs, fix chat, update theme, fix intents
Browse files Browse the repository at this point in the history
remove dashboard1 and redundant components
add counter on notifications
update build software versions
  • Loading branch information
circlesabound committed Mar 24, 2024
1 parent ffd0811 commit d49be62
Show file tree
Hide file tree
Showing 30 changed files with 1,400 additions and 597 deletions.
372 changes: 293 additions & 79 deletions Cargo.lock

Large diffs are not rendered by default.

19 changes: 11 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "fctrl"
version = "0.1.0"
authors = ["circlesabound <circlesabound@users.noreply.github.com>"]
authors = [ "circlesabound <circlesabound@users.noreply.github.com>" ]
edition = "2018"
license = "Apache-2.0"
publish = false
Expand All @@ -11,25 +11,25 @@ bincode = "1.3"
bytes = "1.0"
chrono = { version = "0.4", features = [ "serde" ] }
derive_more = "0.99"
env_logger = "0.10.1"
env_logger = "0.11.3"
factorio-mod-settings-parser = { git = "https://github.com/circlesabound/factorio-mod-settings-parser", rev = "a9fecd6" }
futures = "0.3"
futures-util = "0.3"
http = "1.0"
lazy_static = "1.4"
log = "0.4"
nix = { version = "0.27.1", features = [ "process", "signal" ] }
nix = { version = "0.28", features = [ "process", "signal" ] }
rcon = { version = "0.6", features = [ "rt-tokio" ] }
regex = "1.4"
reqwest = { version = "0.11", features = [ "json" ] }
rocksdb = "0.21"
reqwest = { version = "0.12.1", features = [ "json" ] }
rocksdb = "0.22"
rocket = { version = "0.5", features = [ "json" ] }
serde = { version = "1.0", features = [ "derive" ] }
serde_json = "1.0"
serenity = { version = "0.12", default-features = false, features = [ "client", "gateway", "rustls_backend", "model", "cache" ] }
stream-cancel = "0.8"
strum = "0.25"
strum_macros = "0.25.3"
strum = "0.26.2"
strum_macros = "0.26.2"
tar = "0.4"
tokio = { version = "1.5", features = [ "full" ] }
tokio-stream = { version = "0.1", features = [ "sync" ] }
Expand All @@ -41,7 +41,10 @@ uuid = { version = "1.6.1", features = [ "serde", "v4" ] }
xz2 = "0.1"

[dev-dependencies]
serial_test = "2.0.0"
serial_test = "3.0.0"

[target.'cfg(not(windows))'.dependencies]
openssl-sys = { version = "0.9", features = [ "vendored" ] }

[[bin]]
name = "agent"
Expand Down
8 changes: 4 additions & 4 deletions agent.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM rustlang/rust:nightly AS prepare
WORKDIR /usr/src/app
COPY rust-toolchain.toml .
RUN cargo install cargo-chef --version 0.1.33
RUN cargo install cargo-chef --version 0.1.66
COPY Cargo.toml .
COPY Cargo.lock .
COPY tests tests
Expand All @@ -11,7 +11,7 @@ RUN cargo chef prepare --recipe-path recipe.json
FROM rustlang/rust:nightly AS cache
WORKDIR /usr/src/app
COPY rust-toolchain.toml .
RUN cargo install cargo-chef --version 0.1.33
RUN cargo install cargo-chef --version 0.1.66
RUN apt-get update \
&& apt-get install -y clang
COPY --from=prepare /usr/src/app/recipe.json recipe.json
Expand All @@ -26,7 +26,7 @@ RUN apt-get update \
&& NODE_MAJOR=20 \
&& echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
RUN apt-get update \
&& apt-get install -y clang nodejs openjdk-11-jre-headless
&& apt-get install -y clang nodejs openjdk-17-jre-headless
COPY openapitools.json .
COPY package-lock.json .
COPY package.json .
Expand All @@ -42,7 +42,7 @@ COPY tests tests
COPY src src
RUN cargo build --release --bin agent

FROM debian:bullseye-slim AS runtime
FROM debian:bookworm-slim AS runtime
WORKDIR /app
RUN apt-get update \
&& apt-get install -y ca-certificates
Expand Down
10 changes: 5 additions & 5 deletions mgmt-server.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM rustlang/rust:nightly AS prepare
WORKDIR /usr/src/app
COPY rust-toolchain.toml .
RUN cargo install cargo-chef --version 0.1.33
RUN cargo install cargo-chef --version 0.1.66
COPY Cargo.toml .
COPY Cargo.lock .
COPY tests tests
Expand All @@ -11,7 +11,7 @@ RUN cargo chef prepare --recipe-path recipe.json
FROM rustlang/rust:nightly AS cache
WORKDIR /usr/src/app
COPY rust-toolchain.toml .
RUN cargo install cargo-chef --version 0.1.33
RUN cargo install cargo-chef --version 0.1.66
RUN apt-get update \
&& apt-get install -y clang
COPY --from=prepare /usr/src/app/recipe.json recipe.json
Expand All @@ -26,7 +26,7 @@ RUN apt-get update \
&& NODE_MAJOR=20 \
&& echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
RUN apt-get update \
&& apt-get install -y clang nodejs openjdk-11-jre-headless
&& apt-get install -y clang nodejs openjdk-17-jre-headless
COPY openapitools.json .
COPY package-lock.json .
COPY package.json .
Expand All @@ -42,7 +42,7 @@ COPY tests tests
COPY src src
RUN cargo build --release --bin mgmt-server

FROM node:current-alpine AS web-builder
FROM node:lts-alpine AS web-builder
WORKDIR /app/web
COPY web/package.json /app/web/package.json
COPY web/package-lock.json /app/web/package-lock.json
Expand All @@ -51,7 +51,7 @@ COPY web /app/web
COPY openapi /app/openapi
RUN npm run build -- --configuration production

FROM debian:bullseye-slim AS runtime
FROM debian:bookworm-slim AS runtime
WORKDIR /app
RUN apt-get update \
&& apt-get install -y ca-certificates
Expand Down
59 changes: 51 additions & 8 deletions openapi/mgmt-server-rest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ info:
version: 0.1.0

servers:
- url: /api/v0
- url: /api/v1

paths:
/auth/info:
Expand Down Expand Up @@ -81,6 +81,18 @@ paths:
responses:
'202':
description: Accepted
/server/control/create:
post:
summary: Sends a request to create a new savefile
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/ServerControlCreatePostRequest'
responses:
'202':
description: Request accepted, check the Location header for a websocket address to connect and monitor progress of the operation.
/server/install:
get:
summary: Gets the currently installed version of Factorio.
Expand All @@ -102,7 +114,7 @@ paths:
responses:
'202':
description: Request accepted, check the Location header for a websocket address to connect and monitor progress of the operation.
/server/savefile:
/server/savefiles:
get:
summary: Gets a list of savefiles currently on the server
responses:
Expand All @@ -112,19 +124,43 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/ServerSavefileGetResponse'
/server/savefile/{savefile_id}:
put:
summary: Create a savefile on the server
/server/savefiles/{savefile_id}:
get:
summary: Downloads the requested savefile as a zip
parameters:
- name: savefile_id
in: path
description: Name of the savefile to create
description: Name of the savefile to be uploaded to the server
required: true
schema:
type: string
responses:
'202':
description: Request accepted, check the Location header for a websocket address to connect and monitor progress of the operation.
'200':
description: Savefile zip
content:
application/octet-stream:
schema:
type: string
format: binary
post:
summary: Pushes a savefile to the server for use
parameters:
- name: savefile_id
in: path
description: Name of the savefile to be uploaded to the server
required: true
schema:
type: string
requestBody:
required: true
content:
application/octet-stream:
schema:
type: string
format: binary
responses:
'200':
description: Ok
/server/config/adminlist:
get:
summary: Gets the adminlist the Factorio server is configured to use.
Expand Down Expand Up @@ -462,6 +498,13 @@ components:
- PostGame
player_count:
type: integer
ServerControlCreatePostRequest:
required:
- savefile
properties:
savefile:
type: string
description: Name of the savefile to create
ServerControlStartPostRequest:
required:
- savefile
Expand Down
4 changes: 0 additions & 4 deletions src/agent/factorio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ pub struct Factorio {
pub version: String,
}

impl Factorio {
//
}

pub struct VersionManager {
install_dir: PathBuf,
pub versions: HashMap<String, Factorio>,
Expand Down
8 changes: 8 additions & 0 deletions src/agent/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,18 @@ impl AgentController {
self.save_create(save_name, operation_id).await
}

AgentRequest::SaveGet(save_name) => {
todo!()
}

AgentRequest::SaveList => {
self.save_list(operation_id).await;
}

AgentRequest::SaveSet(save_name, bytes) => {
todo!()
}

// **************
// Mod management
// **************
Expand Down
3 changes: 2 additions & 1 deletion src/mgmt-server/discord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ impl DiscordClient {
event_broker: Arc<EventBroker>,
) -> Result<DiscordClient> {
let cache = Arc::new(Cache::new());
let mut client_builder = serenity::Client::builder(&bot_token, GatewayIntents::all()); // BUG figure out gateway intents
let gateway_intents = GatewayIntents::default() | GatewayIntents::MESSAGE_CONTENT;
let mut client_builder = serenity::Client::builder(&bot_token, gateway_intents);
if let Some(chat_link_channel_id) = chat_link_channel_id {
let handler = Handler {
agent_client: Arc::clone(&agent_client),
Expand Down
3 changes: 2 additions & 1 deletion src/mgmt-server/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,13 @@ async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
routes::auth::discord_grant,
routes::auth::discord_refresh,
routes::server::status,
routes::server::create_savefile,
routes::server::start_server,
routes::server::stop_server,
routes::server::upgrade_install,
routes::server::get_install,
routes::server::get_savefile,
routes::server::get_savefiles,
routes::server::create_savefile,
routes::server::get_adminlist,
routes::server::put_adminlist,
routes::server::get_banlist,
Expand Down
44 changes: 27 additions & 17 deletions src/mgmt-server/routes/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,27 @@ pub async fn status(
}))
}

#[post("/server/control/create", data = "<savefile>")]
pub async fn create_savefile<'a>(
host: HostHeader<'a>,
_a: AuthorizedUser,
agent_client: &State<Arc<AgentApiClient>>,
ws: &State<Arc<WebSocketServer>>,
savefile: Json<ServerControlCreatePostRequest>,
) -> Result<WsStreamingResponder> {
let (id, sub) = agent_client.save_create(savefile.into_inner().savefile).await?;

let resp = WsStreamingResponder::new(Arc::clone(&ws), host, id);

let ws = Arc::clone(&ws);
let path = resp.path.clone();
tokio::spawn(async move {
ws.stream_at(path, sub, Duration::from_secs(300)).await;
});

Ok(resp)
}

#[post("/server/control/start", data = "<savefile>")]
pub async fn start_server(
_a: AuthorizedUser,
Expand Down Expand Up @@ -96,7 +117,7 @@ pub async fn upgrade_install<'a>(
Ok(resp)
}

#[get("/server/savefile")]
#[get("/server/savefiles")]
pub async fn get_savefiles(
_a: AuthorizedUser,
agent_client: &State<Arc<AgentApiClient>>,
Expand All @@ -112,25 +133,14 @@ pub async fn get_savefiles(
Ok(Json(ret))
}

#[put("/server/savefile/<id>")]
pub async fn create_savefile<'a>(
host: HostHeader<'a>,
#[get("/server/savefiles/<id>")]
pub async fn get_savefile(
_a: AuthorizedUser,
agent_client: &State<Arc<AgentApiClient>>,
ws: &State<Arc<WebSocketServer>>,
id: String,
) -> Result<WsStreamingResponder> {
let (id, sub) = agent_client.save_create(id).await?;

let resp = WsStreamingResponder::new(Arc::clone(&ws), host, id);

let ws = Arc::clone(&ws);
let path = resp.path.clone();
tokio::spawn(async move {
ws.stream_at(path, sub, Duration::from_secs(300)).await;
});

Ok(resp)
) -> Result<Option<WsStreamingResponder>> {
// TODO not implemented
Err(crate::error::Error::NotImplemented)
}

#[get("/server/config/adminlist")]
Expand Down
9 changes: 8 additions & 1 deletion src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,17 @@ pub enum AgentRequest {
// *********************************
//
//
/// Create a save file with the requested name.
/// Create a new save file with the requested name.
/// This will overwrite any existing save file of that name.
///
/// **This is a long-running operation.**
SaveCreate(String),
/// Gets the save file zip from the server
SaveGet(String),
/// Get a list of the save files present on the server.
SaveList,
/// Upserts a save file with the requested name
SaveSet(String, SaveBytes),

// *********************************
// * Mod management *
Expand Down Expand Up @@ -205,6 +209,9 @@ pub struct Save {
pub last_modified: DateTime<Utc>,
}

#[derive(Clone, Debug, Deserialize, derive_more::From, derive_more::Into, Serialize)]
pub struct SaveBytes(pub Vec<u8>);

#[derive(Clone, Debug, Deserialize, derive_more::From, derive_more::Into, Serialize)]
pub struct ModSettingsBytes(pub Vec<u8>);

Expand Down
3 changes: 2 additions & 1 deletion web/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
}
],
"styles": [
"src/styles.sass"
"src/styles.sass",
"node_modules/@angular/material/prebuilt-themes/deeppurple-amber.css"
],
"scripts": []
},
Expand Down
Loading

0 comments on commit d49be62

Please sign in to comment.