summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgumi <git@gumi.ca>2020-05-15 12:07:46 -0400
committergumi <git@gumi.ca>2020-05-15 12:43:23 -0400
commit3fb9f748adadbd74fa58a4410ed1082da9424936 (patch)
treeb22f2231c5821d48d35eded1139fbcb02acddad7
parent68ad5ad9782c225cb98c13d66d6e593110ef8a28 (diff)
downloadapi-3fb9f748adadbd74fa58a4410ed1082da9424936.tar.gz
api-3fb9f748adadbd74fa58a4410ed1082da9424936.tar.bz2
api-3fb9f748adadbd74fa58a4410ed1082da9424936.tar.xz
api-3fb9f748adadbd74fa58a4410ed1082da9424936.zip
set legacy variables in ported chars
-rw-r--r--src/routers/vault/index.js2
-rw-r--r--src/routers/vault/middlewares/legacy/account.js70
-rw-r--r--src/routers/vault/models/legacy/char_reg.js27
-rw-r--r--src/routers/vault/types/Char.js2
-rw-r--r--src/routers/vault/types/EvolAccount.js5
-rw-r--r--src/routers/vault/types/GameAccount.js6
-rw-r--r--src/routers/vault/types/LegacyAccount.js5
-rw-r--r--src/routers/vault/types/LegacyChar.js2
-rw-r--r--src/routers/vault/utils/claim.js21
-rw-r--r--src/routers/vault/utils/game_accounts.js22
10 files changed, 147 insertions, 15 deletions
diff --git a/src/routers/vault/index.js b/src/routers/vault/index.js
index c20e2d2..87ab2a7 100644
--- a/src/routers/vault/index.js
+++ b/src/routers/vault/index.js
@@ -19,7 +19,7 @@ const models = {
//"storage",
//"global_acc_reg",
//"acc_reg",
- //"char_reg",
+ "char_reg",
//"party",
],
evol: [
diff --git a/src/routers/vault/middlewares/legacy/account.js b/src/routers/vault/middlewares/legacy/account.js
index 8a541f5..bcf24fa 100644
--- a/src/routers/vault/middlewares/legacy/account.js
+++ b/src/routers/vault/middlewares/legacy/account.js
@@ -6,6 +6,7 @@ const LegacyChar = require("../../types/LegacyChar.js");
const EvolAccount = require("../../types/EvolAccount.js");
const EvolChar = require("../../types/EvolChar.js");
const validate = require("../../utils/validate.js");
+const { Op } = require("sequelize");
const get_accounts = async (req, res, next) => {
let session;
@@ -136,6 +137,27 @@ const claim_by_password = async (req, res, next) => {
char.baseLevel = char_.baseLevel;
char.gender = char_.sex;
+ const char_vars = await req.app.locals.legacy.char_reg.findAll({
+ where: {
+ charId: char_.charId,
+ [Op.or]: [
+ {name: "TUT_var"},
+ {name: "BOSS_POINTS"},
+ ],
+ },
+ limit: 2, // for now we only use these 2 vars ^
+ });
+
+ for (const var_ of char_vars) {
+ if (var_.name === "TUT_var") {
+ char.creationTime = var_.value > 0xFF ? var_.value : 0;
+ } else if (var_.name === "BOSS_POINTS") {
+ char.bossPoints = Math.max(0, var_.value);
+ }
+
+ // in the future maybe here set the vars in a Map<name, value>
+ }
+
account.chars.push(char);
}
@@ -226,11 +248,23 @@ const migrate = async (req, res, next) => {
});
// store the vault account id as a global account var
- await req.app.locals.evol.global_acc_reg_num_db.create({
- accountId: evol_acc.accountId,
- key: "##VAULT", index: 0,
- value: session.vault,
- });
+ await req.app.locals.evol.global_acc_reg_num_db.bulkCreate([
+ {
+ accountId: evol_acc.accountId,
+ key: "##VAULT", index: 0,
+ value: session.vault,
+ },
+ {
+ accountId: evol_acc.accountId,
+ key: "##LEGACY", index: 0,
+ value: legacy.accountId, // the max value uses only 22 bits so we have some room
+ },
+ {
+ accountId: evol_acc.accountId,
+ key: "##LEGACY", index: 1,
+ value: Math.ceil(Date.now() / 1000),
+ },
+ ]);
req.app.locals.vault.migration_log.create({
vaultId: session.vault,
@@ -282,14 +316,24 @@ const migrate = async (req, res, next) => {
continue;
}
- // update the Legacy flags:
- // for now we're only using a single bit but this can be expanded when
- // we need it in the future
- await req.app.locals.evol.char_reg_num_db.create({
- charId: evol_char.charId,
- key: "LEGACY", index: 0,
- value: 0b00000000_00000000_00000000_00000001, // set the Legacy bit
- });
+ // set the legacy variables
+ await req.app.locals.evol.char_reg_num_db.bulkCreate([
+ {
+ charId: evol_char.charId,
+ key: "LEGACY", index: 0,
+ value: char.charId,
+ },
+ {
+ charId: evol_char.charId,
+ key: "LEGACY", index: 1,
+ value: (char.baseLevel & 0xFF) | ((char.bossPoints & 0x7FFFFF) << 8),
+ },
+ {
+ charId: evol_char.charId,
+ key: "LEGACY", index: 2,
+ value: char.creationTime,
+ },
+ ]);
// remove the name reservation
req.app.locals.evol.char_reservation.destroy({
diff --git a/src/routers/vault/models/legacy/char_reg.js b/src/routers/vault/models/legacy/char_reg.js
new file mode 100644
index 0000000..bc79414
--- /dev/null
+++ b/src/routers/vault/models/legacy/char_reg.js
@@ -0,0 +1,27 @@
+const { DataTypes } = require("sequelize"); // from npm registry
+
+module.exports = {
+ fields: {
+ charId: {
+ type: DataTypes.INTEGER.UNSIGNED,
+ primaryKey: true,
+ allowNull: false,
+ },
+ name: {
+ type: DataTypes.STRING,
+ primaryKey: true,
+ allowNull: false,
+ },
+ value: {
+ type: DataTypes.INTEGER,
+ allowNull: false,
+ defaultValue: 0,
+ },
+ },
+ options: {
+ engine: "InnoDB",
+ indexes: [
+ { fields: ["char_id"] },
+ ],
+ }
+};
diff --git a/src/routers/vault/types/Char.js b/src/routers/vault/types/Char.js
index a90b950..98a0f46 100644
--- a/src/routers/vault/types/Char.js
+++ b/src/routers/vault/types/Char.js
@@ -12,6 +12,8 @@ module.exports = class Char {
baseLevel = 1;
/** gender of the char */
gender = "N";
+ /** when the char was created */
+ creationTime = 0;
constructor (acc, id, name) {
this.account = acc;
diff --git a/src/routers/vault/types/EvolAccount.js b/src/routers/vault/types/EvolAccount.js
index 6db03bf..b91924a 100644
--- a/src/routers/vault/types/EvolAccount.js
+++ b/src/routers/vault/types/EvolAccount.js
@@ -1,4 +1,5 @@
const GameAccount = require("./GameAccount.js");
+const EvolChar = require("./EvolChar.js");
/**
* represents an Evol game account
@@ -8,6 +9,10 @@ module.exports = class EvolAccount extends GameAccount {
legacyId = null;
/** reference to the LegacyAccount */
legacyAccount = null;
+ /** evol game characters
+ * @type {EvolChar[]}
+ */
+ chars = [];
/**
* serialize for sending over the network
diff --git a/src/routers/vault/types/GameAccount.js b/src/routers/vault/types/GameAccount.js
index fa94808..87f5336 100644
--- a/src/routers/vault/types/GameAccount.js
+++ b/src/routers/vault/types/GameAccount.js
@@ -1,3 +1,5 @@
+const Char = require("./Char.js");
+
/**
* represents a generic game account
*/
@@ -8,7 +10,9 @@ module.exports = class GameAccount {
userid = "";
/** the email address associated with the account */
email = null;
- /** Char[] */
+ /** game characters
+ * @type {Char[]}
+ */
chars = [];
/** the last time the account logged in */
lastLogin = null;
diff --git a/src/routers/vault/types/LegacyAccount.js b/src/routers/vault/types/LegacyAccount.js
index 747e6df..0e1bc62 100644
--- a/src/routers/vault/types/LegacyAccount.js
+++ b/src/routers/vault/types/LegacyAccount.js
@@ -1,4 +1,5 @@
const GameAccount = require("./GameAccount.js");
+const LegacyChar = require("./LegacyChar.js");
/**
* represents a Legacy game account
@@ -8,6 +9,10 @@ module.exports = class LegacyAccount extends GameAccount {
revoltId = null;
/** reference to the EvolAccount of the target evol account */
revoltAccount = null;
+ /** Legacy game characters
+ * @type {LegacyChar[]}
+ */
+ chars = [];
/**
* serialize for sending over the network
diff --git a/src/routers/vault/types/LegacyChar.js b/src/routers/vault/types/LegacyChar.js
index b893c3f..9fb2ed3 100644
--- a/src/routers/vault/types/LegacyChar.js
+++ b/src/routers/vault/types/LegacyChar.js
@@ -8,6 +8,8 @@ module.exports = class LegacyChar extends Char {
revoltId = null;
/** reference to the EvolChar */
revoltChar = null;
+ /** boss points */
+ bossPoints = 0;
/**
* serialize for sending over the network
diff --git a/src/routers/vault/utils/claim.js b/src/routers/vault/utils/claim.js
index dda9001..12309b2 100644
--- a/src/routers/vault/utils/claim.js
+++ b/src/routers/vault/utils/claim.js
@@ -64,6 +64,27 @@ const claim_accounts = async (req, email, vault_id, session = null) => {
legacy_char.baseLevel = char.baseLevel;
legacy_char.gender = char.sex;
+ const char_vars = await req.app.locals.legacy.char_reg.findAll({
+ where: {
+ charId: char.charId,
+ [Op.or]: [
+ {name: "TUT_var"},
+ {name: "BOSS_POINTS"},
+ ],
+ },
+ limit: 2, // for now we only use these 2 vars ^
+ });
+
+ for (const var_ of char_vars) {
+ if (var_.name === "TUT_var") {
+ legacy_char.creationTime = var_.value > 0xFF ? var_.value : 0;
+ } else if (var_.name === "BOSS_POINTS") {
+ legacy_char.bossPoints = Math.max(0, var_.value);
+ }
+
+ // in the future maybe here set the vars in a Map<name, value>
+ }
+
legacy_account.chars.push(legacy_char);
}
diff --git a/src/routers/vault/utils/game_accounts.js b/src/routers/vault/utils/game_accounts.js
index fb0e5a4..a5df144 100644
--- a/src/routers/vault/utils/game_accounts.js
+++ b/src/routers/vault/utils/game_accounts.js
@@ -2,6 +2,7 @@ const LegacyAccount = require("../types/LegacyAccount.js");
const LegacyChar = require("../types/LegacyChar.js");
const EvolAccount = require("../types/EvolAccount.js");
const EvolChar = require("../types/EvolChar.js");
+const { Op } = require("sequelize");
/**
* fetch the legacy game accounts and cache in the Session
@@ -38,6 +39,27 @@ const get_legacy_accounts = async (req, session) => {
char_.gender = char.sex;
char_.revoltId = char.revoltId;
+ const char_vars = await req.app.locals.legacy.char_reg.findAll({
+ where: {
+ charId: char.charId,
+ [Op.or]: [
+ {name: "TUT_var"},
+ {name: "BOSS_POINTS"},
+ ],
+ },
+ limit: 2, // for now we only use these 2 vars ^
+ });
+
+ for (const var_ of char_vars) {
+ if (var_.name === "TUT_var") {
+ char_.creationTime = var_.value > 0xFF ? var_.value : 0;
+ } else if (var_.name === "BOSS_POINTS") {
+ char_.bossPoints = Math.max(0, var_.value);
+ }
+
+ // in the future maybe here set the vars in a Map<name, value>
+ }
+
account.chars.push(char_);
}