1
+ mod network;
1
2
mod ui;
2
3
3
4
use {
4
- crate :: ui:: ClientUiPlugin ,
5
+ crate :: { network :: ClientNetworkPlugin , ui:: ClientUiPlugin } ,
5
6
aeronet:: io:: { Session , connection:: Disconnected } ,
6
- aeronet_replicon:: client:: AeronetRepliconClientPlugin ,
7
- aeronet_websocket:: client:: WebSocketClientPlugin ,
8
- aeronet_webtransport:: { cert, client:: WebTransportClientPlugin } ,
9
7
bevy:: {
10
8
color:: palettes:: basic:: RED ,
11
9
input:: {
@@ -14,24 +12,16 @@ use {
14
12
} ,
15
13
prelude:: * ,
16
14
} ,
17
- bevy_replicon:: prelude:: * ,
18
15
minigolf:: { GameState , LevelMesh , MinigolfPlugin , Player , PlayerInput } ,
19
16
web_sys:: { HtmlCanvasElement , wasm_bindgen:: JsCast } ,
20
17
} ;
21
18
22
19
fn main ( ) -> AppExit {
23
20
App :: new ( )
24
21
. add_plugins ( (
25
- // core
26
22
DefaultPlugins ,
27
23
ClientUiPlugin ,
28
- // transport
29
- WebTransportClientPlugin ,
30
- WebSocketClientPlugin ,
31
- // replication
32
- RepliconPlugins ,
33
- AeronetRepliconClientPlugin ,
34
- // game
24
+ ClientNetworkPlugin ,
35
25
MinigolfPlugin ,
36
26
) )
37
27
. add_systems ( Startup , setup_level)
@@ -144,79 +134,6 @@ fn on_disconnected(_trigger: Trigger<Disconnected>, mut game_state: ResMut<NextS
144
134
game_state. set ( GameState :: None ) ;
145
135
}
146
136
147
- //
148
- // WebTransport
149
- //
150
-
151
- type WebTransportClientConfig = aeronet_webtransport:: client:: ClientConfig ;
152
-
153
- #[ cfg( target_family = "wasm" ) ]
154
- fn web_transport_config ( cert_hash : String ) -> WebTransportClientConfig {
155
- use aeronet_webtransport:: xwt_web:: { CertificateHash , HashAlgorithm } ;
156
-
157
- let server_certificate_hashes = match cert:: hash_from_b64 ( & cert_hash) {
158
- Ok ( hash) => vec ! [ CertificateHash {
159
- algorithm: HashAlgorithm :: Sha256 ,
160
- value: Vec :: from( hash) ,
161
- } ] ,
162
- Err ( err) => {
163
- warn ! ( "Failed to read certificate hash from string: {err:?}" ) ;
164
- Vec :: new ( )
165
- }
166
- } ;
167
-
168
- WebTransportClientConfig {
169
- server_certificate_hashes,
170
- ..Default :: default ( )
171
- }
172
- }
173
-
174
- #[ cfg( not( target_family = "wasm" ) ) ]
175
- fn web_transport_config ( cert_hash : String ) -> WebTransportClientConfig {
176
- use { aeronet_webtransport:: wtransport:: tls:: Sha256Digest , core:: time:: Duration } ;
177
-
178
- let config = WebTransportClientConfig :: builder ( ) . with_bind_default ( ) ;
179
-
180
- let config = if cert_hash. is_empty ( ) {
181
- warn ! ( "Connecting without certificate validation" ) ;
182
- config. with_no_cert_validation ( )
183
- } else {
184
- match cert:: hash_from_b64 ( & cert_hash) {
185
- Ok ( hash) => config. with_server_certificate_hashes ( [ Sha256Digest :: new ( hash) ] ) ,
186
- Err ( err) => {
187
- warn ! ( "Failed to read certificate hash from string: {err:?}" ) ;
188
- config. with_server_certificate_hashes ( [ ] )
189
- }
190
- }
191
- } ;
192
-
193
- config
194
- . keep_alive_interval ( Some ( Duration :: from_secs ( 1 ) ) )
195
- . max_idle_timeout ( Some ( Duration :: from_secs ( 5 ) ) )
196
- . expect ( "should be a valid idle timeout" )
197
- . build ( )
198
- }
199
-
200
- //
201
- // WebSocket
202
- //
203
-
204
- type WebSocketClientConfig = aeronet_websocket:: client:: ClientConfig ;
205
-
206
- #[ cfg( target_family = "wasm" ) ]
207
- fn web_socket_config ( ) -> WebSocketClientConfig {
208
- WebSocketClientConfig :: default ( )
209
- }
210
-
211
- #[ cfg( not( target_family = "wasm" ) ) ]
212
- fn web_socket_config ( ) -> WebSocketClientConfig {
213
- WebSocketClientConfig :: builder ( ) . with_no_cert_validation ( )
214
- }
215
-
216
- //
217
- // game logic
218
- //
219
-
220
137
fn handle_inputs ( mut inputs : EventWriter < PlayerInput > , input : Res < ButtonInput < KeyCode > > ) {
221
138
let mut movement = Vec2 :: ZERO ;
222
139
if input. just_released ( KeyCode :: ArrowRight ) {
0 commit comments