Add last_seen field to database migration script

This commit is contained in:
funtimes909
2026-04-06 12:30:40 +12:00
parent e31e407f45
commit e4422fcb93
3 changed files with 29 additions and 19 deletions
+2 -1
View File
@@ -1,7 +1,8 @@
create table if not exists favicons (
hash bytea primary key,
data text not null,
first_seen timestamp without time zone not null default now ()
first_seen timestamp without time zone not null default now (),
last_seen timestamp without time zone not null default now ()
);
create table if not exists countries (
+7 -7
View File
@@ -6,8 +6,8 @@ use tokio::process::Command;
use tracing::debug;
use crate::CONFIG;
use crate::database::ServerUpdateOperation;
use crate::database::Database;
use crate::database::ServerUpdateOperation;
pub struct DiscoveryScanner {
pub database: Database,
@@ -34,12 +34,6 @@ impl DiscoveryScanner {
while let Ok(Some(line)) = reader.next_line().await {
let mut line = line.split_whitespace();
// Address
let address = match line.nth(1).and_then(|a| Ipv4Addr::from_str(a).ok()) {
Some(address) => address,
_ => continue,
};
// Port
let port = match line
.nth(3)
@@ -52,6 +46,12 @@ impl DiscoveryScanner {
None => continue,
};
// Address
let address = match line.nth(1).and_then(|a| Ipv4Addr::from_str(a).ok()) {
Some(address) => address,
None => continue,
};
// Immediately ping any returned servers
let completed_server = super::run(address, port).await;
+20 -11
View File
@@ -1,5 +1,8 @@
use std::net::{Ipv4Addr, SocketAddrV4};
use anyhow::bail;
use std::{
net::{Ipv4Addr, SocketAddrV4},
time::Duration,
};
use tokio::{net::TcpStream, task::JoinHandle};
use crate::protocol::{minecraft, response::MinecraftServer};
@@ -12,14 +15,20 @@ pub fn run(address: Ipv4Addr, port: u16) -> JoinHandle<anyhow::Result<MinecraftS
let socket = SocketAddrV4::new(address, port);
let mut stream = TcpStream::connect(socket).await.unwrap();
return match minecraft::simple_ping(&mut stream).await {
Ok(s) => {
match serde_json::from_str::<MinecraftServer>(&s) {
Ok(server) => Ok(server),
Err(e) => bail!("{e}"),
}
}
Err(e) => bail!("{e}")
}
return match tokio::time::timeout(
Duration::from_secs(4),
minecraft::simple_ping(&mut stream),
)
.await
{
Ok(Ok(s)) => {
match serde_json::from_str::<MinecraftServer>(&s) {
Ok(server) => Ok(server),
Err(e) => bail!("{e}"),
}
}
Ok(Err(e)) => bail!("{e}"),
Err(e) => bail!("{e}"),
};
})
}
}