stupid commit
This commit is contained in:
parent
347e7cefa2
commit
21e57c481a
@ -4,6 +4,7 @@ version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
medusa_macros = { path = "externals/medusa_macros"}
|
||||
async-trait = "0.1.82"
|
||||
chrono = "0.4.38"
|
||||
kbinxml = { git = "https://github.com/mbilker/kbinxml-rs.git", version = "3.1.1" }
|
||||
|
174
src/handlers/common/get_facility_handler.rs
Normal file
174
src/handlers/common/get_facility_handler.rs
Normal file
@ -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();
|
||||
|
||||
// <facility status="0">
|
||||
writer
|
||||
.write(XmlEvent::start_element("facility").attr("status", "0"))
|
||||
.unwrap();
|
||||
|
||||
// <location>
|
||||
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
|
||||
|
||||
// <line>
|
||||
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
|
||||
|
||||
// <portfw>
|
||||
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
|
||||
|
||||
// <public>
|
||||
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
|
||||
|
||||
// <share>
|
||||
writer.write(XmlEvent::start_element("share")).unwrap();
|
||||
|
||||
// <eacoin>
|
||||
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
|
||||
|
||||
// <url>
|
||||
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()
|
||||
}
|
||||
}
|
@ -2,5 +2,6 @@
|
||||
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;
|
@ -1,4 +1,3 @@
|
||||
|
||||
#[async_trait]
|
||||
pub trait Handler: Send + Sync {
|
||||
fn module(&self) -> &str;
|
||||
|
12
src/main.rs
12
src/main.rs
@ -9,6 +9,7 @@ mod routes;
|
||||
|
||||
use handlers::boot::get_services_handler::GetServicesHandler;
|
||||
use handlers::common::alive_pcb_tracker_handler::AlivePcbTrackerHandler;
|
||||
use handlers::common::get_facility_handler::GetFacilityHandler;
|
||||
use handlers::common::get_messages_handler::GetMessageHandler;
|
||||
use handlers::common::ota::list_package_handler::ListPackageHandler;
|
||||
use handlers::common::ota::progress_dl_status_handler::ProgressDLStatusHandler;
|
||||
@ -18,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;
|
||||
@ -35,6 +37,7 @@ fn register_handlers() -> Vec<Arc<dyn Handler>> {
|
||||
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 facility_get_handler = Arc::new(GetFacilityHandler::new());
|
||||
|
||||
let handlers: Vec<Arc<dyn Handler>> = vec![
|
||||
get_services_handler,
|
||||
@ -42,12 +45,19 @@ fn register_handlers() -> Vec<Arc<dyn Handler>> {
|
||||
get_messages_handler,
|
||||
put_pcb_event_handler,
|
||||
list_package_handler,
|
||||
progress_dl_status_handler
|
||||
progress_dl_status_handler,
|
||||
facility_get_handler
|
||||
];
|
||||
|
||||
handlers
|
||||
}
|
||||
|
||||
// fn register_macro_handlers() {
|
||||
// let handlers = vec![
|
||||
// Arc::new(handle_facility_get),
|
||||
// ];
|
||||
// }
|
||||
|
||||
#[launch]
|
||||
fn rocket() -> _ {
|
||||
let handlers = register_handlers();
|
||||
|
Loading…
Reference in New Issue
Block a user