@@ -417,10 +417,17 @@ pub async fn query_server(
417417 rules : bool ,
418418 ping : bool ,
419419) -> Result < String > {
420- let now = SystemTime :: now ( )
421- . duration_since ( UNIX_EPOCH )
422- . map_err ( |e| LauncherError :: Other ( format ! ( "System time error: {}" , e) ) ) ?
423- . as_millis ( ) as u64 ;
420+ let now = match SystemTime :: now ( ) . duration_since ( UNIX_EPOCH ) {
421+ Ok ( duration) => duration. as_millis ( ) as u64 ,
422+ Err ( e) => {
423+ let error_details = ErrorResponse {
424+ error : true ,
425+ info : format ! ( "System time error: {}" , e) ,
426+ } ;
427+ return Ok ( serde_json:: to_string ( & error_details)
428+ . unwrap_or_else ( |_| r#"{"error":true,"info":"System time error"}"# . to_string ( ) ) ) ;
429+ }
430+ } ;
424431
425432 let key = format ! ( "{}:{}" , ip, port) ;
426433
@@ -451,7 +458,7 @@ pub async fn query_server(
451458 let mut cache = CACHED_QUERY . lock ( ) . await ;
452459
453460 let should_reuse = match cache. as_ref ( ) {
454- Some ( ( _, cached_key) ) => cached_key == key,
461+ Some ( ( _, cached_key) ) => * cached_key == key,
455462 None => false ,
456463 } ;
457464
@@ -477,11 +484,13 @@ pub async fn query_server(
477484 result. info = Some ( match q. recv ( ) . await {
478485 Ok ( p) => format ! ( "{}" , p) ,
479486 Err ( e) => {
480- let mut error_details = ErrorResponse :: default ( ) ;
481- error_details. error = true ;
482- error_details. info = e. to_string ( ) ;
487+ let error_details = ErrorResponse {
488+ error : true ,
489+ info : e. to_string ( ) ,
490+ } ;
491+
483492 serde_json:: to_string ( & error_details) . unwrap_or_else ( |_| {
484- r#"{"error":true,"info":"Serialization failed"}"# . to_string ( )
493+ r#"{"error":true,"info":"Server information query failed"}" "# . to_string ( )
485494 } )
486495 }
487496 } ) ;
@@ -492,11 +501,13 @@ pub async fn query_server(
492501 result. players = Some ( match q. recv ( ) . await {
493502 Ok ( p) => format ! ( "{}" , p) ,
494503 Err ( e) => {
495- let mut error_details = ErrorResponse :: default ( ) ;
496- error_details. error = true ;
497- error_details. info = e. to_string ( ) ;
504+ let error_details = ErrorResponse {
505+ error : true ,
506+ info : e. to_string ( ) ,
507+ } ;
508+
498509 serde_json:: to_string ( & error_details) . unwrap_or_else ( |_| {
499- r#"{"error":true,"info":"Serialization failed"}"# . to_string ( )
510+ r#"{"error":true,"info":"Server players query failed"}" "# . to_string ( )
500511 } )
501512 }
502513 } ) ;
@@ -507,21 +518,31 @@ pub async fn query_server(
507518 result. rules = Some ( match q. recv ( ) . await {
508519 Ok ( p) => format ! ( "{}" , p) ,
509520 Err ( e) => {
510- let mut error_details = ErrorResponse :: default ( ) ;
511- error_details. error = true ;
512- error_details. info = e. to_string ( ) ;
521+ let error_details = ErrorResponse {
522+ error : true ,
523+ info : e. to_string ( ) ,
524+ } ;
525+
513526 serde_json:: to_string ( & error_details) . unwrap_or_else ( |_| {
514- r#"{"error":true,"info":"Serialization failed"}"# . to_string ( )
527+ r#"{"error":true,"info":"Server rules query failed"}" "# . to_string ( )
515528 } )
516529 }
517530 } ) ;
518531 }
519532
520533 if extra_info {
521- let now_secs = SystemTime :: now ( )
522- . duration_since ( UNIX_EPOCH )
523- . map_err ( |e| LauncherError :: Other ( format ! ( "System time error: {}" , e) ) ) ?
524- . as_secs ( ) ;
534+ let now_secs = match SystemTime :: now ( ) . duration_since ( UNIX_EPOCH ) {
535+ Ok ( duration) => duration. as_secs ( ) ,
536+ Err ( e) => {
537+ let error_details = ErrorResponse {
538+ error : true ,
539+ info : format ! ( "System time error: {}" , e) ,
540+ } ;
541+ return Ok ( serde_json:: to_string ( & error_details) . unwrap_or_else ( |_| {
542+ r#"{"error":true,"info":"System time error"}"# . to_string ( )
543+ } ) ) ;
544+ }
545+ } ;
525546
526547 let key = format ! ( "{}:{}" , ip, port) ;
527548
@@ -552,11 +573,13 @@ pub async fn query_server(
552573 result. extra_info = Some ( match q. recv ( ) . await {
553574 Ok ( p) => format ! ( "{}" , p) ,
554575 Err ( e) => {
555- let mut error_details = ErrorResponse :: default ( ) ;
556- error_details. error = true ;
557- error_details. info = e. to_string ( ) ;
576+ let error_details = ErrorResponse {
577+ error : true ,
578+ info : e. to_string ( ) ,
579+ } ;
580+
558581 serde_json:: to_string ( & error_details) . unwrap_or_else ( |_| {
559- r#"{"error":true,"info":"Serialization failed"}"# . to_string ( )
582+ r#"{"error":true,"info":"Server open.mp information query failed"}" "# . to_string ( )
560583 } )
561584 }
562585 } ) ;
@@ -583,5 +606,7 @@ pub async fn query_server(
583606 * cache = Some ( ( q, key) ) ;
584607 }
585608
586- serde_json:: to_string ( & result) . map_err ( |e| LauncherError :: SerdeJson ( e) )
609+ Ok ( serde_json:: to_string ( & result) . unwrap_or_else ( |_| {
610+ r#"{"error":true,"info":"Information serialization failed"}""# . to_string ( )
611+ } ) )
587612}
0 commit comments