Skip to content

Commit

Permalink
Initial pass for #741
Browse files Browse the repository at this point in the history
  • Loading branch information
mbround18 committed Oct 7, 2023
1 parent 89cd1c9 commit 6084ba3
Show file tree
Hide file tree
Showing 12 changed files with 293 additions and 11 deletions.
118 changes: 114 additions & 4 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
<a href="https://github.com/mbround18/valheim-docker/actions/workflows/docker-release.yml"><img src="https://img.shields.io/github/actions/workflow/status/mbround18/valheim-docker/docker-release.yml?label=Docker&style=for-the-badge" alt=""></a>

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->

[![All Contributors](https://img.shields.io/badge/all_contributors-13-orange.svg?style=flat-square)](#contributors-)

<!-- ALL-CONTRIBUTORS-BADGE:END -->

## Table of Contents
Expand Down
6 changes: 6 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ services:
AUTO_UPDATE: 1
AUTO_UPDATE_SCHEDULE: "0 1 * * *"
TYPE: Vanilla
DEBUG_MODE: 1
PRESET: "Hammer"
MODIFIERS: |
raids=muchmore
combat=hard
deathpenalty=casual
build:
context: .
dockerfile: ./Dockerfile.valheim
Expand Down
1 change: 1 addition & 0 deletions src/odin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ zip = { version = "0.6.3" }
fs_extra = "1.2.0"
glob = "0.3.0"
a2s = "0.5.2"
serde_with = "3.3.0"

[dev-dependencies]
once_cell = "1"
Expand Down
18 changes: 16 additions & 2 deletions src/odin/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ pub struct Cli {
pub run_as_root: bool,

/// Make everything noisy but very helpful to identify issues.
#[arg(long)]
pub debug: bool,
/// This will enable debugging, you can use the env variable DEBUG_MODE to set this as well.
#[arg(long, env = "DEBUG_MODE", action = clap::ArgAction::Set)]
pub debug: String,

/// Will spit out the commands as if it were to run them but not really.
#[arg(short = 'r', long)]
Expand Down Expand Up @@ -52,6 +53,19 @@ pub enum Commands {
/// Sets the public state of the server, (Can be set with ENV variable PUBLIC)
#[arg(short = 'o', long, env = "PUBLIC")]
public: String,

/// Sets flag modifiers for launching the server, (Can be set with ENV variable MODIFIERS)
/// This should be comma separated with equal variables, e.g. "raids=none,combat=hard"
#[arg(long, env = "MODIFIERS")]
modifiers: Option<String>,

/// Sets flag preset for launching the server, (Can be set with ENV variable PRESET)
#[arg(long, env = "PRESET")]
preset: Option<String>,

/// Sets flag set_key for launching the server, (Can be set with ENV variable SET_KEY)
#[arg(long, env = "SET_KEY")]
set_key: Option<String>,
},

/// Installs Valheim with steamcmd
Expand Down
52 changes: 52 additions & 0 deletions src/odin/commands/configure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,71 @@ use crate::files::config::{config_file, write_config};
use crate::files::discord::{discord_file, write_discord};

use log::debug;
use serde::{Deserialize, Serialize};

/// See: https://user-images.githubusercontent.com/34519392/273088066-b9c94664-9eef-419d-999a-8b8798462dee.PNG
/// for a list of modifiers
#[derive(Deserialize, Serialize, Debug)]
pub struct Modifiers {
/// The name of the modifier
pub name: String,

/// The value of the modifier
pub value: String,
}

impl From<String> for Modifiers {
/// Creates a new modifier from a string
fn from(value: String) -> Self {
let mut split = value.split('=');
let name = split.next().unwrap().to_string();
let value = split.next().unwrap().to_string();
Modifiers { name, value }
}
}

pub struct Configuration {
/// Sets the name of the server, (Can be set with ENV variable NAME)
pub name: String,

/// Sets the servers executable path.
pub server_executable: String,

/// Sets the port of the server, (Can be set with ENV variable PORT)
pub port: u16,

/// Sets the world of the server, (Can be set with ENV variable WORLD)
pub world: String,

/// Sets the password of the server, (Can be set with ENV variable PASSWORD)
pub password: String,

/// Sets the public state of the server, (Can be set with ENV variable PUBLIC)
pub public: bool,

/// Sets flag preset for launching the server, (Can be set with ENV variable PRESET)
pub preset: Option<String>,

/// Sets flag modifiers for launching the server, (Can be set with ENV variable MODIFIERS)
pub modifiers: Option<Vec<Modifiers>>,

/// Sets flag set_key for launching the server, (Can be set with ENV variable SET_KEY)
pub set_key: Option<String>,
}

impl Configuration {
/// Creates a new configuration
#[allow(clippy::too_many_arguments)]
pub fn new(
name: String,
server_executable: String,
port: u16,
world: String,
password: String,
public: bool,
preset: Option<String>,
modifiers: Option<Vec<Modifiers>>,
set_key: Option<String>,
) -> Self {
Configuration {
name,
Expand All @@ -28,8 +75,13 @@ impl Configuration {
world,
password,
public,
preset,
modifiers,
set_key,
}
}

/// Invokes the configuration by writing the config file
pub fn invoke(self) {
debug!("Pulling config file...");
let config = config_file();
Expand Down
Loading

0 comments on commit 6084ba3

Please sign in to comment.