Skip to content

Commit d817614

Browse files
feat: tag starts proxy (#880)
1 parent 190d414 commit d817614

File tree

9 files changed

+109
-75
lines changed

9 files changed

+109
-75
lines changed

.github/workflows/integration.yml

Lines changed: 0 additions & 70 deletions
This file was deleted.

Cargo.lock

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ members = [
3333
'crates/hyperion-permission',
3434
'crates/hyperion-proto',
3535
'crates/hyperion-proxy',
36+
'crates/hyperion-proxy-module',
3637
'crates/hyperion-rank-tree',
3738
'crates/hyperion-respawn',
3839
'crates/hyperion-scheduled',
@@ -114,6 +115,9 @@ toml = '0.8.14'
114115
tracing-appender = '0.2.3'
115116
uuid = '1.16.0'
116117

118+
[workspace.dependencies.hyperion-proxy-module]
119+
path = "crates/hyperion-proxy-module"
120+
117121
[workspace.dependencies.bvh]
118122
git = 'https://github.com/andrewgazelka/bvh-data'
119123

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[dependencies]
2+
hyperion-proxy = { workspace = true }
3+
hyperion = { workspace = true }
4+
flecs_ecs = { workspace = true }
5+
tracing = { workspace = true }
6+
tokio = { workspace = true , features = ["full"]}
7+
8+
[lints]
9+
workspace = true
10+
11+
[package]
12+
authors = ["Andrew Gazelka <[email protected]>"]
13+
edition.workspace = true
14+
name = "hyperion-proxy-module"
15+
publish = false
16+
readme = "README.md"
17+
version.workspace = true
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
todo: write readme
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
use std::net::SocketAddr;
2+
3+
use flecs_ecs::{core::World, prelude::*};
4+
use hyperion::runtime::AsyncRuntime;
5+
use tokio::net::TcpListener;
6+
7+
#[derive(Component)]
8+
pub struct HyperionProxyModule;
9+
10+
#[derive(Component)]
11+
pub struct ProxyAddress {
12+
pub proxy: String,
13+
pub server: String,
14+
}
15+
16+
impl Default for ProxyAddress {
17+
fn default() -> Self {
18+
Self {
19+
proxy: "0.0.0.0:25565".to_string(),
20+
server: "127.0.0.1:35565".to_string(),
21+
}
22+
}
23+
}
24+
25+
impl Module for HyperionProxyModule {
26+
fn module(world: &World) {
27+
world.import::<hyperion::HyperionCore>();
28+
world.component::<ProxyAddress>();
29+
30+
proxy_address_observer(world);
31+
}
32+
}
33+
34+
fn proxy_address_observer(world: &World) {
35+
let mut query = world.observer_named::<flecs::OnSet, (
36+
&ProxyAddress, // (0)
37+
&AsyncRuntime, // (1)
38+
)>("proxy_address");
39+
40+
#[rustfmt::skip]
41+
query
42+
.term_at(0).singleton()
43+
.term_at(1).filter().singleton();
44+
45+
query.each(|(addresses, runtime)| {
46+
let proxy = addresses.proxy.clone();
47+
let server = addresses.server.clone();
48+
49+
runtime.spawn(async move {
50+
let listener = TcpListener::bind(&proxy).await.unwrap();
51+
tracing::info!("Listening on {proxy}");
52+
53+
let server: SocketAddr = tokio::net::lookup_host(&server)
54+
.await
55+
.unwrap()
56+
.next()
57+
.unwrap();
58+
59+
hyperion_proxy::run_proxy(listener, server).await.unwrap();
60+
});
61+
});
62+
}

crates/hyperion-proxy/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub mod server_sender;
5050
pub mod util;
5151

5252
#[tracing::instrument(level = "trace", skip_all)]
53-
pub async fn connect(addr: impl ToSocketAddrs + Debug + Clone) -> TcpStream {
53+
async fn connect(addr: impl ToSocketAddrs + Debug + Clone) -> TcpStream {
5454
loop {
5555
if let Ok(stream) = TcpStream::connect(addr.clone()).await {
5656
return stream;

events/tag/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ clap = { workspace = true }
44
compact_str = { workspace = true }
55
derive_more = { workspace = true }
66
dotenvy = { workspace = true }
7+
envy = "0.4"
78
fastrand = { workspace = true }
89
flecs_ecs = { workspace = true }
910
geometry = { workspace = true }
@@ -15,22 +16,21 @@ hyperion-gui = { workspace = true }
1516
hyperion-inventory = { workspace = true }
1617
hyperion-item = { workspace = true }
1718
hyperion-permission = { workspace = true }
19+
hyperion-proxy-module = { workspace = true }
1820
hyperion-rank-tree = { workspace = true }
21+
hyperion-respawn = { workspace = true }
1922
hyperion-scheduled = { workspace = true }
2023
hyperion-text = { workspace = true }
2124
hyperion-utils = { workspace = true }
2225
rayon = { workspace = true }
2326
roaring = { workspace = true }
2427
rustc-hash = { workspace = true }
28+
serde = { version = "1.0", features = ["derive"] }
2529
tracing = { workspace = true }
2630
tracing-subscriber = { workspace = true }
27-
# tracing-tracy = { workspace = true }
2831
uuid = { workspace = true }
29-
hyperion-respawn = { workspace = true }
3032
valence_protocol = { workspace = true }
3133
valence_server = { workspace = true }
32-
serde = { version = "1.0", features = ["derive"] }
33-
envy = "0.4"
3434

3535
[dev-dependencies]
3636
tracing = { workspace = true, features = ["release_max_level_info"] }

events/tag/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ use flecs_ecs::prelude::*;
99
use hyperion::{GameServerEndpoint, HyperionCore, simulation::Player};
1010
use hyperion_clap::hyperion_command::CommandRegistry;
1111
use hyperion_gui::Gui;
12+
use hyperion_proxy_module::ProxyAddress;
1213
use module::{block::BlockModule, damage::DamageModule, vanish::VanishModule};
1314

1415
mod module;
1516

1617
use derive_more::{Deref, DerefMut};
1718
use hyperion::{glam::IVec3, simulation::Position, spatial};
19+
use hyperion_proxy_module::HyperionProxyModule;
1820
use hyperion_rank_tree::Team;
1921
use module::{attack::AttackModule, level::LevelModule, regeneration::RegenerationModule};
2022
use spatial::SpatialIndex;
@@ -135,8 +137,14 @@ pub fn init_game(address: SocketAddr) -> anyhow::Result<()> {
135137
let world = World::new();
136138

137139
world.import::<HyperionCore>();
140+
world.import::<HyperionProxyModule>();
138141
world.import::<TagModule>();
139142

143+
world.set(ProxyAddress {
144+
server: address.to_string(),
145+
..ProxyAddress::default()
146+
});
147+
140148
world.set(GameServerEndpoint::from(address));
141149

142150
let mut app = world.app();

0 commit comments

Comments
 (0)