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