@@ -144,12 +144,10 @@ pub fn parse_ping_response_json(d: &[u8]) -> eyre::Result<PingResponse> {
144144 . unwrap_or_default ( ) ;
145145
146146 let version = v. get ( "version" ) ;
147- let version_name = version
148- . get_str ( "name" )
149- . map ( |s| sanitize_text_for_postgres ( s) ) ;
147+ let version_name = version. get_str ( "name" ) . map ( sanitize_text_for_postgres) ;
150148 let version_protocol = version. get_i32 ( "protocol" ) ;
151149
152- let favicon = v. get_str ( "favicon" ) . map ( |s| sanitize_text_for_postgres ( s ) ) ;
150+ let favicon = v. get_str ( "favicon" ) . map ( sanitize_text_for_postgres) ;
153151 // filter out bad favicons
154152 let favicon = favicon. filter ( |f| f. starts_with ( "data:image/png;base64," ) ) ;
155153 let favicon_hash = favicon. as_ref ( ) . map ( |s| make_favicon_hash ( s) ) ;
@@ -178,8 +176,7 @@ pub fn parse_ping_response_json(d: &[u8]) -> eyre::Result<PingResponse> {
178176 . map ( |a| {
179177 a. iter ( )
180178 . filter_map ( |v| {
181- let Some ( name) = v. get_str ( "name" ) . map ( |s| sanitize_text_for_postgres ( s) )
182- else {
179+ let Some ( name) = v. get_str ( "name" ) . map ( sanitize_text_for_postgres) else {
183180 // name is required
184181 is_fake_sample = true ;
185182 return None ;
@@ -224,18 +221,14 @@ pub fn parse_ping_response_json(d: &[u8]) -> eyre::Result<PingResponse> {
224221 let forge_data = v. get ( "forgeData" ) ;
225222 let forgedata_fml_network_version = forge_data. get_i32 ( "fmlNetworkVersion" ) ;
226223 let mod_info = v. get ( "modinfo" ) ;
227- let modinfo_type = mod_info
228- . get_str ( "type" )
229- . map ( |s| sanitize_text_for_postgres ( s) ) ;
224+ let modinfo_type = mod_info. get_str ( "type" ) . map ( sanitize_text_for_postgres) ;
230225 let is_modded = v. get_bool ( "isModded" ) ;
231226 let modpack_data = v. get ( "modpackData" ) ;
232227 let modpackdata_project_id = modpack_data. get_i32 ( "projectID" ) ;
233- let modpackdata_name = modpack_data
234- . get_str ( "name" )
235- . map ( |s| sanitize_text_for_postgres ( s) ) ;
228+ let modpackdata_name = modpack_data. get_str ( "name" ) . map ( sanitize_text_for_postgres) ;
236229 let modpackdata_version = modpack_data
237230 . get_str ( "version" )
238- . map ( |s| sanitize_text_for_postgres ( s ) ) ;
231+ . map ( sanitize_text_for_postgres) ;
239232
240233 Ok ( PingResponse {
241234 description_json,
@@ -276,25 +269,25 @@ pub async fn insert_server_to_db(
276269 {
277270 let mut shared = db. shared . lock ( ) ;
278271 let ips_with_same_hash = shared. ip_to_hash_and_ports . get_mut ( target. ip ( ) ) ;
279- if let Some ( ( data, previously_checked_ports) ) = ips_with_same_hash {
280- if !previously_checked_ports. contains ( & target. port ( ) ) {
281- if let Some ( count) = & mut data. count {
282- let this_server_hash = make_ping_response_hash ( r) ?;
283-
284- if this_server_hash == data. hash {
285- * count += 1 ;
286- previously_checked_ports. insert ( target. port ( ) ) ;
287-
288- if * count >= 100 {
289- // too many servers with the same hash... add to bad ips!
290- println ! ( "found a new bad ip: {} :(" , target. ip( ) ) ;
291- // we call add_to_ips_with_aliased_servers later
292- is_aliased_server = true ;
293- }
294- } else {
295- // this server has a different hash than the other servers with the same IP
296- data. count = None ;
272+ if let Some ( ( data, previously_checked_ports) ) = ips_with_same_hash
273+ && !previously_checked_ports. contains ( & target. port ( ) )
274+ {
275+ if let Some ( count) = & mut data. count {
276+ let this_server_hash = make_ping_response_hash ( r) ?;
277+
278+ if this_server_hash == data. hash {
279+ * count += 1 ;
280+ previously_checked_ports. insert ( target. port ( ) ) ;
281+
282+ if * count >= 100 {
283+ // too many servers with the same hash... add to bad ips!
284+ println ! ( "found a new bad ip: {} :(" , target. ip( ) ) ;
285+ // we call add_to_ips_with_aliased_servers later
286+ is_aliased_server = true ;
297287 }
288+ } else {
289+ // this server has a different hash than the other servers with the same IP
290+ data. count = None ;
298291 }
299292 }
300293 } else {
@@ -314,7 +307,7 @@ pub async fn insert_server_to_db(
314307
315308 if is_aliased_server {
316309 let db = db. clone ( ) ;
317- let target = target. clone ( ) ;
310+ let target = * target;
318311 tokio:: spawn ( async move {
319312 let _ = db
320313 // for now, assume 25565 is the only allowed port. might change this in the future.
0 commit comments