@@ -347,6 +347,8 @@ struct Client {
347347 log : ConnectingLog ,
348348
349349 last_snapshot : Snapshot ,
350+
351+ start_time : Duration ,
350352}
351353
352354impl Client {
@@ -356,6 +358,7 @@ impl Client {
356358 addr : SocketAddr ,
357359 log : ConnectingLog ,
358360 ) -> anyhow:: Result < LegacyProxy > {
361+ let proxy_start = time. now ( ) ;
359362 let fs = io. fs . clone ( ) ;
360363
361364 log. log ( "Preparing proxy socket" ) ;
@@ -437,7 +440,7 @@ impl Client {
437440 Connless :: RequestInfo ( msg:: connless:: RequestInfo { token : tokens[ 0 ] } ) ,
438441 ) ;
439442 let start_time = time. now ( ) ;
440- let mut last_req = start_time ;
443+ let mut last_req = None ;
441444 let mut last_reconnect = start_time;
442445 while server_info. is_none ( )
443446 && !is_finished_thread. load ( std:: sync:: atomic:: Ordering :: SeqCst )
@@ -511,8 +514,12 @@ impl Client {
511514
512515 let cur_time = time. now ( ) ;
513516 // send new request
514- if cur_time. saturating_sub ( last_req) > Duration :: from_secs ( 5 ) {
515- log. log ( "Sending new info request after 5s timeout" ) ;
517+ if last_req. is_none_or ( |last_req| {
518+ cur_time. saturating_sub ( last_req) > Duration :: from_secs ( 1 )
519+ } ) {
520+ if last_req. is_some ( ) {
521+ log. log ( "Sending new info request after 1s timeout" ) ;
522+ }
516523 let token = rand:: rng ( ) . next_u32 ( ) as u8 ;
517524 conless. sendc (
518525 addr,
@@ -521,7 +528,7 @@ impl Client {
521528
522529 tokens. push ( token) ;
523530
524- last_req = cur_time;
531+ last_req = Some ( cur_time) ;
525532 }
526533
527534 // try to reconnect
@@ -675,6 +682,8 @@ impl Client {
675682 is_finished : is_finished_thread,
676683
677684 log,
685+
686+ start_time : proxy_start,
678687 } ;
679688
680689 app. run_loop ( ) . unwrap ( ) ;
@@ -1584,7 +1593,7 @@ impl Client {
15841593 }
15851594 }
15861595 SnapObj :: ClientInfo ( client_info) => {
1587- if let Some ( ( character_id , info) ) = Self :: player_info_mut ( id, base, snapshot) {
1596+ if let Some ( ( _ , info) ) = Self :: player_info_mut ( id, base, snapshot) {
15881597 fn ints_to_net_str < const MAX_LENGTH : usize > (
15891598 int_arr : & [ i32 ] ,
15901599 ) -> NetworkString < MAX_LENGTH > {
@@ -1596,14 +1605,14 @@ impl Client {
15961605 . map ( NetworkString :: new_lossy)
15971606 . unwrap_or_default ( )
15981607 }
1599- let mut player_info = ( * info. player_info ) . clone ( ) ;
16001608
16011609 // Apply as much info from known player info as possible
1602- if character_id == player_id {
1603- player_info = player. player_info . clone ( ) ;
1604- } else if let Some ( dummy) = base. local_players . get ( & id) {
1605- player_info = dummy. player_info . clone ( ) ;
1606- }
1610+ let mut player_info = if let Some ( dummy) = base. local_players . get ( & id) {
1611+ dummy. player_info . clone ( )
1612+ } else {
1613+ // fall back to player info, since legacy servers don't send enough info
1614+ player. player_info . clone ( )
1615+ } ;
16071616
16081617 // Then overwrite the info the server knows about
16091618 player_info. name = ints_to_net_str ( client_info. name . as_slice ( ) ) ;
@@ -3528,13 +3537,7 @@ impl Client {
35283537
35293538 self . players . insert (
35303539 self . base . id_generator . next_id ( ) ,
3531- ProxyClient :: new (
3532- Default :: default ( ) ,
3533- sock_loop,
3534- self . time . now ( ) ,
3535- 0 ,
3536- false ,
3537- ) ,
3540+ ProxyClient :: new ( Default :: default ( ) , sock_loop, 0 , false ) ,
35383541 ) ;
35393542 }
35403543 }
@@ -3564,13 +3567,7 @@ impl Client {
35643567
35653568 self . players . insert (
35663569 self . base . id_generator . next_id ( ) ,
3567- ProxyClient :: new (
3568- Default :: default ( ) ,
3569- sock_loop,
3570- self . time . now ( ) ,
3571- 0 ,
3572- false ,
3573- ) ,
3570+ ProxyClient :: new ( Default :: default ( ) , sock_loop, 0 , false ) ,
35743571 ) ;
35753572 }
35763573 ClientToServerMessage :: Ready ( msg) => {
@@ -3619,13 +3616,7 @@ impl Client {
36193616 let player_id = self . base . id_generator . next_id ( ) ;
36203617 self . players . insert (
36213618 player_id,
3622- ProxyClient :: new (
3623- ev. player_info ,
3624- sock_loop,
3625- self . time . now ( ) ,
3626- ev. id ,
3627- true ,
3628- ) ,
3619+ ProxyClient :: new ( ev. player_info , sock_loop, ev. id , true ) ,
36293620 ) ;
36303621 if let Some ( con_id) = self . con_id {
36313622 self . server_network . send_unordered_to (
@@ -4531,10 +4522,9 @@ impl Client {
45314522 self . server_network . send_unordered_to (
45324523 & ServerToClientMessage :: ServerInfo {
45334524 info : server_info,
4534- overhead : self
4535- . time
4536- . now ( )
4537- . saturating_sub ( player. data . connect_time ) ,
4525+ // the proxy is not really good at estimating the first ping
4526+ // so give it the whole startup time as overhead instead
4527+ overhead : self . time . now ( ) . saturating_sub ( self . start_time ) ,
45384528 } ,
45394529 & con_id,
45404530 ) ;
0 commit comments