Skip to content

Commit

Permalink
Merge branch 'master' of github.com:MCHPR/MCHPRS
Browse files Browse the repository at this point in the history
  • Loading branch information
StackDoubleFlow committed Jul 2, 2023
2 parents ed519f5 + fec9b70 commit dc98685
Show file tree
Hide file tree
Showing 20 changed files with 81 additions and 43 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ jobs:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
toolchain: stable
target: ${{ matrix.target }}
profile: minimal
override: true
- uses: Swatinem/rust-cache@v1
with:
key: ${{ matrix.target }}
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true
toolchain: stable
- uses: Swatinem/rust-cache@v1
- name: Build
run: cargo test --verbose
9 changes: 5 additions & 4 deletions Cargo.lock

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

14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ Once complete, the optimized executable will be located at `./target/release/mch

MCHPRS will generate a `Config.toml` file in the current working directory when starting the server if it does not exist.

The folowing options are available at the toplevel (under no header):
| Field | Description | Default |
| --- | --- |--- |
| `bind_address` | Bind address and port | `0.0.0.0:25565` |
| `motd` | Message of the day | `"Minecraft High Performance Redstone Server"` |
| `chat_format` | How to format chat message interpolating `username` and `message` with curly braces | `<{username}> {message}` |
| `max_players` | Maximum number of simultaneous players | `99999` |
| `view_distance` | Maximal distance (in chunks) between players and loaded chunks | `8` |
| `bungeecord` | Enable compatibility with [BungeeCord](https://github.com/SpigotMC/BungeeCord) | `false` |
| `whitelist` | Whether or not the whitelist (in `whitelist.json`) shoud be enabled | `false` |
| `schemati` | Mimic the verification and directory layout used by the Open Redstone Engineers [Schemati plugin](https://github.com/OpenRedstoneEngineers/Schemati) | `false` |
| `block_in_hitbox` | Allow placing blocks inside of players (hitbox logic is simplified) | true |
| `auto_redpiler` | Use redpiler automatically | true |

### LuckPerms

MCHPRS has basic support for LuckPerms with MySQL or MariaDB remote database storage. This implementation has no commands or interface and would have to be manged through LuckPerms running on a proxy (`/lpb`) or other server (`/lp`)
Expand Down
3 changes: 2 additions & 1 deletion crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ ctrlc = { version = "3.1", features = ["termination"] }
tracing = "0.1"
chrono = "0.4"
rand = "0.8"
regex = { version = "1.4", features = ["pattern"] }
regex = { version = "1.4" }
backtrace = "0.3"
rusqlite = { version="0.28", features=["bundled"] }
anyhow = "1.0"
Expand All @@ -42,6 +42,7 @@ reqwest = { version = "0.11", features = ["json"] }
itertools = "0.10"
impls = "1"
bincode = "1.3"
once_cell = "1.14.0"
smallvec = "1.9.0"
petgraph = "0.6"
redpiler_graph = { path = "../redpiler_graph" }
Expand Down
25 changes: 22 additions & 3 deletions crates/core/src/blocks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,30 @@ trait BlockTransform {
fn flip(&mut self, dir: crate::blocks::FlipDirection);
}

impl<T> BlockTransform for T {
default fn rotate90(&mut self) {}
default fn flip(&mut self, _dir: crate::blocks::FlipDirection) {}
macro_rules! noop_block_transform {
($($ty:ty),*$(,)?) => {
$(
impl BlockTransform for $ty {
fn rotate90(&mut self) {}
fn flip(&mut self, dir: crate::blocks::FlipDirection) {}
}
)*
};
}

noop_block_transform!(
u8,
u32,
bool,
BlockColorVariant,
BlockFacing,
TrapdoorHalf,
SignType,
redstone::ButtonFace,
redstone::LeverFace,
redstone::ComparatorMode,
);

impl BlockTransform for BlockDirection {
fn flip(&mut self, dir: FlipDirection) {
match dir {
Expand Down
11 changes: 7 additions & 4 deletions crates/core/src/blocks/redstone/redstone_wire.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::blocks::{
};
use crate::world::World;
use std::collections::HashMap;
use std::convert::TryInto;
use std::str::FromStr;

impl Block {
Expand Down Expand Up @@ -628,16 +629,18 @@ impl RedstoneWireTurbo {
if self.nodes[upd1.index].neighbors.is_none() {
self.identify_neighbors(world, upd1);
}
// FIXME: Get rid of this nasty clone
let neighbors = self.nodes[upd1.index].neighbors.clone().unwrap();

let neighbors: [NodeId; 24] = self.nodes[upd1.index].neighbors.as_ref().unwrap()[0..24]
.try_into()
.unwrap();

let layer1 = layer + 1;

for neighbor_id in &neighbors[0..24] {
for neighbor_id in neighbors {
let neighbor = &mut self.nodes[neighbor_id.index];
if layer1 > neighbor.layer {
neighbor.layer = layer1;
self.update_queue[1].push(*neighbor_id);
self.update_queue[1].push(neighbor_id);
}
}

Expand Down
9 changes: 6 additions & 3 deletions crates/core/src/chat.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use once_cell::sync::Lazy;
use regex::Regex;
use serde::Serialize;
use std::sync::LazyLock;

static URL_REGEX: LazyLock<Regex> = LazyLock::new(|| {
static URL_REGEX: Lazy<Regex> = Lazy::new(|| {
Regex::new("([a-zA-Z0-9§\\-:/]+\\.[a-zA-Z/0-9§\\-:_#]+(\\.[a-zA-Z/0-9.§\\-:#\\?\\+=_]+)?)")
.unwrap()
});
Expand Down Expand Up @@ -220,7 +220,10 @@ impl ChatComponent {
for component in components {
let mut last = 0;
let text = &component.text;
for (index, matched) in text.match_indices(&*URL_REGEX) {

for match_ in URL_REGEX.find_iter(text) {
let index = match_.start();
let matched = match_.as_str();
if last != index {
let mut new = component.clone();
new.text = String::from(&text[last..index]);
Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::permissions::PermissionsConfig;
use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};
use std::fs;
use std::io::Write;
use std::sync::LazyLock;
use toml_edit::{value, Document};

pub static CONFIG: LazyLock<ServerConfig> = LazyLock::new(|| ServerConfig::load("Config.toml"));
pub static CONFIG: Lazy<ServerConfig> = Lazy::new(|| ServerConfig::load("Config.toml"));

trait ConfigSerializeDefault {
fn fix_config(self, name: &str, doc: &mut Document);
Expand Down
1 change: 0 additions & 1 deletion crates/core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![deny(rust_2018_idioms)]
#![feature(min_specialization, lazy_cell)]

#[macro_use]
mod utils;
Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/permissions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use crate::utils::HyphenatedUUID;
use anyhow::{anyhow, Context, Result};
use mysql::prelude::*;
use mysql::{OptsBuilder, Pool, PooledConn, Row};
use once_cell::sync::OnceCell;
use serde::{Deserialize, Serialize};
use std::sync::OnceLock;

static POOL: OnceLock<Pool> = OnceLock::new();
static POOL: OnceCell<Pool> = OnceCell::new();

fn conn() -> Result<PooledConn> {
Ok(POOL
Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/plot/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ use mchprs_network::packets::clientbound::{
use mchprs_network::packets::PacketEncoder;
use mchprs_network::PlayerPacketSender;
use mchprs_save_data::plot_data::Tps;
use once_cell::sync::Lazy;
use std::ops::Add;
use std::str::FromStr;
use std::sync::LazyLock;
use std::time::Instant;
use tracing::{debug, info, warn};

Expand Down Expand Up @@ -512,7 +512,7 @@ bitflags! {
// For more information, see https://wiki.vg/Command_Data
/// The `DeclareCommands` packet that is sent when the player joins.
/// This is used for command autocomplete.
pub static DECLARE_COMMANDS: LazyLock<PacketEncoder> = LazyLock::new(|| {
pub static DECLARE_COMMANDS: Lazy<PacketEncoder> = Lazy::new(|| {
CDeclareCommands {
nodes: &[
// 0: Root Node
Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/plot/data.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::{Plot, PlotWorld, PLOT_WIDTH};
use anyhow::{Context, Result};
use mchprs_save_data::plot_data::{ChunkData, PlotData, Tps};
use once_cell::sync::Lazy;
use std::path::Path;
use std::sync::LazyLock;
use std::time::Duration;

// TODO: where to put this?
Expand Down Expand Up @@ -33,7 +33,7 @@ pub fn empty_plot() -> PlotData {
EMPTY_PLOT.clone()
}

static EMPTY_PLOT: LazyLock<PlotData> = LazyLock::new(|| {
static EMPTY_PLOT: Lazy<PlotData> = Lazy::new(|| {
let template_path = Path::new("./world/plots/pTEMPLATE");
if template_path.exists() {
PlotData::load_from_file(template_path).expect("failed to read template plot")
Expand Down
5 changes: 3 additions & 2 deletions crates/core/src/plot/database.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use once_cell::sync::Lazy;
use rusqlite::{params, Connection};
use std::sync::{LazyLock, Mutex, MutexGuard};
use std::sync::{Mutex, MutexGuard};

static CONN: LazyLock<Mutex<Connection>> = LazyLock::new(|| {
static CONN: Lazy<Mutex<Connection>> = Lazy::new(|| {
Mutex::new(Connection::open("./world/plots.db").expect("Error opening plot database!"))
});

Expand Down
5 changes: 3 additions & 2 deletions crates/core/src/plot/worldedit/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use mchprs_blocks::items::{Item, ItemStack};
use mchprs_blocks::{BlockFace, BlockFacing, BlockPos};
use mchprs_network::packets::clientbound::*;
use mchprs_network::packets::SlotData;
use once_cell::sync::Lazy;
use schematic::{load_schematic, save_schematic};
use std::time::Instant;
use tracing::error;
Expand Down Expand Up @@ -252,8 +253,8 @@ pub(super) fn execute_paste(ctx: CommandExecuteContext<'_>) {
}
}

static SCHEMATI_VALIDATE_REGEX: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"[a-zA-Z0-9_.]+\.schem(atic)?").unwrap());
static SCHEMATI_VALIDATE_REGEX: Lazy<Regex> =
Lazy::new(|| Regex::new(r"[a-zA-Z0-9_.]+\.schem(atic)?").unwrap());

pub(super) fn execute_load(mut ctx: CommandExecuteContext<'_>) {
let start_time = Instant::now();
Expand Down
8 changes: 4 additions & 4 deletions crates/core/src/plot/worldedit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ use execute::*;
use mchprs_blocks::block_entities::{BlockEntity, ContainerType};
use mchprs_blocks::{BlockFacing, BlockPos};
use mchprs_utils::map;
use once_cell::sync::Lazy;
use rand::Rng;
use regex::Regex;
use std::collections::HashMap;
use std::fmt;
use std::ops::RangeInclusive;
use std::str::FromStr;
use std::sync::LazyLock;

// Attempts to execute a worldedit command. Returns true of the command was handled.
// The command is not handled if it is not found in the worldedit commands and alias lists.
Expand Down Expand Up @@ -433,7 +433,7 @@ impl Default for WorldeditCommand {
}
}

static COMMANDS: LazyLock<HashMap<&'static str, WorldeditCommand>> = LazyLock::new(|| {
static COMMANDS: Lazy<HashMap<&'static str, WorldeditCommand>> = Lazy::new(|| {
map! {
"up" => WorldeditCommand {
execute_fn: execute_up,
Expand Down Expand Up @@ -727,7 +727,7 @@ static COMMANDS: LazyLock<HashMap<&'static str, WorldeditCommand>> = LazyLock::n
}
});

static ALIASES: LazyLock<HashMap<&'static str, &'static str>> = LazyLock::new(|| {
static ALIASES: Lazy<HashMap<&'static str, &'static str>> = Lazy::new(|| {
map! {
"u" => "up",
"desc" => "descend",
Expand Down Expand Up @@ -803,7 +803,7 @@ impl FromStr for WorldEditPattern {
fn from_str(pattern_str: &str) -> PatternParseResult<WorldEditPattern> {
let mut pattern = WorldEditPattern { parts: Vec::new() };
for part in pattern_str.split(',') {
static RE: LazyLock<Regex> = LazyLock::new(|| {
static RE: Lazy<Regex> = Lazy::new(|| {
Regex::new(r"^(([0-9]+(\.[0-9]+)?)%)?(=)?([0-9]+|(minecraft:)?[a-zA-Z_]+)(:([0-9]+)|\[(([a-zA-Z_]+=[a-zA-Z0-9]+,?)+?)\])?((\|([^|]*?)){1,4})?$").unwrap()
});

Expand Down
6 changes: 3 additions & 3 deletions crates/core/src/plot/worldedit/schematic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ use anyhow::{bail, Context, Result};
use itertools::Itertools;
use mchprs_blocks::block_entities::BlockEntity;
use mchprs_blocks::BlockPos;
use once_cell::sync::Lazy;
use regex::Regex;
use serde::Serialize;
use std::collections::HashMap;
use std::fs::{self, File};
use std::path::PathBuf;
use std::sync::LazyLock;

macro_rules! nbt_as {
// I'm not sure if path is the right type here.
Expand All @@ -28,8 +28,8 @@ macro_rules! nbt_as {
}

fn parse_block(str: &str) -> Option<Block> {
static RE: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"(?:minecraft:)?([a-z_]+)(?:\[([a-z=,0-9]+)\])?").unwrap());
static RE: Lazy<Regex> =
Lazy::new(|| Regex::new(r"(?:minecraft:)?([a-z_]+)(?:\[([a-z=,0-9]+)\])?").unwrap());
let captures = RE.captures(str)?;
let mut block = Block::from_name(captures.get(1)?.as_str()).unwrap_or(Block::Air {});
if let Some(properties_match) = captures.get(2) {
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM rustlang/rust:nightly-slim
FROM rust:slim

RUN apt-get update \
&& apt-get install -y \
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile-plot-scale-5
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM rustlang/rust:nightly-slim
FROM rust:slim

RUN apt-get update \
&& apt-get install -y \
Expand Down
2 changes: 0 additions & 2 deletions rust-toolchain.toml

This file was deleted.

0 comments on commit dc98685

Please sign in to comment.