diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..b49a4b2 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "externals/medusa_macros"] + path = externals/medusa_macros + url = https://gitea.tendokyu.moe/Kayori/medusa_macros.git diff --git a/Cargo.toml b/Cargo.toml index 7c6f8d1..f478aa4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] +medusa_macros = { path = "externals/medusa_macros"} async-trait = "0.1.82" byteorder = "1.5.0" cbc = "0.1.2" diff --git a/externals/medusa_macros b/externals/medusa_macros new file mode 160000 index 0000000..88257a8 --- /dev/null +++ b/externals/medusa_macros @@ -0,0 +1 @@ +Subproject commit 88257a8f7ea5e26015a1b28e14cc39fbebc90459 diff --git a/src/handlers/common/get_facility_handler.rs b/src/handlers/common/get_facility_handler.rs new file mode 100644 index 0000000..bf37f70 --- /dev/null +++ b/src/handlers/common/get_facility_handler.rs @@ -0,0 +1,174 @@ +use std::io::Cursor; + +use crate::handlers::handler::Handler; +use xml::writer::{EmitterConfig, XmlEvent}; + +pub struct GetFacilityHandler { + module: String, + method: String, +} + +impl GetFacilityHandler { + pub fn new() -> Self { + GetFacilityHandler { + module: "facility".to_string(), + method: "get".to_string(), + } + } +} + +#[async_trait] +impl Handler for GetFacilityHandler { + fn module(&self) -> &str { + &self.module + } + + fn method(&self) -> &str { + &self.method + } + + async fn handle(&self, _model: String, _body: String) -> String { + let port = "8000"; + + let mut buffer = Cursor::new(Vec::new()); + let mut writer = EmitterConfig::new() + .perform_indent(true) + .create_writer(&mut buffer); + + writer.write(XmlEvent::start_element("response")).unwrap(); + + // + writer + .write(XmlEvent::start_element("facility").attr("status", "0")) + .unwrap(); + + // + writer.write(XmlEvent::start_element("location")).unwrap(); + writer.write(XmlEvent::start_element("id")).unwrap(); + writer.write(XmlEvent::characters("00000000")).unwrap(); + writer.write(XmlEvent::end_element()).unwrap(); // id + writer.write(XmlEvent::start_element("country")).unwrap(); + writer.write(XmlEvent::characters("US")).unwrap(); + writer.write(XmlEvent::end_element()).unwrap(); // country + writer.write(XmlEvent::start_element("region")).unwrap(); + writer.write(XmlEvent::characters("NA")).unwrap(); + writer.write(XmlEvent::end_element()).unwrap(); // region + writer.write(XmlEvent::start_element("name")).unwrap(); + writer.write(XmlEvent::characters("Medusa")).unwrap(); + writer.write(XmlEvent::end_element()).unwrap(); // name + writer + .write(XmlEvent::start_element("type").attr("__type", "u8")) + .unwrap(); + writer.write(XmlEvent::characters("0")).unwrap(); + writer.write(XmlEvent::end_element()).unwrap(); // type + writer.write(XmlEvent::end_element()).unwrap(); // location + + // + writer.write(XmlEvent::start_element("line")).unwrap(); + writer.write(XmlEvent::start_element("id")).unwrap(); + writer.write(XmlEvent::characters("00000000")).unwrap(); + writer.write(XmlEvent::end_element()).unwrap(); // id + writer + .write(XmlEvent::start_element("class").attr("__type", "u8")) + .unwrap(); + writer.write(XmlEvent::characters("0")).unwrap(); + writer.write(XmlEvent::end_element()).unwrap(); // class + writer.write(XmlEvent::end_element()).unwrap(); // line + + // + writer.write(XmlEvent::start_element("portfw")).unwrap(); + writer + .write(XmlEvent::start_element("globalip").attr("__type", "ip4")) + .unwrap(); + writer.write(XmlEvent::characters("0.0.0.0")).unwrap(); + writer.write(XmlEvent::end_element()).unwrap(); // globalip + writer + .write(XmlEvent::start_element("globalport").attr("__type", "u16")) + .unwrap(); + writer.write(XmlEvent::characters(port)).unwrap(); + writer.write(XmlEvent::end_element()).unwrap(); // globalport + writer + .write(XmlEvent::start_element("privateport").attr("__type", "u16")) + .unwrap(); + writer.write(XmlEvent::characters(port)).unwrap(); + writer.write(XmlEvent::end_element()).unwrap(); // privateport + writer.write(XmlEvent::end_element()).unwrap(); // portfw + + // + writer.write(XmlEvent::start_element("public")).unwrap(); + writer + .write(XmlEvent::start_element("flag").attr("__type", "u8")) + .unwrap(); + writer.write(XmlEvent::characters("1")).unwrap(); + writer.write(XmlEvent::end_element()).unwrap(); // flag + writer.write(XmlEvent::start_element("name")).unwrap(); + writer.write(XmlEvent::characters("Medusa")).unwrap(); + writer.write(XmlEvent::end_element()).unwrap(); // name + writer.write(XmlEvent::start_element("latitude")).unwrap(); + writer.write(XmlEvent::characters("0.0")).unwrap(); + writer.write(XmlEvent::end_element()).unwrap(); // latitude + writer.write(XmlEvent::start_element("longitude")).unwrap(); + writer.write(XmlEvent::characters("0.0")).unwrap(); + writer.write(XmlEvent::end_element()).unwrap(); // longitude + writer.write(XmlEvent::end_element()).unwrap(); // public + + // + writer.write(XmlEvent::start_element("share")).unwrap(); + + // + writer.write(XmlEvent::start_element("eacoin")).unwrap(); + writer + .write(XmlEvent::start_element("notchamount").attr("__type", "s32")) + .unwrap(); + writer.write(XmlEvent::characters("0")).unwrap(); + writer.write(XmlEvent::end_element()).unwrap(); // notchamount + writer + .write(XmlEvent::start_element("notchcount").attr("__type", "s32")) + .unwrap(); + writer.write(XmlEvent::characters("0")).unwrap(); + writer.write(XmlEvent::end_element()).unwrap(); // notchcount + writer + .write(XmlEvent::start_element("supplylimit").attr("__type", "s32")) + .unwrap(); + writer.write(XmlEvent::characters("100000")).unwrap(); + writer.write(XmlEvent::end_element()).unwrap(); // supplylimit + writer.write(XmlEvent::end_element()).unwrap(); // eacoin + + // + writer.write(XmlEvent::start_element("url")).unwrap(); + writer.write(XmlEvent::start_element("eapass")).unwrap(); + writer + .write(XmlEvent::characters("http://eagate.573.jp")) + .unwrap(); + writer.write(XmlEvent::end_element()).unwrap(); // eapass + writer.write(XmlEvent::start_element("arcadefan")).unwrap(); + writer + .write(XmlEvent::characters("http://eagate.573.jp")) + .unwrap(); + writer.write(XmlEvent::end_element()).unwrap(); // arcadefan + writer + .write(XmlEvent::start_element("konaminetdx")) + .unwrap(); + writer + .write(XmlEvent::characters("http://eagate.573.jp")) + .unwrap(); + writer.write(XmlEvent::end_element()).unwrap(); // konaminetdx + writer.write(XmlEvent::start_element("konamiid")).unwrap(); + writer + .write(XmlEvent::characters("http://eagate.573.jp")) + .unwrap(); + writer.write(XmlEvent::end_element()).unwrap(); // konamiid + writer.write(XmlEvent::start_element("eagate")).unwrap(); + writer + .write(XmlEvent::characters("http://eagate.573.jp")) + .unwrap(); + writer.write(XmlEvent::end_element()).unwrap(); // eagate + writer.write(XmlEvent::end_element()).unwrap(); // url + + writer.write(XmlEvent::end_element()).unwrap(); // share + writer.write(XmlEvent::end_element()).unwrap(); // facility + writer.write(XmlEvent::end_element()).unwrap(); // response + + String::from_utf8(buffer.into_inner()).unwrap() + } +} diff --git a/src/handlers/common/mod.rs b/src/handlers/common/mod.rs index a9d4845..482ce37 100644 --- a/src/handlers/common/mod.rs +++ b/src/handlers/common/mod.rs @@ -2,6 +2,7 @@ pub mod alive_pcb_tracker_handler; pub mod get_messages_handler; pub mod put_pcb_event_handler; +pub mod get_facility_handler; pub mod ota; pub mod card; \ No newline at end of file diff --git a/src/handlers/handler.rs b/src/handlers/handler.rs index 4f68d04..77993b4 100644 --- a/src/handlers/handler.rs +++ b/src/handlers/handler.rs @@ -1,4 +1,3 @@ - #[async_trait] pub trait Handler: Send + Sync { fn module(&self) -> &str; diff --git a/src/main.rs b/src/main.rs index 0c760aa..3ec6a8d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,7 +10,6 @@ mod utils; use handlers::boot::get_services_handler::GetServicesHandler; use handlers::common::alive_pcb_tracker_handler::AlivePcbTrackerHandler; -use handlers::common::card::inquire_card_managment_handler::InquireCardManagmentHandler; use handlers::common::get_messages_handler::GetMessageHandler; use handlers::common::ota::list_package_handler::ListPackageHandler; use handlers::common::ota::progress_dl_status_handler::ProgressDLStatusHandler; @@ -20,6 +19,7 @@ use rocket::fs::{relative, FileServer, NamedFile}; use routes::ea::core_route::handle_query_request; use routes::ea::core_route::handle_slash_request; use routes::ea::e_amusement_route::handle_ea_query_request; +//use handlers::common::get_facility_handler::handle_facility_get; #[macro_use] extern crate lazy_static; #[macro_use] extern crate rocket; @@ -37,7 +37,6 @@ fn register_handlers() -> Vec> { let put_pcb_event_handler = Arc::new(PutPcbEventHandler::new()); let list_package_handler = Arc::new(ListPackageHandler::new()); let progress_dl_status_handler = Arc::new(ProgressDLStatusHandler::new()); - let inquire_card_managment_handler = Arc::new(InquireCardManagmentHandler::new()); let handlers: Vec> = vec![ get_services_handler, @@ -45,13 +44,18 @@ fn register_handlers() -> Vec> { get_messages_handler, put_pcb_event_handler, list_package_handler, - progress_dl_status_handler, - inquire_card_managment_handler + progress_dl_status_handler ]; handlers } +// fn register_macro_handlers() { +// let handlers = vec![ +// Arc::new(handle_facility_get), +// ]; +// } + #[launch] fn rocket() -> _ { let handlers = register_handlers();