From 0aa607642d2e3e0c5bef8a0b713fd93eda54f6b1 Mon Sep 17 00:00:00 2001 From: Abwasserrohr <44294954+Abwasserrohr@users.noreply.github.com> Date: Mon, 20 May 2019 12:50:11 +0200 Subject: [PATCH 01/32] Added custom json operations function These new functions allow the server operator to broadcast custom json transactions with an easy to use function: ```customJsonOperation("random uuid","steem wallet name","someIdentifier","{""test"":""hello""}")``` --- .../core/functions/customJsonOperation.sk | 146 ++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 STEEM.CRAFT/core/functions/customJsonOperation.sk diff --git a/STEEM.CRAFT/core/functions/customJsonOperation.sk b/STEEM.CRAFT/core/functions/customJsonOperation.sk new file mode 100644 index 0000000..1ce5841 --- /dev/null +++ b/STEEM.CRAFT/core/functions/customJsonOperation.sk @@ -0,0 +1,146 @@ +# +# ============== +# customJsonOperation.sk +# ============== +# customJsonOperation.sk is part of the STEEM.CRAFT core functions. +# ============== + +import: + java.util.ArrayList + java.util.HashMap + org.apache.commons.lang3.tuple.ImmutablePair + eu.bittrade.libs.steemj.SteemJ + eu.bittrade.libs.steemj.enums.ValidationType + eu.bittrade.libs.steemj.enums.PrivateKeyType + eu.bittrade.libs.steemj.configuration.SteemJConfig + eu.bittrade.libs.steemj.base.models.operations.CustomJsonOperation + eu.bittrade.libs.steemj.base.models.SignedTransaction + eu.bittrade.libs.steemj.base.models.AccountName + +# +# > Function - customJsonOperation +# > Broadcasts a custom json operation. +# > Parameters: +# > random transaction uuid +# > the steem account who should broadcast the transaction +# > the custom json identifier +# > the json itself as string +function customJsonOperation(txuuid:text,account:text,id:text,json:text): + # + # > To allow other scripts to know if there has been an error or not, + # > they can wait until this transaction uuid has been processed. + set metadata value "steem-tx-response-%{_txuuid}%" of getDummy() to "wait" + # + # > Only prepare one json transaction at a time. + while {steemsk::txjson} is set: + wait 1 tick + # + # > Create a HashMap to pass the data using one single variable. + set {steemsk::txjson} to new HashMap() + {steemsk::txjson}.put("txuuid",{_txuuid}) + {steemsk::txjson}.put("account",{_account}) + {steemsk::txjson}.put("id",{_id}) + {steemsk::txjson}.put("json",{_json}) + # + # > Run the actual custoom json transaction using a thread + # > to prevent the game from lagging. + $ thread + # + # > Since we're on a new thread, local variables are no longer availabe + # > here. This means that we can currently only use global variables. + asyncCustomJsonOperation({steemsk::txjson}) + +# +# > Function - asyncCustomJsonOperation +# > Broadcasts a custom json operation. Should only be used by the +# > customJsonOperation function. +# > Parameters: +# > A HashMap with the keys and values for (text)txuuid, (text)account, (text)id and (text)json is required. +function asyncCustomJsonOperation(tx:object): + # + # > Once this function has been called, delete the variable which + # > has been used to pass the data into this function. + delete {steemsk::txjson} + # + # > Get the data out of the HashMap, which has been passed into + # > the function. A HashMap is used, since lists are slower to delete. + set {_txuuid} to {_tx}.get("txuuid") + set {_account} to {_tx}.get("account") + set {_id} to {_tx}.get("id") + set {_json} to {_tx}.get("json") + + # + # > To process Steem transactions, SteemJ is used here. + set {_steemj} to new SteemJ() + + # + # > Custom json operations require at least a private posting key. + # > Since higher authentifications aren't needed here, use posting. + set {_postingauth} to new ArrayList() + # + # > AccountNames are not simply a string but have the type AccountName. + set {_account} to new AccountName({_account}) + # + # > The AccountName has to be passed within an ArrayList, since there could + # > be more required private posting keys for this transactions. This is not + # > necessary for most STEEM.CRAFT uses. + {_postingauth}.add({_account}) + + # + # > To get SteemJ fully working, the vadilation and maximum + # > expiration date has to be changed. For this, a instance + # > of the SteemJ configuration is necessary. + set {_config} to SteemJConfig.getInstance() + {_config}.setValidationLevel(ValidationType.SKIP_VALIDATION!) + {_config}.setMaximumExpirationDateOffset(400000) + + # + # > Every transaction on Steem needs a private key to broadcast. + # > Since our transactions requires a private posting key, we + # > have to add the private key for the account. Because the + # > player should authorize the server wallet, it is not needed + # > to store any private key of a user, but only the private + # > posting key of the server wallet. In case of a hack or + # > a leak, just the server operator has to change his key. + set {_privatekeys} to new ArrayList() + {_privatekeys}.add(new ImmutablePair(PrivateKeyType.POSTING!, getPrivatePostingKey())) + {_config}.getPrivateKeyStorage().addAccount({_account},{_privatekeys}) + delete {_privatekeys} + + # + # > CustomJsonOperation creates a ready to sign transaction out of the data + # > we have. + set {_customjson} to new CustomJsonOperation(null, {_postingauth}, {_id}, {_json}) + + # + # > Each transaction could hold multiple transactions. While this could be + # > useful, only one type of the same operation is allowed per user/block. + set {_operations} to new ArrayList() + {_operations}.add({_customjson}) + + set {_HeadBlockId} to {_steemj}.getDynamicGlobalProperties().getHeadBlockId() + + set {_signedTx} to new SignedTransaction({_HeadBlockId}, {_operations}, null) + + {_signedTx}.sign() + + # + # > It would be useful to have BroadcastTransactionSynchronousReturn to know + # > the block- and transactionid. But currently, it is not working, since + # > SteemJ is trying to check for duplicate transactions. While this is good, + # > many Steem nodes don't allow querying transaction ids, which results in a + # > error for BroadcastTransactionSynchronousReturn. + try {_steemj}.broadcastTransaction({_signedTx}) + + # + # > To know if there has any error occured while broadcasting the transaction, + # > the "last java errror" would have been set with it. This allows the addons + # > to check for errors. If the response is "done", no error has been reported. + if last java error is set: + set metadata value "steem-tx-response-%{_txuuid}%" of getDummy() to last java error + else: + set metadata value "steem-tx-response-%{_txuuid}%" of getDummy() to "done" + # + # > To prevent holding the data forever, response data is deleted after 5 seconds. + wait 5 seconds + delete metadata value "steem-tx-response-%{_txuuid}%" of getDummy() From 9b9436f56ebdd2783272e5ed693b2833fae1009c Mon Sep 17 00:00:00 2001 From: Abwasserrohr <44294954+Abwasserrohr@users.noreply.github.com> Date: Mon, 20 May 2019 12:59:16 +0200 Subject: [PATCH 02/32] Changed a comment. The CustomJsonOperation returns a operation, not a transaction. --- STEEM.CRAFT/core/functions/customJsonOperation.sk | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/STEEM.CRAFT/core/functions/customJsonOperation.sk b/STEEM.CRAFT/core/functions/customJsonOperation.sk index 1ce5841..781e383 100644 --- a/STEEM.CRAFT/core/functions/customJsonOperation.sk +++ b/STEEM.CRAFT/core/functions/customJsonOperation.sk @@ -108,8 +108,7 @@ function asyncCustomJsonOperation(tx:object): delete {_privatekeys} # - # > CustomJsonOperation creates a ready to sign transaction out of the data - # > we have. + # > CustomJsonOperation creates a operation which can be added to a transaction. set {_customjson} to new CustomJsonOperation(null, {_postingauth}, {_id}, {_json}) # From dfafdf1672524cf9f7f8cb38f3451f6c97c55f4f Mon Sep 17 00:00:00 2001 From: Abwasserrohr <44294954+Abwasserrohr@users.noreply.github.com> Date: Mon, 20 May 2019 13:04:41 +0200 Subject: [PATCH 03/32] Added getAccountHistory This function allows the server operator to get the account histsory of a steem wallet name. While it is easy to get the account history without this function, users would have to import some classes from SteemJ, which I want to prevent to not confuse people. --- .../core/functions/getAccountHistory.sk | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 STEEM.CRAFT/core/functions/getAccountHistory.sk diff --git a/STEEM.CRAFT/core/functions/getAccountHistory.sk b/STEEM.CRAFT/core/functions/getAccountHistory.sk new file mode 100644 index 0000000..96c9ecf --- /dev/null +++ b/STEEM.CRAFT/core/functions/getAccountHistory.sk @@ -0,0 +1,22 @@ +# +# ============== +# getAccountHistory.sk +# ============== +# getAccountHistory.sk is part of the STEEM.CRAFT core functions. +# ============== + +import: + eu.bittrade.libs.steemj.SteemJ + eu.bittrade.libs.steemj.base.models.AccountName + +# +# > Function - getAccountHistory +# > Returns the account history +# > Parameters: +# > a steem wallet name +# > where should the query start +# > limit the returned history +function getAccountHistory(account:text,start:int,limit:int) :: object: + set {_steemj} to new SteemJ() + set {_account} to new AccountName({_account}) + return {_steemj}.getAccountHistory({_account},{_start},{_limit}) From 83aa0fac0ec75d5c997676f15efecbde6310dbf6 Mon Sep 17 00:00:00 2001 From: Abwasserrohr <44294954+Abwasserrohr@users.noreply.github.com> Date: Mon, 20 May 2019 13:18:34 +0200 Subject: [PATCH 04/32] Added default tags for comments --- STEEM.CRAFT/config.sk | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/STEEM.CRAFT/config.sk b/STEEM.CRAFT/config.sk index 5ee35c7..c47b8ab 100644 --- a/STEEM.CRAFT/config.sk +++ b/STEEM.CRAFT/config.sk @@ -14,6 +14,7 @@ options: privatepostingkey: "" serveraccountname: "" appname: "STEEM.CRAFT/0.1" + defaultAppTags: ["steemcraft"] DefaultBeneficiaryAccount: "skyroad" DefaultBeneficiaryWeight: 250 @@ -42,6 +43,14 @@ function getServerAccountName() :: text: function getAppName() :: text: return {@appname} +# +# > Function - getDefaultAppTags +# > Actions: +# > Returns the default app tags which should be used if +# > no other app tag is defined. +function getDefaultAppTags() :: object: + return {@defaultAppTags} + # # > Function - getDefaultBeneficiaryAccount # > Actions: From c2d7cedc69191a3329674c891342ff332c9373e7 Mon Sep 17 00:00:00 2001 From: Abwasserrohr <44294954+Abwasserrohr@users.noreply.github.com> Date: Mon, 20 May 2019 14:38:59 +0200 Subject: [PATCH 05/32] Added createComment function The createComment function allows server operators to broadcast comments for players directly from the server using a easy to use function: ```createComment("exampleuuid","exampleuser","hello world body","parentauthor","parentpermlink")``` It could hold more data but this is not necessary to start broadcasting and testing things out. --- STEEM.CRAFT/core/functions/createComment.sk | 257 ++++++++++++++++++++ 1 file changed, 257 insertions(+) create mode 100644 STEEM.CRAFT/core/functions/createComment.sk diff --git a/STEEM.CRAFT/core/functions/createComment.sk b/STEEM.CRAFT/core/functions/createComment.sk new file mode 100644 index 0000000..14c0366 --- /dev/null +++ b/STEEM.CRAFT/core/functions/createComment.sk @@ -0,0 +1,257 @@ +# +# ============== +# createComment.sk +# ============== +# createComment.sk is part of the STEEM.CRAFT core functions. +# ============== + +import: + java.util.ArrayList + java.util.HashMap + org.apache.commons.lang3.tuple.ImmutablePair + eu.bittrade.libs.steemj.SteemJ + eu.bittrade.libs.steemj.enums.PrivateKeyType + eu.bittrade.libs.steemj.enums.AssetSymbolType + eu.bittrade.libs.steemj.configuration.SteemJConfig + eu.bittrade.libs.steemj.base.models.SignedTransaction + eu.bittrade.libs.steemj.base.models.AccountName + eu.bittrade.libs.steemj.base.models.operations.CommentOperation + eu.bittrade.libs.steemj.base.models.BeneficiaryRouteType + eu.bittrade.libs.steemj.base.models.operations.CommentOptionsOperation + eu.bittrade.libs.steemj.base.models.CommentOptionsExtension + eu.bittrade.libs.steemj.base.models.CommentPayoutBeneficiaries + eu.bittrade.libs.steemj.base.models.Asset + eu.bittrade.libs.steemj.base.models.Permlink + eu.bittrade.libs.steemj.util.CondenserUtils + +# +# > Function - createComment: +# > Creates a comment for the player. +# > Parameters: +# > random uuid to identify the transaction and get a response +# > the account which should broadcast the transaction +# > the body of the comment +# > the parent author of the comment +# > the parent permlink of the comment +# > []the title of the comment +# > []the tags of the comment +# > []custom json metadata of the comment +# > []percent Steem Dollar (10000 is 50% SBD) +# > []beneficary account +# > []beneficary weight +function createComment(txuuid:text,account:text,body:text,parentauthor:text,parentpermlink:text,title:text="-",tags:object=null,customjson:text="none",percentSteemDollars:int=10000,BeneficiaryAccount:text="",BeneficiaryWeight:number=101): + # + # > Allow addons to know if a transaction has been processed or not. + set metadata value "steem-tx-response-%{_txuuid}%" of getDummy() to "wait" + # + # > Only process the creation of one comment at a time. + while {steemsk::txcomment} is set: + wait 1 tick + # + # > All the important variables are passed into the asyncCreateComment + # > using a HashMap to make the function easier to view. + set {_tx} to new HashMap() + {_tx}.put("account",{_account}) + {_tx}.put("txuuid","%{_txuuid}%") + {_tx}.put("body",{_body}) + {_tx}.put("parentauthor",{_parentauthor}) + {_tx}.put("customjson",{_customjson}) + {_tx}.put("percentSteemDollars",{_percentSteemDollars}) + {_tx}.put("parentpermlink",{_parentpermlink}) + {_tx}.put("title",{_title}) + {_tx}.put("tags",{_tags}) + {_tx}.put("BeneficiaryAccount",{_BeneficiaryAccount}) + {_tx}.put("BeneficiaryWeight",{_BeneficiaryWeight}) + set {steemsk::txcomment} to {_tx} + # + # > Run the creation of the comment in a separate thread. + $ thread + # + # > Once the function is called within a thread, it can't access + # > to local variables, this is why a global variable is used. + asyncCreateComment({steemsk::txcomment}) + + +# +# > Function - asyncCreateComment: +# > Broadcasts a comment, should only be used by the createComment function. +# > Parameters: +# > a HashMap with all necessary values for a comment. See above. +function asyncCreateComment(tx:object): + # + # > Once this function has been called, delete the global + # > variable which has been used to pass the data into this + # > threaded function. + delete {steemsk::txcomment} + + # + # > Get all the data needed out of the HashMap, this looks better + # > than one big line in the function. + set {_account} to {_tx}.get("account") + set {_txuuid} to {_tx}.get("txuuid") + set {_body} to {_tx}.get("body") + set {_parentauthor} to {_tx}.get("parentauthor") + set {_customjson} to {_tx}.get("customjson") + set {_percentSteemDollars} to {_tx}.get("percentSteemDollars") + set {_parentpermlink} to {_tx}.get("parentpermlink") + set {_title} to {_tx}.get("title") + set {_tags} to {_tx}.get("tags") + set {_BeneficiaryAccount} to {_tx}.get("BeneficiaryAccount") + set {_BeneficiaryWeight} to {_tx}.get("BeneficiaryWeight") + + # + # > To prepare and broadcast comments, SteemJ is needed. + set {_steemj} to new SteemJ() + + # + # > Server operators can customize the beneficary account + # > and weight for the comments, this is why the configuration + # > instance is needed. + set {_config} to SteemJConfig.getInstance() + if {_BeneficiaryAccount} is "": + set {_BeneficiaryAccount} to getDefaultBeneficiaryAccount() + if {_BeneficiaryWeight} > 100: + set {_BeneficiaryWeight} to getDefaultBeneficiaryWeight() + + # + # > Also, the maximum date offset has to be changed to work. + {_config}.setMaximumExpirationDateOffset(400000) + + # + # > The beneficary account and weight which have been used above are set here. + {_config}.setBeneficiaryAccount(new AccountName({_BeneficiaryAccount})) + {_config}.setSteemJWeight({_BeneficiaryWeight}) + + # + # > Transactions could hold multiple operations, this is why a ArrayList is + # > needed in which our comment operation is added. + set {_operations} to new ArrayList() + + # + # > If there aren't any tags set, use the default app tags from config.sk. + if {_tags} is null: + set {_tags} to getDefaultAppTags() + + # + # > The permlink is created here. It is currently always build like this: + # > "re-parentAuthor-randomuuid". + set {_replyto} to {_parentauthor} + + # + # > Since permlinks do not support points ".", they're replaced with nothing. + replace all "." with "" in {_replyto} + + # + # > Then, the permlink string is set. + set {_permlinkstring} to "re-%{_replyto}%-%{_txuuid}%" + + # + # > The new permlink string is set to a Permlink. + set {_permlink} to new Permlink({_permlinkstring}) + + # + # > If no custom json is set, generate it using the CondenserUtils from SteemJ. + # > Additional metadata could be posted using the {_extraMetadata} HashMap. + set {_extraMetadata} to new HashMap() + if {_customjson} is "none": + set {_jsonMetadata} to CondenserUtils.generateSteemitMetadata({_body}, {_tags},getAppName(), "markdown", {_extraMetadata}) + else: + set {_jsonMetadata} to {_customjson} + + # + # > Set the parent author and the author of this commennt to a + # > valid AccountName. + set {_account} to new AccountName({_account}) + set {_parent} to new AccountName({_parentauthor}) + + # + # > Set the private key of the server wallet to the account which should + # > broadcast the transaction. + set {_privatekeys} to new ArrayList() + {_privatekeys}.add(new ImmutablePair(PrivateKeyType.POSTING!, getPrivatePostingKey())) + {_config}.getPrivateKeyStorage().addAccount({_account},{_privatekeys}) + delete {_privatekeys} + + # + # > The parent permlink has to be a permlink too. + set {_parentPermlink_permlink} to new Permlink({_parentpermlink}) + + # + # > The comment operation is created through SteemJ and added to the operations. + set {_commentOperation} to new CommentOperation({_parent},{_parentPermlink_permlink},{_account},{_permlink}," ",{_body},{_jsonMetadata}) + {_operations}.add({_commentOperation}) + + # + # > Currently, votes and curation rewards are enabled by default. + set {_allowVotes} to true + set {_allowCurationRewards} to true + # + # > The maximum accepted payout can be changed to limit the payout value. + # > This can prevent abuse by votebots. It is currently not limited since + # > there is no such abusive behaviour currently for STEEM.CRAFT. + set {_maxAcceptedPayout} to new Asset(1000000000, AssetSymbolType.SBD!) + + # + # > If the beneficary for this is above 0, add beneficaries. + if {_config}.getSteemJWeight() > 0: + # + # > Each comment could have mutliple beneficary route types. + # > Currently, only one beneficary is used. + set {_beneficiaryRouteType} to new BeneficiaryRouteType({_config}.getBeneficiaryAccount(),{_config}.getSteemJWeight()) + + # + # > Since there could be multiple beneficaries, we need a ArrayList. + set {_beneficiaryRouteTypes} to new ArrayList() + + # + # > Our beneficary route is now added to the ArrayList. + {_beneficiaryRouteTypes}.add({_beneficiaryRouteType}) + + # + # > The beneficary routes now have to be set to the CommentPayoutBeneficiaries. + set {_commentPayoutBeneficiaries} to new CommentPayoutBeneficiaries() + {_commentPayoutBeneficiaries}.setBeneficiaries({_beneficiaryRouteTypes}) + + # + # > The beneficaries are a part of the comment option extensions, which are a + # > handled as a ArrayList. + set {_commentOptionsExtensions} to new ArrayList() + {_commentOptionsExtensions}.add({_commentPayoutBeneficiaries}) + + # + # > The commentoptionsoperation will create or update a comment. + set {_commentOptionsOperation} to new CommentOptionsOperation({_account}, {_permlink},{_maxAcceptedPayout}, {_percentSteemDollars}, {_allowVotes}, {_allowCurationRewards},{_commentOptionsExtensions}) + else: + set {_commentOptionsOperation} to new CommentOptionsOperation({_account}, {_permlink},{_maxAcceptedPayout}, {_percentSteemDollars}, {_allowVotes}, {_allowCurationRewards}, null) + + # + # > Multiple operations could be added to one transaction. This is why + # > we have to add our operation to a ArrayList. + {_operations}.add({_commentOptionsOperation}) + + # + # > The head block id is needed to sign the transaction. + set {_HeadBlockId} to {_steemj}.getDynamicGlobalProperties().getHeadBlockId() + + set {_signedTx} to new SignedTransaction({_HeadBlockId},{_operations},null) + + {_signedTx}.sign() + + # + # > Broadcasting a transaction could result in a error. + # > To prevent this from being logged into the console, + # > it has the prefix "try". + try {_steemj}.broadcastTransaction({_signedTx}) + + # + # > If there has been a error in the last broadcast transaction, + # > set the error to the response metadata to allow addons to + # > send human readable errors. + if last java error is set: + set metadata value "steem-tx-response-%{_txuuid}%" of getDummy() to last java errorlast java error + else: + set metadata value "steem-tx-response-%{_txuuid}%" of getDummy() to "done" + # + # > To prevent the responde from being stored forever, delete it after 5 seconds. + wait 5 seconds + delete metadata value "steem-tx-response-%{_txuuid}%" of getDummy() From d0c6532de435733be318a6a3a77699592569e658 Mon Sep 17 00:00:00 2001 From: Abwasserrohr <44294954+Abwasserrohr@users.noreply.github.com> Date: Mon, 20 May 2019 14:40:38 +0200 Subject: [PATCH 06/32] Fixed a mistake --- STEEM.CRAFT/core/functions/createComment.sk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/STEEM.CRAFT/core/functions/createComment.sk b/STEEM.CRAFT/core/functions/createComment.sk index 14c0366..a75fa66 100644 --- a/STEEM.CRAFT/core/functions/createComment.sk +++ b/STEEM.CRAFT/core/functions/createComment.sk @@ -248,7 +248,7 @@ function asyncCreateComment(tx:object): # > set the error to the response metadata to allow addons to # > send human readable errors. if last java error is set: - set metadata value "steem-tx-response-%{_txuuid}%" of getDummy() to last java errorlast java error + set metadata value "steem-tx-response-%{_txuuid}%" of getDummy() to last java error else: set metadata value "steem-tx-response-%{_txuuid}%" of getDummy() to "done" # From 2e2d11b3aa999a6221d712ecabc655fa2dbf007d Mon Sep 17 00:00:00 2001 From: Abwasserrohr <44294954+Abwasserrohr@users.noreply.github.com> Date: Mon, 20 May 2019 15:52:45 +0200 Subject: [PATCH 07/32] objects can't be just null within the function definition in Skript --- STEEM.CRAFT/core/functions/createComment.sk | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/STEEM.CRAFT/core/functions/createComment.sk b/STEEM.CRAFT/core/functions/createComment.sk index a75fa66..ee8cdfe 100644 --- a/STEEM.CRAFT/core/functions/createComment.sk +++ b/STEEM.CRAFT/core/functions/createComment.sk @@ -33,13 +33,13 @@ import: # > the body of the comment # > the parent author of the comment # > the parent permlink of the comment +# > the tags of the comment # > []the title of the comment -# > []the tags of the comment # > []custom json metadata of the comment # > []percent Steem Dollar (10000 is 50% SBD) # > []beneficary account # > []beneficary weight -function createComment(txuuid:text,account:text,body:text,parentauthor:text,parentpermlink:text,title:text="-",tags:object=null,customjson:text="none",percentSteemDollars:int=10000,BeneficiaryAccount:text="",BeneficiaryWeight:number=101): +function createComment(txuuid:text,account:text,body:text,parentauthor:text,parentpermlink:text,tags:object,title:text="-",customjson:text="none",percentSteemDollars:int=10000,BeneficiaryAccount:text="",BeneficiaryWeight:number=101): # # > Allow addons to know if a transaction has been processed or not. set metadata value "steem-tx-response-%{_txuuid}%" of getDummy() to "wait" @@ -63,6 +63,7 @@ function createComment(txuuid:text,account:text,body:text,parentauthor:text,pare {_tx}.put("BeneficiaryAccount",{_BeneficiaryAccount}) {_tx}.put("BeneficiaryWeight",{_BeneficiaryWeight}) set {steemsk::txcomment} to {_tx} + # # > Run the creation of the comment in a separate thread. $ thread @@ -129,7 +130,7 @@ function asyncCreateComment(tx:object): # # > If there aren't any tags set, use the default app tags from config.sk. - if {_tags} is null: + if {_tags} is [""]: set {_tags} to getDefaultAppTags() # From 4b5e781175da6f0b95a2afc36caf52f2a28c2097 Mon Sep 17 00:00:00 2001 From: Abwasserrohr <44294954+Abwasserrohr@users.noreply.github.com> Date: Mon, 20 May 2019 16:08:06 +0200 Subject: [PATCH 08/32] Added getSteemContent getSteemContent allows the server operator to get the content for a author and a permlink. --- STEEM.CRAFT/core/functions/getSteemContent.sk | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 STEEM.CRAFT/core/functions/getSteemContent.sk diff --git a/STEEM.CRAFT/core/functions/getSteemContent.sk b/STEEM.CRAFT/core/functions/getSteemContent.sk new file mode 100644 index 0000000..c255527 --- /dev/null +++ b/STEEM.CRAFT/core/functions/getSteemContent.sk @@ -0,0 +1,16 @@ +# +# ============== +# getSteemContent.sk +# ============== +# getSteemContent.sk is part of the STEEM.CRAFT core functions. +# ============== + +# +# > Function - getSteemContent: +# > Returns the content of the specified author and permlink. +# > Parameters: +# > author +# > permlink +function getSteemContent(author:text,permlink:text) :: object: + set {_steemj} to new SteemJ() + return {_steemj}.getContent(new AccountName({_author}),new Permlink({_permlink})) From 8fb6cc6b6288980770605f04dce6ad705ebac62c Mon Sep 17 00:00:00 2001 From: Abwasserrohr <44294954+Abwasserrohr@users.noreply.github.com> Date: Mon, 20 May 2019 16:10:13 +0200 Subject: [PATCH 09/32] Importing SteemJ is necessary... --- STEEM.CRAFT/core/functions/getSteemContent.sk | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/STEEM.CRAFT/core/functions/getSteemContent.sk b/STEEM.CRAFT/core/functions/getSteemContent.sk index c255527..7a39475 100644 --- a/STEEM.CRAFT/core/functions/getSteemContent.sk +++ b/STEEM.CRAFT/core/functions/getSteemContent.sk @@ -5,6 +5,11 @@ # getSteemContent.sk is part of the STEEM.CRAFT core functions. # ============== +import: + eu.bittrade.libs.steemj.SteemJ + eu.bittrade.libs.steemj.base.models.AccountName + eu.bittrade.libs.steemj.base.models.Permlink + # # > Function - getSteemContent: # > Returns the content of the specified author and permlink. From b3a464e151285e98bfb629f7b1556c705765d668 Mon Sep 17 00:00:00 2001 From: Abwasserrohr <44294954+Abwasserrohr@users.noreply.github.com> Date: Mon, 20 May 2019 16:13:53 +0200 Subject: [PATCH 10/32] Added getDummy function This function allows to create a dummy block for bukkits metadata storage, which is easily usable temporary storage for Skript. --- STEEM.CRAFT/_lib/getDummy.sk | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 STEEM.CRAFT/_lib/getDummy.sk diff --git a/STEEM.CRAFT/_lib/getDummy.sk b/STEEM.CRAFT/_lib/getDummy.sk new file mode 100644 index 0000000..7604692 --- /dev/null +++ b/STEEM.CRAFT/_lib/getDummy.sk @@ -0,0 +1,17 @@ +# +# ============== +# getDummy.sk +# ============== +# getDummy.sk is part of the STEEM.CRAFT library. +# ============== + +# +# > Function - getDummy +# > Actions: +# > Returns a block as a dummy for metadata storage. +function getDummy() :: block: + if {dummyblock} is not a block: + add all worlds to {_worlds::*} + set {_dummy} to {_worlds::1} + set {dummyblock} to block at location at 0.0, 0.0, 0.0 in {_worlds::1} + return {dummyblock} From 8ac70b70ff1f25f2161bbf92c9551a99df0568db Mon Sep 17 00:00:00 2001 From: Abwasserrohr <44294954+Abwasserrohr@users.noreply.github.com> Date: Mon, 20 May 2019 16:15:07 +0200 Subject: [PATCH 11/32] Removed not needed line --- STEEM.CRAFT/_lib/getDummy.sk | 1 - 1 file changed, 1 deletion(-) diff --git a/STEEM.CRAFT/_lib/getDummy.sk b/STEEM.CRAFT/_lib/getDummy.sk index 7604692..ecca46b 100644 --- a/STEEM.CRAFT/_lib/getDummy.sk +++ b/STEEM.CRAFT/_lib/getDummy.sk @@ -12,6 +12,5 @@ function getDummy() :: block: if {dummyblock} is not a block: add all worlds to {_worlds::*} - set {_dummy} to {_worlds::1} set {dummyblock} to block at location at 0.0, 0.0, 0.0 in {_worlds::1} return {dummyblock} From d7ff857163aa82d88784aec3f661c1192fff980d Mon Sep 17 00:00:00 2001 From: Abwasserrohr <44294954+Abwasserrohr@users.noreply.github.com> Date: Mon, 20 May 2019 16:27:21 +0200 Subject: [PATCH 12/32] Added getRandomUUID function The getRandomUUID function returns a ready to use uuid for Skript. This makes it easier for addons, since less work with importing has to be done. --- STEEM.CRAFT/_lib/getRandomUUID.sk | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 STEEM.CRAFT/_lib/getRandomUUID.sk diff --git a/STEEM.CRAFT/_lib/getRandomUUID.sk b/STEEM.CRAFT/_lib/getRandomUUID.sk new file mode 100644 index 0000000..282e9e0 --- /dev/null +++ b/STEEM.CRAFT/_lib/getRandomUUID.sk @@ -0,0 +1,16 @@ +# +# ============== +# getRandomUUID.sk +# ============== +# getRandomUUID.sk is part of the STEEM.CRAFT library. +# ============== + +import: + java.util.UUID + +# +# > Function - getRandomUUID +# > Actions: +# > Returns a random UUID as text. +function getRandomUUID() :: text: + return "%UUID.randomUUID()%" From e528198db6ceb77a5e3ea2313efa72852c670bfc Mon Sep 17 00:00:00 2001 From: Abwasserrohr <44294954+Abwasserrohr@users.noreply.github.com> Date: Mon, 20 May 2019 16:27:52 +0200 Subject: [PATCH 13/32] Changed comment --- STEEM.CRAFT/_lib/getRandomUUID.sk | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/STEEM.CRAFT/_lib/getRandomUUID.sk b/STEEM.CRAFT/_lib/getRandomUUID.sk index 282e9e0..c5ce058 100644 --- a/STEEM.CRAFT/_lib/getRandomUUID.sk +++ b/STEEM.CRAFT/_lib/getRandomUUID.sk @@ -9,8 +9,7 @@ import: java.util.UUID # -# > Function - getRandomUUID -# > Actions: +# > Function - getRandomUUID: # > Returns a random UUID as text. function getRandomUUID() :: text: return "%UUID.randomUUID()%" From 91821bd47a379d702a3bda9149f998fc334cf5c0 Mon Sep 17 00:00:00 2001 From: Abwasserrohr <44294954+Abwasserrohr@users.noreply.github.com> Date: Mon, 20 May 2019 17:18:10 +0200 Subject: [PATCH 14/32] Added claimRewards function claimRewards allows server operators to claim the rewards of the user. The reward goes to the user. --- STEEM.CRAFT/core/functions/claimRewards.sk | 99 ++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 STEEM.CRAFT/core/functions/claimRewards.sk diff --git a/STEEM.CRAFT/core/functions/claimRewards.sk b/STEEM.CRAFT/core/functions/claimRewards.sk new file mode 100644 index 0000000..11be7b8 --- /dev/null +++ b/STEEM.CRAFT/core/functions/claimRewards.sk @@ -0,0 +1,99 @@ +# +# ============== +# claimRewards.sk +# ============== +# claimRewards.sk is part of the STEEM.CRAFT core functions. +# ============== + +import: + java.util.ArrayList + java.util.HashMap + org.apache.commons.lang3.tuple.ImmutablePair + eu.bittrade.libs.steemj.SteemJ + eu.bittrade.libs.steemj.base.models.AccountName + eu.bittrade.libs.steemj.configuration.SteemJConfig + eu.bittrade.libs.steemj.enums.PrivateKeyType + +# +# > Function - claimRewards: +# > Claims the rewards for the specified Steem wallet. +# > Parameters: +# > Steem wallet name +# > random tx uuid (only used for local feedback) +function claimRewards(account:text,txuuid:text): + # + # > Addons can wait for the process until done. Set the response to "wait", + # > they should then wait until it is done. + set metadata value "steem-tx-response-%{_txuuid}%" of getDummy() to "wait" + # + # > Only prepare one claim transaction at once. + while {steemsk::txclaim} is set: + wait 1 tick + # + # > Use a HashMap to call the threaded asyncClaimRewards function. + set {_tx} to new HashMap() + {_tx}.put("account",{_account}) + {_tx}.put("txuuid","%{_txuuid}%") + set {steemsk::txclaim} to {_tx} + # + # > The response by the Steem node is not instantly, this would halt + # > the main game, and needs to be in a thread. + $ thread + # + # > Since this is a thread, only global variables will work here. + # > This is why not the local variable above has been used here. + asyncClaimRewards({steemsk::txclaim}) + +# +# > Function - asyncClaimRewards: +# > Claims the rewards for the specified Steem wallet. +# > Meant to only be used by the claimRewards function. +# > Parameters: +# > (text)account,(text)txuuid (only used for local feedback) +function asyncClaimRewards(tx:object): + # + # > Once this function has been called, remove the global variable + # > which has been used to call this function to allow more being + # > processed. + delete {steemsk::txclaim} + + # + # > Get the txuuid and acccount (as string) out of the HashMap. + set {_txuuid} to {_tx}.get("txuuid") + set {_account} to {_tx}.get("account") + + # + # > To claim the rewards, SteemJ is needed. + set {_steemj} to new SteemJ() + set {_config} to SteemJConfig.getInstance() + + # + # > Convert the string to a usable AccountName. + set {_account} to new AccountName({_account}) + + # + # > SteemJ.claimRewards() uses the default account. Set it here. + {_config}.setDefaultAccount({_account}) + + # + # > Add the private posting keys of the user to the PrivateKeyStorage to allow + # > broadcasting the claimRewards transaction. + set {_privatekeys} to new ArrayList() + {_privatekeys}.add(new ImmutablePair(PrivateKeyType.POSTING!, getPrivatePostingKey())) + {_config}.getPrivateKeyStorage().addAccount({_account},{_privatekeys}) + delete {_privatekeys} + + # + # > To work, the maximum expiration date offset has to decreased from default. + {_config}.setMaximumExpirationDateOffset(400000) + + # + # > claimRewards have a "try" prefix to prevent errors being logged to console. + try {_steemj}.claimRewards() + + # + # > If a error has been produced by the claimRewards, it can be handeled by addons. + if last java error is set: + set metadata value "steem-tx-response-%{_txuuid}%" of getDummy() to last java error + else: + set metadata value "steem-tx-response-%{_txuuid}%" of getDummy() to "done" From d1624b8db9cff85cecd35d784e694e298cadcb2e Mon Sep 17 00:00:00 2001 From: Abwasserrohr <44294954+Abwasserrohr@users.noreply.github.com> Date: Mon, 20 May 2019 18:13:52 +0200 Subject: [PATCH 15/32] Added getSteemResponse function The getSteemResponse function allows the player to get the last steem response quickly. The advantage over using the metadata directly is that rembebering the short function is faster and cleaner to look at. --- STEEM.CRAFT/core/functions/getSteemResponse.sk | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 STEEM.CRAFT/core/functions/getSteemResponse.sk diff --git a/STEEM.CRAFT/core/functions/getSteemResponse.sk b/STEEM.CRAFT/core/functions/getSteemResponse.sk new file mode 100644 index 0000000..74c1b28 --- /dev/null +++ b/STEEM.CRAFT/core/functions/getSteemResponse.sk @@ -0,0 +1,12 @@ +# +# ============== +# getSteemResponse.sk +# ============== +# getSteemResponse.sk is part of the STEEM.CRAFT core functions. +# ============== + +# +# > Function - getSteemResponse: +# > Retuns the current steem response for the transaction uuid. +function getSteemResponse(txuuid:text) :: object: + return metadata value "steem-tx-response-%{_txuuid}%" of getDummy() From 97ca61899742d47b3568c70f9e348beddae64744 Mon Sep 17 00:00:00 2001 From: Abwasserrohr <44294954+Abwasserrohr@users.noreply.github.com> Date: Tue, 21 May 2019 17:13:38 +0200 Subject: [PATCH 16/32] Added getHeadBlockNumber function This function allows to get the server operator the current head block number. --- STEEM.CRAFT/core/functions/getHeadBlockNumber.sk | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 STEEM.CRAFT/core/functions/getHeadBlockNumber.sk diff --git a/STEEM.CRAFT/core/functions/getHeadBlockNumber.sk b/STEEM.CRAFT/core/functions/getHeadBlockNumber.sk new file mode 100644 index 0000000..667207e --- /dev/null +++ b/STEEM.CRAFT/core/functions/getHeadBlockNumber.sk @@ -0,0 +1,16 @@ +# +# ============== +# getHeadBlockNumber.sk +# ============== +# getHeadBlockNumber.sk is part of the STEEM.CRAFT core functions. +# ============== + +import: + eu.bittrade.libs.steemj.SteemJ + +# +# > Function - getHeadBlockNumber: +# > Returns the current head block number. +function getHeadBlockNumber() :: number: + set {_steemj} to new SteemJ() + return {_steemj}.getDynamicGlobalProperties().getHeadBlockNumber() From bbc59b2d035e7249a39bd1c48d2dafd63af7ed64 Mon Sep 17 00:00:00 2001 From: Abwasserrohr <44294954+Abwasserrohr@users.noreply.github.com> Date: Tue, 21 May 2019 18:14:39 +0200 Subject: [PATCH 17/32] Added decompressBase64 function This function allows to decompress a compressed and endcoded base64 string, which returns a normal string. --- .../functions/compression/decompressBase64.sk | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 STEEM.CRAFT/core/functions/compression/decompressBase64.sk diff --git a/STEEM.CRAFT/core/functions/compression/decompressBase64.sk b/STEEM.CRAFT/core/functions/compression/decompressBase64.sk new file mode 100644 index 0000000..50a7498 --- /dev/null +++ b/STEEM.CRAFT/core/functions/compression/decompressBase64.sk @@ -0,0 +1,26 @@ +# +# ============== +# decompressBase64.sk +# ============== +# decompressBase64.sk is part of the STEEM.CRAFT core functions. +# ============== + +import: + org.apache.commons.codec.binary.Base64 + org.apache.commons.io.IOUtils + java.io.ByteArrayInputStream + java.util.zip.GZIPInputStream + +# +# > Function - decompressBase64: +# > Decompresses a compressed base64 string back into a normal string. +# > Parameters: +# > compressed text +# > Returns: +# > decompressed text +function decompressBase64(text:text) :: text: + set {_bytes} to Base64.decodeBase64({_text}) + set {_gzipinput} to new GZIPInputStream(new ByteArrayInputStream({_bytes})) + set {_result} to IOUtils.toString({_gzipinput},"Cp1047") + IOUtils.closeQuietly({_gzipinput}) + return {_result} From a1c8390c8b7b31d678eb3e41f3016381bb5cc03b Mon Sep 17 00:00:00 2001 From: Abwasserrohr <44294954+Abwasserrohr@users.noreply.github.com> Date: Tue, 21 May 2019 18:16:38 +0200 Subject: [PATCH 18/32] Added compressBase64 function compressBase64 allows the server operator to compress a text into a compressed and base64 encoded string. --- .../functions/compression/compressBase64.sk | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 STEEM.CRAFT/core/functions/compression/compressBase64.sk diff --git a/STEEM.CRAFT/core/functions/compression/compressBase64.sk b/STEEM.CRAFT/core/functions/compression/compressBase64.sk new file mode 100644 index 0000000..12dd9c6 --- /dev/null +++ b/STEEM.CRAFT/core/functions/compression/compressBase64.sk @@ -0,0 +1,27 @@ +# +# ============== +# compressBase64.sk +# ============== +# compressBase64.sk is part of the STEEM.CRAFT core functions. +# ============== + +import: + org.apache.commons.codec.binary.Base64 + org.apache.commons.io.IOUtils + java.io.ByteArrayOutputStream + java.util.zip.GZIPOutputStream + +# +# > Function - compressBase64: +# > Compresses a string into a compressed base64 string. +# > Parameters: +# > regular text +# > Returns: +# > compressed base64 string +function compressBase64(text:text) :: text: + set {_baos} to new ByteArrayOutputStream() + set {_gzos} to new GZIPOutputStream({_baos}) + {_gzos}.write({_text}.getBytes("Cp1047")) + IOUtils.closeQuietly({_gzos}) + set {_bytes} to {_baos}.toByteArray() + return Base64.encodeBase64String({_bytes}) From 5b635b9ec10edabdcf75c125bc7e40b9b0f43246 Mon Sep 17 00:00:00 2001 From: Abwasserrohr <44294954+Abwasserrohr@users.noreply.github.com> Date: Tue, 21 May 2019 18:17:40 +0200 Subject: [PATCH 19/32] Changed variable names --- STEEM.CRAFT/core/functions/compression/decompressBase64.sk | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/STEEM.CRAFT/core/functions/compression/decompressBase64.sk b/STEEM.CRAFT/core/functions/compression/decompressBase64.sk index 50a7498..9ccdbe6 100644 --- a/STEEM.CRAFT/core/functions/compression/decompressBase64.sk +++ b/STEEM.CRAFT/core/functions/compression/decompressBase64.sk @@ -20,7 +20,7 @@ import: # > decompressed text function decompressBase64(text:text) :: text: set {_bytes} to Base64.decodeBase64({_text}) - set {_gzipinput} to new GZIPInputStream(new ByteArrayInputStream({_bytes})) - set {_result} to IOUtils.toString({_gzipinput},"Cp1047") - IOUtils.closeQuietly({_gzipinput}) + set {_gzis} to new GZIPInputStream(new ByteArrayInputStream({_bytes})) + set {_result} to IOUtils.toString({_gzis},"Cp1047") + IOUtils.closeQuietly({_gzis}) return {_result} From 7435fd2bcfecb9075a2b275e859c9b610669c659 Mon Sep 17 00:00:00 2001 From: Abwasserrohr <44294954+Abwasserrohr@users.noreply.github.com> Date: Tue, 21 May 2019 18:18:59 +0200 Subject: [PATCH 20/32] Added Base64ToBytes function Base64ToBytes decodes a Base64 encoded string into bytes. --- .../functions/compression/Base64ToBytes.sk | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 STEEM.CRAFT/core/functions/compression/Base64ToBytes.sk diff --git a/STEEM.CRAFT/core/functions/compression/Base64ToBytes.sk b/STEEM.CRAFT/core/functions/compression/Base64ToBytes.sk new file mode 100644 index 0000000..58ac67a --- /dev/null +++ b/STEEM.CRAFT/core/functions/compression/Base64ToBytes.sk @@ -0,0 +1,19 @@ +# +# ============== +# Base64ToBytes.sk +# ============== +# Base64ToBytes.sk is part of the STEEM.CRAFT core functions. +# ============== + +import: + org.apache.commons.codec.binary.Base64 + +# +# > Function - Base64ToBytes: +# > Decodes base64 into bytes +# > Parameters: +# > byte64 string +# > Returns: +# > bytes +function Base64ToBytes(base64:text) :: object: + return Base64.decodeBase64({_base64}) From b6afd4bdaa9f6b64631585c861bd591612f83732 Mon Sep 17 00:00:00 2001 From: Abwasserrohr <44294954+Abwasserrohr@users.noreply.github.com> Date: Tue, 21 May 2019 18:19:37 +0200 Subject: [PATCH 21/32] Added BytesToBase64 function BytesToBase64 encodes bytes into a base64 encoded string. --- .../functions/compression/BytesToBase64.sk | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 STEEM.CRAFT/core/functions/compression/BytesToBase64.sk diff --git a/STEEM.CRAFT/core/functions/compression/BytesToBase64.sk b/STEEM.CRAFT/core/functions/compression/BytesToBase64.sk new file mode 100644 index 0000000..3c7db15 --- /dev/null +++ b/STEEM.CRAFT/core/functions/compression/BytesToBase64.sk @@ -0,0 +1,19 @@ +# +# ============== +# BytesToBase64.sk +# ============== +# BytesToBase64.sk is part of the STEEM.CRAFT core functions. +# ============== + +import: + org.apache.commons.codec.binary.Base64 + +# +# > Function - BytesToBase64: +# > Encodes bytes into a base64 string. +# > Parameters: +# > bytes +# > Returns: +# > byte64 string +function BytesToBase64(bytes:object) :: text: + return Base64.encodeBase64String({_bytes}) From dc3be49bd353cb14d61e636a992cfb7bd09abc9a Mon Sep 17 00:00:00 2001 From: Abwasserrohr <44294954+Abwasserrohr@users.noreply.github.com> Date: Wed, 22 May 2019 12:37:54 +0200 Subject: [PATCH 22/32] Added yaml data storage functions The server operator should be able to later change the storage options. Since the amount of data which is saved could get bigger over time, yaml storage allows the data to not being loaded into ram before it actually gets used. While this is useful, it is slow to parse and read data. It is important to cache the loaded data and not check for it every few seconds. --- STEEM.CRAFT/core/functions/storage/yaml.sk | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 STEEM.CRAFT/core/functions/storage/yaml.sk diff --git a/STEEM.CRAFT/core/functions/storage/yaml.sk b/STEEM.CRAFT/core/functions/storage/yaml.sk new file mode 100644 index 0000000..44b5006 --- /dev/null +++ b/STEEM.CRAFT/core/functions/storage/yaml.sk @@ -0,0 +1,32 @@ +# +# ============== +# yaml.sk +# ============== +# yaml.sk is part of the STEEM.CRAFT core functions. +# ============== + +# +# > Function - saveyamluserdata +# > Saves data for a username and a specific usage type in a yaml file. +# > Parameters: +# > usage identifier +# > the player who should be saved +# > data key +# > data value +function saveyamluserdata(usage:text,player:offline player,key:text,data:object): + set {_uuid} to uuid of {_player} + set yaml value "%{_key}%" from "plugins/Skript/storage/%{_usage}%/%{_uuid}%.yml" to {_data} + +# +# > Function - getyamluserdata +# > Returns the yaml user data to the player by parsing the file. +# > Try to cache results, since this is not very fast. +# > Parameters: +# > usage identifier +# > the player who should be saved +# > data key +# > Returns: +# > data value +function getyamluserdata(usage:text,player:offline player,key:text) :: object: + set {_uuid} to uuid of {_player} + return yaml value "%{_key}%" from "plugins/Skript/storage/%{_usage}%/%{_uuid}%.yml" From 5ce300be3aa7566a27a59aa953ae7ad989e69029 Mon Sep 17 00:00:00 2001 From: Abwasserrohr <44294954+Abwasserrohr@users.noreply.github.com> Date: Wed, 22 May 2019 12:41:21 +0200 Subject: [PATCH 23/32] Added configurable storage format Later, server operators should be able to change the storage type to their own desire. For now, it is only possible to store data in yaml, since it works without any additional setup. --- STEEM.CRAFT/config.sk | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/STEEM.CRAFT/config.sk b/STEEM.CRAFT/config.sk index c47b8ab..e3a21b3 100644 --- a/STEEM.CRAFT/config.sk +++ b/STEEM.CRAFT/config.sk @@ -17,6 +17,9 @@ options: defaultAppTags: ["steemcraft"] DefaultBeneficiaryAccount: "skyroad" DefaultBeneficiaryWeight: 250 + # + # > Currently supported formats: yaml. + storagetype: "yaml" # # > Please do not change these functions, since they are used to share the data between @@ -64,3 +67,10 @@ function getDefaultBeneficiaryAccount() :: text: # > Returns the default beneficary weight. function getDefaultBeneficiaryWeight() :: number: return {@DefaultBeneficiaryWeight} + +# +# > Function - getStorageType +# > Actions: +# > Returns the current storage type. +function getStorageType() :: text: + return {@storagetype} From f557780b05c9ad3c2fc701f8a6dda2943345d374 Mon Sep 17 00:00:00 2001 From: Abwasserrohr <44294954+Abwasserrohr@users.noreply.github.com> Date: Wed, 22 May 2019 12:48:21 +0200 Subject: [PATCH 24/32] Added functions for saving and getting data for users These new functions now allow to get and save data for specific users. It also allows later other storage formats to be added without changing other files. --- STEEM.CRAFT/core/functions/storage/storage.sk | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 STEEM.CRAFT/core/functions/storage/storage.sk diff --git a/STEEM.CRAFT/core/functions/storage/storage.sk b/STEEM.CRAFT/core/functions/storage/storage.sk new file mode 100644 index 0000000..9cc5379 --- /dev/null +++ b/STEEM.CRAFT/core/functions/storage/storage.sk @@ -0,0 +1,40 @@ +# +# ============== +# storage.sk +# ============== +# storage.sk is part of the STEEM.CRAFT core functions. +# ============== + +# +# > Function - saveStorageData +# > Saves data for a username and a specific usage type to the desired format. +# > Parameters: +# > usage identifier +# > the player who should be saved +# > data key +# > data value +function saveStorageData(usage:text,player:offline player,key:text,data:object): + # + # > Get the storage type out of the configuration to allow the server + # > operator multiple storage formats. + set {_storageformat} to getStorageType() + if {_storageformat} is "yaml": + saveyamluserdata({_usage},{_player},{_key},{_data}) + +# +# > Function - getStorageData +# > Returns the requested data from the desired storage format. +# > Try to cache results, since this may not very fast. +# > Parameters: +# > usage identifier +# > the player who should be saved +# > data key +# > Returns: +# > data value +function getStorageData(usage:text,player:offline player,key:text) :: object: + # + # > Get the storage type out of the configuration to allow the server + # > operator multiple storage formats. + set {_storageformat} to getStorageType() + if {_storageformat} is "yaml": + return getyamluserdata({_usage},{_player},{_key}) From 883041ebc8cde8995c3256b8888776fed25e65ae Mon Sep 17 00:00:00 2001 From: Abwasserrohr <44294954+Abwasserrohr@users.noreply.github.com> Date: Wed, 22 May 2019 12:58:33 +0200 Subject: [PATCH 25/32] Added getSyncedAccount function This function returns the synced steem account wallet for the player who is given. If the player has not been synced, it returns false. --- .../core/functions/getSyncedAccount.sk | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 STEEM.CRAFT/core/functions/getSyncedAccount.sk diff --git a/STEEM.CRAFT/core/functions/getSyncedAccount.sk b/STEEM.CRAFT/core/functions/getSyncedAccount.sk new file mode 100644 index 0000000..06f3e80 --- /dev/null +++ b/STEEM.CRAFT/core/functions/getSyncedAccount.sk @@ -0,0 +1,28 @@ +# +# ============== +# getSyncedAccount.sk +# ============== +# getSyncedAccount.sk is part of the STEEM.CRAFT core functions. +# ============== + +# +# > Function - getSyncedAccount +# > Returns the synced steem wallet account for the player. +# > If the player isn't synced, return false. +# > Parameters: +# > player +function getSyncedAccount(player:offline player) :: object: + # + # > Since getting the synced account could be slow from some formats, + # > it is being cached here within the metadata of the player. + if metadata value "steemaccount" of {_player} is not set: + set {_account} to getStorageData("steem",{_player},"account") + set metadata value "steemaccount" of {_player} to {_account} + else: + set {_account} to metadata value "steemaccount" of {_player} + # + # > Only return the account if it actually exists. + if {_account} is set: + return {_account} + else: + return false From e0c5198d47aa5f7a6aca5d87164f3be05bc57657 Mon Sep 17 00:00:00 2001 From: Abwasserrohr <44294954+Abwasserrohr@users.noreply.github.com> Date: Wed, 22 May 2019 13:03:26 +0200 Subject: [PATCH 26/32] Added setSyncedAccount function This function allows to set a synced account. There is no validation done by this function. It should be done before. --- STEEM.CRAFT/core/functions/setSyncedAccount.sk | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 STEEM.CRAFT/core/functions/setSyncedAccount.sk diff --git a/STEEM.CRAFT/core/functions/setSyncedAccount.sk b/STEEM.CRAFT/core/functions/setSyncedAccount.sk new file mode 100644 index 0000000..b5c0eee --- /dev/null +++ b/STEEM.CRAFT/core/functions/setSyncedAccount.sk @@ -0,0 +1,17 @@ +# +# ============== +# setSyncedAccount.sk +# ============== +# setSyncedAccount.sk is part of the STEEM.CRAFT core functions. +# ============== + +# +# > Function - setSyncedAccount +# > Sets the synced steem account wallet for this player to the text. +# > There is no validation, make sure that the player actually owns +# > the synced steem account. +# > Parameters: +# > player who owns the steem account +# > steem account that should be synced +function setSyncedAccount(player:offline player,account:text) :: object: + saveStorageData("steem",{_player},"account",{_account}) From 82dad5e1add2594136961966cb9f247af6defe90 Mon Sep 17 00:00:00 2001 From: Abwasserrohr <44294954+Abwasserrohr@users.noreply.github.com> Date: Wed, 22 May 2019 13:16:54 +0200 Subject: [PATCH 27/32] Added getAccount function This function returns a Steem account to the given text. --- STEEM.CRAFT/core/functions/getAccount.sk | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 STEEM.CRAFT/core/functions/getAccount.sk diff --git a/STEEM.CRAFT/core/functions/getAccount.sk b/STEEM.CRAFT/core/functions/getAccount.sk new file mode 100644 index 0000000..2594f7e --- /dev/null +++ b/STEEM.CRAFT/core/functions/getAccount.sk @@ -0,0 +1,24 @@ +# +# ============== +# getAccount.sk +# ============== +# getAccount.sk is part of the STEEM.CRAFT core functions. +# ============== + +import: + eu.bittrade.libs.steemj.SteemJ + eu.bittrade.libs.steemj.base.models.AccountName + java.util.ArrayList + +# +# > Function - getAccount +# > Returns a steem wallet account +# > Parameters: +# > a steem wallet account name +function getAccount(account:text) :: object: + set {_steemj} to new SteemJ() + set {_account} to {_account}.toLowerCase() + set {_account} to new AccountName({_account}) + set {_accountrequest} to new ArrayList() + {_accountrequest}.add({_account}) + return {_steemj}.getAccounts({_accountrequest}).get(0) From ab68d846d7bb445b40b28815ca08efe13c46d00d Mon Sep 17 00:00:00 2001 From: Abwasserrohr <44294954+Abwasserrohr@users.noreply.github.com> Date: Wed, 22 May 2019 13:30:56 +0200 Subject: [PATCH 28/32] getServerAccountName should return the server account --- STEEM.CRAFT/config.sk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/STEEM.CRAFT/config.sk b/STEEM.CRAFT/config.sk index e3a21b3..8877402 100644 --- a/STEEM.CRAFT/config.sk +++ b/STEEM.CRAFT/config.sk @@ -37,7 +37,7 @@ function getPrivatePostingKey() :: text: # > Actions: # > Returns the server account name. function getServerAccountName() :: text: - return {@privatepostingkey} + return {@serveraccountname} # # > Function - getAppName From e41757a264969cf0a351e435933fdf896ea0523c Mon Sep 17 00:00:00 2001 From: Abwasserrohr <44294954+Abwasserrohr@users.noreply.github.com> Date: Wed, 22 May 2019 14:01:24 +0200 Subject: [PATCH 29/32] Added validateSyncedSteemAccountUUID function The validateSyncedSteemAccountUUID function will check a steem account to match the uuid of the player. This is useful to be sure that the account is actually the right account. This is not safe for offline mode servers. --- .../validateSyncedSteemAccountUUID.sk | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 STEEM.CRAFT/core/functions/validation/validateSyncedSteemAccountUUID.sk diff --git a/STEEM.CRAFT/core/functions/validation/validateSyncedSteemAccountUUID.sk b/STEEM.CRAFT/core/functions/validation/validateSyncedSteemAccountUUID.sk new file mode 100644 index 0000000..6d6e2f2 --- /dev/null +++ b/STEEM.CRAFT/core/functions/validation/validateSyncedSteemAccountUUID.sk @@ -0,0 +1,54 @@ +# +# ============== +# validateSyncedSteemAccountUUID.sk +# ============== +# validateSyncedSteemAccountUUID.sk is part of the STEEM.CRAFT core functions. +# ============== + +import: + com.fasterxml.jackson.databind.ObjectMapper + +# +# > Function - validateSyncedSteemAccountUUID +# > Returns true if the synced steem account is connected properly, if not, +# > false is returned. +# > Parameters: +# > the player which should be checked for being synced +# > the steem account which should be checked for being synced +# > Returns: +# > true=synced | false=not synced +function validateSyncedSteemAccountUUID(player:offline player, account:text="checkstorage") :: boolean: + # + # > If there has been no account defined, use already synced one to + # > validate. + if {_account} is "checkstorage": + set {_account} to getSyncedAccount({_player}) + # + # > If there is no account defined in the parameters and not stored + # > on the server, return false. + if {_account} is false: + return false + + # + # > Since there is an account stored, get the account from the + # > Steem Blockchain to check if the saved uuid matches with the player. + set {_accountdata} to getAccount({_account}) + if {_accountdata} is set: + set {_json} to {_accountdata}.getJsonMetadata() + set {_objectMapper} to new ObjectMapper() + set {_jsonNode} to {_objectMapper}.readTree({_json}) + + # + # > The profile needs the minecraftuuid value set to the ingame uuid. + # > If this value doesn't match, it will return false. + # > The JsonMetadata of the account should contain at least the following data: + # > {"profile":{"minecraftuuid":"minecraft uuid value of the player"}} + set {_steemuuid} to {_jsonNode}.get("profile").get("minecraftuuid").textValue() + + # + # > The uuid of a {_player} has to be stored in a variable + # > before it can be used to check for the same string. + set {_uuid} to uuid of {_player} + if {_uuid} is {_steemuuid}: + return true + return false From a883b0869443d33867780a34b6bc28bc38db77a7 Mon Sep 17 00:00:00 2001 From: Abwasserrohr <44294954+Abwasserrohr@users.noreply.github.com> Date: Wed, 22 May 2019 14:02:32 +0200 Subject: [PATCH 30/32] Added validateSyncedSteemAccountAuths function This function will check if the defined account has the auths the server needs to use the account. If there is no account defined, it will automatically ccheck for the already synced account. --- .../validateSyncedSteemAccountAuths.sk | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 STEEM.CRAFT/core/functions/validation/validateSyncedSteemAccountAuths.sk diff --git a/STEEM.CRAFT/core/functions/validation/validateSyncedSteemAccountAuths.sk b/STEEM.CRAFT/core/functions/validation/validateSyncedSteemAccountAuths.sk new file mode 100644 index 0000000..cf13dd3 --- /dev/null +++ b/STEEM.CRAFT/core/functions/validation/validateSyncedSteemAccountAuths.sk @@ -0,0 +1,38 @@ +# +# ============== +# validateSyncedSteemAccountAuths.sk +# ============== +# validateSyncedSteemAccountAuths.sk is part of the STEEM.CRAFT core functions. +# ============== + +# +# > Function - validateSyncedSteemAccountAuths +# > Returns true if the synced steem account is connected properly, if not, +# > false is returned. +# > Parameters: +# > the player which should be checked for being synced +# > the steem account which should be checked for being synced +# > Returns: +# > true=synced | false=not synced +function validateSyncedSteemAccountAuths(player:offline player, account:text="checkstorage") :: boolean: + # + # > If there has been no account defined, use already synced one to + # > validate. + if {_account} is "checkstorage": + set {_account} to getSyncedAccount({_player}) + # + # > If there is no account defined in the parameters and not stored + # > on the server, return false. + if {_account} is false: + return false + + # + # > Since there is an account stored, get the account from the + # > Steem Blockchain to check if the server has the needed auths. + set {_accountdata} to getAccount({_account}) + if {_accountdata} is set: + set {_neededauth} to getServerAccountName() + loop ...{_accountdata}.getPosting().getAccountAuths().keySet(): + if "%loop-value%" is {_neededauth}: + return true + return false From 5962b89c5c7a167fdc504ef75186acc641336059 Mon Sep 17 00:00:00 2001 From: Abwasserrohr <44294954+Abwasserrohr@users.noreply.github.com> Date: Wed, 22 May 2019 14:19:06 +0200 Subject: [PATCH 31/32] Added chat prefix to configuration The chat prefix configuration allows the server operator to change the prefix of all STEEM.CRAFT addons and core messages by changing it within the config.sk file. This is useful to match the corporate identity of the server. --- STEEM.CRAFT/config.sk | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/STEEM.CRAFT/config.sk b/STEEM.CRAFT/config.sk index 8877402..395e6fc 100644 --- a/STEEM.CRAFT/config.sk +++ b/STEEM.CRAFT/config.sk @@ -20,7 +20,10 @@ options: # # > Currently supported formats: yaml. storagetype: "yaml" - + # + # > Chat prefix that is shown in STEEM.CRAFT addons. + chatprefix: "&7[&6&lSTEEM.CRAFT&7] &8&l>>&7" + # # > Please do not change these functions, since they are used to share the data between # > other Skript files on the server. Be sure to never leak your private posting key! @@ -74,3 +77,10 @@ function getDefaultBeneficiaryWeight() :: number: # > Returns the current storage type. function getStorageType() :: text: return {@storagetype} + +# +# > Function - getChatPrefix +# > Actions: +# > Returns the chat prefix. +function getChatPrefix() :: text: + return {@chatprefix} From ff44e4bdf8f4c832defde0f78088e1ee70e4c927 Mon Sep 17 00:00:00 2001 From: Abwasserrohr <44294954+Abwasserrohr@users.noreply.github.com> Date: Wed, 22 May 2019 14:43:30 +0200 Subject: [PATCH 32/32] Added steemconnect addon This "addon" allows the player to easily connect to the server, the messages help the player with links to broadcast the right transactions needed outside of Minecraft for a fast and secure process. --- STEEM.CRAFT/addons/steemconnect.sk | 100 +++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 STEEM.CRAFT/addons/steemconnect.sk diff --git a/STEEM.CRAFT/addons/steemconnect.sk b/STEEM.CRAFT/addons/steemconnect.sk new file mode 100644 index 0000000..27feb7e --- /dev/null +++ b/STEEM.CRAFT/addons/steemconnect.sk @@ -0,0 +1,100 @@ +# +# ============== +# steemconnect.sk +# ============== +# steemconnect.sk is part of the STEEM.CRAFT addons. +# ============== +# > This addon allows players to easily connect to the server +# > using SteemConnect links. SteemConnect is a trusted place +# > to sign transactions to the Steem Blockchain. +# ============== + +import: + net.md_5.bungee.api.chat.TextComponent + net.md_5.bungee.api.chat.ComponentBuilder + net.md_5.bungee.api.chat.ClickEvent + net.md_5.bungee.api.chat.HoverEvent + net.md_5.bungee.api.chat.HoverEvent$Action as HoverEventAction + net.md_5.bungee.api.chat.ClickEvent$Action as ClickEventAction + +# +# > Command - /steemconnect +# > Gives the player links to connect the account to the server. +# > Also validates if the account is synced correctly and stores +# > the steem name once the verification is done. +command /steemconnect []: + trigger: + # + # > If the player is already synced with this account, there + # > is no need to repeat the process. + if getSyncedAccount(player) is arg-1: + message "%getChatPrefix()% You're already connected to this account." + stop + + # + # > If the player has not set any argument, send the usage. + if arg-1 is not set: + message "%getChatPrefix()% Usage: /steemconnect " + stop + + # + # > If the account name doesn't exist, tell the player + # > about this and add a usage for support. + else if getAccount(arg-1) is not set: + message "%getChatPrefix()% Steem account %arg-1% not found." + message "%getChatPrefix()% Usage: /steemconnect " + stop + + # + # > If the account doesn't have the uuid saved in the profile, send a link + # > which sets the player's uuid to the profile of the steem account. + if validateSyncedSteemAccountUUID(player,arg-1) is false: + + # + # > Create a new ComponentBuilder to make clickable and hoverable text. + set {_builder} to new ComponentBuilder(new TextComponent(getChatPrefix())) + set {_uuid} to uuid of player + set {_updateprofileurl} to "https://app.steemconnect.com/sign/profile-update?minecraftuuid=%{_uuid}%" + set {_msg} to new TextComponent("Click here to sync your Steem account.") + {_msg}.setClickEvent(new ClickEvent(ClickEventAction.OPEN_URL!,{_updateprofileurl})) + {_msg}.setHoverEvent(new HoverEvent(HoverEventAction.SHOW_TEXT!,new ComponentBuilder("Click here to open.").create())) + {_builder}.append({_msg}) + + # + # > This is a temporary fix until ComponentBuilder works again. + execute console command "/tellraw %player% ["""",{""text"":""%getChatPrefix()% ""},{""text"":""Click here to sync your Steem account."",""clickEvent"":{""action"":""open_url"",""value"":""%{_updateprofileurl}%""}}]" + + # + # > The function currently doesn't work correctly, use backup command above. + # > player.sendMessage({_builder}.create()) + message "%getChatPrefix()% Once you're done: /steemconnect %arg-1%" + stop + + # + # > If the account doesn't have the server account authorized, send a link + # > which authorizes the server account. + if validateSyncedSteemAccountAuths(player,arg-1) is false: + + # + # > Create a new ComponentBuilder to make clickable and hoverable text. + set {_builder} to new ComponentBuilder(new TextComponent(getChatPrefix())) + set {_updateprofileurl} to "https://app.steemconnect.com/authorize/@%getServerAccountName()%" + set {_msg} to new TextComponent("Click here to authorize the server.") + {_msg}.setClickEvent(new ClickEvent(ClickEventAction.OPEN_URL!,{_updateprofileurl})) + {_msg}.setHoverEvent(new HoverEvent(HoverEventAction.SHOW_TEXT!,new ComponentBuilder("Click here to open.").create())) + {_builder}.append({_msg}) + + # + # > This is a temporary fix until ComponentBuilder works again. + execute console command "/tellraw %player% ["""",{""text"":""%getChatPrefix()% ""},{""text"":""Click here to authorize the server."",""clickEvent"":{""action"":""open_url"",""value"":""%{_updateprofileurl}%""}}]" + + # + # > The function currently doesn't work correctly, use backup command above. + # > player.sendMessage({_builder}.create()) + message "%getChatPrefix()% Once you're done: /steemconnect %arg-1%" + stop + + # + # > If the event has not been stopped yet, the account is synced. + setSyncedAccount(player,arg-1) + message "%getChatPrefix()% Your account has been successfully connected."