ew/src/main.rs

173 lines
5.8 KiB
Rust
Raw Normal View History

2024-02-21 19:50:18 +00:00
mod encryption;
2024-02-23 15:59:55 +00:00
mod router;
2024-02-21 19:50:18 +00:00
use actix_web::{
2024-02-23 15:59:55 +00:00
post,
get,
2024-02-21 19:50:18 +00:00
HttpResponse,
HttpRequest,
web,
dev::Service
};
#[post("/api/start")]
async fn start_start(req: HttpRequest, body: String) -> HttpResponse { router::start::start(req, body) }
2024-02-23 15:59:55 +00:00
#[post("/api/start/assetHash")]
async fn start_assethash(req: HttpRequest, body: String) -> HttpResponse { router::start::asset_hash(req, body) }
#[post("/api/dummy/login")]
async fn dummy_login(req: HttpRequest, body: String) -> HttpResponse { router::login::dummy(req, body) }
#[get("/api/user")]
async fn user(req: HttpRequest) -> HttpResponse { router::user::user(req) }
#[post("/api/user/initialize")]
async fn user_initialize(req: HttpRequest, body: String) -> HttpResponse { router::user::initialize(req, body) }
#[get("/api/purchase")]
async fn purchase(req: HttpRequest) -> HttpResponse { router::purchase::purchase(req) }
2024-02-24 01:13:03 +00:00
#[post("/api/tutorial")]
async fn tutorial(req: HttpRequest, body: String) -> HttpResponse { router::tutorial::tutorial(req, body) }
#[post("/api/friend")]
async fn friend(req: HttpRequest, body: String) -> HttpResponse { router::friend::friend(req, body) }
#[post("/api/live/guest")]
async fn live_guest(req: HttpRequest, body: String) -> HttpResponse { router::live::guest(req, body) }
#[post("/api/event")]
async fn event(req: HttpRequest, body: String) -> HttpResponse { router::event::event(req, body) }
#[post("/api/live/start")]
async fn live_start(req: HttpRequest, body: String) -> HttpResponse { router::live::start(req, body) }
#[get("/api/live/clearRate")]
async fn live_clearrate(req: HttpRequest) -> HttpResponse { router::live::clearrate(req) }
2024-02-24 01:13:03 +00:00
#[get("/api/mission")]
async fn mission(req: HttpRequest) -> HttpResponse { router::mission::mission(req) }
#[get("/api/home")]
async fn home(req: HttpRequest) -> HttpResponse { router::home::home(req) }
#[post("/api/lottery/get_tutorial")]
async fn lottery_tutorial(req: HttpRequest, body: String) -> HttpResponse { router::lottery::tutorial(req, body) }
#[post("/api/lottery")]
async fn lottery(req: HttpRequest, body: String) -> HttpResponse { router::lottery::lottery(req, body) }
async fn log_unknown_request(req: HttpRequest, body: String) -> HttpResponse {
if body != String::new() {
println!("{}", encryption::decrypt_packet(&body).unwrap());
}
2024-02-23 15:59:55 +00:00
println!("Unhandled request: {}", req.path());
HttpResponse::Ok().body("ok")
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
use actix_web::{App, HttpServer};
let rv = HttpServer::new(|| App::new()
.wrap_fn(|req, srv| {
println!("Request: {}", req.path());
srv.call(req)
})
.service(live_guest)
.service(live_clearrate)
.service(live_start)
.service(event)
.service(purchase)
.service(user_initialize)
.service(start_start)
2024-02-24 01:13:03 +00:00
.service(tutorial)
.service(lottery_tutorial)
.service(lottery)
.service(friend)
2024-02-24 01:13:03 +00:00
.service(mission)
.service(home)
2024-02-23 15:59:55 +00:00
.service(start_assethash)
.service(user)
.service(dummy_login)
2024-02-23 15:59:55 +00:00
.default_service(web::route().to(log_unknown_request)))
.bind(("0.0.0.0", 8080))?
.run();
println!("Server started: http://127.0.0.1:{}", 8080);
rv.await
}
/*
fn main() {
let base64_input = "MX2tzmKTxY7EsV46rYFZuAfxeY0tPHuZ0etG15WsK1MAzs/U0WUXE4bJZINrEvCxqqUbvCYxhDtXp3HoeH/zDXtnW183aF/aYycmUW3aAF6zyio4/PJoqFl7EGET37ruotoQ9Teof2PXpXraF94diw==";
match decrypt_packet(base64_input) {
Ok(decrypted_json) => {
// Process the decrypted JSON
println!("Decrypted JSON: {}", decrypted_json);
}
Err(err) => {
eprintln!("Error decrypting packet: {}", err);
}
}
}
*/
/*
2024-02-21 19:50:18 +00:00
async fn make_post_request(url: &str, body: &str, headers: &HeaderMap) -> Result<String, reqwest::Error> {
let client = reqwest::Client::new();
let mut response = client
.post(url)
.body(body.to_string());
for (name, value) in headers.iter() {
if name == "Accept-Encoding" {continue;};
if name == "host" {
2024-02-22 23:17:12 +00:00
response = response.header("host", "api-sif2.lovelive-sif2.com");
2024-02-21 19:50:18 +00:00
continue;
};
2024-02-23 15:59:55 +00:00
println!("{}: {}", name, value.to_str().unwrap());
2024-02-21 19:50:18 +00:00
response = response.header(name, value.to_str().unwrap());
}
let response_body = response.send().await?.text().await?;
Ok(response_body)
}
async fn make_get_request(url: &str, headers: &HeaderMap) -> Result<String, reqwest::Error> {
let client = reqwest::Client::new();
let mut response = client.get(url);
for (name, value) in headers.iter() {
if name == "Accept-Encoding" {continue;};
if name == "host" {
response = response.header("host", "api.app.lovelive-sif2.bushimo.jp");
continue;
};
response = response.header(name, value.to_str().unwrap());
}
let response_body = response.send().await?.text().await?;
Ok(response_body)
}
async fn log_unknown_request(req: HttpRequest, body: String) -> HttpResponse {
if body != String::new() {
println!("req: {}", encryption::decrypt_packet(&body).unwrap_or(String::new()));
2024-02-22 23:17:12 +00:00
let resp = make_post_request(&format!("https://api-sif2.lovelive-sif2.com{}", req.path()), &body, req.headers()).await.unwrap();
2024-02-21 19:50:18 +00:00
//println!("Unhandled request: {} {}", req.path(), body);
println!("resp: {}", encryption::decrypt_packet(&resp).unwrap_or(String::new()));
HttpResponse::Ok().body(resp)
} else {
2024-02-22 23:17:12 +00:00
let resp = make_get_request(&format!("https://api-sif2.lovelive-sif2.com{}", req.path()), req.headers()).await.unwrap();
2024-02-21 19:50:18 +00:00
//println!("Unhandled request: {} {}", req.path(), body);
println!("resp: {}", encryption::decrypt_packet(&resp).unwrap_or(String::new()));
HttpResponse::Ok().body(resp)
}
2024-02-23 15:59:55 +00:00
}*/