Save accounts as encoded json text, migrate script found in development discord

This commit is contained in:
ElPumpo
2020-03-06 20:41:37 +01:00
parent e31077efbb
commit 3ba2ed150f
5 changed files with 68 additions and 139 deletions
+12 -36
View File
@@ -82,8 +82,18 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
return self.variables[k]
end
self.getAccounts = function()
return self.accounts
self.getAccounts = function(minimal)
if minimal then
local minimalAccounts = {}
for k,v in ipairs(self.accounts) do
minimalAccounts[v.name] = v.money
end
return minimalAccounts
else
return self.accounts
end
end
self.getAccount = function(account)
@@ -151,40 +161,6 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
self.name = newName
end
self.getMissingAccounts = function(cb)
local missingAccounts = {}
for account,label in pairs(Config.Accounts) do
local found = false
for k2,v2 in ipairs(self.accounts) do
if account == v2.name then
found = true
end
end
if not found then
missingAccounts[account] = Config.StartingAccountMoney[account] or 0
end
end
cb(missingAccounts)
end
self.createMissingAccounts = function(missingAccounts, cb)
for name,money in pairs(missingAccounts) do
MySQL.Async.execute('INSERT INTO user_accounts (identifier, name, money) VALUES (@identifier, @name, @money)', {
['@identifier'] = self.identifier,
['@name'] = name,
['@money'] = money
}, function(rowsChanged)
if cb then
cb()
end
end)
end
end
self.setAccountMoney = function(accountName, money)
if money >= 0 then
local account = self.getAccount(accountName)