Skip to content

Commit

Permalink
Refactor part 2: Docs...
Browse files Browse the repository at this point in the history
  • Loading branch information
Hanro50 committed Mar 24, 2023
1 parent ff43b90 commit 72f6ea4
Show file tree
Hide file tree
Showing 14 changed files with 146 additions and 124 deletions.
19 changes: 19 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"cSpell.words": [
"Expt",
"Lexi",
"lexipacks",
"mcjs",
"MCJWT",
"mclc",
"mojang",
"nwjs",
"rlogin",
"rxboxlive",
"rxsts",
"signin",
"xsts",
"xuid",
"yuid"
]
}
198 changes: 99 additions & 99 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lexipacks/english.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"load.auth.microsoft": "Logging into Microsoft account",
"load.auth.xboxLive": "Logging into Xbox Live",
"load.auth.xboxLive.1": "Logging into Xbox Live",
"load.auth.xboxLive.2": "Authenticating with xbox live",
"load.auth.xboxLive.2": "Authenticating with Xbox live",
"load.auth.xsts": "Generating Xbox Live Security Token",

"load.auth.minecraft": "Generic Minecraft login flow event",
Expand Down
7 changes: 3 additions & 4 deletions src/assets.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { readFileSync } from "fs";
import type { Response } from "node-fetch";
import { join } from "path";
import { MCToken } from "./auth/minecraft";
/**
* A copy of the user object mclc uses
*/
Expand All @@ -22,7 +21,7 @@ export type MclcUser = {
};

/**
* If the exact code isn't founnd. The lexicon string is split up and shaved down till it finds a description for the code.
* If the exact code isn't found. The lexicon string is split up and shaved down till it finds a description for the code.
*
* For example; error.auth.microsoft will be shortend to error.auth if error.auth.microsoft isn't found
*/
Expand All @@ -40,7 +39,7 @@ export let lexicon = {

"error.auth.minecraft": "Unknown error occurred when attempting to login to Minecraft",
"error.auth.minecraft.login": "Failed to authenticate with Mojang with given Xbox account",
"error.auth.minecraft.profile": "Failed to fetch minecraft profile",
"error.auth.minecraft.profile": "Failed to fetch Minecraft profile",
"error.auth.minecraft.entitlements": "Failed to fetch player entitlements",

"error.gui": "An unknown gui framework error has occurred",
Expand All @@ -58,7 +57,7 @@ export let lexicon = {
"load.auth.microsoft": "Logging into Microsoft account",
"load.auth.xboxLive": "Logging into Xbox Live",
"load.auth.xboxLive.1": "Logging into Xbox Live",
"load.auth.xboxLive.2": "Authenticating with xbox live",
"load.auth.xboxLive.2": "Authenticating with Xbox live",
"load.auth.xsts": "Generating Xbox Live Security Token",

"load.auth.minecraft": "Generic Minecraft login flow event",
Expand Down
16 changes: 8 additions & 8 deletions src/auth/minecraft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ export function validate(token: MCToken | Minecraft | MclcUser) {
}

/**
* Gets a minecraft token from a saved mcToken.
* @param auth A new instance of the auth object
* Gets a Minecraft token from a saved mcToken.
* @param auth A new instance of the Auth object
* @param token The mcToken
* @param refresh Set to true if we should try refreshing the token
* @returns A newly serialized minecraft Token.
* @returns A newly serialized Minecraft Token.
*
* @warning The xbox object may not be restored using this method!
* @warning The Xbox object may not be restored using this method!
*/
export function fromToken(auth: Auth, token: MCToken): null | Minecraft;
export function fromToken(auth: Auth, token: MCToken, refresh?: boolean): Promise<Minecraft>;
Expand All @@ -58,12 +58,12 @@ export function fromToken(auth: Auth, token: MCToken, refresh?: boolean): null |
}

/**
* Gets a minecraft token from a saved mcToken.
* @param auth A new instance of the auth object
* Gets a Minecraft token from a saved mcToken.
* @param auth A new instance of the Auth object
* @param token The mcToken
* @returns A newly serialized minecraft Token.
* @returns A newly serialized Minecraft Token.
*
* @warning The xbox object may not be restored using this method!
* @warning The Xbox object may not be restored using this method!
*/
export function fromMclcToken(auth: Auth, token: MclcUser, refresh?: boolean): null | Minecraft | Promise<Minecraft> {
return fromToken(
Expand Down
4 changes: 2 additions & 2 deletions src/auth/xbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default class Xbox {
console.log(XSTS.DisplayClaims);
return `XBL3.0 x=${XSTS.DisplayClaims.xui[0].uhs};${XSTS.Token}`;
}
//infxbox

async refresh(force?: boolean) {
if (this.validate() && !force) return this;
let tkn = await this.parent.refresh(this.msToken);
Expand Down Expand Up @@ -125,7 +125,7 @@ export default class Xbox {
return this.exp > Date.now();
}
/**
* Feed this into the refresh funtion in the auth object that generated it.
* Feed this into the refresh function in the Auth object that generated it.
* @returns The refresh token
*/
save() {
Expand Down
3 changes: 2 additions & 1 deletion tests/console/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "launcher",
"private":true,
"name": "test-console",
"version": "0.0.1",
"main": "index.mjs",
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions tests/electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ function createWindow() {
// Open the DevTools.
// mainWindow.webContents.openDevTools()
}
const { auth, wrapError } = require('msmc');
const { Auth, wrapError } = require('msmc');
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.whenReady().then(() => {
createWindow()
console.log("Testing Electron. This should test most of the underlying code")
const msmc = new auth('select_account');
const msmc = new Auth('select_account');
msmc.on('load', console.log).launch('electron').then(async e => {
const t = await e.getMinecraft()
console.log(t.mclc())
Expand Down
3 changes: 2 additions & 1 deletion tests/electron/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "electron-quick-start",
"private":true,
"name": "test-console-electron",
"version": "1.0.0",
"description": "A minimal Electron application",
"main": "main.js",
Expand Down
2 changes: 1 addition & 1 deletion tests/nwjs/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { readFileSync } = require("fs");
const { auth, wrapError } = require("msmc");
const { Auth, wrapError } = require("msmc");
const { assets } = require("msmc");

assets.loadLexiPack("../../lexipacks/french.json")
Expand Down
3 changes: 2 additions & 1 deletion tests/nwjs/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "launcher",
"private":true,
"name": "test-nwjs",
"version": "0.0.1",
"main": "index.html",
"devDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion tests/raw/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "launcher",
"private":true,
"name": "test-raw",
"version": "0.0.1",
"main": "index.js",
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions tests/raw/test2.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import msmc from "msmc";
const authManager = new msmc.Auth("select_account");
//Launch using the 'raw' gui framework (can be 'electron' or 'nwjs')
const xboxManager = await authManager.launch("raw")
//Generate the minecraft login token
//Generate the Minecraft login token
const token = await xboxManager.getMinecraft();
// Pulled from the Minecraft Launcher core docs.
let opts = {
clientPackage: null,
// Simply call this function to convert the msmc minecraft object into a mclc authorization object
// Simply call this function to convert the msmc Minecraft object into a mclc authorization object
authorization: token.mclc(),
root: "./.minecraft",
version: {
Expand Down
2 changes: 1 addition & 1 deletion webpage/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ <h2>Xbox Live Integration</h2>
profiles
as well as the friend-lists of a set user. You can use this to build an interactive launcher that can notify you
when your user's friends are online. Custom client creators could even go a step further and potentially use
this to setup a one click join system. MSMC's social module can run independently meaning you can even
this to setup a one click join system. MSMC's Social module can run independently meaning you can even
potentially run it seperately on a remote server!</p>
<h2>Fine controll over refreshes and Logins</h2>
<img src="./assets/fine controll.png">
Expand Down

0 comments on commit 72f6ea4

Please sign in to comment.