summaryrefslogtreecommitdiff
path: root/server/frob/storage.ts
diff options
context:
space:
mode:
authorgumi <git@gumi.ca>2020-01-22 14:55:34 -0500
committergumi <git@gumi.ca>2020-01-29 15:52:23 -0500
commit1af05ee74d0b2ec4e132617ab71bedd30fbfe753 (patch)
tree34a2ce860fd50f963bce775ad1881e45fe243675 /server/frob/storage.ts
parent26549ea92723843a8522705dd865986804becc99 (diff)
downloadtools-1af05ee74d0b2ec4e132617ab71bedd30fbfe753.tar.gz
tools-1af05ee74d0b2ec4e132617ab71bedd30fbfe753.tar.bz2
tools-1af05ee74d0b2ec4e132617ab71bedd30fbfe753.tar.xz
tools-1af05ee74d0b2ec4e132617ab71bedd30fbfe753.zip
[frob] add ROCKSDB as export target
much slower than dumping to a .sql file and then importing in mariadb, but whatever
Diffstat (limited to 'server/frob/storage.ts')
-rw-r--r--server/frob/storage.ts29
1 files changed, 26 insertions, 3 deletions
diff --git a/server/frob/storage.ts b/server/frob/storage.ts
index 315d656..04559d6 100644
--- a/server/frob/storage.ts
+++ b/server/frob/storage.ts
@@ -6,10 +6,12 @@ class StorageParser {
private storage_items_line = "[0-9]+,(?<nameid>[0-9]+),(?<amount>[0-9]+),(?<equip>[0-9]+),[0-9]+,[0-9]+,[0-9]+,[0-9]+,[0-9]+,[0-9]+,[0-9]+ ";
private storage_regex: RegExp;
private storage_regex_items: RegExp;
+ private encoder;
constructor () {
this.storage_regex = new RegExp(this.storage_line);
this.storage_regex_items = new RegExp(this.storage_items_line, "g");
+ this.encoder = new TextEncoder();
}
private parseLine (line: string) {
@@ -33,12 +35,14 @@ class StorageParser {
}
groups.items = items;
+
+ Deno.write(Deno.stdout.rid, this.encoder.encode(`\r⌛ processing storage of account ${groups.account_id}... `));
return groups;
}
public async * readDB () {
const decoder = new TextDecoder("utf-8");
- console.info("\nwalking through storage.txt...");
+ console.info("\r \nwalking through storage.txt...");
const file = await Deno.open("world/save/storage.txt");
const buf = new Uint8Array(1024);
let accumulator = "";
@@ -93,7 +97,7 @@ class StorageWriter {
async write (storage: any) {
let line = `${storage.account_id},${storage.storage_amount}\t`;
- for (let item of storage.items) {
+ for (const item of storage.items) {
line += `0,${item.nameid},${item.amount},${item.equip},0,0,0,0,0,0,0 `;
}
@@ -109,14 +113,33 @@ class StorageWriter {
if (dry_run) {
Deno.removeSync("world/save/storage.txt.tmp");
} else {
- console.info("overwriting storage.txt...");
+ console.info("\roverwriting storage.txt... ");
await Deno.rename("world/save/storage.txt", "world/save/storage.txt_pre-frob");
await Deno.rename("world/save/storage.txt.tmp", "world/save/storage.txt");
}
}
}
+class StorageSQL {
+ private sql;
+
+ constructor (sql) {
+ this.sql = sql;
+ }
+
+ async write (acc: any) {
+ for (const item of acc.items) {
+ await this.sql.do("INSERT INTO `storage` ?? values?", [
+ ["account_id", "nameid", "amount"],
+ [acc.account_id, item.nameid, item.amount]
+ ]);
+ }
+ }
+}
+
+
export {
StorageParser,
StorageWriter,
+ StorageSQL,
}