Skip to content

Commit e2ea19d

Browse files
committed
argon support wooo!! also ccrendertexture for better performance
1 parent 66548f3 commit e2ea19d

File tree

17 files changed

+235
-145
lines changed

17 files changed

+235
-145
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ endif()
3535
add_subdirectory($ENV{GEODE_SDK} ${CMAKE_CURRENT_BINARY_DIR}/geode)
3636

3737
CPMAddPackage("gh:FireMario211/dashauth#main")
38-
target_link_libraries(${PROJECT_NAME} DashAuth)
38+
CPMAddPackage("gh:GlobedGD/[email protected]")
39+
target_link_libraries(${PROJECT_NAME} DashAuth argon)
3940

4041
setup_geode_mod(${PROJECT_NAME})

changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# v1.4.7
2+
- Previews now use CCRenderTexture to optimize performance on large amounts of objects. (New setting: Pre-Render Object Capacity & Pre-Render Full View)
3+
- Replaced GDAuth with argon
14
# v1.4.6
25
- Sapphire SDK support
36
# v1.4.5

mod.json

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"geode": "4.4.0",
2+
"geode": "4.5.0",
33
"gd": {
44
"win": "2.2074",
55
"android": "2.2074",
@@ -8,7 +8,7 @@
88
},
99
"id": "firee.object-workshop",
1010
"name": "Object Workshop",
11-
"version": "v1.4.6",
11+
"version": "v1.4.7",
1212
"developer": "Firee",
1313
"description": "Download, upload, or find custom objects made by other creators!",
1414
"resources": {
@@ -49,6 +49,20 @@
4949
"default": 0,
5050
"min": 0,
5151
"max": 50000
52+
},
53+
"prerender-objects": {
54+
"name": "Pre-Render Object Capacity",
55+
"description": "The amount of objects needed before they are \"pre-rendered\" for faster performance. Will cause a stutter upon loading. This <cr>does not</c> count for viewing more information about the object. (0 = Always Enable)",
56+
"type": "int",
57+
"default": 5000,
58+
"min": 0,
59+
"max": 50000
60+
},
61+
"prerender-full": {
62+
"name": "Pre-Render Full View",
63+
"description": "Whether or not to also pre-render when viewing more information about the object. Do note this will disable particles. (When they get added)",
64+
"type": "bool",
65+
"default": false
5266
}
5367
},
5468
"dependentold": [

server/src/cache.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ export class CacheManager {
1212
this.cache.set(key, data, ttl * 1000);
1313
}
1414
static delete(key: string): boolean {
15-
return this.cache.delete(key);
15+
//return this.cache.delete(key);
16+
this.deletePattern(key);
17+
return true;
1618
}
1719
static deletePattern(key: string): void {
1820
this.cache.deleteByPattern(key);

server/src/controllers/objects.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@ oRouter.post('/objects/:id/overwrite',
272272
data,
273273
version: objData.version + 1
274274
}, ReviewStatus.Updated);
275+
CacheManager.deletePattern(`GET:/user/${objData.account_id}`);
276+
CacheManager.deletePattern(`GET:/objects/${objectID}`);
275277
} catch (e) {
276278
console.error(e)
277279
res.status(500).json({error: "Something went wrong when uploading."})
@@ -720,11 +722,13 @@ oRouter.post('/objects/:id/delete',
720722
const accountID = verifyRes.user?.account_id;
721723
try {
722724
if (verifyRes.user && verifyRes.user.role == 3) {
723-
const objExists = await pool.query("SELECT EXISTS (SELECT 1 FROM objects WHERE id = $1)", [objectID])
724-
if (!objExists.rows[0].exists) return res.status(404).json({error: "Object not found."});
725+
const objExists = await pool.query("SELECT account_id FROM objects WHERE id = $1", [objectID])
726+
if (!objExists.rows.length) return res.status(404).json({error: "Object not found."});
727+
CacheManager.deletePattern(`GET:/user/${objExists.rows[0].account_id}`);
725728
} else {
726729
const objExists = await pool.query("SELECT EXISTS (SELECT 1 FROM objects WHERE id = $1 AND account_id = $2)", [objectID, accountID])
727730
if (!objExists.rows[0].exists) return res.status(404).json({error: "Object not found."});
731+
CacheManager.deletePattern(`GET:/user/${accountID}`);
728732
}
729733
await pool.query("DELETE FROM objects WHERE id = $1", [objectID]);
730734
res.status(200).json({ message: "Deleted object!" });
@@ -795,6 +799,7 @@ oRouter.post('/objects/:id/update',
795799
const objExists = await pool.query("SELECT EXISTS (SELECT 1 FROM objects WHERE id = $1 AND account_id = $2)", [objectID, accountID])
796800
if (!objExists.rows[0].exists) return res.status(404).json({error: "Object not found."});
797801
await pool.query(query, [name, description, tags, objectID]);
802+
CacheManager.deletePattern(`GET:/user/${accountID}`);
798803
}
799804
CacheManager.delete(`GET:/objects/${objectID}`);
800805
return res.status(200).json({message: "Updated object!"});
@@ -852,6 +857,7 @@ oRouter.post('/objects/:id/accept',
852857
version: objData.version
853858
}, ReviewStatus.Approved, verifyRes.user.name);
854859
res.status(200).json({ message: "Accepted!" });
860+
CacheManager.deletePattern(`GET:/user/${objData.account_id}`);
855861
} catch (e) {
856862
console.error(e);
857863
res.status(500).json({ error: 'Internal server error' });
@@ -953,6 +959,7 @@ oRouter.post('/objects/:id/feature',
953959
}
954960
CacheManager.delete(`GET:/objects/${objectID}`);
955961
CacheManager.deletePattern(`GET:/objects`);
962+
CacheManager.deletePattern(`GET:/user/${objData.account_id}`);
956963
} catch (e) {
957964
console.error(e);
958965
res.status(500).json({ error: 'Internal server error' });
@@ -1389,7 +1396,7 @@ oRouter.get('/objects',
13891396
body('tags').optional().isString(),
13901397
cacheMiddleware(60, (req) => {
13911398
const category = parseInt(req.query.category as string) || 0;
1392-
return !req.query["no-cache"] || category == 4;
1399+
return !req.query["no-cache"] && category != 4;
13931400
}),
13941401
async (req: Request, res: Response) => {
13951402
const result = validationResult(req);

server/src/controllers/user.ts

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,14 @@ interface DashAuth {
8181
}
8282
};
8383

84+
// {"valid":true,"valid_weak":true,"username":"FireeDev"}
85+
interface Argon {
86+
valid: boolean,
87+
valid_weak: boolean,
88+
cause?: string,
89+
username: string
90+
};
91+
8492
uRouter.post("/user/@me",
8593
body('token').notEmpty().isString().withMessage("Token is required"),
8694
async (req: Request, res: Response) => {
@@ -245,6 +253,10 @@ uRouter.post('/gdauth',
245253
VALUES ($1, $2, $3);`,
246254
[user.account_id, authToken, expiration]
247255
);
256+
if (user.name != data.username) {
257+
console.log("[GDAuth] updated username", data.username)
258+
await pool.query(`UPDATE users SET name = $1 WHERE account_id = $2;`, [data.username, user.account_id]);
259+
}
248260
res.status(200).json({ token: authToken });
249261
}).catch(err => {
250262
console.error(err);
@@ -295,6 +307,84 @@ uRouter.post('/dashauth',
295307
VALUES ($1, $2, $3);`,
296308
[user.account_id, authToken, expiration]
297309
);
310+
if (user.name != data.username) {
311+
console.log("[DashAuth] updated username", data.username)
312+
await pool.query(`UPDATE users SET name = $1 WHERE account_id = $2;`, [data.username, user.account_id]);
313+
}
314+
res.status(200).json({ token: authToken });
315+
}).catch(err => {
316+
console.error(err);
317+
res.status(500).json({ error: "Something went wrong when trying to create a user." })
318+
})
319+
320+
}).catch(e => {
321+
if (e.status != 401) {
322+
console.error(e);
323+
res.status(500).send({error: "Something went wrong when trying to communicate with DashEnd servers."})
324+
} else {
325+
console.log("TOKEN NOT RETRIEVED")
326+
res.status(400).json({error: "Token was not retrieved in time. Try again."});
327+
}
328+
})
329+
}).catch(e => {
330+
console.error(e);
331+
res.sendStatus(500);
332+
});
333+
}
334+
);
335+
336+
uRouter.post('/argon',
337+
body('account_id').notEmpty().isNumeric(),
338+
body('token').notEmpty(),
339+
body('username').notEmpty(),
340+
async (req: Request, res: Response) => {
341+
const result = validationResult(req);
342+
if (!result.isEmpty()) return res.status(400).json({ errors: result.array() })
343+
const token = req.body.token as string;
344+
const usernameCheck = req.body.username as string;
345+
const accountID = parseInt(req.body.account_id as string);
346+
getCache().then(pool => {
347+
axios(`https://argon.globed.dev/v1/validation/check_strong?account_id=${accountID}&username=${encodeURIComponent(usernameCheck)}&authtoken=${encodeURIComponent(token)}`, {
348+
headers: {
349+
'User-Agent': 'ow-server/1.0.0'
350+
}
351+
}).then(async axiosRes => {
352+
const data = axiosRes.data as Argon;
353+
if (!process.env.PRODUCTION) {
354+
console.log("[Argon]", data);
355+
}
356+
if (axiosRes.data == "-1") return res.status(403).json({error: "Invalid token."});
357+
if (data.cause) return res.status(401).json({error: `Invalid token: ${data.cause}`});
358+
if (!data.valid && !data.valid_weak) return res.status(403).json({error: "Invalid token."});
359+
const existingUserResult0 = await pool.query(
360+
`SELECT name, account_id FROM users WHERE account_id = $1;`,
361+
[accountID]
362+
);
363+
if (existingUserResult0.rows.length == 1) {
364+
const user = existingUserResult0.rows[0];
365+
if (user.name != data.username && data.valid) {
366+
await pool.query(`UPDATE users SET name = $1 WHERE account_id = $2;`, [data.username, user.account_id]);
367+
}
368+
} else if (!data.valid) {
369+
return res.status(403).json({error: "Username not valid. Refresh your GD login."});
370+
}
371+
pool.query("INSERT INTO users (auth_method, account_id, name) VALUES ($1, $2, $3) ON CONFLICT (account_id) DO NOTHING RETURNING *;", ["argon", accountID, data.username]).then(async userResult => {
372+
let user = userResult.rows[0];
373+
if (!user) {
374+
const existingUserResult = await pool.query(
375+
`SELECT * FROM users WHERE account_id = $1;`,
376+
[accountID]
377+
);
378+
user = existingUserResult.rows[0];
379+
}
380+
if (!user) return res.status(500).json({ error: "Unable to retrieve or create user." });
381+
const authToken = generateAuthToken(user.account_id);
382+
const expiration = new Date(Date.now() + ((60 * 60 * 1000) * 24) * 14); // 2 weeks
383+
await pool.query(
384+
`INSERT INTO user_tokens (account_id, token, expiration)
385+
VALUES ($1, $2, $3);`,
386+
[user.account_id, authToken, expiration]
387+
);
298388
res.status(200).json({ token: authToken });
299389
}).catch(err => {
300390
console.error(err);

src/config.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#define USER_AGENT "ObjectWorkshop/1.4.2"
77

88
#define DASHAUTH 1
9-
#define GDAUTH 1
9+
#define ARGON 1
1010

1111
#define RESULT_LIMIT 9
1212
#define MAX_ZOOM 10

src/gdauth/authentication.cpp

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/gdauth/authentication.hpp

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)