code improvements and clientsettings fallback

This commit is contained in:
Lawin0129
2022-06-11 20:10:08 +01:00
parent b1f3200fa2
commit 993a562c9f
13 changed files with 1725 additions and 2534 deletions

View File

@@ -4,11 +4,10 @@ const crypto = require("crypto");
const fs = require("fs");
const path = require("path");
const functions = require("./functions.js");
const memory = require("./../memory.json");
express.use((req, res, next) => {
// Get raw body in encoding latin1 for ClientSettings
if (req.originalUrl.includes('/fortnite/api/cloudstorage/user/') && req.method == "PUT") {
if (req.originalUrl.toLowerCase().startsWith("/fortnite/api/cloudstorage/user/") && req.method == "PUT") {
req.rawBody = "";
req.setEncoding("latin1");
@@ -19,7 +18,7 @@ express.use((req, res, next) => {
})
express.get("/fortnite/api/cloudstorage/system", async (req, res) => {
functions.GetVersionInfo(req, memory);
const memory = functions.GetVersionInfo(req);
if (memory.build >= 9.40 && memory.build <= 10.40) {
return res.status(404).end();
@@ -65,9 +64,11 @@ express.get("/fortnite/api/cloudstorage/system/:file", async (req, res) => {
})
express.get("/fortnite/api/cloudstorage/user/*/:file", async (req, res) => {
if (!fs.existsSync(path.join(process.env.LOCALAPPDATA, "LawinServer", "ClientSettings"))) {
fs.mkdirSync(path.join(process.env.LOCALAPPDATA, "LawinServer", "ClientSettings"));
}
try {
if (!fs.existsSync(path.join(process.env.LOCALAPPDATA, "LawinServer", "ClientSettings"))) {
fs.mkdirSync(path.join(process.env.LOCALAPPDATA, "LawinServer", "ClientSettings"));
}
} catch (err) {}
res.set("Content-Type", "application/octet-stream")
@@ -77,10 +78,13 @@ express.get("/fortnite/api/cloudstorage/user/*/:file", async (req, res) => {
});
}
functions.GetVersionInfo(req, memory);
const memory = functions.GetVersionInfo(req);
var currentBuildID = memory.CL;
const file = path.join(process.env.LOCALAPPDATA, "LawinServer", "ClientSettings", `ClientSettings-${currentBuildID}.Sav`);
let file;
if (process.env.LOCALAPPDATA) file = path.join(process.env.LOCALAPPDATA, "LawinServer", "ClientSettings", `ClientSettings-${currentBuildID}.Sav`);
else file = path.join(__dirname, "..", "ClientSettings", `ClientSettings-${currentBuildID}.Sav`);
if (fs.existsSync(file)) {
const ParsedFile = fs.readFileSync(file);
@@ -93,16 +97,21 @@ express.get("/fortnite/api/cloudstorage/user/*/:file", async (req, res) => {
})
express.get("/fortnite/api/cloudstorage/user/:accountId", async (req, res) => {
if (!fs.existsSync(path.join(process.env.LOCALAPPDATA, "LawinServer", "ClientSettings"))) {
fs.mkdirSync(path.join(process.env.LOCALAPPDATA, "LawinServer", "ClientSettings"));
}
try {
if (!fs.existsSync(path.join(process.env.LOCALAPPDATA, "LawinServer", "ClientSettings"))) {
fs.mkdirSync(path.join(process.env.LOCALAPPDATA, "LawinServer", "ClientSettings"));
}
} catch (err) {}
res.set("Content-Type", "application/json")
functions.GetVersionInfo(req, memory);
const memory = functions.GetVersionInfo(req);
var currentBuildID = memory.CL;
const file = path.join(process.env.LOCALAPPDATA, "LawinServer", "ClientSettings", `ClientSettings-${currentBuildID}.Sav`);
let file;
if (process.env.LOCALAPPDATA) file = path.join(process.env.LOCALAPPDATA, "LawinServer", "ClientSettings", `ClientSettings-${currentBuildID}.Sav`);
else file = path.join(__dirname, "..", "ClientSettings", `ClientSettings-${currentBuildID}.Sav`);
if (fs.existsSync(file)) {
const ParsedFile = fs.readFileSync(file, 'latin1');
@@ -126,15 +135,26 @@ express.get("/fortnite/api/cloudstorage/user/:accountId", async (req, res) => {
}
})
express.put("/fortnite/api/cloudstorage/user/*/*", async (req, res) => {
if (!fs.existsSync(path.join(process.env.LOCALAPPDATA, "LawinServer", "ClientSettings"))) {
fs.mkdirSync(path.join(process.env.LOCALAPPDATA, "LawinServer", "ClientSettings"));
express.put("/fortnite/api/cloudstorage/user/*/:file", async (req, res) => {
try {
if (!fs.existsSync(path.join(process.env.LOCALAPPDATA, "LawinServer", "ClientSettings"))) {
fs.mkdirSync(path.join(process.env.LOCALAPPDATA, "LawinServer", "ClientSettings"));
}
} catch (err) {}
if (req.params.file.toLowerCase() != "clientsettings.sav") {
return res.status(404).json({
"error": "file not found"
});
}
functions.GetVersionInfo(req, memory);
const memory = functions.GetVersionInfo(req);
var currentBuildID = memory.CL;
const file = path.join(process.env.LOCALAPPDATA, "LawinServer", "ClientSettings", `ClientSettings-${currentBuildID}.Sav`);
let file;
if (process.env.LOCALAPPDATA) file = path.join(process.env.LOCALAPPDATA, "LawinServer", "ClientSettings", `ClientSettings-${currentBuildID}.Sav`);
else file = path.join(__dirname, "..", "ClientSettings", `ClientSettings-${currentBuildID}.Sav`);
fs.writeFileSync(file, req.rawBody, 'latin1');
res.status(204).end();

View File

@@ -4,7 +4,6 @@ const fs = require("fs");
const friendslist = require("./../responses/friendslist.json");
const friendslist2 = require("./../responses/friendslist2.json");
const functions = require("./functions.js");
const memory = require("./../memory.json");
express.get("/friends/api/v1/*/settings", async (req, res) => {
res.json({})
@@ -15,7 +14,7 @@ express.get("/friends/api/v1/*/blocklist", async (req, res) => {
})
express.get("/friends/api/public/friends/:accountId", async (req, res) => {
functions.GetVersionInfo(req, memory);
const memory = functions.GetVersionInfo(req);
if (!friendslist.find(i => i.accountId == req.params.accountId)) {
var FriendObject = {

View File

@@ -1,33 +1,37 @@
const memory = require("./../memory.json");
const XMLBuilder = require("xmlbuilder");
const uuid = require("uuid");
function GetVersionInfo(req, memory) {
function GetVersionInfo(req) {
var memory = {
season: 0,
build: 0.0,
CL: "",
lobby: ""
}
if (req.headers["user-agent"])
{
var CL = "";
if (req.headers["user-agent"]) {
try {
var BuildID = req.headers["user-agent"].split("-")[3].split(",")[0]
try {
var BuildID = req.headers["user-agent"].split("-")[3].split(",")[0]
if (!Number.isNaN(Number(BuildID))) {
CL = BuildID;
}
if (Number.isNaN(Number(BuildID))) {
var BuildID = req.headers["user-agent"].split("-")[3].split(" ")[0]
if (!Number.isNaN(Number(BuildID))) {
CL = BuildID;
}
if (Number.isNaN(Number(BuildID))) {
var BuildID = req.headers["user-agent"].split("-")[3].split(" ")[0]
if (!Number.isNaN(Number(BuildID))) {
CL = BuildID;
}
}
} catch (err) {
try {
var BuildID = req.headers["user-agent"].split("-")[1].split("+")[0]
if (!Number.isNaN(Number(BuildID))) {
CL = BuildID;
}
} catch (err) {}
}
} catch (err) {
try {
var BuildID = req.headers["user-agent"].split("-")[1].split("+")[0]
if (!Number.isNaN(Number(BuildID))) {
CL = BuildID;
}
} catch (err) {}
}
try {
@@ -53,6 +57,8 @@ function GetVersionInfo(req, memory) {
memory.lobby = "LobbyWinterDecor";
}
}
return memory;
}
function getItemShop() {
@@ -131,7 +137,7 @@ function getItemShop() {
}
function getTheater(req) {
GetVersionInfo(req, memory);
const memory = GetVersionInfo(req);
var theater = JSON.stringify(require("./../responses/worldstw.json"));
var Season = "Season" + memory.season;
@@ -178,7 +184,7 @@ function getTheater(req) {
}
function getContentPages(req) {
GetVersionInfo(req, memory);
const memory = GetVersionInfo(req);
const contentpages = JSON.parse(JSON.stringify(require("./../responses/contentpages.json")));

View File

@@ -5,7 +5,6 @@ const path = require("path");
const iniparser = require("ini");
const config = iniparser.parse(fs.readFileSync(path.join(__dirname, "..", "Config", "config.ini")).toString());
const functions = require("./functions.js");
const memory = require("./../memory.json");
express.get("/fortnite/api/matchmaking/session/findPlayer/*", async (req, res) => {
res.status(200);
@@ -13,9 +12,7 @@ express.get("/fortnite/api/matchmaking/session/findPlayer/*", async (req, res) =
})
express.get("/fortnite/api/game/v2/matchmakingservice/ticket/player/*", async (req, res) => {
memory.currentbuildUniqueId = req.query.bucketId.split(":")[0];
fs.writeFileSync("./memory.json", JSON.stringify(memory, null, 2));
res.cookie("currentbuildUniqueId", req.query.bucketId.split(":")[0]);
res.json({
"serviceUrl": "ws://lawinservermatchmaker.herokuapp.com",
@@ -72,7 +69,7 @@ express.get("/fortnite/api/matchmaking/session/:session_id", async (req, res) =>
"usesPresence": false,
"allowJoinViaPresence": true,
"allowJoinViaPresenceFriendsOnly": false,
"buildUniqueId": memory.currentbuildUniqueId, // buildUniqueId is different for every build, this uses the netver of the version you're currently using
"buildUniqueId": req.cookies.currentbuildUniqueId || "0", // buildUniqueId is different for every build, this uses the netver of the version you're currently using
"lastUpdated": new Date().toISOString(),
"started": false
})

View File

@@ -6,10 +6,9 @@ const iniparser = require("ini");
const config = iniparser.parse(fs.readFileSync(path.join(__dirname, "..", "Config", "config.ini")).toString());
const functions = require("./functions.js");
const catalog = functions.getItemShop();
const memory = require("./../memory.json");
express.use(function (req, res, next) {
if (!req.query.profileId) {
express.use((req, res, next) => {
if (!req.query.profileId && req.originalUrl.toLowerCase().startsWith("/fortnite/api/game/v2/profile/")) {
return res.status(404).json({
error: "Profile not defined."
});
@@ -17,7 +16,8 @@ express.use(function (req, res, next) {
fs.readdirSync("./profiles").forEach((file) => {
if (file.endsWith(".json")) {
functions.GetVersionInfo(req, memory);
const memory = functions.GetVersionInfo(req);
const profile = require(`./../profiles/${file}`);
if (!profile.rvn) profile.rvn = 0;
if (!profile.items) profile.items = {}
@@ -61,6 +61,7 @@ express.post("/fortnite/api/game/v2/profile/*/client/SetAffiliateName", async (r
if (req.body.affiliateName.toLowerCase() == code.toLowerCase() || req.body.affiliateName == "") {
profile.stats.attributes.mtx_affiliate_set_time = new Date().toISOString();
profile.stats.attributes.mtx_affiliate = req.body.affiliateName;
StatChanged = true;
}
})
@@ -312,7 +313,7 @@ express.post("/fortnite/api/game/v2/profile/*/client/UnlockRewardNode", async (r
const profile = require(`./../profiles/${req.query.profileId || "athena"}.json`);
const common_core = require("./../profiles/common_core.json");
const WinterFestIDS = require("./../responses/winterfestrewards.json");
functions.GetVersionInfo(req, memory);
const memory = functions.GetVersionInfo(req);
// do not change any of these or you will end up breaking it
var ApplyProfileChanges = [];
@@ -865,7 +866,7 @@ express.post("/fortnite/api/game/v2/profile/*/client/MarkNewQuestNotificationSen
express.post("/fortnite/api/game/v2/profile/*/client/ClientQuestLogin", async (req, res) => {
const profile = require(`./../profiles/${req.query.profileId || "athena"}.json`);
var QuestIDS = JSON.parse(JSON.stringify(require("./../responses/quests.json")));
functions.GetVersionInfo(req, memory);
const memory = functions.GetVersionInfo(req);
// do not change any of these or you will end up breaking it
var ApplyProfileChanges = [];
@@ -1387,7 +1388,7 @@ express.post("/fortnite/api/game/v2/profile/*/client/IncrementNamedCounterStat",
express.post("/fortnite/api/game/v2/profile/*/client/ClaimLoginReward", async (req, res) => {
const profile = require(`./../profiles/${req.query.profileId || "campaign"}.json`);
const DailyRewards = require("./../responses/dailyrewards.json");
functions.GetVersionInfo(req, memory);
const memory = functions.GetVersionInfo(req);
// do not change any of these or you will end up breaking it
var ApplyProfileChanges = [];
@@ -2461,7 +2462,7 @@ express.post("/fortnite/api/game/v2/profile/*/client/TransmogItem", async (req,
// Craft item STW (Guns, melees and traps only)
express.post("/fortnite/api/game/v2/profile/*/client/CraftWorldItem", async (req, res) => {
functions.GetVersionInfo(req, memory);
const memory = functions.GetVersionInfo(req);
const profile = require(`./../profiles/${req.query.profileId || "theater0"}.json`);
var schematic_profile;
@@ -3512,7 +3513,7 @@ express.post("/fortnite/api/game/v2/profile/*/client/ClearHeroLoadout", async (r
// Recycle items STW
express.post("/fortnite/api/game/v2/profile/*/client/RecycleItemBatch", async (req, res) => {
functions.GetVersionInfo(req, memory);
const memory = functions.GetVersionInfo(req);
const profile = require(`./../profiles/${req.query.profileId || "campaign"}.json`);
@@ -5381,7 +5382,7 @@ express.post("/fortnite/api/game/v2/profile/*/client/PurchaseCatalogEntry", asyn
if (value.offerId == req.body.offerId) {
var Quantity = 0;
catalog.storefronts[a].catalogEntries[b].itemGrants.forEach(function(value, c) {
functions.GetVersionInfo(req, memory);
const memory = functions.GetVersionInfo(req);
if (4 >= memory.season && PurchasedLlama == false) {
if (MultiUpdate.length == 0) {

View File

@@ -1,10 +1,9 @@
const Express = require("express");
const express = Express.Router();
const functions = require("./functions.js");
const memory = require("./../memory.json");
express.get("/fortnite/api/calendar/v1/timeline", async (req, res) => {
functions.GetVersionInfo(req, memory);
const memory = functions.GetVersionInfo(req);
var activeEvents = [
{

View File

@@ -5,7 +5,12 @@ const XMLParser = require("xml-parser");
const functions = require("./../structure/functions.js");
const port = 80;
const wss = new WebSocket({ port: port }, console.log("XMPP started listening on port", port));
const wss = new WebSocket({ port: port }, () => console.log("XMPP started listening on port", port));
wss.on("error", (err) => {
if (err.code == "EADDRINUSE") console.log("XMPP \x1b[31mFAILED\x1b[0m to start hosting on port", port);
else throw err;
})
global.Clients = [];
@@ -62,8 +67,10 @@ wss.on('connection', async (ws) => {
if (decodedBase64 && accountId && decodedBase64.length == 3) {
Authenticated = true;
console.log(`An xmpp client with the account id ${accountId} has logged in.`);
Success(ws);
ws.send(XMLBuilder.create("success").attribute("xmlns", "urn:ietf:params:xml:ns:xmpp-sasl").toString());
} else {
return Error(ws);
}
@@ -207,10 +214,6 @@ function Error(ws) {
ws.close();
}
function Success(ws) {
ws.send(XMLBuilder.create("success").attribute("xmlns", "urn:ietf:params:xml:ns:xmpp-sasl").toString());
}
function updatePresenceForAll(ws, body, away, offline) {
if (global.Clients.find(i => i.client == ws)) {
var SenderData = global.Clients.find(i => i.client == ws);