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

@@ -1,11 +1,11 @@
[/Script/FortniteGame.FortGlobals]
bAllowLogout=true
bAllowLogout=true # Enables log out button.
[/Script/FortniteGame.FortChatManager]
bShouldRequestGeneralChatRooms=true
bShouldRequestGeneralChatRooms=true # Request for chat rooms (global chat and founders chat).
bShouldJoinGlobalChat=true
bShouldJoinFounderChat=true
bIsAthenaGlobalChatEnabled=true
bIsAthenaGlobalChatEnabled=true # Battle royale global chat.
[/Script/FortniteGame.FortTextHotfixConfig]
+TextReplacements=(Category=Game, Namespace="", bIsMinimalPatch=True, Key="D5ECE3CD484655CBAE1DB6922C1D87C7", NativeString="Getting Started", LocalizedStrings=(("ar","مرحبًا بك في LawinServer!"),("en","Welcome to LawinServer!"),("de","Willkommen bei LawinServer!"),("es","¡Bienvenidos a LawinServer!"),("es-419","¡Bienvenidos a LawinServer!"),("fr","Bienvenue sur LawinServer !"),("it","Benvenuto in LawinServer!"),("ja","LawinServerへようこそ"),("ko","LawinServer에 오신 것을 환영합니다!"),("pl","Witaj w LawinServerze!"),("pt-BR","Bem-vindo ao LawinServer!"),("ru","Добро пожаловать в LawinServer!"),("tr","LavinServer'a Hoş Geldiniz!")))

View File

@@ -1,11 +1,17 @@
[Config]
bUseConfigDisplayName=false # If this is set to false, it will use the email to display name method.
displayName=LawinServer # Your fortnite display name.
# If this is set to false, it will use the email to display name method.
bUseConfigDisplayName=false
# Your fortnite display name (will only be used if the property above is set to true).
displayName=LawinServer
[Profile]
bCompletedSeasonalQuests=false # If this is set to true, every BR and StW seasonal quest will be on complete. Works for Battle Royale from Season 3 to Season 20 and for Save the World from Season 2 to Season X.
# If this is set to true, every BR and StW seasonal quest will be on complete. Works for Battle Royale from Season 3 to Season 20 and for Save the World from Season 2 to Season X.
bCompletedSeasonalQuests=false
[GameServer]
# Matchmaker gameserver config, you can use this to connect to gameservers like rift (titanium), fortmp, etc... (they have to be hosting though).
ip=127.0.0.1 # IP the matchmaker will use upon join.
port=7777 # PORT the matchmaker will use upon join.
# IP the matchmaker will use upon join.
ip=127.0.0.1
# PORT the matchmaker will use upon join.
port=7777

View File

@@ -2,10 +2,12 @@ const Express = require("express");
const express = Express();
const fs = require("fs");
const path = require("path");
const cookieParser = require("cookie-parser");
express.use(Express.json());
express.use(Express.urlencoded({ extended: true }));
express.use(Express.static('public'));
express.use(cookieParser());
express.use(require("./structure/party.js"));
express.use(require("./structure/discovery.js"))
@@ -24,13 +26,26 @@ express.use(require("./structure/cloudstorage.js"));
express.use(require("./structure/mcp.js"));
const port = process.env.PORT || 3551;
express.listen(port, console.log("LawinServer started listening on port", port));
require("./structure/xmpp.js");
express.listen(port, () => {
console.log("LawinServer started listening on port", port);
if (!fs.existsSync(path.join(process.env.LOCALAPPDATA, "LawinServer"))) fs.mkdirSync(path.join(process.env.LOCALAPPDATA, "LawinServer"));
require("./structure/xmpp.js");
}).on("error", (err) => {
if (err.code == "EADDRINUSE") console.log(`\x1b[31mERROR\x1b[0m: Port ${port} is already in use!`);
else throw err;
// keep this at the end of the code thanks
express.all("*", async (req, res) => {
process.exit(0);
});
try {
if (!fs.existsSync(path.join(process.env.LOCALAPPDATA, "LawinServer"))) fs.mkdirSync(path.join(process.env.LOCALAPPDATA, "LawinServer"));
} catch (err) {
// fallback
if (!fs.existsSync(path.join(__dirname, "ClientSettings"))) fs.mkdirSync(path.join(__dirname, "ClientSettings"));
}
// if endpoint not found, return this error
express.use((req, res, next) => {
var XEpicErrorName = "errors.com.lawinserver.common.not_found";
var XEpicErrorCode = 1004;
@@ -47,5 +62,4 @@ express.all("*", async (req, res) => {
"originatingService": "any",
"intent": "prod"
});
res.end();
});

22
package-lock.json generated
View File

@@ -9,6 +9,7 @@
"version": "1.0.0",
"license": "GPL-3.0",
"dependencies": {
"cookie-parser": "^1.4.6",
"crypto": "^1.0.1",
"express": "^4.17.2",
"fs": "^0.0.1-security",
@@ -92,6 +93,18 @@
"node": ">= 0.6"
}
},
"node_modules/cookie-parser": {
"version": "1.4.6",
"resolved": "https://registry.npmjs.org/cookie-parser/-/cookie-parser-1.4.6.tgz",
"integrity": "sha512-z3IzaNjdwUC2olLIB5/ITd0/setiaFMLYiZJle7xg5Fe9KWAceil7xszYfHHBtDFYLSgJduS2Ty0P1uJdPDJeA==",
"dependencies": {
"cookie": "0.4.1",
"cookie-signature": "1.0.6"
},
"engines": {
"node": ">= 0.8.0"
}
},
"node_modules/cookie-signature": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
@@ -661,6 +674,15 @@
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.1.tgz",
"integrity": "sha512-ZwrFkGJxUR3EIoXtO+yVE69Eb7KlixbaeAWfBQB9vVsNn/o+Yw69gBWSSDK825hQNdN+wF8zELf3dFNl/kxkUA=="
},
"cookie-parser": {
"version": "1.4.6",
"resolved": "https://registry.npmjs.org/cookie-parser/-/cookie-parser-1.4.6.tgz",
"integrity": "sha512-z3IzaNjdwUC2olLIB5/ITd0/setiaFMLYiZJle7xg5Fe9KWAceil7xszYfHHBtDFYLSgJduS2Ty0P1uJdPDJeA==",
"requires": {
"cookie": "0.4.1",
"cookie-signature": "1.0.6"
}
},
"cookie-signature": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",

View File

@@ -4,6 +4,7 @@
"description": "A fortnite backend which supports both BR and STW for every single fortnite build.",
"main": "index.js",
"dependencies": {
"cookie-parser": "^1.4.6",
"crypto": "^1.0.1",
"express": "^4.17.2",
"fs": "^0.0.1-security",

File diff suppressed because it is too large Load Diff

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) => {
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) => {
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) => {
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) {}
functions.GetVersionInfo(req, memory);
if (req.params.file.toLowerCase() != "clientsettings.sav") {
return res.status(404).json({
"error": "file not found"
});
}
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,13 +1,18 @@
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]
if (!Number.isNaN(Number(BuildID))) {
@@ -28,7 +33,6 @@ function GetVersionInfo(req, memory) {
}
} catch (err) {}
}
}
try {
var Build = req.headers["user-agent"].split("Release-")[1].split("-")[0];
@@ -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);