Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
legokichi committed Sep 7, 2023
1 parent 5c469ca commit 2ce14f8
Show file tree
Hide file tree
Showing 13 changed files with 247 additions and 176 deletions.
16 changes: 16 additions & 0 deletions coredump/.gdb_history
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
attach 978530
q
backtrace
q
info proc mapping
q
attach 981363
q
info proc map
q
info shared
info
info mem
info functions
info files
q
8 changes: 8 additions & 0 deletions coredump/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "coredump"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
Binary file added coredump/core.981363
Binary file not shown.
5 changes: 5 additions & 0 deletions coredump/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fn main() {
let a = vec![1,2,3];
std::thread::sleep(std::time::Duration::from_secs(120));
println!("{a:?}");
}
15 changes: 15 additions & 0 deletions dynmap/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "dynmap"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
chrono = { version = "0.4", features = ["serde"] }
futures = { version = "0.3", features = [] }
log = "0.4"
reqwest = { version = "0.11", features = ["json"] }
serde = { version = "1", features = ["derive"] }
serde_json = { version = "1", features = [] }
tokio = { version = "1", features = ["full"] }
2 changes: 2 additions & 0 deletions dynmap/chat.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
cat log.txt |grep chat |awk -F "\t" '{print $4 "\t" $5}'
2 changes: 2 additions & 0 deletions dynmap/pos.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
cat log.txt |grep player |awk -F "\t" '{print $4 "\t" $5 "\t" $6 "\t" $7 "\t" $8}'
139 changes: 139 additions & 0 deletions dynmap/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
#[tokio::main]
async fn main() {
let timestamp = chrono::Utc::now().timestamp_millis();
loop {
let url = format!("https://minecraft-map.sudosan.net/up/world/world/{timestamp}");
let res = reqwest::get(url).await;
let res = match res {
Ok(res) => res,
Err(err) => {
println!("error: {:?}", err);
tokio::time::sleep(std::time::Duration::from_secs(30)).await;
continue;
}
};
if res.status() != reqwest::StatusCode::OK {
println!("error: {}", res.status());
for header in res.headers() {
println!("{}: {}", header.0, header.1.to_str().unwrap());
}
println!("{}", res.text().await.unwrap());
tokio::time::sleep(std::time::Duration::from_secs(30)).await;
continue;
}
let json: serde_json::Value = res.json().await.unwrap();
//println!("{}", serde_json::to_string_pretty(&json).unwrap());
let timestamp = json.pointer("/timestamp").unwrap().as_i64().unwrap();
let is_thundering = json.pointer("/isThundering").unwrap().as_bool().unwrap();
let has_storm = json.pointer("/hasStorm").unwrap().as_bool().unwrap();
let date_str = {
use chrono::TimeZone;
let dt: chrono::DateTime<chrono::Utc> = chrono::Utc
.timestamp_millis_opt(timestamp)
.single()
.unwrap();
let dt: chrono::DateTime<chrono::FixedOffset> =
dt.with_timezone(&chrono::FixedOffset::east_opt(9 * 3600).unwrap());
dt.to_rfc3339_opts(chrono::SecondsFormat::Millis, true)
};
if is_thundering && has_storm {
println!("{date_str}\tthunderstorm");
}
let players = json
.pointer("/players")
.unwrap()
.as_array()
.unwrap()
.iter()
.collect::<Vec<_>>();
for player in players {
let world = player.pointer("/world").unwrap().as_str().unwrap();
let x = player.pointer("/x").unwrap().as_f64().unwrap();
let y = player.pointer("/y").unwrap().as_f64().unwrap();
let z = player.pointer("/z").unwrap().as_f64().unwrap();
let name = player.pointer("/name").unwrap().as_str().unwrap();
let account = player.pointer("/account").unwrap().as_str().unwrap();
println!("{date_str}\tplayer\t{account}\t{name}\t{world}\t{x}\t{y}\t{z}");
}
let updates = json
.pointer("/updates")
.unwrap()
.as_array()
.unwrap()
.iter()
.collect::<Vec<_>>();
for update in updates {
let r#type = update.pointer("/type").unwrap().as_str().unwrap();
if r#type == "chat" {
let timestamp = update.pointer("/timestamp").unwrap().as_i64().unwrap();
let account = update.pointer("/account").unwrap().as_str().unwrap();
let name = update.pointer("/playerName").unwrap().as_str().unwrap();
let message = update.pointer("/message").unwrap().as_str().unwrap();
let date_str = {
use chrono::TimeZone;
let dt: chrono::DateTime<chrono::Utc> = chrono::Utc
.timestamp_millis_opt(timestamp)
.single()
.unwrap();
let dt: chrono::DateTime<chrono::FixedOffset> =
dt.with_timezone(&chrono::FixedOffset::east_opt(9 * 3600).unwrap());
dt.to_rfc3339_opts(chrono::SecondsFormat::Millis, true)
};
println!("{date_str}\tchat\t{account}\t{name}\t{message}");
} else if r#type == "playerjoin" {
let timestamp = update.pointer("/timestamp").unwrap().as_i64().unwrap();
let account = update.pointer("/account").unwrap().as_str().unwrap();
let name = update.pointer("/playerName").unwrap().as_str().unwrap();
let date_str = {
use chrono::TimeZone;
let dt: chrono::DateTime<chrono::Utc> = chrono::Utc
.timestamp_millis_opt(timestamp)
.single()
.unwrap();
let dt: chrono::DateTime<chrono::FixedOffset> =
dt.with_timezone(&chrono::FixedOffset::east_opt(9 * 3600).unwrap());
dt.to_rfc3339_opts(chrono::SecondsFormat::Millis, true)
};
println!("{date_str}\tjoin\t{account}\t{name}");
} else if r#type == "playerquit" {
let timestamp = update.pointer("/timestamp").unwrap().as_i64().unwrap();
let account = update.pointer("/account").unwrap().as_str().unwrap();
let name = update.pointer("/playerName").unwrap().as_str().unwrap();
let date_str = {
use chrono::TimeZone;
let dt: chrono::DateTime<chrono::Utc> = chrono::Utc
.timestamp_millis_opt(timestamp)
.single()
.unwrap();
let dt: chrono::DateTime<chrono::FixedOffset> =
dt.with_timezone(&chrono::FixedOffset::east_opt(9 * 3600).unwrap());
dt.to_rfc3339_opts(chrono::SecondsFormat::Millis, true)
};
println!("{date_str}\tquit\t{account}\t{name}");
} else if r#type == "tile" {
// nop
} else if r#type == "daynight" {
let timestamp = update.pointer("/timestamp").unwrap().as_i64().unwrap();
let is_day = update.pointer("/isday").unwrap().as_bool().unwrap();
let date_str = {
use chrono::TimeZone;
let dt: chrono::DateTime<chrono::Utc> = chrono::Utc
.timestamp_millis_opt(timestamp)
.single()
.unwrap();
let dt: chrono::DateTime<chrono::FixedOffset> =
dt.with_timezone(&chrono::FixedOffset::east_opt(9 * 3600).unwrap());
dt.to_rfc3339_opts(chrono::SecondsFormat::Millis, true)
};
if is_day {
println!("{date_str}\tday");
}else {
println!("{date_str}\tnight");
}
} else {
println!("{}", serde_json::to_string_pretty(&update).unwrap());
}
}
tokio::time::sleep(std::time::Duration::from_secs(30)).await;
}
}
11 changes: 2 additions & 9 deletions mqtt-pah/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,12 @@ version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
default = ["paho"]
paho = ["paho-mqtt", "paho-mqtt-sys", "tempfile"]
rumqtt = ["rumqttc", "rustls-pemfile"]

[dependencies]
anyhow = "1"
futures = "0.3"
log = "0.4"
paho-mqtt = { version = "0.12", features = ["bundled", "build_bindgen"], optional = true }
paho-mqtt-sys = { version = "0.8", optional = true }
rumqttc = { version = "0.22", optional = true }
rustls-pemfile = { version = "1.0", optional = true }
tempfile = { version = "3.6.0", optional = true }
paho-mqtt = { version = "0.12", features = ["bundled", "build_bindgen"] }
paho-mqtt-sys = { version = "0.8" }
tokio = { version = "1", features = ["full"] }
env_logger = "0.10"
12 changes: 6 additions & 6 deletions mqtt-pah/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ server.listen(port, function () {

aedes.on("clientReady", (client)=>{
console.log("aedes clientReady");
setTimeout(()=>{
console.log("aedes client closing");
client.close(()=>{
console.log("aedes client closed");
});
}, 6000);
//setTimeout(()=>{
// console.log("aedes client closing");
// client.close(()=>{
// console.log("aedes client closed");
// });
//}, 6000);
});
});
Loading

0 comments on commit 2ce14f8

Please sign in to comment.