account saving

This commit is contained in:
winter 2023-01-06 00:21:43 +09:00
parent 4788c8f65f
commit 7ffe18b334
3 changed files with 65 additions and 8 deletions

View File

@ -6,14 +6,31 @@ CrystalGauntlet.endpoints["/accounts/backupGJAccount.php"] = ->(context : HTTP::
params = URI::Params.parse(context.request.body.not_nil!.gets_to_end)
LOG.debug { params.inspect }
user_id, account_id = Accounts.auth(params)
if !(user_id && account_id)
username = params["userName"]
password = params["password"]
result = DATABASE.query_all("select id, password from accounts where username = ?", username, as: {Int32, String})
if result.size > 0
account_id, hash = result[0]
bcrypt = Crypto::Bcrypt::Password.new(hash)
if bcrypt.verify(password)
folder = DATA_FOLDER / "saves"
params.each do |key, _|
if key.starts_with?("H4s")
File.write(folder / "#{account_id}_levels.sav", key)
end
end
File.write(folder / "#{account_id}.sav", params["saveData"])
return "1"
else
return "-1"
end
else
return "-1"
end
data = params["saveData"].split(';')
"1"
}
CrystalGauntlet.endpoints["/database/accounts/backupGJAccountNew.php"] = CrystalGauntlet.endpoints["/accounts/backupGJAccount.php"]

View File

@ -0,0 +1,11 @@
require "uri"
require "compress/gzip"
include CrystalGauntlet
CrystalGauntlet.endpoints["/getAccountURL.php"] = ->(context : HTTP::Server::Context): String {
params = URI::Params.parse(context.request.body.not_nil!.gets_to_end)
LOG.debug { params.inspect }
"#{config_get("general.hostname").as(String)}/#{config_get("general.append_path").as(String)[0..-2]}"
}

View File

@ -0,0 +1,29 @@
require "uri"
include CrystalGauntlet
CrystalGauntlet.endpoints["/accounts/syncGJAccount.php"] = ->(context : HTTP::Server::Context): String {
params = URI::Params.parse(context.request.body.not_nil!.gets_to_end)
LOG.debug { params.inspect }
username = params["userName"]
password = params["password"]
result = DATABASE.query_all("select id, password from accounts where username = ?", username, as: {Int32, String})
if result.size > 0
account_id, hash = result[0]
bcrypt = Crypto::Bcrypt::Password.new(hash)
if bcrypt.verify(password)
folder = DATA_FOLDER / "saves"
return "#{File.read(folder / "#{account_id}.sav")};#{File.read(folder / "#{account_id}_levels.sav")};21;30;a;a"
else
return "-1"
end
else
return "-1"
end
}
CrystalGauntlet.endpoints["/database/accounts/syncGJAccountNew.php"] = CrystalGauntlet.endpoints["/accounts/syncGJAccount.php"]