|
|
|
@ -1,6 +1,6 @@
|
|
|
|
|
/** |
|
|
|
|
* Command for changing amount of money players have. |
|
|
|
|
* Copyright 2022 Anton Tarasenko |
|
|
|
|
* Copyright 2022-2023 Anton Tarasenko |
|
|
|
|
*------------------------------------------------------------------------------ |
|
|
|
|
* This file is part of Acedia. |
|
|
|
|
* |
|
|
|
@ -21,7 +21,6 @@ class ACommandUserData extends Command;
|
|
|
|
|
|
|
|
|
|
var private array<EPlayer> playerQueue; |
|
|
|
|
|
|
|
|
|
// TODO: Finish this command after JSON parameters are added |
|
|
|
|
protected function BuildData(CommandDataBuilder builder) |
|
|
|
|
{ |
|
|
|
|
builder.Name(P("userdata")).Group(P("admin")) |
|
|
|
@ -33,7 +32,7 @@ protected function BuildData(CommandDataBuilder builder)
|
|
|
|
|
.Describe(F("Reads user data stored for targeted user under group" |
|
|
|
|
@ "{$TextEmphasis `groupName`} and name" |
|
|
|
|
@ "{$TextEmphasis `dataName`}. If {$TextEmphasis `dataName`} is" |
|
|
|
|
@ "omitted, the data inside the whjole group will be read.")); |
|
|
|
|
@ "omitted, the data inside the whole group will be read.")); |
|
|
|
|
builder.SubCommand(P("write")) |
|
|
|
|
.ParamText(P("groupName")) |
|
|
|
|
.ParamText(P("dataName")) |
|
|
|
@ -49,69 +48,79 @@ protected function ExecutedFor(
|
|
|
|
|
EPlayer instigator) |
|
|
|
|
{ |
|
|
|
|
local AcediaObject userData; |
|
|
|
|
local Text groupName, dataName; |
|
|
|
|
|
|
|
|
|
if (arguments.subCommandName.IsEmpty()) |
|
|
|
|
{ |
|
|
|
|
target |
|
|
|
|
.GetIdentity() |
|
|
|
|
.ReadPersistentData( |
|
|
|
|
arguments.parameters.GetText(P("groupName")), |
|
|
|
|
arguments.parameters.GetText(P("dataName"))) |
|
|
|
|
.connect = UserDataRead; |
|
|
|
|
groupName = arguments.parameters.GetText(P("groupName")); |
|
|
|
|
dataName = arguments.parameters.GetText(P("dataName")); |
|
|
|
|
userData = arguments.parameters.GetItem(P("newData")); |
|
|
|
|
if (arguments.subCommandName.IsEmpty()) { |
|
|
|
|
ReadUserData(target, groupName, dataName); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
userData = arguments.parameters.GetHashTable(P("newData")); |
|
|
|
|
target |
|
|
|
|
.GetIdentity() |
|
|
|
|
.WritePersistentData( |
|
|
|
|
arguments.parameters.GetText(P("groupName")), |
|
|
|
|
arguments.parameters.GetText(P("dataName")), |
|
|
|
|
userData); |
|
|
|
|
else { |
|
|
|
|
WriteUserData(target, groupName, dataName, userData); |
|
|
|
|
} |
|
|
|
|
playerQueue[playerQueue.length] = target; |
|
|
|
|
target.NewRef(); |
|
|
|
|
_.memory.Free(dataName); |
|
|
|
|
_.memory.Free(groupName); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private final function UserDataRead( |
|
|
|
|
Database.DBQueryResult result, |
|
|
|
|
AcediaObject userData, |
|
|
|
|
Database source) |
|
|
|
|
private final function ReadUserData( |
|
|
|
|
EPlayer targetPlayer, |
|
|
|
|
BaseText groupName, |
|
|
|
|
BaseText dataName) |
|
|
|
|
{ |
|
|
|
|
local User identity; |
|
|
|
|
local AcediaObject rawData; |
|
|
|
|
local MutableText dataAsJSON; |
|
|
|
|
local Text targetPlayerName; |
|
|
|
|
local EPlayer targetPlayer; |
|
|
|
|
local MutableText asJSON; |
|
|
|
|
|
|
|
|
|
if (playerQueue.length <= 0) |
|
|
|
|
{ |
|
|
|
|
targetPlayer |
|
|
|
|
.BorrowConsole() |
|
|
|
|
.UseColorOnce(_.color.TextFailure) |
|
|
|
|
.Write(P("There was an internal error with `userdata` command. ")) |
|
|
|
|
.Write(P("Please report it!")); |
|
|
|
|
identity = targetPlayer.GetIdentity(); |
|
|
|
|
if (identity == none) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
targetPlayer = playerQueue[0]; |
|
|
|
|
playerQueue.Remove(0, 1); |
|
|
|
|
if (result != DBR_Success) |
|
|
|
|
targetPlayerName = targetPlayer.GetName(); |
|
|
|
|
rawData = identity.GetPersistentData(groupName, dataName); |
|
|
|
|
dataAsJSON = _.json.PrettyPrint(rawData); |
|
|
|
|
targetPlayer.BorrowConsole() |
|
|
|
|
.Write(F("User data for player ")) |
|
|
|
|
.Write(targetPlayerName) |
|
|
|
|
.Write(P(": ")) |
|
|
|
|
.WriteLine(dataAsJSON); |
|
|
|
|
_.memory.Free(dataAsJSON); |
|
|
|
|
_.memory.Free(rawData); |
|
|
|
|
_.memory.Free(targetPlayerName); |
|
|
|
|
_.memory.Free(identity); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private final function WriteUserData( |
|
|
|
|
EPlayer targetPlayer, |
|
|
|
|
BaseText groupName, |
|
|
|
|
BaseText dataName, |
|
|
|
|
AcediaObject rawData) |
|
|
|
|
{ |
|
|
|
|
targetPlayer |
|
|
|
|
.BorrowConsole() |
|
|
|
|
.UseColorOnce(_.color.TextFailure) |
|
|
|
|
.Write(F("There was an error reading user data, error code: ")) |
|
|
|
|
.WriteLine(_.text.FromInt(int(result))); |
|
|
|
|
local User identity; |
|
|
|
|
local Text targetPlayerName; |
|
|
|
|
|
|
|
|
|
identity = targetPlayer.GetIdentity(); |
|
|
|
|
if (identity == none) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
targetPlayerName = targetPlayer.GetName(); |
|
|
|
|
asJSON = _.json.PrettyPrint(userData); |
|
|
|
|
if (identity.SetPersistentData(groupName, dataName, rawData)) |
|
|
|
|
{ |
|
|
|
|
targetPlayer.BorrowConsole() |
|
|
|
|
.Write(F("{$TextPositive User data for player}")) |
|
|
|
|
.Write(P("User data for player ")) |
|
|
|
|
.Write(targetPlayerName) |
|
|
|
|
.Write(P(":")) |
|
|
|
|
.WriteLine(asJSON); |
|
|
|
|
_.memory.Free(targetPlayer); |
|
|
|
|
_.memory.Free(asJSON); |
|
|
|
|
.WriteLine(F(" was {$TextPositive successfully} changed!")); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
targetPlayer.BorrowConsole() |
|
|
|
|
.Write(P("User data for player ")) |
|
|
|
|
.Write(targetPlayerName) |
|
|
|
|
.WriteLine(F(" has {$TextPositive failed} to change!")); |
|
|
|
|
} |
|
|
|
|
_.memory.Free(targetPlayerName); |
|
|
|
|
_.memory.Free(identity); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
defaultproperties |
|
|
|
|