Compare commits
3 Commits
v1.0
...
asyncversi
| Author | SHA1 | Date |
|---|---|---|
|
|
8d32426962 | |
|
|
5f52900ded | |
|
|
5200ba7723 |
|
|
@ -1,4 +1,4 @@
|
||||||
/target
|
target/
|
||||||
.vscode
|
.vscode
|
||||||
main
|
main
|
||||||
main.exe
|
main.exe
|
||||||
|
|
@ -7,4 +7,5 @@ main.pdb
|
||||||
restarts.log
|
restarts.log
|
||||||
nohup.out
|
nohup.out
|
||||||
server.log
|
server.log
|
||||||
control_panel.log
|
control_panel.log
|
||||||
|
onefetch.out
|
||||||
41
README.md
41
README.md
|
|
@ -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.
|
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
|
## 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
|
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.
|
4. Modify the `user` field in `control-panel/config.json` to be your username.
|
||||||
5. Install rust through using rustup: https://rustup.rs/
|
5. Install rust through using rustup: https://rustup.rs/
|
||||||
6. Install: `sudo ./install.sh`
|
6. Install: `sudo ./install.sh`
|
||||||
7. Run server: `sudo systemctl start velnet`
|
7. Run server: `sudo systemctl start velnet`
|
||||||
8. Run control panel: `sudo systemctl start velnet-control-panel`
|
8. Run control panel: `sudo systemctl start velnet-control-panel`
|
||||||
|
9. Install tuptime: `cargo install tuptime`
|
||||||
9. Install onefetch: `cargo install onefetch`
|
9. Install onefetch: `cargo install onefetch`
|
||||||
|
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
/target
|
|
||||||
.vscode
|
|
||||||
main
|
|
||||||
main.exe
|
|
||||||
main.pdb
|
|
||||||
.idea/
|
|
||||||
onefetch.out
|
|
||||||
|
|
@ -6,7 +6,7 @@ edition = "2021"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-web = "4"
|
actix-web = "4.1.0"
|
||||||
handlebars = { version = "4.2.1", features = ["dir_source"] }
|
handlebars = { version = "4.2.1", features = ["dir_source"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
|
|
||||||
|
|
@ -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"]
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"port": 8080,
|
"port": 8080,
|
||||||
"user": "ntsfranz",
|
"user": "ntsfranz",
|
||||||
"server_log_file": "../server.log",
|
"server_log_file": "../logs/server.log",
|
||||||
"control_panel_log_file": "control_panel.log",
|
"control_panel_log_file": "control_panel.log",
|
||||||
"server_dir": "../",
|
"server_dir": "../",
|
||||||
"handlebars_dev_mode": true
|
"handlebars_dev_mode": true
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
@ -49,24 +49,24 @@ async fn index(hb: web::Data<Handlebars<'_>>) -> HttpResponse {
|
||||||
|
|
||||||
// let restarts_log = lines_from_file(config.restarts_log_file);
|
// let restarts_log = lines_from_file(config.restarts_log_file);
|
||||||
|
|
||||||
let uptime = Command::new("uptime")
|
let uptime = Command::new("tuptime")
|
||||||
.output()
|
.output()
|
||||||
.expect("failed to execute process");
|
.expect("failed to execute process");
|
||||||
|
|
||||||
let _onefetch = Command::new("sh")
|
// let _onefetch = Command::new("sh")
|
||||||
.arg("onefetch_file.sh")
|
// .arg("onefetch_file.sh")
|
||||||
.arg(config.user)
|
// .arg(config.user)
|
||||||
.output()
|
// .output()
|
||||||
.expect("failed");
|
// .expect("failed");
|
||||||
|
|
||||||
let onefetch = fs::read_to_string("onefetch.out").unwrap();
|
// let onefetch = fs::read_to_string("onefetch.out").unwrap();
|
||||||
|
|
||||||
let data = json!({
|
let data = json!({
|
||||||
"log_output": &log_file[(cmp::max((log_file.len() as i64) - 1000, 0) as usize)..],
|
"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)..],
|
// "restarts_output": &restarts_log[(cmp::max((restarts_log.len() as i64) - 1000, 0) as usize)..],
|
||||||
"uptime": format!("{}", String::from_utf8_lossy(&uptime.stdout)),
|
"uptime": format!("{}", String::from_utf8_lossy(&uptime.stdout)),
|
||||||
//"onefetch": format!("{}", String::from_utf8_lossy(&onefetch.stdout))
|
//"onefetch": format!("{}", String::from_utf8_lossy(&onefetch.stdout))
|
||||||
"onefetch": onefetch.trim_end()
|
"onefetch": ""
|
||||||
});
|
});
|
||||||
let body = hb.render("index", &data).unwrap();
|
let body = hb.render("index", &data).unwrap();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.bottom-scroller {
|
.bottom-scroller {
|
||||||
height: 40em;
|
max-height: 40em;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column-reverse;
|
flex-direction: column-reverse;
|
||||||
|
|
@ -45,17 +45,16 @@
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section>
|
{{!-- <section>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="block">
|
<div class="block">
|
||||||
<button class="button" id="restart-button">Restart Server</button>
|
<button class="button" id="restart-button">Restart Server</button>
|
||||||
<button class="button" id="pull-button">Git Pull</button>
|
<button class="button" id="pull-button">Git Pull</button>
|
||||||
<button class="button" id="compile-button">Compile</button>
|
<button class="button" id="compile-button">Compile</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="block">Uptime: {{uptime}}</div>
|
<pre style="font-size: 0.8em;">{{uptime}}</pre>
|
||||||
<pre style="font-size: 0.8em;">{{onefetch}}</pre>
|
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section> --}}
|
||||||
|
|
||||||
<section class="section">
|
<section class="section">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
|
|
||||||
|
|
@ -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:
|
||||||
|
|
@ -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"]
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"port": 5000,
|
"port": 5000,
|
||||||
"tcp_timeout": 30,
|
"tcp_timeout": 30,
|
||||||
"log_file": "server.log"
|
"log_file": "logs/server.log"
|
||||||
}
|
}
|
||||||
|
|
||||||
Loading…
Reference in New Issue