Compare commits

..

3 Commits

15 changed files with 152 additions and 29 deletions

3
.gitignore vendored
View File

@ -1,4 +1,4 @@
/target
target/
.vscode
main
main.exe
@ -8,3 +8,4 @@ restarts.log
nohup.out
server.log
control_panel.log
onefetch.out

View File

@ -1,6 +1,6 @@
# VelNetServerRust
# VelNet Server
This basic, single-file relay server is designed to be used for network games, and is similar to Photon Realtime in design. It is written in Rust, with a single-threaded, non-blocking design and does not rely on any network frameworks (pure TCP/UDP). A Unity/C# client implementation can be found in our VelNetUnity repository.
This basic, single-file relay server is designed to be used for network games, and is similar to Photon Realtime in design. It is written in Rust, with a single-threaded, non-blocking design and does not rely on any network frameworks (pure TCP/UDP). A Unity/C# client implementation can be found in our [VelNetUnity](https://github.com/velaboratory/VelNetUnity) repository.
Like Photon, there is no built-in persistence of rooms or data. Rooms are created when the first client joins and destroyed when the last client leaves.
@ -12,12 +12,45 @@ The server supports both TCP and UDP transports.
## Running
1. Get a linoox server (also runs fine on windows & osx, but the instructions below are for linux)
### Option 1: Pull from Docker Hub
```sh
docker run -p 5000:5000 -p 5000:5000/udp velaboratory/velnet
```
or
```sh
docker run -p 5050:5000 -p 5050:5000/udp --name velnet velaboratory/velnet
```
To run on a different port and change the name of the container.
### Option 2: Use docker-compose
Runs both the control panel and the server.
```sh
docker compose up -d
```
to run, and
```sh
docker compose stop
```
to stop.
This builds the images from the local data in the folder, and doesn't pull anything from Docker Hub.
### Option 3: Run Rust natively
1. Get a linoox server (also runs fine on Windows & OSX, but the instructions below are for Linux)
2. Clone this repo
3. Edit config.json to an open port on your firewall
3. Edit `config.json` to an open port on your firewall
4. Modify the `user` field in `control-panel/config.json` to be your username.
5. Install rust through using rustup: https://rustup.rs/
6. Install: `sudo ./install.sh`
7. Run server: `sudo systemctl start velnet`
8. Run control panel: `sudo systemctl start velnet-control-panel`
9. Install tuptime: `cargo install tuptime`
9. Install onefetch: `cargo install onefetch`

View File

@ -1,7 +0,0 @@
/target
.vscode
main
main.exe
main.pdb
.idea/
onefetch.out

View File

@ -6,7 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
actix-web = "4"
actix-web = "4.1.0"
handlebars = { version = "4.2.1", features = ["dir_source"] }
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }

41
control-panel/Dockerfile Normal file
View File

@ -0,0 +1,41 @@
FROM rust:1.64 as build
# 1. Create a new empty shell project
RUN USER=root cargo new --bin velnet_control_panel
WORKDIR /velnet_control_panel
# 2. Copy our manifests
COPY ./Cargo.lock ./Cargo.lock
COPY ./Cargo.toml ./Cargo.toml
# 3. Build only the dependencies to cache them
RUN cargo build --release && rm src/*.rs
# 4. Now that the dependency is built, copy your source code
COPY ./src ./src
# 5. Build for release.
RUN rm ./target/release/deps/velnet_control_panel*
RUN cargo build --release
# our final base
FROM rust:1.64-slim
WORKDIR /velnet_control_panel
# RUN apt-get update && apt-get install -y extra-runtime-dependencies && rm -rf /var/lib/apt/lists/*
RUN apt update && apt install -y tuptime
# copy the build artifact from the build stage
COPY --from=build /velnet_control_panel/target/release/velnet_control_panel .
# Copy the config files and helper scripts
COPY static static
COPY config.json .
COPY onefetch_file.sh .
COPY git_pull.sh .
COPY compile_server.sh .
EXPOSE 8080
# run
CMD ["./velnet_control_panel"]

View File

@ -1,7 +1,7 @@
{
"port": 8080,
"user": "ntsfranz",
"server_log_file": "../server.log",
"server_log_file": "../logs/server.log",
"control_panel_log_file": "control_panel.log",
"server_dir": "../",
"handlebars_dev_mode": true

View File

@ -0,0 +1,4 @@
docker stop velnet_control_panel
docker build -t velaboratory/velnet_control_panel .
docker rm velnet_control_panel
docker run -d -p 8080:8080 --name velnet_control_panel velaboratory/velnet_control_panel

View File

@ -49,24 +49,24 @@ async fn index(hb: web::Data<Handlebars<'_>>) -> HttpResponse {
// let restarts_log = lines_from_file(config.restarts_log_file);
let uptime = Command::new("uptime")
let uptime = Command::new("tuptime")
.output()
.expect("failed to execute process");
let _onefetch = Command::new("sh")
.arg("onefetch_file.sh")
.arg(config.user)
.output()
.expect("failed");
// let _onefetch = Command::new("sh")
// .arg("onefetch_file.sh")
// .arg(config.user)
// .output()
// .expect("failed");
let onefetch = fs::read_to_string("onefetch.out").unwrap();
// let onefetch = fs::read_to_string("onefetch.out").unwrap();
let data = json!({
"log_output": &log_file[(cmp::max((log_file.len() as i64) - 1000, 0) as usize)..],
// "restarts_output": &restarts_log[(cmp::max((restarts_log.len() as i64) - 1000, 0) as usize)..],
"uptime": format!("{}", String::from_utf8_lossy(&uptime.stdout)),
//"onefetch": format!("{}", String::from_utf8_lossy(&onefetch.stdout))
"onefetch": onefetch.trim_end()
"onefetch": ""
});
let body = hb.render("index", &data).unwrap();

View File

@ -18,7 +18,7 @@
<style>
.bottom-scroller {
height: 40em;
max-height: 40em;
overflow: auto;
display: flex;
flex-direction: column-reverse;
@ -45,17 +45,16 @@
</section>
<section>
{{!-- <section>
<div class="container">
<div class="block">
<button class="button" id="restart-button">Restart Server</button>
<button class="button" id="pull-button">Git Pull</button>
<button class="button" id="compile-button">Compile</button>
</div>
<div class="block">Uptime: {{uptime}}</div>
<pre style="font-size: 0.8em;">{{onefetch}}</pre>
<pre style="font-size: 0.8em;">{{uptime}}</pre>
</div>
</section>
</section> --}}
<section class="section">
<div class="container">

19
docker-compose.yaml Normal file
View File

@ -0,0 +1,19 @@
version: "3.9"
services:
control-panel:
build: control-panel
ports:
- "8080:8080"
volumes:
- logs-volume:/logs
server:
build: server
ports:
- "5000:5000/tcp"
- "5000:5000/udp"
volumes:
- logs-volume:/logs
volumes:
logs-volume:

View File

32
server/Dockerfile Normal file
View File

@ -0,0 +1,32 @@
FROM rust:1.64 as build
# 1. Create a new empty shell project
RUN USER=root cargo new --bin velnet_server
WORKDIR /velnet_server
# 2. Copy our manifests
COPY ./Cargo.lock ./Cargo.lock
COPY ./Cargo.toml ./Cargo.toml
# 3. Build only the dependencies to cache them
RUN cargo build --release && rm src/*.rs
# 4. Now that the dependency is built, copy your source code
COPY ./src ./src
# 5. Build for release.
RUN rm ./target/release/deps/velnet_server*
RUN cargo build --release
# our final base
FROM debian:buster-slim
# copy the build artifact from the build stage
COPY --from=build /velnet_server/target/release/velnet_server .
COPY config.json .
EXPOSE 5000/tcp
EXPOSE 5000/udp
# run
CMD ["./velnet_server"]

View File

@ -1,5 +1,6 @@
{
"port": 5000,
"tcp_timeout": 30,
"log_file": "server.log"
"log_file": "logs/server.log"
}