Add systems for local world persistence (#553)

* chore: Change vscode workspace settings to work with omnisharp

* refactor(.NET): Use connection string builder to init sqlite database

* docs(.NET): Add method documentation to most things that matter

* docs(.NET): Add more docs I forgot to commit apparently

* feat: Add PoC world database structure ^& http listener

* fix: Send a response if VRCX isn't initialized rather than hanging

* feat: Initialize world db schema on startup

* feat: Allow worlds to store data in db through logfile

* use existing current location for worldDB

* Add tooltips

* chore: Make it so vscode can format C# files without prettier

* refactor: Add sqlite-net to (eventually) replace sqlite impl

* refactor: Make use of sqlite-net for world database

* docs: Add todo for fixing some random exception

* refactor: Remove now-unused SQLiteWorld

* refactor: Fix DB init query and change table structure again

* refactor: Add WorldDataRequest, add attributes for camelcase json keys

* Support current user location from API in addition to gameLog

* Change current location check for worldDB

* feat: Take store requests in JSON, identify worlds by GUID on store.

* refactor: Remove unused worldId param from connection key generator

* docs: Add more documentation to the methods for the world database

* fix: Hey wait that's not a primary key

* feat: Add a 10MB data cap for worlds shared across all of their rows.

* fix: Don't calculate size of world date twice when inserting

* refactor: Discard the guid variable since we only check for validity

* docs: Add docs/comments for new data cap functionality

* feat: Implement /getbulk API endpoint

* fix: Correct WorldDB init query typo

* fix: Update data entries properly instead of using 'OR REPLACE'

* refactor: Move endpoint processing to separate methods

* refactor: Add another check for error 503, remove old code

* feat: Add debug capability to /vrcx/getbulk

* fix: Correct the usage of getUser in actuallyGetCurrentLocation

* feat: Add store errors, implement external reading, stop 404ing

* docs: Add docs for new world db funcs

* refactor: Change world db server listen port to 22500

* fix: Use getUser correctly, dumb dumb

* fix: This error set shouldn't be here

* feat: Future-proof api endpoints. Add /status endpoint

---------

Co-authored-by: Natsumi <cmcooper123@hotmail.com>
This commit is contained in:
Teacup
2023-05-31 18:34:50 -04:00
committed by GitHub
parent b06cba0669
commit 0101f3474f
17 changed files with 6193 additions and 147 deletions

View File

@@ -2092,6 +2092,47 @@ speechSynthesis.getVoices();
});
});
API.getUserApiCurrentLocation = function () {
return this.currentUser?.presence?.world;
};
// TODO: traveling to world checks
API.actuallyGetCurrentLocation = async function () {
const gameLogLocation = $app.lastLocation.location;
console.log('gameLog Location', gameLogLocation);
const presence = this.currentUser.presence;
let presenceLocation = this.currentUser.$locationTag;
if (presenceLocation === 'traveling') {
console.log("User is traveling, using $travelingToLocation", this.currentUser.$travelingToLocation);
presenceLocation = this.currentUser.$travelingToLocation;
}
console.log('presence Location', presenceLocation);
// We want to use presence if it's valid to avoid extra API calls, but its prone to being outdated when this function is called.
// So we check if the presence location is the same as the gameLog location; If it is, the presence is (probably) valid and we can use it.
// If it's not, we need to get the user manually to get the correct location.
// If the user happens to be offline or the api is just being dumb, we assume that the user logged into VRCX is different than the one in-game and return the gameLog location.
// This is really dumb.
if (presenceLocation === gameLogLocation) {
console.log('ok presence return');
return presence.world;
}
let args = await this.getUser({ userId: this.currentUser.id });
let user = args.json
console.log('presence bad, got user', user);
if (!$app.isRealInstance(user.location)) {
console.warn(
'presence invalid, user offline and/or instance invalid. returning gamelog location: ',
gameLogLocation
);
return gameLogLocation;
}
console.warn('presence outdated, got user api location instead: ', user.location);
return this.parseLocation(user.location).worldId;
};
API.applyWorld = function (json) {
var ref = this.cachedWorlds.get(json.id);
if (typeof ref === 'undefined') {