chore: rename things to be more to my liking
All checks were successful
/ build (push) Successful in 8m18s
All checks were successful
/ build (push) Successful in 8m18s
This commit is contained in:
parent
0439f362dd
commit
1e281cf61f
3 changed files with 33 additions and 22 deletions
|
|
@ -70,8 +70,9 @@ pub trait MinecraftServerHandle: Send + Sync + 'static + Clone {
|
|||
async fn stop(&self) -> Result<(), OpaqueError>;
|
||||
async fn query_status(&self) -> Result<ServerDeploymentStatus, OpaqueError>;
|
||||
fn get_internal_address(&self) -> &str;
|
||||
fn get_addr(&self) -> String;
|
||||
fn get_port(&self) -> String;
|
||||
fn get_internal_id(&self) -> &str;
|
||||
fn get_join_addr(&self) -> &str;
|
||||
fn get_join_port(&self) -> &str;
|
||||
fn get_motd(&self) -> Option<String>;
|
||||
|
||||
async fn query_server_connectable(&self) -> Result<TcpStream, OpaqueError> {
|
||||
|
|
@ -122,7 +123,7 @@ pub trait MinecraftServerHandle: Send + Sync + 'static + Clone {
|
|||
ServerDeploymentStatus::Connectable(mut tcp_stream) => {
|
||||
let handshake = crate::packets::serverbound::handshake::Handshake::create(
|
||||
crate::types::VarInt::from(746).ok_or("could not create VarInt WTF?")?,
|
||||
crate::types::VarString::from(self.get_addr()),
|
||||
crate::types::VarString::from(self.get_join_addr().to_string()),
|
||||
crate::types::UShort::from(1234),
|
||||
crate::types::VarInt::from(1).ok_or("could not create VarInt WTF?")?,
|
||||
)
|
||||
|
|
@ -162,7 +163,6 @@ pub trait MinecraftAPI<T>: Send + Sync + 'static {
|
|||
async fn query_server(&self, addr: &str, port: &str) -> Result<T, OpaqueError>;
|
||||
fn get_map(&self) -> Arc<tokio::sync::Mutex<HashMap<String, tokio::task::JoinHandle<()>>>>;
|
||||
|
||||
// TODO: move the implementation to here, but
|
||||
/// This should be callable even if there is already a watcher,
|
||||
/// and it should handle the collision itself while returning OK().
|
||||
async fn start_watch(
|
||||
|
|
@ -171,18 +171,18 @@ pub trait MinecraftAPI<T>: Send + Sync + 'static {
|
|||
frequency: std::time::Duration,
|
||||
) -> Result<(), OpaqueError>
|
||||
where
|
||||
Self: Send + Sync + 'static + Clone,
|
||||
Self: Clone,
|
||||
{
|
||||
let inter_addr = server.get_internal_address().to_string();
|
||||
let internal_id = server.get_internal_id().to_string();
|
||||
|
||||
if let Some(handle) = self.get_map().lock().await.get(&inter_addr) {
|
||||
if let Some(handle) = self.get_map().lock().await.get(&internal_id) {
|
||||
if !handle.is_finished() {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
let span = tracing::span!(parent: None,tracing::Level::INFO, "server_watcher", inter_addr, join_addr = server.get_addr(), join_port = server.get_port());
|
||||
let span = tracing::span!(parent: None,tracing::Level::INFO, "server_watcher", internal_id, join_addr = server.get_join_addr(), join_port = server.get_join_port());
|
||||
|
||||
let full_addr_clone = inter_addr.clone();
|
||||
let internal_id_clone = internal_id.clone();
|
||||
let api = self.clone();
|
||||
let handle = tokio::spawn(
|
||||
async move {
|
||||
|
|
@ -208,7 +208,7 @@ pub trait MinecraftAPI<T>: Send + Sync + 'static {
|
|||
drop(status_json);
|
||||
let map = api.get_map();
|
||||
let mut guard = map.lock().await;
|
||||
guard.remove(&full_addr_clone);
|
||||
guard.remove(&internal_id_clone);
|
||||
drop(guard);
|
||||
drop(map);
|
||||
if let Err(err) = server.stop().await {
|
||||
|
|
@ -226,7 +226,7 @@ pub trait MinecraftAPI<T>: Send + Sync + 'static {
|
|||
);
|
||||
let map = self.get_map();
|
||||
let mut guard = map.lock().await;
|
||||
guard.insert(inter_addr.clone(), handle);
|
||||
guard.insert(internal_id, handle);
|
||||
drop(guard);
|
||||
|
||||
Ok(())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue