Cleanly handle unverified gree devices

This commit is contained in:
Ethan O'Brien
2026-07-26 23:15:02 -05:00
parent b5bd8ad4fb
commit 352ff2dbc5
5 changed files with 78 additions and 19 deletions

View File

@@ -118,6 +118,8 @@ pub const RESULT_GAME_VERSION_UPDATED: i32 = 12;
pub const RESULT_RESOURCE_UPDATED: i32 = 13;
pub const RESULT_SESSION: i32 = 14;
pub const PROTOCOL_HEADER: &str = "X-Protocol-Version";
pub fn client_protocol_version(req: &HttpRequest) -> u32 {
@@ -230,11 +232,7 @@ pub fn get_login(headers: &HeaderMap, body: &str) -> String {
Some(token) => {
token
},
None => {
let rv = gree::get_uuid(headers, body);
assert!(rv != String::new());
rv
},
None => gree::get_uuid(headers, body),
}
}

View File

@@ -16,6 +16,7 @@ use crate::database::gree::*;
const APP_ID: &str = "232610769078541";
const SRC_APP_ID: &str = "100900301";
const HMAC_SECRET_HEX: &str = "6438663638653238346566646636306262616563326432323563306366643432";
const ERROR_MIGRATED_DEVICE: i32 = 20;
struct RequireGreeAuth;
@@ -84,7 +85,7 @@ fn get_uid(req: &HttpRequest) -> String {
req.headers()
.get("Authorization")
.and_then(|h| h.to_str().ok())
.and_then(|auth| auth.split(",xoauth_requestor_id=\"").nth(1))
.and_then(|auth| auth.split("xoauth_requestor_id=\"").nth(1))
.and_then(|s| s.split('"').next())
.unwrap_or("")
.to_string()
@@ -95,13 +96,13 @@ fn send(req: HttpRequest, resp: JsonValue) -> impl Responder {
jzon::stringify(resp)
}
async fn not_found() -> impl Responder {
async fn not_found(req: HttpRequest) -> impl Responder {
let resp = object!{
code: 10001,
message: "Not Found",
result: "NG"
};
jzon::stringify(resp)
send(req, resp)
}
async fn initialize(req: HttpRequest, body: String) -> impl Responder {
@@ -119,8 +120,17 @@ async fn initialize(req: HttpRequest, body: String) -> impl Responder {
}
async fn authorize(req: HttpRequest, _body: String) -> impl Responder {
let resp = object!{
result: "OK"
let resp = if is_registered(&get_uid(&req)) {
object!{
result: "OK"
}
} else {
println!("Unregistered device authorizing: {}", get_uid(&req));
object!{
result: "NG",
code: ERROR_MIGRATED_DEVICE,
message: "Device is not registered"
}
};
send(req, resp)

View File

@@ -65,15 +65,23 @@ pub enum UserView {
Ranking,
}
const DEFAULT_CARD: i64 = 10010001;
fn proxy_card_id(id: i64) -> i64 {
let prefix = id / 10000;
if prefix < 10000 {
id
} else if prefix < 14000 {
return id;
}
let rv = if prefix < 14000 {
(prefix - 9000) * 10000 + 1
} else {
10010001
DEFAULT_CARD
};
// Not every prefix has a real character behind it
if crate::router::databases::CARD_LIST[rv.to_string()].is_empty() {
return DEFAULT_CARD;
}
rv
}
pub fn proxy_user_cards(user: &mut JsonValue) {