Skip to content
Draft
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ reqwest = { version = "0.12.22", features = [
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
sf-api = "0.2.1"

sha1 = "0.10.6"
sqlx = { version = "0.8.6", features = ["runtime-tokio", "sqlite"] }
strum = { version = "0.26.3", features = ["derive"] }
Expand Down
60 changes: 60 additions & 0 deletions migrations/20250725103139_expeditions.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
CREATE TABLE Expedition (
id INTEGER PRIMARY KEY autoincrement NOT NULL,
pid INTEGER NOT NULL REFERENCES character (pid) ON DELETE cascade,
target INT NOT NULL,
alu_sec INT NOT NULL,
location_1 INT NOT NULL,
location_2 INT NOT NULL
);

CREATE INDEX ExpeditionPlayer ON Expedition(pid);

CREATE TABLE ActiveExpedition (
pid INTEGER PRIMARY KEY NOT NULL REFERENCES character (pid) ON DELETE cascade,
-- ExpeditionThing
target INT NOT NULL,

item1 INT DEFAULT NULL,
item2 INT DEFAULT NULL,
item3 INT DEFAULT NULL,
item4 INT DEFAULT NULL,

target_current INT NOT NULL DEFAULT 0,
target_amount INT NOT NULL DEFAULT 0,

current_floor INT NOT NULL DEFAULT 1,
heroism INT NOT NULL DEFAULT 0,

floor_stage INT NOT NULL DEFAULT 0,

encounter1 INT NOT NULL DEFAULT 0,
encounter2 INT NOT NULL DEFAULT 0,
encounter3 INT NOT NULL DEFAULT 0,
encounter4 INT NOT NULL DEFAULT 0,

boss_id INT NOT NULL,

reward1_type INT NOT NULL DEFAULT 0,
reward1_amount INT NOT NULL DEFAULT 0,
reward2_type INT NOT NULL DEFAULT 0,
reward2_amount INT NOT NULL DEFAULT 0,
reward3_type INT NOT NULL DEFAULT 0,
reward3_amount INT NOT NULL DEFAULT 0,
reward4_type INT NOT NULL DEFAULT 0,
reward4_amount INT NOT NULL DEFAULT 0
);

INSERT INTO Expedition (target, alu_sec, location_1, location_2, pid)
SELECT 33, 1500, 18, 12, pid FROM Character c;

INSERT INTO Expedition (target, alu_sec, location_1, location_2, pid)
SELECT 93, 1500, 18, 12, pid FROM Character c;

CREATE TABLE UserSetting (
pid INTEGER PRIMARY KEY autoincrement NOT NULL REFERENCES character(pid),
lang TEXT NOT NULL,
quest_pref TEXT NOT NULL DEFAULT 'a'
);

INSERT INTO UserSetting (pid, lang, quest_pref)
SELECT pid, 'en', 'a' FROM Character c;
33 changes: 26 additions & 7 deletions src/command/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ use fastrand::Rng;
use num_traits::FromPrimitive;
use request::Session;
use sf_api::{
gamestate::character::{Class, Gender, Race},
gamestate::{
character::{Class, Gender, Race},
tavern::{ExpeditionThing, Location},
},
misc::{HASH_CONST, sha1_hash},
};
use sqlx::Sqlite;
Expand All @@ -28,9 +31,9 @@ pub(crate) async fn account_check(

match count {
0 => ResponseBuilder::default()
.add_key("serverversion")
.start_section("serverversion")
.add_val(SERVER_VERSION)
.add_key("preregister")
.start_section("preregister")
.add_val(0)
.add_val(0)
.build(),
Expand Down Expand Up @@ -110,6 +113,21 @@ pub(crate) async fn account_create(
.fetch_one(&mut *tx)
.await?;

for _ in 0..2 {
let alu = [5, 10, 15, 20][fastrand::usize(0..4)] * 60;
sqlx::query_scalar!(
"INSERT INTO Expedition
(target, alu_sec, location_1, location_2)
VALUES ($1, $2, $3, $4)",
ExpeditionThing::BrokenSword as i32,
alu,
Location::SprawlingJungle as i32,
Location::SkullIsland as i32
)
.execute(&mut *tx)
.await?;
}

sqlx::query_scalar!("INSERT INTO BAG (pid) VALUES ($1)", pid)
.execute(&mut *tx)
.await?;
Expand Down Expand Up @@ -198,7 +216,7 @@ pub(crate) async fn account_create(
tx.commit().await?;

ResponseBuilder::default()
.add_key("tracking.s")
.start_section("tracking.s")
.add_str("signup")
.build()
}
Expand Down Expand Up @@ -274,9 +292,10 @@ pub(crate) async fn account_login(
let pwhash = info.pw_hash;

let correct_full_hash = sha1_hash(&format!("{pwhash}{login_count}"));
if correct_full_hash != full_hash {
Err(ServerError::WrongPassword)?;
}

// if correct_full_hash != full_hash {
// Err(ServerError::WrongPassword)?;
// }

let session_id: String = (0..DEFAULT_SESSION_ID.len())
.map(|_| rng.alphanumeric())
Expand Down
2 changes: 1 addition & 1 deletion src/command/guild.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub(crate) async fn group_get_hof(
}

ResponseBuilder::default()
.add_key("ranklistgroup.r")
.start_section("ranklistgroup.r")
.add_str(&guilds)
.build()
}
23 changes: 13 additions & 10 deletions src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub(crate) async fn handle_command<'a>(
}

match name {
"PlayerTwitchAuthtoken" => Ok(ServerResponse::Success),
"PlayerTwitchAuthtoken" => Ok(ServerResponse::Success), // TODO:
"AccountCheck" => account_check(db, args).await,
"AccountCreate" => account_create(session, db, args).await,
"AccountDelete" => account_delete(session, db, args).await,
Expand All @@ -85,6 +85,9 @@ pub(crate) async fn handle_command<'a>(
"Poll" => poll(session, "poll", db, Default::default()).await,
"UserSettingsUpdate" => Ok(ServerResponse::Success), // TODO:
"getserverversion" => get_server_version(session, db).await,
"ExpeditionStart" => player_start_expedition(session, db, args).await,
"WorldBossEventPoll" | "WorldBossEnter" => poll(session, "", db, Default::default()).await,
"WorldBossLogRewards" | "WorldBossLogDayInfos" => Ok(ServerResponse::Success),
_ => {
error!("Unknown command: {name} - {args:?}");
Err(ServerError::UnknownRequest(name.into()))
Expand All @@ -99,20 +102,20 @@ async fn pending_reward_view(
) -> Result<ServerResponse, ServerError> {
let _id = args.get_int(0, "msg_id")?;
let mut resp = ResponseBuilder::default();
resp.add_key("pendingrewardressources");
resp.start_section("pendingrewardressources");
for v in 1..=6 {
let val = v;
resp.add_val(val);
resp.add_val(999);
}
resp.add_key("pendingreward.item(0)");
resp.start_section("pendingreward.item(0)");

resp.build()
}

fn player_helpshift_auth_token() -> Result<ServerResponse, ServerError> {
ResponseBuilder::default()
.add_key("helpshiftauthtoken")
.start_section("helpshiftauthtoken")
.add_val("+eZGNZyCPfOiaufZXr/WpzaaCNHEKMmcT7GRJOGWJAU=")
.build()
}
Expand All @@ -134,20 +137,20 @@ async fn get_server_version(
.await?;

ResponseBuilder::default()
.add_key("serverversion")
.start_section("serverversion")
.add_val(SERVER_VERSION)
.add_key("preregister")
.start_section("preregister")
.add_val(now())
.add_val(now())
.add_str("Europe")
.add_str("Berlin")
.add_key("timestamp")
.start_section("timestamp")
.add_val(now())
.add_key("rankmaxplayer")
.start_section("rankmaxplayer")
.add_val(res.charactercount)
.add_key("rankmaxgroup")
.start_section("rankmaxgroup")
.add_val(res.guildcount)
.add_key("country")
.start_section("country")
.add_val("DE")
.build()
}
Expand Down
Loading