Skip to content

Commit b63c69f

Browse files
committed
new rotur.js v7
1 parent bdeecd9 commit b63c69f

File tree

1 file changed

+65
-59
lines changed

1 file changed

+65
-59
lines changed

featured/Rotur.js

Lines changed: 65 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ const blocks = {
7070
}
7171
};
7272

73-
MD5 = function (r) { function n(r, n) { var t, o, e, u, f; return e = 2147483648 & r, u = 2147483648 & n, f = (1073741823 & r) + (1073741823 & n), (t = 1073741824 & r) & (o = 1073741824 & n) ? 2147483648 ^ f ^ e ^ u : t | o ? 1073741824 & f ? 3221225472 ^ f ^ e ^ u : 1073741824 ^ f ^ e ^ u : f ^ e ^ u } function t(r, t, o, e, u, f, a) { return r = n(r, n(n(t & o | ~t & e, u), a)), n(r << f | r >>> 32 - f, t) } function o(r, t, o, e, u, f, a) { return r = n(r, n(n(t & e | o & ~e, u), a)), n(r << f | r >>> 32 - f, t) } function e(r, t, o, e, u, f, a) { return r = n(r, n(n(t ^ o ^ e, u), a)), n(r << f | r >>> 32 - f, t) } function u(r, t, o, e, u, f, a) { return r = n(r, n(n(o ^ (t | ~e), u), a)), n(r << f | r >>> 32 - f, t) } function f(r) { var n, t = "", o = ""; for (n = 0; 3 >= n; n++)t += (o = "0" + (o = r >>> 8 * n & 255).toString(16)).substr(o.length - 2, 2); return t } var a, i, C, c, g, h, d, v, S; for (r = function (r) { r = r.replace(/\r\n/g, "\n"); for (var n = "", t = 0; t < r.length; t++) { var o = r.charCodeAt(t); 128 > o ? n += String.fromCharCode(o) : (127 < o && 2048 > o ? n += String.fromCharCode(o >> 6 | 192) : (n += String.fromCharCode(o >> 12 | 224), n += String.fromCharCode(o >> 6 & 63 | 128)), n += String.fromCharCode(63 & o | 128)) } return n }(r), a = function (r) { for (var n, t = r.length, o = 16 * (((n = t + 8) - n % 64) / 64 + 1), e = Array(o - 1), u = 0, f = 0; f < t;)u = f % 4 * 8, e[n = (f - f % 4) / 4] |= r.charCodeAt(f) << u, f++; return e[n = (f - f % 4) / 4] |= 128 << f % 4 * 8, e[o - 2] = t << 3, e[o - 1] = t >>> 29, e }(r), h = 1732584193, d = 4023233417, v = 2562383102, S = 271733878, r = 0; r < a.length; r += 16)i = h, C = d, c = v, g = S, h = t(h, d, v, S, a[r + 0], 7, 3614090360), S = t(S, h, d, v, a[r + 1], 12, 3905402710), v = t(v, S, h, d, a[r + 2], 17, 606105819), d = t(d, v, S, h, a[r + 3], 22, 3250441966), h = t(h, d, v, S, a[r + 4], 7, 4118548399), S = t(S, h, d, v, a[r + 5], 12, 1200080426), v = t(v, S, h, d, a[r + 6], 17, 2821735955), d = t(d, v, S, h, a[r + 7], 22, 4249261313), h = t(h, d, v, S, a[r + 8], 7, 1770035416), S = t(S, h, d, v, a[r + 9], 12, 2336552879), v = t(v, S, h, d, a[r + 10], 17, 4294925233), d = t(d, v, S, h, a[r + 11], 22, 2304563134), h = t(h, d, v, S, a[r + 12], 7, 1804603682), S = t(S, h, d, v, a[r + 13], 12, 4254626195), v = t(v, S, h, d, a[r + 14], 17, 2792965006), h = o(h, d = t(d, v, S, h, a[r + 15], 22, 1236535329), v, S, a[r + 1], 5, 4129170786), S = o(S, h, d, v, a[r + 6], 9, 3225465664), v = o(v, S, h, d, a[r + 11], 14, 643717713), d = o(d, v, S, h, a[r + 0], 20, 3921069994), h = o(h, d, v, S, a[r + 5], 5, 3593408605), S = o(S, h, d, v, a[r + 10], 9, 38016083), v = o(v, S, h, d, a[r + 15], 14, 3634488961), d = o(d, v, S, h, a[r + 4], 20, 3889429448), h = o(h, d, v, S, a[r + 9], 5, 568446438), S = o(S, h, d, v, a[r + 14], 9, 3275163606), v = o(v, S, h, d, a[r + 3], 14, 4107603335), d = o(d, v, S, h, a[r + 8], 20, 1163531501), h = o(h, d, v, S, a[r + 13], 5, 2850285829), S = o(S, h, d, v, a[r + 2], 9, 4243563512), v = o(v, S, h, d, a[r + 7], 14, 1735328473), h = e(h, d = o(d, v, S, h, a[r + 12], 20, 2368359562), v, S, a[r + 5], 4, 4294588738), S = e(S, h, d, v, a[r + 8], 11, 2272392833), v = e(v, S, h, d, a[r + 11], 16, 1839030562), d = e(d, v, S, h, a[r + 14], 23, 4259657740), h = e(h, d, v, S, a[r + 1], 4, 2763975236), S = e(S, h, d, v, a[r + 4], 11, 1272893353), v = e(v, S, h, d, a[r + 7], 16, 4139469664), d = e(d, v, S, h, a[r + 10], 23, 3200236656), h = e(h, d, v, S, a[r + 13], 4, 681279174), S = e(S, h, d, v, a[r + 0], 11, 3936430074), v = e(v, S, h, d, a[r + 3], 16, 3572445317), d = e(d, v, S, h, a[r + 6], 23, 76029189), h = e(h, d, v, S, a[r + 9], 4, 3654602809), S = e(S, h, d, v, a[r + 12], 11, 3873151461), v = e(v, S, h, d, a[r + 15], 16, 530742520), h = u(h, d = e(d, v, S, h, a[r + 2], 23, 3299628645), v, S, a[r + 0], 6, 4096336452), S = u(S, h, d, v, a[r + 7], 10, 1126891415), v = u(v, S, h, d, a[r + 14], 15, 2878612391), d = u(d, v, S, h, a[r + 5], 21, 4237533241), h = u(h, d, v, S, a[r + 12], 6, 1700485571), S = u(S, h, d, v, a[r + 3], 10, 2399980690), v = u(v, S, h, d, a[r + 10], 15, 4293915773), d = u(d, v, S, h, a[r + 1], 21, 2240044497), h = u(h, d, v, S, a[r + 8], 6, 1873313359), S = u(S, h, d, v, a[r + 15], 10, 4264355552), v = u(v, S, h, d, a[r + 6], 15, 2734768916), d = u(d, v, S, h, a[r + 13], 21, 1309151649), h = u(h, d, v, S, a[r + 4], 6, 4149444226), S = u(S, h, d, v, a[r + 11], 10, 3174756917), v = u(v, S, h, d, a[r + 2], 15, 718787259), d = u(d, v, S, h, a[r + 9], 21, 3951481745), h = n(h, i), d = n(d, C), v = n(v, c), S = n(S, g); return (f(h) + f(d) + f(v) + f(S)).toLowerCase() };
74-
7573
randomString = function (length) {
7674
var result = "";
7775
var characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
@@ -111,7 +109,7 @@ class RoturExtension {
111109
this.lastJoined = "";
112110
this.lastLeft = "";
113111

114-
this.version = 6;
112+
this.version = 7;
115113
this.outdated = false;
116114

117115
this.callJson = {};
@@ -147,6 +145,11 @@ class RoturExtension {
147145
console.error('Error fetching version:', error);
148146
});
149147
}
148+
149+
const cleanUpLogin = () => { window._roturOverlay&&Scratch.renderer.removeOverlay(window._roturOverlay),window.removeEventListener("message",window._roturAuthHandler),delete window._roturOverlay,delete window._roturAuthHandler; }
150+
151+
vm.on("PROJECT_RUN_START", cleanUpLogin);
152+
vm.on("PROJECT_RUN_STOP", cleanUpLogin);
150153
}
151154

152155
async _initializeBadges() {
@@ -172,7 +175,7 @@ class RoturExtension {
172175
getInfo() {
173176
return {
174177
id: "roturEXT",
175-
name: "RoturV6",
178+
name: `RoturV${this.version}`,
176179
color1: "#403041",
177180
blocks: [
178181
blocks.button("New Update Available", "openUpdate", {
@@ -200,6 +203,12 @@ class RoturExtension {
200203
blocks.event("whenDisconnected", "When Disconnected From Server"),
201204
blocks.separator(),
202205
blocks.label("Authentication"),
206+
blocks.command("login_prompt", "Open login prompt with style [STYLE_URL]", {
207+
STYLE_URL: {
208+
type: Scratch.ArgumentType.STRING,
209+
defaultValue: "https://origin.mistium.com/Resources/auth.css",
210+
},
211+
}),
203212
blocks.reporter("login", "Login With Username: [USERNAME] And Password: [PASSWORD]", {
204213
USERNAME: {
205214
type: Scratch.ArgumentType.STRING,
@@ -209,17 +218,17 @@ class RoturExtension {
209218
type: Scratch.ArgumentType.STRING,
210219
defaultValue: "password",
211220
},
212-
}),
213-
blocks.reporter("loginMd5", "Login With Username: [USERNAME] And Password: [PASSWORD] (MD5)", {
221+
}, { hideFromPalette: true }),
222+
blocks.reporter("loginMd5", "Login With Username: [USERNAME] And Password: [PASSWORD] ()", {
214223
USERNAME: {
215224
type: Scratch.ArgumentType.STRING,
216225
defaultValue: "test",
217226
},
218227
PASSWORD: {
219228
type: Scratch.ArgumentType.STRING,
220-
defaultValue: "md5password",
229+
defaultValue: "password",
221230
},
222-
}),
231+
}, { hideFromPalette: true }),
223232
blocks.reporter("loginToken", "Login With Token: [TOKEN]", {
224233
TOKEN: {
225234
type: Scratch.ArgumentType.STRING,
@@ -235,7 +244,7 @@ class RoturExtension {
235244
type: Scratch.ArgumentType.STRING,
236245
defaultValue: "password",
237246
},
238-
}),
247+
}, { hideFromPalette: true }),
239248
blocks.command("logout", "Logout"),
240249
blocks.boolean("loggedIn", "Authenticated"),
241250
blocks.boolean("firstLogin", "Is This The First Login Of Today?", {}, {
@@ -1075,27 +1084,59 @@ class RoturExtension {
10751084
return false;
10761085
}
10771086

1078-
login(args) {
1079-
args.PASSWORD = MD5("" + args.PASSWORD);
1080-
return this._login(args);
1087+
login_prompt({ STYLE_URL }) {
1088+
if (!this.is_connected) { console.error("Not Connected"); return; }
1089+
if (this.authenticated) { console.error("Already Logged In"); return; }
1090+
1091+
// Create iframe for authentication
1092+
const e = document.createElement("iframe");
1093+
e.id = "rotur-auth";
1094+
e.src = `https://rotur.dev/auth?styles=${encodeURIComponent(STYLE_URL)}`;
1095+
Object.assign(e.style, {
1096+
width: "100%",
1097+
height: "100%",
1098+
border: "none",
1099+
pointerEvents: "auto"
1100+
});
1101+
1102+
const t = Scratch.renderer.addOverlay(e);
1103+
1104+
const _roturAuthHandler = (a) => {
1105+
console.log("Rotur Auth Message Received", a);
1106+
if ("https://rotur.dev" === a.origin && "rotur-auth-token" === a.data?.type) {
1107+
1108+
Scratch.renderer.removeOverlay(t);
1109+
e.remove();
1110+
window.removeEventListener("message", _roturAuthHandler);
1111+
1112+
// Now authenticate with the token
1113+
this.loginToken({ TOKEN: a.data.token });
1114+
}
1115+
};
1116+
1117+
window.addEventListener("message", _roturAuthHandler);
1118+
return "Auth window opened";
10811119
}
10821120

1083-
loginMd5(args) {
1084-
return this._login(args);
1121+
login() {}
1122+
loginMd5() {}
1123+
1124+
loginToken(args) {
1125+
return this._loginWithToken(args.TOKEN);
10851126
}
10861127

1087-
async _login(args) {
1128+
async _loginWithToken(token) {
10881129
if (!this.is_connected) return "Not Connected";
10891130
if (this.authenticated) return "Already Logged In";
10901131

10911132
try {
1092-
const response = await fetch(`https://social.rotur.dev/get_user?username=${encodeURIComponent(args.USERNAME)}&password=${encodeURIComponent(args.PASSWORD)}`);
1133+
const response = await fetch(`https://social.rotur.dev/get_user?auth=${encodeURIComponent(token)}`);
10931134

10941135
if (!response.ok) throw new Error(`Authentication failed: ${response.status}`);
10951136

10961137
const packet = await response.json();
10971138

1098-
this.userToken = packet.key;
1139+
this.userToken = packet.key || token;
10991140
this.user = { ...packet };
11001141

11011142
delete this.user.key;
@@ -1113,7 +1154,7 @@ class RoturExtension {
11131154
delete this.user["sys.friends"];
11141155
delete this.user["sys.requests"];
11151156

1116-
this.username = this.designation + "-" + args.USERNAME + "§" + randomString(10);
1157+
this.username = this.designation + "-" + this.user.username + "§" + randomString(10);
11171158

11181159
this.ws.send(
11191160
JSON.stringify({
@@ -1135,37 +1176,18 @@ class RoturExtension {
11351176
})
11361177
);
11371178

1138-
return `Logged in as ${args.USERNAME}`;
1179+
return `Logged in as ${this.user.username}`;
11391180

11401181
} catch (error) {
11411182
this.authenticated = false;
1142-
throw new Error(`Failed to login as ${args.USERNAME}: ${error.message}`);
1183+
throw new Error(`Failed to login: ${error.message}`);
11431184
}
11441185
}
11451186

11461187
register(args) {
11471188
if (!this.is_connected) return "Not Connected";
11481189
if (this.authenticated) return "Already Logged In";
1149-
return this.handlePromise({
1150-
cmd: "pmsg",
1151-
val: {
1152-
client: this.my_client,
1153-
command: "new_account",
1154-
id: ":3",
1155-
ip: this.client.ip,
1156-
payload: {
1157-
username: args.USERNAME,
1158-
password: MD5("" + args.PASSWORD),
1159-
}
1160-
},
1161-
id: this.accounts,
1162-
}, (packet, resolve, reject) => {
1163-
if (packet.val?.payload === "Account Created Successfully") {
1164-
resolve(`Registered as ${args.USERNAME}`);
1165-
} else {
1166-
reject(`Failed to register as ${args.USERNAME}: ${packet.val.payload}`);
1167-
}
1168-
});
1190+
return
11691191
}
11701192

11711193
deleteAccount() {
@@ -1197,20 +1219,7 @@ class RoturExtension {
11971219
}
11981220

11991221
logout() {
1200-
if (!this.is_connected) {
1201-
return;
1202-
}
1203-
this.ws.send(
1204-
JSON.stringify({
1205-
cmd: "pmsg",
1206-
val: {
1207-
command: "logout",
1208-
client: this.my_client,
1209-
id: ":3",
1210-
},
1211-
id: this.accounts,
1212-
}),
1213-
);
1222+
if (!this.is_connected) return;
12141223
this.authenticated = false;
12151224
this.userToken = "";
12161225
this.user = {};
@@ -1222,11 +1231,8 @@ class RoturExtension {
12221231
}
12231232

12241233
getkey(args) {
1225-
if (!this.is_connected) {
1226-
return "Not Connected";
1227-
} else if (!this.authenticated) {
1228-
return "Not Logged In";
1229-
}
1234+
if (!this.is_connected) return "Not Connected";
1235+
if (!this.authenticated) return "Not Logged In";
12301236
if (args.KEY in this.user) {
12311237
let keyData = this.user[args.KEY];
12321238
if (typeof keyData === "object") {

0 commit comments

Comments
 (0)